Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3042648
  • 博文数量: 396
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4209
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-04 13:04
文章分类

全部博文(396)

文章存档

2022年(1)

2021年(2)

2020年(8)

2019年(24)

2018年(135)

2017年(158)

2016年(68)

我的朋友

分类: 嵌入式

2018-09-18 19:23:46

转载至:  http://blog.csdn.net/kuangzuxiaoN/article/details/75028643

开发环境: ubuntu 16.04LTS

目标环境: iTOP4412精英板

交叉编译器: arm-2014.05


到官网下载最新的版本wpa_supplicant-2.6

在官网可以看到wpa_supplicant-2.6的依赖程序

WPA Supplicant Dependencies 

Recommended 

libnl-3.3.0 and OpenSSL-1.1.0f

Optional 

dbus-1.10.20, libxml2-2.9.4, and Qt-5.9.1 

主要依赖于libnl-3.3.0和OpenSSL-1.1.0f,这里给出下载地址:

libnl-3.3.0:   

OpenSSL-1.1.0f:    


移植步骤:

(1)首先移植openssl-1.1.0f

1. 解压并进入到openssl-1.1.0f主目录

 

[cpp] view plain copy
  1. tar -xvf openssl-1.1.0f  
  2. cd openssl-1.1.0f  
2. 执行
[cpp] view plain copy
  1. ./Configure linux-armv4 --prefix=/usr/local/arm/openssl  

配置目标环境,根据自己的板子具体修改,Exynos4412是armv7架构,并且给定路径参数,我要安装的绝对路径是/usr/local/arm/openssl

 

配置成功后,可以看到

 

[cpp] view plain copy
  1. Configuring for linux-armv4  
  2. CC            =gcc  
  3. CFLAG         =-Wall -O3 -pthread   
  4. SHARED_CFLAG  =-fPIC -DOPENSSL_USE_NODELETE  
  5. DEFINES       =DSO_DLFCN HAVE_DLFCN_H NDEBUG OPENSSL_THREADS OPENSSL_NO_STATIC_ENGINE OPENSSL_PIC OPENSSL_BN_ASM_MONT OPENSSL_BN_ASM_GF2m SHA1_ASM SHA256_ASM SHA512_ASM AES_ASM BSAES_ASM GHASH_ASM ECP_NISTZ256_ASM POLY1305_ASM  
  6. LFLAG         =  
  7. PLIB_LFLAG    =  
  8. EX_LIBS       =-ldl   
  9. APPS_OBJ      =  
  10. CPUID_OBJ     =armcap.o armv4cpuid.o  
  11. UPLINK_OBJ    =  
  12. BN_ASM        =bn_asm.o armv4-mont.o armv4-gf2m.o  
  13. EC_ASM        =ecp_nistz256.o ecp_nistz256-armv4.o  
  14. DES_ENC       =des_enc.o fcrypt_b.o  
  15. AES_ENC       =aes_cbc.o aes-armv4.o bsaes-armv7.o aesv8-armx.o  
  16. BF_ENC        =bf_enc.o  
  17. CAST_ENC      =c_enc.o  
  18. RC4_ENC       =rc4_enc.o rc4_skey.o  
  19. RC5_ENC       =rc5_enc.o  
  20. MD5_OBJ_ASM   =  
  21. SHA1_OBJ_ASM  =sha1-armv4-large.o sha256-armv4.o sha512-armv4.o  
  22. RMD160_OBJ_ASM=  
  23. CMLL_ENC      =camellia.o cmll_misc.o cmll_cbc.o  
  24. MODES_OBJ     =ghash-armv4.o ghashv8-armx.o  
  25. PADLOCK_OBJ   =  
  26. CHACHA_ENC    =chacha-armv4.o  
  27. POLY1305_OBJ  =poly1305-armv4.o  
  28. BLAKE2_OBJ    =  
  29. PROCESSOR     =  
  30. RANLIB        =ranlib  
  31. ARFLAGS       =  
  32. PERL          =/usr/bin/perl  
  33.   
  34. THIRTY_TWO_BIT mode  
  35. BN_LLONG mode  
  36. RC4 uses unsigned char  
  37.   
  38. Configured for linux-armv4.  
3. 这里就需要修改交叉编译器,修改Makefile

 

添加交叉编译器:

 

[cpp] view plain copy
  1. CROSS_COMPILE=/usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-   
配置参数中已经指定了路径,因此在Makefile不用修改,可以看到:

 

 

[cpp] view plain copy
  1. 51: INSTALLTOP=/usr/local/arm/openssl  
  2. 52: OPENSSLDIR=/usr/local/arm/openssl/ssl  
  3. 53: LIBDIR=lib  
  4. 54: ENGINESDIR=/usr/local/arm/openssl/lib/engines-1.1  
