|
Contiki 3.x
|
6lowpan is a Working Group in IETF which defines the use of IPv6 on IEEE 802.15.4 links. More...
Data Structures | |
| struct | sicslowpan_addr_context |
| The header for fragments. More... | |
| struct | sicslowpan_nh_compressor |
| The structure of a next header compressor. More... | |
Macros | |
| #define | DEBUG DEBUG_NONE |
| FOR HC-06 COMPLIANCE TODO: -Add compression options to UDP, currently only supports both ports compressed or both ports elided. More... | |
| #define | MAC_MAX_PAYLOAD (127 - 2) |
| Maximum available size for frame headers, link layer security-related overhead, as well as 6LoWPAN payload. More... | |
| #define | COMPRESSION_THRESHOLD 0 |
| Some MAC layers need a minimum payload, which is configurable through the SICSLOWPAN_CONF_COMPRESSION_THRESHOLD option. More... | |
| #define | SICSLOWPAN_FIXED_HDRLEN 21 |
| Fixed size of a frame header. More... | |
Pointers in the packetbuf buffer | |
| #define | PACKETBUF_FRAG_PTR (packetbuf_ptr) |
| #define | PACKETBUF_FRAG_DISPATCH_SIZE 0 /* 16 bit */ |
| #define | PACKETBUF_FRAG_TAG 2 /* 16 bit */ |
| #define | PACKETBUF_FRAG_OFFSET 4 /* 8 bit */ |
| #define | PACKETBUF_IPHC_BUF ((uint8_t *)(packetbuf_ptr + packetbuf_hdr_len)) |
| #define | PACKETBUF_HC1_PTR (packetbuf_ptr + packetbuf_hdr_len) |
| #define | PACKETBUF_HC1_DISPATCH 0 /* 8 bit */ |
| #define | PACKETBUF_HC1_ENCODING 1 /* 8 bit */ |
| #define | PACKETBUF_HC1_TTL 2 /* 8 bit */ |
| #define | PACKETBUF_HC1_HC_UDP_PTR (packetbuf_ptr + packetbuf_hdr_len) |
| #define | PACKETBUF_HC1_HC_UDP_DISPATCH 0 /* 8 bit */ |
| #define | PACKETBUF_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */ |
| #define | PACKETBUF_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */ |
| #define | PACKETBUF_HC1_HC_UDP_TTL 3 /* 8 bit */ |
| #define | PACKETBUF_HC1_HC_UDP_PORTS 4 /* 8 bit */ |
| #define | PACKETBUF_HC1_HC_UDP_CHKSUM 5 /* 16 bit */ |
Pointers in the sicslowpan and uip buffer | |
| #define | SICSLOWPAN_IP_BUF(buf) ((struct uip_ip_hdr *)buf) |
| #define | SICSLOWPAN_UDP_BUF(buf) ((struct uip_udp_hdr *)&buf[UIP_IPH_LEN]) |
| #define | UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) |
| #define | UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLIPH_LEN]) |
| #define | UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[UIP_LLIPH_LEN]) |
| #define | UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN]) |
General variables | |
| static uint8_t * | packetbuf_ptr |
| A pointer to the packetbuf buffer. More... | |
| static uint8_t | packetbuf_hdr_len |
| packetbuf_hdr_len is the total length of (the processed) 6lowpan headers (fragment headers, IPV6 or HC1, HC2, and HC1 and HC2 non compressed fields). | |
| static int | packetbuf_payload_len |
| The length of the payload in the Packetbuf buffer. More... | |
| static uint8_t | uncomp_hdr_len |
| uncomp_hdr_len is the length of the headers before compression (if HC2 is used this includes the UDP header in addition to the IP header). | |
| static int | last_tx_status |
| the result of the last transmitted fragment | |
HC06 specific variables | |
| static struct sicslowpan_addr_context * | context |
| Addresses contexts for IPHC. More... | |
| static uint8_t * | hc06_ptr |
| pointer to the byte where to write next inline field. More... | |
| const uint8_t | unc_llconf [] = {0x0f,0x28,0x22,0x20} |
| const uint8_t | unc_ctxconf [] = {0x00,0x88,0x82,0x80} |
| const uint8_t | unc_mxconf [] = {0x0f, 0x25, 0x23, 0x21} |
| const uint8_t | llprefix [] = {0xfe, 0x80} |
| static const uint8_t | ttl_values [] = {0, 1, 64, 255} |
IPHC related functions | |
|
static struct sicslowpan_addr_context * | addr_context_lookup_by_prefix (uip_ipaddr_t *ipaddr) |
| find the context corresponding to prefix ipaddr | |
|
static struct sicslowpan_addr_context * | addr_context_lookup_by_number (uint8_t number) |
| find the context with the given number | |
| static uint8_t | compress_addr_64 (uint8_t bitpos, uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr) |
| static void | uncompress_addr (uip_ipaddr_t *ipaddr, uint8_t const prefix[], uint8_t pref_post_count, uip_lladdr_t *lladdr) |
| static void | compress_hdr_iphc (linkaddr_t *link_destaddr) |
| Compress IP/UDP header. More... | |
| static void | uncompress_hdr_iphc (uint8_t *buf, uint16_t ip_len) |
| Uncompress IPHC (i.e., IPHC and LOWPAN_UDP) headers and put them in sicslowpan_buf. More... | |
IPv6 dispatch "compression" function | |
| static void | compress_hdr_ipv6 (linkaddr_t *link_destaddr) |
Input/output functions common to all compression schemes | |
| static void | packet_sent (void *ptr, int status, int transmissions) |
| Callback function for the MAC packet sent callback. | |
| static void | send_packet (linkaddr_t *dest) |
| This function is called by the 6lowpan code to send out a packet. More... | |
| static uint8_t | output (const uip_lladdr_t *localdest) |
| Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan. More... | |
| static void | input (void) |
| Process a received 6lowpan packet. More... | |
6lowpan compressions | |
| #define | SICSLOWPAN_COMPRESSION_IPV6 0 |
| #define | SICSLOWPAN_COMPRESSION_HC1 1 |
| #define | SICSLOWPAN_COMPRESSION_HC06 2 |
HC1 encoding | |
| #define | SICSLOWPAN_HC1_NH_UDP 0x02 |
| #define | SICSLOWPAN_HC1_NH_TCP 0x06 |
| #define | SICSLOWPAN_HC1_NH_ICMP6 0x04 |
HC_UDP encoding (works together with HC1) | |
| #define | SICSLOWPAN_HC_UDP_ALL_C 0xE0 |
Address compressibility test functions | |
| #define | sicslowpan_is_iid_16_bit_compressable(a) |
| check whether we can compress the IID in address 'a' to 16 bits. More... | |
| #define | sicslowpan_is_mcast_addr_decompressable(a) |
| check whether the 9-bit group-id of the compressed multicast address is known. More... | |
| #define | sicslowpan_is_mcast_addr_compressable(a) |
| check whether the 112-bit group-id of the multicast address is mappable to a 9-bit group-id It is true if the group is the all nodes or all routers group. | |
| #define | sicslowpan_is_mcast_addr_compressable48(a) |
| #define | sicslowpan_is_mcast_addr_compressable32(a) |
| #define | sicslowpan_is_mcast_addr_compressable8(a) |
6lowpan is a Working Group in IETF which defines the use of IPv6 on IEEE 802.15.4 links.
Our implementation is based on RFC4944 Transmission of IPv6 Packets over IEEE 802.15.4 Networks, draft-hui-6lowpan-interop-00 Interoperability Test for 6LoWPAN, and draft-hui-6lowpan-hc-01 Compression format for IPv6 datagrams in 6lowpan Networks.
RFC4944 defines address configuration mechanisms based on 802.15.4 16-bit and 64-bit addresses, fragmentation of IPv6 packets below IP layer, IPv6 and UDP header compression, a mesh header to enable link-layer forwarding in a mesh under topology, and a broadcast header to enable broadcast in a mesh under topology.
We implement addressing, fragmentation, and header compression. We support the header compression scenarios defined in draft-hui-6lowpan-interop-00. This draft defines an interoperability scenario which was used between ArchRock and Sensinode implementations.
We do not implement mesh under related features, as we target route over techniques.
RFC6282 defines a stateful header compression mechanism which deprecate the stateless header compression mechanism defined in RFC4944. It is much more powerfull and flexible, in particular it allows compression of some multicast addresses and of all global unicast addresses.
6lowpan does not run as a separate process. It is called by the MAC process when a 6lowpan packet is received, and by the tcpip process when an IPv6 packet needs to be sent.
It is initialized from the MAC process, which calls sicslowpan_init (giving as argument a pointer to the mac_driver structure).
The main 6lowpan functions are implemented in the sicslowpan.h and sicslowpan.c files. They are used to format packets between the 802.15.4 and the IPv6 layers.
6lowpan also creates a few IPv6 and link-layer dependencies which are detailed in the next section.
Link-layer addresses
The format of a 802.15.4 address is defined in uip.h.
Neighbor Discovery Link Layer Address options
The format of ND link-layer address options depends on the length of the link-layer addresses. 802.15.4 specificities regarding link-layer address options are implemented in uip-nd6.h.
Address Autoconfiguration
The address autoconfiguration mechanism also depends on the format of the link-layer address. The dependency is reflected in the uip_ds6_set_addr_iid function in uip-ds6.c.
At initialization, the input function in sicslowpan.c is set as the function to be called by the MAC upon packet reception. The output function is set as the tcpip_output function.
At packet reception, the link-layer copies the 802.15.4 payload in the rime buffer, and sets its length. It also stores the source and destination link-layer addresses as two rime addresses.
It then calls the sicslowpan input function. Similarly, when the IPv6 layer has a packet to send over the radio, it puts the packet in uip_buf, sets uip_len and calls the sicslowpan output function.
Compression schemes
The SICSLOWPAN_CONF_COMPRESSION compilation option defines the compression scheme supported. We support IPHC, and IPv6 compression. IPv6 compression are defined in RFC4944, IPHC in RFC6282. What we call IPv6 compression means sending packets with no compression, and adding the IPv6 dispatch before the IPv6 header.
If at compile time IPv6 "compression" is chosen, packets sent will never be compressed, and compressed packets will not be processed at reception.
If at compile time IPHC is chosen, we will try to compress all fields at sending, and will accept packets compressed with the chosen scheme, as well as uncompressed packets.
.
Compression related functions
When a packet is received, the input function is called. Fragmentation issues are handled, then we check the dispatch byte: if it is IPv6, we treat the packet inline. If it is IPHC, the decompression function (uncompress_hdr_iphc) is called.
When a packet needs to be sent, we try to compress it. If only the IPv6 compression support is enabled, we just add the IPv6 dispatch before the 802.15.4 payload. If IPHC support is enabled, we call the corresponding compression function (compress_hdr_iphc) to compress the packet as much as possible.
IPHC comments
IPHC uses address contexts to enable compression of global unicast addresses. All nodes must share context (namely the global prefixes in use) to compress and uncompress such addresses successfully. The context number is defined by 4 bits. Context 00 is reserved for the link local context. Other contexts have to be distributed within the LoWPAN dynamically, by means of ND extensions yet to be implemented.
Until then, if you want to test global address compression, you need to configure the global contexts manually.
| #define COMPRESSION_THRESHOLD 0 |
Some MAC layers need a minimum payload, which is configurable through the SICSLOWPAN_CONF_COMPRESSION_THRESHOLD option.
Definition at line 164 of file sicslowpan.c.
Referenced by output().
| #define DEBUG DEBUG_NONE |
FOR HC-06 COMPLIANCE TODO: -Add compression options to UDP, currently only supports both ports compressed or both ports elided.
-Verify TC/FL compression works
-Add stateless multicast option
Definition at line 75 of file sicslowpan.c.
| #define MAC_MAX_PAYLOAD (127 - 2) |
Maximum available size for frame headers, link layer security-related overhead, as well as 6LoWPAN payload.
Definition at line 155 of file sicslowpan.c.
Referenced by output().
| #define SICSLOWPAN_FIXED_HDRLEN 21 |
Fixed size of a frame header.
This value is used in case framer returns an error or if SICSLOWPAN_USE_FIXED_HDRLEN is defined.
Definition at line 172 of file sicslowpan.c.
Referenced by output().
| #define sicslowpan_is_iid_16_bit_compressable | ( | a | ) |
check whether we can compress the IID in address 'a' to 16 bits.
This is used for unicast addresses only, and is true if the address is on the format <PREFIX>::0000:00ff:fe00:XXXX NOTE: we currently assume 64-bits prefixes
Definition at line 240 of file sicslowpan.h.
| #define sicslowpan_is_mcast_addr_decompressable | ( | a | ) |
check whether the 9-bit group-id of the compressed multicast address is known.
It is true if the 9-bit group is the all nodes or all routers group.
| a | is typed uint8_t * |
Definition at line 254 of file sicslowpan.h.
|
static |
Compress IP/UDP header.
This function is called by the 6lowpan code to create a compressed 6lowpan packet in the packetbuf buffer from a full IPv6 packet in the uip_buf buffer.
IPHC (RFC 6282)
http://tools.ietf.org/html/
For LOWPAN_UDP compression, we either compress both ports or none. General format with LOWPAN_UDP compression is
* 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |0|1|1|TF |N|HLI|C|S|SAM|M|D|DAM| SCI | DCI | comp. IPv6 hdr| * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | compressed IPv6 fields ..... | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | LOWPAN_UDP | non compressed UDP fields ... | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | L4 data ... | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ *
| link_destaddr | L2 destination address, needed to compress IP dest |
Definition at line 669 of file sicslowpan.c.
References addr_context_lookup_by_prefix(), NULL, packetbuf_hdr_len, packetbuf_ptr, UIP_HTONS, UIP_IP_BUF, uip_is_addr_linklocal, uip_is_addr_mcast, uip_is_addr_unspecified, uip_lladdr, and uncomp_hdr_len.
Referenced by output().
|
static |
Process a received 6lowpan packet.
The 6lowpan packet is put in packetbuf by the MAC. If its a frag1 or a non-fragmented packet we first uncompress the IP header. The 6lowpan payload and possibly the uncompressed IP header are then copied in siclowpan_buf. If the IP packet is complete it is copied to uip_buf and the IP layer is called.
Definition at line 1503 of file sicslowpan.c.
References NULL, packetbuf_datalen(), packetbuf_dataptr(), packetbuf_hdr_len, packetbuf_payload_len, packetbuf_ptr, tcpip_input(), uip_buf, UIP_IP_BUF, uip_len, UIP_LLH_LEN, uncomp_hdr_len, and uncompress_hdr_iphc().
Referenced by cc26xx_uart_set_input(), uart0_set_input(), uart_set_input(), and usb_serial_set_input().
|
static |
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
| localdest | The MAC address of the destination |
The IP packet is initially in uip_buf. Its header is compressed and if necessary it is fragmented. The resulting packet/fragments are put in packetbuf and delivered to the 802.15.4 MAC.
Definition at line 1275 of file sicslowpan.c.
References compress_hdr_iphc(), COMPRESSION_THRESHOLD, last_tx_status, linkaddr_copy(), linkaddr_null, MAC_MAX_PAYLOAD, MAC_TX_COLLISION, MAC_TX_ERR, MAC_TX_OK, NULL, packetbuf_clear(), packetbuf_dataptr(), packetbuf_hdr_len, packetbuf_payload_len, packetbuf_ptr, packetbuf_set_datalen(), send_packet(), SICSLOWPAN_FIXED_HDRLEN, UIP_IP_BUF, uip_len, and uncomp_hdr_len.
|
static |
This function is called by the 6lowpan code to send out a packet.
| dest | the link layer destination address of the packet |
Definition at line 1243 of file sicslowpan.c.
References NULL, packet_sent(), uip_lladdr, and watchdog_periodic().
Referenced by output().
|
static |
Uncompress IPHC (i.e., IPHC and LOWPAN_UDP) headers and put them in sicslowpan_buf.
This function is called by the input function when the dispatch is IPHC. We process the packet in the packetbuf buffer, uncompress the header fields, and copy the result in the sicslowpan buffer. At the end of the decompression, packetbuf_hdr_len and uncompressed_hdr_len are set to the appropriate values
| buf | Pointer to the buffer to uncompress the packet into. |
| ip_len | Equal to 0 if the packet is not a fragment (IP length is then inferred from the L2 length), non 0 if the packet is a 1st fragment. |
Definition at line 956 of file sicslowpan.c.
References addr_context_lookup_by_number(), hc06_ptr, NULL, packetbuf_datalen(), packetbuf_hdr_len, packetbuf_ptr, UIP_HTONS, and uncomp_hdr_len.
Referenced by input().
|
static |
Addresses contexts for IPHC.
pointer to an address context.
Definition at line 501 of file sicslowpan.c.
Referenced by PROCESS_THREAD().
|
static |
pointer to the byte where to write next inline field.
Definition at line 504 of file sicslowpan.c.
Referenced by uncompress_hdr_iphc().
|
static |
The length of the payload in the Packetbuf buffer.
The payload is what comes after the compressed or uncompressed headers (can be the IP payload if the IP header only is compressed or the UDP payload if the UDP header is also compressed)
Definition at line 199 of file sicslowpan.c.
|
static |
A pointer to the packetbuf buffer.
We initialize it to the beginning of the packetbuf buffer, then access different fields by updating the offset packetbuf_hdr_len.
Definition at line 184 of file sicslowpan.c.
Referenced by compress_hdr_iphc(), input(), output(), and uncompress_hdr_iphc().
1.8.6