blob: 057e9fdbfac9d93f48b85159e3a5e7954b0a781a [file] [log] [blame]
Sergey Lapin02cf2282009-06-08 12:18:50 +00001
2 Linux IEEE 802.15.4 implementation
3
4
5Introduction
6============
Stefan Schmidt6bf0d842016-11-28 18:22:33 +01007The IEEE 802.15.4 working group focuses on standardization of the bottom
8two layers: Medium Access Control (MAC) and Physical access (PHY). And there
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +00009are mainly two options available for upper layers:
Stefan Schmidt29cd5dd2015-09-03 16:31:34 +020010 - ZigBee - proprietary protocol from the ZigBee Alliance
11 - 6LoWPAN - IPv6 networking over low rate personal area networks
Sergey Lapin02cf2282009-06-08 12:18:50 +000012
Stefan Schmidt6bf0d842016-11-28 18:22:33 +010013The goal of the Linux-wpan is to provide a complete implementation
Stefan Schmidt29cd5dd2015-09-03 16:31:34 +020014of the IEEE 802.15.4 and 6LoWPAN protocols. IEEE 802.15.4 is a stack
Sergey Lapin02cf2282009-06-08 12:18:50 +000015of protocols for organizing Low-Rate Wireless Personal Area Networks.
16
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +000017The stack is composed of three main parts:
18 - IEEE 802.15.4 layer; We have chosen to use plain Berkeley socket API,
Stefan Schmidt6bf0d842016-11-28 18:22:33 +010019 the generic Linux networking stack to transfer IEEE 802.15.4 data
20 messages and a special protocol over netlink for configuration/management
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +000021 - MAC - provides access to shared channel and reliable data delivery
22 - PHY - represents device drivers
Sergey Lapin02cf2282009-06-08 12:18:50 +000023
24
25Socket API
26==========
27
28int sd = socket(PF_IEEE802154, SOCK_DGRAM, 0);
29.....
30
31The address family, socket addresses etc. are defined in the
Dmitry Baryshkov48a2f112009-08-07 02:58:39 +000032include/net/af_ieee802154.h header or in the special header
Lennert Buytenhekb251d4d2015-05-25 15:38:29 +030033in the userspace package (see either http://wpan.cakelab.org/ or the
34git tree at https://github.com/linux-wpan/wpan-tools).
Sergey Lapin02cf2282009-06-08 12:18:50 +000035
Sergey Lapin02cf2282009-06-08 12:18:50 +000036
Sergey Lapin02cf2282009-06-08 12:18:50 +000037Kernel side
38=============
39
40Like with WiFi, there are several types of devices implementing IEEE 802.15.4.
411) 'HardMAC'. The MAC layer is implemented in the device itself, the device
Stefan Schmidt6bf0d842016-11-28 18:22:33 +010042 exports a management (e.g. MLME) and data API.
Sergey Lapin02cf2282009-06-08 12:18:50 +0000432) 'SoftMAC' or just radio. These types of devices are just radio transceivers
44 possibly with some kinds of acceleration like automatic CRC computation and
45 comparation, automagic ACK handling, address matching, etc.
46
47Those types of devices require different approach to be hooked into Linux kernel.
48
49
50HardMAC
51=======
52
Dmitry Baryshkov48a2f112009-08-07 02:58:39 +000053See the header include/net/ieee802154_netdev.h. You have to implement Linux
Sergey Lapin02cf2282009-06-08 12:18:50 +000054net_device, with .type = ARPHRD_IEEE802154. Data is exchanged with socket family
Dmitry Eremin-Solenikova0aea572009-08-19 18:53:39 +040055code via plain sk_buffs. On skb reception skb->cb must contain additional
56info as described in the struct ieee802154_mac_cb. During packet transmission
57the skb->cb is used to provide additional data to device's header_ops->create
Masanari Iidac17cb8b2013-10-30 16:46:15 +090058function. Be aware that this data can be overridden later (when socket code
Dmitry Eremin-Solenikova0aea572009-08-19 18:53:39 +040059submits skb to qdisc), so if you need something from that cb later, you should
60store info in the skb->data on your own.
Sergey Lapin02cf2282009-06-08 12:18:50 +000061
62To hook the MLME interface you have to populate the ml_priv field of your
Werner Almesberger56aa0912013-04-04 06:32:35 +000063net_device with a pointer to struct ieee802154_mlme_ops instance. The fields
64assoc_req, assoc_resp, disassoc_req, start_req, and scan_req are optional.
65All other fields are required.
Sergey Lapin02cf2282009-06-08 12:18:50 +000066
Sergey Lapin02cf2282009-06-08 12:18:50 +000067
68SoftMAC
69=======
70
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +000071The MAC is the middle layer in the IEEE 802.15.4 Linux stack. This moment it
72provides interface for drivers registration and management of slave interfaces.
73
74NOTE: Currently the only monitor device type is supported - it's IEEE 802.15.4
75stack interface for network sniffers (e.g. WireShark).
76
77This layer is going to be extended soon.
Sergey Lapin02cf2282009-06-08 12:18:50 +000078
Lennert Buytenhekb251d4d2015-05-25 15:38:29 +030079See header include/net/mac802154.h and several drivers in
80drivers/net/ieee802154/.
Dmitry Eremin-Solenikova0aea572009-08-19 18:53:39 +040081
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +000082
83Device drivers API
84==================
85
86The include/net/mac802154.h defines following functions:
Jian-Hong Pan8ac5ac12017-08-07 00:28:29 +080087 - struct ieee802154_hw *
88 ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops):
89 allocation of IEEE 802.15.4 compatible hardware device
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +000090
Jian-Hong Pan8ac5ac12017-08-07 00:28:29 +080091 - void ieee802154_free_hw(struct ieee802154_hw *hw):
92 freeing allocated hardware device
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +000093
Jian-Hong Pan8ac5ac12017-08-07 00:28:29 +080094 - int ieee802154_register_hw(struct ieee802154_hw *hw):
95 register PHY which is the allocated hardware device, in the system
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +000096
Jian-Hong Pan8ac5ac12017-08-07 00:28:29 +080097 - void ieee802154_unregister_hw(struct ieee802154_hw *hw):
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +000098 freeing registered PHY
99
100Moreover IEEE 802.15.4 device operations structure should be filled.
101
102Fake drivers
103============
104
Lennert Buytenhekb251d4d2015-05-25 15:38:29 +0300105In addition there is a driver available which simulates a real device with
106SoftMAC (fakelb - IEEE 802.15.4 loopback driver) interface. This option
Stefan Schmidt6bf0d842016-11-28 18:22:33 +0100107provides a possibility to test and debug the stack without usage of real hardware.
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +0000108
Lennert Buytenhekb251d4d2015-05-25 15:38:29 +0300109See sources in drivers/net/ieee802154 folder for more details.
alex.bluesman.smirnov@gmail.comdd456d42012-05-15 20:50:31 +0000110
111
alex.bluesman.smirnov@gmail.com63ce40e2011-11-10 07:41:11 +00001126LoWPAN Linux implementation
113============================
114
Lennert Buytenhekb251d4d2015-05-25 15:38:29 +0300115The IEEE 802.15.4 standard specifies an MTU of 127 bytes, yielding about 80
alex.bluesman.smirnov@gmail.com63ce40e2011-11-10 07:41:11 +0000116octets of actual MAC payload once security is turned on, on a wireless link
117with a link throughput of 250 kbps or less. The 6LoWPAN adaptation format
118[RFC4944] was specified to carry IPv6 datagrams over such constrained links,
119taking into account limited bandwidth, memory, or energy resources that are
120expected in applications such as wireless Sensor Networks. [RFC4944] defines
121a Mesh Addressing header to support sub-IP forwarding, a Fragmentation header
122to support the IPv6 minimum MTU requirement [RFC2460], and stateless header
123compression for IPv6 datagrams (LOWPAN_HC1 and LOWPAN_HC2) to reduce the
124relatively large IPv6 and UDP headers down to (in the best case) several bytes.
125
Stefan Schmidt6bf0d842016-11-28 18:22:33 +0100126In September 2011 the standard update was published - [RFC6282].
alex.bluesman.smirnov@gmail.com63ce40e2011-11-10 07:41:11 +0000127It deprecates HC1 and HC2 compression and defines IPHC encoding format which is
128used in this Linux implementation.
129
Lennert Buytenhekb251d4d2015-05-25 15:38:29 +0300130All the code related to 6lowpan you may find in files: net/6lowpan/*
131and net/ieee802154/6lowpan/*
alex.bluesman.smirnov@gmail.com63ce40e2011-11-10 07:41:11 +0000132
Stefan Schmidt6bf0d842016-11-28 18:22:33 +0100133To setup a 6LoWPAN interface you need:
1341. Add IEEE802.15.4 interface and set channel and PAN ID;
alex.bluesman.smirnov@gmail.com63ce40e2011-11-10 07:41:11 +00001352. Add 6lowpan interface by command like:
136 # ip link add link wpan0 name lowpan0 type lowpan
Stefan Schmidt6bf0d842016-11-28 18:22:33 +01001373. Bring up 'lowpan0' interface