Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1456045
  • 博文数量: 267
  • 博客积分: 3010
  • 博客等级: 少校
  • 技术积分: 3089
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-05 17:09
个人简介

尊天命,尽人事

文章分类

全部博文(267)

文章存档

2017年(6)

2015年(4)

2014年(27)

2013年(52)

2012年(59)

2011年(120)

分类: LINUX

2014-02-25 15:45:18

引用

聪儿嵌入式Linux下3G模块的驱动和应用

嵌入式Linux下3G模块的驱动和应用

1、             开发资源

1.1、硬件资源:

ZTE-mf637u(中国联通)

ZTE-mu351(中国移动)

 

1.2、软件资源:

1.2.1、usb-modeswitch-1.1.3

   libusb-0.1.12.tar.gz

   usb-modeswitch-1.1.3.tar.bz2

 

1.2.2、ppp-2.4.4

   libpcap-0.9.8.tar.gz

   ppp-2.4.4.tar.gz

 

1.2.3、wvdial

1.2.3.1、wvdial-1.54.0(arm-linux-gcc 3.4.1)

zlib-1.2.5.tar.bz2

   openssl-0.9.7g.tar.gz

   openssl-0.9.7g-fix_manpages-1.patch

wvstreams-4.0.1.tar.bz2

wvstreams-4.0.1-tcl84-1.patch

   wvdial-1.54.0.tar.gz

1.2.3.2、wvdial_1.60.4(arm-linux-gcc 4.2.2)

zlib-1.2.5.tar.bz2

   openssl-0.9.8n.tar.gz

   openssl-0.9.8n-fix_manpages-1.patch

   wvstreams-4.6.1.tar.gz

   wvdial_1.60.4.tar.gz

 

2、             Linux开发环境

2.1、主机环境

2.1.1、主机linux系统

   Fedora Core 6

 

2.1.2、主机编译环境

2.1.2.1、gcc -v

Using built-in specs.

Target: i386-redhat-linux

Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux

Thread model: posix

gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)

 

2.1.2.2、/usr/local/arm/3.4.1/bin/arm-linux-gcc -v

Reading specs from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/specs

Configured with: /work/crosstool-0.27/build/arm-linux/gcc-3.4.1-glibc-2.3.2/gcc-3.4.1/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/usr/local/arm/3.4.1 --with-headers=/usr/local/arm/3.4.1/arm-linux/include --with-local-prefix=/usr/local/arm/3.4.1/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long

Thread model: posix

gcc version 3.4.1

 

2.1.2.3、/usr/local/arm/4.2.2/usr/bin/arm-linux-gcc -v

Using built-in specs.

Target: arm-unknown-linux-gnueabi

Configured with: /home/scsuh/workplace/coffee/buildroot-20071011/toolchain_build_arm/gcc-4.2.2/configure --prefix=/usr --build=i386-pc-linux-gnu --host=i386-pc-linux-gnu --target=arm-unknown-linux-gnueabi --enable-languages=c,c++ --with-sysroot=/usr/local/arm/4.2.2-eabi/ --with-build-time-tools=/usr/local/arm/4.2.2-eabi//usr/arm-unknown-linux-gnueabi/bin --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --enable-shared --with-gmp=/usr/local/arm/4.2.2-eabi//gmp --with-mpfr=/usr/local/arm/4.2.2-eabi//mpfr --disable-nls --enable-threads --disable-multilib --disable-largefile --with-arch=armv4t --with-float=soft --enable-cxx-flags=-msoft-float

Thread model: posix

gcc version 4.2.2

 

2.2、开发板环境

2.2.1、CES-6410开发平台

   Samsung S3C6410X, ARM1176JZF-S

   128MB,  Mobile DDR SDRAM

   USB HOST:一个USB HOST 接口,USB2.0全速(12Mbits/s)

 

3、             Linux应用软件的编译

3.1、usb-modeswitch-1.1.3

[root@localhost cdma]# tar xzf libusb-0.1.12.tar.gz

