linux-csi-tools部署记录

我采用old installation instruction 的方法,并对里面个别几个地方有所修改,以适应国内有墙的现状。
参考了一部分这个博客
打开终端把代码复制到终端运行即可。

更新_2016/11/08:刚刚看到知乎有人问为什么ping了但是记录不了dat数据,我当时也遇到过这个问题,解决办法就是安装10.04版本的ubuntu。我曾经因为这个问题重装过无数遍ubuntu,最后按照官网的建议安装了10.04版,就成功了,一点困难都没有遇到。不过现在想要安装旧版ubuntu的话,很多软件安装起来可能会费一点劲,大家可以去寻找一下有没有支持这个版本ubuntu的源。
另外去google上一搜,发现居然连我发的这种浏览量少的文章都有人剽窃,csdn上的内容将删掉,以后发到这里。有事email我the0demiurge@yahoo.com

1. 准备工作

我安装了Ubuntu10.04 desktop-i386版,使用的是刻录光盘镜像的方法,大家也可以制作启动u盘或者用虚拟机安装到物理硬盘(我最喜欢的方式)。注意/home分区要留足够的空间(建议10gb以上),/分区也要足够大,建议5gb以上。其他部分很简单,按照安装包的指示一步步来就可以。因为要编译新内核,根目录空间不足的话会不成功。
安装的时候注意几个问题,Linux碎片化严重,用不受支持的linux发行版或版本会导致编译失败,非常令人头疼。而ubuntu lts版支持时间也不长,安装软件的话如果apt用不了可以试着去百度或launchpad找deb包。
对方提供的github网址里面,下载源代码,到右栏可以找到download zip file,下载完毕之后解压放到~/下面,文件夹改名为linux-80211n-csitool
(放到别的地方也可以,不过需要修改下面每一条引用它的代码),由于国内网络环境不好,文件过大,用Git clone的话及其容易失败,其他的小文件没关系,大家自己解决vpn吧,到网上搜索linvpn应该可以用一阵子,不过ubuntu的vpn设置方面有几点需要注意,百度上面也有介绍。
更新:现在比较好用的解决网络问题的方案是lantern和hosts
可以下载我写的这个脚本来使用hosts长期翻墙
    sudo gedit /etc/modprobe.d/blacklist.conf
  • 1
  • 1
把下面内容粘贴进去,保存。
# blacklist modules under active development
        blacklist iwldvm
        blacklist iwlwifi
        blacklist mac80211
        blacklist cfg80211
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5
该步骤是为了禁止wifi,这样做的目的是让安装驱动的时候不容易出问题

2.Install necessary packages on Ubuntu

安装内核组件
sudo apt-get -y install git-core kernel-package fakeroot build-essential ncurses-dev
  • 1
  • 1
它们是用来编译用户空间工具的库
sudo apt-get -y install libnl-dev libssl-dev    # Install some necessary libraries
  • 1
  • 2
  • 1
  • 2
iw可以用来在命令行界面开启wifi的监控模式和开启40mhz信道。
sudo apt-get -y install iw
  • 1
  • 2
  • 1
  • 2

3.Download, configure, compile, and install our custom Linux kernel

下载附加的工具
git clone git://github.com/dhalperi/linux-80211n-csitool-supplementary.git 
  • 1
  • 2
  • 1
  • 2
设置内核
cd linux-80211n-csitool                 # Go into the kernel src directory
make oldconfig                          # Use our optimized kernel config
make menuconfig                         # Enable your system-specific hardware
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
编译内核
make -j3 bzImage modules                # -j3 here is 3-way parallelism, try #cores+1
sudo make install modules_install       # INSTALL
sudo mkinitramfs -o /boot/initrd.img-`cat include/config/kernel.release` \
        `cat include/config/kernel.release`     # create ramdisk used to boot
sudo update-grub
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5
我在这些步骤里面出现了编译错误的情况,原因是里面的一些头文件和源代码文件名大小写不一致,解决方法是想办法把它复制一下,然后改成大小写一致的文件名(原来的不要删掉)
在一篇csdn blog里面,有人还这么说,如果编译出错,可以试着按照这里来做(关于这一部分,先在窗口输入cat include/config/kernel.release(注意是在 linux-80211n-csitool目录下)获取版本号,一般为3.5.7-csitool。将上述指令改为:sudo mkinitramfs -o /boot/initrd.img-3.5.7-csitool 3.5.7-csitool (注意空格)即可。后续的指令中均要将‘cat include/config/kernel.release’改为3.5.7-csitool)
然而这个方法并不好用
下面安装头文件,记录csi的软件需要用它来编译
sudo mkdir /usr/src/linux-headers-`cat include/config/kernel.release`
sudo cp -rf usr/include /usr/src/linux-headers-`cat include/config/kernel.release`/include
  • 1
  • 2
  • 1
  • 2
编译成功之后重启,就会进入修改过的内核

4. Install our custom firmware.

