2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef __TIZEN_PROFILE_H__
21 #define __TIZEN_PROFILE_H__
25 #include <iniparser.h>
26 #include <libxml/xmlmemory.h>
27 #include <libxml/parser.h>
28 #include <libxml/tree.h>
30 #define MODEL_CONFIG_FILE "/etc/config/model-config.xml"
31 #define TYPE_FIELD "string"
32 #define FEATURE_TAG "platform"
33 #define MODEL_CONFIG_TAG "model-config"
34 #define CERTI_STACK_FILE "/var/lib/bluetooth/stack_test"
35 #define CERTI_PROFILE_FILE "/var/lib/bluetooth/profile_test"
39 TIZEN_PROFILE_UNKNOWN = 0,
40 TIZEN_PROFILE_MOBILE = 0x1,
41 TIZEN_PROFILE_WEARABLE = 0x2,
42 TIZEN_PROFILE_TV = 0x4,
43 TIZEN_PROFILE_IVI = 0x8,
44 TIZEN_PROFILE_IOT = 0x10,
45 TIZEN_PROFILE_COMMON = 0x20,
49 TIZEN_MODEL_UNKNOWN = 0,
50 TIZEN_MODEL_COMMON = 0x1,
51 TIZEN_MODEL_TM1 = 0x2,
52 TIZEN_MODEL_TM2 = 0x4,
53 TIZEN_MODEL_TW1 = 0x8,
54 TIZEN_MODEL_TW2 = 0x10,
55 TIZEN_MODEL_TW3 = 0x20,
56 TIZEN_MODEL_RPI3 = 0x40,
57 TIZEN_MODEL_ROBOT = 0x80,
58 TIZEN_MODEL_FHUB = 0x100,
59 TIZEN_MODEL_DA = 0x200,
63 TIZEN_CERTI_MODE_UNKNOWN = 0,
64 TIZEN_CERTI_MODE_DISABLE = 0x1,
65 TIZEN_CERTI_MODE_STACK = 0x2,
66 TIZEN_CERTI_MODE_PROFILE = 0x4,
67 } tizen_certifcation_mode_t;
69 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
70 static tizen_model_t model = TIZEN_MODEL_UNKNOWN;
71 static tizen_certifcation_mode_t certification_mode = TIZEN_CERTI_MODE_UNKNOWN;
73 static inline int __get_profile_from_model_config_xml(const char *field, char **value)
75 char *node_name = NULL;
76 char *node_value = NULL;
77 xmlNode *cur_node = NULL;
78 xmlNodePtr cur_ptr = NULL;
79 xmlNodePtr model_ptr = NULL;
80 xmlDocPtr xml_doc = NULL;
82 xml_doc = xmlParseFile(MODEL_CONFIG_FILE);
86 cur_ptr = xmlDocGetRootElement(xml_doc);
87 if (cur_ptr == NULL) {
92 for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) {
93 if (!xmlStrcmp(cur_ptr->name, (const xmlChar*)MODEL_CONFIG_TAG))
97 if (cur_ptr == NULL) {
102 cur_ptr = cur_ptr->xmlChildrenNode;
103 for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) {
104 if (!xmlStrcmp(cur_node->name, (const xmlChar*)FEATURE_TAG)) {
105 model_ptr = cur_node;
110 if (model_ptr == NULL) {
116 cur_ptr = model_ptr->xmlChildrenNode;
118 for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) {
119 if (cur_node->type == XML_ELEMENT_NODE) {
120 node_name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name");
122 if (!strncmp(node_name, field, strlen(node_name))) {
123 node_value = (char *)xmlNodeListGetString(xml_doc, cur_node->xmlChildrenNode, 1);
125 *value = strdup(node_value);
140 static inline tizen_profile_t _get_tizen_profile(void)
142 char *profile_name = NULL;
144 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
147 if (__get_profile_from_model_config_xml("tizen.org/feature/profile",
148 &profile_name) < 0) {
149 profile = TIZEN_PROFILE_MOBILE;
153 if (profile_name == NULL) {
154 profile = TIZEN_PROFILE_MOBILE;
158 switch (*profile_name) {
161 profile = TIZEN_PROFILE_MOBILE;
165 profile = TIZEN_PROFILE_WEARABLE;
169 profile = TIZEN_PROFILE_TV;
173 if (!strncasecmp(profile_name, "ivi", 3))
174 profile = TIZEN_PROFILE_IVI;
175 else if (!strncasecmp(profile_name, "iot", 3))
176 profile = TIZEN_PROFILE_IOT;
178 profile = TIZEN_PROFILE_COMMON;
180 default: /* common or unknown ==> ALL ARE COMMON */
181 profile = TIZEN_PROFILE_COMMON;
188 static inline tizen_model_t _get_tizen_model(void)
190 char *model_name = NULL;
192 if (__builtin_expect(model != TIZEN_MODEL_UNKNOWN, 1))
195 if (__get_profile_from_model_config_xml("tizen.org/system/model_name",
197 model = TIZEN_MODEL_COMMON;
201 if (model_name == NULL) {
202 model = TIZEN_MODEL_COMMON;
206 if (!strcasecmp(model_name, "TM1"))
207 model = TIZEN_MODEL_TM1;
208 else if (!strcasecmp(model_name, "TM2"))
209 model = TIZEN_MODEL_TM2;
210 else if (!strcasecmp(model_name, "TW1"))
211 model = TIZEN_MODEL_TW1;
212 else if (!strcasecmp(model_name, "TW2"))
213 model = TIZEN_MODEL_TW2;
214 else if (!strcasecmp(model_name, "TW3"))
215 model = TIZEN_MODEL_TW3;
216 else if (!strcasecmp(model_name, "rpi3"))
217 model = TIZEN_MODEL_RPI3;
218 else if (!strcasecmp(model_name, "gems") || !strncasecmp(model_name, "ServingBot", 10))
219 model = TIZEN_MODEL_ROBOT;
220 else if (!strncasecmp(model_name, "Family Hub", 10))
221 model = TIZEN_MODEL_FHUB;
222 else if (!strcasecmp(model_name, "Robot Vacuum Cleaner") ||
223 !strcasecmp(model_name, "Smart Dryer") ||
224 !strcasecmp(model_name, "Smart Washer") ||
225 !strcasecmp(model_name, "DDMS"))
226 model = TIZEN_MODEL_DA;
228 model = TIZEN_MODEL_COMMON;
235 static inline tizen_certifcation_mode_t _get_tizen_certification_mode(void)
237 if (__builtin_expect(certification_mode != TIZEN_CERTI_MODE_UNKNOWN, 1))
238 return certification_mode;
240 if (access(CERTI_STACK_FILE, F_OK) == 0)
241 certification_mode |= TIZEN_CERTI_MODE_STACK;
243 if (access(CERTI_PROFILE_FILE, F_OK) == 0)
244 certification_mode |= TIZEN_CERTI_MODE_PROFILE;
246 if (certification_mode == TIZEN_CERTI_MODE_UNKNOWN)
247 certification_mode = TIZEN_CERTI_MODE_DISABLE;
249 return certification_mode;
252 #define TIZEN_FEATURE_BLUEZ_BRCM_CHIP ((_get_tizen_profile()) == TIZEN_PROFILE_IVI)
253 #define TIZEN_FEATURE_BLUEZ_WEARABLE ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE)
254 #define TIZEN_FEATURE_BLUEZ_SMS_ONLY ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE)
255 #define TIZEN_FEATURE_BLUEZ_BRCM_QOS ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE)
256 #define TIZEN_FEATURE_BLUEZ_ROLE_CHANGE ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE)
257 #define TIZEN_FEATURE_BLUEZ_CONFIRM_ONLY ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE)
258 #define TIZEN_FEATURE_BLUEZ_SPRD_QOS ((_get_tizen_model()) == TIZEN_MODEL_TM1)
259 #define TIZEN_FEATURE_BLUEZ_SPRD_PAGE_SCAN ((_get_tizen_model()) == TIZEN_MODEL_TM1)
260 #define TIZEN_FEATURE_BLUEZ_SPEAKER_REFERENCE ((_get_tizen_model()) == TIZEN_MODEL_RPI3 && (_get_tizen_profile()) == TIZEN_PROFILE_COMMON)
261 #define TIZEN_FEATURE_ROBOT_REFERENCE ((_get_tizen_model()) == TIZEN_MODEL_ROBOT)
262 #define TIZEN_FEATURE_BLUEZ_FHUB ((_get_tizen_model()) == TIZEN_MODEL_FHUB)
263 #define TIZEN_FEATURE_BLUEZ_DA ((_get_tizen_model()) == TIZEN_MODEL_FHUB || (_get_tizen_model()) == TIZEN_MODEL_DA)
264 #define TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION (((_get_tizen_certification_mode()) & TIZEN_CERTI_MODE_STACK) != 0)
265 #define TIZEN_FEATURE_BLUEZ_PROFILE_CERTIFICATION (((_get_tizen_certification_mode()) & TIZEN_CERTI_MODE_PROFILE) != 0)
267 #endif /* __TIZEN_PROFILE_H__ */