Libusb-1.0.18 编译
./configure –host=arm-linux-gnueabihf –prefix=/home/book/work/software/libusb-1.0.18/temp
checking libudev.h presence… no
checking for libudev.h… no
configure: error: “udev support requested but libudev not installed”
sudo apt-get install libudev-dev
Sudo apt-get update
book@ubuntu:~/work/software/libusb-1.0.18 dpkg−llibudev0Desired=Unknown/Install/Remove/Purge/Hold|Status=Not/Inst/Conf−files/Unpacked/halF−conf/Half−inst/trig−aWait/Trig−pend|/Err?=(none)/Reinst−required(Status,Err:uppercase=bad)||/NameVersionDescription+++−================================−================================−================================================================================iilibudev0175−0ubuntu9.10udevlibrarybook@ubuntu: /work/software/libusb−1.0.18 d p k g − l l i b u d e v 0 D e s i r e d = U n k n o w n / I n s t a l l / R e m o v e / P u r g e / H o l d | S t a t u s = N o t / I n s t / C o n f − f i l e s / U n p a c k e d / h a l F − c o n f / H a l f − i n s t / t r i g − a W a i t / T r i g − p e n d | / E r r ? = ( n o n e ) / R e i n s t − r e q u i r e d ( S t a t u s , E r r : u p p e r c a s e = b a d ) | | / N a m e V e r s i o n D e s c r i p t i o n + + + − ================================ − ================================ − ================================================================================ i i l i b u d e v 0 175 − 0 u b u n t u 9.10 u d e v l i b r a r y b o o k @ u b u n t u : / w o r k / s o f t w a r e / l i b u s b − 1.0.18
book@ubuntu:~/work/software/libusb-1.0.18 book@ubuntu: /work/software/libusb−1.0.18 b o o k @ u b u n t u : / w o r k / s o f t w a r e / l i b u s b − 1.0.18
book@ubuntu:~/work/software/libusb-1.0.18$ dpkg -l libudev-dev
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Description
+++-================================-================================-================================================================================
ii libudev-dev 175-0ubuntu9.10 udev library (development files)
./configure –host=arm-linux-gnueabihf –prefix=/home/book/work/software/libusb-1.0.20/temp –disable-udev
Make
Make install
将编译好的库 复制到工具链中
book@ubuntu:~/work/software/libusb-1.0.20/temp/include/libusb-1.0 sudocplibusb.h/usr/arm−linux−gnueabihf/include/−rfbook@ubuntu: /work/software/libusb−1.0.20/temp/lib s u d o c p l i b u s b . h / u s r / a r m − l i n u x − g n u e a b i h f / i n c l u d e / − r f b o o k @ u b u n t u : / w o r k / s o f t w a r e / l i b u s b − 1.0.20 / t e m p / l i b sudo cp * /usr/arm-linux-gnueabihf/lib -rf
复制到开发板的lib中。
U盘自动挂载
插入U盘后,控制台打印:
[ 330.371634] usb 1-1.2: new high-speed USB device number 4 using musb-hdrc
[ 330.748699] usb 1-1.2: New USB device found, idVendor=0bda, idProduct=0119
[ 330.755888] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 330.763526] usb 1-1.2: Product: USB2.0-CRW
[ 330.767794] usb 1-1.2: Manufacturer: Generic
[ 330.772255] usb 1-1.2: SerialNumber: 20090815198100000
[ 330.788154] scsi1 : usb-storage 1-1.2:1.0
[ 331.803886] scsi 1:0:0:0: Direct-Access Generic- SD/MMC 1.00 PQ: 0 ANSI: 0 CCS
[ 332.470007] sd 1:0:0:0: [sdb] 1984000 512-byte logical blocks: (1.01 GB/968 MiB)
[ 332.478656] sd 1:0:0:0: [sdb] Write Protect is off
[ 332.484569] sd 1:0:0:0: [sdb] No Caching mode page present
[ 332.490296] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[ 332.500849] sd 1:0:0:0: [sdb] No Caching mode page present
[ 332.506636] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[ 332.516993] sdb: sdb1
[ 332.532309] sd 1:0:0:0: [sdb] No Caching mode page present
[ 332.538060] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[ 332.544455] sd 1:0:0:0: [sdb] Attached SCSI removable disk
用 fdisk -l
Disk /dev/sdb: 1015 MB, 1015808000 bytes
255 heads, 63 sectors/track, 123 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 124 991968+ c Win95 FAT32 (LBA)
Partition 1 has different physical/logical endings:
phys=(122, 254, 63) logical=(123, 127, 4)
用挂接命令:
Mount /dev/sdb1 /tmp/u
卸载:退出/tmp/u目录,执行
Umount /tmp/u
利用mdev.conf 配置文件 自动挂载U盘和SD卡
leds?[123]? 0:0 777 * /bin/add_remove_led.sh (韦东山教程文档)
(加载驱动时,将文件权限更改为可读可写,并执行脚本)
把命令写入一个脚本:
add_remove_led.sh
if [ ACTION=“add”];thenechocreate/dev/ A C T I O N = “ a d d ” ] ; t h e n e c h o c r e a t e / d e v / MDEV > /dev/console;
else
echo remove /dev/$MDEV > /dev/console;
fi
2. U盘自动加载
sda[1-9]+ 0:0 777 * /bin/add_remove_udisk.sh
if [ ACTION=“add”];thenmount/dev/ A C T I O N = “ a d d ” ] ; t h e n m o u n t / d e v / MDEV /mnt;
else
umount /mnt;
Fi
例子:
leds?[123]? 0:0 777 * if [ ACTION="add"];thenechocreate/dev/ A C T I O N =" a d d " ] ; t h e n e c h o c r e a t e / d e v / MDEV > /dev/console; else echo remove /dev/ MDEV>/dev/console;fileds?[123]?0:0777∗/bin/addremoveled.shsda[1−9]+0:0777∗if[ M D E V > / d e v / c o n s o l e ; f i l e d s ? [ 123 ] ? 0 : 0 777 ∗ / b i n / a d d r e m o v e l e d . s h s d a [ 1 − 9 ] + 0 : 0 777 ∗ i f [ ACTION = "add" ]; then mount /dev/$MDEV /mnt; else umount /mnt; fi
USB-WIFI调试:
1.配置内核:
make menuconfig, /CONFIG_ATH9K_HTC 得到下面信息
Symbol: ATH9K_HTC [=n] |
| Type : tristate |
| Prompt: Atheros HTC based wireless cards support |
| Defined at drivers/net/wireless/ath/ath9k/Kconfig:100 |
| Depends on: NETDEVICES [=y] && WLAN [=y] && ATH_COMMON [=n] && USB [=y] && MAC80211 [=m] |
| Location: |
| -> Device Drivers |
| -> Network device support (NETDEVICES [=y]) |
| -> Wireless LAN (WLAN [=y]) |
| -> Atheros Wireless Cards (ATH_COMMON [=n])
配置:
-> Networking suppor
-> Wireless
<*> cfg80211 - wireless configuration API
<*> Generic IEEE 802.11 Networking Stack (mac80211)
-> Device Drivers
-> Network device support
-> Wireless LAN
-> Atheros Wireless Cards
<*> Atheros HTC based wireless cards support
make uImage
把固件htc_9271.fw放到开发板/lib/firmware
Cp htc_9271.fw /home/book/work/rootfs_min/lib/firmware
2.安装iw 工具
2.1 安装iw依赖的 libnl库
tar xzf libnl-3.2.23.tar.gz
cd libnl-3.2.23/
./configure –host=arm-linux –prefix=$PWD/tmp
修改 lib/addr.c 添加宏(宏来自内核源码)
make
make install
把编译出来的头文件应该放入:
/usr/arm-linux-gnueabihf-gcc/include
cd tmp/include/libnl3
sudo cp netlink -rf /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
把编译出来的库文件应该放入:
把编译出来的库文件应该放入NFS文件系统的lib目录:
2.2 编译 iw 工具
获取iw工具
可以从https://www.kernel.org/pub/software/network/iw/下载iw-4.0.tar.gz
Makefile中定义了PKG_CONFIG_PATH,路径指向libnl库
export PKG_CONFIG_PATH=/home/book/work/software/wifi_source/01.iw/libnl-3.2.23/temp/lib/pkgconfig:$PKG_CONFIG_PATH
make CC=arm-linux-gnueabihf-gcc
iw list // 列出WIFI网卡的性能
iw dev wlan0 scan // 扫描WIFI AP
iw wlan0 connect dswei // 连接到WIFI AP:dswei (open)
iw wlan0 connect dswei keys d:0:baiwenwang123 // 连接到WIFI AP:dswei (WEP)
d: default, 0: 第0个密码
3.编译wpa_supplicant :
可用于上述4种”认证/加密”
3.1 先编译它的依赖libopenssl
tar xzf openssl-1.0.1d.tar.gz
cd openssl-1.0.1d/
./config shared no-asm –prefix= PWD/tmp修改Makefile:CC=arm−linux−gccAR=arm−linux−ar P W D / t m p 修 改 M a k e f i l e : C C = a r m − l i n u x − g c c A R = a r m − l i n u x − a r (ARFLAGS) r
RANLIB= arm-linux-ranlib
NM= arm-linux-nm
MAKEDEPPROG= arm-linux-gcc
make
make install
3.2 编译wpa_supplicant
要有一个配置文件.config
tar xzf wpa_supplicant-2.0.tar.gz
cd wpa_supplicant-2.0/wpa_supplicant/
cp defconfig .config
修改.config加上一行: CONFIG_LIBNL32=y
修改Makefile:
CC=arm-linux-gcc
编译出错提示 找不到 ssl.h
Makefile 增加一行 CFLAGS += -I/usr/arm-linux-gnueabihf/include/
make
make DESTDIR=$PWD/tmp install
把 wpa_cli wpa_passphrase wpa_supplicant 复制到 文件系统的sbin目录中。
文件系统中创建文件夹 mkdir -p /var/run/wpa_supplicant
(使用: 在examples 目录中有很多的配置文件,可用于open wep wep2 参考
book@ubuntu:~/work/software/wifi_source/02.wpa_supplicant/wpa_supplicant-2.0/wpa_supplicant/examples$ ls *.conf -l
-rw-rw-r– 1 book book 269 Jan 12 2013 ieee8021x.conf
-rw-rw-r– 1 book book 1144 Jan 12 2013 openCryptoki.conf
-rw-rw-r– 1 book book 133 Jan 12 2013 plaintext.conf
-rw-rw-r– 1 book book 2930 Jan 12 2013 udhcpd-p2p.conf
-rw-rw-r– 1 book book 170 Jan 12 2013 wep.conf
-rw-rw-r– 1 book book 284 Jan 12 2013 wpa2-eap-ccmp.conf
-rw-rw-r– 1 book book 181 Jan 12 2013 wpa-psk-tkip.conf )
在文件系统的etc 文件夹中 新建一配置文件 wpa_wpa2.conf
ctrl_interface=/var/run/wpa_supplicant
network={
ssid=”dswei”
psk=”baiwenwang123”
}
配置文件内容解释:
ctrl_interface=/var/run/wpa_supplicant # 一个目录,用于wpa_supplicant和wpa_cli的socket通信
network={
ssid=”dswei”
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
控制台执行
ifconfig wlan0 up
iw dev wlan0 scan // 扫描热点
wpa_supplicant -B -c/etc/wpa_wpa2.conf -iwlan0
wpa_cli -iwlan0 status // 查看状态
访问外网:
修改/etc/resolv.conf添加DNS:
nameserver 192.168.1.1
设置网关:
route add default gw 192.168.1.1
cd bind
修改Makefile:
./configure BUILD_CC=gcc ac_cv_file__dev_random=yes –host=arm-linux-gnueabihf –disable-kqueue
tar xzf bind.tar.gz
cd bind-9.8.4-P2
修改 lib/export/dns/Makefile.in
gen: srcdir/gen.c s r c d i r / g e n . c {CC} ALLCFLAGS A L L C F L A G S {LDFLAGS} -o @ @ {srcdir}/gen.c LIBS改为gen: L I B S 改 为 g e n : {srcdir}/gen.c
BUILDCC B U I L D C C {ALL_CFLAGS} LDFLAGS−o L D F L A G S − o @ srcdir/gen.c s r c d i r / g e n . c {LIBS}
cd ../..
make DESTDIR=$PWD/tmp install
把文件复制到NFS
sudo cp bin/* /work/nfs_root/fs_mini_mdev_new/bin/
sudo cp sbin/* /work/nfs_root/fs_mini_mdev_new/sbin/
sudo cp etc/dhclient.conf.example //work/nfs_root/fs_mini_mdev_new/etc/dhclient.conf
sudo cp etc/dhcpd.conf.example //work/nfs_root/fs_mini_mdev_new/etc/dhcpd.conf
sudo cp client/scripts/linux /work/nfs_root/fs_mini_mdev_new/etc/dhclient-script
chmod +x /work/nfs_root/fs_mini_mdev_new/etc/dhclient-script
并修改
改为
命令:
dhclient wlan0 连上AP 后自动非配ip 和 路由
5.AR9271 驱动模块的编译:
对于包含了AR9271网卡驱动的内核,有一个问题:
在上电之前就接上了网卡,那么系统启动后无法识别出这个网卡。
解决方法:
1.上电后再接网卡
2.把驱动编译为模块,当系统启动后再insmod: 可以在上电之前就接网卡
可能原因:ath9k_htc.ko要用到固件, 但是固件要到根文件系统被挂载后才能访问
将 Atheros HTC based wireless cards support 编译成模块
DEVICES DRIVER
NETWORK device support
Wireles LAN
Atheros Wireless Cards
Atheros HTC based wireless cards support
编译内核 make uImage
编译模块 make modules
cp drivers/net/wireless/ath/ath9k/*.ko 文件 copy 到文件系统中.
init.d/rcs中脚本增加如下命令 :
insmod ath9k_hw.ko
insmod ath9k_common.ko
insmod ath9k_htc.ko
写脚本,利用mdev使一接入WIFI网卡,就自动执行wpa_supplicant等
cat /etc/mdev.conf
wlan0 0:0 777 * /sbin/auto_wifi.sh
cat /sbin/auto_wifi.sh
if [ $ACTION = “add” ];
then
wpa_supplicant -B -c/etc/wpa_wpa2.conf -iwlan0
wpa_cli -a/sbin/wpa_action.sh -B
else
killall wpa_supplicant
killall wpa_cli
killall dhclient
fi
chmod +x /sbin/auto_wifi.sh
一连接上WIFI AP, 就自动执行dhclient
创建一脚本:
cat /sbin/wpa_action.sh
IFNAME= 1CMD= 1 C M D = 2
if [ “ CMD”=“CONNECTED”];thenechoconnect C M D ” = “ C O N N E C T E D ” ] ; t h e n e c h o c o n n e c t IFNAME, dhclient for it > /dev/console
dhclient IFNAMEfiif[“ I F N A M E f i i f [ “ CMD” = “DISCONNECTED” ]; then
echo disconnect $IFNAME, kill dhclient for it > /dev/console
killall dhclient
fi
chmod +x /sbin/wpa_action.sh
iw list // 列出WIFI网卡的性能
iw dev wlan0 scan // 扫描WIFI AP
iw wlan0 connect dswei // 连接到WIFI AP:dswei (open)
iw wlan0 connect dswei keys d:0:baiwenwang123 // 连接到WIFI AP:dswei (WEP)
d: default, 0: 第0个密码
wpa_supplicant -B -c/etc/wpa_wpa2.conf -iwlan0 //-B 后台执行 -c执行脚本 -d 调试信息 /etc/wpa_wpa2.conf
wpa_cli -iwlan0 status // 查看状态
连接WPA-PSK/WPA2-PSK加密的AP
>add_network (假设返回2)
>set_network 2 ssid “dswei”
>set_network 2 psk “baiwenwang123”
>enable_network 2
list_networks //列出配置文件中的网络
scan_results // 列出扫描到的wifi网络
7.Wifi 程序测试:
用以前的 server 、client程序,
Wifi 连接到tp-link路由, 关掉eth0 eth1网卡
Arm板 执行客户端: ./cli 192.168.1.199
Pc ubuntu 执行服务器 : ./ser