• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 #define WIFI_MAX_SSID_LEN 33
25 #define WIFI_MAC_LEN 6
26 #define WIFI_MAX_KEY_LEN 65
27 #define WIFI_MAX_CONFIG_SIZE 10
28 #define WIFI_MAX_SCAN_HOTSPOT_LIMIT 128
29 #define MAX_CALLBACK_NUM 5
30 #define WIFI_COMMON_MAC_LEN 6
31 #define WIFI_PASSPHRASE_LENGTH 64
32 #define WIFI_P2P_NAME_LENGTH 33
33 #define WIFI_INTERFACE_LENGTH 16
34 #define WIFI_DEVICE_TYPE_LENGTH 128
35 #define WIFI_MAX_DEVICES_NUM 256
36 #define WIFI_IP_ADDR_STR_LEN 16
37 
38 typedef enum {
39     BAND_UNKNOWN,
40     BAND_24G,
41     BAND_5G,
42 } SoftBusBand;
43 
44 typedef struct {
45     char ssid[WIFI_MAX_SSID_LEN];
46     unsigned char bssid[WIFI_MAC_LEN];
47     char preSharedKey[WIFI_MAX_KEY_LEN];
48     int32_t securityType;
49     int32_t netId;
50     int32_t isHiddenSsid;
51 } SoftBusWifiDevConf;
52 
53 typedef struct {
54     /* call back for scan result */
55     void (*onSoftBusWifiScanResult)(int state, int size);
56 } ISoftBusScanResult;
57 
58 typedef struct {
59     char ssid[WIFI_MAX_SSID_LEN];
60     unsigned char bssid[WIFI_MAC_LEN];
61     int32_t securityType;
62     int32_t rssi;
63     int32_t band;
64     int32_t frequency;
65     int32_t channelWidth;
66     int32_t centerFrequency0;
67     int32_t centerFrequency1;
68     int64_t timestamp;
69 } SoftBusWifiScanInfo;
70 
71 typedef enum {
72     SOFTBUS_API_WIFI_DISCONNECTED,
73     SOFTBUS_API_WIFI_CONNECTED,
74 } SoftBusWifiConnState;
75 
76 typedef struct {
77     char ssid[WIFI_MAX_SSID_LEN];
78     unsigned char bssid[WIFI_MAC_LEN];
79     int32_t rssi;
80     int32_t band;
81     int32_t frequency;
82     SoftBusWifiConnState connState;
83     unsigned short disconnectedReason;
84     unsigned int ipAddress;
85 } SoftBusWifiLinkedInfo;
86 
87 typedef enum SoftBusP2pGroupStatus {
88     SOFTBUS_API_WIFI_GS_CREATING,
89     SOFTBUS_API_WIFI_GS_CREATED,
90     SOFTBUS_API_WIFI_GS_STARTED,
91     SOFTBUS_API_WIFI_GS_REMOVING,
92     SOFTBUS_API_WIFI_GS_INVALID
93 } SoftBusP2pGroupStatus;
94 
95 typedef enum SoftBusP2pDeviceStatus {
96     SOFTBUS_API_WIFI_PDS_CONNECTED,
97     SOFTBUS_API_WIFI_PDS_INVITED,
98     SOFTBUS_API_WIFI_PDS_FAILED,
99     SOFTBUS_API_WIFI_PDS_AVAILABLE,
100     SOFTBUS_API_WIFI_PDS_UNAVAILABLE
101 } SoftBusP2pDeviceStatus;
102 
103 typedef struct SoftBusWifiP2pWfdInfo {
104     int32_t wfdEnabled; /* 0: false, 1: true */
105     int32_t deviceInfo;
106     int32_t ctrlPort;
107     int32_t maxThroughput;
108 } SoftBusWifiP2pWfdInfo;
109 
110 typedef struct SoftBusWifiP2pDevice {
111     char deviceName[WIFI_P2P_NAME_LENGTH]; /* the value range is 0 to 32 characters. */
112     unsigned char devAddr[WIFI_COMMON_MAC_LEN]; /* the device MAC address */
113     char primaryDeviceType[WIFI_DEVICE_TYPE_LENGTH];
114     char secondaryDeviceType[WIFI_DEVICE_TYPE_LENGTH];
115     SoftBusP2pDeviceStatus status;
116     SoftBusWifiP2pWfdInfo wfdInfo;
117     unsigned int supportWpsConfigMethods;
118     int32_t deviceCapabilitys;
119     int32_t groupCapabilitys;
120 } SoftBusWifiP2pDevice;
121 
122 typedef struct SoftBusWifiP2pGroupInfo {
123     SoftBusWifiP2pDevice owner;
124     int32_t isP2pGroupOwner; /* 0: false, 1: true */
125     char passphrase[WIFI_PASSPHRASE_LENGTH]; /* the value ranges from 8 to 63. */
126     char interface[WIFI_INTERFACE_LENGTH];
127     char groupName[WIFI_P2P_NAME_LENGTH];
128     int32_t networkId;
129     int32_t frequency; /* for example : freq=2412 to select 2.4 GHz channel 1.(Based on 2.4 GHz or 5 GHz) */
130     int32_t isP2pPersistent; /* 0: false, 1: true */
131     SoftBusP2pGroupStatus groupStatus;
132     SoftBusWifiP2pDevice clientDevices[WIFI_MAX_DEVICES_NUM];
133     int32_t clientDevicesSize; /* the true size of clientDevices array */
134     char goIpAddress[WIFI_IP_ADDR_STR_LEN];
135 } SoftBusWifiP2pGroupInfo;
136 
137 int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num);
138 int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig);
139 int32_t SoftBusDisconnectDevice(void);
140 int32_t SoftBusStartWifiScan(void);
141 int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb);
142 /* parameter *result is released by the caller. */
143 int32_t SoftBusGetWifiScanList(SoftBusWifiScanInfo **result, uint32_t *size);
144 int32_t SoftBusUnRegisterWifiEvent(ISoftBusScanResult *cb);
145 int32_t SoftBusGetChannelListFor5G(int32_t *channelList, int32_t num);
146 SoftBusBand SoftBusGetLinkBand(void);
147 int32_t SoftBusGetLinkedInfo(SoftBusWifiLinkedInfo *info);
148 int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo);
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 #endif // SOFTBUS_WIFI_API_ADAPTER_H
154