USB-WIFI RTL8188CU模块驱动

RTL8188CU模块概述

Realtek的8188cu模块WiFi是通过usb接口挂载设备。以下是我对模块使用的所有开发工作。

Linux内核驱动适配和编译

由于芯片驱动官方已经最高支持kernel Linux3.9版本、在对Linux3.14进行移植时出现较多问题。期间出现了很多的坑。

内核配置:

进入内核目录,make menuconfig
[*] Networking support —> 
[*] Wireless —> 


Device Drivers —> 
[*] Network device support —> 
Wireless LAN —> 
[*] Wireless LAN (IEEE 802.11) 
<*> IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)
 

源码移植后、出现此选项

源码编译:

解压源码到kernel目录

tar -xvf rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911.tar.gz

    移动到内核文件中
mv rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911 sbc/am3352-sbc/src/am335x-linux-3.14.26/drivers/net/wireless/rtl8192cu

编译出现的问题
直接make命令编译
问题一:
os_dep/linux/os_intfs.c:320:3: error: implicit declaration of function ‘create_proc_entry’
原因:Linux 3.10版本中已经去除了create_proc_entry函数。
解决方法:下载另一个文件:wget https://raw.github.com/raspberrypi/linux/rpi-3.10.y/drivers/net/wireless/rtl8192cu/os_dep/linux/os_intfs.c,将下载到的文件覆盖原来的os_dep/linux/os_intfs.c。
问题二:
 在编译驱动的时候,出现错误macro "__TIME__" might prevent reproducible builds [-Werror=date-time],
解决办法
只需在相应的Makefile中添加
EXTRA_CFLAGS +=-Wno-error=date-time (不把该行为当成错误)
或者
EXTRA_CFLAGS +=-Wno-date-time(不把该行为当成警告)
便可解决该警告或者错误。
问题三:
ERROR: "wireless_send_event" [drivers/net/wireless/rtl8192cu/8192cu.ko] undefined!
解决办法:
[*] Wireless LAN (IEEE 802.11) 
<*> IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP) 

排除万难、中与编译成功生成驱动模块:
8192cu.ko

无线工具tool编译移植:

wpa_supplicant是wifi客户端(client)加密认证工具,和iwconfig不同,wpa_supplicant支持wep、wpa、wpa2等完整的加密认证,而iwconfig只能支持wep。和wpa_supplocant相对应的,ap端的加密认证工具为hostapd。

iwconfig配置wep模式连接WiFi

解压工具源码安装包
tar -xvf wireless_tools.30.rtl.tar.gz
更改交叉编译工具

编译生成可执行文件

在开发板上进行配置

root@am335x-evm:/mnt/wifi# ifconfig
eth0 Link encap:Ethernet HWaddr 26:C7:3D:A0:40:61
inet addr:192.168.1.147 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2294 errors:0 dropped:2 overruns:0 frame:0
TX packets:51 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:169639 (165.6 KiB) TX bytes:5634 (5.5 KiB)
Interrupt:56
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:700 (700.0 B) TX bytes:700 (700.0 B)
root@am335x-evm:/mnt/wifi# ls
8192cu.ko iwconfig iwevent iwgetid iwlist iwpriv iwspy

添加驱动

