2410 pppd 拨号上网

来源:互联网 发布:数据存储过程 编辑:程序博客网 时间:2024/05/16 15:19
____________________________________
|                                                              |
|  开发板                   s3c2410                 |
|  开发主机          VMware ubuntu10.10    |
|  移植内核             linux-2.6.22.6            |
|   3G模块                 中兴 MG3732   |
|    SIM卡                      联通3G         | 
|    pppd                       ppp-2.4.4               |
|____________________________________|




内核配置:
  -> Device Drivers                                                             
  x       -> USB support                                                              
  x         -> USB Serial Converter support                                           
  x           -> USB Serial Converter support (USB_SERIAL [=y])   
  
  -> Device Drivers                                                             
  x       -> Network device support                                       
  x         -> Network device support (NETDEVICES [=y])   
              <*>   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                                       
<*>     PPP MPPE compression (encryption) (EXPERIMENTAL)                   
<*>     PPP over Ethernet (EXPERIMENTAL)  

PS:该配置仅为支持pppd拨号上网的配置,开发板其他驱动另需配置


让内核识别MG3732:(不同3G模块添加的数据不一样,具体咨询模块公司,当是方法是一致的)


在/driver/usb/serial/ 下的option.c
添加pid,vid 如下:

{ USB_DEVICE(0x19d2, 0xffff) },
{ USB_DEVICE(0x19d2, 0xfffe) },
{ USB_DEVICE(0x19d2, 0xfffd) },
{ USB_DEVICE(0x19d2, 0xfffc) },
{ USB_DEVICE(0x19d2, 0xfffb) }, 
{ USB_DEVICE(0x19d2, 0xfff1) },
{ USB_DEVICE(0x19d2, 0xfff6) },
{ USB_DEVICE(0x19d2, 0xfff7) },
{ USB_DEVICE(0x19d2, 0xfff8) },
{ USB_DEVICE(0x19d2, 0xfff9) },
{ USB_DEVICE(0x19d2, 0xffee) },
{ USB_DEVICE(0x19d2, 0xffed) },
{ USB_DEVICE(0x19d2, 0xffeb) },
{ USB_DEVICE(0x19d2, 0xffec) },

当驱动加载成功后,且插入3G模块,在/dev/目录下可以看到几个ttyUSB0,ttyUSB1等的字符设备文件.







pppd:
下载地址:http://www.linuxfromscratch.org/blfs/view/6.3/basicnet/ppp.html
解压  ppp-2.4.4.tar.gz
执行脚本产生Makefile等文件:./configure
用开发板的交叉编译工具链编译: make CC=arm-linux-gnu-gcc             (工具链需要在/etc/bin目录下存在)
将ppp-2.4.4/chat/chat      ppp-2.4.4/pppd/pppd  复制到开发板文件系统/usr/sbin




脚本:
在开发板文件系统里建立/etc/ppp/peers文件夹,下面所创建出的脚本都存放在该路径
创建拨号选项脚本: vi  wcdma
 1 noauth
 2 debug
 3 connect '/usr/sbin/chat -v -f /etc/ppp/peers/wcdma-chat-connect'
 4 /dev/ttyUSB3
 5 115200
 6 defaultroute
 7 noipdefault
 8 novj
 9 novjccomp
10 noccp
11 ipcp-accept-local
12 ipcp-accept-remote
13 local
14 lock
15 dump
16 nodetach
17 nocrtscts
18 #usepeerdns

参数说明:
ttyS0 ---- 指定连接使用的设备,例如:ttyS0、ttyS1等
57600 ---- 设置连接使用的控制字符传输速率,可以设置为57600、115200等
debug ---- 如果需要加入调试信息,就加入参数debug
logfile /var/ ppplog ---- 将连接过程中的信息输入到某个文件中
mtu 1500
-detach
noipdefault ---- 不使用默认IP就可以加入参数noipdefault
defaultroute
usepeerdns ---- 使用服务器端协商的DNS就可以设置参数usepeerdns
lcp-echo-failure 4 ---- 当连续4次没有收到发出的LCP回声请求时,就认为服务器端已不再响应,就退出执行。这里的失败次数可以灵活来决定。
-ccp ---- 不使用压缩控制协议
-vj ---- 关掉式IP头压缩
-chap ---- 不使用chap鉴权
-mschap-v2 ---- 不使用mschap鉴权
user
hide-password
connect "/usr/bin/chat -v -t6 -f /var/ chat" ---- 制定了要使用的chat脚本的位置。加上参数-v 告诉 chat命令将其所有的输出/入拷贝到系统记录里(通常是 /var/log/messages)。-t 6 指定了执行chat该命令的时间为6s。chat脚本的位置可以位于/etc/目录下,也可以位于/var下,这个可以更加需要灵活设置。
persist --- 永久链接(自动重拨)
crtscts --- 告诉ppp使用modem的硬件流量控制
modem --- 使ppp使用DCD信号来判断连接是否正常,有无掉线现象
deflate --- 使pppd使用defalte压缩方式
idle --- 设置了一个时间限制,当在300秒的时间内没有数据传送,就断开连接
lock --- 则创建一个锁定文件,其他程序在发现存在这个文件后,就能得知相应的串口已经被使用。
demond --- 参数告诉pppd停留在后台,监视网络数据,一旦有要求就立即进行连网,超时后就断开连接,但pppd仍然停留在后台等待下次数据传送
其他的参数具体含义可以参照参考PPPD2.4.4 中options.c中注释:


