18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2007-2012 Siemens AG
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Written by:
68c2ecf20Sopenharmony_ci * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
78c2ecf20Sopenharmony_ci * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
88c2ecf20Sopenharmony_ci * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
98c2ecf20Sopenharmony_ci * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#ifndef __IEEE802154_I_H
128c2ecf20Sopenharmony_ci#define __IEEE802154_I_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
158c2ecf20Sopenharmony_ci#include <linux/mutex.h>
168c2ecf20Sopenharmony_ci#include <linux/hrtimer.h>
178c2ecf20Sopenharmony_ci#include <net/cfg802154.h>
188c2ecf20Sopenharmony_ci#include <net/mac802154.h>
198c2ecf20Sopenharmony_ci#include <net/nl802154.h>
208c2ecf20Sopenharmony_ci#include <net/ieee802154_netdev.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include "llsec.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* mac802154 device private data */
258c2ecf20Sopenharmony_cistruct ieee802154_local {
268c2ecf20Sopenharmony_ci	struct ieee802154_hw hw;
278c2ecf20Sopenharmony_ci	const struct ieee802154_ops *ops;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	/* ieee802154 phy */
308c2ecf20Sopenharmony_ci	struct wpan_phy *phy;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	int open_count;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	/* As in mac80211 slaves list is modified:
358c2ecf20Sopenharmony_ci	 * 1) under the RTNL
368c2ecf20Sopenharmony_ci	 * 2) protected by slaves_mtx;
378c2ecf20Sopenharmony_ci	 * 3) in an RCU manner
388c2ecf20Sopenharmony_ci	 *
398c2ecf20Sopenharmony_ci	 * So atomic readers can use any of this protection methods.
408c2ecf20Sopenharmony_ci	 */
418c2ecf20Sopenharmony_ci	struct list_head	interfaces;
428c2ecf20Sopenharmony_ci	struct mutex		iflist_mtx;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	/* This one is used for scanning and other jobs not to be interfered
458c2ecf20Sopenharmony_ci	 * with serial driver.
468c2ecf20Sopenharmony_ci	 */
478c2ecf20Sopenharmony_ci	struct workqueue_struct	*workqueue;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	struct hrtimer ifs_timer;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	bool started;
528c2ecf20Sopenharmony_ci	bool suspended;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	struct tasklet_struct tasklet;
558c2ecf20Sopenharmony_ci	struct sk_buff_head skb_queue;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	struct sk_buff *tx_skb;
588c2ecf20Sopenharmony_ci	struct work_struct tx_work;
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cienum {
628c2ecf20Sopenharmony_ci	IEEE802154_RX_MSG        = 1,
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cienum ieee802154_sdata_state_bits {
668c2ecf20Sopenharmony_ci	SDATA_STATE_RUNNING,
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* Slave interface definition.
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci * Slaves represent typical network interfaces available from userspace.
728c2ecf20Sopenharmony_ci * Each ieee802154 device/transceiver may have several slaves and able
738c2ecf20Sopenharmony_ci * to be associated with several networks at the same time.
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_cistruct ieee802154_sub_if_data {
768c2ecf20Sopenharmony_ci	struct list_head list; /* the ieee802154_priv->slaves list */
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	struct wpan_dev wpan_dev;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	struct ieee802154_local *local;
818c2ecf20Sopenharmony_ci	struct net_device *dev;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	unsigned long state;
848c2ecf20Sopenharmony_ci	char name[IFNAMSIZ];
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	/* protects sec from concurrent access by netlink. access by
878c2ecf20Sopenharmony_ci	 * encrypt/decrypt/header_create safe without additional protection.
888c2ecf20Sopenharmony_ci	 */
898c2ecf20Sopenharmony_ci	struct mutex sec_mtx;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	struct mac802154_llsec sec;
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* utility functions/constants */
958c2ecf20Sopenharmony_ciextern const void *const mac802154_wpan_phy_privid; /*  for wpan_phy privid */
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistatic inline struct ieee802154_local *
988c2ecf20Sopenharmony_cihw_to_local(struct ieee802154_hw *hw)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	return container_of(hw, struct ieee802154_local, hw);
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic inline struct ieee802154_sub_if_data *
1048c2ecf20Sopenharmony_ciIEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	return netdev_priv(dev);
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistatic inline struct ieee802154_sub_if_data *
1108c2ecf20Sopenharmony_ciIEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev);
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic inline bool
1168c2ecf20Sopenharmony_ciieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	return test_bit(SDATA_STATE_RUNNING, &sdata->state);
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ciextern struct ieee802154_mlme_ops mac802154_mlme_wpan;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_civoid ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb);
1248c2ecf20Sopenharmony_civoid ieee802154_xmit_worker(struct work_struct *work);
1258c2ecf20Sopenharmony_cinetdev_tx_t
1268c2ecf20Sopenharmony_ciieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
1278c2ecf20Sopenharmony_cinetdev_tx_t
1288c2ecf20Sopenharmony_ciieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
1298c2ecf20Sopenharmony_cienum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* MIB callbacks */
1328c2ecf20Sopenharmony_civoid mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ciint mac802154_get_params(struct net_device *dev,
1358c2ecf20Sopenharmony_ci			 struct ieee802154_llsec_params *params);
1368c2ecf20Sopenharmony_ciint mac802154_set_params(struct net_device *dev,
1378c2ecf20Sopenharmony_ci			 const struct ieee802154_llsec_params *params,
1388c2ecf20Sopenharmony_ci			 int changed);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ciint mac802154_add_key(struct net_device *dev,
1418c2ecf20Sopenharmony_ci		      const struct ieee802154_llsec_key_id *id,
1428c2ecf20Sopenharmony_ci		      const struct ieee802154_llsec_key *key);
1438c2ecf20Sopenharmony_ciint mac802154_del_key(struct net_device *dev,
1448c2ecf20Sopenharmony_ci		      const struct ieee802154_llsec_key_id *id);
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciint mac802154_add_dev(struct net_device *dev,
1478c2ecf20Sopenharmony_ci		      const struct ieee802154_llsec_device *llsec_dev);
1488c2ecf20Sopenharmony_ciint mac802154_del_dev(struct net_device *dev, __le64 dev_addr);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciint mac802154_add_devkey(struct net_device *dev,
1518c2ecf20Sopenharmony_ci			 __le64 device_addr,
1528c2ecf20Sopenharmony_ci			 const struct ieee802154_llsec_device_key *key);
1538c2ecf20Sopenharmony_ciint mac802154_del_devkey(struct net_device *dev,
1548c2ecf20Sopenharmony_ci			 __le64 device_addr,
1558c2ecf20Sopenharmony_ci			 const struct ieee802154_llsec_device_key *key);
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ciint mac802154_add_seclevel(struct net_device *dev,
1588c2ecf20Sopenharmony_ci			   const struct ieee802154_llsec_seclevel *sl);
1598c2ecf20Sopenharmony_ciint mac802154_del_seclevel(struct net_device *dev,
1608c2ecf20Sopenharmony_ci			   const struct ieee802154_llsec_seclevel *sl);
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_civoid mac802154_lock_table(struct net_device *dev);
1638c2ecf20Sopenharmony_civoid mac802154_get_table(struct net_device *dev,
1648c2ecf20Sopenharmony_ci			 struct ieee802154_llsec_table **t);
1658c2ecf20Sopenharmony_civoid mac802154_unlock_table(struct net_device *dev);
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ciint mac802154_wpan_update_llsec(struct net_device *dev);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/* interface handling */
1708c2ecf20Sopenharmony_ciint ieee802154_iface_init(void);
1718c2ecf20Sopenharmony_civoid ieee802154_iface_exit(void);
1728c2ecf20Sopenharmony_civoid ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
1738c2ecf20Sopenharmony_cistruct net_device *
1748c2ecf20Sopenharmony_ciieee802154_if_add(struct ieee802154_local *local, const char *name,
1758c2ecf20Sopenharmony_ci		  unsigned char name_assign_type, enum nl802154_iftype type,
1768c2ecf20Sopenharmony_ci		  __le64 extended_addr);
1778c2ecf20Sopenharmony_civoid ieee802154_remove_interfaces(struct ieee802154_local *local);
1788c2ecf20Sopenharmony_civoid ieee802154_stop_device(struct ieee802154_local *local);
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci#endif /* __IEEE802154_I_H */
181