root@am335x-evm:/mnt/wifi# insmod 8192cu.ko
[ 960.694600] rtl8192cu driver version=v4.0.2_9000.20130911
[ 960.700314] build time: Jan 24 2018 20:22:31
[ 960.706246]
[ 960.706246] usb_endpoint_descriptor(0):
[ 960.711844] bLength=7
[ 960.714309] bDescriptorType=5
[ 960.717430] bEndpointAddress=81
[ 960.720725] wMaxPacketSize=200
[ 960.723962] bInterval=0
[ 960.726529] RT_usb_endpoint_is_bulk_in = 1
[ 960.730835]
[ 960.730835] usb_endpoint_descriptor(1):
[ 960.736432] bLength=7
[ 960.738815] bDescriptorType=5
[ 960.741931] bEndpointAddress=2
[ 960.745151] wMaxPacketSize=200
[ 960.748356] bInterval=0
[ 960.750929] RT_usb_endpoint_is_bulk_out = 2
[ 960.755333]
[ 960.755333] usb_endpoint_descriptor(2):
[ 960.760915] bLength=7
[ 960.763312] bDescriptorType=5
[ 960.766426] bEndpointAddress=3
[ 960.769632] wMaxPacketSize=200
[ 960.772846] bInterval=0
[ 960.775418] RT_usb_endpoint_is_bulk_out = 3
[ 960.779807]
[ 960.779807] usb_endpoint_descriptor(3):
[ 960.785401] bLength=7
[ 960.787788] bDescriptorType=5
[ 960.790899] bEndpointAddress=84
[ 960.794331] wMaxPacketSize=40
[ 960.797453] bInterval=1
[ 960.800022] RT_usb_endpoint_is_int_in = 4, Interval = 1
[ 960.805534] nr_endpoint=4, in_num=2, out_num=2
[ 960.805534]
[ 960.811752] USB_SPEED_HIGH
[ 960.815172] CHIP TYPE: RTL8188C_8192C
[ 960.819076] register rtw_netdev_ops to netdev_ops
[ 960.824222] Chip Version ID: VERSION_NORMAL_TSMC_CHIP_88C.
[ 960.829991] RF_Type is 3!!
[ 960.836642] EEPROM type is E-FUSE
[ 960.840135] ====> ReadAdapterInfo8192C
[ 960.844372] Boot from EFUSE, Autoload OK !
[ 960.922000] EEPROMVID = 0x0bda
[ 960.925234] EEPROMPID = 0x8176
[ 960.928442] EEPROMCustomerID : 0x00
[ 960.932102] EEPROMSubCustomerID: 0x00
[ 960.935961] RT_CustomerID: 0x00
[ 960.939266] _ReadMACAddress MAC Address from EFUSE = 00:1d:43:30:1b:fc
[ 960.946139] EEPROMRegulatory = 0x0
[ 960.949710] _ReadBoardType(0)
[ 960.952847] BT Coexistance = disable
[ 960.956603] mlmepriv.ChannelPlan = 0x02
[ 960.960635] _ReadPSSetting...bHWPwrPindetect(0)-bHWPowerdown(0) ,bSupportRemoteWakeup(0)
[ 960.969147] ### PS params=> power_mgnt(1),usbss_enable(0) ###
[ 960.975289] ### AntDivCfg(0)
[ 960.978310] readAdapterInfo_8192CU(): REPLACEMENT = 1
[ 960.983627] <==== ReadAdapterInfo8192C in 150 ms
[ 960.989728] rtw_macaddr_cfg MAC Address = 00:1d:43:30:1b:fc
[ 960.995732] bDriverStopped:1, bSurpriseRemoved:0, bup:0, hw_init_completed:0
[ 961.008437] _rtw_drv_register_netdev, MAC Address (if1) = 00:1d:43:30:1b:fc
[ 961.020251] usbcore: registered new interface driver rtl8192cu
root@am335x-evm:/mnt/wifi# ifconfig
eth0 Link encap:Ethernet HWaddr 26:C7:3D:A0:40:61
inet addr:192.168.1.147 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9567 errors:0 dropped:2 overruns:0 frame:0
TX packets:3781 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:11071491 (10.5 MiB) TX bytes:268210 (261.9 KiB)
Interrupt:56
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:700 (700.0 B) TX bytes:700 (700.0 B)

启动网卡

