1 /* 2 * Copyright (C) 2022 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 OHOS_C_HID2D_H 17 #define OHOS_C_HID2D_H 18 19 #include "wifi_error_code.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #ifndef MAC_LEN 26 #define MAC_LEN 6 27 #endif 28 29 #define IPV4_ARRAY_LEN 4 30 31 #ifndef IF_NAME_LEN 32 #define IF_NAME_LEN 32 33 #endif 34 35 #define MAX_SSID_LEN 33 // max length: 32 + \0 36 #define MAX_KEY_LEN 65 // max length: 64 + \0 37 38 #define CFG_DATA_MAX_BYTES 255 39 40 #define CFG_CALLBACK_BYTE 4 41 42 typedef enum CfgType { 43 CFG_INVALID = -1, 44 GET_SELF_CONFIG = 0, 45 } CfgType; 46 47 typedef void (*WifiCfgChangCallback)(CfgType, char* data, int dataLen); 48 49 typedef enum DhcpMode { 50 CONNECT_GO_NODHCP = 0, 51 CONNECT_AP_DHCP = 1, 52 CONNECT_AP_NODHCP = 2 53 } DhcpMode; 54 55 typedef enum FreqType { 56 FREQUENCY_DEFAULT = 0, 57 FREQUENCY_160M = 1, 58 } FreqType; 59 60 typedef enum SelfCfgType { 61 TYPE_OF_GET_SELF_CONFIG = 1, 62 TYPE_OF_GET_SELF_CONFIG_WITH_PASSWORD = 2 63 } SelfCfgType; 64 65 typedef enum PeerCfgType { 66 TYPE_OF_SET_PEER_CONFIG = 1, 67 TYPE_OF_SET_PEER_STATE_CHANGE = 2 68 } PeerCfgType; 69 70 typedef enum PreferBandwidth { 71 /** default */ 72 BW_DEFAULT, 73 /** indicates the ultimate bandwidth, corresponding to 160 Mbit/s or 320 Mbit/s in the future. */ 74 BW_EXTRAM, 75 /** high throughput. The default value is 80 Mbit/s. */ 76 BW_HIGH_PERF, 77 /** low-latency service type, 40 Mbit/s/80 Mbit/s, 78 * which needs to be determined based on the current channel status. */ 79 BW_LOW_LATENCY 80 } PreferBandwidth; 81 82 typedef enum RecommendStatus { 83 RS_SUCCESS, 84 RS_LOCAL_ADJUST, 85 RS_REMOTE_ADJUST, 86 RS_FAILURE 87 } RecommendStatus; 88 89 typedef struct Hid2dConnectConfig { 90 /** Service set ID (SSID). */ 91 char ssid[MAX_SSID_LEN]; 92 /** Basic service set ID (BSSID). */ 93 unsigned char bssid[MAC_LEN]; 94 /** Key. */ 95 char preSharedKey[MAX_KEY_LEN]; 96 /** group frequency. */ 97 int frequency; 98 /** connection mode. */ 99 DhcpMode dhcpMode; 100 } Hid2dConnectConfig; 101 102 /** 103 * @Description Ip address info structure, the element format is a 4-bit int array. 104 * example: 127.0.0.1 -> int[ 127, 0, 0, 1 ] 105 */ 106 typedef struct IpAddrInfo { 107 unsigned int ip[IPV4_ARRAY_LEN]; 108 unsigned int gateway[IPV4_ARRAY_LEN]; 109 unsigned int netmask[IPV4_ARRAY_LEN]; 110 } IpAddrInfo; 111 112 typedef struct RecommendChannelRequest { 113 /** the interface name of the remote device */ 114 char remoteIfName[IF_NAME_LEN]; 115 /** the mode of the interface on the remote device */ 116 int remoteIfMode; 117 /** interface name of the local device */ 118 char localIfName[IF_NAME_LEN]; 119 /** the mode of the interface on the local device */ 120 int localIfMode; 121 /** preferred frequency band */ 122 int prefBand; 123 /** preferred bandwidth type (enumerated) */ 124 PreferBandwidth prefBandwidth; 125 } RecommendChannelRequest; 126 127 typedef struct RecommendChannelResponse { 128 /** 0: success; 1: local adjustment; 2: remote adjustment; –1: failure */ 129 RecommendStatus status; 130 /* 1 fails. 0-N corresponds to the input array subscript (that is, the interface to be connected) */ 131 int index; 132 /* The primary 20 MHz frequency of the channel */ 133 int centerFreq; 134 /** 135 * Do not used if the access point bandwidth is 20 MHz 136 * If the AP use 40, 80 or 160 MHz, this is the center frequency, if the AP use 80 + 80 MHz, 137 * this is the center frequency of the first segment 138 */ 139 int centerFreq1; 140 /** 141 * Only used if the AP bandwidth is 80 + 80 MHz 142 * if the AP use 80 + 80 MHz, this is the center frequency of the second segment 143 */ 144 int centerFreq2; 145 /* band width */ 146 int bandwidth; 147 } RecommendChannelResponse; 148 149 typedef struct Hid2dUpperScene { 150 /* The mac address of the device */ 151 unsigned char mac[MAC_LEN]; 152 /* The scene of upper layer, hexadecimal digit, currently bit 0-2 is valid, 0: video, 1: audio, 2: file */ 153 unsigned int scene; 154 /* Frame rate, -1/30/60 is valid */ 155 int fps; 156 /* band width, valid only in video scenes, the default value is 0 */ 157 unsigned int bw; 158 } Hid2dUpperScene; 159 160 /** 161 * @Description Request an IP address to the Gc from the IP address pool, used on the GO side. 162 * 163 * @param gcMac - gc mac address 164 * @param ipAddr - Indicates the applied IP address, which is a 4-bit int array. 165 * example: 127.0.0.1 -> ipAddr[ 127, 0, 0, 1 ] 166 * @return WifiErrorCode - operation result 167 */ 168 WifiErrorCode Hid2dRequestGcIp(const unsigned char gcMac[MAC_LEN], unsigned int ipAddr[IPV4_ARRAY_LEN]); 169 170 /** 171 * @Description Increase(+1) shared link reference counting 172 * 173 * @return WifiErrorCode - operation result 174 */ 175 WifiErrorCode Hid2dSharedlinkIncrease(void); 176 177 /** 178 * @Description Decrease(-1) shared link reference counting 179 * 180 * @return WifiErrorCode - operation result 181 */ 182 WifiErrorCode Hid2dSharedlinkDecrease(void); 183 184 /** 185 * @Description Create hid2d group, used on the GO side. 186 * 187 * @param frequency - frequency 188 * @param type - frequency type 189 * @return WifiErrorCode - operation result 190 */ 191 WifiErrorCode Hid2dCreateGroup(const int frequency, FreqType type); 192 193 /** 194 * @Description The GC side actively disconnects from the GO, used on the GC side. 195 * 196 * @param gcIfName - network interface name 197 * @return WifiErrorCode - operation result 198 */ 199 WifiErrorCode Hid2dRemoveGcGroup(const char gcIfName[IF_NAME_LEN]); 200 201 /** 202 * @Description Connect to a specified group using hid2d, used on the GC side. 203 * 204 * @param config - connection parameters 205 * @return WifiErrorCode - operation result 206 */ 207 WifiErrorCode Hid2dConnect(const Hid2dConnectConfig *config); 208 209 /** 210 * @Description Configuring IP addresses for P2P network interfaces, used on the GC side. 211 * 212 * @param ifName - network interface name 213 * @param ipInfo - IP infos 214 * @return WifiErrorCode - operation result 215 */ 216 WifiErrorCode Hid2dConfigIPAddr(const char ifName[IF_NAME_LEN], const IpAddrInfo *ipInfo); 217 218 /** 219 * @Description Clear IP address when the P2P connection is disconnected, used on the GC side. 220 * 221 * @param ifName - network interface name 222 * @return WifiErrorCode - operation result 223 */ 224 WifiErrorCode Hid2dReleaseIPAddr(const char ifName[IF_NAME_LEN]); 225 226 /** 227 * @Description Obtain the recommended channel and bandwidth for link setup 228 * 229 * @param request - request data 230 * @param response - response result 231 * 232 * @return WifiErrorCode - operation result 233 */ 234 WifiErrorCode Hid2dGetRecommendChannel(const RecommendChannelRequest *request, RecommendChannelResponse *response); 235 236 /** 237 * @Description Get 5G channel list 238 * 239 * @param chanList - An array of pre-allocated memory for storing channel list results, 240 * Use the '0' to indicates the end of valid data in the "chanList" array. 241 * 242 * @param len - the length of the pre-alloc "chanList" 243 * @return WifiErrorCode - operation result 244 */ 245 WifiErrorCode Hid2dGetChannelListFor5G(int *chanList, int len); 246 247 /** 248 * @Description get the self wifi configuration information 249 * 250 * @param cfgType - configuration type 251 * @param cfgData - the queried data of wifi configuration 252 * @param getDatValidLen - the valid data length in the array `cfgData` 253 * @return WifiErrorCode - operation result 254 */ 255 WifiErrorCode Hid2dGetSelfWifiCfgInfo(SelfCfgType cfgType, char cfgData[CFG_DATA_MAX_BYTES], int *getDatValidLen); 256 257 /** 258 * @Description set the peer wifi configuration information 259 * 260 * @param cfgType - configuration type 261 * @param cfgData - the wifi configuration data to be set 262 * @param setDataValidLen - the valid data length in the array `cfgData` 263 * @return WifiErrorCode - operation result 264 */ 265 WifiErrorCode Hid2dSetPeerWifiCfgInfo(PeerCfgType cfgType, char cfgData[CFG_DATA_MAX_BYTES], int setDataValidLen); 266 267 /** 268 * @Description Querying the support capability of wide bandwidth 269 * 270 * @return int - 0: not supported, 1: supported 271 */ 272 int Hid2dIsWideBandwidthSupported(void); 273 274 /** 275 * @Description Set the scene of upper layer 276 * 277 * @param ifName - interface name 278 * @param scene - scene 279 * @return WifiErrorCode - operate result 280 */ 281 WifiErrorCode Hid2dSetUpperScene(const char ifName[IF_NAME_LEN], const Hid2dUpperScene *scene); 282 283 /** 284 * @Description Register config change callback 285 * 286 * @param callback - callback 287 * @return WifiErrorCode - operate result 288 */ 289 WifiErrorCode RegisterCfgChangCallback(const WifiCfgChangCallback callback); 290 291 /** 292 * @Description Unregister config change callback 293 * 294 * @return WifiErrorCode - operate result 295 */ 296 WifiErrorCode UnregisterCfgChangCallback(void); 297 #ifdef __cplusplus 298 } 299 #endif 300 301 #endif 302