• 3G网卡PPP拨号


    1.USB_ModeSwitch

    1.1简介

    USB_ModeSwitch is (surprise!) a mode switching tool for controlling 'multi-mode' USB devices.

    USB工作模式:USB存储模式,USB Serial模式。现在3G,无线网卡模块使用USB接口,其工作模式是usb serial模式。

    具体说明见:

    http://www.draisberghof.de/usb_modeswitch/#intro

    1.2 内核配置

    1.2.1 USB驱动

    Device Drivers>>USB support>>
    <*>USB SerialConverter support
    	[*]USBGeneric Serial Driver 
        <*>USBdriver for GSM and CDMA modems
    

    1.2.2 PPP协议支持

    Device Drivers>>Network device support
    <*> PPP (point-to-point protocol) support   
            [*]   PPP multilink support (EXPERIMENTAL)    
            <*>   PPP support for async serial ports      
            <*>   PPP support for sync tty ports          
            <*>   PPP Deflate compression               
     		<*>   PPP BSD-Compress compression 
    

    2.下载制作usb_modeswitch工具

    2.1下载源文件与解压

    2.1.1

    mkdir usbmodeswitch
    cd usbmodeswitch
    wget http://pkgs.fedoraproject.org/repo/pkgs/libusb1/libusb-1.0.0.tar.bz2/df2447c23750ef2b4a314200feacc2ee/libusb-1.0.0.tar.bz2
    wget http://jaist.dl.sourceforge.net/project/libusb/libusb-compat-0.1/libusb-compat-0.1.5/libusb-compat-0.1.5.tar.bz2
    wget http://pkgs.fedoraproject.org/repo/pkgs/usb_modeswitch/usb-modeswitch-1.2.4.tar.bz2/dbd4ce7966d7b4a5a0604a8280f7164d/usb-modeswitch-1.2.4.tar.bz2
    wget http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-data-20170205.tar.bz2
    

    2.1.2 解压

    tar xjf libusb-1.0.0.tar.bz2
    tar xjf libusb-compat-0.1.5.tar.bz2 
    tar xjf usb-modeswitch-1.2.4.tar.bz2
    tar xjf usb-modeswitch-data-20170205.tar.bz2 
    

    2.2编译工具(ARM架构)

    mkdir install
    

    2.2.1编译libusb

    cd libusb-1.0.0
    ./configure CC=/usr/local/arm/4.3.2/bin/arm-linux-gcc(自己的目录) --prefix=xxx/install(自己的目录) --disable-shared --enable-static --build=i686 --host=arm-linux
    make 
    make install
    

    用命令查看ls ../install,有以下文件

    include  lib
    

    2.2.2编译libusb-compat

    cd ../libusb-compat-0.1.5
    export PKG_CONFIG_PATH=xxx/install/lib/pkgconfig(自己的目录):$PKG_CONFIG_PATH
    ./configure CC=/usr/local/arm/4.3.2/bin/arm-linux-gcc(自己的目录) --prefix=xxx/install(自己的目录) --disable-shared --enable-static --build=i686 --host=arm-linux
    make
    make install
    

    2.2.3编译usbmodeswitch

    cd usb-modeswitch-1.2.4
    

    修改Makefile,vim Makefile如下:

    #CC          = gcc
    #CFLAGS      += -Wall
    #LIBS        = -l usb
    CC          = /usr/local/arm/4.3.2/bin/arm-linux-gcc
    CFLAGS      += -Wall -I ../install/include -static
    LIBS        = -L ../install/lib -l usb -l usb-1.0 -l pthread -lrt
    

    或者通过如下命令修改

    sed -i -e "s|^CC.*|CC = /usr/local/arm/4.3.2/bin/arm-linux-gcc |g" Makefile
    sed -i -e "s|^CFLAGS.*|CFLAGS      += -Wall -I../install/include -static|g" Makefile
    sed -i -e "s|^LIBS.*|LIBS        = -L../install/lib/ -l usb -l usb-1.0 -l pthread -lrt|g" Makefile
    

    file usb_modeswitch查看生成的usb_modeswitch

    usb_modeswitch: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
    

    2.3复制usb_modeswitch

    1. 将usb-modeswitch-data-20170205下的usb_modeswitch.d中的所有文件都打包

      tar -cjf usb_modeswitch.d.tar.bz2 usb_modeswitch.d
      拷贝到开发板的etc/usb_modeswitch.d/目录,并解压

      tar -xjf usb_modeswitch.d.tar.bz2

    2. 把usb_modeswitch下载到开发板的/usr/sbin目录下。

    具体方法不在这里阐述了,可以根据自己情况!

    3.编译PPP

    3.1配置ppp

    mkdir ppp
    cd ppp/
    wget https://www.samba.org/ftp/ppp/ppp-2.4.4.tar.gz
    tar -xzf ppp-2.4.4.tar.gz
    cd ppp-2.4.4
    ./configure
    

    3.2修改chat.c

    cd chat/
    

    修改chat.c文件如下:
    1168 if (timeout_next) {
    1169 timeout_next = 0;
    1170 s = clean(s,0); //添加
    1171 timeout = atoi(s);
    1172 free(s); //添加
    1173 if (timeout <= 0)

    3.3修改chat中的Makefile

    INSTALL= install
    CC=/usr/local/arm/4.3.2/bin/arm-linux-gcc  #增加
    
    all:    chat
    
    chat:   chat.o 
        $(CC) -static -o chat chat.o		       #增加静态编译
    

    3.4修改PPPD目录下的auth.c

    cd ../pppd
    

    修改如下:

    1316     //ao->neg_upap = !refuse_pap && (passwd[0] != 0 || get_pap_passwd(NULL));
    1317     ao->neg_upap = !refuse_pap;      //modified
    

    3.5修改PPPD中的Makefile

    33 CC = /usr/local/arm/4.3.2/bin/arm-linux-gcc
    34 # CC = gcc
    47 # MPPE=y
    52 # FILTER=y
    69 # PLUGIN=y
    

    3.6编译PPPD-2.4.4

    cd ../
    make
    

    用file chat/chat pppd/pppd查看

    chat/chat: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped
    pppd/pppd: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
    

    3.7复制chat和pppd到开发板

    将交叉编译出来的这两个应用程序chat和pppd拷贝到开发板 /usr/sbin目录下

    4.配置拨号上网的脚本

    4.1配置文件——wcdma

    vim wcdma
    debug
    nodetach
    lock
    /dev/ttyUSB0
    115200
    user "card"
    password "card"
    crtscts
    show-password
    usepeerdns
    noauth
    noipdefault
    novj
    novjccomp
    noccp
    defaultroute
    ipcp-accept-local
    ipcp-accept-remote
    connect '/usr/sbin/chat -s -v -f wcdma-chat-connect'
    disconnect '/usr/sbin/chat -s -v -f wcdma-chat-disconnect'
    

    4.2配置文件——wcdma-chat-connect

    vim wcdma-chat-connect

    TIMEOUT 5
    ABORT 'NO CARRIER'
    ABORT 'ERROR'
    ABORT 'NO DIALTONE'
    ABORT 'BUSY'
    ABORT 'NO ANSWER'
    '' /rAT
    OK /rATZ
    OK /rAT+CGDCONT=1,"IP","3gnet",,0,0
    OK-AT-OK ATDT*99#
    CONNECT /d/c
    

    4.3配置文件——wcdma-chat-disconnect

    vim wcdma-chat-disconnect

    ABORT "BUSY"
    ABORT "ERROR"
    ABORT "NO DIALTONE"
    SAY "/nSending break to the modem/n"
    '' "/K"
    '' "+++ATH"
    SAY "/nGoodbay/n"
    

    4.4下载配置文件

    mkdir -p /etc/ppp/peers/
    mkdir /var/run -p  
    mkdir /var/lock -p  
    

    将wcdma、wcdma-chat-connect、wcdma-chat-disconnect三个文件下载到此目录下。
    此外,
    将/etc/resolv.conf下的resolv.conf下载到开发板/etc

    5.增加3G网卡的配置文件

    当插上3G网卡时,我们可以发现

    在这找到自己的3G网卡对应的配置文件,并下载到开发板相应目录

    http://www.draisberghof.de/usb_modeswitch/device_reference.txt

    ########################################################
    # Huawei E1550
    # Huawei E1750
    #
    # Contributor: Anders Blomdell, Ahmed Soliman
    DefaultVendor=  0x12d1
    DefaultProduct= 0x1446
    TargetVendor=   0x12d1
    TargetProduct=  0x1001
    MessageContent="55534243123456780000000000000011060000000000000000000000000000"
    MessageEndpoint=0x01
    CheckSuccess=5
    HuaweiMode=0 
    

    6.使用usb_modeswitch

    6.1挂载usbfs文件系统

    1. 临时挂载

      mount -t usbfs usbfs /proc/bus/usb/

    查看一下


    2. 自动挂载usbfs文件系统
    vi /etc/fstab加上

    usbfs  /proc/bus/usb    usbfs   defaults    0   0  
    

    6.2切换到串口设备工作

    usb_modeswitch -c xxx.conf(自己的3G网卡配置文件)
    

    cat /proc/bus/usb/devices

    7.测试——AT指令

    进入AT命令界面模式:

    microcom -s 115200 /dev/ttyUSB0(自己的USB号) 
    
    • 查看模块制造商:at+cgmi
    • 查看模块版本信息:at+cgmr
    • 查看GPRS模块型号:at+cgmm
    • 查看SIM卡是否在位:at+cpin? (Ready表示在位)
    • 查看GPRS模块信号强度,其中”,”前的数字为信号强度,at+csq
    • 查SIM卡是否注册上网络,其中”,”后的值为SIM卡的注册状态。如果状态值为0,表示未注册;如果为1表示本地号码注册上;如果为2,表示正在搜索运营商注册,但没注册上;如果为3表示拒绝注册;如果为4,未知状态;如果为5, 漫游号码注册上。at+creg?
    • 查SIM卡运营商,at+cops?

    8.测试-PPP拨号

    进入/etc/ppp/peers/目录执行

    pppd call wcdma&
    

    在/etc目录下新建resolv.conf,设置域名。
    之后可以ping www.baidu.com

    注:此外根据相关文献,有时还要编辑option.c,添加自己的3G网卡ID

    vim drivers/usb/serial/option.c
    


    参考文献:

    http://blog.csdn.net/ipromiseu/article/details/5154004
    http://blog.csdn.net/u010944778/article/details/47251701
    http://blog.csdn.net/alangdangjia/article/details/9413009
    http://blog.csdn.net/mrx_linux/article/details/47780715
    http://blog.chinaunix.net/uid-20780196-id-259111.html
    http://blog.csdn.net/hanmengaidudu/article/details/17099737


  • 相关阅读:
    寻找两个有序数组的中位数
    JAVA设计模式(组合模式)
    excel 操作
    研究生英语-春
    cvs
    Spring课程安排
    Spring的事务管理
    在WEB项目中集成Spring
    计算机网络参考模型
    揭开5G神秘面纱
  • 原文地址:https://www.cnblogs.com/boyiliushui/p/6701077.html
Copyright © 2020-2023  润新知