The reference-ril of the android--4.2-3g transplant. pppd dial-up Internet access (iii)

Source: Internet
Author: User
Tags dns2 get ip
<span id="Label3"></p><p><p>The REFERENCE-RIL.C in Android's Ril mechanism is the driver interface provided by the Vendor. This driver source code each vendor is provided, the Internet also has the DOWNLOAD. I now use the Huawei Wcdma. Finally compiled into <strong>libreference-ril.so</strong>. About the role of this interface driver in RIL the Android--ril mechanism source code Analysis<br></p></p><p><p>Android 4.2 comes with PPPD source code IN/EXTERNAL/PPP/PPPD. in the same way, kernel is also required to open the support for point-to-point in the network Supports.<br></p></p><p><p><br></p></p><p><p>Writing is not easy, reproduced please specify the source: http://blog.csdn.net/jscese/article/details/40340665</p></p><p><p><br></p></p>A. requestsetupdatacall:<p><p>This is the request for data traffic in the reference-ril.c, and the upper interface is requested by the ONrequest <strong>Ril_request_setup_data_call</strong> . These are in the source code analysis mentioned above, there is a specific analysis, here only from the dial-up connection Analysis.</p></p><p><p></p></p><pre name="code" class="objc">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. Attribute variable for temporary storage of dialing 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?<p><p></p></p><p>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 PDP context 1 if (strcmp (apn, "3gnet") = = 0) {alogd ("jscese display in reference are 3gnet \ N "); Err = At_send_command ("atd*99***1#", &p_response); This is Unicom 3G Internet need 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"); Assuming that the above dial-in instruction is successfully returned, a previously defined PPPD service call script is enabled to dial to obtain IP and other network Parameters//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 property value of the IP address. This value I put in the PPPD dial script to set up, assuming the success of this can be detected in the {aloge ("[%s]: wait for the IP from the 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);}</p></pre><p><p></p></p><p><p><br></p></p><p><p><br></p></p>Two. PPPD<br><p><p>Start a service in the above Requestsetupdatacall to call PPPD dial, first add in Init.rc:</p></p><p><p></p></p><pre name="code" class="html"><pre name="code" class="html">#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</pre></pre><br><p><p></p></p><p><p>The above service is used to boot up the rild, loading the libreference-ril dynamic library,</p></p><p><p>and specify the communication port for the serial port-d/dev/ttyusb2, and also the-s is the socket device-p for the loopback interface<br></p></p><p><p>The following is the PPPD dial script service, used to start the Dial script, and specify the data port.</p></p><p><p><br></p></p><p><p>This PPPD_GPRS service is required to set Permissions. Because I'm in reference-ril, I'm Adding the following in/system/core/init/property_service.c by using Properties:</p></p><p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc">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}};</pre></pre><p><p></p></p><p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc">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}};</pre></pre><br>Set the permissions for the net.ppp1.* to be Used.<br><p><p></p></p><p><p><br></p></p><p><p>INIT.GPRS-PPPD Set the Run permissions In/system/core/include/private/android_filesystem_config.h:</p></p><pre name="code" class="objc"><pre name="code" class="objc">static struct Fs_path_config android_files[] = {.../*jscese add for pppd */ {00777, aid_root, aid_shell, "sy STEM/ETC/INIT.GPRS-PPPD "},/* end*/...}</pre></pre><br><p><p></p></p><strong><strong>INIT.GPRS-PPPD</strong></strong>:<p><p>To post a dial-up script<br></p></p><p><p></p></p><pre name="code" class="python"><pre name="code" class="python">#!/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"</pre></pre><p><p></p></p><p><p><br></p></p><p><p><br></p></p><p><p>In addition, in this dial-up script under the same folder/system/etc/ppp/need to set up and unregister IP and other parameters of the Script. One is called when the dial SUCCEEDS. One is called when the network is disconnected:</p></p><strong><strong>Ip-up-datakey</strong></strong>:<p><p></p></p><pre name="code" class="python"><pre name="code" class="python">#!/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"</pre></pre><br><br><p><p></p></p><strong><strong>ip-down-datakey:</strong></strong><p><p></p></p><pre name="code" class="python"><pre name="code" class="python">#!/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" "" "</pre></pre><p><p></p></p><p><p><br></p></p><p><p>Post a 3gnet dial log for the Unicom apn:</p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p> <p><p>The reference-ril of the android--4.2-3g transplant. pppd dial-up Internet access (iii)</p></p></span>
Related Article

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.