← Documents Documentation/networking/ieee802154.rst GitHub 원문 ↗

Linux 6.18.37 · Networking

IEEE 802.15.4 Developer's Guide

Linux-wpan의 socket/6LoWPAN 계층과 HardMAC·SoftMAC 드라이버 연결 및 mac802154 장치 API를 설명합니다.

Source pathDocumentation/networking/ieee802154.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

ieee802154.rst:1-184

이 안내서는 저전력 무선 링크의 127바이트 MTU 위에서 6LoWPAN이 IPv6를 운반하는 방법과, MAC 구현 위치에 따라 HardMAC과 SoftMAC 드라이버가 커널에 연결되는 방식을 정리합니다.

802.15.4 데이터 경로
PF_IEEE802154 socket / lowpan0IEEE 802.15.4 계층MACPHY driverradio

사용자 API에서 radio까지의 계층입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

소개와 스택 구성

1-25

IEEE 802.15.4 작업 그룹은 하위 두 계층인 MAC과 PHY 표준화에 집중합니다. 상위 계층의 대표 선택지는 ZigBee Alliance의 독점 프로토콜 ZigBee와 저속 개인 영역망에서 IPv6를 제공하는 6LoWPAN입니다.

Linux-wpan의 목표는 저속 무선 개인 영역망을 구성하는 IEEE 802.15.4와 6LoWPAN 프로토콜을 완전히 구현하는 것입니다. 스택은 Berkeley socket API와 일반 Linux 네트워킹 스택으로 데이터를 전달하고 전용 netlink 프로토콜로 설정을 관리하는 IEEE 802.15.4 계층, 공유 채널 접근과 신뢰성 있는 전달을 맡는 MAC, 장치 드라이버를 나타내는 PHY로 구성됩니다.

Linux-wpan 계층
계층역할주요 인터페이스
IEEE 802.15.4데이터 전달과 설정Berkeley socket + netlink
MAC공유 채널 접근과 신뢰성HardMAC 또는 SoftMAC
PHY무선 하드웨어장치 드라이버

802.15.4 스택의 세 부분입니다.

===============================
IEEE 802.15.4 Developer's Guide
===============================

Introduction
============
The IEEE 802.15.4 working group focuses on standardization of the bottom
two layers: Medium Access Control (MAC) and Physical access (PHY). And there
are mainly two options available for upper layers:

- ZigBee - proprietary protocol from the ZigBee Alliance
- 6LoWPAN - IPv6 networking over low rate personal area networks

The goal of the Linux-wpan is to provide a complete implementation
of the IEEE 802.15.4 and 6LoWPAN protocols. IEEE 802.15.4 is a stack
of protocols for organizing Low-Rate Wireless Personal Area Networks.

The stack is composed of three main parts:

- IEEE 802.15.4 layer;  We have chosen to use plain Berkeley socket API,
  the generic Linux networking stack to transfer IEEE 802.15.4 data
  messages and a special protocol over netlink for configuration/management
- MAC - provides access to shared channel and reliable data delivery
- PHY - represents device drivers

소켓 API

26-37

데이터그램 소켓은 `socket(PF_IEEE802154, SOCK_DGRAM, 0)`으로 만듭니다. 주소군과 소켓 주소 정의는 `include/net/af_ieee802154.h` 또는 wpan-tools 사용자 공간 패키지의 전용 헤더에서 찾을 수 있습니다.

Socket API
==========

::

    int sd = socket(PF_IEEE802154, SOCK_DGRAM, 0);

