update openharmony 1.0.1

This commit is contained in:
mamingshuai
2021-03-11 18:37:47 +08:00
parent cb06a6be69
commit 2b38a60f02
16 changed files with 1344 additions and 75 deletions
Executable
View File
+18
View File
@@ -0,0 +1,18 @@
#Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
lite_component("wifi") {
features = [ "$ohos_vendor_adapter_dir/hals/communication/wifi_lite/wifiservice:wifiservice" ]
}
Executable
+177
View File
@@ -0,0 +1,177 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
-36
View File
@@ -1,36 +0,0 @@
# communication_wifi_lite
#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+4 -39
View File
@@ -1,39 +1,4 @@
# communication_wifi_lite
#### 介绍
{**以下是 Gitee 平台说明,您可以替换此简介**
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
## Introduction
This directory provides the implementation of the WLAN interfaces.
see: https://gitee.com/openharmony/docs/blob/master/docs-en/readme/distributed-communication-subsystem.md
+76
View File
@@ -0,0 +1,76 @@
# WLAN服务组件
## 简介
WLAN服务组件为设备提供接入与使用WLAN的相关接口,包括开启、关闭WLAN,监听WLAN状态等。
## 目录
```
foundation/communication/wifi_lite
├── interfaces # 组件对外提供接口代码存放目录
│ └── wifiservice # WLAN服务接口代码存放目录
├── LICENSE # 版权声明文件
```
## 约束
WLAN服务组件使用C语言编写,目前支持wifi-iot开发板。
## 使用
- 设备需要完成以下开发步骤,以开启WLAN:
```
//开启WLAN
WifiErrorCode error = EnableWifi();
if (error != WIFI_SUCCESS) {
return;
}
```
- 设备需要完成以下开发步骤,以触发WLAN扫描:
```
//开启WLAN
WifiErrorCode error = Scan();
if (error != WIFI_SUCCESS) {
return;
}
```
- 设备需要完成以下开发步骤,以获取WLAN扫描结果:
```
WifiScanInfo* infoList = malloc(sizeof(WifiScanInfo) * WIFI_SCAN_HOTSPOT_LIMIT);
unsigned int size = WIFI_SCAN_HOTSPOT_LIMIT;
error = GetScanInfoList(infoList, &size);
if (error != WIFI_SUCCESS || size == 0) {
return;
}
```
- 设备需要完成以下开发步骤,以配置接入点的接入方式:
```
int netId = 0;
WifiDeviceConfig config = {0};
config.freq = 20;
config.securityType = WIFI_SEC_TYPE_PSK;
config.wapiPskType = WIFI_PSK_TYPE_ASCII;
memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "Sample", 10); //在这里输入待连接WLAN的名称
unsigned char bssid[WIFI_MAC_LEN] = {0xac, 0x75, 0x1d, 0xd8, 0x55, 0xc1}; //在这里输入待连接WLAN的BSSID
memcpy_s(config.bssid, WIFI_MAC_LEN, bssid, WIFI_MAC_LEN);
memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "1234567890", 10); //在这里输入待连接WLAN的口令
WifiErrorCode error = AddDeviceConfig(&config, &netId);
if (error != WIFI_SUCCESS || netId == 0) {
return;
}
```
- 设备需要完成以下开发步骤,以连接配置的WLAN:
```
error = ConnectTo(netId); //netId来自上一步
if (error != WIFI_SUCCESS) {
return;
}
```
+11
View File
@@ -0,0 +1,11 @@
## Introduction
In order to support third developers to develop their applications, this directory provides some WLAN interface functions. For example, enable or disable WLAN, or monitor WLAN status.
## Directions
```
.
├── LICENSE
├── README.md
└── wifiservice
```
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file station_info.h
*
* @brief Defines the structure and macro of the station information contained in the event information.
*
* The station information is passed to {@link OnHotspotStaJoin} or {@link OnHotspotStaLeave} invoked when a specified
* event occurs.
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_STATION_INFO_H
#define _WIFI_STATION_INFO_H
#include "wifi_device_config.h"
/**
* @brief Represents the station information.
*
* The station information is returned when {@link OnHotspotStaJoin} or {@link OnHotspotStaLeave} is called. \n
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** MAC address. For its length, see {@link WIFI_MAC_LEN}. */
unsigned char macAddress[WIFI_MAC_LEN];
unsigned short disconnectedReason;
} StationInfo;
#endif // _WIFI_STATION_INFO_H
/** @} */
+228
View File
@@ -0,0 +1,228 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file wifi_device.h
*
* @brief Provides capabilities to enable and disable the station mode, connect to and disconnect from a station,
* query the station status, and listen for events.
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_DEVICE_H
#define _WIFI_DEVICE_H
#include "wifi_event.h"
#include "station_info.h"
#include "wifi_scan_info.h"
#include "wifi_error_code.h"
#include "wifi_linked_info.h"
#include "wifi_device_config.h"
/**
* @brief Enables the station mode.
*
* @return Returns {@link WIFI_SUCCESS} if the station mode is enabled; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode EnableWifi(void);
/**
* @brief Disables the station mode.
*
* @return Returns {@link WIFI_SUCCESS} if the station mode is disabled; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode DisableWifi(void);
/**
* @brief Checks whether the station mode is enabled.
*
* @return Returns {@link WIFI_STA_ACTIVE} if the station mode is enabled; returns {@link WIFI_STA_NOT_ACTIVE}
* otherwise.
* @since 1.0
* @version 1.0
*/
int IsWifiActive(void);
/**
* @brief Starts a Wi-Fi scan.
*
* @return Returns {@link WIFI_SUCCESS} if the Wi-Fi scan is started; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode Scan(void);
/**
* @brief Obtains an array of hotspots detected in a Wi-Fi scan.
*
* The array of hotspots can be obtained only after the Wi-Fi scan is complete. \n
*
* @param result Indicates the array of hotspots detected in a Wi-Fi scan. The array is requested and released by the
* caller. The value must be greater than or equal to {@link WIFI_SCAN_HOTSPOT_LIMIT}.
* @param size Indicates the size of the array.
* @return Returns {@link WIFI_SUCCESS} if the array of hotspots detected in the Wi-Fi scan is obtained; returns an
* error code defined in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode GetScanInfoList(WifiScanInfo* result, unsigned int* size);
/**
* @brief Adds a specified hotspot configuration for connecting to a hotspot.
*
* This function generates a <b>networkId</b>. \n
*
* @param config Indicates the hotspot configuration to add.
* @param result Indicates the generated <b>networkId</b>. Each <b>networkId</b> matches a hotspot configuration.
* @return Returns {@link WIFI_SUCCESS} if the specified hotspot configuration is added; returns an error code defined
* in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode AddDeviceConfig(const WifiDeviceConfig* config, int* result);
/**
* @brief Obtains all hotspot configurations.
*
* Hotspot configurations were added using {@link AddDeviceConfig}. \n
*
* @param result Indicates the array of all hotspot configurations. The array is requested and released by the caller.
* The value must be greater than or equal to {@link WIFI_MAX_CONFIG_SIZE}.
* @param size Indicates the size of the array.
* @return Returns {@link WIFI_SUCCESS} if all hotspot configurations are obtained; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode GetDeviceConfigs(WifiDeviceConfig* result, unsigned int* size);
/**
* @brief Removes a hotspot configuration matching a specified <b>networkId</b>.
*
* @param networkId Indicates the <b>networkId</b> matching the hotspot configuration to remove.
* @return Returns {@link WIFI_SUCCESS} if the hotspot configuration is removed; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode RemoveDevice(int networkId);
/**
* @brief Connects to a hotspot matching a specified <b>networkId</b>.
*
* Before calling this function, call {@link AddDeviceConfig} to add a hotspot configuration. \n
*
* @param networkId Indicates the <b>networkId</b> matching the target hotspot.
* @return Returns {@link WIFI_SUCCESS} if the hotspot is connected; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode ConnectTo(int networkId);
/**
* @brief Disconnects this Wi-Fi connection.
*
* @return Returns {@link WIFI_SUCCESS} if this Wi-Fi connection is disconnected; returns an error code defined
* in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode Disconnect(void);
/**
* @brief Obtains information about the connected hotspot.
*
* @param result Indicates the information about the connected hotspot.
* @return Returns {@link WIFI_SUCCESS} if the information about the connected hotspot is obtained; returns an error
* code defined in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode GetLinkedInfo(WifiLinkedInfo* result);
/**
* @brief Registers a callback for a specified Wi-Fi event.
*
* The registered callback will be invoked when the Wi-Fi event defined in {@link WifiEvent} occurs. \n
*
* @param event Indicates the event for which the callback is to be registered.
* @return Returns {@link WIFI_SUCCESS} if the callback is registered successfully; returns an error code defined
* in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode RegisterWifiEvent(WifiEvent* event);
/**
* @brief Unregisters a callback previously registered for a specified Wi-Fi event.
*
* @param event Indicates the event for which the callback is to be unregistered.
* @return Returns {@link WIFI_SUCCESS} if the callback is unregistered successfully; returns an error code defined
* in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode UnRegisterWifiEvent(const WifiEvent* event);
/**
* @brief Obtains the MAC address of this device.
*
*
*
* @param result Indicates the MAC address of this device. It is a char array whose length is 6.
* @return Returns {@link WIFI_SUCCESS} if the MAC address of this device is obtained; returns an error code defined
* in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode GetDeviceMacAddress(unsigned char* result);
/**
* @brief Starts a Wi-Fi scan based on a specified parameter.
*
* Only results matching the specified parameter will be returned for the Wi-Fi scan.\n
*
* @param params Indicates the pointer to the parameter for starting the Wi-Fi scan.
* For details, see {@link WifiScanParams}.
* @return Returns {@link WIFI_SUCCESS} if the Wi-Fi scan is started successfully;
* returns an error code defined in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode AdvanceScan(WifiScanParams *params);
#endif // _WIFI_DEVICE_H
/** @} */
+173
View File
@@ -0,0 +1,173 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file wifi_device_config.h
*
* @brief Defines the Wi-Fi station configuration.
*
* The Wi-Fi station configuration includes the security type and data length. \n
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_DEVICE_CONFIG_H
#define _WIFI_DEVICE_CONFIG_H
/**
* @brief Indicates the maximum number of Wi-Fi station configurations that can be added using {@link AddDeviceConfig}.
*
* If the maximum number is reached, an error will be returned. In this case, you must delete at least one
* configuration before you can add new ones. \n
*/
#define WIFI_MAX_CONFIG_SIZE 10
/**
* @brief Indicates the value of <b>networkId</b> when the configuration file is unavailable.
*
* Generally, the configuration file is unavailable because the configuration matching the <b>networkId</b> is
* uninitialized. \n
*/
#define WIFI_CONFIG_INVALID (-1)
/**
* @brief Indicates the maximum length of a Wi-Fi SSID.
*
* The maximum length is 32, and the last bit is reserved and set to <b>\0</b>. \n */
#define WIFI_MAX_SSID_LEN 33 // 32 + \0
/**
* @brief Indicates the maximum length of a Wi-Fi key.
*
* The maximum length is 64, and the last bit is reserved and set to <b>\0</b>. \n
*/
#define WIFI_MAX_KEY_LEN 65 // 64 + \0
/**
* @brief Indicates the maximum length of a Wi-Fi MAC address or a Wi-Fi BSSID.
*
*/
#define WIFI_MAC_LEN 6
/**
* @brief Indicates the maximum length of a Wi-Fi PSK.
*
*/
#define WIFI_PSK_LEN 32
/**
* @brief Enumerates Wi-Fi security types.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Invalid security type */
WIFI_SEC_TYPE_INVALID = -1,
/** Open */
WIFI_SEC_TYPE_OPEN,
/** Wired Equivalent Privacy (WEP) */
WIFI_SEC_TYPE_WEP,
/** Pre-shared key (PSK) */
WIFI_SEC_TYPE_PSK,
/** Simultaneous Authentication of Equals (SAE) */
WIFI_SEC_TYPE_SAE,
} WifiSecurityType;
/**
* @brief Enumerates psk encryption types.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Indicates that the ascii type of psk encryption type */
WIFI_PSK_TYPE_ASCII = 0,
/** Indicates that the hex type of psk encryption type */
WIFI_PSK_TYPE_HEX,
} WifiPskType;
/**
* @brief Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.
*
* @since 1.0
* @version 1.0
*/
typedef struct WifiDeviceConfig {
/** Service set ID (SSID). For its length, see {@link WIFI_MAX_SSID_LEN}. */
char ssid[WIFI_MAX_SSID_LEN];
/** Basic service set ID (BSSID). For its length, see {@link WIFI_MAC_LEN}. */
unsigned char bssid[WIFI_MAC_LEN];
/** Key. For its length, see {@link WIFI_MAX_KEY_LEN}. */
char preSharedKey[WIFI_MAX_KEY_LEN];
/** Security type. It is defined in {@link WifiSecurityType}. */
int securityType;
/** Allocated <b>networkId</b> */
int netId;
/** Frequency */
unsigned int freq;
/** PSK type, see {@link WifiPskType}. */
int wapiPskType;
} WifiDeviceConfig;
/**
* @brief Enumerates Wi-Fi scan types.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** A scan based on a specified frequency. */
WIFI_FREQ_SCAN,
/** A scan based on a specified SSID. */
WIFI_SSID_SCAN,
/** A scan based on a specified BSSID. */
WIFI_BSSID_SCAN,
/** A scan based on a specified frequency band. */
WIFI_BAND_SCAN
} WifiScanType;
/**
* @brief Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** Service set ID (SSID). Its maximum length is defined by {@link WIFI_MAX_SSID_LEN}. */
char ssid[WIFI_MAX_SSID_LEN];
/** Length of the SSID. */
char ssidLen;
/** Basic service set ID (BSSID). Its length is defined by {@link WIFI_MAC_LEN}. */
char bssid[WIFI_MAC_LEN];
/** Frequency. */
int freqs;
/** Frequency band. */
int band;
/** Wi-Fi scan type, which is defined by {@link WifiScanType}. */
WifiScanType scanType;
} WifiScanParams;
#endif // _WIFI_DEVICE_CONFIG_H
/** @} */
+71
View File
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file wifi_error_code.h
*
* @brief Defines error codes of the Wi-Fi service.
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_ERROR_CODE_H
#define _WIFI_ERROR_CODE_H
/**
* @brief Enumerates Wi-Fi error codes.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** No errors. */
WIFI_SUCCESS = 0,
/** Invalid parameters */
ERROR_WIFI_INVALID_ARGS = -1,
/** Invalid chip */
ERROR_WIFI_CHIP_INVALID = -2,
/** Invalid Wi-Fi interface */
ERROR_WIFI_IFACE_INVALID = -3,
/** Invalid RTT controller */
ERROR_WIFI_RTT_CONTROLLER_INVALID = -4,
/** Wi-Fi not supported by the current version or device */
ERROR_WIFI_NOT_SUPPORTED = -5,
/** Wi-Fi unavailable */
ERROR_WIFI_NOT_AVAILABLE = -6,
/** Wi-Fi not initialized or started */
ERROR_WIFI_NOT_STARTED = -7,
/** System busy */
ERROR_WIFI_BUSY = -8,
/** Unknown error */
ERROR_WIFI_UNKNOWN = -9
} WifiErrorCode;
#endif // _WIFI_ERROR_CODE_H
/** @} */
+111
View File
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file wifi_event.h
*
* @brief Defines callbacks and structure of Wi-Fi events.
*
* {@link RegisterWifiEvent} can be used to listen for Wi-Fi connection, disconnection, and scan events. \n
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_EVENT_H
#define _WIFI_EVENT_H
#include "wifi_linked_info.h"
#include "station_info.h"
/**
* @brief Indicates that the Wi-Fi station mode is enabled.
*
*/
#define WIFI_STA_ACTIVE 1
/**
* @brief Indicates that the Wi-Fi station mode is disabled.
*
*/
#define WIFI_STA_NOT_ACTIVE 0
/**
* @brief Indicates that the Wi-Fi hotspot mode is enabled.
*
*/
#define WIFI_HOTSPOT_ACTIVE 1
/**
* @brief Indicates that the Wi-Fi hotspot mode is disabled.
*
*/
#define WIFI_HOTSPOT_NOT_ACTIVE 0
/**
* @brief Indicates the maximum number of event listeners that can be registered using {@link RegisterWifiEvent}.
*
* When the maximum number is reached, you need to unregister at least one listener before registering new ones. \n
*/
#define WIFI_MAX_EVENT_SIZE 10
/**
* @brief Represents the pointer to a Wi-Fi event callback for station and hotspot connection, disconnection, or scan.
*
*
* If you do not need a callback, set the value of its pointer to <b>NULL</b>. \n
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** Connection state change */
void (*OnWifiConnectionChanged)(int state, WifiLinkedInfo* info);
/** Scan state change */
void (*OnWifiScanStateChanged)(int state, int size);
/** Hotspot state change */
void (*OnHotspotStateChanged)(int state);
/** Station connected */
void (*OnHotspotStaJoin)(StationInfo* info);
/** Station disconnected */
void (*OnHotspotStaLeave)(StationInfo* info);
} WifiEvent;
/**
* @brief Enumerates states in Wi-Fi events.
*
*
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Unavailable state */
WIFI_STATE_NOT_AVALIABLE = 0,
/** Available state */
WIFI_STATE_AVALIABLE
} WifiEventState;
#endif // _WIFI_EVENT_H
/** @} */
+142
View File
@@ -0,0 +1,142 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file wifi_hotspot.h
*
* @brief Provides capabilities to enable and disable the hotspot mode, connect to and disconnect from a hotspot, query
* the hotspot status, and listen for events.
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_HOTSPOT_H
#define _WIFI_HOTSPOT_H
#include "wifi_device.h"
#include "wifi_error_code.h"
#include "wifi_hotspot_config.h"
#include "wifi_event.h"
/**
* @brief Defines the default channel of the hotspot mode.
*/
#define HOTSPOT_DEFAULT_CHANNEL 6
/**
* @brief Enables the hotspot mode.
*
* Before using this function, you need to invoke {@link SetHotspotConfig} and set at least the SSID, security type,
* and key. \n
*
* @return Returns {@link WIFI_SUCCESS} if the hotspot mode is enabled; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode EnableHotspot(void);
/**
* @brief Disables the hotspot mode.
*
* @return Returns {@link WIFI_SUCCESS} if the hotspot mode is disabled; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode DisableHotspot(void);
/**
* @brief Sets a specified hotspot configuration.
*
* The hotspot configuration includes the SSID, security type, and key. The configuration set overwrites the existing
* configuration and takes effect after the hotspot mode is re-enabled. \n
* Before enabling the hotspot mode for the first time, you must call this function. \n
*
* @param config Indicates the hotspot configuration to set.
* @return Returns {@link WIFI_SUCCESS} if the hotspot configuration is set; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0 */
WifiErrorCode SetHotspotConfig(const HotspotConfig* config);
/**
* @brief Obtains a specified hotspot configuration.
*
* The hotspot configuration includes the SSID, security type, and key. \n
*
* @param result Indicates the obtained hotspot configuration.
* @return Returns {@link WIFI_SUCCESS} if the hotspot configuration is obtained; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode GetHotspotConfig(HotspotConfig* result);
/**
* @brief Checks whether the hotspot mode is enabled.
*
* @return Returns {@link WIFI_HOTSPOT_ACTIVE} if the hotspot mode is enabled; returns {@link WIFI_HOTSPOT_NOT_ACTIVE}
* otherwise.
* @since 1.0
* @version 1.0
*/
int IsHotspotActive(void);
/**
* @brief Obtains an array of stations connected to this hotspot.
*
* The station information is defined in {@link StationInfo}. \n
*
* @param result Indicates the array of stations connected to this hotspot. The array is requested and released by the
* caller. The value must be greater than or equal to {@link WIFI_MAX_STA_NUM}.
* @param size Indicates the size of the array.
* @return Returns {@link WIFI_SUCCESS} if the array of stations connected to this hotspot is obtained; returns an error
* code defined in {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode GetStationList(StationInfo* result, unsigned int* size);
/**
* @brief Obtains the signal level indicated by a specified received signal strength indicator (RSSI) and frequency
* band.
*
*
* Based on the signal level, you can display the signal strength represented by the number of signal bars. \n
*
* @param rssi Indicates the RSSI.
* @param band Indicates the frequency band, either {@link HOTSPOT_BAND_TYPE_5G} or {@link HOTSPOT_BAND_TYPE_2G}.
* @return Returns the signal level if it is obtained; returns <b>-1</b> otherwise.
* @since 1.0
* @version 1.0
*/
int GetSignalLevel(int rssi, int band);
#endif // _WIFI_HOTSPOT_H_
/** @} */
@@ -0,0 +1,127 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file wifi_hotspot_config.h
*
* @brief Defines the Wi-Fi hotspot configuration.
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_HOTSPOT_CONFIG_H
#define _WIFI_HOTSPOT_CONFIG_H
#include "wifi_device_config.h"
#include "wifi_error_code.h"
/**
* @brief Defines the maximum number of stations connected to a hotspot.
*/
#define WIFI_MAX_STA_NUM 6
/**
* @brief Enumerates received signal strength indicator (RSSI) levels.
*
* Four RSSI levels are available: 1 to 4. The higher the RSSI level, the stronger the Wi-Fi signal.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Level 1. The RSSI value for a 2.4 GHz hotspot ranges from <b>-88</b> (included) to <b>-82</b> (excluded),
* and that for a 5 GHz hotspot ranges from <b>-85</b> (included) to <b>-79</b> (excluded). */
RSSI_LEVEL_1 = 1,
/** Level 2. The RSSI value for a 2.4 GHz hotspot ranges from <b>-82</b> (included) to <b>-75</b> (excluded),
* and that for a 5 GHz hotspot ranges from <b>-79</b> (included) to <b>-72</b> (excluded). */
RSSI_LEVEL_2 = 2,
/** Level 3. The RSSI value for a 2.4 GHz hotspot ranges from <b>-75</b> (included) to <b>-65</b> (excluded),
* and that for a 5 GHz hotspot ranges from <b>-72</b> (included) to <b>-65</b> (excluded). */
RSSI_LEVEL_3 = 3,
/** Level 4. The RSSI value for a 2.4 GHz or 5 GHz hotspot is greater than or equal to <b>-65</b>. */
RSSI_LEVEL_4 = 4,
} RssiLevel;
/**
* @brief Enumerates frequency bands supported by the Wi-Fi hotspot mode.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** 2.4 GHz */
HOTSPOT_BAND_TYPE_2G = 1,
/** 5 GHz */
HOTSPOT_BAND_TYPE_5G = 2,
} HotspotBandType;
/**
* @brief Represents the hotspot configuration.
*
* A hotspot configuration must contain the SSID (or BSSID), security type, and key (if the security type is open). \n
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** Service set ID (SSID). For its length, see {@link WIFI_MAX_SSID_LEN}. */
char ssid[WIFI_MAX_SSID_LEN];
/** Security type */
int securityType;
/** Frequency band */
int band;
/** Channel number */
int channelNum;
/** Key. For its length, see {@link WIFI_MAX_SSID_LEN}. */
char preSharedKey[WIFI_MAX_KEY_LEN];
} HotspotConfig;
/**
* @brief Sets the frequency band for this hotspot.
*
* @param band Indicates the frequency band to set.
* @return Returns {@link WIFI_SUCCESS} if the frequency band is set; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode SetBand(int band);
/**
* @brief Obtains the frequency band of this hotspot.
*
* @param result Indicates the obtained frequency band.
* @return Returns {@link WIFI_SUCCESS} if the frequency band is obtained; returns an error code defined in
* {@link WifiErrorCode} otherwise.
* @since 1.0
* @version 1.0
*/
WifiErrorCode GetBand(int* result);
#endif // _WIFI_HOTSPOT_CONFIG_H
/** @} */
+77
View File
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file wifi_linked_info.h
*
* @brief Defines the data structure and macro of the Wi-Fi connection information.
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_LINKED_INFO_H
#define _WIFI_LINKED_INFO_H
#include "wifi_device_config.h"
/**
* @brief Enumerates Wi-Fi connection states.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Disconnected */
WIFI_DISCONNECTED,
/** Connected */
WIFI_CONNECTED
} WifiConnState;
/**
* @brief Represents the Wi-Fi connection information.
*
* This refers to the information about the hotspot connected to this station. The information is obtained using
* {@link GetLinkedInfo}.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** Service set ID (SSID). For its length, see {@link WIFI_MAX_SSID_LEN}. */
char ssid[WIFI_MAX_SSID_LEN];
/** Basic service set ID (BSSID). For its length, see {@link WIFI_MAC_LEN}. */
unsigned char bssid[WIFI_MAC_LEN];
/** Received signal strength indicator (RSSI) */
int rssi;
/** Wi-Fi connection state, which is defined in {@link WifiConnState} */
WifiConnState connState;
/** Reason for Wi-Fi disconnection */
unsigned short disconnectedReason;
} WifiLinkedInfo;
#endif // _WIFI_LINKED_INFO_H
/** @} */
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup wifiservice
* @{
*
* @brief Provides functions for the Wi-Fi station and hotspot modes.
*
* You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
* station or hotspot, query the station or hotspot status, and listen for events. \n
*
* @since 1.0
* @version 1.0
*/
/**
* @file wifi_scan_info.h
*
* @brief Defines the data structure and macro of the Wi-Fi scan result information.
*
* @since 1.0
* @version 1.0
*/
#ifndef _WIFI_SCAN_INFO_H
#define _WIFI_SCAN_INFO_H
#include "wifi_device_config.h"
/**
* @brief Indicates the maximum number of hotspots that can be detected in a Wi-Fi scan.
*/
#define WIFI_SCAN_HOTSPOT_LIMIT 64
/**
* @brief Represents the Wi-Fi scan result information.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** Service set ID (SSID). For its length, see {@link WIFI_MAX_SSID_LEN}. */
char ssid[WIFI_MAX_SSID_LEN];
/** Basic service set ID (BSSID). For its length, see {@link WIFI_MAC_LEN}. */
unsigned char bssid[WIFI_MAC_LEN];
/** Security type. For details, see {@link WifiSecurityType}. */
int securityType;
/** Received signal strength indicator (RSSI) */
int rssi;
/** Frequency band */
int band;
/** Frequency in MHz */
int frequency;
} WifiScanInfo;
#endif // _WIFI_SCAN_INFO_H
/** @} */