diff --git a/core/net/llsec/anti-replay.c b/core/net/llsec/anti-replay.c index 45168ef57..c56d90e0b 100644 --- a/core/net/llsec/anti-replay.c +++ b/core/net/llsec/anti-replay.c @@ -87,7 +87,7 @@ anti_replay_was_replayed(struct anti_replay_info *info) received_counter = anti_replay_get_counter(); - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { /* broadcast */ if(received_counter <= info->last_broadcast_counter) { return 1; diff --git a/core/net/mac/contikimac/contikimac.c b/core/net/mac/contikimac/contikimac.c index e46f51bff..bc3be6566 100644 --- a/core/net/mac/contikimac/contikimac.c +++ b/core/net/mac/contikimac/contikimac.c @@ -522,7 +522,7 @@ send_packet(mac_callback_t mac_callback, void *mac_callback_ptr, /* If NETSTACK_CONF_BRIDGE_MODE is set, assume PACKETBUF_ADDR_SENDER is already set. */ packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &linkaddr_node_addr); #endif - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { is_broadcast = 1; PRINTDEBUG("contikimac: send broadcast\n"); @@ -876,8 +876,7 @@ input_packet(void) packetbuf_totlen() > 0 && (linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_node_addr) || - linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), - &linkaddr_null))) { + packetbuf_holds_broadcast())) { /* This is a regular packet that is destined to us or to the broadcast address. */ diff --git a/core/net/mac/cxmac/cxmac.c b/core/net/mac/cxmac/cxmac.c index 7bb55f227..31032c372 100644 --- a/core/net/mac/cxmac/cxmac.c +++ b/core/net/mac/cxmac/cxmac.c @@ -433,7 +433,7 @@ send_packet(void) /* If NETSTACK_CONF_BRIDGE_MODE is set, assume PACKETBUF_ADDR_SENDER is already set. */ packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &linkaddr_node_addr); #endif - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { is_broadcast = 1; PRINTDEBUG("cxmac: send broadcast\n"); } else { diff --git a/core/net/mac/framer-802154.c b/core/net/mac/framer-802154.c index f1da770a7..03b091feb 100644 --- a/core/net/mac/framer-802154.c +++ b/core/net/mac/framer-802154.c @@ -104,7 +104,7 @@ create_frame(int type, int do_create) /* Build the FCF. */ params.fcf.frame_type = packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE); params.fcf.frame_pending = packetbuf_attr(PACKETBUF_ATTR_PENDING); - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { params.fcf.ack_required = 0; } else { params.fcf.ack_required = packetbuf_attr(PACKETBUF_ATTR_MAC_ACK); @@ -159,11 +159,7 @@ create_frame(int type, int do_create) } params.dest_pid = mac_dst_pan_id; - /* - * If the output address is NULL in the Rime buf, then it is broadcast - * on the 802.15.4 network. - */ - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { /* Broadcast requires short address mode. */ params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; params.dest_addr[0] = 0xFF; diff --git a/core/net/mac/nullrdc.c b/core/net/mac/nullrdc.c index 7f92495e8..3403b764e 100644 --- a/core/net/mac/nullrdc.c +++ b/core/net/mac/nullrdc.c @@ -132,8 +132,7 @@ send_one_packet(mac_callback_t sent, void *ptr) NETSTACK_RADIO.prepare(packetbuf_hdrptr(), packetbuf_totlen()); - is_broadcast = linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), - &linkaddr_null); + is_broadcast = packetbuf_holds_broadcast(); if(NETSTACK_RADIO.receiving_packet() || (!is_broadcast && NETSTACK_RADIO.pending_packet())) { @@ -282,8 +281,7 @@ packet_input(void) #if NULLRDC_ADDRESS_FILTER } else if(!linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_node_addr) && - !linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), - &linkaddr_null)) { + !packetbuf_holds_broadcast()) { PRINTF("nullrdc: not for us\n"); #endif /* NULLRDC_ADDRESS_FILTER */ } else { diff --git a/core/net/mac/sicslowmac/sicslowmac.c b/core/net/mac/sicslowmac/sicslowmac.c index 56db88ff5..9d88a6b78 100644 --- a/core/net/mac/sicslowmac/sicslowmac.c +++ b/core/net/mac/sicslowmac/sicslowmac.c @@ -123,11 +123,7 @@ send_packet(mac_callback_t sent, void *ptr) params.fcf.src_addr_mode = FRAME802154_LONGADDRMODE; params.dest_pid = mac_dst_pan_id; - /* - * If the output address is NULL in the Rime buf, then it is broadcast - * on the 802.15.4 network. - */ - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { /* Broadcast requires short address mode. */ params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; params.dest_addr[0] = 0xFF; diff --git a/core/net/packetbuf.c b/core/net/packetbuf.c index e67c8cf12..43994f61e 100644 --- a/core/net/packetbuf.c +++ b/core/net/packetbuf.c @@ -320,4 +320,11 @@ packetbuf_addr(uint8_t type) } /*---------------------------------------------------------------------------*/ #endif /* PACKETBUF_CONF_ATTRS_INLINE */ +int +packetbuf_holds_broadcast(void) +{ + return linkaddr_cmp(&packetbuf_addrs[PACKETBUF_ADDR_RECEIVER - PACKETBUF_ADDR_FIRST].addr, &linkaddr_null); +} +/*---------------------------------------------------------------------------*/ + /** @} */ diff --git a/core/net/packetbuf.h b/core/net/packetbuf.h index 2bfffd2dd..86e44bb16 100644 --- a/core/net/packetbuf.h +++ b/core/net/packetbuf.h @@ -453,6 +453,12 @@ int packetbuf_set_addr(uint8_t type, const linkaddr_t *addr); const linkaddr_t *packetbuf_addr(uint8_t type); #endif /* PACKETBUF_CONF_ATTRS_INLINE */ +/** + * \brief Checks whether the current packet is a broadcast. + * \retval 0 iff current packet is not a broadcast + */ +int packetbuf_holds_broadcast(void); + void packetbuf_attr_clear(void); void packetbuf_attr_copyto(struct packetbuf_attr *attrs, diff --git a/cpu/avr/radio/mac/sicslowmac.c b/cpu/avr/radio/mac/sicslowmac.c index 0d21d997e..9a176277a 100644 --- a/cpu/avr/radio/mac/sicslowmac.c +++ b/cpu/avr/radio/mac/sicslowmac.c @@ -426,11 +426,7 @@ sicslowmac_dataRequest(void) params.fcf.srcAddrMode = LONGADDRMODE; params.dest_pid = ieee15_4ManagerAddress.get_dst_panid(); - /* - * If the output address is NULL in the Rime buf, then it is broadcast - * on the 802.15.4 network. - */ - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null) ) { + if(packetbuf_holds_broadcast()) { /* Broadcast requires short address mode. */ params.fcf.destAddrMode = SHORTADDRMODE; params.dest_pid = BROADCASTPANDID; diff --git a/platform/avr-ravenusb/sicslow_ethernet.c b/platform/avr-ravenusb/sicslow_ethernet.c index 9acfcd1e8..380adb53b 100644 --- a/platform/avr-ravenusb/sicslow_ethernet.c +++ b/platform/avr-ravenusb/sicslow_ethernet.c @@ -481,11 +481,8 @@ void mac_LowpanToEthernet(void) //Setup generic ethernet stuff ETHBUF(uip_buf)->type = uip_htons(UIP_ETHTYPE_IPV6); - //Check for broadcast message - #if RF230BB - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { -// if(linkaddr_cmp((const linkaddr_t *)destAddr, &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { #else if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) && ( parsed_frame->dest_addr->addr16 == 0xffff) ) { @@ -977,7 +974,7 @@ mac_log_802_15_4_tx(const uint8_t* buffer, size_t total_len) { ETHBUF(raw_buf)->type = uip_htons(0x809A); //UIP_ETHTYPE_802154 0x809A /* Check for broadcast message */ - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { ETHBUF(raw_buf)->dest.addr[0] = 0x33; ETHBUF(raw_buf)->dest.addr[1] = 0x33; ETHBUF(raw_buf)->dest.addr[2] = 0x00; @@ -1018,7 +1015,7 @@ mac_log_802_15_4_rx(const uint8_t* buf, size_t len) { ETHBUF(raw_buf)->type = uip_htons(0x809A); //UIP_ETHTYPE_802154 0x809A /* Check for broadcast message */ - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { ETHBUF(raw_buf)->dest.addr[0] = 0x33; ETHBUF(raw_buf)->dest.addr[1] = 0x33; ETHBUF(raw_buf)->dest.addr[2] = 0x00; diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c index 29967d1c0..a74415020 100644 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ b/tools/sky/uip6-bridge/sicslow_ethernet.c @@ -312,7 +312,7 @@ void mac_LowpanToEthernet(void) ETHBUF(uip_buf)->type = uip_htons(UIP_ETHTYPE_IPV6); //Check for broadcast message - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { /* if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) && */ /* ( parsed_frame->dest_addr->addr16 == 0xffff) ) { */ ETHBUF(uip_buf)->dest.addr[0] = 0x33; diff --git a/tools/stm32w/uip6_bridge/sicslow_ethernet.c b/tools/stm32w/uip6_bridge/sicslow_ethernet.c index 9bd68d0ad..440ed9504 100644 --- a/tools/stm32w/uip6_bridge/sicslow_ethernet.c +++ b/tools/stm32w/uip6_bridge/sicslow_ethernet.c @@ -339,7 +339,7 @@ void mac_LowpanToEthernet(void) ETHBUF(uip_buf)->type = htons(UIP_ETHTYPE_IPV6); //Check for broadcast message - if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) { + if(packetbuf_holds_broadcast()) { /* if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) && */ /* ( parsed_frame->dest_addr->addr16 == 0xffff) ) { */ ETHBUF(uip_buf)->dest.addr[0] = 0x33;