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