The address family, socket addresses etc. are defined in the
include/net/af_ieee802154.h header or in the special header
in the userspace package (see either https://linux-wpan.org/wpan-tools.html
or the git tree at https://github.com/linux-wpan/wpan-tools).

Linux 6LoWPAN 구현

38-64

IEEE 802.15.4 MTU는 127바이트이며 보안을 켜면 실제 MAC payload는 약 80 octet, 링크 처리량은 250kbps 이하입니다. RFC 4944의 6LoWPAN 적응 형식은 이런 대역폭, 메모리, 에너지 제약을 고려해 IPv6 datagram을 전달합니다. Mesh Addressing header는 sub-IP forwarding, Fragmentation header는 IPv6 최소 MTU, LOWPAN_HC1/HC2는 큰 IPv6/UDP header를 최선의 경우 몇 바이트로 줄이는 stateless 압축을 제공합니다.

2011년 RFC 6282는 HC1과 HC2를 폐기하고 Linux 구현이 사용하는 IPHC 인코딩을 정의했습니다. 관련 코드는 `net/6lowpan/*`와 `net/ieee802154/6lowpan/*`에 있습니다.

6LoWPAN 인터페이스를 만들려면 IEEE 802.15.4 인터페이스를 추가하고 channel과 PAN ID를 설정한 뒤 `ip link add link wpan0 name lowpan0 type lowpan`으로 `lowpan0`를 만들고 인터페이스를 올립니다.

6LoWPAN Linux implementation
============================

The IEEE 802.15.4 standard specifies an MTU of 127 bytes, yielding about 80
octets of actual MAC payload once security is turned on, on a wireless link
with a link throughput of 250 kbps or less.  The 6LoWPAN adaptation format
[RFC4944] was specified to carry IPv6 datagrams over such constrained links,
taking into account limited bandwidth, memory, or energy resources that are
expected in applications such as wireless Sensor Networks.  [RFC4944] defines
a Mesh Addressing header to support sub-IP forwarding, a Fragmentation header
to support the IPv6 minimum MTU requirement [RFC2460], and stateless header
compression for IPv6 datagrams (LOWPAN_HC1 and LOWPAN_HC2) to reduce the
relatively large IPv6 and UDP headers down to (in the best case) several bytes.

In September 2011 the standard update was published - [RFC6282].
It deprecates HC1 and HC2 compression and defines IPHC encoding format which is
used in this Linux implementation.

All the code related to 6lowpan you may find in files: net/6lowpan/*
and net/ieee802154/6lowpan/*

To setup a 6LoWPAN interface you need:
1. Add IEEE802.15.4 interface and set channel and PAN ID;
2. Add 6lowpan interface by command like:
# ip link add link wpan0 name lowpan0 type lowpan
3. Bring up 'lowpan0' interface

드라이버 유형

65-77

Wi-Fi와 마찬가지로 IEEE 802.15.4 장치도 구현 위치에 따라 나뉩니다. HardMAC 장치는 MAC 계층을 장치 안에 구현하고 MLME 같은 관리 API와 데이터 API를 노출합니다. SoftMAC 또는 단순 radio 장치는 송수신기를 제공하며 자동 CRC 계산과 비교, ACK 처리, 주소 일치 같은 일부 가속만 포함할 수 있습니다. 두 유형은 Linux 커널에 연결하는 방식이 다릅니다.

Drivers
=======

Like with WiFi, there are several types of devices implementing IEEE 802.15.4.
1) 'HardMAC'. The MAC layer is implemented in the device itself, the device
exports a management (e.g. MLME) and data API.
2) 'SoftMAC' or just radio. These types of devices are just radio transceivers
possibly with some kinds of acceleration like automatic CRC computation and
comparison, automagic ACK handling, address matching, etc.

Each type of device requires a different approach to be hooked into the Linux
kernel.

HardMAC

78-94

HardMAC 드라이버는 `include/net/ieee802154_netdev.h`를 참고해 `.type = ARPHRD_IEEE802154`인 Linux `net_device`를 구현합니다. 소켓 주소군 코드와 데이터는 일반 `sk_buff`로 교환합니다. 수신 시 `skb->cb`에는 `struct ieee802154_mac_cb`의 부가 정보가 있어야 하고, 송신 시 이 영역은 `header_ops->create`에 부가 정보를 전달합니다.

소켓 코드가 `skb`를 qdisc에 넘길 때 `skb->cb`를 덮어쓸 수 있으므로 나중에도 필요한 값은 드라이버가 `skb->data`에 직접 저장해야 합니다. MLME를 연결하려면 `net_device.ml_priv`에 `struct ieee802154_mlme_ops` 포인터를 넣습니다. `assoc_req`, `assoc_resp`, `disassoc_req`, `start_req`, `scan_req`는 선택 사항이고 나머지 필드는 필수입니다.

HardMAC
-------

See the header include/net/ieee802154_netdev.h. You have to implement Linux
net_device, with .type = ARPHRD_IEEE802154. Data is exchanged with socket family
code via plain sk_buffs. On skb reception skb->cb must contain additional
info as described in the struct ieee802154_mac_cb. During packet transmission
the skb->cb is used to provide additional data to the device's
header_ops->create function. Be aware that this data can be overridden later
(when socket code submits skb to qdisc), so if you need something from that cb
later, you should store info in the skb->data on your own.

To hook the MLME interface you have to populate the ml_priv field of your
net_device with a pointer to struct ieee802154_mlme_ops instance. The fields
assoc_req, assoc_resp, disassoc_req, start_req, and scan_req are optional.
All other fields are required.

SoftMAC

95-109

MAC은 Linux IEEE 802.15.4 스택의 중간 계층으로 드라이버 등록과 slave 인터페이스 관리를 제공합니다. 이 문서 시점에는 Wireshark 같은 sniffer용 IEEE 802.15.4 monitor 장치 유형만 지원하며 계층은 확장 예정이라고 설명합니다. 인터페이스는 `include/net/mac802154.h`, 예제 드라이버는 `drivers/net/ieee802154/`에 있습니다.

SoftMAC
-------

The MAC is the middle layer in the IEEE 802.15.4 Linux stack. At the moment, it
provides an interface for driver registration and management of slave
interfaces.

NOTE: Currently the only monitor device type is supported - it's IEEE 802.15.4
stack interface for network sniffers (e.g. WireShark).

This layer is going to be extended soon.

See header include/net/mac802154.h and several drivers in
drivers/net/ieee802154/.

가상 드라이버

110-116

`fakelb`는 실제 SoftMAC 장치를 흉내 내는 IEEE 802.15.4 loopback 드라이버입니다. 실제 무선 하드웨어 없이 스택을 시험하고 디버깅할 수 있습니다.

Fake drivers
------------

In addition there is a driver available which simulates a real device with
SoftMAC (fakelb - IEEE 802.15.4 loopback driver) interface. This option
provides a possibility to test and debug the stack without usage of real hardware.

장치 할당과 등록 API

117-147

`ieee802154_alloc_device(priv_size, ops)`는 IEEE 802.15.4 호환 장치와 드라이버 전용 공간을 할당하고, `ieee802154_free_device(dev)`는 할당한 장치를 해제합니다. `ieee802154_register_device(dev)`는 PHY를 시스템에 등록하며 `ieee802154_unregister_device(dev)`는 등록된 PHY를 제거합니다.

`ieee802154_rx_irqsafe(hw, skb, lqi)`는 하드웨어의 RF Link Quality Indicator와 함께 새 수신 frame이 `skb`에 있음을 스택에 알립니다. `ieee802154_xmit_complete(hw, skb, ifs_handling)`는 해당 frame이 하드웨어를 통해 전송되었거나 곧 전송될 것임을 알립니다.

Device drivers API
==================

The include/net/mac802154.h defines following functions:

.. c:function:: struct ieee802154_dev *ieee802154_alloc_device (size_t priv_size, struct ieee802154_ops *ops)

Allocation of IEEE 802.15.4 compatible device.

.. c:function:: void ieee802154_free_device(struct ieee802154_dev *dev)

Freeing allocated device.

.. c:function:: int ieee802154_register_device(struct ieee802154_dev *dev)

Register PHY in the system.

.. c:function:: void ieee802154_unregister_device(struct ieee802154_dev *dev)

Freeing registered PHY.

.. c:function:: void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, u8 lqi)

Telling 802.15.4 module there is a new received frame in the skb with
the RF Link Quality Indicator (LQI) from the hardware device.

.. c:function:: void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb, bool ifs_handling)

Telling 802.15.4 module the frame in the skb is or going to be
transmitted through the hardware device

필수 장치 연산

148-184

드라이버는 `struct ieee802154_ops`에서 최소한 `start`, `stop`, `xmit_async`, `ed`, `set_channel` callback을 구현해야 합니다. `start(hw)`는 하드웨어 초기화, `stop(hw)`은 정리를 위해 802.15.4 모듈이 호출합니다.

`xmit_async(hw, skb)`는 전송할 각 frame마다 호출되고, `ed(hw, level)`는 하드웨어 Energy Detection 값을 요청합니다. `set_channel(hw, page, channel)`은 radio가 지정한 channel을 수신하도록 설정합니다. 이 밖에도 장치가 지원하는 IEEE 802.15.4 연산 구조체 필드를 채워야 합니다.

SoftMAC 드라이버 동작
ieee802154_alloc_device()ops 설정ieee802154_register_device()
start()set_channel() / ed()xmit_async()ieee802154_xmit_complete()
ieee802154_rx_irqsafe()스택 수신 처리
stop()unregisterfree

등록 이후의 대표 callback 흐름입니다.

The device driver must implement the following callbacks in the IEEE 802.15.4
operations structure at least::

   struct ieee802154_ops {
        ...
        int     (*start)(struct ieee802154_hw *hw);
        void    (*stop)(struct ieee802154_hw *hw);
        ...
        int     (*xmit_async)(struct ieee802154_hw *hw, struct sk_buff *skb);
        int     (*ed)(struct ieee802154_hw *hw, u8 *level);
        int     (*set_channel)(struct ieee802154_hw *hw, u8 page, u8 channel);
        ...
   };

.. c:function:: int start(struct ieee802154_hw *hw)

Handler that 802.15.4 module calls for the hardware device initialization.

.. c:function:: void stop(struct ieee802154_hw *hw)

Handler that 802.15.4 module calls for the hardware device cleanup.

.. c:function:: int xmit_async(struct ieee802154_hw *hw, struct sk_buff *skb)

Handler that 802.15.4 module calls for each frame in the skb going to be
transmitted through the hardware device.

.. c:function:: int ed(struct ieee802154_hw *hw, u8 *level)

Handler that 802.15.4 module calls for Energy Detection from the hardware
device.

.. c:function:: int set_channel(struct ieee802154_hw *hw, u8 page, u8 channel)

Set radio for listening on specific channel of the hardware device.

Moreover IEEE 802.15.4 device operations structure should be filled.