Skip to content

Commit

Permalink
core/net: Added support for "bridge mode".
Browse files Browse the repository at this point in the history
"Bridge mode" allows devices to more easily send 802.15.4 packets as if
they were a different device. It also turns off any packet filtering
that may be implemented at layer 2. It works by allowing
`PACKETBUF_ADDR_SENDER` to be set earlier in the stack.

This is useful for implementing 6LoWPAN-ethernet bridges.

Enabled via setting `NETSTACK_CONF_BRIDGE_MODE` to 1. Disabled by
default.
  • Loading branch information
darconeous committed Mar 10, 2013
1 parent 4e40cb8 commit c0a6936
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/net/mac/contikimac.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,10 @@ send_packet(mac_callback_t mac_callback, void *mac_callback_ptr, struct rdc_buf_
return MAC_TX_ERR_FATAL;
}

#if !NETSTACK_CONF_BRIDGE_MODE
/* If NETSTACK_CONF_BRIDGE_MODE is set, assume PACKETBUF_ADDR_SENDER is already set. */
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &rimeaddr_node_addr);
#endif
if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
is_broadcast = 1;
PRINTDEBUG("contikimac: send broadcast\n");
Expand Down
3 changes: 3 additions & 0 deletions core/net/mac/cxmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,10 @@ send_packet(void)


/* Create the X-MAC header for the data packet. */
#if !NETSTACK_CONF_BRIDGE_MODE
/* If NETSTACK_CONF_BRIDGE_MODE is set, assume PACKETBUF_ADDR_SENDER is already set. */
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &rimeaddr_node_addr);
#endif
if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
is_broadcast = 1;
PRINTDEBUG("cxmac: send broadcast\n");
Expand Down
6 changes: 6 additions & 0 deletions core/net/mac/sicslowmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ send_packet(mac_callback_t sent, void *ptr)
* Set up the source address using only the long address mode for
* phase 1.
*/
#if NETSTACK_CONF_BRIDGE_MODE
rimeaddr_copy((rimeaddr_t *)&params.src_addr,packetbuf_addr(PACKETBUF_ADDR_SENDER));
#else
rimeaddr_copy((rimeaddr_t *)&params.src_addr, &rimeaddr_node_addr);
#endif

params.payload = packetbuf_dataptr();
params.payload_len = packetbuf_datalen();
Expand Down Expand Up @@ -203,12 +207,14 @@ input_packet(void)
}
if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (rimeaddr_t *)&frame.dest_addr);
#if !NETSTACK_CONF_BRIDGE_MODE
if(!rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
&rimeaddr_node_addr)) {
/* Not for this node */
PRINTF("6MAC: not for us\n");
return;
}
#endif
}
}
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (rimeaddr_t *)&frame.src_addr);
Expand Down
5 changes: 5 additions & 0 deletions core/net/sicslowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,11 @@ send_packet(rimeaddr_t *dest)
*/
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, dest);

#if NETSTACK_CONF_BRIDGE_MODE
/* This needs to be explicitly set here for bridge mode to work */
packetbuf_set_addr(PACKETBUF_ADDR_SENDER,(void*)&uip_lladdr);
#endif

/* Force acknowledge from sender (test hardware autoacks) */
#if SICSLOWPAN_CONF_ACK_ALL
packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, 1);
Expand Down

0 comments on commit c0a6936

Please sign in to comment.