Linux 系统下驱动安装及PPP拨号1

## 1.驱动安装 使用 USB 接口,对上层的功能接口是串口,在 Linux 系统中使用 USB转串口的驱动。驱动加载需要首先配置 Linux 内核,配置方法如下: ```` Make menuconfig Devicedrivers->usb support->usb serial converter support ```` **选中如下组件**: ```` USB driver for GSM and CDMA modems ```` ![image.png](https://cos.easydoc.net/84373768/files/k481lw3r.png) 选择后保存设置。 ## 2添加内核 USB 驱动识别 ID 打开内核源码文件 option.c(路径 drivers/usb/serial/option.c),找到 option_ids数组,添加如下内容: ```` { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0532, 0xff, 0xff,0xff) }, { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0536, 0xff, 0xff,0xff) }, { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0542, 0xff, 0xff,0xff) }, { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0573, 0xff, 0xff,0xff) }, { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0579, 0xff, 0xff,0xff) }, ```` **编译好内核烧写后,插上 USB 线连接模组,显示如下信息** ![image.png](https://cos.easydoc.net/84373768/files/k481m9t8.png) 使用 ls /dev 查看设备,出现ttyUSB0 到 ttyUSB3 表示 USB 枚举成功,其中 ttyUSB0 为 AT 口。 ![image.png](https://cos.easydoc.net/84373768/files/k481me88.png) ## 3.切换外网模式 先使用“AT+ZLANENABLE?”命令查看模组当前使用的网络模式(默认为外网模式,开机手动拨号),如果返回 ZLANENABLE 为 1,则表示当前为内网模式, 需要使用以下命令切换为外网模式,手动拨号: echo -ne 'AT+ZLANENABLE=0\r' > /dev/ttyUSB0 此时,模组会重启。 ![image.png](https://cos.easydoc.net/84373768/files/k481ml2w.png) ## 4.编译 ppp-2.4.4 进入ppp-2.4.4源码目录,运行以下命令编译 ```` ./configure make CC=arm-none-linux-gnueabi-gcc ```` 编译到此完成,可以看到在 pppd 文件夹生成了 pppd 工具,在 chat 文件夹生成了 chat工具 ## 5.PPP 拨号 安装开源 pppd 拨号程序,在\bin目录下添加 PPP 启动脚本。推荐脚本如下: ### 5.1启动脚本 ppp.sh ```` #!/bin/sh TELEPHONE=*98*1# # The telephone number for the connection LOCAL_IP=0.0.0.0 # Local IP address if known. Dynamic = 0.0.0.0 REMOTE_IP=0.0.0.0 # Remote IP address if desired. Normally 0.0.0.0 NETMASK=255.255.255.0 # The proper netmask if needed echo -ne 'AT+CVMOD=0\r' > /dev/ttyUSB0 #设置语音模式为 CS_ONLY echo -ne 'AT+CFUN=1\r' > /dev/ttyUSB0 #激活 sleep 10 #延时 10 秒 echo -ne 'AT+CGDCONT=1,\"IP\",\"CMNET\"\r' > /dev/ttyUSB0 #配置 APN /bin/pppd debug lock modem crtscts /dev/ttyUSB1 115200 unit 0 asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP noipdefault netmask $NETMASK defaultroute connect /sbin/dialer_AM410E ```` ### 5.2拨号脚本 dialer_AM410E 在\sbin目录下添加 dialer_AM410E 拨号脚本 ```` #!/bin/sh #This is part 2 of the ppp-on script. It will perform the connection # protocol for the desired connection. exec chat -v \ TIMEOUT 3 \ ABORT '\nBUSY\r' \ ABORT '\nNO ANSWER\r' \ ABORT '\nRINGING\r\n\r\nRINGING\r' \ '' AT '' AT \ 'OK' ATH0 \ TIMEOUT 30 \ OK ATD$TELEPHONE \ CONNECT '' \ ```` ## 6.在\bin目录下执行启动脚本 sh ppp.sh ## 7.查看模块运行状态:ifconfig ![image.png](https://cos.easydoc.net/84373768/files/k481prge.png) ## 8. 验证拨号成功 ping 域名 ```` ping www.baidu.com PING www.baidu.com (61.135.169.121): 56 data bytes 64 bytes from 61.135.169.121: seq=0 ttl=52 time=68.409 ms 64 bytes from 61.135.169.121: seq=1 ttl=52 time=68.564 ms ````