1 /* 2 * Copyright (c) 2023 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 WPA_CLIENT_H 17 #define WPA_CLIENT_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif 27 28 #define ETH_ADDR_LEN 6 29 #ifndef IFNAMSIZ 30 #define IFNAMSIZ 16 31 #endif 32 #define WIFI_REASON_LENGTH 32 33 #define WIFI_SSID_LENGTH 132 34 35 #define WIFI_P2P_DEVICE_TYPE_LENGTH 64 36 #define WIFI_P2P_DEVICE_NAME_LENGTH 128 37 #define WIFI_P2P_WFD_DEVICE_INFO_LENGTH 128 38 #define WIFI_P2P_PASSWORD_SIZE 128 39 #define WIFI_P2P_GROUP_IFNAME_LENGTH 128 40 #define WIFI_PIN_CODE_LENGTH 8 41 #define WIFI_P2P_TLVS_LENGTH 256 42 #define WIFI_BSSID_LEN 6 43 #define WPA_VENDOR_DATA_LEN 256 44 #define WPA_VENDOR_SSID_LEN 32 45 #define WPA_VENDOR_PSK_LEN 64 46 47 typedef enum { 48 WPA_EVENT_DISCONNECT = 0, 49 WPA_EVENT_CONNECT, 50 WPA_EVENT_BSSID_CHANGE, 51 WPA_EVENT_STATE_CHANGED, 52 WPA_EVENT_TEMP_DISABLE, 53 WPA_EVENT_ASSOCIATE_REJECT, 54 WPA_EVENT_WPS_OVERLAP, 55 WPA_EVENT_WPS_TIMEMOUT, 56 WPA_EVENT_RECV_SCAN_RESULT, 57 WPA_EVENT_DEVICE_FOUND, 58 WPA_EVENT_DEVICE_LOST, 59 WPA_EVENT_GO_NEGOTIATION_REQUEST, 60 WPA_EVENT_GO_NEGOTIATION_COMPLETED, 61 WPA_EVENT_INVITATION_RECEIVED, 62 WPA_EVENT_INVITATION_RESULT, 63 WPA_EVENT_GROUP_FORMATION_SUCCESS, 64 WPA_EVENT_GROUP_FORMATION_FAILURE, 65 WPA_EVENT_GROUP_START, 66 WPA_EVENT_GROUP_REMOVED, 67 WPA_EVENT_PROVISION_DISCOVERY_COMPLETED, 68 WPA_EVENT_FIND_STOPPED, 69 WPA_EVENT_SERV_DISC_REQ, 70 WPA_EVENT_SERV_DISC_RESP, 71 WPA_EVENT_STA_CONNECT_STATE, 72 WPA_EVENT_IFACE_CREATED, 73 WPA_EVENT_STA_AUTH_REJECT, 74 WPA_EVENT_STA_NOTIFY, 75 WPA_EVENT_VENDOR_EXT, 76 WPA_EVENT_AUTH_TIMEOUT, 77 WPA_EVENT_IFACE_REMOVED, 78 } WpaCallBackEventType; 79 80 enum WpaClientType { 81 /* 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<8 | 1<<9 | 1<<10 ... | 1<<29 */ 82 WIFI_WPA_TO_HAL_CLIENT = (1 << 29) - 1, 83 WIFI_WPA_CLIENT_BUTT 84 }; 85 86 struct WpaDisconnectParam { 87 unsigned char bssid[WIFI_BSSID_LEN]; 88 int reasonCode; 89 int locallyGenerated; 90 }; 91 92 struct WpaConnectParam { 93 unsigned char bssid[WIFI_BSSID_LEN]; 94 int networkId; 95 }; 96 97 struct WpaBssidChangedParam { 98 unsigned char bssid[WIFI_BSSID_LEN]; 99 unsigned char reason[WIFI_REASON_LENGTH]; 100 }; 101 102 struct WpaStateChangedParam { 103 int status; 104 unsigned char bssid[WIFI_BSSID_LEN]; 105 int networkId; 106 unsigned char ssid[WIFI_SSID_LENGTH]; 107 }; 108 109 struct WpaTempDisabledParam { 110 int networkId; 111 unsigned char ssid[WIFI_SSID_LENGTH]; 112 int authFailures; 113 int duration; 114 unsigned char reason[WIFI_REASON_LENGTH]; 115 }; 116 117 struct WpaAssociateRejectParam { 118 unsigned char bssid[WIFI_BSSID_LEN]; 119 int statusCode; 120 int timeOut; 121 }; 122 123 struct WpaAuthRejectParam { 124 unsigned char bssid[WIFI_BSSID_LEN]; 125 unsigned short authType; 126 unsigned short authTransaction; 127 unsigned short statusCode; 128 }; 129 130 struct WpaRecvScanResultParam { 131 unsigned int scanId; 132 }; 133 134 struct P2pDeviceInfoParam { 135 unsigned char srcAddress[ETH_ADDR_LEN]; 136 unsigned char p2pDeviceAddress[ETH_ADDR_LEN]; 137 unsigned char primaryDeviceType[WIFI_P2P_DEVICE_TYPE_LENGTH]; 138 unsigned char deviceName[WIFI_P2P_DEVICE_NAME_LENGTH]; 139 int configMethods; 140 int deviceCapabilities; 141 int groupCapabilities; 142 unsigned char wfdDeviceInfo[WIFI_P2P_WFD_DEVICE_INFO_LENGTH]; 143 unsigned int wfdLength; 144 unsigned char operSsid[WIFI_P2P_DEVICE_NAME_LENGTH]; 145 }; 146 147 struct P2pDeviceLostParam { 148 unsigned char p2pDeviceAddress[ETH_ADDR_LEN]; 149 int networkId; 150 }; 151 152 struct P2pGoNegotiationRequestParam { 153 unsigned char srcAddress[ETH_ADDR_LEN]; 154 int passwordId; 155 }; 156 157 struct P2pGoNegotiationCompletedParam { 158 int status; 159 }; 160 161 struct P2pInvitationReceivedParam { 162 int type; /* 0:Received, 1:Accepted */ 163 int persistentNetworkId; 164 int operatingFrequency; 165 unsigned char srcAddress[ETH_ADDR_LEN]; 166 unsigned char goDeviceAddress[ETH_ADDR_LEN]; 167 unsigned char bssid[ETH_ADDR_LEN]; 168 }; 169 170 struct P2pInvitationResultParam { 171 int status; 172 unsigned char bssid[ETH_ADDR_LEN]; 173 }; 174 175 struct P2pGroupStartedParam { 176 int isGo; 177 int isPersistent; 178 int frequency; 179 unsigned char groupIfName[WIFI_P2P_GROUP_IFNAME_LENGTH]; 180 unsigned char ssid[WIFI_SSID_LENGTH]; 181 unsigned char psk[WIFI_P2P_PASSWORD_SIZE]; 182 unsigned char passphrase[WIFI_P2P_PASSWORD_SIZE]; 183 unsigned char goDeviceAddress[ETH_ADDR_LEN]; 184 unsigned char goRandomDeviceAddress[ETH_ADDR_LEN]; 185 }; 186 187 struct P2pGroupRemovedParam { 188 int isGo; 189 unsigned char groupIfName[WIFI_P2P_GROUP_IFNAME_LENGTH]; 190 }; 191 192 struct P2pProvisionDiscoveryCompletedParam { 193 int isRequest; 194 int provDiscStatusCode; 195 int configMethods; 196 unsigned char p2pDeviceAddress[ETH_ADDR_LEN]; 197 unsigned char generatedPin[WIFI_PIN_CODE_LENGTH]; 198 }; 199 200 struct P2pServDiscRespParam { 201 int updateIndicator; 202 unsigned char srcAddress[ETH_ADDR_LEN]; 203 unsigned char tlvs[WIFI_P2P_TLVS_LENGTH]; 204 }; 205 206 struct P2pStaConnectStateParam { 207 int state; 208 unsigned char srcAddress[ETH_ADDR_LEN]; 209 unsigned char p2pDeviceAddress[ETH_ADDR_LEN]; 210 }; 211 212 struct P2pServDiscReqInfoParam { 213 int freq; 214 int dialogToken; 215 int updateIndic; 216 unsigned char mac[ETH_ADDR_LEN]; 217 unsigned char tlvs[WIFI_P2P_TLVS_LENGTH]; 218 }; 219 220 struct P2pIfaceCreatedParam { 221 int isGo; 222 }; 223 224 typedef int32_t (*OnReceiveFunc)(uint32_t event, void *data, const char *ifName); 225 226 struct WpaCallbackEvent { 227 uint32_t eventType; /* eventmap */ 228 char ifName[IFNAMSIZ + 1]; 229 OnReceiveFunc onRecFunc; 230 }; 231 232 struct WpaVendorExtInfo { 233 int type; 234 int freq; 235 int width; 236 int id; 237 int status; 238 int reason; 239 unsigned char ssid[WPA_VENDOR_SSID_LEN]; 240 unsigned char psk[WPA_VENDOR_PSK_LEN]; 241 unsigned char devAddr[ETH_ADDR_LEN]; 242 unsigned char data[WPA_VENDOR_DATA_LEN]; 243 }; 244 245 void WpaEventReport(const char *ifName, uint32_t event, void *data); 246 int32_t WpaRegisterEventCallback(OnReceiveFunc onRecFunc, uint32_t eventType, const char *ifName); 247 int32_t WpaUnregisterEventCallback(OnReceiveFunc onRecFunc, uint32_t eventType, const char *ifName); 248 void ReleaseEventCallback(void); 249 #endif 250