platform_wifi.cc revision 3a34ff2bf5e4afd466abb2b9af26abf719ec34fd
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/platform/shared/pal_system_api.h"
22#include "chre/platform/log.h"
23
24namespace chre {
25
26PlatformWifi::PlatformWifi() {
27  mWifiApi = chrePalWifiGetApi(CHRE_PAL_WIFI_API_CURRENT_VERSION);
28  if (mWifiApi != nullptr) {
29    mWifiCallbacks.scanMonitorStatusChangeCallback =
30        PlatformWifi::scanMonitorStatusChangeCallback;
31    mWifiCallbacks.scanResponseCallback =
32        PlatformWifiBase::scanResponseCallback;
33    mWifiCallbacks.scanEventCallback =
34        PlatformWifiBase::scanEventCallback;
35    if (!mWifiApi->open(&gChrePalSystemApi, &mWifiCallbacks)) {
36      LOGE("WiFi PAL open returned false");
37      mWifiApi = nullptr;
38    }
39  } else {
40    LOGW("Requested Wifi PAL (version %08" PRIx32 ") not found",
41         CHRE_PAL_WIFI_API_CURRENT_VERSION);
42  }
43}
44
45PlatformWifi::~PlatformWifi() {
46  if (mWifiApi != nullptr) {
47    mWifiApi->close();
48  }
49}
50
51uint32_t PlatformWifi::getCapabilities() {
52  if (mWifiApi != nullptr) {
53    return mWifiApi->getCapabilities();
54  } else {
55    return CHRE_WIFI_CAPABILITIES_NONE;
56  }
57}
58
59bool PlatformWifi::configureScanMonitor(bool enable) {
60  if (mWifiApi != nullptr) {
61    return mWifiApi->configureScanMonitor(enable);
62  } else {
63    return false;
64  }
65}
66
67void PlatformWifiBase::scanMonitorStatusChangeCallback(bool enabled,
68                                                       uint8_t errorCode) {
69// TODO: Uncomment these two lines below. A build error prevents this due to a
70// cyclic dependency.
71//  EventLoopManagerSingleton::get()->getWifiRequestManager()
72//      .handleScanMonitorStateChange(enabled, errorCode);
73}
74
75void PlatformWifiBase::scanResponseCallback(bool pending, uint8_t errorCode) {
76  // TODO: Implement this.
77}
78
79void PlatformWifiBase::scanEventCallback(struct chreWifiScanEvent *event) {
80  // TODO: Implement this.
81}
82
83}  // namespace chre
84