Fix svace issue
[platform/core/telephony/tel-plugin-database.git] / feature / tfeature.c
1 /*
2  * libtfeature
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Junghwan Song <jump.song@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
22
23 #include "tfeature.h"
24
25 #include <stdlib.h>
26 #include <glib.h>
27 #include <system_info.h>
28 #include <dlog.h>
29
30 #define TFEATURE_LOG_TAG "TFEATURE"
31 #define TFEATURE_INFO(fmt, args...) do { RLOG(LOG_INFO, TFEATURE_LOG_TAG, fmt "\n", ##args); } while (0)
32 #define TFEATURE_WARN(fmt, args...) do { RLOG(LOG_WARN, TFEATURE_LOG_TAG, fmt "\n", ##args); } while (0)
33 #define TFEATURE_ERR(fmt, args...) do { RLOG(LOG_ERROR, TFEATURE_LOG_TAG, fmt "\n", ##args); } while (0)
34
35 #define FEATURE_BITS                    (sizeof(unsigned char) * 8)
36 #define MAX_FEATURE_LIST_BYTES  (FEATURE_BITS * 4)
37 #define SET_FEATURE(X) \
38 { \
39         if (X < TFEATURE_MAX_VALUE) { \
40                 features.feature_list[(X) / FEATURE_BITS] |= ((unsigned char) 1) << ((X) % FEATURE_BITS); \
41                 TFEATURE_INFO("feature[0x%02x] is supported.", (X)); \
42         } else { \
43                 TFEATURE_ERR("invalid feature[0x%02x]", X); \
44         } \
45 }
46 #define CHECK_FEATURE(X) (features.feature_list[(X) / FEATURE_BITS] & ((unsigned char) 1) << ((X) % FEATURE_BITS))
47
48 typedef struct {
49         gboolean valid;
50         unsigned char feature_list[MAX_FEATURE_LIST_BYTES];     // support 255 (2 ^ FEATURE_BITS) features
51 } q_feature_info;
52
53 static q_feature_info features = {FALSE, {0,} };
54
55 static void _tfeature_check_default_feature(void)
56 {
57         SET_FEATURE(TFEATURE_UI_NO_SVC_MANUAL_PLMN_CHECK);
58         SET_FEATURE(TFEATURE_FUNCTION_REFER_EONS_ON_MANUAL_SEARCH);
59 }
60
61 static void _tfeature_check_build_feature(void)
62 {
63 /* Build Feature */
64 #ifdef TIZEN_FEATURE_CDMA
65         SET_FEATURE(TFEATURE_FUNCTION_ENABLE_CDMA);
66 #endif /* TIZEN_FEATURE_CDMA*/
67
68 #ifdef TIZEN_FEATURE_NO_DISPLAY_PANEL
69         SET_FEATURE(TFEATURE_DEVICE_NO_DISPLAY_PANEL);
70 #endif /* TIZEN_FEATURE_NO_DISPLAY_PANEL*/
71
72 #ifdef TIZEN_FEATURE_WEARABLE
73         SET_FEATURE(TFEATURE_DEVICE_WEARABLE);
74         SET_FEATURE(TFEATURE_FUNCTION_IMS_PDN_AUTO_ACTIVATE);
75 #else
76         SET_FEATURE(TFEATURE_FUNCTION_MANAGER_NETWORK_NAME_ENABLE);
77         SET_FEATURE(TFEATURE_FUNCTION_IMS_PDN_AUTO_ACTIVATE);
78 #endif /* TIZEN_FEATURE_WEARABLE */
79
80 #ifdef TIZEN_FEATURE_CHIPSET_VENDOR_EXYNOS
81         SET_FEATURE(TFEATURE_FUNCTION_MANAGER_NETWORK_NAME_ENABLE);
82         SET_FEATURE(TFEATURE_FUNCTION_ENABLE_IPV6_RSRA);
83         SET_FEATURE(TFEATURE_FUNCTION_NET_CHECK_ECC_RAT);
84         SET_FEATURE(TFEATURE_FUNCTION_SEND_APN_INFO);
85         SET_FEATURE(TFEATURE_DEVICE_CHIPSET_VENDOR_EXYNOS);
86 #endif /* TIZEN_FEATURE_CHIPSET_VENDOR_EXYNOS*/
87
88 #ifdef TIZEN_FEATURE_CHIPSET_VENDOR_SPREADTRUM
89         #ifdef TIZEN_FEATURE_PROTOCOL_ATCMD
90         #else
91                 SET_FEATURE(TFEATURE_FUNCTION_SEND_APN_INFO);
92                 SET_FEATURE(TFEATURE_FUNCTION_NET_CHECK_ECC_RAT);
93         #endif
94 #endif
95 }
96
97 static void _tfeature_check_platform_feature()
98 {
99         int ret;
100         char *model_name;
101         bool b_lte_supported = false;
102         bool b_gsm_supported = false;
103         bool b_umts_suported = false;
104         bool b_cdma_supported = false;
105
106         ret = system_info_get_platform_string("http://tizen.org/system/model_name", &model_name);
107         if (ret != SYSTEM_INFO_ERROR_NONE) {
108                 TFEATURE_INFO("system_info_get_platform_string() failed!!! (%d,%s)", ret, get_error_message(ret));
109                 return;
110         }
111
112         TFEATURE_INFO("model_name[%s]", model_name);
113         if (!g_strcmp0(model_name, "TW2")) {
114                 SET_FEATURE(TFEATURE_DEVICE_CHIPSET_VENDOR_EXYNOS);
115                 SET_FEATURE(TFEATURE_FUNCTION_SEND_APN_INFO);
116         }
117
118         free(model_name);
119
120         system_info_get_platform_bool("tizen.org/feature/network.telephony.service.cdma", &b_cdma_supported);
121         system_info_get_platform_bool("tizen.org/feature/network.telephony.service.gsm", &b_gsm_supported);
122         system_info_get_platform_bool("tizen.org/feature/network.telephony.service.umts", &b_umts_suported);
123         system_info_get_platform_bool("tizen.org/feature/network.telephony.service.lte", &b_lte_supported);
124
125         if (true == b_lte_supported) {
126                 TFEATURE_INFO("LTE SUPPORTED");
127                 SET_FEATURE(TFEATURE_DEVICE_LTE_SUPPORTED);
128         }
129
130         if (true == b_lte_supported && false == b_gsm_supported && false == b_umts_suported && false == b_cdma_supported) {
131                 TFEATURE_INFO("LTE only model");
132                 SET_FEATURE(TFEATURE_DEVICE_LTE_ONLY);
133         }
134 }
135
136 static void _tfeature_print_hex_dump()
137 {
138         char buf[255] = {0, };
139         char hex[4] = {0, };
140         int i = 0;
141
142         g_snprintf(buf, 255, "%s%04X: ", "[FEATURE_LIST]", 0);
143         for (i = 0; i < (int)MAX_FEATURE_LIST_BYTES; i++) {
144                 g_snprintf(hex, 4, "%02X ", features.feature_list[i]);
145                 memcpy(buf + strlen(buf), hex, 4);
146
147                 if ((i + 1) % 8 == 0) {
148                         if ((i + 1) % 16 == 0) {
149                                 TFEATURE_INFO("%s", buf);
150                                 memset(buf, 0, 255);
151                                 g_snprintf(buf, 255, "%s%04X: ", "[FEATURE_LIST]", i + 1);
152                         } else {
153                                 g_strlcat(buf, "  ", 255);
154                         }
155                 }
156         }
157
158         TFEATURE_INFO("%s", buf);
159 }
160
161 static void _tfeature_init(void)
162 {
163         _tfeature_check_default_feature();
164         _tfeature_check_build_feature();
165         _tfeature_check_platform_feature();
166
167         _tfeature_print_hex_dump();
168         features.valid = TRUE;
169 }
170
171 tfeature_support tfeature_is_supported(tfeature_name feature)
172 {
173         tfeature_support ret = TFEATURE_NOT_SUPPORTED;
174
175         if (!features.valid) {
176                 _tfeature_init();
177                 TFEATURE_INFO("TFEATURE INITIALIZED!!!");
178         }
179
180         if (features.valid && feature < TFEATURE_MAX_VALUE) {
181                 if (CHECK_FEATURE(feature))
182                         ret = TFEATURE_SUPPORTED;
183                 else
184                         ret = TFEATURE_NOT_SUPPORTED;
185         }
186
187         return ret;
188 }