3G模块SIM5360E拨号上网

首先需要添加usb驱动,这就不介绍了,添加usb驱动参考:

https://blog.csdn.net/qq_43260665/article/details/89789136

在Linux内核2.6.20之后就有一个通用的名叫usbserial的驱动能够支持SIMCom的设备使用

一、修改内核

修改一:添加厂商id和产品id

[wuyujun@wuyujunlocalhost]$ cd fl2440/linux/linux-3.0/drivers/usb/serial/

[wuyujun@wuyujunlocalhost serial]$ vim option.c

在static struct usb_device_id option_ids[]结构体里

/*      add for simcom  */

 

#define SIMCOM_WCDMAN_VENDOR_ID                 0x05C6

#define SIMCOM_WCDMAN_PRODUCT_ID                0x9000

/*      end for simcom  */

static struct usb_device_id option_ids[] = {

        { USB_DEVICE(SIMCOM_WCDMAN_VENDOR_ID, SIMCOM_WCDMAN_PRODUCT_ID) },  /*  add by simcom   */

修改二:添加重启恢复

static struct usb_driver option_driver = {

        .name       = "option",

        .probe      = usb_serial_probe,

        .disconnect = usb_serial_disconnect,

#ifdef CONFIG_PM

        .suspend    = usb_serial_suspend,

        .resume     = usb_serial_resume,

        .reset_resume = usb_serial_resume, /*   add reset_resume        */

修改三:支持低功耗模式

加到static int option_probe(struct usb_serial *serial,const struct usb_device_id *id)函数最后

        if (serial->dev->descriptor.idVendor == SIMCOM_WCDMA_VENDOR_ID &&

        serial->dev->descriptor.idProduct == SIMCOM_WCDMA_PRODUCT_ID)

#ifdef CONFIG_PM

                pm_runtime_set_autosuspend_delay((struct device *)serial->dev, 12*1000) ;/*     for kernel 2.6.38 and above     */

                usb_enable_autosuspend(serial->dev) ;

#endif /* CONFIG_PM */

        }

修改四:添加短报文包标识

[wuyujun@wuyujunlocalhost serial]$ vim usb_wwan.c

static void usb_wwan_setup_urbs(struct usb_serial *serial)函数里

/* outdat endpoints */

for (j = 0; j < N_OUT_URB; ++j) {

portdata->out_urbs[j] = usb_wwan_setup_urb(serial,

                                                port->

bulk_out_endpointAddress,

                                                USB_DIR_OUT,

                                                port,

portdata->

                                             out_buffer

                                         [j],

                                             OUT_BUFLEN,

                                        usb_wwan_outdat_callback);

 

                      portdata->out_urbs[j]->transfer_flags |= URB_ZERO_PACKET ; //add by simcom

                }

二、配置内核

添加USB转串口支持   

Device Drivers  --->

 [*] USB support  --->      

        <*>   USB Serial Converter support  --->  

        <*>   USB driver for GSM and CDMA modems

Device Drivers  --->

Generic Driver Options  --->

       [*] Maintain a devtmpfs filesystem to mount at /dev

