platform_wifi.cc revision a2cff3d6f8402ea803e8532e66557f941dc5fe15
1/*
2 * Copyright (C) 2017 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#include "chre/platform/platform_wifi.h"
18
19#include <cinttypes>
20
21#include "chre/core/event_loop_manager.h"
22#include "chre/platform/shared/pal_system_api.h"
23#include "chre/platform/log.h"
24
25namespace chre {
26
27PlatformWifi::PlatformWifi() {
28  mWifiApi = chrePalWifiGetApi(CHRE_PAL_WIFI_API_CURRENT_VERSION);
29  if (mWifiApi != nullptr) {
30    mWifiCallbacks.scanMonitorStatusChangeCallback =
31        PlatformWifi::scanMonitorStatusChangeCallback;
32    mWifiCallbacks.scanResponseCallback =
33        PlatformWifiBase::scanResponseCallback;
34    mWifiCallbacks.scanEventCallback =
35        PlatformWifiBase::scanEventCallback;
36    if (!mWifiApi->open(&gChrePalSystemApi, &mWifiCallbacks)) {
37      LOGE("WiFi PAL open returned false");
38      mWifiApi = nullptr;
39    }
40  } else {
41    LOGW("Requested Wifi PAL (version %08" PRIx32 ") not found",
42         CHRE_PAL_WIFI_API_CURRENT_VERSION);
43  }
44}
45
46PlatformWifi::~PlatformWifi() {
47  if (mWifiApi != nullptr) {
48    LOGD("Platform WiFi closing");
49    mWifiApi->close();
50    LOGD("Platform WiFi closed");
51  }
52}
53
54uint32_t PlatformWifi::getCapabilities() {
55  if (mWifiApi != nullptr) {
56    return mWifiApi->getCapabilities();
57  } else {
58    return CHRE_WIFI_CAPABILITIES_NONE;
59  }
60}
61
62bool PlatformWifi::configureScanMonitor(bool enable) {
63  if (mWifiApi != nullptr) {
64    return mWifiApi->configureScanMonitor(enable);
65  } else {
66    return false;
67  }
68}
69
70bool PlatformWifi::requestScan(const struct chreWifiScanParams *params) {
71  if (mWifiApi != nullptr) {
72    return mWifiApi->requestScan(params);
73  } else {
74    return false;
75  }
76}
77
78void PlatformWifi::releaseScanEvent(struct chreWifiScanEvent *event) {
79  if (mWifiApi != nullptr) {
80    mWifiApi->releaseScanEvent(event);
81  }
82}
83
84void PlatformWifiBase::scanMonitorStatusChangeCallback(bool enabled,
85                                                       uint8_t errorCode) {
86  EventLoopManagerSingleton::get()->getWifiRequestManager()
87      .handleScanMonitorStateChange(enabled, errorCode);
88}
89
90void PlatformWifiBase::scanResponseCallback(bool pending, uint8_t errorCode) {
91  EventLoopManagerSingleton::get()->getWifiRequestManager()
92      .handleScanResponse(pending, errorCode);
93}
94
95void PlatformWifiBase::scanEventCallback(struct chreWifiScanEvent *event) {
96  EventLoopManagerSingleton::get()->getWifiRequestManager()
97      .handleScanEvent(event);
98}
99
100}  // namespace chre
101