Skip to content

Commit

Permalink
Merge pull request #2600 from authmillenon/ipv6_nc/feat/mc-translation
Browse files Browse the repository at this point in the history
[RFC] ng_netif_hdr: add flags for multicast and broadcast
  • Loading branch information
miri64 committed Apr 14, 2015
2 parents 1af6126 + fa2ab8b commit 67602bb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
18 changes: 16 additions & 2 deletions drivers/xbee/xbee.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate,
return 0;
}

static inline bool _is_broadcast(ng_netif_hdr_t *hdr) {
/* IEEE 802.15.4 does not support multicast so we need to check both flags */
return (bool)(hdr->flags & (NG_NETIF_HDR_FLAGS_BROADCAST |
NG_NETIF_HDR_FLAGS_MULTICAST));
}

int _send(ng_netdev_t *netdev, ng_pktsnip_t *pkt)
{
xbee_t *dev = (xbee_t *)netdev;
Expand All @@ -510,9 +516,10 @@ int _send(ng_netdev_t *netdev, ng_pktsnip_t *pkt)
ng_pktbuf_release(pkt);
return -EOVERFLOW;
}
/* get netif header check address length */
/* get netif header check address length and flags */
hdr = (ng_netif_hdr_t *)pkt->data;
if (!(hdr->dst_l2addr_len == 2 || hdr->dst_l2addr_len == 8)) {
if (!((hdr->dst_l2addr_len == 2) || (hdr->dst_l2addr_len == 8) ||
_is_broadcast(hdr))) {
ng_pktbuf_release(pkt);
return -ENOMSG;
}
Expand All @@ -523,6 +530,13 @@ int _send(ng_netdev_t *netdev, ng_pktsnip_t *pkt)
dev->tx_buf[0] = API_START_DELIMITER;
dev->tx_buf[4] = 0; /* set to zero to disable response frame */
/* set size, API id and address field depending on dst address length */
if (_is_broadcast(hdr)) {
dev->tx_buf[1] = (uint8_t)((size + 5) >> 8);
dev->tx_buf[2] = (uint8_t)(size + 5);
dev->tx_buf[3] = API_ID_TX_SHORT_ADDR;
dev->tx_buf[4] = 0xff;
dev->tx_buf[5] = 0xff;
}
if (hdr->dst_l2addr_len == 2) {
dev->tx_buf[1] = (uint8_t)((size + 5) >> 8);
dev->tx_buf[2] = (uint8_t)(size + 5);
Expand Down
33 changes: 33 additions & 0 deletions sys/include/net/ng_netif/hdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@
extern "C" {
#endif

/**
* @{
* @name Flags for the ng_netif_hdr_t
*/
/**
* @brief Send packet broadcast.
*
* @details Packets with this flag set must be send broadcast.
* ng_netif_hdr_t::dst_l2addr_len and any appended destination
* address must be ignored.
* If the link layer does not support broadcast the packet must be
* dropped silently.
*/
#define NG_NETIF_HDR_FLAGS_BROADCAST (0x80)

/**
* @brief Send packet multicast.
*
* @details Packets with this flag set must be send multicast.
* ng_netif_hdr_t::dst_l2addr_len and any appended destination
* address must be ignored.
* The context for the multicast address must be derived from the
* network layer destination address.
* If the link layer does not support multicast it should interpret
* this flag the same way it does @ref NG_NETIF_HDR_FLAGS_BROADCAST.
*/
#define NG_NETIF_HDR_FLAGS_MULTICAST (0x40)
/**
* @}
*/

/**
* @brief Generic network interface header
*
Expand All @@ -42,6 +73,7 @@ typedef struct __attribute__((packed)) {
uint8_t src_l2addr_len; /**< length of l2 source address in byte */
uint8_t dst_l2addr_len; /**< length of l2 destination address in byte */
kernel_pid_t if_pid; /**< PID of network interface */
uint8_t flags; /**< flags as defined above */
uint8_t rssi; /**< rssi of received packet (optional) */
uint8_t lqi; /**< lqi of received packet (optional) */
} ng_netif_hdr_t;
Expand All @@ -61,6 +93,7 @@ static inline void ng_netif_hdr_init(ng_netif_hdr_t *hdr, uint8_t src_l2addr_len
hdr->if_pid = KERNEL_PID_UNDEF;
hdr->rssi = 0;
hdr->lqi = 0;
hdr->flags = 0;
}

/**
Expand Down
14 changes: 10 additions & 4 deletions sys/shell/commands/sc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ int _netif_send(int argc, char **argv)
size_t addr_len;
ng_pktsnip_t *pkt;
ng_netif_hdr_t *nethdr;

uint8_t flags = 0x00;

if (argc < 4) {
printf("usage: %s <if> <addr> <data>\n", argv[0]);
printf("usage: %s <if> [<addr>|bcast] <data>\n", argv[0]);
return 1;
}

Expand All @@ -388,8 +388,13 @@ int _netif_send(int argc, char **argv)
addr_len = ng_netif_addr_from_str(addr, sizeof(addr), argv[2]);

if (addr_len == 0) {
puts("error: invalid address given");
return 1;
if (strcmp(argv[2], "bcast") == 0) {
flags |= NG_NETIF_HDR_FLAGS_BROADCAST;
}
else {
puts("error: invalid address given");
return 1;
}
}

/* put packet together */
Expand All @@ -399,6 +404,7 @@ int _netif_send(int argc, char **argv)
nethdr = (ng_netif_hdr_t *)pkt->data;
ng_netif_hdr_init(nethdr, 0, addr_len);
ng_netif_hdr_set_dst_addr(nethdr, addr, addr_len);
nethdr->flags = flags;
/* and send it */
ng_netapi_send(dev, pkt);

Expand Down

0 comments on commit 67602bb

Please sign in to comment.