Contiki 2.6

6LowPan Ethernet Interop

Defines

#define DEBUG   0
#define LSB(u16)   (((uint8_t *)&(u16))[0])
 Least significant byte of u16.
#define MSB(u16)   (((uint8_t *)&(u16))[1])
 Most significant byte of u16.
#define TRANSLATE_BIT_MASK   (1<<2)
 Location of TRANSLATE (TR) bit in Ethernet address.
#define LOCAL_BIT_MASK   (1<<1)
 Location of LOCAL (GL) bit in Ethernet address.
#define MULTICAST_BIT_MASK   (1<<0)
 Location of MULTICAST (MU) bit in Ethernet address.

Functions

uint8_t mac_createSicslowpanLongAddr (uint8_t *ethernet, uip_lladdr_t *lowpan)
 Create a 802.15.4 long address from a 802.3 address.
uint8_t mac_createEthernetAddr (uint8_t *ethernet, uip_lladdr_t *lowpan)
 Create a 802.3 address from a 802.15.4 long address.
uint8_t mac_createDefaultEthernetAddr (uint8_t *ethernet)
 Create a 802.3 address (default)
void mac_ethhijack (const struct mac_driver *r)
 Process a received 6lowpan packet.
void mac_ethernetToLowpan (uint8_t *ethHeader)
 Take a packet received over the ethernet link, and send it out over 802.15.4.
void mac_LowpanToEthernet (void)
 Take a packet received over the 802.15.4 link, and send it out over ethernet, performing any translations needed.
int8_t mac_translateIPLinkLayer (lltype_t target)
 Translate IP packet's possible link-layer addresses, passing the message to the appropriate higher level function for this packet (aka: ICMP)
void slide (uint8_t *data, uint8_t length, int16_t slide)
 Slide the pointed to memory up a certain amount, growing/shrinking a buffer.
int8_t mac_translateIcmpLinkLayer (lltype_t target)
 Translate the link-layer (L2) addresses in an ICMP packet.

Variables

uint64_t macLongAddr
 Our own long address.
struct mac_driverpmac
 Perform any setup needed.

Define Documentation

#define DEBUG   0
Ethernet to 6LowPan Address Translation

It should be obvious that since 802.15.4 addresses are 8 bytes, and 802.3 addresses are 6 bytes, some form of address translation is needed. These routines provide this

802.3 Address Formats

802.3 MAC addresses used here have this form:

   +----+----+----+----+----+----+----+----+
   +    +    +    +    +    + TR + GL + MU +
   +----+----+----+----+----+----+----+----+
   

It can be seen this is like a normal ethernet MAC address, with GL being the Global/Local bit, and MU being the Multicast/Unicast bit.

The addition is the 'TR' bit, which if set indicates that the address must be translated when going between 802.15.4 and 802.3.

Address Translation

If the TRANSLATE (TR) bit is CLEAR, this means the 5th and 4th LSBytes of the 802.15.4 address are fffe, aka the address has the hexidecial form:

xxxxxxfffexxxxxx

Note:
You should always aim to set the 802.15.4 addresses of the devices on your network to ones that will satisfy this requirement. Some examples are:
0x02 23 42 ff fe 73 92 28
0x82 00 82 ff fe cd ee 22
So the most significant octets MUST have bit 0 CLEAR, bit 1 SET, and bit 2 CLEAR. The remaining bits in this octet can be anything.

If the TRANSLATE bit is SET, this means the address on the 802.3 side does not directly convert to an 802.15.4 address. To translate it, the remainder of the octet is used as an index in a look-up table. This look-up table simply stores the 4th, 5th, and 8th octet of the 802.15.4 address, and attaches them to the remaining 5 bytes of the 802.3 address.

In this way there can be 32 different 802.15.4 'prefixes', requiring only 96 bytes of RAM in a storage table on the 802.3 to 802.15.4 bridge.

Mulitcast addresses on 802.3 are mapped to broadcast addresses on 802.15.4 and vis-versa. Since IPv6 does not use 802.3 broadcast, this code will drop all 802.3 broadcast packets. They are most likely something unwanted, such as IPv4 packets that snuck in.

Notes on how addresses are stored

An 802.15.4 address will be reported for example as:

0x8877665544332211

Stored in the array as passed to these functions, it will be:

   array[0] = 0x88;
   array[1] = 0x77;
   array[2] = 0x66;
   etc.
   

An 802.3 address will be reported for example as: 02:43:53:35:45:45

Stored in the array as passed to these functions, it will be:

   array[0] = 0x02;
   array[1] = 0x43;
   array[2] = 0x53;
   array[3] = 0x35
   etc.
   

