1. USB设备枚举过程
2. 关键数据结构
1)
2) struct wiphy:wireless hardware description
3)
4) struct ieee80211_hw:hardwareinformation and state
5) struct ieee80211_channel:channeldefinition
6)
3.USB-Wifi驱动架构
2) USB无线网卡驱动层
3.1 向USBCore注册USB驱动
- static
struct usb_driver ath9k_hif_usb_driver = { //USB 驱动 -
.name = KBUILD_MODNAME, -
.probe = ath9k_hif_usb_probe, -
.disconnect = ath9k_hif_usb_disconnect, - #ifdef
CONFIG_PM -
.suspend = ath9k_hif_usb_suspend, -
.resume = ath9k_hif_usb_resume, -
.reset_resume = ath9k_hif_usb_resume, - #endif
-
.id_table = ath9k_hif_usb_ids, -
.soft_unbind = 1, - };
-
- int
ath9k_hif_usb_init(void) - {
-
return usb_register(&ath9k_hif_usb_driver); // 把driver注册到USB驱动链中 - }
-
- void
ath9k_hif_usb_exit(void) - {
-
usb_deregister(&ath9k_hif_usb_driver); // 把driver从USB驱动链中删除 - }
3.2向ieee802.11注册ieee80211_ops
在kernel/drivers/net/wireless/ath/ath9k/htc_drv_main.c中定义了ath9k_htc_ops,其详细定义如下:
- struct
ieee80211_ops ath9k_htc_ops = { -
.tx = ath9k_htc_tx, -
.start = ath9k_htc_start, -
.stop = ath9k_htc_stop, -
.add_interface = ath9k_htc_add_interface, -
.remove_interface = ath9k_htc_remove_interface, -
.config = ath9k_htc_config, -
.configure_filter = ath9k_htc_configure_filter, -
.sta_add = ath9k_htc_sta_add, -
.sta_remove = ath9k_htc_sta_remove, -
.conf_tx = ath9k_htc_conf_tx, -
.bss_info_changed = ath9k_htc_bss_info_changed, -
.set_key = ath9k_htc_set_key, -
.get_tsf = ath9k_htc_get_tsf, -
.set_tsf = ath9k_htc_set_tsf, -
.reset_tsf = ath9k_htc_reset_tsf, -
.ampdu_action = ath9k_htc_ampdu_action, -
.sw_scan_start = ath9k_htc_sw_scan_start, -
.sw_scan_complete = ath9k_htc_sw_scan_complete, -
.set_rts_threshold = ath9k_htc_set_rts_threshold, -
.rfkill_poll = ath9k_htc_rfkill_poll_state, -
.set_coverage_class = ath9k_htc_set_coverage_class, -
.set_bitrate_mask = ath9k_htc_set_bitrate_mask, - };
-
-
4. Wifi工作流程
4.1 Wifi打开基本流程
4.2Wifi关闭基本流程
4.3Wifi待机和唤醒流程
5.注册ieee80211_class
net/wireless/sysfs.c
- struct
class ieee80211_class = { -
.name = "ieee80211", -
.owner = THIS_MODULE, -
.dev_release = wiphy_dev_release, -
.dev_attrs = ieee80211_dev_attrs, - #ifdef
CONFIG_HOTPLUG -
.dev_uevent = wiphy_uevent, - #endif
-
.suspend = wiphy_suspend, // Suspend Wifi -
.resume = wiphy_resume, // Resume Wifi -
.ns_type = &net_ns_type_operations, -
.namespace = wiphy_namespace, - };
-
- int
wiphy_sysfs_init(void) - {
-
return class_register(&ieee80211_class); - }
-
- void
wiphy_sysfs_exit(void) - {
-
class_unregister(&ieee80211_class); - }
它需要调用的structcfg80211_ops定义如下:
net/mac80211/cfg.c
- struct
cfg80211_ops mac80211_config_ops = { -
.add_virtual_intf = ieee80211_add_iface, -
.del_virtual_intf = ieee80211_del_iface, -
.change_virtual_intf = ieee80211_change_iface, -
.add_key = ieee80211_add_key, -
.del_key = ieee80211_del_key, -
.get_key = ieee80211_get_key, -
.set_default_key = ieee80211_config_default_key, -
.set_default_mgmt_key = ieee80211_config_default_mgmt_key, -
.add_beacon = ieee80211_add_beacon, -
.set_beacon = ieee80211_set_beacon, -
.del_beacon = ieee80211_del_beacon, -
.add_station = ieee80211_add_station, -
.del_station = ieee80211_del_station, -
.change_station = ieee80211_change_station, -
.get_station = ieee80211_get_station, -
.dump_station = ieee80211_dump_station, -
.dump_survey = ieee80211_dump_survey, - #ifdef
CONFIG_MAC80211_MESH -
.add_mpath = ieee80211_add_mpath, -
.del_mpath = ieee80211_del_mpath, -
.change_mpath = ieee80211_change_mpath, -
.get_mpath = ieee80211_get_mpath, -
.dump_mpath = ieee80211_dump_mpath, -
.update_mesh_config = ieee80211_update_mesh_config, -
.get_mesh_config = ieee80211_get_mesh_config, -
.join_mesh = ieee80211_join_mesh, -
.leave_mesh = ieee80211_leave_mesh, - #endif
-
.change_bss = ieee80211_change_bss, -
.set_txq_params = ieee80211_set_txq_params, -
.set_channel = ieee80211_set_channel, -
.suspend = ieee80211_suspend, -
.resume = ieee80211_resume, -
.scan = ieee80211_scan, -
.sched_scan_start = ieee80211_sched_scan_start, -
.sched_scan_stop = ieee80211_sched_scan_stop, -
.auth = ieee80211_auth, -
.assoc = ieee80211_assoc, -
.deauth = ieee80211_deauth, -
.disassoc = ieee80211_disassoc, -
.join_ibss = ieee80211_join_ibss, -
.leave_ibss = ieee80211_leave_ibss, -
.set_wiphy_params = ieee80211_set_wiphy_params, -
.set_tx_power = ieee80211_set_tx_power, -
.get_tx_power = ieee80211_get_tx_power, -
.set_wds_peer = ieee80211_set_wds_peer, -
.rfkill_poll = ieee80211_rfkill_poll, -
CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) -
.set_power_mgmt = ieee80211_set_power_mgmt, -
.set_bitrate_mask = ieee80211_set_bitrate_mask, -
.remain_on_channel = ieee80211_remain_on_channel, -
.cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, -
.mgmt_tx = ieee80211_mgmt_tx, -
.mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, -
.set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, -
.mgmt_frame_register = ieee80211_mgmt_frame_register, -
.set_antenna = ieee80211_set_antenna, -
.get_antenna = ieee80211_get_antenna, -
.set_ringparam = ieee80211_set_ringparam, -
.get_ringparam = ieee80211_get_ringparam, - };