1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SOFTBUS_WIFI_API_ADAPTER_H
17 #define SOFTBUS_WIFI_API_ADAPTER_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 #define WIFI_MAX_SSID_LEN 33
26 #define WIFI_MAC_LEN 6
27 #define WIFI_MAX_KEY_LEN 65
28 #define WIFI_MAX_CONFIG_SIZE 10
29 #define WIFI_MAX_SCAN_HOTSPOT_LIMIT 128
30 #define MAX_CALLBACK_NUM 5
31 #define WIFI_COMMON_MAC_LEN 6
32 #define WIFI_PASSPHRASE_LENGTH 64
33 #define WIFI_P2P_NAME_LENGTH 33
34 #define WIFI_INTERFACE_LENGTH 16
35 #define WIFI_DEVICE_TYPE_LENGTH 128
36 #define WIFI_MAX_DEVICES_NUM 256
37 #define WIFI_IP_ADDR_STR_LEN 16
38 
39 typedef enum {
40     BAND_UNKNOWN,
41     BAND_24G,
42     BAND_5G,
43 } SoftBusBand;
44 
45 typedef struct {
46     char ssid[WIFI_MAX_SSID_LEN];
47     unsigned char bssid[WIFI_MAC_LEN];
48     char preSharedKey[WIFI_MAX_KEY_LEN];
49     int32_t securityType;
50     int32_t netId;
51     int32_t isHiddenSsid;
52 } SoftBusWifiDevConf;
53 
54 typedef struct {
55     /* call back for scan result */
56     void (*onSoftBusWifiScanResult)(int state, int size);
57 } ISoftBusScanResult;
58 
59 typedef struct {
60     char ssid[WIFI_MAX_SSID_LEN];
61     unsigned char bssid[WIFI_MAC_LEN];
62     int32_t securityType;
63     int32_t rssi;
64     int32_t band;
65     int32_t frequency;
66     int32_t channelWidth;
67     int32_t centerFrequency0;
68     int32_t centerFrequency1;
69     int64_t timestamp;
70 } SoftBusWifiScanInfo;
71 
72 typedef enum {
73     SOFTBUS_API_WIFI_DISCONNECTED,
74     SOFTBUS_API_WIFI_CONNECTED,
75 } SoftBusWifiConnState;
76 
77 typedef struct {
78     char ssid[WIFI_MAX_SSID_LEN];
79     unsigned char bssid[WIFI_MAC_LEN];
80     int32_t rssi;
81     int32_t band;
82     int32_t frequency;
83     SoftBusWifiConnState connState;
84     unsigned short disconnectedReason;
85     unsigned int ipAddress;
86 } SoftBusWifiLinkedInfo;
87 
88 typedef enum SoftBusP2pGroupStatus {
89     SOFTBUS_API_WIFI_GS_CREATING,
90     SOFTBUS_API_WIFI_GS_CREATED,
91     SOFTBUS_API_WIFI_GS_STARTED,
92     SOFTBUS_API_WIFI_GS_REMOVING,
93     SOFTBUS_API_WIFI_GS_INVALID
94 } SoftBusP2pGroupStatus;
95 
96 typedef enum SoftBusP2pDeviceStatus {
97     SOFTBUS_API_WIFI_PDS_CONNECTED,
98     SOFTBUS_API_WIFI_PDS_INVITED,
99     SOFTBUS_API_WIFI_PDS_FAILED,
100     SOFTBUS_API_WIFI_PDS_AVAILABLE,
101     SOFTBUS_API_WIFI_PDS_UNAVAILABLE
102 } SoftBusP2pDeviceStatus;
103 
104 typedef enum SoftBusWifiDetailState {
105     SOFTBUS_WIFI_STATE_UNKNOWN = -1,
106     SOFTBUS_WIFI_STATE_INACTIVE,
107     SOFTBUS_WIFI_STATE_ACTIVED,
108     SOFTBUS_WIFI_STATE_ACTIVATING,
109     SOFTBUS_WIFI_STATE_DEACTIVATING,
110     SOFTBUS_WIFI_STATE_SEMIACTIVATING,
111     SOFTBUS_WIFI_STATE_SEMIACTIVE,
112 } SoftBusWifiDetailState;
113 
114 typedef struct SoftBusWifiP2pWfdInfo {
115     int32_t wfdEnabled; /* 0: false, 1: true */
116     int32_t deviceInfo;
117     int32_t ctrlPort;
118     int32_t maxThroughput;
119 } SoftBusWifiP2pWfdInfo;
120 
121 typedef struct SoftBusWifiP2pDevice {
122     char deviceName[WIFI_P2P_NAME_LENGTH]; /* the value range is 0 to 32 characters. */
123     unsigned char devAddr[WIFI_COMMON_MAC_LEN]; /* the device MAC address */
124     char primaryDeviceType[WIFI_DEVICE_TYPE_LENGTH];
125     char secondaryDeviceType[WIFI_DEVICE_TYPE_LENGTH];
126     SoftBusP2pDeviceStatus status;
127     SoftBusWifiP2pWfdInfo wfdInfo;
128     unsigned int supportWpsConfigMethods;
129     int32_t deviceCapabilitys;
130     int32_t groupCapabilitys;
131 } SoftBusWifiP2pDevice;
132 
133 typedef struct SoftBusWifiP2pGroupInfo {
134     SoftBusWifiP2pDevice owner;
135     int32_t isP2pGroupOwner; /* 0: false, 1: true */
136     char passphrase[WIFI_PASSPHRASE_LENGTH]; /* the value ranges from 8 to 63. */
137     char interface[WIFI_INTERFACE_LENGTH];
138     char groupName[WIFI_P2P_NAME_LENGTH];
139     int32_t networkId;
140     int32_t frequency; /* for example : freq=2412 to select 2.4 GHz channel 1.(Based on 2.4 GHz or 5 GHz) */
141     int32_t isP2pPersistent; /* 0: false, 1: true */
142     SoftBusP2pGroupStatus groupStatus;
143     SoftBusWifiP2pDevice clientDevices[WIFI_MAX_DEVICES_NUM];
144     int32_t clientDevicesSize; /* the true size of clientDevices array */
145     char goIpAddress[WIFI_IP_ADDR_STR_LEN];
146 } SoftBusWifiP2pGroupInfo;
147 
148 int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num);
149 int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig);
150 int32_t SoftBusDisconnectDevice(void);
151 int32_t SoftBusStartWifiScan(void);
152 int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb);
153 /* parameter *result is released by the caller. */
154 int32_t SoftBusGetWifiScanList(SoftBusWifiScanInfo **result, uint32_t *size);
155 int32_t SoftBusUnRegisterWifiEvent(ISoftBusScanResult *cb);
156 int32_t SoftBusGetChannelListFor5G(int32_t *channelList, int32_t num);
157 SoftBusBand SoftBusGetLinkBand(void);
158 int32_t SoftBusGetLinkedInfo(SoftBusWifiLinkedInfo *info);
159 int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo);
160 bool SoftBusHasWifiDirectCapability(void);
161 bool SoftBusIsWifiTripleMode(void);
162 char* SoftBusGetWifiInterfaceCoexistCap(void);
163 bool SoftBusIsWifiActive(void);
164 bool SoftBusIsHotspotActive(void);
165 SoftBusWifiDetailState SoftBusGetWifiState(void);
166 bool SoftBusIsWifiP2pEnabled(void);
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 #endif // SOFTBUS_WIFI_API_ADAPTER_H
172