Linux Audio

Check our new training course

Loading...
v5.14.15
  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 */
 25struct ieee802154_local {
 26	struct ieee802154_hw hw;
 27	const struct ieee802154_ops *ops;
 28
 
 
 29	/* ieee802154 phy */
 30	struct wpan_phy *phy;
 31
 32	int open_count;
 33
 34	/* As in mac80211 slaves list is modified:
 35	 * 1) under the RTNL
 36	 * 2) protected by slaves_mtx;
 37	 * 3) in an RCU manner
 38	 *
 39	 * So atomic readers can use any of this protection methods.
 40	 */
 41	struct list_head	interfaces;
 42	struct mutex		iflist_mtx;
 43
 44	/* This one is used for scanning and other jobs not to be interfered
 45	 * with serial driver.
 46	 */
 47	struct workqueue_struct	*workqueue;
 
 
 48
 49	struct hrtimer ifs_timer;
 50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 51	bool started;
 52	bool suspended;
 
 53
 54	struct tasklet_struct tasklet;
 55	struct sk_buff_head skb_queue;
 56
 57	struct sk_buff *tx_skb;
 58	struct work_struct tx_work;
 
 
 59};
 60
 61enum {
 62	IEEE802154_RX_MSG        = 1,
 63};
 64
 65enum ieee802154_sdata_state_bits {
 66	SDATA_STATE_RUNNING,
 67};
 68
 69/* Slave interface definition.
 70 *
 71 * Slaves represent typical network interfaces available from userspace.
 72 * Each ieee802154 device/transceiver may have several slaves and able
 73 * to be associated with several networks at the same time.
 74 */
 75struct ieee802154_sub_if_data {
 76	struct list_head list; /* the ieee802154_priv->slaves list */
 77
 78	struct wpan_dev wpan_dev;
 79
 80	struct ieee802154_local *local;
 81	struct net_device *dev;
 82
 
 
 
 
 
 
 
 
 
 
 83	unsigned long state;
 84	char name[IFNAMSIZ];
 85
 86	/* protects sec from concurrent access by netlink. access by
 87	 * encrypt/decrypt/header_create safe without additional protection.
 88	 */
 89	struct mutex sec_mtx;
 90
 91	struct mac802154_llsec sec;
 92};
 93
 94/* utility functions/constants */
 95extern const void *const mac802154_wpan_phy_privid; /*  for wpan_phy privid */
 96
 97static inline struct ieee802154_local *
 98hw_to_local(struct ieee802154_hw *hw)
 99{
100	return container_of(hw, struct ieee802154_local, hw);
101}
102
103static inline struct ieee802154_sub_if_data *
104IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
105{
106	return netdev_priv(dev);
107}
108
109static inline struct ieee802154_sub_if_data *
110IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev)
111{
112	return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev);
113}
114
115static inline bool
116ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
117{
118	return test_bit(SDATA_STATE_RUNNING, &sdata->state);
119}
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
122
123void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb);
124void ieee802154_xmit_worker(struct work_struct *work);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125netdev_tx_t
126ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
127netdev_tx_t
128ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
129enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131/* MIB callbacks */
132void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
133
134int mac802154_get_params(struct net_device *dev,
135			 struct ieee802154_llsec_params *params);
136int mac802154_set_params(struct net_device *dev,
137			 const struct ieee802154_llsec_params *params,
138			 int changed);
139
140int mac802154_add_key(struct net_device *dev,
141		      const struct ieee802154_llsec_key_id *id,
142		      const struct ieee802154_llsec_key *key);
143int mac802154_del_key(struct net_device *dev,
144		      const struct ieee802154_llsec_key_id *id);
145
146int mac802154_add_dev(struct net_device *dev,
147		      const struct ieee802154_llsec_device *llsec_dev);
148int mac802154_del_dev(struct net_device *dev, __le64 dev_addr);
149
150int mac802154_add_devkey(struct net_device *dev,
151			 __le64 device_addr,
152			 const struct ieee802154_llsec_device_key *key);
153int mac802154_del_devkey(struct net_device *dev,
154			 __le64 device_addr,
155			 const struct ieee802154_llsec_device_key *key);
156
157int mac802154_add_seclevel(struct net_device *dev,
158			   const struct ieee802154_llsec_seclevel *sl);
159int mac802154_del_seclevel(struct net_device *dev,
160			   const struct ieee802154_llsec_seclevel *sl);
161
162void mac802154_lock_table(struct net_device *dev);
163void mac802154_get_table(struct net_device *dev,
164			 struct ieee802154_llsec_table **t);
165void mac802154_unlock_table(struct net_device *dev);
166
167int mac802154_wpan_update_llsec(struct net_device *dev);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
169/* interface handling */
170int ieee802154_iface_init(void);
171void ieee802154_iface_exit(void);
172void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
173struct net_device *
174ieee802154_if_add(struct ieee802154_local *local, const char *name,
175		  unsigned char name_assign_type, enum nl802154_iftype type,
176		  __le64 extended_addr);
177void ieee802154_remove_interfaces(struct ieee802154_local *local);
178void ieee802154_stop_device(struct ieee802154_local *local);
179
180#endif /* __IEEE802154_I_H */
v6.13.7
  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
 24enum ieee802154_ongoing {
 25	IEEE802154_IS_SCANNING = BIT(0),
 26	IEEE802154_IS_BEACONING = BIT(1),
 27	IEEE802154_IS_ASSOCIATING = BIT(2),
 28};
 29
 30/* mac802154 device private data */
 31struct ieee802154_local {
 32	struct ieee802154_hw hw;
 33	const struct ieee802154_ops *ops;
 34
 35	/* hardware address filter */
 36	struct ieee802154_hw_addr_filt addr_filt;
 37	/* ieee802154 phy */
 38	struct wpan_phy *phy;
 39
 40	int open_count;
 41
 42	/* As in mac80211 slaves list is modified:
 43	 * 1) under the RTNL
 44	 * 2) protected by slaves_mtx;
 45	 * 3) in an RCU manner
 46	 *
 47	 * So atomic readers can use any of this protection methods.
 48	 */
 49	struct list_head	interfaces;
 50	struct mutex		iflist_mtx;
 51
 52	/* Data related workqueue */
 
 
 53	struct workqueue_struct	*workqueue;
 54	/* MAC commands related workqueue */
 55	struct workqueue_struct	*mac_wq;
 56
 57	struct hrtimer ifs_timer;
 58
 59	/* Scanning */
 60	u8 scan_page;
 61	u8 scan_channel;
 62	struct ieee802154_beacon_req_frame scan_beacon_req;
 63	struct cfg802154_scan_request __rcu *scan_req;
 64	struct delayed_work scan_work;
 65
 66	/* Beaconing */
 67	unsigned int beacon_interval;
 68	struct ieee802154_beacon_frame beacon;
 69	struct cfg802154_beacon_request __rcu *beacon_req;
 70	struct delayed_work beacon_work;
 71
 72	/* Asynchronous tasks */
 73	struct list_head rx_beacon_list;
 74	struct work_struct rx_beacon_work;
 75	struct list_head rx_mac_cmd_list;
 76	struct work_struct rx_mac_cmd_work;
 77
 78	/* Association */
 79	struct ieee802154_pan_device *assoc_dev;
 80	struct completion assoc_done;
 81	__le16 assoc_addr;
 82	u8 assoc_status;
 83	struct work_struct assoc_work;
 84
 85	bool started;
 86	bool suspended;
 87	unsigned long ongoing;
 88
 89	struct tasklet_struct tasklet;
 90	struct sk_buff_head skb_queue;
 91
 92	struct sk_buff *tx_skb;
 93	struct work_struct sync_tx_work;
 94	/* A negative Linux error code or a null/positive MLME error status */
 95	int tx_result;
 96};
 97
 98enum {
 99	IEEE802154_RX_MSG        = 1,
100};
101
102enum ieee802154_sdata_state_bits {
103	SDATA_STATE_RUNNING,
104};
105
106/* Slave interface definition.
107 *
108 * Slaves represent typical network interfaces available from userspace.
109 * Each ieee802154 device/transceiver may have several slaves and able
110 * to be associated with several networks at the same time.
111 */
112struct ieee802154_sub_if_data {
113	struct list_head list; /* the ieee802154_priv->slaves list */
114
115	struct wpan_dev wpan_dev;
116
117	struct ieee802154_local *local;
118	struct net_device *dev;
119
120	/* Each interface starts and works in nominal state at a given filtering
121	 * level given by iface_default_filtering, which is set once for all at
122	 * the interface creation and should not evolve over time. For some MAC
123	 * operations however, the filtering level may change temporarily, as
124	 * reflected in the required_filtering field. The actual filtering at
125	 * the PHY level may be different and is shown in struct wpan_phy.
126	 */
127	enum ieee802154_filtering_level iface_default_filtering;
128	enum ieee802154_filtering_level required_filtering;
129
130	unsigned long state;
131	char name[IFNAMSIZ];
132
133	/* protects sec from concurrent access by netlink. access by
134	 * encrypt/decrypt/header_create safe without additional protection.
135	 */
136	struct mutex sec_mtx;
137
138	struct mac802154_llsec sec;
139};
140
141/* utility functions/constants */
142extern const void *const mac802154_wpan_phy_privid; /*  for wpan_phy privid */
143
144static inline struct ieee802154_local *
145hw_to_local(struct ieee802154_hw *hw)
146{
147	return container_of(hw, struct ieee802154_local, hw);
148}
149
150static inline struct ieee802154_sub_if_data *
151IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
152{
153	return netdev_priv(dev);
154}
155
156static inline struct ieee802154_sub_if_data *
157IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev)
158{
159	return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev);
160}
161
162static inline bool
163ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
164{
165	return test_bit(SDATA_STATE_RUNNING, &sdata->state);
166}
167
168static inline int ieee802154_get_mac_cmd(struct sk_buff *skb, u8 *mac_cmd)
169{
170	struct ieee802154_mac_cmd_pl mac_pl;
171	int ret;
172
173	if (mac_cb(skb)->type != IEEE802154_FC_TYPE_MAC_CMD)
174		return -EINVAL;
175
176	ret = ieee802154_mac_cmd_pl_pull(skb, &mac_pl);
177	if (ret)
178		return ret;
179
180	*mac_cmd = mac_pl.cmd_id;
181	return 0;
182}
183
184extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
185
186void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb);
187void ieee802154_xmit_sync_worker(struct work_struct *work);
188int ieee802154_sync_and_hold_queue(struct ieee802154_local *local);
189int ieee802154_mlme_op_pre(struct ieee802154_local *local);
190int ieee802154_mlme_tx(struct ieee802154_local *local,
191		       struct ieee802154_sub_if_data *sdata,
192		       struct sk_buff *skb);
193int ieee802154_mlme_tx_locked(struct ieee802154_local *local,
194			      struct ieee802154_sub_if_data *sdata,
195			      struct sk_buff *skb);
196void ieee802154_mlme_op_post(struct ieee802154_local *local);
197int ieee802154_mlme_tx_one(struct ieee802154_local *local,
198			   struct ieee802154_sub_if_data *sdata,
199			   struct sk_buff *skb);
200int ieee802154_mlme_tx_one_locked(struct ieee802154_local *local,
201				  struct ieee802154_sub_if_data *sdata,
202				  struct sk_buff *skb);
203netdev_tx_t
204ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
205netdev_tx_t
206ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
207enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
208
209/**
210 * ieee802154_hold_queue - hold ieee802154 queue
211 * @local: main mac object
212 *
213 * Hold a queue by incrementing an atomic counter and requesting the netif
214 * queues to be stopped. The queues cannot be woken up while the counter has not
215 * been reset with as any ieee802154_release_queue() calls as needed.
216 */
217void ieee802154_hold_queue(struct ieee802154_local *local);
218
219/**
220 * ieee802154_release_queue - release ieee802154 queue
221 * @local: main mac object
222 *
223 * Release a queue which is held by decrementing an atomic counter and wake it
224 * up only if the counter reaches 0.
225 */
226void ieee802154_release_queue(struct ieee802154_local *local);
227
228/**
229 * ieee802154_disable_queue - disable ieee802154 queue
230 * @local: main mac object
231 *
232 * When trying to sync the Tx queue, we cannot just stop the queue
233 * (which is basically a bit being set without proper lock handling)
234 * because it would be racy. We actually need to call netif_tx_disable()
235 * instead, which is done by this helper. Restarting the queue can
236 * however still be done with a regular wake call.
237 */
238void ieee802154_disable_queue(struct ieee802154_local *local);
239
240/* MIB callbacks */
241void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
242
243int mac802154_get_params(struct net_device *dev,
244			 struct ieee802154_llsec_params *params);
245int mac802154_set_params(struct net_device *dev,
246			 const struct ieee802154_llsec_params *params,
247			 int changed);
248
249int mac802154_add_key(struct net_device *dev,
250		      const struct ieee802154_llsec_key_id *id,
251		      const struct ieee802154_llsec_key *key);
252int mac802154_del_key(struct net_device *dev,
253		      const struct ieee802154_llsec_key_id *id);
254
255int mac802154_add_dev(struct net_device *dev,
256		      const struct ieee802154_llsec_device *llsec_dev);
257int mac802154_del_dev(struct net_device *dev, __le64 dev_addr);
258
259int mac802154_add_devkey(struct net_device *dev,
260			 __le64 device_addr,
261			 const struct ieee802154_llsec_device_key *key);
262int mac802154_del_devkey(struct net_device *dev,
263			 __le64 device_addr,
264			 const struct ieee802154_llsec_device_key *key);
265
266int mac802154_add_seclevel(struct net_device *dev,
267			   const struct ieee802154_llsec_seclevel *sl);
268int mac802154_del_seclevel(struct net_device *dev,
269			   const struct ieee802154_llsec_seclevel *sl);
270
271void mac802154_lock_table(struct net_device *dev);
272void mac802154_get_table(struct net_device *dev,
273			 struct ieee802154_llsec_table **t);
274void mac802154_unlock_table(struct net_device *dev);
275
276int mac802154_wpan_update_llsec(struct net_device *dev);
277
278/* PAN management handling */
279void mac802154_scan_worker(struct work_struct *work);
280int mac802154_trigger_scan_locked(struct ieee802154_sub_if_data *sdata,
281				  struct cfg802154_scan_request *request);
282int mac802154_abort_scan_locked(struct ieee802154_local *local,
283				struct ieee802154_sub_if_data *sdata);
284int mac802154_process_beacon(struct ieee802154_local *local,
285			     struct sk_buff *skb,
286			     u8 page, u8 channel);
287void mac802154_rx_beacon_worker(struct work_struct *work);
288
289static inline bool mac802154_is_scanning(struct ieee802154_local *local)
290{
291	return test_bit(IEEE802154_IS_SCANNING, &local->ongoing);
292}
293
294void mac802154_beacon_worker(struct work_struct *work);
295int mac802154_send_beacons_locked(struct ieee802154_sub_if_data *sdata,
296				  struct cfg802154_beacon_request *request);
297int mac802154_stop_beacons_locked(struct ieee802154_local *local,
298				  struct ieee802154_sub_if_data *sdata);
299
300static inline bool mac802154_is_beaconing(struct ieee802154_local *local)
301{
302	return test_bit(IEEE802154_IS_BEACONING, &local->ongoing);
303}
304
305void mac802154_rx_mac_cmd_worker(struct work_struct *work);
306
307int mac802154_perform_association(struct ieee802154_sub_if_data *sdata,
308				  struct ieee802154_pan_device *coord,
309				  __le16 *short_addr);
310int mac802154_process_association_resp(struct ieee802154_sub_if_data *sdata,
311				       struct sk_buff *skb);
312
313static inline bool mac802154_is_associating(struct ieee802154_local *local)
314{
315	return test_bit(IEEE802154_IS_ASSOCIATING, &local->ongoing);
316}
317
318int mac802154_send_disassociation_notif(struct ieee802154_sub_if_data *sdata,
319					struct ieee802154_pan_device *target,
320					u8 reason);
321int mac802154_process_disassociation_notif(struct ieee802154_sub_if_data *sdata,
322					   struct sk_buff *skb);
323int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
324				      struct sk_buff *skb);
325
326/* interface handling */
327int ieee802154_iface_init(void);
328void ieee802154_iface_exit(void);
329void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
330struct net_device *
331ieee802154_if_add(struct ieee802154_local *local, const char *name,
332		  unsigned char name_assign_type, enum nl802154_iftype type,
333		  __le64 extended_addr);
334void ieee802154_remove_interfaces(struct ieee802154_local *local);
335void ieee802154_stop_device(struct ieee802154_local *local);
336
337#endif /* __IEEE802154_I_H */