# Installation of Linux 802.11n CSI Tool in Ubuntu 14.04.2 & Visualization of CSI signals in real-time ## 1. Introduction - This page is written for recording the correct(my) steps of installation Linux 80211n CSI Tool and some errors I've met. After installation, I furthermore tried to visualize the CSI signals in real-time. Here is a example figure. ![](https://i.imgur.com/mQy855u.png) ## 2. Environment Preparation: - Operating System: Ubuntu14.04.2 (kernel 4.15) - Wireless Network Interface Card: Intel 5300 - Wifi Router: TP-Link Archer C9 - Install dual system in Windows10 if you need: - Use `rufus.exe` to transfer the .iso file into USB - Basically follow https://www.youtube.com/watch?v=yMHOpOuyjdc&ab_channel=%E5%A2%9E%E5%BB%A3%E5%BB%BA%E6%96%87 :::danger Don't try to use a virtual machine. The wireless NIC works differently on any virtual machine and you will never get the CSI signals. ::: ## 3. Installation of CSI tool - First, install some essential packages. ```c= sudo apt-get install gcc make linux-headers-$(uname -r) git-core apt-get install linux-headers-$(uname -r) //I really typed this command again. apt-get install aptitude && aptitude install dh-autoreconf apt install libelf-dev ``` - Download the tool and Install the Modified Wireless Driver. ```c= CSITOOL_KERNEL_TAG=csitool-$(uname -r | cut -d. -F 1-2) git clone https://github.com/dhalperi/linux-80211n-csitool.git cd linux-80211n-csitool git checkout ${CSITOOL_KERNEL_TAG} make -C /lib/modules/$(uname -r)/build M=$(pwd)/drivers/net/wireless/iwlwifi modules sudo make -C /lib/modules/$(uname -r)/build M=$(pwd)/drivers/net/wireless/iwlwifi INSTALL_MOD_DIR=updates modules_install sudo depmod ``` - After install the driver, install the modified firmware. ```c= cd .. git clone https://github.com/dhalperi/linux-80211n-csitool-supplementary.git for file in /lib/firmware/iwlwifi-5000-*.ucode; do sudo mv $file $file.orig; done sudo cp linux-80211n-csitool-supplementary/firmware/iwlwifi-5000-2.ucode.sigcomm2010 /lib/firmware/ sudo ln -s iwlwifi-5000-2.ucode.sigcomm2010 /lib/firmware/iwlwifi-5000-2.ucode make -C linux-80211n-csitool-supplementary/netlink ``` - Now, you've already completed the installation. And next is to activate the driver. ```c= sudo modprobe -r iwlwifi mac80211 sudo modprobe iwlwifi connector_log=0x1 sudo killall wpa_supplicant ``` :::info You need to type those three commands every time you reboot the computer. And with this tool, you can only connect to unencrypted wifi. ::: ### 3-1. Problems I've met during installation: - The first problem I've met is that compared to [the official installation instructions](https://dhalperi.github.io/linux-80211n-csitool/installation.html), in activating the driver, there are only two commands, `sudo modprobe -r iwlwifi mac80211` and `sudo modprobe iwlwifi connector_log=0x1`. After typing the second command, I can't connect to any unencrypted wifi. Therefore I added the third command, and I successed to connect unencrypted wifi. - The second problem is that after I typed the three commands above, I tried to log CSI signals. But it turned out nothing happened. In [official installation instructions](https://dhalperi.github.io/linux-80211n-csitool/installation.html), during installing essential packages, it only contains `sudo apt-get install gcc make linux-headers-$(uname -r) git-core`. After I added those three commands below in the beginning, it worked out! Furthermore, those three commands can solve the problem, "Can't read private key" which is mentioned in [official installation instructions](https://dhalperi.github.io/linux-80211n-csitool/installation.html). ```c= apt-get install linux-headers-$(uname -r) //I really typed this command again. apt-get install aptitude && aptitude install dh-autoreconf apt install libelf-dev ``` :::info Noted that during the installation, I didn't reboot the computer. ::: ### 3-2. References 1. https://blog.krybot.com/a?ID=fa6c25bf-b8b2-4f3b-bc71-9646bd026f9a 2. https://dhalperi.github.io/linux-80211n-csitool/installation.html 3. https://blog.csdn.net/zhangpeterx/article/details/88044404 ## 4. How to use the tool - First, you need to check the IP of your gateway(router). You can use this command and it'll return the informations of the connection: ```c= route -n ``` In my situation, my gateway IP is 192.168.0.1 . - Next, open a terminal A. Type this command: ```c= sudo linux-80211n-csitool-supplementary/netlink/log_to_file csi.dat ``` - Open another terminal B. Type this command: ```c= sudo ping 192.168.0.1 -i 0.05 ``` After you typied those two command, it should start writing the CSI signals. :::info Noted that `-i 0.05` is used to control the frequency of ping. 0.05 means every 0.05 second, transmit a packet. ::: ## 5. How to visualize the signals in real-time - In my case, I use one computer and one wifi router. And my matlab version is 2014b. - First, download the visualization tool: ```c= git clone https://github.com/lubingxian/Realtime-processing-for-csitool sudo cp ./Realtime-processing-for-csitool/matlab/read_bf_socket.m ./linux-80211n-csitool-supplementary/matlab/ sudo cp ./Realtime-processing-for-csitool/netlink/log_to_server.c ./linux-80211n-csitool-supplementary/netlink/ cd linux-80211n-csitool-supplementary/netlink gcc log_to_server.c -o log_to_server ``` - Next, open Matlab. Type those command in matlab. ```c= cd ./linux-80211n-csitool-supplementary/matlab/ read_bf_socket ``` After typing the command above, it will output "waiting for connection on port 8090." - Meanwhile, open a terminal A, type this command: ```c= sudo ping 192.168.0.1 -i 0.05 ``` - Next, open another terminal B, type this command: ```c= sudo ./linux-80211n-csitool-supplementary/netlink/log_to_server 127.0.0.1 8090 ``` Now, you should see the real-time change of CSI signals in matlab. ### 5-1. Problems I've met during visualizing CSI signals: - The first problem is that after I installed the matlab, I couldn't open matlab. It stucked in opening page. And my solution is reinstall the matlab. Then it worked out. - The second is that I followed the steps of the reference in the beginning. In step 2, I can't run `read_bf_socket` in matlab. It outputs error which is "undefined function read_bfee....". And my solution is copying the `read_bf_socket.m` file to the route `./linux-80211n-csitool-supplementary/matlab/`, and run `read_bf_socket` in matlab again, it works out. :::info In the beginning of this website, you can see a example figure. There are green, red, and blue lines. Each color represents one channel. There ten different lines of each color. It means ten packets recieved recently in one channel. In the code of `read_bf_socket.m`, `line 93` decides how many packets you want to show. Also, there is an annotation at `line 98`. ::: ### 5-2. Reference 1. https://blog.csdn.net/u014645508/article/details/82887470