root@am335x-evm:/mnt/wifi# ifconfig wlan0 up
[ 1002.603095] +871x_drv - drv_open, bup=0
[ 1002.610055] ===> FirmwareDownload91C() fw:Rtl819XFwImageArray_TSMC
[ 1002.616726] FirmwareDownload92C accquire FW from embedded image
[ 1002.622978] fw_ver=v88, fw_subver=2, sig=0x88c0
[ 1002.649241] fw download ok!
[ 1002.652205] Set RF Chip ID to RF_6052 and RF type to 1T1R.
[ 1002.966153] IQK:Start!!!
[ 1002.975077] Path A Rx IQK fail!!
[ 1002.980110] Path A IQK Success!!
[ 1002.988366] Path A Rx IQK fail!!
[ 1002.993931] Path A IQK Success!!
[ 1002.999644] IQK: final_candidate is 0
[ 1003.003565] IQK: RegE94=104 RegE9C=15 RegEA4=ff RegEAC=1 RegEB4=0 RegEBC=0 RegEC4=0 RegECC=0
Path A IQ Calibration Success !
[ 1003.124495] pdmpriv->TxPowerTrackControl = 1
[ 1003.131213] rtl8192cu_hal_init in 520ms
[ 1003.155214] MAC Address = 00:1d:43:30:1b:fc
[ 1003.160049] -871x_drv - drv_open, bup=1
root@am335x-evm:/mnt/wifi# [ 1005.155132] ==>rtw_ps_processor .fw_state(0)
[ 1005.159654] ==>ips_enter cnts:1
[ 1005.163013] ===> rtw_ips_pwr_down...................
[ 1005.169992] ====> rtw_ips_dev_unload...
[ 1005.191302] usb_read_port_cancel
[ 1005.195138] usb_read_port_complete()-1284: RX Warning! bDriverStopped(0) OR bSurpriseRemoved(0) bReadPortCancel(1)
[ 1005.206415] usb_read_port_complete()-1284: RX Warning! bDriverStopped(0) OR bSurpriseRemoved(0) bReadPortCancel(1)
[ 1005.217664] usb_read_port_complete()-1284: RX Warning! bDriverStopped(0) OR bSurpriseRemoved(0) bReadPortCancel(1)
[ 1005.228893] usb_read_port_complete()-1284: RX Warning! bDriverStopped(0) OR bSurpriseRemoved(0) bReadPortCancel(1)
[ 1005.239957] usb_write_port_cancel
[ 1005.244091] ==> rtl8192cu_hal_deinit
[ 1005.247950] bkeepfwalive(0)
[ 1005.250883] card disble without HWSM...........
[ 1005.259031] <=== rtw_ips_pwr_down..................... in 90ms
root@am335x-evm:/mnt/wifi# ifconfig
eth0 Link encap:Ethernet HWaddr 26:C7:3D:A0:40:61
inet addr:192.168.1.147 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9634 errors:0 dropped:2 overruns:0 frame:0
TX packets:3783 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:11077353 (10.5 MiB) TX bytes:268336 (262.0 KiB)
Interrupt:56
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:700 (700.0 B) TX bytes:700 (700.0 B)
wlan0 Link encap:Ethernet HWaddr 00:1D:43:30:1B:FC
UP 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)


搜索周围WiFi AP点

