• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_AP_SERVICE_H
16 #define OHOS_AP_SERVICE_H
17 
18 #include "ap_define.h"
19 #include "wifi_internal_msg.h"
20 #include "i_ap_service.h"
21 #include "i_ap_service_callbacks.h"
22 #include "i_wifi_country_code_change_listener.h"
23 
24 namespace OHOS {
25 namespace Wifi {
26 class ApStateMachine;
27 class ApService {
28     FRIEND_GTEST(ApService);
29 
30 public:
31     /**
32      * @Description  construction method.
33      * @param None
34      * @return None
35      */
36     explicit ApService(ApStateMachine &apStateMachine, int id = 0);
37 
38     /**
39      * @Description  destructor method.
40      * @param None
41      * @return None
42      */
43     ~ApService();
44     DISALLOW_COPY_AND_ASSIGN(ApService)
45 
46     /**
47      * @Description  open hotspot.
48      * @param None
49      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
50      */
51     ErrCode EnableHotspot();
52 
53     /**
54      * @Description  close hotspot.
55      * @param None
56      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
57      */
58     ErrCode DisableHotspot() const;
59 
60     /**
61      * @Description  set ap config.
62      * @param cfg - ap config
63      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
64      */
65     ErrCode SetHotspotConfig(const HotspotConfig &cfg) const;
66 
67     /**
68      * @Description Set the idel timeout of Hotspot
69      *
70      * @param time -input time,
71      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
72      */
73     ErrCode SetHotspotIdleTimeout(int time) const;
74 
75     /**
76      * @Description  add block list
77      * @param stationInfo - sta infos
78      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
79      */
80     ErrCode AddBlockList(const StationInfo &stationInfo) const;
81 
82     /**
83      * @Description  delete block list.
84      * @param stationInfo - sta infos
85      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
86      */
87     ErrCode DelBlockList(const StationInfo &stationInfo) const;
88 
89     /**
90      * @Description  Disconnect a specified STA.
91      * @param stationInfo - sta infos
92      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
93      */
94     ErrCode DisconnetStation(const StationInfo &stationInfo) const;
95 
96     /**
97      * @Description Get the Station List object.
98      *
99      * @param result - current connected station info
100      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
101      */
102     ErrCode GetStationList(std::vector<StationInfo> &result) const;
103 
104     /**
105      * @Description Get valid bands.
106      *
107      * @param bands - return valid bands
108      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
109      */
110     ErrCode GetValidBands(std::vector<BandType> &bands);
111 
112     /**
113      * @Description Get valid channels.
114      *
115      * @param band - input band
116      * @param validchannel - band's valid channel
117      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
118      */
119     ErrCode GetValidChannels(BandType band, std::vector<int32_t> &validChannel);
120 
121     /**
122      * @Description Sets the callback function for the state machine.
123      *
124      * @param callbacks - callbacks list.
125      * @return ErrCode - success: WIFI_OPT_SUCCESS    failed: ERROR_CODE
126      */
127     ErrCode RegisterApServiceCallbacks(const IApServiceCallbacks &callbacks);
128 
129     /**
130      * @Description Get supported power model list
131      *
132      * @param setPowerModelList - supported power model list
133      * @return ErrCode - operation result
134      */
135     ErrCode GetSupportedPowerModel(std::set<PowerModel>& setPowerModelList);
136 
137     /**
138      * @Description Get power model
139      *
140      * @param model - current power model
141      * @return ErrCode - operation result
142      */
143     ErrCode GetPowerModel(PowerModel& model);
144 
145     /**
146      * @Description Get supported power model list
147      *
148      * @param model - the model to be set
149      * @return ErrCode - operation result
150      */
151     ErrCode SetPowerModel(const PowerModel& model);
152 
153 private:
154     class WifiCountryCodeChangeObserver : public IWifiCountryCodeChangeListener {
155     public:
WifiCountryCodeChangeObserver(const std::string & name,StateMachine & stateMachineObj)156         WifiCountryCodeChangeObserver(const std::string &name, StateMachine &stateMachineObj)
157             : IWifiCountryCodeChangeListener(name, stateMachineObj) {}
158         ~WifiCountryCodeChangeObserver() override = default;
159         ErrCode OnWifiCountryCodeChanged(const std::string &wifiCountryCode) override;
160         std::string GetListenerModuleName() override;
161     };
162     ApStateMachine &m_ApStateMachine;
163     int m_id;
164     std::shared_ptr<IWifiCountryCodeChangeListener> m_apObserver;
165 };
166 }  // namespace Wifi
167 }  // namespace OHOS
168 
169 #endif