Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 1 | |
| 2 | Linux IEEE 802.15.4 implementation |
| 3 | |
| 4 | |
| 5 | Introduction |
| 6 | ============ |
Masanari Iida | c17cb8b | 2013-10-30 16:46:15 +0900 | [diff] [blame] | 7 | The IEEE 802.15.4 working group focuses on standardization of bottom |
Stefan Huber | 3d9738a | 2013-06-05 12:24:34 +0200 | [diff] [blame] | 8 | two layers: Medium Access Control (MAC) and Physical (PHY). And there |
alex.bluesman.smirnov@gmail.com | dd456d4 | 2012-05-15 20:50:31 +0000 | [diff] [blame] | 9 | are mainly two options available for upper layers: |
Stefan Schmidt | 29cd5dd | 2015-09-03 16:31:34 +0200 | [diff] [blame] | 10 | - ZigBee - proprietary protocol from the ZigBee Alliance |
| 11 | - 6LoWPAN - IPv6 networking over low rate personal area networks |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 12 | |
Stefan Schmidt | 29cd5dd | 2015-09-03 16:31:34 +0200 | [diff] [blame] | 13 | The linux-wpan project goal is to provide a complete implementation |
| 14 | of the IEEE 802.15.4 and 6LoWPAN protocols. IEEE 802.15.4 is a stack |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 15 | of protocols for organizing Low-Rate Wireless Personal Area Networks. |
| 16 | |
alex.bluesman.smirnov@gmail.com | dd456d4 | 2012-05-15 20:50:31 +0000 | [diff] [blame] | 17 | The stack is composed of three main parts: |
| 18 | - IEEE 802.15.4 layer; We have chosen to use plain Berkeley socket API, |
| 19 | the generic Linux networking stack to transfer IEEE 802.15.4 messages |
| 20 | and a special protocol over genetlink for configuration/management |
| 21 | - MAC - provides access to shared channel and reliable data delivery |
| 22 | - PHY - represents device drivers |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 23 | |
| 24 | |
| 25 | Socket API |
| 26 | ========== |
| 27 | |
| 28 | int sd = socket(PF_IEEE802154, SOCK_DGRAM, 0); |
| 29 | ..... |
| 30 | |
| 31 | The address family, socket addresses etc. are defined in the |
Dmitry Baryshkov | 48a2f11 | 2009-08-07 02:58:39 +0000 | [diff] [blame] | 32 | include/net/af_ieee802154.h header or in the special header |
Lennert Buytenhek | b251d4d | 2015-05-25 15:38:29 +0300 | [diff] [blame] | 33 | in the userspace package (see either http://wpan.cakelab.org/ or the |
| 34 | git tree at https://github.com/linux-wpan/wpan-tools). |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 35 | |
| 36 | One can use SOCK_RAW for passing raw data towards device xmit function. YMMV. |
| 37 | |
| 38 | |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 39 | Kernel side |
| 40 | ============= |
| 41 | |
| 42 | Like with WiFi, there are several types of devices implementing IEEE 802.15.4. |
| 43 | 1) 'HardMAC'. The MAC layer is implemented in the device itself, the device |
| 44 | exports MLME and data API. |
| 45 | 2) 'SoftMAC' or just radio. These types of devices are just radio transceivers |
| 46 | possibly with some kinds of acceleration like automatic CRC computation and |
| 47 | comparation, automagic ACK handling, address matching, etc. |
| 48 | |
| 49 | Those types of devices require different approach to be hooked into Linux kernel. |
| 50 | |
| 51 | |
| 52 | HardMAC |
| 53 | ======= |
| 54 | |
Dmitry Baryshkov | 48a2f11 | 2009-08-07 02:58:39 +0000 | [diff] [blame] | 55 | See the header include/net/ieee802154_netdev.h. You have to implement Linux |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 56 | net_device, with .type = ARPHRD_IEEE802154. Data is exchanged with socket family |
Dmitry Eremin-Solenikov | a0aea57 | 2009-08-19 18:53:39 +0400 | [diff] [blame] | 57 | code via plain sk_buffs. On skb reception skb->cb must contain additional |
| 58 | info as described in the struct ieee802154_mac_cb. During packet transmission |
| 59 | the skb->cb is used to provide additional data to device's header_ops->create |
Masanari Iida | c17cb8b | 2013-10-30 16:46:15 +0900 | [diff] [blame] | 60 | function. Be aware that this data can be overridden later (when socket code |
Dmitry Eremin-Solenikov | a0aea57 | 2009-08-19 18:53:39 +0400 | [diff] [blame] | 61 | submits skb to qdisc), so if you need something from that cb later, you should |
| 62 | store info in the skb->data on your own. |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 63 | |
| 64 | To hook the MLME interface you have to populate the ml_priv field of your |
Werner Almesberger | 56aa091 | 2013-04-04 06:32:35 +0000 | [diff] [blame] | 65 | net_device with a pointer to struct ieee802154_mlme_ops instance. The fields |
| 66 | assoc_req, assoc_resp, disassoc_req, start_req, and scan_req are optional. |
| 67 | All other fields are required. |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 68 | |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 69 | |
| 70 | SoftMAC |
| 71 | ======= |
| 72 | |
alex.bluesman.smirnov@gmail.com | dd456d4 | 2012-05-15 20:50:31 +0000 | [diff] [blame] | 73 | The MAC is the middle layer in the IEEE 802.15.4 Linux stack. This moment it |
| 74 | provides interface for drivers registration and management of slave interfaces. |
| 75 | |
| 76 | NOTE: Currently the only monitor device type is supported - it's IEEE 802.15.4 |
| 77 | stack interface for network sniffers (e.g. WireShark). |
| 78 | |
| 79 | This layer is going to be extended soon. |
Sergey Lapin | 02cf228 | 2009-06-08 12:18:50 +0000 | [diff] [blame] | 80 | |
Lennert Buytenhek | b251d4d | 2015-05-25 15:38:29 +0300 | [diff] [blame] | 81 | See header include/net/mac802154.h and several drivers in |
| 82 | drivers/net/ieee802154/. |
Dmitry Eremin-Solenikov | a0aea57 | 2009-08-19 18:53:39 +0400 | [diff] [blame] | 83 | |
alex.bluesman.smirnov@gmail.com | dd456d4 | 2012-05-15 20:50:31 +0000 | [diff] [blame] | 84 | |
| 85 | Device drivers API |
| 86 | ================== |
| 87 | |
| 88 | The include/net/mac802154.h defines following functions: |
| 89 | - struct ieee802154_dev *ieee802154_alloc_device |
| 90 | (size_t priv_size, struct ieee802154_ops *ops): |
| 91 | allocation of IEEE 802.15.4 compatible device |
| 92 | |
| 93 | - void ieee802154_free_device(struct ieee802154_dev *dev): |
| 94 | freeing allocated device |
| 95 | |
| 96 | - int ieee802154_register_device(struct ieee802154_dev *dev): |
| 97 | register PHY in the system |
| 98 | |
| 99 | - void ieee802154_unregister_device(struct ieee802154_dev *dev): |
| 100 | freeing registered PHY |
| 101 | |
| 102 | Moreover IEEE 802.15.4 device operations structure should be filled. |
| 103 | |
| 104 | Fake drivers |
| 105 | ============ |
| 106 | |
Lennert Buytenhek | b251d4d | 2015-05-25 15:38:29 +0300 | [diff] [blame] | 107 | In addition there is a driver available which simulates a real device with |
| 108 | SoftMAC (fakelb - IEEE 802.15.4 loopback driver) interface. This option |
| 109 | provides possibility to test and debug stack without usage of real hardware. |
alex.bluesman.smirnov@gmail.com | dd456d4 | 2012-05-15 20:50:31 +0000 | [diff] [blame] | 110 | |
Lennert Buytenhek | b251d4d | 2015-05-25 15:38:29 +0300 | [diff] [blame] | 111 | See sources in drivers/net/ieee802154 folder for more details. |
alex.bluesman.smirnov@gmail.com | dd456d4 | 2012-05-15 20:50:31 +0000 | [diff] [blame] | 112 | |
| 113 | |
alex.bluesman.smirnov@gmail.com | 63ce40e | 2011-11-10 07:41:11 +0000 | [diff] [blame] | 114 | 6LoWPAN Linux implementation |
| 115 | ============================ |
| 116 | |
Lennert Buytenhek | b251d4d | 2015-05-25 15:38:29 +0300 | [diff] [blame] | 117 | The IEEE 802.15.4 standard specifies an MTU of 127 bytes, yielding about 80 |
alex.bluesman.smirnov@gmail.com | 63ce40e | 2011-11-10 07:41:11 +0000 | [diff] [blame] | 118 | octets of actual MAC payload once security is turned on, on a wireless link |
| 119 | with a link throughput of 250 kbps or less. The 6LoWPAN adaptation format |
| 120 | [RFC4944] was specified to carry IPv6 datagrams over such constrained links, |
| 121 | taking into account limited bandwidth, memory, or energy resources that are |
| 122 | expected in applications such as wireless Sensor Networks. [RFC4944] defines |
| 123 | a Mesh Addressing header to support sub-IP forwarding, a Fragmentation header |
| 124 | to support the IPv6 minimum MTU requirement [RFC2460], and stateless header |
| 125 | compression for IPv6 datagrams (LOWPAN_HC1 and LOWPAN_HC2) to reduce the |
| 126 | relatively large IPv6 and UDP headers down to (in the best case) several bytes. |
| 127 | |
| 128 | In Semptember 2011 the standard update was published - [RFC6282]. |
| 129 | It deprecates HC1 and HC2 compression and defines IPHC encoding format which is |
| 130 | used in this Linux implementation. |
| 131 | |
Lennert Buytenhek | b251d4d | 2015-05-25 15:38:29 +0300 | [diff] [blame] | 132 | All the code related to 6lowpan you may find in files: net/6lowpan/* |
| 133 | and net/ieee802154/6lowpan/* |
alex.bluesman.smirnov@gmail.com | 63ce40e | 2011-11-10 07:41:11 +0000 | [diff] [blame] | 134 | |
| 135 | To setup 6lowpan interface you need (busybox release > 1.17.0): |
| 136 | 1. Add IEEE802.15.4 interface and initialize PANid; |
| 137 | 2. Add 6lowpan interface by command like: |
| 138 | # ip link add link wpan0 name lowpan0 type lowpan |
| 139 | 3. Set MAC (if needs): |
| 140 | # ip link set lowpan0 address de:ad:be:ef:ca:fe:ba:be |
| 141 | 4. Bring up 'lowpan0' interface |