1 /* 2 * Copyright (C) 2022-2022 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 #ifndef SYSCAP_INTERFACE_H 17 #define SYSCAP_INTERFACE_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #ifndef SINGLE_SYSCAP_LEN 23 #define SINGLE_SYSCAP_LEN (256 + 17) 24 #endif // SINGLE_SYSCAP_LEN 25 #define MAX_MISS_SYSCAP 512 26 #define PCID_MAIN_BYTES 128 27 #define PCID_MAIN_INTS 32 28 29 #define E_EORROR (-1) 30 #define E_OK 0 31 #define E_APIVERSION 1 32 #define E_SYSCAP 2 33 34 #ifdef __cplusplus 35 #if __cplusplus 36 extern "C" { 37 #endif /* __cplusplus */ 38 #endif /* __cplusplus */ 39 40 typedef struct CompareErrorMessage { 41 char *syscap[MAX_MISS_SYSCAP]; 42 uint16_t missSyscapNum; 43 uint16_t targetApiVersion; 44 } CompareError; 45 46 bool EncodeOsSyscap(char *output, int len); 47 bool DecodeOsSyscap(const char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt); 48 bool EncodePrivateSyscap(char **output, int *outputLen); 49 bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt); 50 char *DecodeRpcidToStringFormat(const char *inputFile); 51 /* 52 * params: 53 * pcidString, input string format pcid. 54 * rpcidString, input string format rpcid. 55 * result, output comparison results. 56 * retval: 57 * E_EORROR, compare failed. 58 * E_OK, compare successful and meet the requirements. 59 * E_APIVERSION, compare successful but api version too low. 60 * E_SYSCAP, compare successful but missing some syscaps. 61 * E_APIVERSION | E_SYSCAP, none of api version and syscap 62 * meet the requirements. 63 * notes: 64 * when return E_APIVERSION, the value of result.targetApiVersion 65 * is the require api version. 66 * when return E_SYSCAP, the value of result.missSyscapNum is the missing syscaps's numbers. 67 * result.syscap[] is the array of points to syscap strings. 68 * free variable result by function FreeCompareError. 69 */ 70 int32_t ComparePcidString(const char *pcidString, const char *rpcidString, CompareError *result); 71 int32_t FreeCompareError(CompareError *result); 72 73 #ifdef __cplusplus 74 #if __cplusplus 75 } 76 #endif /* __cplusplus */ 77 #endif /* __cplusplus */ 78 79 #endif /* SYSCAP_INTERFACE_H */