Indented with standard indent rules.
This commit is contained in:
@@ -75,7 +75,9 @@ void dlmstp_millisecond_timer(
|
||||
INCREMENT_AND_LIMIT_UINT16(SilenceTime);
|
||||
}
|
||||
|
||||
void get_abstime(struct timespec *abstime, unsigned long milliseconds)
|
||||
void get_abstime(
|
||||
struct timespec *abstime,
|
||||
unsigned long milliseconds)
|
||||
{
|
||||
struct timeval tp;
|
||||
unsigned long seconds;
|
||||
@@ -86,8 +88,8 @@ void get_abstime(struct timespec *abstime, unsigned long milliseconds)
|
||||
abstime->tv_nsec = tp.tv_usec * 1000;
|
||||
seconds = milliseconds / 1000;
|
||||
abstime->tv_sec += seconds;
|
||||
abstime->tv_nsec += ((milliseconds - (seconds * 1000))*(1000*1000));
|
||||
seconds = abstime->tv_nsec / (1000*1000*1000);
|
||||
abstime->tv_nsec += ((milliseconds - (seconds * 1000)) * (1000 * 1000));
|
||||
seconds = abstime->tv_nsec / (1000 * 1000 * 1000);
|
||||
abstime->tv_sec += seconds;
|
||||
}
|
||||
|
||||
@@ -152,10 +154,8 @@ uint16_t dlmstp_receive(
|
||||
(void) max_pdu;
|
||||
/* see if there is a packet available, and a place
|
||||
to put the reply (if necessary) and process it */
|
||||
get_abstime(&abstime,timeout);
|
||||
rv = pthread_cond_timedwait(
|
||||
&Receive_Packet_Flag,
|
||||
&Receive_Packet_Mutex,
|
||||
get_abstime(&abstime, timeout);
|
||||
rv = pthread_cond_timedwait(&Receive_Packet_Flag, &Receive_Packet_Mutex,
|
||||
&abstime);
|
||||
if (rv == 0) {
|
||||
if (Receive_Packet.ready) {
|
||||
@@ -227,8 +227,8 @@ static void *dlmstp_master_fsm_task(
|
||||
if (milliseconds) {
|
||||
get_abstime(&abstime, milliseconds);
|
||||
/* we want an OS effecient way to wait for a frame */
|
||||
pthread_cond_timedwait(&Received_Frame_Flag,
|
||||
&Received_Frame_Mutex, &abstime);
|
||||
pthread_cond_timedwait(&Received_Frame_Flag, &Received_Frame_Mutex,
|
||||
&abstime);
|
||||
}
|
||||
MSTP_Master_Node_FSM(&MSTP_Port);
|
||||
}
|
||||
@@ -622,26 +622,28 @@ bool dlmstp_init(
|
||||
Receive_Packet.pdu_len = 0;
|
||||
rv = pthread_cond_init(&Receive_Packet_Flag, NULL);
|
||||
if (rv == -1) {
|
||||
fprintf(stderr, "MS/TP Interface: %s\n cannot allocate PThread Condition.\n",
|
||||
fprintf(stderr,
|
||||
"MS/TP Interface: %s\n cannot allocate PThread Condition.\n",
|
||||
ifname);
|
||||
exit(1);
|
||||
}
|
||||
rv = pthread_cond_init(&Received_Frame_Flag, NULL);
|
||||
if (rv == -1) {
|
||||
fprintf(stderr, "MS/TP Interface: %s\n cannot allocate PThread Condition.\n",
|
||||
fprintf(stderr,
|
||||
"MS/TP Interface: %s\n cannot allocate PThread Condition.\n",
|
||||
ifname);
|
||||
exit(1);
|
||||
}
|
||||
rv = pthread_mutex_init(&Receive_Packet_Mutex, NULL);
|
||||
if (rv == -1) {
|
||||
fprintf(stderr, "MS/TP Interface: %s\n cannot allocate PThread Mutex.\n",
|
||||
ifname);
|
||||
fprintf(stderr,
|
||||
"MS/TP Interface: %s\n cannot allocate PThread Mutex.\n", ifname);
|
||||
exit(1);
|
||||
}
|
||||
rv = pthread_mutex_init(&Received_Frame_Mutex, NULL);
|
||||
if (rv == -1) {
|
||||
fprintf(stderr, "MS/TP Interface: %s\n cannot allocate PThread Mutex.\n",
|
||||
ifname);
|
||||
fprintf(stderr,
|
||||
"MS/TP Interface: %s\n cannot allocate PThread Mutex.\n", ifname);
|
||||
exit(1);
|
||||
}
|
||||
/* initialize hardware */
|
||||
|
||||
@@ -110,7 +110,7 @@ static int ethernet_bind(
|
||||
/* alias net-pf-17 af_packet */
|
||||
/* Then follow it by: # modprobe af_packet */
|
||||
/* Note: PF_INET/SOCK_PACKET has been replaced with
|
||||
PF_PACKET/(SOCK_PACKET, SOCK_DGRAM, SOCK_RAW).*/
|
||||
PF_PACKET/(SOCK_PACKET, SOCK_DGRAM, SOCK_RAW). */
|
||||
|
||||
/* Attempt to open the socket for 802.2 ethernet frames */
|
||||
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0) {
|
||||
@@ -125,13 +125,13 @@ static int ethernet_bind(
|
||||
"# modprobe af_packet\n");
|
||||
exit(-1);
|
||||
}
|
||||
#if 0
|
||||
#if 0
|
||||
/* It is very advisable to do a IP_HDRINCL call, to make sure
|
||||
that the kernel knows the header is included in the data,
|
||||
and doesn't insert its own header into the packet before our data */
|
||||
if (setsockopt (sock_fd, IPPROTO_IP, IP_HDRINCL, &sockopt,
|
||||
sizeof(sockopt)) < 0) {
|
||||
printf ("Warning: Cannot set HDRINCL!\n");
|
||||
if (setsockopt(sock_fd, IPPROTO_IP, IP_HDRINCL, &sockopt,
|
||||
sizeof(sockopt)) < 0) {
|
||||
printf("Warning: Cannot set HDRINCL!\n");
|
||||
}
|
||||
#endif
|
||||
/* Bind the socket to an address */
|
||||
|
||||
@@ -117,12 +117,13 @@ uint16_t MSTP_Get_Reply(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int network_init(const char *name, int protocol)
|
||||
static int network_init(
|
||||
const char *name,
|
||||
int protocol)
|
||||
{
|
||||
/* check to see if we are being run as root */
|
||||
if (getuid() != 0) {
|
||||
fprintf(stderr,
|
||||
"Requires root priveleges.\n");
|
||||
fprintf(stderr, "Requires root priveleges.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -162,9 +163,9 @@ static void snap_received_packet(
|
||||
volatile struct mstp_port_struct_t *mstp_port,
|
||||
int sockfd)
|
||||
{
|
||||
uint16_t mtu_len = 0; /* number of octets of packet saved in file */
|
||||
unsigned i = 0; /* counter */
|
||||
static uint8_t mtu[1500] = {0};
|
||||
uint16_t mtu_len = 0; /* number of octets of packet saved in file */
|
||||
unsigned i = 0; /* counter */
|
||||
static uint8_t mtu[1500] = { 0 };
|
||||
|
||||
mtu[0] = 0;
|
||||
mtu[1] = 0;
|
||||
@@ -177,7 +178,7 @@ static void snap_received_packet(
|
||||
mtu[8] = 0;
|
||||
mtu[9] = 0;
|
||||
mtu[10] = 0;
|
||||
mtu[11]= mstp_port->SourceAddress;
|
||||
mtu[11] = mstp_port->SourceAddress;
|
||||
/* length - 12, 13 */
|
||||
mtu[14] = 0xaa; /* DSAP for SNAP */
|
||||
mtu[15] = 0xaa; /* SSAP for SNAP */
|
||||
@@ -199,15 +200,15 @@ static void snap_received_packet(
|
||||
mtu_len = 31;
|
||||
if (mstp_port->DataLength) {
|
||||
for (i = 0; i < mstp_port->DataLength; i++) {
|
||||
mtu[31+i] = mstp_port->InputBuffer[i];
|
||||
mtu[31 + i] = mstp_port->InputBuffer[i];
|
||||
}
|
||||
mtu[31+mstp_port->DataLength] = mstp_port->DataCRCActualMSB;
|
||||
mtu[31+mstp_port->DataLength+1] = mstp_port->DataCRCActualLSB;
|
||||
mtu_len += (mstp_port->DataLength+2);
|
||||
mtu[31 + mstp_port->DataLength] = mstp_port->DataCRCActualMSB;
|
||||
mtu[31 + mstp_port->DataLength + 1] = mstp_port->DataCRCActualLSB;
|
||||
mtu_len += (mstp_port->DataLength + 2);
|
||||
}
|
||||
/* Ethernet length is data only - not address or length bytes */
|
||||
encode_unsigned16(&mtu[12], mtu_len-14);
|
||||
write(sockfd,&mtu[0], mtu_len);
|
||||
encode_unsigned16(&mtu[12], mtu_len - 14);
|
||||
write(sockfd, &mtu[0], mtu_len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user