xref: /OK3568_Linux_fs/kernel/include/net/mac802154.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * IEEE802.15.4-2003 specification
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2007-2012 Siemens AG
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #ifndef NET_MAC802154_H
8*4882a593Smuzhiyun #define NET_MAC802154_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <asm/unaligned.h>
11*4882a593Smuzhiyun #include <net/af_ieee802154.h>
12*4882a593Smuzhiyun #include <linux/ieee802154.h>
13*4882a593Smuzhiyun #include <linux/skbuff.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <net/cfg802154.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /**
18*4882a593Smuzhiyun  * enum ieee802154_hw_addr_filt_flags - hardware address filtering flags
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * The following flags are used to indicate changed address settings from
21*4882a593Smuzhiyun  * the stack to the hardware.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * @IEEE802154_AFILT_SADDR_CHANGED: Indicates that the short address will be
24*4882a593Smuzhiyun  *	change.
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * @IEEE802154_AFILT_IEEEADDR_CHANGED: Indicates that the extended address
27*4882a593Smuzhiyun  *	will be change.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * @IEEE802154_AFILT_PANID_CHANGED: Indicates that the pan id will be change.
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  * @IEEE802154_AFILT_PANC_CHANGED: Indicates that the address filter will
32*4882a593Smuzhiyun  *	do frame address filtering as a pan coordinator.
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun enum ieee802154_hw_addr_filt_flags {
35*4882a593Smuzhiyun 	IEEE802154_AFILT_SADDR_CHANGED		= BIT(0),
36*4882a593Smuzhiyun 	IEEE802154_AFILT_IEEEADDR_CHANGED	= BIT(1),
37*4882a593Smuzhiyun 	IEEE802154_AFILT_PANID_CHANGED		= BIT(2),
38*4882a593Smuzhiyun 	IEEE802154_AFILT_PANC_CHANGED		= BIT(3),
39*4882a593Smuzhiyun };
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /**
42*4882a593Smuzhiyun  * struct ieee802154_hw_addr_filt - hardware address filtering settings
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * @pan_id: pan_id which should be set to the hardware address filter.
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  * @short_addr: short_addr which should be set to the hardware address filter.
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  * @ieee_addr: extended address which should be set to the hardware address
49*4882a593Smuzhiyun  *	filter.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * @pan_coord: boolean if hardware filtering should be operate as coordinator.
52*4882a593Smuzhiyun  */
53*4882a593Smuzhiyun struct ieee802154_hw_addr_filt {
54*4882a593Smuzhiyun 	__le16	pan_id;
55*4882a593Smuzhiyun 	__le16	short_addr;
56*4882a593Smuzhiyun 	__le64	ieee_addr;
57*4882a593Smuzhiyun 	bool	pan_coord;
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /**
61*4882a593Smuzhiyun  * struct ieee802154_hw - ieee802154 hardware
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  * @extra_tx_headroom: headroom to reserve in each transmit skb for use by the
64*4882a593Smuzhiyun  *	driver (e.g. for transmit headers.)
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  * @flags: hardware flags, see &enum ieee802154_hw_flags
67*4882a593Smuzhiyun  *
68*4882a593Smuzhiyun  * @parent: parent device of the hardware.
69*4882a593Smuzhiyun  *
70*4882a593Smuzhiyun  * @priv: pointer to private area that was allocated for driver use along with
71*4882a593Smuzhiyun  *	this structure.
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * @phy: This points to the &struct wpan_phy allocated for this 802.15.4 PHY.
74*4882a593Smuzhiyun  */
75*4882a593Smuzhiyun struct ieee802154_hw {
76*4882a593Smuzhiyun 	/* filled by the driver */
77*4882a593Smuzhiyun 	int	extra_tx_headroom;
78*4882a593Smuzhiyun 	u32	flags;
79*4882a593Smuzhiyun 	struct	device *parent;
80*4882a593Smuzhiyun 	void	*priv;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	/* filled by mac802154 core */
83*4882a593Smuzhiyun 	struct	wpan_phy *phy;
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /**
87*4882a593Smuzhiyun  * enum ieee802154_hw_flags - hardware flags
88*4882a593Smuzhiyun  *
89*4882a593Smuzhiyun  * These flags are used to indicate hardware capabilities to
90*4882a593Smuzhiyun  * the stack. Generally, flags here should have their meaning
91*4882a593Smuzhiyun  * done in a way that the simplest hardware doesn't need setting
92*4882a593Smuzhiyun  * any particular flags. There are some exceptions to this rule,
93*4882a593Smuzhiyun  * however, so you are advised to review these flags carefully.
94*4882a593Smuzhiyun  *
95*4882a593Smuzhiyun  * @IEEE802154_HW_TX_OMIT_CKSUM: Indicates that xmitter will add FCS on it's
96*4882a593Smuzhiyun  *	own.
97*4882a593Smuzhiyun  *
98*4882a593Smuzhiyun  * @IEEE802154_HW_LBT: Indicates that transceiver will support listen before
99*4882a593Smuzhiyun  *	transmit.
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  * @IEEE802154_HW_CSMA_PARAMS: Indicates that transceiver will support csma
102*4882a593Smuzhiyun  *	parameters (max_be, min_be, backoff exponents).
103*4882a593Smuzhiyun  *
104*4882a593Smuzhiyun  * @IEEE802154_HW_FRAME_RETRIES: Indicates that transceiver will support ARET
105*4882a593Smuzhiyun  *	frame retries setting.
106*4882a593Smuzhiyun  *
107*4882a593Smuzhiyun  * @IEEE802154_HW_AFILT: Indicates that transceiver will support hardware
108*4882a593Smuzhiyun  *	address filter setting.
109*4882a593Smuzhiyun  *
110*4882a593Smuzhiyun  * @IEEE802154_HW_PROMISCUOUS: Indicates that transceiver will support
111*4882a593Smuzhiyun  *	promiscuous mode setting.
112*4882a593Smuzhiyun  *
113*4882a593Smuzhiyun  * @IEEE802154_HW_RX_OMIT_CKSUM: Indicates that receiver omits FCS.
114*4882a593Smuzhiyun  *
115*4882a593Smuzhiyun  * @IEEE802154_HW_RX_DROP_BAD_CKSUM: Indicates that receiver will not filter
116*4882a593Smuzhiyun  *	frames with bad checksum.
117*4882a593Smuzhiyun  */
118*4882a593Smuzhiyun enum ieee802154_hw_flags {
119*4882a593Smuzhiyun 	IEEE802154_HW_TX_OMIT_CKSUM	= BIT(0),
120*4882a593Smuzhiyun 	IEEE802154_HW_LBT		= BIT(1),
121*4882a593Smuzhiyun 	IEEE802154_HW_CSMA_PARAMS	= BIT(2),
122*4882a593Smuzhiyun 	IEEE802154_HW_FRAME_RETRIES	= BIT(3),
123*4882a593Smuzhiyun 	IEEE802154_HW_AFILT		= BIT(4),
124*4882a593Smuzhiyun 	IEEE802154_HW_PROMISCUOUS	= BIT(5),
125*4882a593Smuzhiyun 	IEEE802154_HW_RX_OMIT_CKSUM	= BIT(6),
126*4882a593Smuzhiyun 	IEEE802154_HW_RX_DROP_BAD_CKSUM	= BIT(7),
127*4882a593Smuzhiyun };
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
130*4882a593Smuzhiyun #define IEEE802154_HW_OMIT_CKSUM	(IEEE802154_HW_TX_OMIT_CKSUM | \
131*4882a593Smuzhiyun 					 IEEE802154_HW_RX_OMIT_CKSUM)
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /* struct ieee802154_ops - callbacks from mac802154 to the driver
134*4882a593Smuzhiyun  *
135*4882a593Smuzhiyun  * This structure contains various callbacks that the driver may
136*4882a593Smuzhiyun  * handle or, in some cases, must handle, for example to transmit
137*4882a593Smuzhiyun  * a frame.
138*4882a593Smuzhiyun  *
139*4882a593Smuzhiyun  * start: Handler that 802.15.4 module calls for device initialization.
140*4882a593Smuzhiyun  *	  This function is called before the first interface is attached.
141*4882a593Smuzhiyun  *
142*4882a593Smuzhiyun  * stop:  Handler that 802.15.4 module calls for device cleanup.
143*4882a593Smuzhiyun  *	  This function is called after the last interface is removed.
144*4882a593Smuzhiyun  *
145*4882a593Smuzhiyun  * xmit_sync:
146*4882a593Smuzhiyun  *	  Handler that 802.15.4 module calls for each transmitted frame.
147*4882a593Smuzhiyun  *	  skb cntains the buffer starting from the IEEE 802.15.4 header.
148*4882a593Smuzhiyun  *	  The low-level driver should send the frame based on available
149*4882a593Smuzhiyun  *	  configuration. This is called by a workqueue and useful for
150*4882a593Smuzhiyun  *	  synchronous 802.15.4 drivers.
151*4882a593Smuzhiyun  *	  This function should return zero or negative errno.
152*4882a593Smuzhiyun  *
153*4882a593Smuzhiyun  *	  WARNING:
154*4882a593Smuzhiyun  *	  This will be deprecated soon. We don't accept synced xmit callbacks
155*4882a593Smuzhiyun  *	  drivers anymore.
156*4882a593Smuzhiyun  *
157*4882a593Smuzhiyun  * xmit_async:
158*4882a593Smuzhiyun  *	  Handler that 802.15.4 module calls for each transmitted frame.
159*4882a593Smuzhiyun  *	  skb cntains the buffer starting from the IEEE 802.15.4 header.
160*4882a593Smuzhiyun  *	  The low-level driver should send the frame based on available
161*4882a593Smuzhiyun  *	  configuration.
162*4882a593Smuzhiyun  *	  This function should return zero or negative errno.
163*4882a593Smuzhiyun  *
164*4882a593Smuzhiyun  * ed:    Handler that 802.15.4 module calls for Energy Detection.
165*4882a593Smuzhiyun  *	  This function should place the value for detected energy
166*4882a593Smuzhiyun  *	  (usually device-dependant) in the level pointer and return
167*4882a593Smuzhiyun  *	  either zero or negative errno. Called with pib_lock held.
168*4882a593Smuzhiyun  *
169*4882a593Smuzhiyun  * set_channel:
170*4882a593Smuzhiyun  * 	  Set radio for listening on specific channel.
171*4882a593Smuzhiyun  *	  Set the device for listening on specified channel.
172*4882a593Smuzhiyun  *	  Returns either zero, or negative errno. Called with pib_lock held.
173*4882a593Smuzhiyun  *
174*4882a593Smuzhiyun  * set_hw_addr_filt:
175*4882a593Smuzhiyun  *	  Set radio for listening on specific address.
176*4882a593Smuzhiyun  *	  Set the device for listening on specified address.
177*4882a593Smuzhiyun  *	  Returns either zero, or negative errno.
178*4882a593Smuzhiyun  *
179*4882a593Smuzhiyun  * set_txpower:
180*4882a593Smuzhiyun  *	  Set radio transmit power in mBm. Called with pib_lock held.
181*4882a593Smuzhiyun  *	  Returns either zero, or negative errno.
182*4882a593Smuzhiyun  *
183*4882a593Smuzhiyun  * set_lbt
184*4882a593Smuzhiyun  *	  Enables or disables listen before talk on the device. Called with
185*4882a593Smuzhiyun  *	  pib_lock held.
186*4882a593Smuzhiyun  *	  Returns either zero, or negative errno.
187*4882a593Smuzhiyun  *
188*4882a593Smuzhiyun  * set_cca_mode
189*4882a593Smuzhiyun  *	  Sets the CCA mode used by the device. Called with pib_lock held.
190*4882a593Smuzhiyun  *	  Returns either zero, or negative errno.
191*4882a593Smuzhiyun  *
192*4882a593Smuzhiyun  * set_cca_ed_level
193*4882a593Smuzhiyun  *	  Sets the CCA energy detection threshold in mBm. Called with pib_lock
194*4882a593Smuzhiyun  *	  held.
195*4882a593Smuzhiyun  *	  Returns either zero, or negative errno.
196*4882a593Smuzhiyun  *
197*4882a593Smuzhiyun  * set_csma_params
198*4882a593Smuzhiyun  *	  Sets the CSMA parameter set for the PHY. Called with pib_lock held.
199*4882a593Smuzhiyun  *	  Returns either zero, or negative errno.
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * set_frame_retries
202*4882a593Smuzhiyun  *	  Sets the retransmission attempt limit. Called with pib_lock held.
203*4882a593Smuzhiyun  *	  Returns either zero, or negative errno.
204*4882a593Smuzhiyun  *
205*4882a593Smuzhiyun  * set_promiscuous_mode
206*4882a593Smuzhiyun  *	  Enables or disable promiscuous mode.
207*4882a593Smuzhiyun  */
208*4882a593Smuzhiyun struct ieee802154_ops {
209*4882a593Smuzhiyun 	struct module	*owner;
210*4882a593Smuzhiyun 	int		(*start)(struct ieee802154_hw *hw);
211*4882a593Smuzhiyun 	void		(*stop)(struct ieee802154_hw *hw);
212*4882a593Smuzhiyun 	int		(*xmit_sync)(struct ieee802154_hw *hw,
213*4882a593Smuzhiyun 				     struct sk_buff *skb);
214*4882a593Smuzhiyun 	int		(*xmit_async)(struct ieee802154_hw *hw,
215*4882a593Smuzhiyun 				      struct sk_buff *skb);
216*4882a593Smuzhiyun 	int		(*ed)(struct ieee802154_hw *hw, u8 *level);
217*4882a593Smuzhiyun 	int		(*set_channel)(struct ieee802154_hw *hw, u8 page,
218*4882a593Smuzhiyun 				       u8 channel);
219*4882a593Smuzhiyun 	int		(*set_hw_addr_filt)(struct ieee802154_hw *hw,
220*4882a593Smuzhiyun 					    struct ieee802154_hw_addr_filt *filt,
221*4882a593Smuzhiyun 					    unsigned long changed);
222*4882a593Smuzhiyun 	int		(*set_txpower)(struct ieee802154_hw *hw, s32 mbm);
223*4882a593Smuzhiyun 	int		(*set_lbt)(struct ieee802154_hw *hw, bool on);
224*4882a593Smuzhiyun 	int		(*set_cca_mode)(struct ieee802154_hw *hw,
225*4882a593Smuzhiyun 					const struct wpan_phy_cca *cca);
226*4882a593Smuzhiyun 	int		(*set_cca_ed_level)(struct ieee802154_hw *hw, s32 mbm);
227*4882a593Smuzhiyun 	int		(*set_csma_params)(struct ieee802154_hw *hw,
228*4882a593Smuzhiyun 					   u8 min_be, u8 max_be, u8 retries);
229*4882a593Smuzhiyun 	int		(*set_frame_retries)(struct ieee802154_hw *hw,
230*4882a593Smuzhiyun 					     s8 retries);
231*4882a593Smuzhiyun 	int             (*set_promiscuous_mode)(struct ieee802154_hw *hw,
232*4882a593Smuzhiyun 						const bool on);
233*4882a593Smuzhiyun };
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun /**
236*4882a593Smuzhiyun  * ieee802154_get_fc_from_skb - get the frame control field from an skb
237*4882a593Smuzhiyun  * @skb: skb where the frame control field will be get from
238*4882a593Smuzhiyun  */
ieee802154_get_fc_from_skb(const struct sk_buff * skb)239*4882a593Smuzhiyun static inline __le16 ieee802154_get_fc_from_skb(const struct sk_buff *skb)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun 	__le16 fc;
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun 	/* check if we can fc at skb_mac_header of sk buffer */
244*4882a593Smuzhiyun 	if (WARN_ON(!skb_mac_header_was_set(skb) ||
245*4882a593Smuzhiyun 		    (skb_tail_pointer(skb) -
246*4882a593Smuzhiyun 		     skb_mac_header(skb)) < IEEE802154_FC_LEN))
247*4882a593Smuzhiyun 		return cpu_to_le16(0);
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun 	memcpy(&fc, skb_mac_header(skb), IEEE802154_FC_LEN);
250*4882a593Smuzhiyun 	return fc;
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun /**
254*4882a593Smuzhiyun  * ieee802154_skb_dst_pan - get the pointer to destination pan field
255*4882a593Smuzhiyun  * @fc: mac header frame control field
256*4882a593Smuzhiyun  * @skb: skb where the destination pan pointer will be get from
257*4882a593Smuzhiyun  */
ieee802154_skb_dst_pan(__le16 fc,const struct sk_buff * skb)258*4882a593Smuzhiyun static inline unsigned char *ieee802154_skb_dst_pan(__le16 fc,
259*4882a593Smuzhiyun 						    const struct sk_buff *skb)
260*4882a593Smuzhiyun {
261*4882a593Smuzhiyun 	unsigned char *dst_pan;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	switch (ieee802154_daddr_mode(fc)) {
264*4882a593Smuzhiyun 	case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE):
265*4882a593Smuzhiyun 		dst_pan = NULL;
266*4882a593Smuzhiyun 		break;
267*4882a593Smuzhiyun 	case cpu_to_le16(IEEE802154_FCTL_DADDR_SHORT):
268*4882a593Smuzhiyun 	case cpu_to_le16(IEEE802154_FCTL_DADDR_EXTENDED):
269*4882a593Smuzhiyun 		dst_pan = skb_mac_header(skb) +
270*4882a593Smuzhiyun 			  IEEE802154_FC_LEN +
271*4882a593Smuzhiyun 			  IEEE802154_SEQ_LEN;
272*4882a593Smuzhiyun 		break;
273*4882a593Smuzhiyun 	default:
274*4882a593Smuzhiyun 		WARN_ONCE(1, "invalid addr mode detected");
275*4882a593Smuzhiyun 		dst_pan = NULL;
276*4882a593Smuzhiyun 		break;
277*4882a593Smuzhiyun 	}
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun 	return dst_pan;
280*4882a593Smuzhiyun }
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun /**
283*4882a593Smuzhiyun  * ieee802154_skb_src_pan - get the pointer to source pan field
284*4882a593Smuzhiyun  * @fc: mac header frame control field
285*4882a593Smuzhiyun  * @skb: skb where the source pan pointer will be get from
286*4882a593Smuzhiyun  */
ieee802154_skb_src_pan(__le16 fc,const struct sk_buff * skb)287*4882a593Smuzhiyun static inline unsigned char *ieee802154_skb_src_pan(__le16 fc,
288*4882a593Smuzhiyun 						    const struct sk_buff *skb)
289*4882a593Smuzhiyun {
290*4882a593Smuzhiyun 	unsigned char *src_pan;
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 	switch (ieee802154_saddr_mode(fc)) {
293*4882a593Smuzhiyun 	case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE):
294*4882a593Smuzhiyun 		src_pan = NULL;
295*4882a593Smuzhiyun 		break;
296*4882a593Smuzhiyun 	case cpu_to_le16(IEEE802154_FCTL_SADDR_SHORT):
297*4882a593Smuzhiyun 	case cpu_to_le16(IEEE802154_FCTL_SADDR_EXTENDED):
298*4882a593Smuzhiyun 		/* if intra-pan and source addr mode is non none,
299*4882a593Smuzhiyun 		 * then source pan id is equal destination pan id.
300*4882a593Smuzhiyun 		 */
301*4882a593Smuzhiyun 		if (ieee802154_is_intra_pan(fc)) {
302*4882a593Smuzhiyun 			src_pan = ieee802154_skb_dst_pan(fc, skb);
303*4882a593Smuzhiyun 			break;
304*4882a593Smuzhiyun 		}
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun 		switch (ieee802154_daddr_mode(fc)) {
307*4882a593Smuzhiyun 		case cpu_to_le16(IEEE802154_FCTL_ADDR_NONE):
308*4882a593Smuzhiyun 			src_pan = skb_mac_header(skb) +
309*4882a593Smuzhiyun 				  IEEE802154_FC_LEN +
310*4882a593Smuzhiyun 				  IEEE802154_SEQ_LEN;
311*4882a593Smuzhiyun 			break;
312*4882a593Smuzhiyun 		case cpu_to_le16(IEEE802154_FCTL_DADDR_SHORT):
313*4882a593Smuzhiyun 			src_pan = skb_mac_header(skb) +
314*4882a593Smuzhiyun 				  IEEE802154_FC_LEN +
315*4882a593Smuzhiyun 				  IEEE802154_SEQ_LEN +
316*4882a593Smuzhiyun 				  IEEE802154_PAN_ID_LEN +
317*4882a593Smuzhiyun 				  IEEE802154_SHORT_ADDR_LEN;
318*4882a593Smuzhiyun 			break;
319*4882a593Smuzhiyun 		case cpu_to_le16(IEEE802154_FCTL_DADDR_EXTENDED):
320*4882a593Smuzhiyun 			src_pan = skb_mac_header(skb) +
321*4882a593Smuzhiyun 				  IEEE802154_FC_LEN +
322*4882a593Smuzhiyun 				  IEEE802154_SEQ_LEN +
323*4882a593Smuzhiyun 				  IEEE802154_PAN_ID_LEN +
324*4882a593Smuzhiyun 				  IEEE802154_EXTENDED_ADDR_LEN;
325*4882a593Smuzhiyun 			break;
326*4882a593Smuzhiyun 		default:
327*4882a593Smuzhiyun 			WARN_ONCE(1, "invalid addr mode detected");
328*4882a593Smuzhiyun 			src_pan = NULL;
329*4882a593Smuzhiyun 			break;
330*4882a593Smuzhiyun 		}
331*4882a593Smuzhiyun 		break;
332*4882a593Smuzhiyun 	default:
333*4882a593Smuzhiyun 		WARN_ONCE(1, "invalid addr mode detected");
334*4882a593Smuzhiyun 		src_pan = NULL;
335*4882a593Smuzhiyun 		break;
336*4882a593Smuzhiyun 	}
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun 	return src_pan;
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun /**
342*4882a593Smuzhiyun  * ieee802154_skb_is_intra_pan_addressing - checks whenever the mac addressing
343*4882a593Smuzhiyun  *	is an intra pan communication
344*4882a593Smuzhiyun  * @fc: mac header frame control field
345*4882a593Smuzhiyun  * @skb: skb where the source and destination pan should be get from
346*4882a593Smuzhiyun  */
ieee802154_skb_is_intra_pan_addressing(__le16 fc,const struct sk_buff * skb)347*4882a593Smuzhiyun static inline bool ieee802154_skb_is_intra_pan_addressing(__le16 fc,
348*4882a593Smuzhiyun 							  const struct sk_buff *skb)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun 	unsigned char *dst_pan = ieee802154_skb_dst_pan(fc, skb),
351*4882a593Smuzhiyun 		      *src_pan = ieee802154_skb_src_pan(fc, skb);
352*4882a593Smuzhiyun 
353*4882a593Smuzhiyun 	/* if one is NULL is no intra pan addressing */
354*4882a593Smuzhiyun 	if (!dst_pan || !src_pan)
355*4882a593Smuzhiyun 		return false;
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun 	return !memcmp(dst_pan, src_pan, IEEE802154_PAN_ID_LEN);
358*4882a593Smuzhiyun }
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun /**
361*4882a593Smuzhiyun  * ieee802154_be64_to_le64 - copies and convert be64 to le64
362*4882a593Smuzhiyun  * @le64_dst: le64 destination pointer
363*4882a593Smuzhiyun  * @be64_src: be64 source pointer
364*4882a593Smuzhiyun  */
ieee802154_be64_to_le64(void * le64_dst,const void * be64_src)365*4882a593Smuzhiyun static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun 	put_unaligned_le64(get_unaligned_be64(be64_src), le64_dst);
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun /**
371*4882a593Smuzhiyun  * ieee802154_le64_to_be64 - copies and convert le64 to be64
372*4882a593Smuzhiyun  * @be64_dst: be64 destination pointer
373*4882a593Smuzhiyun  * @le64_src: le64 source pointer
374*4882a593Smuzhiyun  */
ieee802154_le64_to_be64(void * be64_dst,const void * le64_src)375*4882a593Smuzhiyun static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
376*4882a593Smuzhiyun {
377*4882a593Smuzhiyun 	put_unaligned_be64(get_unaligned_le64(le64_src), be64_dst);
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun /**
381*4882a593Smuzhiyun  * ieee802154_le16_to_be16 - copies and convert le16 to be16
382*4882a593Smuzhiyun  * @be16_dst: be16 destination pointer
383*4882a593Smuzhiyun  * @le16_src: le16 source pointer
384*4882a593Smuzhiyun  */
ieee802154_le16_to_be16(void * be16_dst,const void * le16_src)385*4882a593Smuzhiyun static inline void ieee802154_le16_to_be16(void *be16_dst, const void *le16_src)
386*4882a593Smuzhiyun {
387*4882a593Smuzhiyun 	put_unaligned_be16(get_unaligned_le16(le16_src), be16_dst);
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun /**
391*4882a593Smuzhiyun  * ieee802154_be16_to_le16 - copies and convert be16 to le16
392*4882a593Smuzhiyun  * @le16_dst: le16 destination pointer
393*4882a593Smuzhiyun  * @be16_src: be16 source pointer
394*4882a593Smuzhiyun  */
ieee802154_be16_to_le16(void * le16_dst,const void * be16_src)395*4882a593Smuzhiyun static inline void ieee802154_be16_to_le16(void *le16_dst, const void *be16_src)
396*4882a593Smuzhiyun {
397*4882a593Smuzhiyun 	put_unaligned_le16(get_unaligned_be16(be16_src), le16_dst);
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun 
400*4882a593Smuzhiyun /**
401*4882a593Smuzhiyun  * ieee802154_alloc_hw - Allocate a new hardware device
402*4882a593Smuzhiyun  *
403*4882a593Smuzhiyun  * This must be called once for each hardware device. The returned pointer
404*4882a593Smuzhiyun  * must be used to refer to this device when calling other functions.
405*4882a593Smuzhiyun  * mac802154 allocates a private data area for the driver pointed to by
406*4882a593Smuzhiyun  * @priv in &struct ieee802154_hw, the size of this area is given as
407*4882a593Smuzhiyun  * @priv_data_len.
408*4882a593Smuzhiyun  *
409*4882a593Smuzhiyun  * @priv_data_len: length of private data
410*4882a593Smuzhiyun  * @ops: callbacks for this device
411*4882a593Smuzhiyun  *
412*4882a593Smuzhiyun  * Return: A pointer to the new hardware device, or %NULL on error.
413*4882a593Smuzhiyun  */
414*4882a593Smuzhiyun struct ieee802154_hw *
415*4882a593Smuzhiyun ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun /**
418*4882a593Smuzhiyun  * ieee802154_free_hw - free hardware descriptor
419*4882a593Smuzhiyun  *
420*4882a593Smuzhiyun  * This function frees everything that was allocated, including the
421*4882a593Smuzhiyun  * private data for the driver. You must call ieee802154_unregister_hw()
422*4882a593Smuzhiyun  * before calling this function.
423*4882a593Smuzhiyun  *
424*4882a593Smuzhiyun  * @hw: the hardware to free
425*4882a593Smuzhiyun  */
426*4882a593Smuzhiyun void ieee802154_free_hw(struct ieee802154_hw *hw);
427*4882a593Smuzhiyun 
428*4882a593Smuzhiyun /**
429*4882a593Smuzhiyun  * ieee802154_register_hw - Register hardware device
430*4882a593Smuzhiyun  *
431*4882a593Smuzhiyun  * You must call this function before any other functions in
432*4882a593Smuzhiyun  * mac802154. Note that before a hardware can be registered, you
433*4882a593Smuzhiyun  * need to fill the contained wpan_phy's information.
434*4882a593Smuzhiyun  *
435*4882a593Smuzhiyun  * @hw: the device to register as returned by ieee802154_alloc_hw()
436*4882a593Smuzhiyun  *
437*4882a593Smuzhiyun  * Return: 0 on success. An error code otherwise.
438*4882a593Smuzhiyun  */
439*4882a593Smuzhiyun int ieee802154_register_hw(struct ieee802154_hw *hw);
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun /**
442*4882a593Smuzhiyun  * ieee802154_unregister_hw - Unregister a hardware device
443*4882a593Smuzhiyun  *
444*4882a593Smuzhiyun  * This function instructs mac802154 to free allocated resources
445*4882a593Smuzhiyun  * and unregister netdevices from the networking subsystem.
446*4882a593Smuzhiyun  *
447*4882a593Smuzhiyun  * @hw: the hardware to unregister
448*4882a593Smuzhiyun  */
449*4882a593Smuzhiyun void ieee802154_unregister_hw(struct ieee802154_hw *hw);
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun /**
452*4882a593Smuzhiyun  * ieee802154_rx_irqsafe - receive frame
453*4882a593Smuzhiyun  *
454*4882a593Smuzhiyun  * Like ieee802154_rx() but can be called in IRQ context
455*4882a593Smuzhiyun  * (internally defers to a tasklet.)
456*4882a593Smuzhiyun  *
457*4882a593Smuzhiyun  * @hw: the hardware this frame came in on
458*4882a593Smuzhiyun  * @skb: the buffer to receive, owned by mac802154 after this call
459*4882a593Smuzhiyun  * @lqi: link quality indicator
460*4882a593Smuzhiyun  */
461*4882a593Smuzhiyun void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
462*4882a593Smuzhiyun 			   u8 lqi);
463*4882a593Smuzhiyun /**
464*4882a593Smuzhiyun  * ieee802154_wake_queue - wake ieee802154 queue
465*4882a593Smuzhiyun  * @hw: pointer as obtained from ieee802154_alloc_hw().
466*4882a593Smuzhiyun  *
467*4882a593Smuzhiyun  * Drivers should use this function instead of netif_wake_queue.
468*4882a593Smuzhiyun  */
469*4882a593Smuzhiyun void ieee802154_wake_queue(struct ieee802154_hw *hw);
470*4882a593Smuzhiyun 
471*4882a593Smuzhiyun /**
472*4882a593Smuzhiyun  * ieee802154_stop_queue - stop ieee802154 queue
473*4882a593Smuzhiyun  * @hw: pointer as obtained from ieee802154_alloc_hw().
474*4882a593Smuzhiyun  *
475*4882a593Smuzhiyun  * Drivers should use this function instead of netif_stop_queue.
476*4882a593Smuzhiyun  */
477*4882a593Smuzhiyun void ieee802154_stop_queue(struct ieee802154_hw *hw);
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun /**
480*4882a593Smuzhiyun  * ieee802154_xmit_complete - frame transmission complete
481*4882a593Smuzhiyun  *
482*4882a593Smuzhiyun  * @hw: pointer as obtained from ieee802154_alloc_hw().
483*4882a593Smuzhiyun  * @skb: buffer for transmission
484*4882a593Smuzhiyun  * @ifs_handling: indicate interframe space handling
485*4882a593Smuzhiyun  */
486*4882a593Smuzhiyun void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
487*4882a593Smuzhiyun 			      bool ifs_handling);
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun #endif /* NET_MAC802154_H */
490