Initialize Tizen 2.3
[framework/telephony/libslp-tapi.git] / test_src / modem.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 <ITapiModem.h>
30 #include <TapiUtility.h>
31
32 #include "menu.h"
33 #include "modem.h"
34
35 static char data_modem_set_flight_mode_mode[MENU_DATA_SIZE + 1] = "1";
36 static char data_modem_set_power_mode[MENU_DATA_SIZE + 1] = "1";
37
38 static void on_noti_modem_power(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
39 {
40         int *status = data;
41
42         msg("");
43         msgb("event(%s) receive !!", TAPI_NOTI_MODEM_POWER);
44
45         if (!status)
46                 return;
47
48         msg(" - status = 0x%x", *status);
49 }
50
51 static void on_modem_get_version(TapiHandle *handle, int result, void *data, void *user_data)
52 {
53         TelMiscVersionInformation *info = data;
54
55         msg("");
56         msgb("tel_get_misc_me_version() response receive");
57         msg(" - result = 0x%x", result);
58
59         if (!info)
60                 return;
61
62         msg(" - sw version = %s", info->szSwVersion);
63         msg(" - hw version = %s", info->szHwVersion);
64         msg(" - RfCal Date = %s", info->szRfCalDate);
65         msg(" - Product Code = %s", info->szProductCode);
66         msg(" - Model ID = %s", info->szModelId);
67 }
68
69 static void on_modem_get_serial_number(TapiHandle *handle, int result, void *data, void *user_data)
70 {
71         TelMiscSNInformation *sn = data;
72
73         msg("");
74         msgb("tel_get_misc_me_sn() response receive");
75         msg(" - result = 0x%x", result);
76
77         if (!sn)
78                 return;
79
80         msg(" - esn number = %s", sn->szEsn);
81         msg(" - meid number = %s", sn->szMeid);
82
83 }
84
85 static void on_modem_get_imei(TapiHandle *handle, int result, void *data, void *user_data)
86 {
87         char *imei = data;
88
89         msg("");
90         msgb("tel_get_misc_me_imei() response receive");
91         msg(" - result = 0x%x", result);
92
93         if (!imei)
94                 return;
95
96         msg(" - IMEI = %s", imei);
97 }
98
99 static void on_modem_get_flight_mode(TapiHandle *handle, int result, void *data, void *user_data)
100 {
101         gboolean *mode = data;
102
103         msg("");
104         msgb("tel_get_flight_mode() response receive");
105         msg(" - result = 0x%x", result);
106
107         if (data)
108                 msg(" - mode = %d", *mode);
109 }
110
111 static void on_modem_set_flight_mode(TapiHandle *handle, int result, void *data, void *user_data)
112 {
113         msg("");
114         msgb("tel_set_flight_mode() response receive");
115         msg(" - result = %s", (result == 1) ? "ON" : (result == 2) ? "OFF" : "FAIL" );
116 }
117
118 static void on_modem_set_power(TapiHandle *handle, int result, void *data, void *user_data)
119 {
120         msg("");
121         msgb("tel_process_power_command() response receive");
122         msg(" - result = 0x%x", result);
123 }
124
125 static int run_modem_get_version(MManager *mm, struct menu_data *menu)
126 {
127         TapiHandle *handle = menu_manager_ref_user_data(mm);
128         int result;
129
130         msg("call tel_get_misc_me_version()");
131
132         result = tel_get_misc_me_version(handle, on_modem_get_version, NULL);
133         if (result != TAPI_API_SUCCESS) {
134                 msg("failed. (result = %d)", result);
135         }
136
137         return 0;
138 }
139
140 static int run_modem_get_version_sync(MManager *mm, struct menu_data *menu)
141 {
142         TapiHandle *handle = menu_manager_ref_user_data(mm);
143         TelMiscVersionInformation *info;
144
145         msg("call tel_get_misc_me_version_sync()");
146
147         info = tel_get_misc_me_version_sync(handle);
148         if (!info) {
149                 msg("failed.");
150                 return 0;
151         }
152
153         msg(" - sw version = %s", info->szSwVersion);
154         msg(" - hw version = %s", info->szHwVersion);
155         msg(" - RfCal Date = %s", info->szRfCalDate);
156         msg(" - Product Code = %s", info->szProductCode);
157         msg(" - Model ID = %s", info->szModelId);
158
159         free(info);
160
161         return 0;
162 }
163
164 static int run_modem_get_serial_number(MManager *mm, struct menu_data *menu)
165 {
166         TapiHandle *handle = menu_manager_ref_user_data(mm);
167         int result;
168
169         msg("call tel_get_misc_me_sn()");
170
171         result = tel_get_misc_me_sn(handle, on_modem_get_serial_number, NULL);
172         if (result != TAPI_API_SUCCESS) {
173                 msg("failed. (result = %d)", result);
174         }
175
176         return 0;
177 }
178
179 static int run_modem_get_serial_number_sync(MManager *mm, struct menu_data *menu)
180 {
181         TapiHandle *handle = menu_manager_ref_user_data(mm);
182         TelMiscSNInformation *sn;
183
184         msg("call tel_get_misc_me_sn_sync()");
185
186         sn = tel_get_misc_me_sn_sync(handle);
187         if (!sn) {
188                 msg("failed.");
189                 return 0;
190         }
191
192         msg(" - esn number = [%s]", sn->szEsn);
193         msg(" - meid number = [%s]", sn->szMeid);
194
195         free(sn);
196
197         return 0;
198 }
199
200 static int run_modem_get_imei(MManager *mm, struct menu_data *menu)
201 {
202         TapiHandle *handle = menu_manager_ref_user_data(mm);
203         int result;
204
205         msg("call tel_get_misc_me_imei()");
206
207         result = tel_get_misc_me_imei(handle, on_modem_get_imei, NULL);
208         if (result != TAPI_API_SUCCESS) {
209                 msg("failed. (result = %d)", result);
210         }
211
212         return 0;
213 }
214
215 static int run_modem_get_imei_sync(MManager *mm, struct menu_data *menu)
216 {
217         TapiHandle *handle = menu_manager_ref_user_data(mm);
218         char *imei;
219
220         msg("call tel_get_misc_me_imei_sync()");
221
222         imei = tel_get_misc_me_imei_sync(handle);
223         if (!imei) {
224                 msg("failed.");
225                 return 0;
226         }
227
228         msg(" - imei = [%s]", imei);
229
230         free(imei);
231
232         return 0;
233 }
234
235 static int run_modem_set_power(MManager *mm, struct menu_data *menu)
236 {
237         TapiHandle *handle = menu_manager_ref_user_data(mm);
238         int result;
239         int mode;
240
241         msg("call tel_process_power_command()");
242
243         mode = atoi(data_modem_set_power_mode);
244
245         result = tel_process_power_command(handle, mode, on_modem_set_power, NULL);
246         if (result != TAPI_API_SUCCESS) {
247                 msg("failed. (result = %d)", result);
248         }
249
250         return 0;
251 }
252
253 static int run_modem_set_flight_mode(MManager *mm, struct menu_data *menu)
254 {
255         TapiHandle *handle = menu_manager_ref_user_data(mm);
256         int result;
257         int mode;
258
259         msg("call tel_set_flight_mode()");
260
261         mode = atoi(data_modem_set_flight_mode_mode);
262
263         result = tel_set_flight_mode(handle, mode, on_modem_set_flight_mode, NULL);
264         if (result != TAPI_API_SUCCESS) {
265                 msg("failed. (result = %d)", result);
266         }
267
268         return 0;
269 }
270
271 static int run_modem_get_flight_mode(MManager *mm, struct menu_data *menu)
272 {
273         TapiHandle *handle = menu_manager_ref_user_data(mm);
274         int result;
275
276         msg("call tel_get_flight_mode()");
277
278         result = tel_get_flight_mode(handle, on_modem_get_flight_mode, NULL);
279         if (result != TAPI_API_SUCCESS) {
280                 msg("failed. (result = %d)", result);
281         }
282
283         return 0;
284 }
285
286 static int run_modem_check_power(MManager *mm, struct menu_data *menu)
287 {
288         TapiHandle *handle = menu_manager_ref_user_data(mm);
289         int result;
290         int status = 0;
291
292         msg("call tel_check_modem_power_status()");
293
294         result = tel_check_modem_power_status(handle, &status);
295         if (result != TAPI_API_SUCCESS) {
296                 msg("failed. (result = %d)", result);
297                 return 0;
298         }
299
300         msg(" - status = %d", status);
301
302         return 0;
303 }
304
305 static struct menu_data menu_modem_get_version[] = {
306         { "1", "run", NULL, run_modem_get_version, NULL},
307         { NULL, NULL, },
308 };
309
310 static struct menu_data menu_modem_get_version_sync[] = {
311         { "1", "run", NULL, run_modem_get_version_sync, NULL},
312         { NULL, NULL, },
313 };
314
315 static struct menu_data menu_modem_get_serial_number[] = {
316         { "1", "run", NULL, run_modem_get_serial_number, NULL},
317         { NULL, NULL, },
318 };
319
320 static struct menu_data menu_modem_get_serial_number_sync[] = {
321         { "1", "run", NULL, run_modem_get_serial_number_sync, NULL},
322         { NULL, NULL, },
323 };
324
325 static struct menu_data menu_modem_get_imei[] = {
326         { "1", "run", NULL, run_modem_get_imei, NULL},
327         { NULL, NULL, },
328 };
329
330 static struct menu_data menu_modem_get_imei_sync[] = {
331         { "1", "run", NULL, run_modem_get_imei_sync, NULL},
332         { NULL, NULL, },
333 };
334
335 static struct menu_data menu_modem_get_flight_mode[] = {
336         { "1", "run", NULL, run_modem_get_flight_mode, NULL},
337         { NULL, NULL, },
338 };
339
340 static struct menu_data menu_modem_set_flight_mode[] = {
341         { "1", "mode (1=ON, 2=OFF)", NULL, NULL, data_modem_set_flight_mode_mode},
342         { "2", "run", NULL, run_modem_set_flight_mode, NULL},
343         { NULL, NULL, },
344 };
345
346 static struct menu_data menu_modem_set_power[] = {
347         { "1", "mode (0=ON, 1=OFF, 2=RESET, 3=LOW)", NULL, NULL, data_modem_set_power_mode},
348         { "2", "run", NULL, run_modem_set_power, NULL},
349         { NULL, NULL, },
350 };
351
352 static struct menu_data menu_modem_check_power[] = {
353         { "1", "run (sync api)", NULL, run_modem_check_power, NULL},
354         { "-", "(-1=unknown, 0=on, 1=off, 2=rst, 3=low, 4=err)", NULL, NULL, NULL},
355         { NULL, NULL, },
356 };
357
358 struct menu_data menu_modem[] = {
359         { "1", "tel_get_misc_me_version", menu_modem_get_version, NULL, NULL},
360         { "1s", "tel_get_misc_me_version_sync", menu_modem_get_version_sync, NULL, NULL},
361         { "2", "tel_get_misc_me_sn", menu_modem_get_serial_number, NULL, NULL},
362         { "2s", "tel_get_misc_me_sn_sync", menu_modem_get_serial_number_sync, NULL, NULL},
363         { "3", "tel_get_misc_me_imei", menu_modem_get_imei, NULL, NULL},
364         { "3s", "tel_get_misc_me_imei_sync", menu_modem_get_imei_sync, NULL, NULL},
365         { "4", "tel_get_flight_mode", menu_modem_get_flight_mode, NULL, NULL},
366         { "4s", "tel_set_flight_mode", menu_modem_set_flight_mode, NULL, NULL},
367         { "5", "tel_process_power_command", menu_modem_set_power, NULL, NULL},
368         { "6", "tel_check_modem_power_status", menu_modem_check_power, NULL, NULL},
369         { NULL, NULL, },
370 };
371
372 void register_modem_event(TapiHandle *handle)
373 {
374         int ret;
375
376         ret = tel_register_noti_event(handle, TAPI_NOTI_MODEM_POWER, on_noti_modem_power, NULL);
377         if (ret != TAPI_API_SUCCESS) {
378                 msg("event register failed(%d)", ret);
379         }
380 }