Initialize Tizen 2.3
[framework/telephony/libslp-tapi.git] / test_src / network.c
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/time.h>
25 #include <unistd.h>
26 #include <glib.h>
27
28 #include <tapi_common.h>
29 #include <ITapiNetwork.h>
30 #include <TapiUtility.h>
31
32 #include "menu.h"
33 #include "network.h"
34
35 static char data_net_set_plmn_mode_manual_act[MENU_DATA_SIZE + 1] = "4";
36 static char data_net_set_plmn_mode_manual_plmn[MENU_DATA_SIZE + 1] = "45001";
37 static char data_net_set_preferred_plmn_mode[MENU_DATA_SIZE + 1] = "1";
38 static char data_net_set_preferred_plmn_plmn[MENU_DATA_SIZE + 1] = "45001";
39 static char data_net_set_preferred_plmn_type[MENU_DATA_SIZE + 1] = "4";
40 static char data_net_set_preferred_plmn_ef_index[MENU_DATA_SIZE + 1] = "0";
41
42 static char data_net_set_mode_mode[MENU_DATA_SIZE + 1] = "3";
43
44 static void on_prop_signal_dbm (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
45 {
46         int *sig_dbm = data;
47
48         msg ("");
49         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_SIGNALSTRENGTH_DBM);
50
51         msg (" - sig_dbm = %d", *sig_dbm);
52 }
53
54 static void on_prop_signal_level (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
55 {
56         int *sig_level = data;
57
58         msg ("");
59         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL);
60
61         msg (" - sig_level = %d", *sig_level);
62 }
63
64 static void on_prop_lac (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
65 {
66         int *lac = data;
67
68         msg ("");
69         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_LAC);
70
71         msg (" - lac = %d", *lac);
72 }
73
74 static void on_prop_plmn (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
75 {
76         msg ("");
77         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_PLMN);
78
79         msg (" - plmn = %s", (char *)data);
80 }
81
82 static void on_prop_cellid (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
83 {
84         int *cell_id = data;
85
86         msg ("");
87         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_CELLID);
88
89         msg (" - cell_id = %d", *cell_id);
90 }
91
92 static void on_prop_service_type (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
93 {
94         int *service_type = data;
95
96         msg ("");
97         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_SERVICE_TYPE);
98
99         msg (" - service_type = %d", *service_type);
100 }
101
102 static void on_prop_act (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
103 {
104         int *act = data;
105
106         msg ("");
107         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_ACT);
108
109         msg (" - access technology = %d", *act);
110 }
111
112 static void on_prop_ps_type (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
113 {
114         int *ps_type = data;
115
116         msg ("");
117         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_PS_TYPE);
118
119         msg (" - ps_type = %d", *ps_type);
120 }
121
122 static void on_prop_circuit_status (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
123 {
124         int *circuit_status = data;
125
126         msg ("");
127         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_CIRCUIT_STATUS);
128
129         msg (" - circuit_status = %d", *circuit_status);
130 }
131
132 static void on_prop_packet_status (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
133 {
134         int *packet_status = data;
135
136         msg ("");
137         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_PACKET_STATUS);
138
139         msg (" - packet_status = %d", *packet_status);
140 }
141
142 static void on_prop_roaming_status (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
143 {
144         guchar *roaming_status = data;
145
146         msg ("");
147         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_ROAMING_STATUS);
148
149         msg (" - roaming_status = %d", *roaming_status);
150 }
151
152 static void on_prop_name_option (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
153 {
154         int *option = data;
155
156         msg ("");
157         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_NAME_OPTION);
158
159         msg (" - name_option = %d", *option);
160 }
161
162 static void on_prop_network_name (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
163 {
164         msg ("");
165         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_NETWORK_NAME);
166
167         msg (" - network_name = %s", (char *)data);
168 }
169
170 static void on_prop_spn_name (TapiHandle *handle, const char *noti_id, void *data, void *user_data)
171 {
172         msg ("");
173         msgp ("property(%s) receive !!", TAPI_PROP_NETWORK_SPN_NAME);
174
175         msg (" - spn_name = %s", (char *)data);
176 }
177
178 static void on_noti_registration_status(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
179 {
180         TelNetworkRegistrationStatus_t *noti = data;
181
182         msg ("");
183         msgb ("event(%s) receive !!", TAPI_NOTI_NETWORK_REGISTRATION_STATUS);
184
185         msg (" - circuit status = %d", noti->cs);
186         msg (" - packet status = %d", noti->ps);
187         msg (" - service type = %d", noti->type);
188         msg (" - is roaming = %d", noti->is_roaming);
189 }
190
191 static void on_noti_cell_info(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
192 {
193         struct tel_noti_network_cell_info *noti = data;
194
195         msg ("");
196         msgb ("event(%s) receive !!", TAPI_NOTI_NETWORK_CELLINFO);
197
198         msg (" - lac = %d", noti->lac);
199         msg (" - cell_id = %d", noti->cell_id);
200 }
201
202 static void on_noti_change(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
203 {
204         struct tel_noti_network_change *noti = data;
205
206         msg ("");
207         msgb ("event(%s) receive !!", TAPI_NOTI_NETWORK_CHANGE);
208
209         msg (" - plmn = %s", noti->plmn);
210         msg (" - act = %d", noti->act);
211 }
212
213 static void on_noti_time_info(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
214 {
215         struct tel_noti_network_time_info *noti = data;
216
217         msg ("");
218         msgb ("event(%s) receive !!", TAPI_NOTI_NETWORK_TIMEINFO);
219
220         msg (" - plmn = %s", noti->plmn);
221         msg (" - year = %d", noti->year);
222         msg (" - month = %d", noti->month);
223         msg (" - day = %d", noti->day);
224         msg (" - hour = %d", noti->hour);
225         msg (" - minute = %d", noti->minute);
226         msg (" - second = %d", noti->second);
227         msg (" - wday = %d", noti->wday);
228         msg (" - gmtoff = %d", noti->gmtoff);
229         msg (" - dstoff = %d", noti->dstoff);
230         msg (" - isdst = %d", noti->isdst);
231 }
232
233 static void on_noti_identity(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
234 {
235         struct tel_noti_network_identity *noti = data;
236
237         msg ("");
238         msgb ("event(%s) receive !!", TAPI_NOTI_NETWORK_IDENTITY);
239
240         msg (" - plmn = %s", noti->plmn);
241         msg (" - short_name = %s", noti->short_name);
242         msg (" - full_name = %s", noti->full_name);
243 }
244
245 static void on_noti_signal_strength(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
246 {
247         struct tel_noti_network_signal_strength *noti = data;
248
249         msg ("");
250         msgb ("event(%s) receive !!", TAPI_NOTI_NETWORK_SIGNALSTRENGTH);
251
252         msg (" - dbm = %d", noti->dbm);
253 }
254
255 static void on_noti_default_data_subs(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
256 {
257         struct tel_noti_network_default_data_subs *noti = data;
258
259         msg ("");
260         msgb ("event(%s) receive !!", TAPI_NOTI_NETWORK_DEFAULT_DATA_SUBSCRIPTION);
261
262         if (noti)
263                 msg (" - 'default' Data Subscription = %s",
264                         ((noti->default_subs == TAPI_NETWORK_DEFAULT_DATA_SUBS_SIM1) ? "SIM 1"
265                         : ((noti->default_subs == TAPI_NETWORK_DEFAULT_DATA_SUBS_SIM2) ? "SIM 2"
266                         : "Unknown")));
267 }
268
269 static void on_noti_default_subs(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
270 {
271         struct tel_noti_network_default_subs *noti = data;
272
273         msg ("");
274         msgb ("event(%s) receive !!", TAPI_NOTI_NETWORK_DEFAULT_SUBSCRIPTION);
275
276         if (noti)
277                 msg (" - 'default' Subscription = %s",
278                         ((noti->default_subs == TAPI_NETWORK_DEFAULT_SUBS_SIM1) ? "SIM 1"
279                         : ((noti->default_subs == TAPI_NETWORK_DEFAULT_SUBS_SIM2) ? "SIM 2"
280                         : "Unknown")));
281 }
282
283 static void on_net_search(TapiHandle *handle, int result, void *data, void *user_data)
284 {
285         TelNetworkPlmnList_t *list = data;
286         int i =0;
287
288         msg ("");
289         msgb ("tel_search_network() response receive");
290         msg (" - result = 0x%x", result);
291
292         if (!list) {
293                 msg (" - failed");
294                 return;
295         }
296
297         msg (" - count = %d", list->networks_count);
298
299         for (i = 0; i < list->networks_count; i++) {
300                 msg (" - [%d] plmn=%s, act=%d, type=%d, name=%s",
301                                 i,
302                                 list->network_list[i].plmn,
303                                 list->network_list[i].access_technology,
304                                 list->network_list[i].type_of_plmn,
305                                 list->network_list[i].network_name);
306         }
307 }
308
309 static void on_net_set_plmn_mode_automatic(TapiHandle *handle, int result, void *data, void *user_data)
310 {
311         msg ("");
312         msgb ("tel_select_network_automatic() response receive");
313         msg (" - result = 0x%x", result);
314 }
315
316 static void on_net_set_plmn_mode_manual(TapiHandle *handle, int result, void *data, void *user_data)
317 {
318         msg ("");
319         msgb ("tel_select_network_manual() response receive");
320         msg (" - result = 0x%x", result);
321 }
322
323 static void on_net_get_plmn_mode(TapiHandle *handle, int result, void *data, void *user_data)
324 {
325         int *mode = data;
326
327         msg ("");
328         msgb ("tel_get_network_selection_mode() response receive");
329         msg (" - result = 0x%x", result);
330
331         if (data)
332                 msg (" - mode = %d", *mode);
333 }
334
335 static void on_net_set_preferred_plmn(TapiHandle *handle, int result, void *data, void *user_data)
336 {
337         msg ("");
338         msgb ("tel_set_preferred_plmn() response receive");
339         msg (" - result = 0x%x", result);
340 }
341
342 static void on_net_get_preferred_plmn(TapiHandle *handle, int result, void *data, void *user_data)
343 {
344         TelNetworkPreferredPlmnList_t *info = data;
345         unsigned int i = 0;
346
347         msg ("");
348         msgb ("tel_get_preferred_plmn() response receive");
349         msg (" - result = 0x%x", result);
350
351         if (!info) {
352                 msg (" - failed");
353                 return;
354         }
355
356         msg (" - count = %d", info->NumOfPrefPlmns);
357
358         for (i = 0; i < info->NumOfPrefPlmns; i++) {
359                 msg (" - [%d] plmn=%s, type=%d, ef_index=%d, name=%s",
360                                 i,
361                                 info->PrefPlmnRecord[i].Plmn,
362                                 info->PrefPlmnRecord[i].SystemType,
363                                 info->PrefPlmnRecord[i].Index,
364                                 info->PrefPlmnRecord[i].network_name);
365         }
366 }
367
368 static void on_net_set_cancel_manual_search(TapiHandle *handle, int result, void *data, void *user_data)
369 {
370         msg ("");
371         msgb ("tel_cancel_network_manual_search() response receive");
372         msg (" - result = 0x%x", result);
373 }
374
375 static void on_net_get_serving_network(TapiHandle *handle, int result, void *data, void *user_data)
376 {
377         TelNetworkServing_t *info = data;
378
379         msg ("");
380         msgb ("tel_get_network_serving() response receive");
381         msg (" - result = 0x%x", result);
382
383         if (!info) {
384                 msg (" - failed");
385                 return;
386         }
387
388         msg (" - plmn = %s", info->plmn);
389         msg (" - access technology = %d", info->act);
390         msg (" - lac = %d", info->info.lac);
391 }
392
393 static void on_net_set_mode(TapiHandle *handle, int result, void *data, void *user_data)
394 {
395         msg ("");
396         msgb ("tel_set_network_mode() response receive");
397         msg (" - result = 0x%x", result);
398 }
399
400 static void on_net_get_mode(TapiHandle *handle, int result, void *data, void *user_data)
401 {
402         int *mode = data;
403
404         msg ("");
405         msgb ("tel_get_network_mode() response receive");
406         msg (" - result = 0x%x", result);
407
408         if (data)
409                 msg (" - mode = %d", *mode);
410 }
411
412 static void on_net_get_neighboring_cell_info(TapiHandle *handle, int result, void *data, void *user_data)
413 {
414         TelNetworkNeighboringCellInfo_t *info = data;
415         int i, j;
416
417         msg ("");
418         msgb ("tel_get_neighboring_cell_info() response receive");
419         msg (" - result = 0x%x", result);
420
421         if (!data)
422                 return;
423
424         msg ("info=%p",info);
425
426         msg ("act=%d",info->serving.act);
427         msg ("mcc=%d",info->serving.mcc);
428         msg ("mnc=%d\n",info->serving.mnc);
429
430         if(info->serving.act <= TAPI_NETWORK_SYSTEM_EGPRS) {
431                 msg ("geran.cell_id=%d",info->serving.cell.geran.cell_id);
432                 msg ("geran.lac=%d",info->serving.cell.geran.lac);
433                 msg ("geran.bcch=%d",info->serving.cell.geran.bcch);
434                 msg ("geran.bsic=%d",info->serving.cell.geran.bsic);
435                 msg ("geran.rxlev=%d\n",info->serving.cell.geran.rxlev);
436         }
437         else if(info->serving.act <= TAPI_NETWORK_SYSTEM_GSM_AND_UMTS) {
438                 msg ("umts.cell_id=%d",info->serving.cell.umts.cell_id);
439                 msg ("umts.lac=%d",info->serving.cell.umts.lac);
440                 msg ("umts.arfcn=%d",info->serving.cell.umts.arfcn);
441                 msg ("umts.psc=%d",info->serving.cell.umts.psc);
442                 msg ("umts.rscp=%d\n",info->serving.cell.umts.rscp);
443         }
444         else if(info->serving.act == TAPI_NETWORK_SYSTEM_LTE) {
445                 msg ("lte.cell_id=%d",info->serving.cell.lte.cell_id);
446                 msg ("lte.lac=%d",info->serving.cell.lte.lac);
447                 msg ("lte.earfcn=%d",info->serving.cell.lte.earfcn);
448                 msg ("lte.tac=%d",info->serving.cell.lte.tac);
449                 msg ("lte.rssi=%d\n",info->serving.cell.lte.rssi);
450         }
451         msg ("geran_list_count=%d",info->geran_list_count);
452         for(i=0; i<info->geran_list_count; i++) {
453                 msg ("[%d] cell_id=%d, lac=%d, bcch=%d, bsic=%d, rxlev=%d,",i,
454                         info->geran_list[i].cell_id, info->geran_list[i].lac, info->geran_list[i].bcch,
455                         info->geran_list[i].bsic, info->geran_list[i].rxlev);
456         }
457
458         msg ("umts_list_count=%d",info->umts_list_count);
459         for(j=0; j<info->umts_list_count; j++) {
460                 msg ("[%d] cell_id=%d, lac=%d, arfcn=%d, psc=%d, rscp=%d,",j,
461                         info->umts_list[j].cell_id, info->umts_list[j].lac, info->umts_list[j].arfcn,
462                         info->umts_list[j].psc, info->umts_list[j].rscp);
463         }
464 }
465
466 static void on_net_set_default_data_subscription(TapiHandle *handle, int result, void *data, void *user_data)
467 {
468         msg ("");
469         msgb ("tel_set_network_default_data_subscription() response receive");
470         msg (" - result = 0x%x", result);
471 }
472
473 static void on_net_set_default_subscription(TapiHandle *handle, int result, void *data, void *user_data)
474 {
475         msg("on_net_set_default_subscription() - result : 0x%x", result);
476 }
477
478 static int run_net_search (MManager *mm, struct menu_data *menu)
479 {
480         TapiHandle *handle = menu_manager_ref_user_data(mm);
481         int result;
482
483         msg ("call tel_search_network()");
484
485         result = tel_search_network (handle, on_net_search, NULL);
486         if (result != TAPI_API_SUCCESS) {
487                 msg ("failed. (result = %d)", result);
488         }
489
490         return 0;
491 }
492
493 static int run_net_set_plmn_mode_automatic (MManager *mm, struct menu_data *menu)
494 {
495         TapiHandle *handle = menu_manager_ref_user_data(mm);
496         int result;
497
498         msg ("call tel_select_network_automatic()");
499
500         result = tel_select_network_automatic (handle, on_net_set_plmn_mode_automatic, NULL);
501         if (result != TAPI_API_SUCCESS) {
502                 msg ("failed. (result = %d)", result);
503         }
504
505         return 0;
506 }
507
508 static int run_net_set_plmn_mode_manual (MManager *mm, struct menu_data *menu)
509 {
510         TapiHandle *handle = menu_manager_ref_user_data(mm);
511         int result;
512         const char *plmn;
513         int act;
514
515         msg ("call tel_select_network_manual()");
516
517         plmn = data_net_set_plmn_mode_manual_plmn;
518         act = atoi(data_net_set_plmn_mode_manual_act);
519
520         result = tel_select_network_manual (handle, plmn, act, on_net_set_plmn_mode_manual, NULL);
521         if (result != TAPI_API_SUCCESS) {
522                 msg ("failed. (result = %d)", result);
523         }
524
525         return 0;
526 }
527
528 static int run_net_get_plmn_mode (MManager *mm, struct menu_data *menu)
529 {
530         TapiHandle *handle = menu_manager_ref_user_data(mm);
531         int result;
532
533         msg ("call tel_get_network_selection_mode()");
534
535         result = tel_get_network_selection_mode (handle, on_net_get_plmn_mode, NULL);
536         if (result != TAPI_API_SUCCESS) {
537                 msg ("failed. (result = %d)", result);
538         }
539
540         return 0;
541 }
542
543 static int run_net_set_preferred_plmn (MManager *mm, struct menu_data *menu)
544 {
545         TapiHandle *handle = menu_manager_ref_user_data(mm);
546         int result;
547         int operation;
548         TelNetworkPreferredPlmnInfo_t info;
549
550         msg ("call tel_set_network_preferred_plmn()");
551
552         memset(&info, 0, sizeof(TelNetworkPreferredPlmnInfo_t));
553
554         operation = atoi(data_net_set_preferred_plmn_mode);
555         info.Index = atoi(data_net_set_preferred_plmn_ef_index);
556         info.SystemType = atoi(data_net_set_preferred_plmn_type);
557         strncpy(info.Plmn, data_net_set_preferred_plmn_plmn, 6);
558
559         result = tel_set_network_preferred_plmn (handle, operation, &info, on_net_set_preferred_plmn, NULL);
560         if (result != TAPI_API_SUCCESS) {
561                 msg ("failed. (result = %d)", result);
562         }
563
564         return 0;
565 }
566
567 static int run_net_get_preferred_plmn (MManager *mm, struct menu_data *menu)
568 {
569         TapiHandle *handle = menu_manager_ref_user_data(mm);
570         int result;
571
572         msg ("call tel_get_network_preferred_plmn()");
573
574         result = tel_get_network_preferred_plmn (handle, on_net_get_preferred_plmn, NULL);
575         if (result != TAPI_API_SUCCESS) {
576                 msg ("failed. (result = %d)", result);
577         }
578
579         return 0;
580 }
581
582 static int run_net_set_cancel_manual_search (MManager *mm, struct menu_data *menu)
583 {
584         TapiHandle *handle = menu_manager_ref_user_data(mm);
585         int result;
586
587         msg ("call tel_cancel_network_manual_search()");
588
589         result = tel_cancel_network_manual_search (handle, on_net_set_cancel_manual_search, NULL);
590         if (result != TAPI_API_SUCCESS) {
591                 msg ("failed. (result = %d)", result);
592         }
593
594         return 0;
595 }
596
597 static int run_net_get_serving_network (MManager *mm, struct menu_data *menu)
598 {
599         TapiHandle *handle = menu_manager_ref_user_data(mm);
600         int result;
601
602         msg ("call tel_get_network_serving()");
603
604         result = tel_get_network_serving (handle, on_net_get_serving_network, NULL);
605         if (result != TAPI_API_SUCCESS) {
606                 msg ("failed. (result = %d)", result);
607         }
608
609         return 0;
610 }
611
612 static int run_net_set_mode (MManager *mm, struct menu_data *menu)
613 {
614         TapiHandle *handle = menu_manager_ref_user_data(mm);
615         int result;
616         int mode;
617
618         msg ("call tel_set_network_mode()");
619
620         mode = atoi(data_net_set_mode_mode);
621
622         result = tel_set_network_mode (handle, mode, on_net_set_mode, NULL);
623         if (result != TAPI_API_SUCCESS) {
624                 msg ("failed. (result = %d)", result);
625         }
626
627         return 0;
628 }
629
630 static int run_net_get_mode (MManager *mm, struct menu_data *menu)
631 {
632         TapiHandle *handle = menu_manager_ref_user_data(mm);
633         int result;
634
635         msg ("call tel_get_network_mode()");
636
637         result = tel_get_network_mode (handle, on_net_get_mode, NULL);
638         if (result != TAPI_API_SUCCESS) {
639                 msg ("failed. (result = %d)", result);
640         }
641
642         return 0;
643 }
644
645 static int run_net_get_neighboring_cell_info (MManager *mm, struct menu_data *menu)
646 {
647         TapiHandle *handle = menu_manager_ref_user_data(mm);
648         int result;
649
650         msg ("call tel_get_network_neighboring_cell_info()");
651
652         result = tel_get_network_neighboring_cell_info (handle, on_net_get_neighboring_cell_info, NULL);
653         if (result != TAPI_API_SUCCESS) {
654                 msg ("failed. (result = %d)", result);
655         }
656
657         return 0;
658 }
659
660 static int run_net_set_default_data_subscription (MManager *mm, struct menu_data *menu)
661 {
662         TapiHandle *handle = menu_manager_ref_user_data(mm);
663         int result;
664
665         msg ("call tel_set_network_default_data_subscription()");
666
667         result = tel_set_network_default_data_subscription (handle, on_net_set_default_data_subscription, NULL);
668         if (result != TAPI_API_SUCCESS) {
669                 msg ("failed. (result = %d)", result);
670         }
671
672         return 0;
673 }
674
675 static int run_net_get_default_data_subscription (MManager *mm, struct menu_data *menu)
676 {
677         TapiHandle *handle = menu_manager_ref_user_data (mm);
678         TelNetworkDefaultDataSubs_t default_subs = TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN;
679         int result = 0;
680
681         msg ("call tel_get_network_default_data_subscription()");
682
683         result = tel_get_network_default_data_subscription (handle, &default_subs);
684         if (result != TAPI_API_SUCCESS) {
685                 msg("api call failed with[0x%x]", result);
686                 return 0;
687         }
688
689         msg("'default' Data Subscription = %s",
690                         ((default_subs == TAPI_NETWORK_DEFAULT_DATA_SUBS_SIM1) ? "SIM 1"
691                         : ((default_subs == TAPI_NETWORK_DEFAULT_DATA_SUBS_SIM2) ? "SIM 2"
692                         : "Unknown")));
693
694         return 0;
695 }
696
697
698 static int run_net_set_default_subscription(MManager *mm, struct menu_data *menu)
699 {
700         TapiHandle *handle = menu_manager_ref_user_data(mm);
701         int result = 0;
702
703         msg("call tel_set_network_default_subscription()");
704
705         result = tel_set_network_default_subscription(handle, on_net_set_default_subscription, NULL);
706         if (result != TAPI_API_SUCCESS) {
707                 msg("failed. (result = %d)", result);
708         }
709
710         return result;
711 }
712
713 static int run_net_get_default_subscription(MManager *mm, struct menu_data *menu)
714 {
715         TapiHandle *handle = menu_manager_ref_user_data(mm);
716         int result = 0;
717         TelNetworkDefaultSubs_t default_subs = TAPI_NETWORK_DEFAULT_SUBS_UNKNOWN;
718
719         msg("call tel_get_network_default_subscription()");
720
721         result = tel_get_network_default_subscription(handle, &default_subs);
722         if (result != TAPI_API_SUCCESS) {
723                 msg("failed. (result = %d)", result);
724                 return 0;
725         }
726
727         msg("'default' Subscription for CS (Voice) = %s",
728                         ((default_subs == TAPI_NETWORK_DEFAULT_SUBS_SIM1) ? "SIM 1"
729                         : ((default_subs == TAPI_NETWORK_DEFAULT_SUBS_SIM2) ? "SIM 2"
730                         : "Unknown")));
731
732         return result;
733 }
734
735 static int show_properties (MManager *mm, struct menu_data *menu)
736 {
737         TapiHandle *handle = menu_manager_ref_user_data(mm);
738         int lac = -1,
739                 cellid = -1,
740                 svc_type = -1,
741                 act = -1,
742                 ps_type = -1,
743                 cs = -1,
744                 ps = -1,
745                 roam = -1,
746                 sig_dbm = -1,
747                 sig_level = -1,
748                 option = -1;
749         char *plmn = NULL,
750                  *n_name = NULL,
751                  *s_name = NULL;
752
753         tel_get_property_int (handle, TAPI_PROP_NETWORK_LAC     , &lac);
754         tel_get_property_int (handle, TAPI_PROP_NETWORK_CELLID, &cellid);
755         tel_get_property_int (handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
756         tel_get_property_int (handle, TAPI_PROP_NETWORK_ACT, &act);
757         tel_get_property_string (handle, TAPI_PROP_NETWORK_PLMN, &plmn);
758         tel_get_property_int (handle, TAPI_PROP_NETWORK_PS_TYPE, &ps_type);
759         tel_get_property_int (handle, TAPI_PROP_NETWORK_CIRCUIT_STATUS, &cs);
760         tel_get_property_int (handle, TAPI_PROP_NETWORK_PACKET_STATUS, &ps);
761         tel_get_property_int (handle, TAPI_PROP_NETWORK_SIGNALSTRENGTH_DBM, &sig_dbm);
762         tel_get_property_int (handle, TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, &sig_level);
763         tel_get_property_int (handle, TAPI_PROP_NETWORK_ROAMING_STATUS, &roam);
764         tel_get_property_int (handle, TAPI_PROP_NETWORK_NAME_OPTION, &option);
765         tel_get_property_string (handle, TAPI_PROP_NETWORK_NETWORK_NAME, &n_name);
766         tel_get_property_string (handle, TAPI_PROP_NETWORK_SPN_NAME, &s_name);
767
768         msg (
769                         "  [lac]: 0x%08X   [cellid]: 0x%08X\n"
770                         "  [service_type]: %d    [act]: %d            [plmn]: \"%s\"\n"
771                         "  [ps_type]: %d         [cs_status]: %d      [ps_status]: %d\n"
772                         "  [sig_dbm]: %d         [sig_level]: %d      [roaming_status]: %d\n"
773                         "  [option]: %d  [network_name]: \"%s\"    [spn_name]: \"%s\"",
774                         lac, cellid,
775                         svc_type, act, plmn,
776                         ps_type, cs, ps,
777                         sig_dbm, sig_level, roam,
778                         option, n_name, s_name);
779
780         g_free (plmn);
781         g_free (n_name);
782         g_free (s_name);
783
784         return 0;
785 }
786
787 static struct menu_data menu_net_search[] = {
788         { "1", "run", NULL, run_net_search, NULL},
789         { NULL, NULL, },
790 };
791
792 static struct menu_data menu_net_set_plmn_mode_automatic[] = {
793         { "1", "run", NULL, run_net_set_plmn_mode_automatic, NULL},
794         { NULL, NULL, },
795 };
796
797 static struct menu_data menu_net_set_plmn_mode_manual[] = {
798         { "1", "act", NULL, NULL, data_net_set_plmn_mode_manual_act},
799         { "2", "plmn (45001)", NULL, NULL, data_net_set_plmn_mode_manual_plmn},
800         { "3", "run", NULL, run_net_set_plmn_mode_manual, NULL},
801         { NULL, NULL, },
802 };
803
804 static struct menu_data menu_net_get_plmn_mode[] = {
805         { "1", "run", NULL, run_net_get_plmn_mode, NULL},
806         { NULL, NULL, },
807 };
808
809 static struct menu_data menu_net_set_preferred_plmn[] = {
810         { "1", "mode (1=add, 2=edit, 3=delete)", NULL, NULL, data_net_set_preferred_plmn_mode},
811         { "2", "plmn (45001)", NULL, NULL, data_net_set_preferred_plmn_plmn},
812         { "3", "type (1=GSM, 2=GPRS, 3=EGPRS, 4=UMTS, ...)", NULL, NULL, data_net_set_preferred_plmn_type},
813         { "4", "ef_index (0,...)", NULL, NULL, data_net_set_preferred_plmn_ef_index},
814         { "5", "run", NULL, run_net_set_preferred_plmn, NULL},
815         { NULL, NULL, },
816 };
817
818 static struct menu_data menu_net_get_preferred_plmn[] = {
819         { "1", "run", NULL, run_net_get_preferred_plmn, NULL},
820         { NULL, NULL, },
821 };
822
823
824 static struct menu_data menu_net_set_cancel_manual_search[] = {
825         { "1", "run", NULL, run_net_set_cancel_manual_search, NULL},
826         { NULL, NULL, },
827 };
828
829
830 static struct menu_data menu_net_get_serving_network[] = {
831         { "1", "run", NULL, run_net_get_serving_network, NULL},
832         { NULL, NULL, },
833 };
834
835 static struct menu_data menu_net_set_mode[] = {
836         { "1", "mode (1=GSM, 2=WCDMA, 4=CDMA, 8=LTE)", NULL, NULL, data_net_set_mode_mode},
837         { "3", "run", NULL, run_net_set_mode, NULL},
838         { NULL, NULL, },
839 };
840
841 static struct menu_data menu_net_get_mode[] = {
842         { "1", "run", NULL, run_net_get_mode, NULL},
843         { NULL, NULL, },
844 };
845
846 static struct menu_data menu_net_get_neighboring_cell_info[] = {
847         { "1", "run", NULL, run_net_get_neighboring_cell_info, NULL},
848         { NULL, NULL, },
849 };
850
851 static struct menu_data menu_net_set_default_data_subscription[] = {
852         { "1", "run", NULL, run_net_set_default_data_subscription, NULL},
853         { NULL, NULL, },
854 };
855
856 static struct menu_data menu_net_get_default_data_subscription[] = {
857         { "1", "run", NULL, run_net_get_default_data_subscription, NULL},
858         { NULL, NULL, },
859 };
860
861 static struct menu_data menu_net_set_default_subscription[] = {
862         { "1", "run", 0, run_net_set_default_subscription, 0},
863         { 0, 0, },
864 };
865
866 static struct menu_data menu_net_get_default_subscription[] = {
867         { "1", "run", 0, run_net_get_default_subscription, 0},
868         { 0, 0, },
869 };
870
871 struct menu_data menu_net[] = {
872         { "1", "Search", menu_net_search, NULL, NULL},
873         { "2a", "SET PLMN Selection mode (Automatic)", menu_net_set_plmn_mode_automatic, NULL, NULL},
874         { "2s", "SET PLMN Selection mode (Manual)", menu_net_set_plmn_mode_manual, NULL, NULL},
875         { "2g", "GET PLMN Selection mode", menu_net_get_plmn_mode, NULL, NULL},
876         { "5s", "SET Preferred PLMN", menu_net_set_preferred_plmn, NULL, NULL},
877         { "5g", "GET Preferred PLMN", menu_net_get_preferred_plmn, NULL, NULL},
878         { "6", "SET Cancel manual search", menu_net_set_cancel_manual_search, NULL, NULL},
879         { "7", "GET Serving network", menu_net_get_serving_network, NULL, NULL},
880         { "8s", "SET Mode", menu_net_set_mode, NULL, NULL},
881         { "8g", "GET Mode", menu_net_get_mode, NULL, NULL},
882         { "9g", "GET Neighboring Cell Info", menu_net_get_neighboring_cell_info, NULL, NULL},
883         { "10", "SET Default Data Subscription", menu_net_set_default_data_subscription, NULL, NULL},
884         { "11", "GET Default Data Subscription", menu_net_get_default_data_subscription, NULL, NULL},
885         { "12", "SET Default Subscription (for Voice)", menu_net_set_default_subscription, 0, 0},
886         { "13", "GET Default Subscription (for Voice)", menu_net_get_default_subscription, 0, 0},
887         { "*", "<Properties>", NULL, show_properties, NULL },
888         { NULL, NULL, },
889 };
890
891 void register_network_event (TapiHandle *handle)
892 {
893         int ret;
894
895         /* Signal */
896         ret = tel_register_noti_event (handle,
897                         TAPI_NOTI_NETWORK_REGISTRATION_STATUS,
898                         on_noti_registration_status, NULL);
899         if (ret != TAPI_API_SUCCESS) {
900                 msg("event register failed(%d)", ret);
901         }
902
903         ret = tel_register_noti_event (handle,
904                         TAPI_NOTI_NETWORK_CELLINFO, on_noti_cell_info, NULL);
905         if (ret != TAPI_API_SUCCESS) {
906                 msg("event register failed(%d)", ret);
907         }
908
909         ret = tel_register_noti_event (handle,
910                         TAPI_NOTI_NETWORK_CHANGE, on_noti_change, NULL);
911         if (ret != TAPI_API_SUCCESS) {
912                 msg("event register failed(%d)", ret);
913         }
914
915         ret = tel_register_noti_event (handle,
916                         TAPI_NOTI_NETWORK_TIMEINFO, on_noti_time_info, NULL);
917         if (ret != TAPI_API_SUCCESS) {
918                 msg("event register failed(%d)", ret);
919         }
920
921         ret = tel_register_noti_event (handle,
922                         TAPI_NOTI_NETWORK_IDENTITY, on_noti_identity, NULL);
923         if (ret != TAPI_API_SUCCESS) {
924                 msg("event register failed(%d)", ret);
925         }
926
927         ret = tel_register_noti_event (handle,
928                         TAPI_NOTI_NETWORK_SIGNALSTRENGTH, on_noti_signal_strength, NULL);
929         if (ret != TAPI_API_SUCCESS) {
930                 msg("event register failed(%d)", ret);
931         }
932
933         ret = tel_register_noti_event (handle,
934                         TAPI_NOTI_NETWORK_DEFAULT_DATA_SUBSCRIPTION, on_noti_default_data_subs, NULL);
935         if (ret != TAPI_API_SUCCESS) {
936                 msg("event register failed(%d)", ret);
937         }
938
939         ret = tel_register_noti_event (handle,
940                         TAPI_NOTI_NETWORK_DEFAULT_SUBSCRIPTION, on_noti_default_subs, NULL);
941         if (ret != TAPI_API_SUCCESS) {
942                 msg("event register failed(%d)", ret);
943         }
944
945         /* Property */
946         ret = tel_register_noti_event (handle,
947                         TAPI_PROP_NETWORK_SIGNALSTRENGTH_DBM, on_prop_signal_dbm, NULL);
948         if (ret != TAPI_API_SUCCESS) {
949                 msg("event register failed(%d)", ret);
950         }
951
952         ret = tel_register_noti_event (handle,
953                         TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, on_prop_signal_level, NULL);
954         if (ret != TAPI_API_SUCCESS) {
955                 msg("event register failed(%d)", ret);
956         }
957
958         ret = tel_register_noti_event (handle,
959                         TAPI_PROP_NETWORK_LAC, on_prop_lac, NULL);
960         if (ret != TAPI_API_SUCCESS) {
961                 msg("event register failed(%d)", ret);
962         }
963
964         ret = tel_register_noti_event (handle,
965                         TAPI_PROP_NETWORK_PLMN, on_prop_plmn, NULL);
966         if (ret != TAPI_API_SUCCESS) {
967                 msg("event register failed(%d)", ret);
968         }
969
970         ret = tel_register_noti_event (handle,
971                         TAPI_PROP_NETWORK_CELLID, on_prop_cellid, NULL);
972         if (ret != TAPI_API_SUCCESS) {
973                 msg("event register failed(%d)", ret);
974         }
975
976         ret = tel_register_noti_event (handle,
977                         TAPI_PROP_NETWORK_SERVICE_TYPE, on_prop_service_type, NULL);
978         if (ret != TAPI_API_SUCCESS) {
979                 msg("event register failed(%d)", ret);
980         }
981
982         ret = tel_register_noti_event (handle,
983                         TAPI_PROP_NETWORK_ACT, on_prop_act, NULL);
984         if (ret != TAPI_API_SUCCESS) {
985                 msg("event register failed(%d)", ret);
986         }
987
988         ret = tel_register_noti_event (handle,
989                         TAPI_PROP_NETWORK_PS_TYPE, on_prop_ps_type, NULL);
990         if (ret != TAPI_API_SUCCESS) {
991                 msg("event register failed(%d)", ret);
992         }
993
994         ret = tel_register_noti_event (handle,
995                         TAPI_PROP_NETWORK_CIRCUIT_STATUS, on_prop_circuit_status, NULL);
996         if (ret != TAPI_API_SUCCESS) {
997                 msg("event register failed(%d)", ret);
998         }
999
1000         ret = tel_register_noti_event (handle,
1001                         TAPI_PROP_NETWORK_PACKET_STATUS, on_prop_packet_status, NULL);
1002         if (ret != TAPI_API_SUCCESS) {
1003                 msg("event register failed(%d)", ret);
1004         }
1005
1006         ret = tel_register_noti_event (handle,
1007                         TAPI_PROP_NETWORK_ROAMING_STATUS, on_prop_roaming_status, NULL);
1008         if (ret != TAPI_API_SUCCESS) {
1009                 msg("event register failed(%d)", ret);
1010         }
1011
1012         ret = tel_register_noti_event (handle,
1013                         TAPI_PROP_NETWORK_NAME_OPTION, on_prop_name_option, NULL);
1014         if (ret != TAPI_API_SUCCESS) {
1015                 msg("event register failed(%d)", ret);
1016         }
1017
1018         ret = tel_register_noti_event (handle,
1019                         TAPI_PROP_NETWORK_NETWORK_NAME, on_prop_network_name, NULL);
1020         if (ret != TAPI_API_SUCCESS) {
1021                 msg("event register failed(%d)", ret);
1022         }
1023
1024         ret = tel_register_noti_event (handle,
1025                         TAPI_PROP_NETWORK_SPN_NAME, on_prop_spn_name, NULL);
1026         if (ret != TAPI_API_SUCCESS) {
1027                 msg("event register failed(%d)", ret);
1028         }
1029 }