USB接口WIFI(MT7601芯片)的驱动源码移植过程详解(驱动源码编译wpa_supplicant工具交叉编译文件系统移植)

Posted 正在起飞的蜗牛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了USB接口WIFI(MT7601芯片)的驱动源码移植过程详解(驱动源码编译wpa_supplicant工具交叉编译文件系统移植)相关的知识,希望对你有一定的参考价值。

1、MT7601的移植步骤

(1)确认你的WT7601网卡硬件是正常的;
(2)修改驱动源码,依赖内核源码树编译并加载;
(3)交叉编译wpa_supplicant工具,移植到根文件系统里;
(4)添加驱动和wpa_supplicant工具依赖的配置文件;
(5)在终端手动执行命令进行上网;
(6)在启动脚步中添加配置网卡并上网的命令,实现开机自动连接WIFI上网;

2、网卡硬件的确认

[root@X210 ]# lsusb 
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 05e3:0608
[root@X210 ]# lsusb 
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 05e3:0608
Bus 001 Device 005: ID 148f:7601

(1)将MT7601WIFI网卡插到开发板的USB口,用lsusb命令可以看到在插网卡后多出来一个usb设备(ID 148f:7601);
(2)其中148f是厂商的ID,表示是哪家厂商生产的芯片;
(3)7601是产品的ID,表示是哪款产品;我们用的是MT7601芯片,MT代表厂商联发科,产品ID是7601;

3、驱动源码移植

3.1、修改源码的Makefile

# 指定WIFI是在什么平台上运行
PLATFORM = SMDK

# 指定内核源码树和编译链
ifeq ($(PLATFORM),SMDK)
LINUX_SRC = /home/daizhixin/S5PV210/kernel/kernel/
CROSS_COMPILE = /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
endif

(1)MT7601驱动源码已经在各种芯片平台上做过移植,需要先选择芯片平台;
(2)设置内核源码树和编译链,这是编译驱动的基础;

3.2、修改USB的VID和PID

/* module table */
USB_DEVICE_ID rtusb_dev_id[] = 
#ifdef RT6570
	USB_DEVICE(0x148f,0x6570), /* Ralink 6570 */
#endif /* RT6570 */
	USB_DEVICE(0x148f, 0x7650), /* MT7650 */
#ifdef MT7601U
	USB_DEVICE(0x148f,0x6370), /* Ralink 6370 */
	USB_DEVICE(0x148f,0x7601), /* MT 6370 */
	USB_DEVICE(0x148f,0x760b),
#endif /* MT7601U */
	 /* Terminating entry */
;

struct usb_driver rtusb_driver = 
		name:RTMP_DRV_NAME,		//用于驱动和设备匹配的名字
		probe:rtusb_probe,
		disconnect:rtusb_disconnect,
		id_table:rtusb_dev_id,	//驱动用来和设备匹配的数组表
	;

(1)在第一步的网卡硬件确认中已经知道了WIFI网卡USB的VID和PID;
(2)rtusb_dev_id数组是此驱动支持的设备的USB的VID和PID,所以rtusb_dev_id数组里必须要配置USB_DEVICE(0x148f,0x7601),也就是必须要定义MT7601U宏;
(3)USB_DEVICE(0x148f,0x7601)是驱动和设备做匹配用的,驱动和设备匹配基本上是两种方式:直接用name去匹配或者在数组中去查找匹配,先匹配name再匹配数组;

3.3、MT7601U的定义

# 驱动的顶层Makefile
ifeq ($(CHIPSET),)
CHIPSET = 7601U
endif

# os/linux/config.mk
ifneq ($(findstring 7601U,$(CHIPSET)),)
WFLAGS += -DMT7601U -DMT7601 -DRLT_MAC -DRLT_RF -DRTMP_MAC_USB -DRTMP_USB_SUPPORT -DRTMP_TIMER_TASK_SUPPORT -DRX_DMA_SCATTER -DVCORECAL_SUPPORT -DRTMP_EFUSE_SUPPORT -DNEW_MBSSID_MODE -DRTMP_INTERNAL_TX_ALC -DCONFIG_ANDES_SUPPORT -DDPD_CALIBRATION_SUPPORT
ifneq ($(findstring $(RT28xx_MODE),AP),)
#WFLAGS += -DSPECIFIC_BCN_BUF_SUPPORT
endif

