Chinaunix首页 | 论坛 | 博客
  • 博客访问: 607319
  • 博文数量: 166
  • 博客积分: 970
  • 博客等级: 准尉
  • 技术积分: 547
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-06 15:16
个人简介

Believe youself!

文章分类

全部博文(166)

文章存档

2017年(1)

2016年(5)

2015年(117)

2014年(14)

2013年(11)

2012年(5)

2010年(4)

2009年(1)

2008年(8)

我的朋友

分类: LINUX

2015-05-25 15:14:55


[From]
本帖最后由 非也 于 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
  2. ping: bad address ''
  3. [root@EmbedSky sky]# ping
  4. ping: bad address ''
  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
  17. PING (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. --- 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
  7. PING (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. --- 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和路由。
阅读(3924) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~