sudo gedit /etc/modprobe.d/blacklist.conf
这一步把blacklist iwlwifi删掉,否则无法连接wifi,删掉之后只能连接没密码的wifi。
运行下面的
#backup original firmware, good for reference
sudo cp /lib/firmware/iwlwifi-5000-2.ucode /lib/firmware/iwlwifi-5000-2.ucode.orig
sudo mv /lib/firmware/iwlwifi-5000-2.ucode /lib/firmware/iwlwifi-5000-2.ucode.orig
# copy ours in separately, keeping name for reference
sudo cp iwlwifi-5000-2.ucode.sigcomm2010 /lib/firmware/
# install ours
sudo cp iwlwifi-5000-2.ucode.sigcomm2010 /lib/firmware/iwlwifi-5000-2.ucode
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
这一步也有点小问题,这里面的文件名可能是有些小问题,如果出错的话,把固件改名,复制到该文件夹里。
我的电脑里面iwlwifi系列如下所示
iwlwifi-1000-3.ucode    iwlwifi-5000-2.ucode.orig
iwlwifi-3945-2.ucode    iwlwifi-5000-2.ucode.sigcomm2010
iwlwifi-4965-2.ucode    iwlwifi-5150-2.ucode
iwlwifi-5000-1.ucode.orig    iwlwifi-6000-4.ucode
iwlwifi-5000-2.ucode 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

5. Download and compile hostap.

At the time of writing, hostap 0.7 is the stable version.
cd                                              # Back out of the kernel tree
git clone git://w1.fi/srv/git/hostap-07.#git      Get the code
cd hostap-07/hostapd
cp <hostap-dotconfig.> config                   # Our hostap config from linux-80211n-csitool-supplementary/hostap-config-files/
make
cp <hostapd.conf-test> hostapd.conf             # Install the vanilla hostap conf we provide
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
这一步没有问题,安装hostapd,把电脑当作access point,功能相当于无线路由器,也可以直接用路由器,省略这一步

6. Install the userspace logging utility.

The userspace netlink tool that logs CSI is located in the supplementary material git at linux-80211n-csitool-supplementary/netlink/.
cd ~/linux-80211n-csitool-supplementary/netlink         # We assume you install into your home directory
make                                                    # hopefully the make succeeds!
# If not, figure out why it didn't compile. Did you install the Linux headers above?
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
编译hostap,实际上这个不编译也没关系,因为有路由器或者安桌手机就可以充当ap
7. Let’s try it out!
sudo modprobe iwlwifi   # did it work?  Do you see logs about iwlwifi in the dmesg?
sudo iwlist scanning    # 扫描ap,窗口中会出现可以扫描到的无线网络。
sudo ~/hostap-07/hostapd/hostapd ~/hostap-07/hostapd/hostapd.conf
# 是启动hostap,此时本机电脑作为ap(相当于路由器的功能)。此时无线网络若还处于连接状态就会出错
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
测试hostap时:
sudo ~/hostap-07/hostapd/hostapd ~/hostap-07/hostapd/hostapd.conf 
  • 1
  • 1
是启动hostap,此时本机电脑作为ap(相当于路由器的功能)。此时无线网络若还处于连接状态就会出错:
所以执行该命令前必须将无线网络连接断开,此时作为路由功能开启(出现结果):
using interface wlan0 with hwaddr 00:21:6a:35:4f:00 and ssid 'csitool-test'
wlan0:STA 38:bc:1a:0d:69:9f IEEE 802.11:authenticated
wlan0:STA 38:bc:1a:0d:69:9f IEEE 802.11:associated(aid 1)
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
手机可以连上‘csitool-test’的网络,状态一直是正在获取ip
Make sure to kill hostapd when you’re done. Then put 802.11n-enabled hostapd config file in place:
cp <hostapd.conf-real> hostapd.conf             # Install the real hostap conf we provide
  • 1
  • 1
采集csi数据部分(关闭本机电脑作为路由的功能,保证连无线网的功能即可,用另一台电脑开启hostapd作为ap):
sudo rmmod iwlwifi mac80211 cfg80211        # remove the modules
sudo modprobe iwlwifi connector_log=0x1      #load the modules and set userspace beamforming logging
#first,associate and set up IP to an AP that will send you HT packets
#需要用另外一台电脑作为ap并设置好IP地址,当前电脑连上那个ap
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
cd ~/linux-80211n-csitool-supplementary/netlink
sudo ./log_to_file tmp.dat                   #当前电脑相当于dp(探测点),log_to_file tmp.dat可以记录csi的值
  • 1
  • 2
  • 1
  • 2
再打开另一个终端(命令行窗口)ping ,ping所连ap的ip地址,ping多次过后便会有csi数据
sudo rmmod iwlwifi mac80211 cfg80211 
sudo modprobe iwlwifi connector_log=0x1
cd ~/wifil/netlink
sudo ./log_to_file  <地址/文件名>
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
最后,使用该软件的时候,现一行一行地把上面代码部分粘贴到terminal里面,再连接没密码的wifi,然后再打开另一个terminal,ping 该ap的ap地址就可以运行
另外,安卓手机ping的ap地址是192.168.43.1
用路由器的话设置成接入点模式。
安装linux-csi-tools的时候还是一年半之前,大一暑假的时候。
文档也是很久之前写的。
现在刚刚把主要用的电脑换成了debian,论文刚被收录,顺便把以前的文档拿出来以免新手和我一样在刚开始走太多弯路。

评论

此博客中的热门博文

Flash被淘汰后打开swf文件的最佳方法

[SOLVED] Supermicro cannot connect to VGA video port or iKVM

MacBook日文键盘四种输入模式输入法切换(同样适用于其他布局的键盘)