ppp 及 usb_modeswitch 等工具移植说明

ppp及usb_modeswitch等工具移植说明
1、libusb移植
usb_modeswitch、usbutils等工具用到libusb提供的API。目前libusb API有两个版本:libusb-1.0和libusb-0.1。
usb_modeswitch使用的libusb API版本是libusb-0.1,如果使用libusb-1.0需要libusb-compat。  libutils-0.90及以前版本使用的libusb API版本是libusb-0.1,libutils-0.91及以后版本使用的libusb API版本是libusb-1.0。 1.1、下载libusb源码
libusb下载地址:http://www.libusb.org 1.2、交叉编译libusb
a) 解压libusb源码包并进入目录libusb-x.x.x。 b) 创建目录install存放生成的库文件及头文件。
c) 配置并生成Makefile: ./configure --build=i686_linux --host=arm-mv5sft-linux-gnueabi(使
用的交叉编译工具)  --prefix=INSTALL_PATH(上一步创建的install目录)。
d) 如果是编译libusb-compat-x.x.x,需要指定libusb-1.0的库文件及头文件目录:export
PKG_CONFIG_PATH=/LIBUSB-1.0_PATH/INSTALL_PATH/lib/pkgconfig:$PKG_CONFIG_PATH。 e) 编译:make。
f) 安装相关库文件及头文件:make install。
g) 如果使用libusb-0.1,把库文件libusb-0.1.so.4.4.4、libusbpp-0.1.so.4.4.4复制到
userspace/rootfs/PLATTYPE/lib/目录。
h) 如果使用libusb-1.0,把库文件libusb-1.0.so.0.0.0、libusb-0.1.so.4.4.4(编译
libusb-compat-x.x.x生成的库文件)复制到userspace/rootfs/PLATTYPE/lib/目录。 
2、usb_modeswitch移植
usb_modeswitch是对usb设备的工作模式进行转换的工具,我们用usb_modeswitch将3G数据卡从storage模式转换到modem模式。
目前usb_modeswitch最新的版本为1.2.3,需要libusb-0.1 API的支持。 2.1、下载usb_modeswitch源码 a) 下载usb_modeswitch源码包,下载地址为:http://www.draisberghof.de/usb_modeswitch/ b) 下载usb_modeswitch-data数据包,该数据包包含usb设备模式转换的脚本文件。下载
地址同上。 2.2、交叉编译usb_modeswitch
a) 解压usb_modeswitch源码包并进入目录usb-modeswitch-x.x.x。 b) 修改Makefile文件:
CC=arm-mv5sft-linux-gnueabi-gcc(使用的交叉编译工具)     STRIP=arm-mv5sft-linux-gnueabi-strip
    INCLUDEDIR=LIBUSB_PATH/INSTALL_PATH/include     LIBDIR=LIBUSB_PATH/INSTALL_PATH/lib     $(PROG):  $(OBJS)
             $(CC) $(CCFLAGS) -I $(INCLUDEDIR) -L $(LIBDIR) -o $(PROG) $(OBJS) $(LIBS) 

c) 编译:make


d) 将编译生成的usb_modeswitch可执行程序复制到userspace/rootfs/PLATTYPE/usr/sbin/
目录。
e) 解压usb-modeswitch-data-20120120.tar.bz2,将解压后usb_modeswitch.d目录下的文件
复制到userspace/rootfs/PLATTYPE/etc/usb_modeswitch.d/目录。 
3、ppp移植
3.1、下载ppp源码
目前ppp的最新版本为ppp-2.4.5。下载地址为:http://ppp.samba.org/download.html 3.2、交叉编译ppp
a) 解压ppp源码包并进入目录ppp-x.x.x。
b) 如果内核中ioctl 命令PPPIOCNEWUNIT作了修改,则需要修改文件
ppp-x.x.x/include/linux/if_ppp.h: struct newunitreq {
int unit;
char ifname[IFNAMSIZ]; }; 
#define PPPIOCNEWUNIT   _IOWR('t', 62, struct newunitreq)   /* create new ppp unit */ c) 如果内核中ioctl 命令PPPIOCNEWUNIT作了修改,则需要修改文件
ppp-x.x.x/pppd/sys-linux.c: static int make_ppp_unit() {
int x, flags;
struct newunitreq req; 
if (ppp_dev_fd >= 0) {  dbglog("in make_ppp_unit, already had /dev/ppp open?");  close(ppp_dev_fd); }
ppp_dev_fd = open("/dev/ppp", O_RDWR); if (ppp_dev_fd < 0)  fatal("Couldn't open /dev/ppp: %m"); flags = fcntl(ppp_dev_fd, F_GETFL); if (flags == -1
|| fcntl(ppp_dev_fd, F_SETFL, flags | O_NONBLOCK) == -1) warn("Couldn't set /dev/ppp to nonblock: %m"); memset(&req, 0, sizeof(struct newunitreq)); req.unit = -1;
memcpy(req.ifname, "3gppp", 5);
x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &req); if (x < 0)  error("Couldn't create new ppp unit: %m");

