tizen 2.3 release
[framework/api/telephony.git] / src / telephony_modem.c
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <glib.h>
21 #include <gio/gio.h>
22 #include <dlog.h>
23
24 #include <tapi_common.h>
25 #include <ITapiModem.h>
26 #include "telephony_common.h"
27 #include "telephony_modem.h"
28 #include "telephony_private.h"
29
30 #ifdef LOG_TAG
31 #undef LOG_TAG
32 #endif
33 #define LOG_TAG "CAPI_TELEPHONY"
34
35 #define CHECK_INPUT_PARAMETER(arg) \
36         if (arg == NULL) { \
37                 LOGE("INVALID_PARAMETER"); \
38                 return TELEPHONY_ERROR_INVALID_PARAMETER; \
39         }
40
41 int telephony_modem_get_imei(telephony_h handle, char **imei)
42 {
43         GVariant *gv = NULL;
44         GError *gerr = NULL;
45         int tapi_result;
46         char *tapi_imei;
47         int error = TELEPHONY_ERROR_OPERATION_FAILED;
48         TapiHandle *tapi_h;
49
50         CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE);
51         CHECK_INPUT_PARAMETER(handle);
52         tapi_h = ((telephony_data *)handle)->tapi_h;
53         CHECK_INPUT_PARAMETER(tapi_h);
54         CHECK_INPUT_PARAMETER(imei);
55
56         gv = g_dbus_connection_call_sync(tapi_h->dbus_connection,
57                 DBUS_TELEPHONY_SERVICE, tapi_h->path, DBUS_TELEPHONY_MODEM_INTERFACE,
58                 "GetIMEI", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerr);
59
60         if (gv) {
61                 g_variant_get(gv, "(is)", &tapi_result, &tapi_imei);
62                 if (tapi_result == 0) {
63                         if (tapi_imei != NULL && strlen(tapi_imei) != 0) {
64                                 *imei = g_strdup_printf("%s", tapi_imei);
65                                 error = TELEPHONY_ERROR_NONE;
66                         }
67                 }
68         } else {
69                 LOGE("g_dbus_conn failed. error (%s)", gerr->message);
70                 if (strstr(gerr->message, "No access rights")) {
71                         LOGE("PERMISSION_DENIED");
72                         error = TELEPHONY_ERROR_PERMISSION_DENIED;
73                 }
74         }
75
76         return error;
77 }