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