4. 执行make,完成编译

 

5. 执行sudo make install,完成安装

6. 可以看到openssl被编译成静态库,放在指定目录/usr/local/arm/openssl下

 

[cpp] view plain copy
  1. yang@yang:/usr/local/arm/openssl$ ls  
  2. bin  include  lib  share  ssl  
  3. yang@yang:/usr/local/arm/openssl/lib$ ls  
  4. engines-1.1  libcrypto.so      libssl.a   libssl.so.1.1  
  5. libcrypto.a  libcrypto.so.1.1  libssl.so  pkgconfig  
  6. yang@yang:/usr/local/arm/openssl/lib$   
7. 将lib中的libcrypto.a、libcrypto.so.1.1、libssl.so.1.1和libssl.a文件拷贝到开发板文件系统的/lib目录下,bin中的openssl文件拷贝到开发板的/bin中

 


(2)移植libnl-3.3.0

1.解压并进入到主目录

[cpp] view plain copy
  1. cd libnl-3.3.0  
2.配置交叉编译选项
[cpp] view plain copy
  1. sudo ./configure --host=arm-linux --prefix=/usr/local/arm/libnl --enable-static --enable-shared CC=/usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-gcc  
在这里交叉编译器用的是绝对路径。

 

可能会出现如下错误:

 

[cpp] view plain copy
  1. configure: WARNING: bison not found. Please install before continuing.  
  2. configure: WARNING: flex not found. Please install before continuing.  
  3. configure: error: Required packages are missing. Please install them and rerun ./configure  
根据提示,安装bison和flex

 

 

[cpp] view plain copy
  1. sudo apt-get install bison  
  2. sudo apt-get install flex  
再次使用配置编译选项命令,最终看到如下输出
[cpp] view plain copy
  1. -------------------------------------------------------------------------------  
  2.                                   NOTE  
  3.   
  4.  There have been some changes starting with 3.2 regarding where and how libnl  
  5.  is being installed on the system in order to allow multiple libnl versions  
  6.  to be installed in parallel:  
  7.   
  8.     - Headers will be installed in ${prefix}/include/libnl3, therefore  
  9.       you will need to add "-I/usr/include/libnl3" to CFLAGS  
  10.   
  11.     - The library basename was renamed to libnl-3, i.e. the SO names become  
  12.       libnl-3.so., libnl-route-3.so, etc.  
  13.   
  14.     - libtool versioning was assumed, to ease detection of compatible library  
  15.       versions.  
  16.   
  17.  If you are using pkg-config for detecting and linking against the library   
  18.  things will continue magically as if nothing every happened. If you are   
  19.  linking manually you need to adapt your Makefiles or switch to using   
  20.  pkg-config files.  
  21.   
  22. -------------------------------------------------------------------------------  
配置成功。

 

3. 开始编译,执行make命令

4. 安装,执行make install命令

在/usr/local/arm/libnl目录下有以下文件

[cpp] view plain copy
  1. yang@yang:/usr/local/arm/libnl$ ls  
  2. bin  etc  include  lib  share  
  3. yang@yang:/usr/local/arm/libnl$ ls lib/  
  4. libnl                    libnl-genl-3.so            libnl-route-3.a  
  5. libnl-3.a                libnl-genl-3.so.200        libnl-route-3.la  
  6. libnl-3.la               libnl-genl-3.so.200.25.0   libnl-route-3.so  
  7. libnl-3.so               libnl-idiag-3.a            libnl-route-3.so.200  
  8. libnl-3.so.200           libnl-idiag-3.la           libnl-route-3.so.200.25.0  
  9. libnl-3.so.200.25.0      libnl-idiag-3.so           libnl-xfrm-3.a  
  10. libnl-cli-3.a            libnl-idiag-3.so.200       libnl-xfrm-3.la  
  11. libnl-cli-3.la           libnl-idiag-3.so.200.25.0  libnl-xfrm-3.so  
  12. libnl-cli-3.so           libnl-nf-3.a               libnl-xfrm-3.so.200  
  13. libnl-cli-3.so.200       libnl-nf-3.la              libnl-xfrm-3.so.200.25.0  
  14. libnl-cli-3.so.200.25.0  libnl-nf-3.so              pkgconfig  
  15. libnl-genl-3.a           libnl-nf-3.so.200  
  16. libnl-genl-3.la          libnl-nf-3.so.200.25.0  
5. 安装成功,将libnl-3.so.200.25.0、libnl-genl-3.so.200.25.0放到开发板的/lib目录,并创建软链接

 

 

