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 <hdf_remote_service.h> 21 #include "utils/common.h" 22 #include "wpa_supplicant_hal.h" 23 #include "wpa_client.h" 24 #include "wpa_common_cmd_ext.h" 25 26 #define WIFI_SSID_LENGTH 132 27 #define WIFI_BSSID_LENGTH 18 28 #define KEY_MGMT_LENG 20 29 #define WIFI_NETWORK_FLAGS_LENGTH 64 30 #define WIFI_COUNTRY_CODE_MAXLEN 2 31 #define COLUMN_INDEX_ZERO 0 32 #define COLUMN_INDEX_ONE 1 33 #define COLUMN_INDEX_TWO 2 34 #define COUNTRY_CODE_LENGTH_MAX 2 35 #define CMD_SIZE 100 36 #define REPLY_SIZE 1024 37 /* get more than 100 p2p lists */ 38 #define P2P_LIST_REPLY_SIZE 7168 39 #define HDI_POS_TEN 10 40 #define HDI_POS_FOURTH 4 41 #define REPLY_SIZE_FACTOR_FIRST 4 42 #define REPLY_SIZE_FACTOR_SECOND 10 43 #define WPA_CMD_BUF_LEN 256 44 #define WPA_SUPPLICANT_NAME "wpa_supplicant" 45 #ifdef OHOS_EUPDATER 46 #define CONFIG_ROOR_DIR "/tmp/service/el1/public/wifi" 47 #else 48 #define CONFIG_ROOR_DIR "/data/service/el1/public/wifi" 49 #endif // OHOS_EUPDATER 50 #define START_CMD "wpa_supplicant -c"CONFIG_ROOR_DIR"/wpa_supplicant/wpa_supplicant.conf"\ 51 " -g@abstract:"CONFIG_ROOR_DIR"/sockets/wpa/wlan0" 52 #define WPA_SLEEP_TIME (100 * 1000) /* 100ms */ 53 #define MAX_WPA_MAIN_ARGC_NUM 20 54 #define MAX_WPA_MAIN_ARGV_LEN 128 55 #define WIFI_NETWORK_CONFIG_NAME_LENGTH 64 56 #define WIFI_NETWORK_CONFIG_VALUE_LENGTH 2048 57 #define CMD_LEN 6 58 59 int32_t WpaInterfaceAddNetwork(struct IWpaInterface *self, const char *ifName, int32_t *networkId); 60 int32_t WpaInterfaceRemoveNetwork(struct IWpaInterface *self, const char *ifName, int32_t networkId); 61 int32_t WpaInterfaceDisableNetwork(struct IWpaInterface *self, const char *ifName, const int32_t networkId); 62 int32_t WpaInterfaceSetNetwork(struct IWpaInterface *self, const char *ifName, const int32_t networkId, 63 const char *name, const char *value); 64 int32_t WpaInterfaceListNetworks(struct IWpaInterface *self, const char *ifName, 65 struct HdiWifiWpaNetworkInfo *networkInfo, uint32_t *networkInfoLen); 66 int32_t WpaInterfaceSelectNetwork(struct IWpaInterface *self, const char *ifName, 67 const int32_t networkId); 68 int32_t WpaInterfaceEnableNetwork(struct IWpaInterface *self, const char *ifName, 69 const int32_t networkId); 70 int32_t WpaInterfaceReconnect(struct IWpaInterface *self, const char *ifName); 71 int32_t WpaInterfaceDisconnect(struct IWpaInterface *self, const char *ifName); 72 int32_t WpaInterfaceSetPowerSave(struct IWpaInterface *self, const char *ifName, const int32_t enable); 73 int32_t WpaInterfaceAutoConnect(struct IWpaInterface *self, const char *ifName, const int32_t enable); 74 int32_t WpaInterfaceWifiStatus(struct IWpaInterface *self, const char *ifName, 75 struct HdiWpaCmdStatus *status); 76 int32_t WpaInterfaceSaveConfig(struct IWpaInterface *self, const char *ifName); 77 int32_t WpaInterfaceWpsPbcMode(struct IWpaInterface *self, const char *ifName, 78 const struct HdiWifiWpsParam *wpaParam); 79 int32_t WpaInterfaceWpsPinMode(struct IWpaInterface *self, const char *ifName, 80 const struct HdiWifiWpsParam *wpaParam, int *pinCode); 81 int32_t WpaInterfaceWpsCancel(struct IWpaInterface *self, const char *ifName); 82 int32_t WpaInterfaceGetCountryCode(struct IWpaInterface *self, const char *ifName, 83 char *countryCode, uint32_t countryCodeLen); 84 int32_t WpaInterfaceGetNetwork(struct IWpaInterface *self, const char *ifName, 85 const int32_t networkId, const char *param, char *value, uint32_t valueLen); 86 int32_t WpaInterfaceBlocklistClear(struct IWpaInterface *self, const char *ifName); 87 int32_t WpaInterfaceSetSuspendMode(struct IWpaInterface *self, const char *ifName, const int32_t mode); 88 int32_t WpaInterfaceRegisterEventCallback(struct IWpaInterface *self, struct IWpaCallback *cbFunc, 89 const char *ifName); 90 int32_t WpaInterfaceUnregisterEventCallback(struct IWpaInterface *self, struct IWpaCallback *cbFunc, 91 const char *ifName); 92 int32_t WpaInterfaceWifiConstruct(void); 93 int32_t WpaInterfaceWifiDestruct(void); 94 void WpaEventReport(const char *ifName, uint32_t event, void *data); 95 int32_t WpaInterfaceGetConnectionCapabilities(struct IWpaInterface *self, const char *ifName, 96 struct ConnectionCapabilities *connectionCap); 97 int32_t WpaInterfaceGetScanSsid(struct IWpaInterface *self, const char *ifName, int32_t *enable); 98 int32_t WpaInterfaceGetPskPassphrase(struct IWpaInterface *self, const char *ifName, char *psk, uint32_t pskLen); 99 int32_t WpaInterfaceGetPsk(struct IWpaInterface *self, const char *ifName, uint8_t *psk, uint32_t *pskLen); 100 int32_t WpaInterfaceGetWepKey(struct IWpaInterface *self, const char *ifName, int keyIdx, uint8_t *wepKey, 101 uint32_t *wepKeyLen); 102 int32_t WpaInterfaceGetWepTxKeyIdx(struct IWpaInterface *self, const char *ifName, int *keyIdx); 103 int32_t WpaInterfaceGetRequirePmf(struct IWpaInterface *self, const char *ifName, int *enable); 104 int32_t WpaInterfaceSetCountryCode(struct IWpaInterface *self, const char *ifName, const char *countryCode); 105 int32_t WpaInterfaceReassociate(struct IWpaInterface *self, const char *ifName); 106 int32_t WpaInterfaceStaShellCmd(struct IWpaInterface *self, const char *ifName, const char *cmd); 107 108 void HdfWpaDelRemoteObj(struct IWpaCallback *self); 109 void ClearHdfWpaRemoteObj(void); 110 int32_t FillData(uint8_t **dst, uint32_t *dstLen, uint8_t *src, uint32_t srcLen); 111 pthread_mutex_t *GetInterfaceLock(); 112 113 struct StWpaMainParam { 114 int argc; 115 char argv[MAX_WPA_MAIN_ARGC_NUM][MAX_WPA_MAIN_ARGV_LEN]; 116 }; 117 struct RemoteServiceDeathRecipient { 118 struct HdfDeathRecipient recipient; 119 }; 120 #endif 121