root@am335x-evm:/mnt/wifi# ifconfig wlan0 192.168.1.166
root@am335x-evm:/mnt/wifi# ./iwlist wlan0 scanning
[ 1251.243269] _rtw_pwr_wakeup call ips_leave....
[ 1251.247992] ==>ips_leave cnts:1
[ 1251.251292] ===> rtw_ips_pwr_up..............
[ 1251.256064] ===> ips_netdrv_open.........
[ 1251.264501] ===> FirmwareDownload91C() fw:Rtl819XFwImageArray_TSMC
[ 1251.271108] FirmwareDownload92C accquire FW from embedded image
[ 1251.277517] fw_ver=v88, fw_subver=2, sig=0x88c0
[ 1251.303432] fw download ok!
[ 1251.306388] Set RF Chip ID to RF_6052 and RF type to 1T1R.
[ 1251.626253] IQK:Start!!!
[ 1251.635242] Path A Rx IQK fail!!
[ 1251.640332] Path A Rx IQK fail!!
[ 1251.643774] Path A IQK Only Tx Success!!
[ 1251.652991] Path A Rx IQK fail!!
[ 1251.658083] Path A Rx IQK fail!!
[ 1251.661478] Path A IQK Only Tx Success!!
[ 1251.668513] IQK: final_candidate is 0
[ 1251.672379] IQK: RegE94=104 RegE9C=14 RegEA4=0 RegEAC=0 RegEB4=0 RegEBC=0 RegEC4=0 RegECC=0
Path A IQ Calibration Success !
[ 1251.685692] _PHY_PathAFillIQKMatrix only Tx OK
[ 1251.794453] pdmpriv->TxPowerTrackControl = 1
[ 1251.801205] rtl8192cu_hal_init in 540ms
[ 1251.825412] <=== rtw_ips_pwr_up.............. in 580ms
[ 1251.830990] ==> ips_leave.....LED(0x00028080)...
[ 1253.135544] survey done event(12) band:0 for wlan0
wlan0 Scan completed :
Cell 01 - Address: 00:6B:8E:F1:6F:70
ESSID:"@PHICOMM_68"
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.427 GHz (Channel 4)
Encryption key:on
Bit Rates:300 Mb/s
Extra:wpa_ie=dd1a0050f20101000050f20202000050f2020050f20401000050f202
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
Extra:rsn_ie=30180100000fac020200000fac02000fac040100000fac020000
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
Quality=58/100 Signal level=57/100
Cell 02 - Address: B0:95:8E:5A:1C:18
ESSID:"huchengwei"
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.437 GHz (Channel 6)
Encryption key:on
Bit Rates:300 Mb/s
Extra:wpa_ie=dd160050f20101000050f20401000050f20401000050f202
IE: WPA Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Extra:rsn_ie=30140100000fac040100000fac040100000fac020000
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Quality=0/100 Signal level=10/100
Cell 03 - Address: EC:26:CA:41:63:FD
ESSID:"deutschwerkstatt"
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.437 GHz (Channel 6)
Encryption key:on
Bit Rates:144 Mb/s
Extra:wpa_ie=dd160050f20101000050f20401000050f20401000050f202
IE: WPA Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Extra:rsn_ie=30140100000fac040100000fac040100000fac020000
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Quality=0/100 Signal level=23/100
Cell 04 - Address: DC:FE:18:14:74:BE
ESSID:"YATIGERS-2.4G"
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.462 GHz (Channel 11)
Encryption key:on
Bit Rates:300 Mb/s
Extra:wpa_ie=dd1a0050f20101000050f20202000050f2020050f20401000050f202
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
Extra:rsn_ie=30180100000fac020200000fac02000fac040100000fac020000
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
Quality=66/100 Signal level=82/100

连接WiFi

