Add tfeature definition and functionality
[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_model_config()
98 {
99         char *model_name;
100         int ret;
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 (SYSTEM_INFO_ERROR_NONE == ret && model_name) {
108                 TFEATURE_INFO("model_name[%s]", model_name);
109                 free(model_name);
110         }
111         system_info_get_platform_bool("tizen.org/feature/network.telephony.service.cdma", &b_cdma_supported);
112         system_info_get_platform_bool("tizen.org/feature/network.telephony.service.gsm", &b_gsm_supported);
113         system_info_get_platform_bool("tizen.org/feature/network.telephony.service.umts", &b_umts_suported);
114         system_info_get_platform_bool("tizen.org/feature/network.telephony.service.lte", &b_lte_supported);
115
116         if(true == b_lte_supported && false == b_gsm_supported && false == b_umts_suported && false == b_cdma_supported){
117                 TFEATURE_INFO("LTE only model");
118                 SET_FEATURE(TFEATURE_DEVICE_LTE_ONLY);
119         }
120 }
121
122 static void _tfeature_print_hex_dump()
123 {
124         char buf[255] = {0, };
125         char hex[4] = {0, };
126         int i = 0;
127
128         g_snprintf(buf, 255, "%s%04X: ", "[FEATURE_LIST]", 0);
129         for (i = 0; i < (int)MAX_FEATURE_LIST_BYTES; i++) {
130                 g_snprintf(hex, 4, "%02X ", features.feature_list[i]);
131                 memcpy(buf + strlen(buf), hex, 4);
132
133                 if ((i + 1) % 8 == 0) {
134                         if ((i + 1) % 16 == 0) {
135                                 TFEATURE_INFO("%s", buf);
136                                 memset(buf, 0, 255);
137                                 g_snprintf(buf, 255, "%s%04X: ", "[FEATURE_LIST]", i + 1);
138                         } else {
139                                 g_strlcat (buf, "  ", 255);
140                         }
141                 }
142         }
143
144         TFEATURE_INFO("%s", buf);
145 }
146
147 static void _tfeature_init(void)
148 {
149         _tfeature_check_default_feature();
150         _tfeature_check_build_feature();
151         _tfeature_check_model_config();
152
153         _tfeature_print_hex_dump();
154         features.valid = TRUE;
155 }
156
157 tfeature_support tfeature_is_supported(tfeature_name feature)
158 {
159         tfeature_support ret = TFEATURE_NOT_SUPPORTED;
160
161         if (!features.valid) {
162                 _tfeature_init();
163         }
164
165         if (features.valid && feature < TFEATURE_MAX_VALUE) {
166                 if (CHECK_FEATURE(feature))
167                         ret = TFEATURE_SUPPORTED;
168                 else
169                         ret = TFEATURE_NOT_SUPPORTED;
170         }
171
172         return ret;
173 }