1、wireless-tools测试不加密AP

1.      从www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html 下载wireless_tools.30.pre9.tar.gz, 此版本支持non-ASCII char in ESSID

2.      解压到mydroid/external/wireless-tools目录

3.      创建Android.mk,内容如下

LOCAL_PATH:= $(call my-dir)
################## build iwlib ###################
include $(CLEAR_VARS)
LOCAL_SRC_FILES := iwlib.c
LOCAL_CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Winline -MMD -fPIC
LOCAL_MODULE:= libiw
LOCAL_STATIC_LIBRARIES := libcutils libc libm
include $(BUILD_STATIC_LIBRARY)
################## build iwconfig ###################
include $(CLEAR_VARS)
LOCAL_SRC_FILES := iwconfig.c
LOCAL_CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Winline -MMD -fPIC
LOCAL_MODULE:= iwconfig
LOCAL_STATIC_LIBRARIES := libcutils libc libm libiw
#LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbin
#LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
#LOCAL_MODULE_TAGS := eng user
include $(BUILD_EXECUTABLE)
################## build iwlist ###################
include $(CLEAR_VARS)
LOCAL_SRC_FILES := iwlist.c iwlib.h
LOCAL_CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Winline -MMD -fPIC
LOCAL_MODULE:= iwlist
LOCAL_STATIC_LIBRARIES := libcutils libc libm libiw
#LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbin
#LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
#LOCAL_MODULE_TAGS := eng user
include $(BUILD_EXECUTABLE)

4.      修改
将wireless.22.h 更名为wireless.h
修改ifrename.c 增加getline的函数,代码可以从external/genext2fs/genext2fs.c中获得,注意里边是用宏把另一个函数传给getline
修改iwlib.h,将#include <net/ethernet.h>改为#include <net/if_ether.h>

5.      编译
robin@robin-virtual-machine:~/mydroid/external/wireless-tools$ . ../../build/envsetup.sh 
robin@robin-virtual-machine:~/mydroid/external/wireless-tools$ mm


编译出错:

external/wireless_tools.29/iwlist.c: In function 'print_scanning_info':
external/wireless_tools.29/iwlist.c:633:7: error: 'IW_EV_LCP_PK2_LEN' undeclared (first use in this function)
external/wireless_tools.29/iwlist.c:633:7: note: each undeclared identifier is reported only once for each function it appears in
external/wireless_tools.29/iwlist.c:633:50: error: 'IW_EV_POINT_PK2_LEN' undeclared (first use in this function)
make: *** [out/target/product/sabresd_6dq/obj/EXECUTABLES/iwlist_intermediates/iwlist.o] Error 1

解决办法:

1> 在wireless.h最后添加以下两句:

#undef IW_EV_LCP_PK_LEN
#undef IW_EV_POINT_PK_LEN
2>在Android.mk中删除iwlib.h

################## build iwlist ###################
include $(CLEAR_VARS)
LOCAL_SRC_FILES := iwlist.c #iwlib.h

重新mm

robin@robin-virtual-machine:~/workspace/sources/android_kk4.4.2/external/wireless_tools.29$ mm
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.4.2
TARGET_PRODUCT=sabresd_6dq
TARGET_BUILD_VARIANT=user
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a9
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.2.0-23-generic-x86_64-with-Ubuntu-12.04-precise
HOST_BUILD_TYPE=release
BUILD_ID=1.0.0-rc3
OUT_DIR=out
============================================
No private recovery resources for TARGET_DEVICE sabresd_6dq
make: Entering directory `/home/robin/workspace/sources/android_kk4.4.2'
target thumb C: libiw <= external/wireless_tools.29/iwlib.c
target StaticLib: libiw (out/target/product/sabresd_6dq/obj/STATIC_LIBRARIES/libiw_intermediates/libiw.a)
target thumb C: iwconfig <= external/wireless_tools.29/iwconfig.c
target Executable: iwconfig (out/target/product/sabresd_6dq/obj/EXECUTABLES/iwconfig_intermediates/LINKED/iwconfig)
target Symbolic: iwconfig (out/target/product/sabresd_6dq/symbols/system/xbin/iwconfig)
target Strip: iwconfig (out/target/product/sabresd_6dq/obj/EXECUTABLES/iwconfig_intermediates/iwconfig)
Install: out/target/product/sabresd_6dq/system/xbin/iwconfig
target thumb C: iwlist <= external/wireless_tools.29/iwlist.c
target Executable: iwlist (out/target/product/sabresd_6dq/obj/EXECUTABLES/iwlist_intermediates/LINKED/iwlist)
target Symbolic: iwlist (out/target/product/sabresd_6dq/symbols/system/xbin/iwlist)
Export includes file: external/wireless_tools.29/Android.mk -- out/target/product/sabresd_6dq/obj/EXECUTABLES/iwlist_intermediates/export_includes
target Strip: iwlist (out/target/product/sabresd_6dq/obj/EXECUTABLES/iwlist_intermediates/iwlist)
Install: out/target/product/sabresd_6dq/system/xbin/iwlist
make: Leaving directory `/home/robin/workspace/sources/android_kk4.4.2'

编译通过在out/target/product/sabresd_6dq/symbols/system/xbin中生成了iwconfig和iwlist


6.重新编译system.img烧入板子

robin@robin-virtual-machine:make snod


7.上电测试

由于wireless_tools只能测试未加密的热点,所以手机分享热点后

