Home | History | Annotate | Download | only in default
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef WIFI_H_
     18 #define WIFI_H_
     19 
     20 #include <functional>
     21 
     22 #include <android-base/macros.h>
     23 #include <android/hardware/wifi/1.0/IWifi.h>
     24 #include <utils/Looper.h>
     25 
     26 #include "hidl_callback_util.h"
     27 #include "wifi_chip.h"
     28 #include "wifi_legacy_hal.h"
     29 #include "wifi_mode_controller.h"
     30 
     31 namespace android {
     32 namespace hardware {
     33 namespace wifi {
     34 namespace V1_0 {
     35 namespace implementation {
     36 
     37 /**
     38  * Root HIDL interface object used to control the Wifi HAL.
     39  */
     40 class Wifi : public IWifi {
     41  public:
     42   Wifi();
     43 
     44   bool isValid();
     45 
     46   // HIDL methods exposed.
     47   Return<void> registerEventCallback(
     48       const sp<IWifiEventCallback>& event_callback,
     49       registerEventCallback_cb hidl_status_cb) override;
     50   Return<bool> isStarted() override;
     51   Return<void> start(start_cb hidl_status_cb) override;
     52   Return<void> stop(stop_cb hidl_status_cb) override;
     53   Return<void> getChipIds(getChipIds_cb hidl_status_cb) override;
     54   Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override;
     55 
     56  private:
     57   enum class RunState { STOPPED, STARTED, STOPPING };
     58 
     59   // Corresponding worker functions for the HIDL methods.
     60   WifiStatus registerEventCallbackInternal(
     61       const sp<IWifiEventCallback>& event_callback);
     62   WifiStatus startInternal();
     63   WifiStatus stopInternal();
     64   std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal();
     65   std::pair<WifiStatus, sp<IWifiChip>> getChipInternal(ChipId chip_id);
     66 
     67   WifiStatus initializeLegacyHal();
     68   WifiStatus stopLegacyHalAndDeinitializeModeController();
     69 
     70   // Instance is created in this root level |IWifi| HIDL interface object
     71   // and shared with all the child HIDL interface objects.
     72   std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
     73   std::shared_ptr<mode_controller::WifiModeController> mode_controller_;
     74   RunState run_state_;
     75   sp<WifiChip> chip_;
     76   hidl_callback_util::HidlCallbackHandler<IWifiEventCallback> event_cb_handler_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(Wifi);
     79 };
     80 
     81 }  // namespace implementation
     82 }  // namespace V1_0
     83 }  // namespace wifi
     84 }  // namespace hardware
     85 }  // namespace android
     86 
     87 #endif  // WIFI_H_
     88