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
+1 -1
View File
@@ -1 +1 @@
-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl
+9 -13
View File
@@ -72,8 +72,7 @@ static void MyErrorHandler(
/* FIXME: verify src and invoke id */ /* FIXME: verify src and invoke id */
(void) src; (void) src;
(void) invoke_id; (void) invoke_id;
printf("BACnet Error: %s: %s\r\n", printf("BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class),
bactext_error_class_name(error_class),
bactext_error_code_name(error_code)); bactext_error_code_name(error_code));
Error_Detected = true; Error_Detected = true;
} }
@@ -129,8 +128,7 @@ static void Init_Service_Handlers(
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property); handler_read_property);
/* handle communication so we can shutup when asked */ /* handle communication so we can shutup when asked */
apdu_set_confirmed_handler apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control); handler_device_communication_control);
/* handle the ack coming back */ /* handle the ack coming back */
apdu_set_confirmed_simple_ack_handler apdu_set_confirmed_simple_ack_handler
@@ -162,11 +160,8 @@ int main(
/* note: priority 16 and 0 should produce the same end results... */ /* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s device-instance state timeout [password]\r\n" printf("Usage: %s device-instance state timeout [password]\r\n"
"Send BACnet DeviceCommunicationControl service to device.\r\n" "Send BACnet DeviceCommunicationControl service to device.\r\n"
"\r\n" "\r\n" "The device-instance can be 0 to %d.\r\n"
"The device-instance can be 0 to %d.\r\n" "Possible state values:\r\n" " 0=enable\r\n" " 1=disable\r\n"
"Possible state values:\r\n"
" 0=enable\r\n"
" 1=disable\r\n"
" 2=disable-initiation\r\n" " 2=disable-initiation\r\n"
"The timeout can be 0 for infinite, or a value in minutes for disable.\r\n" "The timeout can be 0 for infinite, or a value in minutes for disable.\r\n"
"The optional password is a character string of 1 to 20 characters.\r\n" "The optional password is a character string of 1 to 20 characters.\r\n"
@@ -196,8 +191,8 @@ int main(
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds =
Device_Number_Of_APDU_Retries(); (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
@@ -218,8 +213,9 @@ int main(
if (Error_Detected) if (Error_Detected)
break; break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found =
&max_apdu, &Target_Address); address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) { if (found) {
if (invoke_id == 0) { if (invoke_id == 0) {
invoke_id = invoke_id =
+10 -9
View File
@@ -79,8 +79,7 @@ static void MyErrorHandler(
(void) src; (void) src;
(void) invoke_id; (void) invoke_id;
#if 1 #if 1
printf("BACnet Error: %s: %s\r\n", printf("BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class),
bactext_error_class_name(error_class),
bactext_error_code_name(error_code)); bactext_error_code_name(error_code));
#else #else
(void) error_class; (void) error_class;
@@ -151,7 +150,8 @@ void PrintReadPropertyData(
application_data_len = data->application_data_len; application_data_len = data->application_data_len;
/* value? loop until all of the len is gone... */ /* value? loop until all of the len is gone... */
for (;;) { for (;;) {
len = bacapp_decode_application_data(application_data, len =
bacapp_decode_application_data(application_data,
(uint8_t) application_data_len, &value); (uint8_t) application_data_len, &value);
if (first_value && (len < application_data_len)) { if (first_value && (len < application_data_len)) {
first_value = false; first_value = false;
@@ -233,8 +233,8 @@ static uint8_t Read_Properties(
if (pRequired[index] != -1) { if (pRequired[index] != -1) {
printf(" %s: ", bactext_property_name(pRequired[index])); printf(" %s: ", bactext_property_name(pRequired[index]));
invoke_id = Send_Read_Property_Request(device_instance, invoke_id =
OBJECT_DEVICE, Send_Read_Property_Request(device_instance, OBJECT_DEVICE,
device_instance, pRequired[index], BACNET_ARRAY_ALL); device_instance, pRequired[index], BACNET_ARRAY_ALL);
if (invoke_id) { if (invoke_id) {
index++; index++;
@@ -282,8 +282,8 @@ int main(
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds =
Device_Number_Of_APDU_Retries(); (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
printf("List of Objects in test device:\r\n"); printf("List of Objects in test device:\r\n");
@@ -305,8 +305,9 @@ int main(
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
} }
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found =
&max_apdu, &Target_Address); address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) { if (found) {
/* invoke ID is set to zero when it is not in use */ /* invoke ID is set to zero when it is not in use */
if (invoke_id == 0) { if (invoke_id == 0) {
+16 -12
View File
@@ -117,12 +117,14 @@ void handler_atomic_read_file(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n"); fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n");
#endif #endif
@@ -131,7 +133,8 @@ void handler_atomic_read_file(
len = arf_decode_service_request(service_request, service_len, &data); len = arf_decode_service_request(service_request, service_len, &data);
/* bad decoding - send an abort */ /* bad decoding - send an abort */
if (len < 0) { 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n"); fprintf(stderr, "Bad Encoding. Sending Abort!\n");
@@ -151,8 +154,8 @@ void handler_atomic_read_file(
data.type.stream.requestedOctetCount); data.type.stream.requestedOctetCount);
#endif #endif
len = len =
arf_ack_encode_apdu(&Handler_Transmit_Buffer arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
} else { } else {
error = true; error = true;
error_class = ERROR_CLASS_OBJECT; error_class = ERROR_CLASS_OBJECT;
@@ -185,13 +188,14 @@ void handler_atomic_read_file(
if (error) { if (error) {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE,
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code); error_class, error_code);
} }
ARF_ABORT: ARF_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+2 -2
View File
@@ -73,8 +73,8 @@ void handler_atomic_read_file_ack(
if (pFilename) { if (pFilename) {
pFile = fopen(pFilename, "rb"); pFile = fopen(pFilename, "rb");
if (pFile) { if (pFile) {
(void) fseek(pFile, (void) fseek(pFile, data.type.stream.fileStartPosition,
data.type.stream.fileStartPosition, SEEK_SET); SEEK_SET);
if (fwrite(octetstring_value(&data.fileData), if (fwrite(octetstring_value(&data.fileData),
octetstring_length(&data.fileData), 1, octetstring_length(&data.fileData), 1,
pFile) != 1) { pFile) != 1) {
+16 -12
View File
@@ -95,12 +95,14 @@ void handler_atomic_write_file(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Segmented Message. Sending Abort!\n"); fprintf(stderr, "Segmented Message. Sending Abort!\n");
#endif #endif
@@ -109,7 +111,8 @@ void handler_atomic_write_file(
len = awf_decode_service_request(service_request, service_len, &data); len = awf_decode_service_request(service_request, service_len, &data);
/* bad decoding - send an abort */ /* bad decoding - send an abort */
if (len < 0) { 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n"); fprintf(stderr, "Bad Encoding. Sending Abort!\n");
@@ -127,8 +130,8 @@ void handler_atomic_write_file(
octetstring_length(&data.fileData)); octetstring_length(&data.fileData));
#endif #endif
len = len =
awf_ack_encode_apdu(&Handler_Transmit_Buffer awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
} else { } else {
error = true; error = true;
error_class = ERROR_CLASS_OBJECT; error_class = ERROR_CLASS_OBJECT;
@@ -150,13 +153,14 @@ void handler_atomic_write_file(
if (error) { if (error) {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE,
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code); error_class, error_code);
} }
AWF_ABORT: AWF_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+34 -23
View File
@@ -58,56 +58,65 @@ void handler_device_communication_control(
/* encode the NPDU portion of the reply packet */ /* encode the NPDU portion of the reply packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl!\n"); fprintf(stderr, "DeviceCommunicationControl!\n");
#endif #endif
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Abort - segmented message.\n"); "Sending Abort - segmented message.\n");
#endif #endif
goto DCC_ABORT; goto DCC_ABORT;
} }
/* decode the service request only */ /* decode the service request only */
len = dcc_decode_service_request(service_request, len =
service_len, &timeDuration, &state, &password); dcc_decode_service_request(service_request, service_len, &timeDuration,
&state, &password);
#if PRINT_ENABLED #if PRINT_ENABLED
if (len > 0) if (len > 0)
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr,
"timeout=%u state=%u password=%s\n", "DeviceCommunicationControl: " "timeout=%u state=%u password=%s\n",
(unsigned) timeDuration, (unsigned) timeDuration, (unsigned) state,
(unsigned) state, characterstring_value(&password)); characterstring_value(&password));
#endif #endif
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len < 0) { 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Abort - could not decode.\n"); "Sending Abort - could not decode.\n");
#endif #endif
goto DCC_ABORT; goto DCC_ABORT;
} }
if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) { if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Reject - undefined enumeration\n"); "Sending Reject - undefined enumeration\n");
#endif #endif
} else { } else {
if (characterstring_ansi_same(&password, My_Password)) { if (characterstring_ansi_same(&password, My_Password)) {
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL); SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr,
"Sending Simple Ack!\n"); "DeviceCommunicationControl: " "Sending Simple Ack!\n");
#endif #endif
dcc_set_status_duration(state, timeDuration); dcc_set_status_duration(state, timeDuration);
} else { } else {
@@ -125,12 +134,14 @@ void handler_device_communication_control(
} }
DCC_ABORT: DCC_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr,
"Failed to send PDU (%s)!\n", strerror(errno)); "DeviceCommunicationControl: " "Failed to send PDU (%s)!\n",
strerror(errno));
#endif #endif
return; return;
+6 -4
View File
@@ -44,8 +44,9 @@ void handler_i_am_add(
uint16_t vendor_id = 0; uint16_t vendor_id = 0;
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len =
&device_id, &max_apdu, &segmentation, &vendor_id); iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Received I-Am Request"); fprintf(stderr, "Received I-Am Request");
#endif #endif
@@ -75,8 +76,9 @@ void handler_i_am_bind(
uint16_t vendor_id = 0; uint16_t vendor_id = 0;
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len =
&device_id, &max_apdu, &segmentation, &vendor_id); iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
/* only add address if requested to bind */ /* only add address if requested to bind */
address_add_binding(device_id, max_apdu, src); address_add_binding(device_id, max_apdu, src);
+20 -14
View File
@@ -58,15 +58,17 @@ void handler_reinitialize_device(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice!\n"); fprintf(stderr, "ReinitializeDevice!\n");
#endif #endif
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"ReinitializeDevice: Sending Abort - segmented message.\n"); "ReinitializeDevice: Sending Abort - segmented message.\n");
@@ -74,8 +76,9 @@ void handler_reinitialize_device(
goto RD_ABORT; goto RD_ABORT;
} }
/* decode the service request only */ /* decode the service request only */
len = rd_decode_service_request(service_request, len =
service_len, &state, &their_password); rd_decode_service_request(service_request, service_len, &state,
&their_password);
#if PRINT_ENABLED #if PRINT_ENABLED
if (len > 0) if (len > 0)
fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n", fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n",
@@ -85,7 +88,8 @@ void handler_reinitialize_device(
#endif #endif
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len < 0) { 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
@@ -95,7 +99,8 @@ void handler_reinitialize_device(
} }
/* check the data from the request */ /* check the data from the request */
if (state >= MAX_BACNET_REINITIALIZED_STATE) { if (state >= MAX_BACNET_REINITIALIZED_STATE) {
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
@@ -104,7 +109,8 @@ void handler_reinitialize_device(
} else { } else {
characterstring_init_ansi(&My_Password, Password); characterstring_init_ansi(&My_Password, Password);
if (characterstring_same(&their_password, &My_Password)) { if (characterstring_same(&their_password, &My_Password)) {
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE); SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
#if PRINT_ENABLED #if PRINT_ENABLED
@@ -117,8 +123,7 @@ void handler_reinitialize_device(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE); ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
@@ -128,8 +133,9 @@ void handler_reinitialize_device(
} }
RD_ABORT: RD_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
+63 -47
View File
@@ -72,78 +72,88 @@ int Encode_Property_APDU(
switch (object_type) { switch (object_type) {
case OBJECT_DEVICE: case OBJECT_DEVICE:
if (Device_Valid_Object_Instance_Number(object_instance)) { if (Device_Valid_Object_Instance_Number(object_instance)) {
apdu_len = Device_Encode_Property_APDU(&apdu[0], apdu_len =
property, array_index, error_class, error_code); Device_Encode_Property_APDU(&apdu[0], property,
array_index, error_class, error_code);
} }
break; break;
case OBJECT_ANALOG_INPUT: case OBJECT_ANALOG_INPUT:
if (Analog_Input_Valid_Instance(object_instance)) { if (Analog_Input_Valid_Instance(object_instance)) {
apdu_len = Analog_Input_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Analog_Input_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_ANALOG_OUTPUT: case OBJECT_ANALOG_OUTPUT:
if (Analog_Output_Valid_Instance(object_instance)) { if (Analog_Output_Valid_Instance(object_instance)) {
apdu_len = Analog_Output_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Analog_Output_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_ANALOG_VALUE: case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(object_instance)) { if (Analog_Value_Valid_Instance(object_instance)) {
apdu_len = Analog_Value_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Analog_Value_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
if (Binary_Input_Valid_Instance(object_instance)) { if (Binary_Input_Valid_Instance(object_instance)) {
apdu_len = Binary_Input_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Binary_Input_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_BINARY_OUTPUT: case OBJECT_BINARY_OUTPUT:
if (Binary_Output_Valid_Instance(object_instance)) { if (Binary_Output_Valid_Instance(object_instance)) {
apdu_len = Binary_Output_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Binary_Output_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_BINARY_VALUE: case OBJECT_BINARY_VALUE:
if (Binary_Value_Valid_Instance(object_instance)) { if (Binary_Value_Valid_Instance(object_instance)) {
apdu_len = Binary_Value_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Binary_Value_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_LIFE_SAFETY_POINT: case OBJECT_LIFE_SAFETY_POINT:
if (Life_Safety_Point_Valid_Instance(object_instance)) { if (Life_Safety_Point_Valid_Instance(object_instance)) {
apdu_len = Life_Safety_Point_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Life_Safety_Point_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_LOAD_CONTROL: case OBJECT_LOAD_CONTROL:
if (Load_Control_Valid_Instance(object_instance)) { if (Load_Control_Valid_Instance(object_instance)) {
apdu_len = Load_Control_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Load_Control_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_MULTI_STATE_OUTPUT: case OBJECT_MULTI_STATE_OUTPUT:
if (Multistate_Output_Valid_Instance(object_instance)) { if (Multistate_Output_Valid_Instance(object_instance)) {
apdu_len = Multistate_Output_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Multistate_Output_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
#if defined(BACFILE) #if defined(BACFILE)
case OBJECT_FILE: case OBJECT_FILE:
if (bacfile_valid_instance(object_instance)) { if (bacfile_valid_instance(object_instance)) {
apdu_len = bacfile_encode_property_apdu(&apdu[0], apdu_len =
object_instance, bacfile_encode_property_apdu(&apdu[0], object_instance,
property, array_index, error_class, error_code); property, array_index, error_class, error_code);
} }
break; break;
@@ -176,13 +186,15 @@ void handler_read_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "RP: Segmented message. Sending Abort!\n"); fprintf(stderr, "RP: Segmented message. Sending Abort!\n");
#endif #endif
@@ -196,7 +208,8 @@ void handler_read_property(
#endif #endif
if (len < 0) { if (len < 0) {
/* bad decoding - send an abort */ /* 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "RP: Bad Encoding. Sending Abort!\n"); fprintf(stderr, "RP: Bad Encoding. Sending Abort!\n");
@@ -206,10 +219,10 @@ void handler_read_property(
/* assume that there is an error */ /* assume that there is an error */
error = true; error = true;
len = Encode_Property_APDU(&Temp_Buf[0], len =
data.object_type, Encode_Property_APDU(&Temp_Buf[0], data.object_type,
data.object_instance, data.object_instance, data.object_property, data.array_index,
data.object_property, data.array_index, &error_class, &error_code); &error_class, &error_code);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
@@ -226,16 +239,18 @@ void handler_read_property(
if (error) { if (error) {
if (len == -2) { if (len == -2) {
/* BACnet APDU too small to fit data, so proper response is Abort */ /* 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, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "RP: Reply too big to fit into APDU!\n"); fprintf(stderr, "RP: Reply too big to fit into APDU!\n");
#endif #endif
} else { } else {
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "RP: Sending Error!\n"); fprintf(stderr, "RP: Sending Error!\n");
#endif #endif
@@ -243,8 +258,9 @@ void handler_read_property(
} }
RP_ABORT: RP_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+2 -1
View File
@@ -71,7 +71,8 @@ static void PrintReadPropertyData(
/* FIXME: what if application_data_len is bigger than 255? */ /* FIXME: what if application_data_len is bigger than 255? */
/* value? need to loop until all of the len is gone... */ /* value? need to loop until all of the len is gone... */
for (;;) { for (;;) {
len = bacapp_decode_application_data(application_data, len =
bacapp_decode_application_data(application_data,
(uint8_t) application_data_len, &value); (uint8_t) application_data_len, &value);
if (first_value && (len < application_data_len)) { if (first_value && (len < application_data_len)) {
first_value = false; first_value = false;
+51 -36
View File
@@ -198,8 +198,9 @@ static unsigned RPM_Object_Property_Count(
unsigned count = 0; /* return value */ unsigned count = 0; /* return value */
if (special_property == PROP_ALL) { if (special_property == PROP_ALL) {
count = pPropertyList->Required.count + count =
pPropertyList->Optional.count + pPropertyList->Proprietary.count; pPropertyList->Required.count + pPropertyList->Optional.count +
pPropertyList->Proprietary.count;
} else if (special_property == PROP_REQUIRED) { } else if (special_property == PROP_REQUIRED) {
count = pPropertyList->Required.count; count = pPropertyList->Required.count;
} else if (special_property == PROP_OPTIONAL) { } else if (special_property == PROP_OPTIONAL) {
@@ -246,19 +247,20 @@ int RPM_Encode_Property(
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT; BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
len = rpm_ack_encode_apdu_object_property(&Temp_Buf[0], len =
object_property, array_index); rpm_ack_encode_apdu_object_property(&Temp_Buf[0], object_property,
array_index);
len = apdu_copy(&apdu[0], &Temp_Buf[0], offset, len, max_apdu); len = apdu_copy(&apdu[0], &Temp_Buf[0], offset, len, max_apdu);
if (!len) if (!len)
return 0; return 0;
apdu_len += len; apdu_len += len;
len = Encode_Property_APDU(&Temp_Buf[0], len =
object_type, Encode_Property_APDU(&Temp_Buf[0], object_type, object_instance,
object_instance,
object_property, array_index, &error_class, &error_code); object_property, array_index, &error_class, &error_code);
if (len < 0) { if (len < 0) {
/* error was returned - encode that for the response */ /* error was returned - encode that for the response */
len = rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0], len =
rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0],
error_class, error_code); error_class, error_code);
len = len =
apdu_copy(&apdu[0], &Temp_Buf[0], offset + apdu_len, len, apdu_copy(&apdu[0], &Temp_Buf[0], offset + apdu_len, len,
@@ -304,12 +306,14 @@ void handler_read_property_multiple(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], npdu_len =
src, &my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
apdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], apdu_len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
printf("RPM: Segmented message. Sending Abort!\r\n"); printf("RPM: Segmented message. Sending Abort!\r\n");
#endif #endif
@@ -317,16 +321,19 @@ void handler_read_property_multiple(
} }
/* decode apdu request & encode apdu reply /* decode apdu request & encode apdu reply
encode complex ack, invoke id, service choice */ encode complex ack, invoke id, service choice */
apdu_len = rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], apdu_len =
rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id); service_data->invoke_id);
do { do {
len = rpm_decode_object_id(&service_request[decode_len], len =
rpm_decode_object_id(&service_request[decode_len],
service_len - decode_len, &object_type, &object_instance); service_len - decode_len, &object_type, &object_instance);
/* end of object? */ /* end of object? */
if (len > 0) { if (len > 0) {
decode_len += len; decode_len += len;
} else { } else {
len = rpm_decode_object_end(&service_request[decode_len], len =
rpm_decode_object_end(&service_request[decode_len],
service_len - decode_len); service_len - decode_len);
if (len == 1) { if (len == 1) {
decode_len++; decode_len++;
@@ -351,12 +358,15 @@ void handler_read_property_multiple(
} }
break; break;
} }
len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], len =
object_type, object_instance); rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], object_type,
copy_len = apdu_copy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], object_instance);
copy_len =
apdu_copy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
apdu_len, len, sizeof(Handler_Transmit_Buffer)); apdu_len, len, sizeof(Handler_Transmit_Buffer));
if (!copy_len) { if (!copy_len) {
apdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT; goto RPM_ABORT;
@@ -365,13 +375,15 @@ void handler_read_property_multiple(
} }
/* do each property of this object of the RPM request */ /* do each property of this object of the RPM request */
do { do {
len = rpm_decode_object_property(&service_request[decode_len], len =
rpm_decode_object_property(&service_request[decode_len],
service_len - decode_len, &object_property, &array_index); service_len - decode_len, &object_property, &array_index);
/* end of property list? */ /* end of property list? */
if (len > 0) { if (len > 0) {
decode_len += len; decode_len += len;
} else { } else {
len = rpm_decode_object_end(&service_request[decode_len], len =
rpm_decode_object_end(&service_request[decode_len],
service_len - decode_len); service_len - decode_len);
if (len == 1) { if (len == 1) {
decode_len++; decode_len++;
@@ -409,16 +421,18 @@ void handler_read_property_multiple(
special_object_property = object_property; special_object_property = object_property;
RPM_Property_List(object_type, &property_list); RPM_Property_List(object_type, &property_list);
property_count = RPM_Object_Property_Count(&property_list, property_count =
RPM_Object_Property_Count(&property_list,
special_object_property); special_object_property);
for (index = 0; index < property_count; index++) { for (index = 0; index < property_count; index++) {
object_property = RPM_Object_Property(&property_list, object_property =
RPM_Object_Property(&property_list,
special_object_property, index); special_object_property, index);
len = RPM_Encode_Property(&Handler_Transmit_Buffer[0], len =
npdu_len + apdu_len, RPM_Encode_Property(&Handler_Transmit_Buffer[0],
sizeof(Handler_Transmit_Buffer), npdu_len + apdu_len, sizeof(Handler_Transmit_Buffer),
object_type, object_type, object_instance, object_property,
object_instance, object_property, array_index); array_index);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
@@ -431,11 +445,11 @@ void handler_read_property_multiple(
} }
} else { } else {
/* handle an individual property */ /* handle an individual property */
len = RPM_Encode_Property(&Handler_Transmit_Buffer[0], len =
npdu_len + apdu_len, RPM_Encode_Property(&Handler_Transmit_Buffer[0],
sizeof(Handler_Transmit_Buffer), npdu_len + apdu_len, sizeof(Handler_Transmit_Buffer),
object_type, object_type, object_instance, object_property,
object_instance, object_property, array_index); array_index);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
@@ -453,6 +467,7 @@ void handler_read_property_multiple(
} while (1); } while (1);
RPM_ABORT: RPM_ABORT:
pdu_len = apdu_len + npdu_len; pdu_len = apdu_len + npdu_len;
bytes_sent = datalink_send_pdu(src, bytes_sent =
&npdu_data, &Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
} }
+6 -4
View File
@@ -60,8 +60,9 @@ void handler_timesync(
(void) src; (void) src;
(void) service_len; (void) service_len;
len = timesync_decode_service_request(service_request, len =
service_len, &bdate, &btime); timesync_decode_service_request(service_request, service_len, &bdate,
&btime);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Received TimeSyncronization Request\r\n"); fprintf(stderr, "Received TimeSyncronization Request\r\n");
show_bacnet_date_time(&bdate, &btime); show_bacnet_date_time(&bdate, &btime);
@@ -82,8 +83,9 @@ void handler_timesync_utc(
(void) src; (void) src;
(void) service_len; (void) service_len;
len = timesync_decode_service_request(service_request, len =
service_len, &bdate, &btime); timesync_decode_service_request(service_request, service_len, &bdate,
&btime);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Received TimeSyncronization Request\r\n"); fprintf(stderr, "Received TimeSyncronization Request\r\n");
show_bacnet_date_time(&bdate, &btime); show_bacnet_date_time(&bdate, &btime);
+5 -4
View File
@@ -62,11 +62,12 @@ void handler_who_has(
if (data.object_name) { if (data.object_name) {
/* valid name in my device? */ /* valid name in my device? */
object_name = characterstring_value(&data.object.name); object_name = characterstring_value(&data.object.name);
found = Device_Valid_Object_Name(object_name, found =
&object_type, &object_instance); Device_Valid_Object_Name(object_name, &object_type,
&object_instance);
if (found) if (found)
Send_I_Have(Device_Object_Instance_Number(), Send_I_Have(Device_Object_Instance_Number(), object_type,
object_type, object_instance, object_name); object_instance, object_name);
} else { } else {
/* valid object in my device? */ /* valid object in my device? */
object_name = object_name =
+3 -2
View File
@@ -47,8 +47,9 @@ void handler_who_is(
int32_t high_limit = 0; int32_t high_limit = 0;
(void) src; (void) src;
len = whois_decode_service_request(service_request, len =
service_len, &low_limit, &high_limit); whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
if (len == 0) if (len == 0)
iam_send(&Handler_Transmit_Buffer[0]); iam_send(&Handler_Transmit_Buffer[0]);
else if (len != -1) { else if (len != -1) {
+31 -28
View File
@@ -68,15 +68,17 @@ void handler_write_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Received Request!\n"); fprintf(stderr, "WP: Received Request!\n");
#endif #endif
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Segmented message. Sending Abort!\n"); fprintf(stderr, "WP: Segmented message. Sending Abort!\n");
#endif #endif
@@ -86,15 +88,15 @@ void handler_write_property(
#if PRINT_ENABLED #if PRINT_ENABLED
if (len > 0) if (len > 0)
fprintf(stderr, "WP: type=%u instance=%u property=%u index=%d\n", fprintf(stderr, "WP: type=%u instance=%u property=%u index=%d\n",
wp_data.object_type, wp_data.object_type, wp_data.object_instance,
wp_data.object_instance,
wp_data.object_property, wp_data.array_index); wp_data.object_property, wp_data.array_index);
else else
fprintf(stderr, "WP: Unable to decode Request!\n"); fprintf(stderr, "WP: Unable to decode Request!\n");
#endif #endif
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n"); fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n");
@@ -113,8 +115,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Sending Error for Device!\n"); fprintf(stderr, "WP: Sending Error for Device!\n");
#endif #endif
@@ -144,8 +146,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for BO!\n"); fprintf(stderr, "WP: Sending Write Access Error for BO!\n");
#endif #endif
@@ -163,8 +165,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for BV!\n"); fprintf(stderr, "WP: Sending Write Access Error for BV!\n");
#endif #endif
@@ -182,8 +184,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for AO!\n"); fprintf(stderr, "WP: Sending Write Access Error for AO!\n");
#endif #endif
@@ -201,8 +203,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for AV!\n"); fprintf(stderr, "WP: Sending Write Access Error for AV!\n");
#endif #endif
@@ -220,8 +222,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for LSP!\n"); fprintf(stderr, "WP: Sending Write Access Error for LSP!\n");
#endif #endif
@@ -239,8 +241,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"WP: Sending Write Access Error for Load Control!\n"); "WP: Sending Write Access Error for Load Control!\n");
@@ -260,8 +262,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for MSO!\n"); fprintf(stderr, "WP: Sending Write Access Error for MSO!\n");
#endif #endif
@@ -279,8 +281,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for File!\n"); fprintf(stderr, "WP: Sending Write Access Error for File!\n");
#endif #endif
@@ -299,8 +301,9 @@ void handler_write_property(
} }
WP_ABORT: WP_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno));
+8 -5
View File
@@ -52,15 +52,18 @@ void handler_unrecognized_service(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE);
pdu_len += len; pdu_len += len;
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent > 0) if (bytes_sent > 0)
fprintf(stderr, "Sent Reject!\n"); fprintf(stderr, "Sent Reject!\n");
+8 -5
View File
@@ -78,10 +78,12 @@ uint8_t Send_Atomic_Read_File_Stream(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
len = arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &npdu_data);
invoke_id, &data); len =
arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len; pdu_len += len;
/* will the APDU fit the target device? /* will the APDU fit the target device?
note: if there is a bottleneck router in between note: if there is a bottleneck router in between
@@ -104,7 +106,8 @@ uint8_t Send_Atomic_Read_File_Stream(
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicReadFile Request " fprintf(stderr,
"Failed to Send AtomicReadFile Request "
"(payload exceeds destination maximum APDU)!\n"); "(payload exceeds destination maximum APDU)!\n");
#endif #endif
} }
+7 -4
View File
@@ -83,8 +83,9 @@ uint8_t Send_Atomic_Write_File_Stream(
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data); &my_address, &npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
len = awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
invoke_id, &data); awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len; pdu_len += len;
/* will the APDU fit the target device? /* will the APDU fit the target device?
note: if there is a bottleneck router in between note: if there is a bottleneck router in between
@@ -107,7 +108,8 @@ uint8_t Send_Atomic_Write_File_Stream(
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicWriteFile Request " fprintf(stderr,
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds destination maximum APDU [%u])!\n", "(payload [%d] exceeds destination maximum APDU [%u])!\n",
pdu_len, max_apdu); pdu_len, max_apdu);
#endif #endif
@@ -116,7 +118,8 @@ uint8_t Send_Atomic_Write_File_Stream(
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicWriteFile Request " fprintf(stderr,
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds octet string capacity)!\n", pdu_len); "(payload [%d] exceeds octet string capacity)!\n", pdu_len);
#endif #endif
} }
+5 -4
View File
@@ -72,12 +72,13 @@ uint8_t Send_Device_Communication_Control_Request(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
characterstring_init_ansi(&password_string, password); characterstring_init_ansi(&password_string, password);
len = dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
invoke_id, dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
timeDuration, state, password ? &password_string : NULL); timeDuration, state, password ? &password_string : NULL);
pdu_len += len; pdu_len += len;
/* will it fit in the sender? /* will it fit in the sender?
+5 -4
View File
@@ -64,8 +64,8 @@ void Send_I_Have(
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
NULL, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.device_id.type = OBJECT_DEVICE; data.device_id.type = OBJECT_DEVICE;
data.device_id.instance = device_id; data.device_id.instance = device_id;
@@ -75,8 +75,9 @@ void Send_I_Have(
len = ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); len = ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len; pdu_len += len;
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n",
+8 -5
View File
@@ -71,12 +71,14 @@ uint8_t Send_Reinitialize_Device_Request(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
characterstring_init_ansi(&password_string, password); characterstring_init_ansi(&password_string, password);
len = rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
invoke_id, state, password ? &password_string : NULL); rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, state,
password ? &password_string : NULL);
pdu_len += len; pdu_len += len;
/* will it fit in the sender? /* will it fit in the sender?
note: if there is a bottleneck router in between note: if there is a bottleneck router in between
@@ -99,7 +101,8 @@ uint8_t Send_Reinitialize_Device_Request(
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReinitializeDevice Request " fprintf(stderr,
"Failed to Send ReinitializeDevice Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif #endif
} }
+9 -7
View File
@@ -74,15 +74,17 @@ uint8_t Send_Read_Property_Request(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.object_type = object_type; data.object_type = object_type;
data.object_instance = object_instance; data.object_instance = object_instance;
data.object_property = object_property; data.object_property = object_property;
data.array_index = array_index; data.array_index = array_index;
len = rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
invoke_id, &data); rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len; pdu_len += len;
/* will it fit in the sender? /* will it fit in the sender?
note: if there is a bottleneck router in between note: if there is a bottleneck router in between
@@ -97,15 +99,15 @@ uint8_t Send_Read_Property_Request(
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr, "Failed to Send ReadProperty Request (%s)!\n",
"Failed to Send ReadProperty Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReadProperty Request " fprintf(stderr,
"Failed to Send ReadProperty Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif #endif
} }
+13 -12
View File
@@ -59,19 +59,19 @@ void Send_TimeSync(
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
NULL, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
len = timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
bdate, btime); timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime);
pdu_len += len; pdu_len += len;
/* send it out the datalink */ /* send it out the datalink */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr, "Failed to Send Time-Synchronization Request (%s)!\n",
"Failed to Send Time-Synchronization Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
@@ -91,10 +91,11 @@ void Send_TimeSyncUTC(
/* we could use unicast or broadcast */ /* we could use unicast or broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
pdu_len = timesync_utc_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len =
bdate, btime); timesync_utc_encode_apdu(&Handler_Transmit_Buffer[0], bdate, btime);
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
+10 -8
View File
@@ -62,8 +62,8 @@ void Send_WhoHas_Name(
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
NULL, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.low_limit = low_limit; data.low_limit = low_limit;
data.high_limit = high_limit; data.high_limit = high_limit;
@@ -72,8 +72,9 @@ void Send_WhoHas_Name(
len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len; pdu_len += len;
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
@@ -102,8 +103,8 @@ void Send_WhoHas_Object(
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
NULL, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.low_limit = low_limit; data.low_limit = low_limit;
data.high_limit = high_limit; data.high_limit = high_limit;
@@ -112,8 +113,9 @@ void Send_WhoHas_Object(
data.object.identifier.instance = object_instance; data.object.identifier.instance = object_instance;
len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
+8 -6
View File
@@ -61,14 +61,16 @@ void Send_WhoIs(
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
NULL, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
len = whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
low_limit, high_limit); whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit,
high_limit);
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
+13 -14
View File
@@ -77,8 +77,9 @@ uint8_t Send_Write_Property_Request_Data(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.object_type = object_type; data.object_type = object_type;
data.object_instance = object_instance; data.object_instance = object_instance;
@@ -88,8 +89,9 @@ uint8_t Send_Write_Property_Request_Data(
memcpy(&data.application_data[0], &application_data[0], memcpy(&data.application_data[0], &application_data[0],
application_data_len); application_data_len);
data.priority = priority; data.priority = priority;
len = wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
invoke_id, &data); wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len; pdu_len += len;
/* will it fit in the sender? /* will it fit in the sender?
note: if there is a bottleneck router in between note: if there is a bottleneck router in between
@@ -104,15 +106,15 @@ uint8_t Send_Write_Property_Request_Data(
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr, "Failed to Send WriteProperty Request (%s)!\n",
"Failed to Send WriteProperty Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send WriteProperty Request " fprintf(stderr,
"Failed to Send WriteProperty Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif #endif
} }
@@ -135,8 +137,7 @@ uint8_t Send_Write_Property_Request(
while (object_value) { while (object_value) {
#if PRINT_ENABLED_DEBUG #if PRINT_ENABLED_DEBUG
fprintf(stderr, "WriteProperty service: " fprintf(stderr, "WriteProperty service: " "%s tag=%d\n",
"%s tag=%d\n",
(object_value->context_specific ? "context" : "application"), (object_value->context_specific ? "context" : "application"),
(int) (object_value->context_specific ? object_value-> (int) (object_value->context_specific ? object_value->
context_tag : object_value->tag)); context_tag : object_value->tag));
@@ -150,9 +151,7 @@ uint8_t Send_Write_Property_Request(
object_value = object_value->next; object_value = object_value->next;
} }
return Send_Write_Property_Request_Data(device_id, return Send_Write_Property_Request_Data(device_id, object_type,
object_type, object_instance, object_property, &application_data[0], apdu_len,
object_instance, priority, array_index);
object_property,
&application_data[0], apdu_len, priority, array_index);
} }
+4 -4
View File
@@ -211,14 +211,14 @@ void testAnalogInput(
/* FIXME: we should do a lot more testing here... */ /* FIXME: we should do a lot more testing here... */
len = Analog_Input_Encode_Property_APDU(&apdu[0], len =
instance, Analog_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0); ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT); ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -411,7 +411,8 @@ bool Analog_Output_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -491,14 +492,14 @@ void testAnalogOutput(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Analog_Output_Encode_Property_APDU(&apdu[0], len =
instance, Analog_Output_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_OUTPUT); ct_test(pTest, decoded_type == OBJECT_ANALOG_OUTPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -339,7 +339,8 @@ bool Analog_Value_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -439,14 +440,14 @@ void testAnalog_Value(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Analog_Value_Encode_Property_APDU(&apdu[0], len =
instance, Analog_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE); ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+17 -12
View File
@@ -198,8 +198,9 @@ int bacfile_encode_property_apdu(
(void) array_index; (void) array_index;
switch (property) { switch (property) {
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
apdu_len = encode_application_object_id(&apdu[0], apdu_len =
OBJECT_FILE, object_instance); encode_application_object_id(&apdu[0], OBJECT_FILE,
object_instance);
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
sprintf(text_string, "FILE %d", object_instance); sprintf(text_string, "FILE %d", object_instance);
@@ -222,7 +223,8 @@ int bacfile_encode_property_apdu(
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_FILE_SIZE: case PROP_FILE_SIZE:
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
encode_application_unsigned(&apdu[0],
bacfile_file_size(object_instance)); bacfile_file_size(object_instance));
break; break;
case PROP_MODIFICATION_DATE: case PROP_MODIFICATION_DATE:
@@ -285,7 +287,8 @@ bool bacfile_write_property(
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -371,18 +374,19 @@ uint32_t bacfile_instance_from_tsm(
uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */ uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */
bool found = false; bool found = false;
found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0], found =
tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0],
&apdu_len); &apdu_len);
if (found) { if (found) {
if (!npdu_data.network_layer_message if (!npdu_data.network_layer_message && npdu_data.data_expecting_reply
&& npdu_data.data_expecting_reply
&& (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { && (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
len = len =
apdu_decode_confirmed_service_request(&apdu[0], apdu_decode_confirmed_service_request(&apdu[0], apdu_len,
apdu_len, &service_data, &service_choice, &service_data, &service_choice, &service_request,
&service_request, &service_request_len); &service_request_len);
if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) { if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) {
len = arf_decode_service_request(service_request, len =
arf_decode_service_request(service_request,
service_request_len, &data); service_request_len, &data);
if (len > 0) { if (len > 0) {
if (data.object_type == OBJECT_FILE) if (data.object_type == OBJECT_FILE)
@@ -410,7 +414,8 @@ bool bacfile_read_data(
pFile = fopen(pFilename, "rb"); pFile = fopen(pFilename, "rb");
if (pFile) { if (pFile) {
(void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET); (void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET);
len = fread(octetstring_value(&data->fileData), 1, len =
fread(octetstring_value(&data->fileData), 1,
data->type.stream.requestedOctetCount, pFile); data->type.stream.requestedOctetCount, pFile);
if (len < data->type.stream.requestedOctetCount) if (len < data->type.stream.requestedOctetCount)
data->endOfFile = true; data->endOfFile = true;
+4 -4
View File
@@ -256,14 +256,14 @@ void testBinaryInput(
/* FIXME: we should do a lot more testing here... */ /* FIXME: we should do a lot more testing here... */
len = Binary_Input_Encode_Property_APDU(&apdu[0], len =
instance, Binary_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0); ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT); ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -335,7 +335,8 @@ bool Binary_Output_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -437,14 +438,14 @@ void testBinaryOutput(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Binary_Output_Encode_Property_APDU(&apdu[0], len =
instance, Binary_Output_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_OUTPUT); ct_test(pTest, decoded_type == OBJECT_BINARY_OUTPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -328,7 +328,8 @@ bool Binary_Value_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -429,14 +430,14 @@ void testBinary_Value(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Binary_Value_Encode_Property_APDU(&apdu[0], len =
instance, Binary_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE); ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+10 -6
View File
@@ -663,7 +663,8 @@ int Device_Encode_Property_APDU(
switch (property) { switch (property) {
case PROP_OBJECT_IDENTIFIER: 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); Object_Instance_Number);
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
@@ -839,11 +840,13 @@ int Device_Encode_Property_APDU(
} }
break; break;
case PROP_MAX_APDU_LENGTH_ACCEPTED: 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()); Device_Max_APDU_Length_Accepted());
break; break;
case PROP_SEGMENTATION_SUPPORTED: case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
encode_application_enumerated(&apdu[0],
Device_Segmentation_Supported()); Device_Segmentation_Supported());
break; break;
case PROP_APDU_TIMEOUT: case PROP_APDU_TIMEOUT:
@@ -897,7 +900,8 @@ bool Device_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -921,8 +925,8 @@ bool Device_Write_Property(
case PROP_NUMBER_OF_APDU_RETRIES: case PROP_NUMBER_OF_APDU_RETRIES:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
/* FIXME: bounds check? */ /* FIXME: bounds check? */
Device_Set_Number_Of_APDU_Retries((uint8_t) value. Device_Set_Number_Of_APDU_Retries((uint8_t) value.type.
type.Unsigned_Int); Unsigned_Int);
status = true; status = true;
} else { } else {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
+50 -34
View File
@@ -314,12 +314,10 @@ struct tm {
timer = time(NULL); timer = time(NULL);
tblock = localtime(&timer); tblock = localtime(&timer);
datetime_set_values(bdatetime, datetime_set_values(bdatetime, (uint16_t) tblock->tm_year,
(uint16_t) tblock->tm_year, (uint8_t) tblock->tm_mon, (uint8_t) tblock->tm_mday,
(uint8_t) tblock->tm_mon, (uint8_t) tblock->tm_hour, (uint8_t) tblock->tm_min,
(uint8_t) tblock->tm_mday, (uint8_t) tblock->tm_sec, 0);
(uint8_t) tblock->tm_hour,
(uint8_t) tblock->tm_min, (uint8_t) tblock->tm_sec, 0);
} }
/* convert the shed level request into an Analog Output Present_Value */ /* convert the shed level request into an Analog Output Present_Value */
@@ -758,16 +756,19 @@ int Load_Control_Encode_Property_APDU(
case PROP_REQUESTED_SHED_LEVEL: case PROP_REQUESTED_SHED_LEVEL:
switch (Requested_Shed_Level[object_index].type) { switch (Requested_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT: case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0, apdu_len =
encode_context_unsigned(&apdu[0], 0,
Requested_Shed_Level[object_index].value.percent); Requested_Shed_Level[object_index].value.percent);
break; break;
case BACNET_SHED_TYPE_AMOUNT: case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2, apdu_len =
encode_context_real(&apdu[0], 2,
Requested_Shed_Level[object_index].value.amount); Requested_Shed_Level[object_index].value.amount);
break; break;
case BACNET_SHED_TYPE_LEVEL: case BACNET_SHED_TYPE_LEVEL:
default: default:
apdu_len = encode_context_unsigned(&apdu[0], 1, apdu_len =
encode_context_unsigned(&apdu[0], 1,
Requested_Shed_Level[object_index].value.level); Requested_Shed_Level[object_index].value.level);
break; break;
} }
@@ -777,16 +778,19 @@ int Load_Control_Encode_Property_APDU(
encode_application_date(&apdu[0], encode_application_date(&apdu[0],
&Start_Time[object_index].date); &Start_Time[object_index].date);
apdu_len = len; apdu_len = len;
len = encode_application_time(&apdu[apdu_len], len =
encode_application_time(&apdu[apdu_len],
&Start_Time[object_index].time); &Start_Time[object_index].time);
apdu_len += len; apdu_len += len;
break; break;
case PROP_SHED_DURATION: case PROP_SHED_DURATION:
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
encode_application_unsigned(&apdu[0],
Shed_Duration[object_index]); Shed_Duration[object_index]);
break; break;
case PROP_DUTY_WINDOW: case PROP_DUTY_WINDOW:
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
encode_application_unsigned(&apdu[0],
Duty_Window[object_index]); Duty_Window[object_index]);
break; break;
case PROP_ENABLE: case PROP_ENABLE:
@@ -794,22 +798,26 @@ int Load_Control_Encode_Property_APDU(
apdu_len = encode_application_boolean(&apdu[0], state); apdu_len = encode_application_boolean(&apdu[0], state);
break; break;
case PROP_FULL_DUTY_BASELINE: /* optional */ case PROP_FULL_DUTY_BASELINE: /* optional */
apdu_len = encode_application_real(&apdu[0], apdu_len =
encode_application_real(&apdu[0],
Full_Duty_Baseline[object_index]); Full_Duty_Baseline[object_index]);
break; break;
case PROP_EXPECTED_SHED_LEVEL: case PROP_EXPECTED_SHED_LEVEL:
switch (Expected_Shed_Level[object_index].type) { switch (Expected_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT: case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0, apdu_len =
encode_context_unsigned(&apdu[0], 0,
Expected_Shed_Level[object_index].value.percent); Expected_Shed_Level[object_index].value.percent);
break; break;
case BACNET_SHED_TYPE_AMOUNT: case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2, apdu_len =
encode_context_real(&apdu[0], 2,
Expected_Shed_Level[object_index].value.amount); Expected_Shed_Level[object_index].value.amount);
break; break;
case BACNET_SHED_TYPE_LEVEL: case BACNET_SHED_TYPE_LEVEL:
default: default:
apdu_len = encode_context_unsigned(&apdu[0], 1, apdu_len =
encode_context_unsigned(&apdu[0], 1,
Expected_Shed_Level[object_index].value.level); Expected_Shed_Level[object_index].value.level);
break; break;
} }
@@ -817,16 +825,19 @@ int Load_Control_Encode_Property_APDU(
case PROP_ACTUAL_SHED_LEVEL: case PROP_ACTUAL_SHED_LEVEL:
switch (Actual_Shed_Level[object_index].type) { switch (Actual_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT: case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0, apdu_len =
encode_context_unsigned(&apdu[0], 0,
Actual_Shed_Level[object_index].value.percent); Actual_Shed_Level[object_index].value.percent);
break; break;
case BACNET_SHED_TYPE_AMOUNT: case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2, apdu_len =
encode_context_real(&apdu[0], 2,
Actual_Shed_Level[object_index].value.amount); Actual_Shed_Level[object_index].value.amount);
break; break;
case BACNET_SHED_TYPE_LEVEL: case BACNET_SHED_TYPE_LEVEL:
default: default:
apdu_len = encode_context_unsigned(&apdu[0], 1, apdu_len =
encode_context_unsigned(&apdu[0], 1,
Actual_Shed_Level[object_index].value.level); Actual_Shed_Level[object_index].value.level);
break; break;
} }
@@ -857,7 +868,8 @@ int Load_Control_Encode_Property_APDU(
} }
} else { } else {
if (array_index <= MAX_SHED_LEVELS) { if (array_index <= MAX_SHED_LEVELS) {
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
encode_application_unsigned(&apdu[0],
Shed_Levels[object_index][array_index - 1]); Shed_Levels[object_index][array_index - 1]);
} else { } else {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
@@ -879,7 +891,8 @@ int Load_Control_Encode_Property_APDU(
/* FIXME: check if we have room before adding it to APDU */ /* FIXME: check if we have room before adding it to APDU */
characterstring_init_ansi(&char_string, characterstring_init_ansi(&char_string,
Shed_Level_Descriptions[i]); Shed_Level_Descriptions[i]);
len = encode_application_character_string(&apdu[apdu_len], len =
encode_application_character_string(&apdu[apdu_len],
&char_string); &char_string);
/* add it if we have room */ /* add it if we have room */
if ((apdu_len + len) < MAX_APDU) if ((apdu_len + len) < MAX_APDU)
@@ -895,7 +908,8 @@ int Load_Control_Encode_Property_APDU(
if (array_index <= MAX_SHED_LEVELS) { if (array_index <= MAX_SHED_LEVELS) {
characterstring_init_ansi(&char_string, characterstring_init_ansi(&char_string,
Shed_Level_Descriptions[array_index - 1]); Shed_Level_Descriptions[array_index - 1]);
apdu_len = encode_application_character_string(&apdu[0], apdu_len =
encode_application_character_string(&apdu[0],
&char_string); &char_string);
} else { } else {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
@@ -932,16 +946,18 @@ bool Load_Control_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
object_index = Load_Control_Instance_To_Index(wp_data->object_instance); object_index = Load_Control_Instance_To_Index(wp_data->object_instance);
switch (wp_data->object_property) { switch (wp_data->object_property) {
case PROP_REQUESTED_SHED_LEVEL: case PROP_REQUESTED_SHED_LEVEL:
len = bacapp_decode_context_data(wp_data->application_data, len =
wp_data->application_data_len, bacapp_decode_context_data(wp_data->application_data,
&value, PROP_REQUESTED_SHED_LEVEL); wp_data->application_data_len, &value,
PROP_REQUESTED_SHED_LEVEL);
if (value.context_tag == 0) { if (value.context_tag == 0) {
/* percent - Unsigned */ /* percent - Unsigned */
Requested_Shed_Level[object_index].type = Requested_Shed_Level[object_index].type =
@@ -974,8 +990,8 @@ bool Load_Control_Write_Property(
break; break;
case PROP_START_TIME: case PROP_START_TIME:
if (value.tag == BACNET_APPLICATION_TAG_DATE) { if (value.tag == BACNET_APPLICATION_TAG_DATE) {
memcpy(&Start_Time[object_index].date, memcpy(&Start_Time[object_index].date, &value.type.Date,
&value.type.Date, sizeof(value.type.Date)); sizeof(value.type.Date));
Start_Time_Property_Written[object_index] = true; Start_Time_Property_Written[object_index] = true;
status = true; status = true;
} else { } else {
@@ -988,8 +1004,8 @@ bool Load_Control_Write_Property(
bacapp_decode_application_data(wp_data->application_data + len, bacapp_decode_application_data(wp_data->application_data + len,
wp_data->application_data_len - len, &value); wp_data->application_data_len - len, &value);
if (len && value.tag == BACNET_APPLICATION_TAG_TIME) { if (len && value.tag == BACNET_APPLICATION_TAG_TIME) {
memcpy(&Start_Time[object_index].time, memcpy(&Start_Time[object_index].time, &value.type.Time,
&value.type.Time, sizeof(value.type.Time)); sizeof(value.type.Time));
status = true; status = true;
} else { } else {
status = false; status = false;
@@ -1455,14 +1471,14 @@ void testLoadControl(
BACNET_ERROR_CLASS error_class; BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Load_Control_Encode_Property_APDU(&apdu[0], len =
instance, Load_Control_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_LOAD_CONTROL); ct_test(pTest, decoded_type == OBJECT_LOAD_CONTROL);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+14 -10
View File
@@ -144,8 +144,9 @@ int Lighting_Output_Decode_Lighting_Command(
/* Tag 0: operation */ /* Tag 0: operation */
if (!decode_is_context_tag(&apdu[apdu_len], 0)) if (!decode_is_context_tag(&apdu[apdu_len], 0))
return -1; return -1;
len = decode_tag_number_and_value(&apdu[apdu_len], len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&len_value_type);
apdu_len += len; apdu_len += len;
len = len =
decode_enumerated(&apdu[apdu_len], len_value_type, decode_enumerated(&apdu[apdu_len], len_value_type,
@@ -153,8 +154,9 @@ int Lighting_Output_Decode_Lighting_Command(
apdu_len += len; apdu_len += len;
/* Tag 1: level - OPTIONAL */ /* Tag 1: level - OPTIONAL */
if (decode_is_context_tag(&apdu[apdu_len], 1)) { if (decode_is_context_tag(&apdu[apdu_len], 1)) {
len = decode_tag_number_and_value(&apdu[apdu_len], len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&len_value_type);
apdu_len += len; apdu_len += len;
len = decode_real(&apdu[apdu_len], &real_value); len = decode_real(&apdu[apdu_len], &real_value);
apdu_len += len; apdu_len += len;
@@ -412,7 +414,8 @@ int Lighting_Output_Encode_Property_APDU(
apdu_len = encode_application_real(&apdu[0], real_value); apdu_len = encode_application_real(&apdu[0], real_value);
break; break;
case PROP_LIGHTING_COMMAND: case PROP_LIGHTING_COMMAND:
apdu_len = Lighting_Output_Encode_Lighting_Command(&apdu[0], apdu_len =
Lighting_Output_Encode_Lighting_Command(&apdu[0],
&Lighting_Command[object_instance]); &Lighting_Command[object_instance]);
break; break;
case PROP_STATUS_FLAGS: case PROP_STATUS_FLAGS:
@@ -521,7 +524,8 @@ bool Lighting_Output_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -615,14 +619,14 @@ void testLightingOutput(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Lighting_Output_Encode_Property_APDU(&apdu[0], len =
instance, Lighting_Output_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_LIGHTING_OUTPUT); ct_test(pTest, decoded_type == OBJECT_LIGHTING_OUTPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -307,7 +307,8 @@ bool Life_Safety_Point_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -373,14 +374,14 @@ void testLifeSafetyPoint(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Life_Safety_Point_Encode_Property_APDU(&apdu[0], len =
instance, Life_Safety_Point_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_LIFE_SAFETY_POINT); ct_test(pTest, decoded_type == OBJECT_LIFE_SAFETY_POINT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+8 -6
View File
@@ -312,7 +312,8 @@ int Multistate_Output_Encode_Property_APDU(
apdu_len = encode_application_enumerated(&apdu[0], present_value); apdu_len = encode_application_enumerated(&apdu[0], present_value);
break; break;
case PROP_NUMBER_OF_STATES: case PROP_NUMBER_OF_STATES:
apdu_len = encode_application_unsigned(&apdu[apdu_len], apdu_len =
encode_application_unsigned(&apdu[apdu_len],
MULTISTATE_NUMBER_OF_STATES); MULTISTATE_NUMBER_OF_STATES);
break; break;
@@ -346,7 +347,8 @@ bool Multistate_Output_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -451,14 +453,14 @@ void testMultistateOutput(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Multistate_Output_Encode_Property_APDU(&apdu[0], len =
instance, Multistate_Output_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_MULTI_STATE_OUTPUT); ct_test(pTest, decoded_type == OBJECT_MULTI_STATE_OUTPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+10 -10
View File
@@ -132,8 +132,7 @@ static void AtomicReadFileAckHandler(
octets_written = fwrite(octetstring_value(&data.fileData), 1, /* unit to write in bytes - in our case, an octet is one byte */ octets_written = fwrite(octetstring_value(&data.fileData), 1, /* unit to write in bytes - in our case, an octet is one byte */
octetstring_length(&data.fileData), pFile); octetstring_length(&data.fileData), pFile);
if (octets_written != octetstring_length(&data.fileData)) if (octets_written != octetstring_length(&data.fileData))
fprintf(stderr, fprintf(stderr, "Unable to write data to file \"%s\".\n",
"Unable to write data to file \"%s\".\n",
Local_File_Name); Local_File_Name);
else else
printf("\r%u bytes", printf("\r%u bytes",
@@ -161,8 +160,9 @@ static void LocalIAmHandler(
(void) src; (void) src;
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len =
&device_id, &max_apdu, &segmentation, &vendor_id); iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
if (len != -1) { if (len != -1) {
address_add(device_id, max_apdu, src); address_add(device_id, max_apdu, src);
} else } else
@@ -242,8 +242,8 @@ int main(
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds =
Device_Number_Of_APDU_Retries(); (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
@@ -264,8 +264,9 @@ int main(
if (End_Of_File_Detected || Error_Detected) if (End_Of_File_Detected || Error_Detected)
break; break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found =
&max_apdu, &Target_Address); address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) { if (found) {
/* calculate the smaller of our APDU size or theirs /* calculate the smaller of our APDU size or theirs
and remove the overhead of the APDU (about 16 octets max). and remove the overhead of the APDU (about 16 octets max).
@@ -292,8 +293,7 @@ int main(
/* we'll read the file in chunks /* we'll read the file in chunks
less than max_apdu to keep unsegmented */ less than max_apdu to keep unsegmented */
invoke_id = invoke_id =
Send_Atomic_Read_File_Stream Send_Atomic_Read_File_Stream(Target_Device_Object_Instance,
(Target_Device_Object_Instance,
Target_File_Object_Instance, fileStartPosition, Target_File_Object_Instance, fileStartPosition,
requestedOctetCount); requestedOctetCount);
Current_Invoke_ID = invoke_id; Current_Invoke_ID = invoke_id;
+8 -8
View File
@@ -190,8 +190,8 @@ int main(
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds =
Device_Number_Of_APDU_Retries(); (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
@@ -212,15 +212,15 @@ int main(
if (Error_Detected) if (Error_Detected)
break; break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found =
&max_apdu, &Target_Address); address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) { if (found) {
if (invoke_id == 0) { if (invoke_id == 0) {
invoke_id = invoke_id =
Send_Read_Property_Request Send_Read_Property_Request(Target_Device_Object_Instance,
(Target_Device_Object_Instance, Target_Object_Type, Target_Object_Type, Target_Object_Instance,
Target_Object_Instance, Target_Object_Property, Target_Object_Property, Target_Object_Index);
Target_Object_Index);
} else if (tsm_invoke_id_free(invoke_id)) } else if (tsm_invoke_id_free(invoke_id))
break; break;
else if (tsm_invoke_id_failed(invoke_id)) { else if (tsm_invoke_id_failed(invoke_id)) {
+10 -16
View File
@@ -70,8 +70,7 @@ static void MyErrorHandler(
/* FIXME: verify src and invoke id */ /* FIXME: verify src and invoke id */
(void) src; (void) src;
(void) invoke_id; (void) invoke_id;
printf("BACnet Error: %s: %s\r\n", printf("BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class),
bactext_error_class_name(error_class),
bactext_error_code_name(error_code)); bactext_error_code_name(error_code));
Error_Detected = true; Error_Detected = true;
} }
@@ -155,17 +154,11 @@ int main(
if (argc < 3) { if (argc < 3) {
/* note: priority 16 and 0 should produce the same end results... */ /* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s device-instance state [password]\r\n" printf("Usage: %s device-instance state [password]\r\n"
"Send BACnet ReinitializeDevice service to device.\r\n" "Send BACnet ReinitializeDevice service to device.\r\n" "\r\n"
"\r\n"
"The device-instance can be 0 to %d.\r\n" "The device-instance can be 0 to %d.\r\n"
"Possible state values:\r\n" "Possible state values:\r\n" " 0=coldstart\r\n"
" 0=coldstart\r\n" " 1=warmstart\r\n" " 2=startbackup\r\n" " 3=endbackup\r\n"
" 1=warmstart\r\n" " 4=startrestore\r\n" " 5=endrestore\r\n" " 6=abortrestore\r\n"
" 2=startbackup\r\n"
" 3=endbackup\r\n"
" 4=startrestore\r\n"
" 5=endrestore\r\n"
" 6=abortrestore\r\n"
"The optional password is a character string of 1 to 20 characters.\r\n", "The optional password is a character string of 1 to 20 characters.\r\n",
filename_remove_path(argv[0]), BACNET_MAX_INSTANCE - 1); filename_remove_path(argv[0]), BACNET_MAX_INSTANCE - 1);
return 0; return 0;
@@ -191,8 +184,8 @@ int main(
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds =
Device_Number_Of_APDU_Retries(); (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
@@ -213,8 +206,9 @@ int main(
if (Error_Detected) if (Error_Detected)
break; break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found =
&max_apdu, &Target_Address); address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) { if (found) {
if (invoke_id == 0) { if (invoke_id == 0) {
invoke_id = invoke_id =
+6 -9
View File
@@ -81,13 +81,12 @@ static void Init_Service_Handlers(
#endif #endif
apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
handler_reinitialize_device); handler_reinitialize_device);
apdu_set_unconfirmed_handler apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, handler_timesync_utc); handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
handler_timesync); handler_timesync);
/* handle communication so we can shutup when asked */ /* handle communication so we can shutup when asked */
apdu_set_confirmed_handler apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control); handler_device_communication_control);
} }
@@ -144,11 +143,9 @@ int main(
dlmstp_set_mac_address(127); dlmstp_set_mac_address(127);
} }
#endif #endif
printf("BACnet Server Demo\n" printf("BACnet Server Demo\n" "BACnet Stack Version %s\n"
"BACnet Stack Version %s\n" "BACnet Device ID: %u\n" "Max APDU: %d\n", BACnet_Version,
"BACnet Device ID: %u\n" Device_Object_Instance_Number(), MAX_APDU);
"Max APDU: %d\n",
BACnet_Version, Device_Object_Instance_Number(), MAX_APDU);
Init_Service_Handlers(); Init_Service_Handlers();
BIP_Debug = true; BIP_Debug = true;
if (!datalink_init(getenv("BACNET_IFACE"))) if (!datalink_init(getenv("BACNET_IFACE")))
+6 -12
View File
@@ -96,8 +96,8 @@ static void Init_Service_Handlers(
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property); handler_read_property);
/* handle the reply (request) coming in */ /* handle the reply (request) coming in */
apdu_set_unconfirmed_handler apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, handler_timesync_utc); handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
handler_timesync); handler_timesync);
/* handle any errors coming back */ /* handle any errors coming back */
@@ -127,17 +127,11 @@ int main(
printf("Usage: %s date time [device-instance]\r\n" printf("Usage: %s date time [device-instance]\r\n"
"Send BACnet TimeSynchronization request to all devices.\r\n" "Send BACnet TimeSynchronization request to all devices.\r\n"
"date format: year/month/day:dayofweek (e.g. 2006/4/1:6)\r\n" "date format: year/month/day:dayofweek (e.g. 2006/4/1:6)\r\n"
"year: AD, such as 2006\r\n" "year: AD, such as 2006\r\n" "month: 1=January, 12=December\r\n"
"month: 1=January, 12=December\r\n" "day: 1-31\r\n" "dayofweek: 1=Monday, 7=Sunday\r\n" "\r\n"
"day: 1-31\r\n"
"dayofweek: 1=Monday, 7=Sunday\r\n"
"\r\n"
"time format: hour:minute:second.hundredths (e.g. 23:59:59.12)\r\n" "time format: hour:minute:second.hundredths (e.g. 23:59:59.12)\r\n"
"hour: 0-23\r\n" "hour: 0-23\r\n" "minute: 0-59\r\n" "second: 0-59\r\n"
"minute: 0-59\r\n" "hundredths: 0-99\r\n" "\r\n"
"second: 0-59\r\n"
"hundredths: 0-99\r\n"
"\r\n"
"Optional device-instance sends a unicast time sync.\r\n", "Optional device-instance sends a unicast time sync.\r\n",
filename_remove_path(argv[0])); filename_remove_path(argv[0]));
return 0; return 0;
+17 -35
View File
@@ -78,55 +78,38 @@ int main(
if (argc < 7) { if (argc < 7) {
/* note: priority 16 and 0 should produce the same end results... */ /* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s pid device-id object-type object-instance " printf("Usage: %s pid device-id object-type object-instance "
"time property tag value [priority] [index]\r\n" "time property tag value [priority] [index]\r\n" "\r\n" "pid:\r\n"
"\r\n" "Process Identifier for this broadcast.\r\n" "\r\n"
"pid:\r\n"
"Process Identifier for this broadcast.\r\n"
"\r\n"
"device-id:\r\n" "device-id:\r\n"
"The Initiating BACnet Device Object Instance number.\r\n" "The Initiating BACnet Device Object Instance number.\r\n" "\r\n"
"\r\n"
"object-type:\r\n" "object-type:\r\n"
"The monitored object type is the integer value of the\r\n" "The monitored object type is the integer value of the\r\n"
"enumeration BACNET_OBJECT_TYPE in bacenum.h. For example,\r\n" "enumeration BACNET_OBJECT_TYPE in bacenum.h. For example,\r\n"
"if you were monitoring Analog Output 2, the object-type\r\n" "if you were monitoring Analog Output 2, the object-type\r\n"
"would be 1.\r\n" "would be 1.\r\n" "\r\n" "object-instance:\r\n"
"\r\n" "The monitored object instance number.\r\n" "\r\n" "time:\r\n"
"object-instance:\r\n"
"The monitored object instance number.\r\n"
"\r\n"
"time:\r\n"
"The subscription time remaining is conveyed in seconds.\r\n" "The subscription time remaining is conveyed in seconds.\r\n"
"\r\n" "\r\n" "property:\r\n"
"property:\r\n"
"The property is an integer value of the enumeration \r\n" "The property is an integer value of the enumeration \r\n"
"BACNET_PROPERTY_ID in bacenum.h. For example, if you were\r\n" "BACNET_PROPERTY_ID in bacenum.h. For example, if you were\r\n"
"monitoring the Present Value property, you would use 85\r\n" "monitoring the Present Value property, you would use 85\r\n"
"as the property.\r\n" "as the property.\r\n" "\r\n" "tag:\r\n"
"\r\n"
"tag:\r\n"
"Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n" "Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n"
"in bacenum.h. It is the data type of the value that you are\r\n" "in bacenum.h. It is the data type of the value that you are\r\n"
"monitoring. For example, if you were monitoring a REAL value, you would \r\n" "monitoring. For example, if you were monitoring a REAL value, you would \r\n"
"use a tag of 4." "use a tag of 4." "\r\n" "value:\r\n"
"\r\n"
"value:\r\n"
"The value is an ASCII representation of some type of data that you\r\n" "The value is an ASCII representation of some type of data that you\r\n"
"are monitoring. It is encoded using the tag information provided. For\r\n" "are monitoring. It is encoded using the tag information provided. For\r\n"
"example, if you were writing a REAL value of 100.0, you would use \r\n" "example, if you were writing a REAL value of 100.0, you would use \r\n"
"100.0 as the value.\r\n" "100.0 as the value.\r\n" "\r\n" "[priority]:\r\n"
"\r\n"
"[priority]:\r\n"
"This optional parameter is used for reporting the priority of the\r\n" "This optional parameter is used for reporting the priority of the\r\n"
"value. If no priority is given, none is sent, and the BACnet \r\n" "value. If no priority is given, none is sent, and the BACnet \r\n"
"standard requires that the value is reported at the lowest \r\n" "standard requires that the value is reported at the lowest \r\n"
"priority (16) if the object property supports priorities.\r\n" "priority (16) if the object property supports priorities.\r\n"
"\r\n" "\r\n" "[index]\r\n"
"[index]\r\n"
"This optional integer parameter is the index number of an array.\r\n" "This optional integer parameter is the index number of an array.\r\n"
"If the property is an array, individual elements can be reported.\r\n" "If the property is an array, individual elements can be reported.\r\n"
"\r\n" "\r\n" "Here is a brief overview of BACnet property and tags:\r\n"
"Here is a brief overview of BACnet property and tags:\r\n"
"Certain properties are expected to be written with certain \r\n" "Certain properties are expected to be written with certain \r\n"
"application tags, so you probably need to know which ones to use\r\n" "application tags, so you probably need to know which ones to use\r\n"
"with each property of each object. It is almost safe to say that\r\n" "with each property of each object. It is almost safe to say that\r\n"
@@ -136,9 +119,7 @@ int main(
"accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n" "accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n"
"the demo to use this kind of table - but I also wanted to be able\r\n" "the demo to use this kind of table - but I also wanted to be able\r\n"
"to do negative testing by passing the wrong tag and have the server\r\n" "to do negative testing by passing the wrong tag and have the server\r\n"
"return a reject message.\r\n" "return a reject message.\r\n" "\r\n" "Example:\r\n"
"\r\n"
"Example:\r\n"
"If you want generate an unconfirmed COV,\r\n" "If you want generate an unconfirmed COV,\r\n"
"you could send the following command:\r\n" "you could send the following command:\r\n"
"%s 1 2 3 4 5 85 4 100.0\r\n" "%s 1 2 3 4 5 85 4 100.0\r\n"
@@ -191,12 +172,13 @@ int main(
return 1; return 1;
} }
if (tag >= MAX_BACNET_APPLICATION_TAG) { if (tag >= MAX_BACNET_APPLICATION_TAG) {
fprintf(stderr, "tag=%u - it must be less than %u\r\n", fprintf(stderr, "tag=%u - it must be less than %u\r\n", tag,
tag, MAX_BACNET_APPLICATION_TAG); MAX_BACNET_APPLICATION_TAG);
return 1; return 1;
} }
status = bacapp_parse_application_data(tag, status =
value_string, &cov_data.listOfValues.value); bacapp_parse_application_data(tag, value_string,
&cov_data.listOfValues.value);
if (!status) { if (!status) {
/* FIXME: show the expected entry format for the tag */ /* FIXME: show the expected entry format for the tag */
fprintf(stderr, "unable to parse the tag value\r\n"); fprintf(stderr, "unable to parse the tag value\r\n");
+5 -9
View File
@@ -121,14 +121,11 @@ int main(
/* note: priority 16 and 0 should produce the same end results... */ /* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s <object-type object-instance | object-name>\r\n" printf("Usage: %s <object-type object-instance | object-name>\r\n"
"Send BACnet WhoHas request to devices, and wait for responses.\r\n" "Send BACnet WhoHas request to devices, and wait for responses.\r\n"
"\r\n" "\r\n" "Use either:\r\n" "The object-type can be 0 to %d.\r\n"
"Use either:\r\n" "The object-instance can be 0 to %d.\r\n" "or:\r\n"
"The object-type can be 0 to %d.\r\n"
"The object-instance can be 0 to %d.\r\n"
"or:\r\n"
"The object-name can be any string of characters.\r\n", "The object-name can be any string of characters.\r\n",
filename_remove_path(argv[0]), filename_remove_path(argv[0]), MAX_BACNET_OBJECT_TYPE - 1,
MAX_BACNET_OBJECT_TYPE - 1, BACNET_MAX_INSTANCE); BACNET_MAX_INSTANCE);
return 0; return 0;
} }
/* decode the command line parameters */ /* decode the command line parameters */
@@ -138,8 +135,7 @@ int main(
Target_Object_Type = strtol(argv[1], NULL, 0); Target_Object_Type = strtol(argv[1], NULL, 0);
Target_Object_Instance = strtol(argv[2], NULL, 0); Target_Object_Instance = strtol(argv[2], NULL, 0);
if (Target_Object_Instance > BACNET_MAX_INSTANCE) { if (Target_Object_Instance > BACNET_MAX_INSTANCE) {
fprintf(stderr, fprintf(stderr, "object-instance=%u - it must be less than %u\r\n",
"object-instance=%u - it must be less than %u\r\n",
Target_Object_Instance, BACNET_MAX_INSTANCE + 1); Target_Object_Instance, BACNET_MAX_INSTANCE + 1);
return 1; return 1;
} }
+10 -7
View File
@@ -117,8 +117,9 @@ static void LocalIAmHandler(
(void) src; (void) src;
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len =
&device_id, &max_apdu, &segmentation, &vendor_id); iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
if (len != -1) { if (len != -1) {
address_add(device_id, max_apdu, src); address_add(device_id, max_apdu, src);
} else } else
@@ -198,8 +199,8 @@ int main(
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds =
Device_Number_Of_APDU_Retries(); (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
@@ -222,8 +223,9 @@ int main(
break; break;
} }
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found =
&max_apdu, &Target_Address); address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) { if (found) {
/* calculate the smaller of our APDU size or theirs /* calculate the smaller of our APDU size or theirs
and remove the overhead of the APDU (varies depending on size). and remove the overhead of the APDU (varies depending on size).
@@ -252,7 +254,8 @@ int main(
pFile = fopen(Local_File_Name, "rb"); pFile = fopen(Local_File_Name, "rb");
if (pFile) { if (pFile) {
(void) fseek(pFile, fileStartPosition, SEEK_SET); (void) fseek(pFile, fileStartPosition, SEEK_SET);
len = fread(octetstring_value(&fileData), 1, len =
fread(octetstring_value(&fileData), 1,
requestedOctetCount, pFile); requestedOctetCount, pFile);
if (len < requestedOctetCount) if (len < requestedOctetCount)
End_Of_File_Detected = true; End_Of_File_Detected = true;
+22 -34
View File
@@ -178,50 +178,39 @@ int main(
"communicate to. This number will be used to try and bind with\r\n" "communicate to. This number will be used to try and bind with\r\n"
"the device using Who-Is and I-Am services. For example, if you were\r\n" "the device using Who-Is and I-Am services. For example, if you were\r\n"
"writing to Device Object 123, the device-instance would be 123.\r\n" "writing to Device Object 123, the device-instance would be 123.\r\n"
"\r\n" "\r\n" "object-type:\r\n"
"object-type:\r\n"
"The object type is the integer value of the enumeration\r\n" "The object type is the integer value of the enumeration\r\n"
"BACNET_OBJECT_TYPE in bacenum.h. It is the object that you are\r\n" "BACNET_OBJECT_TYPE in bacenum.h. It is the object that you are\r\n"
"writing to. For example if you were writing to Analog Output 2, \r\n" "writing to. For example if you were writing to Analog Output 2, \r\n"
"the object-type would be 1.\r\n" "the object-type would be 1.\r\n" "\r\n" "object-instance:\r\n"
"\r\n"
"object-instance:\r\n"
"This is the object instance number of the object that you are \r\n" "This is the object instance number of the object that you are \r\n"
"writing to. For example, if you were writing to Analog Output 2, \r\n" "writing to. For example, if you were writing to Analog Output 2, \r\n"
"the object-instance would be 2.\r\n" "the object-instance would be 2.\r\n" "\r\n" "property:\r\n"
"\r\n"
"property:\r\n"
"The property is an integer value of the enumeration \r\n" "The property is an integer value of the enumeration \r\n"
"BACNET_PROPERTY_ID in bacenum.h. It is the property you are \r\n" "BACNET_PROPERTY_ID in bacenum.h. It is the property you are \r\n"
"writing to. For example, if you were writing to the Present Value\r\n" "writing to. For example, if you were writing to the Present Value\r\n"
"property, you would use 85 as the property.\r\n" "property, you would use 85 as the property.\r\n" "\r\n"
"\r\n"
"priority:\r\n" "priority:\r\n"
"This parameter is used for setting the priority of the\r\n" "This parameter is used for setting the priority of the\r\n"
"write. If Priority 0 is given, no priority is sent. The BACnet \r\n" "write. If Priority 0 is given, no priority is sent. The BACnet \r\n"
"standard states that the value is written at the lowest \r\n" "standard states that the value is written at the lowest \r\n"
"priority (16) if the object property supports priorities\r\n" "priority (16) if the object property supports priorities\r\n"
"when no priority is sent.\r\n" "when no priority is sent.\r\n" "\r\n" "index\r\n"
"\r\n"
"index\r\n"
"This integer parameter is the index number of an array.\r\n" "This integer parameter is the index number of an array.\r\n"
"If the property is an array, individual elements can be written\r\n" "If the property is an array, individual elements can be written\r\n"
"to if supported. If this parameter is -1, the index is ignored.\r\n" "to if supported. If this parameter is -1, the index is ignored.\r\n"
"\r\n" "\r\n" "tag:\r\n"
"tag:\r\n"
"Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n" "Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n"
"in bacenum.h. It is the data type of the value that you are\r\n" "in bacenum.h. It is the data type of the value that you are\r\n"
"writing. For example, if you were writing a REAL value, you would \r\n" "writing. For example, if you were writing a REAL value, you would \r\n"
"use a tag of 4.\r\n" "use a tag of 4.\r\n"
"Context tags are created using two tags in a row. The context tag\r\n" "Context tags are created using two tags in a row. The context tag\r\n"
"is preceded by a C. Ctag tag. C2 4 creates a context 2 tagged REAL.\r\n" "is preceded by a C. Ctag tag. C2 4 creates a context 2 tagged REAL.\r\n"
"\r\n" "\r\n" "value:\r\n"
"value:\r\n"
"The value is an ASCII representation of some type of data that you\r\n" "The value is an ASCII representation of some type of data that you\r\n"
"are writing. It is encoded using the tag information provided. For\r\n" "are writing. It is encoded using the tag information provided. For\r\n"
"example, if you were writing a REAL value of 100.0, you would use \r\n" "example, if you were writing a REAL value of 100.0, you would use \r\n"
"100.0 as the value.\r\n" "100.0 as the value.\r\n" "\r\n"
"\r\n"
"Here is a brief overview of BACnet property and tags:\r\n" "Here is a brief overview of BACnet property and tags:\r\n"
"Certain properties are expected to be written with certain \r\n" "Certain properties are expected to be written with certain \r\n"
"application tags, so you probably need to know which ones to use\r\n" "application tags, so you probably need to know which ones to use\r\n"
@@ -232,15 +221,13 @@ int main(
"accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n" "accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n"
"the demo to use this kind of table - but I also wanted to be able\r\n" "the demo to use this kind of table - but I also wanted to be able\r\n"
"to do negative testing by passing the wrong tag and have the server\r\n" "to do negative testing by passing the wrong tag and have the server\r\n"
"return a reject message.\r\n" "return a reject message.\r\n" "\r\n" "Example:\r\n"
"\r\n"
"Example:\r\n"
"If you want send a 100 to the Present-Value in the Analog Output\r\n" "If you want send a 100 to the Present-Value in the Analog Output\r\n"
"at priority 16, you could send the following command:\r\n" "at priority 16, you could send the following command:\r\n"
"%s 123 1 0 85 4 100\r\n" "%s 123 1 0 85 4 100\r\n"
"You could also send a relinquish command:\r\n" "You could also send a relinquish command:\r\n"
"%s 123 1 0 85 0 0\r\n", "%s 123 1 0 85 0 0\r\n", filename_remove_path(argv[0]),
filename_remove_path(argv[0]), filename_remove_path(argv[0])); filename_remove_path(argv[0]));
} }
return 0; return 0;
} }
@@ -296,8 +283,9 @@ int main(
property_tag, MAX_BACNET_APPLICATION_TAG); property_tag, MAX_BACNET_APPLICATION_TAG);
return 1; return 1;
} }
status = bacapp_parse_application_data(property_tag, status =
value_string, &Target_Object_Property_Value[i]); bacapp_parse_application_data(property_tag, value_string,
&Target_Object_Property_Value[i]);
if (!status) { if (!status) {
/* FIXME: show the expected entry format for the tag */ /* FIXME: show the expected entry format for the tag */
fprintf(stderr, "unable to parse the tag value\r\n"); fprintf(stderr, "unable to parse the tag value\r\n");
@@ -319,8 +307,8 @@ int main(
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds =
Device_Number_Of_APDU_Retries(); (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
@@ -341,15 +329,15 @@ int main(
if (Error_Detected) if (Error_Detected)
break; break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found =
&max_apdu, &Target_Address); address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) { if (found) {
if (invoke_id == 0) { if (invoke_id == 0) {
invoke_id = invoke_id =
Send_Write_Property_Request Send_Write_Property_Request(Target_Device_Object_Instance,
(Target_Device_Object_Instance, Target_Object_Type, Target_Object_Type, Target_Object_Instance,
Target_Object_Instance, Target_Object_Property, Target_Object_Property, &Target_Object_Property_Value[0],
&Target_Object_Property_Value[0],
Target_Object_Property_Priority, Target_Object_Property_Priority,
Target_Object_Property_Index); Target_Object_Property_Index);
} else if (tsm_invoke_id_free(invoke_id)) } else if (tsm_invoke_id_free(invoke_id))
+1 -1
View File
@@ -6,7 +6,7 @@
[ -x /usr/bin/dos2unix ] || exit 0 [ -x /usr/bin/dos2unix ] || exit 0
INDENTRC=".indent.pro" INDENTRC=".indent.pro"
if [ ! -x ${INDENTRC} ] if [ ! -e ${INDENTRC} ]
then then
echo No ${INDENTRC} file found. Creating ${INDENTRC} file. echo No ${INDENTRC} file found. Creating ${INDENTRC} file.
echo "-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl" > ${INDENTRC} echo "-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl" > ${INDENTRC}
+8 -7
View File
@@ -122,11 +122,12 @@ int Analog_Input_Encode_Property_APDU(
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
OBJECT_ANALOG_INPUT); encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
apdu_len = encode_application_real(&apdu[0], apdu_len =
encode_application_real(&apdu[0],
Analog_Input_Present_Value(object_instance)); Analog_Input_Present_Value(object_instance));
break; break;
case PROP_STATUS_FLAGS: case PROP_STATUS_FLAGS:
@@ -177,14 +178,14 @@ void testAnalogInput(
/* FIXME: we should do a lot more testing here... */ /* FIXME: we should do a lot more testing here... */
len = Analog_Input_Encode_Property_APDU(&apdu[0], len =
instance, Analog_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0); ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT); ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -296,7 +296,8 @@ bool Analog_Value_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -400,14 +401,14 @@ void testAnalog_Value(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Analog_Value_Encode_Property_APDU(&apdu[0], len =
instance, Analog_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE); ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
ct_test(pTest, decoded_instance == instance); 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... */ /* FIXME: we should do a lot more testing here... */
len = Binary_Input_Encode_Property_APDU(&apdu[0], len =
instance, Binary_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0); ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT); ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -207,7 +207,8 @@ bool Binary_Value_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -315,14 +316,14 @@ void testBinary_Value(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Binary_Value_Encode_Property_APDU(&apdu[0], len =
instance, Binary_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE); ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE);
ct_test(pTest, decoded_instance == instance); 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 */ /* FIXME: change the hardcoded names to suit your application */
switch (property) { switch (property) {
case PROP_OBJECT_IDENTIFIER: 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); Object_Instance_Number);
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
@@ -416,11 +417,13 @@ int Device_Encode_Property_APDU(
} }
break; break;
case PROP_MAX_APDU_LENGTH_ACCEPTED: 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()); Device_Max_APDU_Length_Accepted());
break; break;
case PROP_SEGMENTATION_SUPPORTED: case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
encode_application_enumerated(&apdu[0],
Device_Segmentation_Supported()); Device_Segmentation_Supported());
break; break;
case PROP_APDU_TIMEOUT: case PROP_APDU_TIMEOUT:
@@ -502,7 +505,8 @@ bool Device_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -510,8 +514,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type. (Device_Set_Object_Instance_Number(value.type.Object_Id.
Object_Id.instance))) { instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
+29 -32
View File
@@ -303,8 +303,9 @@ static bool dlmstp_compare_data_expecting_reply(
/* decode the request data */ /* decode the request data */
request.address.mac[0] = src_address; request.address.mac[0] = src_address;
request.address.mac_len = 1; request.address.mac_len = 1;
offset = npdu_decode(&request_pdu[0], offset =
NULL, &request.address, &request.npdu_data); npdu_decode(&request_pdu[0], NULL, &request.address,
&request.npdu_data);
if (request.npdu_data.network_layer_message) { if (request.npdu_data.network_layer_message) {
return false; return false;
} }
@@ -321,8 +322,8 @@ static bool dlmstp_compare_data_expecting_reply(
/* decode the reply data */ /* decode the reply data */
reply.address.mac[0] = dest_address; reply.address.mac[0] = dest_address;
reply.address.mac_len = 1; reply.address.mac_len = 1;
offset = npdu_decode(&reply_pdu[0], offset =
&reply.address, NULL, &reply.npdu_data); npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
if (reply.npdu_data.network_layer_message) { if (reply.npdu_data.network_layer_message) {
return false; return false;
} }
@@ -788,9 +789,7 @@ static bool MSTP_Master_Node_FSM(
} else { } else {
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
} }
MSTP_Send_Frame(frame_type, MSTP_Send_Frame(frame_type, TransmitPacketDest, This_Station,
TransmitPacketDest,
This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen); (uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false; MSTP_Flag.TransmitPacketPending = false;
FrameCount++; FrameCount++;
@@ -904,8 +903,8 @@ static bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */ /* address at which a new master node may be found in that case. */
TokenCount++; TokenCount++;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
EventCount = 0; EventCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN; Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -927,8 +926,8 @@ static bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */ /* ResetMaintenancePFM */
Poll_Station = This_Station; Poll_Station = This_Station;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
TokenCount = 1; /* changed in Errata SSPC-135-2004 */ TokenCount = 1; /* changed in Errata SSPC-135-2004 */
EventCount = 0; EventCount = 0;
@@ -937,8 +936,8 @@ static bool MSTP_Master_Node_FSM(
} else { } else {
/* SendMaintenancePFM */ /* SendMaintenancePFM */
Poll_Station = next_poll_station; Poll_Station = next_poll_station;
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
Poll_Station, This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER; Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
} }
@@ -959,8 +958,8 @@ static bool MSTP_Master_Node_FSM(
/* RetrySendToken */ /* RetrySendToken */
RetryCount++; RetryCount++;
/* Transmit a Token frame to NS */ /* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
EventCount = 0; EventCount = 0;
/* re-enter the current state to listen for NS */ /* re-enter the current state to listen for NS */
/* to begin using the token. */ /* to begin using the token. */
@@ -969,8 +968,8 @@ static bool MSTP_Master_Node_FSM(
/* Assume that NS has failed. */ /* Assume that NS has failed. */
Poll_Station = next_next_station; Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */ /* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
Poll_Station, This_Station, NULL, 0); This_Station, NULL, 0);
/* no known successor node */ /* no known successor node */
Next_Station = This_Station; Next_Station = This_Station;
RetryCount = 0; RetryCount = 0;
@@ -1003,8 +1002,8 @@ static bool MSTP_Master_Node_FSM(
/* on the network and is empowered to create a token. */ /* on the network and is empowered to create a token. */
Poll_Station = next_this_station; Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */ /* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
Poll_Station, This_Station, NULL, 0); This_Station, NULL, 0);
/* indicate that the next station is unknown */ /* indicate that the next station is unknown */
Next_Station = This_Station; Next_Station = This_Station;
RetryCount = 0; RetryCount = 0;
@@ -1027,8 +1026,8 @@ static bool MSTP_Master_Node_FSM(
Next_Station = SourceAddress; Next_Station = SourceAddress;
EventCount = 0; EventCount = 0;
/* Transmit a Token frame to NS */ /* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
Poll_Station = This_Station; Poll_Station = This_Station;
TokenCount = 0; TokenCount = 0;
RetryCount = 0; RetryCount = 0;
@@ -1060,8 +1059,8 @@ static bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */ /* poll for a master at address PS. */
EventCount = 0; EventCount = 0;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN; Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
} else { } else {
@@ -1092,10 +1091,10 @@ static bool MSTP_Master_Node_FSM(
case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST: case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST:
/* Note: we could wait for up to Treply_delay */ /* Note: we could wait for up to Treply_delay */
if (MSTP_Flag.TransmitPacketPending) { if (MSTP_Flag.TransmitPacketPending) {
matched = dlmstp_compare_data_expecting_reply(&InputBuffer[0], matched =
DataLength, dlmstp_compare_data_expecting_reply(&InputBuffer[0],
SourceAddress, DataLength, SourceAddress, &TransmitPacket[0],
&TransmitPacket[0], TransmitPacketLen, TransmitPacketDest); TransmitPacketLen, TransmitPacketDest);
} }
if (MSTP_Flag.TransmitPacketPending && matched) { if (MSTP_Flag.TransmitPacketPending && matched) {
/* Reply */ /* Reply */
@@ -1111,9 +1110,7 @@ static bool MSTP_Master_Node_FSM(
} else { } else {
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
} }
MSTP_Send_Frame(frame_type, MSTP_Send_Frame(frame_type, TransmitPacketDest, This_Station,
TransmitPacketDest,
This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen); (uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false; MSTP_Flag.TransmitPacketPending = false;
Master_State = MSTP_MASTER_STATE_IDLE; 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. */ /* Any reply shall wait until this node receives the token. */
/* Call MSTP_Send_Frame to transmit a Reply Postponed frame, */ /* Call MSTP_Send_Frame to transmit a Reply Postponed frame, */
/* and enter the IDLE state. */ /* and enter the IDLE state. */
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED, MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED, SourceAddress,
SourceAddress, This_Station, NULL, 0); This_Station, NULL, 0);
Master_State = MSTP_MASTER_STATE_IDLE; Master_State = MSTP_MASTER_STATE_IDLE;
} }
/* clear our flag we were holding for comparison */ /* clear our flag we were holding for comparison */
+41 -30
View File
@@ -65,36 +65,41 @@ int Encode_Property_APDU(
switch (object_type) { switch (object_type) {
case OBJECT_DEVICE: case OBJECT_DEVICE:
if (Device_Valid_Object_Instance_Number(object_instance)) { if (Device_Valid_Object_Instance_Number(object_instance)) {
apdu_len = Device_Encode_Property_APDU(&apdu[0], apdu_len =
property, array_index, error_class, error_code); Device_Encode_Property_APDU(&apdu[0], property,
array_index, error_class, error_code);
} }
break; break;
case OBJECT_ANALOG_INPUT: case OBJECT_ANALOG_INPUT:
if (Analog_Input_Valid_Instance(object_instance)) { if (Analog_Input_Valid_Instance(object_instance)) {
apdu_len = Analog_Input_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Analog_Input_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_ANALOG_VALUE: case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(object_instance)) { if (Analog_Value_Valid_Instance(object_instance)) {
apdu_len = Analog_Value_Encode_Property_APDU(&Temp_Buf[0], apdu_len =
object_instance, Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
if (Binary_Input_Valid_Instance(object_instance)) { if (Binary_Input_Valid_Instance(object_instance)) {
apdu_len = Binary_Input_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Binary_Input_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
case OBJECT_BINARY_VALUE: case OBJECT_BINARY_VALUE:
if (Binary_Value_Valid_Instance(object_instance)) { if (Binary_Value_Valid_Instance(object_instance)) {
apdu_len = Binary_Value_Encode_Property_APDU(&Temp_Buf[0], apdu_len =
object_instance, Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
default: default:
@@ -125,28 +130,31 @@ void handler_read_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
goto RP_ABORT; goto RP_ABORT;
} }
len = rp_decode_service_request(service_request, service_len, &data); len = rp_decode_service_request(service_request, service_len, &data);
if (len < 0) { if (len < 0) {
/* bad decoding - send an abort */ /* 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
goto RP_ABORT; goto RP_ABORT;
} }
/* most cases will be error */ /* most cases will be error */
error = true; error = true;
len = Encode_Property_APDU(&Temp_Buf[0], len =
data.object_type, Encode_Property_APDU(&Temp_Buf[0], data.object_type,
data.object_instance, data.object_instance, data.object_property, data.array_index,
data.object_property, data.array_index, &error_class, &error_code); &error_class, &error_code);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
@@ -160,19 +168,22 @@ void handler_read_property(
if (error) { if (error) {
if (len == -2) { if (len == -2) {
/* BACnet APDU too small to fit data, so proper response is Abort */ /* 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, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RP_ABORT; goto RP_ABORT;
} }
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
} }
RP_ABORT: RP_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return; return;
} }
+18 -14
View File
@@ -63,19 +63,22 @@ void handler_write_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
goto WP_ABORT; goto WP_ABORT;
} }
/* decode the service request only */ /* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data); len = wp_decode_service_request(service_request, service_len, &wp_data);
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
goto WP_ABORT; goto WP_ABORT;
} }
@@ -89,8 +92,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
} }
break; break;
case OBJECT_ANALOG_INPUT: case OBJECT_ANALOG_INPUT:
@@ -111,8 +114,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
} }
break; break;
case OBJECT_ANALOG_VALUE: case OBJECT_ANALOG_VALUE:
@@ -124,8 +127,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
} }
break; break;
default: default:
@@ -137,8 +140,9 @@ void handler_write_property(
} }
WP_ABORT: WP_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return; return;
} }
+3 -2
View File
@@ -77,8 +77,9 @@ void LowLevelInit(
// //
// OUT = 0 (not used) // OUT = 0 (not used)
// result: AT91C_CKGR_PLLR = 0x00000000480A0E (PLL Register) // result: AT91C_CKGR_PLLR = 0x00000000480A0E (PLL Register)
pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 14) | pPMC->PMC_PLLR =
(AT91C_CKGR_PLLCOUNT & (10 << 8)) | (AT91C_CKGR_MUL & (72 << 16))); ((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) // Wait the startup time (until PMC Status register LOCK bit is set)
while (!(pPMC->PMC_SR & AT91C_PMC_LOCK)); 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, apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_property); handler_write_property);
/* handle communication so we can shutup when asked */ /* handle communication so we can shutup when asked */
apdu_set_confirmed_handler apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control); handler_device_communication_control);
#endif #endif
} }
+4 -4
View File
@@ -122,13 +122,13 @@ int Analog_Input_Encode_Property_APDU(
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
OBJECT_ANALOG_INPUT); encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
object_index = Analog_Input_Instance_To_Index(object_instance); object_index = Analog_Input_Instance_To_Index(object_instance);
apdu_len = encode_application_real(&apdu[0], apdu_len =
Present_Value[object_index]); encode_application_real(&apdu[0], Present_Value[object_index]);
break; break;
case PROP_STATUS_FLAGS: case PROP_STATUS_FLAGS:
bitstring_init(&bit_string); bitstring_init(&bit_string);
+4 -5
View File
@@ -103,12 +103,11 @@ void apdu_handler(
switch (apdu[0] & 0xF0) { switch (apdu[0] & 0xF0) {
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST: case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */ len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */
apdu_len, apdu_len, &service_data, &service_choice, &service_request,
&service_data, &service_request_len);
&service_choice, &service_request, &service_request_len);
if (service_choice == SERVICE_CONFIRMED_READ_PROPERTY) { if (service_choice == SERVICE_CONFIRMED_READ_PROPERTY) {
handler_read_property(service_request, handler_read_property(service_request, service_request_len,
service_request_len, src, &service_data); src, &service_data);
} }
#if 0 #if 0
else if (service_choice == SERVICE_CONFIRMED_WRITE_PROPERTY) { else if (service_choice == SERVICE_CONFIRMED_WRITE_PROPERTY) {
+6 -5
View File
@@ -175,7 +175,8 @@ bool Analog_Value_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -219,14 +220,14 @@ void testAnalog_Value(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Analog_Value_Encode_Property_APDU(&apdu[0], len =
instance, Analog_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE); ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
ct_test(pTest, decoded_instance == instance); 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 */ /* FIXME: change the hardcoded names to suit your application */
switch (property) { switch (property) {
case PROP_OBJECT_IDENTIFIER: 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); Object_Instance_Number);
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
@@ -342,8 +343,8 @@ int Device_Encode_Property_APDU(
apdu_len = encode_application_unsigned(&apdu[0], MAX_APDU); apdu_len = encode_application_unsigned(&apdu[0], MAX_APDU);
break; break;
case PROP_SEGMENTATION_SUPPORTED: case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
SEGMENTATION_NONE); encode_application_enumerated(&apdu[0], SEGMENTATION_NONE);
break; break;
case PROP_APDU_TIMEOUT: case PROP_APDU_TIMEOUT:
apdu_len = encode_application_unsigned(&apdu[0], 60000); apdu_len = encode_application_unsigned(&apdu[0], 60000);
@@ -396,7 +397,8 @@ bool Device_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -404,8 +406,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type. (Device_Set_Object_Instance_Number(value.type.Object_Id.
Object_Id.instance))) { instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
+20 -22
View File
@@ -697,8 +697,7 @@ static bool MSTP_Master_Node_FSM(
TransmitPacketLen = dlmstp_encode_unconfirmed_frame(); TransmitPacketLen = dlmstp_encode_unconfirmed_frame();
if (TransmitPacketLen) { if (TransmitPacketLen) {
MSTP_Send_Frame(FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY, MSTP_Send_Frame(FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY,
MSTP_BROADCAST_ADDRESS, MSTP_BROADCAST_ADDRESS, This_Station,
This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen); (uint8_t *) & TransmitPacket[0], TransmitPacketLen);
FrameCount++; FrameCount++;
} else { } else {
@@ -798,8 +797,8 @@ static bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */ /* address at which a new master node may be found in that case. */
TokenCount++; TokenCount++;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
EventCount = 0; EventCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN; Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -821,8 +820,8 @@ static bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */ /* ResetMaintenancePFM */
Poll_Station = This_Station; Poll_Station = This_Station;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
TokenCount = 1; /* changed in Errata SSPC-135-2004 */ TokenCount = 1; /* changed in Errata SSPC-135-2004 */
EventCount = 0; EventCount = 0;
@@ -831,8 +830,8 @@ static bool MSTP_Master_Node_FSM(
} else { } else {
/* SendMaintenancePFM */ /* SendMaintenancePFM */
Poll_Station = next_poll_station; Poll_Station = next_poll_station;
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
Poll_Station, This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER; Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
} }
@@ -853,8 +852,8 @@ static bool MSTP_Master_Node_FSM(
/* RetrySendToken */ /* RetrySendToken */
RetryCount++; RetryCount++;
/* Transmit a Token frame to NS */ /* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
EventCount = 0; EventCount = 0;
/* re-enter the current state to listen for NS */ /* re-enter the current state to listen for NS */
/* to begin using the token. */ /* to begin using the token. */
@@ -863,8 +862,8 @@ static bool MSTP_Master_Node_FSM(
/* Assume that NS has failed. */ /* Assume that NS has failed. */
Poll_Station = next_next_station; Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */ /* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
Poll_Station, This_Station, NULL, 0); This_Station, NULL, 0);
/* no known successor node */ /* no known successor node */
Next_Station = This_Station; Next_Station = This_Station;
RetryCount = 0; RetryCount = 0;
@@ -897,8 +896,8 @@ static bool MSTP_Master_Node_FSM(
/* on the network and is empowered to create a token. */ /* on the network and is empowered to create a token. */
Poll_Station = next_this_station; Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */ /* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
Poll_Station, This_Station, NULL, 0); This_Station, NULL, 0);
/* indicate that the next station is unknown */ /* indicate that the next station is unknown */
Next_Station = This_Station; Next_Station = This_Station;
RetryCount = 0; RetryCount = 0;
@@ -921,8 +920,8 @@ static bool MSTP_Master_Node_FSM(
Next_Station = SourceAddress; Next_Station = SourceAddress;
EventCount = 0; EventCount = 0;
/* Transmit a Token frame to NS */ /* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
Poll_Station = This_Station; Poll_Station = This_Station;
TokenCount = 0; TokenCount = 0;
RetryCount = 0; RetryCount = 0;
@@ -954,8 +953,8 @@ static bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */ /* poll for a master at address PS. */
EventCount = 0; EventCount = 0;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
Next_Station, This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN; Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
} else { } else {
@@ -996,8 +995,7 @@ static bool MSTP_Master_Node_FSM(
/* and enter the IDLE state to wait for the next frame. */ /* and enter the IDLE state to wait for the next frame. */
/* Note: optimized such that we are never a client */ /* Note: optimized such that we are never a client */
MSTP_Send_Frame(FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY, MSTP_Send_Frame(FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY,
TransmitPacketDest, TransmitPacketDest, This_Station,
This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen); (uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false; MSTP_Flag.TransmitPacketPending = false;
Master_State = MSTP_MASTER_STATE_IDLE; 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. */ /* Any reply shall wait until this node receives the token. */
/* Call MSTP_Send_Frame to transmit a Reply Postponed frame, */ /* Call MSTP_Send_Frame to transmit a Reply Postponed frame, */
/* and enter the IDLE state. */ /* and enter the IDLE state. */
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED, MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED, SourceAddress,
SourceAddress, This_Station, NULL, 0); This_Station, NULL, 0);
Master_State = MSTP_MASTER_STATE_IDLE; Master_State = MSTP_MASTER_STATE_IDLE;
} }
/* clear our flag we were holding for comparison */ /* clear our flag we were holding for comparison */
+29 -21
View File
@@ -67,15 +67,17 @@ int Encode_Property_APDU(
switch (object_type) { switch (object_type) {
case OBJECT_DEVICE: case OBJECT_DEVICE:
if (Device_Valid_Object_Instance_Number(object_instance)) { if (Device_Valid_Object_Instance_Number(object_instance)) {
apdu_len = Device_Encode_Property_APDU(&apdu[0], apdu_len =
property, array_index, error_class, error_code); Device_Encode_Property_APDU(&apdu[0], property,
array_index, error_class, error_code);
} }
break; break;
case OBJECT_ANALOG_VALUE: case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(object_instance)) { if (Analog_Value_Valid_Instance(object_instance)) {
apdu_len = Analog_Value_Encode_Property_APDU(&apdu[0], apdu_len =
object_instance, Analog_Value_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code); object_instance, property, array_index, error_class,
error_code);
} }
break; break;
default: default:
@@ -107,24 +109,27 @@ void handler_read_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (len < 0) { if (len < 0) {
/* bad decoding - send an abort */ /* 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
} else { } else {
/* most cases will be error */ /* most cases will be error */
error = true; error = true;
len = Encode_Property_APDU(&Temp_Buf[0], len =
data.object_type, Encode_Property_APDU(&Temp_Buf[0], data.object_type,
data.object_instance, data.object_instance, data.object_property, data.array_index,
data.object_property, data.array_index, &error_class, &error_code); &error_class, &error_code);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
@@ -140,21 +145,24 @@ void handler_read_property(
switch (len) { switch (len) {
/* BACnet APDU too small to fit data, so proper response is Abort */ /* BACnet APDU too small to fit data, so proper response is Abort */
case -2: case -2:
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
break; break;
case -1: case -1:
default: default:
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
break; break;
} }
} }
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return; return;
} }
+3 -2
View File
@@ -50,8 +50,9 @@ void handler_who_is(
int32_t target_device; int32_t target_device;
(void) src; (void) src;
len = whois_decode_service_request(service_request, len =
service_len, &low_limit, &high_limit); whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
if (len == 0) { if (len == 0) {
Send_I_Am = true; Send_I_Am = true;
} else if (len != -1) { } else if (len != -1) {
+12 -8
View File
@@ -67,16 +67,19 @@ void handler_write_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
} else { } else {
switch (wp_data.object_type) { switch (wp_data.object_type) {
#if 0 #if 0
@@ -143,8 +146,9 @@ void handler_write_property(
} }
} }
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return; return;
} }
+9 -10
View File
@@ -124,8 +124,8 @@ static int arcnet_bind(
"You might need to add the following to modules.conf\n" "You might need to add the following to modules.conf\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n" "(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n" "alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n" "Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
"Then follow it by:\n" "# modprobe af_packet\n"); "# modprobe af_packet\n");
exit(-1); exit(-1);
} }
@@ -144,14 +144,14 @@ static int arcnet_bind(
if (bind(sock_fd, &ARCNET_Socket_Address, if (bind(sock_fd, &ARCNET_Socket_Address,
sizeof(ARCNET_Socket_Address)) != 0) { sizeof(ARCNET_Socket_Address)) != 0) {
/* Bind problem, close socket and return */ /* Bind problem, close socket and return */
fprintf(stderr, fprintf(stderr, "arcnet: Unable to bind socket : %s\n",
"arcnet: Unable to bind socket : %s\n", strerror(errno)); strerror(errno));
fprintf(stderr, fprintf(stderr,
"You might need to add the following to modules.conf\n" "You might need to add the following to modules.conf\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n" "(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n" "alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n" "Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
"Then follow it by:\n" "# modprobe af_packet\n"); "# modprobe af_packet\n");
/* Close the socket */ /* Close the socket */
close(sock_fd); close(sock_fd);
exit(-1); exit(-1);
@@ -170,8 +170,8 @@ static int arcnet_bind(
/* Strcpy the interface name into the address */ /* Strcpy the interface name into the address */
strncpy(ARCNET_Socket_Address.sa_data, interface_name, strncpy(ARCNET_Socket_Address.sa_data, interface_name,
sizeof(ARCNET_Socket_Address.sa_data) - 1); sizeof(ARCNET_Socket_Address.sa_data) - 1);
fprintf(stderr, "arcnet: MAC=%02Xh iface=\"%s\"\n", fprintf(stderr, "arcnet: MAC=%02Xh iface=\"%s\"\n", ARCNET_MAC_Address,
ARCNET_MAC_Address, ARCNET_Socket_Address.sa_data); ARCNET_Socket_Address.sa_data);
atexit(arcnet_cleanup); atexit(arcnet_cleanup);
@@ -295,8 +295,7 @@ uint16_t arcnet_receive(
/* using O_NONBLOCK and no data */ /* using O_NONBLOCK and no data */
/* was immediately available for reading. */ /* was immediately available for reading. */
if (errno != EAGAIN) if (errno != EAGAIN)
fprintf(stderr, fprintf(stderr, "ethernet: Read error in receiving packet: %s\n",
"ethernet: Read error in receiving packet: %s\n",
strerror(errno)); strerror(errno));
return 0; return 0;
} }
+10 -8
View File
@@ -103,8 +103,8 @@ static void bip_set_interface(
if (BIP_Debug) { if (BIP_Debug) {
fprintf(stderr, "IP Broadcast Address: %s\n", fprintf(stderr, "IP Broadcast Address: %s\n",
inet_ntoa(broadcast_address)); inet_ntoa(broadcast_address));
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", bip_get_port(),
bip_get_port(), bip_get_port()); bip_get_port());
} }
} }
@@ -128,16 +128,18 @@ bool bip_init(
/* Allow us to use the same socket for sending and receiving */ /* Allow us to use the same socket for sending and receiving */
/* This makes sure that the src port is correct when sending */ /* This makes sure that the src port is correct when sending */
sockopt = 1; sockopt = 1;
status = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, status =
&sockopt, sizeof(sockopt)); setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &sockopt,
sizeof(sockopt));
if (status < 0) { if (status < 0) {
close(sock_fd); close(sock_fd);
bip_set_socket(-1); bip_set_socket(-1);
return status; return status;
} }
/* allow us to send a broadcast */ /* allow us to send a broadcast */
status = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, status =
&sockopt, sizeof(sockopt)); setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, &sockopt,
sizeof(sockopt));
if (status < 0) { if (status < 0) {
close(sock_fd); close(sock_fd);
bip_set_socket(-1); bip_set_socket(-1);
@@ -148,8 +150,8 @@ bool bip_init(
sin.sin_addr.s_addr = htonl(INADDR_ANY); sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port()); sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero)); memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
status = bind(sock_fd, status =
(const struct sockaddr *) &sin, sizeof(struct sockaddr)); bind(sock_fd, (const struct sockaddr *) &sin, sizeof(struct sockaddr));
if (status < 0) { if (status < 0) {
close(sock_fd); close(sock_fd);
bip_set_socket(-1); bip_set_socket(-1);
+22 -27
View File
@@ -177,8 +177,7 @@ uint16_t dlmstp_receive(
/* was immediately available for reading. */ /* was immediately available for reading. */
if (errno != EAGAIN) { if (errno != EAGAIN) {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr, "mstp: Read error in Receive_Client packet: %s\n",
"mstp: Read error in Receive_Client packet: %s\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
@@ -320,8 +319,8 @@ int dlmstp_get_transmit_packet(
max = Transmit_Client_SockFD; max = Transmit_Client_SockFD;
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0) { if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0) {
received_bytes = read(Transmit_Client_SockFD, received_bytes =
packet, sizeof(DLMSTP_PACKET)); read(Transmit_Client_SockFD, packet, sizeof(DLMSTP_PACKET));
} else { } else {
return 0; return 0;
} }
@@ -333,8 +332,7 @@ int dlmstp_get_transmit_packet(
/* was immediately available for reading. */ /* was immediately available for reading. */
if (errno != EAGAIN) { if (errno != EAGAIN) {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr, "mstp: Read error in Transmit_Client packet: %s\n",
"mstp: Read error in Transmit_Client packet: %s\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
@@ -369,9 +367,8 @@ uint16_t MSTP_Get_Send(
} }
/* convert the PDU into the MSTP Frame */ /* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */ pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize, mstp_port->OutputBufferSize, packet.frame_type, destination,
packet.frame_type, mstp_port->This_Station, &packet.pdu[0], packet.pdu_len);
destination, mstp_port->This_Station, &packet.pdu[0], packet.pdu_len);
return pdu_len; return pdu_len;
} }
@@ -401,8 +398,9 @@ bool dlmstp_compare_data_expecting_reply(
/* decode the request data */ /* decode the request data */
request.address.mac[0] = src_address; request.address.mac[0] = src_address;
request.address.mac_len = 1; request.address.mac_len = 1;
offset = npdu_decode(&request_pdu[0], offset =
NULL, &request.address, &request.npdu_data); npdu_decode(&request_pdu[0], NULL, &request.address,
&request.npdu_data);
if (request.npdu_data.network_layer_message) { if (request.npdu_data.network_layer_message) {
return false; return false;
} }
@@ -418,8 +416,8 @@ bool dlmstp_compare_data_expecting_reply(
request.service_choice = request_pdu[offset + 3]; request.service_choice = request_pdu[offset + 3];
/* decode the reply data */ /* decode the reply data */
bacnet_address_copy(&reply.address, dest_address); bacnet_address_copy(&reply.address, dest_address);
offset = npdu_decode(&reply_pdu[0], offset =
&reply.address, NULL, &reply.npdu_data); npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
if (reply.npdu_data.network_layer_message) { if (reply.npdu_data.network_layer_message) {
return false; return false;
} }
@@ -508,25 +506,23 @@ uint16_t MSTP_Get_Reply(
return 0; return 0;
} }
/* is this the reply to the DER? */ /* is this the reply to the DER? */
matched = dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0], matched =
mstp_port->DataLength, dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
mstp_port->SourceAddress, mstp_port->DataLength, mstp_port->SourceAddress,
&Transmit_Packet.pdu[0], &Transmit_Packet.pdu[0], Transmit_Packet.pdu_len,
Transmit_Packet.pdu_len, &Transmit_Packet.address); &Transmit_Packet.address);
if (matched) { if (matched) {
/* convert the PDU into the MSTP Frame */ /* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */ pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize, mstp_port->OutputBufferSize, Transmit_Packet.frame_type,
Transmit_Packet.frame_type, destination, mstp_port->This_Station, &Transmit_Packet.pdu[0],
destination, Transmit_Packet.pdu_len);
mstp_port->This_Station,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
/* not used here, but setting it anyway */ /* not used here, but setting it anyway */
Transmit_Packet.ready = false; Transmit_Packet.ready = false;
} else { } else {
/* put it back into the queue */ /* put it back into the queue */
(void) write(Transmit_Server_SockFD, (void) write(Transmit_Server_SockFD, &Transmit_Packet,
&Transmit_Packet, sizeof(Transmit_Packet)); sizeof(Transmit_Packet));
} }
return pdu_len; return pdu_len;
@@ -842,8 +838,7 @@ int main(
/* forever task */ /* forever task */
for (;;) { for (;;) {
#if (defined(MSTP_TEST_REQUEST) && MSTP_TEST_REQUEST) #if (defined(MSTP_TEST_REQUEST) && MSTP_TEST_REQUEST)
MSTP_Create_And_Send_Frame(&MSTP_Port, MSTP_Create_And_Send_Frame(&MSTP_Port, FRAME_TYPE_TEST_REQUEST,
FRAME_TYPE_TEST_REQUEST,
MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0); MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0);
nanosleep(&timeOut, &remains); nanosleep(&timeOut, &remains);
#endif #endif
+11 -12
View File
@@ -112,14 +112,14 @@ static int ethernet_bind(
/* Attempt to open the socket for 802.2 ethernet frames */ /* Attempt to open the socket for 802.2 ethernet frames */
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0) { if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0) {
/* Error occured */ /* Error occured */
fprintf(stderr, fprintf(stderr, "ethernet: Error opening socket: %s\n",
"ethernet: Error opening socket: %s\n", strerror(errno)); strerror(errno));
fprintf(stderr, fprintf(stderr,
"You might need to add the following to modules.conf\n" "You might need to add the following to modules.conf\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n" "(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n" "alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n" "Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
"Then follow it by:\n" "# modprobe af_packet\n"); "# modprobe af_packet\n");
exit(-1); exit(-1);
} }
/* Bind the socket to an address */ /* Bind the socket to an address */
@@ -132,14 +132,14 @@ static int ethernet_bind(
/* Attempt to bind the socket to the interface */ /* Attempt to bind the socket to the interface */
if (bind(sock_fd, eth_addr, sizeof(struct sockaddr)) != 0) { if (bind(sock_fd, eth_addr, sizeof(struct sockaddr)) != 0) {
/* Bind problem, close socket and return */ /* Bind problem, close socket and return */
fprintf(stderr, fprintf(stderr, "ethernet: Unable to bind 802.2 socket : %s\n",
"ethernet: Unable to bind 802.2 socket : %s\n", strerror(errno)); strerror(errno));
fprintf(stderr, fprintf(stderr,
"You might need to add the following to modules.conf\n" "You might need to add the following to modules.conf\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n" "(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n" "alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n" "Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
"Then follow it by:\n" "# modprobe af_packet\n"); "# modprobe af_packet\n");
/* Close the socket */ /* Close the socket */
close(sock_fd); close(sock_fd);
exit(-1); exit(-1);
@@ -248,8 +248,8 @@ int ethernet_send_pdu(
/* Send the packet */ /* Send the packet */
bytes = bytes =
sendto(eth802_sockfd, &mtu, mtu_len, 0, sendto(eth802_sockfd, &mtu, mtu_len, 0, (struct sockaddr *) &eth_addr,
(struct sockaddr *) &eth_addr, sizeof(struct sockaddr)); sizeof(struct sockaddr));
/* did it get sent? */ /* did it get sent? */
if (bytes < 0) if (bytes < 0)
fprintf(stderr, "ethernet: Error sending packet: %s\n", fprintf(stderr, "ethernet: Error sending packet: %s\n",
@@ -303,8 +303,7 @@ uint16_t ethernet_receive(
/* using O_NONBLOCK and no data */ /* using O_NONBLOCK and no data */
/* was immediately available for reading. */ /* was immediately available for reading. */
if (errno != EAGAIN) if (errno != EAGAIN)
fprintf(stderr, fprintf(stderr, "ethernet: Read error in receiving packet: %s\n",
"ethernet: Read error in receiving packet: %s\n",
strerror(errno)); strerror(errno));
return 0; return 0;
} }
+5 -4
View File
@@ -63,8 +63,9 @@ static void LocalIAmHandler(
(void) src; (void) src;
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len =
&device_id, &max_apdu, &segmentation, &vendor_id); iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
fprintf(stderr, "Received I-Am Request"); fprintf(stderr, "Received I-Am Request");
if (len != -1) { if (len != -1) {
fprintf(stderr, " from %u!\n", device_id); 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 got the reply with matching invoke ID or the TSM of the
invoke ID expired. This demo is doing things asynchronously. */ invoke ID expired. This demo is doing things asynchronously. */
status = Send_Read_Property_Request(device_id, /* destination device */ status = Send_Read_Property_Request(device_id, /* destination device */
OBJECT_DEVICE, OBJECT_DEVICE, device_id, object_props[property],
device_id, object_props[property], BACNET_ARRAY_ALL); BACNET_ARRAY_ALL);
if (status) if (status)
property++; 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, */ /* Data CRC: (present only if Length is non-zero) two octets, */
/* least significant octet first */ /* least significant octet first */
/* (pad): (optional) at most one octet of padding: X'FF' */ /* (pad): (optional) at most one octet of padding: X'FF' */
fprintf(stderr, fprintf(stderr, "55 FF %02X %02X %02X %02X %02X %02X ",
"55 FF %02X %02X %02X %02X %02X %02X ", mstp_port->FrameType, mstp_port->DestinationAddress,
mstp_port->FrameType, mstp_port->SourceAddress, HI_BYTE(mstp_port->DataLength),
mstp_port->DestinationAddress,
mstp_port->SourceAddress,
HI_BYTE(mstp_port->DataLength),
LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual); LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual);
if (mstp_port->DataLength) { if (mstp_port->DataLength) {
for (i = 0; i < mstp_port->DataLength; i++) { for (i = 0; i < mstp_port->DataLength; i++) {
fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]); fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]);
} }
fprintf(stderr, fprintf(stderr, "%02X %02X ", mstp_port->DataCRCActualMSB,
"%02X %02X ", mstp_port->DataCRCActualLSB);
mstp_port->DataCRCActualMSB, mstp_port->DataCRCActualLSB);
} }
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType)); fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
fprintf(stderr, "\n"); 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); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
OBJECT_ANALOG_INPUT); encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
apdu_len = encode_application_real(&apdu[0], apdu_len =
encode_application_real(&apdu[0],
Analog_Input_Present_Value(object_instance)); Analog_Input_Present_Value(object_instance));
break; break;
case PROP_STATUS_FLAGS: case PROP_STATUS_FLAGS:
@@ -174,14 +175,14 @@ void testAnalogInput(
/* FIXME: we should do a lot more testing here... */ /* FIXME: we should do a lot more testing here... */
len = Analog_Input_Encode_Property_APDU(&apdu[0], len =
instance, Analog_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0); ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT); ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -293,7 +293,8 @@ bool Analog_Value_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -397,14 +398,14 @@ void testAnalog_Value(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Analog_Value_Encode_Property_APDU(&apdu[0], len =
instance, Analog_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE); ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
ct_test(pTest, decoded_instance == instance); 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... */ /* FIXME: we should do a lot more testing here... */
len = Binary_Input_Encode_Property_APDU(&apdu[0], len =
instance, Binary_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0); ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT); ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -208,7 +208,8 @@ bool Binary_Value_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -316,14 +317,14 @@ void testBinary_Value(
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
len = Binary_Value_Encode_Property_APDU(&apdu[0], len =
instance, Binary_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len], len =
(int *) &decoded_type, &decoded_instance); decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE); ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE);
ct_test(pTest, decoded_instance == instance); 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 */ /* FIXME: change the hardcoded names to suit your application */
switch (property) { switch (property) {
case PROP_OBJECT_IDENTIFIER: 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); Object_Instance_Number);
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
@@ -428,11 +429,13 @@ int Device_Encode_Property_APDU(
} }
break; break;
case PROP_MAX_APDU_LENGTH_ACCEPTED: 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()); Device_Max_APDU_Length_Accepted());
break; break;
case PROP_SEGMENTATION_SUPPORTED: case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
encode_application_enumerated(&apdu[0],
Device_Segmentation_Supported()); Device_Segmentation_Supported());
break; break;
case PROP_APDU_TIMEOUT: case PROP_APDU_TIMEOUT:
@@ -514,7 +517,8 @@ bool Device_Write_Property(
return false; return false;
} }
/* decode the some of the request */ /* 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); wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */ /* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */ /* FIXME: len == 0: unable to decode? */
@@ -522,8 +526,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type. (Device_Set_Object_Instance_Number(value.type.Object_Id.
Object_Id.instance))) { instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
+6 -7
View File
@@ -139,11 +139,10 @@ int dlmstp_send_pdu(
if ((8 /* header len */ + pdu_len) > MAX_MPDU) { if ((8 /* header len */ + pdu_len) > MAX_MPDU) {
return -4; return -4;
} }
bytes_sent = MSTP_Create_Frame( bytes_sent =
(uint8_t *) & MSTP_Port.TxBuffer[0], MSTP_Create_Frame((uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), sizeof(MSTP_Port.TxBuffer), MSTP_Port.TxFrameType, destination,
MSTP_Port.TxFrameType, MSTP_Port.This_Station, pdu, pdu_len);
destination, MSTP_Port.This_Station, pdu, pdu_len);
MSTP_Port.TxLength = bytes_sent; MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true; MSTP_Port.TxReady = true;
MSTP_Packets++; MSTP_Packets++;
@@ -180,8 +179,8 @@ void dlmstp_task(
if (Receive_Buffer.ready && !MSTP_Port.TxReady) { if (Receive_Buffer.ready && !MSTP_Port.TxReady) {
if (Receive_Buffer.pdu_len) { if (Receive_Buffer.pdu_len) {
MSTP_Packets++; MSTP_Packets++;
npdu_handler(&Receive_Buffer.address, npdu_handler(&Receive_Buffer.address, &Receive_Buffer.pdu[0],
&Receive_Buffer.pdu[0], Receive_Buffer.pdu_len); Receive_Buffer.pdu_len);
} }
Receive_Buffer.ready = false; Receive_Buffer.ready = false;
} }
+44 -37
View File
@@ -66,19 +66,22 @@ void handler_read_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
goto RP_ABORT; goto RP_ABORT;
} }
len = rp_decode_service_request(service_request, service_len, &data); len = rp_decode_service_request(service_request, service_len, &data);
if (len < 0) { if (len < 0) {
/* bad decoding - send an abort */ /* 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
goto RP_ABORT; goto RP_ABORT;
} }
@@ -88,26 +91,27 @@ void handler_read_property(
case OBJECT_DEVICE: case OBJECT_DEVICE:
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
if (Device_Valid_Object_Instance_Number(data.object_instance)) { if (Device_Valid_Object_Instance_Number(data.object_instance)) {
len = Device_Encode_Property_APDU(&Temp_Buf[0], len =
data.object_property, Device_Encode_Property_APDU(&Temp_Buf[0],
data.array_index, &error_class, &error_code); data.object_property, data.array_index, &error_class,
&error_code);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
error = false; error = false;
} }
} }
break; break;
case OBJECT_ANALOG_INPUT: case OBJECT_ANALOG_INPUT:
if (Analog_Input_Valid_Instance(data.object_instance)) { if (Analog_Input_Valid_Instance(data.object_instance)) {
len = Analog_Input_Encode_Property_APDU(&Temp_Buf[0], len =
data.object_instance, Analog_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_property, data.object_instance, data.object_property,
data.array_index, &error_class, &error_code); data.array_index, &error_class, &error_code);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
@@ -115,17 +119,17 @@ void handler_read_property(
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
error = false; error = false;
} }
} }
break; break;
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
if (Binary_Input_Valid_Instance(data.object_instance)) { if (Binary_Input_Valid_Instance(data.object_instance)) {
len = Binary_Input_Encode_Property_APDU(&Temp_Buf[0], len =
data.object_instance, Binary_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_property, data.object_instance, data.object_property,
data.array_index, &error_class, &error_code); data.array_index, &error_class, &error_code);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
@@ -133,17 +137,17 @@ void handler_read_property(
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
error = false; error = false;
} }
} }
break; break;
case OBJECT_BINARY_VALUE: case OBJECT_BINARY_VALUE:
if (Binary_Value_Valid_Instance(data.object_instance)) { if (Binary_Value_Valid_Instance(data.object_instance)) {
len = Binary_Value_Encode_Property_APDU(&Temp_Buf[0], len =
data.object_instance, Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_property, data.object_instance, data.object_property,
data.array_index, &error_class, &error_code); data.array_index, &error_class, &error_code);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
@@ -151,17 +155,17 @@ void handler_read_property(
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
error = false; error = false;
} }
} }
break; break;
case OBJECT_ANALOG_VALUE: case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(data.object_instance)) { if (Analog_Value_Valid_Instance(data.object_instance)) {
len = Analog_Value_Encode_Property_APDU(&Temp_Buf[0], len =
data.object_instance, Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_property, data.object_instance, data.object_property,
data.array_index, &error_class, &error_code); data.array_index, &error_class, &error_code);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
@@ -169,8 +173,8 @@ void handler_read_property(
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
error = false; error = false;
} }
} }
@@ -181,19 +185,22 @@ void handler_read_property(
if (error) { if (error) {
if (len == -2) { if (len == -2) {
/* BACnet APDU too small to fit data, so proper response is Abort */ /* 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, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RP_ABORT; goto RP_ABORT;
} }
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
} }
RP_ABORT: RP_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
return; return;
} }
+18 -14
View File
@@ -62,19 +62,22 @@ void handler_write_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, pdu_len =
&my_address, &npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
goto WP_ABORT; goto WP_ABORT;
} }
/* decode the service request only */ /* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data); len = wp_decode_service_request(service_request, service_len, &wp_data);
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { 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); service_data->invoke_id, ABORT_REASON_OTHER, true);
goto WP_ABORT; goto WP_ABORT;
} }
@@ -91,8 +94,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Property Error for Device!\n"); fprintf(stderr, "Sending Write Property Error for Device!\n");
#endif #endif
@@ -122,8 +125,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for BV!\n"); fprintf(stderr, "Sending Write Access Error for BV!\n");
#endif #endif
@@ -141,8 +144,8 @@ void handler_write_property(
} else { } else {
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for AV!\n"); fprintf(stderr, "Sending Write Access Error for AV!\n");
#endif #endif
@@ -160,8 +163,9 @@ void handler_write_property(
} }
WP_ABORT: WP_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent =
&Handler_Transmit_Buffer[0], pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); 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, apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_property); handler_write_property);
#if 0 #if 0
apdu_set_unconfirmed_handler apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, handler_timesync_utc); handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
handler_timesync); handler_timesync);
#endif #endif
/* handle communication so we can shutup when asked */ /* handle communication so we can shutup when asked */
apdu_set_confirmed_handler apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control); handler_device_communication_control);
} }
+36 -49
View File
@@ -506,7 +506,8 @@ void MSTP_Receive_Frame_FSM(
#endif #endif
/* DataOctet */ /* DataOctet */
if (mstp_port->Index < mstp_port->DataLength) { 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->DataCRC);
mstp_port->InputBuffer[mstp_port->Index] = mstp_port->InputBuffer[mstp_port->Index] =
mstp_port->DataRegister; mstp_port->DataRegister;
@@ -515,14 +516,16 @@ void MSTP_Receive_Frame_FSM(
} }
/* CRC1 */ /* CRC1 */
else if (mstp_port->Index == mstp_port->DataLength) { 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->DataCRC);
mstp_port->Index++; mstp_port->Index++;
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;
} }
/* CRC2 */ /* CRC2 */
else if (mstp_port->Index == (mstp_port->DataLength + 1)) { 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); mstp_port->DataCRC);
/* STATE DATA CRC - no need for new state */ /* STATE DATA CRC - no need for new state */
/* indicate the complete reception of a valid frame */ /* indicate the complete reception of a valid frame */
@@ -570,26 +573,21 @@ bool MSTP_Master_Node_FSM(
#endif #endif
/* some calculations that several states need */ /* some calculations that several states need */
next_poll_station = (mstp_port->Poll_Station + 1) % next_poll_station =
(mstp_port->Nmax_master + 1); (mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1);
next_this_station = (mstp_port->This_Station + 1) % next_this_station =
(mstp_port->Nmax_master + 1); (mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1);
next_next_station = (mstp_port->Next_Station + 1) % next_next_station =
(mstp_port->Nmax_master + 1); (mstp_port->Next_Station + 1) % (mstp_port->Nmax_master + 1);
#if PRINT_ENABLED_MASTER #if PRINT_ENABLED_MASTER
if (mstp_port->master_state != master_state) { if (mstp_port->master_state != master_state) {
master_state = mstp_port->master_state; master_state = mstp_port->master_state;
fprintf(stderr, fprintf(stderr,
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n", "MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n",
mstp_port->This_Station, mstp_port->This_Station, next_this_station,
next_this_station, mstp_port->Next_Station, next_next_station,
mstp_port->Next_Station, mstp_port->Poll_Station, next_poll_station, mstp_port->EventCount,
next_next_station, mstp_port->TokenCount, mstp_port->SilenceTimer,
mstp_port->Poll_Station,
next_poll_station,
mstp_port->EventCount,
mstp_port->TokenCount,
mstp_port->SilenceTimer,
mstptext_master_state(mstp_port->master_state)); mstptext_master_state(mstp_port->master_state));
} }
#endif #endif
@@ -625,17 +623,14 @@ bool MSTP_Master_Node_FSM(
#if PRINT_ENABLED_MASTER #if PRINT_ENABLED_MASTER
fprintf(stderr, fprintf(stderr,
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n", "MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n",
mstp_port->SourceAddress, mstp_port->SourceAddress, mstp_port->DestinationAddress,
mstp_port->DestinationAddress, mstp_port->DataLength, mstp_port->FrameCount,
mstp_port->DataLength,
mstp_port->FrameCount,
mstp_port->SilenceTimer, mstp_port->SilenceTimer,
mstptext_frame_type(mstp_port->FrameType)); mstptext_frame_type(mstp_port->FrameType));
#endif #endif
/* destined for me! */ /* destined for me! */
if ((mstp_port->DestinationAddress == if ((mstp_port->DestinationAddress == mstp_port->This_Station)
mstp_port->This_Station) || || (mstp_port->DestinationAddress ==
(mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) { MSTP_BROADCAST_ADDRESS)) {
switch (mstp_port->FrameType) { switch (mstp_port->FrameType) {
/* ReceivedToken */ /* ReceivedToken */
@@ -827,10 +822,9 @@ bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */ /* address at which a new master node may be found in that case. */
mstp_port->TokenCount++; mstp_port->TokenCount++;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL,
mstp_port->Next_Station, 0);
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN; mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -854,10 +848,9 @@ bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */ /* ResetMaintenancePFM */
mstp_port->Poll_Station = mstp_port->This_Station; mstp_port->Poll_Station = mstp_port->This_Station;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL,
mstp_port->Next_Station, 0);
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */ mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
@@ -867,8 +860,8 @@ bool MSTP_Master_Node_FSM(
/* SendMaintenancePFM */ /* SendMaintenancePFM */
mstp_port->Poll_Station = next_poll_station; mstp_port->Poll_Station = next_poll_station;
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
} }
@@ -889,8 +882,7 @@ bool MSTP_Master_Node_FSM(
/* RetrySendToken */ /* RetrySendToken */
mstp_port->RetryCount++; mstp_port->RetryCount++;
/* Transmit a Token frame to NS */ /* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL, mstp_port->Next_Station, mstp_port->This_Station, NULL,
0); 0);
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
@@ -902,9 +894,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_next_station; mstp_port->Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */ /* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, mstp_port->This_Station, NULL, 0);
0);
/* no known successor node */ /* no known successor node */
mstp_port->Next_Station = mstp_port->This_Station; mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
@@ -940,9 +931,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_this_station; mstp_port->Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */ /* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, mstp_port->This_Station, NULL, 0);
0);
/* indicate that the next station is unknown */ /* indicate that the next station is unknown */
mstp_port->Next_Station = mstp_port->This_Station; mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
@@ -967,8 +957,7 @@ bool MSTP_Master_Node_FSM(
mstp_port->Next_Station = mstp_port->SourceAddress; mstp_port->Next_Station = mstp_port->SourceAddress;
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
/* Transmit a Token frame to NS */ /* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL, mstp_port->Next_Station, mstp_port->This_Station, NULL,
0); 0);
mstp_port->Poll_Station = mstp_port->This_Station; mstp_port->Poll_Station = mstp_port->This_Station;
@@ -1002,8 +991,7 @@ bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */ /* poll for a master at address PS. */
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, mstp_port->Next_Station, mstp_port->This_Station,
NULL, 0); NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
@@ -1073,8 +1061,7 @@ bool MSTP_Master_Node_FSM(
/* and enter the IDLE state. */ /* and enter the IDLE state. */
{ {
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_REPLY_POSTPONED, FRAME_TYPE_REPLY_POSTPONED, mstp_port->SourceAddress,
mstp_port->SourceAddress,
mstp_port->This_Station, NULL, 0); mstp_port->This_Station, NULL, 0);
mstp_port->master_state = MSTP_MASTER_STATE_IDLE; mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
} }
+4 -4
View File
@@ -174,8 +174,8 @@ static void NetInitialize(
} }
#else #else
/* Set the IP address and interface */ /* Set the IP address and interface */
printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0], printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0], TargetIP[1],
TargetIP[1], TargetIP[2], TargetIP[3]); TargetIP[2], TargetIP[3]);
Result = xn_set_ip(interface, TargetIP, NetMask); Result = xn_set_ip(interface, TargetIP, NetMask);
/* define default gateway and DNS server */ /* define default gateway and DNS server */
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF); 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_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port()); sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', 8); memset(&(sin.sin_zero), '\0', 8);
rv = bind(sock_fd, rv = bind(sock_fd, (const struct sockaddr *) &sin,
(const struct sockaddr *) &sin, sizeof(struct sockaddr)); sizeof(struct sockaddr));
if (rv < 0) { if (rv < 0) {
close(sock_fd); close(sock_fd);
bip_set_socket(-1); bip_set_socket(-1);
+4 -5
View File
@@ -98,11 +98,10 @@ int dlmstp_send_pdu(
} }
memmove(&PDU_Buffer[mtu_len], pdu, pdu_len); memmove(&PDU_Buffer[mtu_len], pdu, pdu_len);
mtu_len += pdu_len; mtu_len += pdu_len;
bytes_sent = MSTP_Create_Frame( bytes_sent =
(uint8_t *) & MSTP_Port.TxBuffer[0], MSTP_Create_Frame((uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), sizeof(MSTP_Port.TxBuffer), MSTP_Port.TxFrameType, destination,
MSTP_Port.TxFrameType, MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
destination, MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
MSTP_Port.TxLength = bytes_sent; MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true; 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"); fprintf(stderr, "ethernet: failed to bind to socket!\r\n");
Ethernet_Address.sa_family = AF_INET; Ethernet_Address.sa_family = AF_INET;
memset(Ethernet_Address.sa_data, 0, sizeof(Ethernet_Address.sa_data)); memset(Ethernet_Address.sa_data, 0, sizeof(Ethernet_Address.sa_data));
if (bind(Ethernet_Socket, if (bind(Ethernet_Socket, &Ethernet_Address,
&Ethernet_Address, sizeof(Ethernet_Address)) == SOCKET_ERROR) sizeof(Ethernet_Address)) == SOCKET_ERROR)
fprintf(stderr, "ethernet: failed to bind to socket!\r\n"); fprintf(stderr, "ethernet: failed to bind to socket!\r\n");
/*setsockopt(Ethernet_Socket,SOL_SOCKET,SO_802_2,(char *)&value,sizeof(value)); */ /*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 */ /* using O_NONBLOCK and no data */
/* was immediately available for reading. */ /* was immediately available for reading. */
if (errno != EAGAIN) if (errno != EAGAIN)
fprintf(stderr, fprintf(stderr, "ethernet: Read error in receiving packet: %s\n",
"ethernet: Read error in receiving packet: %s\n",
strerror(errno)); strerror(errno));
return 0; return 0;
} }
+36 -49
View File
@@ -560,7 +560,8 @@ void MSTP_Receive_Frame_FSM(
#endif #endif
/* DataOctet */ /* DataOctet */
if (mstp_port->Index < mstp_port->DataLength) { 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->DataCRC);
mstp_port->InputBuffer[mstp_port->Index] = mstp_port->InputBuffer[mstp_port->Index] =
mstp_port->DataRegister; mstp_port->DataRegister;
@@ -569,14 +570,16 @@ void MSTP_Receive_Frame_FSM(
} }
/* CRC1 */ /* CRC1 */
else if (mstp_port->Index == mstp_port->DataLength) { 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->DataCRC);
mstp_port->Index++; mstp_port->Index++;
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;
} }
/* CRC2 */ /* CRC2 */
else if (mstp_port->Index == (mstp_port->DataLength + 1)) { 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); mstp_port->DataCRC);
/* STATE DATA CRC - no need for new state */ /* STATE DATA CRC - no need for new state */
/* indicate the complete reception of a valid frame */ /* indicate the complete reception of a valid frame */
@@ -708,26 +711,21 @@ bool MSTP_Master_Node_FSM(
#endif #endif
/* some calculations that several states need */ /* some calculations that several states need */
next_poll_station = (mstp_port->Poll_Station + 1) % next_poll_station =
(mstp_port->Nmax_master + 1); (mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1);
next_this_station = (mstp_port->This_Station + 1) % next_this_station =
(mstp_port->Nmax_master + 1); (mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1);
next_next_station = (mstp_port->Next_Station + 1) % next_next_station =
(mstp_port->Nmax_master + 1); (mstp_port->Next_Station + 1) % (mstp_port->Nmax_master + 1);
#if PRINT_ENABLED_MASTER #if PRINT_ENABLED_MASTER
if (mstp_port->master_state != master_state) { if (mstp_port->master_state != master_state) {
master_state = mstp_port->master_state; master_state = mstp_port->master_state;
fprintf(stderr, fprintf(stderr,
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n", "MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n",
mstp_port->This_Station, mstp_port->This_Station, next_this_station,
next_this_station, mstp_port->Next_Station, next_next_station,
mstp_port->Next_Station, mstp_port->Poll_Station, next_poll_station, mstp_port->EventCount,
next_next_station, mstp_port->TokenCount, mstp_port->SilenceTimer,
mstp_port->Poll_Station,
next_poll_station,
mstp_port->EventCount,
mstp_port->TokenCount,
mstp_port->SilenceTimer,
mstp_master_state_text(mstp_port->master_state)); mstp_master_state_text(mstp_port->master_state));
} }
#endif #endif
@@ -763,17 +761,14 @@ bool MSTP_Master_Node_FSM(
#if PRINT_ENABLED_MASTER #if PRINT_ENABLED_MASTER
fprintf(stderr, fprintf(stderr,
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n", "MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n",
mstp_port->SourceAddress, mstp_port->SourceAddress, mstp_port->DestinationAddress,
mstp_port->DestinationAddress, mstp_port->DataLength, mstp_port->FrameCount,
mstp_port->DataLength,
mstp_port->FrameCount,
mstp_port->SilenceTimer, mstp_port->SilenceTimer,
mstp_frame_type_text(mstp_port->FrameType)); mstp_frame_type_text(mstp_port->FrameType));
#endif #endif
/* destined for me! */ /* destined for me! */
if ((mstp_port->DestinationAddress == if ((mstp_port->DestinationAddress == mstp_port->This_Station)
mstp_port->This_Station) || || (mstp_port->DestinationAddress ==
(mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) { MSTP_BROADCAST_ADDRESS)) {
switch (mstp_port->FrameType) { switch (mstp_port->FrameType) {
/* ReceivedToken */ /* ReceivedToken */
@@ -964,10 +959,9 @@ bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */ /* address at which a new master node may be found in that case. */
mstp_port->TokenCount++; mstp_port->TokenCount++;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL,
mstp_port->Next_Station, 0);
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN; mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -991,10 +985,9 @@ bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */ /* ResetMaintenancePFM */
mstp_port->Poll_Station = mstp_port->This_Station; mstp_port->Poll_Station = mstp_port->This_Station;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL,
mstp_port->Next_Station, 0);
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */ mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
@@ -1004,8 +997,8 @@ bool MSTP_Master_Node_FSM(
/* SendMaintenancePFM */ /* SendMaintenancePFM */
mstp_port->Poll_Station = next_poll_station; mstp_port->Poll_Station = next_poll_station;
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
} }
@@ -1027,8 +1020,7 @@ bool MSTP_Master_Node_FSM(
/* RetrySendToken */ /* RetrySendToken */
mstp_port->RetryCount++; mstp_port->RetryCount++;
/* Transmit a Token frame to NS */ /* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL, mstp_port->Next_Station, mstp_port->This_Station, NULL,
0); 0);
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
@@ -1040,9 +1032,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_next_station; mstp_port->Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */ /* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, mstp_port->This_Station, NULL, 0);
0);
/* no known successor node */ /* no known successor node */
mstp_port->Next_Station = mstp_port->This_Station; mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
@@ -1079,9 +1070,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_this_station; mstp_port->Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */ /* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, mstp_port->This_Station, NULL, 0);
0);
/* indicate that the next station is unknown */ /* indicate that the next station is unknown */
mstp_port->Next_Station = mstp_port->This_Station; mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
@@ -1107,8 +1097,7 @@ bool MSTP_Master_Node_FSM(
mstp_port->Next_Station = mstp_port->SourceAddress; mstp_port->Next_Station = mstp_port->SourceAddress;
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
/* Transmit a Token frame to NS */ /* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL, mstp_port->Next_Station, mstp_port->This_Station, NULL,
0); 0);
mstp_port->Poll_Station = mstp_port->This_Station; mstp_port->Poll_Station = mstp_port->This_Station;
@@ -1141,8 +1130,7 @@ bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */ /* poll for a master at address PS. */
mstp_port->EventCount = 0; mstp_port->EventCount = 0;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, mstp_port->Next_Station, mstp_port->This_Station,
NULL, 0); NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
@@ -1214,8 +1202,7 @@ bool MSTP_Master_Node_FSM(
/* and enter the IDLE state. */ /* and enter the IDLE state. */
{ {
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_REPLY_POSTPONED, FRAME_TYPE_REPLY_POSTPONED, mstp_port->SourceAddress,
mstp_port->SourceAddress,
mstp_port->This_Station, NULL, 0); mstp_port->This_Station, NULL, 0);
mstp_port->master_state = MSTP_MASTER_STATE_IDLE; mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
transition_now = true; transition_now = true;
+15 -16
View File
@@ -214,8 +214,7 @@ static char *winsock_error_code_text(
case WSAEDISCON: case WSAEDISCON:
return "Disconnect."; return "Disconnect.";
case WSAHOST_NOT_FOUND: case WSAHOST_NOT_FOUND:
return "Host not found. " return "Host not found. " "This message indicates that the key "
"This message indicates that the key "
"(name, address, and so on) was not found."; "(name, address, and so on) was not found.";
case WSATRY_AGAIN: case WSATRY_AGAIN:
return "Nonauthoritative host not found. " return "Nonauthoritative host not found. "
@@ -251,8 +250,8 @@ bool bip_init(
/*Result = WSAStartup(MAKEWORD(2,2), &wd); */ /*Result = WSAStartup(MAKEWORD(2,2), &wd); */
if (Result != 0) { if (Result != 0) {
Code = WSAGetLastError(); Code = WSAGetLastError();
printf("TCP/IP stack initialization failed\n" printf("TCP/IP stack initialization failed\n" " error code: %i %s\n",
" error code: %i %s\n", Code, winsock_error_code_text(Code)); Code, winsock_error_code_text(Code));
exit(1); exit(1);
} }
atexit(cleanup); atexit(cleanup);
@@ -265,8 +264,8 @@ bool bip_init(
address.s_addr = gethostaddr(); address.s_addr = gethostaddr();
if (address.s_addr == (unsigned) -1) { if (address.s_addr == (unsigned) -1) {
Code = WSAGetLastError(); Code = WSAGetLastError();
printf("Get host address failed\n" printf("Get host address failed\n" " error code: %i %s\n", Code,
" error code: %i %s\n", Code, winsock_error_code_text(Code)); winsock_error_code_text(Code));
exit(1); exit(1);
} }
bip_set_addr(address.s_addr); bip_set_addr(address.s_addr);
@@ -282,8 +281,8 @@ bool bip_init(
broadcast_address.s_addr = htonl(bip_get_broadcast_addr()); broadcast_address.s_addr = htonl(bip_get_broadcast_addr());
fprintf(stderr, "IP Broadcast Address: %s\n", fprintf(stderr, "IP Broadcast Address: %s\n",
inet_ntoa(broadcast_address)); inet_ntoa(broadcast_address));
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", bip_get_port(),
bip_get_port(), bip_get_port()); bip_get_port());
} }
/* assumes that the driver has already been initialized */ /* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 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 */ /* Allow us to use the same socket for sending and receiving */
/* This makes sure that the src port is correct when sending */ /* This makes sure that the src port is correct when sending */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value,
(char *) &value, sizeof(value)); sizeof(value));
if (rv < 0) { if (rv < 0) {
fprintf(stderr, "bip: failed to set REUSEADDR socket option.\n"); fprintf(stderr, "bip: failed to set REUSEADDR socket option.\n");
close(sock_fd); close(sock_fd);
@@ -303,8 +302,8 @@ bool bip_init(
return false; return false;
} }
/* allow us to send a broadcast */ /* allow us to send a broadcast */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, (char *) &value,
(char *) &value, sizeof(value)); sizeof(value));
if (rv < 0) { if (rv < 0) {
fprintf(stderr, "bip: failed to set BROADCAST socket option.\n"); fprintf(stderr, "bip: failed to set BROADCAST socket option.\n");
close(sock_fd); close(sock_fd);
@@ -315,8 +314,8 @@ bool bip_init(
/* probably only for Apple... */ /* probably only for Apple... */
/* rebind a port that is already in use. /* rebind a port that is already in use.
Note: all users of the port must specify this flag */ Note: all users of the port must specify this flag */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT, rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT, (char *) &value,
(char *) &value, sizeof(value)); sizeof(value));
if (rv < 0) { if (rv < 0) {
fprintf(stderr, "bip: failed to set REUSEPORT socket option.\n"); fprintf(stderr, "bip: failed to set REUSEPORT socket option.\n");
close(sock_fd); close(sock_fd);
@@ -347,8 +346,8 @@ bool bip_init(
#endif #endif
sin.sin_port = htons(bip_get_port()); sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero)); memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
rv = bind(sock_fd, rv = bind(sock_fd, (const struct sockaddr *) &sin,
(const struct sockaddr *) &sin, sizeof(struct sockaddr)); sizeof(struct sockaddr));
if (rv < 0) { if (rv < 0) {
fprintf(stderr, "bip: failed to bind to %s port %hd\n", fprintf(stderr, "bip: failed to bind to %s port %hd\n",
inet_ntoa(sin.sin_addr), bip_get_port()); 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) { if (Receive_Packet.pdu_len) {
MSTP_Packets++; MSTP_Packets++;
if (src) { if (src) {
memmove(src, memmove(src, &Receive_Packet.address,
&Receive_Packet.address,
sizeof(Receive_Packet.address)); sizeof(Receive_Packet.address));
} }
if (pdu) { if (pdu) {
memmove(pdu, memmove(pdu, &Receive_Packet.pdu,
&Receive_Packet.pdu, sizeof(Receive_Packet.pdu)); sizeof(Receive_Packet.pdu));
} }
pdu_len = Receive_Packet.pdu_len; pdu_len = Receive_Packet.pdu_len;
} }
@@ -301,11 +300,9 @@ uint16_t MSTP_Get_Send(
} }
/* convert the PDU into the MSTP Frame */ /* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */ pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize, mstp_port->OutputBufferSize, Transmit_Packet.frame_type, destination,
Transmit_Packet.frame_type, mstp_port->This_Station, &Transmit_Packet.pdu[0],
destination, Transmit_Packet.pdu_len);
mstp_port->This_Station,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
Transmit_Packet.ready = false; Transmit_Packet.ready = false;
return pdu_len; return pdu_len;
@@ -336,8 +333,9 @@ bool dlmstp_compare_data_expecting_reply(
/* decode the request data */ /* decode the request data */
request.address.mac[0] = src_address; request.address.mac[0] = src_address;
request.address.mac_len = 1; request.address.mac_len = 1;
offset = npdu_decode(&request_pdu[0], offset =
NULL, &request.address, &request.npdu_data); npdu_decode(&request_pdu[0], NULL, &request.address,
&request.npdu_data);
if (request.npdu_data.network_layer_message) { if (request.npdu_data.network_layer_message) {
return false; return false;
} }
@@ -353,8 +351,8 @@ bool dlmstp_compare_data_expecting_reply(
request.service_choice = request_pdu[offset + 3]; request.service_choice = request_pdu[offset + 3];
/* decode the reply data */ /* decode the reply data */
bacnet_address_copy(&reply.address, dest_address); bacnet_address_copy(&reply.address, dest_address);
offset = npdu_decode(&reply_pdu[0], offset =
&reply.address, NULL, &reply.npdu_data); npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
if (reply.npdu_data.network_layer_message) { if (reply.npdu_data.network_layer_message) {
return false; return false;
} }
@@ -443,19 +441,18 @@ uint16_t MSTP_Get_Reply(
return 0; return 0;
} }
/* is this the reply to the DER? */ /* is this the reply to the DER? */
matched = dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0], matched =
mstp_port->DataLength, dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
mstp_port->SourceAddress, mstp_port->DataLength, mstp_port->SourceAddress,
&Transmit_Packet.pdu[0], &Transmit_Packet.pdu[0], Transmit_Packet.pdu_len,
Transmit_Packet.pdu_len, &Transmit_Packet.address); &Transmit_Packet.address);
if (!matched) if (!matched)
return 0; return 0;
/* convert the PDU into the MSTP Frame */ /* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */ pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize, mstp_port->OutputBufferSize, Transmit_Packet.frame_type, destination,
Transmit_Packet.frame_type, mstp_port->This_Station, &Transmit_Packet.pdu[0],
destination, mstp_port->This_Station, Transmit_Packet.pdu_len);
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
Transmit_Packet.ready = false; Transmit_Packet.ready = false;
return pdu_len; return pdu_len;
@@ -721,8 +718,7 @@ int main(
for (;;) { for (;;) {
pdu_len = dlmstp_receive(NULL, NULL, 0, INFINITE); pdu_len = dlmstp_receive(NULL, NULL, 0, INFINITE);
#if 0 #if 0
MSTP_Create_And_Send_Frame(&MSTP_Port, MSTP_Create_And_Send_Frame(&MSTP_Port, FRAME_TYPE_TEST_REQUEST,
FRAME_TYPE_TEST_REQUEST,
MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0); MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0);
#endif #endif
} }
+10 -12
View File
@@ -155,8 +155,8 @@ bool ethernet_init(
*/ */
/* Retrieve the device list */ /* Retrieve the device list */
if (pcap_findalldevs(&pcap_all_if, pcap_errbuf) == -1) { if (pcap_findalldevs(&pcap_all_if, pcap_errbuf) == -1) {
sprintf(msgBuf, sprintf(msgBuf, "ethernet.c: error in pcap_findalldevs: %s\n",
"ethernet.c: error in pcap_findalldevs: %s\n", pcap_errbuf); pcap_errbuf);
LogError(msgBuf); LogError(msgBuf);
return false; return false;
} }
@@ -167,8 +167,8 @@ bool ethernet_init(
} }
pcap_freealldevs(pcap_all_if); /* we don't need it anymore */ pcap_freealldevs(pcap_all_if); /* we don't need it anymore */
if (dev == NULL) { if (dev == NULL) {
sprintf(msgBuf, sprintf(msgBuf, "ethernet.c: specified interface not found: %s\n",
"ethernet.c: specified interface not found: %s\n", if_name); if_name);
LogError(msgBuf); LogError(msgBuf);
return false; return false;
} }
@@ -180,8 +180,8 @@ bool ethernet_init(
lpAdapter = PacketOpenAdapter(if_name); lpAdapter = PacketOpenAdapter(if_name);
if (lpAdapter == NULL) { if (lpAdapter == NULL) {
ethernet_cleanup(); ethernet_cleanup();
sprintf(msgBuf, sprintf(msgBuf, "ethernet.c: error in PacketOpenAdapter(\"%s\")\n",
"ethernet.c: error in PacketOpenAdapter(\"%s\")\n", if_name); if_name);
LogError(msgBuf); LogError(msgBuf);
return false; return false;
} }
@@ -284,8 +284,7 @@ int ethernet_send(
if (pcap_sendpacket(pcap_eth802_fp, mtu, mtu_len) != 0) { if (pcap_sendpacket(pcap_eth802_fp, mtu, mtu_len) != 0) {
/* did it get sent? */ /* did it get sent? */
char msgBuf[200]; char msgBuf[200];
sprintf(msgBuf, sprintf(msgBuf, "ethernet.c: error sending packet: %s\n",
"ethernet.c: error sending packet: %s\n",
pcap_geterr(pcap_eth802_fp)); pcap_geterr(pcap_eth802_fp));
LogError(msgBuf); LogError(msgBuf);
return -5; return -5;
@@ -342,8 +341,7 @@ uint16_t ethernet_receive(
res = pcap_next_ex(pcap_eth802_fp, &header, &pkt_data); res = pcap_next_ex(pcap_eth802_fp, &header, &pkt_data);
if (res < 0) { if (res < 0) {
char msgBuf[200]; char msgBuf[200];
sprintf(msgBuf, sprintf(msgBuf, "ethernet.c: error in receiving packet: %s\n",
"ethernet.c: error in receiving packet: %s\n",
pcap_geterr(pcap_eth802_fp)); pcap_geterr(pcap_eth802_fp));
return 0; return 0;
} else if (res == 0) } else if (res == 0)
@@ -445,8 +443,8 @@ void ethernet_debug_address(
} }
/* if */ /* if */
if (dest) { if (dest) {
sprintf(msgBuf, sprintf(msgBuf, "Address:\n MAC Length=%d\n MAC Address=",
"Address:\n MAC Length=%d\n MAC Address=", dest->mac_len); dest->mac_len);
LogInfo(msgBuf); LogInfo(msgBuf);
for (i = 0; i < MAX_MAC_LEN; i++) { for (i = 0; i < MAX_MAC_LEN; i++) {
sprintf(msgBuf, "%02X ", (unsigned) dest->mac[i]); sprintf(msgBuf, "%02X ", (unsigned) dest->mac[i]);
+5 -4
View File
@@ -105,8 +105,8 @@ static void Read_Properties(
next_device = true; next_device = true;
else { else {
status = Send_Read_Property_Request(device_id, /* destination device */ status = Send_Read_Property_Request(device_id, /* destination device */
OBJECT_DEVICE, OBJECT_DEVICE, device_id, object_props[property],
device_id, object_props[property], BACNET_ARRAY_ALL); BACNET_ARRAY_ALL);
if (status) if (status)
property++; property++;
} }
@@ -137,8 +137,9 @@ static void LocalIAmHandler(
(void) src; (void) src;
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len =
&device_id, &max_apdu, &segmentation, &vendor_id); iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
fprintf(stderr, "Received I-Am Request"); fprintf(stderr, "Received I-Am Request");
if (len != -1) { if (len != -1) {
fprintf(stderr, " from %u!\n", device_id); 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_Initialize(
void) void)
{ {
RS485_Handle = CreateFile(RS485_Port_Name, RS485_Handle =
GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, CreateFile(RS485_Port_Name, GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING,
/*FILE_FLAG_OVERLAPPED */ 0, /*FILE_FLAG_OVERLAPPED */ 0,
0); 0);
if (RS485_Handle == INVALID_HANDLE_VALUE) { 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, */ /* Data CRC: (present only if Length is non-zero) two octets, */
/* least significant octet first */ /* least significant octet first */
/* (pad): (optional) at most one octet of padding: X'FF' */ /* (pad): (optional) at most one octet of padding: X'FF' */
fprintf(stderr, fprintf(stderr, "55 FF %02X %02X %02X %02X %02X %02X ",
"55 FF %02X %02X %02X %02X %02X %02X ", mstp_port->FrameType, mstp_port->DestinationAddress,
mstp_port->FrameType, mstp_port->SourceAddress, HI_BYTE(mstp_port->DataLength),
mstp_port->DestinationAddress,
mstp_port->SourceAddress,
HI_BYTE(mstp_port->DataLength),
LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual); LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual);
if (mstp_port->DataLength) { if (mstp_port->DataLength) {
for (i = 0; i < mstp_port->DataLength; i++) { for (i = 0; i < mstp_port->DataLength; i++) {
fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]); fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]);
} }
fprintf(stderr, fprintf(stderr, "%02X %02X ", mstp_port->DataCRCActualMSB,
"%02X %02X ", mstp_port->DataCRCActualLSB);
mstp_port->DataCRCActualMSB, mstp_port->DataCRCActualLSB);
} }
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType)); fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
fprintf(stderr, "\n"); fprintf(stderr, "\n");
+18 -12
View File
@@ -103,8 +103,9 @@ int abort_decode_apdu(
else else
*server = false; *server = false;
if (apdu_len > 1) { if (apdu_len > 1) {
len = abort_decode_service_request(&apdu[1], len =
apdu_len - 1, invoke_id, abort_reason); abort_decode_service_request(&apdu[1], apdu_len - 1, invoke_id,
abort_reason);
} }
} }
@@ -127,8 +128,9 @@ void testAbortAPDU(
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server); len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
apdu_len = len; apdu_len = len;
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
len = abort_decode_apdu(&apdu[0], len =
apdu_len, &test_invoke_id, &test_abort_reason, &test_server); abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason); ct_test(pTest, test_abort_reason == abort_reason);
@@ -154,8 +156,9 @@ void testAbort(
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server); len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
apdu_len = len; apdu_len = len;
len = abort_decode_apdu(&apdu[0], len =
apdu_len, &test_invoke_id, &test_abort_reason, &test_server); abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason); ct_test(pTest, test_abort_reason == abort_reason);
@@ -163,18 +166,21 @@ void testAbort(
/* change type to get negative response */ /* change type to get negative response */
apdu[0] = PDU_TYPE_REJECT; apdu[0] = PDU_TYPE_REJECT;
len = abort_decode_apdu(&apdu[0], len =
apdu_len, &test_invoke_id, &test_abort_reason, &test_server); abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len == -1); ct_test(pTest, len == -1);
/* test NULL APDU */ /* test NULL APDU */
len = abort_decode_apdu(NULL, len =
apdu_len, &test_invoke_id, &test_abort_reason, &test_server); abort_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_abort_reason,
&test_server);
ct_test(pTest, len == -1); ct_test(pTest, len == -1);
/* force a zero length */ /* force a zero length */
len = abort_decode_apdu(&apdu[0], len =
0, &test_invoke_id, &test_abort_reason, &test_server); abort_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_abort_reason,
&test_server);
ct_test(pTest, len == 0); ct_test(pTest, len == 0);
/* check them all... */ /* check them all... */
+3 -4
View File
@@ -59,8 +59,7 @@ void address_remove_device(
unsigned i; unsigned i;
for (i = 0; i < MAX_ADDRESS_CACHE; i++) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if ((Address_Cache[i].valid || if ((Address_Cache[i].valid || Address_Cache[i].bind_request) &&
Address_Cache[i].bind_request) &&
(Address_Cache[i].device_id == device_id)) { (Address_Cache[i].device_id == device_id)) {
Address_Cache[i].valid = false; Address_Cache[i].valid = false;
break; break;
@@ -320,8 +319,8 @@ void testAddress(
&test_address)); &test_address));
ct_test(pTest, test_max_apdu == max_apdu); ct_test(pTest, test_max_apdu == max_apdu);
ct_test(pTest, bacnet_address_same(&test_address, &src)); ct_test(pTest, bacnet_address_same(&test_address, &src));
ct_test(pTest, address_get_by_index(i, &test_device_id, ct_test(pTest, address_get_by_index(i, &test_device_id, &test_max_apdu,
&test_max_apdu, &test_address)); &test_address));
ct_test(pTest, test_device_id == device_id); ct_test(pTest, test_device_id == device_id);
ct_test(pTest, test_max_apdu == max_apdu); ct_test(pTest, test_max_apdu == max_apdu);
ct_test(pTest, bacnet_address_same(&test_address, &src)); ct_test(pTest, bacnet_address_same(&test_address, &src));
+3 -5
View File
@@ -304,9 +304,8 @@ void apdu_handler(
switch (apdu[0] & 0xF0) { switch (apdu[0] & 0xF0) {
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST: case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */ len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */
apdu_len, apdu_len, &service_data, &service_choice, &service_request,
&service_data, &service_request_len);
&service_choice, &service_request, &service_request_len);
/* When network communications are completely disabled, /* When network communications are completely disabled,
only DeviceCommunicationControl and ReinitializeDevice APDUs only DeviceCommunicationControl and ReinitializeDevice APDUs
shall be processed and no messages shall be initiated. */ shall be processed and no messages shall be initiated. */
@@ -437,8 +436,7 @@ void apdu_handler(
len += decode_enumerated(&apdu[len], len_value, &error_code); len += decode_enumerated(&apdu[len], len_value, &error_code);
if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) { if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) {
if (Error_Function[service_choice]) if (Error_Function[service_choice])
Error_Function[service_choice] (src, Error_Function[service_choice] (src, invoke_id,
invoke_id,
(BACNET_ERROR_CLASS) error_class, (BACNET_ERROR_CLASS) error_class,
(BACNET_ERROR_CODE) error_code); (BACNET_ERROR_CODE) error_code);
} }
+100 -63
View File
@@ -55,22 +55,27 @@ int arf_encode_apdu(
apdu[2] = invoke_id; apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */ apdu[3] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */
apdu_len = 4; apdu_len = 4;
apdu_len += encode_application_object_id(&apdu[apdu_len], apdu_len +=
data->object_type, data->object_instance); encode_application_object_id(&apdu[apdu_len], data->object_type,
data->object_instance);
switch (data->access) { switch (data->access) {
case FILE_STREAM_ACCESS: case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0); apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len], apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition); data->type.stream.fileStartPosition);
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.stream.requestedOctetCount); data->type.stream.requestedOctetCount);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0); apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break; break;
case FILE_RECORD_ACCESS: case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1); apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len], apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord); data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.RecordCount); data->type.record.RecordCount);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1); apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break; break;
@@ -108,21 +113,25 @@ int arf_decode_service_request(
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
len++; len++;
/* fileStartPosition */ /* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1; return -1;
len += decode_signed(&apdu[len], len +=
len_value_type, &data->type.stream.fileStartPosition); decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
/* requestedOctetCount */ /* requestedOctetCount */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1; return -1;
len += decode_unsigned(&apdu[len], len +=
len_value_type, &data->type.stream.requestedOctetCount); decode_unsigned(&apdu[len], len_value_type,
&data->type.stream.requestedOctetCount);
if (!decode_is_closing_tag_number(&apdu[len], 0)) if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1; return -1;
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
@@ -132,21 +141,25 @@ int arf_decode_service_request(
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
len++; len++;
/* fileStartRecord */ /* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1; return -1;
len += decode_signed(&apdu[len], len +=
len_value_type, &data->type.record.fileStartRecord); decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
/* RecordCount */ /* RecordCount */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1; return -1;
len += decode_unsigned(&apdu[len], len +=
len_value_type, &data->type.record.RecordCount); decode_unsigned(&apdu[len], len_value_type,
&data->type.record.RecordCount);
if (!decode_is_closing_tag_number(&apdu[len], 1)) if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1; return -1;
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
@@ -179,8 +192,8 @@ int arf_decode_apdu(
offset = 4; offset = 4;
if (apdu_len > offset) { if (apdu_len > offset) {
len = arf_decode_service_request(&apdu[offset], len =
apdu_len - offset, data); arf_decode_service_request(&apdu[offset], apdu_len - offset, data);
} }
return len; return len;
@@ -205,19 +218,24 @@ int arf_ack_encode_apdu(
switch (data->access) { switch (data->access) {
case FILE_STREAM_ACCESS: case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0); apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len], apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition); data->type.stream.fileStartPosition);
apdu_len += encode_application_octet_string(&apdu[apdu_len], apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData); &data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0); apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break; break;
case FILE_RECORD_ACCESS: case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1); apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len], apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord); data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.RecordCount); data->type.record.RecordCount);
apdu_len += encode_application_octet_string(&apdu[apdu_len], apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData); &data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1); apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break; break;
@@ -253,21 +271,25 @@ int arf_ack_decode_service_request(
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
len++; len++;
/* fileStartPosition */ /* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1; return -1;
len += decode_signed(&apdu[len], len +=
len_value_type, &data->type.stream.fileStartPosition); decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
/* fileData */ /* fileData */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1; return -1;
len += decode_octet_string(&apdu[len], len +=
len_value_type, &data->fileData); decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 0)) if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1; return -1;
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
@@ -277,29 +299,35 @@ int arf_ack_decode_service_request(
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
len++; len++;
/* fileStartRecord */ /* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1; return -1;
len += decode_signed(&apdu[len], len +=
len_value_type, &data->type.record.fileStartRecord); decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
/* returnedRecordCount */ /* returnedRecordCount */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1; return -1;
len += decode_unsigned(&apdu[len], len +=
len_value_type, &data->type.record.RecordCount); decode_unsigned(&apdu[len], len_value_type,
&data->type.record.RecordCount);
/* fileData */ /* fileData */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1; return -1;
len += decode_octet_string(&apdu[len], len +=
len_value_type, &data->fileData); decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 1)) if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1; return -1;
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
@@ -331,8 +359,9 @@ int arf_ack_decode_apdu(
offset = 3; offset = 3;
if (apdu_len > offset) { if (apdu_len > offset) {
len = arf_ack_decode_service_request(&apdu[offset], len =
apdu_len - offset, data); arf_ack_decode_service_request(&apdu[offset], apdu_len - offset,
data);
} }
return len; return len;
@@ -364,15 +393,19 @@ void testAtomicReadFileAckAccess(
ct_test(pTest, test_data.endOfFile == data->endOfFile); ct_test(pTest, test_data.endOfFile == data->endOfFile);
ct_test(pTest, test_data.access == data->access); ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) { if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition == ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition); data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) { } else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord == ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord); data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.RecordCount == ct_test(pTest,
test_data.type.record.RecordCount ==
data->type.record.RecordCount); data->type.record.RecordCount);
} }
ct_test(pTest, octetstring_length(&test_data.fileData) == ct_test(pTest,
octetstring_length(&test_data.fileData) ==
octetstring_length(&data->fileData)); octetstring_length(&data->fileData));
ct_test(pTest, memcmp(octetstring_value(&test_data.fileData), ct_test(pTest, memcmp(octetstring_value(&test_data.fileData),
octetstring_value(&data->fileData), octetstring_value(&data->fileData),
@@ -389,16 +422,16 @@ void testAtomicReadFileAck(
data.endOfFile = true; data.endOfFile = true;
data.access = FILE_STREAM_ACCESS; data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = 0; data.type.stream.fileStartPosition = 0;
octetstring_init(&data.fileData, octetstring_init(&data.fileData, test_octet_string,
test_octet_string, sizeof(test_octet_string)); sizeof(test_octet_string));
testAtomicReadFileAckAccess(pTest, &data); testAtomicReadFileAckAccess(pTest, &data);
data.endOfFile = false; data.endOfFile = false;
data.access = FILE_RECORD_ACCESS; data.access = FILE_RECORD_ACCESS;
data.type.record.fileStartRecord = 1; data.type.record.fileStartRecord = 1;
data.type.record.RecordCount = 2; data.type.record.RecordCount = 2;
octetstring_init(&data.fileData, octetstring_init(&data.fileData, test_octet_string,
test_octet_string, sizeof(test_octet_string)); sizeof(test_octet_string));
testAtomicReadFileAckAccess(pTest, &data); testAtomicReadFileAckAccess(pTest, &data);
return; return;
@@ -425,14 +458,18 @@ void testAtomicReadFileAccess(
ct_test(pTest, test_data.object_instance == data->object_instance); ct_test(pTest, test_data.object_instance == data->object_instance);
ct_test(pTest, test_data.access == data->access); ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) { if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition == ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition); data->type.stream.fileStartPosition);
ct_test(pTest, test_data.type.stream.requestedOctetCount == ct_test(pTest,
test_data.type.stream.requestedOctetCount ==
data->type.stream.requestedOctetCount); data->type.stream.requestedOctetCount);
} else if (test_data.access == FILE_RECORD_ACCESS) { } else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord == ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord); data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.RecordCount == ct_test(pTest,
test_data.type.record.RecordCount ==
data->type.record.RecordCount); data->type.record.RecordCount);
} }
} }
+66 -43
View File
@@ -55,24 +55,30 @@ int awf_encode_apdu(
apdu[2] = invoke_id; apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */ apdu[3] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */
apdu_len = 4; apdu_len = 4;
apdu_len += encode_application_object_id(&apdu[apdu_len], apdu_len +=
data->object_type, data->object_instance); encode_application_object_id(&apdu[apdu_len], data->object_type,
data->object_instance);
switch (data->access) { switch (data->access) {
case FILE_STREAM_ACCESS: case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0); apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len], apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition); data->type.stream.fileStartPosition);
apdu_len += encode_application_octet_string(&apdu[apdu_len], apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData); &data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0); apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break; break;
case FILE_RECORD_ACCESS: case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1); apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len], apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord); data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.returnedRecordCount); data->type.record.returnedRecordCount);
apdu_len += encode_application_octet_string(&apdu[apdu_len], apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData); &data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1); apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break; break;
@@ -112,21 +118,24 @@ int awf_decode_service_request(
/* a tag number of 2 is not extended so only one octet */ /* a tag number of 2 is not extended so only one octet */
len++; len++;
/* fileStartPosition */ /* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1; return -1;
len += decode_signed(&apdu[len], len_value_type, &signed_value); len += decode_signed(&apdu[len], len_value_type, &signed_value);
data->type.stream.fileStartPosition = signed_value; data->type.stream.fileStartPosition = signed_value;
/* fileData */ /* fileData */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1; return -1;
len += decode_octet_string(&apdu[len], len +=
len_value_type, &data->fileData); decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 0)) if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1; return -1;
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
@@ -136,30 +145,34 @@ int awf_decode_service_request(
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
len++; len++;
/* fileStartRecord */ /* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1; return -1;
len += decode_signed(&apdu[len], len_value_type, &signed_value); len += decode_signed(&apdu[len], len_value_type, &signed_value);
data->type.record.fileStartRecord = signed_value; data->type.record.fileStartRecord = signed_value;
/* returnedRecordCount */ /* returnedRecordCount */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1; return -1;
len += decode_unsigned(&apdu[len], len_value_type, len +=
&unsigned_value); decode_unsigned(&apdu[len], len_value_type, &unsigned_value);
data->type.record.returnedRecordCount = unsigned_value; data->type.record.returnedRecordCount = unsigned_value;
/* fileData */ /* fileData */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len; len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1; return -1;
len += decode_octet_string(&apdu[len], len +=
len_value_type, &data->fileData); decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 1)) if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1; return -1;
/* a tag number is not extended so only one octet */ /* a tag number is not extended so only one octet */
@@ -192,8 +205,8 @@ int awf_decode_apdu(
offset = 4; offset = 4;
if (apdu_len > offset) { if (apdu_len > offset) {
len = awf_decode_service_request(&apdu[offset], len =
apdu_len - offset, data); awf_decode_service_request(&apdu[offset], apdu_len - offset, data);
} }
return len; return len;
@@ -213,11 +226,13 @@ int awf_ack_encode_apdu(
apdu_len = 3; apdu_len = 3;
switch (data->access) { switch (data->access) {
case FILE_STREAM_ACCESS: case FILE_STREAM_ACCESS:
apdu_len += encode_context_signed(&apdu[apdu_len], 0, apdu_len +=
encode_context_signed(&apdu[apdu_len], 0,
data->type.stream.fileStartPosition); data->type.stream.fileStartPosition);
break; break;
case FILE_RECORD_ACCESS: case FILE_RECORD_ACCESS:
apdu_len += encode_context_signed(&apdu[apdu_len], 1, apdu_len +=
encode_context_signed(&apdu[apdu_len], 1,
data->type.record.fileStartRecord); data->type.record.fileStartRecord);
break; break;
default: default:
@@ -245,12 +260,14 @@ int awf_ack_decode_service_request(
&len_value_type); &len_value_type);
if (tag_number == 0) { if (tag_number == 0) {
data->access = FILE_STREAM_ACCESS; data->access = FILE_STREAM_ACCESS;
len += decode_signed(&apdu[len], len +=
len_value_type, &data->type.stream.fileStartPosition); decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
} else if (tag_number == 1) { } else if (tag_number == 1) {
data->access = FILE_RECORD_ACCESS; data->access = FILE_RECORD_ACCESS;
len += decode_signed(&apdu[len], len +=
len_value_type, &data->type.record.fileStartRecord); decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
} else } else
return -1; return -1;
} }
@@ -278,8 +295,8 @@ int awf_ack_decode_apdu(
offset = 3; offset = 3;
if (apdu_len > offset) { if (apdu_len > offset) {
len = awf_decode_service_request(&apdu[offset], len =
apdu_len - offset, data); awf_decode_service_request(&apdu[offset], apdu_len - offset, data);
} }
return len; return len;
@@ -311,15 +328,19 @@ void testAtomicWriteFileAccess(
ct_test(pTest, test_data.object_instance == data->object_instance); ct_test(pTest, test_data.object_instance == data->object_instance);
ct_test(pTest, test_data.access == data->access); ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) { if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition == ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition); data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) { } else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord == ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord); data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.returnedRecordCount == ct_test(pTest,
test_data.type.record.returnedRecordCount ==
data->type.record.returnedRecordCount); data->type.record.returnedRecordCount);
} }
ct_test(pTest, octetstring_length(&test_data.fileData) == ct_test(pTest,
octetstring_length(&test_data.fileData) ==
octetstring_length(&data->fileData)); octetstring_length(&data->fileData));
ct_test(pTest, memcmp(octetstring_value(&test_data.fileData), ct_test(pTest, memcmp(octetstring_value(&test_data.fileData),
octetstring_value(&data->fileData), octetstring_value(&data->fileData),
@@ -336,8 +357,8 @@ void testAtomicWriteFile(
data.object_instance = 1; data.object_instance = 1;
data.access = FILE_STREAM_ACCESS; data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = 0; data.type.stream.fileStartPosition = 0;
octetstring_init(&data.fileData, octetstring_init(&data.fileData, test_octet_string,
test_octet_string, sizeof(test_octet_string)); sizeof(test_octet_string));
testAtomicWriteFileAccess(pTest, &data); testAtomicWriteFileAccess(pTest, &data);
data.object_type = OBJECT_FILE; data.object_type = OBJECT_FILE;
@@ -345,8 +366,8 @@ void testAtomicWriteFile(
data.access = FILE_RECORD_ACCESS; data.access = FILE_RECORD_ACCESS;
data.type.record.fileStartRecord = 1; data.type.record.fileStartRecord = 1;
data.type.record.returnedRecordCount = 2; data.type.record.returnedRecordCount = 2;
octetstring_init(&data.fileData, octetstring_init(&data.fileData, test_octet_string,
test_octet_string, sizeof(test_octet_string)); sizeof(test_octet_string));
testAtomicWriteFileAccess(pTest, &data); testAtomicWriteFileAccess(pTest, &data);
return; return;
@@ -371,10 +392,12 @@ void testAtomicWriteFileAckAccess(
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_data.access == data->access); ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) { if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition == ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition); data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) { } else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord == ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord); data->type.record.fileStartRecord);
} }
} }
+135 -89
View File
@@ -62,19 +62,21 @@ int bacapp_encode_application_data(
#endif #endif
#if defined (BACAPP_BOOLEAN) #if defined (BACAPP_BOOLEAN)
case BACNET_APPLICATION_TAG_BOOLEAN: case BACNET_APPLICATION_TAG_BOOLEAN:
apdu_len = encode_application_boolean(&apdu[0], apdu_len =
value->type.Boolean); encode_application_boolean(&apdu[0], value->type.Boolean);
break; break;
#endif #endif
#if defined (BACAPP_UNSIGNED) #if defined (BACAPP_UNSIGNED)
case BACNET_APPLICATION_TAG_UNSIGNED_INT: case BACNET_APPLICATION_TAG_UNSIGNED_INT:
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
encode_application_unsigned(&apdu[0],
value->type.Unsigned_Int); value->type.Unsigned_Int);
break; break;
#endif #endif
#if defined (BACAPP_SIGNED) #if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT: case BACNET_APPLICATION_TAG_SIGNED_INT:
apdu_len = encode_application_signed(&apdu[0], apdu_len =
encode_application_signed(&apdu[0],
value->type.Signed_Int); value->type.Signed_Int);
break; break;
#endif #endif
@@ -86,31 +88,35 @@ int bacapp_encode_application_data(
#if defined (BACAPP_DOUBLE) #if defined (BACAPP_DOUBLE)
case BACNET_APPLICATION_TAG_DOUBLE: case BACNET_APPLICATION_TAG_DOUBLE:
/* FIXME: double is not implemented yet. */ /* FIXME: double is not implemented yet. */
apdu_len = encode_application_double(&apdu[0], apdu_len =
value->type.Double); encode_application_double(&apdu[0], value->type.Double);
break; break;
#endif #endif
#if defined (BACAPP_OCTET_STRING) #if defined (BACAPP_OCTET_STRING)
case BACNET_APPLICATION_TAG_OCTET_STRING: case BACNET_APPLICATION_TAG_OCTET_STRING:
apdu_len = encode_application_octet_string(&apdu[0], apdu_len =
encode_application_octet_string(&apdu[0],
&value->type.Octet_String); &value->type.Octet_String);
break; break;
#endif #endif
#if defined (BACAPP_CHARACTER_STRING) #if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING: case BACNET_APPLICATION_TAG_CHARACTER_STRING:
apdu_len = encode_application_character_string(&apdu[0], apdu_len =
encode_application_character_string(&apdu[0],
&value->type.Character_String); &value->type.Character_String);
break; break;
#endif #endif
#if defined (BACAPP_BIT_STRING) #if defined (BACAPP_BIT_STRING)
case BACNET_APPLICATION_TAG_BIT_STRING: case BACNET_APPLICATION_TAG_BIT_STRING:
apdu_len = encode_application_bitstring(&apdu[0], apdu_len =
encode_application_bitstring(&apdu[0],
&value->type.Bit_String); &value->type.Bit_String);
break; break;
#endif #endif
#if defined (BACAPP_ENUMERATED) #if defined (BACAPP_ENUMERATED)
case BACNET_APPLICATION_TAG_ENUMERATED: case BACNET_APPLICATION_TAG_ENUMERATED:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
encode_application_enumerated(&apdu[0],
value->type.Enumerated); value->type.Enumerated);
break; break;
#endif #endif
@@ -128,7 +134,8 @@ int bacapp_encode_application_data(
#endif #endif
#if defined (BACAPP_OBJECT_ID) #if defined (BACAPP_OBJECT_ID)
case BACNET_APPLICATION_TAG_OBJECT_ID: case BACNET_APPLICATION_TAG_OBJECT_ID:
apdu_len = encode_application_object_id(&apdu[0], apdu_len =
encode_application_object_id(&apdu[0],
value->type.Object_Id.type, value->type.Object_Id.type,
value->type.Object_Id.instance); value->type.Object_Id.instance);
break; break;
@@ -166,14 +173,16 @@ int bacapp_decode_data(
#endif #endif
#if defined (BACAPP_UNSIGNED) #if defined (BACAPP_UNSIGNED)
case BACNET_APPLICATION_TAG_UNSIGNED_INT: case BACNET_APPLICATION_TAG_UNSIGNED_INT:
len = decode_unsigned(&apdu[0], len =
len_value_type, &value->type.Unsigned_Int); decode_unsigned(&apdu[0], len_value_type,
&value->type.Unsigned_Int);
break; break;
#endif #endif
#if defined (BACAPP_SIGNED) #if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT: case BACNET_APPLICATION_TAG_SIGNED_INT:
len = decode_signed(&apdu[0], len =
len_value_type, &value->type.Signed_Int); decode_signed(&apdu[0], len_value_type,
&value->type.Signed_Int);
break; break;
#endif #endif
#if defined (BACAPP_REAL) #if defined (BACAPP_REAL)
@@ -188,26 +197,30 @@ int bacapp_decode_data(
#endif #endif
#if defined (BACAPP_OCTET_STRING) #if defined (BACAPP_OCTET_STRING)
case BACNET_APPLICATION_TAG_OCTET_STRING: case BACNET_APPLICATION_TAG_OCTET_STRING:
len = decode_octet_string(&apdu[0], len =
len_value_type, &value->type.Octet_String); decode_octet_string(&apdu[0], len_value_type,
&value->type.Octet_String);
break; break;
#endif #endif
#if defined (BACAPP_CHARACTER_STRING) #if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING: case BACNET_APPLICATION_TAG_CHARACTER_STRING:
len = decode_character_string(&apdu[0], len =
len_value_type, &value->type.Character_String); decode_character_string(&apdu[0], len_value_type,
&value->type.Character_String);
break; break;
#endif #endif
#if defined (BACAPP_BIT_STRING) #if defined (BACAPP_BIT_STRING)
case BACNET_APPLICATION_TAG_BIT_STRING: case BACNET_APPLICATION_TAG_BIT_STRING:
len = decode_bitstring(&apdu[0], len =
len_value_type, &value->type.Bit_String); decode_bitstring(&apdu[0], len_value_type,
&value->type.Bit_String);
break; break;
#endif #endif
#if defined (BACAPP_ENUMERATED) #if defined (BACAPP_ENUMERATED)
case BACNET_APPLICATION_TAG_ENUMERATED: case BACNET_APPLICATION_TAG_ENUMERATED:
len = decode_enumerated(&apdu[0], len =
len_value_type, &value->type.Enumerated); decode_enumerated(&apdu[0], len_value_type,
&value->type.Enumerated);
break; break;
#endif #endif
#if defined (BACAPP_DATE) #if defined (BACAPP_DATE)
@@ -253,13 +266,15 @@ int bacapp_decode_application_data(
max_apdu_len = max_apdu_len; max_apdu_len = max_apdu_len;
if (apdu && value && !decode_is_context_specific(apdu)) { if (apdu && value && !decode_is_context_specific(apdu)) {
value->context_specific = false; value->context_specific = false;
tag_len = decode_tag_number_and_value(&apdu[0], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[0], &tag_number,
&len_value_type);
if (tag_len) { if (tag_len) {
len += tag_len; len += tag_len;
value->tag = tag_number; value->tag = tag_number;
len += bacapp_decode_data(&apdu[len], len +=
tag_number, len_value_type, value); bacapp_decode_data(&apdu[len], tag_number, len_value_type,
value);
} }
value->next = NULL; value->next = NULL;
} }
@@ -283,7 +298,8 @@ int bacapp_encode_context_data_value(
#endif #endif
#if defined (BACAPP_BOOLEAN) #if defined (BACAPP_BOOLEAN)
case BACNET_APPLICATION_TAG_BOOLEAN: case BACNET_APPLICATION_TAG_BOOLEAN:
apdu_len = encode_context_boolean(&apdu[0], context_tag_number, apdu_len =
encode_context_boolean(&apdu[0], context_tag_number,
value->type.Boolean); value->type.Boolean);
break; break;
#endif #endif
@@ -296,20 +312,23 @@ int bacapp_encode_context_data_value(
#endif #endif
#if defined (BACAPP_SIGNED) #if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT: case BACNET_APPLICATION_TAG_SIGNED_INT:
apdu_len = encode_context_signed(&apdu[0], context_tag_number, apdu_len =
encode_context_signed(&apdu[0], context_tag_number,
value->type.Signed_Int); value->type.Signed_Int);
break; break;
#endif #endif
#if defined (BACAPP_REAL) #if defined (BACAPP_REAL)
case BACNET_APPLICATION_TAG_REAL: case BACNET_APPLICATION_TAG_REAL:
apdu_len = encode_context_real(&apdu[0], context_tag_number, apdu_len =
encode_context_real(&apdu[0], context_tag_number,
value->type.Real); value->type.Real);
break; break;
#endif #endif
#if defined (BACAPP_DOUBLE) #if defined (BACAPP_DOUBLE)
case BACNET_APPLICATION_TAG_DOUBLE: case BACNET_APPLICATION_TAG_DOUBLE:
/* FIXME: double is not implemented yet. */ /* FIXME: double is not implemented yet. */
apdu_len = encode_context_double(&apdu[0], context_tag_number, apdu_len =
encode_context_double(&apdu[0], context_tag_number,
value->type.Double); value->type.Double);
break; break;
#endif #endif
@@ -343,13 +362,15 @@ int bacapp_encode_context_data_value(
#endif #endif
#if defined (BACAPP_DATE) #if defined (BACAPP_DATE)
case BACNET_APPLICATION_TAG_DATE: case BACNET_APPLICATION_TAG_DATE:
apdu_len = encode_context_date(&apdu[0], context_tag_number, apdu_len =
encode_context_date(&apdu[0], context_tag_number,
&value->type.Date); &value->type.Date);
break; break;
#endif #endif
#if defined (BACAPP_TIME) #if defined (BACAPP_TIME)
case BACNET_APPLICATION_TAG_TIME: case BACNET_APPLICATION_TAG_TIME:
apdu_len = encode_context_time(&apdu[0], context_tag_number, apdu_len =
encode_context_time(&apdu[0], context_tag_number,
&value->type.Time); &value->type.Time);
break; break;
#endif #endif
@@ -445,8 +466,9 @@ int bacapp_encode_context_data(
if (value && apdu) { if (value && apdu) {
tag_data_type = bacapp_context_tag_type(property, value->context_tag); tag_data_type = bacapp_context_tag_type(property, value->context_tag);
if (tag_data_type < MAX_BACNET_APPLICATION_TAG) { if (tag_data_type < MAX_BACNET_APPLICATION_TAG) {
apdu_len = bacapp_encode_context_data_value(&apdu[0], apdu_len =
value->context_tag, value); bacapp_encode_context_data_value(&apdu[0], value->context_tag,
value);
} else { } else {
/* FIXME: what now? */ /* FIXME: what now? */
apdu_len = 0; apdu_len = 0;
@@ -472,15 +494,17 @@ int bacapp_decode_context_data(
max_apdu_len = max_apdu_len; max_apdu_len = max_apdu_len;
if (apdu && value && decode_is_context_specific(apdu)) { if (apdu && value && decode_is_context_specific(apdu)) {
value->context_specific = true; value->context_specific = true;
tag_len = decode_tag_number_and_value(&apdu[0], tag_len =
&tag_number, &len_value_type); decode_tag_number_and_value(&apdu[0], &tag_number,
&len_value_type);
if (tag_len) { if (tag_len) {
apdu_len = tag_len; apdu_len = tag_len;
value->context_tag = tag_number; value->context_tag = tag_number;
value->tag = bacapp_context_tag_type(property, tag_number); value->tag = bacapp_context_tag_type(property, tag_number);
if (value->tag < MAX_BACNET_APPLICATION_TAG) { if (value->tag < MAX_BACNET_APPLICATION_TAG) {
len = bacapp_decode_data(&apdu[apdu_len], len =
value->tag, len_value_type, value); bacapp_decode_data(&apdu[apdu_len], value->tag,
len_value_type, value);
apdu_len += len; apdu_len += len;
} else { } else {
/* FIXME: what now? */ /* FIXME: what now? */
@@ -501,8 +525,9 @@ int bacapp_encode_data(
if (value && apdu) { if (value && apdu) {
if (value->context_specific) { if (value->context_specific) {
apdu_len = bacapp_encode_context_data_value(&apdu[0], apdu_len =
value->context_tag, value); bacapp_encode_context_data_value(&apdu[0], value->context_tag,
value);
} else { } else {
apdu_len = bacapp_encode_application_data(&apdu[0], value); apdu_len = bacapp_encode_application_data(&apdu[0], value);
} }
@@ -622,29 +647,33 @@ int bacapp_data_len(
BACNET_APPLICATION_DATA_VALUE application_value; BACNET_APPLICATION_DATA_VALUE application_value;
if (decode_is_opening_tag(&apdu[0])) { if (decode_is_opening_tag(&apdu[0])) {
len = decode_tag_number_and_value(&apdu[apdu_len], len =
&tag_number, &value); decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &value);
apdu_len += len; apdu_len += len;
opening_tag_number = tag_number; opening_tag_number = tag_number;
opening_tag_number_counter = 1; opening_tag_number_counter = 1;
while (opening_tag_number_counter) { while (opening_tag_number_counter) {
if (decode_is_opening_tag(&apdu[apdu_len])) { if (decode_is_opening_tag(&apdu[apdu_len])) {
len = decode_tag_number_and_value(&apdu[apdu_len], len =
&tag_number, &value); decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&value);
if (tag_number == opening_tag_number) if (tag_number == opening_tag_number)
opening_tag_number_counter++; opening_tag_number_counter++;
} else if (decode_is_closing_tag(&apdu[apdu_len])) { } else if (decode_is_closing_tag(&apdu[apdu_len])) {
len = decode_tag_number_and_value(&apdu[apdu_len], len =
&tag_number, &value); decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&value);
if (tag_number == opening_tag_number) if (tag_number == opening_tag_number)
opening_tag_number_counter--; opening_tag_number_counter--;
} else if (decode_is_context_specific(&apdu[apdu_len])) { } else if (decode_is_context_specific(&apdu[apdu_len])) {
/* context-specific tagged data */ /* context-specific tagged data */
len = bacapp_decode_context_data(&apdu[apdu_len], len =
bacapp_decode_context_data(&apdu[apdu_len],
max_apdu_len - apdu_len, &application_value, property); max_apdu_len - apdu_len, &application_value, property);
} else { } else {
/* application tagged data */ /* application tagged data */
len = bacapp_decode_application_data(&apdu[apdu_len], len =
bacapp_decode_application_data(&apdu[apdu_len],
max_apdu_len - apdu_len, &application_value); max_apdu_len - apdu_len, &application_value);
} }
apdu_len += len; apdu_len += len;
@@ -850,7 +879,8 @@ bool bacapp_parse_application_data(
break; break;
#endif #endif
case BACNET_APPLICATION_TAG_OCTET_STRING: case BACNET_APPLICATION_TAG_OCTET_STRING:
status = octetstring_init(&value->type.Octet_String, status =
octetstring_init(&value->type.Octet_String,
(uint8_t *) argv, strlen(argv)); (uint8_t *) argv, strlen(argv));
break; break;
case BACNET_APPLICATION_TAG_CHARACTER_STRING: case BACNET_APPLICATION_TAG_CHARACTER_STRING:
@@ -871,8 +901,8 @@ bool bacapp_parse_application_data(
count = count =
sscanf(argv, "%d/%d/%d:%d", &year, &month, &day, &wday); sscanf(argv, "%d/%d/%d:%d", &year, &month, &day, &wday);
if (count == 3) { if (count == 3) {
datetime_set_date(&value->type.Date, datetime_set_date(&value->type.Date, (uint16_t) year,
(uint16_t) year, (uint8_t) month, (uint8_t) day); (uint8_t) month, (uint8_t) day);
} else if (count == 4) { } else if (count == 4) {
value->type.Date.year = year; value->type.Date.year = year;
value->type.Date.month = month; value->type.Date.month = month;
@@ -1012,7 +1042,8 @@ bool bacapp_same_value(
#endif #endif
#if defined (BACAPP_CHARACTER_STRING) #if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING: case BACNET_APPLICATION_TAG_CHARACTER_STRING:
status = characterstring_same(&value->type.Character_String, status =
characterstring_same(&value->type.Character_String,
&test_value->type.Character_String); &test_value->type.Character_String);
break; break;
#endif #endif
@@ -1046,7 +1077,8 @@ void testBACnetApplicationDataLength(
len = encode_closing_tag(&apdu[apdu_len], 3); len = encode_closing_tag(&apdu[apdu_len], 3);
apdu_len += len; apdu_len += len;
/* verify the length of the data inside the opening/closing tags */ /* verify the length of the data inside the opening/closing tags */
len = bacapp_data_len(&apdu[0], apdu_len, len =
bacapp_data_len(&apdu[0], apdu_len,
PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES); PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES);
ct_test(pTest, test_len == len); ct_test(pTest, test_len == len);
@@ -1194,27 +1226,30 @@ void testBACnetApplicationData(
bool status = false; bool status = false;
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_NULL, status =
NULL, &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_NULL, NULL,
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
status = testBACnetApplicationDataValue(&value); status = testBACnetApplicationDataValue(&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, status =
"1", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "1",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Boolean == true); ct_test(pTest, value.type.Boolean == true);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, status =
"0", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "0",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Boolean == false); ct_test(pTest, value.type.Boolean == false);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, "0",
"0", &value); &value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Unsigned_Int == 0); ct_test(pTest, value.type.Unsigned_Int == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1232,14 +1267,14 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, "0",
"0", &value); &value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Signed_Int == 0); ct_test(pTest, value.type.Signed_Int == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, "-1",
"-1", &value); &value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Signed_Int == -1); ct_test(pTest, value.type.Signed_Int == -1);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1256,30 +1291,35 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Signed_Int == -32768); ct_test(pTest, value.type.Signed_Int == -32768);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, status =
"0.0", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "0.0",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, status =
"-1.0", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-1.0",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, status =
"1.0", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "1.0",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, status =
"3.14159", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "3.14159",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, status =
"-3.14159", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-3.14159",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, "0",
"0", &value); &value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Enumerated == 0); ct_test(pTest, value.type.Enumerated == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1296,7 +1336,8 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Enumerated == 0xFFFFFFFF); ct_test(pTest, value.type.Enumerated == 0xFFFFFFFF);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
"2005/5/22:1", &value); "2005/5/22:1", &value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2005); ct_test(pTest, value.type.Date.year == 2005);
@@ -1306,8 +1347,9 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
/* Happy Valentines Day! */ /* Happy Valentines Day! */
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, status =
"2007/2/14", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, "2007/2/14",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2007); ct_test(pTest, value.type.Date.year == 2007);
ct_test(pTest, value.type.Date.month == 2); ct_test(pTest, value.type.Date.month == 2);
@@ -1316,7 +1358,8 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
/* Wildcard Values */ /* Wildcard Values */
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
"2155/255/255:255", &value); "2155/255/255:255", &value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2155); ct_test(pTest, value.type.Date.year == 2155);
@@ -1325,7 +1368,8 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Date.wday == 255); ct_test(pTest, value.type.Date.wday == 255);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
"23:59:59.12", &value); "23:59:59.12", &value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23); ct_test(pTest, value.type.Time.hour == 23);
@@ -1334,8 +1378,9 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Time.hundredths == 12); ct_test(pTest, value.type.Time.hundredths == 12);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, status =
"23:59:59", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59:59",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23); ct_test(pTest, value.type.Time.hour == 23);
ct_test(pTest, value.type.Time.min == 59); ct_test(pTest, value.type.Time.min == 59);
@@ -1343,8 +1388,9 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Time.hundredths == 0); ct_test(pTest, value.type.Time.hundredths == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, status =
"23:59", &value); bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59",
&value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23); ct_test(pTest, value.type.Time.hour == 23);
ct_test(pTest, value.type.Time.min == 59); ct_test(pTest, value.type.Time.min == 59);
@@ -1361,8 +1407,8 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
status = status =
bacapp_parse_application_data bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING,
(BACNET_APPLICATION_TAG_CHARACTER_STRING, "Karg!", &value); "Karg!", &value);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value)); ct_test(pTest, testBACnetApplicationDataValue(&value));
+40 -30
View File
@@ -442,8 +442,8 @@ int encode_application_boolean(
if (boolean_value) if (boolean_value)
len_value = 1; len_value = 1;
len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BOOLEAN, false, len =
len_value); encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BOOLEAN, false, len_value);
return len; return len;
} }
@@ -553,8 +553,8 @@ int decode_bitstring(
byte_reverse_bits(apdu[len++])); byte_reverse_bits(apdu[len++]));
} }
unused_bits = apdu[0] & 0x07; unused_bits = apdu[0] & 0x07;
bitstring_set_bits_used(bit_string, bitstring_set_bits_used(bit_string, (uint8_t) bytes_used,
(uint8_t) bytes_used, unused_bits); unused_bits);
} }
} }
@@ -577,8 +577,8 @@ int encode_bitstring(
apdu[len++] = 0; apdu[len++] = 0;
else { else {
used_bytes = bitstring_bytes_used(bit_string); used_bytes = bitstring_bytes_used(bit_string);
remaining_used_bits = bitstring_bits_used(bit_string) - remaining_used_bits =
((used_bytes - 1) * 8); bitstring_bits_used(bit_string) - ((used_bytes - 1) * 8);
/* number of unused bits in the subsequent final octet */ /* number of unused bits in the subsequent final octet */
apdu[len++] = 8 - remaining_used_bits; apdu[len++] = 8 - remaining_used_bits;
for (i = 0; i < used_bytes; i++) { for (i = 0; i < used_bytes; i++) {
@@ -598,7 +598,8 @@ int encode_application_bitstring(
/* bit string may use more than 1 octet for the tag, so find out how many */ /* bit string may use more than 1 octet for the tag, so find out how many */
bit_string_encoded_length += bitstring_bytes_used(bit_string); bit_string_encoded_length += bitstring_bytes_used(bit_string);
len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false, len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false,
bit_string_encoded_length); bit_string_encoded_length);
len += encode_bitstring(&apdu[len], bit_string); len += encode_bitstring(&apdu[len], bit_string);
@@ -652,8 +653,9 @@ int encode_bacnet_object_id(
int len = 0; int len = 0;
type = object_type; type = object_type;
value = ((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | value =
(instance & BACNET_MAX_INSTANCE); ((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | (instance &
BACNET_MAX_INSTANCE);
len = encode_unsigned32(apdu, value); len = encode_unsigned32(apdu, value);
return len; return len;
@@ -732,8 +734,8 @@ int encode_application_octet_string(
if (octet_string) { if (octet_string) {
apdu_len = apdu_len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OCTET_STRING, encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OCTET_STRING, false,
false, octetstring_length(octet_string)); octetstring_length(octet_string));
/* FIXME: probably need to pass in the length of the APDU /* FIXME: probably need to pass in the length of the APDU
to bounds check since it might not be the only data chunk */ to bounds check since it might not be the only data chunk */
if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU) if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU)
@@ -756,8 +758,9 @@ int encode_context_octet_string(
int apdu_len = 0; int apdu_len = 0;
if (apdu && octet_string) { if (apdu && octet_string) {
apdu_len = encode_tag(&apdu[0], (uint8_t) tag_number, apdu_len =
true, octetstring_length(octet_string)); encode_tag(&apdu[0], (uint8_t) tag_number, true,
octetstring_length(octet_string));
if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU) if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU)
apdu_len += encode_octet_string(&apdu[apdu_len], octet_string); apdu_len += encode_octet_string(&apdu[apdu_len], octet_string);
else else
@@ -816,8 +819,8 @@ int encode_application_character_string(
string_len = characterstring_length(char_string) + 1 /* for encoding */ ; string_len = characterstring_length(char_string) + 1 /* for encoding */ ;
len = len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING, encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING, false,
false, string_len); string_len);
if ((len + string_len) < MAX_APDU) if ((len + string_len) < MAX_APDU)
len += encode_bacnet_character_string(&apdu[len], char_string); len += encode_bacnet_character_string(&apdu[len], char_string);
else else
@@ -855,7 +858,8 @@ int decode_character_string(
int len = 0; /* return value */ int len = 0; /* return value */
bool status = false; bool status = false;
status = characterstring_init(char_string, apdu[0], (char *) &apdu[1], status =
characterstring_init(char_string, apdu[0], (char *) &apdu[1],
len_value - 1); len_value - 1);
if (status) if (status)
len = len_value; len = len_value;
@@ -950,8 +954,8 @@ int encode_application_unsigned(
int len = 0; int len = 0;
len = encode_bacnet_unsigned(&apdu[1], value); len = encode_bacnet_unsigned(&apdu[1], value);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT, len +=
false, len); encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT, false, len);
return len; return len;
} }
@@ -1410,7 +1414,8 @@ void testBACDCodeTags(
/* test the len-value-type portion */ /* test the len-value-type portion */
for (value = 1;; value = value << 1) { for (value = 1;; value = value << 1) {
len = encode_tag(&apdu[0], tag_number, false, value); len = encode_tag(&apdu[0], tag_number, false, value);
len = decode_tag_number_and_value(&apdu[0], &test_tag_number, len =
decode_tag_number_and_value(&apdu[0], &test_tag_number,
&test_value); &test_value);
ct_test(pTest, tag_number == test_tag_number); ct_test(pTest, tag_number == test_tag_number);
ct_test(pTest, value == test_value); ct_test(pTest, value == test_value);
@@ -1682,7 +1687,8 @@ void testBACDCodeOctetString(
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING);
len += decode_octet_string(&array[len], len_value, &test_octet_string); len += decode_octet_string(&array[len], len_value, &test_octet_string);
ct_test(pTest, apdu_len == len); ct_test(pTest, apdu_len == len);
diff = memcmp(octetstring_value(&octet_string), &test_value[0], diff =
memcmp(octetstring_value(&octet_string), &test_value[0],
octetstring_length(&octet_string)); octetstring_length(&octet_string));
ct_test(pTest, diff == 0); ct_test(pTest, diff == 0);
@@ -1696,13 +1702,15 @@ void testBACDCodeOctetString(
decode_tag_number_and_value(&encoded_array[0], &tag_number, decode_tag_number_and_value(&encoded_array[0], &tag_number,
&len_value); &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING);
len += decode_octet_string(&encoded_array[len], len_value, len +=
decode_octet_string(&encoded_array[len], len_value,
&test_octet_string); &test_octet_string);
if (apdu_len != len) { if (apdu_len != len) {
printf("test octet string=#%d\n", i); printf("test octet string=#%d\n", i);
} }
ct_test(pTest, apdu_len == len); ct_test(pTest, apdu_len == len);
diff = memcmp(octetstring_value(&octet_string), &test_value[0], diff =
memcmp(octetstring_value(&octet_string), &test_value[0],
octetstring_length(&octet_string)); octetstring_length(&octet_string));
if (diff) { if (diff) {
printf("test octet string=#%d\n", i); printf("test octet string=#%d\n", i);
@@ -1736,7 +1744,8 @@ void testBACDCodeCharacterString(
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING);
len += decode_character_string(&array[len], len_value, &test_char_string); len += decode_character_string(&array[len], len_value, &test_char_string);
ct_test(pTest, apdu_len == len); ct_test(pTest, apdu_len == len);
diff = memcmp(characterstring_value(&char_string), &test_value[0], diff =
memcmp(characterstring_value(&char_string), &test_value[0],
characterstring_length(&char_string)); characterstring_length(&char_string));
ct_test(pTest, diff == 0); ct_test(pTest, diff == 0);
for (i = 0; i < MAX_CHARACTER_STRING_BYTES - 1; i++) { for (i = 0; i < MAX_CHARACTER_STRING_BYTES - 1; i++) {
@@ -1758,7 +1767,8 @@ void testBACDCodeCharacterString(
printf("test string=#%d apdu_len=%d len=%d\n", i, apdu_len, len); printf("test string=#%d apdu_len=%d len=%d\n", i, apdu_len, len);
} }
ct_test(pTest, apdu_len == len); ct_test(pTest, apdu_len == len);
diff = memcmp(characterstring_value(&char_string), &test_value[0], diff =
memcmp(characterstring_value(&char_string), &test_value[0],
characterstring_length(&char_string)); characterstring_length(&char_string));
if (diff) { if (diff) {
printf("test string=#%d\n", i); printf("test string=#%d\n", i);
@@ -1784,8 +1794,8 @@ void testBACDCodeObject(
uint32_t decoded_instance = 0; uint32_t decoded_instance = 0;
encode_bacnet_object_id(&encoded_array[0], type, instance); encode_bacnet_object_id(&encoded_array[0], type, instance);
decode_object_id(&encoded_array[0], decode_object_id(&encoded_array[0], (int *) &decoded_type,
(int *) &decoded_type, &decoded_instance); &decoded_instance);
ct_test(pTest, decoded_type == type); ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
encode_bacnet_object_id(&object_array[0], type, instance); encode_bacnet_object_id(&object_array[0], type, instance);
@@ -1794,13 +1804,13 @@ void testBACDCodeObject(
for (type = 0; type < 1024; type++) { for (type = 0; type < 1024; type++) {
for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) { for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) {
encode_bacnet_object_id(&encoded_array[0], type, instance); encode_bacnet_object_id(&encoded_array[0], type, instance);
decode_object_id(&encoded_array[0], decode_object_id(&encoded_array[0], (int *) &decoded_type,
(int *) &decoded_type, &decoded_instance); &decoded_instance);
ct_test(pTest, decoded_type == type); ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
encode_bacnet_object_id(&object_array[0], type, instance); encode_bacnet_object_id(&object_array[0], type, instance);
ct_test(pTest, memcmp(&object_array[0], ct_test(pTest, memcmp(&object_array[0], &encoded_array[0],
&encoded_array[0], sizeof(object_array)) == 0); sizeof(object_array)) == 0);
} }
} }

Some files were not shown because too many files have changed in this diff Show More