(1)在顶层Makefile中,有CHIPSET变量,我们在编译时没有传参就默认等于7601U;
(2)在config.mk配置文件中,会判断CHIPSET 的值,如果等于7601U就会在WFLAGS 变量中追加配置,其中就包括"-DMT7601",效果就是定义了MT7601宏;

3.4、开启Wpa_Supplicant支持

# Support Wpa_Supplicant
# i.e. wpa_supplicant -Dralink
HAS_WPA_SUPPLICANT=y

修改os/linux/config.mk配置文件的HAS_WPA_SUPPLICANT配置项,只有开启以后WIFI才能使用Wpa_Supplicant;

3.5、修改WIFI网卡的名字

#ifdef android_SUPPORT
#define INF_MAIN_DEV_NAME		"wlan"
#define INF_MBSSID_DEV_NAME		"wlan"
#else
#define INF_MAIN_DEV_NAME		"ra"
#define INF_MBSSID_DEV_NAME		"ra"
#endif /* ANDROID_SUPPORT */

在rtmp_def.h中,有两个宏去定义WIFI网卡的名字,也就是将来用ifconfig命令看到的网卡名字, 常用的WIFI网卡名字就是wlan和ra;

4、交叉编译wpa_supplicant工具

参考博客:《wpa_supplicant工具移植到嵌入式设备》

5、文件系统中配置WIFI网卡

5.1、MT7601网卡的配置文件

#ifdef RTMP_MAC_USB
#define STA_PROFILE_PATH			"/etc/Wireless/RT2870STA/RT2870STA.dat"
#define STA_DRIVER_VERSION			"3.0.0.3"
#ifdef MULTIPLE_CARD_SUPPORT
#define CARD_INFO_PATH			"/etc/Wireless/RT2870STA/RT2870STACard.dat"
#endif /* MULTIPLE_CARD_SUPPORT */
#endif /* RTMP_MAC_USB */

(1)在rt_drv.h文件中,CARD_INFO_PATH宏指定了驱动配置文件的路径;
(2)RT2870STACard.dat配置文件在驱动源码中,将其拷贝到"/etc/Wireless/RT2870STA/RT2870STACard.dat"目录;
(3)如果没有这个配置文件,驱动可以正常安装,"ifconfig -a"可以看到WIFI网卡ra0,但是无法开启WIFI网卡;

5.2、wpa_supplicant的配置文件

5.2.1、配置文件的说明

You will need to make a configuration file, e.g.,
/etc/wpa_supplicant.conf, with network configuration for the networks
you are going to use. Configuration file section below includes
explanation fo the configuration file format and includes various
examples. Once the configuration is ready, you can test whether the
configuration work by first running wpa_supplicant with following
command to start it on foreground with debugging enabled:

wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -d

Assuming everything goes fine, you can start using following command
to start wpa_supplicant on background without debugging:

wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -B

Please note that if you included more than one driver interface in the
build time configuration (.config), you may need to specify which
interface to use by including -D<driver name> option on the command
line. See following section for more details on command line options
for wpa_supplicant.

上面摘抄自wpa_supplicant.conf源码的README说明文件,wpa_supplicant工具在运行时需要依赖"/etc/wpa_supplicant.conf"配置文件;

5.2.2、/etc/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant

network=
        key_mgmt=WPA-PSK	# 密码管理模式
        ssid="qin_da_mao"	# 要连接的WIFI的名字
        psk="18100170821"	# 要连接的WIFI的密码

5.3、/var/run/wpa_supplicant

(1)/var/run/wpa_supplicant是默认的也是推荐使用的存放套接字的目录,wpa_cli将会在尝试和wpa_supplicant连接时使用它;
(2)如果当前文件系统没有这个目录,需要新建,否则执行wpa_supplicant时会报错;

5.4、 添加NDS服务器:/etc/resolv.conf

nameserver 192.168.31.1

(1)/etc/resolv.conf文件是配置DNS服务器的ip地址,关键字是nameserver ,后面跟DNS服务器的ip地址,上面配置了一个DNS服务器ip地址,还可以在后面再设置多个DNS服务器地址;
(2)上面设置的192.168.31.1是路由器的地址,实际上路由器既是网关又是DNS服务器;

6、确定网关IP和DNS服务器的IP

(1)先用电脑连接上路由器,在Windows中可以看到连接上的WIFI的信息;
(2)上面是用我的电脑连接上名字为"qin_da_mao"的WIFI,我电脑无线网卡分配到的ip是192.168.31.14,网关和路由器都是192.168.31.1;

