嵌入式Linux使用USB无线网卡

      参考http://www.linuxidc.com/Linux/2013-07/86994.htm,

      我使用磊科的NW362,使用芯片rtl8192cu,VID:PID=0bda:8178,已经在源码中了,不需要添加

      官网下载驱动源代码 

http://www.realtek.com.tw/downloads/downloadsView.aspx?Langid=3&PNid=48&PFid=48&Level=5&Conn=4&DownTypeID=3&GetDown=false&Downloads=true#RTL8188CE


      搜索下载8192cu,0001-RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911.zip


      在driver下rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911.tar.gz 即为驱动解压,在Makefile中添加一些信息,这里添加:

xxxxxxx  (环境变量的设置, 这里我使用include $(TOPDIR)/Makefile.in)


CONFIG_PLATFORM_ARM_GM8139 = y


($(CONFIG_PLATFORM_ARM_GM8139), y)
EXTRA_CFLAGS += -DCONFIG_LITTLE_ENDIAN
ARCH := arm
CROSS_COMPILE := arm-linux-
KSRC = $(LINUX_SRC)
endif


     编写build.sh:关键

echo "LINUX_SRC=/home/ubuntu/WORKING_DIRECTORY/fuchch/gm8139/linux-3.3-fa/" > Makefile.in
echo "CROSS_COMPILE=arm-unknown-linux-uclibcgnueabi-" >> Makefile.in

make TOPDIR=`pwd`


     编译得到8192cu.ko


      在板子上加载,输出信息

[root@GK sdcard]# insmod 8192cu.ko
rtl8192cu driver version=v4.0.2_9000.20130911
build time: May  4 2016 10:50:26
usbcore: registered new interface driver rtl8192cu


      插入USB网卡,输出信息

[root@GK sdcard]# usb 1-1: new high-speed USB device number 4 using fotg210

usb_endpoint_descriptor(0):
bLength=7
bDescriptorType=5
bEndpointAddress=81
wMaxPacketSize=200
bInterval=0
RT_usb_endpoint_is_bulk_in = 1

usb_endpoint_descriptor(1):
bLength=7
bDescriptorType=5
bEndpointAddress=2
wMaxPacketSize=200
bInterval=0
RT_usb_endpoint_is_bulk_out = 2

usb_endpoint_descriptor(2):
bLength=7
bDescriptorType=5
bEndpointAddress=3
wMaxPacketSize=200
bInterval=0
RT_usb_endpoint_is_bulk_out = 3

usb_endpoint_descriptor(3):
bLength=7
bDescriptorType=5
bEndpointAddress=84
wMaxPacketSize=40
bInterval=1
RT_usb_endpoint_is_int_in = 4, Interval = 1
nr_endpoint=4, in_num=2, out_num=2

USB_SPEED_HIGH
CHIP TYPE: RTL8188C_8192C
register rtw_netdev_ops to netdev_ops
Chip Version ID: VERSION_NORMAL_TSMC_CHIP_92C.
RF_Type is 2!!
EEPROM type is E-FUSE
====> ReadAdapterInfo8192C
Boot from EFUSE, Autoload OK !
EEPROMVID = 0x0bda
EEPROMPID = 0x8178
EEPROMCustomerID : 0x00
EEPROMSubCustomerID: 0x00
RT_CustomerID: 0x00
_ReadMACAddress MAC Address from EFUSE = 08:10:79:17:db:6b
EEPROMRegulatory = 0x0
_ReadBoardType(0)
BT Coexistance = disable
mlmepriv.ChannelPlan = 0x02
_ReadPSSetting...bHWPwrPindetect(0)-bHWPowerdown(0) ,bSupportRemoteWakeup(0)
### PS params=>  power_mgnt(1),usbss_enable(0) ###
### AntDivCfg(0)
readAdapterInfo_8192CU(): REPLACEMENT = 1
<==== ReadAdapterInfo8192C in 130 ms
rtw_macaddr_cfg MAC Address  = 08:10:79:17:db:6b
bDriverStopped:1, bSurpriseRemoved:0, bup:0, hw_init_completed:0
_rtw_drv_register_netdev, MAC Address (if1) = 08:10:79:17:db:6b


      默认是wlan0,

[root@GK sdcard]# ifconfig wlan0 up
+871x_drv - drv_open, bup=0
 ===> FirmwareDownload91C() fw:Rtl819XFwImageArray_TSMC
FirmwareDownload92C accquire FW from embedded image
fw_ver=v88, fw_subver=2, sig=0x88c0
fw download ok!
Set RF Chip ID to RF_6052 and RF type to 2.
IQK:Start!!!
Path A IQK Success!!
Path B IQK Success!!
Path A IQK Success!!
Path B IQK Success!!
IQK: final_candidate is 0
IQK: RegE94=ff RegE9C=3 RegEA4=fd RegEAC=3fd RegEB4=ff RegEBC=c RegEC4=f9 RegECC=4
 Path A IQ Calibration Success !
