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