1 /* 2 * Copyright (C) 2024 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 HDI_HOSTAPD_HAL_H 16 #define HDI_HOSTAPD_HAL_H 17 18 #include <dirent.h> 19 #include <pthread.h> 20 #include <stdbool.h> 21 #include <string.h> 22 #include <sys/types.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define BUFSIZE_CMD 256 29 #define FILE_NAME_SIZE 256 30 #define BUFSIZE_REQUEST 4096 31 #define BUFSIZE_REQUEST_SMALL 64 32 #define BUFSIZE_RECV 4096 33 #define PASSWD_MIN_LEN 8 34 #define FAIL_LENGTH 4 35 #define UNKNOWN_COMMAND_LENGTH 15 36 #define REQUEST_FAILED (-2) 37 #define BUFFER_SIZE_128 128 38 #define BUFFER_SIZE_64 64 39 #define BUFFER_SIZE_32 32 40 #define BUFFER_SIZE_16 16 41 #define AP_NUM 1 42 43 #if (AP_NUM > 1) 44 typedef enum EnApInstance { 45 AP_5G_MAIN_INSTANCE, 46 AP_2G_MAIN_INSTANCE, 47 AP_MAX_INSTANCE 48 } ApInstance; 49 #else 50 typedef enum EnApInstance { 51 AP_2G_MAIN_INSTANCE, 52 AP_MAX_INSTANCE 53 } ApInstance; 54 #endif 55 56 typedef struct StStatusInfo { 57 char state[BUFFER_SIZE_16]; 58 char phy[BUFFER_SIZE_16]; 59 int freq; 60 int channel; 61 char supportedRates[BUFFER_SIZE_64]; 62 char bss[BUFFER_SIZE_16]; 63 char bssid[BUFFER_SIZE_32]; 64 char ssid[BUFFER_SIZE_32]; 65 } StatusInfo; 66 67 /* AP Band */ 68 typedef enum ApBand { 69 AP_NONE_BAND = 0, /* Unknown Band */ 70 AP_2GHZ_BAND = 1, /* 2.4GHz Band */ 71 AP_5GHZ_BAND = 2, /* 5GHz Band */ 72 AP_ANY_BAND = 3, /* Dual-mode frequency band */ 73 AP_DFS_BAND = 4 /* Dynamic Frequency Selection band */ 74 } ApBand; 75 76 /* Encryption Mode */ 77 typedef enum KeyMgmt { 78 NONE = 0, /* WPA not used. */ 79 WPA_PSK = 1, /* WPA pre-shared key ({@ preSharedKey} needs to be specified.) */ 80 /** 81 * WPA with EAP authentication. It is usually used with an external 82 * authentication server. 83 */ 84 WPA_EAP = 2, 85 /** 86 * IEEE 802.1X with EAP authentication and optionally dynamically generated 87 * WEP keys. 88 */ 89 IEEE8021X = 3, 90 /** 91 * WPA2 pre-shared key, which is used for soft APs({@ preSharedKey} needs to 92 * be specified). 93 */ 94 WPA2_PSK = 4, 95 OSEN = 5, /* Hotspot 2.0 Rel 2 online signup connection. */ 96 FT_PSK = 6, /* Fast BSS Transition (IEEE 802.11r) with pre-shared key. */ 97 FT_EAP = 7 /* Fast BSS Transition (IEEE 802.11r) with EAP authentication. */ 98 } KeyMgmt; 99 100 /* Defines the HAL device structure. */ 101 typedef struct StWifiHostapdHalDevice { 102 struct wpa_ctrl *ctrlConn; 103 struct wpa_ctrl *ctrlRecv; 104 int execDisable; 105 int (*stopAp)(int id); 106 int (*enableAp)(int id); 107 int (*disableAp)(int id); 108 int (*addBlocklist)(const char *mac, int id); 109 int (*delBlocklist)(const char *mac, int id); 110 int (*status)(StatusInfo *info, int id); 111 int (*showConnectedDevList)(char *info, int size, int id); 112 int (*reloadApConfigInfo)(int id); 113 int (*disConnectedDev)(const char *mac, int id); 114 int (*setCountryCode)(const char *code, int id); 115 int (*setApName)(const char *name, int id); 116 int (*setApRsnPairwise)(const char *type, int id); 117 int (*setApWpaPairwise)(const char *type, int id); 118 int (*setApWpaKeyMgmt)(const char *type, int id); 119 int (*setApWpaValue)(int securityType, int id); 120 int (*setApPasswd)(const char *pass, int id); 121 int (*setApChannel)(int channel, int id); 122 int (*setApWmm)(int value, int id); 123 int (*setAp80211n)(int value, int id); 124 int (*setApBand)(int band, int id); 125 int (*setApMaxConnHw)(int maxConn, int channel); 126 int (*setApMaxConn)(int maxConn, int id); 127 } WifiHostapdHalDevice; 128 129 typedef struct StWifiHostapdHalDeviceInfo { 130 int id; 131 WifiHostapdHalDevice *hostapdHalDev; 132 char *cfgName; 133 char *config; 134 char *udpPort; 135 } WifiHostapdHalDeviceInfo; 136 137 const WifiHostapdHalDeviceInfo *GetWifiCfg(int *len); 138 WifiHostapdHalDevice *GetWifiHostapdDev(int id); 139 void ReleaseHostapdDev(int id); 140 void GetDestPort(char *destPort, size_t len, int id); 141 int InitCfg(const char *ifaceName); 142 int GetIfaceState(const char *ifaceName); 143 #ifdef __cplusplus 144 } 145 #endif 146 #endif /* HDI_HOSTAPD_HAL_H */ 147