轉zz:cfg80211的kernel架構(基于Linux 3.08)之sta
2, 幾個主要流程 a) malloc & init(softmac) 內存分布
struct wiphy
struct ieee80211_local
Driver private class
結構體關系
初始化順序 module_init,注冊xxxx_driver_ops xxxx_probe,各種資源初始化。 ieee80211_alloc_hw,兩個參數分別為mac80211_config_ops和private class的size wiphy_new分配整塊內存,wiphy_new里面初始化cfg80211_registered_device的一些成員 初始化ieee80211_local各個成員,并將wiphy.priv指向ieee80211_local ieee80211_local偏移到末尾,指針指向private class,并且保留在ieee80211_local.hw.priv 初始化private class ieee80211_register_hw,實現mac80211硬件的注冊 wiphy_register添加dev(device_add),以及一些sanity檢測 并且初始化channel,iface以及wep等。 調用ieee80211_if_add添加一個wlan0,類型為sta的net_device,并且給該net_device分配一塊私有數據區(qū):ieee80211_sub_if_data,已經實現了一套net_device_ops
b) beacon frame 接收流程
對于管理幀,通常是ieee80211_rx_handlers調用ieee80211_rx_h_mgmt,然后用wq的方式調用ieee80211_iface_work進一步調用ieee80211_sta_rx_queued_mgmt去處理。
beacon響應流程
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成功之后會調用driver的set_key函數update key, 一般是放到wifi芯片某個管腳對應的緩存區(qū)域,從而實現硬件加密(與xmit skb緩存區(qū)進行與或,eg)。
具體函數棧流程如下:
點擊(此處)折疊或打開
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
????????????????通過timer定時觸發(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幀
沒連上,正在scan,不用管
手頭有任務,先把手頭任務做完,然后斷開連接
手頭沒任務,調用driver的channel_switch(回調實現后面的改chan值)或者hw_config函數,然后把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





