diff --git a/CHANGELOG.md b/CHANGELOG.md index 16aa26c5..ea2f1251 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apps/initrouter/main.c b/apps/initrouter/main.c index 763e960d..948693bf 100644 --- a/apps/initrouter/main.c +++ b/apps/initrouter/main.c @@ -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], diff --git a/apps/mstpcap/main.c b/apps/mstpcap/main.c index 53f6ed7b..8d127cd3 100644 --- a/apps/mstpcap/main.c +++ b/apps/mstpcap/main.c @@ -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; diff --git a/apps/netnumis/main.c b/apps/netnumis/main.c index d3af0a3b..d7337f4b 100644 --- a/apps/netnumis/main.c +++ b/apps/netnumis/main.c @@ -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)); diff --git a/apps/router-ipv6/main.c b/apps/router-ipv6/main.c index e5007f71..480923a9 100644 --- a/apps/router-ipv6/main.c +++ b/apps/router-ipv6/main.c @@ -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) { diff --git a/apps/router-mstp/main.c b/apps/router-mstp/main.c index ab5ea450..5f1073af 100644 --- a/apps/router-mstp/main.c +++ b/apps/router-mstp/main.c @@ -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) { diff --git a/apps/router/main.c b/apps/router/main.c index ba2e9fa8..8a7624cf 100644 --- a/apps/router/main.c +++ b/apps/router/main.c @@ -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); diff --git a/apps/router/network_layer.c b/apps/router/network_layer.c index d0dc3884..862fad5a 100644 --- a/apps/router/network_layer.c +++ b/apps/router/network_layer.c @@ -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); diff --git a/apps/whatisnetnum/main.c b/apps/whatisnetnum/main.c index 60e7a5ed..3f0d17bb 100644 --- a/apps/whatisnetnum/main.c +++ b/apps/whatisnetnum/main.c @@ -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)); diff --git a/apps/whoisrouter/main.c b/apps/whoisrouter/main.c index c6c2d872..6db782bf 100644 --- a/apps/whoisrouter/main.c +++ b/apps/whoisrouter/main.c @@ -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)); diff --git a/ports/at91sam7s/dlmstp.c b/ports/at91sam7s/dlmstp.c index 62fc7e88..607a8230 100644 --- a/ports/at91sam7s/dlmstp.c +++ b/ports/at91sam7s/dlmstp.c @@ -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; } diff --git a/ports/bdk-atxx4-mstp/dlmstp.c b/ports/bdk-atxx4-mstp/dlmstp.c index b0d8e726..750d6bb9 100644 --- a/ports/bdk-atxx4-mstp/dlmstp.c +++ b/ports/bdk-atxx4-mstp/dlmstp.c @@ -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; } diff --git a/ports/linux/dlmstp.c b/ports/linux/dlmstp.c index 0af1a24f..c30dba45 100644 --- a/ports/linux/dlmstp.c +++ b/ports/linux/dlmstp.c @@ -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 - diff --git a/ports/linux/dlmstp_linux.c b/ports/linux/dlmstp_linux.c index ce924f02..6ea4ecb9 100644 --- a/ports/linux/dlmstp_linux.c +++ b/ports/linux/dlmstp_linux.c @@ -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, diff --git a/ports/pic18f6720/mstp.c b/ports/pic18f6720/mstp.c index eaae855d..adc9fa0d 100644 --- a/ports/pic18f6720/mstp.c +++ b/ports/pic18f6720/mstp.c @@ -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 diff --git a/ports/pic18f97j60/mstp.c b/ports/pic18f97j60/mstp.c index b4344c61..f61daad3 100644 --- a/ports/pic18f97j60/mstp.c +++ b/ports/pic18f97j60/mstp.c @@ -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 diff --git a/ports/stm32f4xx/dlmstp.c b/ports/stm32f4xx/dlmstp.c index 2a3fac5b..2f8e0683 100644 --- a/ports/stm32f4xx/dlmstp.c +++ b/ports/stm32f4xx/dlmstp.c @@ -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 { diff --git a/ports/win32/dlmstp-mm.c b/ports/win32/dlmstp-mm.c index 284780a3..6b2dc7e0 100644 --- a/ports/win32/dlmstp-mm.c +++ b/ports/win32/dlmstp-mm.c @@ -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; } diff --git a/ports/win32/dlmstp.c b/ports/win32/dlmstp.c index 8fccf21c..49f9f91b 100644 --- a/ports/win32/dlmstp.c +++ b/ports/win32/dlmstp.c @@ -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; } diff --git a/ports/xplained/dlmstp.c b/ports/xplained/dlmstp.c index 351d223d..9f51131b 100644 --- a/ports/xplained/dlmstp.c +++ b/ports/xplained/dlmstp.c @@ -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; } diff --git a/src/bacnet/basic/npdu/h_routed_npdu.c b/src/bacnet/basic/npdu/h_routed_npdu.c index 69449ce0..ba754b4b 100644 --- a/src/bacnet/basic/npdu/h_routed_npdu.c +++ b/src/bacnet/basic/npdu/h_routed_npdu.c @@ -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) { diff --git a/src/bacnet/npdu.h b/src/bacnet/npdu.h index b1ecaff6..484f2509 100644 --- a/src/bacnet/npdu.h +++ b/src/bacnet/npdu.h @@ -27,6 +27,7 @@ #include #include #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, diff --git a/test/bacnet/npdu/src/main.c b/test/bacnet/npdu/src/main.c index 8098b0d4..0e930969 100644 --- a/test/bacnet/npdu/src/main.c +++ b/test/bacnet/npdu/src/main.c @@ -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);