[root@localhost cdma]# cp libusb-0.1.12 libusb-0.1.12-arm

[root@localhost cdma]# cd libusb-0.1.12-arm

[root@localhost libusb-0.1.12-arm]#./configure --prefix=/works/cdma/install --host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g++

[root@localhost libusb-0.1.12-arm]# make

[root@localhost libusb-0.1.12-arm]# make install

[root@localhost libusb-0.1.12-arm]# cd ..

 

[root@localhost cdma]# tar xjf usb-modeswitch-1.1.3.tar.bz2

[root@localhost cdma]# cp usb-modeswitch-1.1.3 usb-modeswitch-1.1.3-arm

[root@localhost cdma]# cd usb-modeswitch-1.1.3-arm

[root@localhost usb-modeswitch-1.1.3-arm]#

修改Makefile

CC          = gcc

改为

CC          = arm-linux-gcc

CFLAGS      += -Wall -l usb

改为

CFLAGS      += -Wall -l usb -I/works/cdma/install/include -L/works/cdma/install/lib

修改usb_modeswitch.c

//                    readConfigFile("/etc/usb_modeswitch.setup");

改为

                      readConfigFile("/etc/usb_modeswitch.setup");

[root@localhost usb-modeswitch-1.1.3-arm]# make

[root@localhost usb-modeswitch-1.1.3-arm]# make install

[root@localhost usb-modeswitch-1.1.3-arm]# cd ..

[root@localhost cdma]#

 

3.2、ppp-2.4.4

[root@localhost cdma]# tar xzf libpcap-0.9.8.tar.gz

[root@localhost cdma]# cp libpcap-0.9.8 libpcap-0.9.8-arm

[root@localhost libpcap-0.9.8-arm]# ./configure --prefix=/works/cdma/install --host=arm-linux --with-pcap

make: *** No rule to make target `pcap-yes.o', needed by `libpcap.a'.  Stop.

修改Makefile

PSRC =  pcap-yes.c

改为

PSRC =  pcap-linux.c

[root@localhost libpcap-0.9.8-arm]# make

[root@localhost libpcap-0.9.8-arm]# make install

[root@localhost libpcap-0.9.8-arm]# cd ..

 

tar xzvf ppp-2.4.4.tar.gz

[root@localhost cdma]# cd ppp-2.4.4

[root@localhost ppp-2.4.4]# ./configure --host=arm-linux

vi pppd/Makefile

 

LIBS    += -lpcap

CFLAGS  += -DPPP_FILTER

改为

LIBS    += -lpcap -L../../libpcap-0.9.8

CFLAGS  += -DPPP_FILTER -I../../libpcap-0.9.8

 

[root@localhost ppp-2.4.4]# make CC=arm-linux-gcc

 

3.3、wvdial

3.3.1、wvdial-1.54.0

[root@localhost wvdial-1.54.0]# export PATH=/usr/local/arm/3.4.1/bin:$PATH

[root@localhost wvdial-1.54.0]# tar xjf zlib-1.2.5.tar.bz2

[root@localhost wvdial-1.54.0]# cd zlib-1.2.5

[root@localhost zlib-1.2.5]#./configure --prefix=/works/wvdial-1.54.0/install

修改Makefile

CC = arm-linux-gcc

CPP=arm-linux-gcc -E

AR=arm-linux-ar rc

RANLIB=arm-linux-ranlib

[root@localhost zlib-1.2.5]# make

[root@localhost zlib-1.2.5]# make install

 

[root@localhost wvdial-1.54.0]# tar xzf openssl-0.9.7g.tar.gz

[root@localhost wvdial-1.54.0]# cd openssl-0.9.7g

[root@localhost openssl-0.9.7g]# patch -Np1 -i ../openssl-0.9.7g-fix_manpages-1.patch

[root@localhost openssl-0.9.7g]#./Configure --prefix=/works/wvdial-1.54.0/install os/compiler:arm-linux-gcc

[root@localhost openssl-0.9.7g]# make

[root@localhost openssl-0.9.7g]# make install

