The reference-ril of the android--4.2-3g transplant. PPPD Dial-up internet access (iii)

Source: Internet
Author: User
Tags dns2 get ip strcmp



Android Ril mechanism in the REFERENCE-RIL.C is the driver interface provided by the manufacturer, the driver source of the various manufacturers are provided, the Internet also has downloaded, I now use is WCDMA, and finally compiled into Libreference-ril.so, the role of this interface driver in Ril can be referenced in the Android--ril mechanism source code Analysis



Android 4.2 comes with PPPD source code in/EXTERNAL/PPP/PPPD.






Writing is not easy, reproduced please specify the source: http://blog.csdn.net/jscese/article/details/40340665





A. Requestsetupdatacall:


This is the request for data traffic in the REFERENCE-RIL.C, and the upper interface is requested by the ONrequest Ril_request_setup_data_call . These in the above mentioned in the source code analysis has detailed analysis, here only from the dial-up connection analysis.





static void Requestsetupdatacall (void *data, size_t datalen, Ril_token t) {const char *APN;    Char *cmd;    int err;    Atresponse *p_response = NULL; Char ppp_dnses[(Property_value_max * 2) + 3] = {'} '};    Initializes an array of properties used to temporarily store dialing property variables char Ppp_local_ip[property_value_max] = {'} '};    Char Ril_pppd_tty[property_value_max] = {'} '};    Char Ppp_dns1[property_value_max] = {'} '};    Char Ppp_dns2[property_value_max] = {'} '};    Char Ppp_gw[property_value_max] = {'} '};    Char Exit_code[property_value_max] = {'} '};    int n = 1; Ril_data_call_response_v6 *responses = alloca (n * sizeof (RIL_DATA_CALL_RESPONSE_V6)); Using IPv6 APN = ((const char * *) data) [2];     Access point incoming APN/* ALOGD ("Jscese display in reference APN = = '%s ' \ n", APN);  APN = "3gnet"; */Alogd ("[%s] Jscese display in reference APN '%s '", __func__, APN); #ifdef use_ti_commands//Config    For Multislot class ten (probably default anyway eh?) Err = At_send_command ("at%cprim=\" gmm\ ", \" CONFIG Multislot_cLass=<10>\ "", NULL);     Err = At_send_command ("at%data=2,\" uart\ ", 1,,\" Ser\ ", \" Uart\ ", 0", NULL); #endif/* use_ti_commands */int fd, qmistatus;    size_t cur = 0;    size_t Len;    ssize_t written, Rlen;    Char status[32] = {0};    int retry = 10;    const char *pdp_type;    ALOGD ("Requesting data connection to APN '%s '", APN); Pdp_type = "IP";    Jscese Add for Dial asprintf (&cmd, "at+cgdcont=1,\"%s\ ", \"%s\ ", 0,0", Pdp_type, APN); Fixme Check for error here Err = At_send_command (cmd, NULL);    The at Instruction Free (cmd) of the access point is sent, #if 0//Set required QoS params to default err = At_send_command ("At+cgqreq=1", NULL);    Set minimum QoS params to default err = At_send_command ("At+cgqmin=1", NULL);    Packet-domain Event Reporting Err = At_send_command ("at+cgerep=1,0", NULL); Hangup anything that's happening there now err = At_send_command ("at+cgact=1,0", NULL); #endif//Start data on PD  P Context 1 if (strcmp (APN, "3gnet") = = 0)  {ALOGD ("Jscese Display in reference is 3gnet \ n");  Err = At_send_command ("atd*99***1#", &p_response); This is the Unicom 3G Internet needs to dial the number atd*99***1# get the connection} else if (strcmp (APN, "ctnet") = = 0) {alogd ("Jscese display in refer        ence is ctnet \ n ");    Err = At_send_command ("atd#777", &p_response);    } if (Err < 0 | | p_response->success = = 0) {goto error;    } at_response_free (P_response); Sleep (1);    Wait for the modem to finish Property_set ("Net.ppp1.local-ip", "" ");    Property_set ("Net.gprs.ppp-exit", "" "); Property_set ("Ctl.start", "Pppd_gprs");    If the above dial-in command returns successfully, a previously defined PPPD service call script is enabled to dial the network parameters such as IP//Dialup sleep (3);    /*jscese add try 5 times to get ip*/int iretry = 5;        while (Iretry > 0) {property_get ("Net.gprs.ppp-exit", Exit_code, "");            if (strcmp (Exit_code, "0")! = 0) {aloge ("PPPd Exit with code%s", Exit_code);            iretry = 0;        Break} alogi ("Waiting for Property");            if (Wait_for_property ("Net.ppp1.local-ip", NULL, Ten) < 0)//monitor the IP address of the attribute value, this value I put in the PPPD dial script to set up, if successful here can be monitored {        Aloge ("[%s]: Wait for IP from PPP link at%d\n", __func__, Iretry);            } else {Alogi ("[%s]: Got IP from PPP link\r\n", __func__);        Break    } iretry--;        } if (iretry <= 0) {aloge ("[%s]: fail to get ip\r\n", __func__);    Goto error; }/* IF (Wait_for_property ("Net.ppp1.local-ip", NULL, Ten) < 0) {Aloge ("Timeout waiting net.ppp1.local-ip-g     Iving up!\n ");     Goto error;    }*/property_get ("Net.ppp1.local-ip", Ppp_local_ip, NULL);    Property_get ("net.ppp1.dns1", ppp_dns1, NULL);    Property_get ("Net.ppp1.dns2", Ppp_dns2, NULL);    Property_get ("NET.PPP1.GW", PPP_GW, NULL);    sprintf (ppp_dnses, "%s%s", ppp_dns1, PPP_DNS2);    Alogi ("Got net.ppp1.local-ip:%s\n", ppp_local_ip);    Responses[0].status = 0; ResponseS[0].suggestedretrytime =-1;    Responses[0].cid = 1;    Responses[0].active = 2;    Responses[0].type = "PPP";    Responses[0].ifname = Ppp_tty_path;    responses[0].addresses = ppp_local_ip;    responses[0].dnses = ppp_dnses;  Responses[0].gateways = PPP_GW; This responses is provided to the upper Ril_onrequestcomplete (T, ril_e_success, responses, n * sizeof (RIL_DATA_CALL_RESPONSE_) by getting the network properties set to the    V6));    Return    Error:ril_onrequestcomplete (t, Ril_e_generic_failure, NULL, 0); At_response_free (p_response);}










Two. pppd


Start a service in the above Requestsetupdatacall to invoke PPPD dialing, first add in init.rc:






#jscese Add for Usb_switch service if 3G dongle add for Serialservice ril-daemon/system/bin/rild-l/system/lib/librefe rence-ril.so---D/DEV/TTYUSB2    class main    socket rild stream 660 root radio    socket rild-debug stream 660 Radi O system    user root    Group Radio cache inet Misc Audio Logservice Pppd_gprs/system/etc/ppp/init.gprs-pppd/dev/tty USB0    user root    Group Radio cache inet Misc    disabled    oneshot## end





The above service is used to boot up the rild, load libreference-ril dynamic library,



and specify the communication port for the serial port-D/DEV/TTYUSB2, and also the-s for the socket device-p for the loopback interface



The following is the PPPD dial-up Scripting service, which is used to start the dial script and specify the data port.






This PPPD_GPRS service needs to set permissions, because I am in the reference-ril inside the/system/core/init/property_service.c by the property is added as follows:






struct {    const char *service;    unsigned int uid;    unsigned int gid;} Control_perms[] = {    {"dumpstate", Aid_shell, Aid_log},    {"Ril-daemon", Aid_radio, Aid_radio},/*jscese add for pp PD 3g*/    {"Pppd_gprs", Aid_radio, Aid_log},/*end*/     {NULL, 0, 0}};








struct {    const char *prefix;    unsigned int uid;    unsigned int gid;} Property_perms[] = {.../*jscese add pppd for  3g*/    {"Net.ppp1.", aid_radio,0},/*end*/    {NULL, 0, 0}};

Set the permissions for the net.ppp1.* to be used.








INIT.GPRS-PPPD set execution permissions in/system/core/include/private/android_filesystem_config.h:



static struct Fs_path_config android_files[] = {.../*jscese add for PPPD */    {00777, aid_root,      Aid_shell,    "sy STEM/ETC/INIT.GPRS-PPPD "},/*    end*/...}




INIT.GPRS-PPPD


To post a dial-up script






#!/system/bin/sh pppd_pid= user= '/system/bin/getprop net.gprs.user ' password= '/system/bin/getprop Net.gprs.password '/system/bin/setprop ' Net.gprs.ppp-exit "" "/SYSTEM/BIN/PPPD $115200 linkname datakey Unit 1 crtscts usepeerdns Noauth Defaultroute noipdefault ipcp-accept-local ipcp-accept-remote ipcp-max-failure 5 lcp-echo-interval lcp-echo-failure Modem dump Debug Kdebug 8pppd_exit=$? pppd_pid=$! /system/bin/log-t PPPD "PPPD exited with $PPPD _exit"/system/bin/setprop "Net.gprs.ppp-exit" "$PPPD _exit"











Also in this dial-up script in the same directory/system/etc/ppp/need to set up and log off IP parameters such as the script, one when the dial is successful, one is called when the network is disconnected:


Ip-up-datakey





#!/system/bin/shcase $ in    ppp1)        /android/bin/iptables--flush;        /android/bin/iptables--table Nat--flush;        /android/bin/iptables--delete-chain;        /android/bin/iptables--table Nat--append postrouting--out-interface ppp0-j Masquerade;        /android/bin/iptables--append FORWARD--in-interface ppp1-j ACCEPT;        echo 0 >/proc/sys/net/ipv4/ip_forward;        echo 1 >/proc/sys/net/ipv4/ip_forward;;    PPP0)    /system/bin/setprop "Net.interfaces.defaultroute" "Ppp1";;    ; Esac/system/bin/setprop "Net.ppp1.dns1" "$DNS 1"/system/bin/setprop "Net.ppp1.dns2" "$DNS 2"/system/bin/setprop " Net.ppp1.local-ip "" $IPLOCAL "/system/bin/setprop" Net.ppp1.remote-ip "" $IPREMOTE "/system/bin/setprop" NET.PPP1.GW " "$IPREMOTE"/system/bin/setprop "Net.ppp1.if" "$IFNAME"





Ip-down-datakey:





#!/system/bin/shcase $ in    ppp1)        echo 0 >/proc/sys/net/ipv4/ip_forward;;;        Esac/system/bin/setprop "net.ppp1.dns1" ""/system/bin/setprop "Net.ppp1.dns2" ""/system/bin/setprop " Net.ppp1.local-ip "" "/system/bin/setprop" Net.ppp1.remote-ip "" "/system/bin/setprop" NET.PPP1.GW "" "/system/bin/ SetProp "Net.ppp1.if" "" "








Post a 3gnet dial log for the Unicom APN:
























The reference-ril of the android--4.2-3g transplant. PPPD Dial-up internet access (iii)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.