root@sabresd_6dq:/ # iwlist wlan0 scanning
[ 2252.051232] CFG80211-ERROR) wl_notify_scan_status : scan is not ready 
wlan0     Scan completed :
          Cell 01 - Address: 02:1A:11:F0:F0:1F
                    ESSID:"MI 3"
                    Mode:Managed
                    Frequency:2.437 GHz (Channel 6)
                    Quality:3/5  Signal level:-69 dBm  Noise level:-92 dBm
                    Encryption key:off
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                              24 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 9 Mb/s
                              12 Mb/s; 48 Mb/s
          Cell 02 - Address: 80:89:17:DE:6D:9A
                    ESSID:"kejidasha"
                    Mode:Managed
                    Frequency:2.452 GHz (Channel 9)
                    Quality:0/5  Signal level:-92 dBm  Noise level:-92 dBm
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: WPA Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    Encryption key:on
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
                              48 Mb/s; 54 Mb/s
          Cell 03 - Address: CC:34:29:16:85:28
                    ESSID:"TP-LINK_AUTO"
                    Mode:Managed
                    Frequency:2.452 GHz (Channel 9)
                    Quality:1/5  Signal level:-80 dBm  Noise level:-92 dBm
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD310050F204104A00011010440001021047001000000000000010000000CC3429168528103C0001011049000600372A000120
                    IE: WPA Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    Encryption key:on
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
                              48 Mb/s; 54 Mb/s
可以看到附近很多热点 ,第一个就是我手机分享的热点--------------ESSID:"MI 3"

//连接热点
root@sabresd_6dq:/ # iwconfig wlan0 essid "MI 3"    
root@sabresd_6dq:/ # 
[ 2394.435038] wl_bss_connect_done succeeded with 02:1a:11:f0:f0:1f
[ 2394.455820] wl_notify_connect_status nothing
[ 2394.460479] wl_bss_connect_done succeeded with 02:1a:11:f0:f0:1f

//分配IP
root@sabresd_6dq:/ # ifconfig wlan0 192.168.43.100 netmask 255.255.255.0 up (静态分配ip,
         也可以动态分配,用DHCP)

//提示连接成功,用busybox ifconfig -a 可以看到分配的IP号了

root@sabresd_6dq:/ # busybox ifconfig -a                                       
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1792 (1.7 KiB)  TX bytes:1792 (1.7 KiB)

p2p0      Link encap:Ethernet  HWaddr 9A:3B:16:14:54:D9  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 98:3B:16:14:54:D9  
          inet addr:192.168.43.100  Bcast:192.168.43.255  Mask:255.255.255.0
          inet6 addr: fe80::9a3b:16ff:fe14:54d9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:68 errors:0 dropped:0 overruns:0 frame:0
          TX packets:55 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4748 (4.6 KiB)  TX bytes:4202 (4.1 KiB)
//我手机热点IP基点为:192.168.43.1

//无线路由
root@sabresd_6dq:/ # route add default gw 192.168.43.1

//ping
root@sabresd_6dq:/ # ping 192.168.43.1                                         
PING 192.168.43.1 (192.168.43.1) 56(84) bytes of data.
64 bytes from 192.168.43.1: icmp_seq=1 ttl=64 time=61.1 ms
64 bytes from 192.168.43.1: icmp_seq=2 ttl=64 time=24.0 ms
64 bytes from 192.168.43.1: icmp_seq=3 ttl=64 time=33.0 ms
64 bytes from 192.168.43.1: icmp_seq=4 ttl=64 time=30.6 ms
64 bytes from 192.168.43.1: icmp_seq=5 ttl=64 time=31.4 ms
64 bytes from 192.168.43.1: icmp_seq=6 ttl=64 time=20.5 ms
^C
--- 192.168.43.1 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 20.512/33.479/61.105/13.112 ms

搞定收工 !!下班回家!!



2、wpa_supplicant测试加密AP

通过上面wireless-tools的测试,已经证明WiFi驱动层是OK了的,但因为现在大多数AP都是加密的 ,所以就需要用到wpa_supplicant,我们编译android系统时,就已经把自带的wpa_supplicant和wpa_cli编译好并放到system/bin目录下了

1>配置wpa_supplicant

修改out目录下 android_kk4.4.2/out/target/product/sabresd_6dq/system/etc/wifi/wpa_supplicant.conf 文件

#添加如下代码

network={
     ssid="TP-LINK_AUTO"
     psk="86676890"
     key_mgmt=WPA-PSK
     priority=2
}

#明文连接是不被路由器所接受的,所以还得将密码转为psk密码
#密文转换需要用到wpa_passphrase,但Android并没有自带,移植了半天都没能实现,所以在Ubuntu中实行转换:
#执行:wpa_passphrase TP-LINK_AUTO 86676890
#转换后如下:

network={
     ssid="TP-LINK_AUTO"
     #psk="86676890"
     psk=66ce62f4531249341e240baca32f3af523074d74a099f77d3c81f983c4a5ae17
     key_mgmt=WPA-PSK
     priority=2
}



2>连接AP(吐槽:真心蛋疼的编辑器,每行的空格,编辑时好好的,发表显示就成换行了)

在板子的终端输入: wpa_supplicant -Dnl80211 -iwlan0 -c/system/etc/wifi/wpa_supplicant.conf &

打印一系列信息,如下:



3>分配IP

命令:ifconfig wlan0 192.168.1.108

测试:ping 192.168.1.107测试结果如下:



wpa_supplicant测试成功!接下来的工作就是将wpa_supplicant和Android层对接了。





Logo

更多推荐