Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions zephyr/subsys/bacnet_datalink/bip-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ int bip_send_pdu(
uint8_t *pdu,
unsigned pdu_len)
{
dest->net = BACNET_BROADCAST_NETWORK;
return bvlc_send_pdu(dest, npdu_data, pdu, pdu_len);
}

Expand Down Expand Up @@ -636,7 +635,14 @@ bool bip_init(const char *ifname)
int sock_fd;
struct sockaddr_in sin = { 0 };

bip_set_interface(ifname);
/* Only call bip_set_interface() if we don't have an address yet.
* On re-init after bip_cleanup() (port change / enable-disable cycle)
* BIP_Address is already populated from the initial DHCP assignment, so
* calling bip_set_interface() again would try to re-add a MANUAL address
* on top of the DHCP one and corrupt the interface netmask. */
if (BIP_Address.s_addr == 0) {
bip_set_interface(ifname);
}

if (BIP_Address.s_addr == 0) {
LOG_ERR(
Expand Down Expand Up @@ -685,13 +691,18 @@ void bip_cleanup(void)
{
LOG_DBG("bip_cleanup()");

memset(&BIP_Address, 0, sizeof(BIP_Address));
memset(&BIP_Broadcast_Addr, 0, sizeof(BIP_Broadcast_Addr));

/* Only close the sockets — preserve BIP_Address and BIP_Broadcast_Addr so
* that a subsequent bip_init() takes the static (non-blocking) path in
* bip_set_interface() instead of blocking on wait_for_net_event() again. */
if (BIP_Socket != -1) {
zsock_close(BIP_Socket);
}
BIP_Socket = -1;

if (BIP_Broadcast_Socket != -1) {
zsock_close(BIP_Broadcast_Socket);
}
BIP_Broadcast_Socket = -1;

return;
}