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
24extern "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
47typedef 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} WpaCallBackEventType;
78
79enum WpaClientType {
80    /* 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<8 | 1<<9 | 1<<10 ... | 1<<29 */
81    WIFI_WPA_TO_HAL_CLIENT = (1 << 29) - 1,
82    WIFI_WPA_CLIENT_BUTT
83};
84
85struct WpaDisconnectParam {
86    unsigned char bssid[WIFI_BSSID_LEN];
87    int  reasonCode;
88    int locallyGenerated;
89};
90
91struct WpaConnectParam {
92    unsigned char bssid[WIFI_BSSID_LEN];
93    int  networkId;
94};
95
96struct WpaBssidChangedParam {
97    unsigned char bssid[WIFI_BSSID_LEN];
98    unsigned char reason[WIFI_REASON_LENGTH];
99};
100
101struct WpaStateChangedParam {
102    int status;
103    unsigned char bssid[WIFI_BSSID_LEN];
104    int  networkId;
105    unsigned char ssid[WIFI_SSID_LENGTH];
106};
107
108struct WpaTempDisabledParam {
109    int  networkId;
110    unsigned char ssid[WIFI_SSID_LENGTH];
111    int authFailures;
112    int duration;
113    unsigned char reason[WIFI_REASON_LENGTH];
114};
115
116struct WpaAssociateRejectParam {
117    unsigned char bssid[WIFI_BSSID_LEN];
118    int statusCode;
119    int timeOut;
120};
121
122struct WpaAuthRejectParam {
123    unsigned char bssid[WIFI_BSSID_LEN];
124    unsigned short authType;
125    unsigned short authTransaction;
126    unsigned short statusCode;
127};
128
129struct WpaRecvScanResultParam {
130    unsigned int scanId;
131};
132
133struct P2pDeviceInfoParam {
134    unsigned char srcAddress[ETH_ADDR_LEN];
135    unsigned char p2pDeviceAddress[ETH_ADDR_LEN];
136    unsigned char primaryDeviceType[WIFI_P2P_DEVICE_TYPE_LENGTH];
137    unsigned char deviceName[WIFI_P2P_DEVICE_NAME_LENGTH];
138    int configMethods;
139    int deviceCapabilities;
140    int groupCapabilities;
141    unsigned char wfdDeviceInfo[WIFI_P2P_WFD_DEVICE_INFO_LENGTH];
142    unsigned int wfdLength;
143    unsigned char operSsid[WIFI_P2P_DEVICE_NAME_LENGTH];
144};
145
146struct P2pDeviceLostParam {
147    unsigned char p2pDeviceAddress[ETH_ADDR_LEN];
148    int  networkId;
149};
150
151struct P2pGoNegotiationRequestParam {
152    unsigned char srcAddress[ETH_ADDR_LEN];
153    int passwordId;
154};
155
156struct P2pGoNegotiationCompletedParam {
157    int status;
158};
159
160struct P2pInvitationReceivedParam {
161    int type; /* 0:Received, 1:Accepted */
162    int persistentNetworkId;
163    int operatingFrequency;
164    unsigned char srcAddress[ETH_ADDR_LEN];
165    unsigned char goDeviceAddress[ETH_ADDR_LEN];
166    unsigned char bssid[ETH_ADDR_LEN];
167};
168
169struct P2pInvitationResultParam {
170    int status;
171    unsigned char bssid[ETH_ADDR_LEN];
172};
173
174struct P2pGroupStartedParam {
175    int isGo;
176    int isPersistent;
177    int frequency;
178    unsigned char groupIfName[WIFI_P2P_GROUP_IFNAME_LENGTH];
179    unsigned char ssid[WIFI_SSID_LENGTH];
180    unsigned char psk[WIFI_P2P_PASSWORD_SIZE];
181    unsigned char passphrase[WIFI_P2P_PASSWORD_SIZE];
182    unsigned char goDeviceAddress[ETH_ADDR_LEN];
183    unsigned char goRandomDeviceAddress[ETH_ADDR_LEN];
184};
185
186struct P2pGroupRemovedParam {
187    int isGo;
188    unsigned char groupIfName[WIFI_P2P_GROUP_IFNAME_LENGTH];
189};
190
191struct P2pProvisionDiscoveryCompletedParam {
192    int isRequest;
193    int provDiscStatusCode;
194    int configMethods;
195    unsigned char p2pDeviceAddress[ETH_ADDR_LEN];
196    unsigned char generatedPin[WIFI_PIN_CODE_LENGTH];
197};
198
199struct P2pServDiscRespParam {
200    int updateIndicator;
201    unsigned char srcAddress[ETH_ADDR_LEN];
202    unsigned char tlvs[WIFI_P2P_TLVS_LENGTH];
203};
204
205struct P2pStaConnectStateParam {
206    int state;
207    unsigned char srcAddress[ETH_ADDR_LEN];
208    unsigned char p2pDeviceAddress[ETH_ADDR_LEN];
209};
210
211struct P2pServDiscReqInfoParam {
212    int freq;
213    int dialogToken;
214    int updateIndic;
215    unsigned char mac[ETH_ADDR_LEN];
216    unsigned char tlvs[WIFI_P2P_TLVS_LENGTH];
217};
218
219struct P2pIfaceCreatedParam {
220    int isGo;
221};
222
223typedef int32_t (*OnReceiveFunc)(uint32_t event, void *data, const char *ifName);
224
225struct WpaCallbackEvent {
226    uint32_t eventType; /* eventmap */
227    char ifName[IFNAMSIZ + 1];
228    OnReceiveFunc onRecFunc;
229};
230
231struct WpaVendorExtInfo {
232    int type;
233    int freq;
234    int width;
235    int id;
236    int status;
237    int reason;
238    unsigned char ssid[WPA_VENDOR_SSID_LEN];
239    unsigned char psk[WPA_VENDOR_PSK_LEN];
240    unsigned char devAddr[ETH_ADDR_LEN];
241    unsigned char data[WPA_VENDOR_DATA_LEN];
242};
243
244void WpaEventReport(const char *ifName, uint32_t event, void *data);
245int32_t WpaRegisterEventCallback(OnReceiveFunc onRecFunc, uint32_t eventType, const char *ifName);
246int32_t WpaUnregisterEventCallback(OnReceiveFunc onRecFunc, uint32_t eventType, const char *ifName);
247void ReleaseEventCallback(void);
248#endif
249