拨号脚本:wcdma-chat-connect 
 1 ABORT "BUSY"
 2 ABORT "NO CARRIER"
 3 ABORT "NO DIALTONE"
 4 ABORT "ERROR"
 5 ABORT "NO ANSWER"
 6 TIMEOUT 50
 7 SAY "start dialling...\n"
 8 "" AT
 9 SAY "need OK1111"
10 OK ATZ
11 SAY "set APN to wcdma"
12 OK "AT+CGDCONT=1,\"IP\",\"3gnet\""
13 SAY "dailing *99#"
14 OK ATDT*99#
15 CONNECT
 
几个ABORT行的意思是如果modem返回诸如BUSY之类的信息,则取消chat过程,连接失败;
TIMEOUT 50表示连接的超时值为50秒。
首先发出一个at命令,期待modem返回一个OK,然后拨号*99#,期待modem返回CONNECT,如果modem返回了CONNECT,则表明连接建立成功。
 
 
断开脚本:wcdma-chat-disconnect 
 1 BORT "ERROR"
 2 ABORT "NO DIALTONE"
 3 SAY "\nSending break to the modem\n"
 4 ""\k"
 5 "" +++ATH"
 6 SAY "\nGood bey!\n"


 
 
测试:
启动开发板,进入文件系统,插上3G模块(MG3732 )
提示:
option 1-1:1.0: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
option 1-1:1.1: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
option 1-1:1.2: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2
option 1-1:1.3: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB3
  scsi 0:0:0:0: Direct-Access     ZTE      USB Storage FFEB 2.31 PQ: 0 ANSI: 2
sd 0:0:0:0: [sda] Attached SCSI removable disk
sd 0:0:0:0: Attached scsi generic sg0 type 0

说明内核已经识别出3G模块出来了


调用脚本拨号:(脚本调用失败有可能是板子重启,3G模块里面的数据还存在有冲突导致失败)
# pppd call wcdma &
# pppd options in effect:
debug           # (from /etc/ppp/peers/wcdma)
nodetach                # (from /etc/ppp/peers/wcdma)
dump            # (from /etc/ppp/peers/wcdma)
noauth          # (from /etc/ppp/peers/wcdma)
/dev/ttyUSB3            # (from /etc/ppp/peers/wcdma)
115200          # (from /etc/ppp/peers/wcdma)
lock            # (from /etc/ppp/peers/wcdma)
connect /usr/sbin/chat -v -f /etc/ppp/peers/wcdma-chat-connect          # (from  /etc/ppp/peers/wcdma)
nocrtscts               # (from /etc/ppp/peers/wcdma)
local           # (from /etc/ppp/peers/wcdma)
novj            # (from /etc/ppp/peers/wcdma)
novjccomp               # (from /etc/ppp/peers/wcdma)
ipcp-accept-local               # (from /etc/ppp/peers/wcdma)
ipcp-accept-remote              # (from /etc/ppp/peers/wcdma)
noipdefault             # (from /etc/ppp/peers/wcdma)
defaultroute            # (from /etc/ppp/peers/wcdma)
noccp           # (from /etc/ppp/peers/wcdma)
Removed stale lock on ttyUSB3 (pid 815)
start dialling...
Serial connection established.
using channel 1
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB3
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xbc0c6609> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x0 <asyncmap 0x0> <auth chap MD5> <magic 0xcd571e> <pcomp>                                                                                                  <accomp>]
No auth is possible
sent [LCP ConfRej id=0x0 <auth chap MD5>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xbc0c6609> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xcd571e> <pcomp> <accomp>]
sent [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xcd571e> <pcomp> <accomp>]
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0>]
rcvd [LCP DiscReq id=0x2 magic=0xcd571e]
rcvd [IPCP ConfNak id=0x1 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 1                                                                                                 0.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x2 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x2 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 1                                                                                                 0.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x3 <addr 0.0.0.0>]
rcvd [IPCP ConfReq id=0x0]
sent [IPCP ConfNak id=0x0 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x3 <addr 172.28.249.208>]
sent [IPCP ConfReq id=0x4 <addr 172.28.249.208>]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfAck id=0x1]
rcvd [IPCP ConfAck id=0x4 <addr 172.28.249.208>]
Could not determine remote IP address: defaulting to 10.64.64.64
local  IP address 172.28.249.208
remote IP address 10.64.64.64


# ifconfig
eth0      Link encap:Ethernet  HWaddr 03:80:20:51:7A:27
         inet addr:192.168.7.227  Bcast:192.168.7.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:4801 errors:33 dropped:33 overruns:0 frame:0
         TX packets:3310 errors:0 dropped:0 overruns:0 carrier:0
         collisions:871 txqueuelen:1000
         RX bytes:3553248 (3.3 MiB)  TX bytes:575718 (562.2 KiB)
         Interrupt:53 Base address:0x300

