blob: 9400bcb82cd1c68c9e6ef9f8d7c4658ad7dc765a [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
9 */
10/* MediaTek Inc. (C) 2010. All rights reserved.
11 *
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 *
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
34 */
35
36#include <stdio.h>
37#include <stdlib.h>
38#include <binder/Parcel.h>
39#include <vendor-ril/telephony/ril.h>
40#include <pal/pal_nm.h>
41#include <string.h>
42#include <log/log.h>
43#include <strings.h>
44#include <apn_interface.h>
45#include <vector>
46#include <string>
47
48#include "data/data.h"
49#include "common.h"
50
51#include "data/data_gdbus.h"
52#include "Radio_capability_switch_util.h"
53#include "util/utils.h"
54
55#undef LOG_TAG
56#define LOG_TAG "DEMO_DATA"
57
58#define SKIP_DATA_SETTINGS -2
59
60typedef struct {
61 char apn_type[10];
62 int cid;
63 int net_id;
64 char ifname[16];
65}map_cid;
66
67struct apntype_2_bitmask {
68char *type;
69int typebitmask;
70};
71
72#define APN_TYPE_ALL "*"
73#define TEXT_APN_TYPE_DEFAULT "default"
74#define TEXT_APN_TYPE_IMS "ims"
75#define TEXT_APN_TYPE_MMS "mms"
76#define TEXT_APN_TYPE_SUPL "supl"
77#define TEXT_APN_TYPE_DUN "dun"
78#define TEXT_APN_TYPE_HIPRI "hipri"
79#define TEXT_APN_TYPE_FOTA "fota"
80#define TEXT_APN_TYPE_CBS "cbs"
81#define TEXT_APN_TYPE_EMERGENCY "emergency"
82#define TEXTAPN_TYPE_IA "ia"
83#define TEXT_APN_TYPE_DM "dm"
84#define TEXT_APN_TYPE_WAP "wap"
85#define TEXT_APN_TYPE_NET "net"
86#define TEXT_APN_TYPE_CMMAIL "cmmail"
87#define TEXT_APN_TYPE_TETHERING "tethering"
88#define TEXT_APN_TYPE_RCSE "rcse"
89#define TEXT_APN_TYPE_XCAP "xcap"
90#define TEXT_APN_TYPE_RCS "rcs"
91
92//for IOT card type
93#define IOT_TEXT_APN_TYPE_DEFAULT "iot_default"
94#define IOT_TEXT_APN_TYPE_NET_0 "iot_net_0"
95#define IOT_TEXT_APN_TYPE_NET_1 "iot_net_1"
96#define IOT_TEXT_APN_TYPE_NET_2 "iot_net_2"
97#define IOT_TEXT_APN_TYPE_NET_3 "iot_net_3"
98#define IOT_TEXT_APN_TYPE_NET_4 "iot_net_4"
99#define IOT_TEXT_APN_TYPE_NET_5 "iot_net_5"
100#define IOT_TEXT_APN_TYPE_NET_6 "iot_net_6"
101
102#ifdef TARGET_PLATFORM_MT2731
103#define DATAASST_PDN_APN_TYPE_UNKNOWN 0x0
104#define DATAASST_PDN_APN_TYPE_DEFAULT 0x1
105#define DATAASST_PDN_APN_TYPE_MMS 0x2
106#define DATAASST_PDN_APN_TYPE_SUPL 0x4
107#define DATAASST_PDN_APN_TYPE_DUN 0x8
108#define DATAASST_PDN_APN_TYPE_HIPRI 0x10
109#define DATAASST_PDN_APN_TYPE_FOTA 0x20
110#define DATAASST_PDN_APN_TYPE_IMS 0x40
111#define DATAASST_PDN_APN_TYPE_CBS 0x80
112#define DATAASST_PDN_APN_TYPE_IA 0x100
113#define DATAASST_PDN_APN_TYPE_EMERGENCY 0x200
114#define DATAASST_PDN_APN_TYPE_WAP 0x400
115#define DATAASST_PDN_APN_TYPE_XCAP 0x800
116#define DATAASST_PDN_APN_TYPE_RCS 0x1000
117#define DATAASST_PDN_APN_TYPE_BIP 0x2000
118#define DATAASST_PDN_APN_TYPE_VSIM 0x4000
119#else
120#define DATAASST_PDN_APN_TYPE_UNKNOWN (0x00000000)
121#define DATAASST_PDN_APN_TYPE_DEFAULT (0x00000001)
122#define DATAASST_PDN_APN_TYPE_IMS (0x00000002)
123#define DATAASST_PDN_APN_TYPE_MMS (0x00000004)
124#define DATAASST_PDN_APN_TYPE_SUPL (0x00000008)
125#define DATAASST_PDN_APN_TYPE_DUN (0x00000010)
126#define DATAASST_PDN_APN_TYPE_HIPRI (0x00000020)
127#define DATAASST_PDN_APN_TYPE_FOTA (0x00000040)
128#define DATAASST_PDN_APN_TYPE_CBS (0x00000080)
129#define DATAASST_PDN_APN_TYPE_EMERGENCY (0x00000100)
130#define DATAASST_PDN_APN_TYPE_IA (0x00000200)
131#define DATAASST_PDN_APN_TYPE_DM (0x00000400)
132#define DATAASST_PDN_APN_TYPE_WAP (0x00000800)
133#define DATAASST_PDN_APN_TYPE_NET (0x00001000)
134#define DATAASST_PDN_APN_TYPE_CMMAIL (0x00002000)
135#define DATAASST_PDN_APN_TYPE_TETHERING (0x00004000)
136#define DATAASST_PDN_APN_TYPE_RCSE (0x00008000)
137#define DATAASST_PDN_APN_TYPE_XCAP (0x00010000)
138#define DATAASST_PDN_APN_TYPE_RCS (0x00020000)
139#endif
140//for IOT
141#define IOT_DATAASST_PDN_APN_TYPE_DEFAULT (0x00100000)
142#define IOT_DATAASST_PDN_APN_TYPE_NET_0 (0x00200000)
143#define IOT_DATAASST_PDN_APN_TYPE_NET_1 (0x00400000)
144#define IOT_DATAASST_PDN_APN_TYPE_NET_2 (0x00800000)
145#define IOT_DATAASST_PDN_APN_TYPE_NET_3 (0x01000000)
146#define IOT_DATAASST_PDN_APN_TYPE_NET_4 (0x02000000)
147#define IOT_DATAASST_PDN_APN_TYPE_NET_5 (0x04000000)
148#define IOT_DATAASST_PDN_APN_TYPE_NET_6 (0x08000000)
149
150#define LEN 128
151char line[LEN] = {0};
152char csname[27] = {0};
153static int net_id = 1000;
154
155int ims_type_in_db = 0;
156
157static int data_call_num = 0;
158
159RIL_Data_Call_Response_v6 *data_call_response = NULL;
160const int INVALID_VALUE = -1;
161const int INVALID = -2;
162int gcid = -1;
163bool isEnable = false;
164
165char cur_apn_type[12]={0};
166
167int SETUP_DATA_AUTH_NONE = 0;
168int SETUP_DATA_AUTH_PAP = 1;
169int SETUP_DATA_AUTH_CHAP = 2;
170int SETUP_DATA_AUTH_PAP_CHAP = 3;
171
172char* SETUP_DATA_PROTOCOL_IPV4 = "IP";
173char* SETUP_DATA_PROTOCOL_IPV6 = "IPV6";
174char* SETUP_DATA_PROTOCOL_IPV4V6 = "IPV4V6";
175
176map_cid current_cid[8] = {
177 {"", -1, -1, ""}, \
178 {"", -1, -1, ""}, \
179 {"", -1, -1, ""}, \
180 {"", -1, -1, ""}, \
181 {"", -1, -1, ""}, \
182 {"", -1, -1, ""}, \
183 {"", -1, -1, ""}, \
184 {"", -1, -1, ""}
185};
186
187//when 1, libvendor-ril manage the PDN retry , network configuration than create from ril request.
188bool isEnableLocalconf(){
189 bool isEnable;
190 RLOGD("enable configuration: %d", isEnable);
191
192 char prop_value[64] = { 0 };
193
194 utils::mtk_property_get("persist.pdnby.vendor",prop_value,"0");
195
196 isEnable = atoi(prop_value);
197
198 RLOGD("mtk_property_get configuration: %d", isEnable);
199 return isEnable;
200}
201
202/* Deactivate data call reasons */
203int DEACTIVATE_REASON_NONE = 0;
204int DEACTIVATE_REASON_RADIO_OFF = 1;
205int DEACTIVATE_REASON_PDP_RESET = 2;
206
207char dns[4][40] = {0};
208int dnsNum = 0;
209
210int findCellularName(char *s)
211{
212 int i = 0;
213 while (i < LEN) {
214 if (strncmp((s + i), "cellular_", 9) == 0) {
215 strncpy(csname, (s + i), 26);
216 csname[26] = '\0';
217 RLOGD("cellular service name is %s\n", csname);
218 return i;
219 } else {
220 i++;
221 }
222 }
223 return -1;
224}
225
226int getCellularService()
227{
228 FILE *cmd = popen("connmanctl services | grep cellular", "r");
229
230 if (cmd == NULL) {
231 RLOGD("open pipe fail!\n");
232 return -1;
233 }
234
235 fgets(line, LEN, cmd);
236 RLOGD("line is %s\n", line);
237
238 pclose(cmd);
239 return 0;
240}
241
242char* checkParameters(char* para)
243{
244 if (strcasecmp(para, "null") == 0) {
245 return "";
246 } else {
247 return para;
248 }
249}
250
251void updateApntype(char* apntype)
252{
253 if(strcasecmp(cur_apn_type, "ims") == 0
254 || strcasecmp(cur_apn_type, "xcap") == 0
255 || strcasecmp(cur_apn_type, "ia") == 0)
256 {
257 RLOGD("the current apn type: %s, don't set router, so just return", cur_apn_type);
258 return;
259 }
260
261 for(int i =0; i < 8; i++)
262 {
263 if((strcmp(current_cid[i].apn_type, "") == 0) || (current_cid[i].cid == INVALID_VALUE))
264 {
265 memset(current_cid[i].apn_type,0, strlen(current_cid[i].apn_type));
266 strcpy(current_cid[i].apn_type, apntype);
267 RLOGD("updateApntype[%d]: %s", i, apntype);
268 break;
269 }
270 }
271}
272
273void updatenetId(char* apntype, int net_id)
274{
275 for(int i =0; i < 8; i++)
276 {
277 for (int i = 0; i < 8 ; i++)
278 {
279 if(current_cid[i].net_id== INVALID_VALUE
280 && (strcmp(current_cid[i].apn_type, apntype) == 0))
281 {
282 current_cid[i].net_id = net_id;
283 RLOGD("updatenetId[%d]: %d", i, net_id);
284 }
285 }
286 }
287}
288
289void updateInterfaceName(char* apntype,char* interface_name)
290{
291 for (int i = 0; i < 8 ; i++)
292 {
293 if((strcmp(current_cid[i].ifname, "") == 0)
294 && (strcmp(current_cid[i].apn_type, apntype) == 0))
295 {
296 memset(current_cid[i].ifname,0, strlen(current_cid[i].ifname));
297 strncpy(current_cid[i].ifname, interface_name, sizeof(current_cid[i].ifname) - 1);
298 current_cid[i].ifname[sizeof(current_cid[i].ifname) - 1] = '\0';
299 RLOGD("updateinterfaceName[%d]: %s", i, current_cid[i].ifname);
300 break;
301 }
302 }
303}
304void destroyCid(char* apntype)
305{
306 for(int i =0; i < 8; i++)
307 {
308 if(strcmp(current_cid[i].apn_type, apntype) == 0)
309 {
310 strcpy(current_cid[i].apn_type, "");
311 current_cid[i].cid = -1;
312 current_cid[i].net_id = -1;
313 strcpy(current_cid[i].ifname, "");
314 RLOGD("destroyCid[%d]: %s",i, apntype);
315 break;
316 }
317 }
318}
319
320int getcid(char* apntype)
321{
322 int cid = INVALID_VALUE;
323 for(int i = 0; i < 8; i++)
324 {
325 if(strcmp(current_cid[i].apn_type, apntype) == 0)
326 {
327 cid = current_cid[i].cid;
328 break;
329 }
330 }
331 RLOGD("getcid: %d , apntype: %s", cid, apntype);
332 return cid;
333}
334
335int getnetId(char* apntype)
336{
337 int netid = INVALID_VALUE;
338 for(int i = 0; i < 8; i++)
339 {
340 if(strcmp(current_cid[i].apn_type, apntype) == 0)
341 {
342 netid = current_cid[i].net_id;
343 break;
344 }
345 }
346 RLOGD("getnetId: %d , apntype: %s", netid, apntype);
347 return netid;
348}
349
350char* getIfnameFromCache(char* apnType)
351{
352 char* interfaceName = NULL;
353 for(int i = 0; i < 8; i++)
354 {
355 if(strcmp(current_cid[i].apn_type, apnType) == 0)
356 {
357 interfaceName = current_cid[i].ifname;
358 break;
359 }
360 }
361 RLOGD("getIfnameFromCache: %s, apntype: %s", interfaceName, apnType);
362 return interfaceName;
363}
364
365char* getDns(char* apnType)
366{
367 RLOGD("getDns start data_call_num: %d", data_call_num);
368 char dnses[150] = "";
369 int cid = getcid(apnType);
370 if(cid == INVALID_VALUE)
371 {
372 RLOGD("cid is invalid");
373 return NULL;
374 }
375 for(int i = 0 ; i < data_call_num; i++)
376 {
377 if((data_call_response != NULL) && (data_call_response[i].cid == cid))
378 {
379 strncpy(dnses, data_call_response[i].dnses, sizeof(dnses)-1);
380 dnses[sizeof(dnses) -1] = '\0';
381 }
382 }
383 RLOGD("dnses: %s", dnses);
384 if (strcmp(dnses, "") == 0)
385 {
386 RLOGD("dnses is null");
387 return NULL;
388 }
389
390 dns[4][40] = {0};
391 dnsNum = 0;
392
393 RLOGD("fill data");
394 if(strstr(dnses, " "))
395 {
396 char* p = strtok(dnses, " ");
397 while(p)
398 {
399 if(dnsNum < 4)
400 {
401 RLOGD("dns[%d]: %s",dnsNum, p);
402 strcpy(dns[dnsNum],p);
403 dnsNum++;
404 }
405 p = strtok(NULL, " ");
406 }
407 } else {
408 RLOGD("dns: %s, only one", dnses);
409 strcpy(dns[dnsNum],dnses);
410 dnsNum++;
411 }
412 return dnses;
413}
414
415char* getAddress(char* apnType, const char token)
416{
417 char* ip = NULL;
418 char* addrs = NULL;
419 int cid = getcid(apnType);
420 if(cid == INVALID_VALUE)
421 {
422 RLOGD("cid is invalid");
423 return NULL;
424 }
425 for(int i = 0 ; i < data_call_num; i++)
426 {
427 if((data_call_response != NULL) && (data_call_response[i].cid == cid))
428 {
429 addrs = data_call_response[i].addresses;
430 }
431 }
432 if(!addrs)
433 {
434 RLOGD("addresss is null");
435 return NULL;
436 }
437 if(strstr(addrs, " "))
438 {
439 char* p = strtok(addrs, " ");
440 while(p)
441 {
442 if(strchr(p, token))
443 {
444 ip = p;
445 break;
446 } else {
447 p = strtok(p, " ");
448 }
449 }
450 } else {
451 if(strchr(addrs, token))
452 {
453 ip = addrs;
454 }
455 }
456 RLOGD("ip: %s", ip);
457 return ip;
458}
459
460char* getGateWay(char* apnType, const char token)
461{
462 char* gateway = NULL;
463 char* gateways = NULL;
464 int cid = getcid(apnType);
465 if(cid == INVALID_VALUE)
466 {
467 RLOGD("cid is invalid");
468 return NULL;
469 }
470 for(int i = 0 ; i < data_call_num; i++)
471 {
472 if((data_call_response != NULL) && (data_call_response[i].cid == cid))
473 {
474 gateways = data_call_response[i].gateways;
475 }
476 }
477 if(!gateways)
478 {
479 RLOGD("gateways is null");
480 return NULL;
481 }
482 if(strstr(gateways, " "))
483 {
484 char* p = strtok(gateways, " ");
485 while(p)
486 {
487 if(strchr(p, token))
488 {
489 gateway = p;
490 break;
491 } else {
492 p = strtok(p, " ");
493 }
494 }
495 } else {
496 if(strchr(gateways, token))
497 {
498 gateway = gateways;
499 }
500 }
501 RLOGD("gateway : %s", gateway);
502 return gateway;
503}
504char* getInterfaceNameFromLocal(char* apnType)
505{
506 char* interfaceName = NULL;
507 int cid = getcid(apnType);
508 if(cid == INVALID_VALUE)
509 {
510 RLOGD("cid is invalid");
511 return NULL;
512 }
513 for(int i = 0 ; i < 8; i++)
514 {
515 if(current_cid[i].cid == cid)
516 {
517 interfaceName = current_cid[i].ifname;
518 }
519 }
520 RLOGD("interfaceName: %s", interfaceName);
521 return interfaceName;
522}
523char* getInterfaceName(char* apnType)
524{
525 char* interfaceName = NULL;
526 int cid = getcid(apnType);
527 if(cid == INVALID_VALUE)
528 {
529 RLOGD("cid is invalid");
530 return NULL;
531 }
532 for(int i = 0 ; i < data_call_num; i++)
533 {
534 if((data_call_response != NULL) && (data_call_response[i].cid == cid))
535 {
536 interfaceName= data_call_response[i].ifname;
537 }
538 }
539 RLOGD("interfaceName: %s", interfaceName);
540 return interfaceName;
541}
542
543void configInterNetNetwork(char * apnType)
544{
545 //if route had filled. do fill the router information
546 char* interface_name = getInterfaceName(apnType);
547 if(!interface_name)
548 {
549 RLOGW("config fail, interface_name is nul");
550 return;
551 }
552 //if mal had set the route, don't set it.
553 unsigned int netid = 0;
554 int value = nm_interface_get_netid(interface_name, &netid);
555 if(netid > 0) {
556 RLOGW("the netid exsited. value: %d, netid: %d ", value, netid);
557 return;
558 }
559 if(net_id +1 >= 2000 ) {
560 net_id = 1001;
561 } else {
562 net_id++;
563 }
564
565 RLOGD("NET_ID: %d", net_id);
566 updatenetId(apnType,net_id);
567
568 char* temp_gateway = NULL;
569 char ipv4_gateway[16] = "";
570 char ipv6_gateway[40] = "";
571 temp_gateway = getGateWay(apnType, '.');
572 if(temp_gateway != NULL) {
573 strcpy(ipv4_gateway, temp_gateway);
574 }
575 temp_gateway = NULL;
576 temp_gateway = getGateWay(apnType,':');
577 if(temp_gateway != NULL) {
578 strcpy(ipv6_gateway, temp_gateway);
579 }
580
581
582 int prefix_len_ipv4 = 8;
583 int prefix_len_ipv6 = 64;
584 char* temp_dns[4] = {0};
585
586 updateInterfaceName(apnType,interface_name);
587 getDns(apnType);
588 char* DESTIONNATION_IPV4 = "0.0.0.0/0";
589 char* DESTIONNATION_IPV6 = "::/0";
590
591 RLOGD("nm_network_create() netid: %d", net_id);
592 if(nm_network_create(net_id, NULL) != 0)
593 {
594 RLOGD("nm_network_create() fail");
595 goto DEMO_CONFIG_NET_IF_ERR_1;
596 }
597
598 RLOGD("nm_network_interface_add() netid: %d, interface_name: %s", net_id, interface_name);
599 if(nm_network_interface_add(net_id, interface_name) != 0)
600 {
601 RLOGD("nm_network_interface_add() fail");
602 goto DEMO_CONFIG_NET_IF_ERR_2;
603 }
604
605 RLOGD("nm_network_route_add() netid: %d, ifname: %s, destion_ipv4: %s, ipv4_gateway: %s", net_id, interface_name, DESTIONNATION_IPV4,ipv4_gateway);
606 if (strlen(ipv4_gateway) != 0 && nm_network_route_add(net_id, interface_name, DESTIONNATION_IPV4,ipv4_gateway, 0, 1) != 0)
607 {
608 RLOGD("nm_network_route_add() gateway_v4 fail");
609 goto DEMO_CONFIG_NET_IF_ERR_2;
610 }
611
612 RLOGD("nm_network_route_add() netid: %d, ifname: %s, destion_ipv6: %s, ipv6_gateway: %s", net_id, interface_name, DESTIONNATION_IPV6,ipv6_gateway);
613 if (strlen(ipv6_gateway) != 0 && nm_network_route_add(net_id, interface_name, DESTIONNATION_IPV6,ipv6_gateway, 0, 1) != 0)
614 {
615 RLOGD("nm_network_route_add() gateway_v6 fail");
616 goto DEMO_CONFIG_NET_IF_ERR_2;
617 }
618
619 for (int k = 0 ; k < dnsNum; k++)
620 {
621 temp_dns[k] = dns[k];
622 }
623
624 if (nm_resolver_dns_set(net_id, interface_name, temp_dns, dnsNum, NM_NETWORK_TYPE_INTERNET) !=0)
625 {
626 RLOGD("nm_resolver_dns_set() fail");
627 goto DEMO_CONFIG_NET_IF_ERR_3;
628 }
629
630 if(strstr(apnType, "default") != NULL) {
631 RLOGD("nm_network_default_set(): netid: %d", net_id);
632 if(nm_network_default_set(net_id) != 0)
633 {
634 RLOGD("nm_network_default_set() fail");
635 return;
636 }
637 }
638
639 RLOGD("Demo App config network Done");
640 return;
641
642DEMO_CONFIG_NET_IF_ERR_3:
643 if(nm_resolver_dns_clear(net_id) != 0)
644 {
645 RLOGD("nm_resolver_dns_clear fail.");
646 }
647
648DEMO_CONFIG_NET_IF_ERR_2:
649 if(nm_network_interface_remove(net_id, interface_name) != 0)
650 {
651 RLOGD("nm_network_interface_remove fail.");
652 }
653
654DEMO_CONFIG_NET_IF_ERR_1:
655 if(nm_network_destroy(net_id) != 0)
656 {
657 RLOGD("nm_network_destroy fail.");
658 }
659 destroyCid(apnType);
660}
661
662void releaseInternetNetworkconfig(char* apnType)
663{
664 if(strcasecmp(cur_apn_type, "ims") == 0
665 || strcasecmp(cur_apn_type, "xcap") == 0
666 || strcasecmp(cur_apn_type, "ia") == 0)
667 {
668 RLOGD("the current apn type: %s, don't set router, so just return", cur_apn_type);
669 return;
670 }
671
672 char* ifname = getInterfaceNameFromLocal(apnType);
673
674 if((ifname == NULL)||(strcmp("", ifname) == 0))
675 {
676 RLOGD("interface_name is \"\"");
677 return;
678 }
679
680 //if mal had set the route, don't set it.
681 unsigned int netid = 0;
682 int value = nm_interface_get_netid(ifname, &netid);
683 RLOGD("query netid. value: %d, netid: %d ", value, netid);
684 if(netid <= 0) return;
685
686 if(nm_resolver_dns_clear(netid) != 0)
687 {
688 RLOGD("nm_resolver_dns_clear fail.");
689 }
690
691 if(nm_network_interface_remove(netid, ifname) != 0)
692 {
693 RLOGD("nm_network_interface_remove fail.");
694 }
695
696 if(nm_network_destroy(netid) != 0)
697 {
698 RLOGD("nm_network_destroy fail.");
699 }
700}
701
702int getApnProfileID(char *apnType)
703{
704 int profile_id;
705 if (strcasecmp(apnType, "mms") == 0) {
706 profile_id = DATA_PROFILE_MMS;
707 } else if (strcasecmp(apnType, "supl") == 0) {
708 profile_id =DATA_PROFILE_SUPL;
709 } else if (strcasecmp(apnType, "dun") == 0) {
710 profile_id = DATA_PROFILE_TETHERED;
711 } else if (strcasecmp(apnType, "hipri") == 0) {
712 profile_id = DATA_PROFILE_HIPRI; // DEFAULT for now
713 } else if (strcasecmp(apnType, "fota") == 0) {
714 profile_id = DATA_PROFILE_FOTA;
715 }else if (strcasecmp(apnType, "ims") == 0) {
716 profile_id = DATA_PROFILE_IMS;
717 }else if (strcasecmp(apnType, "cbs") == 0) {
718 profile_id = DATA_PROFILE_CBS;
719 } else if (strcasecmp(apnType, "emergency") == 0) {
720 profile_id = DATA_PROFILE_EMERGENCY;
721 } else if (strcasecmp(apnType, "wap") == 0) {
722 profile_id = DATA_PROFILE_WAP;
723 }else if (strcasecmp(apnType, "xcap") == 0) {
724 profile_id = DATA_PROFILE_XCAP;
725 }else if (strcasecmp(apnType, "rcs") == 0) {
726 profile_id = DATA_PROFILE_RCS;
727 }else if (strcasecmp(apnType, "bip") == 0) {
728 profile_id = DATA_PROFILE_BIP;
729 }else if (strcasecmp(apnType, "vsim") == 0) {
730 profile_id = DATA_PROFILE_VSIM;
731 }else {
732 profile_id = DATA_PROFILE_DEFAULT;
733 }
734
735 RLOGD("getApnProfileID apn type :%s, profile_id: %d",apnType, profile_id);
736 return profile_id;
737}
738
739int setDataAllowed(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
740{
741 if(argc != 2)
742 {
743 free(pRI);
744 RLOGD("the peremeters numbers isn't right , so return");
745 return -1;
746 }
747
748 android::Parcel p;
749 size_t pos = p.dataPosition();
750 p.writeInt32(1);
751 p.writeInt32(atoi(argv[1])); //allowed ? 1:0
752 p.setDataPosition(pos);
753 pRI->pCI->dispatchFunction(p, pRI);
754
755 return 0;
756}
757
758int setupDataCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
759{
760 if(argc > 2){
761 return setupDataCallargc(argc,argv,socket_id,pRI);
762 }
763 char cmd[256];
764 getCellularService();
765 findCellularName(line);
766 sprintf(cmd, "connmanctl connect %s", csname);
767 int ret = system(cmd);
768 memset(line, LEN*sizeof(char), 0);
769 memset(line, 27*sizeof(char), 0);
770
771 updataDataConnectState(get_default_sim_data(), true);
772 /* no response from telecore, free pRI prevent memory leak */
773 if (pRI != NULL) {
774 free(pRI);
775 }
776
777 return ret;
778}
779
780int getIntefaceId(char * apnType) {
781 int all_interface_id[5] = {1,2,3,7,0};
782 int temp_cid = INVALID_VALUE;
783 if (getcid(apnType) == INVALID_VALUE) {
784 bool is_find = false;
785 for(int i=0; i<5; i++)
786 {
787 temp_cid = all_interface_id[i];
788 bool is_exsited = false;
789 for (int j=0; j < 8; j++)
790 {
791 if (current_cid[j].cid != INVALID_VALUE && current_cid[j].cid == temp_cid)
792 {
793 is_exsited = true;
794 break;
795 }
796 }
797 if(!is_exsited)
798 {
799 is_find = true;
800 break;
801 }
802 }
803 if(!is_find)
804 {
805 RLOGE("PDN numbers is max, cann't create new PDN");
806 temp_cid = INVALID_VALUE;
807 } else {
808 // for *default* type. should use interface 0 as interface id.
809 if (strstr(apnType, "default") != NULL && temp_cid != 0)
810 {
811 temp_cid = 0;
812 }
813 }
814 }
815 RLOGD("getInterfaceId apn type: %s, inteface id : %d", apnType, temp_cid);
816 return temp_cid;
817}
818
819int setupDataCallargc(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
820{
821 if(argc != 8)
822 {
823 free(pRI);
824 RLOGD("the parameters numbers isn't right , so return");
825 return -1;
826 }
827
828 char radioTechnoloy[2];
829 char profile[8]={};
830 char* apnType = argv[2];
831 if(strcasecmp(apnType, "null") == 0)
832 {
833 free(pRI);
834 RLOGD("apnType shouldn't is null");
835 return -1;
836 }
837 if(!isEnableLocalconf()) {
838 free(pRI);
839 return enableData(true, apnType);
840 }
841 for(int i =0; i < 8; i++)
842 {
843 if(apnType != NULL && strcmp(current_cid[i].apn_type, apnType) == 0)
844 {
845 free(pRI);
846 RLOGD("PDN existed, only return. type: %s",apnType);
847 return -1;
848 }
849 }
850 //cur_apn_type = apnType;
851 memset(cur_apn_type, 0, sizeof(cur_apn_type));
852 memcpy(cur_apn_type,apnType,sizeof(cur_apn_type));
853 RLOGD("cur_apn_Type is %s",cur_apn_type);
854
855 char* apn = argv[1];
856 if(strcasecmp(apn, "null") == 0)
857 {
858 free(pRI);
859 RLOGD("apn shouldn't is null");
860 return -1;
861 }
862 char* user = checkParameters(argv[3]);
863 char* password = checkParameters(argv[4]);
864 char* protocol;
865 sprintf(radioTechnoloy, "%d",get_reg_data_radio_tech(Radio_capability_switch_util::get_main_capability_phone_id()));
866
867 sprintf(profile, "%d", getApnProfileID(apnType));
868 char authtype[2];
869 if(strcasecmp(argv[5], "null") == 0)
870 {
871 int temp = (strcmp(user, "") == 0) ? SETUP_DATA_AUTH_NONE : SETUP_DATA_AUTH_PAP_CHAP;
872 sprintf(authtype, "%d", temp);
873 } else {
874 strcpy(authtype, argv[5]);
875 }
876 authtype[1] = '\0';
877 //TBD
878 if(/*getDataRoamingFromRegistration()*/ false)
879 {
880 if(strcasecmp(argv[7], "null") == 0)
881 {
882 protocol = SETUP_DATA_PROTOCOL_IPV4;
883 } else {
884 protocol = argv[7];
885 }
886 } else {
887 if(strcasecmp(argv[6], "null") == 0)
888 {
889 protocol = SETUP_DATA_PROTOCOL_IPV4;
890 } else {
891 protocol = argv[6];
892 }
893 }
894
895 if(getIntefaceId(apnType) == INVALID_VALUE)
896 {
897 free(pRI);
898 RLOGE("the PDN exsited for %s type or PDN number max", apnType);
899 return -1;
900 }
901
902 char interface_id[2] = {0};
903 sprintf(interface_id, "%d", (getIntefaceId(apnType) + 1));
904 interface_id[1] = '\0';
905 android::Parcel p;
906 size_t pos = p.dataPosition();
907 p.writeInt32(8);
908 writeStringToParcel(p,radioTechnoloy);
909 writeStringToParcel(p,profile);
910 writeStringToParcel(p,apn);
911 writeStringToParcel(p,user);
912 writeStringToParcel(p,password);
913 writeStringToParcel(p,authtype);
914 writeStringToParcel(p,protocol);
915 writeStringToParcel(p, interface_id);
916 p.setDataPosition(pos);
917 updateApntype(apnType);
918 RLOGD("setupDataCallargc: \nradioTechnoloy: %s\nprofileId: %s\napn: %s\n \
919 username: %s\npassword: %s\nauthType: %s\nprotocol %s\napnType: %s\ninterface_id: %s",radioTechnoloy,profile,apn,
920 user,password,authtype,protocol,apnType, interface_id);
921 pRI->pCI->dispatchFunction(p, pRI);
922 return 0;
923}
924
925int deactivateDataCallarc(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
926{
927 if(argc != 2)
928 {
929 free(pRI);
930 RLOGD("the peremeters numbers isn't right , so return");
931 return -1;
932 }
933
934 char* apnType = argv[1];
935 if(!isEnableLocalconf()) {
936 free(pRI);
937 return enableData(false, apnType);
938 }
939 char cid[8];
940 char reason[8];
941 int temp_cid = getcid(apnType);
942 if(temp_cid == INVALID_VALUE)
943 {
944 free(pRI);
945 RLOGD("cid is invalid");
946 return -1;
947 }
948 sprintf(cid, "%d", temp_cid);
949
950 sprintf(reason,"%d",DEACTIVATE_REASON_NONE);
951
952 android::Parcel p;
953 size_t pos = p.dataPosition();
954 p.writeInt32(2);
955 writeStringToParcel(p,cid);
956 writeStringToParcel(p,reason);
957 p.setDataPosition(pos);
958 pRI->pCI->dispatchFunction(p, pRI);
959 releaseInternetNetworkconfig(apnType);
960 destroyCid(apnType);
961 RLOGD("deactivateDataCall() done");
962 return 0;
963}
964
965int deactivateDataCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
966{
967 if(argc == 2){
968 char* apnType = argv[1];
969
970 return deactivateDataCallarc(argc,argv,socket_id,pRI);
971 }
972 char cmd[256];
973 getCellularService();
974 findCellularName(line);
975 sprintf(cmd, "connmanctl disconnect %s", csname);
976 int ret = system(cmd);
977 memset(line, LEN*sizeof(char), 0);
978 memset(line, 27*sizeof(char), 0);
979 updataDataConnectState(get_default_sim_data(), false);
980 /* no response from telecore, free pRI prevent memory leak */
981 if (pRI != NULL) {
982 free(pRI);
983 }
984
985 return ret;
986}
987
988#if 0
989int apnSetting(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
990{
991 //apn show add delete update
992 free(pRI);
993 if(argc < 2){
994 RLOGD("the peremeters numbers isn't right , so return");
995 return -1;
996 }
997 int ret = APN_ERR;
998 apn_list_t* g_apnlist = NULL;
999 if(strncmp(argv[1], "show", 4) == 0){
1000 apn_record_t* record = apn_malloc_record();
1001 apn_build_cRecord(record, APN_PROP_MCC, mcc);
1002 apn_build_iRecord(record, APN_PROP_iMNC, mnc);
1003 if(g_apnlist){
1004 apn_free_list(g_apnlist);
1005 g_apnlist = NULL;
1006 }
1007 apn_query_db(record, &g_apnlist);
1008 RLOGD("apn list count %d\n",g_apnlist->count);
1009 apn_record_t* instance = g_apnlist->top;
1010 char apn_list[2048] = {0};
1011 int len = 0;
1012 while(instance != NULL) {
1013 for (int i = 0; i < instance->count; i++) {
1014 if (instance->values[i] != NULL) {
1015 if (i == (instance->count - 1)) {
1016 sprintf(apn_list+len,"%s/%s\n ",apn_get_prop_name(instance->columnIdx[i]),instance->values[i]);
1017 }else{
1018 sprintf(apn_list+len,"%s/%s; ",apn_get_prop_name(instance->columnIdx[i]),instance->values[i]);
1019 }
1020 len = strlen(apn_list);
1021 }
1022 }
1023 instance = (apn_record_t* )instance->next;
1024 }
1025 apn_free_record(record);
1026 android::emResultNotify(apn_list);
1027 RLOGD("Apn list: /%s",apn_list);
1028 }
1029 if(strncmp(argv[1], "add", 3) == 0){
1030 int i = 0;
1031 int apnidx = APN_ERR;
1032 apn_record_t* record = apn_malloc_record();
1033 RLOGD("add record count = %d",(argc-2));
1034 for (i = 0; i < (argc - 2 ) ; i+=2){
1035 apnidx = apn_get_idx_by_name(argv[i+2]);
1036 if(apnidx != APN_ERR){
1037 apn_build_iRecord(record,apnidx,argv[i+3]);
1038 }else{
1039 RLOGD("record name [%s] is not invalid",argv[i+2]);
1040 }
1041 }
1042 ret = apn_insert_record_db(record);
1043 apn_free_record(record);
1044 if(ret == -1){
1045 android::emResultNotify("add apn fail.\n");
1046 }else{
1047 android::emResultNotify("add apn success.\n");
1048 }
1049 }
1050 if(strncmp(argv[1], "delete", 6) == 0){
1051 if(argc < 3){
1052 RLOGD("the peremeters numbers isn't right , so return");
1053 return -1;
1054 }
1055 int apnid = atoi(argv[2]);
1056 RLOGD("delete id %d",apnid);
1057 ret = apn_delete_record_db(apnid);
1058 if(ret == -1){
1059 android::emResultNotify("delete apn fail.\n");
1060 }else{
1061 android::emResultNotify("delete apn success.\n");
1062 }
1063 }
1064 if(strncmp(argv[1], "update", 6) == 0){
1065 if(argc < 3){
1066 RLOGD("the peremeters numbers isn't right , so return");
1067 }
1068 int apnid = atoi(argv[2]);
1069 char *updateid_str = NULL;
1070 //get the select record and update it : _id
1071 apn_record_t* instance = g_apnlist->top;
1072 while(instance != NULL) {
1073 char *value = NULL;
1074 value = (char *)apn_get_prop_from_record(instance,APN_PROP_iId);
1075 if(value != NULL){
1076 if(apnid == atoi(value)){
1077 updateid_str = value;
1078 break;
1079 }
1080 }else{
1081 RLOGD("warning: record has no id");
1082 }
1083 instance = (apn_record_t* )instance->next;
1084 }
1085 if(updateid_str == NULL){
1086 RLOGD("the apn id(%d) is not exist in apn database, please check" ,apnid);
1087 android::emResultNotify("update fail, the apn id to update is not exist in apn database");
1088 return -1;
1089 }
1090 apn_record_t* record = apn_malloc_record();
1091 int columnidx = -1;
1092 apn_build_iRecord(record,APN_PROP_iId,updateid_str);
1093 for(int i = 0; i < (argc - 3) ; i+=2){
1094 columnidx = apn_get_idx_by_name(argv[i+3]);
1095 if(columnidx != APN_ERR){
1096 apn_build_iRecord(record,columnidx,argv[i+4]);
1097 }else{
1098 RLOGD("record name [%s] is not invalid",argv[i+2]);
1099 }
1100 }
1101 ret = apn_update_record_db(record);
1102 apn_free_record(record);
1103 if(ret == -1){
1104 android::emResultNotify("update apn fail.\n");
1105 }else{
1106 android::emResultNotify("update apn success.\n");
1107 }
1108 }
1109
1110}
1111#endif
1112
1113int setInitialAttachApnargc(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1114{
1115 if(argc != 6)
1116 {
1117 free(pRI);
1118 RLOGD("the peremeters numbers isn't right , so return");
1119 return -1;
1120 }
1121
1122 android::Parcel p;
1123 size_t pos = p.dataPosition();
1124 char* apn = checkParameters(argv[1]);
1125 char* protocol;
1126 if(strcasecmp(argv[2], "null") == 0)
1127 {
1128 protocol = SETUP_DATA_PROTOCOL_IPV4;
1129 } else {
1130 protocol = argv[2];
1131 }
1132 int authType = -1;
1133 if(strcasecmp("null", argv[3]) != 0)
1134 {
1135 authType = atoi(argv[3]);
1136 }
1137 char* username = checkParameters(argv[4]);
1138 char* password = checkParameters(argv[5]);
1139 writeStringToParcel(p,apn); //apn
1140 writeStringToParcel(p,protocol); //protocol
1141 p.writeInt32(authType); //authType
1142 writeStringToParcel(p,username);//username
1143 writeStringToParcel(p,password);//password
1144 p.setDataPosition(pos);
1145
1146 pRI->pCI->dispatchFunction(p, pRI);
1147 return 0;
1148}
1149
1150int getDataCallList(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1151{
1152 if(argc != 1)
1153 {
1154 free(pRI);
1155 RLOGD("the peremeters numbers isn't right , so return");
1156 return -1;
1157 }
1158
1159 android::Parcel p;
1160 pRI->pCI->dispatchFunction(p, pRI);
1161 return 0;
1162}
1163
1164int getLastDataCallFailCause(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1165{
1166 if(argc != 1)
1167 {
1168 free(pRI);
1169 RLOGD("the peremeters numbers isn't right , so return");
1170 return -1;
1171 }
1172
1173 android::Parcel p;
1174 pRI->pCI->dispatchFunction(p, pRI);
1175 return 0;
1176}
1177
1178void updateRILDataCallResponsev6(int num ,RIL_Data_Call_Response_v6* p_cur)
1179{
1180 if(!isEnableLocalconf()) return;
1181 data_call_num = num;
1182 if(strcasecmp(cur_apn_type, "ims") == 0
1183 || strcasecmp(cur_apn_type, "xcap") == 0
1184 || strcasecmp(cur_apn_type, "ia") == 0)
1185 {
1186 RLOGD("the current apn type: %s, don't set router, so just return", cur_apn_type);
1187 return;
1188 }
1189
1190 if(data_call_response != NULL)
1191 {
1192 free(data_call_response);
1193 }
1194
1195 data_call_response = (RIL_Data_Call_Response_v6 *)calloc(1, num*sizeof(RIL_Data_Call_Response_v6));
1196 if(p_cur)
1197 {
1198 memcpy(data_call_response,p_cur, num*sizeof(RIL_Data_Call_Response_v6));
1199 int j;
1200 RLOGD("num: %d", num);
1201 for (j = num-1; j >=0 ; j--)
1202 {
1203 int temp_cid = data_call_response[j].cid;
1204 int k;
1205 for(k = 0; k < 8 ; k++)
1206 {
1207 if(current_cid[k].cid == temp_cid)
1208 {
1209 break;
1210 }
1211 }
1212
1213 if (k >= 8)
1214 {
1215 break;
1216 }
1217 }
1218
1219 RLOGD("updateRILDataCallResponsev6()... j: %d", j);
1220 if(j < 0)
1221 {
1222 RLOGD("don't update data map_cid");
1223 return;
1224 }
1225
1226 int new_cid = data_call_response[j].cid;
1227 RLOGD("updateRILDataCallResponsev6()... j: %d, new_cid: %d",j, new_cid);
1228
1229 for (int i = 0; i < 8 ; i++)
1230 {
1231 if((strcmp(current_cid[i].apn_type, "") != 0) && current_cid[i].cid == INVALID_VALUE)
1232 {
1233 RLOGD("update current_cid[%d]: %d", i , new_cid);
1234 current_cid[i].cid = new_cid;
1235 break;
1236 }
1237 }
1238 configInterNetNetwork(cur_apn_type);
1239 } else {
1240 RLOGD("updateRILDataCallResponsev6 fail");
1241 }
1242}
1243
1244void handleUnsolDataCalllistChange(int num ,RIL_Data_Call_Response_v6* p_cur){
1245 for(int i =0; i < 8; i++)
1246 {
1247 int temp_cid = current_cid[i].cid;
1248 if(temp_cid != -1){
1249 int j;
1250 bool isContant = false;
1251 for(j=0; j < num; j++){
1252 if(p_cur[i].cid == temp_cid){
1253 isContant = true;
1254 break;
1255 }
1256 }
1257 RLOGD("isContant = %d, curent_cid[%d].cid = %d", isContant, i, temp_cid);
1258 if(!isContant){
1259 releaseInternetNetworkconfig(current_cid[i].apn_type);
1260 destroyCid(current_cid[i].apn_type);
1261 }
1262 }
1263 }
1264}
1265
1266static int getApntypeBitmask(const char *type)
1267{
1268 struct apntype_2_bitmask apntypebitmask[] = {
1269 {TEXT_APN_TYPE_DEFAULT,DATAASST_PDN_APN_TYPE_DEFAULT},
1270 {TEXT_APN_TYPE_IMS,DATAASST_PDN_APN_TYPE_IMS},
1271 {TEXT_APN_TYPE_MMS,DATAASST_PDN_APN_TYPE_MMS},
1272 {TEXT_APN_TYPE_SUPL,DATAASST_PDN_APN_TYPE_SUPL},
1273 {TEXT_APN_TYPE_DUN,DATAASST_PDN_APN_TYPE_DUN},
1274 {TEXT_APN_TYPE_HIPRI,DATAASST_PDN_APN_TYPE_HIPRI},
1275 {TEXT_APN_TYPE_FOTA,DATAASST_PDN_APN_TYPE_FOTA},
1276 {TEXT_APN_TYPE_CBS,DATAASST_PDN_APN_TYPE_CBS},
1277 {TEXT_APN_TYPE_EMERGENCY,DATAASST_PDN_APN_TYPE_EMERGENCY},
1278 {TEXTAPN_TYPE_IA,DATAASST_PDN_APN_TYPE_IA},
1279#if !(defined(TARGET_PLATFORM_MT2731))
1280 {TEXT_APN_TYPE_DM,DATAASST_PDN_APN_TYPE_DM},
1281#endif
1282 {TEXT_APN_TYPE_WAP,DATAASST_PDN_APN_TYPE_WAP},
1283#if !(defined(TARGET_PLATFORM_MT2731))
1284 {TEXT_APN_TYPE_NET,DATAASST_PDN_APN_TYPE_NET},
1285 {TEXT_APN_TYPE_CMMAIL,DATAASST_PDN_APN_TYPE_CMMAIL},
1286 {TEXT_APN_TYPE_TETHERING,DATAASST_PDN_APN_TYPE_TETHERING},
1287 {TEXT_APN_TYPE_RCSE,DATAASST_PDN_APN_TYPE_RCSE},
1288#endif
1289 {TEXT_APN_TYPE_XCAP,DATAASST_PDN_APN_TYPE_XCAP},
1290 {TEXT_APN_TYPE_RCS,DATAASST_PDN_APN_TYPE_RCS},
1291 {IOT_TEXT_APN_TYPE_DEFAULT ,IOT_DATAASST_PDN_APN_TYPE_DEFAULT}, //for IOT
1292 {IOT_TEXT_APN_TYPE_NET_0 ,IOT_DATAASST_PDN_APN_TYPE_NET_0},//for IOT
1293 {IOT_TEXT_APN_TYPE_NET_1 ,IOT_DATAASST_PDN_APN_TYPE_NET_1},//for IOT
1294 {IOT_TEXT_APN_TYPE_NET_2 ,IOT_DATAASST_PDN_APN_TYPE_NET_2},//for IOT
1295 {IOT_TEXT_APN_TYPE_NET_3 ,IOT_DATAASST_PDN_APN_TYPE_NET_3},//for IOT
1296 {IOT_TEXT_APN_TYPE_NET_4 ,IOT_DATAASST_PDN_APN_TYPE_NET_4},//for IOT
1297 {IOT_TEXT_APN_TYPE_NET_5 ,IOT_DATAASST_PDN_APN_TYPE_NET_5},//for IOT
1298 {IOT_TEXT_APN_TYPE_NET_6 ,IOT_DATAASST_PDN_APN_TYPE_NET_6},//for IOT
1299 };
1300 int len = sizeof(apntypebitmask)/sizeof(apntype_2_bitmask);
1301 for(int i = 0; i < len ; i++){
1302 if(strcasecmp(type,apntypebitmask[i].type) == 0)
1303 return apntypebitmask[i].typebitmask;
1304 }
1305 return DATAASST_PDN_APN_TYPE_UNKNOWN;
1306}
1307
1308static int check_is_number(char* str) {
1309 if(utils::is_number(str)){
1310 return atoi(str);
1311 } else {
1312 return INVALID;
1313 }
1314}
1315
1316//RIL_REQUEST_SET_DATA_PROFILE
1317int setDataProfile(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1318{
1319 int count = check_is_number(argv[1]);
1320 if(count == INVALID) {
1321 free(pRI);
1322 printf("the peremeters count(%s) isn't invalid , so return\n", argv[1]);
1323 RLOGD("the peremeters count(%s) isn't invalid , so return", argv[1]);
1324 return -1;
1325 }
1326
1327 if((argc-2) != 11*count) {
1328 free(pRI);
1329 printf("the peremeters numbers isn't right , so return\n");
1330 RLOGD("the peremeters numbers isn't right , so return");
1331 return -1;
1332 }
1333 android::Parcel p;
1334 size_t pos = p.dataPosition();
1335 p.writeInt32(count); //profileId
1336 for (int i=2; i < argc; i++) {
1337 int profileId = 0;
1338 std::vector<std::string> v;
1339 utils::tokenize(std::string(argv[i]),',',v);
1340 int index = 0;
1341 for(auto s: v) {
1342 RLOGD("%d:%s",index, s.c_str());
1343 profileId |= getApntypeBitmask(s.c_str());
1344 index++;
1345 }
1346 p.writeInt32(profileId); //profileId
1347 char* apn = checkParameters(argv[i+1]);
1348 writeStringToParcel(p,apn); //apn
1349 char* protocol;
1350 if(strcasecmp(argv[i+2], "null") == 0)
1351 {
1352 protocol = SETUP_DATA_PROTOCOL_IPV4V6;
1353 } else {
1354 protocol = argv[i+2];
1355 }
1356 writeStringToParcel(p,protocol); //protocol
1357 int authType = -1;
1358 if((strcasecmp("null", argv[i+3]) != 0) && (strcasecmp("-1", argv[i+3]) != 0))
1359 {
1360 authType = check_is_number(argv[i+3]);
1361 if (authType == INVALID) {
1362 free(pRI);
1363 printf("the peremeters authType(%s) isn't invalid , so return\n", argv[i+3]);
1364 return -1;
1365 }
1366 }
1367 p.writeInt32(authType); //authType
1368 char* username = checkParameters(argv[i+4]);
1369 writeStringToParcel(p,username);//username
1370 char* password = checkParameters(argv[i+5]);
1371 writeStringToParcel(p,password);//password
1372 int type = check_is_number(argv[i+6]);
1373 if(type == INVALID) {
1374 free(pRI);
1375 printf("the peremeters type(%s) isn't invalid , so return\n", argv[i+6]);
1376 RLOGD("the peremeters type(%s) isn't invalid , so return", argv[i+6]);
1377 return -1;
1378 }
1379 p.writeInt32(type); //type
1380 int maxConnsTime = check_is_number(argv[i+7]);
1381 if(maxConnsTime == INVALID) {
1382 free(pRI);
1383 printf("the peremeters maxConnsTime(%s) isn't invalid , so return\n", argv[i+7]);
1384 RLOGD("the peremeters maxConnsTime(%s) isn't invalid , so return", argv[i+7]);
1385 return -1;
1386 }
1387 p.writeInt32(maxConnsTime); //maxConnsTime
1388 int maxConns = check_is_number(argv[i+8]);
1389 if(maxConns == INVALID) {
1390 free(pRI);
1391 printf("the peremeters maxConns(%s) isn't invalid , so return\n", argv[i+8]);
1392 RLOGD("the peremeters maxConns(%s) isn't invalid , so return", argv[i+8]);
1393 return -1;
1394 }
1395 p.writeInt32(maxConns); //maxConns
1396 int waitTime = check_is_number(argv[i+9]);
1397 if(waitTime == INVALID) {
1398 free(pRI);
1399 printf("the peremeters waitTime(%s) isn't invalid , so return\n", argv[i+9]);
1400 RLOGD("the peremeters waitTime(%s) isn't invalid , so return", argv[i+9]);
1401 return -1;
1402 }
1403 p.writeInt32(waitTime); //waitTime
1404 int enabled = check_is_number(argv[i+10]);
1405 if(enabled == INVALID) {
1406 free(pRI);
1407 printf("the peremeters enabled(%s) isn't invalid , so return\n", argv[i+10]);
1408 RLOGD("the peremeters enabled(%s) isn't invalid , so return", argv[i+10]);
1409 return -1;
1410 }
1411 p.writeInt32(enabled); //enabled
1412 RLOGD("index=%d",i);
1413 i = i+10;
1414 }
1415 p.setDataPosition(pos);
1416
1417 pRI->pCI->dispatchFunction(p, pRI);
1418
1419 return 0;
1420}
1421
1422/**
1423* RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD
1424*
1425* Set data features.
1426 * The domestic roaming/international roaming should not set with roaming in the same project.
1427* The default data SIM should not set by this RIL request directly
1428*
1429* "data" is const int *
1430* ((const int*)data)[0] specify if data enable or not,-2 means skip this setting.
1431* ((const int*)data)[1] specify the roaming setting, -2 means skip this setting.
1432* ((const int*)data)[2] specify the default data sim, -2 means skip this setting.
1433* ((const int*)data)[3] specify the domestic roaming setting, -2 means skip this setting.
1434* ((const int*)data)[4] specify the international roaming setting, -2 means skip this setting.
1435*
1436* "response" is the NULL.
1437*
1438* Valid errors:
1439* SUCCESS
1440* GENERIC_FAILURE
1441*/
1442int syncDataSettingsToMd(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) {
1443 if (argc != 6){
1444 RLOGD("syncDataSettingsToMd parameters number isn't enough");
1445 free(pRI);
1446 return -1;
1447 }
1448 int32_t data_enable = std::stoi(argv[1]);
1449 int32_t roaming = std::stoi(argv[2]);
1450 int32_t default_data = std::stoi(argv[3]);
1451 int32_t domes_roa = std::stoi(argv[4]);
1452 int32_t inter_roa = std::stoi(argv[5]);
1453 RLOGD("syncDataSettingsToMd data_enable=%d, roaming=%d, default_data=%d, domes_roa=%d inter_roa=%d",
1454 data_enable, roaming, default_data, domes_roa, inter_roa);
1455 android::Parcel p;
1456 size_t pos = p.dataPosition();
1457 p.writeInt32(5);
1458 p.writeInt32(data_enable);
1459 p.writeInt32(roaming);
1460 p.writeInt32(default_data);
1461 p.writeInt32(domes_roa);
1462 p.writeInt32(inter_roa);
1463
1464 p.setDataPosition(pos);
1465 pRI->pCI->dispatchFunction(p, pRI);
1466 return 0;
1467}
1468
1469int syncDataSettings(RIL_SOCKET_ID socket_id) {
1470 char* slotID = "1";
1471 if(socket_id == 0) {
1472 slotID = "0";
1473 }
1474 char* tmp[6] = {"RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD", "-2", "-2", slotID, "-2", "-2"};
1475 RequestInfo *pRI = creatRILInfoAndInit(RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD, OTHER, socket_id);
1476 if(pRI == NULL) return -1;
1477 syncDataSettingsToMd(6,tmp,socket_id,pRI);
1478 return 0;
1479}
1480
1481int modifyApnRecord(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) {
1482 free(pRI);
1483 if (argc < 3){
1484 RLOGD("%s parameters number isn't enough", __FUNCTION__);
1485 return -1;
1486 }
1487 RLOGD("%s,cmd:%s,record:%s", __FUNCTION__,argv[1],argv[2]);
1488 int cmd = std::stoi(argv[1]);
1489 char* record = argv[2];
1490 modifyApnDB(cmd, record);
1491 return 0;
1492}
1493
1494int resetApnRecord(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) {
1495 RLOGD("%s", __FUNCTION__);
1496 free(pRI);
1497 resetApnDB();
1498 return 0;
1499}