[root@localhost openssl-0.9.7g]# cd ..

 

[root@localhost wvdial-1.54.0]# tar xjf wvstreams-4.0.1.tar.bz2

[root@localhost wvdial-1.54.0]# cd wvstreams-4.0.1

[root@localhost wvstreams-4.0.1]# patch -Np1 -i ../wvstreams-4.0.1-tcl84-1.patch

修改configure

with_openssl=no

改为

with_openssl=yes

(有两处)

[root@localhost wvstreams-4.0.1]# ./configure --prefix=/works/wvdial-1.54.0/install --host=arm-linux CFLAGS=-I/works/cdma/install/include LDFLAGS=-L/works/cdma/install/lib/ --with-zlib=/works/cdma/zlib-1.2.5 --with-openssl=/works/cdma/openssl-0.9.8n --without-dbus --with-pam=no --with-tcl=no --with-qt=no

[root@localhost wvstreams-4.0.1]# make

linking libwvutils.so...

/usr/lib/libz.so: could not read symbols: Invalid operation

collect2: ld returned 1 exit status

make: *** [libwvutils.so] Error 1

[root@localhost wvstreams-4.0.1]# arm-linux-gcc -L./xplc -L/works/cdma/install/lib/ -L./xplc  -L. -g  -Wl,-soname,libwvutils.so.4.0 -shared -o libwvutils.so utils/strcrypt.o utils/verstring.o utils/wvaudioencoder.o utils/wvbase64.o utils/wvbdbhash.o utils/wvcrash.o utils/wvdiriter.o utils/wvgzip.o utils/wvhashtable.o utils/wvhex.o utils/wvmagiccircle.o utils/wvmatrix.o utils/wvqdbmhash.o utils/wvrateadjust.o utils/wvserialize.o utils/wvshmzone.o utils/wvstringtable.o utils/wvsubproc.o utils/wvtest.o utils/wvwordwrap.o libwvbase.so      -lsupc++ -lgcc_eh

[root@localhost wvstreams-4.0.1]# make

[root@localhost wvstreams-4.0.1]# vi wvrules.mk

XX_LIBS := $(XX_LIBS) $(shell $(CC) -lsupc++ -lgcc_eh 2>&1 | grep -q "undefined reference" && echo " -lsupc++ -lgcc_eh")

改为

XX_LIBS := $(XX_LIBS) $(shell $(CC) -lsupc++ -lgcc_eh 2>&1 | grep -q "undefined reference" && echo " -lz -lcrypt -lsupc++ -lgcc_eh")

[root@localhost wvstreams-4.0.1]# make

compiling crypto/wvtripledes.o...

crypto/wvtripledes.cc: In member function `virtual bool

   WvTripleDESEncoder::_encode(WvBuf&, WvBuf&, bool)':

crypto/wvtripledes.cc:108: error: cannot convert `const unsigned char*' to `

   unsigned char (*)[8]' for argument `1' to `void DES_ecb3_encrypt(unsigned

   char (*)[8], unsigned char (*)[8], DES_key_schedule*, DES_key_schedule*,

   DES_key_schedule*, int)'

make: *** [crypto/wvtripledes.o] Error 1

解决方法:

crypto/wvtripledes.cc

修改

#if OPENSSL_VERSION_NUMBER >= 0x0090705FL

改为

#if 0

 

compiling crypto/wvx509.o...

crypto/wvx509.cc: In member function `WvString WvX509Mgr::get_extension(int)':

crypto/wvx509.cc:1168: error: invalid conversion from `unsigned char**' to `

   const unsigned char**'

crypto/wvx509.cc:1171: error: invalid conversion from `unsigned char**' to `

   const unsigned char**'

make: *** [crypto/wvx509.o] Error 1

解决方法:

crypto/wvx509.cc

                    if (method->it)

                        ext_data = ASN1_item_d2i(NULL, &ext->value->data,

                                                ext->value->length,

                                                ASN1_ITEM_ptr(method->it));

                    else

                        ext_data = method->d2i(NULL, &ext->value->data,

                                              ext->value->length);

