18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2007, 2008, 2009 Siemens AG
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Written by:
68c2ecf20Sopenharmony_ci * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef __NET_CFG802154_H
108c2ecf20Sopenharmony_ci#define __NET_CFG802154_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/ieee802154.h>
138c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
148c2ecf20Sopenharmony_ci#include <linux/mutex.h>
158c2ecf20Sopenharmony_ci#include <linux/bug.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <net/nl802154.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistruct wpan_phy;
208c2ecf20Sopenharmony_cistruct wpan_phy_cca;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
238c2ecf20Sopenharmony_cistruct ieee802154_llsec_device_key;
248c2ecf20Sopenharmony_cistruct ieee802154_llsec_seclevel;
258c2ecf20Sopenharmony_cistruct ieee802154_llsec_params;
268c2ecf20Sopenharmony_cistruct ieee802154_llsec_device;
278c2ecf20Sopenharmony_cistruct ieee802154_llsec_table;
288c2ecf20Sopenharmony_cistruct ieee802154_llsec_key_id;
298c2ecf20Sopenharmony_cistruct ieee802154_llsec_key;
308c2ecf20Sopenharmony_ci#endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct cfg802154_ops {
338c2ecf20Sopenharmony_ci	struct net_device * (*add_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
348c2ecf20Sopenharmony_ci							   const char *name,
358c2ecf20Sopenharmony_ci							   unsigned char name_assign_type,
368c2ecf20Sopenharmony_ci							   int type);
378c2ecf20Sopenharmony_ci	void	(*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
388c2ecf20Sopenharmony_ci					       struct net_device *dev);
398c2ecf20Sopenharmony_ci	int	(*suspend)(struct wpan_phy *wpan_phy);
408c2ecf20Sopenharmony_ci	int	(*resume)(struct wpan_phy *wpan_phy);
418c2ecf20Sopenharmony_ci	int	(*add_virtual_intf)(struct wpan_phy *wpan_phy,
428c2ecf20Sopenharmony_ci				    const char *name,
438c2ecf20Sopenharmony_ci				    unsigned char name_assign_type,
448c2ecf20Sopenharmony_ci				    enum nl802154_iftype type,
458c2ecf20Sopenharmony_ci				    __le64 extended_addr);
468c2ecf20Sopenharmony_ci	int	(*del_virtual_intf)(struct wpan_phy *wpan_phy,
478c2ecf20Sopenharmony_ci				    struct wpan_dev *wpan_dev);
488c2ecf20Sopenharmony_ci	int	(*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
498c2ecf20Sopenharmony_ci	int	(*set_cca_mode)(struct wpan_phy *wpan_phy,
508c2ecf20Sopenharmony_ci				const struct wpan_phy_cca *cca);
518c2ecf20Sopenharmony_ci	int     (*set_cca_ed_level)(struct wpan_phy *wpan_phy, s32 ed_level);
528c2ecf20Sopenharmony_ci	int     (*set_tx_power)(struct wpan_phy *wpan_phy, s32 power);
538c2ecf20Sopenharmony_ci	int	(*set_pan_id)(struct wpan_phy *wpan_phy,
548c2ecf20Sopenharmony_ci			      struct wpan_dev *wpan_dev, __le16 pan_id);
558c2ecf20Sopenharmony_ci	int	(*set_short_addr)(struct wpan_phy *wpan_phy,
568c2ecf20Sopenharmony_ci				  struct wpan_dev *wpan_dev, __le16 short_addr);
578c2ecf20Sopenharmony_ci	int	(*set_backoff_exponent)(struct wpan_phy *wpan_phy,
588c2ecf20Sopenharmony_ci					struct wpan_dev *wpan_dev, u8 min_be,
598c2ecf20Sopenharmony_ci					u8 max_be);
608c2ecf20Sopenharmony_ci	int	(*set_max_csma_backoffs)(struct wpan_phy *wpan_phy,
618c2ecf20Sopenharmony_ci					 struct wpan_dev *wpan_dev,
628c2ecf20Sopenharmony_ci					 u8 max_csma_backoffs);
638c2ecf20Sopenharmony_ci	int	(*set_max_frame_retries)(struct wpan_phy *wpan_phy,
648c2ecf20Sopenharmony_ci					 struct wpan_dev *wpan_dev,
658c2ecf20Sopenharmony_ci					 s8 max_frame_retries);
668c2ecf20Sopenharmony_ci	int	(*set_lbt_mode)(struct wpan_phy *wpan_phy,
678c2ecf20Sopenharmony_ci				struct wpan_dev *wpan_dev, bool mode);
688c2ecf20Sopenharmony_ci	int	(*set_ackreq_default)(struct wpan_phy *wpan_phy,
698c2ecf20Sopenharmony_ci				      struct wpan_dev *wpan_dev, bool ackreq);
708c2ecf20Sopenharmony_ci#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
718c2ecf20Sopenharmony_ci	void	(*get_llsec_table)(struct wpan_phy *wpan_phy,
728c2ecf20Sopenharmony_ci				   struct wpan_dev *wpan_dev,
738c2ecf20Sopenharmony_ci				   struct ieee802154_llsec_table **table);
748c2ecf20Sopenharmony_ci	void	(*lock_llsec_table)(struct wpan_phy *wpan_phy,
758c2ecf20Sopenharmony_ci				    struct wpan_dev *wpan_dev);
768c2ecf20Sopenharmony_ci	void	(*unlock_llsec_table)(struct wpan_phy *wpan_phy,
778c2ecf20Sopenharmony_ci				      struct wpan_dev *wpan_dev);
788c2ecf20Sopenharmony_ci	/* TODO remove locking/get table callbacks, this is part of the
798c2ecf20Sopenharmony_ci	 * nl802154 interface and should be accessible from ieee802154 layer.
808c2ecf20Sopenharmony_ci	 */
818c2ecf20Sopenharmony_ci	int	(*get_llsec_params)(struct wpan_phy *wpan_phy,
828c2ecf20Sopenharmony_ci				    struct wpan_dev *wpan_dev,
838c2ecf20Sopenharmony_ci				    struct ieee802154_llsec_params *params);
848c2ecf20Sopenharmony_ci	int	(*set_llsec_params)(struct wpan_phy *wpan_phy,
858c2ecf20Sopenharmony_ci				    struct wpan_dev *wpan_dev,
868c2ecf20Sopenharmony_ci				    const struct ieee802154_llsec_params *params,
878c2ecf20Sopenharmony_ci				    int changed);
888c2ecf20Sopenharmony_ci	int	(*add_llsec_key)(struct wpan_phy *wpan_phy,
898c2ecf20Sopenharmony_ci				 struct wpan_dev *wpan_dev,
908c2ecf20Sopenharmony_ci				 const struct ieee802154_llsec_key_id *id,
918c2ecf20Sopenharmony_ci				 const struct ieee802154_llsec_key *key);
928c2ecf20Sopenharmony_ci	int	(*del_llsec_key)(struct wpan_phy *wpan_phy,
938c2ecf20Sopenharmony_ci				 struct wpan_dev *wpan_dev,
948c2ecf20Sopenharmony_ci				 const struct ieee802154_llsec_key_id *id);
958c2ecf20Sopenharmony_ci	int	(*add_seclevel)(struct wpan_phy *wpan_phy,
968c2ecf20Sopenharmony_ci				 struct wpan_dev *wpan_dev,
978c2ecf20Sopenharmony_ci				 const struct ieee802154_llsec_seclevel *sl);
988c2ecf20Sopenharmony_ci	int	(*del_seclevel)(struct wpan_phy *wpan_phy,
998c2ecf20Sopenharmony_ci				 struct wpan_dev *wpan_dev,
1008c2ecf20Sopenharmony_ci				 const struct ieee802154_llsec_seclevel *sl);
1018c2ecf20Sopenharmony_ci	int	(*add_device)(struct wpan_phy *wpan_phy,
1028c2ecf20Sopenharmony_ci			      struct wpan_dev *wpan_dev,
1038c2ecf20Sopenharmony_ci			      const struct ieee802154_llsec_device *dev);
1048c2ecf20Sopenharmony_ci	int	(*del_device)(struct wpan_phy *wpan_phy,
1058c2ecf20Sopenharmony_ci			      struct wpan_dev *wpan_dev, __le64 extended_addr);
1068c2ecf20Sopenharmony_ci	int	(*add_devkey)(struct wpan_phy *wpan_phy,
1078c2ecf20Sopenharmony_ci			      struct wpan_dev *wpan_dev,
1088c2ecf20Sopenharmony_ci			      __le64 extended_addr,
1098c2ecf20Sopenharmony_ci			      const struct ieee802154_llsec_device_key *key);
1108c2ecf20Sopenharmony_ci	int	(*del_devkey)(struct wpan_phy *wpan_phy,
1118c2ecf20Sopenharmony_ci			      struct wpan_dev *wpan_dev,
1128c2ecf20Sopenharmony_ci			      __le64 extended_addr,
1138c2ecf20Sopenharmony_ci			      const struct ieee802154_llsec_device_key *key);
1148c2ecf20Sopenharmony_ci#endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic inline bool
1188c2ecf20Sopenharmony_ciwpan_phy_supported_bool(bool b, enum nl802154_supported_bool_states st)
1198c2ecf20Sopenharmony_ci{
1208c2ecf20Sopenharmony_ci	switch (st) {
1218c2ecf20Sopenharmony_ci	case NL802154_SUPPORTED_BOOL_TRUE:
1228c2ecf20Sopenharmony_ci		return b;
1238c2ecf20Sopenharmony_ci	case NL802154_SUPPORTED_BOOL_FALSE:
1248c2ecf20Sopenharmony_ci		return !b;
1258c2ecf20Sopenharmony_ci	case NL802154_SUPPORTED_BOOL_BOTH:
1268c2ecf20Sopenharmony_ci		return true;
1278c2ecf20Sopenharmony_ci	default:
1288c2ecf20Sopenharmony_ci		WARN_ON(1);
1298c2ecf20Sopenharmony_ci	}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	return false;
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistruct wpan_phy_supported {
1358c2ecf20Sopenharmony_ci	u32 channels[IEEE802154_MAX_PAGE + 1],
1368c2ecf20Sopenharmony_ci	    cca_modes, cca_opts, iftypes;
1378c2ecf20Sopenharmony_ci	enum nl802154_supported_bool_states lbt;
1388c2ecf20Sopenharmony_ci	u8 min_minbe, max_minbe, min_maxbe, max_maxbe,
1398c2ecf20Sopenharmony_ci	   min_csma_backoffs, max_csma_backoffs;
1408c2ecf20Sopenharmony_ci	s8 min_frame_retries, max_frame_retries;
1418c2ecf20Sopenharmony_ci	size_t tx_powers_size, cca_ed_levels_size;
1428c2ecf20Sopenharmony_ci	const s32 *tx_powers, *cca_ed_levels;
1438c2ecf20Sopenharmony_ci};
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistruct wpan_phy_cca {
1468c2ecf20Sopenharmony_ci	enum nl802154_cca_modes mode;
1478c2ecf20Sopenharmony_ci	enum nl802154_cca_opts opt;
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic inline bool
1518c2ecf20Sopenharmony_ciwpan_phy_cca_cmp(const struct wpan_phy_cca *a, const struct wpan_phy_cca *b)
1528c2ecf20Sopenharmony_ci{
1538c2ecf20Sopenharmony_ci	if (a->mode != b->mode)
1548c2ecf20Sopenharmony_ci		return false;
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	if (a->mode == NL802154_CCA_ENERGY_CARRIER)
1578c2ecf20Sopenharmony_ci		return a->opt == b->opt;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	return true;
1608c2ecf20Sopenharmony_ci}
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/**
1638c2ecf20Sopenharmony_ci * @WPAN_PHY_FLAG_TRANSMIT_POWER: Indicates that transceiver will support
1648c2ecf20Sopenharmony_ci *	transmit power setting.
1658c2ecf20Sopenharmony_ci * @WPAN_PHY_FLAG_CCA_ED_LEVEL: Indicates that transceiver will support cca ed
1668c2ecf20Sopenharmony_ci *	level setting.
1678c2ecf20Sopenharmony_ci * @WPAN_PHY_FLAG_CCA_MODE: Indicates that transceiver will support cca mode
1688c2ecf20Sopenharmony_ci *	setting.
1698c2ecf20Sopenharmony_ci */
1708c2ecf20Sopenharmony_cienum wpan_phy_flags {
1718c2ecf20Sopenharmony_ci	WPAN_PHY_FLAG_TXPOWER		= BIT(1),
1728c2ecf20Sopenharmony_ci	WPAN_PHY_FLAG_CCA_ED_LEVEL	= BIT(2),
1738c2ecf20Sopenharmony_ci	WPAN_PHY_FLAG_CCA_MODE		= BIT(3),
1748c2ecf20Sopenharmony_ci};
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_cistruct wpan_phy {
1778c2ecf20Sopenharmony_ci	/* If multiple wpan_phys are registered and you're handed e.g.
1788c2ecf20Sopenharmony_ci	 * a regular netdev with assigned ieee802154_ptr, you won't
1798c2ecf20Sopenharmony_ci	 * know whether it points to a wpan_phy your driver has registered
1808c2ecf20Sopenharmony_ci	 * or not. Assign this to something global to your driver to
1818c2ecf20Sopenharmony_ci	 * help determine whether you own this wpan_phy or not.
1828c2ecf20Sopenharmony_ci	 */
1838c2ecf20Sopenharmony_ci	const void *privid;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	u32 flags;
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	/*
1888c2ecf20Sopenharmony_ci	 * This is a PIB according to 802.15.4-2011.
1898c2ecf20Sopenharmony_ci	 * We do not provide timing-related variables, as they
1908c2ecf20Sopenharmony_ci	 * aren't used outside of driver
1918c2ecf20Sopenharmony_ci	 */
1928c2ecf20Sopenharmony_ci	u8 current_channel;
1938c2ecf20Sopenharmony_ci	u8 current_page;
1948c2ecf20Sopenharmony_ci	struct wpan_phy_supported supported;
1958c2ecf20Sopenharmony_ci	/* current transmit_power in mBm */
1968c2ecf20Sopenharmony_ci	s32 transmit_power;
1978c2ecf20Sopenharmony_ci	struct wpan_phy_cca cca;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	__le64 perm_extended_addr;
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	/* current cca ed threshold in mBm */
2028c2ecf20Sopenharmony_ci	s32 cca_ed_level;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	/* PHY depended MAC PIB values */
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci	/* 802.15.4 acronym: Tdsym in usec */
2078c2ecf20Sopenharmony_ci	u8 symbol_duration;
2088c2ecf20Sopenharmony_ci	/* lifs and sifs periods timing */
2098c2ecf20Sopenharmony_ci	u16 lifs_period;
2108c2ecf20Sopenharmony_ci	u16 sifs_period;
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	struct device dev;
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	/* the network namespace this phy lives in currently */
2158c2ecf20Sopenharmony_ci	possible_net_t _net;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	char priv[] __aligned(NETDEV_ALIGN);
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic inline struct net *wpan_phy_net(struct wpan_phy *wpan_phy)
2218c2ecf20Sopenharmony_ci{
2228c2ecf20Sopenharmony_ci	return read_pnet(&wpan_phy->_net);
2238c2ecf20Sopenharmony_ci}
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistatic inline void wpan_phy_net_set(struct wpan_phy *wpan_phy, struct net *net)
2268c2ecf20Sopenharmony_ci{
2278c2ecf20Sopenharmony_ci	write_pnet(&wpan_phy->_net, net);
2288c2ecf20Sopenharmony_ci}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_cistruct ieee802154_addr {
2318c2ecf20Sopenharmony_ci	u8 mode;
2328c2ecf20Sopenharmony_ci	__le16 pan_id;
2338c2ecf20Sopenharmony_ci	union {
2348c2ecf20Sopenharmony_ci		__le16 short_addr;
2358c2ecf20Sopenharmony_ci		__le64 extended_addr;
2368c2ecf20Sopenharmony_ci	};
2378c2ecf20Sopenharmony_ci};
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cistruct ieee802154_llsec_key_id {
2408c2ecf20Sopenharmony_ci	u8 mode;
2418c2ecf20Sopenharmony_ci	u8 id;
2428c2ecf20Sopenharmony_ci	union {
2438c2ecf20Sopenharmony_ci		struct ieee802154_addr device_addr;
2448c2ecf20Sopenharmony_ci		__le32 short_source;
2458c2ecf20Sopenharmony_ci		__le64 extended_source;
2468c2ecf20Sopenharmony_ci	};
2478c2ecf20Sopenharmony_ci};
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci#define IEEE802154_LLSEC_KEY_SIZE 16
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_cistruct ieee802154_llsec_key {
2528c2ecf20Sopenharmony_ci	u8 frame_types;
2538c2ecf20Sopenharmony_ci	u32 cmd_frame_ids;
2548c2ecf20Sopenharmony_ci	/* TODO replace with NL802154_KEY_SIZE */
2558c2ecf20Sopenharmony_ci	u8 key[IEEE802154_LLSEC_KEY_SIZE];
2568c2ecf20Sopenharmony_ci};
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_cistruct ieee802154_llsec_key_entry {
2598c2ecf20Sopenharmony_ci	struct list_head list;
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	struct ieee802154_llsec_key_id id;
2628c2ecf20Sopenharmony_ci	struct ieee802154_llsec_key *key;
2638c2ecf20Sopenharmony_ci};
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_cistruct ieee802154_llsec_params {
2668c2ecf20Sopenharmony_ci	bool enabled;
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	__be32 frame_counter;
2698c2ecf20Sopenharmony_ci	u8 out_level;
2708c2ecf20Sopenharmony_ci	struct ieee802154_llsec_key_id out_key;
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	__le64 default_key_source;
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	__le16 pan_id;
2758c2ecf20Sopenharmony_ci	__le64 hwaddr;
2768c2ecf20Sopenharmony_ci	__le64 coord_hwaddr;
2778c2ecf20Sopenharmony_ci	__le16 coord_shortaddr;
2788c2ecf20Sopenharmony_ci};
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistruct ieee802154_llsec_table {
2818c2ecf20Sopenharmony_ci	struct list_head keys;
2828c2ecf20Sopenharmony_ci	struct list_head devices;
2838c2ecf20Sopenharmony_ci	struct list_head security_levels;
2848c2ecf20Sopenharmony_ci};
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_cistruct ieee802154_llsec_seclevel {
2878c2ecf20Sopenharmony_ci	struct list_head list;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	u8 frame_type;
2908c2ecf20Sopenharmony_ci	u8 cmd_frame_id;
2918c2ecf20Sopenharmony_ci	bool device_override;
2928c2ecf20Sopenharmony_ci	u32 sec_levels;
2938c2ecf20Sopenharmony_ci};
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_cistruct ieee802154_llsec_device {
2968c2ecf20Sopenharmony_ci	struct list_head list;
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	__le16 pan_id;
2998c2ecf20Sopenharmony_ci	__le16 short_addr;
3008c2ecf20Sopenharmony_ci	__le64 hwaddr;
3018c2ecf20Sopenharmony_ci	u32 frame_counter;
3028c2ecf20Sopenharmony_ci	bool seclevel_exempt;
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	u8 key_mode;
3058c2ecf20Sopenharmony_ci	struct list_head keys;
3068c2ecf20Sopenharmony_ci};
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistruct ieee802154_llsec_device_key {
3098c2ecf20Sopenharmony_ci	struct list_head list;
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	struct ieee802154_llsec_key_id key_id;
3128c2ecf20Sopenharmony_ci	u32 frame_counter;
3138c2ecf20Sopenharmony_ci};
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cistruct wpan_dev_header_ops {
3168c2ecf20Sopenharmony_ci	/* TODO create callback currently assumes ieee802154_mac_cb inside
3178c2ecf20Sopenharmony_ci	 * skb->cb. This should be changed to give these information as
3188c2ecf20Sopenharmony_ci	 * parameter.
3198c2ecf20Sopenharmony_ci	 */
3208c2ecf20Sopenharmony_ci	int	(*create)(struct sk_buff *skb, struct net_device *dev,
3218c2ecf20Sopenharmony_ci			  const struct ieee802154_addr *daddr,
3228c2ecf20Sopenharmony_ci			  const struct ieee802154_addr *saddr,
3238c2ecf20Sopenharmony_ci			  unsigned int len);
3248c2ecf20Sopenharmony_ci};
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_cistruct wpan_dev {
3278c2ecf20Sopenharmony_ci	struct wpan_phy *wpan_phy;
3288c2ecf20Sopenharmony_ci	int iftype;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	/* the remainder of this struct should be private to cfg802154 */
3318c2ecf20Sopenharmony_ci	struct list_head list;
3328c2ecf20Sopenharmony_ci	struct net_device *netdev;
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	const struct wpan_dev_header_ops *header_ops;
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	/* lowpan interface, set when the wpan_dev belongs to one lowpan_dev */
3378c2ecf20Sopenharmony_ci	struct net_device *lowpan_dev;
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	u32 identifier;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	/* MAC PIB */
3428c2ecf20Sopenharmony_ci	__le16 pan_id;
3438c2ecf20Sopenharmony_ci	__le16 short_addr;
3448c2ecf20Sopenharmony_ci	__le64 extended_addr;
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	/* MAC BSN field */
3478c2ecf20Sopenharmony_ci	atomic_t bsn;
3488c2ecf20Sopenharmony_ci	/* MAC DSN field */
3498c2ecf20Sopenharmony_ci	atomic_t dsn;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	u8 min_be;
3528c2ecf20Sopenharmony_ci	u8 max_be;
3538c2ecf20Sopenharmony_ci	u8 csma_retries;
3548c2ecf20Sopenharmony_ci	s8 frame_retries;
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	bool lbt;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	bool promiscuous_mode;
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	/* fallback for acknowledgment bit setting */
3618c2ecf20Sopenharmony_ci	bool ackreq;
3628c2ecf20Sopenharmony_ci};
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci#define to_phy(_dev)	container_of(_dev, struct wpan_phy, dev)
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_cistatic inline int
3678c2ecf20Sopenharmony_ciwpan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
3688c2ecf20Sopenharmony_ci		     const struct ieee802154_addr *daddr,
3698c2ecf20Sopenharmony_ci		     const struct ieee802154_addr *saddr,
3708c2ecf20Sopenharmony_ci		     unsigned int len)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	return wpan_dev->header_ops->create(skb, dev, daddr, saddr, len);
3758c2ecf20Sopenharmony_ci}
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_cistruct wpan_phy *
3788c2ecf20Sopenharmony_ciwpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size);
3798c2ecf20Sopenharmony_cistatic inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev)
3808c2ecf20Sopenharmony_ci{
3818c2ecf20Sopenharmony_ci	phy->dev.parent = dev;
3828c2ecf20Sopenharmony_ci}
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ciint wpan_phy_register(struct wpan_phy *phy);
3858c2ecf20Sopenharmony_civoid wpan_phy_unregister(struct wpan_phy *phy);
3868c2ecf20Sopenharmony_civoid wpan_phy_free(struct wpan_phy *phy);
3878c2ecf20Sopenharmony_ci/* Same semantics as for class_for_each_device */
3888c2ecf20Sopenharmony_ciint wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data);
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_cistatic inline void *wpan_phy_priv(struct wpan_phy *phy)
3918c2ecf20Sopenharmony_ci{
3928c2ecf20Sopenharmony_ci	BUG_ON(!phy);
3938c2ecf20Sopenharmony_ci	return &phy->priv;
3948c2ecf20Sopenharmony_ci}
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_cistruct wpan_phy *wpan_phy_find(const char *str);
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_cistatic inline void wpan_phy_put(struct wpan_phy *phy)
3998c2ecf20Sopenharmony_ci{
4008c2ecf20Sopenharmony_ci	put_device(&phy->dev);
4018c2ecf20Sopenharmony_ci}
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_cistatic inline const char *wpan_phy_name(struct wpan_phy *phy)
4048c2ecf20Sopenharmony_ci{
4058c2ecf20Sopenharmony_ci	return dev_name(&phy->dev);
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci#endif /* __NET_CFG802154_H */
409