       [*]   Automount devtmpfs at /dev, after the kernel mounted the rootfs

添加内核对PPP拨号支持

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 BSD-Compress compression

配置完后重新编译内核并烧录内核

启动好系统之后插上sim5360e模块会出现如下信息:

usb 1-1.2: new full speed USB device number 4 using s3c2410-ohci

option 1-1.2:1.0: GSM modem (1-port) converter detected

usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB0

option 1-1.2:1.1: GSM modem (1-port) converter detected

usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB1

option 1-1.2:1.2: GSM modem (1-port) converter detected

usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB2

option 1-1.2:1.3: GSM modem (1-port) converter detected

usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB3

option 1-1.2:1.4: GSM modem (1-port) converter detected

usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB4

~ >: ls dev/ttyUSB*

dev/ttyUSB0  dev/ttyUSB1  dev/ttyUSB2  dev/ttyUSB3  dev/ttyUSB4

插上SIM5630E如果出现上述现象说明内核使能成功

用ls命令可以看到/devttyUSB0,ttyUSB1,ttyUSB2,ttyUSB3,ttyUSB4五个设备在/dev目录下被创建,五个设备分别为五个不同功能模块,ttyUSB2作为AT命令的接口.

三大运营商2G/3G/4G频率分配和网络制式

所以sim5360最好使用联通卡进行拨号上网

三、移植拨号工具pppd和chat

进行拨号上网还需要用ppp上网需要两个程序:pppd和chat 。这两个程序有开源代码,只需要根据自己的情况修改移植到开发板就可以了

[wuyujun@wuyujunlocalhost 3rdparty]$ cd ~/fl2440/3rdparty/

[wuyujun@wuyujunlocalhost 3rdparty]$ wget http://samba.org/ftp/ppp/ppp-2.4.5.tar.gz

[wuyujun@wuyujunlocalhost 3rdparty]$ tar zxvf ppp-2.4.5.tar.gz ppp-2.4.5.tar.gz

[wuyujun@wuyujunlocalhost ppp-2.4.5]$ ./configure  //生成makefile

[wuyujun@wuyujunlocalhost ppp-2.4.5]$ cd chat/

[wuyujun@wuyujunlocalhost chat]$ vim chat.c   

...

if (timeout_next) {

        timeout_next = 0;

        s = clean(s, 0);//add by WuYujun

        timeout = atoi(s);

        free(s);//add by Wuyujun

 

[wuyujun@wuyujunlocalhost chat]$ vim Makefile

...

COPTS=  -O2 -g -pipe

CFLAGS= $(COPTS) $(CDEFS)

 

CC =/opt/xtools/arm920t/bin/arm-linux-gcc //根据自己的情况添加交叉编译器

INSTALL= install

[wuyujun@wuyujunlocalhost chat]$ cd ../pppd    //切换到pppd目录下

[wuyujun@wuyujunlocalhost pppd]$ vim Makefile

CC =/opt/xtools/arm920t/bin/arm-linux-gcc //根据自己的情况添加交叉编译器

[wuyujun@wuyujunlocalhost pppd]$ vim auth.c

hadchap = -1;

        /*      commented out by WuYujun        */

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

    ao->neg_chap = (!refuse_chap || !refuse_mschap || !refuse_mschap_v2)

[wuyujun@wuyujunlocalhost pppd]$ cd ..

[wuyujun@wuyujunlocalhost ppp-2.4.5]$ make

[wuyujun@wuyujunlocalhost ppp-2.4.5]$ cd chat/

[wuyujun@wuyujunlocalhost chat]$ ls

chat  chat.8  chat.c  chat.o  Makefile  Makefile.linux  Makefile.sol2

[wuyujun@wuyujunlocalhost chat]$ file chat  //可以看到chat文件是ARM可执行文件

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

生成的chat是ARM开发板可执行文件,将其传到开发板的/bin或者/sbin路径下

[wuyujun@wuyujunlocalhost chat]$ cd ../pppd

[wuyujun@wuyujunlocalhost pppd]$ file pppd

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

~ >: tftp -gr pppd 192.168.137.1

pppd                 100% |*******************************|   788k  0:00:00 ETA

~ >: tftp -gr chat 192.168.137.1

chat                 100% |*******************************| 51028   0:00:00 ETA

~ >: mv chat pppd /bin/    //放到/bin路径下面

/bin >: chmod a+x chat

/bin >: chmod a+x pppd

 

~ >: cd /etc/

/etc >: mkdir -p ppp/peers   //在开发板的/etc目录新建/ppp/peers目录并在peers目录下创建如下配置文件

/etc >: cd ppp/peers/          

/etc/ppp/peers >: vi wcdma    //编写配置文件,给pppd进程提供配置参数

#Copyright (c) 2019 WuYujun  

#set debug ,send message to /var/log/messages

debug

#To keep pppd on the terminal

nodetach

lock   #

#set seriral

/dev/ttyUSB3

# set baudrate

115200           #设置波特率

user "wyj"        #如果需要chap或pap认证,则输入该用户名和密码                                     

password "wuyujun"  

# set flowrate

crtscts                

show-password

usepeerdns

noauth             #不设置认证

noipdefault         #禁用默认IP   

novj             #禁用TCP压缩

novjccomp

noccp

# Accept the peer's idea of our local IP address

ipcp-accept-local

# ipcp-accept-remote

ipcp-accept-remote

connect '/bin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect' #/bin/chat根据你chat放置的位置

disconnect '/bin/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect'

/etc/ppp/peers >: vi wcdma-chat-connect

ABORT 'NO CARRIER'

ABORT 'ERROR'

ABORT 'NO DIALTONE'

ABORT 'BUSY'

ABORT 'NO ANSWER'

'' \rAT   #发送AT命令

OK \rATZ   #等待接收OK,接收到OK发送ATZ命令

OK \rAT+CGDCONT=1,"IP","3gnet",,0,0  #接收到OK,发送AT+CGDCONT=1...命令

#下面一行是联通的拨号设置,不同的运营商拨号方式有所不同

OK-AT-OK ATDT*99#

CONNECT \d\c

运营商(ISP

APN

拨号号码

帐号

密码

中国联通WCDMA

China Unicom

3GNET

*99#

中国电信CDMA2000

China Telecom

EVDO网络

#777

ctnet@mycdma.cn

vnet.mobi

1X网络

#777

card (CARD)

cardCARD

中国移动 TD-SCDMA

China Mobile

CMNET

*98*1#

中国移动 GPRS

China Mobile

CMNET

*99***1#

 

/etc/ppp/peers >: vi wcdma-chat-disconnect   //出错处理wcdma-chat-disconnect 脚本

ABORT "ERROR"

ABORT "NO DIALTONE"

SAY "\nSending break to the modem\n"

'' "\K"

'' "+++ATH"

SAY "\nGoodbay\n"

/etc/ppp/peers >: pwd

/etc/ppp/peers

/etc/ppp/peers >: ls

wcdma                  wcdma-chat-connect     wcdma-chat-disconnect

用microcom,查看我们的卡是否装好以及是否有信号(ttyUSB2是AT命令接口)。

~ >:microcom -s 115200 /dev/ttyUSB2

常用AT命令

A       重复上次命令

ATE0    关闭回显

ATE1    开启回显

AT+CGMM     可查看模块名

AT+CGMR     可查看模块版本信息

AT+CGMI     可查看模块制造商

AT+CSQ      可查看信号强度

AT+CPIN?    查看SIM卡是否到位

AT+CREG?    查看SIM卡是否注册上,网络注册的情况。(注册上后才可以拨号)

AT+COPS?    查看SIM卡运营商

/etc/ppp/peers >: pppd call wcdma&  //拨号上网,出现如下信息说明拨号连接成功

/etc/ppp/peers >: abort on (NO CARRIER)
abort on (ERROR)
abort on (NO DIALTONE)
abort on (BUSY)
abort on (NO ANSWER)
send (^MAT^M)
expect (OK)
AT^M^M
OK
 -- got it

send (^MATZ^M)
expect (OK)
^M
ATZ^M^M
OK
 -- got it

send (^MAT+CGDCONT=1,"IP","3gnet",,0,0^M)
expect (OK)
^M
AT+CGDCONT=1,"IP","3gnet",,0,0^M^M
OK
 -- got it

send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
CONNECT
 -- got it

send (\d)
Script /bin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect finished (pid 1041), status = 0x0
Serial connection established.
using channel 2
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB3
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x6cc2e313> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x2 <asyncmap 0x0> <auth chap MD5> <magic 0x2fb4793> <pcomp> <accomp>]
sent [LCP ConfAck id=0x2 <asyncmap 0x0> <auth chap MD5> <magic 0x2fb4793> <pcomp> <accomp>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x6cc2e313> <pcomp> <accomp>]
rcvd [LCP DiscReq id=0x3 magic=0x2fb4793]
rcvd [CHAP Challenge id=0x1 <aca2066a9400a2d92c64d41a7692fc6d>, name = "UMTS_CHAP_SRVR"]
sent [CHAP Response id=0x1 <68be2548b69885fd8d514b893d366581>, name = "wyj"]
rcvd [CHAP Success id=0x1 ""]
CHAP authentication succeeded
CHAP authentication succeeded
sent [IPCP ConfReq id=0x1 <compress VJ 0f 00> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [proto=0x3] 01 00 04
Unsupported protocol 0x3 received
sent [LCP ProtRej id=0x2 00 03 01 00 04]
sent [IPCP ConfReq id=0x1 <compress VJ 0f 00> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfReq id=0x2]
sent [IPCP ConfNak id=0x2 <addr 0.0.0.0>]
rcvd [IPCP ConfRej id=0x1 <compress VJ 0f 00>]
sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfReq id=0x3]
sent [IPCP ConfAck id=0x3]
rcvd [IPCP ConfNak id=0x2 <addr 10.1.50.212> <ms-dns1 202.102.128.68> <ms-dns2 202.102.134.68>]
sent [IPCP ConfReq id=0x3 <addr 10.1.50.212> <ms-dns1 202.102.128.68> <ms-dns2 202.102.134.68>]
rcvd [IPCP ConfAck id=0x3 <addr 10.1.50.212> <ms-dns1 202.102.128.68> <ms-dns2 202.102.134.68>]
Could not determine remote IP address: defaulting to 10.64.64.64
local  IP address 10.1.50.212
remote IP address 10.64.64.64
primary   DNS address 202.102.128.68
secondary DNS address 202.102.134.68

/etc/ppp/peers >: cd

~ >: ifconfig   //查看网卡可以发现ppp0的网络接口

eth0      Link encap:Ethernet  HWaddr 0E:9E:AA:E2:43:97  

          inet addr:192.168.137.9  Bcast:192.168.137.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:121 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:26434 (25.8 KiB)  TX bytes:0 (0.0 B)

          Interrupt:51 Base address:0x6300

 

ppp0      Link encap:Point-to-Point Protocol  

          inet addr:10.1.50.212  P-t-P:10.64.64.64  Mask:255.255.255.255

          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  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:3

          RX bytes:65 (65.0 B)  TX bytes:114 (114.0 B)

ppp0网关是10.64.64.64

~ >: ping baidu.com

ping: bad address 'baidu.com'

~ >: vi /etc/resolv.conf    //配置DNS域名解析

nameserver 8.8.8.8

nameserver 114.114.114.114

~ >: mv /etc/resolv.conf /etc/resolv.conf.bak   

~ >: ln -s /etc/ppp/resolv.conf /etc/resolv.conf #建立一个软链接,链接到全局DNS

~ >: route add default gw 10.64.64.64    //添加默认网关

~ >: ping baidu.com  

PING baidu.com (123.125.114.144): 56 data bytes

64 bytes from 123.125.114.144: seq=0 ttl=51 time=160.000 ms

64 bytes from 123.125.114.144: seq=1 ttl=51 time=125.000 ms

64 bytes from 123.125.114.144: seq=2 ttl=51 time=200.000 ms

64 bytes from 123.125.114.144: seq=3 ttl=51 time=195.000 ms

 

参考:https://blog.csdn.net/qicheng777/article/details/73554639

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值