indented.
This commit is contained in:
@@ -124,8 +124,8 @@ static int arcnet_bind(
|
||||
"You might need to add the following to modules.conf\n"
|
||||
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
||||
"alias net-pf-17 af_packet\n"
|
||||
"Also, add af_packet to /etc/modules.\n"
|
||||
"Then follow it by:\n" "# modprobe af_packet\n");
|
||||
"Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
|
||||
"# modprobe af_packet\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -144,14 +144,14 @@ static int arcnet_bind(
|
||||
if (bind(sock_fd, &ARCNET_Socket_Address,
|
||||
sizeof(ARCNET_Socket_Address)) != 0) {
|
||||
/* Bind problem, close socket and return */
|
||||
fprintf(stderr,
|
||||
"arcnet: Unable to bind socket : %s\n", strerror(errno));
|
||||
fprintf(stderr, "arcnet: Unable to bind socket : %s\n",
|
||||
strerror(errno));
|
||||
fprintf(stderr,
|
||||
"You might need to add the following to modules.conf\n"
|
||||
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
||||
"alias net-pf-17 af_packet\n"
|
||||
"Also, add af_packet to /etc/modules.\n"
|
||||
"Then follow it by:\n" "# modprobe af_packet\n");
|
||||
"Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
|
||||
"# modprobe af_packet\n");
|
||||
/* Close the socket */
|
||||
close(sock_fd);
|
||||
exit(-1);
|
||||
@@ -170,8 +170,8 @@ static int arcnet_bind(
|
||||
/* Strcpy the interface name into the address */
|
||||
strncpy(ARCNET_Socket_Address.sa_data, interface_name,
|
||||
sizeof(ARCNET_Socket_Address.sa_data) - 1);
|
||||
fprintf(stderr, "arcnet: MAC=%02Xh iface=\"%s\"\n",
|
||||
ARCNET_MAC_Address, ARCNET_Socket_Address.sa_data);
|
||||
fprintf(stderr, "arcnet: MAC=%02Xh iface=\"%s\"\n", ARCNET_MAC_Address,
|
||||
ARCNET_Socket_Address.sa_data);
|
||||
|
||||
atexit(arcnet_cleanup);
|
||||
|
||||
@@ -295,8 +295,7 @@ uint16_t arcnet_receive(
|
||||
/* using O_NONBLOCK and no data */
|
||||
/* was immediately available for reading. */
|
||||
if (errno != EAGAIN)
|
||||
fprintf(stderr,
|
||||
"ethernet: Read error in receiving packet: %s\n",
|
||||
fprintf(stderr, "ethernet: Read error in receiving packet: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ static void bip_set_interface(
|
||||
if (BIP_Debug) {
|
||||
fprintf(stderr, "IP Broadcast Address: %s\n",
|
||||
inet_ntoa(broadcast_address));
|
||||
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n",
|
||||
bip_get_port(), bip_get_port());
|
||||
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", bip_get_port(),
|
||||
bip_get_port());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,16 +128,18 @@ bool bip_init(
|
||||
/* Allow us to use the same socket for sending and receiving */
|
||||
/* This makes sure that the src port is correct when sending */
|
||||
sockopt = 1;
|
||||
status = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
&sockopt, sizeof(sockopt));
|
||||
status =
|
||||
setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &sockopt,
|
||||
sizeof(sockopt));
|
||||
if (status < 0) {
|
||||
close(sock_fd);
|
||||
bip_set_socket(-1);
|
||||
return status;
|
||||
}
|
||||
/* allow us to send a broadcast */
|
||||
status = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
|
||||
&sockopt, sizeof(sockopt));
|
||||
status =
|
||||
setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, &sockopt,
|
||||
sizeof(sockopt));
|
||||
if (status < 0) {
|
||||
close(sock_fd);
|
||||
bip_set_socket(-1);
|
||||
@@ -148,8 +150,8 @@ bool bip_init(
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
sin.sin_port = htons(bip_get_port());
|
||||
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
|
||||
status = bind(sock_fd,
|
||||
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
||||
status =
|
||||
bind(sock_fd, (const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
||||
if (status < 0) {
|
||||
close(sock_fd);
|
||||
bip_set_socket(-1);
|
||||
|
||||
@@ -177,8 +177,7 @@ uint16_t dlmstp_receive(
|
||||
/* was immediately available for reading. */
|
||||
if (errno != EAGAIN) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"mstp: Read error in Receive_Client packet: %s\n",
|
||||
fprintf(stderr, "mstp: Read error in Receive_Client packet: %s\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
}
|
||||
@@ -320,8 +319,8 @@ int dlmstp_get_transmit_packet(
|
||||
max = Transmit_Client_SockFD;
|
||||
|
||||
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0) {
|
||||
received_bytes = read(Transmit_Client_SockFD,
|
||||
packet, sizeof(DLMSTP_PACKET));
|
||||
received_bytes =
|
||||
read(Transmit_Client_SockFD, packet, sizeof(DLMSTP_PACKET));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
@@ -333,8 +332,7 @@ int dlmstp_get_transmit_packet(
|
||||
/* was immediately available for reading. */
|
||||
if (errno != EAGAIN) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"mstp: Read error in Transmit_Client packet: %s\n",
|
||||
fprintf(stderr, "mstp: Read error in Transmit_Client packet: %s\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
}
|
||||
@@ -369,9 +367,8 @@ uint16_t MSTP_Get_Send(
|
||||
}
|
||||
/* convert the PDU into the MSTP Frame */
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||
mstp_port->OutputBufferSize,
|
||||
packet.frame_type,
|
||||
destination, mstp_port->This_Station, &packet.pdu[0], packet.pdu_len);
|
||||
mstp_port->OutputBufferSize, packet.frame_type, destination,
|
||||
mstp_port->This_Station, &packet.pdu[0], packet.pdu_len);
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
@@ -401,8 +398,9 @@ bool dlmstp_compare_data_expecting_reply(
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(&request_pdu[0],
|
||||
NULL, &request.address, &request.npdu_data);
|
||||
offset =
|
||||
npdu_decode(&request_pdu[0], NULL, &request.address,
|
||||
&request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -418,8 +416,8 @@ bool dlmstp_compare_data_expecting_reply(
|
||||
request.service_choice = request_pdu[offset + 3];
|
||||
/* decode the reply data */
|
||||
bacnet_address_copy(&reply.address, dest_address);
|
||||
offset = npdu_decode(&reply_pdu[0],
|
||||
&reply.address, NULL, &reply.npdu_data);
|
||||
offset =
|
||||
npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -508,25 +506,23 @@ uint16_t MSTP_Get_Reply(
|
||||
return 0;
|
||||
}
|
||||
/* is this the reply to the DER? */
|
||||
matched = dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
|
||||
mstp_port->DataLength,
|
||||
mstp_port->SourceAddress,
|
||||
&Transmit_Packet.pdu[0],
|
||||
Transmit_Packet.pdu_len, &Transmit_Packet.address);
|
||||
matched =
|
||||
dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
|
||||
mstp_port->DataLength, mstp_port->SourceAddress,
|
||||
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len,
|
||||
&Transmit_Packet.address);
|
||||
if (matched) {
|
||||
/* convert the PDU into the MSTP Frame */
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||
mstp_port->OutputBufferSize,
|
||||
Transmit_Packet.frame_type,
|
||||
destination,
|
||||
mstp_port->This_Station,
|
||||
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
|
||||
mstp_port->OutputBufferSize, Transmit_Packet.frame_type,
|
||||
destination, mstp_port->This_Station, &Transmit_Packet.pdu[0],
|
||||
Transmit_Packet.pdu_len);
|
||||
/* not used here, but setting it anyway */
|
||||
Transmit_Packet.ready = false;
|
||||
} else {
|
||||
/* put it back into the queue */
|
||||
(void) write(Transmit_Server_SockFD,
|
||||
&Transmit_Packet, sizeof(Transmit_Packet));
|
||||
(void) write(Transmit_Server_SockFD, &Transmit_Packet,
|
||||
sizeof(Transmit_Packet));
|
||||
}
|
||||
|
||||
return pdu_len;
|
||||
@@ -842,8 +838,7 @@ int main(
|
||||
/* forever task */
|
||||
for (;;) {
|
||||
#if (defined(MSTP_TEST_REQUEST) && MSTP_TEST_REQUEST)
|
||||
MSTP_Create_And_Send_Frame(&MSTP_Port,
|
||||
FRAME_TYPE_TEST_REQUEST,
|
||||
MSTP_Create_And_Send_Frame(&MSTP_Port, FRAME_TYPE_TEST_REQUEST,
|
||||
MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0);
|
||||
nanosleep(&timeOut, &remains);
|
||||
#endif
|
||||
|
||||
@@ -112,14 +112,14 @@ static int ethernet_bind(
|
||||
/* Attempt to open the socket for 802.2 ethernet frames */
|
||||
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0) {
|
||||
/* Error occured */
|
||||
fprintf(stderr,
|
||||
"ethernet: Error opening socket: %s\n", strerror(errno));
|
||||
fprintf(stderr, "ethernet: Error opening socket: %s\n",
|
||||
strerror(errno));
|
||||
fprintf(stderr,
|
||||
"You might need to add the following to modules.conf\n"
|
||||
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
||||
"alias net-pf-17 af_packet\n"
|
||||
"Also, add af_packet to /etc/modules.\n"
|
||||
"Then follow it by:\n" "# modprobe af_packet\n");
|
||||
"Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
|
||||
"# modprobe af_packet\n");
|
||||
exit(-1);
|
||||
}
|
||||
/* Bind the socket to an address */
|
||||
@@ -132,14 +132,14 @@ static int ethernet_bind(
|
||||
/* Attempt to bind the socket to the interface */
|
||||
if (bind(sock_fd, eth_addr, sizeof(struct sockaddr)) != 0) {
|
||||
/* Bind problem, close socket and return */
|
||||
fprintf(stderr,
|
||||
"ethernet: Unable to bind 802.2 socket : %s\n", strerror(errno));
|
||||
fprintf(stderr, "ethernet: Unable to bind 802.2 socket : %s\n",
|
||||
strerror(errno));
|
||||
fprintf(stderr,
|
||||
"You might need to add the following to modules.conf\n"
|
||||
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
||||
"alias net-pf-17 af_packet\n"
|
||||
"Also, add af_packet to /etc/modules.\n"
|
||||
"Then follow it by:\n" "# modprobe af_packet\n");
|
||||
"Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
|
||||
"# modprobe af_packet\n");
|
||||
/* Close the socket */
|
||||
close(sock_fd);
|
||||
exit(-1);
|
||||
@@ -248,8 +248,8 @@ int ethernet_send_pdu(
|
||||
|
||||
/* Send the packet */
|
||||
bytes =
|
||||
sendto(eth802_sockfd, &mtu, mtu_len, 0,
|
||||
(struct sockaddr *) ð_addr, sizeof(struct sockaddr));
|
||||
sendto(eth802_sockfd, &mtu, mtu_len, 0, (struct sockaddr *) ð_addr,
|
||||
sizeof(struct sockaddr));
|
||||
/* did it get sent? */
|
||||
if (bytes < 0)
|
||||
fprintf(stderr, "ethernet: Error sending packet: %s\n",
|
||||
@@ -303,8 +303,7 @@ uint16_t ethernet_receive(
|
||||
/* using O_NONBLOCK and no data */
|
||||
/* was immediately available for reading. */
|
||||
if (errno != EAGAIN)
|
||||
fprintf(stderr,
|
||||
"ethernet: Read error in receiving packet: %s\n",
|
||||
fprintf(stderr, "ethernet: Read error in receiving packet: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -63,8 +63,9 @@ static void LocalIAmHandler(
|
||||
|
||||
(void) src;
|
||||
(void) service_len;
|
||||
len = iam_decode_service_request(service_request,
|
||||
&device_id, &max_apdu, &segmentation, &vendor_id);
|
||||
len =
|
||||
iam_decode_service_request(service_request, &device_id, &max_apdu,
|
||||
&segmentation, &vendor_id);
|
||||
fprintf(stderr, "Received I-Am Request");
|
||||
if (len != -1) {
|
||||
fprintf(stderr, " from %u!\n", device_id);
|
||||
@@ -138,8 +139,8 @@ static void Read_Properties(
|
||||
got the reply with matching invoke ID or the TSM of the
|
||||
invoke ID expired. This demo is doing things asynchronously. */
|
||||
status = Send_Read_Property_Request(device_id, /* destination device */
|
||||
OBJECT_DEVICE,
|
||||
device_id, object_props[property], BACNET_ARRAY_ALL);
|
||||
OBJECT_DEVICE, device_id, object_props[property],
|
||||
BACNET_ARRAY_ALL);
|
||||
if (status)
|
||||
property++;
|
||||
}
|
||||
|
||||
@@ -160,20 +160,16 @@ static void print_received_packet(
|
||||
/* Data CRC: (present only if Length is non-zero) two octets, */
|
||||
/* least significant octet first */
|
||||
/* (pad): (optional) at most one octet of padding: X'FF' */
|
||||
fprintf(stderr,
|
||||
"55 FF %02X %02X %02X %02X %02X %02X ",
|
||||
mstp_port->FrameType,
|
||||
mstp_port->DestinationAddress,
|
||||
mstp_port->SourceAddress,
|
||||
HI_BYTE(mstp_port->DataLength),
|
||||
fprintf(stderr, "55 FF %02X %02X %02X %02X %02X %02X ",
|
||||
mstp_port->FrameType, mstp_port->DestinationAddress,
|
||||
mstp_port->SourceAddress, HI_BYTE(mstp_port->DataLength),
|
||||
LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual);
|
||||
if (mstp_port->DataLength) {
|
||||
for (i = 0; i < mstp_port->DataLength; i++) {
|
||||
fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]);
|
||||
}
|
||||
fprintf(stderr,
|
||||
"%02X %02X ",
|
||||
mstp_port->DataCRCActualMSB, mstp_port->DataCRCActualLSB);
|
||||
fprintf(stderr, "%02X %02X ", mstp_port->DataCRCActualMSB,
|
||||
mstp_port->DataCRCActualLSB);
|
||||
}
|
||||
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
Reference in New Issue
Block a user