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模塊作介紹),是下面是要用到的實物圖:


 

 

(上圖中的一些次要部件沒有列出來,需要的部分會提到)

 

先測試USB無線模塊是否正常,我把它插在電腦上並且連接在普通無線路由器上,顯示如下所示,則說明正常。


之后拔出,因為我的電腦用有線。

 

 

內核配置

從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={

        ssid="Router_Kernel"

        #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={

        ssid="Router_Kernel"

        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

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM