• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef WPA_COMMON_CMD_H
16 #define WPA_COMMON_CMD_H
17 
18 #include "../wpa_impl.h"
19 #include <pthread.h>
20 #include "utils/common.h"
21 
22 #define WIFI_SSID_LENGTH 132
23 #define WIFI_BSSID_LENGTH 18
24 #define KEY_MGMT_LENG 20
25 #define WIFI_NETWORK_FLAGS_LENGTH 64
26 #define WIFI_COUNTRY_CODE_MAXLEN 2
27 #define COLUMN_INDEX_ZERO 0
28 #define COLUMN_INDEX_ONE 1
29 #define COLUMN_INDEX_TWO 2
30 #define COUNTRY_CODE_LENGTH_MAX 2
31 #define CMD_SIZE 100
32 #define REPLY_SIZE 1024
33 #define HDI_POS_TEN 10
34 #define HDI_POS_FOURTH 4
35 #define REPLY_SIZE_FACTOR_FIRST 4
36 #define REPLY_SIZE_FACTOR_SECOND 10
37 #define WPA_CMD_BUF_LEN 256
38 #define WPA_SUPPLICANT_NAME "wpa_supplicant"
39 #ifdef OHOS_EUPDATER
40 #define CONFIG_ROOR_DIR "/tmp/service/el1/public/wifi"
41 #else
42 #define CONFIG_ROOR_DIR "/data/service/el1/public/wifi"
43 #endif // OHOS_EUPDATER
44 #define START_CMD "wpa_supplicant -c"CONFIG_ROOR_DIR"/wpa_supplicant/wpa_supplicant.conf"\
45     " -g@abstract:"CONFIG_ROOR_DIR"/sockets/wpa/wlan0"
46 #define WPA_SLEEP_TIME (100 * 1000) /* 100ms */
47 #define MAX_WPA_MAIN_ARGC_NUM 20
48 #define MAX_WPA_MAIN_ARGV_LEN 128
49 #define WIFI_NETWORK_CONFIG_NAME_LENGTH 64
50 #define WIFI_NETWORK_CONFIG_VALUE_LENGTH 256
51 #define CMD_LEN 6
52 
53 int32_t WpaInterfaceStart(struct IWpaInterface *self);
54 int32_t WpaInterfaceStop(struct IWpaInterface *self);
55 int32_t WpaInterfaceAddWpaIface(struct IWpaInterface *self, const char *ifName, const char *confName) ;
56 int32_t WpaInterfaceRemoveWpaIface(struct IWpaInterface *self, const char *ifName);
57 int32_t WpaInterfaceScan(struct IWpaInterface *self, const char *ifName);
58 int32_t WpaInterfaceScanResult(struct IWpaInterface *self, const char *ifName, unsigned char *resultBuf,
59     uint32_t *resultBufLen);
60 int32_t WpaInterfaceAddNetwork(struct IWpaInterface *self, const char *ifName, int32_t *networkId);
61 int32_t WpaInterfaceRemoveNetwork(struct IWpaInterface *self, const char *ifName, int32_t networkId);
62 int32_t WpaInterfaceDisableNetwork(struct IWpaInterface *self, const char *ifName, const int32_t networkId);
63 int32_t WpaInterfaceSetNetwork(struct IWpaInterface *self, const char *ifName, const int32_t networkId,
64     const char *name, const char *value);
65 int32_t WpaInterfaceListNetworks(struct IWpaInterface *self, const char *ifName,
66     struct HdiWifiWpaNetworkInfo *networkInfo, uint32_t *networkInfoLen);
67 int32_t WpaInterfaceSelectNetwork(struct IWpaInterface *self, const char *ifName,
68     const int32_t networkId);
69 int32_t WpaInterfaceEnableNetwork(struct IWpaInterface *self, const char *ifName,
70     const int32_t networkId);
71 int32_t WpaInterfaceReconnect(struct IWpaInterface *self, const char *ifName);
72 int32_t WpaInterfaceDisconnect(struct IWpaInterface *self, const char *ifName);
73 int32_t WpaInterfaceSetPowerSave(struct IWpaInterface *self, const char *ifName, const int32_t enable);
74 int32_t  WpaInterfaceAutoConnect(struct IWpaInterface *self, const char *ifName, const int32_t enable);
75 int32_t WpaInterfaceWifiStatus(struct IWpaInterface *self, const char *ifName,
76     struct HdiWpaCmdStatus *status);
77 int32_t WpaInterfaceSaveConfig(struct IWpaInterface *self, const char *ifName);
78 int32_t WpaInterfaceWpsPbcMode(struct IWpaInterface *self, const char *ifName,
79     const struct HdiWifiWpsParam *wpaParam);
80 int32_t WpaInterfaceWpsPinMode(struct IWpaInterface *self, const char *ifName,
81     const struct HdiWifiWpsParam *wpaParam, int *pinCode);
82 int32_t WpaInterfaceWpsCancel(struct IWpaInterface *self, const char *ifName);
83 int32_t WpaInterfaceGetCountryCode(struct IWpaInterface *self, const char *ifName,
84     char *countryCode, uint32_t countryCodeLen);
85 int32_t WpaInterfaceGetNetwork(struct IWpaInterface *self, const char *ifName,
86     const int32_t networkId, const char *param, char *value, uint32_t valueLen);
87 int32_t WpaInterfaceBlocklistClear(struct IWpaInterface *self, const char *ifName);
88 int32_t WpaInterfaceSetSuspendMode(struct IWpaInterface *self, const char *ifName, const int32_t mode);
89 int32_t WpaInterfaceRegisterEventCallback(struct IWpaInterface *self, struct IWpaCallback *cbFunc,
90     const char *ifName);
91 int32_t WpaInterfaceUnregisterEventCallback(struct IWpaInterface *self, struct IWpaCallback *cbFunc,
92     const char *ifName);
93 int32_t WpaInterfaceWifiConstruct(void);
94 int32_t WpaInterfaceWifiDestruct(void);
95 void WpaEventReport(const char *ifName, uint32_t event, void *data);
96 int32_t WpaInterfaceGetConnectionCapabilities(struct IWpaInterface *self, const char *ifName,
97     struct ConnectionCapabilities *connectionCap);
98 int32_t WpaInterfaceGetScanSsid(struct IWpaInterface *self, const char *ifName, int32_t *enable);
99 int32_t WpaInterfaceGetPskPassphrase(struct IWpaInterface *self, const char *ifName, char *psk, uint32_t pskLen);
100 int32_t WpaInterfaceGetPsk(struct IWpaInterface *self, const char *ifName, uint8_t *psk, uint32_t *pskLen);
101 int32_t WpaInterfaceGetWepKey(struct IWpaInterface *self, const char *ifName, int keyIdx, uint8_t *wepKey,
102     uint32_t *wepKeyLen);
103 int32_t WpaInterfaceGetWepTxKeyIdx(struct IWpaInterface *self, const char *ifName, int *keyIdx);
104 int32_t WpaInterfaceGetRequirePmf(struct IWpaInterface *self, const char *ifName, int *enable);
105 int32_t WpaInterfaceSetCountryCode(struct IWpaInterface *self, const char *ifName, const char *countryCode);
106 int32_t WpaInterfaceReassociate(struct IWpaInterface *self, const char *ifName);
107 int32_t WpaInterfaceStaShellCmd(struct IWpaInterface *self, const char *ifName, const char *cmd);
108 
109 void StrSafeCopy(char *dst, unsigned len, const char *src);
110 int32_t FillData(uint8_t **dst, uint32_t *dstLen, uint8_t *src, uint32_t srcLen);
111 const char *macToStr(const u8 *addr);
112 struct StWpaMainParam {
113     int argc;
114     char argv[MAX_WPA_MAIN_ARGC_NUM][MAX_WPA_MAIN_ARGV_LEN];
115 };
116 
117 typedef struct WifiNetworkInfo {
118     int id;
119     char ssid[WIFI_SSID_LENGTH];
120     char bssid[WIFI_BSSID_LENGTH];
121     char flags[WIFI_NETWORK_FLAGS_LENGTH];
122 } WifiNetworkInfo;
123 
124 typedef enum DeviceConfigType {
125     DEVICE_CONFIG_SSID = 0, /* Network Name. */
126     DEVICE_CONFIG_PSK = 1,  /* Password. */
127     /**
128      * Encryption Mode: WPA-PSK - wpa/wp2; NONE - password less network; WPA-EAP, SAE, wpa3.
129      */
130     DEVICE_CONFIG_KEYMGMT = 2,
131     DEVICE_CONFIG_PRIORITY = 3, /* WPA network priority */
132     /**
133      * Set this bit to 1 and deliver it when the hidden network is connected.
134      * In other cases, set this bit to 0 but do not deliver it.
135      */
136     DEVICE_CONFIG_SCAN_SSID = 4,
137     DEVICE_CONFIG_EAP = 5,             /* EPA Mode:/EAP/PEAP. */
138     DEVICE_CONFIG_IDENTITY = 6,        /* Account name. */
139     DEVICE_CONFIG_PASSWORD = 7,        /* Account password. */
140     DEVICE_CONFIG_BSSID = 8,           /* bssid. */
141     DEVICE_CONFIG_AUTH_ALGORITHMS = 9, /* auth algorithms */
142     DEVICE_CONFIG_WEP_KEY_IDX = 10,    /* wep key idx */
143     DEVICE_CONFIG_WEP_KEY_0 = 11,
144     DEVICE_CONFIG_WEP_KEY_1 = 12,
145     DEVICE_CONFIG_WEP_KEY_2 = 13,
146     DEVICE_CONFIG_WEP_KEY_3 = 14,
147     DEVICE_CONFIG_EAP_CLIENT_CERT = 15,
148     DEVICE_CONFIG_EAP_PRIVATE_KEY = 16,
149     DEVICE_CONFIG_EAP_PHASE2METHOD = 17,
150     DEVICE_CONFIG_IEEE80211W = 18,
151     DEVICE_CONFIG_ALLOW_PROTOCOLS = 19,
152     DEVICE_CONFIG_GROUP_CIPHERS = 20,
153     DEVICE_CONFIG_PAIRWISE_CIPHERS = 21,
154     DEVICE_CONFIG_SAE_PASSWD = 22,
155     /**
156      * Number of network configuration parameters, which is used as the last
157      * parameter.
158      */
159     DEVICE_CONFIG_END_POS,
160 } DeviceConfigType;
161 
162 typedef struct WpaSsidField {
163     DeviceConfigType field;
164     char fieldName[32];
165     int flag; /* 0 need add "" 1 no need */
166 } WpaSsidField;
167 
168 #endif
169