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