marsh-fish
是否可以提供 Ad-hoc (IBSS) mode 的實作程式碼?
有關 Ad-hoc (IBSS) mode 相關程式碼的更新可見 Support ad hoc network #70
jychen0611
dcciou
請問是否知道封包的傳遞錯誤率
據我所知,目前 iw 相關命令無法提供 BER (bit error rate) 的相關底層傳輸資訊,但能透過 iw dev vw_i link 得知封包傳遞接收的數量及 byte 數統計。若想用模擬的方式推得 BER ,則須考量SNR (signal-to-noise ratio)、編碼模式、距離、阻擋等因素。可見 What is the relation between Bit Error Rate (BER), distance d and SNR(dB)?
jychen0611
vwifi 是個程式碼約~三千行,具體而微的 WiFi 裝置驅動程式,採用 cfg80211 框架。目前 vwifi 支援 scan, connect, disconnect 等 cfg80211 的介面操作,並得以正確處理 Tx/Rx 封包。
commit 5add321 "wifi: cfg80211: remove scan_width support"
kernel version : v6.9-rc6 ~ v6.7-rc1
date : Sep 13, 2023
There really isn't any support for scanning at different channel widths than 20 MHz since there's no way to set it.
Remove this support for now, if somebody wants to maintain this whole thing later we can revisit how it should work.
beacon [bee-kuhn]
a guiding or warning signal, as a light or fire, especially one in an elevated position.
在此指用來傳遞 BSS (Basic Service Set) 的相關訊息的 management frame,使其他無線裝置能得知該 BSS 的存在。
A beacon frame is a type of management frame in IEEE 802.11 WLANs. It contains information about the network. Beacon frames are transmitted periodically; they serve to announce the presence of a wireless LAN and to provide a timing signal to synchronise communications with the devices using the network (the members of a service set).
In an infrastructure basic service set (BSS), beacon frames are transmitted by the access point (AP).
In ad hoc (IBSS) networks, beacon generation is distributed among the stations.
commit bb55441 "wifi: cfg80211: split struct cfg80211_ap_settings"
kernel version : v6.9-rc6 ~ v6.7-rc1
date : Sep 25, 2023
Using the full struct cfg80211_ap_settings for an update is misleading, since most settings cannot be updated. Split the update case off into a new struct cfg80211_ap_update.
commit 66f85d5 "wifi: cfg80211: modify prototype for change_beacon"
kernel version : v6.9-rc6 ~ v6.7-rc1
date : Sep 13, 2023
Modify the prototype for change_beacon() in struct cfg80211_op to accept cfg80211_ap_settings instead of cfg80211_beacon_data so that it can process data in addition to beacons.
Modify the prototypes of ieee80211_change_beacon() and driver specific functions accordingly.
Simply put, the change_beacon function now includes two additional parameters, fils_discovery and unsol_bcast_probe_resp, which are part of the cfg80211_ap_update structure.
閱讀《802.11 Wireless Networks: The Definitive Guide, 2/e》建立基礎概念
〈Lightweight and Fast WiFi Access in Virtual Machines〉, Open Source Summit Europe 2023
ref :
WI-FI 7 MCS TABLE
MCS Table
採用 802.11n (HT) 做為 PHY,設置如下 :
Modulation : 64-QAM
Data Bandwidth : 20MHz
Number of Spatial Streams : 4
參照 802.11n (HT) 調變對照表可得
Number of Data Subcarriers : 52
Number of Coded Bits per Subcarrier per Stream : 6
Coding : 5/6
OFDM Symbol Duration : 3.2 us
Guard Interval Duration : 0.8 us
即
經公式推算後可得 data rate = 260 Mbps 與顯示結果相符
在結構體 vwifi_vif
上新增 tx_power
以描述裝置的傳輸功率。
在 cfg80211_ops
的架構上新增 vwifi_set_tx_power
及 vwifi_get_tx_power
用以設定和取得裝置的功率。
使用者可透過 iwconfig [interface] txpower [transmit power (dBm)] 設定裝置傳輸功率。
以下命令將 vw0
的傳輸功率設為 11 dBm
為了維持命令一致性,必須支援 iw 命令設置 transmit power。
由於使用 iw 命令會導致 set_tx_power
的輸入參數 wdev
為 NULL,詳見
cfg80211: allow per interface TX power setting
The TX power setting is currently per wiphy (hardware
device) but with multi-channel capabilities that doesn't
make much sense any more.Allow drivers (and mac80211) to advertise support for
per-interface TX power configuration. When the TX power is configured for the wiphy, the wdev will be NULL and the driver can still handle that, but when a wdev is given the TX power can be set only for that wdev now.
Signed-off-by: Johannes Berg johannes.berg@intel.com
因此新增函式 wiphy_get_vwifi_vif
以利用參數 wiphy
取得裝置的 virtual interface。
此外,亦利用參數 type
以區別命令為 auto/limit/fixed。
使用者可使用 iw dev [interface] set txpower [auto/limit/fixed] [transmit power (mBm)] 來設定。
以下命令將 vw0
的傳輸功率設為 1100 mBm (即 11 dBm)
在 wiphy
上新增 NL80211_IFTYPE_ADHOC
interface type,使其能透過 vwifi_change_iface
的 operation 切換成 Ad-hoc (IBSS) 模式。
使用者可透過命令 iw dev [interface] set type ibss 將裝置切換成 IBSS 模式。
在 cfg80211_ops
的架構上新增 vwifi_join_ibss
及 vwifi_leave_ibss
使 IBSS 裝置能加入特定 IBSS cell 及頻段。
使用者可透過命令 iw dev [interface] ibss join [SSID] [freq in MHz] [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>] [basic-rates <rate in Mbps,rate2,…>] [mcast-rate <rate in Mbps>] [key d:0:abcde] 加入特定 IBSS cell 並同時建置其它設定。若此 IBSS cell 原先不存在則創建之。
以下命令使 vw3
加入 SSID 為 ibss1
的 IBSS cell,且指定頻段為 2412 MHz。
若要離開目前的 IBSS cell,則可使用 iw dev [interface] ibss leave
在 vwifi_join_ibss
中應紀錄 AD-HOC 之相關設定。
紀錄 AD-HOC 相關資訊的結構體定義在 virtual interface 中。
在全域結構體 vwifi_context
中新增 ibss_list
以便尋找 ibss 裝置,當裝置 join 後便會被加入 ibss_list
,若裝置 leave 則會被移出。
在轉送前要確認 source 和 destination 是否處於相同 IBSS cell,以及確認是否在該 IBSS cell 的同個 BSS 中。
vw3
, vw4
, vw5
皆在同 IBSS cell 中,讓 vw3
ping vw4
,可發現封包正常傳遞。
觀察核心訊息可發現在 vw3
的 ARP cache 中原先無 10.0.0.5
對應的 mac address。
因此流程如下:
vw3
會先發送 ARP Request 封包 (broadcast) 請求 10.0.0.5
對應的 mac address。vw4
會回傳 ARP Reply (內含 vw4 的 mac address),vw5 則無視之。vw3
收到 vw4
回傳的 ARP Reply 後,再進行 ICMP 封包傳遞 (Ping Request)。vw4
收到 vw3
的 Ping Request 後,回傳 Ping Reply。vw3
和 vw5
處於不同 IBSS cell,讓 vw3
ping vw5
,如預期般失敗,原因在於兩者處於不同 IBSS,無法通訊。
觀察核心訊息可發現, vw3
三度嘗試用 ARP Request 請求 mac address,但沒有裝置回應。
vw3
為 IBSS mode, vw2
則為 STA mode,讓 vw3
ping vw2
,如預期般失敗。
如同測試二,vw3
三度嘗試用 ARP Request 請求 mac address,但沒有裝置回應。
執行 scan 可發現該 bss 資訊
建立設定檔 wpa_supplicant_ibss.conf
使用命令 wpa_supplicant 設定 vw3
和 vw4
加入 ibss1
觀察 interface 資訊可發現兩者皆成功加入 ibss1
仔細觀察核心訊息可發現一開始 ibss1
不存在,於是 vw3
創建之。而 vw4
透過掃描得知 ibss1
的存在,並加入之。
值得注意的一點是,使用 WPA 創建 ibss 網路,其 BSSID 應由系統自動生成 (這樣可確保了每個 IBSS 網路的唯一性),因此並不會出現在 join
函式的輸入參數中。
因此當 join
參數的 BSSID 為 NULL 時,應比對當前存在的 ibss 網路。若有符合其 WPA 設定則沿用 BSSID ,否則以當前裝置的 MAC address 作為新網路的 BSSID。
嘗試讓 vw3
ping vw4
,封包傳遞成功。
vw5
以手動方式創建並加入 ibss2
, vw3
和 vw4
則以 WPA 設定加入 ibss1
。
觀察核心訊息可發現,由於 vw5
先創建 ibss2
,所以 vw3
一開始設定時會掃描到 ibss2
,然而這並不符合 vw3
的 WPA 設定。於是 vw3
會自己創建一個 ibss1
。隨後 vw4
也會進行掃描,並同時發現 ibss1
和 ibss2
,選擇 ibss1
加入之。
讓 vw3
ping vw5
,很明顯無法傳遞封包。
2022q1 vwifi
Linux 核心專題: vwifi
Lightweight and Fast WiFi Access in Virtual Machines
802.11 Wireless Networks: The Definitive Guide, 2/e
LKMPG
cfg80211_ops
WI-FI 7 MCS TABLE
MCS Table
iw commands