天嵌 ARM开发社区

 找回密码
 注册
查看: 36781|回复: 104

wpa_supplicant管理无线wifi网络

  [复制链接]
TQ-lkp 发表于 2012-12-14 15:21:51 | 显示全部楼层 |阅读模式
本帖最后由 非也 于 2013-3-27 18:17 编辑

    为了感谢大家一直以来对天嵌科技的支持和鼓励,公司决定陆续放出Linux实用工具教程,希望大家一如既往的支持天嵌,天嵌的发展离不开广大的朋友!
   “授人以鱼不如授人以渔”,天嵌科技本着负责任的态度教大家如何使用和开发,助您翱翔于嵌入式的天空!
    本次介绍的是使用wpa_supplicant管理连接无线wifi网络,有不对之处希望大家多多指正,谢谢。
          wpa移植及内核配置。
    1、保证wifi模块处于准备状态。
     使用iwlist能搜索出ap,表示模块已经就绪。
  1. [root@EmbedSky /]# ifconfig wlan0 down
  2. [root@EmbedSky /]# ifconfig wlan0 up
  3. MacValue1=2
  4. MacValue2=0
  5. 0x1300 = 00064300
  6. [root@EmbedSky /]# iwlist wlan0 scanning
  7. wlan0     Scan completed :
  8.           Cell 01 - Address: 00:23:89:82:88:A0
  9.                     Protocol:802.11b/g
  10.                     ESSID:"ChinaNet"
  11.                     Mode:Managed
  12.                     Frequency:2.412 GHz (Channel 1)
  13.                     Quality=78/100  Signal level=-59 dBm  Noise level=-92 dBm
  14.                     Encryption key:off
  15.                     Bit Rates:54 Mb/s
  16.           Cell 02 - Address: 00:23:89:82:88:A1
  17.                     Protocol:802.11b/g
  18.                     ESSID:"hsfz"
  19.                     Mode:Managed
  20.                     Frequency:2.412 GHz (Channel 1)
  21.                     Quality=2/100  Signal level=-89 dBm  Noise level=-84 dBm
  22.                     Encryption key:off
  23.                     Bit Rates:54 Mb/s
复制代码

   2、根据实际wifi参数修改/etc/wpa_supplicant.conf配置文件                                                         
     注意ctrl_interface,ssid,key_mgmt,proto,psk,要根据wifi实际情况修改。
  1. fast_reauth=1
  2. ctrl_interface=wlan0
  3. update_config=1
  4. ap_scan=1

  5. network={
  6.         ssid="EmbedSky_test"
  7.         scan_ssid=1
  8.         key_mgmt=WPA-PSK
  9.         proto=WPA
  10.         pairwise=TKIP
  11.         group=TKIP
  12.        psk="1234567890"
  13. }
复制代码
    3、调用wpa_supplicant连接wifi
    wext为wifi模块使用的驱动协议,wlan0是wifi模块的设备名
  1. wpa_supplicant  -Dwext -iwlan0 -c/etc/wpa_supplicant.conf  -dd&
复制代码
        以下是wpa_supplicant连接时的打印信息(部分):        
  1. RX EAPOL from 00:27:19:64:f8:a8
  2. RX EAPOL - hexdump(len=99): 01 03 00 5f fe 00 89 00 20 00 00 00 00 00 00 00 01 eb 6b f1 83 4a cb a4 28 65 85 ee 0
  3. Setting authentication timeout: 10 sec 0 usec
  4. IEEE 802.1X RX: version=1 type=3 length=95
  5. WPA: Installing GTK to the driver (keyidx=1 tx=0 len=32).
  6. WPA: RSC - hexdump(len=6): 00 00 00 00 00 00
  7. wpa_driver_wext_set_key: alg=2 key_idx=1 set_tx=0 seq_len=6 key_len=32
  8. WPA: Sending EAPOL-Key 2/2
  9. WPA: TX EAPOL-Key - hexdump(len=99): 01 03 00 5f fe 03 11 00 20 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 0
  10. WPA: Key negotiation completed with 00:27:19:64:f8:a8 [PTK=TKIP GTK=TKIP]
  11. Cancelling authentication timeout
  12. Removed BSSID 00:27:19:64:f8:a8 from blacklist
  13. State: GROUP_HANDSHAKE -> COMPLETED
  14. CTRL-EVENT-CONNECTED - Connection to 00:27:19:64:f8:a8 completed (auth) [id=0 id_str=]
  15. wpa_driver_wext_set_operstate: operstate 0->1 (UP)
  16. WEXT: Operstate: linkmode=-1, operstate=6
  17. EAPOL: External notification - portValid=1
  18. EAPOL: External notification - EAP success=1
  19. EAPOL: SUPP_PAE entering state AUTHENTICATING
  20. EAPOL: SUPP_BE entering state SUCCESS
  21. EAP: EAP entering state DISABLED
  22. EAPOL: SUPP_PAE entering state AUTHENTICATED
  23. EAPOL: SUPP_BE entering state IDLE
  24. EAPOL authentication completed successfully
  25. RTM_NEWLINK: operstate=1 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
  26. RTM_NEWLINK, IFLA_IFNAME: Interface 'wlan0' added
  27. EAPOL: startWhen --> 0
  28. EAPOL: disable timer tick
  29. RSN: processing PMKSA candidate list
  30. RSN: not in suitable state for new pre-authentication
