# Channel Selection ###### tags: `Openwrt` ## 使用步驟 1. 至 github 連結下載所有檔案。解壓縮後,將所有檔案放到 openwrt上的同一個資料夾底下。 [Channel-Selection-Algorithm](https://github.com/zaqNitori/Channel-Selection-Algorithm) 2. 使用以下指令確認各個實體介面上,虛擬介面的情況。 ``` iw dev ``` * 顯示結果會如下圖所示。 ![](https://hackmd.io/_uploads/ryPAaBEP2.png) ![](https://hackmd.io/_uploads/SyX1CBVPh.png) 3. 在要執行的那個實體介面上(phy0 or phy1),至少要有一個 monitor mode 以及一個non-monitor mode。 ``` iw phy <phyname> interface add <name> type <type> 在 2.4GHz 上新增一個 monitor mode iw phy phy0 interface add moni0 type monitor 介面新增完後記得要啟動它 ifconfig <name> up ``` * 下面的文章會告知要如何透過 iw cmd 來新增/刪除 介面。 [Adding interfaces with iw](http://linuxwireless.sipsolutions.net/en/users/Documentation/iw/__v19.html) 4. 確認資料夾底下應該要有這些內容。 ![](https://hackmd.io/_uploads/rJJi184P2.png) 5. 透過以下指令來進行程式呼叫 ``` ./Channel_Selection.sh -p [-s] [-f] flag: p => 強制需要,用來指定要在哪個實體介面卡上跑 CS演算法。 phy0 for 2.4GHz; phy1 for 5GHz s => 設定每個頻道要掃描幾秒。秒數要給整數,無法使用浮點數。 預設為 1秒。 f => 設定總共要進行幾次 Channel Hopping。 預設為 1次。 ``` ``` 假設要在 2.4GHz上運行,並且每個頻道掃描 2秒,總共跑 3次,則指令下法為: ./Channel_Selection.sh -p phy0 -s 2 -f 3 ``` * 執行時如果有 Permission denied 的錯誤訊息,則將下列程式碼執行一遍: ``` chmod u+x *.sh or chmod u+x Channel_Selection.sh chmod u+x Control_Interface.sh chmod u+x channel_hop.sh ``` 6. 若是執行成功則會看到相關的顯示訊息。同時執行過程中所有的虛擬介面將被關閉,等待程式結束後,會在自動重啟。 ![](https://hackmd.io/_uploads/ryHKG8Ev2.png) ![](https://hackmd.io/_uploads/Bkh9fUVvh.png) ## TCPDUMP with frame type and frame size (Second Version) * Download [tcpdump.exe](https://github.com/zaqNitori/Channel-Selection-Algorithm/blob/main/tcpdump) first. * Check if openwrt original tcpdump package exists or not. If so then uninstall it. ``` opkg list-installed | grep "tcpdump" opkg remove tcpdump ``` * On openwrt command line find PATH directories and put tcpdump.exe under one of the PATH directories. ``` echo $PATH ``` * Check if tcpdump exe file works, should show something like following text ``` tcpdump --version ``` ![](https://hackmd.io/_uploads/H1ns6mLih.png) * Then the tcpdump is installed successfully. ### IF tcpdump.exe cant work then should compile by yourself. * Download [print-802_11.c](https://github.com/zaqNitori/Channel-Selection-Algorithm/blob/main/print-802_11.c) first and replace the original print-802_11.c. **Make sure to clone the tcpdump repo** * Follow [this page](https://openwrt-nctu.gitbook.io/project/openwrt-compile-env/openwrt-cross-compiler) to build cross compiler environment. * Then follow [this note](https://hackmd.io/@zaqNitori/SJrOxba5h) to Compile TCPDUMP at your cross compiler environment.