indented.

This commit is contained in:
skarg
2007-11-29 16:39:48 +00:00
parent 06d23fcf1f
commit 1477603af6
123 changed files with 1994 additions and 1688 deletions
+8 -7
View File
@@ -122,11 +122,12 @@ int Analog_Input_Encode_Property_APDU(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0],
OBJECT_ANALOG_INPUT);
apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break;
case PROP_PRESENT_VALUE:
apdu_len = encode_application_real(&apdu[0],
apdu_len =
encode_application_real(&apdu[0],
Analog_Input_Present_Value(object_instance));
break;
case PROP_STATUS_FLAGS:
@@ -177,14 +178,14 @@ void testAnalogInput(
/* FIXME: we should do a lot more testing here... */
len = Analog_Input_Encode_Property_APDU(&apdu[0],
instance,
len =
Analog_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -296,7 +296,8 @@ bool Analog_Value_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -400,14 +401,14 @@ void testAnalog_Value(
BACNET_ERROR_CODE error_code;
len = Analog_Value_Encode_Property_APDU(&apdu[0],
instance,
len =
Analog_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
ct_test(pTest, decoded_instance == instance);
+4 -4
View File
@@ -211,14 +211,14 @@ void testBinaryInput(
/* FIXME: we should do a lot more testing here... */
len = Binary_Input_Encode_Property_APDU(&apdu[0],
instance,
len =
Binary_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -207,7 +207,8 @@ bool Binary_Value_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -315,14 +316,14 @@ void testBinary_Value(
BACNET_ERROR_CODE error_code;
len = Binary_Value_Encode_Property_APDU(&apdu[0],
instance,
len =
Binary_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE);
ct_test(pTest, decoded_instance == instance);
+10 -6
View File
@@ -277,7 +277,8 @@ int Device_Encode_Property_APDU(
/* FIXME: change the hardcoded names to suit your application */
switch (property) {
case PROP_OBJECT_IDENTIFIER:
apdu_len = encode_application_object_id(&apdu[0], OBJECT_DEVICE,
apdu_len =
encode_application_object_id(&apdu[0], OBJECT_DEVICE,
Object_Instance_Number);
break;
case PROP_OBJECT_NAME:
@@ -416,11 +417,13 @@ int Device_Encode_Property_APDU(
}
break;
case PROP_MAX_APDU_LENGTH_ACCEPTED:
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
Device_Max_APDU_Length_Accepted());
break;
case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0],
apdu_len =
encode_application_enumerated(&apdu[0],
Device_Segmentation_Supported());
break;
case PROP_APDU_TIMEOUT:
@@ -502,7 +505,8 @@ bool Device_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -510,8 +514,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.
Object_Id.instance))) {
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
/* we could send an I-Am broadcast to let the world know */
status = true;
} else {
+29 -32
View File
@@ -303,8 +303,9 @@ static 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;
}
@@ -321,8 +322,8 @@ static bool dlmstp_compare_data_expecting_reply(
/* decode the reply data */
reply.address.mac[0] = dest_address;
reply.address.mac_len = 1;
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;
}
@@ -788,9 +789,7 @@ static bool MSTP_Master_Node_FSM(
} else {
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
}
MSTP_Send_Frame(frame_type,
TransmitPacketDest,
This_Station,
MSTP_Send_Frame(frame_type, TransmitPacketDest, This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false;
FrameCount++;
@@ -904,8 +903,8 @@ static bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */
TokenCount++;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
EventCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -927,8 +926,8 @@ static bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */
Poll_Station = This_Station;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
TokenCount = 1; /* changed in Errata SSPC-135-2004 */
EventCount = 0;
@@ -937,8 +936,8 @@ static bool MSTP_Master_Node_FSM(
} else {
/* SendMaintenancePFM */
Poll_Station = next_poll_station;
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -959,8 +958,8 @@ static bool MSTP_Master_Node_FSM(
/* RetrySendToken */
RetryCount++;
/* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
EventCount = 0;
/* re-enter the current state to listen for NS */
/* to begin using the token. */
@@ -969,8 +968,8 @@ static bool MSTP_Master_Node_FSM(
/* Assume that NS has failed. */
Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
/* no known successor node */
Next_Station = This_Station;
RetryCount = 0;
@@ -1003,8 +1002,8 @@ static bool MSTP_Master_Node_FSM(
/* on the network and is empowered to create a token. */
Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
/* indicate that the next station is unknown */
Next_Station = This_Station;
RetryCount = 0;
@@ -1027,8 +1026,8 @@ static bool MSTP_Master_Node_FSM(
Next_Station = SourceAddress;
EventCount = 0;
/* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
Poll_Station = This_Station;
TokenCount = 0;
RetryCount = 0;
@@ -1060,8 +1059,8 @@ static bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */
EventCount = 0;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
} else {
@@ -1092,10 +1091,10 @@ static bool MSTP_Master_Node_FSM(
case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST:
/* Note: we could wait for up to Treply_delay */
if (MSTP_Flag.TransmitPacketPending) {
matched = dlmstp_compare_data_expecting_reply(&InputBuffer[0],
DataLength,
SourceAddress,
&TransmitPacket[0], TransmitPacketLen, TransmitPacketDest);
matched =
dlmstp_compare_data_expecting_reply(&InputBuffer[0],
DataLength, SourceAddress, &TransmitPacket[0],
TransmitPacketLen, TransmitPacketDest);
}
if (MSTP_Flag.TransmitPacketPending && matched) {
/* Reply */
@@ -1111,9 +1110,7 @@ static bool MSTP_Master_Node_FSM(
} else {
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
}
MSTP_Send_Frame(frame_type,
TransmitPacketDest,
This_Station,
MSTP_Send_Frame(frame_type, TransmitPacketDest, This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false;
Master_State = MSTP_MASTER_STATE_IDLE;
@@ -1127,8 +1124,8 @@ static bool MSTP_Master_Node_FSM(
/* Any reply shall wait until this node receives the token. */
/* Call MSTP_Send_Frame to transmit a Reply Postponed frame, */
/* and enter the IDLE state. */
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED,
SourceAddress, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED, SourceAddress,
This_Station, NULL, 0);
Master_State = MSTP_MASTER_STATE_IDLE;
}
/* clear our flag we were holding for comparison */
+41 -30
View File
@@ -65,36 +65,41 @@ int Encode_Property_APDU(
switch (object_type) {
case OBJECT_DEVICE:
if (Device_Valid_Object_Instance_Number(object_instance)) {
apdu_len = Device_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code);
apdu_len =
Device_Encode_Property_APDU(&apdu[0], property,
array_index, error_class, error_code);
}
break;
case OBJECT_ANALOG_INPUT:
if (Analog_Input_Valid_Instance(object_instance)) {
apdu_len = Analog_Input_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Analog_Input_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(object_instance)) {
apdu_len = Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_BINARY_INPUT:
if (Binary_Input_Valid_Instance(object_instance)) {
apdu_len = Binary_Input_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Binary_Input_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_BINARY_VALUE:
if (Binary_Value_Valid_Instance(object_instance)) {
apdu_len = Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
default:
@@ -125,28 +130,31 @@ void handler_read_property(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
goto RP_ABORT;
}
len = rp_decode_service_request(service_request, service_len, &data);
if (len < 0) {
/* bad decoding - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
goto RP_ABORT;
}
/* most cases will be error */
error = true;
len = Encode_Property_APDU(&Temp_Buf[0],
data.object_type,
data.object_instance,
data.object_property, data.array_index, &error_class, &error_code);
len =
Encode_Property_APDU(&Temp_Buf[0], data.object_type,
data.object_instance, data.object_property, data.array_index,
&error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0];
@@ -160,19 +168,22 @@ void handler_read_property(
if (error) {
if (len == -2) {
/* BACnet APDU too small to fit data, so proper response is Abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RP_ABORT;
}
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
}
RP_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return;
}
+18 -14
View File
@@ -63,19 +63,22 @@ void handler_write_property(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
goto WP_ABORT;
}
/* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data);
/* bad decoding or something we didn't understand - send an abort */
if (len <= 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
goto WP_ABORT;
}
@@ -89,8 +92,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
}
break;
case OBJECT_ANALOG_INPUT:
@@ -111,8 +114,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
}
break;
case OBJECT_ANALOG_VALUE:
@@ -124,8 +127,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
}
break;
default:
@@ -137,8 +140,9 @@ void handler_write_property(
}
WP_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return;
}
+3 -2
View File
@@ -77,8 +77,9 @@ void LowLevelInit(
//
// OUT = 0 (not used)
// result: AT91C_CKGR_PLLR = 0x00000000480A0E (PLL Register)
pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 14) |
(AT91C_CKGR_PLLCOUNT & (10 << 8)) | (AT91C_CKGR_MUL & (72 << 16)));
pPMC->PMC_PLLR =
((AT91C_CKGR_DIV & 14) | (AT91C_CKGR_PLLCOUNT & (10 << 8)) |
(AT91C_CKGR_MUL & (72 << 16)));
// Wait the startup time (until PMC Status register LOCK bit is set)
while (!(pPMC->PMC_SR & AT91C_PMC_LOCK));
+1 -2
View File
@@ -155,8 +155,7 @@ static void bacnet_init(
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_property);
/* handle communication so we can shutup when asked */
apdu_set_confirmed_handler
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control);
#endif
}
+4 -4
View File
@@ -122,13 +122,13 @@ int Analog_Input_Encode_Property_APDU(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0],
OBJECT_ANALOG_INPUT);
apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break;
case PROP_PRESENT_VALUE:
object_index = Analog_Input_Instance_To_Index(object_instance);
apdu_len = encode_application_real(&apdu[0],
Present_Value[object_index]);
apdu_len =
encode_application_real(&apdu[0], Present_Value[object_index]);
break;
case PROP_STATUS_FLAGS:
bitstring_init(&bit_string);
+4 -5
View File
@@ -103,12 +103,11 @@ void apdu_handler(
switch (apdu[0] & 0xF0) {
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */
apdu_len,
&service_data,
&service_choice, &service_request, &service_request_len);
apdu_len, &service_data, &service_choice, &service_request,
&service_request_len);
if (service_choice == SERVICE_CONFIRMED_READ_PROPERTY) {
handler_read_property(service_request,
service_request_len, src, &service_data);
handler_read_property(service_request, service_request_len,
src, &service_data);
}
#if 0
else if (service_choice == SERVICE_CONFIRMED_WRITE_PROPERTY) {
+6 -5
View File
@@ -175,7 +175,8 @@ bool Analog_Value_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -219,14 +220,14 @@ void testAnalog_Value(
BACNET_ERROR_CODE error_code;
len = Analog_Value_Encode_Property_APDU(&apdu[0],
instance,
len =
Analog_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
ct_test(pTest, decoded_instance == instance);
+8 -6
View File
@@ -217,7 +217,8 @@ int Device_Encode_Property_APDU(
/* FIXME: change the hardcoded names to suit your application */
switch (property) {
case PROP_OBJECT_IDENTIFIER:
apdu_len = encode_application_object_id(&apdu[0], OBJECT_DEVICE,
apdu_len =
encode_application_object_id(&apdu[0], OBJECT_DEVICE,
Object_Instance_Number);
break;
case PROP_OBJECT_NAME:
@@ -342,8 +343,8 @@ int Device_Encode_Property_APDU(
apdu_len = encode_application_unsigned(&apdu[0], MAX_APDU);
break;
case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0],
SEGMENTATION_NONE);
apdu_len =
encode_application_enumerated(&apdu[0], SEGMENTATION_NONE);
break;
case PROP_APDU_TIMEOUT:
apdu_len = encode_application_unsigned(&apdu[0], 60000);
@@ -396,7 +397,8 @@ bool Device_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -404,8 +406,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.
Object_Id.instance))) {
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
/* we could send an I-Am broadcast to let the world know */
status = true;
} else {
+20 -22
View File
@@ -697,8 +697,7 @@ static bool MSTP_Master_Node_FSM(
TransmitPacketLen = dlmstp_encode_unconfirmed_frame();
if (TransmitPacketLen) {
MSTP_Send_Frame(FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY,
MSTP_BROADCAST_ADDRESS,
This_Station,
MSTP_BROADCAST_ADDRESS, This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen);
FrameCount++;
} else {
@@ -798,8 +797,8 @@ static bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */
TokenCount++;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
EventCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -821,8 +820,8 @@ static bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */
Poll_Station = This_Station;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
TokenCount = 1; /* changed in Errata SSPC-135-2004 */
EventCount = 0;
@@ -831,8 +830,8 @@ static bool MSTP_Master_Node_FSM(
} else {
/* SendMaintenancePFM */
Poll_Station = next_poll_station;
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -853,8 +852,8 @@ static bool MSTP_Master_Node_FSM(
/* RetrySendToken */
RetryCount++;
/* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
EventCount = 0;
/* re-enter the current state to listen for NS */
/* to begin using the token. */
@@ -863,8 +862,8 @@ static bool MSTP_Master_Node_FSM(
/* Assume that NS has failed. */
Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
/* no known successor node */
Next_Station = This_Station;
RetryCount = 0;
@@ -897,8 +896,8 @@ static bool MSTP_Master_Node_FSM(
/* on the network and is empowered to create a token. */
Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
/* indicate that the next station is unknown */
Next_Station = This_Station;
RetryCount = 0;
@@ -921,8 +920,8 @@ static bool MSTP_Master_Node_FSM(
Next_Station = SourceAddress;
EventCount = 0;
/* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
Poll_Station = This_Station;
TokenCount = 0;
RetryCount = 0;
@@ -954,8 +953,8 @@ static bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */
EventCount = 0;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
} else {
@@ -996,8 +995,7 @@ static bool MSTP_Master_Node_FSM(
/* and enter the IDLE state to wait for the next frame. */
/* Note: optimized such that we are never a client */
MSTP_Send_Frame(FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY,
TransmitPacketDest,
This_Station,
TransmitPacketDest, This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false;
Master_State = MSTP_MASTER_STATE_IDLE;
@@ -1011,8 +1009,8 @@ static bool MSTP_Master_Node_FSM(
/* Any reply shall wait until this node receives the token. */
/* Call MSTP_Send_Frame to transmit a Reply Postponed frame, */
/* and enter the IDLE state. */
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED,
SourceAddress, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED, SourceAddress,
This_Station, NULL, 0);
Master_State = MSTP_MASTER_STATE_IDLE;
}
/* clear our flag we were holding for comparison */
+29 -21
View File
@@ -67,15 +67,17 @@ int Encode_Property_APDU(
switch (object_type) {
case OBJECT_DEVICE:
if (Device_Valid_Object_Instance_Number(object_instance)) {
apdu_len = Device_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code);
apdu_len =
Device_Encode_Property_APDU(&apdu[0], property,
array_index, error_class, error_code);
}
break;
case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(object_instance)) {
apdu_len = Analog_Value_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Analog_Value_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
default:
@@ -107,24 +109,27 @@ void handler_read_property(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (len < 0) {
/* bad decoding - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
} else if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
} else {
/* most cases will be error */
error = true;
len = Encode_Property_APDU(&Temp_Buf[0],
data.object_type,
data.object_instance,
data.object_property, data.array_index, &error_class, &error_code);
len =
Encode_Property_APDU(&Temp_Buf[0], data.object_type,
data.object_instance, data.object_property, data.array_index,
&error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0];
@@ -140,21 +145,24 @@ void handler_read_property(
switch (len) {
/* BACnet APDU too small to fit data, so proper response is Abort */
case -2:
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
break;
case -1:
default:
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
break;
}
}
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return;
}
+3 -2
View File
@@ -50,8 +50,9 @@ void handler_who_is(
int32_t target_device;
(void) src;
len = whois_decode_service_request(service_request,
service_len, &low_limit, &high_limit);
len =
whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
if (len == 0) {
Send_I_Am = true;
} else if (len != -1) {
+12 -8
View File
@@ -67,16 +67,19 @@ void handler_write_property(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
/* bad decoding or something we didn't understand - send an abort */
if (len <= 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
} else if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
} else {
switch (wp_data.object_type) {
#if 0
@@ -143,8 +146,9 @@ void handler_write_property(
}
}
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return;
}
+9 -10
View File
@@ -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;
}
+10 -8
View File
@@ -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);
+22 -27
View File
@@ -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
+11 -12
View File
@@ -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 *) &eth_addr, sizeof(struct sockaddr));
sendto(eth802_sockfd, &mtu, mtu_len, 0, (struct sockaddr *) &eth_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;
}
+5 -4
View File
@@ -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++;
}
+5 -9
View File
@@ -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");
+8 -7
View File
@@ -119,11 +119,12 @@ int Analog_Input_Encode_Property_APDU(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0],
OBJECT_ANALOG_INPUT);
apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break;
case PROP_PRESENT_VALUE:
apdu_len = encode_application_real(&apdu[0],
apdu_len =
encode_application_real(&apdu[0],
Analog_Input_Present_Value(object_instance));
break;
case PROP_STATUS_FLAGS:
@@ -174,14 +175,14 @@ void testAnalogInput(
/* FIXME: we should do a lot more testing here... */
len = Analog_Input_Encode_Property_APDU(&apdu[0],
instance,
len =
Analog_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -293,7 +293,8 @@ bool Analog_Value_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -397,14 +398,14 @@ void testAnalog_Value(
BACNET_ERROR_CODE error_code;
len = Analog_Value_Encode_Property_APDU(&apdu[0],
instance,
len =
Analog_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
ct_test(pTest, decoded_instance == instance);
+4 -4
View File
@@ -208,14 +208,14 @@ void testBinaryInput(
/* FIXME: we should do a lot more testing here... */
len = Binary_Input_Encode_Property_APDU(&apdu[0],
instance,
len =
Binary_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -208,7 +208,8 @@ bool Binary_Value_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -316,14 +317,14 @@ void testBinary_Value(
BACNET_ERROR_CODE error_code;
len = Binary_Value_Encode_Property_APDU(&apdu[0],
instance,
len =
Binary_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE);
ct_test(pTest, decoded_instance == instance);
+10 -6
View File
@@ -284,7 +284,8 @@ int Device_Encode_Property_APDU(
/* FIXME: change the hardcoded names to suit your application */
switch (property) {
case PROP_OBJECT_IDENTIFIER:
apdu_len = encode_application_object_id(&apdu[0], OBJECT_DEVICE,
apdu_len =
encode_application_object_id(&apdu[0], OBJECT_DEVICE,
Object_Instance_Number);
break;
case PROP_OBJECT_NAME:
@@ -428,11 +429,13 @@ int Device_Encode_Property_APDU(
}
break;
case PROP_MAX_APDU_LENGTH_ACCEPTED:
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
Device_Max_APDU_Length_Accepted());
break;
case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0],
apdu_len =
encode_application_enumerated(&apdu[0],
Device_Segmentation_Supported());
break;
case PROP_APDU_TIMEOUT:
@@ -514,7 +517,8 @@ bool Device_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -522,8 +526,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.
Object_Id.instance))) {
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
/* we could send an I-Am broadcast to let the world know */
status = true;
} else {
+6 -7
View File
@@ -139,11 +139,10 @@ int dlmstp_send_pdu(
if ((8 /* header len */ + pdu_len) > MAX_MPDU) {
return -4;
}
bytes_sent = MSTP_Create_Frame(
(uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType,
destination, MSTP_Port.This_Station, pdu, pdu_len);
bytes_sent =
MSTP_Create_Frame((uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), MSTP_Port.TxFrameType, destination,
MSTP_Port.This_Station, pdu, pdu_len);
MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true;
MSTP_Packets++;
@@ -180,8 +179,8 @@ void dlmstp_task(
if (Receive_Buffer.ready && !MSTP_Port.TxReady) {
if (Receive_Buffer.pdu_len) {
MSTP_Packets++;
npdu_handler(&Receive_Buffer.address,
&Receive_Buffer.pdu[0], Receive_Buffer.pdu_len);
npdu_handler(&Receive_Buffer.address, &Receive_Buffer.pdu[0],
Receive_Buffer.pdu_len);
}
Receive_Buffer.ready = false;
}
+44 -37
View File
@@ -66,19 +66,22 @@ void handler_read_property(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
goto RP_ABORT;
}
len = rp_decode_service_request(service_request, service_len, &data);
if (len < 0) {
/* bad decoding - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
goto RP_ABORT;
}
@@ -88,26 +91,27 @@ void handler_read_property(
case OBJECT_DEVICE:
/* FIXME: probably need a length limitation sent with encode */
if (Device_Valid_Object_Instance_Number(data.object_instance)) {
len = Device_Encode_Property_APDU(&Temp_Buf[0],
data.object_property,
data.array_index, &error_class, &error_code);
len =
Device_Encode_Property_APDU(&Temp_Buf[0],
data.object_property, data.array_index, &error_class,
&error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0];
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
break;
case OBJECT_ANALOG_INPUT:
if (Analog_Input_Valid_Instance(data.object_instance)) {
len = Analog_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
len =
Analog_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance, data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
@@ -115,17 +119,17 @@ void handler_read_property(
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
break;
case OBJECT_BINARY_INPUT:
if (Binary_Input_Valid_Instance(data.object_instance)) {
len = Binary_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
len =
Binary_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance, data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
@@ -133,17 +137,17 @@ void handler_read_property(
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
break;
case OBJECT_BINARY_VALUE:
if (Binary_Value_Valid_Instance(data.object_instance)) {
len = Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
len =
Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance, data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
@@ -151,17 +155,17 @@ void handler_read_property(
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
break;
case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(data.object_instance)) {
len = Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
len =
Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance, data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
@@ -169,8 +173,8 @@ void handler_read_property(
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
@@ -181,19 +185,22 @@ void handler_read_property(
if (error) {
if (len == -2) {
/* BACnet APDU too small to fit data, so proper response is Abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RP_ABORT;
}
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
}
RP_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return;
}
+18 -14
View File
@@ -62,19 +62,22 @@ void handler_write_property(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
goto WP_ABORT;
}
/* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data);
/* bad decoding or something we didn't understand - send an abort */
if (len <= 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
goto WP_ABORT;
}
@@ -91,8 +94,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Property Error for Device!\n");
#endif
@@ -122,8 +125,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for BV!\n");
#endif
@@ -141,8 +144,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for AV!\n");
#endif
@@ -160,8 +163,9 @@ void handler_write_property(
}
WP_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+3 -4
View File
@@ -106,14 +106,13 @@ static void BACnet_Service_Handlers_Init(
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_property);
#if 0
apdu_set_unconfirmed_handler
(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
handler_timesync);
#endif
/* handle communication so we can shutup when asked */
apdu_set_confirmed_handler
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control);
}
+36 -49
View File
@@ -506,7 +506,8 @@ void MSTP_Receive_Frame_FSM(
#endif
/* DataOctet */
if (mstp_port->Index < mstp_port->DataLength) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
mstp_port->InputBuffer[mstp_port->Index] =
mstp_port->DataRegister;
@@ -515,14 +516,16 @@ void MSTP_Receive_Frame_FSM(
}
/* CRC1 */
else if (mstp_port->Index == mstp_port->DataLength) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
mstp_port->Index++;
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;
}
/* CRC2 */
else if (mstp_port->Index == (mstp_port->DataLength + 1)) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
/* STATE DATA CRC - no need for new state */
/* indicate the complete reception of a valid frame */
@@ -570,26 +573,21 @@ bool MSTP_Master_Node_FSM(
#endif
/* some calculations that several states need */
next_poll_station = (mstp_port->Poll_Station + 1) %
(mstp_port->Nmax_master + 1);
next_this_station = (mstp_port->This_Station + 1) %
(mstp_port->Nmax_master + 1);
next_next_station = (mstp_port->Next_Station + 1) %
(mstp_port->Nmax_master + 1);
next_poll_station =
(mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1);
next_this_station =
(mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1);
next_next_station =
(mstp_port->Next_Station + 1) % (mstp_port->Nmax_master + 1);
#if PRINT_ENABLED_MASTER
if (mstp_port->master_state != master_state) {
master_state = mstp_port->master_state;
fprintf(stderr,
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n",
mstp_port->This_Station,
next_this_station,
mstp_port->Next_Station,
next_next_station,
mstp_port->Poll_Station,
next_poll_station,
mstp_port->EventCount,
mstp_port->TokenCount,
mstp_port->SilenceTimer,
mstp_port->This_Station, next_this_station,
mstp_port->Next_Station, next_next_station,
mstp_port->Poll_Station, next_poll_station, mstp_port->EventCount,
mstp_port->TokenCount, mstp_port->SilenceTimer,
mstptext_master_state(mstp_port->master_state));
}
#endif
@@ -625,17 +623,14 @@ bool MSTP_Master_Node_FSM(
#if PRINT_ENABLED_MASTER
fprintf(stderr,
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n",
mstp_port->SourceAddress,
mstp_port->DestinationAddress,
mstp_port->DataLength,
mstp_port->FrameCount,
mstp_port->SourceAddress, mstp_port->DestinationAddress,
mstp_port->DataLength, mstp_port->FrameCount,
mstp_port->SilenceTimer,
mstptext_frame_type(mstp_port->FrameType));
#endif
/* destined for me! */
if ((mstp_port->DestinationAddress ==
mstp_port->This_Station) ||
(mstp_port->DestinationAddress ==
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|| (mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
switch (mstp_port->FrameType) {
/* ReceivedToken */
@@ -827,10 +822,9 @@ bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */
mstp_port->TokenCount++;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station,
mstp_port->This_Station, NULL, 0);
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->RetryCount = 0;
mstp_port->EventCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -854,10 +848,9 @@ bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */
mstp_port->Poll_Station = mstp_port->This_Station;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station,
mstp_port->This_Station, NULL, 0);
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->RetryCount = 0;
mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */
mstp_port->EventCount = 0;
@@ -867,8 +860,8 @@ bool MSTP_Master_Node_FSM(
/* SendMaintenancePFM */
mstp_port->Poll_Station = next_poll_station;
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -889,8 +882,7 @@ bool MSTP_Master_Node_FSM(
/* RetrySendToken */
mstp_port->RetryCount++;
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->EventCount = 0;
@@ -902,9 +894,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
/* no known successor node */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
@@ -940,9 +931,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
/* indicate that the next station is unknown */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
@@ -967,8 +957,7 @@ bool MSTP_Master_Node_FSM(
mstp_port->Next_Station = mstp_port->SourceAddress;
mstp_port->EventCount = 0;
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->Poll_Station = mstp_port->This_Station;
@@ -1002,8 +991,7 @@ bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */
mstp_port->EventCount = 0;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station,
NULL, 0);
mstp_port->RetryCount = 0;
@@ -1073,8 +1061,7 @@ bool MSTP_Master_Node_FSM(
/* and enter the IDLE state. */
{
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_REPLY_POSTPONED,
mstp_port->SourceAddress,
FRAME_TYPE_REPLY_POSTPONED, mstp_port->SourceAddress,
mstp_port->This_Station, NULL, 0);
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
}
+4 -4
View File
@@ -174,8 +174,8 @@ static void NetInitialize(
}
#else
/* Set the IP address and interface */
printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0],
TargetIP[1], TargetIP[2], TargetIP[3]);
printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0], TargetIP[1],
TargetIP[2], TargetIP[3]);
Result = xn_set_ip(interface, TargetIP, NetMask);
/* define default gateway and DNS server */
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF);
@@ -271,8 +271,8 @@ bool bip_init(
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', 8);
rv = bind(sock_fd,
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
rv = bind(sock_fd, (const struct sockaddr *) &sin,
sizeof(struct sockaddr));
if (rv < 0) {
close(sock_fd);
bip_set_socket(-1);
+4 -5
View File
@@ -98,11 +98,10 @@ int dlmstp_send_pdu(
}
memmove(&PDU_Buffer[mtu_len], pdu, pdu_len);
mtu_len += pdu_len;
bytes_sent = MSTP_Create_Frame(
(uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType,
destination, MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
bytes_sent =
MSTP_Create_Frame((uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), MSTP_Port.TxFrameType, destination,
MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true;
}
+3 -4
View File
@@ -78,8 +78,8 @@ bool ethernet_init(
fprintf(stderr, "ethernet: failed to bind to socket!\r\n");
Ethernet_Address.sa_family = AF_INET;
memset(Ethernet_Address.sa_data, 0, sizeof(Ethernet_Address.sa_data));
if (bind(Ethernet_Socket,
&Ethernet_Address, sizeof(Ethernet_Address)) == SOCKET_ERROR)
if (bind(Ethernet_Socket, &Ethernet_Address,
sizeof(Ethernet_Address)) == SOCKET_ERROR)
fprintf(stderr, "ethernet: failed to bind to socket!\r\n");
/*setsockopt(Ethernet_Socket,SOL_SOCKET,SO_802_2,(char *)&value,sizeof(value)); */
@@ -227,8 +227,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;
}
+36 -49
View File
@@ -560,7 +560,8 @@ void MSTP_Receive_Frame_FSM(
#endif
/* DataOctet */
if (mstp_port->Index < mstp_port->DataLength) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
mstp_port->InputBuffer[mstp_port->Index] =
mstp_port->DataRegister;
@@ -569,14 +570,16 @@ void MSTP_Receive_Frame_FSM(
}
/* CRC1 */
else if (mstp_port->Index == mstp_port->DataLength) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
mstp_port->Index++;
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;
}
/* CRC2 */
else if (mstp_port->Index == (mstp_port->DataLength + 1)) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
/* STATE DATA CRC - no need for new state */
/* indicate the complete reception of a valid frame */
@@ -708,26 +711,21 @@ bool MSTP_Master_Node_FSM(
#endif
/* some calculations that several states need */
next_poll_station = (mstp_port->Poll_Station + 1) %
(mstp_port->Nmax_master + 1);
next_this_station = (mstp_port->This_Station + 1) %
(mstp_port->Nmax_master + 1);
next_next_station = (mstp_port->Next_Station + 1) %
(mstp_port->Nmax_master + 1);
next_poll_station =
(mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1);
next_this_station =
(mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1);
next_next_station =
(mstp_port->Next_Station + 1) % (mstp_port->Nmax_master + 1);
#if PRINT_ENABLED_MASTER
if (mstp_port->master_state != master_state) {
master_state = mstp_port->master_state;
fprintf(stderr,
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n",
mstp_port->This_Station,
next_this_station,
mstp_port->Next_Station,
next_next_station,
mstp_port->Poll_Station,
next_poll_station,
mstp_port->EventCount,
mstp_port->TokenCount,
mstp_port->SilenceTimer,
mstp_port->This_Station, next_this_station,
mstp_port->Next_Station, next_next_station,
mstp_port->Poll_Station, next_poll_station, mstp_port->EventCount,
mstp_port->TokenCount, mstp_port->SilenceTimer,
mstp_master_state_text(mstp_port->master_state));
}
#endif
@@ -763,17 +761,14 @@ bool MSTP_Master_Node_FSM(
#if PRINT_ENABLED_MASTER
fprintf(stderr,
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n",
mstp_port->SourceAddress,
mstp_port->DestinationAddress,
mstp_port->DataLength,
mstp_port->FrameCount,
mstp_port->SourceAddress, mstp_port->DestinationAddress,
mstp_port->DataLength, mstp_port->FrameCount,
mstp_port->SilenceTimer,
mstp_frame_type_text(mstp_port->FrameType));
#endif
/* destined for me! */
if ((mstp_port->DestinationAddress ==
mstp_port->This_Station) ||
(mstp_port->DestinationAddress ==
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|| (mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
switch (mstp_port->FrameType) {
/* ReceivedToken */
@@ -964,10 +959,9 @@ bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */
mstp_port->TokenCount++;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station,
mstp_port->This_Station, NULL, 0);
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->RetryCount = 0;
mstp_port->EventCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -991,10 +985,9 @@ bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */
mstp_port->Poll_Station = mstp_port->This_Station;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station,
mstp_port->This_Station, NULL, 0);
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->RetryCount = 0;
mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */
mstp_port->EventCount = 0;
@@ -1004,8 +997,8 @@ bool MSTP_Master_Node_FSM(
/* SendMaintenancePFM */
mstp_port->Poll_Station = next_poll_station;
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -1027,8 +1020,7 @@ bool MSTP_Master_Node_FSM(
/* RetrySendToken */
mstp_port->RetryCount++;
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->EventCount = 0;
@@ -1040,9 +1032,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
/* no known successor node */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
@@ -1079,9 +1070,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
/* indicate that the next station is unknown */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
@@ -1107,8 +1097,7 @@ bool MSTP_Master_Node_FSM(
mstp_port->Next_Station = mstp_port->SourceAddress;
mstp_port->EventCount = 0;
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->Poll_Station = mstp_port->This_Station;
@@ -1141,8 +1130,7 @@ bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */
mstp_port->EventCount = 0;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station,
NULL, 0);
mstp_port->RetryCount = 0;
@@ -1214,8 +1202,7 @@ bool MSTP_Master_Node_FSM(
/* and enter the IDLE state. */
{
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_REPLY_POSTPONED,
mstp_port->SourceAddress,
FRAME_TYPE_REPLY_POSTPONED, mstp_port->SourceAddress,
mstp_port->This_Station, NULL, 0);
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
transition_now = true;
+15 -16
View File
@@ -214,8 +214,7 @@ static char *winsock_error_code_text(
case WSAEDISCON:
return "Disconnect.";
case WSAHOST_NOT_FOUND:
return "Host not found. "
"This message indicates that the key "
return "Host not found. " "This message indicates that the key "
"(name, address, and so on) was not found.";
case WSATRY_AGAIN:
return "Nonauthoritative host not found. "
@@ -251,8 +250,8 @@ bool bip_init(
/*Result = WSAStartup(MAKEWORD(2,2), &wd); */
if (Result != 0) {
Code = WSAGetLastError();
printf("TCP/IP stack initialization failed\n"
" error code: %i %s\n", Code, winsock_error_code_text(Code));
printf("TCP/IP stack initialization failed\n" " error code: %i %s\n",
Code, winsock_error_code_text(Code));
exit(1);
}
atexit(cleanup);
@@ -265,8 +264,8 @@ bool bip_init(
address.s_addr = gethostaddr();
if (address.s_addr == (unsigned) -1) {
Code = WSAGetLastError();
printf("Get host address failed\n"
" error code: %i %s\n", Code, winsock_error_code_text(Code));
printf("Get host address failed\n" " error code: %i %s\n", Code,
winsock_error_code_text(Code));
exit(1);
}
bip_set_addr(address.s_addr);
@@ -282,8 +281,8 @@ bool bip_init(
broadcast_address.s_addr = htonl(bip_get_broadcast_addr());
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());
}
/* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@@ -294,8 +293,8 @@ 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 */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set REUSEADDR socket option.\n");
close(sock_fd);
@@ -303,8 +302,8 @@ bool bip_init(
return false;
}
/* allow us to send a broadcast */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set BROADCAST socket option.\n");
close(sock_fd);
@@ -315,8 +314,8 @@ bool bip_init(
/* probably only for Apple... */
/* rebind a port that is already in use.
Note: all users of the port must specify this flag */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set REUSEPORT socket option.\n");
close(sock_fd);
@@ -347,8 +346,8 @@ bool bip_init(
#endif
sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
rv = bind(sock_fd,
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
rv = bind(sock_fd, (const struct sockaddr *) &sin,
sizeof(struct sockaddr));
if (rv < 0) {
fprintf(stderr, "bip: failed to bind to %s port %hd\n",
inet_ntoa(sin.sin_addr), bip_get_port());
+20 -24
View File
@@ -144,13 +144,12 @@ uint16_t dlmstp_receive(
if (Receive_Packet.pdu_len) {
MSTP_Packets++;
if (src) {
memmove(src,
&Receive_Packet.address,
memmove(src, &Receive_Packet.address,
sizeof(Receive_Packet.address));
}
if (pdu) {
memmove(pdu,
&Receive_Packet.pdu, sizeof(Receive_Packet.pdu));
memmove(pdu, &Receive_Packet.pdu,
sizeof(Receive_Packet.pdu));
}
pdu_len = Receive_Packet.pdu_len;
}
@@ -301,11 +300,9 @@ 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,
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);
Transmit_Packet.ready = false;
return pdu_len;
@@ -336,8 +333,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;
}
@@ -353,8 +351,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;
}
@@ -443,19 +441,18 @@ 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)
return 0;
/* 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);
Transmit_Packet.ready = false;
return pdu_len;
@@ -721,8 +718,7 @@ int main(
for (;;) {
pdu_len = dlmstp_receive(NULL, NULL, 0, INFINITE);
#if 0
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);
#endif
}
+10 -12
View File
@@ -155,8 +155,8 @@ bool ethernet_init(
*/
/* Retrieve the device list */
if (pcap_findalldevs(&pcap_all_if, pcap_errbuf) == -1) {
sprintf(msgBuf,
"ethernet.c: error in pcap_findalldevs: %s\n", pcap_errbuf);
sprintf(msgBuf, "ethernet.c: error in pcap_findalldevs: %s\n",
pcap_errbuf);
LogError(msgBuf);
return false;
}
@@ -167,8 +167,8 @@ bool ethernet_init(
}
pcap_freealldevs(pcap_all_if); /* we don't need it anymore */
if (dev == NULL) {
sprintf(msgBuf,
"ethernet.c: specified interface not found: %s\n", if_name);
sprintf(msgBuf, "ethernet.c: specified interface not found: %s\n",
if_name);
LogError(msgBuf);
return false;
}
@@ -180,8 +180,8 @@ bool ethernet_init(
lpAdapter = PacketOpenAdapter(if_name);
if (lpAdapter == NULL) {
ethernet_cleanup();
sprintf(msgBuf,
"ethernet.c: error in PacketOpenAdapter(\"%s\")\n", if_name);
sprintf(msgBuf, "ethernet.c: error in PacketOpenAdapter(\"%s\")\n",
if_name);
LogError(msgBuf);
return false;
}
@@ -284,8 +284,7 @@ int ethernet_send(
if (pcap_sendpacket(pcap_eth802_fp, mtu, mtu_len) != 0) {
/* did it get sent? */
char msgBuf[200];
sprintf(msgBuf,
"ethernet.c: error sending packet: %s\n",
sprintf(msgBuf, "ethernet.c: error sending packet: %s\n",
pcap_geterr(pcap_eth802_fp));
LogError(msgBuf);
return -5;
@@ -342,8 +341,7 @@ uint16_t ethernet_receive(
res = pcap_next_ex(pcap_eth802_fp, &header, &pkt_data);
if (res < 0) {
char msgBuf[200];
sprintf(msgBuf,
"ethernet.c: error in receiving packet: %s\n",
sprintf(msgBuf, "ethernet.c: error in receiving packet: %s\n",
pcap_geterr(pcap_eth802_fp));
return 0;
} else if (res == 0)
@@ -445,8 +443,8 @@ void ethernet_debug_address(
}
/* if */
if (dest) {
sprintf(msgBuf,
"Address:\n MAC Length=%d\n MAC Address=", dest->mac_len);
sprintf(msgBuf, "Address:\n MAC Length=%d\n MAC Address=",
dest->mac_len);
LogInfo(msgBuf);
for (i = 0; i < MAX_MAC_LEN; i++) {
sprintf(msgBuf, "%02X ", (unsigned) dest->mac[i]);
+5 -4
View File
@@ -105,8 +105,8 @@ static void Read_Properties(
next_device = true;
else {
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++;
}
@@ -137,8 +137,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);
+3 -2
View File
@@ -190,8 +190,9 @@ static void RS485_Configure_Status(
void RS485_Initialize(
void)
{
RS485_Handle = CreateFile(RS485_Port_Name,
GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
RS485_Handle =
CreateFile(RS485_Port_Name, GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING,
/*FILE_FLAG_OVERLAPPED */ 0,
0);
if (RS485_Handle == INVALID_HANDLE_VALUE) {
+5 -9
View File
@@ -129,20 +129,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");