改为

                    if (method->it)

                        ext_data = ASN1_item_d2i(NULL, (const unsigned char **)&ext->value->data,

                                                ext->value->length,

                                                ASN1_ITEM_ptr(method->it));

                    else

                        ext_data = method->d2i(NULL, (const unsigned char **)&ext->value->data,

                                              ext->value->length);

 

compiling streams/wvpam.o...

streams/wvpam.cc: In member function `bool WvPam::authenticate(const

   WvFastString&, const WvFastString&, const WvFastString&)':

streams/wvpam.cc:71: error: `fail' undeclared (first use this function)

streams/wvpam.cc:71: error: (Each undeclared identifier is reported only once

   for each function it appears in.)

make: *** [streams/wvpam.o] Error 1

解决方法:

    return fail;

改为

    return false;

 

[root@localhost wvstreams-4.0.1]# make install

[root@localhost wvstreams-4.0.1]# cp libwvutils.so ../install/lib/libwvutils.so.4.0 -a

[root@localhost wvstreams-4.0.1]# cd ..

 

[root@localhost wvdial-1.54.0]# tar xzf wvdial-1.54.0.tar.gz

[root@localhost wvdial-1.54.0]# cd wvdial-1.54.0

[root@localhost wvdial-1.54.0]# cp /works/wvdial-1.54.0/install/include/wvstreams/*.h .

[root@localhost wvdial-1.54.0]# vi Makefile

PREFIX=/usr/local

改为

PREFIX=/works/wvdial-1.54.0/install

 

PPPDIR=/etc/ppp/peers

改为

PPPDIR=${PREFIX}/etc/ppp/peers

 

XPATH=.. ../wvstreams/include $(PKGINC)

改为

XPATH=/works/wvdial-1.54.0/install/include/wvstreams

 

LIBS += -L../wvstreams -lwvutils -lwvstreams

改为

LIBS += -L/works/wvdial-1.54.0/install/lib -lwvutils -lwvstreams -lwvbase -lz

 

[root@localhost wvdial-1.54.0]# vi wvrules.mk

增加

CC = arm-linux-g++

CXX = arm-linux-g++

[root@localhost wvdial-1.54.0]# make

[root@localhost wvdial-1.54.0]# make install

 

3.3.2、wvdial-1.60.4

export PATH=/usr/local/arm/4.2.2-eabi/usr/bin:$PATH

tar xjf zlib-1.2.5.tar.bz2

cd zlib-1.2.5

./configure --prefix=/works/cdma/install-4.2.2

修改Makefile

CC = arm-linux-gcc

CPP=arm-linux-gcc -E

AR=arm-linux-ar rc

RANLIB=arm-linux-ranlib

make

make install

 

openssl-0.9.8n

patch -Np1 -i ../openssl-0.9.8n-fix_manpages-1.patch

./Configure --prefix=/works/cdma/install-4.2.2 os/compiler:arm-linux-gcc

make

make install

 

wvstreams-4.6.1

修改configure

with_zlib=no

改为

with_zlib=yes

(有两处)

 

with_openssl=no

改为

with_openssl=yes

(有两处)

./configure --prefix=/works/cdma/install-4.2.2 --host=arm-linux CPPFLAGS=-I/works/cdma/install-4.2.2/include LDFLAGS=-L/works/cdma/zlib-1.2.5-4.2.2 CFLAGS=-I/works/cdma/zlib-1.2.5-4.2.2 --with-zlib=/works/cdma/zlib-1.2.5-4.2.2/ --with-openssl=/works/cdma/openssl-0.9.8n-4.2.2 --without-dbus --with-pam=no --with-tcl=no --with-qt=no --without-valgrind

make

make install

 

wvdial-1.60.4

修改Makefile

prefix=/usr/local

改为

prefix=/works/cdma/install-4.2.2

 

PPPDIR=/etc/ppp/peers

改为

PPPDIR=${prefix}/etc/ppp/peers

 