root@am335x-evm:/mnt/wifi# ./iwconfig wlan0 key YTGS25257758
Error for wireless request "Set Encode" (8B2A) :
invalid argument "YTGS25257758".
root@am335x-evm:/mnt/wifi# ./iwconfig wlan0 essid "YATIGERS-2.4G"
[ 1421.483915] _rtw_pwr_wakeup call ips_leave....
[ 1421.488626] ==>ips_leave cnts:2
[ 1421.491926] ===> rtw_ips_pwr_up..............
[ 1421.496744] ===> ips_netdrv_open.........
[ 1421.505563] ===> FirmwareDownload91C() fw:Rtl819XFwImageArray_TSMC
[ 1421.512173] FirmwareDownload92C accquire FW from embedded image
[ 1421.518589] fw_ver=v88, fw_subver=2, sig=0x88c0
[ 1421.544544] fw download ok!
[ 1421.547499] Set RF Chip ID to RF_6052 and RF type to 1T1R.
[ 1421.866093] IQK:Start!!!
[ 1421.875145] Path A IQK Success!!
[ 1421.883112] Path A Rx IQK fail!!
[ 1421.888205] Path A Rx IQK fail!!
[ 1421.891601] Path A IQK Only Tx Success!!
[ 1421.902763] Path A IQK Success!!
[ 1421.908461] IQK: final_candidate is 0
[ 1421.912331] IQK: RegE94=104 RegE9C=14 RegEA4=ff RegEAC=0 RegEB4=0 RegEBC=0 RegEC4=0 RegECC=0
Path A IQ Calibration Success !
[ 1422.034466] pdmpriv->TxPowerTrackControl = 1
[ 1422.041203] rtl8192cu_hal_init in 540ms
[ 1422.065457] <=== rtw_ips_pwr_up.............. in 580ms
[ 1422.071035] ==> ips_leave.....LED(0x00028080)...
[ 1422.075945] =>rtw_wx_set_essid
[ 1422.079158] ssid=YATIGERS-2.4G, len=13
[ 1422.083503] Set SSID under fw_state=0x00000008
[ 1422.088213] [by_bssid:0][assoc_ssid:YATIGERS-2.4G][to_roaming:0] new candidate: YATIGERS-2.4G(dc:fe:18:14:74:be, ch11) rssi:-58
[ 1422.100317] rtw_select_and_join_from_scanned_queue: candidate: YATIGERS-2.4G(dc:fe:18:14:74:be, ch:11)
[ 1422.110203] link to Ralink AP
[ 1422.113385] <=rtw_wx_set_essid, ret 0
root@am335x-evm:/mnt/wifi# [ 1422.121616] set ch/bw before connected
[ 1422.125868] start_join_set_ch_bw: ch=11, bwmode=1, ch_offset=2
[ 1422.217255] link to Ralink AP
[ 1422.267760] OnAuthClient
[ 1422.270479] network.SupportedRates[0]=82
[ 1422.274601] network.SupportedRates[1]=84
[ 1422.278719] network.SupportedRates[2]=8B
[ 1422.282836] network.SupportedRates[3]=96
[ 1422.286954] network.SupportedRates[4]=12
[ 1422.291070] network.SupportedRates[5]=24
[ 1422.295188] network.SupportedRates[6]=48
[ 1422.299305] network.SupportedRates[7]=6C
[ 1422.303422] network.SupportedRates[8]=0C
[ 1422.307540] network.SupportedRates[9]=18
[ 1422.311658] network.SupportedRates[10]=30
[ 1422.315866] network.SupportedRates[11]=60
[ 1422.320079] bssrate_len = 12
[ 1422.342232] OnAssocRsp
[ 1422.344765] report_join_res(4)
[ 1422.348014] rtw_joinbss_update_network
[ 1422.351961] +rtw_update_ht_cap()
[ 1422.355382] rtw_joinbss_update_stainfo
[ 1422.359619] OnAction_back
[ 1422.362388] OnAction_back, action=0
[ 1422.366117] issue_action_BA, category=3, action=1, status=0
[ 1422.372152] HW_VAR_BASIC_RATE: BrateCfg(0x15d)
[ 1422.379523] WMM(0): 0, a42b
[ 1422.382886] WMM(1): 0, a44f
[ 1422.385902] WMM(2): 0, 5e4322
[ 1422.389088] WMM(3): 0, 2f3222
[ 1422.392211] HTOnAssocRsp
[ 1422.398868] update raid entry, mask=0xfffff, arg=0x80
[ 1422.405371] rtl8192c_set_FwJoinBssReport_cmd mstatus(1)
[ 1422.411380] SetFwRsvdPagePkt
[ 1422.415505] Set RSVD page location to Fw.
[ 1422.420276] =>mlmeext_joinbss_event_callback
[ 1427.075863] rtl8192c_dm_RF_Saving(): RF_Save
[ 1431.072987] rtw_set_ps_mode(): Enter 802.11 power save mode...
[ 1431.079829] rtl8192c_dm_RF_Saving(): RF_Normal
[ 1431.084564] rtl8192c_set_FwPwrMode_cmd(): Mode = 1, SmartPS = 2
root@am335x-evm:/mnt/wifi# ./iwconfig wlan0
[ 1499.280772] rtw_wx_get_rts, rts_thresh=2347
[ 1499.286239] rtw_wx_get_frag, frag_len=2346
wlan0 IEEE 802.11bgn ESSID:"YATIGERS-2.4G" Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency:2.462 GHz Access Point: DC:FE:18:14:74:BE
Bit Rate:150 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=99/100 Signal level=67/100 Noise level=0/100
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0

