Fix [bug#80] npdu_decode via deprecation (#447)
* Fix [bug#80] npdu_decode via deprecation --------- Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -16,6 +16,7 @@ The git repositories are hosted at the following sites:
|
||||
|
||||
### Security
|
||||
|
||||
- Fix [bug#80] npdu_decode via deprecation (#447)
|
||||
- Fix [bug#79] out of bounds jump in h_apdu.c:apdu_handler (#446)
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -185,7 +185,7 @@ static void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
BACNET_NPDU_DATA npdu_data = { 0 };
|
||||
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
|
||||
if (npdu_data.network_layer_message) {
|
||||
if (apdu_offset <= pdu_len) {
|
||||
My_Router_Handler(src, &npdu_data, &pdu[apdu_offset],
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ static void mstp_monitor_i_am(uint8_t mac, uint8_t *pdu, uint16_t pdu_len)
|
||||
|
||||
if (pdu[0] == BACNET_PROTOCOL_VERSION) {
|
||||
MSTP_Fill_BACnet_Address(&src, mac);
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, &src, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, &src, &npdu_data);
|
||||
if ((!npdu_data.network_layer_message) && (apdu_offset > 0) &&
|
||||
(apdu_offset < pdu_len) && (src.net == 0)) {
|
||||
apdu_len = pdu_len - apdu_offset;
|
||||
|
||||
@@ -149,7 +149,7 @@ static void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
BACNET_NPDU_DATA npdu_data = { 0 };
|
||||
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
|
||||
if (npdu_data.network_layer_message) {
|
||||
My_Router_Handler(src, &npdu_data, &pdu[apdu_offset],
|
||||
(uint16_t)(pdu_len - apdu_offset));
|
||||
|
||||
@@ -945,7 +945,7 @@ static void my_routing_npdu_handler(
|
||||
if (!pdu) {
|
||||
/* no packet */
|
||||
} else if (pdu[0] == BACNET_PROTOCOL_VERSION) {
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
|
||||
if (apdu_offset <= 0) {
|
||||
fprintf(stderr, "NPDU: Decoding failed; Discarded!\n");
|
||||
} else if (npdu_data.network_layer_message) {
|
||||
|
||||
@@ -943,7 +943,7 @@ static void my_routing_npdu_handler(
|
||||
if (!pdu) {
|
||||
/* no packet */
|
||||
} else if (pdu[0] == BACNET_PROTOCOL_VERSION) {
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
|
||||
if (apdu_offset <= 0) {
|
||||
fprintf(stderr, "NPDU: Decoding failed; Discarded!\n");
|
||||
} else if (npdu_data.network_layer_message) {
|
||||
|
||||
+2
-1
@@ -766,7 +766,8 @@ uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
|
||||
|
||||
memmove(data, msg->data, sizeof(MSG_DATA));
|
||||
|
||||
apdu_offset = npdu_decode(data->pdu, &data->dest, &addr, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(data->pdu, data->pdu_len, &data->dest,
|
||||
&addr, &npdu_data);
|
||||
apdu_len = data->pdu_len - apdu_offset;
|
||||
|
||||
srcport = find_snet(msg->origin);
|
||||
|
||||
@@ -45,7 +45,8 @@ uint16_t process_network_message(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
|
||||
|
||||
memmove(data, msg->data, sizeof(MSG_DATA));
|
||||
|
||||
apdu_offset = npdu_decode(data->pdu, &data->dest, NULL, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(data->pdu, data->pdu_len, &data->dest,
|
||||
NULL, &npdu_data);
|
||||
apdu_len = data->pdu_len - apdu_offset;
|
||||
|
||||
srcport = find_snet(msg->origin);
|
||||
|
||||
@@ -134,7 +134,7 @@ static void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
BACNET_NPDU_DATA npdu_data = { 0 };
|
||||
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
|
||||
if (npdu_data.network_layer_message) {
|
||||
My_Router_Handler(src, &npdu_data, &pdu[apdu_offset],
|
||||
(uint16_t)(pdu_len - apdu_offset));
|
||||
|
||||
@@ -132,7 +132,7 @@ static void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
BACNET_NPDU_DATA npdu_data = { 0 };
|
||||
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
|
||||
if (npdu_data.network_layer_message) {
|
||||
My_Router_Handler(src, &npdu_data, &pdu[apdu_offset],
|
||||
(uint16_t)(pdu_len - apdu_offset));
|
||||
|
||||
@@ -245,8 +245,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -263,7 +263,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the reply data */
|
||||
reply.address.mac[0] = dest_address;
|
||||
reply.address.mac_len = 1;
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -246,8 +246,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -264,7 +264,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the reply data */
|
||||
reply.address.mac[0] = dest_address;
|
||||
reply.address.mac_len = 1;
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+19
-18
@@ -192,14 +192,14 @@ void dlmstp_cleanup(void)
|
||||
pthread_mutex_lock(&Thread_Mutex);
|
||||
run_thread = false;
|
||||
pthread_mutex_unlock(&Thread_Mutex);
|
||||
pthread_join (hThread, NULL);
|
||||
pthread_join(hThread, NULL);
|
||||
pthread_cond_destroy(&Received_Frame_Flag);
|
||||
pthread_cond_destroy(&Receive_Packet_Flag);
|
||||
pthread_cond_destroy(&Master_Done_Flag);
|
||||
pthread_mutex_destroy(&Received_Frame_Mutex);
|
||||
pthread_mutex_destroy(&Receive_Packet_Mutex);
|
||||
pthread_mutex_destroy(&Master_Done_Mutex);
|
||||
pthread_mutex_destroy (&Ring_Buffer_Mutex);
|
||||
pthread_mutex_destroy(&Ring_Buffer_Mutex);
|
||||
}
|
||||
|
||||
/* returns number of bytes sent on success, zero on failure */
|
||||
@@ -211,7 +211,7 @@ int dlmstp_send_pdu(BACNET_ADDRESS *dest, /* destination address */
|
||||
int bytes_sent = 0;
|
||||
struct mstp_pdu_packet *pkt;
|
||||
unsigned i = 0;
|
||||
pthread_mutex_lock (&Ring_Buffer_Mutex);
|
||||
pthread_mutex_lock(&Ring_Buffer_Mutex);
|
||||
pkt = (struct mstp_pdu_packet *)Ringbuf_Data_Peek(&PDU_Queue);
|
||||
if (pkt) {
|
||||
pkt->data_expecting_reply = npdu_data->data_expecting_reply;
|
||||
@@ -229,7 +229,7 @@ int dlmstp_send_pdu(BACNET_ADDRESS *dest, /* destination address */
|
||||
bytes_sent = pdu_len;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock (&Ring_Buffer_Mutex);
|
||||
pthread_mutex_unlock(&Ring_Buffer_Mutex);
|
||||
|
||||
return bytes_sent;
|
||||
}
|
||||
@@ -310,17 +310,18 @@ static void *dlmstp_master_fsm_task(void *pArg)
|
||||
while (run_loop) {
|
||||
/* do nothing while immediate transitioning */
|
||||
run_loop = MSTP_Master_Node_FSM(&MSTP_Port);
|
||||
pthread_mutex_lock (&Thread_Mutex);
|
||||
if (!run_thread) run_loop = false;
|
||||
pthread_mutex_unlock (&Thread_Mutex);
|
||||
pthread_mutex_lock(&Thread_Mutex);
|
||||
if (!run_thread)
|
||||
run_loop = false;
|
||||
pthread_mutex_unlock(&Thread_Mutex);
|
||||
}
|
||||
} else if (MSTP_Port.This_Station < 255) {
|
||||
MSTP_Slave_Node_FSM(&MSTP_Port);
|
||||
}
|
||||
}
|
||||
pthread_mutex_lock (&Thread_Mutex);
|
||||
pthread_mutex_lock(&Thread_Mutex);
|
||||
thread_alive = run_thread;
|
||||
pthread_mutex_unlock (&Thread_Mutex);
|
||||
pthread_mutex_unlock(&Thread_Mutex);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -389,9 +390,9 @@ uint16_t MSTP_Get_Send(
|
||||
struct mstp_pdu_packet *pkt;
|
||||
|
||||
(void)timeout;
|
||||
pthread_mutex_lock (&Ring_Buffer_Mutex);
|
||||
pthread_mutex_lock(&Ring_Buffer_Mutex);
|
||||
if (Ringbuf_Empty(&PDU_Queue)) {
|
||||
pthread_mutex_unlock (&Ring_Buffer_Mutex);
|
||||
pthread_mutex_unlock(&Ring_Buffer_Mutex);
|
||||
return 0;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *)Ringbuf_Peek(&PDU_Queue);
|
||||
@@ -406,7 +407,7 @@ uint16_t MSTP_Get_Send(
|
||||
mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
|
||||
mstp_port->This_Station, (uint8_t *)&pkt->buffer[0], pkt->length);
|
||||
(void)Ringbuf_Pop(&PDU_Queue, NULL);
|
||||
pthread_mutex_unlock (&Ring_Buffer_Mutex);
|
||||
pthread_mutex_unlock(&Ring_Buffer_Mutex);
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
@@ -438,8 +439,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
@@ -467,7 +468,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the reply data */
|
||||
reply.address.mac[0] = dest_address;
|
||||
reply.address.mac_len = 1;
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
@@ -730,8 +732,8 @@ bool dlmstp_init(char *ifname)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pthread_mutex_init (&Ring_Buffer_Mutex, NULL);
|
||||
pthread_mutex_init (&Thread_Mutex, NULL);
|
||||
pthread_mutex_init(&Ring_Buffer_Mutex, NULL);
|
||||
pthread_mutex_init(&Thread_Mutex, NULL);
|
||||
|
||||
/* initialize PDU queue */
|
||||
Ringbuf_Init(&PDU_Queue, (uint8_t *)&PDU_Buffer,
|
||||
@@ -825,4 +827,3 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -411,8 +411,8 @@ bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
@@ -440,7 +440,8 @@ bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the reply data */
|
||||
reply.address.mac[0] = dest_address;
|
||||
reply.address.mac_len = 1;
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
|
||||
@@ -567,8 +567,8 @@ static bool mstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -585,7 +585,8 @@ static bool mstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the reply data */
|
||||
reply.address.mac[0] = dest_address;
|
||||
reply.address.mac_len = 1;
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -753,9 +754,9 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
|
||||
break;
|
||||
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
|
||||
if ((mstp_port->DestinationAddress ==
|
||||
MSTP_BROADCAST_ADDRESS) &&
|
||||
MSTP_BROADCAST_ADDRESS) &&
|
||||
(npdu_confirmed_service(mstp_port->InputBuffer,
|
||||
mstp_port->DataLength))) {
|
||||
mstp_port->DataLength))) {
|
||||
/* BTL test: verifies that the IUT will quietly
|
||||
discard any Confirmed-Request-PDU, whose
|
||||
destination address is a multicast or
|
||||
|
||||
@@ -567,8 +567,8 @@ static bool mstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -585,7 +585,8 @@ static bool mstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the reply data */
|
||||
reply.address.mac[0] = dest_address;
|
||||
reply.address.mac_len = 1;
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -761,9 +762,9 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
|
||||
break;
|
||||
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
|
||||
if ((mstp_port->DestinationAddress ==
|
||||
MSTP_BROADCAST_ADDRESS) &&
|
||||
MSTP_BROADCAST_ADDRESS) &&
|
||||
(npdu_confirmed_service(mstp_port->InputBuffer,
|
||||
mstp_port->DataLength))) {
|
||||
mstp_port->DataLength))) {
|
||||
/* BTL test: verifies that the IUT will quietly
|
||||
discard any Confirmed-Request-PDU, whose
|
||||
destination address is a multicast or
|
||||
|
||||
@@ -247,8 +247,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -265,7 +265,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the reply data */
|
||||
reply.address.mac[0] = dest_address;
|
||||
reply.address.mac_len = 1;
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -582,8 +583,8 @@ static void MSTP_Receive_Frame_FSM(void)
|
||||
source = SourceAddress;
|
||||
destination = DestinationAddress;
|
||||
frame = FrameType;
|
||||
Frame_Rx_Callback(source, destination,
|
||||
frame, InputBuffer, DataLength);
|
||||
Frame_Rx_Callback(source, destination, frame,
|
||||
InputBuffer, DataLength);
|
||||
}
|
||||
/* wait for the start of the next frame. */
|
||||
Receive_State = MSTP_RECEIVE_STATE_IDLE;
|
||||
@@ -674,8 +675,8 @@ static void MSTP_Receive_Frame_FSM(void)
|
||||
source = SourceAddress;
|
||||
destination = DestinationAddress;
|
||||
frame = FrameType;
|
||||
Frame_Rx_Callback(source, destination,
|
||||
frame, InputBuffer, DataLength);
|
||||
Frame_Rx_Callback(source, destination, frame,
|
||||
InputBuffer, DataLength);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -323,8 +323,8 @@ bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -340,7 +340,8 @@ bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
request.service_choice = request_pdu[offset + 3];
|
||||
/* decode the reply data */
|
||||
bacnet_address_copy(&reply.address, dest_address);
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -308,8 +308,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = (uint16_t)npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = (uint16_t)bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -325,8 +325,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
request.service_choice = request_pdu[offset + 3];
|
||||
/* decode the reply data */
|
||||
bacnet_address_copy(&reply.address, dest_address);
|
||||
offset = (uint16_t)npdu_decode(
|
||||
&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = (uint16_t)bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -239,8 +239,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the request data */
|
||||
request.address.mac[0] = src_address;
|
||||
request.address.mac_len = 1;
|
||||
offset = npdu_decode(
|
||||
&request_pdu[0], NULL, &request.address, &request.npdu_data);
|
||||
offset = bacnet_npdu_decode(request_pdu, request_pdu_len, NULL,
|
||||
&request.address, &request.npdu_data);
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
@@ -257,7 +257,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t *request_pdu,
|
||||
/* decode the reply data */
|
||||
reply.address.mac[0] = dest_address;
|
||||
reply.address.mac_len = 1;
|
||||
offset = npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
|
||||
offset = bacnet_npdu_decode(
|
||||
reply_pdu, reply_pdu_len, &reply.address, NULL, &reply.npdu_data);
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ void routing_npdu_handler(
|
||||
|
||||
/* only handle the version that we know how to handle */
|
||||
if (pdu[0] == BACNET_PROTOCOL_VERSION) {
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
|
||||
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
|
||||
if (apdu_offset <= 0) {
|
||||
debug_printf("NPDU: Decoding failed; Discarded!\n");
|
||||
} else if (npdu_data.network_layer_message) {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "bacnet/bacnet_stack_exports.h"
|
||||
#include "bacnet/basic/sys/platform.h"
|
||||
#include "bacnet/bacdef.h"
|
||||
#include "bacnet/bacenum.h"
|
||||
|
||||
@@ -98,6 +99,7 @@ extern "C" {
|
||||
BACNET_NPDU_DATA * dest,
|
||||
BACNET_NPDU_DATA * src);
|
||||
|
||||
BACNET_STACK_DEPRECATED("Use bacnet_npdu_decode() instead")
|
||||
BACNET_STACK_EXPORT
|
||||
int npdu_decode(
|
||||
uint8_t * npdu,
|
||||
|
||||
@@ -42,7 +42,7 @@ static void test_NPDU_Network(void)
|
||||
len = npdu_encode_pdu(&pdu[0], &dest, &src, &npdu_data);
|
||||
zassert_not_equal(len, 0, NULL);
|
||||
/* can we get the info back? */
|
||||
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
|
||||
npdu_len = bacnet_npdu_decode(pdu, sizeof(pdu), &npdu_dest, &npdu_src, &npdu_data);
|
||||
zassert_not_equal(npdu_len, 0, NULL);
|
||||
zassert_equal(npdu_data.data_expecting_reply, data_expecting_reply, NULL);
|
||||
zassert_equal(npdu_data.network_layer_message, network_layer_message, NULL);
|
||||
@@ -95,7 +95,7 @@ static void testNPDU2(void)
|
||||
len = npdu_encode_pdu(&pdu[0], &dest, &src, &npdu_data);
|
||||
zassert_not_equal(len, 0, NULL);
|
||||
/* can we get the info back? */
|
||||
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
|
||||
npdu_len = bacnet_npdu_decode(pdu, sizeof(pdu), &npdu_dest, &npdu_src, &npdu_data);
|
||||
zassert_not_equal(npdu_len, 0, NULL);
|
||||
zassert_equal(npdu_data.data_expecting_reply, data_expecting_reply, NULL);
|
||||
zassert_equal(npdu_data.network_layer_message, network_layer_message, NULL);
|
||||
@@ -160,7 +160,7 @@ static void testNPDU1(void)
|
||||
len = npdu_encode_pdu(&pdu[0], &dest, &src, &npdu_data);
|
||||
zassert_not_equal(len, 0, NULL);
|
||||
/* can we get the info back? */
|
||||
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
|
||||
npdu_len = bacnet_npdu_decode(pdu, sizeof(pdu), &npdu_dest, &npdu_src, &npdu_data);
|
||||
zassert_not_equal(npdu_len, 0, NULL);
|
||||
zassert_equal(npdu_data.data_expecting_reply, data_expecting_reply, NULL);
|
||||
zassert_equal(npdu_data.network_layer_message, network_layer_message, NULL);
|
||||
|
||||
Reference in New Issue
Block a user