PC_CFLAGS=$(shell pkg-config --cflags libwvstreams)

改为

PC_CFLAGS=-I/works/cdma/install-4.2.2/include/wvstreams

 

PC_LIBS=$(shell pkg-config --libs libwvstreams)

PC_LIBS=-L/works/cdma/install-4.2.2/lib -lwvstreams -lwvutils -lwvbase

 

修改wvrules.mk

WVLINK_CC = gcc

改为

WVLINK_CC = arm-linux-g++

CC = arm-linux-g++

CXX = arm-linux-g++

 

make

make install

 

4、             Linux内核的配置与修改

4.1、linux内核配置

make menuconfig

Device Drivers  ---> 

[*] Network device support  --->

   PPP (point-to-point protocol) support

[*]     PPP multilink support (EXPERIMENTAL)

[*]     PPP filtering

     PPP support for async serial ports

     PPP support for sync tty ports

     PPP Deflate compression

     PPP MPPE compression (encryption) (EXPERIMENTAL)

     PPP over Ethernet (EXPERIMENTAL)

  [*] USB support  --->

   USB Modem (CDC ACM) support

USB Serial Converter support  --->

     USB driver for GSM and CDMA modems

 

4.2、linux内核修改

drivers/usb/serial/option.c

static struct usb_device_id option_ids[] = {

};

在这个数组中添加两项

        { USB_DEVICE(0x19d2, 0x0031) },

        { USB_DEVICE(0x19d2, 0x0034) },

4.3、linux内核编译

make zImage

make modules

 

5、             3G模块的使用

5.1、加载内核模块

insmod option.ko

insmod cdc-acm.ko

insmod slhc.ko

insmod ppp_generic.ko

insmod pppox.ko

insmod pppoe.ko

insmod ppp_synctty.ko

insmod ppp_deflate.ko

insmod crc-ccitt.ko

insmod ppp_async.ko

insmod sha1_generic.ko

insmod ppp_mppe.ko

 

5.2、加载USB文件系统

mount -t usbfs usbfs /proc/bus/usb

 

5.3、ZTE-mf637u(中国联通)的使用

5.3.1、配置文件/etc/usb_modeswitch.setup

# Configuration for the usb-modeswitch package, a mode switching tool for

# USB devices providing multiple states or modes

#

# This file is evaluated by the wrapper script "usb_modeswitch" in /lib/udev

# To enable an option, set it to "1", "yes" or "true" (case doesn't matter)

# Everything else counts as "disable"

 

 

# Disable automatic mode switching globally (e.g. to access the original

# install storage)

 

DisableSwitching=0

 

 

# Enable logging (results in a extensive report file in /var/log, named

# "usb_modeswitch_"

 

EnableLogging=0

 

########################################################

# ZTE MF622 (aka "Onda MDC502HS")

# ZTE MF626

# ZTE MF628+ (tested version from Telia / Sweden)

# ZTE MF633

# ZTE MF636 (aka "Telstra / BigPond 7.2 Mobile Card")

# ZTE MF637

#

# Contributor: Joakim Wennergren and others

 

DefaultVendor=  0x19d2

DefaultProduct= 0x2000

 

TargetVendor=   0x19d2

TargetProduct=  0x0031

 

MessageContent="5553424312345678000000000000061b000000020000000000000000000000"

MessageContent2="5553424312345678000000000000061b000000030000000000000000000000"

 

NeedResponse=1

 

5.3.2、配置文件/etc/wvdial.conf

[Dialer Defaults]

 

Modem = /dev/ttyUSB2

 

Init1 = ATZ

 

Init3 = ATE0V1

 

Init5 = ATS0=0

 

Init6 = AT+CGDCONT=1,"IP","uninet"

 

Init7 = AT+CFUN=1

 

Modem Type = USB Modem

 

Baud = 460800

 

New PPPD = yes

 

ISDN = 0

 

Phone = *99***1#

 

Password = any

 

Username = any

 

Stupid Mode = 1

 

