OpenWrt之上wifi探針簡單實現

之前一直在rt2860v2上面做探針數據捕獲和試驗,並沒有基於社區的驅動做過,應該也不是特別麻煩,netlink可以沿用以前的,只要找到802.11驅動裏面幀解析的地方就可以了,直接通過netlink把數據broadcast到應用層,應用層還是採用之前的接收模塊來接收即可,之前的接收模塊代碼:

https://github.com/lixuande/rt2860v2-detect-user

現在數據獲取的代碼:

https://github.com/lixuande/wifidetect-openwrt

probe幀數據捕獲

要找到驅動裏面probe幀捕獲的接口,就要簡單瞭解一下linux下無線驅動的實現,這篇文章講的相對詳細一些:

https://blog.csdn.net/zimiao815/article/details/55511338

我們要做的其實只是在接收幀的處理接口捕獲probe就足夠了,重點關注處理rx數據的handle,在對應的rx.c中有接口:

__ieee80211_rx_handle_packet

對應的函數說明也比較明顯:

/*
 * This is the actual Rx frames handler. as it belongs to Rx path it must
 * be called with rcu_read_lock protection.
 */
static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
					 struct sk_buff *skb,
					 struct napi_struct *napi)

這個接口就是實際的rx幀處理接口。
在接口中添加我們想要的處理函數:

if (ieee80211_is_probe_req(fc)){ //added by lixuande 20180902
		struct ieee80211_rx_status *sta = IEEE80211_SKB_RXCB(skb);
		
		wifi_detect detect;
			
		detect.subtype = 4;
		detect.frametype = 2;
		detect.rssi0 = (128 - sta->signal);
		detect.rssi1 = sta->signal;
		detect.rssi2 = sta->signal;
		
		send_detectdata_to_user(hdr->addr2, detect);
	}

send_detectdata_to_user是後面通過內核向用戶態發送探針數據的接口。這裏的subtype和frametype是爲了和rt2860v2中的幀格式保持一致,表示管理幀中的probe幀。

幀數據發送

幀數據的發送採用netlink方式。
最初在rt2860v2之上採用過proc節點與用戶態交互數據,問題較多,主要是無法多個應用同時獲取數據,還是netlink更合適一些。
netlink可以理解爲內核態的socket連接,採用的是異步通信方式,支持多播模式,一個內核模塊可以將詳細廣播給多個應用模塊,只要每個應用去監聽對應的netlink協議枚舉就可以。
netlink的代碼放在:

https://github.com/lixuande/wifidetect-openwrt

對於netlink初始和退出的接口:

int rt_netlink_init(void);
int rt_netlink_exit(void);

仿照之前rt2860v2,放在mac80211驅動初始化接口中即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章