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_HOSTAPD_HAL_H
16 #define WIFI_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 #include "wifi_hal_struct.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define BUFSIZE_CMD 256
30 #define FILE_NAME_SIZE 256
31 #define BUFSIZE_REQUEST 4096
32 #define BUFSIZE_REQUEST_SMALL 64
33 #define BUFSIZE_RECV 4096
34 #define PASSWD_MIN_LEN 8
35 #define FAIL_LENGTH 4
36 #define UNKNOWN_COMMAND_LENGTH 15
37 #define REQUEST_FAILED (-2)
38 #define BUFFER_SIZE_128 128
39 #define BUFFER_SIZE_64 64
40 #define BUFFER_SIZE_32 32
41 #define BUFFER_SIZE_16 16
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 /* Defines the HAL device structure. */
68 typedef struct StWifiHostapdHalDevice {
69     struct wpa_ctrl *ctrlConn;
70     struct wpa_ctrl *ctrlRecv;
71     pthread_t tid;
72     int threadRunFlag;
73     int execDisable;
74     int (*setApInfo)(HostapdConfig *info, int id);
75     int (*enableAp)(int id);
76     int (*disableAp)(int id);
77     int (*addBlocklist)(const char *mac, int id);
78     int (*delBlocklist)(const char *mac, int id);
79     int (*status)(StatusInfo *info, int id);
80     int (*showConnectedDevList)(char *info, int size, int id);
81     int (*reloadApConfigInfo)(int id);
82     int (*disConnectedDev)(const char *mac, int id);
83     int (*setCountryCode)(const char *code, int id);
84     int (*terminateAp)(int id);
85 } WifiHostapdHalDevice;
86 
87 typedef struct StWifiHostapdHalDeviceInfo {
88     int id;
89     WifiHostapdHalDevice *hostapdHalDev;
90     char *cfgName;
91     char *config;
92     char *udpPort;
93 } WifiHostapdHalDeviceInfo;
94 
95 WifiHostapdHalDeviceInfo *GetWifiCfg(int *len);
96 /**
97  * @Description Get the Wifi Hostapd Dev object.
98  *
99  * @return WifiHostapdHalDevice*
100  */
101 WifiHostapdHalDevice *GetWifiHostapdDev(int id);
102 
103 /**
104  * @Description Release the Wifi Hostapd Dev object.
105  *
106  */
107 void ReleaseHostapdDev(int id);
108 
109 /**
110  * @Description Hostpad string concatenation.
111  *
112  */
113 void GetDestPort(char *destPort, size_t len, int id);
114 
115 #ifdef __cplusplus
116 }
117 #endif
118 #endif /* WIFI_HOSTAPD_HAL_H */