轉(zhuǎn)zz:cfg80211的kernel架構(gòu)(基于Linux 3.08)之sta
2, 幾個(gè)主要流程 a) malloc & init(softmac) 內(nèi)存分布
struct wiphy
struct ieee80211_local
Driver private class
結(jié)構(gòu)體關(guān)系
初始化順序 module_init,注冊(cè)xxxx_driver_ops xxxx_probe,各種資源初始化。 ieee80211_alloc_hw,兩個(gè)參數(shù)分別為mac80211_config_ops和private class的size wiphy_new分配整塊內(nèi)存,wiphy_new里面初始化cfg80211_registered_device的一些成員 初始化ieee80211_local各個(gè)成員,并將wiphy.priv指向ieee80211_local ieee80211_local偏移到末尾,指針指向private class,并且保留在ieee80211_local.hw.priv 初始化private class ieee80211_register_hw,實(shí)現(xiàn)mac80211硬件的注冊(cè) wiphy_register添加dev(device_add),以及一些sanity檢測(cè) 并且初始化channel,iface以及wep等。 調(diào)用ieee80211_if_add添加一個(gè)wlan0,類型為sta的net_device,并且給該net_device分配一塊私有數(shù)據(jù)區(qū):ieee80211_sub_if_data,已經(jīng)實(shí)現(xiàn)了一套net_device_ops
b) beacon frame 接收流程
對(duì)于管理幀,通常是ieee80211_rx_handlers調(diào)用ieee80211_rx_h_mgmt,然后用wq的方式調(diào)用ieee80211_iface_work進(jìn)一步調(diào)用ieee80211_sta_rx_queued_mgmt去處理。
beacon響應(yīng)流程
TIM IE:
E-id | length | DTIM count | DTIM period | Bitmap control | PVM(1-256byte)
remain to investigate: how passive scan is implemented by beacon?
c) scan
d) auth and associate wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME
true): sme_authenticate->wpa_driver_nl80211_authenticate...->cfg80211_mlme_auth false):? wpa_drv_associate->wpa_driver_nl80211_connect...->cfg80211_mlme_auth
assoc成功之后會(huì)調(diào)用driver的set_key函數(shù)update key, 一般是放到wifi芯片某個(gè)管腳對(duì)應(yīng)的緩存區(qū)域,從而實(shí)現(xiàn)硬件加密(與xmit skb緩存區(qū)進(jìn)行與或,eg)。
具體函數(shù)棧流程如下:
點(diǎn)擊(此處)折疊或打開
nl80211_connect????cfg80211_connect(after scan?and?have bbs)
????????cfg80211_conn_do_work
????????????__cfg80211_mlme_auth
????????????????rdev->ops->auth(&rdev->wiphy,?dev,?&req);
CallBack by rx irq:
ieee80211_rx_irqsafe
ieee80211_tasklet_handler
????ieee80211_rx
????????__ieee80211_rx_handle_packet
????????????ieee80211_prepare_and_rx_handle
????????????????????ieee80211_invoke_rx_handlers
????????????????????????ieee80211_rx_handlers
????????????????????????????ieee80211_rx_h_mgmt
Queuework:
ieee80211_iface_work(iface.c)
????ieee80211_sta_rx_queued_mgmt
????????ieee80211_rx_mgmt_auth
????????cfg80211_send_rx_auth
????????????nl80211_send_rx_auth(告訴用戶空間)
????????????cfg80211_sme_rx_auth
????????????????schedule_work(&rdev->conn_work)
Queuework:
cfg80211_conn_work
????__cfg80211_mlme_assoc
????????rdev->ops->assoc
CallBack by rx irq
....
ieee80211_sta_rx_queued_mgmt
????ieee80211_rx_mgmt_assoc_resp
????????ieee80211_assoc_success
????????????ieee80211_sta_rx_notify
????????????????通過(guò)timer定時(shí)觸發(fā) ieee80211_mgd_probe_ap_send
????????????????發(fā)送nullfunction或者probe_req
????cfg80211_send_rx_assoc
????????????nl80211_send_rx_assoc(告訴用戶空間)
????????????__cfg80211_connect_result
????????????????nl80211_send_connect_result
????????????????cfg80211_upload_connect_keys
????????????????????rdev->ops->add_key e) rx/tx data rx:
xmit:
e) csa 1)beacon 2)action幀
沒(méi)連上,正在scan,不用管
手頭有任務(wù),先把手頭任務(wù)做完,然后斷開連接
手頭沒(méi)任務(wù),調(diào)用driver的channel_switch(回調(diào)實(shí)現(xiàn)后面的改chan值)或者h(yuǎn)w_config函數(shù),然后把local的chan值改一下
f) missing
some details: off channel,
3, wifi driver部分之bcmdhd a) init(施工ing)b) fireware load(施工ing)
原文地址:http://blog.chinaunix.net/uid-27167114-id-3783603.html