Definition at line 244 of file sicslow_ethernet.c.


Function Documentation

uint8_t mac_createDefaultEthernetAddr ( uint8_t *  ethernet)

Create a 802.3 address (default)

Parameters:
ethernetPointer to ethernet address

Definition at line 925 of file sicslow_ethernet.c.

Referenced by mac_LowpanToEthernet(), and mac_translateIcmpLinkLayer().

uint8_t mac_createEthernetAddr ( uint8_t *  ethernet,
uip_lladdr_t lowpan 
)

Create a 802.3 address from a 802.15.4 long address.

Parameters:
ethernetPointer to ethernet address
lowpanPointer to 802.15.4 address

UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS

Definition at line 824 of file sicslow_ethernet.c.

References LOCAL_BIT_MASK, macLongAddr, MULTICAST_BIT_MASK, and TRANSLATE_BIT_MASK.

Referenced by mac_LowpanToEthernet(), and mac_translateIcmpLinkLayer().

uint8_t mac_createSicslowpanLongAddr ( uint8_t *  ethernet,
uip_lladdr_t lowpan 
)

Create a 802.15.4 long address from a 802.3 address.

Parameters:
ethernetPointer to ethernet address
lowpanPointer to 802.15.4 address

UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS

Definition at line 749 of file sicslow_ethernet.c.

References LOCAL_BIT_MASK, macLongAddr, MULTICAST_BIT_MASK, and TRANSLATE_BIT_MASK.

Referenced by mac_ethernetToLowpan(), and mac_translateIcmpLinkLayer().

void mac_ethhijack ( const struct mac_driver r)

Process a received 6lowpan packet.

Hijack function.

Parameters:
rThe MAC layer

The 6lowpan packet is put in packetbuf by the MAC. This routine calls any other needed layers (either 6lowpan, or just raw ethernet dump)

Definition at line 1070 of file sicslow_ethernet.c.

References mac_802154raw().

int8_t mac_translateIcmpLinkLayer ( lltype_t  target)

Translate the link-layer (L2) addresses in an ICMP packet.

This will just be NA/NS/RA/RS packets currently.

Parameters:
targetThe target we want to end up with - either ll_8023_type for ethernet, or ll_802154_type for 802.15.4
Returns:
Returns how successful the translation was
Return values:
0Addresses, if present, were translated.
-1ICMP message was unknown type, nothing done.
-2ICMP Length does not make sense?
-3Unknown 'target' type

Things without link-layer

Definition at line 603 of file sicslow_ethernet.c.

References ICMP6_DST_UNREACH, ICMP6_ECHO_REPLY, ICMP6_ECHO_REQUEST, ICMP6_NA, ICMP6_NS, ICMP6_PACKET_TOO_BIG, ICMP6_PARAM_PROB, ICMP6_RA, ICMP6_REDIRECT, ICMP6_RS, ICMP6_TIME_EXCEEDED, mac_createDefaultEthernetAddr(), mac_createEthernetAddr(), mac_createSicslowpanLongAddr(), slide(), uip_icmp6chksum(), UIP_ICMP_BUF, UIP_IP_BUF, uip_len, and UIP_ND6_OPT_SLLAO.

Referenced by mac_translateIPLinkLayer().

int8_t mac_translateIPLinkLayer ( lltype_t  target)

Translate IP packet's possible link-layer addresses, passing the message to the appropriate higher level function for this packet (aka: ICMP)

Parameters:
targetThe target we want to end up with - either ll_8023_type for ethernet, or ll_802154_type for 802.15.4
Returns:
Returns how successful the translation was
Return values:
0Addresses, if present, were translated.
<0Negative return values indicate various errors, as defined by the higher level function.

Definition at line 563 of file sicslow_ethernet.c.

References mac_translateIcmpLinkLayer(), and UIP_IP_BUF.

Referenced by mac_ethernetToLowpan(), and mac_LowpanToEthernet().

void slide ( uint8_t *  data,
uint8_t  length,
int16_t  slide 
)

Slide the pointed to memory up a certain amount, growing/shrinking a buffer.

Parameters:
dataPointer to start of data buffer
lengthLength of the data buffer
slideHow many bytes to slide the buffer up in memory (if +) or down in memory (if -)

Definition at line 938 of file sicslow_ethernet.c.

Referenced by mac_translateIcmpLinkLayer().


Variable Documentation

uint64_t macLongAddr

Our own long address.

This needs to be read from EEPROM or other secure memory storage.

Definition at line 145 of file mac.c.

Referenced by mac_createEthernetAddr(), mac_createSicslowpanLongAddr(), mac_init(), menu_process(), and sicslowmac_resetRequest().