Path B IQ Calibration Success !
pdmpriv->TxPowerTrackControl = 1
rtl8192cu_hal_init in 550ms
MAC Address = 08:10:79:17:db:6b
-871x_drv - drv_open, bup=1
[root@GK sdcard]# ==>rtw_ps_processor .fw_state(0)
==>ips_enter cnts:1
===> rtw_ips_pwr_down...................
====> rtw_ips_dev_unload...
usb_read_port_cancel
usb_read_port_complete()-1284: RX Warning! bDriverStopped(0) OR bSurpriseRemoved(0) bReadPortCancel(1)
usb_read_port_complete()-1284: RX Warning! bDriverStopped(0) OR bSurpriseRemoved(0) bReadPortCancel(1)
usb_read_port_complete()-1284: RX Warning! bDriverStopped(0) OR bSurpriseRemoved(0) bReadPortCancel(1)
usb_read_port_complete()-1284: RX Warning! bDriverStopped(0) OR bSurpriseRemoved(0) bReadPortCancel(1)
usb_write_port_cancel
==> rtl8192cu_hal_deinit
bkeepfwalive(0)
card disble without HWSM...........
<=== rtw_ips_pwr_down..................... in 90ms


      ifconfig查看

[root@GK sdcard]# ifconfig
wlan0     Link encap:Ethernet  HWaddr 08:10:79:17:DB:6B  
          UP BROADCAST RUNNING 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)


       OK,下面就是wireless_tools及wpa_supplicant_hostapd

       Wireless tools for Linux是一个Linux命令行工具包,用来设置支持Linux Wireless Extension的无线设备。Wireless tools for Linux 和 Linux Wireless Extension 由 Jean Tourrilhes在维护,由Hewlett-Packard(HP惠普)赞助。

      经常会用到的主要是iwlist、iwconfig、 iwpriv:

命令行:(ap不需要验证密码)

iwlist mlan0 scan //搜索ap

iwconfig mlan0 essid “linksys” //连接ap

udhcpc –i mlan0  //获得动态IP

 

命令行:(ap需要验证密码)

iwlist mlan0 scan //搜索ap

iwconfig mlan0 key  xxxxxxxxxx  // 输入验证密码

iwconfig mlan0 key open //密码验证功能打开

iwconfig mlan0 essid “linksys” //连接ap

udhcpc –i mlan0 //获得动态IP

 

   关于iwconfig 可以看上一篇文章;这里补充一下有关iwpriv:
       [root@root- /]#iwpriv
    mlan0     Available private ioctls :
          extscan          (8BFA) : set   0 int   & get   2 char
          hostcmd          (8BE4) : set 2047 byte  & get 2047 byte
          arpfilter        (8BE6) : set 2047 byte  & get 2047 byte


---------------------------------------------------------------------------------------------------------------------------------------------------------

      在wireless_tools下有wireless_tools.30.rtl.tar.gz,解压,采用的是静态编译,得到ifrename、iwconfig、iwevent、iwgetid、iwlist、iwpriv、iwspy


      拷贝、测试:

[root@GK bin]# ./iwconfig
lo        no wirelrtw_wx_get_rts, rts_thresh=2347
rtw_wx_get_frag, frag_len=2346


wlan0     unassociated  Nickname:"<WIFI@REALTEK>"
          Mode:Auto  Frequency=2.412 GHz  Access Point: Not-Associated   
          Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality:0  Signal level:0  Noise level:0
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

eth0      no wireless extensions.


---------------------------------------------------------------------------------------------------------------------------------------------------------

wpa_supplicant_hostapd

      hostapd是架设软AP的,这里不做AP使用,可以不移植,以后有需求再说。

      wpa_supplicant是用以支持WPA/WPA2的,现在推荐使用WPA/WPA2,所以需要移植。

      编译时提示 netlink/genl/genl.h: No such file or directory,需要移植libnl


      编译得到wpa_cli wpa_supplicant wpa_passphrase


     使用:参考http://blog.csdn.net/ziyouwa/article/details/12081009


Wpa_supplicant是linux系统下一个非常强大的无线网卡管理程序。google搜索到的它似乎不支持WPA2和AES,其实不然,参考它的文档可以发现,WPA2只是RSN的别名,而AES也是CCMP的一部分,所以它们的支持完全是没有问题的。

它的文档看起来非常复杂,其实配置非常简单,下面先给出我的wpa_supplication.conf

[python] view plain copy
  1. ctrl_interface=/var/run/wpa_supplicant  
  2. ctrl_interface_group=wheel  
  3. update_config=1  
  4.   
  5. network={  
  6.     ssid="xxxx"  
  7.     scan_ssid=1  
  8.     psk=xxxxxxxxx37bca5cf24a345f514d319211822f568bba28f8f0b74c894e7644  
  9.     proto=RSN  
  10.     key_mgmt=WPA-PSK  
  11.     pairwise=CCMP  
  12.     auth_alg=OPEN  
  13. }  

