blob: 3ea77197e59966ef52a4b50a7405b5b8c36c580f [file] [log] [blame]
lhb07f4e12022-02-17 22:08:54 -08001//SPDX-License-Identifier: MediaTekProprietary
lh7b0674a2022-01-10 00:34:35 -08002/* Copyright Statement:
3 *
4 * This software/firmware and related documentation ("MediaTek Software") are
5 * protected under relevant copyright laws. The information contained herein
6 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
7 * Without the prior written permission of MediaTek inc. and/or its licensors,
8 * any reproduction, modification, use or disclosure of MediaTek Software,
9 * and information contained herein, in whole or in part, shall be strictly prohibited.
10 */
11/* MediaTek Inc. (C) 2010. All rights reserved.
12 *
13 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
14 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
15 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
16 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
19 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
20 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
21 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
22 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
23 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
24 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
25 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
26 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
27 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
28 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
29 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
30 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
31 *
32 * The following software/firmware and/or related documentation ("MediaTek Software")
33 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
34 * applicable license agreements with MediaTek Inc.
35 */
36
37#include <unistd.h>
38#include <string.h>
39#include <log/log.h>
40#include <vendor-ril/telephony/ril.h>
41extern "C" {
42#include <gio/gio.h>
43#include <glib.h>
44}
45
46#include "common.h"
47/*Warren add for t800 ril service 2021/12/25 start*/
48#include "lynq_common.h"
49#include "lynq_interface.h"
50#include <binder/Parcel.h>
ll6e73f202022-12-28 14:59:46 +080051#include "ATCI.h"
llf6e3ffd2023-01-12 22:31:29 +080052#include "atci_lynq_data_cmd.h"
ll6e73f202022-12-28 14:59:46 +080053#ifdef LED_SUPPORT
54#include "led.h"
55#endif
lh7b0674a2022-01-10 00:34:35 -080056using android::Parcel;
57
58/*Warren add for t800 ril service 2021/12/25 end*/
59
60#define LOG_TAG "DEMO_DATA_GDBUS"
61#define TELEPHONY_SERVICE "mtk.telephony" /*well-known bus name */
62#define TELEPHONY_DATA_INTERFACE "mtk.telephony.Data" /*interface name*/
63#define TELEPHONY_DATA_PATH "/mtk/telephony/data" /*object name*/
ll62a2b402022-11-16 21:19:04 +080064#define DEBUG 0
lh7b0674a2022-01-10 00:34:35 -080065
66GMainLoop *loop = NULL;
67GDBusProxy *proxy = NULL;
68MTK_Data_Call_Response_v1 req_response;
69MTK_Data_Call_Response_v1 urc_response;
ll90a255c2022-04-07 09:09:55 +000070
ll62a2b402022-11-16 21:19:04 +080071
rjw20006d12022-04-21 16:29:04 +080072/*Typethree add for t800 ril service 2022/04/14 start*/
73
74int lynq_data_modify_apn(gchar *reason,int lynq_request_id)
75{
76 Parcel p;
77 if(reason == NULL)
78 {
79 RLOGD("modify apn reason apn");
80 return -1;
81 }
82 p.writeInt32(1);
83 p.writeInt32(lynq_request_id);
84 p.writeInt32(0);
85 writeStringToParcel(p,reason);
rjw7ee7bb42023-01-18 11:34:28 +080086 android::LYNQ_RIL_urcBroadcast(p,lynq_request_id);
rjw20006d12022-04-21 16:29:04 +080087 return 0;
88}
89
90/*Typethree add for t800 ril service 2022/04/14 end*/
91
ll90a255c2022-04-07 09:09:55 +000092/*Warren add for t103 szzt atsvc 2022/1/5 start*/
ll62a2b402022-11-16 21:19:04 +080093/*lei modify on 2022/11/16*/
ll62a2b402022-11-16 21:19:04 +080094/*lei modify on 2022/11/16*/
ll90a255c2022-04-07 09:09:55 +000095/*Warren add for t103 szzt atsvc 2022/1/5 end*/
96
lh7b0674a2022-01-10 00:34:35 -080097/*Warren add for t800 ril service 2021/12/25 start*/
98int lynq_data_management(MTK_Data_Call_Response_v1 *urc_response)
99{
100 char apn_t[LYNQ_APN_LEN_MAX] = {};
101 char apnType_t[LYNQ_APNTPYE_LEN_MAX] = {};
102 char iface_t[LYNQ_APNTPYE_LEN_MAX] = {};
103 if(!urc_response)
104 {
105 RLOGD("urc_response is null!!!");
106 return -1;
107 }
108 bool apnHasCreated = FALSE;
lh7b0674a2022-01-10 00:34:35 -0800109 Parcel p;
lha62e0882023-10-31 05:17:11 -0700110 if(urc_response->pdnState == PDN_TIMEOUT_CANCEL)
111 {
112 p.writeInt32(1);
113 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
114 p.writeInt32(0);//temporary plan
115 p.writeInt32(urc_response->pdnState);
116 writeStringToParcel(p,urc_response->apnName);
117 writeStringToParcel(p,urc_response->apnType);
118 writeStringToParcel(p,urc_response->ifname);
119 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
120 return 0;
121 }
lh7b0674a2022-01-10 00:34:35 -0800122 if(urc_response->cId > 0)
123 {
124 if(urc_response->pdnState==PDN_DISCONNECTED)//if user disable data call,the pdn state wiil change to disconnected.
125 {
126 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
127 {
ll62a2b402022-11-16 21:19:04 +0800128 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800129 printf("line %d [PDN_DISCONNECTED]apn_table[%d],apntype:%s,apnstatus:%d,,,urc_response->apnName:%s\n",__LINE__, i,apn_table[i].apntype,apn_table[i].apnstatus,urc_response->apnType);
ll62a2b402022-11-16 21:19:04 +0800130 #endif
lh7b0674a2022-01-10 00:34:35 -0800131 RLOGD("[PDN_DISCONNECTED]apn_table[%d],apntype:%s,apnstatus:%d,,,urc_response->apnName:%s\n",i,apn_table[i].apntype,apn_table[i].apnstatus,urc_response->apnType);
132 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0)&&(apn_table[i].apnstatus==0))
133 {
134 bzero(apn_table[i].apn,LYNQ_APN_LEN_MAX);
135 bzero(apn_table[i].apntype,LYNQ_APNTPYE_LEN_MAX);
xy.he5cb8fd22023-10-23 07:20:54 -0700136 bzero(apn_table[i].ifaceName,LYNQ_APNTPYE_LEN_MAX);
ll62a2b402022-11-16 21:19:04 +0800137 apn_table[i].used = 0;
138 apn_table[i].netId = 0;
139 apn_table[i].pdpstate = PDN_DISCONNECTED;
lh7b0674a2022-01-10 00:34:35 -0800140 apn_count--;
141 p.writeInt32 (1);
142 p.writeInt32 (LYNQ_URC_DATA_CALL_STATUS_IND);
143 p.writeInt32 (0);//temporary plan
144 p.writeInt32(PDN_DISCONNECTED);
Hong_Liu6149f182023-05-12 02:15:14 -0700145 writeStringToParcel(p,urc_response->apnName);
rjw5d2a50e2022-02-28 15:01:49 +0800146 writeStringToParcel(p,urc_response->apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700147 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800148 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800149 RLOGD("removed apn:%s,apntype:%s",apn_table[i].apn,apn_table[i].apntype);
lh7b0674a2022-01-10 00:34:35 -0800150 break;
151 }
152 }
153 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
154 {
155 RLOGD("for apn_table[%d].apn:%s,apntype:%s,used:%d,apnstatus:%d\n",i,apn_table[i].apn,
156 apn_table[i].apntype,apn_table[i].used,apn_table[i].apnstatus);
157 }
158 }
159 else
160 {
161 /*if the pdn status change,tele-fwk will send pdn status to me.
162 **The reason for the status change may be that enable data call,
163 **the user disable the data call, and the signal is interrupted.
164 */
165 if(apn_count==0)//first new apn has created
166 {
167 RLOGD("first apn_count:%d\n",apn_count);
168 memcpy(apn_table[apn_count].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
169 memcpy(apn_table[apn_count].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
170 memcpy(apn_table[apn_count].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
ll62a2b402022-11-16 21:19:04 +0800171 memcpy(apn_table[apn_count].address,urc_response->addresses,strlen(urc_response->addresses)+1);
172 apn_table[apn_count].pdpstate = urc_response->pdnState;
173 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800174 printf("line %d apn_table[%d].apn:%s,apntype:%s,,,urc_response->apnName:%s,urc_response->apntype:%s\n",__LINE__,apn_count,apn_table[apn_count].apn,apn_table[apn_count].apntype,urc_response->apnName,urc_response->apnType);
ll62a2b402022-11-16 21:19:04 +0800175 #endif
lh7b0674a2022-01-10 00:34:35 -0800176 RLOGD("apn_table[%d].apn:%s,apntype:%s,,,urc_response->apnName:%s,urc_response->apntype:%s\n",apn_count,apn_table[apn_count].apn,apn_table[apn_count].apntype,urc_response->apnName,urc_response->apnType);
177 apn_table[apn_count].apnstatus=1;
178 apn_table[apn_count].used=1;
179 apn_table[apn_count].netId=urc_response->netId;
180 apn_count++;
181 p.writeInt32(1);
182 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
183 p.writeInt32(0);//temporary plan
184 p.writeInt32(PDN_CONNECTED);
185 writeStringToParcel(p,urc_response->apnName);
186 writeStringToParcel(p,urc_response->apnType);
187 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800188 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
189#ifdef LED_SUPPORT
190 mbtk_netled_state_update(GPIO_NETLED_PPP_CONNECT);
191#endif
lh7b0674a2022-01-10 00:34:35 -0800192 }
193 else
194 {
ll62a2b402022-11-16 21:19:04 +0800195 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)//means apn state changed,need update
lh7b0674a2022-01-10 00:34:35 -0800196 {
ll62a2b402022-11-16 21:19:04 +0800197 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800198 printf("line %d for apn_table[%d].apn:%s,,,,urc_response->apnName:%s\n",__LINE__,i,apn_table[i].apn,urc_response->apnName);
ll62a2b402022-11-16 21:19:04 +0800199 #endif
Hong_Liu8d77acf2023-08-30 02:11:09 -0700200 RLOGD("for apn_table[%d].apntype:%s,,,,urc_response->apnType:%s\n",i,apn_table[i].apntype,urc_response->apnType);
201 if(strcmp(apn_table[i].apntype,urc_response->apnType)==0)
lh7b0674a2022-01-10 00:34:35 -0800202 {
ll62a2b402022-11-16 21:19:04 +0800203 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800204 printf("line %d This apn has been created update???!!!\n",__LINE__);
ll62a2b402022-11-16 21:19:04 +0800205 #endif
lh7b0674a2022-01-10 00:34:35 -0800206 RLOGD("This apn has been created!!!");
lh7b0674a2022-01-10 00:34:35 -0800207 apnHasCreated = TRUE;
208 if(apn_table[i].netId!=urc_response->netId)
209 {
ll62a2b402022-11-16 21:19:04 +0800210 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800211 printf("update???\n");
ll62a2b402022-11-16 21:19:04 +0800212 #endif
213 apn_table[i].netId = urc_response->netId;
214 apn_table[i].pdpstate = urc_response->pdnState;
215 memcpy(apn_table[i].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
216 memcpy(apn_table[i].address,urc_response->addresses,strlen(urc_response->addresses)+1);
lh7b0674a2022-01-10 00:34:35 -0800217 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
218 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
219 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
220 /*send urc to client
221 send apn_t,apnType_t,urc_response->pdnState,iface_t to client
222 */
223 p.writeInt32(1);
224 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
225 p.writeInt32(0);//temporary plan
226 p.writeInt32(urc_response->pdnState);
227 writeStringToParcel(p,apn_t);
228 writeStringToParcel(p,apnType_t);
229 writeStringToParcel(p,iface_t);
rjw7ee7bb42023-01-18 11:34:28 +0800230 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800231 }
232 break;
233 }
234 }
ll62a2b402022-11-16 21:19:04 +0800235 if(!apnHasCreated)//Multiple APNs are established new apn has created
lh7b0674a2022-01-10 00:34:35 -0800236 {
237 bool getLable = FALSE;
238 int lable = 0;
ll62a2b402022-11-16 21:19:04 +0800239 for(lable;lable < LYNQ_APN_CHANNEL_MAX;lable++)//to find not used array element subscript
lh7b0674a2022-01-10 00:34:35 -0800240 {
241 if(apn_table[lable].used==0)
242 {
243 getLable = TRUE;
244 break;
245 }
246 }
247 if(getLable)
248 {
ll62a2b402022-11-16 21:19:04 +0800249 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800250 printf("line %d Multiple APNs are established\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800251 #endif
lh7b0674a2022-01-10 00:34:35 -0800252 RLOGD("[getLable]:label==%d\n",lable);
253 memcpy(apn_table[lable].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
254 memcpy(apn_table[lable].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
255 memcpy(apn_table[lable].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
ll62a2b402022-11-16 21:19:04 +0800256 apn_table[lable].pdpstate = urc_response->pdnState;
257 memcpy(apn_table[lable].address,urc_response->addresses,strlen(urc_response->addresses)+1);
lh7b0674a2022-01-10 00:34:35 -0800258 RLOGD("new apn_table[%d].apn:%s,apntype:%s,,,urc_response->apnName:%s,urc_response->apntype:%s\n",lable,apn_table[lable].apn,apn_table[lable].apntype,urc_response->apnName,urc_response->apnType);
259 apn_table[lable].apnstatus=1;
260 apn_table[lable].used=1;
261 apn_table[lable].netId=urc_response->netId;
262 apn_count++;
263 p.writeInt32(1);
264 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
265 p.writeInt32(0);//temporary plan
266 p.writeInt32(urc_response->pdnState);
267 writeStringToParcel(p,urc_response->apnName);
268 writeStringToParcel(p,urc_response->apnType);
269 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800270 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800271 }
272 else
273 {
274 RLOGD("unkown error");
275 }
276 }
277 }
278 }
279 }
ll62a2b402022-11-16 21:19:04 +0800280 else //cid < 0 it means:when at+cfun=0 will into this or when connecting
lh7b0674a2022-01-10 00:34:35 -0800281 {
282 apnHasCreated = FALSE;
283 RLOGD("[cid < 0] apn_count:%d\n",apn_count);
Hong_Liudc46d412023-05-18 13:36:26 -0700284 if(urc_response->pdnState==PDN_DISCONNECTED)//if user disable data call,the pdn state wiil change to disconnected.
285 {
286 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
287 {
288 #if DEBUG
289 printf("line %d [PDN_DISCONNECTED]apn_table[%d],apntype:%s,apnstatus:%d,,,urc_response->apnName:%s\n",__LINE__, i,apn_table[i].apntype,apn_table[i].apnstatus,urc_response->apnType);
290 #endif
291 RLOGD("[PDN_DISCONNECTED]apn_table[%d],apntype:%s,apnstatus:%d,,,urc_response->apnName:%s\n",i,apn_table[i].apntype,apn_table[i].apnstatus,urc_response->apnType);
292 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0)&&(apn_table[i].apnstatus==0))
293 {
294 bzero(apn_table[i].apn,LYNQ_APN_LEN_MAX);
295 bzero(apn_table[i].apntype,LYNQ_APNTPYE_LEN_MAX);
xy.he5cb8fd22023-10-23 07:20:54 -0700296 bzero(apn_table[i].ifaceName,LYNQ_APNTPYE_LEN_MAX);
Hong_Liudc46d412023-05-18 13:36:26 -0700297 apn_table[i].used = 0;
298 apn_table[i].netId = 0;
299 apn_table[i].pdpstate = PDN_DISCONNECTED;
300 apn_count--;
301 p.writeInt32 (1);
302 p.writeInt32 (LYNQ_URC_DATA_CALL_STATUS_IND);
303 p.writeInt32 (0);//temporary plan
304 p.writeInt32(PDN_DISCONNECTED);
305 writeStringToParcel(p,urc_response->apnName);
306 writeStringToParcel(p,urc_response->apnType);
307 writeStringToParcel(p,urc_response->ifname);
308 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
309 RLOGD("removed apn:%s,apntype:%s",apn_table[i].apn,apn_table[i].apntype);
310 break;
311 }
312 }
313 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
314 {
315 RLOGD("for apn_table[%d].apn:%s,apntype:%s,used:%d,apnstatus:%d\n",i,apn_table[i].apn,
316 apn_table[i].apntype,apn_table[i].used,apn_table[i].apnstatus);
Hong_Liu088a97e2023-06-05 07:48:17 -0700317 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0))
318 {
319 apn_table[i].pdpstate = urc_response->pdnState;
320 char ptr[1] = "";
321 if(NULL == urc_response->ifname)
322 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700323 memset(iface_t,0,LYNQ_APNTPYE_LEN_MAX);
324 memset(apn_table[i].ifaceName,0,LYNQ_APNTPYE_LEN_MAX);
325 }
326 else
327 {
328 memcpy(iface_t,urc_response->ifname,strlen(urc_response->ifname)+1);
xy.he5cb8fd22023-10-23 07:20:54 -0700329 memcpy(apn_table[i].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
Hong_Liu088a97e2023-06-05 07:48:17 -0700330 }
331 if(NULL == urc_response->addresses)
332 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700333 memset(apn_table[i].address,0,LYNQ_APNTPYE_LEN_MAX);
Hong_Liu088a97e2023-06-05 07:48:17 -0700334 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700335 memcpy(apnType_t,urc_response->apnType,strlen(urc_response->apnType)+1);
336 memcpy(apn_t,urc_response->apnName,strlen(urc_response->apnName)+1);
Hong_Liu088a97e2023-06-05 07:48:17 -0700337 p.writeInt32(1);
338 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
339 p.writeInt32(0);//temporary plan
340 p.writeInt32(urc_response->pdnState);
341 writeStringToParcel(p,apn_t);
342 writeStringToParcel(p,apnType_t);
343 writeStringToParcel(p,iface_t);
344 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
345 RLOGD("cid is %d apn:%s,apntype:%s",urc_response->cId,apn_table[i].apn,apn_table[i].apntype);
346 }
Hong_Liudc46d412023-05-18 13:36:26 -0700347 }
348 return 0;
349 }
lh7b0674a2022-01-10 00:34:35 -0800350 if(apn_count>0)
351 {
352 int i = 0;
353 for(i;i < LYNQ_APN_CHANNEL_MAX;i++)
354 {
ll62a2b402022-11-16 21:19:04 +0800355 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800356 printf("line %d don't know\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800357 #endif
lh7b0674a2022-01-10 00:34:35 -0800358 RLOGD("[cid<0]apn_table[%d].apntype:%s,,,,urc_response->apntype:%s\n",i,apn_table[i].apntype,urc_response->apnType);
359 if(strcmp(apn_table[i].apntype,urc_response->apnType)==0)
360 {
361 RLOGD("apntype:%s PDN status has changed!!!\n",urc_response->apnType);
362 apnHasCreated = TRUE;
363 break;
364 }
365 }
366 if(apnHasCreated)
367 {
ll62a2b402022-11-16 21:19:04 +0800368 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800369 printf("line %d don't know\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800370 #endif
371 apn_table[i].pdpstate = urc_response->pdnState;
372 char ptr[1] = "";
373 if(NULL == urc_response->ifname)
374 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700375 memset(iface_t,0,LYNQ_APNTPYE_LEN_MAX);
376 memset(apn_table[i].ifaceName,0,LYNQ_APNTPYE_LEN_MAX);
377 }
378 else
379 {
380 memcpy(iface_t,urc_response->ifname,strlen(urc_response->ifname)+1);
xy.he5cb8fd22023-10-23 07:20:54 -0700381 memcpy(apn_table[i].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
ll62a2b402022-11-16 21:19:04 +0800382 }
383 if(NULL == urc_response->addresses)
384 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700385 memset(apn_table[i].address,0,LYNQ_APNTPYE_LEN_MAX);
ll62a2b402022-11-16 21:19:04 +0800386 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700387 memcpy(apnType_t,urc_response->apnType,strlen(urc_response->apnType)+1);
388 memcpy(apn_t,urc_response->apnName,strlen(urc_response->apnName)+1);
lh7b0674a2022-01-10 00:34:35 -0800389 p.writeInt32(1);
390 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
391 p.writeInt32(0);//temporary plan
392 p.writeInt32(urc_response->pdnState);
393 writeStringToParcel(p,apn_t);
394 writeStringToParcel(p,apnType_t);
395 writeStringToParcel(p,iface_t);
rjw7ee7bb42023-01-18 11:34:28 +0800396 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800397 }
398 }
399 }
400 return 0;
401}
402/*Warren add for t800 ril service 2021/12/25 end*/
403void freeMem(MTK_Data_Call_Response_v1 response)
404{
405 g_free(response.apnType);
406 g_free(response.type);
407 g_free(response.ifname);
408 g_free(response.addresses);
409 g_free(response.dnses);
410 g_free(response.gateways);
411 g_free(response.pcscf);
412}
413
414char* apnState2string(RIL_Data_Call_PdnState apnState) {
415 switch (apnState) {
416 case RIL_Data_Call_PdnState::PDN_CONNECTED:
417 return "PDN_CONNECTED";
418 case RIL_Data_Call_PdnState::PDN_CONNECTING:
419 return "PDN_CONNECTING";
420 case RIL_Data_Call_PdnState::PDN_DISCONNECTED:
421 return "PDN_DISCONNECTED";
422 case RIL_Data_Call_PdnState::PDN_DISCONNECTING:
423 return "PDN_DISCONNECTING";
424 case RIL_Data_Call_PdnState::PDN_FAILED:
425 return "PDN_FAILED";
426 case RIL_Data_Call_PdnState::PDN_IDLE:
427 return "PDN_IDLE";
428 case RIL_Data_Call_PdnState::PDN_RETRYING:
429 return "PDN_RETRYING";
430 case RIL_Data_Call_PdnState::PDN_SCANNING:
431 return "PDN_SCANNING";
lha62e0882023-10-31 05:17:11 -0700432 case RIL_Data_Call_PdnState::PDN_TIMEOUT_CANCEL:
433 return "PDN_TIMEOUT_CANCEL";
lh7b0674a2022-01-10 00:34:35 -0800434 default:
435 return "UNKNOWN";
436 }
437}
438
439void dumpResponse(MTK_Data_Call_Response_v1 *dataCallResponse)
440{
441 RLOGD("dumpResponse: netId: %d, pdnState: %s, status: %d, cId: %d, apnType: %s,"
442 " protocolType: %s, ifaceName: %s, address: %s, dns: %s, gateway: %s, pcscf: %s, mtu: %d, apn: %s",
443 dataCallResponse->netId, apnState2string(RIL_Data_Call_PdnState(dataCallResponse->pdnState)),
444 dataCallResponse->status, dataCallResponse->cId, dataCallResponse->apnType, dataCallResponse->type,
445 dataCallResponse->ifname, dataCallResponse->addresses, dataCallResponse->dnses,
446 dataCallResponse->gateways, dataCallResponse->pcscf, dataCallResponse->mtu, dataCallResponse->apnName);
447}
448
449void parse(GVariant* result, MTK_Data_Call_Response_v1* data) {
450 g_variant_get(result, "((iiiisssssssis))", &(data->netId),
451 &(data->pdnState), &(data->status),
452 &(data->cId), &(data->apnType), &(data->type),
453 &(data->ifname), &(data->addresses),
454 &(data->dnses), &(data->gateways),
455 &(data->pcscf), &(data->mtu),&(data->apnName));
456}
457
458void proxy_method_cb (GDBusProxy *proxy,
459 GAsyncResult *res,
460 gpointer user_data)
461{
462 RLOGD("method call back");
463 GError *error;
464 GVariant *result;
465
466 error = NULL;
467 result = g_dbus_proxy_call_finish(proxy, res, &error);
468
469 if(error != NULL)
470 {
471 RLOGD("method call back error %s", error->message);
472 g_error_free(error);
473 return;
474 }
475 freeMem(req_response);
476 parse(result, &req_response);
477 dumpResponse(&req_response);
478 g_variant_unref(result);
479}
480
481int enableData (bool isEnable, gchar *apn_type)
482{
483 RLOGD("send: %s, %s", (isEnable ? "TRUE": "FALSE"), apn_type);
484 g_dbus_proxy_call(proxy,
485 "enableData",
486 g_variant_new("(bs)", isEnable, apn_type),
487 G_DBUS_CALL_FLAGS_NONE,
488 -1,
489 NULL,
490 (GAsyncReadyCallback) proxy_method_cb,
491 NULL);
492 return 1;
493}
rjw20006d12022-04-21 16:29:04 +0800494/*Typethree add for t800 RIL Service 2022/04/14 start*/
lh7b0674a2022-01-10 00:34:35 -0800495void modifyApnDB_method_cb (GDBusProxy *proxy,
496 GAsyncResult *res,
497 gpointer user_data)
498{
499 RLOGD("method call back");
500 GError *error;
501 GVariant *result;
502 gchar* reason = NULL;
503
504 error = NULL;
505 result = g_dbus_proxy_call_finish(proxy, res, &error);
506
507 if(error != NULL)
508 {
509 RLOGD("method call back error %s", error->message);
510 printf("modify apn db error: %s\n", error->message);
rjw20006d12022-04-21 16:29:04 +0800511 lynq_data_modify_apn(error->message,LYNQ_URC_MODIFY_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800512 g_error_free(error);
513 return;
514 }
515 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
516 g_variant_get (result, "(&s)", &reason);
517 RLOGD("modifyApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
518 printf("modify apn db success, return message: %s\n", ((reason == NULL)? "":reason));
519 //printf("modifyApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
ll6e73f202022-12-28 14:59:46 +0800520 /*lei add for AT+LEAPNMOD*/
llf6e3ffd2023-01-12 22:31:29 +0800521 if(g_flag_apn)
522 {
523 char apn_buf[256];
524 sprintf(apn_buf, "+LEAPNMOD:%s", ((reason == NULL)? "":reason));
525 ATCIResponseNoToken(0, apn_buf, 666);//tmp plan
526 }
ll6e73f202022-12-28 14:59:46 +0800527 /*lei add for AT+LEAPNMOD*/
lh7b0674a2022-01-10 00:34:35 -0800528 g_variant_unref(result);
rjw20006d12022-04-21 16:29:04 +0800529 lynq_data_modify_apn(reason,LYNQ_URC_MODIFY_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800530}
531
532int modifyApnDB(int cmd, gchar *record) {
533 RLOGD("%s: cmd: %d, record:%s", __FUNCTION__, cmd, record);
534 g_dbus_proxy_call(proxy,
535 "modifyApnDB",
536 g_variant_new("(is)", cmd, record),
537 G_DBUS_CALL_FLAGS_NONE,
538 -1,
539 NULL,
540 (GAsyncReadyCallback) modifyApnDB_method_cb,
541 NULL);
542 return 1;
543}
544
545void resetApnDB_method_cb (GDBusProxy *proxy,
546 GAsyncResult *res,
547 gpointer user_data)
548{
549 RLOGD("resetApnDB_method_cb call back");
550 GError *error;
551 GVariant *result;
552 gchar* reason = NULL;
553
554 error = NULL;
555 result = g_dbus_proxy_call_finish(proxy, res, &error);
556
557 if(error != NULL)
558 {
559 RLOGD("method call back error %s", error->message);
560 printf("reset apn DB error: %s\n", error->message);
rjw20006d12022-04-21 16:29:04 +0800561 lynq_data_modify_apn(error->message,LYNQ_URC_RESET_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800562 g_error_free(error);
563 return;
564 }
565 g_variant_get (result, "(&s)", &reason);
566 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
567 RLOGD("resetApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
568 printf("reset apn DB success, return message: %s\n", ((reason == NULL)? "":reason));
569 //printf("resetApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
570 g_variant_unref(result);
rjw20006d12022-04-21 16:29:04 +0800571 lynq_data_modify_apn(reason,LYNQ_URC_RESET_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800572}
rjw20006d12022-04-21 16:29:04 +0800573/*Typethree add for t800 RIL Service 2022/04/14 end*/
lh7b0674a2022-01-10 00:34:35 -0800574
575int resetApnDB() {
576 RLOGD("%s", __FUNCTION__);
577 g_dbus_proxy_call(proxy,
578 "resetApnDB",NULL,
579 G_DBUS_CALL_FLAGS_NONE,
580 -1,
581 NULL,
582 (GAsyncReadyCallback) resetApnDB_method_cb,
583 NULL);
584 return 1;
585}
586
ll90a255c2022-04-07 09:09:55 +0000587
lh7b0674a2022-01-10 00:34:35 -0800588void proxy_signals_on_signal (GDBusProxy *proxy,
589 const gchar *sender_name,
590 const gchar *signal_name,
591 GVariant *parameters,
592 gpointer user_data)
593{
594 RLOGD("signal_name: %s", signal_name);
595 printf("signal_name: %s\n", signal_name);
596 freeMem(urc_response);
597 parse(parameters, &urc_response);
598 dumpResponse(&urc_response);
599 if(g_strcmp0(signal_name, "lynq_data_resp") == 0)
600 {
601 printf("[lynq_data_resp]do something\n");
602 return;
603 }
604 lynq_data_management(&urc_response);
605 if(g_strcmp0(signal_name, "LYNQ_TEST") == 0)
606 {
607 printf("do something\n");
608 }
609 if(g_strcmp0(signal_name, "default") == 0)
610 {
611 if(urc_response.pdnState == RIL_Data_Call_PdnState::PDN_DISCONNECTED) {
612 notifyDataSignal();
xja1c30b82022-01-25 16:13:48 +0800613 } else if (urc_response.pdnState == RIL_Data_Call_PdnState::PDN_FAILED) {
614 updataDataConnectState(get_default_sim_data(), false);
lh7b0674a2022-01-10 00:34:35 -0800615 }
616 }
617 return;
618
619}
620
621void proxy_ready(GObject *source, GAsyncResult *result, gpointer user_data) {
622 GError *error;
623
624 error = NULL;
625 proxy = g_dbus_proxy_new_for_bus_finish(result, &error);
626 if (proxy == NULL) {
627 RLOGE("create proxy fail");
628 return ;
629 }
630 RLOGD("proxy is ready");
631 gulong signal_handler_id;
632
633 signal_handler_id = g_signal_connect(proxy, "g-signal",
634 G_CALLBACK (proxy_signals_on_signal), NULL);
635 if (signal_handler_id == 0) {
636 RLOGE("listen singal fail!");
637 }
638}
639
640void* init_data_gdbus_cb(void *param)
641{
642 /* all the tests rely on a shared main loop */
643 loop = g_main_loop_new(NULL, FALSE);
644
645 g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
646 G_DBUS_PROXY_FLAGS_NONE,
647 NULL, /* GDBusInterfaceInfo */
648 TELEPHONY_SERVICE, /* name */
649 TELEPHONY_DATA_PATH, /* object path */
650 TELEPHONY_DATA_INTERFACE, /* interface */
651 NULL, /* GCancellable */
652 proxy_ready,
653 NULL);
654
655 g_main_loop_run(loop);
656
657 RLOGD("data gdbus main loop run()");
658 if(proxy != NULL) {
659 g_object_unref (proxy);
660 }
661 if(loop != NULL) {
662 g_main_loop_unref(loop);
663 }
xja1c30b82022-01-25 16:13:48 +0800664 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800665}
666