1 /*
2  * Copyright (C) 2021-2022 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 
16 #ifndef OHOS_WIFI_AP_MSG_H
17 #define OHOS_WIFI_AP_MSG_H
18 #include <cstdint>
19 #include <set>
20 #include <string>
21 #include "wifi_common_msg.h"
22 
23 namespace OHOS {
24 namespace Wifi {
25 #define AP_CHANNEL_INVALID (-1)
26 #define AP_CHANNEL_DEFAULT 6
27 #define AP_CHANNEL_5G_DEFAULT 149
28 #define AP_CHANNEL_5G_NOT_RECOMMEND (165)  // cannot group bandwidth of 40M or above
29 #define WIFI_BSSID_LENGTH 18
30 #define DHCP_LEASE_TIME_MIN 60
31 #define DHCP_LEASE_TIME 21600
32 #define WIFI_SSID_MAX_LEN 32
33 #define WIFI_IP_MAX_LEN 15
34 #define AP_BANDWIDTH_DEFAULT 0
35 #define AP_BANDWIDTH_160 8
36 #define AP_CHANNEL_5G_160M_DEFAULT 36
37 #define AP_CHANNEL_5G_160M_SET_BEGIN 36
38 #define AP_CHANNEL_5G_160M_SET_END 48
39 
40 const std::string AP_DEFAULT_IP = "192.168.43.1";
41 
42 enum class ApState {
43     AP_STATE_NONE = 0,
44     AP_STATE_IDLE,
45     AP_STATE_STARTING,
46     AP_STATE_STARTED,
47     AP_STATE_CLOSING,
48     AP_STATE_CLOSED,
49 };
50 
51 /* Encryption Mode */
52 enum class KeyMgmt {
53     NONE = 0,
54     WPA_PSK = 1,
55     WPA_EAP = 2,
56     IEEE8021X = 3,
57     WPA2_PSK = 4,
58     OSEN = 5,
59     FT_PSK = 6,
60     FT_EAP = 7
61 };
62 
63 enum class BandType {
64     BAND_NONE = 0, /* unknown */
65     BAND_2GHZ = 1, /* 2.4GHz */
66     BAND_5GHZ = 2, /* 5GHz */
67     BAND_6GHZ = 3, /* 6GHz */
68     BAND_60GHZ = 4, /* 60GHz */
69     BAND_ANY = 5, /* Dual-mode frequency band */
70 };
71 
72 enum class PowerModel {
73     SLEEPING = 0, /* Sleeping model. */
74     GENERAL = 1, /* General model. */
75     THROUGH_WALL = 2, /* Through wall model. */
76 };
77 
78 struct HotspotConfig {
HotspotConfigHotspotConfig79     HotspotConfig()
80     {
81         securityType = KeyMgmt::WPA2_PSK;
82         band = BandType::BAND_2GHZ;
83         channel = AP_CHANNEL_DEFAULT;
84         maxConn = -1;
85         leaseTime = DHCP_LEASE_TIME;
86         apBandWidth = AP_BANDWIDTH_DEFAULT;
87     }
88 
SetSsidHotspotConfig89     inline void SetSsid(const std::string &newSsid)
90     {
91         ssid = newSsid;
92     }
GetSsidHotspotConfig93     inline const std::string &GetSsid() const
94     {
95         return ssid;
96     }
97 
SetPreSharedKeyHotspotConfig98     inline void SetPreSharedKey(const std::string &newKey)
99     {
100         preSharedKey = newKey;
101     }
GetPreSharedKeyHotspotConfig102     inline const std::string &GetPreSharedKey() const
103     {
104         return preSharedKey;
105     }
106 
SetSecurityTypeHotspotConfig107     inline void SetSecurityType(KeyMgmt type)
108     {
109         securityType = type;
110     }
GetSecurityTypeHotspotConfig111     inline KeyMgmt GetSecurityType() const
112     {
113         return securityType;
114     }
115 
SetBandHotspotConfig116     inline void SetBand(BandType newBand)
117     {
118         band = newBand;
119     }
GetBandHotspotConfig120     inline BandType GetBand() const
121     {
122         return band;
123     }
SetBandWidthHotspotConfig124     inline void SetBandWidth(int32_t BandWidth)
125     {
126         apBandWidth = BandWidth;
127     }
GetBandWidthHotspotConfig128     inline int32_t GetBandWidth() const
129     {
130         return apBandWidth;
131     }
132 
SetChannelHotspotConfig133     inline void SetChannel(int32_t newchannel)
134     {
135         channel = newchannel;
136     }
GetChannelHotspotConfig137     inline int32_t GetChannel() const
138     {
139         return channel;
140     }
141 
SetMaxConnHotspotConfig142     inline void SetMaxConn(int32_t newMaxConn)
143     {
144         maxConn = newMaxConn;
145     }
GetMaxConnHotspotConfig146     inline int32_t GetMaxConn() const
147     {
148         return maxConn;
149     }
150 
SetIpAddressHotspotConfig151     inline void SetIpAddress(const std::string &newIpAddress)
152     {
153         ipAddress = newIpAddress;
154     }
155 
GetIpAddressHotspotConfig156     inline const std::string &GetIpAddress() const
157     {
158         return ipAddress;
159     }
160 
SetLeaseTimeHotspotConfig161     inline void SetLeaseTime(int32_t newLeaseTime)
162     {
163         leaseTime = newLeaseTime;
164     }
165 
GetLeaseTimeHotspotConfig166     inline int32_t GetLeaseTime() const
167     {
168         return leaseTime;
169     }
170 private:
171     std::string ssid;         /* Hotspot name, The string length range is 1~32 */
172     std::string preSharedKey; /* Hotspot password ,The string length range is 8~63 */
173     KeyMgmt securityType;     /* Hotspot Encryption type, Optional NONE/WPA_PSK/WPA2_PSK */
174     BandType band;
175     int32_t channel;
176     int32_t maxConn;
177     std::string ipAddress;    /* Hotspot IP address of the dhcp server */
178     int32_t leaseTime;
179     int32_t apBandWidth;
180 };
181 
182 struct StationInfo {
183     std::string deviceName; /* Device name */
184     std::string bssid;      /* Device Mac */
185     int bssidType; /* bssid type */
186     std::string ipAddr;     /* Device IP address */
187 };
188 
189 struct HotspotMacConfig {
SetCallingBundleNameHotspotMacConfig190     inline void SetCallingBundleName(std::string &bundleName)
191     {
192         callingBundleName = bundleName;
193     }
194 
GetCallingBundleNameHotspotMacConfig195     inline std::string GetCallingBundleName() const
196     {
197         return callingBundleName;
198     }
199 
SetRandomMacHotspotMacConfig200     inline void SetRandomMac(std::string &mac)
201     {
202         randomMac = mac;
203     }
204 
GetRandomMacHotspotMacConfig205     inline std::string GetRandomMac() const
206     {
207         return randomMac;
208     }
209 
210 private:
211     std::string callingBundleName;
212     std::string randomMac;
213 };
214 
215 }  // namespace Wifi
216 }  // namespace OHOS
217 #endif