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