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