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