└── cnefeatureconfig ├── Android.mk ├── inc └── CneFeatureConfig.h └── src └── CneFeatureConfig.cpp /cnefeatureconfig/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | LOCAL_ARM_MODE := arm 4 | 5 | LOCAL_SRC_FILES:= \ 6 | src/CneFeatureConfig.cpp\ 7 | 8 | LOCAL_MODULE:= libcnefeatureconfig 9 | LOCAL_MODULE_TAGS := optional 10 | 11 | LOCAL_SHARED_LIBRARIES := libc libcutils liblog 12 | 13 | LOCAL_C_INCLUDES := \ 14 | external/connectivity/cnefeatureconfig/inc 15 | 16 | LOCAL_PRELINK_MODULE := false 17 | 18 | include $(BUILD_SHARED_LIBRARY) 19 | 20 | -------------------------------------------------------------------------------- /cnefeatureconfig/inc/CneFeatureConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef CneFeatureConfig_H 2 | #define CneFeatureConfig_H 3 | 4 | /*========================================================================= 5 | Copyright (c) 2012, 2014 The Linux Foundation. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials provided 15 | with the distribution. 16 | * Neither the name of The Linux Foundation nor the names of its 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 29 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | =========================================================================*/ 32 | 33 | /* Enum Feature represents values to be used to 34 | * query whether a feature is enabled. 35 | */ 36 | 37 | enum Feature { 38 | CNE = 1, 39 | FMC = 2, 40 | WQE = 3, 41 | NSRM = 4, 42 | ATP = 5, 43 | }; 44 | 45 | #include 46 | 47 | #ifdef LOGE 48 | #define CFC_LOGE LOGE 49 | #else 50 | #define CFC_LOGE ALOGE 51 | #endif 52 | 53 | #ifdef LOGW 54 | #define CFC_LOGW LOGW 55 | #else 56 | #define CFC_LOGW ALOGW 57 | #endif 58 | 59 | #ifdef LOGD 60 | #define CFC_LOGD LOGD 61 | #else 62 | #define CFC_LOGD ALOGD 63 | #endif 64 | 65 | #ifdef LOGI 66 | #define CFC_LOGI LOGI 67 | #else 68 | #define CFC_LOGI ALOGI 69 | #endif 70 | 71 | #ifdef LOGV 72 | #define CFC_LOGV LOGV 73 | #else 74 | #define CFC_LOGV ALOGV 75 | #endif 76 | 77 | #define CNE_FEATURE_PROP "persist.cne.feature" 78 | 79 | #ifdef __cplusplus 80 | extern "C" 81 | #endif /*__cplusplus*/ 82 | /* Provide C function to be used by JNI and other C/C++ modules. 83 | * Parameter should be one of the following values: 84 | * CNE 85 | * FMC, 86 | * WQE, 87 | * NSRM 88 | */ 89 | bool isFeatureEnabled(int f); 90 | 91 | #ifdef __cplusplus 92 | /* Allow clients to query what features of CNE are 93 | * enabled. 94 | */ 95 | class CneFeatureConfig { 96 | private: 97 | bool bCne; 98 | bool bFmc; 99 | bool bWqe; 100 | bool bNsrm; 101 | bool bAtp; 102 | /* Reads the CNE_FEATURE_PROP to determine which features 103 | are currently enabled.*/ 104 | void readFeature(void); 105 | 106 | /* Enum FeatureProperty values represents all permissible feature values. 107 | * CNE_FEATURE_PROP must have one of these values: 108 | * CNE_ONLY --> bCne set true 109 | * FMC_CNE --> bCne & bFmc set true 110 | * WQE_CNE --> bFmc & bCne set true 111 | * NSRM_CNE --> bNsrm & bCne set true 112 | * FMC_NSRM_CNE --> bFmc, bNsrm, bCne set true 113 | * WQE_NSRM_CNE --> bWqe, bNsrm, bCne set true 114 | * Any other value will return false. By default 115 | * LinkManager used if CNE disabled. 116 | */ 117 | enum FeatureProperty { 118 | LINK_MGR = 0, /* Link Manager - no CNE features enabled */ 119 | CNE_ONLY = 1, /* CNE only */ 120 | FMC_CNE = 2, /* CNE feature is prerequisite */ 121 | WQE_CNE = 3, /* CNE feature is prerequisite */ 122 | NSRM_CNE = 4, /* CNE feature is prerequisite */ 123 | FMC_NSRM_CNE = 5, /* CNE feature is prerequisite */ 124 | WQE_NSRM_CNE = 6, /* CNE feature is prerequisite */ 125 | ATP_CNE = 7, /* CNE feature is prerequisite */ 126 | ATP_NSRM_CNE = 8, /* CNE feature is prerequisite */ 127 | ATP_NSRM_WQE_CNE = 9, /* CNE feature is prerequisite */ 128 | }; 129 | 130 | public: 131 | bool isEnabled(Feature f); 132 | CneFeatureConfig(); 133 | ~CneFeatureConfig(); 134 | }; 135 | 136 | #endif /*__cplusplus*/ 137 | 138 | #endif /*CneFeatureConfig_H*/ 139 | 140 | -------------------------------------------------------------------------------- /cnefeatureconfig/src/CneFeatureConfig.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | Copyright (c) 2012, 2014 The Linux Foundation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the name of The Linux Foundation nor the names of its 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | ==============================================================================*/ 30 | 31 | /*------------------------------------------------------------------------------ 32 | * Include Files 33 | * ---------------------------------------------------------------------------*/ 34 | #include 35 | #include 36 | #include "CneFeatureConfig.h" 37 | #include 38 | 39 | /*------------------------------------------------------------------------------ 40 | * Preprocessor Definitions and Constants 41 | * ---------------------------------------------------------------------------*/ 42 | #undef LOG_TAG 43 | #define LOG_TAG "CNEFEATURECONFIG" 44 | 45 | /*----------------------------------------------------------------------------- 46 | * Global functions 47 | * --------------------------------------------------------------------------*/ 48 | bool isFeatureEnabled(int f) 49 | { 50 | bool bEnabled = false; 51 | CneFeatureConfig *cneFeature = new CneFeatureConfig; 52 | 53 | if (NULL != cneFeature) { 54 | bEnabled = cneFeature->isEnabled((Feature) f); 55 | delete cneFeature; 56 | } else { 57 | CFC_LOGE("Failed to instantiate CneFeatureConfig! Default = disabled"); 58 | } 59 | 60 | return bEnabled; 61 | } 62 | 63 | /*----------------------------------------------------------------------------- 64 | * Class methods 65 | * --------------------------------------------------------------------------*/ 66 | CneFeatureConfig::CneFeatureConfig():bCne(false), 67 | bFmc(false), 68 | bWqe(false), 69 | bNsrm(false), 70 | bAtp(false) 71 | { 72 | } 73 | 74 | CneFeatureConfig::~CneFeatureConfig() 75 | { 76 | } 77 | 78 | /* Read the currently set feature property value. 79 | */ 80 | void CneFeatureConfig::readFeature(void) { 81 | FeatureProperty val; 82 | char prop_value_feature[PROPERTY_VALUE_MAX] = {'\0'}; 83 | property_get(CNE_FEATURE_PROP, prop_value_feature, "0"); 84 | val = (FeatureProperty) atoi(prop_value_feature); 85 | 86 | switch (val) { 87 | case LINK_MGR: // 0 --> Use Link Manager. Cne is completely disabled. 88 | { 89 | // do nothing 90 | break; 91 | } 92 | case CNE_ONLY: // 1--> Only Cne default behavior enabled. 93 | { 94 | bCne = true; 95 | break; 96 | } 97 | case FMC_CNE: // 2--> CNE enabled. FMC mode 98 | { 99 | bCne = true; 100 | bFmc = true; 101 | break; 102 | } 103 | case NSRM_CNE: // 3--> CNE enabled. NSRM mode. 104 | { 105 | bCne = true; 106 | bNsrm = true; 107 | break; 108 | } 109 | case WQE_CNE: // 4--> CNE enabled. WQE mode. 110 | { 111 | bCne = true; 112 | bWqe = true; 113 | break; 114 | } 115 | case FMC_NSRM_CNE: //5 --> CNE enabled. FMC & NSRM mode. 116 | { 117 | bCne = true; 118 | bFmc = true; 119 | bNsrm = true; 120 | break; 121 | } 122 | case WQE_NSRM_CNE: //6 --> CNE enabled. WQE & NSRM mode. 123 | { 124 | bCne = true; 125 | bWqe = true; 126 | bNsrm = true; 127 | break; 128 | } 129 | case ATP_CNE: //7 --> CNE enabled. ATP mode. 130 | { 131 | bCne = true; 132 | bAtp = true; 133 | break; 134 | } 135 | case ATP_NSRM_CNE: //8 --> CNE enabled. ATP & NSRM mode. 136 | { 137 | bCne = true; 138 | bAtp = true; 139 | bNsrm = true; 140 | break; 141 | } 142 | case ATP_NSRM_WQE_CNE: //9 --> CNE enabled. ATP WQE & NSRM mode. 143 | { 144 | bCne = true; 145 | bAtp = true; 146 | bNsrm = true; 147 | bWqe = true; 148 | break; 149 | } 150 | default: 151 | CFC_LOGW("Unknown feature value in property. Features disabled by default"); 152 | } 153 | } 154 | 155 | bool CneFeatureConfig::isEnabled(Feature f) { 156 | readFeature(); 157 | switch(f){ 158 | case CNE: 159 | return bCne; 160 | break; 161 | case FMC: 162 | return bFmc; 163 | break; 164 | case NSRM: 165 | return bNsrm; 166 | break; 167 | case WQE: 168 | return bWqe; 169 | break; 170 | case ATP: 171 | return bAtp; 172 | break; 173 | default: 174 | CFC_LOGW("Feature %d not known, returning default", f); 175 | return false; 176 | } 177 | 178 | return false; 179 | } 180 | 181 | --------------------------------------------------------------------------------