ifunit = req.unit; return x;
}
d) 如果要使用3gppp接口,则需要修改文件ppp-x.x.x/pppd/main.c:
void
set_ifunit(iskey)     int iskey; {
    info("Using interface %s ", “3gppp”);
    slprintf(ifname, sizeof(ifname), "3gppp ");     script_setenv("IFNAME", ifname, iskey);     if (iskey) {  create_pidfile(getpid()); /* write pid to file */  create_linkpidfile(getpid());     } }
e) 配置并生成Makefile: ./configure。
f) 编译:make  CC=arm-mv5sft-linux-gnueai-gcc(使用的交叉编译工具)。 g) 将生成的可执行程序./chat/chat、./pppd/pppd、./pppdump/pppdump、./pppstats/pppstats
复制到userspace/rootfs/PLATTYPE/usr/sbin/目录。 3.3、编写拨号脚本文件
a) WCDMA制式
pppd拨号脚本文件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 /etc/ppp/peers/chat-wcdma-connect'
disconnect '/usr//sbin/chat -s -v -f /etc/ppp/peers/chat-wcdma-disconnect' chat拨号连接文件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
chat拨号断开文件chat-wcdma-disconnect      ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n" '' "\K"
'' "+++ATH"
SAY "\nGoodbay\n"  b) TD-SCDMA制式
pppd拨号脚本文件td-scdma
debug
logfile /var/log/pppd.log lock
/dev/ttyUSB0(根据数据卡类型修改) 115200 user "card"
password "card" crtscts
connect '/usr/sbin/chat -v -t3 -f /etc/ppp/peers/chat-td-connect' disconnect '/usr/sbin/chat -s -v -f /etc/ppp/peers/chat-td-disconnect' show-password usepeerdns noauth noipdefault novj
novjccomp noccp
defaultroute ipcp-accept-local ipcp-accept-remote
chat拨号连接文件chat-td-connect     ABORT 'BUSY'

ABORT 'NO CARRIER' ABORT 'VOICE'
ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT 'DELAYED' '' ATZ '' ATE0V1 '' ATS0=0
'' AT+CGDCONT=1,"IP","cmnet" OK-AT-OK "ATD*99***1#" CONNECT
chat拨号断开文件chat-td-disconnect     ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n" '' "\K"
'' "+++ATH"
SAY "\nGoodbay\n" c) EVDO制式
pppd拨号脚本文件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 /etc/ppp/peers/chat-evdo-connect'
disconnect '/usr//sbin/chat -s -v -f /etc/ppp/peers/chat-evdo-disconnect'
        chat拨号连接文件chat-evdo-connect             TIMEOUT 5

ABORT 'NO CARRIER' ABORT 'ERROR'
ABORT 'NO DIALTONE' ABORT 'BUSY'
ABORT 'NO ANSWER' '' \rATZ
OK-AT-OK ATD#777 CONNECT \d\c
        chat拨号断开文件chat-evdo-disconnect             ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n" "" "\k"
