1094332d3Sopenharmony_ci# WLAN<a name="EN-US_TOPIC_0000001078436908"></a>
2094332d3Sopenharmony_ci
3094332d3Sopenharmony_ci-   [Introduction](#section11660541593)
4094332d3Sopenharmony_ci-   [Directory Structure](#section161941989596)
5094332d3Sopenharmony_ci-   [Available APIs](#section1564411661810)
6094332d3Sopenharmony_ci-   [Usage Guidelines](#section19806524151819)
7094332d3Sopenharmony_ci-   [Repositories Involved](#section1371113476307)
8094332d3Sopenharmony_ci
9094332d3Sopenharmony_ci## Introduction<a name="section11660541593"></a>
10094332d3Sopenharmony_ci
11094332d3Sopenharmony_ciThis repository defines and implements the WLAN-related Hardware Driver Interfaces \(HDIs\) which provide the following functionalities:
12094332d3Sopenharmony_ci
13094332d3Sopenharmony_ci1.  Creating and stopping a channel between the hardware abstraction layer \(HAL\) and the WLAN driver
14094332d3Sopenharmony_ci2.  Obtaining the WLAN features supported by the device
15094332d3Sopenharmony_ci3.  Creating a WLAN feature instance
16094332d3Sopenharmony_ci
17094332d3Sopenharmony_ci**Figure  1**  WLAN driver module architecture<a name="fig14142101381112"></a>  
18094332d3Sopenharmony_ci![](figures/wlan-driver-module-architecture.png "wlan-driver-module-architecture")
19094332d3Sopenharmony_ci
20094332d3Sopenharmony_ci## Directory Structure<a name="section161941989596"></a>
21094332d3Sopenharmony_ci
22094332d3Sopenharmony_ciThe directory structure of the WLAN repository is as follows:
23094332d3Sopenharmony_ci
24094332d3Sopenharmony_ci```
25094332d3Sopenharmony_ci/drivers/peripheral/wlan
26094332d3Sopenharmony_ci├── client             # Client that implements the communication between the user space and kernel space
27094332d3Sopenharmony_ci│   └── include       # Client header files
28094332d3Sopenharmony_ci│   └── src           # Client code
29094332d3Sopenharmony_ci├── hal                # HAL code
30094332d3Sopenharmony_ci│   └── include       # HAL header files
31094332d3Sopenharmony_ci│   └── src           # HAL code implementation
32094332d3Sopenharmony_ci├── interfaces         # APIs exposed externally
33094332d3Sopenharmony_ci│   └── include       # Header files containing APIs exposed externally
34094332d3Sopenharmony_ci```
35094332d3Sopenharmony_ci
36094332d3Sopenharmony_ci## Available APIs<a name="section1564411661810"></a>
37094332d3Sopenharmony_ci
38094332d3Sopenharmony_ciThe WLAN HAL module provides APIs for the Wi-Fi service, such as creating and destroying an  **IWiFi**  object and setting the MAC address. The following table lists the APIs.
39094332d3Sopenharmony_ci
40094332d3Sopenharmony_ci**Table  1**  APIs provided by the WLAN HAL module
41094332d3Sopenharmony_ci
42094332d3Sopenharmony_ci<a name="table1521573319472"></a>
43094332d3Sopenharmony_ci<table><thead align="left"><tr id="row121519334474"><th class="cellrowborder" valign="top" width="15.079999999999998%" id="mcps1.2.4.1.1"><p id="p1221510339475"><a name="p1221510339475"></a><a name="p1221510339475"></a>Header File</p>
44094332d3Sopenharmony_ci</th>
45094332d3Sopenharmony_ci<th class="cellrowborder" valign="top" width="60.33%" id="mcps1.2.4.1.2"><p id="p0215153344716"><a name="p0215153344716"></a><a name="p0215153344716"></a>API</p>
46094332d3Sopenharmony_ci</th>
47094332d3Sopenharmony_ci<th class="cellrowborder" valign="top" width="24.59%" id="mcps1.2.4.1.3"><p id="p1421503315478"><a name="p1421503315478"></a><a name="p1421503315478"></a>Description</p>
48094332d3Sopenharmony_ci</th>
49094332d3Sopenharmony_ci</tr>
50094332d3Sopenharmony_ci</thead>
51094332d3Sopenharmony_ci<tbody><tr id="row112150333476"><td class="cellrowborder" rowspan="12" valign="top" width="15.079999999999998%" headers="mcps1.2.4.1.1 "><p id="p2155710125317"><a name="p2155710125317"></a><a name="p2155710125317"></a>wifi_hal.h</p>
52094332d3Sopenharmony_ci<p id="p189132019183"><a name="p189132019183"></a><a name="p189132019183"></a></p>
53094332d3Sopenharmony_ci</td>
54094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" width="60.33%" headers="mcps1.2.4.1.2 "><p id="p363110387399"><a name="p363110387399"></a><a name="p363110387399"></a>int32_t WifiConstruct(struct IWiFi **wifiInstance);</p>
55094332d3Sopenharmony_ci</td>
56094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" width="24.59%" headers="mcps1.2.4.1.3 "><p id="p1363012387393"><a name="p1363012387393"></a><a name="p1363012387393"></a>Creates an <strong id="b1851191156"><a name="b1851191156"></a><a name="b1851191156"></a>IWiFi</strong> object with basic capabilities.</p>
57094332d3Sopenharmony_ci</td>
58094332d3Sopenharmony_ci</tr>
59094332d3Sopenharmony_ci<tr id="row112151233194714"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p7629163817393"><a name="p7629163817393"></a><a name="p7629163817393"></a>int32_t WifiDestruct(struct IWiFi **wifiInstance);</p>
60094332d3Sopenharmony_ci</td>
61094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2627638173917"><a name="p2627638173917"></a><a name="p2627638173917"></a>Destroys an <strong id="b1088016455520"><a name="b1088016455520"></a><a name="b1088016455520"></a>IWiFi</strong> object.</p>
62094332d3Sopenharmony_ci</td>
63094332d3Sopenharmony_ci<tr id="row1214611564542"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p4950434142314"><a name="p4950434142314"></a><a name="p4950434142314"></a>int32_t (*start)(struct IWiFi *);</p>
64094332d3Sopenharmony_ci</td>
65094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1162543816393"><a name="p1162543816393"></a><a name="p1162543816393"></a>Creates a channel between the HAL and the driver and obtains the NIC supported by the driver.</p>
66094332d3Sopenharmony_ci</td>
67094332d3Sopenharmony_ci</tr>
68094332d3Sopenharmony_ci<tr id="row167876105514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p162433816392"><a name="p162433816392"></a><a name="p162433816392"></a>int32_t (*stop)(struct IWiFi *);</p>
69094332d3Sopenharmony_ci</td>
70094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p186235383393"><a name="p186235383393"></a><a name="p186235383393"></a>Stops the channel between the HAL and the driver.</p>
71094332d3Sopenharmony_ci</td>
72094332d3Sopenharmony_ci</tr>
73094332d3Sopenharmony_ci<tr id="row77607815516"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6760128135514"><a name="p6760128135514"></a><a name="p6760128135514"></a>int32_t (*getSupportFeature)(uint8_t *supType, uint32_t size);</p>
74094332d3Sopenharmony_ci</td>
75094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1176014845516"><a name="p1176014845516"></a><a name="p1176014845516"></a>Obtains the WLAN features available for the device no matter whether it works as an AP, STA, or P2P server/client.</p>
76094332d3Sopenharmony_ci</td>
77094332d3Sopenharmony_ci</tr>
78094332d3Sopenharmony_ci<tr id="row93918373572"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2039103714572"><a name="p2039103714572"></a><a name="p2039103714572"></a>int32_t (*getSupportCombo)(uint64_t *combo, uint32_t size);</p>
79094332d3Sopenharmony_ci</td>
80094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p13916375570"><a name="p13916375570"></a><a name="p13916375570"></a>Obtains the WLAN features available for the device that plays different roles simultaneously (any combination of AP, STA, and P2P server/client).</p>
81094332d3Sopenharmony_ci</td>
82094332d3Sopenharmony_ci</tr>
83094332d3Sopenharmony_ci<tr id="row25031321195815"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p13503142195814"><a name="p13503142195814"></a><a name="p13503142195814"></a>int32_t (*createFeature)(int32_t type, struct IWiFiBaseFeature **ifeature);</p>
84094332d3Sopenharmony_ci</td>
85094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p11503172115585"><a name="p11503172115585"></a><a name="p11503172115585"></a>Creates an <strong id="b85498454446"><a name="b85498454446"></a><a name="b85498454446"></a>IWiFiBaseFeature</strong> object of a specified type.</p>
86094332d3Sopenharmony_ci</td>
87094332d3Sopenharmony_ci</tr>
88094332d3Sopenharmony_ci<tr id="row14371833185819"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1443863325820"><a name="p1443863325820"></a><a name="p1443863325820"></a>int32_t (*getFeatureByIfName)(const char *ifName, struct IWiFiBaseFeature **ifeature);</p>
89094332d3Sopenharmony_ci</td>
90094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1343819334584"><a name="p1343819334584"></a><a name="p1343819334584"></a>Obtains an <strong id="b1678312213451"><a name="b1678312213451"></a><a name="b1678312213451"></a>IWiFiBaseFeature</strong> object based on a specified network interface name.</p>
91094332d3Sopenharmony_ci</td>
92094332d3Sopenharmony_ci</tr>
93094332d3Sopenharmony_ci<tr id="row03398561587"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1933965615812"><a name="p1933965615812"></a><a name="p1933965615812"></a>int32_t (*registerEventCallback)(CallbackFunc cbFunc);</p>
94094332d3Sopenharmony_ci</td>
95094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p103396560587"><a name="p103396560587"></a><a name="p103396560587"></a>Registers a callback to listen for IWiFi asynchronous events.</p>
96094332d3Sopenharmony_ci</td>
97094332d3Sopenharmony_ci</tr>
98094332d3Sopenharmony_ci<tr id="row894162955918"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1694112914590"><a name="p1694112914590"></a><a name="p1694112914590"></a>int32_t (*unRegisterEventCallback)(void);</p>
99094332d3Sopenharmony_ci</td>
100094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p18948295597"><a name="p18948295597"></a><a name="p18948295597"></a>Unregisters an <strong id="b1979834134512"><a name="b1979834134512"></a><a name="b1979834134512"></a>IWiFi</strong> callback.</p>
101094332d3Sopenharmony_ci</td>
102094332d3Sopenharmony_ci</tr>
103094332d3Sopenharmony_ci<tr id="row122731451103"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2273125104"><a name="p2273125104"></a><a name="p2273125104"></a>int32_t (*destroyFeature)(struct IWiFiBaseFeature *ifeature);</p>
104094332d3Sopenharmony_ci</td>
105094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p92731553017"><a name="p92731553017"></a><a name="p92731553017"></a>Destroys a specified <strong id="b15348165794518"><a name="b15348165794518"></a><a name="b15348165794518"></a>IWiFiBaseFeature</strong> object.</p>
106094332d3Sopenharmony_ci</td>
107094332d3Sopenharmony_ci</tr>
108094332d3Sopenharmony_ci<tr id="row172153335473"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1292417115515"><a name="p1292417115515"></a><a name="p1292417115515"></a>int32_t (*resetDriver)(const uint8_t chipId);</p>
109094332d3Sopenharmony_ci</td>
110094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p17272317145516"><a name="p17272317145516"></a><a name="p17272317145516"></a>Resets the WLAN driver with a specified chip ID.</p>
111094332d3Sopenharmony_ci</td>
112094332d3Sopenharmony_ci</tr>
113094332d3Sopenharmony_ci<tr id="row27321001058"><td class="cellrowborder" rowspan="2" valign="top" width="15.079999999999998%" headers="mcps1.2.4.1.1 "><p id="p134208191041"><a name="p134208191041"></a><a name="p134208191041"></a>wifi_hal_ap_feature.h</p>
114094332d3Sopenharmony_ci</td>
115094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" width="60.33%" headers="mcps1.2.4.1.2 "><p id="p77321105516"><a name="p77321105516"></a><a name="p77321105516"></a>int32_t (*getAssociatedStas)(const struct IWiFiAp *apFeature, struct StaInfo *staInfo, uint32_t count, uint32_t *num);</p>
116094332d3Sopenharmony_ci</td>
117094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" width="24.59%" headers="mcps1.2.4.1.3 "><p id="p1673213014513"><a name="p1673213014513"></a><a name="p1673213014513"></a>Obtains information (MAC addresses only in the current version) about all the connected STAs.</p>
118094332d3Sopenharmony_ci</td>
119094332d3Sopenharmony_ci</tr>
120094332d3Sopenharmony_ci<tr id="row39802291664"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p149801729465"><a name="p149801729465"></a><a name="p149801729465"></a>int32_t (*setCountryCode)(const struct IWiFiAp *apFeature, const char *code, uint32_t len);</p>
121094332d3Sopenharmony_ci</td>
122094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p098022910610"><a name="p098022910610"></a><a name="p098022910610"></a>Sets the country/region code.</p>
123094332d3Sopenharmony_ci</td>
124094332d3Sopenharmony_ci<tr id="row14149145512411"><td class="cellrowborder" rowspan="1" valign="top" width="15.079999999999998%" headers="mcps1.2.4.1.1 "><p id="p18149155246"><a name="p18149155246"></a><a name="p18149155246"></a>wifi_hal_sta_feature.h</p>
125094332d3Sopenharmony_ci</td>
126094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" width="60.33%" headers="mcps1.2.4.1.2 "><p id="p17149165511414"><a name="p17149165511414"></a><a name="p17149165511414"></a>int32_t (*setScanningMacAddres)(const struct IWiFiSta *staFeature, unsigned char *scanMac, uint8_t len);</p>
127094332d3Sopenharmony_ci</td>
128094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" width="24.59%" headers="mcps1.2.4.1.3 "><p id="p181491255149"><a name="p181491255149"></a><a name="p181491255149"></a>Sets a single MAC address to scan for.</p>
129094332d3Sopenharmony_ci</td>
130094332d3Sopenharmony_ci<tr id="row451796205011"><td class="cellrowborder" rowspan="8" valign="top" width="15.079999999999998%" headers="mcps1.2.4.1.1 "><p id="p2659417135013"><a name="p2659417135013"></a><a name="p2659417135013"></a>wifi_hal_base_feature.h</p>
131094332d3Sopenharmony_ci</td>
132094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" width="60.33%" headers="mcps1.2.4.1.2 "><p id="p73831421111010"><a name="p73831421111010"></a><a name="p73831421111010"></a>const char *(*getNetworkIfaceName)(const struct IWiFiBaseFeature *baseFeature);</p>
133094332d3Sopenharmony_ci</td>
134094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" width="24.59%" headers="mcps1.2.4.1.3 "><p id="p16363321101014"><a name="p16363321101014"></a><a name="p16363321101014"></a>Obtains the name of a network interface.</p>
135094332d3Sopenharmony_ci</td>
136094332d3Sopenharmony_ci</tr>
137094332d3Sopenharmony_ci<tr id="row1657914017107"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p15117233152315"><a name="p15117233152315"></a><a name="p15117233152315"></a>int32_t (*getFeatureType)(const struct IWiFiBaseFeature *);</p>
138094332d3Sopenharmony_ci</td>
139094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p195182610507"><a name="p195182610507"></a><a name="p195182610507"></a>Obtains the feature type.</p>
140094332d3Sopenharmony_ci</td>
141094332d3Sopenharmony_ci</tr>
142094332d3Sopenharmony_ci<tr id="row5518663503"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p125181260501"><a name="p125181260501"></a><a name="p125181260501"></a>int32_t (*setMacAddress)(const struct IWiFiBaseFeature *, unsigned char *, uint8_t);</p>
143094332d3Sopenharmony_ci</td>
144094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1151815635014"><a name="p1151815635014"></a><a name="p1151815635014"></a>Sets the MAC address.</p>
145094332d3Sopenharmony_ci</td>
146094332d3Sopenharmony_ci</tr>
147094332d3Sopenharmony_ci<tr id="row851915617503"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p20519865500"><a name="p20519865500"></a><a name="p20519865500"></a>int32_t (*getDeviceMacAddress)(const struct IWiFiBaseFeature *, unsigned char *, uint8_t);</p>
148094332d3Sopenharmony_ci</td>
149094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p14519469509"><a name="p14519469509"></a><a name="p14519469509"></a>Obtains the device MAC address.</p>
150094332d3Sopenharmony_ci</td>
151094332d3Sopenharmony_ci</tr>
152094332d3Sopenharmony_ci<tr id="row986761516115"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2867181581116"><a name="p2867181581116"></a><a name="p2867181581116"></a>int32_t (*getValidFreqsWithBand)(const struct IWiFiBaseFeature *baseFeature, int32_t band, int32_t *freqs, uint32_t count, uint32_t *num);</p>
153094332d3Sopenharmony_ci</td>
154094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p15867101551112"><a name="p15867101551112"></a><a name="p15867101551112"></a>Obtains the frequencies supported by the 2.4 GHz or 5 GHz band.</p>
155094332d3Sopenharmony_ci</td>
156094332d3Sopenharmony_ci</tr>
157094332d3Sopenharmony_ci<tr id="row18232258171117"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p145195620502"><a name="p145195620502"></a><a name="p145195620502"></a>int32_t (*setTxPower)(const struct IWiFiBaseFeature *, int32_t);</p>
158094332d3Sopenharmony_ci</td>
159094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p175191863503"><a name="p175191863503"></a><a name="p175191863503"></a>Sets the transmit power.</p>
160094332d3Sopenharmony_ci</td>
161094332d3Sopenharmony_ci</tr>
162094332d3Sopenharmony_ci<tr id="row1744948201219"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p7449128101215"><a name="p7449128101215"></a><a name="p7449128101215"></a>int32_t (*getChipId)(const struct IWiFiBaseFeature *baseFeature, uint8_t *chipId);</p>
163094332d3Sopenharmony_ci</td>
164094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1244998131219"><a name="p1244998131219"></a><a name="p1244998131219"></a>Obtains the chip ID of the current driver.</p>
165094332d3Sopenharmony_ci</td>
166094332d3Sopenharmony_ci</tr>
167094332d3Sopenharmony_ci<tr id="row34351131216"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p743711161213"><a name="p743711161213"></a><a name="p743711161213"></a>int32_t (*getIfNamesByChipId)(const uint8_t chipId, char **ifNames, uint32_t *num);</p>
168094332d3Sopenharmony_ci</td>
169094332d3Sopenharmony_ci<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p164361118121"><a name="p164361118121"></a><a name="p164361118121"></a>Obtains names of all the NICs of the current chip based on the chip ID.</p>
170094332d3Sopenharmony_ci</td>
171094332d3Sopenharmony_ci</tbody>
172094332d3Sopenharmony_ci</table>
173094332d3Sopenharmony_ci
174094332d3Sopenharmony_ci## Usage Guidelines<a name="section19806524151819"></a>
175094332d3Sopenharmony_ci
176094332d3Sopenharmony_ciThe following describes how to use the WLAN HAL module.
177094332d3Sopenharmony_ci
178094332d3Sopenharmony_ci1.  Call the  **WifiConstruct**  function to create an  **IWiFi**  object.
179094332d3Sopenharmony_ci2.  Use the created  **IWiFi**  object to call the  **start**  function to create a channel between the HAL and the driver and obtain the driver NIC information.
180094332d3Sopenharmony_ci3.  Call the  **createFeature**  function to create an AP feature or STA feature. You can call functions to perform operations on the created feature \(use an AP feature as an example\).
181094332d3Sopenharmony_ci4.  Call functions to perform operations, such as calling the  **setMacAddress**  function to set the MAC address and calling the  **getDeviceMacAddress**  function to obtain the device MAC address.
182094332d3Sopenharmony_ci5.  Call the  **destroyFeature**  function to destroy the created feature.
183094332d3Sopenharmony_ci6.  Call the  **stop**  function to stop the channel between the HAL and the driver.
184094332d3Sopenharmony_ci7.  Call the  **WifiDestruct**  function to destroy the  **IWiFi**  object.
185094332d3Sopenharmony_ci
186094332d3Sopenharmony_ciThe sample code is as follows:
187094332d3Sopenharmony_ci
188094332d3Sopenharmony_ci```
189094332d3Sopenharmony_ci#include "wifi_hal.h"
190094332d3Sopenharmony_ci#include "wifi_hal_sta_feature.h"
191094332d3Sopenharmony_ci#include "wifi_hal_ap_feature.h"
192094332d3Sopenharmony_ci#include "wifi_hal_cmd.h"
193094332d3Sopenharmony_ci#include "wifi_hal_event.h"
194094332d3Sopenharmony_ci
195094332d3Sopenharmony_ci#define MAC_LEN 6
196094332d3Sopenharmony_ci
197094332d3Sopenharmony_cistatic void *hal_main()
198094332d3Sopenharmony_ci{
199094332d3Sopenharmony_ci    int ret;
200094332d3Sopenharmony_ci    struct IWiFi *wifi;
201094332d3Sopenharmony_ci
202094332d3Sopenharmony_ci    /* Create an IWiFi object. */
203094332d3Sopenharmony_ci    ret = WifiConstruct(&wifi);
204094332d3Sopenharmony_ci    if (ret != 0 || wifi == NULL) {
205094332d3Sopenharmony_ci        return;
206094332d3Sopenharmony_ci    }
207094332d3Sopenharmony_ci
208094332d3Sopenharmony_ci    /* Create a channel between the HAL and the driver. */
209094332d3Sopenharmony_ci    ret = wifi->start(wifi);
210094332d3Sopenharmony_ci    if (ret != 0) {
211094332d3Sopenharmony_ci        return;
212094332d3Sopenharmony_ci    }
213094332d3Sopenharmony_ci
214094332d3Sopenharmony_ci    /* Create an AP feature. */
215094332d3Sopenharmony_ci    ret = wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
216094332d3Sopenharmony_ci    if (ret != 0) {
217094332d3Sopenharmony_ci        return;
218094332d3Sopenharmony_ci    }
219094332d3Sopenharmony_ci
220094332d3Sopenharmony_ci    /* Obtain the device MAC address. */
221094332d3Sopenharmony_ci    unsigned char mac[MAC_LEN] = {0};
222094332d3Sopenharmony_ci    ret = apFeature->baseFeature.getDeviceMacAddress((struct IWiFiBaseFeature *)apFeature, mac, MAC_LEN);
223094332d3Sopenharmony_ci    if (ret != 0) {
224094332d3Sopenharmony_ci        return;
225094332d3Sopenharmony_ci    }
226094332d3Sopenharmony_ci
227094332d3Sopenharmony_ci    /* Destroy the created AP feature. */
228094332d3Sopenharmony_ci    ret = wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
229094332d3Sopenharmony_ci    if (ret != 0) {
230094332d3Sopenharmony_ci        return;
231094332d3Sopenharmony_ci    }
232094332d3Sopenharmony_ci
233094332d3Sopenharmony_ci    /* Stop the created channel. */
234094332d3Sopenharmony_ci    ret = wifi->stop(wifi);
235094332d3Sopenharmony_ci    if (ret != 0) {
236094332d3Sopenharmony_ci        return;
237094332d3Sopenharmony_ci    }
238094332d3Sopenharmony_ci
239094332d3Sopenharmony_ci    /* Destroy the created IWiFi object. */
240094332d3Sopenharmony_ci    ret = WifiDestruct(&wifi);
241094332d3Sopenharmony_ci    if (ret != 0) {
242094332d3Sopenharmony_ci        return;
243094332d3Sopenharmony_ci    }
244094332d3Sopenharmony_ci    return;
245094332d3Sopenharmony_ci}
246094332d3Sopenharmony_ci```
247094332d3Sopenharmony_ci
248094332d3Sopenharmony_ci## Repositories Involved<a name="section1371113476307"></a>
249094332d3Sopenharmony_ci
250094332d3Sopenharmony_ci[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver.md)
251094332d3Sopenharmony_ci
252094332d3Sopenharmony_ci[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
253094332d3Sopenharmony_ci
254094332d3Sopenharmony_ci[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
255094332d3Sopenharmony_ci
256094332d3Sopenharmony_ci[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
257094332d3Sopenharmony_ci
258094332d3Sopenharmony_ci[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral)
259094332d3Sopenharmony_ci
260