【统一互联】iot_connect WIFI 接口适配
iot_connect
iot_connect 组件 ble 接口位于iot_connect/adapter/ble 目录下。ohos_lite 为小系统,ohos_standard为标准设备。
ble 对接芯片适配层标准设备可以参考社区Rk3568的实现,小设备可以参考通用互联ws63的实现。
接口列表
需要实现的接口头文件参考OpenHarmony wifi_lite 仓foundation/communication/wifi_lite/interfaces/wifiservice目录的的wifi相关头文件。
下文中列出必须实现的接口实示例。下列返回方法,规定 0 为成功,如果厂商协议栈规定非0为成功,需要转化。
EnableWifi
Enables the station mode
WifiErrorCode EnableWifi(void) {
// 调用wifi协议栈接口
int ret = wifi_sta_enable();
if (ret == SUCCESS) {
return WIFI_SUCCESS;
}
return ERROR_WIFI_UNKNOWN;
}
DisableWifi
Disables the station mode
WifiErrorCode DisableWifi(void) {
// 调用wifi协议栈接口
int ret = wifi_sta_disable();
if (ret == SUCCESS) {
return WIFI_SUCCESS;
}
return ERROR_WIFI_UNKNOWN;
}
IsWifiActive
Checks whether the station mode is enabled
WifiErrorCode IsWifiActive(void) {
// 调用wifi协议栈接口
return WIFI_SUCCESS;
}
Scan
Starts a Wi-Fi scan
WifiErrorCode Scan() {
// 调用wifi协议栈接口
int ret = wifi_sta_scan();
if (ret == SUCCESS) {
return WIFI_SUCCESS;
}
return ERROR_WIFI_UNKNOWN;
}
GetScanInfoList
Obtains an array of hotspots detected in a Wi-Fi scan
WifiErrorCode GetScanInfoList(WifiScanInfo *result, unsigned int *size)
{
// 调用wifi协议栈接口
wifi_sta_get_scan_info(ScanList, size);
// 转化
return WIFI_SUCCESS;
}
AddDeviceConfig
Adds a specified hotspot configuration for connecting to a hotspot.
WifiErrorCode AddDeviceConfig(const WifiDeviceConfig *config, int *result)
{
return WIFI_SUCCESS;
}
GetDeviceConfigs
Obtains all hotspot configurations.
WifiErrorCode GetDeviceConfigs(WifiDeviceConfig *result, unsigned int *size)
{
return WIFI_SUCCESS;
}
RemoveDevice
Removes a hotspot configuration matching a specified.
WifiErrorCode RemoveDevice(int networkId) {
return WIFI_SUCCESS;
}
ConnectTo
Connects to a hotspot matching a specified
WifiErrorCode ConnectTo(int networkId) {
// 调用wifi协议栈接口
int ret = wifi_sta_connect();
if (ret == SUCCESS) {
return WIFI_SUCCESS;
}
return ERROR_WIFI_UNKNOWN;
}
Disconnect
Disconnects this Wi-Fi connection
WifiErrorCode Disconnect(void)
{
// 调用wifi协议栈接口
int ret = wifi_sta_disconnect();
if (ret == SUCCESS) {
return WIFI_SUCCESS;
}
return ERROR_WIFI_UNKNOWN;
}
GetLinkedInfo
Obtains information about the connected hotspot
WifiErrorCode GetLinkedInfo(WifiLinkedInfo *result)
{
// 调用wifi协议栈接口
int ret = wifi_sta_get_ap_info();
if (ret != SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
// 转化
return WIFI_SUCCESS;
}
GetDeviceMacAddress
Obtains the MAC address of this device.
WifiErrorCode GetDeviceMacAddress(unsigned char *result) {
// 调用wifi协议栈接口
wifi_linked_info_stru LinkedInfo = {0};
int ret = wifi_sta_get_ap_info(&LinkedInfo);
if (ret != SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
memcpy_s(result, WIFI_MAC_LEN, LinkedInfo.bssid, WIFI_MAC_LEN);
return WIFI_SUCCESS;
}
AdvanceScan
Starts a Wi-Fi scan based on a specified parameter.
WifiErrorCode AdvanceScan(WifiScanParams *params) {
if (params == NULL) {
return ERROR_WIFI_UNKNOWN;
}
// 调用wifi协议栈接口
int ret = wifi_sta_scan_advance(ScanParams);
if (ret != SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
GetIpInfo
get the ip address
int GetIpInfo(IpInfo *info)
{
// 可调用dhc或者网络模块的相关接口
return WIFI_SUCCESS;
}
RegisterWifiEvent
Registers a callback for a specified Wi-Fi event
static WifiEvent *g_event;
static void OnWifiScanStateChangedCallback(int32_t state, int32_t size)
{
if (g_event->OnWifiScanStateChanged) {
g_event->OnWifiScanStateChanged(state, size);
}
}
WifiErrorCode RegisterWifiEvent(WifiEvent *event) {
// 调用wifi协议栈接口
// 需要实现
g_event = event;
wifi_event_stru cb = {0};
cb.wifi_event_scan_state_changed = OnWifiScanStateChangedCallback;
cb.wifi_event_connection_changed = OnWifiConnectionChangedCallback;
cb.wifi_event_softap_sta_join = OnHotspotStaJoinCallback;
cb.wifi_event_softap_sta_leave = OnHotspotStaLeaveCallback;
cb.wifi_event_softap_state_changed = OnHotspotStateChangedCallback;
int ret = wifi_register_event_cb(cb);
if (ret != SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
UnRegisterWifiEvent
Unregisters a callback previously registered for a specified Wi-Fi event
WifiErrorCode UnRegisterWifiEvent(const WifiEvent *event) {
// 调用wifi协议栈接口
int ret = wifi_unregister_event_cb(ScanParams);
if (ret != SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
EnableHotspot
Enables the hotspot mode.
WifiErrorCode EnableHotspot() {
// 调用wifi协议栈接口,开启softap
return WIFI_SUCCESS;
}
EnableHotspot
Disables the hotspot mode.
WifiErrorCode DisableHotspot() {
// 调用wifi协议栈接口,关闭softap
return WIFI_SUCCESS;
}
SetHotspotConfig
Sets a specified hotspot configuration.
WifiErrorCode SetHotspotConfig(const HotspotConfig *config) {
return WIFI_SUCCESS;
}
GetHotspotConfig
Obtains a specified hotspot configuration
WifiErrorCode GetHotspotConfig(const HotspotConfig *result) {
return WIFI_SUCCESS;
}
IsHotspotActive
Checks whether the hotspot mode is enabled
int IsHotspotActive(void) {
// 调用wifi协议栈接口
int ret = wifi_is_softap_enabled();
if (ret != SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
GetStationList
Obtains an array of stations connected to this hotspot
WifiErrorCode GetStationList(StationInfo *result, unsigned int *size) {
// 调用wifi协议栈接口
// 该方法需要返回 sta 设备的ip
int ret = wifi_softap_get_sta_list(ScanParams);
if (ret != SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
// 转化
return WIFI_SUCCESS;
}
DisassociateSta
Disconnects from the station with a specified MAC address
WifiErrorCode DisassociateSta(unsigned char *mac, int macLen) {
// 调用wifi协议栈接口
int ret = wifi_softap_deauth_sta(mac, macLen);
if (ret != SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
// 转化
return WIFI_SUCCESS;
}
iot-connect 接口修改
IotcGetSoftApIp 接口
oh_lite iotc_network.c 文件中的 IotcGetSoftApIp 需要基于引入lwip相关的接口适配。
lwap 相关接口
iotc_socket.c 中调用 lwip,socket 的相关接口需要基于芯片引入的三范库修改适配。
更多推荐
所有评论(0)