无线网卡驱动起来之后,还需要在用户态的一些程序支持,从而可以寻找热点并连接热点,访问网络。wifi连接时候的有出于两个方面的考虑:
出现了不同的标准,这些认证/加密常见的有下面这些:
而针对不同的认证/加密就有不同的软件来辅助我们wifi设备的认证/连接:
直接在Yocto中用bitbake编译即可,参考我以前的博客:Yocto tips (11): Yocto如何往最终的rootfs中添加软件
wpa_supplicant共有三个工具集:
这些工具的作用与使用可以查看man手册。
mkdir /var/run/wpa_supplicant
ctrl_interface=/var/run/wpa_supplicant # 一个目录,用于wpa_supplicant和wpa_cli的socket通信 network={ ssid="XXXX" 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="XXXYYY" #密码 }
然后我们可以将此配置文件放置到/etc/XXX.conf
然后以Background(后台daemon)运行wpa_supplicant:
wpa_supplicant -B -c /etc/XXX.conf -iwlan0
运行结果如下:
然后查看状态
wpa_cli -iwlan0 status // 查看状态
如果是scanning状态,那么我们可以使用iw命令来查看是否有我们需要的热点:
root@imx6qsabresd:~# iw dev wlan0 scan BSS 80:89:17:e4:49:e4(on wlan0) TSF: 1475597209984 usec (17d, 01:53:17) freq: 2462 beacon interval: 100 TUs capability: ESS Privacy ShortPreamble ShortSlotTime (0x0431) signal: -45.00 dBm last seen: 180 ms ago Information elements from Probe Response frame: SSID: ruishanghua Supported rates: 1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 DS Parameter set: channel 11 ERP: <no flags> Extended supported rates: 24.0 36.0 48.0 54.0 HT capabilities: Capabilities: 0x106e HT20/HT40 SM Power Save disabled RX HT20 SGI RX HT40 SGI No RX STBC Max AMSDU length: 3839 bytes DSSS/CCK HT40 Maximum RX AMPDU length 65535 bytes (exponent: 0x003) Minimum RX AMPDU time spacing: No restriction (0x00) HT RX MCS rate indexes supported: 0-15 HT TX MCS rate indexes are undefined HT operation: * primary channel: 11 * secondary channel offset: below * STA channel width: any * RIFS: 0 * HT protection: 20 MHz * non-GF present: 0 * OBSS non-GF present: 0 * dual beacon: 0 * dual CTS protection: 0 * STBC beacon: 0 * L-SIG TXOP Prot: 0 * PCO active: 0 * PCO phase: 0 RSN: * Version: 1 * Group cipher: CCMP * Pairwise ciphers: CCMP * Authentication suites: PSK * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) WPA: * Version: 1 * Group cipher: CCMP * Pairwise ciphers: CCMP * Authentication suites: PSK WMM: * Parameter version 1 * BE: CW 15-1023, AIFSN 3 * BK: CW 15-1023, AIFSN 7 * VI: CW 7-15, AIFSN 2, TXOP 3008 usec * VO: CW 3-7, AIFSN 2, TXOP 1504 usec
或者对SSID过滤查看:
root@imx6qsabresd:~# iw dev wlan0 scan | grep SSID: SSID: ruishanghua SSID: ziroom101 SSID: TPGuest_28A4 SSID: TP-LINK_2CBE SSID: Tenda_13B190 SSID: yun SSID: TP-LINK_FA6C SSID: TP-LINK_chj
或者使用wap_cli来查看:
root@imx6qsabresd:~# wpa_cli scan_results Selected interface 'wlan0' bssid / frequency / signal level / flags / ssid 80:89:17:e4:49:e4 2462 -46 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] ruishanghua bc:46:99:97:4b:cc 2462 -66 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] ziroom101 bc:46:99:99:fa:6c 2437 -68 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] TP-LINK_FA6C ce:46:99:65:28:a4 2437 -71 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] TPGuest_28A4 fc:d7:33:35:2c:be 2412 -72 [ESS] TP-LINK_2CBE 8c:be:be:23:28:ba 2417 -64 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] yun bc:46:99:65:28:a4 2437 -71 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] TP-LINK_chj 80:89:17:fe:0c:a2 2412 -66 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] TP-LINK_601
然后使用dhcp来获取与设置IP与DNS(nameserver),以及gateway。关于IP,DNS与gateway的大概作用如下:
下面是使用busybox的udhcpc的结果:
可以看到在/etc/resolv.conf中的内容被配置好了:
然后就是联通测试:
ping 192.168.1.1
因为DNS与网管都配置好了,所以其实我们可以ping通外网了:
至此,我们就可以使用这个wlan了。