2.1 概念: 认证/加密
无线加密的多种方法及其区别(WEP WPA TKIP EAP)
以手机上WIFI热点为例,有4种常用的"认证/加密"
a. open
b. WEP
c. WPA(TKIP)
d. WPA2(AES)
2.2 编译、使用iw,wpa_supplicant,dhcp
a. 旧工具iwconfig, iw是它的替代者, 可用于这2种"认证/加密": open, WEP
a.1
tar xzf libnl-3.2.23.tar.gz
cd libnl-3.2.23/
./configure --host=arm-linux --prefix=$PWD/tmp
修改 lib/addr.c 添加宏(宏来自内核源码)
make
make install
把编译出来的头文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
cd tmp/include/libnl3
sudo cp netlink -rf /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
把编译出来的库文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
把编译出来的库文件应该放入NFS文件系统的lib目录:
/work/nfs_root/fs_mini_mdev_new/lib
a.2
tar xjf iw-3.11.tar.bz2
cd iw-3.11/
修改Makefile:
CC = "arm-linux-gcc"
NL3xFOUND := Y
#LIBS += $(shell $(PKG_CONFIG) --libs $(NLLIBNAME))
#CFLAGS += $(shell $(PKG_CONFIG) --cflags $(NLLIBNAME))
在info.c的代码前面添加
#define htole16(X) (((((uint16_t)(X)) << 8) | ((uint16_t)(X) >> 8)) & 0xffff)
使用:
iw list // 列出WIFI网卡的性能
ifconfig wlan0 up
iw dev wlan0 scan // 扫描WIFI AP
iw wlan0 connect dswei // 连接到WIFI AP:dswei (open)
iw wlan0 connect dswei keys d:0:baiwenwang123 // 连接到WIFI AP:dswei (WEP)
d: default, 0: 第0个密码
ifconfig wlan0 192.168.1.55
ping 192.168.1.1
iw wlan0 disconnect
b. wpa_supplicant : 可用于上述4种"认证/加密"
b.1 先编译它的依赖libopenssl
tar xzf openssl-1.0.1d.tar.gz
cd openssl-1.0.1d/
./config shared no-asm --prefix=$PWD/tmp
修改Makefile:
CC= arm-linux-gcc
AR= arm-linux-ar $(ARFLAGS) r
RANLIB= arm-linux-ranlib
NM= arm-linux-nm
MAKEDEPPROG= arm-linux-gcc
make
make install
安装:
把编译出来的头文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
把编译出来的库文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
把编译出来的库文件应该放入NFS文件系统的lib目录:
/work/nfs_root/fs_mini_mdev_new/lib
b.2 要有一个配置文件.config
tar xzf wpa_supplicant-2.0.tar.gz
cd wpa_supplicant-2.0/wpa_supplicant/
cp defconfig .config
修改.config加上一行: CONFIG_LIBNL32=y
修改Makefile:
CC=arm-linux-gcc
make
make DESTDIR=$PWD/tmp install
使用:
mkdir -p /var/run/wpa_supplicant
① OPEN
wpa_supplicant -B -c/etc/plaintext.conf -iwlan0
wpa_cli -iwlan0 status // 查看状态
ifconfig wlan0 192.168.1.55
ping 192.168.1.1
配置文件内容为:
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="dswei"
key_mgmt=NONE
}
② WEP/WEP
wpa_supplicant -B -c/etc/wep.conf -iwlan0
wpa_cli -iwlan0 status // 查看状态
ifconfig wlan0 192.168.1.55
ping 192.168.1.1
配置文件:
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="dswei"
key_mgmt=NONE
wep_key0="baiwenwang123"
wep_tx_keyidx=0
}
③WPA(TKIP)
wpa_supplicant -B -c/etc/wpa-psk-tkip.conf -iwlan0
wpa_cli -iwlan0 status // 查看状态
ifconfig wlan0 192.168.1.55
ping 192.168.1.1
配置文件
ctrl_interface=/var/run/wpa_supplicant # 一个目录,用于wpa_supplicant和wpa_cli的socket通信
network={
ssid="dswei"
proto=WPA # proto: list of accepted protocols, 可取WPA,RSN
# If not set, this defaults to: WPA RSN
key_mgmt=WPA-PSK # 认证方式
# If not set, this defaults to: WPA-PSK WPA-EAP
pairwise=TKIP # If not set, this defaults to: CCMP TKIP
group=TKIP # If not set, this defaults to: CCMP TKIP WEP104 WEP40
psk="baiwenwang12"
}
④ WPA2(AES)
wpa_supplicant -B -c/etc/wpa_wpa2.conf -iwlan0
wpa_cli -iwlan0 status // 查看状态
ifconfig wlan0 192.168.1.55
ping 192.168.1.1
配置文件:
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="dswei"
psk="baiwenwang123"
}
另:
wpa_cli可工作于"命令模式"和"交互模式"
⑤ 配置文件里设置多个network:
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="dswei"
psk="baiwenwang123"
}
network={
ssid="Programer"
psk="baiwenwang"
}
⑥ 访问外网:
修改/etc/resolv.conf添加DNS:
nameserver 192.168.1.1
设置网关:
route add default gw 192.168.1.1