android的gprs的上网过程:
1、在ril层中打开模块对应的数据业务设备,比如/dev/ttyUSB3
2、往数据设备发送AT+CGDCONT命令指定对应apn,发送ATDT*98*1#等拨号指令
3、上述AT指令返回OK之后,就可以启动pppd_gprs脚本了,启动之前,先设置好apn的属性,例如user,pwd,device等
property_set("net.gprs.user", user); property_set("net.gprs.password", pwd); property_set("net.gprs.device", device); property_set("net.gprs.ppp-exit", ""); property_set("ctl.start", "pppd_gprs");4、属性的设置过程在我的上一篇blog有详细阐述 http://blog.csdn.net/yinlijun2004/article/details/6981954
看property_service.c中void handle_property_set_fd(int fd)函数的代码
switch(msg.cmd) { case PROP_MSG_SETPROP: msg.name[PROP_NAME_MAX-1] = 0; msg.value[PROP_VALUE_MAX-1] = 0; if(memcmp(msg.name,"ctl.",4) == 0) { if (check_control_perms(msg.value, cr.uid, cr.gid)) { handle_control_message((char*) msg.name + 4, (char*) msg.value); } else { ERROR("sys_prop: Unable to %s service ctl [%s] uid: %d pid:%d\n", msg.name + 4, msg.value, cr.uid, cr.pid); }
void handle_control_message(const char *msg, const char *arg) { if (!strcmp(msg,"start")) { msg_start(arg); } else if (!strcmp(msg,"stop")) { msg_stop(arg); } else { ERROR("unknown control msg '%s'\n", msg); } }
static void msg_start(const char *name) { struct service *svc; char *tmp = NULL; char *args = NULL; if (!strchr(name, ':')) svc = service_find_by_name(name); else { tmp = strdup(name); args = strchr(tmp, ':'); *args = '\0'; args++; svc = service_find_by_name(tmp); } if (svc) { service_start(svc, args); } else { ERROR("no such service '%s'\n", name); } if (tmp) free(tmp); }
5、pppd_gprs服务在初始化脚本init.XX.rc中定义,由parser.c解析到service_list中
service pppd_gprs /system/xbin/pppd_gprs user root group root oneshot disabled6、pppd_gprs脚本读取刚刚已经设置好的apn的属性,执行pppd进程
USER=`/system/bin/getprop net.gprs.user` PASSWORD=`/system/bin/getprop net.gprs.password` DEVICE=`/system/bin/getprop net.gprs.device` /system/bin/setprop net.gprs.ppp-exit "" /system/bin/pppd -detach $DEVICE 115200 noipdefault noauth debug novj usepeerdns noccp ipcp-no-addresses kdebug 4 defaultroute user $USER password $PASSWORD /system/bin/setprop net.gprs.ppp-exit $? #exit $?