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 29ac8037c3SAlexander Aring /* hardware address filter */ 30ac8037c3SAlexander Aring struct ieee802154_hw_addr_filt addr_filt; 310f1556bcSAlexander Aring /* ieee802154 phy */ 320f1556bcSAlexander Aring struct wpan_phy *phy; 330f1556bcSAlexander Aring 340f1556bcSAlexander Aring int open_count; 350f1556bcSAlexander Aring 360f1556bcSAlexander Aring /* As in mac80211 slaves list is modified: 370f1556bcSAlexander Aring * 1) under the RTNL 380f1556bcSAlexander Aring * 2) protected by slaves_mtx; 390f1556bcSAlexander Aring * 3) in an RCU manner 400f1556bcSAlexander Aring * 410f1556bcSAlexander Aring * So atomic readers can use any of this protection methods. 420f1556bcSAlexander Aring */ 43d98be45bSAlexander Aring struct list_head interfaces; 44d98be45bSAlexander Aring struct mutex iflist_mtx; 450f1556bcSAlexander Aring 460f1556bcSAlexander Aring /* This one is used for scanning and other jobs not to be interfered 470f1556bcSAlexander Aring * with serial driver. 480f1556bcSAlexander Aring */ 49f7730542SAlexander Aring struct workqueue_struct *workqueue; 500f1556bcSAlexander Aring 5161f2dcbaSAlexander Aring struct hrtimer ifs_timer; 5261f2dcbaSAlexander Aring 535d65cae4SAlexander Aring bool started; 543cf24cf8SAlexander Aring bool suspended; 55c5c47e67SAlexander Aring 56c5c47e67SAlexander Aring struct tasklet_struct tasklet; 57c5c47e67SAlexander Aring struct sk_buff_head skb_queue; 58c22ff7b4SLennert Buytenhek 59c22ff7b4SLennert Buytenhek struct sk_buff *tx_skb; 60983a974bSMiquel Raynal struct work_struct sync_tx_work; 61337e2f86SMiquel Raynal /* A negative Linux error code or a null/positive MLME error status */ 62337e2f86SMiquel Raynal int tx_result; 630f1556bcSAlexander Aring }; 640f1556bcSAlexander Aring 65c5c47e67SAlexander Aring enum { 66c5c47e67SAlexander Aring IEEE802154_RX_MSG = 1, 67c5c47e67SAlexander Aring }; 68c5c47e67SAlexander Aring 690ea3da64SAlexander Aring enum ieee802154_sdata_state_bits { 700ea3da64SAlexander Aring SDATA_STATE_RUNNING, 710ea3da64SAlexander Aring }; 720ea3da64SAlexander Aring 730f1556bcSAlexander Aring /* Slave interface definition. 740f1556bcSAlexander Aring * 750f1556bcSAlexander Aring * Slaves represent typical network interfaces available from userspace. 760f1556bcSAlexander Aring * Each ieee802154 device/transceiver may have several slaves and able 770f1556bcSAlexander Aring * to be associated with several networks at the same time. 780f1556bcSAlexander Aring */ 79036562f9SAlexander Aring struct ieee802154_sub_if_data { 800f1556bcSAlexander Aring struct list_head list; /* the ieee802154_priv->slaves list */ 810f1556bcSAlexander Aring 82d5ae67baSAlexander Aring struct wpan_dev wpan_dev; 83d5ae67baSAlexander Aring 8404e850feSAlexander Aring struct ieee802154_local *local; 850f1556bcSAlexander Aring struct net_device *dev; 860f1556bcSAlexander Aring 87ac8037c3SAlexander Aring /* Each interface starts and works in nominal state at a given filtering 88ac8037c3SAlexander Aring * level given by iface_default_filtering, which is set once for all at 89ac8037c3SAlexander Aring * the interface creation and should not evolve over time. For some MAC 90ac8037c3SAlexander Aring * operations however, the filtering level may change temporarily, as 91ac8037c3SAlexander Aring * reflected in the required_filtering field. The actual filtering at 92ac8037c3SAlexander Aring * the PHY level may be different and is shown in struct wpan_phy. 93ac8037c3SAlexander Aring */ 94ac8037c3SAlexander Aring enum ieee802154_filtering_level iface_default_filtering; 95ac8037c3SAlexander Aring enum ieee802154_filtering_level required_filtering; 96ac8037c3SAlexander Aring 970ea3da64SAlexander Aring unsigned long state; 98d5ae67baSAlexander Aring char name[IFNAMSIZ]; 990f1556bcSAlexander Aring 1000f1556bcSAlexander Aring /* protects sec from concurrent access by netlink. access by 1010f1556bcSAlexander Aring * encrypt/decrypt/header_create safe without additional protection. 1020f1556bcSAlexander Aring */ 1030f1556bcSAlexander Aring struct mutex sec_mtx; 1040f1556bcSAlexander Aring 1050f1556bcSAlexander Aring struct mac802154_llsec sec; 1060f1556bcSAlexander Aring }; 1070f1556bcSAlexander Aring 1086322d50dSAlexander Aring /* utility functions/constants */ 1096322d50dSAlexander Aring extern const void *const mac802154_wpan_phy_privid; /* for wpan_phy privid */ 1106322d50dSAlexander Aring 11160741361SAlexander Aring static inline struct ieee802154_local * 11260741361SAlexander Aring hw_to_local(struct ieee802154_hw *hw) 11360741361SAlexander Aring { 11460741361SAlexander Aring return container_of(hw, struct ieee802154_local, hw); 11560741361SAlexander Aring } 11660741361SAlexander Aring 11759d19cd7SAlexander Aring static inline struct ieee802154_sub_if_data * 11859d19cd7SAlexander Aring IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev) 11959d19cd7SAlexander Aring { 12059d19cd7SAlexander Aring return netdev_priv(dev); 12159d19cd7SAlexander Aring } 12259d19cd7SAlexander Aring 123b821ecd4SAlexander Aring static inline struct ieee802154_sub_if_data * 124b821ecd4SAlexander Aring IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev) 125b821ecd4SAlexander Aring { 126b821ecd4SAlexander Aring return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev); 127b821ecd4SAlexander Aring } 128b821ecd4SAlexander Aring 1290ea3da64SAlexander Aring static inline bool 1300ea3da64SAlexander Aring ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata) 1310ea3da64SAlexander Aring { 1320ea3da64SAlexander Aring return test_bit(SDATA_STATE_RUNNING, &sdata->state); 1330ea3da64SAlexander Aring } 1340ea3da64SAlexander Aring 1350f1556bcSAlexander Aring extern struct ieee802154_mlme_ops mac802154_mlme_wpan; 1360f1556bcSAlexander Aring 137d10270ceSVarka Bhadram void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb); 138be8c6d86SMiquel Raynal void ieee802154_xmit_sync_worker(struct work_struct *work); 139f0feb349SMiquel Raynal int ieee802154_sync_and_hold_queue(struct ieee802154_local *local); 140ddd9ee7cSMiquel Raynal int ieee802154_mlme_op_pre(struct ieee802154_local *local); 141fbdaa5baSMiquel Raynal int ieee802154_mlme_tx(struct ieee802154_local *local, 142fbdaa5baSMiquel Raynal struct ieee802154_sub_if_data *sdata, 143fbdaa5baSMiquel Raynal struct sk_buff *skb); 144*dd180962SMiquel Raynal int ieee802154_mlme_tx_locked(struct ieee802154_local *local, 145*dd180962SMiquel Raynal struct ieee802154_sub_if_data *sdata, 146*dd180962SMiquel Raynal struct sk_buff *skb); 147ddd9ee7cSMiquel Raynal void ieee802154_mlme_op_post(struct ieee802154_local *local); 148fbdaa5baSMiquel Raynal int ieee802154_mlme_tx_one(struct ieee802154_local *local, 149fbdaa5baSMiquel Raynal struct ieee802154_sub_if_data *sdata, 150fbdaa5baSMiquel Raynal struct sk_buff *skb); 151*dd180962SMiquel Raynal int ieee802154_mlme_tx_one_locked(struct ieee802154_local *local, 152*dd180962SMiquel Raynal struct ieee802154_sub_if_data *sdata, 153*dd180962SMiquel Raynal struct sk_buff *skb); 154e5e584fcSAlexander Aring netdev_tx_t 155e5e584fcSAlexander Aring ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev); 156e5e584fcSAlexander Aring netdev_tx_t 157e5e584fcSAlexander Aring ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev); 15861f2dcbaSAlexander Aring enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer); 1590f1556bcSAlexander Aring 16020a19d1dSMiquel Raynal /** 16120a19d1dSMiquel Raynal * ieee802154_hold_queue - hold ieee802154 queue 16220a19d1dSMiquel Raynal * @local: main mac object 16320a19d1dSMiquel Raynal * 16420a19d1dSMiquel Raynal * Hold a queue by incrementing an atomic counter and requesting the netif 16520a19d1dSMiquel Raynal * queues to be stopped. The queues cannot be woken up while the counter has not 16620a19d1dSMiquel Raynal * been reset with as any ieee802154_release_queue() calls as needed. 16720a19d1dSMiquel Raynal */ 16820a19d1dSMiquel Raynal void ieee802154_hold_queue(struct ieee802154_local *local); 16920a19d1dSMiquel Raynal 17020a19d1dSMiquel Raynal /** 17120a19d1dSMiquel Raynal * ieee802154_release_queue - release ieee802154 queue 17220a19d1dSMiquel Raynal * @local: main mac object 17320a19d1dSMiquel Raynal * 17420a19d1dSMiquel Raynal * Release a queue which is held by decrementing an atomic counter and wake it 17520a19d1dSMiquel Raynal * up only if the counter reaches 0. 17620a19d1dSMiquel Raynal */ 17720a19d1dSMiquel Raynal void ieee802154_release_queue(struct ieee802154_local *local); 17820a19d1dSMiquel Raynal 179a40612f3SMiquel Raynal /** 180a40612f3SMiquel Raynal * ieee802154_disable_queue - disable ieee802154 queue 181a40612f3SMiquel Raynal * @local: main mac object 182a40612f3SMiquel Raynal * 183a40612f3SMiquel Raynal * When trying to sync the Tx queue, we cannot just stop the queue 184a40612f3SMiquel Raynal * (which is basically a bit being set without proper lock handling) 185a40612f3SMiquel Raynal * because it would be racy. We actually need to call netif_tx_disable() 186a40612f3SMiquel Raynal * instead, which is done by this helper. Restarting the queue can 187a40612f3SMiquel Raynal * however still be done with a regular wake call. 188a40612f3SMiquel Raynal */ 189a40612f3SMiquel Raynal void ieee802154_disable_queue(struct ieee802154_local *local); 190a40612f3SMiquel Raynal 1910f1556bcSAlexander Aring /* MIB callbacks */ 1920f1556bcSAlexander Aring void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); 1930f1556bcSAlexander Aring 1940f1556bcSAlexander Aring int mac802154_get_params(struct net_device *dev, 1950f1556bcSAlexander Aring struct ieee802154_llsec_params *params); 1960f1556bcSAlexander Aring int mac802154_set_params(struct net_device *dev, 1970f1556bcSAlexander Aring const struct ieee802154_llsec_params *params, 1980f1556bcSAlexander Aring int changed); 1990f1556bcSAlexander Aring 2000f1556bcSAlexander Aring int mac802154_add_key(struct net_device *dev, 2010f1556bcSAlexander Aring const struct ieee802154_llsec_key_id *id, 2020f1556bcSAlexander Aring const struct ieee802154_llsec_key *key); 2030f1556bcSAlexander Aring int mac802154_del_key(struct net_device *dev, 2040f1556bcSAlexander Aring const struct ieee802154_llsec_key_id *id); 2050f1556bcSAlexander Aring 2060f1556bcSAlexander Aring int mac802154_add_dev(struct net_device *dev, 2070f1556bcSAlexander Aring const struct ieee802154_llsec_device *llsec_dev); 2080f1556bcSAlexander Aring int mac802154_del_dev(struct net_device *dev, __le64 dev_addr); 2090f1556bcSAlexander Aring 2100f1556bcSAlexander Aring int mac802154_add_devkey(struct net_device *dev, 2110f1556bcSAlexander Aring __le64 device_addr, 2120f1556bcSAlexander Aring const struct ieee802154_llsec_device_key *key); 2130f1556bcSAlexander Aring int mac802154_del_devkey(struct net_device *dev, 2140f1556bcSAlexander Aring __le64 device_addr, 2150f1556bcSAlexander Aring const struct ieee802154_llsec_device_key *key); 2160f1556bcSAlexander Aring 2170f1556bcSAlexander Aring int mac802154_add_seclevel(struct net_device *dev, 2180f1556bcSAlexander Aring const struct ieee802154_llsec_seclevel *sl); 2190f1556bcSAlexander Aring int mac802154_del_seclevel(struct net_device *dev, 2200f1556bcSAlexander Aring const struct ieee802154_llsec_seclevel *sl); 2210f1556bcSAlexander Aring 2220f1556bcSAlexander Aring void mac802154_lock_table(struct net_device *dev); 2230f1556bcSAlexander Aring void mac802154_get_table(struct net_device *dev, 2240f1556bcSAlexander Aring struct ieee802154_llsec_table **t); 2250f1556bcSAlexander Aring void mac802154_unlock_table(struct net_device *dev); 2260f1556bcSAlexander Aring 227d77b4852SAlexander Aring int mac802154_wpan_update_llsec(struct net_device *dev); 228d77b4852SAlexander Aring 229be4fd8e5SAlexander Aring /* interface handling */ 230be4fd8e5SAlexander Aring int ieee802154_iface_init(void); 231be4fd8e5SAlexander Aring void ieee802154_iface_exit(void); 232b210b187SAlexander Aring void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata); 233986a8abfSAlexander Aring struct net_device * 234986a8abfSAlexander Aring ieee802154_if_add(struct ieee802154_local *local, const char *name, 2355b4a1039SVarka Bhadram unsigned char name_assign_type, enum nl802154_iftype type, 2365b4a1039SVarka Bhadram __le64 extended_addr); 237592dfbfcSAlexander Aring void ieee802154_remove_interfaces(struct ieee802154_local *local); 238c4227c8aSAlexander Aring void ieee802154_stop_device(struct ieee802154_local *local); 2394a9a816aSAlexander Aring 2400f1556bcSAlexander Aring #endif /* __IEEE802154_I_H */ 241