diff --git a/bacnet-stack/ports/at91sam7s/dlmstp.c b/bacnet-stack/ports/at91sam7s/dlmstp.c index 0cd79461..18c04e0b 100644 --- a/bacnet-stack/ports/at91sam7s/dlmstp.c +++ b/bacnet-stack/ports/at91sam7s/dlmstp.c @@ -1238,7 +1238,12 @@ int dlmstp_send_pdu( pkt->buffer[i] = pdu[i]; } pkt->length = pdu_len; - pkt->destination_mac = dest->mac[0]; + if (dest && dest->mac_len) { + pkt->destination_mac = dest->mac[0]; + } else { + /* mac_len = 0 is a broadcast address */ + pkt->destination_mac = MSTP_BROADCAST_ADDRESS; + } bytes_sent = pdu_len; } diff --git a/bacnet-stack/ports/atmega168/dlmstp.c b/bacnet-stack/ports/atmega168/dlmstp.c index c2bea1fc..fb01d121 100644 --- a/bacnet-stack/ports/atmega168/dlmstp.c +++ b/bacnet-stack/ports/atmega168/dlmstp.c @@ -987,7 +987,12 @@ int dlmstp_send_pdu( TransmitPacket = pdu; TransmitPacketLen = pdu_len; bytes_sent = pdu_len; - TransmitPacketDest = dest->mac[0]; + if (dest && dest->mac_len) { + TransmitPacketDest = dest->mac[0]; + } else { + /* mac_len = 0 is a broadcast address */ + TransmitPacketDest = MSTP_BROADCAST_ADDRESS; + } MSTP_Flag.TransmitPacketPending = true; } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c b/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c index 2387e304..7562b7f5 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c @@ -1201,7 +1201,12 @@ int dlmstp_send_pdu( pkt->buffer[i] = pdu[i]; } pkt->length = pdu_len; - pkt->destination_mac = dest->mac[0]; + if (dest && dest->mac_len) { + pkt->destination_mac = dest->mac[0]; + } else { + /* mac_len = 0 is a broadcast address */ + pkt->destination_mac = MSTP_BROADCAST_ADDRESS; + } bytes_sent = pdu_len; } diff --git a/bacnet-stack/ports/linux/dlmstp.c b/bacnet-stack/ports/linux/dlmstp.c index 073ef6ed..42cfcca8 100644 --- a/bacnet-stack/ports/linux/dlmstp.c +++ b/bacnet-stack/ports/linux/dlmstp.c @@ -161,7 +161,12 @@ int dlmstp_send_pdu( pkt->buffer[i] = pdu[i]; } pkt->length = pdu_len; - pkt->destination_mac = dest->mac[0]; + if (dest && dest->mac_len) { + pkt->destination_mac = dest->mac[0]; + } else { + /* mac_len = 0 is a broadcast address */ + pkt->destination_mac = MSTP_BROADCAST_ADDRESS; + } bytes_sent = pdu_len; } diff --git a/bacnet-stack/ports/pic18f6720/dlmstp.c b/bacnet-stack/ports/pic18f6720/dlmstp.c index 59d93cab..7877617c 100644 --- a/bacnet-stack/ports/pic18f6720/dlmstp.c +++ b/bacnet-stack/ports/pic18f6720/dlmstp.c @@ -105,10 +105,11 @@ int dlmstp_send_pdu( MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; /* load destination MAC address */ - if (dest && dest->mac_len == 1) { + if (dest && dest->mac_len) { MSTP_Port.TxDestination = dest->mac[0]; } else { - return -2; + /* mac_len = 0 is a broadcast address */ + MSTP_Port.TxDestination = MSTP_BROADCAST_ADDRESS; } dlmstp_get_my_address(&src); if ((MAX_HEADER + pdu_len) > MAX_MPDU) { diff --git a/bacnet-stack/ports/rtos32/dlmstp.c b/bacnet-stack/ports/rtos32/dlmstp.c index 1a3eddb7..9108a7ac 100644 --- a/bacnet-stack/ports/rtos32/dlmstp.c +++ b/bacnet-stack/ports/rtos32/dlmstp.c @@ -74,19 +74,17 @@ int dlmstp_send_pdu( unsigned mtu_len = 0; if (MSTP_Port.TxReady == false) { - if (npdu_data->confirmed_message) + if (npdu_data->confirmed_message) { MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY; - else + } else { MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; - + } /* load destination MAC address */ - if (dest && dest->mac_len == 1) { + if (dest->mac_len) { destination = dest->mac[0]; } else { -#if PRINT_ENABLED - fprintf(stderr, "mstp: invalid destination MAC address!\n"); -#endif - return -2; + /* mac_len = 0 is a broadcast address */ + destination = MSTP_BROADCAST_ADDRESS; } /* header len */ mtu_len = MAX_HEADER - 2 /* data crc */ ; diff --git a/bacnet-stack/ports/stm32f10x/dlmstp.c b/bacnet-stack/ports/stm32f10x/dlmstp.c index 7879f9bf..fd7d47ea 100644 --- a/bacnet-stack/ports/stm32f10x/dlmstp.c +++ b/bacnet-stack/ports/stm32f10x/dlmstp.c @@ -1281,10 +1281,10 @@ int dlmstp_send_pdu( pkt->buffer[i] = pdu[i]; } pkt->length = pdu_len; - if (dest->mac_len == 0) { - pkt->destination_mac = MSTP_BROADCAST_ADDRESS; - } else { + if (dest && dest->mac_len) { pkt->destination_mac = dest->mac[0]; + } else { + pkt->destination_mac = MSTP_BROADCAST_ADDRESS; } bytes_sent = pdu_len; } diff --git a/bacnet-stack/ports/win32/dlmstp-mm.c b/bacnet-stack/ports/win32/dlmstp-mm.c index 82c00fce..223d6976 100644 --- a/bacnet-stack/ports/win32/dlmstp-mm.c +++ b/bacnet-stack/ports/win32/dlmstp-mm.c @@ -291,10 +291,11 @@ uint16_t MSTP_Get_Send( return 0; } /* load destination MAC address */ - if (Transmit_Packet.address.mac_len == 1) { + /* load destination MAC address */ + if (Transmit_Packet.address.mac_len) { destination = Transmit_Packet.address.mac[0]; } else { - return 0; + destination = MSTP_BROADCAST_ADDRESS; } if ((MAX_HEADER + Transmit_Packet.pdu_len) > MAX_MPDU) { return 0; diff --git a/bacnet-stack/ports/win32/dlmstp.c b/bacnet-stack/ports/win32/dlmstp.c index d3c19802..d0b170a8 100644 --- a/bacnet-stack/ports/win32/dlmstp.c +++ b/bacnet-stack/ports/win32/dlmstp.c @@ -279,10 +279,10 @@ uint16_t MSTP_Get_Send( return 0; } /* load destination MAC address */ - if (Transmit_Packet.address.mac_len == 1) { + if (Transmit_Packet.address.mac_len) { destination = Transmit_Packet.address.mac[0]; } else { - return 0; + destination = MSTP_BROADCAST_ADDRESS; } if ((MAX_HEADER + Transmit_Packet.pdu_len) > MAX_MPDU) { return 0;