blob: 3d067b82d32fcf54fec3c01cf384f9fd4e20049d [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>
51using android::Parcel;
52
53/*Warren add for t800 ril service 2021/12/25 end*/
54
55#define LOG_TAG "DEMO_DATA_GDBUS"
56#define TELEPHONY_SERVICE "mtk.telephony" /*well-known bus name */
57#define TELEPHONY_DATA_INTERFACE "mtk.telephony.Data" /*interface name*/
58#define TELEPHONY_DATA_PATH "/mtk/telephony/data" /*object name*/
59
60GMainLoop *loop = NULL;
61GDBusProxy *proxy = NULL;
62MTK_Data_Call_Response_v1 req_response;
63MTK_Data_Call_Response_v1 urc_response;
64/*Warren add for t800 ril service 2021/12/25 start*/
65int lynq_data_management(MTK_Data_Call_Response_v1 *urc_response)
66{
67 char apn_t[LYNQ_APN_LEN_MAX] = {};
68 char apnType_t[LYNQ_APNTPYE_LEN_MAX] = {};
69 char iface_t[LYNQ_APNTPYE_LEN_MAX] = {};
70 if(!urc_response)
71 {
72 RLOGD("urc_response is null!!!");
73 return -1;
74 }
75 bool apnHasCreated = FALSE;
76 char Buf[1024] = {0};
77 bzero(Buf, 1024);
78 Parcel p;
79 if(urc_response->cId > 0)
80 {
81 if(urc_response->pdnState==PDN_DISCONNECTED)//if user disable data call,the pdn state wiil change to disconnected.
82 {
83 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
84 {
85 //printf("data test 002:count:%d\n",i);
86 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);
87 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0)&&(apn_table[i].apnstatus==0))
88 {
89 bzero(apn_table[i].apn,LYNQ_APN_LEN_MAX);
90 bzero(apn_table[i].apntype,LYNQ_APNTPYE_LEN_MAX);
91 apn_table[i].used=0;
92 apn_table[i].netId=0;
93 apn_count--;
94 p.writeInt32 (1);
95 p.writeInt32 (LYNQ_URC_DATA_CALL_STATUS_IND);
96 p.writeInt32 (0);//temporary plan
97 p.writeInt32(PDN_DISCONNECTED);
98 android::LYNQ_RIL_urcBroadcast(p);
99 RLOGD("removed apn:%s,apntype:%s",apn_table[i].apn,apn_table[i].apntype);
100 //printf("removed apn:%s,apntype:%s\n",apn_table[i].apn,apn_table[i].apntype);
101 break;
102 }
103 }
104 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
105 {
106 RLOGD("for apn_table[%d].apn:%s,apntype:%s,used:%d,apnstatus:%d\n",i,apn_table[i].apn,
107 apn_table[i].apntype,apn_table[i].used,apn_table[i].apnstatus);
108 }
109 }
110 else
111 {
112 /*if the pdn status change,tele-fwk will send pdn status to me.
113 **The reason for the status change may be that enable data call,
114 **the user disable the data call, and the signal is interrupted.
115 */
116 if(apn_count==0)//first new apn has created
117 {
118 RLOGD("first apn_count:%d\n",apn_count);
119 memcpy(apn_table[apn_count].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
120 memcpy(apn_table[apn_count].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
121 memcpy(apn_table[apn_count].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
122 //printf("apn_table[%d].apn:%s,,,,urc_response->apnName:%s\n",apn_count,apn_table[apn_count].apn,urc_response->apnName);
123 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);
124 apn_table[apn_count].apnstatus=1;
125 apn_table[apn_count].used=1;
126 apn_table[apn_count].netId=urc_response->netId;
127 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_CONNECTED);
132 writeStringToParcel(p,urc_response->apnName);
133 writeStringToParcel(p,urc_response->apnType);
134 writeStringToParcel(p,urc_response->ifname);
135 android::LYNQ_RIL_urcBroadcast(p);
136 }
137 else
138 {
139 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
140 {
141 RLOGD("for apn_table[%d].apn:%s,,,,urc_response->apnName:%s\n",i,apn_table[i].apn,urc_response->apnName);
142 if(strcmp(apn_table[i].apn,urc_response->apnName)==0)
143 {
144 RLOGD("This apn has been created!!!");
145 printf("This apn has been created!!!\n");
146 apnHasCreated = TRUE;
147 if(apn_table[i].netId!=urc_response->netId)
148 {
149 apn_table[i].netId=urc_response->netId;
150 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
151 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
152 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
153 /*send urc to client
154 send apn_t,apnType_t,urc_response->pdnState,iface_t to client
155 */
156 p.writeInt32(1);
157 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
158 p.writeInt32(0);//temporary plan
159 p.writeInt32(urc_response->pdnState);
160 writeStringToParcel(p,apn_t);
161 writeStringToParcel(p,apnType_t);
162 writeStringToParcel(p,iface_t);
163 android::LYNQ_RIL_urcBroadcast(p);
164 //lynq_data_callback(apn_t,apnType_t,urc_response->pdnState,iface_t);
165 //sprintf(Buf,"+LAPNST:%s,%s,%d,%s\n",apn_table[i].apn,apn_table[i].apntype,urc_response->pdnState,urc_response->ifname);
166 //printf("eBuf:%s\n",Buf);
167 //int n = write(ttyGS3_fd,Buf,strlen(Buf));
168 //if(n<0)
169 //{
170 // perror("lynq resp write:");
171 //}
172 }
173 break;
174 }
175 }
176 if(!apnHasCreated)//new apn has created
177 {
178 bool getLable = FALSE;
179 int lable = 0;
180 for(lable;lable < LYNQ_APN_CHANNEL_MAX;lable++)
181 {
182 if(apn_table[lable].used==0)
183 {
184 getLable = TRUE;
185 break;
186 }
187 }
188 if(getLable)
189 {
190 RLOGD("[getLable]:label==%d\n",lable);
191 memcpy(apn_table[lable].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
192 memcpy(apn_table[lable].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
193 memcpy(apn_table[lable].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
194 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);
195 apn_table[lable].apnstatus=1;
196 apn_table[lable].used=1;
197 apn_table[lable].netId=urc_response->netId;
198 apn_count++;
199 p.writeInt32(1);
200 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
201 p.writeInt32(0);//temporary plan
202 p.writeInt32(urc_response->pdnState);
203 writeStringToParcel(p,urc_response->apnName);
204 writeStringToParcel(p,urc_response->apnType);
205 writeStringToParcel(p,urc_response->ifname);
206 android::LYNQ_RIL_urcBroadcast(p);
207 }
208 else
209 {
210 RLOGD("unkown error");
211 }
212 }
213 }
214 }
215 }
216 else
217 {
218 apnHasCreated = FALSE;
219 RLOGD("[cid < 0] apn_count:%d\n",apn_count);
220 if(apn_count>0)
221 {
222 int i = 0;
223 for(i;i < LYNQ_APN_CHANNEL_MAX;i++)
224 {
225 RLOGD("[cid<0]apn_table[%d].apntype:%s,,,,urc_response->apntype:%s\n",i,apn_table[i].apntype,urc_response->apnType);
226 if(strcmp(apn_table[i].apntype,urc_response->apnType)==0)
227 {
228 RLOGD("apntype:%s PDN status has changed!!!\n",urc_response->apnType);
229 apnHasCreated = TRUE;
230 break;
231 }
232 }
233 if(apnHasCreated)
234 {
235 //sprintf(Buf,"+LAPNST:%s,%s,%d\n",apn_table[i].apn,apn_table[i].apntype,urc_response->pdnState);
236 //printf("Buf:%s\n",Buf);
237 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
238 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
239 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
240 p.writeInt32(1);
241 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
242 p.writeInt32(0);//temporary plan
243 p.writeInt32(urc_response->pdnState);
244 writeStringToParcel(p,apn_t);
245 writeStringToParcel(p,apnType_t);
246 writeStringToParcel(p,iface_t);
247 android::LYNQ_RIL_urcBroadcast(p);
248 //int n = write(ttyGS3_fd,Buf,strlen(Buf));
249 //if(n<0)
250 //{
251 // perror("lynq resp write:");
252 //}
253 }
254 }
255 }
256 return 0;
257}
258/*Warren add for t800 ril service 2021/12/25 end*/
259void freeMem(MTK_Data_Call_Response_v1 response)
260{
261 g_free(response.apnType);
262 g_free(response.type);
263 g_free(response.ifname);
264 g_free(response.addresses);
265 g_free(response.dnses);
266 g_free(response.gateways);
267 g_free(response.pcscf);
268}
269
270char* apnState2string(RIL_Data_Call_PdnState apnState) {
271 switch (apnState) {
272 case RIL_Data_Call_PdnState::PDN_CONNECTED:
273 return "PDN_CONNECTED";
274 case RIL_Data_Call_PdnState::PDN_CONNECTING:
275 return "PDN_CONNECTING";
276 case RIL_Data_Call_PdnState::PDN_DISCONNECTED:
277 return "PDN_DISCONNECTED";
278 case RIL_Data_Call_PdnState::PDN_DISCONNECTING:
279 return "PDN_DISCONNECTING";
280 case RIL_Data_Call_PdnState::PDN_FAILED:
281 return "PDN_FAILED";
282 case RIL_Data_Call_PdnState::PDN_IDLE:
283 return "PDN_IDLE";
284 case RIL_Data_Call_PdnState::PDN_RETRYING:
285 return "PDN_RETRYING";
286 case RIL_Data_Call_PdnState::PDN_SCANNING:
287 return "PDN_SCANNING";
288 default:
289 return "UNKNOWN";
290 }
291}
292
293void dumpResponse(MTK_Data_Call_Response_v1 *dataCallResponse)
294{
295 RLOGD("dumpResponse: netId: %d, pdnState: %s, status: %d, cId: %d, apnType: %s,"
296 " protocolType: %s, ifaceName: %s, address: %s, dns: %s, gateway: %s, pcscf: %s, mtu: %d, apn: %s",
297 dataCallResponse->netId, apnState2string(RIL_Data_Call_PdnState(dataCallResponse->pdnState)),
298 dataCallResponse->status, dataCallResponse->cId, dataCallResponse->apnType, dataCallResponse->type,
299 dataCallResponse->ifname, dataCallResponse->addresses, dataCallResponse->dnses,
300 dataCallResponse->gateways, dataCallResponse->pcscf, dataCallResponse->mtu, dataCallResponse->apnName);
301}
302
303void parse(GVariant* result, MTK_Data_Call_Response_v1* data) {
304 g_variant_get(result, "((iiiisssssssis))", &(data->netId),
305 &(data->pdnState), &(data->status),
306 &(data->cId), &(data->apnType), &(data->type),
307 &(data->ifname), &(data->addresses),
308 &(data->dnses), &(data->gateways),
309 &(data->pcscf), &(data->mtu),&(data->apnName));
310}
311
312void proxy_method_cb (GDBusProxy *proxy,
313 GAsyncResult *res,
314 gpointer user_data)
315{
316 RLOGD("method call back");
317 GError *error;
318 GVariant *result;
319
320 error = NULL;
321 result = g_dbus_proxy_call_finish(proxy, res, &error);
322
323 if(error != NULL)
324 {
325 RLOGD("method call back error %s", error->message);
326 g_error_free(error);
327 return;
328 }
329 freeMem(req_response);
330 parse(result, &req_response);
331 dumpResponse(&req_response);
332 g_variant_unref(result);
333}
334
335int enableData (bool isEnable, gchar *apn_type)
336{
337 RLOGD("send: %s, %s", (isEnable ? "TRUE": "FALSE"), apn_type);
338 g_dbus_proxy_call(proxy,
339 "enableData",
340 g_variant_new("(bs)", isEnable, apn_type),
341 G_DBUS_CALL_FLAGS_NONE,
342 -1,
343 NULL,
344 (GAsyncReadyCallback) proxy_method_cb,
345 NULL);
346 return 1;
347}
348
349void modifyApnDB_method_cb (GDBusProxy *proxy,
350 GAsyncResult *res,
351 gpointer user_data)
352{
353 RLOGD("method call back");
354 GError *error;
355 GVariant *result;
356 gchar* reason = NULL;
357
358 error = NULL;
359 result = g_dbus_proxy_call_finish(proxy, res, &error);
360
361 if(error != NULL)
362 {
363 RLOGD("method call back error %s", error->message);
364 printf("modify apn db error: %s\n", error->message);
365 g_error_free(error);
366 return;
367 }
368 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
369 g_variant_get (result, "(&s)", &reason);
370 RLOGD("modifyApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
371 printf("modify apn db success, return message: %s\n", ((reason == NULL)? "":reason));
372 //printf("modifyApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
373 g_variant_unref(result);
374}
375
376int modifyApnDB(int cmd, gchar *record) {
377 RLOGD("%s: cmd: %d, record:%s", __FUNCTION__, cmd, record);
378 g_dbus_proxy_call(proxy,
379 "modifyApnDB",
380 g_variant_new("(is)", cmd, record),
381 G_DBUS_CALL_FLAGS_NONE,
382 -1,
383 NULL,
384 (GAsyncReadyCallback) modifyApnDB_method_cb,
385 NULL);
386 return 1;
387}
388
389void resetApnDB_method_cb (GDBusProxy *proxy,
390 GAsyncResult *res,
391 gpointer user_data)
392{
393 RLOGD("resetApnDB_method_cb call back");
394 GError *error;
395 GVariant *result;
396 gchar* reason = NULL;
397
398 error = NULL;
399 result = g_dbus_proxy_call_finish(proxy, res, &error);
400
401 if(error != NULL)
402 {
403 RLOGD("method call back error %s", error->message);
404 printf("reset apn DB error: %s\n", error->message);
405 g_error_free(error);
406 return;
407 }
408 g_variant_get (result, "(&s)", &reason);
409 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
410 RLOGD("resetApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
411 printf("reset apn DB success, return message: %s\n", ((reason == NULL)? "":reason));
412 //printf("resetApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
413 g_variant_unref(result);
414}
415
416int resetApnDB() {
417 RLOGD("%s", __FUNCTION__);
418 g_dbus_proxy_call(proxy,
419 "resetApnDB",NULL,
420 G_DBUS_CALL_FLAGS_NONE,
421 -1,
422 NULL,
423 (GAsyncReadyCallback) resetApnDB_method_cb,
424 NULL);
425 return 1;
426}
427
428void proxy_signals_on_signal (GDBusProxy *proxy,
429 const gchar *sender_name,
430 const gchar *signal_name,
431 GVariant *parameters,
432 gpointer user_data)
433{
434 RLOGD("signal_name: %s", signal_name);
435 printf("signal_name: %s\n", signal_name);
436 freeMem(urc_response);
437 parse(parameters, &urc_response);
438 dumpResponse(&urc_response);
439 if(g_strcmp0(signal_name, "lynq_data_resp") == 0)
440 {
441 printf("[lynq_data_resp]do something\n");
442 return;
443 }
444 lynq_data_management(&urc_response);
445 if(g_strcmp0(signal_name, "LYNQ_TEST") == 0)
446 {
447 printf("do something\n");
448 }
449 if(g_strcmp0(signal_name, "default") == 0)
450 {
451 if(urc_response.pdnState == RIL_Data_Call_PdnState::PDN_DISCONNECTED) {
452 notifyDataSignal();
xja1c30b82022-01-25 16:13:48 +0800453 } else if (urc_response.pdnState == RIL_Data_Call_PdnState::PDN_FAILED) {
454 updataDataConnectState(get_default_sim_data(), false);
lh7b0674a2022-01-10 00:34:35 -0800455 }
456 }
457 return;
458
459}
460
461void proxy_ready(GObject *source, GAsyncResult *result, gpointer user_data) {
462 GError *error;
463
464 error = NULL;
465 proxy = g_dbus_proxy_new_for_bus_finish(result, &error);
466 if (proxy == NULL) {
467 RLOGE("create proxy fail");
468 return ;
469 }
470 RLOGD("proxy is ready");
471 gulong signal_handler_id;
472
473 signal_handler_id = g_signal_connect(proxy, "g-signal",
474 G_CALLBACK (proxy_signals_on_signal), NULL);
475 if (signal_handler_id == 0) {
476 RLOGE("listen singal fail!");
477 }
478}
479
480void* init_data_gdbus_cb(void *param)
481{
482 /* all the tests rely on a shared main loop */
483 loop = g_main_loop_new(NULL, FALSE);
484
485 g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
486 G_DBUS_PROXY_FLAGS_NONE,
487 NULL, /* GDBusInterfaceInfo */
488 TELEPHONY_SERVICE, /* name */
489 TELEPHONY_DATA_PATH, /* object path */
490 TELEPHONY_DATA_INTERFACE, /* interface */
491 NULL, /* GCancellable */
492 proxy_ready,
493 NULL);
494
495 g_main_loop_run(loop);
496
497 RLOGD("data gdbus main loop run()");
498 if(proxy != NULL) {
499 g_object_unref (proxy);
500 }
501 if(loop != NULL) {
502 g_main_loop_unref(loop);
503 }
xja1c30b82022-01-25 16:13:48 +0800504 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800505}
506