5.3.3 ZTE-mf637u(中国联通)的操作步骤

5.3.3.1、设置环境变量

export PATH= /works/wvdial-1.54.0/install/bin: /works/cdma/install/bin :$PATH

export LD_LIBRARY_PATH= /works/wvdial-1.54.0/install/lib: /works/cdma/install/lib:$LD_LIBRARY_PATH

5.3.3.2、插入ZTE-mf637u(中国联通)无线网卡

5.3.3.3、等待5秒钟左右、运行usb-modeswitch -W

5.3.3.4、运行wvdial

--> WvDial: Internet dialer version 1.54.0

--> Cannot open /dev/ttyUSB2: Cannot get information for serial port.

--> Cannot open /dev/ttyUSB2: Cannot get information for serial port.

--> Cannot open /dev/ttyUSB2: Cannot get information for serial port.

 

解决:(两种方法)

5.3.3.4.1将wvstreams-4.0.1/streams/wvmodem.cc

#if HAVE_LINUX_SERIAL_H

改为

#if 0

 

5.3.3.4.2. wvstreams-4.0.1的配置命令增加ac_cv_header_linux_serial_h=no

即./configure --prefix=/works/wvdial-1.54.0/install --host=arm-linux CFLAGS=-I/works/cdma/install/include LDFLAGS=-L/works/cdma/install/lib/ --with-zlib=/works/cdma/zlib-1.2.5 --with-openssl=/works/cdma/openssl-0.9.8n --without-dbus --with-pam=no --with-tcl=no --with-qt=no ac_cv_header_linux_serial_h=no

重新编译。

 

5.4、ZTE-mu351(中国移动)的使用

5.4.1、配置文件/etc/wvdial.conf

Modem = /dev/ttyACM2

Init1 = ATZ

Init3 = ATE0V1

Init5 = ATS0=0

Init6 = AT+CGDCONT=1,"IP","cmnet"

Init7 = AT+CFUN=1

Modem Type = USB Modem

Baud = 460800

New PPPD = yes

ISDN = 0

Phone = *99***1#

Password = any

Username = any

Stupid Mode = 1

5.4.2、ZTE-mu351(中国移动)的操作步骤

5.4.2.1、设置环境变量

export PATH=/root/cdma:$PATH

export LD_LIBRARY_PATH=/root/cdma:$LD_LIBRARY_PATH

5.4.2.2、插入ZTE-mu351(中国移动)无线网卡

5.4.2.3、等待5秒钟左右、运行eject /dev/sr0。(5.3.3.3也可以使用此方法)

5.4.2.4、运行wvdial

--> WvDial: Internet dialer version 1.54.0

--> Initializing modem.

--> Sending: ATZ

ATZ

OK

--> Sending: ATE0V1

ATE0V1

OK

--> Sending: ATS0=0

OK

--> Sending: AT+CGDCONT=1,"IP","cmnet"

OK

--> Sending: AT+CFUN=1

OK

--> Modem initialized.

--> Sending: ATDT*99***1#

--> Waiting for carrier.

NO CARRIER

--> No Carrier!  Trying again.

--> Sending: ATDT*99***1#

--> Waiting for carrier.

NO CARRIER

--> No Carrier!  Trying again.

--> Sending: ATDT*99***1#

--> Waiting for carrier.

NO CARRIER

--> No Carrier!  Trying again.

--> Sending: ATDT*99***1#

--> Waiting for carrier.

NO CARRIER

--> No Carrier!  Trying again.

--> Sending: ATDT*99***1#

--> Waiting for carrier.

^MODE: 15

CONNECT 2800000

--> Carrier detected.  Starting PPP immediately.

--> Starting pppd at Mon Aug 16 16:17:15 2010

--> pid of pppd: 1364

--> Using interface ppp0

--> local  IP address 10.67.54.108

--> remote IP address 192.200.1.21

--> primary   DNS address 211.136.20.203

--> secondary DNS address 211.136.17.107

 

 

6、             参考资料

 

 

 

阅读(4770) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~