S3C2440实现wifi、3G上网和迷你无线路由的制作(一)

S3C2440实现wifi、3G上网和迷你无线路由的制作

fulinux 凌云实验室

本文将通过ARMlinux平台,借助RT2070/RT3070芯片的无线模块(或使用RT2070/RT3070芯片的USB无线上网卡)、3G无线上网卡,实现无线上网、通过ADSL3G的迷你无线路由器的制作。

wifi上网

首先是利用s3c2440开发板和RT2070/RT3070芯片的无线模块实现无线上网的功能,即让无线模块工作在STA模式,所谓的STAWLAN中一般为客户端,可以是装有无线网卡的计算机,也可以是有WiFi模块的智能手机。STA可以是移动的,也可以是固定的,是无线局域网的最基本组成单元。

这里假定已经成功移植了linux-3.0内核和可读写的文件系统,例如ubifsyaffsjffs2文件系统,这里使用jffs2。下图是已经运行好的系统在secure CRT上的显示的结果:

~ >: ls

apps     data     home     lib      media    proc     stat     usr

backup   dev      info     linuxrc  mnt      root     sys      var

bin      etc      init     logs     opt      sbin     tmp

~ >: 

这里使用一个集成RT2070芯片的USB无线网卡(或其他无线模块,注明一点就是30702070的模块是完全兼容的,下面我们只以RT2070模块作介绍),是下面是要用到的实物图:

S3C2440实现wifi、3G上网和迷你无线路由的制作(一)

(上图中的一些次要部件没有列出来,需要的部分会提到)

先测试USB无线模块是否正常,我把它插在电脑上并且连接在普通无线路由器上,显示如下所示,则说明正常。

S3C2440实现wifi、3G上网和迷你无线路由的制作(一)

之后拔出,因为我的电脑用有线。

内核配置

从Linux-3.0开始,RT2070/3070的STA驱动已经作为正式版本加入了Linux内核源码中了(从Linux-2.6.32开始以实验版本加入Linux内核中)。本篇文章主要介绍如何在内核中编译支持RT2070的STA模式驱动,并连接到我的无线路由器上去。

1, 配置Linux-3.0内核支持RT2070,我们以Build-in的方式将RT2070的驱动集成到内核里去,一下是一些需要的选项,其他配置可以自己试试:

[*] Networking support  --->

         -*-   Wireless  --->

              <*>   cfg80211 - wireless configuration API

              [ ]     nl80211 testmode command

              [ ]     enable developer warnings

              [ ]     cfg80211 regulatory debugging

              [*]     enable powersave by default

              [ ]     use statically compiled regulatory rules database

              [ ]     cfg80211 wireless extensions compatibility

              <*>   Common routines for IEEE802.11 drivers

              [ ]   lib80211 debugging messages

              <*>   Generic IEEE 802.11 Networking Stack (mac80211)

              [ ]   PID controller based rate control algorithm

              [*]   Minstrel

              [*]     Minstrel 802.11n support

                    Default rate control algorithm (Minstrel)  --->

              [ ]   Enable mac80211 mesh networking (pre-802.11s) support

              [ ]   Select mac80211 debugging features  --->

Device Drivers  --->

       Generic Driver Options  --->

              (/sbin/hotplug) path to uevent helper

              [ ] Maintain a devtmpfs filesystem to mount at /dev

              [ ] Select only drivers that don't need compile-time external firmware

              [ ] Prevent firmware from being built

              -*- Userspace firmware loading support

              [*]   Include in-kernel firmware blobs in kernel binary

              ()    External firmware blobs to build into the kernel binary

[*] Network device support  --->

          [*]   Wireless LAN  --->

             <*>   Ralink driver support  --->

                   --- Ralink driver support

                   < >   Ralink rt2500 (USB) support

                   < >   Ralink rt2501/rt73 (USB) support

                   <*>   Ralink rt27xx/rt28xx/rt30xx (USB) support

                   [ ]    rt2800usb - Include support for rt33xx devices

                   [ ]    rt2800usb - Include support for rt35xx devices (EXPERIMENTAL)

                   [ ]    rt2800usb - Include support for rt53xx devices (EXPERIMENTAL)

                   [ ]    rt2800usb - Include support for unknown (USB) devices

                   [*]   Ralink debug output

注明:

acfg80211