7、确认网关支持的IP地址范围

(1)登录路由器的管理界面:在游览器中输入路由器的IP地址,登录路由器的管理界面,我这里就是192.168.31.1;
(2)在局域网设置界面可以看到路由器中可分配的ip地址范围是192.168.31.5——192.168.31.254;
(3)如果我们给无线网卡静态设置ip,要范围就只能是192.168.31.5——192.168.31.254,并且需要保证这个ip地址在局域网内没有其他设备占用;

8、确认板子是否连接上路由器


(1)在路由器的管理界面可以看到已经连接上路由器的设备;在板子的终端用ifconfig命令查看
网卡的ip地址和MAC地址;
(2)两者对照就可以知道板子的无线网卡是否已经连接上路由器;

8、终端手动连接WIFI并上网

8.1、执行的命令

ifconfig //查看当前开启的网卡
insmod mt7601Usta.ko            //安装驱动程序
ifconfig -a //查看当前所以的网卡,确认是否有无线网卡ra0
mkdir -p /var/run/wpa_supplicant //创建目录
ifconfig ra0 up                 //开启无线网卡
wpa_supplicant -B -c /etc/wpa_supplicant.conf -i ra0  	//连接无线网络
wpa_cli -i ra0 status       	//查看连接状态
ifconfig ra0 192.168.31.20 255.255.255.0 192.168.31.1  	//手动配置ip,注意不能和有线网卡在同一网段
route add default gw 192.168.31.1 dev ra0  				//配置网关为ra0
ping 192.168.31.1    			//ping 网关
ping 8.8.8.8        			//ping 外网
ping 192.168.31.14				//ping局域网内的设备,也就是同样连接到路由器的设备,192.168.31.14	是我电脑的ip
ping www.baidu.com   			//验证DNS服务器是否有效

(1)上面配置的硬件条件:板子上有两张网卡,有线网卡和无线网卡(MT7601),其中有线网卡直连电脑(网段:192.168.1.0),无线网卡连接WIFI;
(2)上面是手动设置ra0的IP地址,IP地址要符合路由器分配的IP地址范围;
(3)默认网关要设置成ra0,这样ping外网时才会从ra0发消息;
(4)有线网卡的网络ip是可以手动改的,只有电脑端和板子的有线网卡在同一网段就行;
(5)无线网卡ra0的ip不能随便设置,需要查看路由器支持的IP地址范围;

8.2、命令执行的过程

[root@X210 ]# insmod mt7601Usta.ko //加载驱动
[   42.356187] rtusb init rt2870 --->
[   42.359130] ===>rt2870_probe()!
[   42.361233] --> RTMPAllocAdapterBlock
······
[   42.557017] <===rt2870_probe()!
[   42.561914] usbcore: registered new interface driver rt2870
[root@X210 ]# 
[root@X210 ]# 
[root@X210 ]# ifconfig -a	//确认驱动加载后是否生成ra0网卡
eth0      Link encap:Ethernet  HWaddr 00:09:C0:FF:EC:48  
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::209:c0ff:feff:ec48%2065568/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11814 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9615 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:16755646 (15.9 MiB)  TX bytes:1167002 (1.1 MiB)
          Interrupt:42 Base address:0x4300 

ifb0      Link encap:Ethernet  HWaddr 1A:2C:67:D8:9C:51  
          BROADCAST NOARP  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:32 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ifb1      Link encap:Ethernet  HWaddr DA:10:2D:44:71:98  
          BROADCAST NOARP  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:32 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ip6tnl0   Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          NOARP  MTU:1460  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:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1%2064704/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  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:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ra0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          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)

sit0      Link encap:IPv6-in-IPv4  
          NOARP  MTU:1480  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:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
[root@X210 ]# 
[root@X210 ]# mkdir -p /var/run/wpa_supplicant	//wpa_supplicant工具需要的目录
[root@X210 ]# 
[root@X210 ]# ifconfig ra0 up	//开启ra0网卡
[   66.726358] WlanFunCtrl.word = 0xff200003
[   66.729281] MACVersion = 0x76010500
······
[   67.991147] CNTL - All roaming failed, restore to channel 1, Total BSS[00]
[   67.998013] ==>  DMAIdle, GloCfg=0x40000050
[root@X210 ]# 
[root@X210 ]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:09:C0:FF:EC:48  
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::209:c0ff:feff:ec48%2065568/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11925 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9716 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:16788584 (16.0 MiB)  TX bytes:1192732 (1.1 MiB)
          Interrupt:42 Base address:0x4300 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1%2064704/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  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:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ra0       Link encap:Ethernet  HWaddr 1C:BF:CE:22:D4:AB  
          inet6 addr: fe80::1ebf:ceff:fe22:d4ab%2066432/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:25 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:5167 (5.0 KiB)  TX bytes:0 (0.0 B)

