cfg80211 subsystem中的wiphy

来源:互联网 发布:c语言实现web服务器 编辑:程序博客网 时间:2024/06/07 10:25

无线网络设备驱动使用cfg80211需要硬件设备在cfg80211中实现注册。实现注册就要定义一系列的硬件功能描述的结构体。
每个设备的基础性结构体是wiphy,设备连接到系统时,都要使用。每个wiphy有0个,1个或者许多个虚拟接口相关联。

struct wiphy定义在内核include/net/cfg80211.h中

struct wiphy {    /* assign these fields before you register the wiphy */    /* permanent MAC address(es) */    u8 perm_addr[ETH_ALEN];    u8 addr_mask[ETH_ALEN];    struct mac_address *addresses;    const struct ieee80211_txrx_stypes *mgmt_stypes;    const struct ieee80211_iface_combination *iface_combinations;    int n_iface_combinations;    u16 software_iftypes;    u16 n_addresses;    /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */    u16 interface_modes;    u16 max_acl_mac_addrs;    u32 flags, regulatory_flags, features;    u8 ext_features[DIV_ROUND_UP(NUM_NL80211_EXT_FEATURES, 8)];    u32 ap_sme_capa;    enum cfg80211_signal_type signal_type;    int bss_priv_size;    u8 max_scan_ssids;    u8 max_sched_scan_ssids;    u8 max_match_sets;    u16 max_scan_ie_len;    u16 max_sched_scan_ie_len;    u32 max_sched_scan_plans;    u32 max_sched_scan_plan_interval;    u32 max_sched_scan_plan_iterations;    int n_cipher_suites;    const u32 *cipher_suites;    u8 retry_short;    u8 retry_long;    u32 frag_threshold;    u32 rts_threshold;    u8 coverage_class;    char fw_version[ETHTOOL_FWVERS_LEN];    u32 hw_version;#ifdef CONFIG_PM    const struct wiphy_wowlan_support *wowlan;    struct cfg80211_wowlan *wowlan_config;#endif    u16 max_remain_on_channel_duration;    u8 max_num_pmkids;    u32 available_antennas_tx;    u32 available_antennas_rx;    /*     * Bitmap of supported protocols for probe response offloading     * see &enum nl80211_probe_resp_offload_support_attr. Only valid     * when the wiphy flag @WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD is set.     */    u32 probe_resp_offload;    const u8 *extended_capabilities, *extended_capabilities_mask;    u8 extended_capabilities_len;    /* If multiple wiphys are registered and you're handed e.g.     * a regular netdev with assigned ieee80211_ptr, you won't     * know whether it points to a wiphy your driver has registered     * or not. Assign this to something global to your driver to     * help determine whether you own this wiphy or not. */    const void *privid;    struct ieee80211_supported_band *bands[NUM_NL80211_BANDS];    /* Lets us get back the wiphy on the callback */    void (*reg_notifier)(struct wiphy *wiphy,                 struct regulatory_request *request);    /* fields below are read-only, assigned by cfg80211 */    const struct ieee80211_regdomain __rcu *regd;    /* the item in /sys/class/ieee80211/ points to this,     * you need use set_wiphy_dev() (see below) */    struct device dev;    /* protects ->resume, ->suspend sysfs callbacks against unregister hw */    bool registered;    /* dir in debugfs: ieee80211/<wiphyname> */    struct dentry *debugfsdir;    const struct ieee80211_ht_cap *ht_capa_mod_mask;    const struct ieee80211_vht_cap *vht_capa_mod_mask;    struct list_head wdev_list;    /* the network namespace this phy lives in currently */    possible_net_t _net;#ifdef CONFIG_CFG80211_WEXT    const struct iw_handler_def *wext;#endif    const struct wiphy_coalesce_support *coalesce;    const struct wiphy_vendor_command *vendor_commands;    const struct nl80211_vendor_cmd_info *vendor_events;    int n_vendor_commands, n_vendor_events;    u16 max_ap_assoc_sta;    u8 max_num_csa_counters;    u8 max_adj_channel_rssi_comp;    u32 bss_select_support;    char priv[0] __aligned(NETDEV_ALIGN);};

wiphy结构体成员:

perm_addr[ETH_ALEN] 

固定的设备mac地址

addr_mask[ETH_ALEN]  

如果设备支持使用掩码多mac地址,则可根据掩码将相应的标志位置1 。例如,最后四位可变,则该成员设置为 00-00-00-00-00-0f,实际变动位应该取决于增加的设备接口,如果接口和掩码不能匹配,这接口无法启用。

addresses 

如果设备有多个mac地址,这这个指针指向地址列表,第一个地址就时默认perm_addr。

mgmt_stypes  

struct ieee80211_txrx_stypes 结构体指针

iface_combinations

struct ieee80211_iface_combination

n_iface_combinations 

iface_combinations 数组的条目个数

software_iftypes  

软件接口类型

n_addresses 

addresses 中的address个数

interface_modes 

wiphy可以用借口的模式,由设备驱动设置

max_acl_mac_addrs

acl中设备支持的最大mac地址数

flags

wiphy 的标志位, 可以查看enum wiphy_flags

regulatory_flags

wiphy regulatory 标志位, 可以查看enum ieee80211_regulatory_flags

features

features advertised to nl80211, 可以查看enum nl80211_feature_flags

ext_features[DIV_ROUND_UP(NUM_NL80211_EXT_FEATURES# 8)]

扩展的features advertised to nl80211, see enum nl80211_ext_feature_index

ap_sme_capa

AP SME capabilities, flags from enum nl80211_ap_sme_features

signal_type

signal类型, 从 struct cfg80211_bss 中获取

bss_priv_size

each BSS struct has private data allocated with it, this variable determines its size

max_scan_ssids

maximum number of SSIDs the device can scan for in any given scan

max_sched_scan_ssids

maximum number of SSIDs the device can scan for in any given scheduled scan

max_match_sets

maximum number of match sets the device can handle when performing a scheduled scan, 0 if filtering is not supported.

max_scan_ie_len

maximum length of user-controlled IEs device can add to probe request frames transmitted during a scan, must not include fixed IEs like supported rates

max_sched_scan_ie_len

same as max_scan_ie_len, but for scheduled scans

max_sched_scan_plans

maximum number of scan plans (scan interval and number of iterations) for scheduled scan supported by the device.

 max_sched_scan_plan_interval

maximum interval (in seconds) for a single scan plan supported by the device.

max_sched_scan_plan_iterations

maximum number of iterations for a single scan plan supported by the device.

 n_cipher_suites

number of supported cipher suites

 cipher_suites

supported cipher suites

 retry_short

Retry limit for short frames (dot11ShortRetryLimit)

retry_long

Retry limit for long frames (dot11LongRetryLimit)

frag_threshold

Fragmentation threshold (dot11FragmentationThreshold); -1 = fragmentation disabled, only odd values >= 256 used

rts_threshold

RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled

coverage_class

current coverage class

fw_version[ETHTOOL_FWVERS_LEN]

firmware version for ethtool reporting

hw_version

hardware version for ethtool reporting

wowlan

WoWLAN support information

wowlan_config

current WoWLAN configuration; this should usually not be used since access to it is necessarily racy, use the parameter passed to the suspend() operation instead.

max_remain_on_channel_duration

Maximum time a remain-on-channel operation may request, if implemented.

max_num_pmkids

maximum number of PMKIDs supported by device

available_antennas_tx

bitmap of antennas which are available to be configured as TX antennas. Antenna configuration commands will be rejected unless this or available_antennas_rx is set.

available_antennas_rx
bitmap of antennas which are available to be configured as RX antennas. Antenna configuration commands will be rejected unless this or available_antennas_tx is set.

probe_resp_offload

Bitmap of supported protocols for probe response offloading. See enum nl80211_probe_resp_offload_support_attr. Only valid when the wiphy flag WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD is set.

extended_capabilities

extended capabilities supported by the driver, additional capabilities might be supported by userspace; these are the 802.11 extended capabilities (“Extended Capabilities element”) and are in the same format as in the information element. See 802.11-2012 8.4.2.29 for the defined fields. These are the default extended capabilities to be used if the capabilities are not specified for a specific interface type in iftype_ext_capab.

extended_capabilities_mask

mask of the valid values

extended_capabilities_len

length of the extended capabilities

iftype_ext_capab

array of extended capabilities per interface type

num_iftype_ext_capab

number of interface types for which extended capabilities are specified separately.

privid

a pointer that drivers can use to identify if an arbitrary wiphy is theirs, e.g. in global notifiers

bands[NUM_NL80211_BANDS]

information about bands/channels supported by this device
reg_notifier
the driver’s regulatory notification callback, note that if your driver uses wiphy_apply_custom_regulatory() the reg_notifier’s request can be passed as NULL

regd

the driver’s regulatory domain, if one was requested via the regulatory_hint()API. This can be used by the driver on the reg_notifier()if it chooses to ignore future regulatory domain changes caused by other drivers.

 dev

(virtual) struct device for this wiphy

registered

helps synchronize suspend/resume with wiphy unregister

debugfsdir

debugfs directory used for this wiphy, will be renamed automatically on wiphy
renames

ht_capa_mod_mask

Specify what ht_cap values can be over-ridden. If null, then none can be over-ridden.

vht_capa_mod_mask

Specify what VHT capabilities can be over-ridden. If null, then none can be over-ridden.

 wdev_list

the list of associated (virtual) interfaces; this list must not be modified by the driver, but can be read with RTNL/RCU protection.

_net

the network namespace this wiphy currently lives in

wext

wireless extension handlers

coalesce

packet coalescing support information

vendor_commands

array of vendor commands supported by the hardware

 vendor_events

array of vendor events supported by the hardware

n_vendor_commands

number of vendor commands

 n_vendor_events

number of vendor events

 max_ap_assoc_sta

maximum number of associated stations supported in AP mode (including P2P GO) or 0 to indicate no such limit is advertised. The driver is allowed to advertise a theoretical limit that it can reach in some cases, but may not always reach.

 max_num_csa_counters

Number of supported csa_counters in beacons and probe responses. This value should be set if the driver wishes to limit the number of csa counters. Default (0) means infinite.

 max_adj_channel_rssi_comp

max offset of between the channel on which the frame was sent and the channel on which the frame was heard for which the reported rssi is still valid. If a driver is able to compensate the low rssi when a frame is heard on different channel, then it should set this variable to the maximal offset for which it can compensate. This value should be set in MHz.

 bss_select_support

bitmask indicating the BSS selection criteria supported by the driver in the.:c:func:connect() callback. The bit position maps to the attribute indices defined in enum nl80211_bss_select_attr.

 cookie_counter

unique generic cookie counter, used to identify objects.

 priv[0]

driver private data (sized according to wiphy_new() parameter)


无线设备状态结构体 struct wireless_dev

对于netdevs,该结构体需要结构体net_device使用ieee80211_ptr 域来分配获取,需要注册。

struct wireless_dev {    struct wiphy *wiphy;    enum nl80211_iftype iftype;    /* the remainder of this struct should be private to cfg80211 */    struct list_head list;    struct net_device *netdev;    u32 identifier;    struct list_head mgmt_registrations;    spinlock_t mgmt_registrations_lock;    struct mutex mtx;    bool use_4addr, p2p_started;    u8 address[ETH_ALEN] __aligned(sizeof(u16));    /* currently used for IBSS and SME - might be rearranged later */    u8 ssid[IEEE80211_MAX_SSID_LEN];    u8 ssid_len, mesh_id_len, mesh_id_up_len;    struct cfg80211_conn *conn;    struct cfg80211_cached_keys *connect_keys;    enum ieee80211_bss_type conn_bss_type;    struct list_head event_list;    spinlock_t event_lock;    struct cfg80211_internal_bss *current_bss; /* associated / joined */    struct cfg80211_chan_def preset_chandef;    struct cfg80211_chan_def chandef;    bool ibss_fixed;    bool ibss_dfs_possible;    bool ps;    int ps_timeout;    int beacon_interval;    u32 ap_unexpected_nlportid;    bool cac_started;    unsigned long cac_start_time;    unsigned int cac_time_ms;    u32 owner_nlportid;#ifdef CONFIG_CFG80211_WEXT    /* wext data */    struct {        struct cfg80211_ibss_params ibss;        struct cfg80211_connect_params connect;        struct cfg80211_cached_keys *keys;        const u8 *ie;        size_t ie_len;        u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];        u8 ssid[IEEE80211_MAX_SSID_LEN];        s8 default_key, default_mgmt_key;        bool prev_bssid_valid;    } wext;#endif};

与wiphy相关的操作函数

struct wiphy * wiphy_new(const struct cfg80211_ops * ops, int sizeof_priv) 

为使用cfg80211创建一个新的wiphy

参数:
const struct cfg80211_ops * ops 设备的配置操作
int sizeof_priv 私有数据区分配的大小

返回值:
返回一个指向新的wiphy的指针。

int wiphy_register(struct wiphy * wiphy) 

在cfg80211中注册一个wiphy

参数:
struct wiphy * wiphy 要注册的wiphy

返回值
创建wiphy成功返回,成功索引,否则返回错误码。

void wiphy_unregister(struct wiphy * wiphy) 

在cfg80211中注销一个wiphy

参数
struct wiphy * wiphy

void wiphy_free(struct wiphy * wiphy) 

释放wiphy

参数
struct wiphy * wiphy

const char * wiphy_name(const struct wiphy * wiphy) 

获取wiphy的名字

参数
const struct wiphy * wiphy

返回值:
返回wiphy的名字

struct device * wiphy_dev(struct wiphy * wiphy) 

获取wiphy dev指针

参数:
struct wiphy * wiphy

返回值
返回dev的wiphy

void * wiphy_priv(struct wiphy * wiphy) 

返回wiphy的私有数据

struct wiphy * priv_to_wiphy(void * priv) 

返回包含私有数据的wiphy

void set_wiphy_dev(struct wiphy * wiphy, struct device * dev) 

为wiphy设置设备指针

void * wdev_priv(struct wireless_dev * wdev) 

wireless_dev中返回wiphy

0 0
原创粉丝点击