1 /* 2 * Copyright (C) 2024 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 WPA_HDI_UTIL_H 17 #define WPA_HDI_UTIL_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #define NUMBER_BASE 10 24 #define MAX_INT32_LENGTH 11 /* -2147483648 ~ 2147483647 */ 25 #define MAX_UINT32_LENGTH 10 /* 0 ~ 4294967295 */ 26 27 /** 28 * @Description Convert [a,b,c,d,e,f] mac address to string type [xx:xx:xx:xx:xx:xx] 29 * 30 * @param mac - mac address 31 * @param macSize - mac size, must be equal to 6 32 * @param macStr - output mac string, type: [xx:xx:xx:xx:xx:xx] 33 * @param strLen - mac string len, must bigger than 17 34 * @return int - convert result. 0 - Failed 1 - Success 35 */ 36 int ConvertMacToStr(const unsigned char *mac, int macSize, char *macStr, int strLen); 37 38 /** 39 * @Description Convert mac string type [xx:xx:xx:xx:xx:xx] to array type 40 * 41 * @param macStr - input mac address, string type like xx:xx:xx:xx:xx:xx 42 * @param mac - output mac array 43 * @param macSize - mac array length, must be equal to 6 44 * @return int - convert result. 0 - Failed 1 - Success 45 */ 46 int ConvertMacToArray(const char *macStr, unsigned char *mac, int macSize); 47 48 /** 49 * @Description Judge input is valid mac string 50 * 51 * @param macStr - input mac string 52 * @return int - -1 - invalid 0 valid 53 */ 54 int CheckMacIsValid(const char *macStr); 55 56 /** 57 * @Description Get the state of interface 58 * @param ifaceName - the name of interface 59 * @return int - 0: down 1: up 60 */ 61 int GetIfaceState(const char *ifaceName); 62 63 /** 64 * @DataAnonymize Anonymize the input data 65 * @param input - the data to anonymize 66 * @param inputlen - the length of the input data 67 * @param output - anonymized data 68 * @param outputSize - the size the output data 69 * @return int - 0: success 1: failied 70 */ 71 int DataAnonymize(const char *input, int inputLen, char* output, int outputSize); 72 73 char IsValidHexCharAndConvert(char c); 74 75 unsigned int StrtoUint(const char *input); 76 77 int StrtoInt(const char *input); 78 79 #ifdef __cplusplus 80 } 81 #endif 82 #endif 83