blob: d6fb6cd27d313f858fbc3dda45edf6e05276a2a7 [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);
xy.he5cb8fd22023-10-23 07:20:54 -0700124 bzero(apn_table[i].ifaceName,LYNQ_APNTPYE_LEN_MAX);
ll62a2b402022-11-16 21:19:04 +0800125 apn_table[i].used = 0;
126 apn_table[i].netId = 0;
127 apn_table[i].pdpstate = PDN_DISCONNECTED;
lh7b0674a2022-01-10 00:34:35 -0800128 apn_count--;
129 p.writeInt32 (1);
130 p.writeInt32 (LYNQ_URC_DATA_CALL_STATUS_IND);
131 p.writeInt32 (0);//temporary plan
132 p.writeInt32(PDN_DISCONNECTED);
Hong_Liu6149f182023-05-12 02:15:14 -0700133 writeStringToParcel(p,urc_response->apnName);
rjw5d2a50e2022-02-28 15:01:49 +0800134 writeStringToParcel(p,urc_response->apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700135 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800136 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800137 RLOGD("removed apn:%s,apntype:%s",apn_table[i].apn,apn_table[i].apntype);
lh7b0674a2022-01-10 00:34:35 -0800138 break;
139 }
140 }
141 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
142 {
143 RLOGD("for apn_table[%d].apn:%s,apntype:%s,used:%d,apnstatus:%d\n",i,apn_table[i].apn,
144 apn_table[i].apntype,apn_table[i].used,apn_table[i].apnstatus);
145 }
146 }
147 else
148 {
149 /*if the pdn status change,tele-fwk will send pdn status to me.
150 **The reason for the status change may be that enable data call,
151 **the user disable the data call, and the signal is interrupted.
152 */
153 if(apn_count==0)//first new apn has created
154 {
155 RLOGD("first apn_count:%d\n",apn_count);
156 memcpy(apn_table[apn_count].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
157 memcpy(apn_table[apn_count].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
158 memcpy(apn_table[apn_count].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
ll62a2b402022-11-16 21:19:04 +0800159 memcpy(apn_table[apn_count].address,urc_response->addresses,strlen(urc_response->addresses)+1);
160 apn_table[apn_count].pdpstate = urc_response->pdnState;
161 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800162 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 +0800163 #endif
lh7b0674a2022-01-10 00:34:35 -0800164 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);
165 apn_table[apn_count].apnstatus=1;
166 apn_table[apn_count].used=1;
167 apn_table[apn_count].netId=urc_response->netId;
168 apn_count++;
169 p.writeInt32(1);
170 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
171 p.writeInt32(0);//temporary plan
172 p.writeInt32(PDN_CONNECTED);
173 writeStringToParcel(p,urc_response->apnName);
174 writeStringToParcel(p,urc_response->apnType);
175 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800176 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
177#ifdef LED_SUPPORT
178 mbtk_netled_state_update(GPIO_NETLED_PPP_CONNECT);
179#endif
lh7b0674a2022-01-10 00:34:35 -0800180 }
181 else
182 {
ll62a2b402022-11-16 21:19:04 +0800183 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)//means apn state changed,need update
lh7b0674a2022-01-10 00:34:35 -0800184 {
ll62a2b402022-11-16 21:19:04 +0800185 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800186 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 +0800187 #endif
Hong_Liu8d77acf2023-08-30 02:11:09 -0700188 RLOGD("for apn_table[%d].apntype:%s,,,,urc_response->apnType:%s\n",i,apn_table[i].apntype,urc_response->apnType);
189 if(strcmp(apn_table[i].apntype,urc_response->apnType)==0)
lh7b0674a2022-01-10 00:34:35 -0800190 {
ll62a2b402022-11-16 21:19:04 +0800191 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800192 printf("line %d This apn has been created update???!!!\n",__LINE__);
ll62a2b402022-11-16 21:19:04 +0800193 #endif
lh7b0674a2022-01-10 00:34:35 -0800194 RLOGD("This apn has been created!!!");
lh7b0674a2022-01-10 00:34:35 -0800195 apnHasCreated = TRUE;
196 if(apn_table[i].netId!=urc_response->netId)
197 {
ll62a2b402022-11-16 21:19:04 +0800198 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800199 printf("update???\n");
ll62a2b402022-11-16 21:19:04 +0800200 #endif
201 apn_table[i].netId = urc_response->netId;
202 apn_table[i].pdpstate = urc_response->pdnState;
203 memcpy(apn_table[i].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
204 memcpy(apn_table[i].address,urc_response->addresses,strlen(urc_response->addresses)+1);
lh7b0674a2022-01-10 00:34:35 -0800205 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
206 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
207 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
208 /*send urc to client
209 send apn_t,apnType_t,urc_response->pdnState,iface_t to client
210 */
211 p.writeInt32(1);
212 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
213 p.writeInt32(0);//temporary plan
214 p.writeInt32(urc_response->pdnState);
215 writeStringToParcel(p,apn_t);
216 writeStringToParcel(p,apnType_t);
217 writeStringToParcel(p,iface_t);
rjw7ee7bb42023-01-18 11:34:28 +0800218 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800219 }
220 break;
221 }
222 }
ll62a2b402022-11-16 21:19:04 +0800223 if(!apnHasCreated)//Multiple APNs are established new apn has created
lh7b0674a2022-01-10 00:34:35 -0800224 {
225 bool getLable = FALSE;
226 int lable = 0;
ll62a2b402022-11-16 21:19:04 +0800227 for(lable;lable < LYNQ_APN_CHANNEL_MAX;lable++)//to find not used array element subscript
lh7b0674a2022-01-10 00:34:35 -0800228 {
229 if(apn_table[lable].used==0)
230 {
231 getLable = TRUE;
232 break;
233 }
234 }
235 if(getLable)
236 {
ll62a2b402022-11-16 21:19:04 +0800237 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800238 printf("line %d Multiple APNs are established\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800239 #endif
lh7b0674a2022-01-10 00:34:35 -0800240 RLOGD("[getLable]:label==%d\n",lable);
241 memcpy(apn_table[lable].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
242 memcpy(apn_table[lable].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
243 memcpy(apn_table[lable].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
ll62a2b402022-11-16 21:19:04 +0800244 apn_table[lable].pdpstate = urc_response->pdnState;
245 memcpy(apn_table[lable].address,urc_response->addresses,strlen(urc_response->addresses)+1);
lh7b0674a2022-01-10 00:34:35 -0800246 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);
247 apn_table[lable].apnstatus=1;
248 apn_table[lable].used=1;
249 apn_table[lable].netId=urc_response->netId;
250 apn_count++;
251 p.writeInt32(1);
252 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
253 p.writeInt32(0);//temporary plan
254 p.writeInt32(urc_response->pdnState);
255 writeStringToParcel(p,urc_response->apnName);
256 writeStringToParcel(p,urc_response->apnType);
257 writeStringToParcel(p,urc_response->ifname);
rjw7ee7bb42023-01-18 11:34:28 +0800258 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800259 }
260 else
261 {
262 RLOGD("unkown error");
263 }
264 }
265 }
266 }
267 }
ll62a2b402022-11-16 21:19:04 +0800268 else //cid < 0 it means:when at+cfun=0 will into this or when connecting
lh7b0674a2022-01-10 00:34:35 -0800269 {
270 apnHasCreated = FALSE;
271 RLOGD("[cid < 0] apn_count:%d\n",apn_count);
Hong_Liudc46d412023-05-18 13:36:26 -0700272 if(urc_response->pdnState==PDN_DISCONNECTED)//if user disable data call,the pdn state wiil change to disconnected.
273 {
274 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
275 {
276 #if DEBUG
277 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);
278 #endif
279 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);
280 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0)&&(apn_table[i].apnstatus==0))
281 {
282 bzero(apn_table[i].apn,LYNQ_APN_LEN_MAX);
283 bzero(apn_table[i].apntype,LYNQ_APNTPYE_LEN_MAX);
xy.he5cb8fd22023-10-23 07:20:54 -0700284 bzero(apn_table[i].ifaceName,LYNQ_APNTPYE_LEN_MAX);
Hong_Liudc46d412023-05-18 13:36:26 -0700285 apn_table[i].used = 0;
286 apn_table[i].netId = 0;
287 apn_table[i].pdpstate = PDN_DISCONNECTED;
288 apn_count--;
289 p.writeInt32 (1);
290 p.writeInt32 (LYNQ_URC_DATA_CALL_STATUS_IND);
291 p.writeInt32 (0);//temporary plan
292 p.writeInt32(PDN_DISCONNECTED);
293 writeStringToParcel(p,urc_response->apnName);
294 writeStringToParcel(p,urc_response->apnType);
295 writeStringToParcel(p,urc_response->ifname);
296 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
297 RLOGD("removed apn:%s,apntype:%s",apn_table[i].apn,apn_table[i].apntype);
298 break;
299 }
300 }
301 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
302 {
303 RLOGD("for apn_table[%d].apn:%s,apntype:%s,used:%d,apnstatus:%d\n",i,apn_table[i].apn,
304 apn_table[i].apntype,apn_table[i].used,apn_table[i].apnstatus);
Hong_Liu088a97e2023-06-05 07:48:17 -0700305 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0))
306 {
307 apn_table[i].pdpstate = urc_response->pdnState;
308 char ptr[1] = "";
309 if(NULL == urc_response->ifname)
310 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700311 memset(iface_t,0,LYNQ_APNTPYE_LEN_MAX);
312 memset(apn_table[i].ifaceName,0,LYNQ_APNTPYE_LEN_MAX);
313 }
314 else
315 {
316 memcpy(iface_t,urc_response->ifname,strlen(urc_response->ifname)+1);
xy.he5cb8fd22023-10-23 07:20:54 -0700317 memcpy(apn_table[i].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
Hong_Liu088a97e2023-06-05 07:48:17 -0700318 }
319 if(NULL == urc_response->addresses)
320 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700321 memset(apn_table[i].address,0,LYNQ_APNTPYE_LEN_MAX);
Hong_Liu088a97e2023-06-05 07:48:17 -0700322 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700323 memcpy(apnType_t,urc_response->apnType,strlen(urc_response->apnType)+1);
324 memcpy(apn_t,urc_response->apnName,strlen(urc_response->apnName)+1);
Hong_Liu088a97e2023-06-05 07:48:17 -0700325 p.writeInt32(1);
326 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
327 p.writeInt32(0);//temporary plan
328 p.writeInt32(urc_response->pdnState);
329 writeStringToParcel(p,apn_t);
330 writeStringToParcel(p,apnType_t);
331 writeStringToParcel(p,iface_t);
332 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
333 RLOGD("cid is %d apn:%s,apntype:%s",urc_response->cId,apn_table[i].apn,apn_table[i].apntype);
334 }
Hong_Liudc46d412023-05-18 13:36:26 -0700335 }
336 return 0;
337 }
lh7b0674a2022-01-10 00:34:35 -0800338 if(apn_count>0)
339 {
340 int i = 0;
341 for(i;i < LYNQ_APN_CHANNEL_MAX;i++)
342 {
ll62a2b402022-11-16 21:19:04 +0800343 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800344 printf("line %d don't know\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800345 #endif
lh7b0674a2022-01-10 00:34:35 -0800346 RLOGD("[cid<0]apn_table[%d].apntype:%s,,,,urc_response->apntype:%s\n",i,apn_table[i].apntype,urc_response->apnType);
347 if(strcmp(apn_table[i].apntype,urc_response->apnType)==0)
348 {
349 RLOGD("apntype:%s PDN status has changed!!!\n",urc_response->apnType);
350 apnHasCreated = TRUE;
351 break;
352 }
353 }
354 if(apnHasCreated)
355 {
ll62a2b402022-11-16 21:19:04 +0800356 #if DEBUG
ll6e73f202022-12-28 14:59:46 +0800357 printf("line %d don't know\n", __LINE__);
ll62a2b402022-11-16 21:19:04 +0800358 #endif
359 apn_table[i].pdpstate = urc_response->pdnState;
360 char ptr[1] = "";
361 if(NULL == urc_response->ifname)
362 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700363 memset(iface_t,0,LYNQ_APNTPYE_LEN_MAX);
364 memset(apn_table[i].ifaceName,0,LYNQ_APNTPYE_LEN_MAX);
365 }
366 else
367 {
368 memcpy(iface_t,urc_response->ifname,strlen(urc_response->ifname)+1);
xy.he5cb8fd22023-10-23 07:20:54 -0700369 memcpy(apn_table[i].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
ll62a2b402022-11-16 21:19:04 +0800370 }
371 if(NULL == urc_response->addresses)
372 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700373 memset(apn_table[i].address,0,LYNQ_APNTPYE_LEN_MAX);
ll62a2b402022-11-16 21:19:04 +0800374 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700375 memcpy(apnType_t,urc_response->apnType,strlen(urc_response->apnType)+1);
376 memcpy(apn_t,urc_response->apnName,strlen(urc_response->apnName)+1);
lh7b0674a2022-01-10 00:34:35 -0800377 p.writeInt32(1);
378 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
379 p.writeInt32(0);//temporary plan
380 p.writeInt32(urc_response->pdnState);
381 writeStringToParcel(p,apn_t);
382 writeStringToParcel(p,apnType_t);
383 writeStringToParcel(p,iface_t);
rjw7ee7bb42023-01-18 11:34:28 +0800384 android::LYNQ_RIL_urcBroadcast(p,LYNQ_URC_DATA_CALL_STATUS_IND);
lh7b0674a2022-01-10 00:34:35 -0800385 }
386 }
387 }
388 return 0;
389}
390/*Warren add for t800 ril service 2021/12/25 end*/
391void freeMem(MTK_Data_Call_Response_v1 response)
392{
393 g_free(response.apnType);
394 g_free(response.type);
395 g_free(response.ifname);
396 g_free(response.addresses);
397 g_free(response.dnses);
398 g_free(response.gateways);
399 g_free(response.pcscf);
400}
401
402char* apnState2string(RIL_Data_Call_PdnState apnState) {
403 switch (apnState) {
404 case RIL_Data_Call_PdnState::PDN_CONNECTED:
405 return "PDN_CONNECTED";
406 case RIL_Data_Call_PdnState::PDN_CONNECTING:
407 return "PDN_CONNECTING";
408 case RIL_Data_Call_PdnState::PDN_DISCONNECTED:
409 return "PDN_DISCONNECTED";
410 case RIL_Data_Call_PdnState::PDN_DISCONNECTING:
411 return "PDN_DISCONNECTING";
412 case RIL_Data_Call_PdnState::PDN_FAILED:
413 return "PDN_FAILED";
414 case RIL_Data_Call_PdnState::PDN_IDLE:
415 return "PDN_IDLE";
416 case RIL_Data_Call_PdnState::PDN_RETRYING:
417 return "PDN_RETRYING";
418 case RIL_Data_Call_PdnState::PDN_SCANNING:
419 return "PDN_SCANNING";
420 default:
421 return "UNKNOWN";
422 }
423}
424
425void dumpResponse(MTK_Data_Call_Response_v1 *dataCallResponse)
426{
427 RLOGD("dumpResponse: netId: %d, pdnState: %s, status: %d, cId: %d, apnType: %s,"
428 " protocolType: %s, ifaceName: %s, address: %s, dns: %s, gateway: %s, pcscf: %s, mtu: %d, apn: %s",
429 dataCallResponse->netId, apnState2string(RIL_Data_Call_PdnState(dataCallResponse->pdnState)),
430 dataCallResponse->status, dataCallResponse->cId, dataCallResponse->apnType, dataCallResponse->type,
431 dataCallResponse->ifname, dataCallResponse->addresses, dataCallResponse->dnses,
432 dataCallResponse->gateways, dataCallResponse->pcscf, dataCallResponse->mtu, dataCallResponse->apnName);
433}
434
435void parse(GVariant* result, MTK_Data_Call_Response_v1* data) {
436 g_variant_get(result, "((iiiisssssssis))", &(data->netId),
437 &(data->pdnState), &(data->status),
438 &(data->cId), &(data->apnType), &(data->type),
439 &(data->ifname), &(data->addresses),
440 &(data->dnses), &(data->gateways),
441 &(data->pcscf), &(data->mtu),&(data->apnName));
442}
443
444void proxy_method_cb (GDBusProxy *proxy,
445 GAsyncResult *res,
446 gpointer user_data)
447{
448 RLOGD("method call back");
449 GError *error;
450 GVariant *result;
451
452 error = NULL;
453 result = g_dbus_proxy_call_finish(proxy, res, &error);
454
455 if(error != NULL)
456 {
457 RLOGD("method call back error %s", error->message);
458 g_error_free(error);
459 return;
460 }
461 freeMem(req_response);
462 parse(result, &req_response);
463 dumpResponse(&req_response);
464 g_variant_unref(result);
465}
466
467int enableData (bool isEnable, gchar *apn_type)
468{
469 RLOGD("send: %s, %s", (isEnable ? "TRUE": "FALSE"), apn_type);
470 g_dbus_proxy_call(proxy,
471 "enableData",
472 g_variant_new("(bs)", isEnable, apn_type),
473 G_DBUS_CALL_FLAGS_NONE,
474 -1,
475 NULL,
476 (GAsyncReadyCallback) proxy_method_cb,
477 NULL);
478 return 1;
479}
rjw20006d12022-04-21 16:29:04 +0800480/*Typethree add for t800 RIL Service 2022/04/14 start*/
lh7b0674a2022-01-10 00:34:35 -0800481void modifyApnDB_method_cb (GDBusProxy *proxy,
482 GAsyncResult *res,
483 gpointer user_data)
484{
485 RLOGD("method call back");
486 GError *error;
487 GVariant *result;
488 gchar* reason = NULL;
489
490 error = NULL;
491 result = g_dbus_proxy_call_finish(proxy, res, &error);
492
493 if(error != NULL)
494 {
495 RLOGD("method call back error %s", error->message);
496 printf("modify apn db error: %s\n", error->message);
rjw20006d12022-04-21 16:29:04 +0800497 lynq_data_modify_apn(error->message,LYNQ_URC_MODIFY_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800498 g_error_free(error);
499 return;
500 }
501 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
502 g_variant_get (result, "(&s)", &reason);
503 RLOGD("modifyApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
504 printf("modify apn db success, return message: %s\n", ((reason == NULL)? "":reason));
505 //printf("modifyApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
ll6e73f202022-12-28 14:59:46 +0800506 /*lei add for AT+LEAPNMOD*/
llf6e3ffd2023-01-12 22:31:29 +0800507 if(g_flag_apn)
508 {
509 char apn_buf[256];
510 sprintf(apn_buf, "+LEAPNMOD:%s", ((reason == NULL)? "":reason));
511 ATCIResponseNoToken(0, apn_buf, 666);//tmp plan
512 }
ll6e73f202022-12-28 14:59:46 +0800513 /*lei add for AT+LEAPNMOD*/
lh7b0674a2022-01-10 00:34:35 -0800514 g_variant_unref(result);
rjw20006d12022-04-21 16:29:04 +0800515 lynq_data_modify_apn(reason,LYNQ_URC_MODIFY_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800516}
517
518int modifyApnDB(int cmd, gchar *record) {
519 RLOGD("%s: cmd: %d, record:%s", __FUNCTION__, cmd, record);
520 g_dbus_proxy_call(proxy,
521 "modifyApnDB",
522 g_variant_new("(is)", cmd, record),
523 G_DBUS_CALL_FLAGS_NONE,
524 -1,
525 NULL,
526 (GAsyncReadyCallback) modifyApnDB_method_cb,
527 NULL);
528 return 1;
529}
530
531void resetApnDB_method_cb (GDBusProxy *proxy,
532 GAsyncResult *res,
533 gpointer user_data)
534{
535 RLOGD("resetApnDB_method_cb call back");
536 GError *error;
537 GVariant *result;
538 gchar* reason = NULL;
539
540 error = NULL;
541 result = g_dbus_proxy_call_finish(proxy, res, &error);
542
543 if(error != NULL)
544 {
545 RLOGD("method call back error %s", error->message);
546 printf("reset apn DB error: %s\n", error->message);
rjw20006d12022-04-21 16:29:04 +0800547 lynq_data_modify_apn(error->message,LYNQ_URC_RESET_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800548 g_error_free(error);
549 return;
550 }
551 g_variant_get (result, "(&s)", &reason);
552 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
553 RLOGD("resetApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
554 printf("reset apn DB success, return message: %s\n", ((reason == NULL)? "":reason));
555 //printf("resetApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
556 g_variant_unref(result);
rjw20006d12022-04-21 16:29:04 +0800557 lynq_data_modify_apn(reason,LYNQ_URC_RESET_APNDB);
lh7b0674a2022-01-10 00:34:35 -0800558}
rjw20006d12022-04-21 16:29:04 +0800559/*Typethree add for t800 RIL Service 2022/04/14 end*/
lh7b0674a2022-01-10 00:34:35 -0800560
561int resetApnDB() {
562 RLOGD("%s", __FUNCTION__);
563 g_dbus_proxy_call(proxy,
564 "resetApnDB",NULL,
565 G_DBUS_CALL_FLAGS_NONE,
566 -1,
567 NULL,
568 (GAsyncReadyCallback) resetApnDB_method_cb,
569 NULL);
570 return 1;
571}
572
ll90a255c2022-04-07 09:09:55 +0000573
lh7b0674a2022-01-10 00:34:35 -0800574void proxy_signals_on_signal (GDBusProxy *proxy,
575 const gchar *sender_name,
576 const gchar *signal_name,
577 GVariant *parameters,
578 gpointer user_data)
579{
580 RLOGD("signal_name: %s", signal_name);
581 printf("signal_name: %s\n", signal_name);
582 freeMem(urc_response);
583 parse(parameters, &urc_response);
584 dumpResponse(&urc_response);
585 if(g_strcmp0(signal_name, "lynq_data_resp") == 0)
586 {
587 printf("[lynq_data_resp]do something\n");
588 return;
589 }
590 lynq_data_management(&urc_response);
591 if(g_strcmp0(signal_name, "LYNQ_TEST") == 0)
592 {
593 printf("do something\n");
594 }
595 if(g_strcmp0(signal_name, "default") == 0)
596 {
597 if(urc_response.pdnState == RIL_Data_Call_PdnState::PDN_DISCONNECTED) {
598 notifyDataSignal();
xja1c30b82022-01-25 16:13:48 +0800599 } else if (urc_response.pdnState == RIL_Data_Call_PdnState::PDN_FAILED) {
600 updataDataConnectState(get_default_sim_data(), false);
lh7b0674a2022-01-10 00:34:35 -0800601 }
602 }
603 return;
604
605}
606
607void proxy_ready(GObject *source, GAsyncResult *result, gpointer user_data) {
608 GError *error;
609
610 error = NULL;
611 proxy = g_dbus_proxy_new_for_bus_finish(result, &error);
612 if (proxy == NULL) {
613 RLOGE("create proxy fail");
614 return ;
615 }
616 RLOGD("proxy is ready");
617 gulong signal_handler_id;
618
619 signal_handler_id = g_signal_connect(proxy, "g-signal",
620 G_CALLBACK (proxy_signals_on_signal), NULL);
621 if (signal_handler_id == 0) {
622 RLOGE("listen singal fail!");
623 }
624}
625
626void* init_data_gdbus_cb(void *param)
627{
628 /* all the tests rely on a shared main loop */
629 loop = g_main_loop_new(NULL, FALSE);
630
631 g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
632 G_DBUS_PROXY_FLAGS_NONE,
633 NULL, /* GDBusInterfaceInfo */
634 TELEPHONY_SERVICE, /* name */
635 TELEPHONY_DATA_PATH, /* object path */
636 TELEPHONY_DATA_INTERFACE, /* interface */
637 NULL, /* GCancellable */
638 proxy_ready,
639 NULL);
640
641 g_main_loop_run(loop);
642
643 RLOGD("data gdbus main loop run()");
644 if(proxy != NULL) {
645 g_object_unref (proxy);
646 }
647 if(loop != NULL) {
648 g_main_loop_unref(loop);
649 }
xja1c30b82022-01-25 16:13:48 +0800650 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800651}
652