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_AUTH_CENTER_H
17 #define OHOS_WIFI_AUTH_CENTER_H
18 
19 #include <map>
20 #include "wifi_logger.h"
21 
22 namespace OHOS {
23 namespace Wifi {
24 class WifiAuthCenter {
25 public:
26     static WifiAuthCenter &GetInstance();
27 
28     /**
29      * @Description Init WifiAuthCenter object
30      *
31      * @return int - init result, when 0 means success, other means some fails happened
32      */
33     int Init();
34 
35     /**
36      * @Description Verify whether the app is system app
37      *
38      * @return bool - true : system app
39      */
40     static bool IsSystemAccess();
41 
42     /**
43      * @Description Verify whether the app is native process
44      *
45      * @return bool - true : native process
46      */
47     static bool IsNativeProcess();
48 
49     /**
50      * @Description Verify whether the app has the same process permission
51      *
52      * @param pid - the app's process id
53      * @param uid - the app id
54      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
55      */
56     int VerifySameProcessPermission(const int &pid, const int &uid);
57 
58     /**
59      * @Description Verify whether the app has the permission to operator wifi
60      *
61      * @param pid - the app's process id
62      * @param uid - the app id
63      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
64      */
65     int VerifySetWifiInfoPermission(const int &pid, const int &uid);
66 
67     /**
68      * @Description Verify whether the app has the permission to visit wifi
69      *
70      * @param pid - the app's process id
71      * @param uid - the app id
72      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
73      */
74     int VerifyGetWifiInfoPermission(const int &pid, const int &uid);
75 
76     /**
77      * @Description Verify whether the app has the permission to get scan info.
78      *
79      * @param pid - the app's process id
80      * @param uid - the app id
81      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
82      */
83     int VerifyGetScanInfosPermission(const int &pid, const int &uid);
84 
85     /**
86      * @Description Verify whether the app has the permission to get mac address
87      *
88      * @param pid - the app's process id
89      * @param uid - the app id
90      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
91      */
92     int VerifyGetWifiLocalMacPermission(const int &pid, const int &uid);
93 
94     /**
95      * @Description Verify whether the app has the permission to open / close hotspot
96      *
97      * @param pid - the app's process id
98      * @param uid - the app id
99      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
100      */
101     int VerifyWifiConnectionPermission(const int &pid, const int &uid);
102 
103     /**
104      * @Description Verify whether the app has the permission to override hotspot config, hotspot blocklist config
105      *
106      * @param pid - the app's process id
107      * @param uid - the app id
108      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
109      */
110     int VerifySetWifiConfigPermission(const int &pid, const int &uid);
111 
112     /**
113      * @Description Verify whether the app has the permission to get hotspot config, hotspot blocklist config
114      *
115      * @param pid - the app's process id
116      * @param uid - the app id
117      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
118      */
119     int VerifyGetWifiConfigPermission(const int &pid, const int &uid);
120 
121     /**
122      * @Description : Verify location information about nearby P2P devices Permission.
123      *
124      * @param pid - Process ID.[in]
125      * @param uid - User ID.[in]
126      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
127      */
128     int VerifyGetWifiDirectDevicePermission(const int &pid, const int &uid);
129 
130     /**
131      * @Description : Verify manage wifi hotspot Permission.
132      *
133      * @param pid - Process ID.[in]
134      * @param uid - User ID.[in]
135      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
136      */
137     int VerifyManageWifiHotspotPermission(const int &pid, const int &uid);
138 
139     /**
140      * @Description : Get wifi peers mac Permission.
141      *
142      * @param pid - Process ID.[in]
143      * @param uid - User ID.[in]
144      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
145      */
146     int VerifyGetWifiPeersMacPermission(const int &pid, const int &uid);
147 
148     /**
149      * @Description : Get wifi peers mac Permission.
150      *
151      * @param pid - Process ID.[in]
152      * @param uid - User ID.[in]
153      * @param tokenId - Token ID.[in]
154      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
155      */
156     int VerifyGetWifiPeersMacPermissionEx(const int &pid, const int &uid, const int &tokenId);
157 
158     /**
159      * @Description : Get wifi internal wifi info Permission.
160      *
161      * @param pid - Process ID.[in]
162      * @param uid - User ID.[in]
163      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
164      */
165     int VerifyGetWifiInfoInternalPermission(const int &pid, const int &uid);
166 
167     /**
168      * @Description : Verify manage wifi hotspot extend permission.
169      *
170      * @param pid - Process ID.[in]
171      * @param uid - User ID.[in]
172      * @return int - PERMISSION_DENIED or PERMISSION_GRANTED
173      */
174     int VerifyManageWifiHotspotExtPermission(const int &pid, const int &uid);
175 
176 private:
177     /* system auth service client */
178 };
179 } // namespace Wifi
180 } // namespace OHOS
181 
182 #endif