1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "lnn_feature_capability.h"
17 
18 #include <stdint.h>
19 
20 #include "lnn_log.h"
21 #include "softbus_errcode.h"
22 #include "softbus_feature_config.h"
23 
24 #define DEFAUTL_LNN_FEATURE 0x3E2 // 0x3EA
25 
LnnSetFeatureCapability(uint64_t * feature,FeatureCapability capaBit)26 int32_t LnnSetFeatureCapability(uint64_t *feature, FeatureCapability capaBit)
27 {
28     if (feature == NULL || capaBit >= BIT_FEATURE_COUNT) {
29         LNN_LOGE(LNN_LEDGER, "in para error");
30         return SOFTBUS_INVALID_PARAM;
31     }
32     *feature = (*feature) | (1 << (uint64_t)capaBit);
33     return SOFTBUS_OK;
34 }
35 
LnnClearFeatureCapability(uint64_t * feature,FeatureCapability capaBit)36 int32_t LnnClearFeatureCapability(uint64_t *feature, FeatureCapability capaBit)
37 {
38     if (feature == NULL || capaBit >= BIT_FEATURE_COUNT) {
39         LNN_LOGE(LNN_LEDGER, "in para error");
40         return SOFTBUS_INVALID_PARAM;
41     }
42     *feature = (*feature) & (~(1 << (uint64_t)capaBit));
43     return SOFTBUS_OK;
44 }
45 
IsFeatureSupport(uint64_t feature,FeatureCapability capaBit)46 bool IsFeatureSupport(uint64_t feature, FeatureCapability capaBit)
47 {
48     return ((feature & (1 << (uint64_t)capaBit)) != 0);
49 }
50 
LnnGetFeatureCapabilty(void)51 uint64_t LnnGetFeatureCapabilty(void)
52 {
53     uint64_t configValue;
54     if (SoftbusGetConfig(SOFTBUS_INT_LNN_SUPPORT_FEATURE,
55         (unsigned char*)&configValue, sizeof(configValue)) != SOFTBUS_OK) {
56         LNN_LOGE(LNN_LEDGER, "get lnn feature fail, use default value");
57         configValue = DEFAUTL_LNN_FEATURE;
58     }
59     LNN_LOGI(LNN_LEDGER, "lnn feature configValue=%{public}" PRIu64, configValue);
60     return configValue;
61 }