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