/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef __TIZEN_PROFILE_H__ #define __TIZEN_PROFILE_H__ #include #include #include #include #include #define MODEL_CONFIG_FILE "/etc/config/model-config.xml" #define TYPE_FIELD "string" #define FEATURE_TAG "platform" #define MODEL_CONFIG_TAG "model-config" typedef enum { TIZEN_PROFILE_UNKNOWN = 0, TIZEN_PROFILE_MOBILE = 0x1, TIZEN_PROFILE_WEARABLE = 0x2, TIZEN_PROFILE_TV = 0x4, TIZEN_PROFILE_IVI = 0x8, TIZEN_PROFILE_IOT = 0x10, TIZEN_PROFILE_COMMON = 0x20, } tizen_profile_t; typedef enum { TIZEN_MODEL_UNKNOWN = 0, TIZEN_MODEL_COMMON = 0x1, TIZEN_MODEL_TM1 = 0x2, TIZEN_MODEL_TM2 = 0x4, TIZEN_MODEL_TW1 = 0x8, TIZEN_MODEL_TW2 = 0x10, TIZEN_MODEL_TW3 = 0x20, TIZEN_MODEL_RPI3 = 0x40, } tizen_model_t; static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN; static tizen_model_t model = TIZEN_MODEL_UNKNOWN; static inline int __get_profile_from_model_config_xml(const char *field, char **value) { char *node_name = NULL; char *node_value = NULL; xmlNode *cur_node = NULL; xmlNodePtr cur_ptr = NULL; xmlNodePtr model_ptr = NULL; xmlDocPtr xml_doc = NULL; xml_doc = xmlParseFile(MODEL_CONFIG_FILE); if (xml_doc == NULL) return -1; cur_ptr = xmlDocGetRootElement(xml_doc); if (cur_ptr == NULL) { xmlFreeDoc(xml_doc); return -1; } for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) { if (!xmlStrcmp(cur_ptr->name, (const xmlChar*)MODEL_CONFIG_TAG)) break; } if (cur_ptr == NULL) { xmlFreeDoc(xml_doc); return -1; } cur_ptr = cur_ptr->xmlChildrenNode; for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) { if (!xmlStrcmp(cur_node->name, (const xmlChar*)FEATURE_TAG)) { model_ptr = cur_node; break; } } if (model_ptr == NULL) { xmlFreeDoc(xml_doc); return -1; } if (model_ptr) { cur_ptr = model_ptr->xmlChildrenNode; for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { node_name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name"); if (!strncmp(node_name, field, strlen(node_name))) { node_value = (char *)xmlNodeListGetString(xml_doc, cur_node->xmlChildrenNode, 1); if (node_value) { *value = strdup(node_value); free(node_name); free(node_value); break; } } free(node_name); } } } xmlFreeDoc(xml_doc); return 0; } static inline tizen_profile_t _get_tizen_profile(void) { char *profile_name = NULL; if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1)) return profile; if (__get_profile_from_model_config_xml("tizen.org/feature/profile", &profile_name) < 0) { profile = TIZEN_PROFILE_MOBILE; return profile; } if (profile_name == NULL) { profile = TIZEN_PROFILE_MOBILE; return profile; } switch (*profile_name) { case 'm': case 'M': profile = TIZEN_PROFILE_MOBILE; break; case 'w': case 'W': profile = TIZEN_PROFILE_WEARABLE; break; case 't': case 'T': profile = TIZEN_PROFILE_TV; break; case 'i': case 'I': if (!strncasecmp(profile_name, "ivi", 3)) profile = TIZEN_PROFILE_IVI; else if (!strncasecmp(profile_name, "iot", 3)) profile = TIZEN_PROFILE_IOT; else profile = TIZEN_PROFILE_COMMON; break; default: /* common or unknown ==> ALL ARE COMMON */ profile = TIZEN_PROFILE_COMMON; } free(profile_name); return profile; } static inline tizen_model_t _get_tizen_model(void) { char *model_name = NULL; if (__builtin_expect(model != TIZEN_MODEL_UNKNOWN, 1)) return model; if (__get_profile_from_model_config_xml("tizen.org/system/model_name", &model_name) < 0) { model = TIZEN_MODEL_COMMON; return model; } if (model_name == NULL) { model = TIZEN_MODEL_COMMON; return model; } if (!strcasecmp(model_name, "TM1")) model = TIZEN_MODEL_TM1; else if (!strcasecmp(model_name, "TM2")) model = TIZEN_MODEL_TM2; else if (!strcasecmp(model_name, "TW1")) model = TIZEN_MODEL_TW1; else if (!strcasecmp(model_name, "TW2")) model = TIZEN_MODEL_TW2; else if (!strcasecmp(model_name, "TW3")) model = TIZEN_MODEL_TW3; else if (!strcasecmp(model_name, "rpi3")) model = TIZEN_MODEL_RPI3; else model = TIZEN_MODEL_COMMON; free(model_name); return model; } #define TIZEN_FEATURE_BLUEZ_BRCM_CHIP ((_get_tizen_profile()) == TIZEN_PROFILE_IVI) #define TIZEN_FEATURE_BLUEZ_SMS_ONLY ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE) #define TIZEN_FEATURE_BLUEZ_BRCM_QOS ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE) #define TIZEN_FEATURE_BLUEZ_ROLE_CHANGE ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE) #define TIZEN_FEATURE_BLUEZ_CONFIRM_ONLY ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE) #define TIZEN_FEATURE_BLUEZ_SPRD_QOS ((_get_tizen_model()) == TIZEN_MODEL_TM1) #define TIZEN_FEATURE_BLUEZ_SPRD_PAGE_SCAN ((_get_tizen_model()) == TIZEN_MODEL_TM1) #define TIZEN_FEATURE_BLUEZ_SPEAKER_REFERENCE ((_get_tizen_model()) == TIZEN_MODEL_RPI3 && (_get_tizen_profile()) == TIZEN_PROFILE_COMMON) #endif /* __TIZEN_PROFILE_H__ */