屏蔽eth0来试着ping网关

root@am335x-evm:/mnt/wifi# ./iwconfig wlan0
[ 1499.280772] rtw_wx_get_rts, rts_thresh=2347
[ 1499.286239] rtw_wx_get_frag, frag_len=2346
wlan0 IEEE 802.11bgn ESSID:"YATIGERS-2.4G" Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency:2.462 GHz Access Point: DC:FE:18:14:74:BE
Bit Rate:150 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=99/100 Signal level=67/100 Noise level=0/100
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
root@am335x-evm:/mnt/wifi# ifconfig
eth0 Link encap:Ethernet HWaddr 26:C7:3D:A0:40:61
inet addr:192.168.1.147 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10239 errors:0 dropped:7 overruns:0 frame:0
TX packets:3881 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:11213377 (10.6 MiB) TX bytes:278688 (272.1 KiB)
Interrupt:56
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:700 (700.0 B) TX bytes:700 (700.0 B)
wlan0 Link encap:Ethernet HWaddr 00:1D:43:30:1B:FC
inet addr:192.168.1.166 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:335 errors:0 dropped:339 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40400 (39.4 KiB) TX bytes:0 (0.0 B)
root@am335x-evm:/mnt/wifi# ifconfig eth0 down
root@am335x-evm:/mnt/wifi# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:700 (700.0 B) TX bytes:700 (700.0 B)
wlan0 Link encap:Ethernet HWaddr 00:1D:43:30:1B:FC
inet addr:192.168.1.166 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:375 errors:0 dropped:379 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:45253 (44.1 KiB) TX bytes:0 (0.0 B)
root@am335x-evm:/mnt/wifi# ping 192.168.1.1
[ 1606.213877] rtw_set_ps_mode(): Busy Traffic , Leave 802.11 power save..
[ 1606.221047] rtl8192c_set_FwPwrMode_cmd(): Mode = 0, SmartPS = 0
[ 1606.227764] OnAction_back
[ 1606.230533] OnAction_back, action=0
[ 1606.234249] issue_action_BA, category=3, action=1, status=0
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: seq=0 ttl=64 time=26.190 ms
64 bytes from 192.168.1.1: seq=1 ttl=64 time=13.609 ms
64 bytes from 192.168.1.1: seq=2 ttl=64 time=9.448 ms
64 bytes from 192.168.1.1: seq=3 ttl=64 time=13.246 ms
64 bytes from 192.168.1.1: seq=4 ttl=64 time=19.149 ms
64 bytes from 192.168.1.1: seq=5 ttl=64 time=25.671 ms
64 bytes from 192.168.1.1: seq=6 ttl=64 time=15.957 ms
--- 192.168.1.1 ping statistics ---
22 packets transmitted, 22 packets received, 0% packet loss
round-trip min/avg/max = 6.152/22.831/183.121 ms

用hostapd配置WiFi作为AP接入点

hostapd是一款运行在用户态软件,能够为认证服务器提供管理接入点。下面是无线网卡常见的工作模式及其作用。


显然,平时我们的计算机的无线网卡一般工作在Managed模式,而我们平常使用的路由器的无线网卡则是一般工作在Master模式。我们借助hostapd让我们计算机的无线网卡更换模式,使其工作在Master模式,这样我们的计算机就能够成为一个无线接入点从而为其他设备提供服务。

移植hostapd

libnl库的安装

libnl源码官网http://www.infradead.org/~tgr/libnl/
    下载1.1版本的、libnl-1.1.4.tar.gz
    解压
    tar -xvf libnl-1.1.4.tar.gz
    mkdir install
    配置安装目录
    ./configure -prefix=/home/fluency/workspace/wifi/libnl-1.1.4/install
    编译
    make CC=arm-linux-gnuabihf-gcc
    make install

