Contiki 2.5
|
Macros | |
#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. More... | |
uint8_t | mac_createEthernetAddr (uint8_t *ethernet, uip_lladdr_t *lowpan) |
Create a 802.3 address from a 802.15.4 long address. More... | |
uint8_t | mac_createDefaultEthernetAddr (uint8_t *ethernet) |
Create a 802.3 address (default) More... | |
void | mac_ethhijack (const struct mac_driver *r) |
Process a received 6lowpan packet. More... | |
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) More... | |
void | slide (uint8_t *data, uint8_t length, int16_t slide) |
Slide the pointed to memory up a certain amount, growing/shrinking a buffer. More... | |
int8_t | mac_translateIcmpLinkLayer (lltype_t target) |
Translate the link-layer (L2) addresses in an ICMP packet. More... | |
Variables | |
uint64_t | macLongAddr |
Our own long address. More... | |
struct mac_driver * | pmac |
Perform any setup needed. | |
#define DEBUG 0 |
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 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.
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
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.
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.
uint8_t mac_createDefaultEthernetAddr | ( | uint8_t * | ethernet | ) |
Create a 802.3 address (default)
ethernet | Pointer 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.
ethernet | Pointer to ethernet address |
lowpan | Pointer 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.
ethernet | Pointer to ethernet address |
lowpan | Pointer 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.
r | The 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.
target | The target we want to end up with - either ll_8023_type for ethernet, or ll_802154_type for 802.15.4 |
0 | Addresses, if present, were translated. |
-1 | ICMP message was unknown type, nothing done. |
-2 | ICMP Length does not make sense? |
-3 | Unknown '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, and uip_len.
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)
target | The target we want to end up with - either ll_8023_type for ethernet, or ll_802154_type for 802.15.4 |
0 | Addresses, if present, were translated. |
<0 | Negative 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.
data | Pointer to start of data buffer |
length | Length of the data buffer |
slide | How 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().
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().