lo        Link encap:Local Loopback
         inet addr:127.0.0.1  Mask:255.0.0.0
         UP LOOPBACK RUNNING  MTU:16436  Metric:1
         RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ppp0      Link encap:Point-to-Point Protocol
         inet addr:172.28.249.208  P-t-P:10.64.64.64  Mask:255.255.255.255
         UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
         RX packets:7 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:112 (112.0 B)  TX bytes:54 (54.0 B)

说明拨号成功,现在可以ping一下外网IP 测试
      #ping  210.21.196.6 -I ppp0   (需要指明数据出口网卡,不然默认从eth0出去)
   
PING 210.21.196.6: 56 data bytes
64 bytes from 61.135.169.105: seq=0 ttl=49 time=186.064 ms
64 bytes from 61.135.169.105: seq=1 ttl=49 time=181.484 ms
64 bytes from 61.135.169.105: seq=2 ttl=49 time=226.594 ms
64 bytes from 61.135.169.105: seq=3 ttl=49 time=221.544 ms
64 bytes from 61.135.169.105: seq=4 ttl=49 time=216.590 ms
64 bytes from 61.135.169.105: seq=5 ttl=49 time=211.548 ms
64 bytes from 61.135.169.105: seq=6 ttl=49 time=196.596 ms
64 bytes from 61.135.169.105: seq=7 ttl=49 time=211.552 ms

--- 210.21.196.6 statistics ---
9 packets transmitted, 8 packets received, 11% packet loss
round-trip min/avg/max = 181.484/206.496/226.594 ms

如果需要ping域名 需要将拨号时产生的DNS服务器地址配置从/etc/ppp/resolv.conf 复制到 /etc/resolv.conf        (也可以设置链接)       
PS:此处有可能ping不通,请看文章最后补充
# ping www.baidu.com -I ppp0
PING www.baidu.com (61.135.169.105): 56 data bytes
64 bytes from 61.135.169.105: seq=0 ttl=49 time=215.605 ms
64 bytes from 61.135.169.105: seq=1 ttl=49 time=211.516 ms
64 bytes from 61.135.169.105: seq=2 ttl=49 time=206.564 ms
64 bytes from 61.135.169.105: seq=3 ttl=49 time=201.582 ms
64 bytes from 61.135.169.105: seq=4 ttl=49 time=196.565 ms
64 bytes from 61.135.169.105: seq=5 ttl=49 time=191.646 ms
64 bytes from 61.135.169.105: seq=6 ttl=49 time=186.563 ms
64 bytes from 61.135.169.105: seq=7 ttl=49 time=181.583 ms
64 bytes from 61.135.169.105: seq=8 ttl=49 time=216.562 ms
64 bytes from 61.135.169.105: seq=9 ttl=49 time=211.581 ms
64 bytes from 61.135.169.105: seq=10 ttl=49 time=206.619 ms
64 bytes from 61.135.169.105: seq=11 ttl=49 time=201.596 ms
64 bytes from 61.135.169.105: seq=12 ttl=49 time=196.577 ms
64 bytes from 61.135.169.105: seq=13 ttl=49 time=191.584 ms
64 bytes from 61.135.169.105: seq=14 ttl=49 time=186.579 ms
64 bytes from 61.135.169.105: seq=15 ttl=49 time=221.644 ms
64 bytes from 61.135.169.105: seq=16 ttl=49 time=216.577 ms
64 bytes from 61.135.169.105: seq=17 ttl=49 time=211.585 ms
64 bytes from 61.135.169.105: seq=18 ttl=49 time=206.576 ms

--- www.baidu.com ping statistics ---
19 packets transmitted, 19 packets received, 0% packet loss
round-trip min/avg/max = 181.583/203.110/221.644 ms


当域名测试成功,可以通过telnet登录bbs.newsmth.net测试
    #telnet bbs.newsmth.net






补充:
当域名ping不通时,可能是默认的网关指向eth0的网关
虽然ping时指定了数据包的出口-I ppp0 但是使用的路由表却是eth0的路由表

(此为ping不通的情况)
# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.64.64.64     *               255.255.255.255 UH    0      0        0 ppp0
192.168.7.0     *               255.255.255.0   U     0      0        0 eth0
default         192.168.7.1     0.0.0.0         UG    0      0        0 eth0

(此为ping通时情况)
# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.64.64.64     *               255.255.255.255 UH    0      0        0 ppp0
192.168.7.0     *               255.255.255.0   U     0      0        0 eth0
default         *               0.0.0.0         U     0      0        0 ppp0

解决方法:
方法1.uboot启动参数时,不要指定默认网卡
成功参数:
setenv bootargs console=ttySAC0,115200 init=/linuxrc ethaddr=03:80:20:51:7a:27 root=/dev/nfs rw nfsroot=192.168.7.127:/opt/filesystem ip=192.168.7.227:192.168.7.127


   方法2.
     设置默认网关
     
    
 
原创粉丝点击