xref: /openbmc/linux/net/mac802154/ieee802154_i.h (revision 282ccf6efb7c5d75b0283b66ed487957163ce8fe)
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 
22*282ccf6eSFlorian Westphal #include <linux/interrupt.h>
230f1556bcSAlexander Aring #include <linux/mutex.h>
2461f2dcbaSAlexander Aring #include <linux/hrtimer.h>
25d5ae67baSAlexander Aring #include <net/cfg802154.h>
260f1556bcSAlexander Aring #include <net/mac802154.h>
27944742a3SAlexander Aring #include <net/nl802154.h>
280f1556bcSAlexander Aring #include <net/ieee802154_netdev.h>
290f1556bcSAlexander Aring 
300f1556bcSAlexander Aring #include "llsec.h"
310f1556bcSAlexander Aring 
320f1556bcSAlexander Aring /* mac802154 device private data */
33a5e1ec53SAlexander Aring struct ieee802154_local {
345a504397SAlexander Aring 	struct ieee802154_hw hw;
3516301861SAlexander Aring 	const struct ieee802154_ops *ops;
360f1556bcSAlexander Aring 
370f1556bcSAlexander Aring 	/* ieee802154 phy */
380f1556bcSAlexander Aring 	struct wpan_phy *phy;
390f1556bcSAlexander Aring 
400f1556bcSAlexander Aring 	int open_count;
410f1556bcSAlexander Aring 
420f1556bcSAlexander Aring 	/* As in mac80211 slaves list is modified:
430f1556bcSAlexander Aring 	 * 1) under the RTNL
440f1556bcSAlexander Aring 	 * 2) protected by slaves_mtx;
450f1556bcSAlexander Aring 	 * 3) in an RCU manner
460f1556bcSAlexander Aring 	 *
470f1556bcSAlexander Aring 	 * So atomic readers can use any of this protection methods.
480f1556bcSAlexander Aring 	 */
49d98be45bSAlexander Aring 	struct list_head	interfaces;
50d98be45bSAlexander Aring 	struct mutex		iflist_mtx;
510f1556bcSAlexander Aring 
520f1556bcSAlexander Aring 	/* This one is used for scanning and other jobs not to be interfered
530f1556bcSAlexander Aring 	 * with serial driver.
540f1556bcSAlexander Aring 	 */
55f7730542SAlexander Aring 	struct workqueue_struct	*workqueue;
560f1556bcSAlexander Aring 
5761f2dcbaSAlexander Aring 	struct hrtimer ifs_timer;
5861f2dcbaSAlexander Aring 
595d65cae4SAlexander Aring 	bool started;
603cf24cf8SAlexander Aring 	bool suspended;
61c5c47e67SAlexander Aring 
62c5c47e67SAlexander Aring 	struct tasklet_struct tasklet;
63c5c47e67SAlexander Aring 	struct sk_buff_head skb_queue;
64c22ff7b4SLennert Buytenhek 
65c22ff7b4SLennert Buytenhek 	struct sk_buff *tx_skb;
66c22ff7b4SLennert Buytenhek 	struct work_struct tx_work;
670f1556bcSAlexander Aring };
680f1556bcSAlexander Aring 
69c5c47e67SAlexander Aring enum {
70c5c47e67SAlexander Aring 	IEEE802154_RX_MSG        = 1,
71c5c47e67SAlexander Aring };
72c5c47e67SAlexander Aring 
730ea3da64SAlexander Aring enum ieee802154_sdata_state_bits {
740ea3da64SAlexander Aring 	SDATA_STATE_RUNNING,
750ea3da64SAlexander Aring };
760ea3da64SAlexander Aring 
770f1556bcSAlexander Aring /* Slave interface definition.
780f1556bcSAlexander Aring  *
790f1556bcSAlexander Aring  * Slaves represent typical network interfaces available from userspace.
800f1556bcSAlexander Aring  * Each ieee802154 device/transceiver may have several slaves and able
810f1556bcSAlexander Aring  * to be associated with several networks at the same time.
820f1556bcSAlexander Aring  */
83036562f9SAlexander Aring struct ieee802154_sub_if_data {
840f1556bcSAlexander Aring 	struct list_head list; /* the ieee802154_priv->slaves list */
850f1556bcSAlexander Aring 
86d5ae67baSAlexander Aring 	struct wpan_dev wpan_dev;
87d5ae67baSAlexander Aring 
8804e850feSAlexander Aring 	struct ieee802154_local *local;
890f1556bcSAlexander Aring 	struct net_device *dev;
900f1556bcSAlexander Aring 
910ea3da64SAlexander Aring 	unsigned long state;
92d5ae67baSAlexander Aring 	char name[IFNAMSIZ];
930f1556bcSAlexander Aring 
940f1556bcSAlexander Aring 	/* protects sec from concurrent access by netlink. access by
950f1556bcSAlexander Aring 	 * encrypt/decrypt/header_create safe without additional protection.
960f1556bcSAlexander Aring 	 */
970f1556bcSAlexander Aring 	struct mutex sec_mtx;
980f1556bcSAlexander Aring 
990f1556bcSAlexander Aring 	struct mac802154_llsec sec;
1000f1556bcSAlexander Aring };
1010f1556bcSAlexander Aring 
1026322d50dSAlexander Aring /* utility functions/constants */
1036322d50dSAlexander Aring extern const void *const mac802154_wpan_phy_privid; /*  for wpan_phy privid */
1046322d50dSAlexander Aring 
10560741361SAlexander Aring static inline struct ieee802154_local *
10660741361SAlexander Aring hw_to_local(struct ieee802154_hw *hw)
10760741361SAlexander Aring {
10860741361SAlexander Aring 	return container_of(hw, struct ieee802154_local, hw);
10960741361SAlexander Aring }
11060741361SAlexander Aring 
11159d19cd7SAlexander Aring static inline struct ieee802154_sub_if_data *
11259d19cd7SAlexander Aring IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
11359d19cd7SAlexander Aring {
11459d19cd7SAlexander Aring 	return netdev_priv(dev);
11559d19cd7SAlexander Aring }
11659d19cd7SAlexander Aring 
117b821ecd4SAlexander Aring static inline struct ieee802154_sub_if_data *
118b821ecd4SAlexander Aring IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev)
119b821ecd4SAlexander Aring {
120b821ecd4SAlexander Aring 	return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev);
121b821ecd4SAlexander Aring }
122b821ecd4SAlexander Aring 
1230ea3da64SAlexander Aring static inline bool
1240ea3da64SAlexander Aring ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
1250ea3da64SAlexander Aring {
1260ea3da64SAlexander Aring 	return test_bit(SDATA_STATE_RUNNING, &sdata->state);
1270ea3da64SAlexander Aring }
1280ea3da64SAlexander Aring 
1290f1556bcSAlexander Aring extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
1300f1556bcSAlexander Aring 
131d10270ceSVarka Bhadram void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb);
132c22ff7b4SLennert Buytenhek void ieee802154_xmit_worker(struct work_struct *work);
133e5e584fcSAlexander Aring netdev_tx_t
134e5e584fcSAlexander Aring ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
135e5e584fcSAlexander Aring netdev_tx_t
136e5e584fcSAlexander Aring ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
13761f2dcbaSAlexander Aring enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
1380f1556bcSAlexander Aring 
1390f1556bcSAlexander Aring /* MIB callbacks */
1400f1556bcSAlexander Aring void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
1410f1556bcSAlexander Aring 
1420f1556bcSAlexander Aring int mac802154_get_params(struct net_device *dev,
1430f1556bcSAlexander Aring 			 struct ieee802154_llsec_params *params);
1440f1556bcSAlexander Aring int mac802154_set_params(struct net_device *dev,
1450f1556bcSAlexander Aring 			 const struct ieee802154_llsec_params *params,
1460f1556bcSAlexander Aring 			 int changed);
1470f1556bcSAlexander Aring 
1480f1556bcSAlexander Aring int mac802154_add_key(struct net_device *dev,
1490f1556bcSAlexander Aring 		      const struct ieee802154_llsec_key_id *id,
1500f1556bcSAlexander Aring 		      const struct ieee802154_llsec_key *key);
1510f1556bcSAlexander Aring int mac802154_del_key(struct net_device *dev,
1520f1556bcSAlexander Aring 		      const struct ieee802154_llsec_key_id *id);
1530f1556bcSAlexander Aring 
1540f1556bcSAlexander Aring int mac802154_add_dev(struct net_device *dev,
1550f1556bcSAlexander Aring 		      const struct ieee802154_llsec_device *llsec_dev);
1560f1556bcSAlexander Aring int mac802154_del_dev(struct net_device *dev, __le64 dev_addr);
1570f1556bcSAlexander Aring 
1580f1556bcSAlexander Aring int mac802154_add_devkey(struct net_device *dev,
1590f1556bcSAlexander Aring 			 __le64 device_addr,
1600f1556bcSAlexander Aring 			 const struct ieee802154_llsec_device_key *key);
1610f1556bcSAlexander Aring int mac802154_del_devkey(struct net_device *dev,
1620f1556bcSAlexander Aring 			 __le64 device_addr,
1630f1556bcSAlexander Aring 			 const struct ieee802154_llsec_device_key *key);
1640f1556bcSAlexander Aring 
1650f1556bcSAlexander Aring int mac802154_add_seclevel(struct net_device *dev,
1660f1556bcSAlexander Aring 			   const struct ieee802154_llsec_seclevel *sl);
1670f1556bcSAlexander Aring int mac802154_del_seclevel(struct net_device *dev,
1680f1556bcSAlexander Aring 			   const struct ieee802154_llsec_seclevel *sl);
1690f1556bcSAlexander Aring 
1700f1556bcSAlexander Aring void mac802154_lock_table(struct net_device *dev);
1710f1556bcSAlexander Aring void mac802154_get_table(struct net_device *dev,
1720f1556bcSAlexander Aring 			 struct ieee802154_llsec_table **t);
1730f1556bcSAlexander Aring void mac802154_unlock_table(struct net_device *dev);
1740f1556bcSAlexander Aring 
175d77b4852SAlexander Aring int mac802154_wpan_update_llsec(struct net_device *dev);
176d77b4852SAlexander Aring 
177be4fd8e5SAlexander Aring /* interface handling */
178be4fd8e5SAlexander Aring int ieee802154_iface_init(void);
179be4fd8e5SAlexander Aring void ieee802154_iface_exit(void);
180b210b187SAlexander Aring void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
181986a8abfSAlexander Aring struct net_device *
182986a8abfSAlexander Aring ieee802154_if_add(struct ieee802154_local *local, const char *name,
1835b4a1039SVarka Bhadram 		  unsigned char name_assign_type, enum nl802154_iftype type,
1845b4a1039SVarka Bhadram 		  __le64 extended_addr);
185592dfbfcSAlexander Aring void ieee802154_remove_interfaces(struct ieee802154_local *local);
186c4227c8aSAlexander Aring void ieee802154_stop_device(struct ieee802154_local *local);
1874a9a816aSAlexander Aring 
1880f1556bcSAlexander Aring #endif /* __IEEE802154_I_H */
189