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 
16 #ifndef WIFI_H
17 #define WIFI_H
18 
19 #include "v1_0/ichip_controller.h"
20 #include "v1_0/iconcrete_chip.h"
21 #include "v1_0/chip_types.h"
22 #include "iface_tool.h"
23 #include "wifi_vendor_hal_list.h"
24 #include "wifi_chip_modes.h"
25 #include "callback_handler.h"
26 #include "wifi_chip.h"
27 #include "remote_death_recipient.h"
28 #include "iface_util.h"
29 
30 namespace OHOS {
31 namespace HDI {
32 namespace Wlan {
33 namespace Chip {
34 namespace V1_0 {
35 class Wifi : public IChipController {
36 public:
37     Wifi();
38 
39     ~Wifi();
40 
41     bool IsValid();
42 
43     int32_t RegisterWifiEventCallback(const sptr<IChipControllerCallback>& eventCallback) override;
44 
45     int32_t IsInit(bool& inited) override;
46 
47     int32_t Init() override;
48 
49     int32_t Release() override;
50 
51     int32_t GetAvailableChips(std::vector<uint32_t>& chipIds) override;
52 
53     int32_t GetChipService(uint32_t chipId, sptr<IConcreteChip>& chip) override;
54 
55 private:
56     enum class RunState { STOPPED, STARTED, STOPPING };
57     ErrorCode InitializVendorHal();
58     ErrorCode StopVendorHal(std::unique_lock<std::recursive_mutex>* lock);
59     uint32_t GetChipIdFromWifiChip(sptr <WifiChip>& chip);
60     void OnRemoteDied(const wptr<IRemoteObject>& object);
61     int32_t AddWifiDeathRecipient(const sptr<IChipControllerCallback>& eventCallback);
62     int32_t RemoveWifiDeathRecipient(const sptr<IChipControllerCallback>& eventCallback);
63 
64     std::shared_ptr<IfaceTool> ifaceTool_;
65     std::shared_ptr<WifiVendorHalList> vendorHalList_;
66     std::vector<std::shared_ptr<WifiVendorHal>> vendorHals_;
67     RunState runState_;
68     std::vector<sptr<WifiChip>> chips_;
69     CallbackHandler<IChipControllerCallback> cbHandler_;
70     sptr<RemoteDeathRecipient> remoteDeathRecipient_ = nullptr;
71 };
72 }
73 }
74 }
75 }
76 }
77 #endif //WIFI_H_