Commit | Line | Data |
---|---|---|
02cf2286 SL |
1 | |
2 | Linux IEEE 802.15.4 implementation | |
3 | ||
4 | ||
5 | Introduction | |
6 | ============ | |
6bf0d84d SS |
7 | The IEEE 802.15.4 working group focuses on standardization of the bottom |
8 | two layers: Medium Access Control (MAC) and Physical access (PHY). And there | |
dd456d45 | 9 | are mainly two options available for upper layers: |
29cd5ddc SS |
10 | - ZigBee - proprietary protocol from the ZigBee Alliance |
11 | - 6LoWPAN - IPv6 networking over low rate personal area networks | |
02cf2286 | 12 | |
6bf0d84d | 13 | The goal of the Linux-wpan is to provide a complete implementation |
29cd5ddc | 14 | of the IEEE 802.15.4 and 6LoWPAN protocols. IEEE 802.15.4 is a stack |
02cf2286 SL |
15 | of protocols for organizing Low-Rate Wireless Personal Area Networks. |
16 | ||
dd456d45 | 17 | The stack is composed of three main parts: |
18 | - IEEE 802.15.4 layer; We have chosen to use plain Berkeley socket API, | |
6bf0d84d SS |
19 | the generic Linux networking stack to transfer IEEE 802.15.4 data |
20 | messages and a special protocol over netlink for configuration/management | |
dd456d45 | 21 | - MAC - provides access to shared channel and reliable data delivery |
22 | - PHY - represents device drivers | |
02cf2286 SL |
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 | |
48a2f112 | 32 | include/net/af_ieee802154.h header or in the special header |
b251d4de LB |
33 | in the userspace package (see either http://wpan.cakelab.org/ or the |
34 | git tree at https://github.com/linux-wpan/wpan-tools). | |
02cf2286 | 35 | |
02cf2286 | 36 | |
02cf2286 SL |
37 | Kernel side |
38 | ============= | |
39 | ||
40 | Like with WiFi, there are several types of devices implementing IEEE 802.15.4. | |
41 | 1) 'HardMAC'. The MAC layer is implemented in the device itself, the device | |
6bf0d84d | 42 | exports a management (e.g. MLME) and data API. |
02cf2286 SL |
43 | 2) '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 | ||
47 | Those types of devices require different approach to be hooked into Linux kernel. | |
48 | ||
49 | ||
50 | HardMAC | |
51 | ======= | |
52 | ||
48a2f112 | 53 | See the header include/net/ieee802154_netdev.h. You have to implement Linux |
02cf2286 | 54 | net_device, with .type = ARPHRD_IEEE802154. Data is exchanged with socket family |
a0aea577 DES |
55 | code via plain sk_buffs. On skb reception skb->cb must contain additional |
56 | info as described in the struct ieee802154_mac_cb. During packet transmission | |
57 | the skb->cb is used to provide additional data to device's header_ops->create | |
c17cb8b5 | 58 | function. Be aware that this data can be overridden later (when socket code |
a0aea577 DES |
59 | submits skb to qdisc), so if you need something from that cb later, you should |
60 | store info in the skb->data on your own. | |
02cf2286 SL |
61 | |
62 | To hook the MLME interface you have to populate the ml_priv field of your | |
56aa091d WA |
63 | net_device with a pointer to struct ieee802154_mlme_ops instance. The fields |
64 | assoc_req, assoc_resp, disassoc_req, start_req, and scan_req are optional. | |
65 | All other fields are required. | |
02cf2286 | 66 | |
02cf2286 SL |
67 | |
68 | SoftMAC | |
69 | ======= | |
70 | ||
dd456d45 | 71 | The MAC is the middle layer in the IEEE 802.15.4 Linux stack. This moment it |
72 | provides interface for drivers registration and management of slave interfaces. | |
73 | ||
74 | NOTE: Currently the only monitor device type is supported - it's IEEE 802.15.4 | |
75 | stack interface for network sniffers (e.g. WireShark). | |
76 | ||
77 | This layer is going to be extended soon. | |
02cf2286 | 78 | |
b251d4de LB |
79 | See header include/net/mac802154.h and several drivers in |
80 | drivers/net/ieee802154/. | |
a0aea577 | 81 | |
dd456d45 | 82 | |
83 | Device drivers API | |
84 | ================== | |
85 | ||
86 | The include/net/mac802154.h defines following functions: | |
8ac5ac1b JHP |
87 | - 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 | |
dd456d45 | 90 | |
8ac5ac1b JHP |
91 | - void ieee802154_free_hw(struct ieee802154_hw *hw): |
92 | freeing allocated hardware device | |
dd456d45 | 93 | |
8ac5ac1b JHP |
94 | - int ieee802154_register_hw(struct ieee802154_hw *hw): |
95 | register PHY which is the allocated hardware device, in the system | |
dd456d45 | 96 | |
8ac5ac1b | 97 | - void ieee802154_unregister_hw(struct ieee802154_hw *hw): |
dd456d45 | 98 | freeing registered PHY |
99 | ||
5c7f2acc JHP |
100 | - void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, |
101 | u8 lqi): | |
102 | telling 802.15.4 module there is a new received frame in the skb with | |
103 | the RF Link Quality Indicator (LQI) from the hardware device | |
104 | ||
105 | - void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb, | |
106 | bool ifs_handling): | |
107 | telling 802.15.4 module the frame in the skb is or going to be | |
108 | transmitted through the hardware device | |
109 | ||
110 | The device driver must implement the following callbacks in the IEEE 802.15.4 | |
111 | operations structure at least: | |
112 | struct ieee802154_ops { | |
113 | ... | |
114 | int (*start)(struct ieee802154_hw *hw); | |
115 | void (*stop)(struct ieee802154_hw *hw); | |
116 | ... | |
117 | int (*xmit_async)(struct ieee802154_hw *hw, struct sk_buff *skb); | |
118 | int (*ed)(struct ieee802154_hw *hw, u8 *level); | |
119 | int (*set_channel)(struct ieee802154_hw *hw, u8 page, u8 channel); | |
120 | ... | |
121 | }; | |
122 | ||
123 | - int start(struct ieee802154_hw *hw): | |
124 | handler that 802.15.4 module calls for the hardware device initialization. | |
125 | ||
126 | - void stop(struct ieee802154_hw *hw): | |
127 | handler that 802.15.4 module calls for the hardware device cleanup. | |
128 | ||
129 | - int xmit_async(struct ieee802154_hw *hw, struct sk_buff *skb): | |
130 | handler that 802.15.4 module calls for each frame in the skb going to be | |
131 | transmitted through the hardware device. | |
132 | ||
133 | - int ed(struct ieee802154_hw *hw, u8 *level): | |
134 | handler that 802.15.4 module calls for Energy Detection from the hardware | |
135 | device. | |
136 | ||
137 | - int set_channel(struct ieee802154_hw *hw, u8 page, u8 channel): | |
138 | set radio for listening on specific channel of the hardware device. | |
139 | ||
dd456d45 | 140 | Moreover IEEE 802.15.4 device operations structure should be filled. |
141 | ||
142 | Fake drivers | |
143 | ============ | |
144 | ||
b251d4de LB |
145 | In addition there is a driver available which simulates a real device with |
146 | SoftMAC (fakelb - IEEE 802.15.4 loopback driver) interface. This option | |
6bf0d84d | 147 | provides a possibility to test and debug the stack without usage of real hardware. |
dd456d45 | 148 | |
b251d4de | 149 | See sources in drivers/net/ieee802154 folder for more details. |
dd456d45 | 150 | |
151 | ||
63ce40e4 | 152 | 6LoWPAN Linux implementation |
153 | ============================ | |
154 | ||
b251d4de | 155 | The IEEE 802.15.4 standard specifies an MTU of 127 bytes, yielding about 80 |
63ce40e4 | 156 | octets of actual MAC payload once security is turned on, on a wireless link |
157 | with a link throughput of 250 kbps or less. The 6LoWPAN adaptation format | |
158 | [RFC4944] was specified to carry IPv6 datagrams over such constrained links, | |
159 | taking into account limited bandwidth, memory, or energy resources that are | |
160 | expected in applications such as wireless Sensor Networks. [RFC4944] defines | |
161 | a Mesh Addressing header to support sub-IP forwarding, a Fragmentation header | |
162 | to support the IPv6 minimum MTU requirement [RFC2460], and stateless header | |
163 | compression for IPv6 datagrams (LOWPAN_HC1 and LOWPAN_HC2) to reduce the | |
164 | relatively large IPv6 and UDP headers down to (in the best case) several bytes. | |
165 | ||
6bf0d84d | 166 | In September 2011 the standard update was published - [RFC6282]. |
63ce40e4 | 167 | It deprecates HC1 and HC2 compression and defines IPHC encoding format which is |
168 | used in this Linux implementation. | |
169 | ||
b251d4de LB |
170 | All the code related to 6lowpan you may find in files: net/6lowpan/* |
171 | and net/ieee802154/6lowpan/* | |
63ce40e4 | 172 | |
6bf0d84d SS |
173 | To setup a 6LoWPAN interface you need: |
174 | 1. Add IEEE802.15.4 interface and set channel and PAN ID; | |
63ce40e4 | 175 | 2. Add 6lowpan interface by command like: |
176 | # ip link add link wpan0 name lowpan0 type lowpan | |
6bf0d84d | 177 | 3. Bring up 'lowpan0' interface |