blob: 2d78727a13d6f9172fb6e870c79ff319204b0766 [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;
110 if(urc_response->cId > 0)
111 {
112 if(urc_response->pdnState==PDN_DISCONNECTED)//if user disable data call,the pdn state wiil change to disconnected.
113 {
114 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
115 {
ll62a2b402022-11-16 21:19:04 +0800116 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800117 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 +0800118 #endif
lh7b0674a2022-01-10 00:34:35 -0800119 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);
120 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0)&&(apn_table[i].apnstatus==0))
121 {
122 bzero(apn_table[i].apn,LYNQ_APN_LEN_MAX);
123 bzero(apn_table[i].apntype,LYNQ_APNTPYE_LEN_MAX);
ll62a2b402022-11-16 21:19:04 +0800124 apn_table[i].used = 0;
125 apn_table[i].netId = 0;
126 apn_table[i].pdpstate = PDN_DISCONNECTED;
lh7b0674a2022-01-10 00:34:35 -0800127 apn_count--;
128 p.writeInt32 (1);
129 p.writeInt32 (LYNQ_URC_DATA_CALL_STATUS_IND);
130 p.writeInt32 (0);//temporary plan
131 p.writeInt32(PDN_DISCONNECTED);
Hong_Liu6149f182023-05-12 02:15:14 -0700132 writeStringToParcel(p,urc_response->apnName);
rjw5d2a50e2022-02-28 15:01:49 +0800133 writeStringToParcel(p,urc_response->apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700134 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800135 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800136 RLOGD("removed apn:%s,apntype:%s",apn_table[i].apn,apn_table[i].apntype);
lh7b0674a2022-01-10 00:34:35 -0800137 break;
138 }
139 }
140 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
141 {
142 RLOGD("for apn_table[%d].apn:%s,apntype:%s,used:%d,apnstatus:%d\n",i,apn_table[i].apn,
143 apn_table[i].apntype,apn_table[i].used,apn_table[i].apnstatus);
144 }
145 }
146 else
147 {
148 /*if the pdn status change,tele-fwk will send pdn status to me.
149 **The reason for the status change may be that enable data call,
150 **the user disable the data call, and the signal is interrupted.
151 */
152 if(apn_count==0)//first new apn has created
153 {
154 RLOGD("first apn_count:%d\n",apn_count);
155 memcpy(apn_table[apn_count].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
156 memcpy(apn_table[apn_count].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
157 memcpy(apn_table[apn_count].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
ll62a2b402022-11-16 21:19:04 +0800158 memcpy(apn_table[apn_count].address,urc_response->addresses,strlen(urc_response->addresses)+1);
159 apn_table[apn_count].pdpstate = urc_response->pdnState;
160 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800161 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 +0800162 #endif
lh7b0674a2022-01-10 00:34:35 -0800163 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);
164 apn_table[apn_count].apnstatus=1;
165 apn_table[apn_count].used=1;
166 apn_table[apn_count].netId=urc_response->netId;
167 apn_count++;
168 p.writeInt32(1);
169 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
170 p.writeInt32(0);//temporary plan
171 p.writeInt32(PDN_CONNECTED);
172 writeStringToParcel(p,urc_response->apnName);
173 writeStringToParcel(p,urc_response->apnType);
174 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800175 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
176#ifdef LED_SUPPORT
177 mbtk_netled_state_update(GPIO_NETLED_PPP_CONNECT);
178#endif
lh7b0674a2022-01-10 00:34:35 -0800179 }
180 else
181 {
ll62a2b402022-11-16 21:19:04 +0800182 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)//means apn state changed,need update
lh7b0674a2022-01-10 00:34:35 -0800183 {
ll62a2b402022-11-16 21:19:04 +0800184 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800185 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 +0800186 #endif
lh7b0674a2022-01-10 00:34:35 -0800187 RLOGD("for apn_table[%d].apn:%s,,,,urc_response->apnName:%s\n",i,apn_table[i].apn,urc_response->apnName);
188 if(strcmp(apn_table[i].apn,urc_response->apnName)==0)
189 {
ll62a2b402022-11-16 21:19:04 +0800190 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800191 printf("line %d This apn has been created update???!!!\n",__LINE__);
ll62a2b402022-11-16 21:19:04 +0800192 #endif
lh7b0674a2022-01-10 00:34:35 -0800193 RLOGD("This apn has been created!!!");
lh7b0674a2022-01-10 00:34:35 -0800194 apnHasCreated = TRUE;
195 if(apn_table[i].netId!=urc_response->netId)
196 {
ll62a2b402022-11-16 21:19:04 +0800197 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800198 printf("update???\n");
ll62a2b402022-11-16 21:19:04 +0800199 #endif
200 apn_table[i].netId = urc_response->netId;
201 apn_table[i].pdpstate = urc_response->pdnState;
202 memcpy(apn_table[i].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
203 memcpy(apn_table[i].address,urc_response->addresses,strlen(urc_response->addresses)+1);
lh7b0674a2022-01-10 00:34:35 -0800204 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
205 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
206 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
207 /*send urc to client
208 send apn_t,apnType_t,urc_response->pdnState,iface_t to client
209 */
210 p.writeInt32(1);
211 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
212 p.writeInt32(0);//temporary plan
213 p.writeInt32(urc_response->pdnState);
214 writeStringToParcel(p,apn_t);
215 writeStringToParcel(p,apnType_t);
216 writeStringToParcel(p,iface_t);
rjw7ee7bb42023-01-18 11:34:28 +0800217 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800218 }
219 break;
220 }
221 }
ll62a2b402022-11-16 21:19:04 +0800222 if(!apnHasCreated)//Multiple APNs are established new apn has created
lh7b0674a2022-01-10 00:34:35 -0800223 {
224 bool getLable = FALSE;
225 int lable = 0;
ll62a2b402022-11-16 21:19:04 +0800226 for(lable;lable < LYNQ_APN_CHANNEL_MAX;lable++)//to find not used array element subscript
lh7b0674a2022-01-10 00:34:35 -0800227 {
228 if(apn_table[lable].used==0)
229 {
230 getLable = TRUE;
231 break;
232 }
233 }
234 if(getLable)
235 {
ll62a2b402022-11-16 21:19:04 +0800236 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800237 printf("line %d Multiple APNs are established\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800238 #endif
lh7b0674a2022-01-10 00:34:35 -0800239 RLOGD("[getLable]:label==%d\n",lable);
240 memcpy(apn_table[lable].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
241 memcpy(apn_table[lable].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
242 memcpy(apn_table[lable].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
ll62a2b402022-11-16 21:19:04 +0800243 apn_table[lable].pdpstate = urc_response->pdnState;
244 memcpy(apn_table[lable].address,urc_response->addresses,strlen(urc_response->addresses)+1);
lh7b0674a2022-01-10 00:34:35 -0800245 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);
246 apn_table[lable].apnstatus=1;
247 apn_table[lable].used=1;
248 apn_table[lable].netId=urc_response->netId;
249 apn_count++;
250 p.writeInt32(1);
251 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
252 p.writeInt32(0);//temporary plan
253 p.writeInt32(urc_response->pdnState);
254 writeStringToParcel(p,urc_response->apnName);
255 writeStringToParcel(p,urc_response->apnType);
256 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800257 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800258 }
259 else
260 {
261 RLOGD("unkown error");
262 }
263 }
264 }
265 }
266 }
ll62a2b402022-11-16 21:19:04 +0800267 else //cid < 0 it means:when at+cfun=0 will into this or when connecting
lh7b0674a2022-01-10 00:34:35 -0800268 {
269 apnHasCreated = FALSE;
270 RLOGD("[cid < 0] apn_count:%d\n",apn_count);
Hong_Liudc46d412023-05-18 13:36:26 -0700271 if(urc_response->pdnState==PDN_DISCONNECTED)//if user disable data call,the pdn state wiil change to disconnected.
272 {
273 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
274 {
275 #if DEBUG
276 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);
277 #endif
278 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);
279 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0)&&(apn_table[i].apnstatus==0))
280 {
281 bzero(apn_table[i].apn,LYNQ_APN_LEN_MAX);
282 bzero(apn_table[i].apntype,LYNQ_APNTPYE_LEN_MAX);
283 apn_table[i].used = 0;
284 apn_table[i].netId = 0;
285 apn_table[i].pdpstate = PDN_DISCONNECTED;
286 apn_count--;
287 p.writeInt32 (1);
288 p.writeInt32 (LYNQ_URC_DATA_CALL_STATUS_IND);
289 p.writeInt32 (0);//temporary plan
290 p.writeInt32(PDN_DISCONNECTED);
291 writeStringToParcel(p,urc_response->apnName);
292 writeStringToParcel(p,urc_response->apnType);
293 writeStringToParcel(p,urc_response->ifname);
294 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
295 RLOGD("removed apn:%s,apntype:%s",apn_table[i].apn,apn_table[i].apntype);
296 break;
297 }
298 }
299 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
300 {
301 RLOGD("for apn_table[%d].apn:%s,apntype:%s,used:%d,apnstatus:%d\n",i,apn_table[i].apn,
302 apn_table[i].apntype,apn_table[i].used,apn_table[i].apnstatus);
Hong_Liu088a97e2023-06-05 07:48:17 -0700303 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0))
304 {
305 apn_table[i].pdpstate = urc_response->pdnState;
306 char ptr[1] = "";
307 if(NULL == urc_response->ifname)
308 {
309 memcpy(apn_table[i].ifaceName, ptr,strlen(ptr)+1);
310 }
311 if(NULL == urc_response->addresses)
312 {
313 memcpy(apn_table[i].address, ptr, strlen(ptr)+1);
314 }
315 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
316 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
317 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
318 p.writeInt32(1);
319 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
320 p.writeInt32(0);//temporary plan
321 p.writeInt32(urc_response->pdnState);
322 writeStringToParcel(p,apn_t);
323 writeStringToParcel(p,apnType_t);
324 writeStringToParcel(p,iface_t);
325 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
326 RLOGD("cid is %d apn:%s,apntype:%s",urc_response->cId,apn_table[i].apn,apn_table[i].apntype);
327 }
Hong_Liudc46d412023-05-18 13:36:26 -0700328 }
329 return 0;
330 }
lh7b0674a2022-01-10 00:34:35 -0800331 if(apn_count>0)
332 {
333 int i = 0;
334 for(i;i < LYNQ_APN_CHANNEL_MAX;i++)
335 {
ll62a2b402022-11-16 21:19:04 +0800336 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800337 printf("line %d don't know\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800338 #endif
lh7b0674a2022-01-10 00:34:35 -0800339 RLOGD("[cid<0]apn_table[%d].apntype:%s,,,,urc_response->apntype:%s\n",i,apn_table[i].apntype,urc_response->apnType);
340 if(strcmp(apn_table[i].apntype,urc_response->apnType)==0)
341 {
342 RLOGD("apntype:%s PDN status has changed!!!\n",urc_response->apnType);
343 apnHasCreated = TRUE;
344 break;
345 }
346 }
347 if(apnHasCreated)
348 {
ll62a2b402022-11-16 21:19:04 +0800349 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800350 printf("line %d don't know\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800351 #endif
352 apn_table[i].pdpstate = urc_response->pdnState;
353 char ptr[1] = "";
354 if(NULL == urc_response->ifname)
355 {
356 memcpy(apn_table[i].ifaceName, ptr,strlen(ptr)+1);
357 }
358 if(NULL == urc_response->addresses)
359 {
360 memcpy(apn_table[i].address, ptr, strlen(ptr)+1);
361 }
lh7b0674a2022-01-10 00:34:35 -0800362 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
363 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
364 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
365 p.writeInt32(1);
366 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
367 p.writeInt32(0);//temporary plan
368 p.writeInt32(urc_response->pdnState);
369 writeStringToParcel(p,apn_t);
370 writeStringToParcel(p,apnType_t);
371 writeStringToParcel(p,iface_t);
rjw7ee7bb42023-01-18 11:34:28 +0800372 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800373 }
374 }
375 }
376 return 0;
377}
378/*Warren add for t800 ril service 2021/12/25 end*/
379void freeMem(MTK_Data_Call_Response_v1 response)
380{
381 g_free(response.apnType);
382 g_free(response.type);
383 g_free(response.ifname);
384 g_free(response.addresses);
385 g_free(response.dnses);
386 g_free(response.gateways);
387 g_free(response.pcscf);
388}
389
390char* apnState2string(RIL_Data_Call_PdnState apnState) {
391 switch (apnState) {
392 case RIL_Data_Call_PdnState::PDN_CONNECTED:
393 return "PDN_CONNECTED";
394 case RIL_Data_Call_PdnState::PDN_CONNECTING:
395 return "PDN_CONNECTING";
396 case RIL_Data_Call_PdnState::PDN_DISCONNECTED:
397 return "PDN_DISCONNECTED";
398 case RIL_Data_Call_PdnState::PDN_DISCONNECTING:
399 return "PDN_DISCONNECTING";
400 case RIL_Data_Call_PdnState::PDN_FAILED:
401 return "PDN_FAILED";
402 case RIL_Data_Call_PdnState::PDN_IDLE:
403 return "PDN_IDLE";
404 case RIL_Data_Call_PdnState::PDN_RETRYING:
405 return "PDN_RETRYING";
406 case RIL_Data_Call_PdnState::PDN_SCANNING:
407 return "PDN_SCANNING";
408 default:
409 return "UNKNOWN";
410 }
411}
412
413void dumpResponse(MTK_Data_Call_Response_v1 *dataCallResponse)
414{
415 RLOGD("dumpResponse: netId: %d, pdnState: %s, status: %d, cId: %d, apnType: %s,"
416 " protocolType: %s, ifaceName: %s, address: %s, dns: %s, gateway: %s, pcscf: %s, mtu: %d, apn: %s",
417 dataCallResponse->netId, apnState2string(RIL_Data_Call_PdnState(dataCallResponse->pdnState)),
418 dataCallResponse->status, dataCallResponse->cId, dataCallResponse->apnType, dataCallResponse->type,
419 dataCallResponse->ifname, dataCallResponse->addresses, dataCallResponse->dnses,
420 dataCallResponse->gateways, dataCallResponse->pcscf, dataCallResponse->mtu, dataCallResponse->apnName);
421}
422
423void parse(GVariant* result, MTK_Data_Call_Response_v1* data) {
424 g_variant_get(result, "((iiiisssssssis))", &(data->netId),
425 &(data->pdnState), &(data->status),
426 &(data->cId), &(data->apnType), &(data->type),
427 &(data->ifname), &(data->addresses),
428 &(data->dnses), &(data->gateways),
429 &(data->pcscf), &(data->mtu),&(data->apnName));
430}
431
432void proxy_method_cb (GDBusProxy *proxy,
433 GAsyncResult *res,
434 gpointer user_data)
435{
436 RLOGD("method call back");
437 GError *error;
438 GVariant *result;
439
440 error = NULL;
441 result = g_dbus_proxy_call_finish(proxy, res, &error);
442
443 if(error != NULL)
444 {
445 RLOGD("method call back error %s", error->message);
446 g_error_free(error);
447 return;
448 }
449 freeMem(req_response);
450 parse(result, &req_response);
451 dumpResponse(&req_response);
452 g_variant_unref(result);
453}
454
455int enableData (bool isEnable, gchar *apn_type)
456{
457 RLOGD("send: %s, %s", (isEnable ? "TRUE": "FALSE"), apn_type);
458 g_dbus_proxy_call(proxy,
459 "enableData",
460 g_variant_new("(bs)", isEnable, apn_type),
461 G_DBUS_CALL_FLAGS_NONE,
462 -1,
463 NULL,
464 (GAsyncReadyCallback) proxy_method_cb,
465 NULL);
466 return 1;
467}
rjw20006d12022-04-21 16:29:04 +0800468/*Typethree add for t800 RIL Service 2022/04/14 start*/
lh7b0674a2022-01-10 00:34:35 -0800469void modifyApnDB_method_cb (GDBusProxy *proxy,
470 GAsyncResult *res,
471 gpointer user_data)
472{
473 RLOGD("method call back");
474 GError *error;
475 GVariant *result;
476 gchar* reason = NULL;
477
478 error = NULL;
479 result = g_dbus_proxy_call_finish(proxy, res, &error);
480
481 if(error != NULL)
482 {
483 RLOGD("method call back error %s", error->message);
484 printf("modify apn db error: %s\n", error->message);
rjw20006d12022-04-21 16:29:04 +0800485 lynq_data_modify_apn(error->message,LYNQ_URC_MODIFY_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800486 g_error_free(error);
487 return;
488 }
489 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
490 g_variant_get (result, "(&s)", &reason);
491 RLOGD("modifyApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
492 printf("modify apn db success, return message: %s\n", ((reason == NULL)? "":reason));
493 //printf("modifyApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
ll6e73f202022-12-28 14:59:46 +0800494 /*lei add for AT+LEAPNMOD*/
llf6e3ffd2023-01-12 22:31:29 +0800495 if(g_flag_apn)
496 {
497 char apn_buf[256];
498 sprintf(apn_buf, "+LEAPNMOD:%s", ((reason == NULL)? "":reason));
499 ATCIResponseNoToken(0, apn_buf, 666);//tmp plan
500 }
ll6e73f202022-12-28 14:59:46 +0800501 /*lei add for AT+LEAPNMOD*/
lh7b0674a2022-01-10 00:34:35 -0800502 g_variant_unref(result);
rjw20006d12022-04-21 16:29:04 +0800503 lynq_data_modify_apn(reason,LYNQ_URC_MODIFY_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800504}
505
506int modifyApnDB(int cmd, gchar *record) {
507 RLOGD("%s: cmd: %d, record:%s", __FUNCTION__, cmd, record);
508 g_dbus_proxy_call(proxy,
509 "modifyApnDB",
510 g_variant_new("(is)", cmd, record),
511 G_DBUS_CALL_FLAGS_NONE,
512 -1,
513 NULL,
514 (GAsyncReadyCallback) modifyApnDB_method_cb,
515 NULL);
516 return 1;
517}
518
519void resetApnDB_method_cb (GDBusProxy *proxy,
520 GAsyncResult *res,
521 gpointer user_data)
522{
523 RLOGD("resetApnDB_method_cb call back");
524 GError *error;
525 GVariant *result;
526 gchar* reason = NULL;
527
528 error = NULL;
529 result = g_dbus_proxy_call_finish(proxy, res, &error);
530
531 if(error != NULL)
532 {
533 RLOGD("method call back error %s", error->message);
534 printf("reset apn DB error: %s\n", error->message);
rjw20006d12022-04-21 16:29:04 +0800535 lynq_data_modify_apn(error->message,LYNQ_URC_RESET_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800536 g_error_free(error);
537 return;
538 }
539 g_variant_get (result, "(&s)", &reason);
540 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
541 RLOGD("resetApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
542 printf("reset apn DB success, return message: %s\n", ((reason == NULL)? "":reason));
543 //printf("resetApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
544 g_variant_unref(result);
rjw20006d12022-04-21 16:29:04 +0800545 lynq_data_modify_apn(reason,LYNQ_URC_RESET_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800546}
rjw20006d12022-04-21 16:29:04 +0800547/*Typethree add for t800 RIL Service 2022/04/14 end*/
lh7b0674a2022-01-10 00:34:35 -0800548
549int resetApnDB() {
550 RLOGD("%s", __FUNCTION__);
551 g_dbus_proxy_call(proxy,
552 "resetApnDB",NULL,
553 G_DBUS_CALL_FLAGS_NONE,
554 -1,
555 NULL,
556 (GAsyncReadyCallback) resetApnDB_method_cb,
557 NULL);
558 return 1;
559}
560
ll90a255c2022-04-07 09:09:55 +0000561
lh7b0674a2022-01-10 00:34:35 -0800562void proxy_signals_on_signal (GDBusProxy *proxy,
563 const gchar *sender_name,
564 const gchar *signal_name,
565 GVariant *parameters,
566 gpointer user_data)
567{
568 RLOGD("signal_name: %s", signal_name);
569 printf("signal_name: %s\n", signal_name);
570 freeMem(urc_response);
571 parse(parameters, &urc_response);
572 dumpResponse(&urc_response);
573 if(g_strcmp0(signal_name, "lynq_data_resp") == 0)
574 {
575 printf("[lynq_data_resp]do something\n");
576 return;
577 }
578 lynq_data_management(&urc_response);
579 if(g_strcmp0(signal_name, "LYNQ_TEST") == 0)
580 {
581 printf("do something\n");
582 }
583 if(g_strcmp0(signal_name, "default") == 0)
584 {
585 if(urc_response.pdnState == RIL_Data_Call_PdnState::PDN_DISCONNECTED) {
586 notifyDataSignal();
xja1c30b82022-01-25 16:13:48 +0800587 } else if (urc_response.pdnState == RIL_Data_Call_PdnState::PDN_FAILED) {
588 updataDataConnectState(get_default_sim_data(), false);
lh7b0674a2022-01-10 00:34:35 -0800589 }
590 }
591 return;
592
593}
594
595void proxy_ready(GObject *source, GAsyncResult *result, gpointer user_data) {
596 GError *error;
597
598 error = NULL;
599 proxy = g_dbus_proxy_new_for_bus_finish(result, &error);
600 if (proxy == NULL) {
601 RLOGE("create proxy fail");
602 return ;
603 }
604 RLOGD("proxy is ready");
605 gulong signal_handler_id;
606
607 signal_handler_id = g_signal_connect(proxy, "g-signal",
608 G_CALLBACK (proxy_signals_on_signal), NULL);
609 if (signal_handler_id == 0) {
610 RLOGE("listen singal fail!");
611 }
612}
613
614void* init_data_gdbus_cb(void *param)
615{
616 /* all the tests rely on a shared main loop */
617 loop = g_main_loop_new(NULL, FALSE);
618
619 g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
620 G_DBUS_PROXY_FLAGS_NONE,
621 NULL, /* GDBusInterfaceInfo */
622 TELEPHONY_SERVICE, /* name */
623 TELEPHONY_DATA_PATH, /* object path */
624 TELEPHONY_DATA_INTERFACE, /* interface */
625 NULL, /* GCancellable */
626 proxy_ready,
627 NULL);
628
629 g_main_loop_run(loop);
630
631 RLOGD("data gdbus main loop run()");
632 if(proxy != NULL) {
633 g_object_unref (proxy);
634 }
635 if(loop != NULL) {
636 g_main_loop_unref(loop);
637 }
xja1c30b82022-01-25 16:13:48 +0800638 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800639}
640