openssl库的安装

OpenSSL官网https://www.openssl.org/source/old/0.9.x/
    下载openssl-0.9.8e.tar.gz
    解压配置
    tar -xvf openssl-0.9.8e.tar.gz
    mkdir install
    安装目录
    ./config -prefix=/home/fluency/workspace/wifi/openssl-0.9.8e/install/
    交叉编译工具
    ./config os/compiler:arm-linux-gnueabihf-gcc
    make
    make install

hostapd的编译

    到官网下载源码http://w1.fi/releases/snapshots/ hostapd-0.8-snapshot.tar.gz

     解压配置

    tar -xvf hostapd-0.8-snapshot.tar.gz

    cp deconfig .config

    vim .config


修改Makefile
指定libnl、ssl的头文件和库文件路径

关于Relocations in generic ELF (EM: 40)的解决办法

然后命令编译(指定编译器和连接工具)
make CC=arm-linux-gnueabihf-gcc LD=arm-linux-gnueabihf-ld
移植
hostapd hostapd_cli 可执行文件
运行中出现库文件缺失(进行cp)
fluency@ubuntu:~/workspace/wifi/libnl-1.1.4/install/lib$ cp libnl.so* /home/fluency/nfsboot/wifi/
sudo ln -s 源文件 目标文件 (为库文件创建连接)

命令执行AP设置

/*---------配置文件AM335Wifi.conf----------------------*/
interface=wlan0
ssid=Fluency
channel=9
hw_mode=g
ignore_broadcast_ssid=0
auth_algs=1
wpa=3
wpa_passphrase=12345679
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
/*------------------------------------------*/
root@am335x-evm:/mnt/wifi# ./hostapd ./AM335Wifi.conf -B
Configuration file: ./hostapAP.conf
drv->ifindex=4
l2_sock_recv==l2_sock_xmit=0x0x5[28441.760693] _rtw_pwr_wakeup call ips_leave....
2630
[28441.768844] ==>ips_leave cnts:3
[28441.772652] ===>  rtw_ips_pwr_up..............
[28441.777335] ===> ips_netdrv_open.........
[28441.786126]  ===> FirmwareDownload91C() fw:Rtl819XFwImageArray_TSMC
[28441.792915] FirmwareDownload92C accquire FW from embedded image
[28441.799145] fw_ver=v88, fw_subver=2, sig=0x88c0
[28441.824193] fw download ok!
[28441.827141] Set RF Chip ID to RF_6052 and RF type to 1T1R.
[28442.136384] IQK:Start!!!
[28442.145387] Path A IQK Success!!
[28442.153503] Path A IQK Success!!
[28442.159184] IQK: final_candidate is 0
[28442.163094] IQK: RegE94=104 RegE9C=14 RegEA4=ff RegEAC=1 RegEB4=0 RegEBC=0 RegEC4=0 RegECC=0
 Path A IQ Calibration Success !
