10f1556bcSAlexander Aring /* 20f1556bcSAlexander Aring * Copyright (C) 2007-2012 Siemens AG 30f1556bcSAlexander Aring * 40f1556bcSAlexander Aring * This program is free software; you can redistribute it and/or modify 50f1556bcSAlexander Aring * it under the terms of the GNU General Public License version 2 60f1556bcSAlexander Aring * as published by the Free Software Foundation. 70f1556bcSAlexander Aring * 80f1556bcSAlexander Aring * This program is distributed in the hope that it will be useful, 90f1556bcSAlexander Aring * but WITHOUT ANY WARRANTY; without even the implied warranty of 100f1556bcSAlexander Aring * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 110f1556bcSAlexander Aring * GNU General Public License for more details. 120f1556bcSAlexander Aring * 130f1556bcSAlexander Aring * Written by: 140f1556bcSAlexander Aring * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 150f1556bcSAlexander Aring * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 160f1556bcSAlexander Aring * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 170f1556bcSAlexander Aring * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 180f1556bcSAlexander Aring */ 190f1556bcSAlexander Aring #ifndef __IEEE802154_I_H 200f1556bcSAlexander Aring #define __IEEE802154_I_H 210f1556bcSAlexander Aring 220f1556bcSAlexander Aring #include <linux/mutex.h> 23d5ae67baSAlexander Aring #include <net/cfg802154.h> 240f1556bcSAlexander Aring #include <net/mac802154.h> 250f1556bcSAlexander Aring #include <net/ieee802154_netdev.h> 260f1556bcSAlexander Aring 270f1556bcSAlexander Aring #include "llsec.h" 280f1556bcSAlexander Aring 290f1556bcSAlexander Aring /* mac802154 device private data */ 30a5e1ec53SAlexander Aring struct ieee802154_local { 315a504397SAlexander Aring struct ieee802154_hw hw; 3216301861SAlexander Aring const struct ieee802154_ops *ops; 330f1556bcSAlexander Aring 340f1556bcSAlexander Aring /* ieee802154 phy */ 350f1556bcSAlexander Aring struct wpan_phy *phy; 360f1556bcSAlexander Aring 370f1556bcSAlexander Aring int open_count; 380f1556bcSAlexander Aring 390f1556bcSAlexander Aring /* As in mac80211 slaves list is modified: 400f1556bcSAlexander Aring * 1) under the RTNL 410f1556bcSAlexander Aring * 2) protected by slaves_mtx; 420f1556bcSAlexander Aring * 3) in an RCU manner 430f1556bcSAlexander Aring * 440f1556bcSAlexander Aring * So atomic readers can use any of this protection methods. 450f1556bcSAlexander Aring */ 46d98be45bSAlexander Aring struct list_head interfaces; 47d98be45bSAlexander Aring struct mutex iflist_mtx; 480f1556bcSAlexander Aring 490f1556bcSAlexander Aring /* This one is used for scanning and other jobs not to be interfered 500f1556bcSAlexander Aring * with serial driver. 510f1556bcSAlexander Aring */ 52f7730542SAlexander Aring struct workqueue_struct *workqueue; 530f1556bcSAlexander Aring 545d65cae4SAlexander Aring bool started; 55c5c47e67SAlexander Aring 56c5c47e67SAlexander Aring struct tasklet_struct tasklet; 57c5c47e67SAlexander Aring struct sk_buff_head skb_queue; 580f1556bcSAlexander Aring }; 590f1556bcSAlexander Aring 60c5c47e67SAlexander Aring enum { 61c5c47e67SAlexander Aring IEEE802154_RX_MSG = 1, 62c5c47e67SAlexander Aring }; 63c5c47e67SAlexander Aring 640ea3da64SAlexander Aring enum ieee802154_sdata_state_bits { 650ea3da64SAlexander Aring SDATA_STATE_RUNNING, 660ea3da64SAlexander Aring }; 670ea3da64SAlexander Aring 680f1556bcSAlexander Aring /* Slave interface definition. 690f1556bcSAlexander Aring * 700f1556bcSAlexander Aring * Slaves represent typical network interfaces available from userspace. 710f1556bcSAlexander Aring * Each ieee802154 device/transceiver may have several slaves and able 720f1556bcSAlexander Aring * to be associated with several networks at the same time. 730f1556bcSAlexander Aring */ 74036562f9SAlexander Aring struct ieee802154_sub_if_data { 750f1556bcSAlexander Aring struct list_head list; /* the ieee802154_priv->slaves list */ 760f1556bcSAlexander Aring 77d5ae67baSAlexander Aring struct wpan_dev wpan_dev; 78d5ae67baSAlexander Aring 7904e850feSAlexander Aring struct ieee802154_local *local; 800f1556bcSAlexander Aring struct net_device *dev; 810f1556bcSAlexander Aring 820ea3da64SAlexander Aring unsigned long state; 83d5ae67baSAlexander Aring char name[IFNAMSIZ]; 840f1556bcSAlexander Aring 850f1556bcSAlexander Aring spinlock_t mib_lock; 860f1556bcSAlexander Aring 870f1556bcSAlexander Aring /* protects sec from concurrent access by netlink. access by 880f1556bcSAlexander Aring * encrypt/decrypt/header_create safe without additional protection. 890f1556bcSAlexander Aring */ 900f1556bcSAlexander Aring struct mutex sec_mtx; 910f1556bcSAlexander Aring 920f1556bcSAlexander Aring struct mac802154_llsec sec; 937c118c1aSAlexander Aring /* must be last, dynamically sized area in this! */ 947c118c1aSAlexander Aring struct ieee802154_vif vif; 950f1556bcSAlexander Aring }; 960f1556bcSAlexander Aring 970f1556bcSAlexander Aring #define MAC802154_CHAN_NONE 0xff /* No channel is assigned */ 980f1556bcSAlexander 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 1110ea3da64SAlexander Aring static inline bool 1120ea3da64SAlexander Aring ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata) 1130ea3da64SAlexander Aring { 1140ea3da64SAlexander Aring return test_bit(SDATA_STATE_RUNNING, &sdata->state); 1150ea3da64SAlexander Aring } 1160ea3da64SAlexander Aring 1170f1556bcSAlexander Aring extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced; 1180f1556bcSAlexander Aring extern struct ieee802154_mlme_ops mac802154_mlme_wpan; 1190f1556bcSAlexander Aring 1200f1556bcSAlexander Aring void mac802154_monitor_setup(struct net_device *dev); 121e5e584fcSAlexander Aring netdev_tx_t 122e5e584fcSAlexander Aring ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev); 1230f1556bcSAlexander Aring 1240f1556bcSAlexander Aring void mac802154_wpan_setup(struct net_device *dev); 125e5e584fcSAlexander Aring netdev_tx_t 126e5e584fcSAlexander Aring ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev); 1270f1556bcSAlexander Aring 1280f1556bcSAlexander Aring /* MIB callbacks */ 1290f1556bcSAlexander Aring void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val); 1300f1556bcSAlexander Aring __le16 mac802154_dev_get_short_addr(const struct net_device *dev); 1310f1556bcSAlexander Aring __le16 mac802154_dev_get_pan_id(const struct net_device *dev); 1320f1556bcSAlexander Aring void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val); 1330f1556bcSAlexander Aring void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan); 1340f1556bcSAlexander Aring u8 mac802154_dev_get_dsn(const struct net_device *dev); 1350f1556bcSAlexander Aring 1360f1556bcSAlexander Aring int mac802154_get_params(struct net_device *dev, 1370f1556bcSAlexander Aring struct ieee802154_llsec_params *params); 1380f1556bcSAlexander Aring int mac802154_set_params(struct net_device *dev, 1390f1556bcSAlexander Aring const struct ieee802154_llsec_params *params, 1400f1556bcSAlexander Aring int changed); 1410f1556bcSAlexander Aring 1420f1556bcSAlexander Aring int mac802154_add_key(struct net_device *dev, 1430f1556bcSAlexander Aring const struct ieee802154_llsec_key_id *id, 1440f1556bcSAlexander Aring const struct ieee802154_llsec_key *key); 1450f1556bcSAlexander Aring int mac802154_del_key(struct net_device *dev, 1460f1556bcSAlexander Aring const struct ieee802154_llsec_key_id *id); 1470f1556bcSAlexander Aring 1480f1556bcSAlexander Aring int mac802154_add_dev(struct net_device *dev, 1490f1556bcSAlexander Aring const struct ieee802154_llsec_device *llsec_dev); 1500f1556bcSAlexander Aring int mac802154_del_dev(struct net_device *dev, __le64 dev_addr); 1510f1556bcSAlexander Aring 1520f1556bcSAlexander Aring int mac802154_add_devkey(struct net_device *dev, 1530f1556bcSAlexander Aring __le64 device_addr, 1540f1556bcSAlexander Aring const struct ieee802154_llsec_device_key *key); 1550f1556bcSAlexander Aring int mac802154_del_devkey(struct net_device *dev, 1560f1556bcSAlexander Aring __le64 device_addr, 1570f1556bcSAlexander Aring const struct ieee802154_llsec_device_key *key); 1580f1556bcSAlexander Aring 1590f1556bcSAlexander Aring int mac802154_add_seclevel(struct net_device *dev, 1600f1556bcSAlexander Aring const struct ieee802154_llsec_seclevel *sl); 1610f1556bcSAlexander Aring int mac802154_del_seclevel(struct net_device *dev, 1620f1556bcSAlexander Aring const struct ieee802154_llsec_seclevel *sl); 1630f1556bcSAlexander Aring 1640f1556bcSAlexander Aring void mac802154_lock_table(struct net_device *dev); 1650f1556bcSAlexander Aring void mac802154_get_table(struct net_device *dev, 1660f1556bcSAlexander Aring struct ieee802154_llsec_table **t); 1670f1556bcSAlexander Aring void mac802154_unlock_table(struct net_device *dev); 1680f1556bcSAlexander Aring 1694a9a816aSAlexander Aring struct net_device * 1704a9a816aSAlexander Aring mac802154_add_iface(struct wpan_phy *phy, const char *name, int type); 171b210b187SAlexander Aring void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata); 172986a8abfSAlexander Aring struct net_device * 173986a8abfSAlexander Aring ieee802154_if_add(struct ieee802154_local *local, const char *name, 174986a8abfSAlexander Aring struct wpan_dev **new_wpan_dev, int type); 175*592dfbfcSAlexander Aring void ieee802154_remove_interfaces(struct ieee802154_local *local); 1764a9a816aSAlexander Aring 1770f1556bcSAlexander Aring #endif /* __IEEE802154_I_H */ 178