11802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 20f1556bcSAlexander Aring /* 30f1556bcSAlexander Aring * Copyright (C) 2007-2012 Siemens AG 40f1556bcSAlexander Aring * 50f1556bcSAlexander Aring * Written by: 60f1556bcSAlexander Aring * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 70f1556bcSAlexander Aring * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 80f1556bcSAlexander Aring * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 90f1556bcSAlexander Aring * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 100f1556bcSAlexander Aring */ 110f1556bcSAlexander Aring #ifndef __IEEE802154_I_H 120f1556bcSAlexander Aring #define __IEEE802154_I_H 130f1556bcSAlexander Aring 14282ccf6eSFlorian Westphal #include <linux/interrupt.h> 150f1556bcSAlexander Aring #include <linux/mutex.h> 1661f2dcbaSAlexander Aring #include <linux/hrtimer.h> 17d5ae67baSAlexander Aring #include <net/cfg802154.h> 180f1556bcSAlexander Aring #include <net/mac802154.h> 19944742a3SAlexander Aring #include <net/nl802154.h> 200f1556bcSAlexander Aring #include <net/ieee802154_netdev.h> 210f1556bcSAlexander Aring 220f1556bcSAlexander Aring #include "llsec.h" 230f1556bcSAlexander Aring 24*57588c71SMiquel Raynal enum ieee802154_ongoing { 25*57588c71SMiquel Raynal IEEE802154_IS_SCANNING = BIT(0), 26*57588c71SMiquel Raynal }; 27*57588c71SMiquel Raynal 280f1556bcSAlexander Aring /* mac802154 device private data */ 29a5e1ec53SAlexander Aring struct ieee802154_local { 305a504397SAlexander Aring struct ieee802154_hw hw; 3116301861SAlexander Aring const struct ieee802154_ops *ops; 320f1556bcSAlexander Aring 33ac8037c3SAlexander Aring /* hardware address filter */ 34ac8037c3SAlexander Aring struct ieee802154_hw_addr_filt addr_filt; 350f1556bcSAlexander Aring /* ieee802154 phy */ 360f1556bcSAlexander Aring struct wpan_phy *phy; 370f1556bcSAlexander Aring 380f1556bcSAlexander Aring int open_count; 390f1556bcSAlexander Aring 400f1556bcSAlexander Aring /* As in mac80211 slaves list is modified: 410f1556bcSAlexander Aring * 1) under the RTNL 420f1556bcSAlexander Aring * 2) protected by slaves_mtx; 430f1556bcSAlexander Aring * 3) in an RCU manner 440f1556bcSAlexander Aring * 450f1556bcSAlexander Aring * So atomic readers can use any of this protection methods. 460f1556bcSAlexander Aring */ 47d98be45bSAlexander Aring struct list_head interfaces; 48d98be45bSAlexander Aring struct mutex iflist_mtx; 490f1556bcSAlexander Aring 50*57588c71SMiquel Raynal /* Data related workqueue */ 51f7730542SAlexander Aring struct workqueue_struct *workqueue; 52*57588c71SMiquel Raynal /* MAC commands related workqueue */ 53*57588c71SMiquel Raynal struct workqueue_struct *mac_wq; 540f1556bcSAlexander Aring 5561f2dcbaSAlexander Aring struct hrtimer ifs_timer; 5661f2dcbaSAlexander Aring 57*57588c71SMiquel Raynal /* Scanning */ 58*57588c71SMiquel Raynal u8 scan_page; 59*57588c71SMiquel Raynal u8 scan_channel; 60*57588c71SMiquel Raynal struct cfg802154_scan_request __rcu *scan_req; 61*57588c71SMiquel Raynal struct delayed_work scan_work; 62*57588c71SMiquel Raynal 63*57588c71SMiquel Raynal /* Asynchronous tasks */ 64*57588c71SMiquel Raynal struct list_head rx_beacon_list; 65*57588c71SMiquel Raynal struct work_struct rx_beacon_work; 66*57588c71SMiquel Raynal 675d65cae4SAlexander Aring bool started; 683cf24cf8SAlexander Aring bool suspended; 69*57588c71SMiquel Raynal unsigned long ongoing; 70c5c47e67SAlexander Aring 71c5c47e67SAlexander Aring struct tasklet_struct tasklet; 72c5c47e67SAlexander Aring struct sk_buff_head skb_queue; 73c22ff7b4SLennert Buytenhek 74c22ff7b4SLennert Buytenhek struct sk_buff *tx_skb; 75983a974bSMiquel Raynal struct work_struct sync_tx_work; 76337e2f86SMiquel Raynal /* A negative Linux error code or a null/positive MLME error status */ 77337e2f86SMiquel Raynal int tx_result; 780f1556bcSAlexander Aring }; 790f1556bcSAlexander Aring 80c5c47e67SAlexander Aring enum { 81c5c47e67SAlexander Aring IEEE802154_RX_MSG = 1, 82c5c47e67SAlexander Aring }; 83c5c47e67SAlexander Aring 840ea3da64SAlexander Aring enum ieee802154_sdata_state_bits { 850ea3da64SAlexander Aring SDATA_STATE_RUNNING, 860ea3da64SAlexander Aring }; 870ea3da64SAlexander Aring 880f1556bcSAlexander Aring /* Slave interface definition. 890f1556bcSAlexander Aring * 900f1556bcSAlexander Aring * Slaves represent typical network interfaces available from userspace. 910f1556bcSAlexander Aring * Each ieee802154 device/transceiver may have several slaves and able 920f1556bcSAlexander Aring * to be associated with several networks at the same time. 930f1556bcSAlexander Aring */ 94036562f9SAlexander Aring struct ieee802154_sub_if_data { 950f1556bcSAlexander Aring struct list_head list; /* the ieee802154_priv->slaves list */ 960f1556bcSAlexander Aring 97d5ae67baSAlexander Aring struct wpan_dev wpan_dev; 98d5ae67baSAlexander Aring 9904e850feSAlexander Aring struct ieee802154_local *local; 1000f1556bcSAlexander Aring struct net_device *dev; 1010f1556bcSAlexander Aring 102ac8037c3SAlexander Aring /* Each interface starts and works in nominal state at a given filtering 103ac8037c3SAlexander Aring * level given by iface_default_filtering, which is set once for all at 104ac8037c3SAlexander Aring * the interface creation and should not evolve over time. For some MAC 105ac8037c3SAlexander Aring * operations however, the filtering level may change temporarily, as 106ac8037c3SAlexander Aring * reflected in the required_filtering field. The actual filtering at 107ac8037c3SAlexander Aring * the PHY level may be different and is shown in struct wpan_phy. 108ac8037c3SAlexander Aring */ 109ac8037c3SAlexander Aring enum ieee802154_filtering_level iface_default_filtering; 110ac8037c3SAlexander Aring enum ieee802154_filtering_level required_filtering; 111ac8037c3SAlexander Aring 1120ea3da64SAlexander Aring unsigned long state; 113d5ae67baSAlexander Aring char name[IFNAMSIZ]; 1140f1556bcSAlexander Aring 1150f1556bcSAlexander Aring /* protects sec from concurrent access by netlink. access by 1160f1556bcSAlexander Aring * encrypt/decrypt/header_create safe without additional protection. 1170f1556bcSAlexander Aring */ 1180f1556bcSAlexander Aring struct mutex sec_mtx; 1190f1556bcSAlexander Aring 1200f1556bcSAlexander Aring struct mac802154_llsec sec; 1210f1556bcSAlexander Aring }; 1220f1556bcSAlexander Aring 1236322d50dSAlexander Aring /* utility functions/constants */ 1246322d50dSAlexander Aring extern const void *const mac802154_wpan_phy_privid; /* for wpan_phy privid */ 1256322d50dSAlexander Aring 12660741361SAlexander Aring static inline struct ieee802154_local * 12760741361SAlexander Aring hw_to_local(struct ieee802154_hw *hw) 12860741361SAlexander Aring { 12960741361SAlexander Aring return container_of(hw, struct ieee802154_local, hw); 13060741361SAlexander Aring } 13160741361SAlexander Aring 13259d19cd7SAlexander Aring static inline struct ieee802154_sub_if_data * 13359d19cd7SAlexander Aring IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev) 13459d19cd7SAlexander Aring { 13559d19cd7SAlexander Aring return netdev_priv(dev); 13659d19cd7SAlexander Aring } 13759d19cd7SAlexander Aring 138b821ecd4SAlexander Aring static inline struct ieee802154_sub_if_data * 139b821ecd4SAlexander Aring IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev) 140b821ecd4SAlexander Aring { 141b821ecd4SAlexander Aring return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev); 142b821ecd4SAlexander Aring } 143b821ecd4SAlexander Aring 1440ea3da64SAlexander Aring static inline bool 1450ea3da64SAlexander Aring ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata) 1460ea3da64SAlexander Aring { 1470ea3da64SAlexander Aring return test_bit(SDATA_STATE_RUNNING, &sdata->state); 1480ea3da64SAlexander Aring } 1490ea3da64SAlexander Aring 1500f1556bcSAlexander Aring extern struct ieee802154_mlme_ops mac802154_mlme_wpan; 1510f1556bcSAlexander Aring 152d10270ceSVarka Bhadram void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb); 153be8c6d86SMiquel Raynal void ieee802154_xmit_sync_worker(struct work_struct *work); 154f0feb349SMiquel Raynal int ieee802154_sync_and_hold_queue(struct ieee802154_local *local); 155ddd9ee7cSMiquel Raynal int ieee802154_mlme_op_pre(struct ieee802154_local *local); 156fbdaa5baSMiquel Raynal int ieee802154_mlme_tx(struct ieee802154_local *local, 157fbdaa5baSMiquel Raynal struct ieee802154_sub_if_data *sdata, 158fbdaa5baSMiquel Raynal struct sk_buff *skb); 159dd180962SMiquel Raynal int ieee802154_mlme_tx_locked(struct ieee802154_local *local, 160dd180962SMiquel Raynal struct ieee802154_sub_if_data *sdata, 161dd180962SMiquel Raynal struct sk_buff *skb); 162ddd9ee7cSMiquel Raynal void ieee802154_mlme_op_post(struct ieee802154_local *local); 163fbdaa5baSMiquel Raynal int ieee802154_mlme_tx_one(struct ieee802154_local *local, 164fbdaa5baSMiquel Raynal struct ieee802154_sub_if_data *sdata, 165fbdaa5baSMiquel Raynal struct sk_buff *skb); 166dd180962SMiquel Raynal int ieee802154_mlme_tx_one_locked(struct ieee802154_local *local, 167dd180962SMiquel Raynal struct ieee802154_sub_if_data *sdata, 168dd180962SMiquel Raynal struct sk_buff *skb); 169e5e584fcSAlexander Aring netdev_tx_t 170e5e584fcSAlexander Aring ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev); 171e5e584fcSAlexander Aring netdev_tx_t 172e5e584fcSAlexander Aring ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev); 17361f2dcbaSAlexander Aring enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer); 1740f1556bcSAlexander Aring 17520a19d1dSMiquel Raynal /** 17620a19d1dSMiquel Raynal * ieee802154_hold_queue - hold ieee802154 queue 17720a19d1dSMiquel Raynal * @local: main mac object 17820a19d1dSMiquel Raynal * 17920a19d1dSMiquel Raynal * Hold a queue by incrementing an atomic counter and requesting the netif 18020a19d1dSMiquel Raynal * queues to be stopped. The queues cannot be woken up while the counter has not 18120a19d1dSMiquel Raynal * been reset with as any ieee802154_release_queue() calls as needed. 18220a19d1dSMiquel Raynal */ 18320a19d1dSMiquel Raynal void ieee802154_hold_queue(struct ieee802154_local *local); 18420a19d1dSMiquel Raynal 18520a19d1dSMiquel Raynal /** 18620a19d1dSMiquel Raynal * ieee802154_release_queue - release ieee802154 queue 18720a19d1dSMiquel Raynal * @local: main mac object 18820a19d1dSMiquel Raynal * 18920a19d1dSMiquel Raynal * Release a queue which is held by decrementing an atomic counter and wake it 19020a19d1dSMiquel Raynal * up only if the counter reaches 0. 19120a19d1dSMiquel Raynal */ 19220a19d1dSMiquel Raynal void ieee802154_release_queue(struct ieee802154_local *local); 19320a19d1dSMiquel Raynal 194a40612f3SMiquel Raynal /** 195a40612f3SMiquel Raynal * ieee802154_disable_queue - disable ieee802154 queue 196a40612f3SMiquel Raynal * @local: main mac object 197a40612f3SMiquel Raynal * 198a40612f3SMiquel Raynal * When trying to sync the Tx queue, we cannot just stop the queue 199a40612f3SMiquel Raynal * (which is basically a bit being set without proper lock handling) 200a40612f3SMiquel Raynal * because it would be racy. We actually need to call netif_tx_disable() 201a40612f3SMiquel Raynal * instead, which is done by this helper. Restarting the queue can 202a40612f3SMiquel Raynal * however still be done with a regular wake call. 203a40612f3SMiquel Raynal */ 204a40612f3SMiquel Raynal void ieee802154_disable_queue(struct ieee802154_local *local); 205a40612f3SMiquel Raynal 2060f1556bcSAlexander Aring /* MIB callbacks */ 2070f1556bcSAlexander Aring void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); 2080f1556bcSAlexander Aring 2090f1556bcSAlexander Aring int mac802154_get_params(struct net_device *dev, 2100f1556bcSAlexander Aring struct ieee802154_llsec_params *params); 2110f1556bcSAlexander Aring int mac802154_set_params(struct net_device *dev, 2120f1556bcSAlexander Aring const struct ieee802154_llsec_params *params, 2130f1556bcSAlexander Aring int changed); 2140f1556bcSAlexander Aring 2150f1556bcSAlexander Aring int mac802154_add_key(struct net_device *dev, 2160f1556bcSAlexander Aring const struct ieee802154_llsec_key_id *id, 2170f1556bcSAlexander Aring const struct ieee802154_llsec_key *key); 2180f1556bcSAlexander Aring int mac802154_del_key(struct net_device *dev, 2190f1556bcSAlexander Aring const struct ieee802154_llsec_key_id *id); 2200f1556bcSAlexander Aring 2210f1556bcSAlexander Aring int mac802154_add_dev(struct net_device *dev, 2220f1556bcSAlexander Aring const struct ieee802154_llsec_device *llsec_dev); 2230f1556bcSAlexander Aring int mac802154_del_dev(struct net_device *dev, __le64 dev_addr); 2240f1556bcSAlexander Aring 2250f1556bcSAlexander Aring int mac802154_add_devkey(struct net_device *dev, 2260f1556bcSAlexander Aring __le64 device_addr, 2270f1556bcSAlexander Aring const struct ieee802154_llsec_device_key *key); 2280f1556bcSAlexander Aring int mac802154_del_devkey(struct net_device *dev, 2290f1556bcSAlexander Aring __le64 device_addr, 2300f1556bcSAlexander Aring const struct ieee802154_llsec_device_key *key); 2310f1556bcSAlexander Aring 2320f1556bcSAlexander Aring int mac802154_add_seclevel(struct net_device *dev, 2330f1556bcSAlexander Aring const struct ieee802154_llsec_seclevel *sl); 2340f1556bcSAlexander Aring int mac802154_del_seclevel(struct net_device *dev, 2350f1556bcSAlexander Aring const struct ieee802154_llsec_seclevel *sl); 2360f1556bcSAlexander Aring 2370f1556bcSAlexander Aring void mac802154_lock_table(struct net_device *dev); 2380f1556bcSAlexander Aring void mac802154_get_table(struct net_device *dev, 2390f1556bcSAlexander Aring struct ieee802154_llsec_table **t); 2400f1556bcSAlexander Aring void mac802154_unlock_table(struct net_device *dev); 2410f1556bcSAlexander Aring 242d77b4852SAlexander Aring int mac802154_wpan_update_llsec(struct net_device *dev); 243d77b4852SAlexander Aring 244*57588c71SMiquel Raynal /* PAN management handling */ 245*57588c71SMiquel Raynal void mac802154_scan_worker(struct work_struct *work); 246*57588c71SMiquel Raynal int mac802154_trigger_scan_locked(struct ieee802154_sub_if_data *sdata, 247*57588c71SMiquel Raynal struct cfg802154_scan_request *request); 248*57588c71SMiquel Raynal int mac802154_abort_scan_locked(struct ieee802154_local *local, 249*57588c71SMiquel Raynal struct ieee802154_sub_if_data *sdata); 250*57588c71SMiquel Raynal int mac802154_process_beacon(struct ieee802154_local *local, 251*57588c71SMiquel Raynal struct sk_buff *skb, 252*57588c71SMiquel Raynal u8 page, u8 channel); 253*57588c71SMiquel Raynal void mac802154_rx_beacon_worker(struct work_struct *work); 254*57588c71SMiquel Raynal 255*57588c71SMiquel Raynal static inline bool mac802154_is_scanning(struct ieee802154_local *local) 256*57588c71SMiquel Raynal { 257*57588c71SMiquel Raynal return test_bit(IEEE802154_IS_SCANNING, &local->ongoing); 258*57588c71SMiquel Raynal } 259*57588c71SMiquel Raynal 260be4fd8e5SAlexander Aring /* interface handling */ 261be4fd8e5SAlexander Aring int ieee802154_iface_init(void); 262be4fd8e5SAlexander Aring void ieee802154_iface_exit(void); 263b210b187SAlexander Aring void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata); 264986a8abfSAlexander Aring struct net_device * 265986a8abfSAlexander Aring ieee802154_if_add(struct ieee802154_local *local, const char *name, 2665b4a1039SVarka Bhadram unsigned char name_assign_type, enum nl802154_iftype type, 2675b4a1039SVarka Bhadram __le64 extended_addr); 268592dfbfcSAlexander Aring void ieee802154_remove_interfaces(struct ieee802154_local *local); 269c4227c8aSAlexander Aring void ieee802154_stop_device(struct ieee802154_local *local); 2704a9a816aSAlexander Aring 2710f1556bcSAlexander Aring #endif /* __IEEE802154_I_H */ 272