Tizen 2.1 base
[platform/core/api/system-info.git] / src / system_info_network.c
1 /*
2  * Copyright (c) 2011 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
21 #include <vconf.h>
22 #include <dlog.h>
23
24 #include <tapi_common.h>
25 #include <ITapiModem.h>
26
27 #include <system_info.h>
28 #include <system_info_private.h>
29
30 #ifdef LOG_TAG
31 #undef LOG_TAG
32 #endif
33
34 #define LOG_TAG "CAPI_SYSTEM_INFO"
35
36 int system_info_get_network_type(system_info_key_e key, system_info_data_type_e data_type, void **value)
37 {
38         int service_type = 0;
39         char *NETWORK_TYPE = NULL;
40
41         if (system_info_vconf_get_value_int(VCONFKEY_TELEPHONY_SVCTYPE, &service_type))
42                 return SYSTEM_INFO_ERROR_IO_ERROR;
43
44         switch (service_type) {
45         case VCONFKEY_TELEPHONY_SVCTYPE_NONE:
46                 NETWORK_TYPE = strdup("NoService");
47                 break;
48         case VCONFKEY_TELEPHONY_SVCTYPE_NOSVC:
49                 NETWORK_TYPE = strdup("NoService");
50                 break;
51         case VCONFKEY_TELEPHONY_SVCTYPE_EMERGENCY:
52                 NETWORK_TYPE = strdup("Emergency");
53                 break;
54         case VCONFKEY_TELEPHONY_SVCTYPE_2G:
55                 NETWORK_TYPE = strdup("GSM");
56                 break;
57         case VCONFKEY_TELEPHONY_SVCTYPE_2_5G:
58                 NETWORK_TYPE = strdup("GPRS");
59                 break;
60         case VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE:
61                 NETWORK_TYPE = strdup("EDGE");
62                 break;
63         case VCONFKEY_TELEPHONY_SVCTYPE_3G:
64                 NETWORK_TYPE = strdup("UMTS");
65                 break;
66         case VCONFKEY_TELEPHONY_SVCTYPE_HSDPA:
67                 NETWORK_TYPE = strdup("HSDPA");
68                 break;
69         }
70
71         if (NETWORK_TYPE == NULL) {
72                 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
73                 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
74         }
75
76         *value = NETWORK_TYPE;
77
78         return SYSTEM_INFO_ERROR_NONE;
79 }
80
81 int system_info_get_mobile_device_id(system_info_key_e key, system_info_data_type_e data_type, void **value)
82 {
83         TapiHandle *handle = NULL;
84         char *imei = NULL;
85         char *MOBILE_DEVICE_ID = NULL;
86
87         handle = tel_init(0);
88
89         if (NULL == handle) {
90                 LOGE("tel_init ERROR");
91                 *value = NULL;
92                 return SYSTEM_INFO_ERROR_IO_ERROR;
93         }
94
95         imei = tel_get_misc_me_imei_sync(handle);
96
97         if (imei == NULL) {
98                 LOGE("IMEI value is NULL");
99                 tel_deinit(handle);
100                 *value = NULL;
101                 return SYSTEM_INFO_ERROR_IO_ERROR;
102         }
103
104         MOBILE_DEVICE_ID = strdup((char *)imei);
105
106         if (MOBILE_DEVICE_ID == NULL) {
107                 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
108                 free(imei);
109                 tel_deinit(handle);
110                 *value = NULL;
111                 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
112         }
113
114         free(imei);
115         tel_deinit(handle);
116         *value = MOBILE_DEVICE_ID;
117         return SYSTEM_INFO_ERROR_NONE;
118 }