cfg80211 is the Linux 802.11 configuration API. cfg80211 replaces Wireless-Extensions. nl80211 is used to configure a cfg80211 device and is used for kernel <–> userspace communication. Wireless extensions is now in maintenance mode, no new features will be added to it, we'll only fix bugs for it. cfg80211 is now feature-par complete with wireless-extensions, it actually has a lot more features that are simply not available and will never be available through wireless extensions. When implementing a cfg80211 driver wireless extensions support is still provided automatically for you through cfg80211 through CONFIG_CFG80211_WEXT. Distributions no longer needing wireless extensions can remove this and are encouraged to do so. cfg80211 also provides full regulatory support, this is done through wireless-regdb and the usage of CRDA.

All new Linux wireless drivers should be written targeting either cfg80211 for fullmac devices or mac80211 for softmac devices.

(摘自:http://wireless.kernel.org/en/developers/Documentation/cfg80211

bMinstrel

minstrel is a mac80211 rate control algorithm ported over from MadWifi which supports multiple rate retries and claimed to be one of the best, if not the best, rate control algorithm.

(摘自:http://wireless.kernel.org/en/developers/Documentation/mac80211/RateControl/minstrel/

chotplug

这里是支持热插拔。

dFirmware

固件的目的是初始化,()    External firmware blobs to build into the kernel binary这一选项可以加入固件路径。

e[*]   Ralink debug output

这个选项选了后容易出现下面的警告。

cfg80211: Calling CRDA to update world regulatory domain

2插入RT2070无线网卡并加载新内核启动

………..

RAMDISK: gzip image found at block 0

    usb 1-1: new full speed USB device number 2 using at91_ohci

    hub 1-1:1.0: USB hub found

    hub 1-1:1.0: 4 ports detected

    usb 1-1.3: new full speed USB device number 3 using at91_ohci

    phy0 -> rt2x00_set_chip: Info - Chipset detected - rt: 2070, rf: 0006, rev: 0201.

    ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'

    EXT2-fs (ram0): warning: mounting unchecked fs, running e2fsck is recommended

    VFS: Mounted root (ext2 filesystem) on device 1:0.

    Freeing init memory: 128K

使用lsusb命令查看:

~ >: lsusb

Bus 001 Device 001: ID 1d6b:0001

Bus 001 Device 002: ID 05e3:0606

Bus 001 Device 003: ID 148f:2070

~ >: 

如果是热插拔的话会,在插入的那一刻,串口会打印如下信息:

~ >: usb 1-1.1: new full speed USB device number 3 using s3c2410-ohci

usb 1-1.1: New USB device found, idVendor=148f, idProduct=2070

usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3

usb 1-1.1: Product: 802.11 g WLAN

usb 1-1.1: Manufacturer: Ralink

usb 1-1.1: SerialNumber: 1.0

ifconfig是查看网卡的信息。

ifconfig [Interface]

Interface是可选项,如果不加此项,则显示系统中所有网卡的信息。如果添加此选项则显示所指定的网卡信息,例如:

~ >: ifconfig wlan0

wlan0     Link encap:Ethernet  HWaddr C8:3A:35:C6:A2:B5  

          inet addr:192.168.5.1  Bcast:192.168.5.255  Mask:255.255.255.0

          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)

我们可以看到

第一行:连接类型:Ethernet(以太网)HWaddr(硬件mac地址)

第二行:网卡的IP地址、子网、掩码

第三行:MULTICAST(支持组播)MTU:1500(最大传输单元):1500字节

第四、五行:接收、发送数据包情况统计

第七行:接收、发送数据字节数统计信息。

~ >: ifconfig wlan0 up

    phy0 -> rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'.

    phy0 -> rt2x00lib_request_firmware: Error - Failed to request Firmware.

ifconfig: SIOCSIFFLAGS: No such file or directory

这时我们在使用RT2070的驱动时发现,RT2070的驱动还需要rt2870.bin这个系统固件(firmware)

1, Linux内核官方站点下载rt2870.bin这个系统固件

 I. PC上下载rt2870.bin这个系统固件:

[guowenxue@centos6 ~]$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git

   [guowenxue@centos6 ~]$ ls -l linux-firmware/rt2870.bin

   -rw-rw-r-- 1 guowenxue guowenxue 8192 Dec 23 09:37 linux-firmware/rt2870.bin

II. AT91SAM9260开发板上将rt2870.bin下载到/lib/firmware路径下,这时能重启网卡:

   /lib >: mkdir -p  /lib/firmware

   /lib >: cd firmware/

   /lib/firmware >: tget rt2870.bin

   rt2870.bin           100% |*******************************|  8192   0:00:00 ETA

   /lib/firmware >: ls

   rt2870.bin

  iwconfig命令来自下面交叉编译的wireless_tools程序

  ~ >: iwconfig wlan0   

wlan0     IEEE 802.11bg  ESSID:off/any  

          Mode:Managed  Access Point: Not-Associated   Tx-Power=0 dBm   

          Retry  long limit:7   RTS thr:off   Fragment thr:off

          Encryption key:off

          Power Management:on

          

~ >: ifconfig wlan0 up

phy1 -> rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'.

phy1 -> rt2x00lib_request_firmware: Info - Firmware detected - version: 0.29.

phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 102.

phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 4, CWmax: 5, Aifs: 2, TXop: 188.

phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 5, CWmax: 10, Aifs: 3, TXop: 0.

phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 5, CWmax: 10, Aifs: 7, TXop: 0.

2, 下载/交叉编译wireless_toolsshell脚本,这些工具包括iwconfig, iwlist, iwpriv等:

[guowenxue@centos6 wireless]$ ls

openssl  wireless_tools  wpa_supplicant

[guowenxue@centos6 wireless]$ cd wireless_tools/

[guowenxue@centos6 wireless_tools]$ ls

build.sh

[guowenxue@centos6 wireless_tools]$ cat build.sh 

#!/bin/sh

#+--------------------------------------------------------------------------------------------

#|Description:  This shell script used to download tree wireless_tools code and cross compile it.

#|     Author:  GuoWenxue <guowenxue@gmail.com>

#|  ChangeLog:

#|           1, Initialize 1.0.0 on 2011.11.23

#+--------------------------------------------------------------------------------------------

PRJ_PATH=`pwd`

APP_NAME="wireless_tools.29"

PACK_SUFIX="tar.gz"

DL_ADDR="http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/$APP_NAME.$PACK_SUFIX"

INST_PATH=${PRJ_PATH}/../mnt/usr/sbin/

ARCH=arm926t

CROSS=

sup_arch=("" "arm926t" "arm920t" )

function select_arch()

{

   echo "Current support ARCH: "

   i=1

   len=${#sup_arch[*]}

   while [ $i -lt $len ]; do

     echo "$i: ${sup_arch[$i]}"

     let i++;

   done

   echo "Please select: "

   index=

   read index

   ARCH=${sup_arch[$index]}

}

function decompress_packet()

(

   echo "+---------------------------------------------+"

   echo "|  Decompress $1 now"  

   echo "+---------------------------------------------+"

    ftype=`file "$1"`

    case "$ftype" in

       "$1: Zip archive"*)

           unzip "$1" ;;

       "$1: gzip compressed"*)

           if [ 0 != `expr "$1" : ".*.tar.*" ` ] ; then

               tar -xzf $1

           else

               gzip -d "$1"

           fi ;;

       "$1: bzip2 compressed"*)

           if [ 0 != `expr "$1" : ".*.tar.*" ` ] ; then

               tar -xjf $1

           else

               bunzip2 "$1"

           fi ;;

       "$1: POSIX tar archive"*)

           tar -xf "$1" ;;

       *)

          echo "$1 is unknow compress format";;

    esac

)

