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 240f1556bcSAlexander Aring /* mac802154 device private data */ 25a5e1ec53SAlexander Aring struct ieee802154_local { 265a504397SAlexander Aring struct ieee802154_hw hw; 2716301861SAlexander Aring const struct ieee802154_ops *ops; 280f1556bcSAlexander Aring 290f1556bcSAlexander Aring /* ieee802154 phy */ 300f1556bcSAlexander Aring struct wpan_phy *phy; 310f1556bcSAlexander Aring 320f1556bcSAlexander Aring int open_count; 330f1556bcSAlexander Aring 340f1556bcSAlexander Aring /* As in mac80211 slaves list is modified: 350f1556bcSAlexander Aring * 1) under the RTNL 360f1556bcSAlexander Aring * 2) protected by slaves_mtx; 370f1556bcSAlexander Aring * 3) in an RCU manner 380f1556bcSAlexander Aring * 390f1556bcSAlexander Aring * So atomic readers can use any of this protection methods. 400f1556bcSAlexander Aring */ 41d98be45bSAlexander Aring struct list_head interfaces; 42d98be45bSAlexander Aring struct mutex iflist_mtx; 430f1556bcSAlexander Aring 440f1556bcSAlexander Aring /* This one is used for scanning and other jobs not to be interfered 450f1556bcSAlexander Aring * with serial driver. 460f1556bcSAlexander Aring */ 47f7730542SAlexander Aring struct workqueue_struct *workqueue; 480f1556bcSAlexander Aring 4961f2dcbaSAlexander Aring struct hrtimer ifs_timer; 5061f2dcbaSAlexander Aring 515d65cae4SAlexander Aring bool started; 523cf24cf8SAlexander Aring bool suspended; 53c5c47e67SAlexander Aring 54c5c47e67SAlexander Aring struct tasklet_struct tasklet; 55c5c47e67SAlexander Aring struct sk_buff_head skb_queue; 56c22ff7b4SLennert Buytenhek 57c22ff7b4SLennert Buytenhek struct sk_buff *tx_skb; 58983a974bSMiquel Raynal struct work_struct sync_tx_work; 59337e2f86SMiquel Raynal /* A negative Linux error code or a null/positive MLME error status */ 60337e2f86SMiquel Raynal int tx_result; 610f1556bcSAlexander Aring }; 620f1556bcSAlexander Aring 63c5c47e67SAlexander Aring enum { 64c5c47e67SAlexander Aring IEEE802154_RX_MSG = 1, 65c5c47e67SAlexander Aring }; 66c5c47e67SAlexander Aring 670ea3da64SAlexander Aring enum ieee802154_sdata_state_bits { 680ea3da64SAlexander Aring SDATA_STATE_RUNNING, 690ea3da64SAlexander Aring }; 700ea3da64SAlexander Aring 710f1556bcSAlexander Aring /* Slave interface definition. 720f1556bcSAlexander Aring * 730f1556bcSAlexander Aring * Slaves represent typical network interfaces available from userspace. 740f1556bcSAlexander Aring * Each ieee802154 device/transceiver may have several slaves and able 750f1556bcSAlexander Aring * to be associated with several networks at the same time. 760f1556bcSAlexander Aring */ 77036562f9SAlexander Aring struct ieee802154_sub_if_data { 780f1556bcSAlexander Aring struct list_head list; /* the ieee802154_priv->slaves list */ 790f1556bcSAlexander Aring 80d5ae67baSAlexander Aring struct wpan_dev wpan_dev; 81d5ae67baSAlexander Aring 8204e850feSAlexander Aring struct ieee802154_local *local; 830f1556bcSAlexander Aring struct net_device *dev; 840f1556bcSAlexander Aring 850ea3da64SAlexander Aring unsigned long state; 86d5ae67baSAlexander Aring char name[IFNAMSIZ]; 870f1556bcSAlexander Aring 880f1556bcSAlexander Aring /* protects sec from concurrent access by netlink. access by 890f1556bcSAlexander Aring * encrypt/decrypt/header_create safe without additional protection. 900f1556bcSAlexander Aring */ 910f1556bcSAlexander Aring struct mutex sec_mtx; 920f1556bcSAlexander Aring 930f1556bcSAlexander Aring struct mac802154_llsec sec; 940f1556bcSAlexander Aring }; 950f1556bcSAlexander Aring 966322d50dSAlexander Aring /* utility functions/constants */ 976322d50dSAlexander Aring extern const void *const mac802154_wpan_phy_privid; /* for wpan_phy privid */ 986322d50dSAlexander Aring 9960741361SAlexander Aring static inline struct ieee802154_local * 10060741361SAlexander Aring hw_to_local(struct ieee802154_hw *hw) 10160741361SAlexander Aring { 10260741361SAlexander Aring return container_of(hw, struct ieee802154_local, hw); 10360741361SAlexander Aring } 10460741361SAlexander Aring 10559d19cd7SAlexander Aring static inline struct ieee802154_sub_if_data * 10659d19cd7SAlexander Aring IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev) 10759d19cd7SAlexander Aring { 10859d19cd7SAlexander Aring return netdev_priv(dev); 10959d19cd7SAlexander Aring } 11059d19cd7SAlexander Aring 111b821ecd4SAlexander Aring static inline struct ieee802154_sub_if_data * 112b821ecd4SAlexander Aring IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev) 113b821ecd4SAlexander Aring { 114b821ecd4SAlexander Aring return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev); 115b821ecd4SAlexander Aring } 116b821ecd4SAlexander Aring 1170ea3da64SAlexander Aring static inline bool 1180ea3da64SAlexander Aring ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata) 1190ea3da64SAlexander Aring { 1200ea3da64SAlexander Aring return test_bit(SDATA_STATE_RUNNING, &sdata->state); 1210ea3da64SAlexander Aring } 1220ea3da64SAlexander Aring 1230f1556bcSAlexander Aring extern struct ieee802154_mlme_ops mac802154_mlme_wpan; 1240f1556bcSAlexander Aring 125d10270ceSVarka Bhadram void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb); 126be8c6d86SMiquel Raynal void ieee802154_xmit_sync_worker(struct work_struct *work); 127f0feb349SMiquel Raynal int ieee802154_sync_and_hold_queue(struct ieee802154_local *local); 128ddd9ee7cSMiquel Raynal int ieee802154_mlme_op_pre(struct ieee802154_local *local); 129*fbdaa5baSMiquel Raynal int ieee802154_mlme_tx(struct ieee802154_local *local, 130*fbdaa5baSMiquel Raynal struct ieee802154_sub_if_data *sdata, 131*fbdaa5baSMiquel Raynal struct sk_buff *skb); 132ddd9ee7cSMiquel Raynal void ieee802154_mlme_op_post(struct ieee802154_local *local); 133*fbdaa5baSMiquel Raynal int ieee802154_mlme_tx_one(struct ieee802154_local *local, 134*fbdaa5baSMiquel Raynal struct ieee802154_sub_if_data *sdata, 135*fbdaa5baSMiquel Raynal struct sk_buff *skb); 136e5e584fcSAlexander Aring netdev_tx_t 137e5e584fcSAlexander Aring ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev); 138e5e584fcSAlexander Aring netdev_tx_t 139e5e584fcSAlexander Aring ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev); 14061f2dcbaSAlexander Aring enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer); 1410f1556bcSAlexander Aring 14220a19d1dSMiquel Raynal /** 14320a19d1dSMiquel Raynal * ieee802154_hold_queue - hold ieee802154 queue 14420a19d1dSMiquel Raynal * @local: main mac object 14520a19d1dSMiquel Raynal * 14620a19d1dSMiquel Raynal * Hold a queue by incrementing an atomic counter and requesting the netif 14720a19d1dSMiquel Raynal * queues to be stopped. The queues cannot be woken up while the counter has not 14820a19d1dSMiquel Raynal * been reset with as any ieee802154_release_queue() calls as needed. 14920a19d1dSMiquel Raynal */ 15020a19d1dSMiquel Raynal void ieee802154_hold_queue(struct ieee802154_local *local); 15120a19d1dSMiquel Raynal 15220a19d1dSMiquel Raynal /** 15320a19d1dSMiquel Raynal * ieee802154_release_queue - release ieee802154 queue 15420a19d1dSMiquel Raynal * @local: main mac object 15520a19d1dSMiquel Raynal * 15620a19d1dSMiquel Raynal * Release a queue which is held by decrementing an atomic counter and wake it 15720a19d1dSMiquel Raynal * up only if the counter reaches 0. 15820a19d1dSMiquel Raynal */ 15920a19d1dSMiquel Raynal void ieee802154_release_queue(struct ieee802154_local *local); 16020a19d1dSMiquel Raynal 161a40612f3SMiquel Raynal /** 162a40612f3SMiquel Raynal * ieee802154_disable_queue - disable ieee802154 queue 163a40612f3SMiquel Raynal * @local: main mac object 164a40612f3SMiquel Raynal * 165a40612f3SMiquel Raynal * When trying to sync the Tx queue, we cannot just stop the queue 166a40612f3SMiquel Raynal * (which is basically a bit being set without proper lock handling) 167a40612f3SMiquel Raynal * because it would be racy. We actually need to call netif_tx_disable() 168a40612f3SMiquel Raynal * instead, which is done by this helper. Restarting the queue can 169a40612f3SMiquel Raynal * however still be done with a regular wake call. 170a40612f3SMiquel Raynal */ 171a40612f3SMiquel Raynal void ieee802154_disable_queue(struct ieee802154_local *local); 172a40612f3SMiquel Raynal 1730f1556bcSAlexander Aring /* MIB callbacks */ 1740f1556bcSAlexander Aring void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); 1750f1556bcSAlexander Aring 1760f1556bcSAlexander Aring int mac802154_get_params(struct net_device *dev, 1770f1556bcSAlexander Aring struct ieee802154_llsec_params *params); 1780f1556bcSAlexander Aring int mac802154_set_params(struct net_device *dev, 1790f1556bcSAlexander Aring const struct ieee802154_llsec_params *params, 1800f1556bcSAlexander Aring int changed); 1810f1556bcSAlexander Aring 1820f1556bcSAlexander Aring int mac802154_add_key(struct net_device *dev, 1830f1556bcSAlexander Aring const struct ieee802154_llsec_key_id *id, 1840f1556bcSAlexander Aring const struct ieee802154_llsec_key *key); 1850f1556bcSAlexander Aring int mac802154_del_key(struct net_device *dev, 1860f1556bcSAlexander Aring const struct ieee802154_llsec_key_id *id); 1870f1556bcSAlexander Aring 1880f1556bcSAlexander Aring int mac802154_add_dev(struct net_device *dev, 1890f1556bcSAlexander Aring const struct ieee802154_llsec_device *llsec_dev); 1900f1556bcSAlexander Aring int mac802154_del_dev(struct net_device *dev, __le64 dev_addr); 1910f1556bcSAlexander Aring 1920f1556bcSAlexander Aring int mac802154_add_devkey(struct net_device *dev, 1930f1556bcSAlexander Aring __le64 device_addr, 1940f1556bcSAlexander Aring const struct ieee802154_llsec_device_key *key); 1950f1556bcSAlexander Aring int mac802154_del_devkey(struct net_device *dev, 1960f1556bcSAlexander Aring __le64 device_addr, 1970f1556bcSAlexander Aring const struct ieee802154_llsec_device_key *key); 1980f1556bcSAlexander Aring 1990f1556bcSAlexander Aring int mac802154_add_seclevel(struct net_device *dev, 2000f1556bcSAlexander Aring const struct ieee802154_llsec_seclevel *sl); 2010f1556bcSAlexander Aring int mac802154_del_seclevel(struct net_device *dev, 2020f1556bcSAlexander Aring const struct ieee802154_llsec_seclevel *sl); 2030f1556bcSAlexander Aring 2040f1556bcSAlexander Aring void mac802154_lock_table(struct net_device *dev); 2050f1556bcSAlexander Aring void mac802154_get_table(struct net_device *dev, 2060f1556bcSAlexander Aring struct ieee802154_llsec_table **t); 2070f1556bcSAlexander Aring void mac802154_unlock_table(struct net_device *dev); 2080f1556bcSAlexander Aring 209d77b4852SAlexander Aring int mac802154_wpan_update_llsec(struct net_device *dev); 210d77b4852SAlexander Aring 211be4fd8e5SAlexander Aring /* interface handling */ 212be4fd8e5SAlexander Aring int ieee802154_iface_init(void); 213be4fd8e5SAlexander Aring void ieee802154_iface_exit(void); 214b210b187SAlexander Aring void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata); 215986a8abfSAlexander Aring struct net_device * 216986a8abfSAlexander Aring ieee802154_if_add(struct ieee802154_local *local, const char *name, 2175b4a1039SVarka Bhadram unsigned char name_assign_type, enum nl802154_iftype type, 2185b4a1039SVarka Bhadram __le64 extended_addr); 219592dfbfcSAlexander Aring void ieee802154_remove_interfaces(struct ieee802154_local *local); 220c4227c8aSAlexander Aring void ieee802154_stop_device(struct ieee802154_local *local); 2214a9a816aSAlexander Aring 2220f1556bcSAlexander Aring #endif /* __IEEE802154_I_H */ 223