^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2007, 2008, 2009 Siemens AG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef __NET_CFG802154_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define __NET_CFG802154_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/ieee802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/nl802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct wpan_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct wpan_phy_cca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct ieee802154_llsec_device_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct ieee802154_llsec_seclevel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct ieee802154_llsec_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct ieee802154_llsec_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct ieee802154_llsec_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct ieee802154_llsec_key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct ieee802154_llsec_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct cfg802154_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct net_device * (*add_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned char name_assign_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) void (*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int (*suspend)(struct wpan_phy *wpan_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int (*resume)(struct wpan_phy *wpan_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int (*add_virtual_intf)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned char name_assign_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) enum nl802154_iftype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) __le64 extended_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int (*del_virtual_intf)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct wpan_dev *wpan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int (*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int (*set_cca_mode)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) const struct wpan_phy_cca *cca);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int (*set_cca_ed_level)(struct wpan_phy *wpan_phy, s32 ed_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int (*set_tx_power)(struct wpan_phy *wpan_phy, s32 power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int (*set_pan_id)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct wpan_dev *wpan_dev, __le16 pan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int (*set_short_addr)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct wpan_dev *wpan_dev, __le16 short_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int (*set_backoff_exponent)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct wpan_dev *wpan_dev, u8 min_be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u8 max_be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int (*set_max_csma_backoffs)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u8 max_csma_backoffs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int (*set_max_frame_retries)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) s8 max_frame_retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int (*set_lbt_mode)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct wpan_dev *wpan_dev, bool mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int (*set_ackreq_default)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct wpan_dev *wpan_dev, bool ackreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) void (*get_llsec_table)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct ieee802154_llsec_table **table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) void (*lock_llsec_table)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct wpan_dev *wpan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) void (*unlock_llsec_table)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct wpan_dev *wpan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* TODO remove locking/get table callbacks, this is part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * nl802154 interface and should be accessible from ieee802154 layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int (*get_llsec_params)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct ieee802154_llsec_params *params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int (*set_llsec_params)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) const struct ieee802154_llsec_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int (*add_llsec_key)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) const struct ieee802154_llsec_key_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const struct ieee802154_llsec_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int (*del_llsec_key)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) const struct ieee802154_llsec_key_id *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int (*add_seclevel)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) const struct ieee802154_llsec_seclevel *sl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int (*del_seclevel)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) const struct ieee802154_llsec_seclevel *sl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int (*add_device)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) const struct ieee802154_llsec_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int (*del_device)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct wpan_dev *wpan_dev, __le64 extended_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int (*add_devkey)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) __le64 extended_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) const struct ieee802154_llsec_device_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int (*del_devkey)(struct wpan_phy *wpan_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct wpan_dev *wpan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) __le64 extended_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) const struct ieee802154_llsec_device_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) wpan_phy_supported_bool(bool b, enum nl802154_supported_bool_states st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) switch (st) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) case NL802154_SUPPORTED_BOOL_TRUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) case NL802154_SUPPORTED_BOOL_FALSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return !b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) case NL802154_SUPPORTED_BOOL_BOTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct wpan_phy_supported {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u32 channels[IEEE802154_MAX_PAGE + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) cca_modes, cca_opts, iftypes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) enum nl802154_supported_bool_states lbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u8 min_minbe, max_minbe, min_maxbe, max_maxbe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) min_csma_backoffs, max_csma_backoffs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) s8 min_frame_retries, max_frame_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) size_t tx_powers_size, cca_ed_levels_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) const s32 *tx_powers, *cca_ed_levels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct wpan_phy_cca {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) enum nl802154_cca_modes mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) enum nl802154_cca_opts opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) wpan_phy_cca_cmp(const struct wpan_phy_cca *a, const struct wpan_phy_cca *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (a->mode != b->mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (a->mode == NL802154_CCA_ENERGY_CARRIER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return a->opt == b->opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * @WPAN_PHY_FLAG_TRANSMIT_POWER: Indicates that transceiver will support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * transmit power setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * @WPAN_PHY_FLAG_CCA_ED_LEVEL: Indicates that transceiver will support cca ed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * level setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * @WPAN_PHY_FLAG_CCA_MODE: Indicates that transceiver will support cca mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) enum wpan_phy_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) WPAN_PHY_FLAG_TXPOWER = BIT(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) WPAN_PHY_FLAG_CCA_ED_LEVEL = BIT(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) WPAN_PHY_FLAG_CCA_MODE = BIT(3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct wpan_phy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* If multiple wpan_phys are registered and you're handed e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * a regular netdev with assigned ieee802154_ptr, you won't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * know whether it points to a wpan_phy your driver has registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * or not. Assign this to something global to your driver to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * help determine whether you own this wpan_phy or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) const void *privid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * This is a PIB according to 802.15.4-2011.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * We do not provide timing-related variables, as they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * aren't used outside of driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) u8 current_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) u8 current_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct wpan_phy_supported supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* current transmit_power in mBm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) s32 transmit_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct wpan_phy_cca cca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) __le64 perm_extended_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* current cca ed threshold in mBm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) s32 cca_ed_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* PHY depended MAC PIB values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* 802.15.4 acronym: Tdsym in usec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) u8 symbol_duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* lifs and sifs periods timing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u16 lifs_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u16 sifs_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* the network namespace this phy lives in currently */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) possible_net_t _net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) char priv[] __aligned(NETDEV_ALIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static inline struct net *wpan_phy_net(struct wpan_phy *wpan_phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return read_pnet(&wpan_phy->_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static inline void wpan_phy_net_set(struct wpan_phy *wpan_phy, struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) write_pnet(&wpan_phy->_net, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct ieee802154_addr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) __le16 pan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) __le16 short_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) __le64 extended_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct ieee802154_llsec_key_id {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) u8 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct ieee802154_addr device_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) __le32 short_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) __le64 extended_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #define IEEE802154_LLSEC_KEY_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct ieee802154_llsec_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) u8 frame_types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) u32 cmd_frame_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* TODO replace with NL802154_KEY_SIZE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) u8 key[IEEE802154_LLSEC_KEY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct ieee802154_llsec_key_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct ieee802154_llsec_key_id id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct ieee802154_llsec_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct ieee802154_llsec_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) bool enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) __be32 frame_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) u8 out_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct ieee802154_llsec_key_id out_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) __le64 default_key_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) __le16 pan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) __le64 hwaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) __le64 coord_hwaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) __le16 coord_shortaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct ieee802154_llsec_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct list_head keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct list_head devices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct list_head security_levels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct ieee802154_llsec_seclevel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) u8 frame_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) u8 cmd_frame_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) bool device_override;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) u32 sec_levels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct ieee802154_llsec_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) __le16 pan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) __le16 short_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) __le64 hwaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) u32 frame_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) bool seclevel_exempt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) u8 key_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct list_head keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct ieee802154_llsec_device_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct ieee802154_llsec_key_id key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) u32 frame_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct wpan_dev_header_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* TODO create callback currently assumes ieee802154_mac_cb inside
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * skb->cb. This should be changed to give these information as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int (*create)(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) const struct ieee802154_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) const struct ieee802154_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct wpan_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct wpan_phy *wpan_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int iftype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* the remainder of this struct should be private to cfg802154 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct net_device *netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) const struct wpan_dev_header_ops *header_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* lowpan interface, set when the wpan_dev belongs to one lowpan_dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct net_device *lowpan_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) u32 identifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /* MAC PIB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) __le16 pan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) __le16 short_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) __le64 extended_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* MAC BSN field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) atomic_t bsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* MAC DSN field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) atomic_t dsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) u8 min_be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) u8 max_be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) u8 csma_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) s8 frame_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) bool lbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) bool promiscuous_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /* fallback for acknowledgment bit setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) bool ackreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #define to_phy(_dev) container_of(_dev, struct wpan_phy, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) wpan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) const struct ieee802154_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) const struct ieee802154_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return wpan_dev->header_ops->create(skb, dev, daddr, saddr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct wpan_phy *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) phy->dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) int wpan_phy_register(struct wpan_phy *phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) void wpan_phy_unregister(struct wpan_phy *phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) void wpan_phy_free(struct wpan_phy *phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /* Same semantics as for class_for_each_device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static inline void *wpan_phy_priv(struct wpan_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) BUG_ON(!phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return &phy->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct wpan_phy *wpan_phy_find(const char *str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static inline void wpan_phy_put(struct wpan_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) put_device(&phy->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static inline const char *wpan_phy_name(struct wpan_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return dev_name(&phy->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #endif /* __NET_CFG802154_H */