• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MAX_CONN_DEFAULT (-1)
28 #define AP_CHANNEL_5G_DEFAULT 149
29 #define AP_CHANNEL_5G_NOT_RECOMMEND (165)  // cannot group bandwidth of 40M or above
30 #define WIFI_BSSID_LENGTH 18
31 #define DHCP_LEASE_TIME_MIN 60
32 #define DHCP_LEASE_TIME 21600
33 #define WIFI_SSID_MAX_LEN 32
34 #define WIFI_IP_MAX_LEN 15
35 #define AP_BANDWIDTH_DEFAULT 0
36 #define AP_BANDWIDTH_160 8
37 #define AP_CHANNEL_5G_160M_DEFAULT 36
38 #define AP_CHANNEL_5G_160M_SET_BEGIN 36
39 #define AP_CHANNEL_5G_160M_SET_END 48
40 
41 const std::string AP_DEFAULT_IP = "192.168.43.1";
42 
43 enum class ApState {
44     AP_STATE_NONE = 0,
45     AP_STATE_IDLE,
46     AP_STATE_STARTING,
47     AP_STATE_STARTED,
48     AP_STATE_CLOSING,
49     AP_STATE_CLOSED,
50 };
51 
52 /* Encryption Mode */
53 enum class KeyMgmt {
54     NONE = 0,
55     WPA_PSK = 1,
56     WPA_EAP = 2,
57     IEEE8021X = 3,
58     WPA2_PSK = 4,
59     OSEN = 5,
60     FT_PSK = 6,
61     FT_EAP = 7
62 };
63 
64 enum class BandType {
65     BAND_NONE = 0, /* unknown */
66     BAND_2GHZ = 1, /* 2.4GHz */
67     BAND_5GHZ = 2, /* 5GHz */
68     BAND_6GHZ = 3, /* 6GHz */
69     BAND_60GHZ = 4, /* 60GHz */
70     BAND_ANY = 5, /* Dual-mode frequency band */
71 };
72 
73 enum class PowerModel {
74     SLEEPING = 0, /* Sleeping model. */
75     GENERAL = 1, /* General model. */
76     THROUGH_WALL = 2, /* Through wall model. */
77 };
78 
79 struct HotspotConfig {
HotspotConfigHotspotConfig80     HotspotConfig()
81     {
82         securityType = KeyMgmt::WPA2_PSK;
83         band = BandType::BAND_2GHZ;
84         channel = AP_CHANNEL_DEFAULT;
85         maxConn = AP_MAX_CONN_DEFAULT;
86         leaseTime = DHCP_LEASE_TIME;
87         apBandWidth = AP_BANDWIDTH_DEFAULT;
88         randomMac = "";
89     }
90 
SetSsidHotspotConfig91     inline void SetSsid(const std::string &newSsid)
92     {
93         ssid = newSsid;
94     }
GetSsidHotspotConfig95     inline const std::string &GetSsid() const
96     {
97         return ssid;
98     }
99 
SetPreSharedKeyHotspotConfig100     inline void SetPreSharedKey(const std::string &newKey)
101     {
102         preSharedKey = newKey;
103     }
GetPreSharedKeyHotspotConfig104     inline const std::string &GetPreSharedKey() const
105     {
106         return preSharedKey;
107     }
108 
SetSecurityTypeHotspotConfig109     inline void SetSecurityType(KeyMgmt type)
110     {
111         securityType = type;
112     }
GetSecurityTypeHotspotConfig113     inline KeyMgmt GetSecurityType() const
114     {
115         return securityType;
116     }
117 
SetBandHotspotConfig118     inline void SetBand(BandType newBand)
119     {
120         band = newBand;
121     }
GetBandHotspotConfig122     inline BandType GetBand() const
123     {
124         return band;
125     }
126 
SetBandWidthHotspotConfig127     inline void SetBandWidth(int32_t BandWidth)
128     {
129         apBandWidth = BandWidth;
130     }
GetBandWidthHotspotConfig131     inline int32_t GetBandWidth() const
132     {
133         return apBandWidth;
134     }
135 
SetChannelHotspotConfig136     inline void SetChannel(int32_t newchannel)
137     {
138         channel = newchannel;
139     }
GetChannelHotspotConfig140     inline int32_t GetChannel() const
141     {
142         return channel;
143     }
144 
SetMaxConnHotspotConfig145     inline void SetMaxConn(int32_t newMaxConn)
146     {
147         maxConn = newMaxConn;
148     }
GetMaxConnHotspotConfig149     inline int32_t GetMaxConn() const
150     {
151         return maxConn;
152     }
153 
SetIpAddressHotspotConfig154     inline void SetIpAddress(const std::string &newIpAddress)
155     {
156         ipAddress = newIpAddress;
157     }
158 
GetIpAddressHotspotConfig159     inline const std::string &GetIpAddress() const
160     {
161         return ipAddress;
162     }
163 
SetLeaseTimeHotspotConfig164     inline void SetLeaseTime(int32_t newLeaseTime)
165     {
166         leaseTime = newLeaseTime;
167     }
168 
GetLeaseTimeHotspotConfig169     inline int32_t GetLeaseTime() const
170     {
171         return leaseTime;
172     }
173 
SetRandomMacHotspotConfig174     inline void SetRandomMac(const std::string &newRandomMac)
175     {
176         randomMac = newRandomMac;
177     }
178 
GetRandomMacHotspotConfig179     inline const std::string &GetRandomMac() const
180     {
181         return randomMac;
182     }
183 private:
184     std::string ssid;         /* Hotspot name, The string length range is 1~32 */
185     std::string preSharedKey; /* Hotspot password ,The string length range is 8~63 */
186     KeyMgmt securityType;     /* Hotspot Encryption type, Optional NONE/WPA_PSK/WPA2_PSK */
187     BandType band;
188     int32_t channel;
189     int32_t maxConn;
190     std::string ipAddress;    /* Hotspot IP address of the dhcp server */
191     int32_t leaseTime;
192     int32_t apBandWidth;
193     std::string randomMac;
194 };
195 
196 struct StationInfo {
197     std::string deviceName; /* Device name */
198     std::string bssid;      /* Device Mac */
199     int bssidType{0}; /* bssid type */
200     std::string ipAddr;     /* Device IP address */
201 };
202 
203 enum class HotspotMode {
204     NONE = 0,
205     SOFTAP,
206     RPT,
207     LOCAL_ONLY_SOFTAP,
208 };
209 }  // namespace Wifi
210 }  // namespace OHOS
211 #endif