复制代码
    看到CTRL-EVENT-CONNECTED,就表示连接成功了。       
    4、给wifi模块动态分配IP

  1. [root@EmbedSky sky]# ping www.baidu.com
  2. ping: bad address 'www.baidu.com'
  3. [root@EmbedSky sky]# ping www.baidu.com
  4. ping: bad address 'www.baidu.com'
  5. [root@EmbedSky sky]# udhcpc -b -i wlan0
  6. udhcpc (v1.16.0) started
  7. Ignore event for foreign ifindex 2
  8. Sending discover...
  9. Sending select for 192.168.1.229...
  10. Lease of 192.168.1.229 obtained, lease time 7200
  11. Ignore event for foreign ifindex 2
  12. deleting routers
  13. route: SIOCDELRT: No such process
  14. adding dns 192.168.1.2
  15. adding dns 0.0.0.0
  16. [root@EmbedSky sky]# ping www.baidu.com
  17. PING www.baidu.com (61.135.169.105): 56 data bytes
  18. 64 bytes from 61.135.169.105: seq=0 ttl=54 time=306.288 ms
  19. ^C
  20. --- www.baidu.com ping statistics ---
  21. 2 packets transmitted, 1 packets received, 50% packet loss
  22. round-trip min/avg/max = 306.288/306.288/306.288 ms
复制代码
    5、给wifi模块分配静态IP                  
    首先要先设置DNS,/etc/resolv.conf文件,请根据实际情况修改

  1. nameserver 202.96.128.86
  2. nameserver 202.96.134.133
复制代码
    关闭eth0,否则会默认使用eth0来连接网络。添加路由,否则无法连通网络。
  1. [root@EmbedSky /]# ifconfig wlan0 192.168.1.22
  2. [root@EmbedSky /]# ifconfig eth0 down
  3. Ignore event for foreign ifindex 2
  4. [root@EmbedSky /]# ifconfig eth0 down
  5. [root@EmbedSky /]# route add default gw 192.168.1.2
  6. [root@EmbedSky /]# ping www.baidu.com
  7. PING www.baidu.com (61.135.169.125): 56 data bytes
  8. 64 bytes from 61.135.169.125: seq=0 ttl=54 time=216.279 ms
  9. 64 bytes from 61.135.169.125: seq=1 ttl=54 time=214.120 ms
  10. ^C
  11. --- www.baidu.com ping statistics ---
  12. 9 packets transmitted, 5 packets received, 44% packet loss
  13. round-trip min/avg/max = 212.083/222.935/244.256 ms
  14. [root@EmbedSky /]#
复制代码
   FAQ:
    1、无法连接ap
    内核中Networking support-> Networking options -> Packet socket,添加支持。要确保wifi模块处理就绪状态,使用iwlist wlan0 scanning命令判断。
    2、连上后无法动态分配IP
    确保内核已经选上dhcp支持。
    3、IP分配成功后无法访问外网
    请设置dns和路由。
附件是wpa可执行文件和配置文件:
游客,如果您要查看本帖隐藏内容请回复

    我们一直在努力做的更好!请大家回复后下载,感谢您对天嵌科技的支持!




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
亚瑟王 发表于 2012-12-14 18:41:34 | 显示全部楼层
好帖子需要顶起来。
lzty634158 发表于 2012-12-16 13:36:35 | 显示全部楼层
谢谢分享,以前做的这个没成功,这次再试试!
lzty634158 发表于 2012-12-16 15:00:18 | 显示全部楼层
运行出现下面情况:
wpa_supplicant: error while loading shared libraries: libnl.so.1: cannot open shared object file: No such file or directory  

lib 目录下也没有这个文件!提供的库也没有!
496812749 发表于 2012-12-21 11:01:05 | 显示全部楼层
支持天嵌,顶一个
zhoulinshijie 发表于 2012-12-23 22:02:52 | 显示全部楼层
wpa supplicant几乎是唯一的一个无线管理工具了
millay2630 发表于 2012-12-31 01:52:59 | 显示全部楼层
看了下,希望下载了能先直接用一下
希白 发表于 2013-1-4 11:11:28 | 显示全部楼层
很好的资料,正需要,下来看看
myzhyzhy 发表于 2013-1-4 15:04:27 | 显示全部楼层
看一下!!!!
chgh1306 发表于 2013-1-4 15:12:38 | 显示全部楼层
顶起来,常用的WIFI管理工具
allen_linux 发表于 2013-1-5 14:46:24 | 显示全部楼层
太强大啦,顶一个,哈哈
莫小陂 发表于 2013-1-11 23:06:40 | 显示全部楼层
这个用得着,下载下来看看
lantian5435 发表于 2013-1-12 13:24:30 | 显示全部楼层
good thanks:victory:
Hens007 发表于 2013-1-12 21:11:25 | 显示全部楼层
严重在顶楼主!
cini 发表于 2013-1-12 21:42:04 | 显示全部楼层
看看 希望能直接用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-4-23 21:13 , Processed in 1.031250 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表