• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 OHOS_WIFI_COMMON_UTIL_H
17 #define OHOS_WIFI_COMMON_UTIL_H
18 
19 #include <string>
20 #include <vector>
21 #include "securec.h"
22 
23 #ifndef WIFI_MAC_LEN
24 #define WIFI_MAC_LEN 6
25 #endif
26 
27 namespace OHOS {
28 namespace Wifi {
29 /**
30  * @Description MAC address anonymization
31  *
32  * <p> eg: a2:7c:b0:98:e3:92 -> a2:7c:**:**:**:92
33  *
34  * @param str - Input MAC address
35  * @return std::string - Processed MAC
36  */
37 std::string MacAnonymize(const std::string str);
38 
39 /**
40  * @Description MAC address anonymization
41  *
42  * <p> eg: 192.168.0.1 -> 192.***.*.1
43  *
44  * @param str - Input MAC address
45  * @return std::string - Processed MAC
46  */
47 std::string IpAnonymize(const std::string str);
48 
49 /**
50  * @Description Converting string MAC to a C-style MAC address
51  *
52  * @param strMac - Input MAC address
53  * @param mac - conversion result
54  * @return errno_t - EOK for success, failure for other values.
55  */
56 errno_t MacStrToArray(const std::string& strMac, unsigned char mac[WIFI_MAC_LEN]);
57 
58 /**
59  * @Description Converting C-style MAC to a string MAC
60  *
61  * @param mac - Input MAC address
62  * @return string - conversion result.
63  */
64 std::string MacArrayToStr(const unsigned char mac[WIFI_MAC_LEN]);
65 
66 /**
67  * @Description Check whether the array of MAC address is empty
68  *
69  * @param mac - Input MAC address
70  * @return bool - true: empty, false: not empty
71  */
72 bool IsMacArrayEmpty(const unsigned char mac[WIFI_MAC_LEN]);
73 
74 /**
75  * @Description Converting a string IP Address to an integer IP address
76  *
77  * @param strIp - Input string IP address
78  * @return int - integer IP address
79  */
80 int Ip2Number(const std::string& strIp);
81 
82 /**
83  * @Description Converting an integer IP address to a string IP Address
84  *
85  * @param intIp - Input integer IP address
86  * @return string - string IP address
87  */
88 std::string Number2Ip(int intIp);
89 
90 /**
91  * @Description Splitting strings by delimiter
92  *
93  * @param str - Input string
94  * @param delim - Split delimiter
95  * @return std::vector<std::string> - Split result
96  */
97 std::vector<std::string> StrSplit(const std::string& str, const std::string& delim);
98 
99 /**
100  * @Description get bundle name
101  *
102  * @return bool - bundle name
103  */
104 std::string GetBundleName();
105 
106 /**
107  * @Description Check whether the app is a system app
108  *
109  * @return bool - Returns true for yes, false for no.
110  */
111 bool IsSystemApp();
112 }  // namespace Wifi
113 }  // namespace OHOS
114 #endif