[28442.284387] pdmpriv->TxPowerTrackControl = 1
[28442.291139] rtl8192cu_hal_init in 510ms
[28442.315333] <===  rtw_ips_pwr_up.............. in 540ms
[28442.320912] ==> ips_leave.....LED(0x00028080)...
[28442.325816] set_mode = IW_MODE_MASTER
[28442.330516] hw_var_set_opmode()-4234 mode = 3
[28442.335576] rtw_hostapd_sta_flush
[28442.340158] rtw_sta_flush(wlan0)
[28442.343639] issue_deauth to ff:ff:ff:ff:ff:ff
+rtl871x_sta_deauth_ops, ff:ff:ff:ff:ff:ff is de[28442.349304] rtw_set_encryption
auth, reason=2
rtl871x_set_key_ops
[28442.356518] clear default encryption keys, keyid=0
rtl871x_set_key_ops
[28442.366165] rtw_set_encryption
[28442.371042] clear default encryption keys, keyid=1
rtl871x_set_key_ops
[28442.376983] rtw_set_encryption
[28442.381887] clear default encryption keys, keyid=2
rtl871x_set_key_ops
[28442.387511] rtw_set_encryption
[28442.392466] clear default encryption keys, keyid=3
Using interface wlan0 with hwaddr 00:1d:43:30:1b:fc and ssid 'YOUR_SSID'
rtl871x_set_wps_assoc_resp_ie
[28442.551185] rtw_set_wps_assoc_resp, len=14
rtl871x_set_wps_beacon_ie
[28442.558408] rtw_set_wps_beacon, len=14
rtl871x_set_wps_probe_resp_ie
[28442.564877] rtw_set_wps_probe_resp, len=14
rtl871x_set_key_ops
[28442.580558] rtw_set_encryption
[28442.585520] rtw_set_encryption, set group_key, TKIP
[28442.590653] set_group_key
[28442.594451] SetHwReg8192CU, 5126, RCR= 7000228e 
rtl871x_set_beacon_ops
[28442.599478] rtw_set_beacon, len=105
[28442.605184] rtw_check_beacon_data, len=91
[28442.613419] CH=9, BW=0, offset=0
[28442.617047] HW_VAR_BASIC_RATE: BrateCfg(0x15d)
[28442.623180] update_bmc_sta, mask=0x6000000f, arg=0x81
rtl871x_set_hidden_ssid ignore_broadcast_ssid:0,[28442.628976] rtw_set_hidden_ssid(wlan0) ignore_broadcast_ssid:0, YOUR_SSID,9 YOUR_SSID,9rtl871x_set_acl
[28447.325844] rtl8192c_dm_RF_Saving(): RF_Normal
[28519.433519] IQK:Start!!!
[28519.442255] Path A IQK Success!!
[28519.451203] Path A IQK Success!!
[28519.457527] IQK: final_candidate is 0
[28519.461397] IQK: RegE94=103 RegE9C=11 RegEA4=fe RegEAC=2 RegEB4=0 RegEBC=0 RegEC4=0 RegECC=0

 Path A IQ Calibration Success !

配置DHCP服务
root@am335x-evm:/mnt/wifi#udhcpd ./udhcpd.conf
/*---------配置文件udhcpd.conf----------------------*/
start   192.168.63.100
end             192.168.63.254
interface       wlan0
opt     dns     192.168.10.2 192.168.10.10
option  subnet  255.255.255.0
opt     router  192.168.63.70
opt     wins    192.168.63.10
option  dns     129.219.13.81   # appened to above DNS servers for a total of 3
option  domain  local

option  lease   864000          # 10 days of seconds

/*------------------------------------------*/
连接加入AP热点
name为Fluency
passwd为12345679
可以看到分配的ID为192.168.2.100


root@am335x-evm:/mnt/wifi# ping 192.168.2.100
PING 192.168.2.100 (192.168.2.100): 56 data bytes
64 bytes from 192.168.2.100: seq=0 ttl=64 time=129.361 ms
64 bytes from 192.168.2.100: seq=1 ttl=64 time=143.283 ms
64 bytes from 192.168.2.100: seq=2 ttl=64 time=34.387 ms
64 bytes from 192.168.2.100: seq=3 ttl=64 time=70.293 ms
64 bytes from 192.168.2.100: seq=4 ttl=64 time=79.402 ms
64 bytes from 192.168.2.100: seq=5 ttl=64 time=103.304 ms
--- 192.168.2.100 ping statistics ---
35 packets transmitted, 35 packets received, 0% packet loss
round-trip min/avg/max = 24.044/76.401/150.222 ms
到此RTL8188CU模块驱动的驱动所有功能都已完成
添加到rc.local脚本启动

WiFi性能测试

用iperf命令
启动tcp服务器

手机软件netwroktool


然后server端就能看到测试带宽信息



以上完成对WiFi驱动的所有工作、设备就有了一个无线网卡啦

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值