[cpp] view plain copy
  1. ln -s libnl-3.so.200.25.0 libnl-3.so  
  2. ln -s libnl-3.so.200.25.0 libnl-3.so.200  
  3. ln -s libnl-genl-3.so.200.25.0 libnl-genl-3.so  
  4. ln -s libnl-genl-3.so.200.25.0 libnl-genl-3.so.200  

(3)移植wpa_supplicant-2.6

 

1. 解压并进入到wpa_supplicant-2.6主目录,并生成.config文件

 

[cpp] view plain copy
  1. cd wpa_supplicant-2.6  
  2. cp defconfig .config  
2. 修改.config文件

 

 

[cpp] view plain copy
  1. CC=/usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-gcc -L/usr/local/arm/openssl/lib  
  2. CFLAGS += -I/usr/local/arm/openssl/include  
  3. LIBS += -L/usr/local/arm/openssl/lib  
  4.    
  5. CONFIG_DRIVER_NL80211=y  
  6.   
  7. CONFIG_LIBNL32=y  
  8. CFLAGS += -I/usr/local/arm/libnl/include  
  9. LIBS += -L/usr/local/arm/libnl/lib  
这里只给出主要的修改部分,其他使用默认设置就好。注意,这里一定要添加libnl的配置,否则会出现错误:

 

 

[cpp] view plain copy
  1. ../src/drivers/driver_nl80211.c:17:31: fatal error: netlink/genl/genl.h: No such file or directory  
  2.  #include   
  3.                                ^  
  4. compilation terminated.  
  5. Makefile:1776: recipe for target '../src/drivers/driver_nl80211.o' failed  
  6. make: *** [../src/drivers/driver_nl80211.o] Error 1  
3. 编译,执行make
4. 将生成的wpa_cli、wpa_passphrase、 wpa_supplicant等工具添加到开发板文件系统/bin目录下,并且拷贝配置文件到开发板文件系统/etc目录下。

 

 

[cpp] view plain copy
  1. cp examples/wpa-psk-tkip.conf rootfs/etc/wpa_supplicant.conf  

 

5. 修改wpa_supplicant.conf

 

[cpp] view plain copy
  1. # WPA-PSK/TKIP  
  2.   
  3. ctrl_interface=/var/run/wpa_supplicant  
  4.   
  5. network={  
  6.         ssid="yang"     #无线网络名称  
  7.         key_mgmt=WPA-PSK  
  8.         proto=WPA  
  9.         pairwise=TKIP  
  10.         group=TKIP  
  11.         psk="57b559b778"    #无线网络密码  
  12. }  

 

(4)测试wpa_supplicant

1. 在开发板的/var/run/下创建文件wpa_supplicant

 

[cpp] view plain copy
  1. mkdir -p wpa_supplicant  

 

2. 使用命令:

 

[cpp] view plain copy
  1. wpa_passphrase yang 57b559b778 >> wpa_supplicant.conf   

 

创建连接暗文密码(PSK密码),通过明码转换,修改wpa_supplicant.conf,用PSK密码替换明文密码

 

[cpp] view plain copy
  1. # WPA-PSK/TKIP  
  2.   
  3. ctrl_interface=/var/run/wpa_supplicant  
  4.   
  5. network={  
  6.         ssid="yang"  
  7.         key_mgmt=WPA-PSK  
  8.         proto=WPA  
  9.         pairwise=TKIP  
  10.         group=TKIP  
  11.         psk=725e926081647954f9af00e46904fd6382b2cbc91b8ab7b5655a8d8db146c5dc  
  12. }  