if [ -z $ARCH ] ; then

  select_arch

fi

if [ "arm920t" != $ARCH  -a "arm926t" != $ARCH ] ; then 

    echo "+------------------------------------------------------------------+"

    echo "|  ERROR: Unsupport platform $ARCH to cross compile "  

    echo "+------------------------------------------------------------------+"

    exit -1;

else

    CROSS="/opt/buildroot-2011.11/${ARCH}/usr/bin/arm-linux-"

fi

# Download source code packet

if [ ! -s $APP_NAME.$PACK_SUFIX ] ; then

    echo "+------------------------------------------------------------------+"

    echo "|  Download $APP_NAME.$PACK_SUFIX now "  

    echo "+------------------------------------------------------------------+" 

    wget $DL_ADDR 

fi

# Decompress source code packet

if [ ! -d $APP_NAME ] ; then

    decompress_packet $APP_NAME.$PACK_SUFIX

fi

echo "+------------------------------------------------------------------+"

echo "|          Build $APP_NAME for $ARCH "

echo "| Crosstool:  $CROSS"

echo "+------------------------------------------------------------------+"

cd $APP_NAME

   FILE=Makefile

   line=`sed -n '/^CC =/=' $FILE`

   sed -n "$line p" $FILE | grep "$CROSS"

   if [ 0 != $? ] ; then

       sed -i -e ${line}s"|.*|CC = ${CROSS}gcc|" $FILE

       line=`sed -n '/^AR =/=' $FILE`

       sed -i -e ${line}s"|.*|AR = ${CROSS}ar|" $FILE

       line=`sed -n '/^RANLIB =/=' $FILE`

       sed -i -e ${line}s"|.*|RANLIB = ${CROSS}ranlib|" $FILE

       line=`sed -n '/BUILD_STATIC =/=' $FILE`

       sed -i -e ${line}s"|.*|BUILD_STATIC = y|" $FILE

   fi

   make clean

   make

