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