Commit | Line | Data |
---|---|---|
0afd7ad9 | 1 | /* |
2 | * IEEE802.15.4-2003 specification | |
3 | * | |
4 | * Copyright (C) 2007-2012 Siemens AG | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
0afd7ad9 | 15 | */ |
16 | #ifndef NET_MAC802154_H | |
17 | #define NET_MAC802154_H | |
18 | ||
19 | #include <net/af_ieee802154.h> | |
239a84a9 | 20 | #include <linux/ieee802154.h> |
94b4f6c2 | 21 | #include <linux/skbuff.h> |
ba5bf17e | 22 | #include <linux/unaligned/memmove.h> |
0afd7ad9 | 23 | |
7fe9a388 AA |
24 | #include <net/cfg802154.h> |
25 | ||
32bad7e3 | 26 | /* General MAC frame format: |
27 | * 2 bytes: Frame Control | |
28 | * 1 byte: Sequence Number | |
29 | * 20 bytes: Addressing fields | |
30 | * 14 bytes: Auxiliary Security Header | |
31 | */ | |
32 | #define MAC802154_FRAME_HARD_HEADER_LEN (2 + 1 + 20 + 14) | |
33 | ||
0afd7ad9 | 34 | /* The following flags are used to indicate changed address settings from |
35 | * the stack to the hardware. | |
36 | */ | |
37 | ||
38 | /* indicates that the Short Address changed */ | |
57205c14 | 39 | #define IEEE802154_AFILT_SADDR_CHANGED 0x00000001 |
0afd7ad9 | 40 | /* indicates that the IEEE Address changed */ |
57205c14 | 41 | #define IEEE802154_AFILT_IEEEADDR_CHANGED 0x00000002 |
0afd7ad9 | 42 | /* indicates that the PAN ID changed */ |
57205c14 | 43 | #define IEEE802154_AFILT_PANID_CHANGED 0x00000004 |
0afd7ad9 | 44 | /* indicates that PAN Coordinator status changed */ |
57205c14 | 45 | #define IEEE802154_AFILT_PANC_CHANGED 0x00000008 |
0afd7ad9 | 46 | |
47 | struct ieee802154_hw_addr_filt { | |
48 | __le16 pan_id; /* Each independent PAN selects a unique | |
49 | * identifier. This PAN id allows communication | |
50 | * between devices within a network using short | |
51 | * addresses and enables transmissions between | |
52 | * devices across independent networks. | |
53 | */ | |
54 | __le16 short_addr; | |
b70ab2e8 | 55 | __le64 ieee_addr; |
0afd7ad9 | 56 | u8 pan_coord; |
57 | }; | |
58 | ||
7c118c1a AA |
59 | struct ieee802154_vif { |
60 | int type; | |
61 | ||
62 | /* must be last */ | |
63 | u8 drv_priv[0] __aligned(sizeof(void *)); | |
64 | }; | |
65 | ||
5a504397 | 66 | struct ieee802154_hw { |
0afd7ad9 | 67 | /* filled by the driver */ |
68 | int extra_tx_headroom; | |
69 | u32 flags; | |
70 | struct device *parent; | |
71 | ||
72 | /* filled by mac802154 core */ | |
73 | struct ieee802154_hw_addr_filt hw_filt; | |
74 | void *priv; | |
75 | struct wpan_phy *phy; | |
7c118c1a | 76 | size_t vif_data_size; |
0afd7ad9 | 77 | }; |
78 | ||
79 | /* Checksum is in hardware and is omitted from a packet | |
80 | * | |
81 | * These following flags are used to indicate hardware capabilities to | |
82 | * the stack. Generally, flags here should have their meaning | |
83 | * done in a way that the simplest hardware doesn't need setting | |
84 | * any particular flags. There are some exceptions to this rule, | |
85 | * however, so you are advised to review these flags carefully. | |
86 | */ | |
87 | ||
90386a7e AA |
88 | /* Indicates that xmitter will add FCS on it's own. */ |
89 | #define IEEE802154_HW_TX_OMIT_CKSUM 0x00000001 | |
0afd7ad9 | 90 | /* Indicates that receiver will autorespond with ACK frames. */ |
90a6161d | 91 | #define IEEE802154_HW_AACK 0x00000002 |
640985ec | 92 | /* Indicates that transceiver will support transmit power setting. */ |
90a6161d | 93 | #define IEEE802154_HW_TXPOWER 0x00000004 |
640985ec | 94 | /* Indicates that transceiver will support listen before transmit. */ |
90a6161d | 95 | #define IEEE802154_HW_LBT 0x00000008 |
640985ec | 96 | /* Indicates that transceiver will support cca mode setting. */ |
90a6161d | 97 | #define IEEE802154_HW_CCA_MODE 0x00000010 |
640985ec | 98 | /* Indicates that transceiver will support cca ed level setting. */ |
90a6161d | 99 | #define IEEE802154_HW_CCA_ED_LEVEL 0x00000020 |
640985ec AA |
100 | /* Indicates that transceiver will support csma (max_be, min_be, csma retries) |
101 | * settings. */ | |
90a6161d | 102 | #define IEEE802154_HW_CSMA_PARAMS 0x00000040 |
640985ec | 103 | /* Indicates that transceiver will support ARET frame retries setting. */ |
90a6161d | 104 | #define IEEE802154_HW_FRAME_RETRIES 0x00000080 |
c8fc84ed AA |
105 | /* Indicates that transceiver will support hardware address filter setting. */ |
106 | #define IEEE802154_HW_AFILT 0x00000100 | |
94b79222 AA |
107 | /* Indicates that transceiver will support promiscuous mode setting. */ |
108 | #define IEEE802154_HW_PROMISCUOUS 0x00000200 | |
90386a7e AA |
109 | /* Indicates that receiver omits FCS. */ |
110 | #define IEEE802154_HW_RX_OMIT_CKSUM 0x00000400 | |
ec718f3d AA |
111 | /* Indicates that receiver will not filter frames with bad checksum. */ |
112 | #define IEEE802154_HW_RX_DROP_BAD_CKSUM 0x00000800 | |
90386a7e AA |
113 | |
114 | /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */ | |
115 | #define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \ | |
116 | IEEE802154_HW_RX_OMIT_CKSUM) | |
640985ec AA |
117 | |
118 | /* This groups the most common CSMA support fields into one. */ | |
119 | #define IEEE802154_HW_CSMA (IEEE802154_HW_CCA_MODE | \ | |
120 | IEEE802154_HW_CCA_ED_LEVEL | \ | |
ab79be3e AA |
121 | IEEE802154_HW_CSMA_PARAMS) |
122 | ||
123 | /* This groups the most common ARET support fields into one. */ | |
124 | #define IEEE802154_HW_ARET (IEEE802154_HW_CSMA | \ | |
640985ec | 125 | IEEE802154_HW_FRAME_RETRIES) |
0afd7ad9 | 126 | |
127 | /* struct ieee802154_ops - callbacks from mac802154 to the driver | |
128 | * | |
129 | * This structure contains various callbacks that the driver may | |
130 | * handle or, in some cases, must handle, for example to transmit | |
131 | * a frame. | |
132 | * | |
133 | * start: Handler that 802.15.4 module calls for device initialization. | |
134 | * This function is called before the first interface is attached. | |
135 | * | |
136 | * stop: Handler that 802.15.4 module calls for device cleanup. | |
137 | * This function is called after the last interface is removed. | |
138 | * | |
ed0a5dce AA |
139 | * xmit_sync: |
140 | * Handler that 802.15.4 module calls for each transmitted frame. | |
141 | * skb cntains the buffer starting from the IEEE 802.15.4 header. | |
142 | * The low-level driver should send the frame based on available | |
143 | * configuration. This is called by a workqueue and useful for | |
144 | * synchronous 802.15.4 drivers. | |
145 | * This function should return zero or negative errno. | |
146 | * | |
1e7283a2 AA |
147 | * WARNING: |
148 | * This will be deprecated soon. We don't accept synced xmit callbacks | |
149 | * drivers anymore. | |
150 | * | |
ed0a5dce AA |
151 | * xmit_async: |
152 | * Handler that 802.15.4 module calls for each transmitted frame. | |
0afd7ad9 | 153 | * skb cntains the buffer starting from the IEEE 802.15.4 header. |
154 | * The low-level driver should send the frame based on available | |
155 | * configuration. | |
dc67c6b3 | 156 | * This function should return zero or negative errno. |
0afd7ad9 | 157 | * |
158 | * ed: Handler that 802.15.4 module calls for Energy Detection. | |
159 | * This function should place the value for detected energy | |
160 | * (usually device-dependant) in the level pointer and return | |
161 | * either zero or negative errno. Called with pib_lock held. | |
162 | * | |
163 | * set_channel: | |
164 | * Set radio for listening on specific channel. | |
165 | * Set the device for listening on specified channel. | |
166 | * Returns either zero, or negative errno. Called with pib_lock held. | |
167 | * | |
168 | * set_hw_addr_filt: | |
169 | * Set radio for listening on specific address. | |
170 | * Set the device for listening on specified address. | |
171 | * Returns either zero, or negative errno. | |
9b2777d6 PB |
172 | * |
173 | * set_txpower: | |
174 | * Set radio transmit power in dB. Called with pib_lock held. | |
175 | * Returns either zero, or negative errno. | |
84dda3c6 PB |
176 | * |
177 | * set_lbt | |
178 | * Enables or disables listen before talk on the device. Called with | |
179 | * pib_lock held. | |
180 | * Returns either zero, or negative errno. | |
ba08fea5 PB |
181 | * |
182 | * set_cca_mode | |
183 | * Sets the CCA mode used by the device. Called with pib_lock held. | |
184 | * Returns either zero, or negative errno. | |
6ca00197 PB |
185 | * |
186 | * set_cca_ed_level | |
187 | * Sets the CCA energy detection threshold in dBm. Called with pib_lock | |
188 | * held. | |
189 | * Returns either zero, or negative errno. | |
4244db1b PB |
190 | * |
191 | * set_csma_params | |
192 | * Sets the CSMA parameter set for the PHY. Called with pib_lock held. | |
193 | * Returns either zero, or negative errno. | |
194 | * | |
195 | * set_frame_retries | |
196 | * Sets the retransmission attempt limit. Called with pib_lock held. | |
197 | * Returns either zero, or negative errno. | |
94b79222 AA |
198 | * |
199 | * set_promiscuous_mode | |
200 | * Enables or disable promiscuous mode. | |
0afd7ad9 | 201 | */ |
202 | struct ieee802154_ops { | |
203 | struct module *owner; | |
5a504397 AA |
204 | int (*start)(struct ieee802154_hw *hw); |
205 | void (*stop)(struct ieee802154_hw *hw); | |
ed0a5dce AA |
206 | int (*xmit_sync)(struct ieee802154_hw *hw, |
207 | struct sk_buff *skb); | |
208 | int (*xmit_async)(struct ieee802154_hw *hw, | |
209 | struct sk_buff *skb); | |
5a504397 | 210 | int (*ed)(struct ieee802154_hw *hw, u8 *level); |
e37d2ec8 AA |
211 | int (*set_channel)(struct ieee802154_hw *hw, u8 page, |
212 | u8 channel); | |
5a504397 AA |
213 | int (*set_hw_addr_filt)(struct ieee802154_hw *hw, |
214 | struct ieee802154_hw_addr_filt *filt, | |
0afd7ad9 | 215 | unsigned long changed); |
5a504397 AA |
216 | int (*set_txpower)(struct ieee802154_hw *hw, int db); |
217 | int (*set_lbt)(struct ieee802154_hw *hw, bool on); | |
7fe9a388 AA |
218 | int (*set_cca_mode)(struct ieee802154_hw *hw, |
219 | const struct wpan_phy_cca *cca); | |
5a504397 | 220 | int (*set_cca_ed_level)(struct ieee802154_hw *hw, |
6ca00197 | 221 | s32 level); |
5a504397 | 222 | int (*set_csma_params)(struct ieee802154_hw *hw, |
4244db1b | 223 | u8 min_be, u8 max_be, u8 retries); |
5a504397 | 224 | int (*set_frame_retries)(struct ieee802154_hw *hw, |
4244db1b | 225 | s8 retries); |
94b79222 AA |
226 | int (*set_promiscuous_mode)(struct ieee802154_hw *hw, |
227 | const bool on); | |
0afd7ad9 | 228 | }; |
229 | ||
ab24f50f | 230 | /** |
705cbbbe AA |
231 | * ieee802154_be64_to_le64 - copies and convert be64 to le64 |
232 | * @le64_dst: le64 destination pointer | |
233 | * @be64_src: be64 source pointer | |
ab24f50f | 234 | */ |
705cbbbe | 235 | static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src) |
ab24f50f | 236 | { |
ba5bf17e | 237 | __put_unaligned_memmove64(swab64p(be64_src), le64_dst); |
ab24f50f AA |
238 | } |
239 | ||
239a84a9 AA |
240 | /** |
241 | * ieee802154_le64_to_be64 - copies and convert le64 to be64 | |
242 | * @be64_dst: be64 destination pointer | |
243 | * @le64_src: le64 source pointer | |
244 | */ | |
245 | static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src) | |
246 | { | |
b9767969 | 247 | __put_unaligned_memmove64(swab64p(le64_src), be64_dst); |
239a84a9 AA |
248 | } |
249 | ||
5a504397 AA |
250 | /* Basic interface to register ieee802154 hwice */ |
251 | struct ieee802154_hw * | |
16301861 | 252 | ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops); |
5a504397 AA |
253 | void ieee802154_free_hw(struct ieee802154_hw *hw); |
254 | int ieee802154_register_hw(struct ieee802154_hw *hw); | |
255 | void ieee802154_unregister_hw(struct ieee802154_hw *hw); | |
1010f540 | 256 | |
c5c47e67 | 257 | void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb); |
5a504397 | 258 | void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, |
1cd829c8 | 259 | u8 lqi); |
260 | ||
c2085103 AA |
261 | void ieee802154_wake_queue(struct ieee802154_hw *hw); |
262 | void ieee802154_stop_queue(struct ieee802154_hw *hw); | |
61f2dcba AA |
263 | void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb, |
264 | bool ifs_handling); | |
c2085103 | 265 | |
0afd7ad9 | 266 | #endif /* NET_MAC802154_H */ |