cd -

[guowenxue@centos6 wireless_tools]$ sh build.sh

[guowenxue@centos6 wireless_tools]$ ls wireless_tools.29/

***  iwlist   ***  iwspy  ***  iwgetid  ***  iwconfig  ***

***  ifrename  ***  iwpriv  ***   iwevent  ***

/****************************转载声明**********************************/

3, 由于wpa_supplicant依赖openssl库,所以这里我们得先交叉编译openssl,在交叉编译之前,我们得把wpa_supplicant-0.7.3.tar.gz源码中的openssl的补丁给打了,参见下面的编译脚本:

[guowenxue@centos6 wireless]$ cd openssl/

[guowenxue@centos6 openssl]$ ls

build.sh

[guowenxue@centos6 openssl]$ cat build.sh 

#!/bin/sh

#+--------------------------------------------------------------------------------------------

#|Description:  This shell script used to download tree wireless_tools code and cross compile it.

#|     Author:  GuoWenxue <guowenxue@gmail.com>

#|  ChangeLog:

#|           1, Initialize 1.0.0 on 2011.11.23

#+--------------------------------------------------------------------------------------------

PRJ_PATH=`pwd`

APP_NAME="openssl-0.9.8i"

PACK_SUFIX="tar.gz"

DL_ADDR="http://www.openssl.org/source/$APP_NAME.$PACK_SUFIX"

INST_PATH=$PRJ_PATH/install

#INST_PATH=../install

ARCH=arm926t

CROSS=

sup_arch=("" "arm926t" "arm920t" )

function select_arch()

{

   echo "Current support ARCH: "

   i=1

   len=${#sup_arch[*]}

   while [ $i -lt $len ]; do

     echo "$i: ${sup_arch[$i]}"

     let i++;

   done

   echo "Please select: "

   index=

   read index

   ARCH=${sup_arch[$index]}

}

function decompress_packet()

(

   echo "+---------------------------------------------+"

   echo "|  Decompress $1 now"  

   echo "+---------------------------------------------+"

    ftype=`file "$1"`

    case "$ftype" in

       "$1: Zip archive"*)

           unzip "$1" ;;

       "$1: gzip compressed"*)

           if [ 0 != `expr "$1" : ".*.tar.*" ` ] ; then

               tar -xzf $1

           else

               gzip -d "$1"

           fi ;;

       "$1: bzip2 compressed"*)

           if [ 0 != `expr "$1" : ".*.tar.*" ` ] ; then

               tar -xjf $1

           else

               bunzip2 "$1"

           fi ;;

       "$1: POSIX tar archive"*)

           tar -xf "$1" ;;

       *)

          echo "$1 is unknow compress format";;

    esac

)

if [ -z $ARCH ] ; then

  select_arch

fi

if [ "arm920t" != $ARCH  -a "arm926t" != $ARCH ] ; then 

    echo "+------------------------------------------------------------------+"

    echo "|  ERROR: Unsupport platform $ARCH to cross compile "  

    echo "+------------------------------------------------------------------+"

    exit -1;

else

    CROSS="/opt/buildroot-2011.11/${ARCH}/usr/bin/arm-linux-"

fi 

export CC=${CROSS}gcc 

export CXX=${CROSS}g++ 

export AR=${CROSS}ar 

export AS=${CROSS}as 

export LD=${CROSS}ld 

export NM=${CROSS}nm 

export RANLIB=${CROSS}ranlib 

export STRIP=${CROSS}strip

# Download source code packet