[root@X210 ]# 
[root@X210 ]# wpa_supplicant -B -c /etc/wpa_supplicant.conf -i ra0	//连接WIFI
Successfully initialized wpa_supplicant

[   86.623522] Read: SHARED_KEY_MODE_BASE at this Bss[0] KeyIdx[1]= 0x0 
[   86.628495] Write: SHARED_KEY_MODE_BASE at this Bss[0] = 0x30 
······
[root@X210 ]# 
[root@X210 ]# wpa_cli -i ra0 status 	//查看WIFI是否连接上
bssid=8c:53:c3:e4:34:90
freq=0
ssid=qin_da_mao	//WIFI的名字
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=TKIP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
address=1c:bf:ce:22:d4:ab	//ra0无线网卡的MAC地址
[root@X210 ]# 
[root@X210 ]# ifconfig ra0 192.168.31.20 255.255.255.0 192.168.31.1	//设置ra0的IP地址
ifconfig: SIOCSIFADDR: Invalid argument
[root@X210 ]# 
[root@X210 ]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:09:C0:FF:EC:48  
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::209:c0ff:feff:ec48%2065568/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:14440 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11788 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:20185246 (19.2 MiB)  TX bytes:1461692 (1.3 MiB)
          Interrupt:42 Base address:0x4300 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1%2064704/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  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:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ra0       Link encap:Ethernet  HWaddr 1C:BF:CE:22:D4:AB  
          inet addr:192.168.31.20  Bcast:192.168.31.255  Mask:255.255.255.0
          inet6 addr: fe80::1ebf:ceff:fe22:d4ab%2066432/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:883 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:226057 (220.7 KiB)  TX bytes:4018 (3.9 KiB)

[root@X210 ]# 
[root@X210 ]# route add default gw 192.168.31.1 dev ra0 	//添加默认网关
[root@X210 ]# 
[root@X210 ]# route -n	//查看路由表
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.31.0    0.0.0.0         255.255.255.0   U     0      0        0 ra0
0.0.0.0         192.168.31.1    0.0.0.0         UG    0      0        0 ra0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
[root@X210 ]# 
[root@X210 ]# ping 192.168.31.1    //ping网关
PING 192.168.31.1 (192.168.31.1): 56 data bytes
64 bytes from 192.168.31.1: seq=0 ttl=64 time=3.095 ms
[  148.506432] PeerAddBAReqAction ==> (Wcid = 1)
[  148.509313] BA - PeerAddBAReqAction----> 
[  148.513310] Rcv Wcid(1) AddBAReq
[  148.516520] BARecSessionAdd(1): Idx = 1, BAWinSize(req 64) = 64
[  148.522468] Start Seq = 00000004
[  148.525623] RTMP_TimerListAdd: add timer obj e0bcb214!
[  148.530723] RTMPInitTimer: e0bcb214
[  148.534285] CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = 1, SetTid  = 10000, DeleteTid = ffffffff.
[  148.543184] MACEntry[1]RXBAbitmap = 0x1. BARecWcidArray=1
[  148.548527] PeerAddBAReqAction(1): TID(0), BufSize(64) <== 
[  148.554082] CntlEnqueueForRecv(): BAR-Wcid(1), Tid (0)
[  148.559167] BAR(1) : Tid (0) - 0004:ffff
[  148.563071] 1-MACValue= e4c3538c,
[  148.567255] 2-MACValue= 19034,
64 bytes from 192.168.31.1: seq=1 ttl=64 time=1.521 ms
64 bytes from 192.168.31.1: seq=2 ttl=64 time=17.692 ms
64 bytes from 192.168.31.1: seq=3 ttl=64 time=2.514 ms
64 bytes from 192.168.31.1: seq=4 ttl=64 time=1.465 ms
64 bytes from 192.168.31.1: seq=5 ttl=64 time=6.807 ms
64 bytes from 192.168.31.1: seq=6 ttl=64 time=3.385 ms
^C
--- 192.168.31.1 ping statistics ---
7 packets transmitted, 7 packets received, 0% packet loss
round-trip min/avg/max = 1.465/5.211/17.692 ms
[root@X210 ]# 
[root@X210 ]# 
[root@X210 ]# ping 8.8.8.8	//ping外网
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=109 time=35.843 ms
64 bytes from 8.8.8.8: seq=1 ttl=109 time=65.865 ms
64 bytes from 8.8.8.8: seq=2 ttl=109 time=35.168 ms
64 bytes from 8.8.8.8: seq=3 ttl=109 time=56.251 ms
64 bytes from 8.8.8.8: seq=4 ttl=109 time=35.594 ms
^C
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 35.168/45.744/65.865 ms
[root@X210 ]# 
[root@X210 ]# ping www.baidu.com 	//却DNS服务器能用
PING www.baidu.com (182.61.200.6): 56 data bytes
64 bytes from 182.61.200.6: seq=0 ttl=49 time=33.525 ms
64 bytes from 182.61.200.6: seq=1 ttl=49 time=30.483 ms
64 bytes from 182.61.200.6: seq=2 ttl=49 time=31.160 ms
64 bytes from 182.61.200.6: seq=3 ttl=49 time=31.757 ms
^C
--- www.baidu.com ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 30.483/31.731/33.525 ms
[root@X210 ]# 
[root@X210 ]# ping 192.168.31.14 //ping局域网内的其他设置,比如:同样连接上WIFI的电脑
PING 192.168.31.14 (192.168.31.14): 56 data bytes
64 bytes from 192.168.31.14: seq=0 ttl=128 time=2130.325 ms
64 bytes from 192.168.31.14: seq=1 ttl=128 time=1131.656 ms
64 bytes from 192.168.31.14: seq=2 ttl=128 time=131.546 ms
64 bytes from 192.168.31.14: seq=3 ttl=128 time=6.192 ms
64 bytes from 192.168.31.14: seq=4 ttl=128 time=2.392 ms
64 bytes from 192.168.31.14: seq=5 ttl=128 time=19.488 ms
64 bytes from 192.168.31.14: seq=6 ttl=128 time=3.778 ms
64 bytes from 192.168.31.14: seq=7 ttl=128 time=4.579 ms
64 bytes from 192.168.31.14: seq=8 ttl=128 time=3.876 ms