解释一下上面的比较容易困惑的地方:

签名三句应该是个模板,没仔细研究过。

network=开始是无线接入点的具体配置,一般的无线接入点可以用wpa_passphrase来自动生成,语法是

[python] view plain copy
  1. yj@YJ_N ~ $ wpa_passphrase  
  2. usage: wpa_passphrase <ssid> [passphrase]  
  3.   
  4. If passphrase is left out, it will be read from stdin  
  5.   
  6. 接下来看个实例:  
  7.   
  8. yj@YJ_N ~ $ wpa_passphrase TPLINK 12345678  
  9. network={  
  10.         ssid="TPLINK"  
  11.         #psk="12345678"  
  12.         psk=992194d7a6158009bfa25773108291642f28a0c32a31ab2556a15dee97ef0dbb  
  13. }  
  14. 这里表示名为TPLINK的接入点,密码是12345678,输出就是该接入点在wpa_supplicant.conf里面的配置内容,可以直接用下面的命令自动写入  
  15.   
  16. yj@YJ_N ~ $ wpa_passphrase TPLINK 12345678 |sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf  

继续解释最开始的例子,network=后面的内容

ssid :接入点名称,这个没什么好说的

scan_ssid=1 :这个很容易错过,如果你的无线接入点是隐藏的,那么这个就是必须的,亲身经历,折腾了好久才搞定,记之备忘。

psk=xx :是加密后的密码,用wpa_passphrase自动生成的

proto=RSN  WPA2就选这个,抄一下官方配置文件例子里面的:

[python] view plain copy
  1. # proto: list of accepted protocols ---支持的协议列表  
  2. # WPA = WPA/IEEE 802.11i/D3.0    
  3. # RSN = WPA2/IEEE 802.11i (also WPA2 can be used as an alias for RSN) ---也能使用WPA2,它只是RSN的一个别名而已  
  4. # If not set, this defaults to: WPA RSN   ---如果不设置,默认就是WPA RSN,即全部支持  

key_mgmt= 认证密钥管理协议,还是抄:

[python] view plain copy
  1. # key_mgmt: list of accepted authenticated key management protocols  ---支持的协议列表  
  2. # WPA-PSK = WPA pre-shared key (this requires 'psk' field)     ---一般都是这个,这就包括了WPA、WPA2开始的那些方式  
  3. # WPA-EAP = WPA using EAP authentication    ---这个就是WEP开头的,猜的,求验证  
  4. # IEEE8021X = IEEE 802.1X using EAP authentication and (optionally) dynamically  
  5. #   generated WEP keys  
  6. # NONE = WPA is not used; plaintext or static WEP could be used  ---这个是开放的,没密码,联通、电信之类的就这个  
  7. # WPA-PSK-SHA256 = Like WPA-PSK but using stronger SHA256-based algorithms  
  8. # WPA-EAP-SHA256 = Like WPA-EAP but using stronger SHA256-based algorithms  
  9. # If not set, this defaults to: WPA-PSK WPA-EAP ---如果未设置,默认支持WAP、WEP开头那些  

pairwise= 这个就是加密方式,继续抄

[python] view plain copy
  1. # pairwise: list of accepted pairwise (unicast) ciphers for WPA   ---WPA可用的加密方式列表  
  2. # CCMP = AES in Counter mode with CBC-MAC [RFC 3610, IEEE 802.11i/D7.0]  ---看到没,这个就是AES,换了马甲而已  
  3. # TKIP = Temporal Key Integrity Protocol [IEEE 802.11i/D7.0] ---TKIP 这个倒是没变  
  4. # NONE = Use only Group Keys (deprecated, should not be included if APs support  
  5. #   pairwise keys)   ---这个估计很少用  
  6. # If not set, this defaults to: CCMP TKIP  ---不设置的话是CCMP TKIP,看似正确,其实有些路由器无法自动识别,只能二选一,很坑爹。 

   



      1. 加载网卡驱动

      2. 插上USB网卡

      3. iwconfig查看(结果为wlan0)

      4. 使用ifconfig(ifup不知道怎么用)来启动 ifconfig wlan0 up

      5. iwlist wlan0 scan扫描周围可连接的无线网路

      6. wpa_passphrase netname passwd > wpa_supplicant.conf生成配置文件

      7. 修改wpa_supplicant.conf

      8. 启动 wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -d


      但是提示Could not open file /sys/class/net/wlan0/phy80211/name: No such file or directory


      后来发现linux内核还得配置,除了wireless支持外,在

Device Drivers  --->

      [*] Staging drivers  --->

             <*>   USB/IP support (EXPERIMENTAL)

             <M>   Support for rtllib wireless devices

             <M>     Support for rtllib CCMP crypto

             <M>     Support for rtllib TKIP crypto

             <M>     Support for rtllib WEP crypto

你可能感兴趣的:(嵌入式Linux使用USB无线网卡)