"" "+++ATH"
SAY "\nGoodbye\n" 
将以上文件复制到userspace/rootfs/PLATTYPE/etc/ppp/peers/目录下。 
4、usbutils移植
usbutils包含lsusb,是linux下查看usb设备信息的工具。 4.1、下载usbutils源码
目前usbutils最新版本为usbutils-004。下载地址为:
http://ftp.tlk-l.net/pub/mirrors/kernel.org/linux/utils/usb/usbutils/
4.2、交叉编译usbutils(以下适用于usbutils-0.90及以前版本) a) 解压usbutils源码包并进入目录usbutils-x.x.x。 b) 配置并生成Makefile:
./configure  CC=arm-mv5sft-linux-gnueabi-gcc  
LIBUSB_CFLAGS=LIBUSB_PATH/INSTALL_PATH/include  LIBUSB_LIBS=LIBUSB_PATH/INSTALL_PATH/lib/libsusb.so    CPPFLAGS=-I/ LIBUSB_PATH/INSTALL_PATH/include
--datadir=/usr/sbin(该路径需要与usb.ids在文件系统中的路径相同) --disable-zlib
c) 编译:make。
d) 将生成的可执行程序lsusb复制到userspace/rootfs/PLATTYPE/usr/sbin/目录。 e) 下载最新的usb.ids并将其复制到userspace/rootfs/PLATTYPE/usr/sbin/目录。
下载地址为:http://www.linux-usb.org/usb-ids.html 


http://wenku.baidu.com/link?url=zlbrRZh9azY9CEPFzuEn0GqX3Ym3vAF6VPkTzZiweForL7LSJYWHvpaf4j0emyPn8iB8uHLrkWPulQKfg70-5HKdt29GjUBNj-nHXFMLete

p​p​p​及​u​s​b​_​m​o​d​e​s​w​i​t​c​h​等​工​具​移​植​说​明


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用lwIP库中的ppp_listen函数的示例代码: ```c #include "ppp.h" #define PPP_DEVICE_NAME "ppp0" /* PPP link status callback */ static void link_status_cb(void *ctx, enum netif_nsc_reason reason, const struct netif *netif) { switch (reason) { case NETIF_NSC_IPV4_CONNECTED: /* IPv4 address has been assigned */ break; case NETIF_NSC_IPV6_CONNECTED: /* IPv6 address has been assigned */ break; case NETIF_NSC_IPV4_DISCONNECTED: case NETIF_NSC_IPV6_DISCONNECTED: /* Link has been disconnected */ break; default: break; } } int main(void) { struct netif ppp_netif; struct ppp_pcb *ppp; /* Initialize lwIP stack */ lwip_init(); /* Create a new PPP control block */ ppp = ppp_new(); /* Set up the PPP options */ ppp_set_auth(ppp, PPP_AUTHTYPE_NONE, NULL, NULL); /* Disable authentication */ ppp_set_default(ppp); /* Use default options */ /* Create a new network interface for PPP */ netif_add(&ppp_netif, NULL, NULL, NULL, ppp, ppp_netif_init, tcpip_input); /* Set up the link status callback */ netif_set_status_callback(&ppp_netif, link_status_cb); /* Start listening for incoming PPP connections */ ppp_listen(ppp); /* Start the lwIP stack */ sys_thread_new("lwip_thread", lwip_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); /* Wait for PPP connection */ while (ppp_link_status(ppp) != PPP_CONNECTED) { sys_msleep(1000); } /* PPP connection established */ printf("PPP connection established!\n"); /* Use the PPP network interface */ netif_set_up(&ppp_netif); /* Wait forever */ while (1) { sys_msleep(1000); } return 0; } ``` 在上面的示例代码中,我们创建了一个PPPD控制块(`ppp_new()`)并设置了PPPD选项(`ppp_set_auth()`和`ppp_set_default()`)。我们还创建了一个新的网络接口并将其与PPP控制块相关联(`netif_add()`)。然后,我们设置了一个回调函数,以便在PPP链路状态更改时得到通知(`netif_set_status_callback()`)。最后,我们调用`ppp_listen()`函数开始监听传入的PPP连接。 在等待PPP连接建立期间,我们可以执行其他操作。例如,启动lwIP堆栈(`lwip_thread()`),并在PPP连接建立后将网络接口设置为活动状态(`netif_set_up()`)。 请注意,上面的代码示例中省略了一些错误检查和清理代码,为了简化示例。在实际应用程序中,您需要添加适当的错误检查和清理代码,以确保代码的正确性和稳定性。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值