busybox中需打開:wc,pidof;
busybox中shell下打開getopts
百度搜索“Serial connection established. using channel 1”包含大量問題解答
2013-12-22? ? ? 0個評論? ? ? ?
收藏 ? ?
我要投稿
一.ARM-Linux
ARM-Linux-2.6.17
3G USB Modem:huaweiE220(WCDMA),huaweiEC156(EVDO)
arm-linux至少需要支持usb host,usb storage,usbfs,usb serial
?
二.Linux驅動
option.c
linux中option.c就是針對3G modem的驅動,稍作修改即可支持大部分的3G usb modem
目前我的這個版本的USB Option PCMCIA serial driver依賴于USB_SERIAL && USB_OHCI_HCD && PCCARD,所以系統要保證已經選定了這三個選項,如果host不同,可以自行修改USB_OHCI_HCD這個依賴項,我的目前使用isp芯片所以就修改了這個依賴項,總而言之,usb host是必須需要的.
添加對華為e220和華為ec156的支持,在option_ids數組中添加子項:
1.? ? ? #define HUAWEI_PRODUCT_E220? ? ? ? ? ? ? ? ? ? 0x1003 ?
2.? ? ? #define HUAWEI_PRODUCT_EC156 ? ? ? ? ? ? ? ? ? 0x140c ?
1.? ? ? { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, ?
2.? ? ? { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_EC156)}, ?
?
三.工具
usb_switchmode-1.2.4
這是目前的最新版本,使用這個工具的目的是將默認被識別為存儲設備的3g usb modem轉換為可以通訊的多個串口設備,以用于ppp撥號連接.
此工具依賴于linusb的,全部交叉編譯之,.
? ? ? ? 1.下載并交叉編譯libusb-0.1.12:
./configure --build=i686-linux --host=arm-linux --prefix=$PWD/install
make
make -n install? (確定安裝目錄)
make install? ?
至此,libusb編譯完畢.
2.交叉編譯usb_switchmode
修改makefile:
cc=arm-linux-gcc
INCLUDEDIR =/home/jay/tools/3G/libusb-0.1.12/install/include
LIBDIR =/home/jay/tools/3G/libusb-0.1.12/install/lib
$(CC) -I $(INCLUDEDIR) -L $(LIBDIR) -o $(PROG) $(OBJS) $(CFLAGS) $(LIBS) $(LDFLAGS) -static
make
順利通過,至此得到靜態編譯的usb_switchmode
?
3.將usb_switchmode移到arm linux文件系統中,然后將usb_switchmode.conf文件夾復制進arm linux中的/etc/目錄下,這個文件夾下是很多3g usb modem的配置文件.
4.pppd撥號軟件
移植pppd2.4.5
./configure
make CC=arm-linux-gcc
需要的東西就是:pppd chat pppdump pppstats下可執行程序pppd, chat, pppdump, pppstats
在嵌入式文件系統下需要建立/etc/ppp/peers文件夾
?
四.使用
插入3g usb modem的時候會被默認識別為u盤,此時使用usb_switchmode工具轉換,就會綁定到多個串口上去,
usb_modeswitch -W -c /etc/usb_modeswitch.d/12d1_1505
其中-W僅僅是顯示詳細配置信息,-c是指指定配置文件,usb_switchmode自帶的配置文件貌似在嵌入式下使用都多多少少有點問題,隨后發現,必須要指定
DefaultVendor 和 DefaultProduct兩個參數.
usb 1-1: new full speed USB device using isp1362-hcd and address 8
usb 1-1: configuration #1 chosen from 1 choice
option 1-1:1.0: Option 3G data card converter detected
usb 1-1: Option 3G data card converter now attached to ttyUSB0
option 1-1:1.1: Option 3G data card converter detected
usb 1-1: Option 3G data card converter now attached to ttyUSB1
option 1-1:1.2: Option 3G data card converter detected
usb 1-1: Option 3G data card converter now attached to ttyUSB2
option 1-1:1.3: Option 3G data card converter detected
usb 1-1: Option 3G data card converter now attached to ttyUSB3
scsi6 : SCSI emulation for USB Mass Storage devices
如果沒有ttyUSB0之類的設備節點,可以自己手動建立,
mknod /dev/ttyUSB0 c 188 0
mknod /dev/ttyUSB0 c 188 1
....
之后可以
echo ATZ>/dev/ttyUSB0,如果沒有錯誤,轉換基本ok.
?
最后就剩下ppp撥號
目前我使用的e220是wcdma制式,ec156是evdo制式,其撥號腳本少有不同(驅動僅僅是設備號碼有點點區別)
1.wcdma:
1.? ? ? debug ?
2.? ? ? nodetach ?
3.? ? ? lock ?
4.? ? ? /dev/ttyUSB0 ?
5.? ? ? 115200 ?
6.? ? ? user "14522023288" ?
7.? ? ? password "******" ?
8.? ? ? crtscts ?
9.? ? ? show-password ?
10. ? usepeerdns ?
11. ? noauth ?
12. ? noipdefault ?
13. ? novj ?
14. ? novjccomp ?
15. ? noccp ?
16. ? defaultroute ?
17. ? ipcp-accept-local ?
18. ? ipcp-accept-remote ?
19. ? connect '/usr/sbin/chat -s -v -f chat-wcdma-connect' ?
20. ? disconnect '/usr/sbin/chat -s -v -f chat-wcdma-disconnect' ?
chat-wcdma-connect:
1.? ? ? TIMEOUT 5 ?
2.? ? ? ABORT 'NO CARRIER' ?
3.? ? ? ABORT 'ERROR' ?
4.? ? ? ABORT 'NO DIALTONE' ?
5.? ? ? ABORT 'BUSY' ?
6.? ? ? ABORT 'NO ANSWER' ?
7.? ? ? '' /rAT ?
8.? ? ? OK /rATZ ?
9.? ? ? OK /rAT+CGDCONT=1,"IP","3gnet",,0,0 ?
10. ? OK-AT-OK ATDT*99# ?
11. ? CONNECT /d/c ?
chat-wcdma-disconnect:
[html] view plaincopy
1.? ? ? ABORT "BUSY" ?
2.? ? ? ABORT "ERROR" ?
3.? ? ? ABORT "NO DIALTONE" ?
4.? ? ? SAY "/nSending break to the modem/n" ?
5.? ? ? '' "/K" ?
6.? ? ? '' "+++ATH" ?
7.? ? ? SAY "/nGoodbay/n" ?
2.evdo
1.? ? ? debug ?
2.? ? ? nodetach ?
3.? ? ? lock ?
4.? ? ? /dev/ttyUSB0 ?
5.? ? ? 115200 ?
6.? ? ? user "ctnet@mycdma.cn" ?
7.? ? ? password "vnet.mobi" ?
8.? ? ? crtscts ?
9.? ? ? show-password ?
10. ? usepeerdns ?
11. ? noauth ?
12. ? noipdefault ?
13. ? novj ?
14. ? novjccomp ?
15. ? noccp ?
16. ? defaultroute ?
17. ? ipcp-accept-local ?
18. ? ipcp-accept-remote ?
19. ? connect '/usr/sbin/chat -s -v -f /etc/ppp/peers/chat-evdo-connect' ?
20. ? disconnect '/usr/sbin/chat -s -v -f /etc/ppp/peers/chat-evdo-disconnect' ?
chat-evdo-connect:
1.? ? ? TIMEOUT 60 ?
2.? ? ? ABORT 'NO CARRIER' ?
3.? ? ? ABORT 'ERROR' ?
4.? ? ? ABORT 'NO DIALTONE' ?
5.? ? ? ABORT 'BUSY' ?
6.? ? ? ABORT 'NO ANSWER' ?
7.? ? ? '' /rATZ ?
8.? ? ? OK-AT-OK ATD#777 ?
9.? ? ? CONNECT /d/c ?
chat-evdo-disconnect:
1.? ? ? ABORT 'NO CARRIER' ?
2.? ? ? ABORT 'ERROR' ?
3.? ? ? ABORT 'NO DIALTONE' ?
4.? ? ? ABORT 'BUSY' ?
5.? ? ? ABORT 'NO ANSWER' ?
6.? ? ? SAY "/nSending break to the modem/n" ?
7.? ? ? '' "/K" ?
8.? ? ? '' "+++ATH" ?
9.? ? ? SAY "/nGoodbay/n" ?
后臺撥號使用:
pppd call wcdma&
pppd call evdo&
電信的ecdo貌似賬號密碼必須使用ctnet@mycdma.cn vnet.mobi,不能使用電話號碼和給定的密碼.
如果撥號成功ifconfig可以看到ppp0
ppp0? ? ? Link encap:Point-to-Point Protocol ?
? ? ? ? ? inet addr:183.43.180.134? P-t-P:113.115.0.1? Mask:255.255.255.255
? ? ? ? ? UP POINTOPOINT RUNNING NOARP MULTICAST? MTU:1500? Metric:1
? ? ? ? ? RX packets:4 errors:0 dropped:0 overruns:0 frame:0
? ? ? ? ? TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
? ? ? ? ? collisions:0 txqueuelen:3?
? ? ? ? ? RX bytes:70 (70.0 B)? TX bytes:64 (64.0 B)
測試網絡:
# ping www.baidu.com
PING www.a.shifen.com (220.181.111.148): 56 data bytes
64 bytes from 220.181.111.148: icmp_seq=0 ttl=55 time=91.3 ms
64 bytes from 220.181.111.148: icmp_seq=1 ttl=55 time=105.3 ms
64 bytes from 220.181.111.148: icmp_seq=2 ttl=55 time=93.9 ms
64 bytes from 220.181.111.148: icmp_seq=3 ttl=55 time=98.9 ms
64 bytes from 220.181.111.148: icmp_seq=4 ttl=55 time=95.4 ms
ping的時候注意屏蔽掉eth0之類的其他網絡節點:ifconfig eth0 down
如果無法解析域名,多半應該是dns問題,本來ppp的dns是自動獲取的,但是它保存的路徑是/etc/ppp/resolv.conf,但是linux使用的卻是/etc/resolv.conf,所以我們建立一個軟連接即可:
ln -s /etc/ppp/resolv.conf /etc/resolv.conf
至此3G usb modem嵌入式下使用告一段落
斷開3G網卡,需要將ppp/script下的poff腳本拷貝到開發板/usr/sbin下,且修改為可執行的權限
斷開3G網卡:poff
DNS問題:拷貝/etc/ppp/resolv.conf?到/etc/resolv.conf
?atd NO CARRIER出錯?
? ? ? gsm/gprs模塊如果是語音撥號(打電話)格式是ATDT05923434343;<回車>,注意有分號。如果是數據分組撥號(CSD或者GPRS)格式是ATDT*99***1#<回車>,注意回車前沒有分號。注意一下。錯了肯定會報NO CARRIER,或者NO DIALTONE
這個是每個運行商的撥號中心號碼:
運營商名稱 ? ? ? 接入點 ? ? ? ? ? ? ? 用戶名密碼 ? ? ? 撥號號碼? ? ? ? ? ? ? ? ? ?備注? ?
中國移動? ? ? ? ? Cmnet cmwap? ? ? ? ?無? ? ? ? ? ? *99***1#? ? ? ? ? ? ? ? ? ? 2.5G2.75G(GPRS)? ?
? ? ? ? ? ? ? ? ? ? ? ? ? Cmnet cmwap? ? ? ? ? 無 ? ? ? ? ? ? *98*1# ? ? ? ? ? ? ? ? ? ? ? 3G(TD-SCDMA)? ?
中國聯通? ? ? ? ? ? 3gnet? ? ? ? ? ? ? ? ? ? ? ?無 ? ? ? ? ? ? *99#? ? ? ? ? ? ? ? ? ? ? ? ? ? 3G(WCDMA)? ?
中國電信 ? ? ? ? ? ? ?無 ? ? ? ? ? ? ? ? ? ? card? card ? ? ? #777 ? ? ? ? ? ? ? ? ? ? ? ? ? 2G? 3G? ?
運營商(ISP)APN 撥號號碼帳號密碼
中國聯通WCDMA(China Unicom)3GNET *99#空空
中國電信CDMA2000(China Telecom)EVDO網絡空#777 ctnet@mycdma.cnvnet.mobi
1X網絡空#777 card (CARD)card(CARD)
中國移動 TD-SCDMA(China Mobile)CMNET *98*1#空空
中國移動 GPRS(China Mobile)CMNET *99***1#空空
各種撥號腳本
A. 聯通WCDMA-HSDPA:
(1)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 chat-wcdma-connect'
disconnect '/usr/sbin/chat -s -v -f chat-wcdma-disconnect'
(2) chat-wcdma-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
(3) chat-wcdma-disconnect?
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n”
B. 移動TD-CDMA
(1)td:?
debug
logfile /var/log/pppd.log
lock
/dev/ttyUSB0
115200
user "card"
password "card"
crtscts
connect '/usr/sbin/chat -v -t3 -f td-connect-chat'
disconnect '/usr/sbin/chat -s -v -f td-disconnect-chat'
show-password
usepeerdns
noauth
noipdefault
novj
novjccomp
noccp
defaultroute
ipcp-accept-local
ipcp-accept-remote
(2) td-connect-chat:?
ABORT 'NO CARRIER'
ABORT 'ERROR'
ABORT 'NO DIALTONE'
ABORT 'BUSY'
ABORT 'NO ANSWER'
'' \rATZ
OK-AT-OK ATD#777
CONNECT \d\c
(3) td-disconnect-chat:?
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n"
C. 電信CDMA1x
(1) cdma1x:?
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 cdma1x-connect-chat'
disconnect '/usr/sbin/chat -s -v -f cdma1x-disconnect-chat'
(2) cdma1x-connect-chat:?
TIMEOUT 5
ABORT 'NO CARRIER'
ABORT 'ERROR'
ABORT 'NO DIALTONE'
ABORT 'BUSY'
ABORT 'NO ANSWER'
'' \rATZ
OK \rAT\^PREFMODE=2
OK-AT-OK ATD#777
CONNECT \d\c
(3) cdma1x-disconnect-chat:?
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n”
D. 電信CDMA2000-EVDO
(1) evdo:?
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 evdo-connect-chat'
disconnect '/usr/sbin/chat -s -v -f evdo-disconnect-chat'
(2)evdo-connect-chat:?
TIMEOUT 5
ABORT 'NO CARRIER'
ABORT 'ERROR'
ABORT 'NO DIALTONE'
ABORT 'BUSY'
ABORT 'NO ANSWER'
'' \rATZ
OK-AT-OK ATD#777
CONNECT \d\c
(3)evdo-disconnect-chat:?
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n"
HSPA
WCDMA的發展基本可以分為以下幾個不同的版本。首先是R99/R4版本,這個版本算是WCDMA的早期版本,現在我們通常也把這個版本叫做WCDMA,這個版本可以提供384Kbps的最高上傳速度和2Mbps的最高下載速度。后來WCDMA發展到了R5版本,這時提出了一個技術,就是HSDPA(高速下行分組數據接入技術),這個版本大幅度強化了R99/R4版本的最高下載速度,達到7.2Mbps或者14.4Mbps,我們現在就把這個版本的WCDMA叫做HSDPA。在接下來技術進一步進化,到了R6版本時,提出了HSUPA(高速上行分組數據接入技術),這個技術在保持R5版本的下行速度不變的情況下大幅度強化了HSDPA的最高上行速度,提升到5.76Mbps,我們現在就把R6版本的WCDMA叫做HSUPA,R5和R6版本統稱HSPA。技術總是進化的,到了R7版本時,HSPA+出現了,這個版本保持R...
HSPA英文全稱為HSPA High-Speed Packet Access。
WCDMA的R99和R4系統能夠提供的最高上下行速率分別為64kbps和384kbps,為了能夠與CDMA1XEV-DO抗衡,WCDMA在R5規范中引入了HSDPA,在R6規范中引入了HSUPA,HS-DPA和HSUPA合稱為HSPA。
HSDPA(高速下行分組接入)在下行鏈路上能夠實現高達14.4Mbit/s的速率。通過新的自適應調制與編碼以及將部分無線接口控制功能從無線網絡控制器轉移到基站中,實現了更高效的調度以及更快捷的重傳,HSDPA的性能得到了優化和提升。
HSUPA(高速上行分組接入)在上行鏈路中能夠實現高達5.76Mbit/s的速度。基站中更高效的上行鏈路調度以及更快捷的重傳控制成就了HSUPA的優越性能。
HSPA+(增強型高速分組接入)是HSPA的強化版本。HSPA+比HSPA的速度更快,性能更好,技術更先進,同時網絡也更穩定,是目前LTE技術運用之前的最快的網絡。
setsockopt綁定到特定interface
http://hi.baidu.com/lewutian/item/6b8a2c80db48e929110ef314
(轉)SOL_BINDTODEVICE
SOL_BINDTODEVICE是setsockopt設置中的一種套接口選項.當套接口被綁定到
指定的網絡設備接口之后,只有來自該設備的數據包才會被套接口處理。
在Linux下,對網絡設備的引用是通過struct ifreq來完成.通過設置struct
ifreq中的ifr_name[IFNAMSIZ]來指定網絡設備接口.舉例如下:
struct ifreq interface;
char *inf = "eth0";
strncpy(interface.ifr_name, inf, IFNAMSIZ);
這樣再通過設置:
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,(char *)&interface, sizeof(interface)) < 0)
{
? ? close(fd);
? ? return -1;
}
就綁定到了接口"eth0"上,所有數據報的收發都只經過這個接口.
對于SOL_BINDTODEVICE的總結如下:
(1)? ? ? ?對于TCP套接口、UDP套接口、RAW套接口,可以通過SO_BINDTODEVICE套接口選項將套接口綁定到指定的網絡接口上。綁定之后,套接口的所有數據包收發都只經過指定的網絡接口;
(2)? ? ? ?對于PF_PACKET類型的套接口,不能通過SO_BINDTODEVICE綁定到指定的網絡接口上,而要通過bind(2)來與特定的網絡接口綁定,所用的套接口地址結構為struct sockaddr_ll,此套接口地址結構是鏈路層的地址結構,獨立于具體的網絡設備。比如,該地址結構既可以用于表示PPP設備,也能用于表示ethernet設備。
(3)? ? ? ? SO_BINDTODEVICE套接口選項只適用于Linux系統。如果要編寫運行在多操作系統平臺上的程序,不能依賴SO_BINDTODEVICE來完成套接口與具體設備的綁定。
轉自:http://blog.chinaunix.net/u2/64516/showart_673646.html
另有一篇比較不錯,講述如何使用setsockopt()和getsockopt()及套接口選項
http://hi.baidu.com/goodluckyyc/blog/item/7d3f442d6436b2eb8b1399ba.html
setsockopt()和getsockopt()的選項名稱選項 意義 期望值 SO_BINDTODEVICE
可以使socket只在某個特殊的網絡接口(網卡)有效。
一個字符串給出設備的名稱,或者一個空字符串返回默認值 SO_BROADCAST允許廣播地址發送和接收信息包,只對UDP有效。布爾型整數 SO_DONTROUTE禁止通過路由器和網關往外發送信息包。可以防止數據離開本地網絡,起到安全保護的作用。布爾型整數 SO_KEEPALIVE可以使TCP通信的信息包保持連續性,在連接數很多,而且要持續連接時很有用,減少重新連接服務器的開銷。布爾型整數? SO_OOBINLINE可以把收到的不正常數據看成是正常的數據;也就是說,會通過一個標準的對recv()的調用來接收這些數據布爾型整數? SO_REUSEADDR當socket關閉后,本地端用于該socket的端口號立刻就可以被重用。這個可以減少TIME_WAIT的存在布爾型整數? SO_TYPE 重新得到socket類型(例如:SOCK_STREAM或 SOCK_DGRAM)。只用于getsockopt()整數
原文地址http://neupest.blog.163.com/blog/static/53714126200932331436280/
?
setsockopt()和getsockopt()的選項名稱
?
?
選項 意義 期望值?
SO_BINDTODEVICE 可以使socket只在某個特殊的網絡接口(網卡)有效。一個字符串給出設備的名稱,或者一個空字符串返回默認值?
SO_BROADCAST 允許廣播地址發送和接收信息包,只對UDP有效。布爾型整數?
SO_DONTROUTE 禁止通過路由器和網關往外發送信息包。可以防止數據離開本地網絡,起到安全保護的作用。布爾型整數?
SO_KEEPALIVE 可以使TCP通信的信息包保持連續性,在連接數很多,而且要持續連接時很有用,減少重新連接服務器的開銷。布爾型整數 ?
SO_OOBINLINE 可以把收到的不正常數據看成是正常的數據;也就是說,會通過一個標準的對recv()的調用來接收這些數據布爾型整數 ?
SO_REUSEADDR 當socket關閉后,本地端用于該socket的端口號立刻就可以被重用。這個可以減少TIME_WAIT的存在布爾型整數 ?
SO_TYPE 重新得到socket類型(例如:SOCK_STREAM或 SOCK_DGRAM)。只用于getsockopt()整數?
?
?多網卡發送數據包?
通常情況,非特殊程序聯網,不會指定使用有線還是無線網卡,更不會指定用哪個網卡。假如同時有兩塊網卡(筆記本就有無線有無線兩塊),在有線和無線都連上的情況下,使用哪個網線上網,是系統決定的,如果用戶自己沒對此時行特別設置的話,系統會默認使用有線的。如果你正在使用有圖形界面的Linux,在托盤的網絡圖標就可以設置,把無線網卡禁掉。如果非圖形界面,你要告訴大家你是用什么發行版的Linux,假設你兩個網卡都可以聯網了,那就試下在終端打入以下命令來禁無線網卡: ifconfig wlan0 down 如果執行完后,程序無法聯網,就說明你的有線網卡沒配置好,你要給大家提供更多的信息,比如可以打入: ifconfig -a把輸出粘上來給大家看。
分類: C/C++
方法一:
使用libnet,這里就不介紹了
方法二:
使用原始套接字
>>
>>指定網卡發送數據的時候不需要指定網卡IP,只要設置struct ifreg ifr.ifr_name就可以了。
>>例如:
>>? ? struct ifreq ifr;
>>? ? fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
>>? ? memset(&ifr, 0, sizeof (ifr));
>>? ? strncpy(ifr.ifr_name, "eth0", sizeof (ifr.ifr_name) -1);
>>? ? ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
>>? ? if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0 )
>>? ? {
>>? ? ? ? snprintf(err_buf, ERRBUF_SIZE,
>>? ? ? ? ? ? ? ? "SIOCGIFHWADDR: %s", strerror(errno));
>>? ? ? ? return -1;
>>? ? }
>>
方法三:bind的時候設置不同網卡的ip
這種情況適用于運行Server端操作,為套接字綁定不同的接口ip,可以接受不同網絡[不同ISP]的數據包
在雙線接入主機中,可以使用這種方法來編寫程序,來相應不同接口的數據包,而且反應快。
方法四:
in_addr interface;
interface.s_addr = inet_addr("192.168.0.100");
setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, reinterpret_cast<char*>(&interface), sizeof(interface))
方法五:
問題:一臺服務器有多張網卡,要讓數據包從指定的發出去,怎么實現,多謝!
假如linux服務器下有幾個網卡,且都屬于一個網段,通常數據從eth0,發出,那該如何指定一些特殊數據從eth1或eth2發送呢?
哪位知道的給個解決方案好不??
認為較好的答案:
假設:
有3個網卡 eth0 eth1 eth2
地址:192.168.0.1 192.168.0.2 192.168.0.3網關 192.168.0.254
ip route add default via 192.168.0.254 dev eth0 table 100 src 192.168.0.1
ip route add default via 192.168.0.254 dev eth1 table 200 src 192.168.0.2
ip route add default via 192.168.0.254 dev eth3 table 300 src 192.168.0.3
ip rule add from 192.168.0.1 table 100
ip rule add from 192.168.0.2 table 200
ip rule add from 192.168.0.3 table 300
這樣設置后,你訪問哪個地址,就會使用哪個網卡來發送數據
還有,多個網卡設置為同一段的IP不會引起任何麻煩,只是需要提醒的是設置IP的時候不能每個網卡都設置缺省網關,否則就會有麻煩了。?
windows 中有雙網卡,一個網卡的IP地址為192.168.180.1一個是192.168.170.1?
在沒有手工添加路由項的情況下,這時ping 發出的數據全部是從192.168.180.1這個網卡發出去。?
那么了為能夠讓192.168.170.1這個網卡也能夠往外ping那么必須指定一條路由?
route add 192.168.0.0 mask 255.255.255.0 192.168.170.254?
這樣192.168.170.1這個網卡就能夠往外ping了
cortex-A8上3G模塊的支持
作者:陳老師,華清遠見嵌入式學院講師。
|? 開發主機? ? ? ? ? VMware ubuntu10.10? ? |
? ? ? ? |? 移植內核 ? ? ? ? ? ? linux-2.6.22.6? ? ? ? ? ? |
? ? ? ? | ? 3G模塊 ? ? ? ? ? ? ? ?華為 E220 ? ? ? ? ? |
? ? ? ? |? ? SIM卡? ? ? ? ? ? ? ? ? ? ?聯通3G ? ? ? ? ? ? ? ? ? ? |
? ? ? ? |? ? pppd ? ? ? ? ? ? ? ? ? ? ? ppp-2.4.4 ? ? ? ? ?
? ? ? ? | ? ? ? ? |
? ? ? ? |____________________________________|
內核配置:
增加內核支持USB 轉Serial 驅動
-> Device Drivers ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? x ? ? ? -> USB support? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? x ? ? ? ? -> USB Serial Converter support ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? x ? ? ? ? ? -> USB Serial Converter support (USB_SERIAL [=y]) ?
?? ? ? ? ? ? ? ? ? ? ? ? ? [*]USB Generic Serial Driver
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <*>USB driver for GSM and CDMA modems
增加內核支持PPP協議驅動
? ? ? ? -> 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)
pppd:
下載地址:http://www.linuxfromscratch.org/blfs/view/6.3/basicnet/ppp.html
? ? ? ? 解壓? ppp-2.4.4.tar.gz
? ? ? ? 執行腳本產生Makefile等文件:./configure
若為android系統,則需要改變編譯方式,需要靜態編譯;(因為 android c庫使用的是Bionic庫,不與GNU C庫,ucLibc,或任何已知的Linux C庫相兼容,所以編譯時需要靜態編譯)
chat: ? chat.o
? ? ? ? ? ? ? ? $(CC) -o chat chat.o? -static
? ? ? ? chat.o: chat.c
? ? ? ? ? ? ? ? $(CC) -c $(CFLAGS) -o chat.o chat.c? -static
用開發板的交叉編譯工具鏈編譯: make CC=arm-unknown-linux-gnueabi-gcc
將ppp-2.4.4/chat/chat? ? ? ppp-2.4.4/pppd/pppd?復制到開發板文件系統/usr/sbin
在到開發板文件系統/var/ 下建立run目錄
開始編寫腳本:
在開發板文件系統里建立/etc/ppp/peers文件夾,下面所創建出的腳本都存放在該路徑
1、創建撥號選項腳本: vi? wcdma
1 noauth
?? ? ? ? 2 debug
?? ? ? ? 3 connect '/usr/sbin/chat -v -f /etc/ppp/peers/wcdma-chat-connect'
?? ? ? ? 4 /dev/ttyUSB0
?? ? ? ? 5 115200?
?? ? ? ? 6 defaultroute
?? ? ? ? 7 noipdefault
?? ? ? ? 8 novj
?? ? ? ? 9 novjccomp
? ? ? ? 10 noccp
? ? ? ? 11 ipcp-accept-local
? ? ? ? 12 ipcp-accept-remote
? ? ? ? 13 local
? ? ? ? 15 dump
? ? ? ? 16 nodetach
? ? ? ? 17 nocrtscts
? ? ? ? 18 #usepeerdns ? ?
2、創建腳本: vi wcdma-chat-connect
1 "" AT
? ? ? ? 2 OK ATDT? *99#?
? ? ? ? 3 CONNECT
測試:
啟動開發板,進入文件系統,插上3G模塊(MG3732)
提示:
usb 1-1: new full speed USB device using s3c2410-ohci and address 4
? ? ? ? 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
? ? ? ? libusual: modprobe for usb-storage succeeded, but module is not present
我們使用的是ttyUSB0,雖然有module is not present,但是不影響ping;
調用腳本撥號:
? ? ? ? # pppd call wcdma &?
終端會出現:
?? ? ? [root@wuqing/]#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/ttyUSB0? ? ? ? ? ? # (from /etc/ppp/peers/wcdma)
115200? ? ? ? ? # (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)
Serial connection established.
using channel 3
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB0
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x9793836> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x0 <asyncmap 0x0> <auth chap MD5> <magic 0xcd7ea3> <pcomp>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <accomp>]
No auth is possible
sent [LCP ConfRej id=0x0 <auth chap MD5>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x9793836> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xcd7ea3> <pcomp> <accomp>]
sent [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xcd7ea3> <pcomp> <accomp>]
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0>]
rcvd [LCP DiscReq id=0x2 magic=0xcd7ea3]
rcvd [IPCP ConfNak id=0x1 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.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 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x3 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x3 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x4 <addr 0.0.0.0>]
rcvd [IPCP ConfReq id=0x0]
sent [IPCP ConfNak id=0x0 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x4 <addr 172.17.15.110>]
sent [IPCP ConfReq id=0x5 <addr 172.17.15.110>]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfAck id=0x1]
rcvd [IPCP ConfAck id=0x5 <addr 172.17.15.110>]
Could not determine remote IP address: defaulting to 10.64.64.64
local? IP address 172.17.15.110
remote IP address 10.64.64.64
此時用ifconfig命令,會看到ppp0:?
?? ? ? # ifconfig
eth0? ? ? Link encap:Ethernet? HWaddr 00:00:3E:26:0A:00
? ? ? ? ? inet addr:192.168.1.3? Bcast:192.168.1.255? Mask:255.255.255.0
? ? ? ? ? UP BROADCAST RUNNING MULTICAST? MTU:1500? Metric:1
? ? ? ? ? RX packets:3402 errors:53 dropped:53 overruns:0 frame:0
? ? ? ? ? TX packets:1742 errors:0 dropped:0 overruns:0 carrier:0
? ? ? ? ? collisions:1498 txqueuelen:1000
? ? ? ? ? RX bytes:4058678 (3.8 MiB)? TX bytes:663372 (647.8 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.17.15.110? P-t-P:10.64.64.64? Mask:255.255.255.255
? ? ? ? ? UP POINTOPOINT RUNNING NOARP MULTICAST? MTU:1500? Metric:1
? ? ? ? ? RX packets:8 errors:0 dropped:0 overruns:0 frame:0
? ? ? ? ? TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
? ? ? ? ? collisions:0 txqueuelen:3
? ? ? ? ? RX bytes:168 (168.0 B)? TX bytes:104 (104.0 B)
看到ppp0 說明撥號成功,現在可以ping一下外網IP測試
#ping 220.181.111.147 -I ppp0 ? (需要指明數據出口網卡,有可能默認從eth0出去)
PING www.baidu.com (220.181.111.147): 56 data bytes
64 bytes from 220.181.111.147: seq=0 ttl=49 time=397.414 ms
64 bytes from 220.181.111.147: seq=1 ttl=49 time=345.459 ms
64 bytes from 220.181.111.147: seq=2 ttl=49 time=340.552 ms
64 bytes from 220.181.111.147: seq=3 ttl=49 time=355.576 ms
64 bytes from 220.181.111.147: seq=4 ttl=49 time=330.651 ms
64 bytes from 220.181.111.147: seq=5 ttl=49 time=355.569 ms
64 bytes from 220.181.111.147: seq=6 ttl=49 time=330.554 ms
64 bytes from 220.181.111.147: seq=7 ttl=49 time=335.571 ms
64 bytes from 220.181.111.147: seq=8 ttl=49 time=360.553 ms
補充:
當域名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
補充2:
嵌入式Linux操作系統下,如果要進行PPP連接,就需要配置撥號要使用的連接腳本。這些腳本參數就決定了PPPD的行為,會對PPP連接產生很大的影響。和PPP連接關系密切的有兩個腳本是wcdma-chat-connect'和wcdma兩個腳本。其中,wcdma-chat-connect腳本是用來進行AT呼叫和控制的腳本,而wcdma腳本就影響PPP連接的。
1.? wcdma-chat-connect腳本
一個簡單的wcdma-chat-connect腳本有下面的結構:
""? ? ? ? ? ? ? AT
? ? ? ? OK ? ? ? ? ? ? ATDT? dialnumber
? ? ? ? CONNECT? ? ? ""
一個wcdma-chat-connect腳本都是由字符串對來組成的。前面的字符串都是期望獲取的串,緊跟的是發送的字符串。這個腳本每一項的具體含義是這樣的:
1) ? MODEM期望空字符串。這句話的意思直接理解就是MODEM不管收到什么字符串,先發出字符串AT;
? ? ? ? 2) ? 期望收到“OK”字符串,然后發送字符串“ATDT dialnumber”
? ? ? ? 3) ? 如果收到“CONNECT”,就不再發送,認為數據鏈路已建立連接。
這樣的wcdma-chat-connect腳本是最簡單的,如果需要進行超時控制,就可以加入如下字段:
TIMEOUT 10
如果要增加對特殊情況的處理,就加入下面字段:
? ? ? ? ABORT ? ? ? ? ? BUSY? ? ? ? ?
? ? ? ? ABORT ? ? ? ? ? NO ANSWER
? ? ? ? ABORT ? ? ? ? ? RINGING
這三行語句的意思是:如果收到字符串“BUSY”、“NO ANSWER”、“RINGING”就退出執行。
所以在考慮到各種特殊情況下,配置一個PPP連接的wcdma-chat-connect腳本就可以像下面這樣:
TIMEOUT ? ? ? ? 30
? ? ? ? ABORT ? ? ? ? ? BUSY? ? ? ? ?
? ? ? ? ? ? ? ? ABORT ? ? ? ? ? NO ANSWER
? ? ? ? ? ? ? ? ABORT ? ? ? ? ? RINGING
? ? ? ? "" ? ? ? ? ? ? ? ? AT
? ? ? ? OK? ? ? ? ? ? ? ? ATDT dialnumber
? ? ? ? CONNECT ? ? ? ? ""
2. wcdma腳本
OPTIONS腳本的內容,為PPP連接指定了連接使用的設備、使用的控制字符傳輸速率、指定了硬件加速、溢出控制等。
例如下面的wcdma腳本:
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文件中注釋。
?linux pppd GRPS 配置若干問題 2012-09-05 16:18:13
分類: 嵌入式
本人使用的TD的模塊是LC63**,在上個月的這幾天剛拿到板子,折騰了將近一個月,這個板子打電話,上網都沒有問題了。
?
首先還是有必要介紹一下ppp協議了,是TD上網的基礎:
PPP是點對點的連接協議。這種連接建立之后,將給兩點分別分配IP地址,使用這個IP可以進行兩點之間的通訊。互聯網最初的“撥號上網”方式說的就是它。因為現在最流行的互聯網連接方式是Ethernet,所以PPP大都被很多人遺忘。還有就是PPP出來一個“變種”,被叫做PPPoE,也就是 PPP on Ethernet,這又增加了一個PPP被遺忘的理由.
?
先說說PPP連接互聯網的一種比較常見的方式。
PC—-Modem—-PPP—–RemoteHost—-Internet
PC可以通過某種方式連接到調制解調器,調制解調器負責將數字信號轉換成電信號(這個說法有點模糊,可能是音頻或者脈沖),用一組“AT”命令與遠程的一臺主機通訊,這臺主機是接入互聯網的,主要負責將你的PC發過來包再次轉發。下行流程于上面說的這個過程正好相反。從這個過程來看,PC的配置主要問題集中在:
? ? * 如何配置調制解調器Modem? ? ? -------------pppd
? ? * 如何配置那一組AT命令通訊腳本 -----------chat
正好這兩個問題在Linux中有兩個簡單的工具一一對應,調制解調器的配置可以用過pppd完成,而AT命令的通訊腳本可以交給chat。
現在常見的Linux系統中都自帶了pppd的模塊,如果沒有可以自己下載來手動編譯,然后將生成的可以執行文件(pppd,chat等)放到/usr/sbin/文件夾下即可。
下面就配置系統的pppd吧:
安裝完pppd后生成/etc/ppp/目錄,修改/etc/ppp/peers/cmnet文件(若沒有該文件,可手動建立,文件名不一定為cmnet):
/dev/ttyUSB1
115200
modem
nocrtscts
nocdtrcts
local
debug
nodetach
#nobsdcomp
#nodeflate
#novj
usepeerdns
defaultroute
noipdefault
ipcp-accept-local
ipcp-accept-remote
lock
connect '/usr/sbin/chat -s -v -f /etc/ppp/chat/cmtc-isp'
這些命令如果不明白的,可一到網上搜,很容易找到,就不再說明:
修改/etc/ppp/chat/cmtc-isp文件(本人的系統中沒有該chat目錄,則手動建立,建立cmtc-isp):
ABORT? ? 'BUSY'
ABORT? ? 'NO CARRIER'
ABORT? ? 'ERROR'
ABORT? ? '+CME ERROR:100'
"" ? ? AT
OK ? ? AT+CGDCONT=1,"IP","CMNET",,0,0
OK ? AT+CGEQREQ=1,2,128,2048,0,0,0,0,"0E0","0E0",,0,0
OK ? AT
OK ? AT
OK ? ATS0=0
OK ? AT
OK ? AT
OK ? ATD*98*1#
CONNECT
這個文件中都是一些AT指令,網上也比較多,不再說明。
?
運行 pppd call cmnet 即可啟動pppd腳本程序,如不出意外,會返回以下一些內容
?
abort on (BUSY)
abort on (NO CARRIER)
abort on (ERROR)
abort on (+CME ERROR:100)
send (AT^M)
expect (OK)
^M
OK
?-- got it
send (AT+CGDCONT=1,"IP","CMNET",,0,0^M)
expect (OK)
^M
^M
OK
?-- got it
send (AT+CGEQREQ=1,2,128,2048,0,0,0,0,"0E0","0E0",,0,0^M)
expect (OK)
^M
^M
OK
?-- got it
send (AT^M)
expect (OK)
^M
^M
OK
?-- got it
send (AT^M)
expect (OK)
^M
^M
OK
?-- got it
send (ATS0=0^M)
expect (OK)
^M
^M
OK
?-- got it
send (AT^M)
expect (OK)
^M
^M
OK
?-- got it
send (AT^M)
expect (OK)
^M
^M
OK
?-- got it
send (ATD*98*1#^M)
expect (CONNECT)
^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
^ORIG: 1,2^M
^M
+PCD: 1,1^M
^M
CONNECT
?-- got it
Serial connection established.
using channel 1
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB1
sent [LCP ConfReq id=0x1 ]
rcvd [LCP ConfReq id=0x28 ]
No auth is possible
sent [LCP ConfRej id=0x28 ]
rcvd [LCP ConfAck id=0x1 ]
rcvd [LCP ConfReq id=0x29 ]
sent [LCP ConfAck id=0x29 ]
sent [CCP ConfReq id=0x1 ]
sent [IPCP ConfReq id=0x1 ]
rcvd [LCP ProtRej id=0x2a 80 fd 01 01 00 0c 1a 04 78 00 18 04 78 00]
Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
sent [IPCP ConfReq id=0x1 ]
rcvd [IPCP ConfReq id=0x2b ]
sent [IPCP ConfAck id=0x2b ]
rcvd [IPCP ConfRej id=0x1 ]
sent [IPCP ConfReq id=0x2 ]
rcvd [IPCP ConfNak id=0x2 ]
sent [IPCP ConfReq id=0x3 ]
rcvd [IPCP ConfAck id=0x3 ]
local? IP address 10.170.57.106
remote IP address 192.168.0.1
primary ? DNS address 211.136.17.108
?
我也到google里面搜了一些,發現有的TD需要用戶名和密碼,我的這個不需要也可以上網,也不知道為啥啦。
看到pppd call cmnet成功返回ip和DNS后說明pppd成功了,此時如果系統中的eth0這個設備啟動了,則需要通過ifconfig eth0 down命令將其關閉,避免兩個上網的端口沖突。
再設置ppp0端口的路由為系統的默認路由,命令如下:
route del default
route add default ppp0
將得到的DNS存到 /etc/resolve.conf文件中 nameserver 211.136.17.108(注:如果TD設備的文檔中已給出這個DNS,則可以在運行pppd之前就放到resolve.conf這個文件中)
現在pppd成功啟動了,很多人都會用ping這個命令去試一下網絡是否通了,但是ping是行不通的。因為我們每次運行pppd這個程序返回的ip都是網內的動態ip,可以連接到公共網,但公共網卻無法返回回來,所需只能通過瀏覽器的方式來測試網絡是否已通。需要設置網絡的代理,代理如下:10.0.0.172? 80。設置之后輸入url即可訪問網站了。
其中還有一個小問題:
本人一開始沒喲考慮這個usbserial模塊的問題,導致后來運行pppd call cmnet的時候老是出現如下的錯誤:
Serial connection established.
Couldn't get channel number: Inappropriate ioctl for devic
后來想了好久才明白是這個usbserial的問題
所以需要從新編譯這個模塊,這就涉及到linux驅動的問題了,如有不明白linux驅動的需要查找一些書來看一看了。
1.下載內核(注:下載的內核不一定要和系統的內核版本完全相同,我下載的內核版本就和系統的版本不一樣),解壓內核
2.copy當前內核配置文件至內核源代碼目錄下,
cp /boot/config-$(uname -r) /usr/src/linux-2.6.28/.config(即到/boot目錄下找一個config開頭的配置文件,將其復制到解壓后的內核目錄下,修改文件名為:.config即可)
3.為編譯模塊創建配置文件。
cd /usr/src/linux-source-2.6.24/ && make oldconfig
通過make oldconfig可以減少很多不必要的選擇,使用系統當前的配置作為新內核默認的配置,也可以運行make menuconfig等命令
4.對內核源碼中的usbserial.c修改
usbserial.c進行修改,修改usb_serial_probe()函數中buffer_size = 4096;好像共有4個地方需要修改
5.編譯修改后的模塊(這里實際上編譯了所有的USB串口模塊,但至少比編譯整個內核快得多)
make -C /lib/modules/$(uname -r)/build M=/usr/src/linux-2.6.28/drivers/usb/serial
/lib/modules/..../build為系統目錄,如我的是:/lib/modules/2.6.32.10-90.fc12.i686.PAE/build。
后面一個目錄為當前編譯的usbserial模塊的目錄。
6.備份當前使用的usbserial.ko,然后將上步生成的usbserial.ko copy到/lib/modules/kernel/drivers/usb/serial/
如果找不到內核中usbserial.ko的位置,可以通過locate usbserial.ko指令找到
大概的過程和問題就這樣了,終于搞定了!!!!!!!!!!
FROM:http://blog.csdn.net/yalexiaoqiang/article/details/5564715
linux的/dev/ttyACM0是什么樣的設備
usb設備插入到板子上后出現
cdc_acm 1-1:1.0: ttyACM0: USB ACM device
請問ttyACM0是種什么樣的設備?
類似于usb轉串口的那種嗎?
對ttyACM1的讀寫可以按照串口的操作
ttyACM0fd = open("/dev/ttyACM0", O_RDWR); 奇偶校驗和數據位是都需要設置,
?除了不用設置波特率外,其他都是一樣的操作
然后如果要往ttyACM0中傳數據就是用write(,,);
接收數據就用read(,,);
ttyACM0就是映射cdma modem的設備文件, 訪問方法的的話應該和ttyS0之類的一樣訪問
內核打開ttyACM支持的選項: Device Drivers-->USB support->USB support-->USB Gadget Support -->
?? ? ? ? ? ? ? ? ? ? ? ? ? --> USB Peripheral Controller (Inventra HDRC USB Peripheral (TI, ADI, ...))
?? ? ? ? ? ? ? ? ? ? ? ? ? -->USB Gadget Drivers-->Serial Gadget (with CDC ACM and CDC OBEX support)
在主機測能看到/dev/ttyACM0,說明配置是對的
What is the difference between /dev/ttyUSB and /dev/ttyACM? 分類: Linux
2014-04-27 19:24 1328人閱讀 評論(0) 收藏 舉報 目錄(?)
[+] Have you ever wondered why some USB devices used/dev/ttyUSB0 (or 1, or n) and others/dev/ttyACM0 (or 1, or n) when they are plugged into the host computer, while they seem to be acting as UART devices (RS-232-like) over USB in both cases? Have you wondered why example USB firmwares for microcontrollers always end up with names such as/dev/ttyACM0 and never as /dev/ttyUSB0?
Warning: this is a Linux specific post, although it also contains genuine pieces of USB culture. What does ttyACM mean? The USB implementors forum organization has described how devices conforming to the Communications Device Class (CDC) should present themselves to the USB host. The USB implementors forum also specified how CDC subclasses should act, including for those devices intended to talk with each other over the public switched telephone network (PSTN). Those are known as modems because the data goes through a modulation operation on the sending side, which transforms the bits into analog signals that can be carried over phone wires, and then through a demodulation operation on the receiving side to convert the analog signal back into the original bits.
To discuss with the modem, the host USB driver must use one of the existing control models. For example, thedirect line control model controls how data is exchanged between the host and the modem through an audio class interface, with the host taking charge of the modulation, demodulation, data compression (such as V.42bis) and error correction (such as V.42). This model is used by some USB soft modems, which are very cheap because they mostly contain a DSP chip and some amplification and line adaptation layers.
Another control model, aptly named abstract control model or ACM, lets the modem hardware perform the analog functions, and require that it supports the ITU V.250 (also known as Hayes in its former life) command set, either in the data stream or as a separate control stream through the communication class interface. When the commands are multiplexed with the data in the data stream, an escape sequence such as Hayes 302 (also known as “1 sec +++ 1 sec”) or TIES (that nobody remembers) must allow the host to put the modem into command mode.
When developping on a USB-enabled embedded microcontroller that needs to exchange data with a computer over USB, it is tempting to use a standardized way of communication which is well supported by virtually every operating system. This is why most people choose to implement CDC/PSTN with ACM (did you notice that the Linux kernel driver for /dev/ttyACM0 is named cdc_acm?) because it is the simplest way to exchange raw data.
But what about the mandatory V.250 command set? It is almost never implemented in such devices, but since the host has no reason to spontaneously generate V.250 commands by itself, the device will never have to answer them. Pretending the embedded device is a modem is the simplest way to communicate with it, even though it will probably never perform any modulation or demodulation task. Linux will not know that the device is lying, and will have it show up as /dev/ttyS0. What does ttyUSB mean? Sometimes, the embedded microcontroller does not come with a hardware USB interface. While it is possible to use a software-only USB stack, the additional constraints put onto the CPU and the usually small storage size often lead board designers to include a dedicated UART to USB bridge. Several vendors, such as FTDIor Prolific sell dedicated chips for a few euros.
Those vendors opted not to lie to the host computer in having the chips announce themselves as USB modems when they were not. Each vendor defined its own (usually proprietary) protocols, with commands allowing to control functions of the chips such as setting the baud rate or controlling additional signals used to implement hardware flow control.
When it is practical to do so, Linux groups devices with similar functionalities under the same default device or interface names. For example, the UARTs present on your computer (if any) will be named /dev/ttyS0 and/dev/ttyS1 even if one of them is a legacy 16550 chip and the other one is a MAX3100 SPI-controlled UART. Similarly, the devices offering UART-over-USB functionalities are named /dev/ttyUSB0,/dev/ttyUSB1, and so on, even though they are in fact using distinct device drivers. Conclusion So, when you see a /dev/ttyACM0 popping up, you can try to send it the escape sequence followed by AT commands, but there is a good chance that the device only pretends to be a modem and will happily send those characters to the core application without even considering intercepting them. If it is a /dev/ttyS0, do not try, unless the device behind the USB-UART bridge understands those command by itself (this is the case for the XBee chip).
利用FT232進行USB-RS232接口的開發 2010-05-12 01:14:01 分類: LINUX
市面上的USB轉串口線,為了壓低成本,穩定性做的都不是很好。
有興趣的話,自己焊接一條,用Ft232,比較簡單,而且也穩定
FT232特征及應用
? ? USB的神奇在于它是現代化的接口并通過USB總線直接給設備供電,它的接口輕巧并能使大量數據在其中傳輸,這些都是它的優點。缺點是硬件的設計因為高頻率和復雜的協議而變得困難。該如何是好?我們如何把我們的微控制器(Microcontroller)與USB總線連上? FTDI,一個蘇格蘭的公司,有了解決的辦法(http://www.ftdichip.com)。他們提供了一種實現USB與串口連接的芯片FT232。 FT232芯片一邊是RS232,另一邊是USB。換一句話說,你只是將原來需要外加電源的MAX232轉化成了帶RS232轉換線的FT232芯片。FT232是USB轉RS232/RS422/RS485的32pin LQFP單芯片轉換IC。
特點:
1 USB端口到串行端口通信
1 支持RS232標準串行端口及RS422/RS485介面
1 虛擬串口驅動程序VCP支持:
- Windows 98 and Windows 98 SE
- Windows 2000/ME/XP
- MAC OS-8 and OS-9
- MAC OS-X
- Linux 2.40
1 USB驅動程序D2XX 支持
- Windows 98 and Windows98 SE
- Windows 2000/ME/XP
1 完全兼容USB V1.1及USB V2.0 規范
1 提供384Byte的接收緩存和128Byte的發送緩存。
1 USB全速連接 12Mb/s
1 USB總線直接取電,無需外接電源
1 支持自動握手協議
1 高達1 Mbps(RS232)或者3Mbps(RS422/RS485)的傳輸速率
1 符合TIA/EIA的RS422/RS485標準
1 支持遠程喚醒和電源管理
1 可支持點到多點(RS485)
? ? FT232提供的USB轉232串口在RS232和USB口之間非常容易地建立可靠的連接。通過利用USB接口具有的即插即用和熱插拔的能力給串口RS232外圍設備提供非常容易使用的環境。它的設計可以讓你方便地連接諸如手提電話、數碼相機、ISDN-TA、Modem等設備,并提供高達115.2Kbps的傳輸速率。(如果電平轉換IC采用Maxim MAX3245CAI,則傳輸速率可達到1Mbps以上的速率)。
? ? FT232提供的USB轉RS422/RS485設備把RS422/RS485與USB兩種通訊協議取長補短,將它們的優點集于一身,在RS422/RS485和USB口之間建立可靠的連接。利用USB接口具有的即插即用和熱插拔的能力可以給RS422/RS485設備提供非常容易使用的環境。同時利用RS422/RS485具有的遠距離傳輸和抗干擾性能好等特點賦予了USB口遠距離傳輸的功能。它的設計可以讓你方便地連接諸如PLC和PLD、條碼掃描器、工控自動化等設備,并提供高達3Mbps的傳輸速率。?
? ? FT232是真正的跨平臺的解決方案,有適合各種操作系統的版本,為Linux內核準備的是ftdi_sio并且源代碼開放,它是Linux內核的一部分。FT232不僅提供了USB到RS232的連接,它的Linux下的內核模塊仍在繼續開發之中以擴充所有的函數功能。
? ? 一個需要注意的問題是電力的消耗,如果你設計了一個總線供電的設備,必須讓它小于100mA的電流。你的設備還必須支持USB掛起模式(Suspend),USB處于掛起模式時,要求設備的耗電量必須小于0.5mA。如果你的設備不支持USB掛起模式,FT232提供了一個簡單有效的方法在USB處于掛起模式時去關閉你的設備電源。?
? ? 市面上有很多USB轉RS232的解決方案,例如Prolific公司的PL-2303系列。但是Prolific公司PL-2303系列的驅動程序不支持MAC OS的操作系統,并且沒有提供D2XX驅動程序,不方便設計人員使用DLL來設計應用軟件。FT232BM還提供一個93C46(93C56或93C66)EEPROM,用于存儲產品的VID、PID、設備序列號及一些說明性文字等。這些需要用戶自己編寫,編寫的應用程序由FTDI提供。用戶只須運行相應的應用程序,寫入自己相應的信息即可。如果設備采用總線供電且需要消耗100mA以上,500mA以下的電流,則可以在EEPROM中設定一個最大的電流范圍,設備需要使用這個EEPROM中的電流描述符去告知主機系統,設備需要多大的電流。該EEPROM是可選的。若沒有EEPROM,FT232BM將使用默認的VID、PID、產品描述符和電源描述符,并且沒有設備的序列號。
? ? 利用FT232進行USB接口的開發,簡單、容易,開發周期短,易于為工程實踐所采用。同時,也可以直接用于新產品的開發,如數碼相機的USB接口、MP3播放器的USB接口及無線Modem的USB接口等。