blob: 6f6e7ecf829790b877757a91bdeb1f86f605f6e9 [file] [log] [blame]
lh7b0674a2022-01-10 00:34:35 -08001/* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
9 */
10/* MediaTek Inc. (C) 2010. All rights reserved.
11 *
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 *
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
34 */
35
36#include <unistd.h>
37#include <string.h>
38#include <log/log.h>
39#include <vendor-ril/telephony/ril.h>
40extern "C" {
41#include <gio/gio.h>
42#include <glib.h>
43}
44
45#include "common.h"
46/*Warren add for t800 ril service 2021/12/25 start*/
47#include "lynq_common.h"
48#include "lynq_interface.h"
49#include <binder/Parcel.h>
50using android::Parcel;
51
52/*Warren add for t800 ril service 2021/12/25 end*/
53
54#define LOG_TAG "DEMO_DATA_GDBUS"
55#define TELEPHONY_SERVICE "mtk.telephony" /*well-known bus name */
56#define TELEPHONY_DATA_INTERFACE "mtk.telephony.Data" /*interface name*/
57#define TELEPHONY_DATA_PATH "/mtk/telephony/data" /*object name*/
58
59GMainLoop *loop = NULL;
60GDBusProxy *proxy = NULL;
61MTK_Data_Call_Response_v1 req_response;
62MTK_Data_Call_Response_v1 urc_response;
63/*Warren add for t800 ril service 2021/12/25 start*/
64int lynq_data_management(MTK_Data_Call_Response_v1 *urc_response)
65{
66 char apn_t[LYNQ_APN_LEN_MAX] = {};
67 char apnType_t[LYNQ_APNTPYE_LEN_MAX] = {};
68 char iface_t[LYNQ_APNTPYE_LEN_MAX] = {};
69 if(!urc_response)
70 {
71 RLOGD("urc_response is null!!!");
72 return -1;
73 }
74 bool apnHasCreated = FALSE;
75 char Buf[1024] = {0};
76 bzero(Buf, 1024);
77 Parcel p;
78 if(urc_response->cId > 0)
79 {
80 if(urc_response->pdnState==PDN_DISCONNECTED)//if user disable data call,the pdn state wiil change to disconnected.
81 {
82 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
83 {
84 //printf("data test 002:count:%d\n",i);
85 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);
86 if((strcmp(apn_table[i].apntype,urc_response->apnType)==0)&&(apn_table[i].apnstatus==0))
87 {
88 bzero(apn_table[i].apn,LYNQ_APN_LEN_MAX);
89 bzero(apn_table[i].apntype,LYNQ_APNTPYE_LEN_MAX);
90 apn_table[i].used=0;
91 apn_table[i].netId=0;
92 apn_count--;
93 p.writeInt32 (1);
94 p.writeInt32 (LYNQ_URC_DATA_CALL_STATUS_IND);
95 p.writeInt32 (0);//temporary plan
96 p.writeInt32(PDN_DISCONNECTED);
97 android::LYNQ_RIL_urcBroadcast(p);
98 RLOGD("removed apn:%s,apntype:%s",apn_table[i].apn,apn_table[i].apntype);
99 //printf("removed apn:%s,apntype:%s\n",apn_table[i].apn,apn_table[i].apntype);
100 break;
101 }
102 }
103 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
104 {
105 RLOGD("for apn_table[%d].apn:%s,apntype:%s,used:%d,apnstatus:%d\n",i,apn_table[i].apn,
106 apn_table[i].apntype,apn_table[i].used,apn_table[i].apnstatus);
107 }
108 }
109 else
110 {
111 /*if the pdn status change,tele-fwk will send pdn status to me.
112 **The reason for the status change may be that enable data call,
113 **the user disable the data call, and the signal is interrupted.
114 */
115 if(apn_count==0)//first new apn has created
116 {
117 RLOGD("first apn_count:%d\n",apn_count);
118 memcpy(apn_table[apn_count].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
119 memcpy(apn_table[apn_count].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
120 memcpy(apn_table[apn_count].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
121 //printf("apn_table[%d].apn:%s,,,,urc_response->apnName:%s\n",apn_count,apn_table[apn_count].apn,urc_response->apnName);
122 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);
123 apn_table[apn_count].apnstatus=1;
124 apn_table[apn_count].used=1;
125 apn_table[apn_count].netId=urc_response->netId;
126 apn_count++;
127 p.writeInt32(1);
128 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
129 p.writeInt32(0);//temporary plan
130 p.writeInt32(PDN_CONNECTED);
131 writeStringToParcel(p,urc_response->apnName);
132 writeStringToParcel(p,urc_response->apnType);
133 writeStringToParcel(p,urc_response->ifname);
134 android::LYNQ_RIL_urcBroadcast(p);
135 }
136 else
137 {
138 for(int i = 0;i < LYNQ_APN_CHANNEL_MAX;i++)
139 {
140 RLOGD("for apn_table[%d].apn:%s,,,,urc_response->apnName:%s\n",i,apn_table[i].apn,urc_response->apnName);
141 if(strcmp(apn_table[i].apn,urc_response->apnName)==0)
142 {
143 RLOGD("This apn has been created!!!");
144 printf("This apn has been created!!!\n");
145 apnHasCreated = TRUE;
146 if(apn_table[i].netId!=urc_response->netId)
147 {
148 apn_table[i].netId=urc_response->netId;
149 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
150 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
151 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
152 /*send urc to client
153 send apn_t,apnType_t,urc_response->pdnState,iface_t to client
154 */
155 p.writeInt32(1);
156 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
157 p.writeInt32(0);//temporary plan
158 p.writeInt32(urc_response->pdnState);
159 writeStringToParcel(p,apn_t);
160 writeStringToParcel(p,apnType_t);
161 writeStringToParcel(p,iface_t);
162 android::LYNQ_RIL_urcBroadcast(p);
163 //lynq_data_callback(apn_t,apnType_t,urc_response->pdnState,iface_t);
164 //sprintf(Buf,"+LAPNST:%s,%s,%d,%s\n",apn_table[i].apn,apn_table[i].apntype,urc_response->pdnState,urc_response->ifname);
165 //printf("eBuf:%s\n",Buf);
166 //int n = write(ttyGS3_fd,Buf,strlen(Buf));
167 //if(n<0)
168 //{
169 // perror("lynq resp write:");
170 //}
171 }
172 break;
173 }
174 }
175 if(!apnHasCreated)//new apn has created
176 {
177 bool getLable = FALSE;
178 int lable = 0;
179 for(lable;lable < LYNQ_APN_CHANNEL_MAX;lable++)
180 {
181 if(apn_table[lable].used==0)
182 {
183 getLable = TRUE;
184 break;
185 }
186 }
187 if(getLable)
188 {
189 RLOGD("[getLable]:label==%d\n",lable);
190 memcpy(apn_table[lable].apn,urc_response->apnName,strlen(urc_response->apnName)+1);
191 memcpy(apn_table[lable].apntype,urc_response->apnType,strlen(urc_response->apnType)+1);
192 memcpy(apn_table[lable].ifaceName,urc_response->ifname,strlen(urc_response->ifname)+1);
193 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);
194 apn_table[lable].apnstatus=1;
195 apn_table[lable].used=1;
196 apn_table[lable].netId=urc_response->netId;
197 apn_count++;
198 p.writeInt32(1);
199 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
200 p.writeInt32(0);//temporary plan
201 p.writeInt32(urc_response->pdnState);
202 writeStringToParcel(p,urc_response->apnName);
203 writeStringToParcel(p,urc_response->apnType);
204 writeStringToParcel(p,urc_response->ifname);
205 android::LYNQ_RIL_urcBroadcast(p);
206 }
207 else
208 {
209 RLOGD("unkown error");
210 }
211 }
212 }
213 }
214 }
215 else
216 {
217 apnHasCreated = FALSE;
218 RLOGD("[cid < 0] apn_count:%d\n",apn_count);
219 if(apn_count>0)
220 {
221 int i = 0;
222 for(i;i < LYNQ_APN_CHANNEL_MAX;i++)
223 {
224 RLOGD("[cid<0]apn_table[%d].apntype:%s,,,,urc_response->apntype:%s\n",i,apn_table[i].apntype,urc_response->apnType);
225 if(strcmp(apn_table[i].apntype,urc_response->apnType)==0)
226 {
227 RLOGD("apntype:%s PDN status has changed!!!\n",urc_response->apnType);
228 apnHasCreated = TRUE;
229 break;
230 }
231 }
232 if(apnHasCreated)
233 {
234 //sprintf(Buf,"+LAPNST:%s,%s,%d\n",apn_table[i].apn,apn_table[i].apntype,urc_response->pdnState);
235 //printf("Buf:%s\n",Buf);
236 memcpy(iface_t,apn_table[i].ifaceName,strlen(apn_table[i].ifaceName)+1);
237 memcpy(apnType_t,apn_table[i].apntype,strlen(apn_table[i].apntype)+1);
238 memcpy(apn_t,apn_table[i].apn,strlen(apn_table[i].apn)+1);
239 p.writeInt32(1);
240 p.writeInt32(LYNQ_URC_DATA_CALL_STATUS_IND);
241 p.writeInt32(0);//temporary plan
242 p.writeInt32(urc_response->pdnState);
243 writeStringToParcel(p,apn_t);
244 writeStringToParcel(p,apnType_t);
245 writeStringToParcel(p,iface_t);
246 android::LYNQ_RIL_urcBroadcast(p);
247 //int n = write(ttyGS3_fd,Buf,strlen(Buf));
248 //if(n<0)
249 //{
250 // perror("lynq resp write:");
251 //}
252 }
253 }
254 }
255 return 0;
256}
257/*Warren add for t800 ril service 2021/12/25 end*/
258void freeMem(MTK_Data_Call_Response_v1 response)
259{
260 g_free(response.apnType);
261 g_free(response.type);
262 g_free(response.ifname);
263 g_free(response.addresses);
264 g_free(response.dnses);
265 g_free(response.gateways);
266 g_free(response.pcscf);
267}
268
269char* apnState2string(RIL_Data_Call_PdnState apnState) {
270 switch (apnState) {
271 case RIL_Data_Call_PdnState::PDN_CONNECTED:
272 return "PDN_CONNECTED";
273 case RIL_Data_Call_PdnState::PDN_CONNECTING:
274 return "PDN_CONNECTING";
275 case RIL_Data_Call_PdnState::PDN_DISCONNECTED:
276 return "PDN_DISCONNECTED";
277 case RIL_Data_Call_PdnState::PDN_DISCONNECTING:
278 return "PDN_DISCONNECTING";
279 case RIL_Data_Call_PdnState::PDN_FAILED:
280 return "PDN_FAILED";
281 case RIL_Data_Call_PdnState::PDN_IDLE:
282 return "PDN_IDLE";
283 case RIL_Data_Call_PdnState::PDN_RETRYING:
284 return "PDN_RETRYING";
285 case RIL_Data_Call_PdnState::PDN_SCANNING:
286 return "PDN_SCANNING";
287 default:
288 return "UNKNOWN";
289 }
290}
291
292void dumpResponse(MTK_Data_Call_Response_v1 *dataCallResponse)
293{
294 RLOGD("dumpResponse: netId: %d, pdnState: %s, status: %d, cId: %d, apnType: %s,"
295 " protocolType: %s, ifaceName: %s, address: %s, dns: %s, gateway: %s, pcscf: %s, mtu: %d, apn: %s",
296 dataCallResponse->netId, apnState2string(RIL_Data_Call_PdnState(dataCallResponse->pdnState)),
297 dataCallResponse->status, dataCallResponse->cId, dataCallResponse->apnType, dataCallResponse->type,
298 dataCallResponse->ifname, dataCallResponse->addresses, dataCallResponse->dnses,
299 dataCallResponse->gateways, dataCallResponse->pcscf, dataCallResponse->mtu, dataCallResponse->apnName);
300}
301
302void parse(GVariant* result, MTK_Data_Call_Response_v1* data) {
303 g_variant_get(result, "((iiiisssssssis))", &(data->netId),
304 &(data->pdnState), &(data->status),
305 &(data->cId), &(data->apnType), &(data->type),
306 &(data->ifname), &(data->addresses),
307 &(data->dnses), &(data->gateways),
308 &(data->pcscf), &(data->mtu),&(data->apnName));
309}
310
311void proxy_method_cb (GDBusProxy *proxy,
312 GAsyncResult *res,
313 gpointer user_data)
314{
315 RLOGD("method call back");
316 GError *error;
317 GVariant *result;
318
319 error = NULL;
320 result = g_dbus_proxy_call_finish(proxy, res, &error);
321
322 if(error != NULL)
323 {
324 RLOGD("method call back error %s", error->message);
325 g_error_free(error);
326 return;
327 }
328 freeMem(req_response);
329 parse(result, &req_response);
330 dumpResponse(&req_response);
331 g_variant_unref(result);
332}
333
334int enableData (bool isEnable, gchar *apn_type)
335{
336 RLOGD("send: %s, %s", (isEnable ? "TRUE": "FALSE"), apn_type);
337 g_dbus_proxy_call(proxy,
338 "enableData",
339 g_variant_new("(bs)", isEnable, apn_type),
340 G_DBUS_CALL_FLAGS_NONE,
341 -1,
342 NULL,
343 (GAsyncReadyCallback) proxy_method_cb,
344 NULL);
345 return 1;
346}
347
348void modifyApnDB_method_cb (GDBusProxy *proxy,
349 GAsyncResult *res,
350 gpointer user_data)
351{
352 RLOGD("method call back");
353 GError *error;
354 GVariant *result;
355 gchar* reason = NULL;
356
357 error = NULL;
358 result = g_dbus_proxy_call_finish(proxy, res, &error);
359
360 if(error != NULL)
361 {
362 RLOGD("method call back error %s", error->message);
363 printf("modify apn db error: %s\n", error->message);
364 g_error_free(error);
365 return;
366 }
367 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
368 g_variant_get (result, "(&s)", &reason);
369 RLOGD("modifyApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
370 printf("modify apn db success, return message: %s\n", ((reason == NULL)? "":reason));
371 //printf("modifyApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
372 g_variant_unref(result);
373}
374
375int modifyApnDB(int cmd, gchar *record) {
376 RLOGD("%s: cmd: %d, record:%s", __FUNCTION__, cmd, record);
377 g_dbus_proxy_call(proxy,
378 "modifyApnDB",
379 g_variant_new("(is)", cmd, record),
380 G_DBUS_CALL_FLAGS_NONE,
381 -1,
382 NULL,
383 (GAsyncReadyCallback) modifyApnDB_method_cb,
384 NULL);
385 return 1;
386}
387
388void resetApnDB_method_cb (GDBusProxy *proxy,
389 GAsyncResult *res,
390 gpointer user_data)
391{
392 RLOGD("resetApnDB_method_cb call back");
393 GError *error;
394 GVariant *result;
395 gchar* reason = NULL;
396
397 error = NULL;
398 result = g_dbus_proxy_call_finish(proxy, res, &error);
399
400 if(error != NULL)
401 {
402 RLOGD("method call back error %s", error->message);
403 printf("reset apn DB error: %s\n", error->message);
404 g_error_free(error);
405 return;
406 }
407 g_variant_get (result, "(&s)", &reason);
408 //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
409 RLOGD("resetApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
410 printf("reset apn DB success, return message: %s\n", ((reason == NULL)? "":reason));
411 //printf("resetApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
412 g_variant_unref(result);
413}
414
415int resetApnDB() {
416 RLOGD("%s", __FUNCTION__);
417 g_dbus_proxy_call(proxy,
418 "resetApnDB",NULL,
419 G_DBUS_CALL_FLAGS_NONE,
420 -1,
421 NULL,
422 (GAsyncReadyCallback) resetApnDB_method_cb,
423 NULL);
424 return 1;
425}
426
427void proxy_signals_on_signal (GDBusProxy *proxy,
428 const gchar *sender_name,
429 const gchar *signal_name,
430 GVariant *parameters,
431 gpointer user_data)
432{
433 RLOGD("signal_name: %s", signal_name);
434 printf("signal_name: %s\n", signal_name);
435 freeMem(urc_response);
436 parse(parameters, &urc_response);
437 dumpResponse(&urc_response);
438 if(g_strcmp0(signal_name, "lynq_data_resp") == 0)
439 {
440 printf("[lynq_data_resp]do something\n");
441 return;
442 }
443 lynq_data_management(&urc_response);
444 if(g_strcmp0(signal_name, "LYNQ_TEST") == 0)
445 {
446 printf("do something\n");
447 }
448 if(g_strcmp0(signal_name, "default") == 0)
449 {
450 if(urc_response.pdnState == RIL_Data_Call_PdnState::PDN_DISCONNECTED) {
451 notifyDataSignal();
452 }
453 }
454 return;
455
456}
457
458void proxy_ready(GObject *source, GAsyncResult *result, gpointer user_data) {
459 GError *error;
460
461 error = NULL;
462 proxy = g_dbus_proxy_new_for_bus_finish(result, &error);
463 if (proxy == NULL) {
464 RLOGE("create proxy fail");
465 return ;
466 }
467 RLOGD("proxy is ready");
468 gulong signal_handler_id;
469
470 signal_handler_id = g_signal_connect(proxy, "g-signal",
471 G_CALLBACK (proxy_signals_on_signal), NULL);
472 if (signal_handler_id == 0) {
473 RLOGE("listen singal fail!");
474 }
475}
476
477void* init_data_gdbus_cb(void *param)
478{
479 /* all the tests rely on a shared main loop */
480 loop = g_main_loop_new(NULL, FALSE);
481
482 g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
483 G_DBUS_PROXY_FLAGS_NONE,
484 NULL, /* GDBusInterfaceInfo */
485 TELEPHONY_SERVICE, /* name */
486 TELEPHONY_DATA_PATH, /* object path */
487 TELEPHONY_DATA_INTERFACE, /* interface */
488 NULL, /* GCancellable */
489 proxy_ready,
490 NULL);
491
492 g_main_loop_run(loop);
493
494 RLOGD("data gdbus main loop run()");
495 if(proxy != NULL) {
496 g_object_unref (proxy);
497 }
498 if(loop != NULL) {
499 g_main_loop_unref(loop);
500 }
501}
502