if [ ! -s $APP_NAME.$PACK_SUFIX ] ; then 

    echo "+------------------------------------------------------------------+" 

    echo "|  Download $APP_NAME.$PACK_SUFIX now "  

    echo "+------------------------------------------------------------------+" 

    wget $DL_ADDR 

fi 

# Decompress source code packet 

if [ ! -d $APP_NAME ] ; then 

    decompress_packet $APP_NAME.$PACK_SUFIX 

fi

if [ ! -d $INST_PATH ] ; then

    mkdir -p $INST_PATH

else

    echo "$APP_NAME already cross compiled, exit now..."

    exit;

fi

echo "+------------------------------------------------------------------+"

echo "|          Build $APP_NAME for $ARCH "

echo "| Crosstool:  $CROSS"

echo "+------------------------------------------------------------------+"

cd $APP_NAME

   set x

   #该补丁来自wpa_supplicant源码

   patch -p1 < ../patch/$APP_NAME-tls-extensions.patch 

   #Modify the compiler

   FILE=Makefile

   line=`sed -n '/^CC= cc/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|CC = ${CROSS}gcc|" $FILE 

   fi

   line=`sed -n '/^AR=ar/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|AR = ${CROSS}ar $(ARFLAGS) r|" $FILE 

   fi

   

   line=`sed -n '/^RANLIB= /=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|RANLIB = ${CROSS}ranlib|" $FILE 

   fi

   #Support build shared library

   line=`sed -n '/^OPTIONS= /=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|OPTIONS=enable-shared no-camellia no-capieng no-cms no-gmp no-krb5 no-mdc2 no-montasm no-rc5 no-rfc3779 no-seed no-tlsext no-zlib no-zlib-dynamic|" $FILE

   fi

   line=`sed -n '/^SHLIB_EXT=/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|SHLIB_EXT=.so.$(SHLIB_MAJOR).$(SHLIB_MINOR)|" $FILE 

   fi

   line=`sed -n '/^SHLIB_TARGET/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|SHLIB_TARGET=linux-shared|" $FILE 

   fi

   line=`sed -n '/^build_all:/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|build_all: build_libs build_apps build_tests build_tools build-shared|" $FILE 

   fi

   #Modify install path

   line=`sed -n '/^INSTALLTOP=/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|INSTALLTOP = $INST_PATH|" $FILE

   fi

   line=`sed -n '/^OPENSSLDIR=/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|OPENSSLDIR = $INST_PATH|" $FILE 

   fi

       

   make && make install

   #cp -af *.so* $INST_PATH/lib

cd 

[guowenxue@centos6 openssl]$ sh build.sh

[guowenxue@centos6 openssl]$ ls

build.sh  install  openssl-0.9.8i  openssl-0.9.8i.tar.gz  patch

[guowenxue@centos6 openssl]$ ls install/

bin  certs  include  lib  man  misc  openssl.cnf  private

4, 下载交叉编译wpa_supplicant的脚本

[guowenxue@centos6 wireless]$ cd wpa_supplicant/

[guowenxue@centos6 wpa_supplicant]$ ls

build.sh

[guowenxue@centos6 openssl]$ cat build.sh 

#!/bin/sh

#+--------------------------------------------------------------------------------------------

#|Description:  This shell script used to download tree wireless_tools code and cross compile it.

#|     Author:  GuoWenxue <guowenxue@gmail.com>

#|  ChangeLog:

#|           1, Initialize 1.0.0 on 2011.11.23

#+--------------------------------------------------------------------------------------------

PRJ_PATH=`pwd`

APP_NAME="openssl-0.9.8i"

PACK_SUFIX="tar.gz"

DL_ADDR="http://www.openssl.org/source/$APP_NAME.$PACK_SUFIX"

INST_PATH=$PRJ_PATH/install

#INST_PATH=../install

ARCH=arm926t

CROSS=

sup_arch=("" "arm926t" "arm920t" )

function select_arch()

{

   echo "Current support ARCH: "

   i=1

   len=${#sup_arch[*]}

   while [ $i -lt $len ]; do

     echo "$i: ${sup_arch[$i]}"

     let i++;

   done

   echo "Please select: "

   index=

   read index

   ARCH=${sup_arch[$index]}

}

function decompress_packet()

(

   echo "+---------------------------------------------+"

   echo "|  Decompress $1 now"  

   echo "+---------------------------------------------+"

    ftype=`file "$1"`

    case "$ftype" in

       "$1: Zip archive"*)

           unzip "$1" ;;

       "$1: gzip compressed"*)

           if [ 0 != `expr "$1" : ".*.tar.*" ` ] ; then

               tar -xzf $1

           else

               gzip -d "$1"

           fi ;;

       "$1: bzip2 compressed"*)

           if [ 0 != `expr "$1" : ".*.tar.*" ` ] ; then

               tar -xjf $1

           else

               bunzip2 "$1"

           fi ;;

       "$1: POSIX tar archive"*)

           tar -xf "$1" ;;

       *)

          echo "$1 is unknow compress format";;

    esac

)

if [ -z $ARCH ] ; then

  select_arch

fi

if [ "arm920t" != $ARCH  -a "arm926t" != $ARCH ] ; then 

    echo "+------------------------------------------------------------------+"

    echo "|  ERROR: Unsupport platform $ARCH to cross compile "  

    echo "+------------------------------------------------------------------+"

    exit -1;

else

    CROSS="/opt/buildroot-2011.11/${ARCH}/usr/bin/arm-linux-"

fi 

export CC=${CROSS}gcc 

export CXX=${CROSS}g++ 

export AR=${CROSS}ar 

export AS=${CROSS}as 

export LD=${CROSS}ld 

export NM=${CROSS}nm 

export RANLIB=${CROSS}ranlib 

export STRIP=${CROSS}strip

# Download source code packet

if [ ! -s $APP_NAME.$PACK_SUFIX ] ; then 

    echo "+------------------------------------------------------------------+" 

    echo "|  Download $APP_NAME.$PACK_SUFIX now "  

    echo "+------------------------------------------------------------------+" 

    wget $DL_ADDR 

fi 

# Decompress source code packet 

if [ ! -d $APP_NAME ] ; then 

    decompress_packet $APP_NAME.$PACK_SUFIX 

fi

if [ ! -d $INST_PATH ] ; then

    mkdir -p $INST_PATH

else

    echo "$APP_NAME already cross compiled, exit now..."

    exit;

fi

echo "+------------------------------------------------------------------+"

echo "|          Build $APP_NAME for $ARCH "

echo "| Crosstool:  $CROSS"

echo "+------------------------------------------------------------------+"

cd $APP_NAME

   set -x

   patch -p1 < ../patch/$APP_NAME-tls-extensions.patch 

   #Modify the compiler

   FILE=Makefile

   line=`sed -n '/^CC= cc/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|CC = ${CROSS}gcc|" $FILE 

   fi

   line=`sed -n '/^AR=ar/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|AR = ${CROSS}ar $(ARFLAGS) r|" $FILE 

   fi

   

   line=`sed -n '/^RANLIB= /=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|RANLIB = ${CROSS}ranlib|" $FILE 

   fi

   #Support build shared library

   line=`sed -n '/^OPTIONS= /=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|OPTIONS=enable-shared no-camellia no-capieng no-cms no-gmp no-krb5 no-mdc2 no-montasm no-rc5 no-rfc3779 no-seed no-tlsext no-zlib no-zlib-dynamic|" $FILE

   fi

   line=`sed -n '/^SHLIB_EXT=/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|SHLIB_EXT=.so.$(SHLIB_MAJOR).$(SHLIB_MINOR)|" $FILE 

   fi

   line=`sed -n '/^SHLIB_TARGET/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|SHLIB_TARGET=linux-shared|" $FILE 

   fi

   line=`sed -n '/^build_all:/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|build_all: build_libs build_apps build_tests build_tools build-shared|" $FILE 

   fi

   #Modify install path

   line=`sed -n '/^INSTALLTOP=/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|INSTALLTOP = $INST_PATH|" $FILE

   fi

   line=`sed -n '/^OPENSSLDIR=/=' $FILE` 

   if [ -n "$line" ] ; then 

       sed -i -e ${line}s"|.*|OPENSSLDIR = $INST_PATH|" $FILE 

   fi

       

   make && make install

   #cp -af *.so* $INST_PATH/lib

cd 

[guowenxue@centos6 wpa_supplicant]$ ls

build.sh  wpa_supplicant-0.7.3  wpa_supplicant-0.7.3.tar.gz

[guowenxue@centos6 wpa_supplicant]$ ls wpa_supplicant-0.7.3/wpa_supplicant/

***  wpa_supplicant  ***  wpa_cli      ***  wpa_passphrase    

5, 安装上面交叉编译出来的一些二进制可执行文件到ARM开发板上:

~ >: ls /apps/tools/

iwlist          wpa_passphrase        iwpriv        

wpa_supplicant   iwconfig       

使用wpa_passphrase创建wpa_supplicant的配置文件,使用加密后的密码,不用明文。当然使用明文密码也可以连接到无线路由器:

~ >: wpa_passphrase Router_Kernel password >> wpa_supplicant.conf

~ >: cat wpa_supplicant.conf 

network={

        ss

        #psk="password"

        psk=81a8c46543f339bbcd0381b4d7a13673d4e02f67108d978fb545435a15d95ea5

}

修改后的配置文件如下:

~ >: cat /apps/etc/wireless/wpa_supplicant.conf 

# WPA-PSK/TKIP

# wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant

network={

        ss

        key_mgmt=WPA-PSK

        proto=WPA

        pairwise=TKIP

        group=TKIP

        #psk="password"  这里使用明文密码也可以

        psk=81a8c46543f339bbcd0381b4d7a13673d4e02f67108d978fb545435a15d95ea5

}

运行wpa_supplicant来连接无线路由器

~ >: wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf &

Trying to associate with d8:5d:4c:18:04:7a (SSID='Router_Kernel' freq=2437 MHz)

phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 2, TXop: 47.

phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 94.

phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 4, CWmax: 10, Aifs: 3, TXop: 0.

phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7, TXop: 0.

Associated with d8:5d:4c:18:04:7a

WPA: Key negotiation completed with d8:5d:4c:18:04:7a [PTK=TKIP GTK=TKIP]

CTRL-EVENT-CONNECTED - Connection to d8:5d:4c:18:04:7a completed (auth) [id=0 id_str=]

WPA: Group rekeying completed with d8:5d:4c:18:04:7a [GTK=TKIP]

~ >: iwconfig 

lo        no wireless extensions.

eth0      no wireless extensions.

eth1      no wireless extensions.

wlan0     IEEE 802.11bg  ESSID:"Router_Kernel"  

          Mode:Managed  Frequency:2.437 GHz  Access Point: D8:5D:4C:18:04:7A   

          Bit Rate=1 Mb/s   Tx-Power=20 dBm   

          Retry  long limit:7   RTS thr:off   Fragment thr:off

          Encryption key:off

          Power Management:on

          Link Quality=69/70  Signal level=-41 dBm  

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:49   Missed beacon:0

~ >: udhcpc -i wlan0

udhcpc (v1.19.3) started

Sending discover...

Sending select for 192.168.1.100...

Lease of 192.168.1.100 obtained, lease time 7200

deleting routers

route: SIOCDELRT: No such process

adding dns 4.2.2.2

adding dns 8.8.8.8

~ >: ifconfig wlan0

wlan0     Link encap:Ethernet  HWaddr 00:E0:4C:D4:04:76  

          inet addr:192.168.1.100  Bcast:255.255.255.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:575 errors:0 dropped:0 overruns:0 frame:0

          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:26672 (26.0 KiB)  TX bytes:1300 (1.2 KiB)

~ >: ifconfig eth1 down

~ >: ifconfig eth0 down

~ >: ifconfig

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:6 errors:0 dropped:0 overruns:0 frame:0

          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:510 (510.0 B)  TX bytes:510 (510.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:E0:4C:D4:04:76  

          inet addr:192.168.1.100  Bcast:255.255.255.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:5521 errors:0 dropped:0 overruns:0 frame:0

          TX packets:46 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:244469 (238.7 KiB)  TX bytes:5454 (5.3 KiB)

~ >: ping 192.168.1.2

PING 192.168.1.2 (192.168.1.2): 56 data bytes

64 bytes from 192.168.1.2: seq=0 ttl=64 time=11.123 ms

64 bytes from 192.168.1.2: seq=1 ttl=64 time=3.467 ms

^C

--- 192.168.1.2 ping statistics ---

3 packets transmitted, 2 packets received, 33% packet loss

round-trip min/avg/max = 3.467/7.295/11.123 ms

参考:  

wpa_supplicant的编译,使用参考:

 http://blog.csdn.net/farsight2009/article/details/5660878

 http://www.linuxidc.com/Linux/2011-10/45202.htm

http://www.cnblogs.com/zhuqing/archive/2011/04/06/2006763.html

 http://blog.chinaunix.net/space.php?uid=22915173&do=blog&id=88182