1 /*
2  * Copyright (C) 2021 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 #ifndef WIFI_WPA_SUPPLICANT_HAL_H
16 #define WIFI_WPA_SUPPLICANT_HAL_H
17 
18 #include <sys/types.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <malloc.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include "wifi_hal_struct.h"
25 #include "wifi_hal_define.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 #define KEY_MGMT_LENG 20
31 struct WpaHalCmdStatus {
32     char bssid[WIFI_BSSID_LENGTH];
33     int freq;
34     char ssid[WIFI_SSID_LENGTH];
35     int id;
36     char keyMgmt[KEY_MGMT_LENG];
37     char address[WIFI_BSSID_LENGTH];
38 };
39 
40 struct WpaSetNetworkArgv {
41     int id;          /* network id */
42     DeviceConfigType param; /* set network param */
43     char value[WIFI_NETWORK_CONFIG_VALUE_LENGTH];  /* set network value */
44 };
45 
46 typedef struct WpaSsidField {
47     DeviceConfigType field;
48     char fieldName[32];
49     int flag; /* 0 need add "" 1 no need */
50 } WpaSsidField;
51 
52 struct WpaGetNetworkArgv {
53     int id; /* network id. */
54     char param[WIFI_NETWORK_CONFIG_VALUE_LENGTH]; /* parameter */
55 };
56 
57 struct WpaWpsPbcArgv {
58     int anyFlag;
59     int multiAp;
60     char bssid[WIFI_BSSID_LENGTH];
61 };
62 
63 struct WpaWpsPinArgv {
64     char bssid[WIFI_BSSID_LENGTH];
65     char pinCode[WIFI_PIN_CODE_LENGTH + 1];
66 };
67 
68 struct NeedParseIe {
69     ScanInfoElem* ieExtern;
70     ScanInfoElem* ieVhtOper;
71     ScanInfoElem* ieHtOper;
72     ScanInfoElem* ieMaxRate;
73     ScanInfoElem* ieErp;
74     ScanInfoElem* ieExtMaxRate;
75 };
76 
77 typedef struct WifiWpaStaInterface WifiWpaStaInterface;
78 struct WifiWpaStaInterface {
79     int staNo;
80     char ifname[WIFI_IFACE_NAME_MAXLEN];
81     WifiWpaStaInterface *next;
82 
83     int (*wpaCliCmdStatus)(WifiWpaStaInterface *p, struct WpaHalCmdStatus *pcmd);
84     int (*wpaCliCmdAddNetworks)(WifiWpaStaInterface *p);
85     int (*wpaCliCmdReconnect)(WifiWpaStaInterface *p);
86     int (*wpaCliCmdReassociate)(WifiWpaStaInterface *p);
87     int (*wpaCliCmdDisconnect)(WifiWpaStaInterface *p);
88     int (*wpaCliCmdSaveConfig)(WifiWpaStaInterface *p);
89     int (*wpaCliCmdSetNetwork)(WifiWpaStaInterface *p, const struct WpaSetNetworkArgv *argv);
90     int (*wpaCliCmdEnableNetwork)(WifiWpaStaInterface *p, int networkId);
91     int (*wpaCliCmdSelectNetwork)(WifiWpaStaInterface *p, int networkId);
92     int (*wpaCliCmdDisableNetwork)(WifiWpaStaInterface *p, int networkId);
93     int (*wpaCliCmdRemoveNetwork)(WifiWpaStaInterface *p, int networkId);
94     int (*wpaCliCmdGetNetwork)(WifiWpaStaInterface *p, const struct WpaGetNetworkArgv *argv, char *pcmd, unsigned size);
95     int (*wpaCliCmdWpsPbc)(WifiWpaStaInterface *p, const struct WpaWpsPbcArgv *wpspbc);
96     int (*wpaCliCmdWpsPin)(WifiWpaStaInterface *p, const struct WpaWpsPinArgv *wpspin, int *pincode);
97     int (*wpaCliCmdWpsCancel)(WifiWpaStaInterface *p);
98     int (*wpaCliCmdPowerSave)(WifiWpaStaInterface *p, int enable);
99     int (*wpaCliCmdSetRoamConfig)(WifiWpaStaInterface *p, const char *bssid);
100     int (*wpaCliCmdSetCountryCode)(WifiWpaStaInterface *p, const char *countryCode);
101     int (*wpaCliCmdGetCountryCode)(WifiWpaStaInterface *p, char *countryCode, int codeSize);
102     int (*wpaCliCmdSetAutoConnect)(WifiWpaStaInterface *p, int enable);
103     int (*wpaCliCmdWpaBlockListClear)(WifiWpaStaInterface *p);
104     int (*wpaCliCmdListNetworks)(WifiWpaStaInterface *p, WifiNetworkInfo *pcmd, int *size);
105     int (*wpaCliCmdScan)(WifiWpaStaInterface *p, const ScanSettings *settings);
106     int (*wpaCliCmdScanInfo)(WifiWpaStaInterface *p, ScanInfo *pcmd, int *size);
107     int (*wpaCliCmdGetSignalInfo)(WifiWpaStaInterface *p, WpaSignalInfo *info);
108     int (*wpaCliCmdWpaSetSuspendMode)(WifiWpaStaInterface *p, bool mode);
109     int (*wpaCliCmdWpaSetPowerMode)(WifiWpaStaInterface *p, bool mode);
110 };
111 
112 /**
113  * @Description Get wpa interface about sta.
114  *
115  * @return WifiWpaStaInterface*.
116  */
117 WifiWpaStaInterface *GetWifiStaInterface(int staNo);
118 
119 /**
120  * @Description Release sta interface
121  *
122  */
123 void ReleaseWifiStaInterface(int staNo);
124 
125 WifiWpaStaInterface *TraversalWifiStaInterface(void);
126 int GetStaInterfaceNo(const char *ifName);
127 
128 int DelScanInfoLine(ScanInfo *pcmd, char *srcBuf, int length);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 #endif