1# @ohos.enterprise.wifiManager (Wi-Fi Management)
2
3The **wifiManager** module provides Wi-Fi management capabilities for enterprise devices, including obtaining the Wi-Fi status.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> The APIs of this module can be used only in the stage model.
10>
11> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled.
12>
13> The global restriction policies are provided by **restrictions**. To disable Wi-Fi globally, see [@ohos.enterprise.restrictions](js-apis-enterprise-restrictions.md).
14
15## Modules to Import
16
17```ts
18import { wifiManager } from '@kit.MDMKit';
19```
20
21## wifiManager.isWifiActiveSync
22
23isWifiActiveSync(admin: Want): boolean
24
25Checks whether Wi-Fi is active through the specified device administrator application. This API returns the result synchronously.
26
27**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI
28
29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
30
31
32
33**Parameters**
34
35| Name| Type                                                   | Mandatory| Description          |
36| ------ | ------------------------------------------------------- | ---- | -------------- |
37| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.|
38
39**Return value**
40
41| Type   | Description                                                      |
42| ------- | ---------------------------------------------------------- |
43| boolean | Returns **true** if Wi-Fi is active; returns **false** otherwise.|
44
45**Error codes**
46
47For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
48
49| ID| Error Message                                                    |
50| -------- | ------------------------------------------------------------ |
51| 9200001  | The application is not an administrator application of the device. |
52| 9200002  | The administrator application does not have permission to manage the device. |
53| 201      | Permission verification failed. The application does not have the permission required to call the API. |
54| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
55
56**Example**
57
58```ts
59import { Want } from '@kit.AbilityKit';
60let wantTemp: Want = {
61  bundleName: 'com.example.myapplication',
62  abilityName: 'EntryAbility',
63};
64
65try {
66  let result: boolean = wifiManager.isWifiActiveSync(wantTemp);
67  console.info(`Succeeded in query is wifi active or not, result : ${result}`);
68} catch (err) {
69  console.error(`Failed to query is wifi active or not. Code: ${err.code}, message: ${err.message}`);
70}
71```
72
73## wifiManager.setWifiProfileSync
74
75setWifiProfileSync(admin: Want, profile: WifiProfile): void
76
77Sets Wi-Fi profile through the specified device administrator application to enable the device to connect to the specified network.
78
79**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_WIFI
80
81**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
82
83
84
85**Parameters**
86
87| Name | Type                                                   | Mandatory| Description          |
88| ------- | ------------------------------------------------------- | ---- | -------------- |
89| admin   | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.|
90| profile | [WifiProfile](#wifiprofile)                             | Yes  | Wi-Fi profile information.|
91
92**Error codes**
93
94For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
95
96| ID| Error Message                                                    |
97| -------- | ------------------------------------------------------------ |
98| 9200001  | The application is not an administrator application of the device. |
99| 9200002  | The administrator application does not have permission to manage the device. |
100| 201      | Permission verification failed. The application does not have the permission required to call the API. |
101| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
102
103**Example**
104
105```ts
106import { Want } from '@kit.AbilityKit';
107import { BusinessError } from '@kit.BasicServicesKit';
108let wantTemp: Want = {
109  bundleName: 'com.example.myapplication',
110  abilityName: 'EntryAbility',
111};
112let profile: wifiManager.WifiProfile = {
113  'ssid': 'name',
114  'preSharedKey': 'passwd',
115  'securityType': wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
116};
117
118try {
119  wifiManager.setWifiProfileSync(wantTemp, profile);
120  console.info('Succeeded in setting wifi profile.');
121} catch (err) {
122  console.error(`Failed to set wifi profile. Code: ${err.code}, message: ${err.message}`);
123}
124```
125
126## WifiProfile
127
128Represents the Wi-Fi profile information.
129
130**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
131
132
133
134| Name         | Type                                 | Mandatory| Description                         |
135| ------------- | ------------------------------------- | ---- | ----------------------------- |
136| ssid | string | Yes| Service set identifier (SSID) of the hotspot, in UTF-8 format.|
137| bssid         | string                                | No  | Basic service set identifier (BSSID) of the hotspot.                |
138| preSharedKey  | string                                | Yes  | Pre-shared key (PSK) of the hotspot.                 |
139| isHiddenSsid  | boolean                               | No  | Whether the network is hidden.             |
140| securityType  | [WifiSecurityType](#wifisecuritytype) | Yes  | Security type.                   |
141| creatorUid    | number                                | No  | ID of the creator.               |
142| disableReason | number                                | No  | Reason for disabling Wi-Fi.                   |
143| netId         | number                                | No  | Network ID allocated.               |
144| randomMacType | number | No| Type of the random MAC.|
145| randomMacAddr | string                                | No  | Random MAC address.                |
146| ipType        | [IpType](#iptype)                     | No  | IP address type.                 |
147| staticIp      | [IpProfile](#ipprofile)               | No  | Static IP address information.             |
148| eapProfile    | [WifiEapProfile](#wifieapprofile)     | No  | Extensible Authentication Protocol (EAP) configuration.     |
149
150## WifiSecurityType
151
152Enumerates the Wi-Fi security types.
153
154**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
155
156
157
158| Name                     | Value  | Description                                                        |
159| ------------------------- | ---- | ------------------------------------------------------------ |
160| WIFI_SEC_TYPE_INVALID     | 0    | Invalid security type.                                              |
161| WIFI_SEC_TYPE_OPEN        | 1    | Open security type.                                              |
162| WIFI_SEC_TYPE_WEP         | 2    | Wired Equivalent Privacy (WEP).     |
163| WIFI_SEC_TYPE_PSK         | 3    | PSK.                    |
164| WIFI_SEC_TYPE_SAE         | 4    | Simultaneous Authentication of Equals (SAE).|
165| WIFI_SEC_TYPE_EAP         | 5    | EAP.                                               |
166| WIFI_SEC_TYPE_EAP_SUITE_B | 6    | Suite B 192-bit encryption.                                     |
167| WIFI_SEC_TYPE_OWE         | 7    | Opportunistic Wireless Encryption (OWE).                                        |
168| WIFI_SEC_TYPE_WAPI_CERT   | 8    | WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).                                         |
169| WIFI_SEC_TYPE_WAPI_PSK    | 9    | WAPI-PSK.                                          |
170
171## IpType
172
173Enumerates the IP address types.
174
175**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
176
177
178
179| Name   | Value  | Description          |
180| ------- | ---- | -------------- |
181| STATIC  | 0    | Static IP address.      |
182| DHCP    | 1    | IP address allocated by DHCP.|
183| UNKNOWN | 2    | Not specified.      |
184
185## IpProfile
186
187Represents IP configuration information.
188
189**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
190
191
192
193| Name        | Type               | Mandatory| Description       |
194| ------------ | ------------------- | ---- | ----------- |
195| ipAddress    | number              | Yes  | IP address.   |
196| gateway      | number              | Yes  | Gateway.     |
197| prefixLength | number              | Yes  | Subnet mask.     |
198| dnsServers   | number[]            | Yes  | Domain name server (DNS) information.|
199| domains      | Array<string> | Yes  | Domain information.   |
200
201## WifiEapProfile
202
203Represents EAP profile (configuration) information.
204
205**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
206
207
208
209| Name             | Type                         | Mandatory| Description                            |
210| ----------------- | ----------------------------- | ---- | -------------------------------- |
211| eapMethod         | [EapMethod](#eapmethod)       | Yes  | EAP authentication method.                    |
212| phase2Method      | [Phase2Method](#phase2method) | Yes  | Phase 2 authentication method.              |
213| identity          | string                        | Yes  | Identity Information.                      |
214| anonymousIdentity | string                        | Yes  | Anonymous identity.                      |
215| password          | string                        | Yes  | Password.                          |
216| caCertAliases     | string                        | Yes  | CA certificate alias.                   |
217| caPath            | string                        | Yes  | CA certificate path.                   |
218| clientCertAliases | string                        | Yes  | Client certificate alias.                |
219| certEntry         | Uint8Array                    | Yes  | CA certificate content.                   |
220| certPassword      | string                        | Yes  | CA certificate password.                    |
221| altSubjectMatch   | string                        | Yes  | A string to match the alternate subject.                  |
222| domainSuffixMatch | string                        | Yes  | A string to match the domain suffix.                    |
223| realm             | string                        | Yes  | Realm for the passpoint credential.              |
224| plmn              | string                        | Yes  | Public land mobile network (PLMN) of the passpoint credential provider.|
225| eapSubId          | number                        | Yes  | Sub-ID of the SIM card.                   |
226
227## EapMethod
228
229Enumerates the EAP authentication methods.
230
231**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
232
233
234
235| Name          | Value  | Description            |
236| -------------- | ---- | ---------------- |
237| EAP_NONE       | 0    | Not specified.        |
238| EAP_PEAP       | 1    | PEAP.      |
239| EAP_TLS        | 2    | TLS.       |
240| EAP_TTLS       | 3    | TTLS.      |
241| EAP_PWD        | 4    | Password.       |
242| EAP_SIM        | 5    | SIM.       |
243| EAP_AKA        | 6    | AKA.       |
244| EAP_AKA_PRIME  | 7    | AKA Prime. |
245| EAP_UNAUTH_TLS | 8    | UNAUTH TLS.|
246
247## Phase2Method
248
249Enumerates the Phase 2 authentication methods.
250
251**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
252
253
254
255| Name            | Value  | Description           |
256| ---------------- | ---- | --------------- |
257| PHASE2_NONE      | 0    | Not specified.       |
258| PHASE2_PAP       | 1    | PAP.      |
259| PHASE2_MSCHAP    | 2    | MS-CHAP.   |
260| PHASE2_MSCHAPV2  | 3    | MS-CHAPv2. |
261| PHASE2_GTC       | 4    | GTC.      |
262| PHASE2_SIM       | 5    | SIM.      |
263| PHASE2_AKA       | 6    | AKA.      |
264| PHASE2_AKA_PRIME | 7    | AKA Prime.|
265