3. 在开发板的终端命令行使用命令wpa_supplicant,出现如下信息,说明wpa_supplicant移植成功  
[cpp] view plain copy
  1. Successfully initialized wpa_supplicant  
  2. wpa_supplicant v2.6  
  3. Copyright (c) 2003-2016, Jouni Malinen  and contributors  
  4.   
  5. This software may be distributed under the terms of the BSD license.  
  6. See README for more details.  
  7.   
  8. This product includes software developed by the OpenSSL Project  
  9. for use in the OpenSSL Toolkit (http://)  
  10.   
  11. usage:  
  12.   wpa_supplicant [-BddhKLqqtvW] [-P] [-g] \  
  13.         [-G] \  
  14.         -i -c [-C] [-D] [-p] \  
  15.         [-b] [-e] \  
  16.         [-o] [-O] \  
  17.         [-N -i -c [-C] [-D] \  
  18.         [-p] [-b] [-I] ...]  
  19.   
  20. drivers:  
  21.   nl80211 = Linux nl80211/cfg80211  
  22.   wext = Linux wireless extensions (generic)  
  23.   wired = Wired Ethernet driver  
  24. options:  
  25.   -b = optional bridge interface name  
  26.   -B = run daemon in the background  
  27.   -c = Configuration file  
  28.   -C = ctrl_interface parameter (only used if -c is not)  
  29.   -d = increase debugging verbosity (-dd even more)  
  30.   -D = driver name (can be multiple drivers: nl80211,wext)  
  31.   -e = entropy file  
  32.   -g = global ctrl_interface  
  33.   -G = global ctrl_interface group  
  34.   -h = show this help text  
  35.   -i = interface name  
  36.   -I = additional configuration file  
  37.   -K = include keys (passwords, etc.) in debug output  
  38.   -L = show license (BSD)  
  39.   -N = start describing new interface  
  40.   -o = override driver parameter for new interfaces  
  41.   -O = override ctrl_interface parameter for new interfaces  
  42.   -p = driver parameters  
  43.   -P = PID file  
  44.   -q = decrease debugging verbosity (-qq even less)  
  45.   -t = include timestamp in debug messages  
  46.   -v = show version  
  47.   -W = wait for a control interface monitor before starting  
  48. example:  
  49.   wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf  
4. 加载网卡驱动,并且配置IP地址
[cpp] view plain copy
  1. ifconfig wlan0 up  
  2. ifconfig wlan0 10.42.0.12 netmask 255.255.255.0   
注意:此处设置的IP需要与你将要连接的局域网IP在同一网段,或者是直接移植DHCP

 

5. 用ifconfig命令查看无线网卡

[cpp] view plain copy
  1. eth0      Link encap:Ethernet  HWaddr 08:90:90:90:90:90    
  2.           inet addr:192.168.1.230  Bcast:192.168.1.255  Mask:255.255.255.0  
  3.           inet6 addr: fe80::a90:90ff:fe90:9090/64 Scope:Link  
  4.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
  5.           RX packets:19520 errors:0 dropped:123 overruns:0 frame:0  
  6.           TX packets:6 errors:0 dropped:0 overruns:0 carrier:0  
  7.           collisions:0 txqueuelen:1000   
  8.           RX bytes:1323355 (1.2 MiB)  TX bytes:480 (480.0 B)  
  9.   
  10. lo        Link encap:Local Loopback    
  11.           inet addr:127.0.0.1  Mask:255.0.0.0  
  12.           inet6 addr: ::1/128 Scope:Host  
  13.           UP LOOPBACK RUNNING  MTU:16436  Metric:1  
  14.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  15.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  16.           collisions:0 txqueuelen:0   
  17.           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)  
  18.   
  19. wlan0     Link encap:Ethernet  HWaddr 48:8A:D2:3A:9E:24    
  20.           inet addr:10.42.0.12  Bcast:10.42.0.255  Mask:255.255.255.0  
  21.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
  22.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  23.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  24.           collisions:0 txqueuelen:1000   
  25.           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)  
6. 加载网卡成功,连接无线局域网

 

这里根据wpa_supplicant命令的提示,使用提示命令

 

[cpp] view plain copy
  1. wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf  
会出现如下错误:

 

 

[cpp] view plain copy
  1. nl80211: deinit ifname=wlan0 disabled_11b_rates=0  
  2. wlan0: Failed to initialize driver interface  
可见wlan0驱动不支持Linux nl80211/cfg80211, 因此改用
[cpp] view plain copy
  1. wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf  
注:关于nl80211和wext无线驱动接口的区别

 

  nl80211 = Linux nl80211/cfg80211

  wext = Linux wireless extensions (generic)

可参考: http://blog.csdn.net/dickjtk/article/details/11862815 

7. 测试无线局域网,将要连接的无线网IP: 10.42.0.1

 

[cpp] view plain copy
  1. PING 10.42.0.1 (10.42.0.1): 56 data bytes  
  2. 64 bytes from 10.42.0.1: seq=0 ttl=64 time=8.918 ms  
  3. 64 bytes from 10.42.0.1: seq=1 ttl=64 time=1.402 ms  
  4. 64 bytes from 10.42.0.1: seq=2 ttl=64 time=1.315 ms  
  5. 64 bytes from 10.42.0.1: seq=3 ttl=64 time=3.993 ms  
  6. 64 bytes from 10.42.0.1: seq=4 ttl=64 time=3.141 ms  
  7. 64 bytes from 10.42.0.1: seq=5 ttl=64 time=2.574 ms  
  8. 64 bytes from 10.42.0.1: seq=6 ttl=64 time=2.136 ms  
  9. 64 bytes from 10.42.0.1: seq=7 ttl=64 time=1.561 ms  
  10. ^C  
  11. --- 10.42.0.1 ping statistics ---  
  12. 8 packets transmitted, 8 packets received, 0% packet loss  
  13. round-trip min/avg/max = 1.315/3.130/8.918 ms  
网络连接成功。
阅读(2487) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~