日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

3G模块SIM5360E拨号上网

發(fā)布時(shí)間:2023/12/16 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 3G模块SIM5360E拨号上网 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

首先需要添加usb驅(qū)動(dòng),這就不介紹了,添加usb驅(qū)動(dòng)參考:

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

在Linux內(nèi)核2.6.20之后就有一個(gè)通用的名叫usbserial的驅(qū)動(dòng)能夠支持SIMCom的設(shè)備使用

一、修改內(nèi)核

修改一:添加廠商id和產(chǎn)品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[]結(jié)構(gòu)體里

/* ?????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 ??*/

修改二:添加重啟恢復(fù)

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)函數(shù)最后

????????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 */

????????}

修改四:添加短報(bào)文包標(biāo)識(shí)

[wuyujun@wuyujunlocalhost serial]$?vim usb_wwan.c

static void usb_wwan_setup_urbs(struct usb_serial *serial)函數(shù)里

/* 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

????????????????}

二、配置內(nèi)核

添加USB轉(zhuǎn)串口支持 ??

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

添加內(nèi)核對PPP撥號(hào)支持

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

配置完后重新編譯內(nèi)核并燒錄內(nèi)核

啟動(dòng)好系統(tǒng)之后插上sim5360e模塊會(huì)出現(xiàn)如下信息:

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如果出現(xiàn)上述現(xiàn)象說明內(nèi)核使能成功

用ls命令可以看到/devttyUSB0,ttyUSB1,ttyUSB2,ttyUSB3,ttyUSB4五個(gè)設(shè)備在/dev目錄下被創(chuàng)建,五個(gè)設(shè)備分別為五個(gè)不同功能模塊,ttyUSB2作為AT命令的接口.

三大運(yùn)營商2G/3G/4G頻率分配和網(wǎng)絡(luò)制式

所以sim5360最好使用聯(lián)通卡進(jìn)行撥號(hào)上網(wǎng)

三、移植撥號(hào)工具pppd和chat

進(jìn)行撥號(hào)上網(wǎng)還需要用ppp上網(wǎng)需要兩個(gè)程序:pppd和chat 。這兩個(gè)程序有開源代碼,只需要根據(jù)自己的情況修改移植到開發(fā)板就可以了

[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?//根據(jù)自己的情況添加交叉編譯器

INSTALL= install

[wuyujun@wuyujunlocalhost chat]$?cd ../pppd????//切換到pppd目錄下

[wuyujun@wuyujunlocalhost pppd]$ vim Makefile

CC =/opt/xtools/arm920t/bin/arm-linux-gcc?//根據(jù)自己的情況添加交叉編譯器

[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可執(zhí)行文件

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開發(fā)板可執(zhí)行文件,將其傳到開發(fā)板的/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 ??//在開發(fā)板的/etc目錄新建/ppp/peers目錄并在peers目錄下創(chuàng)建如下配置文件

/etc >:?cd ppp/peers/ ?????????

/etc/ppp/peers >:?vi wcdma ???//編寫配置文件,給pppd進(jìn)程提供配置參數(shù)

#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 ??????????#設(shè)置波特率

user "wyj" ???????#如果需要chap或pap認(rèn)證,則輸入該用戶名和密碼 ????????????????????????????????????

password "wuyujun" ?

# set flowrate

crtscts ???????????????

show-password

usepeerdns

noauth ????????????#不設(shè)置認(rèn)證

noipdefault ????????#禁用默認(rèn)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根據(jù)你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 ??#發(fā)送AT命令

OK \rATZ ??#等待接收OK,接收到OK發(fā)送ATZ命令

OK \rAT+CGDCONT=1,"IP","3gnet",,0,0 ?#接收到OK,發(fā)送AT+CGDCONT=1...命令

#下面一行是聯(lián)通的撥號(hào)設(shè)置,不同的運(yùn)營商撥號(hào)方式有所不同

OK-AT-OK ATDT*99#

CONNECT \d\c

運(yùn)營商(ISP

APN

撥號(hào)號(hào)碼

帳號(hào)

密碼

中國聯(lián)通WCDMA

China Unicom

3GNET

*99#

中國電信CDMA2000

China Telecom

EVDO網(wǎng)絡(luò)

#777

ctnet@mycdma.cn

vnet.mobi

1X網(wǎng)絡(luò)

#777

card (CARD)

cardCARD

中國移動(dòng)?TD-SCDMA

China Mobile

CMNET

*98*1#

中國移動(dòng)?GPRS

China Mobile

CMNET

*99***1#

?

/etc/ppp/peers >:?vi wcdma-chat-disconnect ??//出錯(cuò)處理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,查看我們的卡是否裝好以及是否有信號(hào)(ttyUSB2是AT命令接口)。

~ >:microcom -s 115200 /dev/ttyUSB2

常用AT命令

A???????重復(fù)上次命令

ATE0 ???關(guān)閉回顯

ATE1 ???開啟回顯

AT+CGMM?????可查看模塊名

AT+CGMR?????可查看模塊版本信息

AT+CGMI?????可查看模塊制造商

AT+CSQ??????可查看信號(hào)強(qiáng)度

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

AT+CREG? ???查看SIM卡是否注冊上,網(wǎng)絡(luò)注冊的情況。(注冊上后才可以撥號(hào))

AT+COPS? ???查看SIM卡運(yùn)營商

/etc/ppp/peers >:?pppd call wcdma& ?//撥號(hào)上網(wǎng),出現(xiàn)如下信息說明撥號(hào)連接成功

/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 itsend (^MATZ^M) expect (OK) ^M ATZ^M^M OK-- got itsend (^MAT+CGDCONT=1,"IP","3gnet",,0,0^M) expect (OK) ^M AT+CGDCONT=1,"IP","3gnet",,0,0^M^M OK-- got itsend (ATDT*99#^M) expect (CONNECT) ^M ATDT*99#^M^M CONNECT-- got itsend (\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???//查看網(wǎng)卡可以發(fā)現(xiàn)ppp0的網(wǎng)絡(luò)接口

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網(wǎng)關(guān)是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 #建立一個(gè)軟鏈接,鏈接到全局DNS

~ >: route add default gw 10.64.64.64 ???//添加默認(rèn)網(wǎng)關(guān)

~ >: 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

總結(jié)

以上是生活随笔為你收集整理的3G模块SIM5360E拨号上网的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。