xref: /openbmc/linux/net/mac802154/ieee802154_i.h (revision 5d65cae4bf6ffe29bba90f621e947922c5fb80db)
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>
230f1556bcSAlexander Aring #include <net/mac802154.h>
240f1556bcSAlexander Aring #include <net/ieee802154_netdev.h>
250f1556bcSAlexander Aring 
260f1556bcSAlexander Aring #include "llsec.h"
270f1556bcSAlexander Aring 
280f1556bcSAlexander Aring /* mac802154 device private data */
29a5e1ec53SAlexander Aring struct ieee802154_local {
305a504397SAlexander Aring 	struct ieee802154_hw hw;
3116301861SAlexander Aring 	const struct ieee802154_ops *ops;
320f1556bcSAlexander Aring 
330f1556bcSAlexander Aring 	/* ieee802154 phy */
340f1556bcSAlexander Aring 	struct wpan_phy *phy;
350f1556bcSAlexander Aring 
360f1556bcSAlexander Aring 	int open_count;
370f1556bcSAlexander Aring 
380f1556bcSAlexander Aring 	/* As in mac80211 slaves list is modified:
390f1556bcSAlexander Aring 	 * 1) under the RTNL
400f1556bcSAlexander Aring 	 * 2) protected by slaves_mtx;
410f1556bcSAlexander Aring 	 * 3) in an RCU manner
420f1556bcSAlexander Aring 	 *
430f1556bcSAlexander Aring 	 * So atomic readers can use any of this protection methods.
440f1556bcSAlexander Aring 	 */
45d98be45bSAlexander Aring 	struct list_head	interfaces;
46d98be45bSAlexander Aring 	struct mutex		iflist_mtx;
470f1556bcSAlexander Aring 
480f1556bcSAlexander Aring 	/* This one is used for scanning and other jobs not to be interfered
490f1556bcSAlexander Aring 	 * with serial driver.
500f1556bcSAlexander Aring 	 */
51f7730542SAlexander Aring 	struct workqueue_struct	*workqueue;
520f1556bcSAlexander Aring 
530f1556bcSAlexander Aring 	/* SoftMAC device is registered and running. One can add subinterfaces.
540f1556bcSAlexander Aring 	 * This flag should be modified under slaves_mtx and RTNL, so you can
550f1556bcSAlexander Aring 	 * read them using any of protection methods.
560f1556bcSAlexander Aring 	 */
57*5d65cae4SAlexander Aring 	bool started;
58c5c47e67SAlexander Aring 
59c5c47e67SAlexander Aring 	struct tasklet_struct tasklet;
60c5c47e67SAlexander Aring 	struct sk_buff_head skb_queue;
610f1556bcSAlexander Aring };
620f1556bcSAlexander Aring 
630f1556bcSAlexander Aring #define	MAC802154_DEVICE_STOPPED	0x00
640f1556bcSAlexander Aring #define MAC802154_DEVICE_RUN		0x01
650f1556bcSAlexander Aring 
66c5c47e67SAlexander Aring enum {
67c5c47e67SAlexander Aring 	IEEE802154_RX_MSG        = 1,
68c5c47e67SAlexander Aring };
69c5c47e67SAlexander Aring 
700ea3da64SAlexander Aring enum ieee802154_sdata_state_bits {
710ea3da64SAlexander Aring 	SDATA_STATE_RUNNING,
720ea3da64SAlexander Aring };
730ea3da64SAlexander Aring 
740f1556bcSAlexander Aring /* Slave interface definition.
750f1556bcSAlexander Aring  *
760f1556bcSAlexander Aring  * Slaves represent typical network interfaces available from userspace.
770f1556bcSAlexander Aring  * Each ieee802154 device/transceiver may have several slaves and able
780f1556bcSAlexander Aring  * to be associated with several networks at the same time.
790f1556bcSAlexander Aring  */
80036562f9SAlexander Aring struct ieee802154_sub_if_data {
810f1556bcSAlexander Aring 	struct list_head list; /* the ieee802154_priv->slaves list */
820f1556bcSAlexander Aring 
8304e850feSAlexander Aring 	struct ieee802154_local *local;
840f1556bcSAlexander Aring 	struct net_device *dev;
850f1556bcSAlexander Aring 
860f1556bcSAlexander Aring 	int type;
870ea3da64SAlexander Aring 	unsigned long state;
880f1556bcSAlexander Aring 
890f1556bcSAlexander Aring 	spinlock_t mib_lock;
900f1556bcSAlexander Aring 
910f1556bcSAlexander Aring 	__le16 pan_id;
920f1556bcSAlexander Aring 	__le16 short_addr;
930f1556bcSAlexander Aring 	__le64 extended_addr;
940f1556bcSAlexander Aring 
950f1556bcSAlexander Aring 	u8 chan;
960f1556bcSAlexander Aring 	u8 page;
970f1556bcSAlexander Aring 
980f1556bcSAlexander Aring 	struct ieee802154_mac_params mac_params;
990f1556bcSAlexander Aring 
1000f1556bcSAlexander Aring 	/* MAC BSN field */
1010f1556bcSAlexander Aring 	u8 bsn;
1020f1556bcSAlexander Aring 	/* MAC DSN field */
1030f1556bcSAlexander Aring 	u8 dsn;
1040f1556bcSAlexander Aring 
1050f1556bcSAlexander Aring 	/* protects sec from concurrent access by netlink. access by
1060f1556bcSAlexander Aring 	 * encrypt/decrypt/header_create safe without additional protection.
1070f1556bcSAlexander Aring 	 */
1080f1556bcSAlexander Aring 	struct mutex sec_mtx;
1090f1556bcSAlexander Aring 
1100f1556bcSAlexander Aring 	struct mac802154_llsec sec;
1110f1556bcSAlexander Aring };
1120f1556bcSAlexander Aring 
1130f1556bcSAlexander Aring #define MAC802154_CHAN_NONE		0xff /* No channel is assigned */
1140f1556bcSAlexander Aring 
11560741361SAlexander Aring static inline struct ieee802154_local *
11660741361SAlexander Aring hw_to_local(struct ieee802154_hw *hw)
11760741361SAlexander Aring {
11860741361SAlexander Aring 	return container_of(hw, struct ieee802154_local, hw);
11960741361SAlexander Aring }
12060741361SAlexander Aring 
12159d19cd7SAlexander Aring static inline struct ieee802154_sub_if_data *
12259d19cd7SAlexander Aring IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
12359d19cd7SAlexander Aring {
12459d19cd7SAlexander Aring 	return netdev_priv(dev);
12559d19cd7SAlexander Aring }
12659d19cd7SAlexander Aring 
1270ea3da64SAlexander Aring static inline bool
1280ea3da64SAlexander Aring ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
1290ea3da64SAlexander Aring {
1300ea3da64SAlexander Aring 	return test_bit(SDATA_STATE_RUNNING, &sdata->state);
1310ea3da64SAlexander Aring }
1320ea3da64SAlexander Aring 
1330f1556bcSAlexander Aring extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced;
1340f1556bcSAlexander Aring extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
1350f1556bcSAlexander Aring 
1360f1556bcSAlexander Aring void mac802154_monitor_setup(struct net_device *dev);
137e5e584fcSAlexander Aring netdev_tx_t
138e5e584fcSAlexander Aring ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
1390f1556bcSAlexander Aring 
1400f1556bcSAlexander Aring void mac802154_wpan_setup(struct net_device *dev);
141e5e584fcSAlexander Aring netdev_tx_t
142e5e584fcSAlexander Aring ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
1430f1556bcSAlexander Aring 
1440f1556bcSAlexander Aring /* MIB callbacks */
1450f1556bcSAlexander Aring void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val);
1460f1556bcSAlexander Aring __le16 mac802154_dev_get_short_addr(const struct net_device *dev);
1470f1556bcSAlexander Aring void mac802154_dev_set_ieee_addr(struct net_device *dev);
1480f1556bcSAlexander Aring __le16 mac802154_dev_get_pan_id(const struct net_device *dev);
1490f1556bcSAlexander Aring void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val);
1500f1556bcSAlexander Aring void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
1510f1556bcSAlexander Aring u8 mac802154_dev_get_dsn(const struct net_device *dev);
1520f1556bcSAlexander Aring 
1530f1556bcSAlexander Aring int mac802154_set_mac_params(struct net_device *dev,
1540f1556bcSAlexander Aring 			     const struct ieee802154_mac_params *params);
1550f1556bcSAlexander Aring void mac802154_get_mac_params(struct net_device *dev,
1560f1556bcSAlexander Aring 			      struct ieee802154_mac_params *params);
1570f1556bcSAlexander Aring 
1580f1556bcSAlexander Aring int mac802154_get_params(struct net_device *dev,
1590f1556bcSAlexander Aring 			 struct ieee802154_llsec_params *params);
1600f1556bcSAlexander Aring int mac802154_set_params(struct net_device *dev,
1610f1556bcSAlexander Aring 			 const struct ieee802154_llsec_params *params,
1620f1556bcSAlexander Aring 			 int changed);
1630f1556bcSAlexander Aring 
1640f1556bcSAlexander Aring int mac802154_add_key(struct net_device *dev,
1650f1556bcSAlexander Aring 		      const struct ieee802154_llsec_key_id *id,
1660f1556bcSAlexander Aring 		      const struct ieee802154_llsec_key *key);
1670f1556bcSAlexander Aring int mac802154_del_key(struct net_device *dev,
1680f1556bcSAlexander Aring 		      const struct ieee802154_llsec_key_id *id);
1690f1556bcSAlexander Aring 
1700f1556bcSAlexander Aring int mac802154_add_dev(struct net_device *dev,
1710f1556bcSAlexander Aring 		      const struct ieee802154_llsec_device *llsec_dev);
1720f1556bcSAlexander Aring int mac802154_del_dev(struct net_device *dev, __le64 dev_addr);
1730f1556bcSAlexander Aring 
1740f1556bcSAlexander Aring int mac802154_add_devkey(struct net_device *dev,
1750f1556bcSAlexander Aring 			 __le64 device_addr,
1760f1556bcSAlexander Aring 			 const struct ieee802154_llsec_device_key *key);
1770f1556bcSAlexander Aring int mac802154_del_devkey(struct net_device *dev,
1780f1556bcSAlexander Aring 			 __le64 device_addr,
1790f1556bcSAlexander Aring 			 const struct ieee802154_llsec_device_key *key);
1800f1556bcSAlexander Aring 
1810f1556bcSAlexander Aring int mac802154_add_seclevel(struct net_device *dev,
1820f1556bcSAlexander Aring 			   const struct ieee802154_llsec_seclevel *sl);
1830f1556bcSAlexander Aring int mac802154_del_seclevel(struct net_device *dev,
1840f1556bcSAlexander Aring 			   const struct ieee802154_llsec_seclevel *sl);
1850f1556bcSAlexander Aring 
1860f1556bcSAlexander Aring void mac802154_lock_table(struct net_device *dev);
1870f1556bcSAlexander Aring void mac802154_get_table(struct net_device *dev,
1880f1556bcSAlexander Aring 			 struct ieee802154_llsec_table **t);
1890f1556bcSAlexander Aring void mac802154_unlock_table(struct net_device *dev);
1900f1556bcSAlexander Aring 
1910f1556bcSAlexander Aring #endif /* __IEEE802154_I_H */
192