xref: /openbmc/linux/net/mac802154/ieee802154_i.h (revision e8254a8e)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2007-2012 Siemens AG
4  *
5  * Written by:
6  * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
7  * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
8  * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
9  * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
10  */
11 #ifndef __IEEE802154_I_H
12 #define __IEEE802154_I_H
13 
14 #include <linux/interrupt.h>
15 #include <linux/mutex.h>
16 #include <linux/hrtimer.h>
17 #include <net/cfg802154.h>
18 #include <net/mac802154.h>
19 #include <net/nl802154.h>
20 #include <net/ieee802154_netdev.h>
21 
22 #include "llsec.h"
23 
24 /* mac802154 device private data */
25 struct ieee802154_local {
26 	struct ieee802154_hw hw;
27 	const struct ieee802154_ops *ops;
28 
29 	/* hardware address filter */
30 	struct ieee802154_hw_addr_filt addr_filt;
31 	/* ieee802154 phy */
32 	struct wpan_phy *phy;
33 
34 	int open_count;
35 
36 	/* As in mac80211 slaves list is modified:
37 	 * 1) under the RTNL
38 	 * 2) protected by slaves_mtx;
39 	 * 3) in an RCU manner
40 	 *
41 	 * So atomic readers can use any of this protection methods.
42 	 */
43 	struct list_head	interfaces;
44 	struct mutex		iflist_mtx;
45 
46 	/* This one is used for scanning and other jobs not to be interfered
47 	 * with serial driver.
48 	 */
49 	struct workqueue_struct	*workqueue;
50 
51 	struct hrtimer ifs_timer;
52 
53 	bool started;
54 	bool suspended;
55 
56 	struct tasklet_struct tasklet;
57 	struct sk_buff_head skb_queue;
58 
59 	struct sk_buff *tx_skb;
60 	struct work_struct sync_tx_work;
61 	/* A negative Linux error code or a null/positive MLME error status */
62 	int tx_result;
63 };
64 
65 enum {
66 	IEEE802154_RX_MSG        = 1,
67 };
68 
69 enum ieee802154_sdata_state_bits {
70 	SDATA_STATE_RUNNING,
71 };
72 
73 /* Slave interface definition.
74  *
75  * Slaves represent typical network interfaces available from userspace.
76  * Each ieee802154 device/transceiver may have several slaves and able
77  * to be associated with several networks at the same time.
78  */
79 struct ieee802154_sub_if_data {
80 	struct list_head list; /* the ieee802154_priv->slaves list */
81 
82 	struct wpan_dev wpan_dev;
83 
84 	struct ieee802154_local *local;
85 	struct net_device *dev;
86 
87 	/* Each interface starts and works in nominal state at a given filtering
88 	 * level given by iface_default_filtering, which is set once for all at
89 	 * the interface creation and should not evolve over time. For some MAC
90 	 * operations however, the filtering level may change temporarily, as
91 	 * reflected in the required_filtering field. The actual filtering at
92 	 * the PHY level may be different and is shown in struct wpan_phy.
93 	 */
94 	enum ieee802154_filtering_level iface_default_filtering;
95 	enum ieee802154_filtering_level required_filtering;
96 
97 	unsigned long state;
98 	char name[IFNAMSIZ];
99 
100 	/* protects sec from concurrent access by netlink. access by
101 	 * encrypt/decrypt/header_create safe without additional protection.
102 	 */
103 	struct mutex sec_mtx;
104 
105 	struct mac802154_llsec sec;
106 };
107 
108 /* utility functions/constants */
109 extern const void *const mac802154_wpan_phy_privid; /*  for wpan_phy privid */
110 
111 static inline struct ieee802154_local *
112 hw_to_local(struct ieee802154_hw *hw)
113 {
114 	return container_of(hw, struct ieee802154_local, hw);
115 }
116 
117 static inline struct ieee802154_sub_if_data *
118 IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
119 {
120 	return netdev_priv(dev);
121 }
122 
123 static inline struct ieee802154_sub_if_data *
124 IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev)
125 {
126 	return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev);
127 }
128 
129 static inline bool
130 ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
131 {
132 	return test_bit(SDATA_STATE_RUNNING, &sdata->state);
133 }
134 
135 extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
136 
137 void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb);
138 void ieee802154_xmit_sync_worker(struct work_struct *work);
139 int ieee802154_sync_and_hold_queue(struct ieee802154_local *local);
140 int ieee802154_mlme_op_pre(struct ieee802154_local *local);
141 int ieee802154_mlme_tx(struct ieee802154_local *local,
142 		       struct ieee802154_sub_if_data *sdata,
143 		       struct sk_buff *skb);
144 void ieee802154_mlme_op_post(struct ieee802154_local *local);
145 int ieee802154_mlme_tx_one(struct ieee802154_local *local,
146 			   struct ieee802154_sub_if_data *sdata,
147 			   struct sk_buff *skb);
148 netdev_tx_t
149 ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
150 netdev_tx_t
151 ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
152 enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
153 
154 /**
155  * ieee802154_hold_queue - hold ieee802154 queue
156  * @local: main mac object
157  *
158  * Hold a queue by incrementing an atomic counter and requesting the netif
159  * queues to be stopped. The queues cannot be woken up while the counter has not
160  * been reset with as any ieee802154_release_queue() calls as needed.
161  */
162 void ieee802154_hold_queue(struct ieee802154_local *local);
163 
164 /**
165  * ieee802154_release_queue - release ieee802154 queue
166  * @local: main mac object
167  *
168  * Release a queue which is held by decrementing an atomic counter and wake it
169  * up only if the counter reaches 0.
170  */
171 void ieee802154_release_queue(struct ieee802154_local *local);
172 
173 /**
174  * ieee802154_disable_queue - disable ieee802154 queue
175  * @local: main mac object
176  *
177  * When trying to sync the Tx queue, we cannot just stop the queue
178  * (which is basically a bit being set without proper lock handling)
179  * because it would be racy. We actually need to call netif_tx_disable()
180  * instead, which is done by this helper. Restarting the queue can
181  * however still be done with a regular wake call.
182  */
183 void ieee802154_disable_queue(struct ieee802154_local *local);
184 
185 /* MIB callbacks */
186 void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
187 
188 int mac802154_get_params(struct net_device *dev,
189 			 struct ieee802154_llsec_params *params);
190 int mac802154_set_params(struct net_device *dev,
191 			 const struct ieee802154_llsec_params *params,
192 			 int changed);
193 
194 int mac802154_add_key(struct net_device *dev,
195 		      const struct ieee802154_llsec_key_id *id,
196 		      const struct ieee802154_llsec_key *key);
197 int mac802154_del_key(struct net_device *dev,
198 		      const struct ieee802154_llsec_key_id *id);
199 
200 int mac802154_add_dev(struct net_device *dev,
201 		      const struct ieee802154_llsec_device *llsec_dev);
202 int mac802154_del_dev(struct net_device *dev, __le64 dev_addr);
203 
204 int mac802154_add_devkey(struct net_device *dev,
205 			 __le64 device_addr,
206 			 const struct ieee802154_llsec_device_key *key);
207 int mac802154_del_devkey(struct net_device *dev,
208 			 __le64 device_addr,
209 			 const struct ieee802154_llsec_device_key *key);
210 
211 int mac802154_add_seclevel(struct net_device *dev,
212 			   const struct ieee802154_llsec_seclevel *sl);
213 int mac802154_del_seclevel(struct net_device *dev,
214 			   const struct ieee802154_llsec_seclevel *sl);
215 
216 void mac802154_lock_table(struct net_device *dev);
217 void mac802154_get_table(struct net_device *dev,
218 			 struct ieee802154_llsec_table **t);
219 void mac802154_unlock_table(struct net_device *dev);
220 
221 int mac802154_wpan_update_llsec(struct net_device *dev);
222 
223 /* interface handling */
224 int ieee802154_iface_init(void);
225 void ieee802154_iface_exit(void);
226 void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
227 struct net_device *
228 ieee802154_if_add(struct ieee802154_local *local, const char *name,
229 		  unsigned char name_assign_type, enum nl802154_iftype type,
230 		  __le64 extended_addr);
231 void ieee802154_remove_interfaces(struct ieee802154_local *local);
232 void ieee802154_stop_device(struct ieee802154_local *local);
233 
234 #endif /* __IEEE802154_I_H */
235