Corrected bug in all confirmed handlers: if a segmented message was received, the handler tried to decode it instead of immediately sending an abort. This caused lockup with WriteProperty.
This commit is contained in:
@@ -109,12 +109,21 @@ void handler_atomic_read_file(uint8_t * service_request,
|
|||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Received Atomic-Read-File Request!\n");
|
fprintf(stderr, "Received Atomic-Read-File Request!\n");
|
||||||
#endif
|
#endif
|
||||||
len = arf_decode_service_request(service_request, service_len, &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, 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 = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
|
||||||
&my_address, &npdu_data);
|
&my_address, &npdu_data);
|
||||||
|
if (service_data->segmented_message) {
|
||||||
|
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
|
service_data->invoke_id,
|
||||||
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n");
|
||||||
|
#endif
|
||||||
|
goto ARF_ABORT;
|
||||||
|
}
|
||||||
|
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],
|
||||||
@@ -122,14 +131,9 @@ void handler_atomic_read_file(uint8_t * service_request,
|
|||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
|
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
|
||||||
#endif
|
#endif
|
||||||
} else if (service_data->segmented_message) {
|
goto ARF_ABORT;
|
||||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
}
|
||||||
service_data->invoke_id,
|
if (data.object_type == OBJECT_FILE) {
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
|
||||||
#if PRINT_ENABLED
|
|
||||||
fprintf(stderr, "Segmented Message. Sending Abort!\n");
|
|
||||||
#endif
|
|
||||||
} else if (data.object_type == OBJECT_FILE) {
|
|
||||||
if (!bacfile_valid_instance(data.object_instance)) {
|
if (!bacfile_valid_instance(data.object_instance)) {
|
||||||
error = true;
|
error = true;
|
||||||
} else if (data.access == FILE_STREAM_ACCESS) {
|
} else if (data.access == FILE_STREAM_ACCESS) {
|
||||||
@@ -179,6 +183,7 @@ void handler_atomic_read_file(uint8_t * service_request,
|
|||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code);
|
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code);
|
||||||
}
|
}
|
||||||
|
ARF_ABORT:
|
||||||
pdu_len += len;
|
pdu_len += len;
|
||||||
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
||||||
&Handler_Transmit_Buffer[0], pdu_len);
|
&Handler_Transmit_Buffer[0], pdu_len);
|
||||||
|
|||||||
@@ -87,12 +87,21 @@ void handler_atomic_write_file(uint8_t * service_request,
|
|||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Received AtomicWriteFile Request!\n");
|
fprintf(stderr, "Received AtomicWriteFile Request!\n");
|
||||||
#endif
|
#endif
|
||||||
len = awf_decode_service_request(service_request, service_len, &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, 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 = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
|
||||||
&my_address, &npdu_data);
|
&my_address, &npdu_data);
|
||||||
|
if (service_data->segmented_message) {
|
||||||
|
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
|
service_data->invoke_id,
|
||||||
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
fprintf(stderr, "Segmented Message. Sending Abort!\n");
|
||||||
|
#endif
|
||||||
|
goto AWF_ABORT;
|
||||||
|
}
|
||||||
|
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],
|
||||||
@@ -100,14 +109,9 @@ void handler_atomic_write_file(uint8_t * service_request,
|
|||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
|
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
|
||||||
#endif
|
#endif
|
||||||
} else if (service_data->segmented_message) {
|
goto AWF_ABORT;
|
||||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
}
|
||||||
service_data->invoke_id,
|
if (data.object_type == OBJECT_FILE) {
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
|
||||||
#if PRINT_ENABLED
|
|
||||||
fprintf(stderr, "Segmented Message. Sending Abort!\n");
|
|
||||||
#endif
|
|
||||||
} else if (data.object_type == OBJECT_FILE) {
|
|
||||||
if (!bacfile_valid_instance(data.object_instance)) {
|
if (!bacfile_valid_instance(data.object_instance)) {
|
||||||
error = true;
|
error = true;
|
||||||
} else if (data.access == FILE_STREAM_ACCESS) {
|
} else if (data.access == FILE_STREAM_ACCESS) {
|
||||||
@@ -144,6 +148,7 @@ void handler_atomic_write_file(uint8_t * service_request,
|
|||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code);
|
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code);
|
||||||
}
|
}
|
||||||
|
AWF_ABORT:
|
||||||
pdu_len += len;
|
pdu_len += len;
|
||||||
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
||||||
&Handler_Transmit_Buffer[0], pdu_len);
|
&Handler_Transmit_Buffer[0], pdu_len);
|
||||||
|
|||||||
@@ -53,16 +53,28 @@ void handler_device_communication_control(uint8_t * service_request,
|
|||||||
BACNET_NPDU_DATA npdu_data;
|
BACNET_NPDU_DATA npdu_data;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
|
|
||||||
/* decode the service request only */
|
/* encode the NPDU portion of the reply packet */
|
||||||
len = dcc_decode_service_request(service_request,
|
|
||||||
service_len, &timeDuration, &state, &password);
|
|
||||||
/* 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 = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
|
||||||
&my_address, &npdu_data);
|
&my_address, &npdu_data);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "DeviceCommunicationControl!\n");
|
fprintf(stderr, "DeviceCommunicationControl!\n");
|
||||||
|
#endif
|
||||||
|
if (service_data->segmented_message) {
|
||||||
|
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
|
service_data->invoke_id,
|
||||||
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
|
"Sending Abort - segmented message.\n");
|
||||||
|
#endif
|
||||||
|
goto DCC_ABORT;
|
||||||
|
}
|
||||||
|
/* decode the service request only */
|
||||||
|
len = dcc_decode_service_request(service_request,
|
||||||
|
service_len, &timeDuration, &state, &password);
|
||||||
|
#if PRINT_ENABLED
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"timeout=%u state=%u password=%s\n",
|
"timeout=%u state=%u password=%s\n",
|
||||||
@@ -77,15 +89,9 @@ void handler_device_communication_control(uint8_t * service_request,
|
|||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Abort - could not decode.\n");
|
"Sending Abort - could not decode.\n");
|
||||||
#endif
|
#endif
|
||||||
} else if (service_data->segmented_message) {
|
goto DCC_ABORT;
|
||||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
}
|
||||||
service_data->invoke_id,
|
if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
|
||||||
#if PRINT_ENABLED
|
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
|
||||||
"Sending Abort - segmented message.\n");
|
|
||||||
#endif
|
|
||||||
} else 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
|
||||||
@@ -115,6 +121,7 @@ void handler_device_communication_control(uint8_t * service_request,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DCC_ABORT:
|
||||||
pdu_len += len;
|
pdu_len += len;
|
||||||
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
||||||
&Handler_Transmit_Buffer[0], pdu_len);
|
&Handler_Transmit_Buffer[0], pdu_len);
|
||||||
|
|||||||
@@ -53,9 +53,6 @@ void handler_reinitialize_device(uint8_t * service_request,
|
|||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
|
|
||||||
/* decode the service request only */
|
|
||||||
len = rd_decode_service_request(service_request,
|
|
||||||
service_len, &state, &their_password);
|
|
||||||
/* 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);
|
||||||
@@ -63,6 +60,21 @@ void handler_reinitialize_device(uint8_t * service_request,
|
|||||||
&my_address, &npdu_data);
|
&my_address, &npdu_data);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "ReinitializeDevice!\n");
|
fprintf(stderr, "ReinitializeDevice!\n");
|
||||||
|
#endif
|
||||||
|
if (service_data->segmented_message) {
|
||||||
|
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
|
service_data->invoke_id,
|
||||||
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
fprintf(stderr,
|
||||||
|
"ReinitializeDevice: Sending Abort - segmented message.\n");
|
||||||
|
#endif
|
||||||
|
goto RD_ABORT;
|
||||||
|
}
|
||||||
|
/* decode the service request only */
|
||||||
|
len = rd_decode_service_request(service_request,
|
||||||
|
service_len, &state, &their_password);
|
||||||
|
#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",
|
||||||
(unsigned) state, characterstring_value(&their_password));
|
(unsigned) state, characterstring_value(&their_password));
|
||||||
@@ -77,15 +89,10 @@ void handler_reinitialize_device(uint8_t * service_request,
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ReinitializeDevice: Sending Abort - could not decode.\n");
|
"ReinitializeDevice: Sending Abort - could not decode.\n");
|
||||||
#endif
|
#endif
|
||||||
} else if (service_data->segmented_message) {
|
goto RD_ABORT;
|
||||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
}
|
||||||
service_data->invoke_id,
|
/* check the data from the request */
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
if (state >= MAX_BACNET_REINITIALIZED_STATE) {
|
||||||
#if PRINT_ENABLED
|
|
||||||
fprintf(stderr,
|
|
||||||
"ReinitializeDevice: Sending Abort - segmented message.\n");
|
|
||||||
#endif
|
|
||||||
} else 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
|
||||||
@@ -117,6 +124,7 @@ void handler_reinitialize_device(uint8_t * service_request,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
RD_ABORT:
|
||||||
pdu_len += len;
|
pdu_len += len;
|
||||||
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
||||||
&Handler_Transmit_Buffer[0], pdu_len);
|
&Handler_Transmit_Buffer[0], pdu_len);
|
||||||
|
|||||||
@@ -199,33 +199,38 @@ void handler_read_property(uint8_t * service_request,
|
|||||||
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
|
|
||||||
len = rp_decode_service_request(service_request, service_len, &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, 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 = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
|
||||||
&my_address, &npdu_data);
|
&my_address, &npdu_data);
|
||||||
|
if (service_data->segmented_message) {
|
||||||
|
/* we don't support segmentation - send an abort */
|
||||||
|
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
|
service_data->invoke_id,
|
||||||
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
fprintf(stderr, "RP: Segmented message. Sending Abort!\n");
|
||||||
|
#endif
|
||||||
|
goto RP_ABORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = rp_decode_service_request(service_request, service_len, &data);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
fprintf(stderr, "Unable to decode Read-Property Request!\n");
|
fprintf(stderr, "RP: Unable to decode Request!\n");
|
||||||
#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, "Sending Abort!\n");
|
fprintf(stderr, "RP: Bad Encoding. Sending Abort!\n");
|
||||||
#endif
|
#endif
|
||||||
} else if (service_data->segmented_message) {
|
goto RP_ABORT;
|
||||||
/* we don't support segmentation - send an abort */
|
}
|
||||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
/* assume that there is an error */
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
|
||||||
#if PRINT_ENABLED
|
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
/* most cases will be error */
|
|
||||||
error = true;
|
error = true;
|
||||||
len = Encode_Property_APDU(
|
len = Encode_Property_APDU(
|
||||||
&Temp_Buf[0],
|
&Temp_Buf[0],
|
||||||
@@ -244,30 +249,29 @@ void handler_read_property(uint8_t * service_request,
|
|||||||
service_data->invoke_id, &data);
|
service_data->invoke_id, &data);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Read Property Ack!\n");
|
"RP: Sending Ack!\n");
|
||||||
#endif
|
#endif
|
||||||
error = false;
|
error = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (error) {
|
if (error) {
|
||||||
switch (len) {
|
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 */
|
||||||
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;
|
#if PRINT_ENABLED
|
||||||
case -1:
|
fprintf(stderr, "RP: Reply too big to fit into APDU!\n");
|
||||||
default:
|
#endif
|
||||||
|
} else {
|
||||||
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
|
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
|
||||||
break;
|
|
||||||
}
|
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Read Property Error!\n");
|
fprintf(stderr, "RP: Sending Error!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
RP_ABORT:
|
||||||
pdu_len += len;
|
pdu_len += len;
|
||||||
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
||||||
&Handler_Transmit_Buffer[0], pdu_len);
|
&Handler_Transmit_Buffer[0], pdu_len);
|
||||||
|
|||||||
@@ -318,29 +318,16 @@ void handler_read_property_multiple(
|
|||||||
npdu_len = npdu_encode_pdu(
|
npdu_len = npdu_encode_pdu(
|
||||||
&Handler_Transmit_Buffer[0],
|
&Handler_Transmit_Buffer[0],
|
||||||
src, &my_address, &npdu_data);
|
src, &my_address, &npdu_data);
|
||||||
#if PRINT_ENABLED
|
if (service_data->segmented_message) {
|
||||||
if (service_len <= 0)
|
|
||||||
printf("RPM: Unable to decode request!\r\n");
|
|
||||||
#endif
|
|
||||||
/* bad decoding - send an abort */
|
|
||||||
if (service_len == 0)
|
|
||||||
{
|
|
||||||
apdu_len = abort_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[npdu_len],
|
|
||||||
service_data->invoke_id,
|
|
||||||
ABORT_REASON_OTHER, true);
|
|
||||||
#if PRINT_ENABLED
|
|
||||||
printf("RPM: Sending Abort!\r\n");
|
|
||||||
#endif
|
|
||||||
} else if (service_data->segmented_message) {
|
|
||||||
apdu_len = abort_encode_apdu(
|
apdu_len = abort_encode_apdu(
|
||||||
&Handler_Transmit_Buffer[npdu_len],
|
&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);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
printf("RPM: Sending Abort!\r\n");
|
printf("RPM: Segmented message. Sending Abort!\r\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
goto RPM_ABORT;
|
||||||
|
}
|
||||||
/* 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(
|
apdu_len = rpm_ack_encode_apdu_init(
|
||||||
@@ -508,7 +495,6 @@ void handler_read_property_multiple(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} 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(
|
bytes_sent = datalink_send_pdu(
|
||||||
|
|||||||
@@ -47,8 +47,6 @@ void handler_who_is(uint8_t * service_request,
|
|||||||
(void) src;
|
(void) src;
|
||||||
len = whois_decode_service_request(service_request,
|
len = whois_decode_service_request(service_request,
|
||||||
service_len, &low_limit, &high_limit);
|
service_len, &low_limit, &high_limit);
|
||||||
/* in our simple system, we just set a flag and let the main loop
|
|
||||||
send the I-Am request. */
|
|
||||||
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) {
|
||||||
|
|||||||
@@ -63,39 +63,43 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
|
|
||||||
/* decode the service request only */
|
|
||||||
len = wp_decode_service_request(service_request,
|
|
||||||
service_len, &wp_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, 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 = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
|
||||||
&my_address, &npdu_data);
|
&my_address, &npdu_data);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Received Write-Property Request!\n");
|
fprintf(stderr, "WP: Received Request!\n");
|
||||||
|
#endif
|
||||||
|
if (service_data->segmented_message) {
|
||||||
|
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
|
service_data->invoke_id,
|
||||||
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
fprintf(stderr, "WP: Segmented message. Sending Abort!\n");
|
||||||
|
#endif
|
||||||
|
goto WP_ABORT;
|
||||||
|
} /* decode the service request only */
|
||||||
|
len = wp_decode_service_request(service_request,
|
||||||
|
service_len, &wp_data);
|
||||||
|
#if PRINT_ENABLED
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
fprintf(stderr, "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, "Unable to decode Write-Property 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, "Sending Abort!\n");
|
fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n");
|
||||||
#endif
|
#endif
|
||||||
} else if (service_data->segmented_message) {
|
goto WP_ABORT;
|
||||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
}
|
||||||
service_data->invoke_id,
|
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
|
||||||
#if PRINT_ENABLED
|
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
switch (wp_data.object_type) {
|
switch (wp_data.object_type) {
|
||||||
case OBJECT_DEVICE:
|
case OBJECT_DEVICE:
|
||||||
if (Device_Write_Property(&wp_data, &error_class, &error_code)) {
|
if (Device_Write_Property(&wp_data, &error_class, &error_code)) {
|
||||||
@@ -105,7 +109,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for Device!\n");
|
"WP: Sending Simple Ack for Device!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -115,7 +119,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Error for Device!\n");
|
"WP: Sending Error for Device!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -128,7 +132,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
|
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
error_class, error_code);
|
error_class, error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Write Access Error!\n");
|
fprintf(stderr, "WP: Sending Write Access Error!\n");
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case OBJECT_BINARY_OUTPUT:
|
case OBJECT_BINARY_OUTPUT:
|
||||||
@@ -140,7 +144,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for BO!\n");
|
"WP: Sending Simple Ack for BO!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -149,7 +153,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Write Access Error for BO!\n");
|
fprintf(stderr, "WP: Sending Write Access Error for BO!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -162,7 +166,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for BV!\n");
|
"WP: Sending Simple Ack for BV!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -171,7 +175,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Write Access Error for BV!\n");
|
fprintf(stderr, "WP: Sending Write Access Error for BV!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -184,7 +188,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for AO!\n");
|
"WP: Sending Simple Ack for AO!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -193,7 +197,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Write Access Error for AO!\n");
|
fprintf(stderr, "WP: Sending Write Access Error for AO!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -206,7 +210,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for AV!\n");
|
"WP: Sending Simple Ack for AV!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -215,7 +219,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Write Access Error for AV!\n");
|
fprintf(stderr, "WP: Sending Write Access Error for AV!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -228,7 +232,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for LSP!\n");
|
"WP: Sending Simple Ack for LSP!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -237,7 +241,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Write Access Error for LSP!\n");
|
fprintf(stderr, "WP: Sending Write Access Error for LSP!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -250,7 +254,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for Load Control!\n");
|
"WP: Sending Simple Ack for Load Control!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -260,7 +264,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Access Error for Load Control!\n");
|
"WP: Sending Write Access Error for Load Control!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -273,7 +277,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for MSO!\n");
|
"WP: Sending Write Property Simple Ack for MSO!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -282,7 +286,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Write Access Error for MSO!\n");
|
fprintf(stderr, "WP: Sending Write Access Error for MSO!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -296,7 +300,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Sending Write Property Simple Ack for File!\n");
|
"WP: Sending Simple Ack for File!\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
len =
|
len =
|
||||||
@@ -305,7 +309,7 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_code);
|
error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Write Access Error for File!\n");
|
fprintf(stderr, "WP: Sending Write Access Error for File!\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -316,17 +320,17 @@ void handler_write_property(uint8_t * service_request,
|
|||||||
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
|
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
error_class, error_code);
|
error_class, error_code);
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "Sending Unknown Object Error!\n");
|
fprintf(stderr, "WP: Sending Unknown Object Error!\n");
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
WP_ABORT:
|
||||||
pdu_len += len;
|
pdu_len += len;
|
||||||
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
bytes_sent = datalink_send_pdu(src, &npdu_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, "Failed to send PDU (%s)!\n", strerror(errno));
|
fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user