usb wifi驱动接收底层硬件数据:
1. hal/hal_hci/hal_usb.c/usb_init_recv_priv()调用tasklet_init,设置数据接收处理函数usb_recv_tasklet()
usb_recv_tasklet() -> recvbuf2recvframe() -> rtw_recv_entry() -> recv_func() -> recv_func_prehandle() -> validate_recv_frame()
2. 在validate_recv_frame()中根据type区分MGT帧、Ctrl帧、Data帧。对于MGT帧,调用validate_recv_mgnt_frame() -> mgt_dispatcher()
3. 在mgt_dispatcher()中根据subtype区分beacon帧、probe帧、action帧、auth帧、assoc帧等
驱动接收到底层硬件数据之后,一种情况是自己处理掉,一种情况是向上层传递。
驱动上传数据方式:
1. napi方式:混合使用中断和轮询,比netif_rx新,效率高。
2. netif_rx方式:中断处理方式,通过netif_rx() -> netif_rx_schedule()触发软中断NET_RX_SOFTIRQ,调用net_rx_action() -> poll() -> netif_receive_skb() -> func()[ip_rcv() ...]
3. cfg80211方式:如cfg80211_rx_mgmt()
wpa_supplicant接收数据
wpa_supplicant通过nl80211与驱动中的cfg80211通过netlink socket通信,使用libnl库。
1. wpa_supplicant中通过nl_cb_set()设置的回调函数process_bss_event()
2. process_bss_event() -> mlme_event()根据不同的类型(如auth、assoc、frame、status等)进入不同路线
3. 以frame(NL80211_CMD_FRAME)为例:mlme_event() -> mlme_event_mgmt() -> wpa_supplicant_event(EVENT_RX_MGMT)
4. events.c/wpa_supplicant_event()根据不同的event类型,如EVENT_AUTH,EVENT_ASSOC,EVENT_RX_MGMT等进行不同处理
5. 以EVENT_RX_MGMT为例,wpa_supplicant_event()再根据子类型进入不同路线,如probe,action等。
wpa_supplicant发送数据
1. 初始化时设置struct p2p_config的接口函数,如p2p.send_probe_resp = wpas_send_probe_resp等
2. send_probe_resp() -> wpas_send_probe_resp() -> driver的send_mlme() -> driver_nl80211_send_mlme() -> nl_send_auto_complete()
usb wifi驱动接收上层协议栈数据:
1. 驱动初始化时调用rtw_wdev_alloc()设置cfg80211接口struct cfg80211_ops
2. 协议栈调用接口如mgmt_tx() -> cfg80211_rtw_mgmt_tx() -> _cfg80211_rtw_mgmt_tx() -> dump_mgntframe_and_wait_ack() -> rtw_hal_mgnt_xmit()
wpa_supplicant设备查找:
1. wpa_cli发送命令:wpa_cli.c/wpa_cli_cmd_p2p_find() -> "P2P_FIND"
2. wpa_supplicant接收命令:ctrl_iface.c/wpa_supplicant_ctrl_iface_process() -> p2p_ctrl_find() -> wpas_p2p_find() -> p2p_supplicant.c/p2p_find() -> p2p->cfg->p2p_scan()
3. p2p_supplicant.c/wpas_p2p_init()/p2p.p2p_scan=wpas_p2p_scan() -> radio_add_work(wpas_p2p_trigger_scan_cb)
wpas_p2p_trigger_scan_cb()
wpa_drv_scan()
wpa_s->driver->scan2()/driver_nl80211_scan2() -> wpa_driver_nl80211_scan()
send_and_recv_msgs() // 触发驱动扫描
驱动事件:wpa_supplicant_event(EVENT_SCAN_STARTED)
eloop_register_timeout(wpa_driver_nl80211_scan_timeout)
Timer事件:wpa_supplicant_event(EVENT_SCAN_RESULTS)
wpa_supplicant_event_scan_results() -> _wpa_supplicant_event_scan_results()
scan_res = wpa_supplicant_get_scan_results()
wpa_drv_get_scan_results2()
wpa_s->driver->get_scan_results2()/wpa_driver_nl80211_get_scan_results()
filter_scan_res()
wpa_bss_update_scan_res() // 注意这里P2P的probe requst不会更新到bss链表中
wpa_s->scan_res_handler(scan_res)=wpas_p2p_scan_res_handler(scan_res) // 在wpas_p2p_trigger_scan_cb中设置的
p2p_scan_res_handler()
p2p_scan_res_handled()
p2p_notify_scan_trigger_status()
eloop_register_timeout(p2p_scan_timeout)
wpa_s->scan_res_handler = wpas_p2p_scan_res_handler