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