9、实现开机自动连接WIFI

9.1、自动加载网卡驱动和连接WIFI

insmod /usr/lib/modules/mt7601Usta.ko  
mkdir -p /var/run/wpa_supplicant
ifconfig ra0 up   
wpa_supplicant -B -c /etc/wpa_supplicant.conf -i ra0
wpa_cli -i ra0 status

(1)在/etc/init.d/rcS文件中添加上面的脚本,在开机时会被自动执行,实现网卡驱动加载和WIFI连接;
(2)对rcs文件不熟悉的参考博客:《嵌入式系统开发——文件系统中inittab文件、rcS文件、fstab文件、profile文件详解》

9.2、实现静态分配IP地址

auto ra0
iface ra0 inet static
address 192.168.31.21
netmask 255.255.255.0
gateway 192.168.31.1

在/etc/network/interfaces文件中添加网卡的配置,注意这个配置需要重启网卡才能生效;

9.3、实现dhcp动态分配IP地址

9.3.1、udhcpc命令实现

udhcpc -i ra0

在rcS脚本中添加上面的命令;

9.3.2、用/etc/network/interfaces文件实现

auto ra0
iface ra0 inet dhcp

推荐

给大家推荐一个学校嵌入式知识的网站,博主在大学时候学习嵌入式知识、找工作的时候都在用这个网站,网站里有C语言、Linux等等的笔试题、面试常问问题等等知识,无论是学习基础知识、面试刷题、交流工作经验都是不错的选择。大家一起进步,欢迎留言交流。
链接:学习神器跳转

以上是关于USB接口WIFI(MT7601芯片)的驱动源码移植过程详解(驱动源码编译wpa_supplicant工具交叉编译文件系统移植)的主要内容,如果未能解决你的问题,请参考以下文章

Linux 驱动开发:USB无线wifi驱动开发(MT7601)完成WIFI管理工具安装

Linux 驱动开发:USB无线wifi驱动开发(MT7601)完成WIFI管理工具安装

嵌入式Linux下移植MT7601无线WIFI(网卡)驱动

S5PV210 移植无线wifi网卡 MT7601

7无线wifi传输视频开发

rtl8188eu与mt7601驱动相同吗