嵌入式Linux下3G模块的驱动和应用1、开发资源1.1、硬件资源:ZTE-mf637u(中国联通)ZTE-mu351(中国移动)1.2、软件资源:1.2.1、usb-modeswitch-1.1.3libusb-0.1.12.tar.gzusb-modeswitch-1.1.3.tar.bz21.2.2、ppp-2.4.4libpcap-0.9.8.tar.gzppp-2.4.4.tar.gz1.2.3、wvdial1.2.3.1、wvdial-1.54.0(arm-linux-gcc 3.4.1) zlib-1.2.5.tar.bz2openssl-0.9.7g.tar.gzopenssl-0.9.7g-fix_manpages-1.patch wvstreams-4.0.1.tar.bz2wvstreams-4.0.1-tcl84-1.patchwvdial-1.54.0.tar.gz1.2.3.2、wvdial_1.60.4(arm-linux-gcc 4.2.2)zlib-1.2.5.tar.bz2openssl-0.9.8n.tar.gzopenssl-0.9.8n-fix_manpages-1.patchwvstreams-4.6.1.tar.gzwvdial_1.60.4.tar.gz2、Linux开发环境2.1、主机环境2.1.1、主机linux系统Fedora Core 62.1.2、主机编译环境2.1.2.1、gcc -vUsing built-in specs.Target: i386-redhat-linuxConfigured 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-linuxThread model: posixgcc 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 -vReading specs from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/specsConfigured 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-longThread model: posixgcc version 3.4.12.1.2.3、/usr/local/arm/4.2.2/usr/bin/arm-linux-gcc -vUsing built-in specs.Target: arm-unknown-linux-gnueabiConfigured with:/home/scsuh/workplace/coffee/buildroot-20071011/toolchain_build_arm/gcc-4.2.2/configu re --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-floatThread model: posixgcc version 4.2.22.2、开发板环境2.2.1、CES-6410开发平台Samsung S3C6410X, ARM1176JZF-S128MB, Mobile DDR SDRAMUSB 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]#修改MakefileCC = gcc改为CC = arm-linux-gccCFLAGS += -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-pcapmake: *** No rule to make target `pcap-yes.o', needed by `libpcap.a'. Stop.修改MakefilePSRC = 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 ..[root@localhost cdma]# 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-linuxvi pppd/MakefileLIBS += -lpcapCFLAGS += -DPPP_FILTER改为LIBS += -lpcap -L../../libpcap-0.9.8CFLAGS += -DPPP_FILTER -I../../libpcap-0.9.8[root@localhost ppp-2.4.4]# make CC=arm-linux-gcc3.3、wvdial3.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修改MakefileCC = arm-linux-gccCPP=arm-linux-gcc -EAR=arm-linux-ar rcRANLIB=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修改configurewith_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/includeLDFLAGS=-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]# makelinking libwvutils.so.../usr/lib/libz.so: could not read symbols: Invalid operationcollect2: ld returned 1 exit statusmake: *** [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.outils/verstring.o utils/wvaudioencoder.o utils/wvbase64.o utils/wvbdbhash.outils/wvcrash.o utils/wvdiriter.o utils/wvgzip.o utils/wvhashtable.o utils/wvhex.outils/wvmagiccircle.o utils/wvmatrix.o utils/wvqdbmhash.o utils/wvrateadjust.outils/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.mkXX_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]# makecompiling crypto/wvtripledes.o...crypto/: In member function `virtual boolWvTripleDESEncoder::_encode(WvBuf&, WvBuf&, bool)':crypto/: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/修改#if OPENSSL_VERSION_NUMBER >= 0x0090705FL改为#if 0compiling crypto/wvx509.o...crypto/: In member function `WvString WvX509Mgr::get_extension(int)': crypto/:1168: error: invalid conversion from `unsigned char**' to `const unsigned char**'crypto/:1171: error: invalid conversion from `unsigned char**' to `const unsigned char**'make: *** [crypto/wvx509.o] Error 1解决方法:crypto/if (method->it)ext_data = ASN1_item_d2i(NULL, &ext->value->data,ext->value->length,ASN1_ITEM_ptr(method->it));elseext_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));elseext_data = method->d2i(NULL, (const unsigned char**)&ext->value->data,ext->value->length);compiling streams/wvpam.o...streams/: In member function `bool WvPam::authenticate(constWvFastString&, const WvFastString&, const WvFastString&)':streams/:71: error: `fail' undeclared (first use this function)streams/:71: error: (Each undeclared identifier is reported only oncefor 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 MakefilePREFIX=/usr/local改为PREFIX=/works/wvdial-1.54.0/installPPPDIR=/etc/ppp/peers改为PPPDIR=${PREFIX}/etc/ppp/peersXPATH=.. ../wvstreams/include $(PKGINC)改为XPATH=/works/wvdial-1.54.0/install/include/wvstreamsLIBS += -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 install3.3.2、wvdial-1.60.4export PATH=/usr/local/arm/4.2.2-eabi/usr/bin:$PATHtar xjf zlib-1.2.5.tar.bz2cd zlib-1.2.5./configure --prefix=/works/cdma/install-4.2.2修改MakefileCC = arm-linux-gccCPP=arm-linux-gcc -EAR=arm-linux-ar rcLDSHARED=arm-linux-gcc ....RANLIB=arm-linux-ranlibmakemake installopenssl-0.9.8npatch -N -p1 -i ../openssl-0.9.8n-fix_manpages-1.patch./Configure --prefix=/works/cdma/install-4.2.2 os/compiler:arm-linux-gcc makemake installwvstreams-4.6.1修改configurewith_zlib=no改为with_zlib=yes(有两处)with_openssl=no改为with_openssl=yes(有两处)./configure --prefix=/works/cdma/install-4.2.2 --host=arm-linuxCPPFLAGS=-I/works/cdma/install-4.2.2/includeLDFLAGS=-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-valgrindmake如果出现undefined reference to"EVP_MD_size"错误将出现错误的语句returnEVP_MD_size((evp_md_st *)evpmd;改成return ((evp_md_st *)evpmd)->md_size;即可make installwvdial-1.60.4修改Makefileprefix=/usr/local改为prefix=/works/cdma/install-4.2.2PPPDIR=/etc/ppp/peers改为PPPDIR=${prefix}/etc/ppp/peersPC_CFLAGS=$(shell pkg-config --cflags libwvstreams)改为PC_CFLAGS=-I/works/cdma/install-4.2.2/include/wvstreamsPC_LIBS=$(shell pkg-config --libs libwvstreams)PC_LIBS=-L/works/cdma/install-4.2.2/lib -lwvstreams -lwvutils -lwvbase修改wvrules.mkWVLINK_CC = gcc改为WVLINK_CC = arm-linux-g++CC = arm-linux-g++CXX = arm-linux-g++makemake install4、Linux内核的配置与修改4.1、linux内核配置make menuconfigDevice Drivers --->[*] Network device support ---><M> PPP (point-to-point protocol) support[*] PPP multilink support (EXPERIMENTAL)[*] PPP filtering<M> PPP support for async serial ports<M> PPP support for sync tty ports<M> PPP Deflate compression<M> PPP MPPE compression (encryption) (EXPERIMENTAL) <M> PPP over Ethernet (EXPERIMENTAL)[*] USB support ---><M> USB Modem (CDC ACM) supportUSB Serial Converter support ---><M> USB driver for GSM and CDMA modems4.2、linux内核修改drivers/usb/serial/option.cstatic struct usb_device_id option_ids[] = {…};在这个数组中添加两项{ USB_DEVICE(0x19d2, 0x0031) },{ USB_DEVICE(0x19d2, 0x0034) },4.3、linux内核编译make zImagemake modules5、3G模块的使用5.1、加载内核模块insmod option.koinsmod cdc-acm.koinsmod slhc.koinsmod ppp_generic.koinsmod pppox.koinsmod pppoe.koinsmod ppp_synctty.koinsmod ppp_deflate.koinsmod crc-ccitt.koinsmod ppp_async.koinsmod sha1_generic.koinsmod ppp_mppe.ko5.2、加载USB文件系统mount -t usbfs usbfs /proc/bus/usb5.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_<interface-name>"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 othersDefaultVendor= 0x19d2DefaultProduct= 0x2000TargetVendor= 0x19d2TargetProduct= 0x0031MessageContent="5553424312345678000000000000061b0000000200000000000 00000000000"MessageContent2="5553424312345678000000000000061b000000030000000000 000000000000"NeedResponse=15.3.2、配置文件/etc/wvdial.conf[Dialer Defaults]Modem = /dev/ttyUSB2Init1 = ATZInit3 = ATE0V1Init5 = ATS0=0Init6 = AT+CGDCONT=1,"IP","uninet" Init7 = AT+CFUN=1Modem Type = USB ModemBaud = 460800New PPPD = yesISDN = 0Phone = *99***1#Password = anyUsername = anyStupid Mode = 15.3.3 ZTE-mf637u(中国联通)的操作步骤5.3.3.1、设置环境变量export PATH= /works/wvdial-1.54.0/install/bin: /works/cdma/install/bin :$PATHexport LD_LIBRARY_PATH= /works/wvdial-1.54.0/install/lib:/works/cdma/install/lib:$LD_LIBRARY_PATH5.3.3.2、插入ZTE-mf637u(中国联通)无线网卡5.3.3.3、等待5秒钟左右、运行usb-modeswitch -W5.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/#if HAVE_LINUX_SERIAL_H改为#if 05.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-linuxCFLAGS=-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 重新编译。