• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 namespace chre {
26 
PlatformWifi()27 PlatformWifi::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 
~PlatformWifi()46 PlatformWifi::~PlatformWifi() {
47   if (mWifiApi != nullptr) {
48     mWifiApi->close();
49   }
50 }
51 
getCapabilities()52 uint32_t PlatformWifi::getCapabilities() {
53   if (mWifiApi != nullptr) {
54     return mWifiApi->getCapabilities();
55   } else {
56     return CHRE_WIFI_CAPABILITIES_NONE;
57   }
58 }
59 
configureScanMonitor(bool enable)60 bool PlatformWifi::configureScanMonitor(bool enable) {
61   if (mWifiApi != nullptr) {
62     return mWifiApi->configureScanMonitor(enable);
63   } else {
64     return false;
65   }
66 }
67 
requestScan(const struct chreWifiScanParams * params)68 bool PlatformWifi::requestScan(const struct chreWifiScanParams *params) {
69   if (mWifiApi != nullptr) {
70     return mWifiApi->requestScan(params);
71   } else {
72     return false;
73   }
74 }
75 
releaseScanEvent(struct chreWifiScanEvent * event)76 void PlatformWifi::releaseScanEvent(struct chreWifiScanEvent *event) {
77   if (mWifiApi != nullptr) {
78     mWifiApi->releaseScanEvent(event);
79   }
80 }
81 
scanMonitorStatusChangeCallback(bool enabled,uint8_t errorCode)82 void PlatformWifiBase::scanMonitorStatusChangeCallback(bool enabled,
83                                                        uint8_t errorCode) {
84   EventLoopManagerSingleton::get()->getWifiRequestManager()
85       .handleScanMonitorStateChange(enabled, errorCode);
86 }
87 
scanResponseCallback(bool pending,uint8_t errorCode)88 void PlatformWifiBase::scanResponseCallback(bool pending, uint8_t errorCode) {
89   EventLoopManagerSingleton::get()->getWifiRequestManager()
90       .handleScanResponse(pending, errorCode);
91 }
92 
scanEventCallback(struct chreWifiScanEvent * event)93 void PlatformWifiBase::scanEventCallback(struct chreWifiScanEvent *event) {
94   EventLoopManagerSingleton::get()->getWifiRequestManager()
95       .handleScanEvent(event);
96 }
97 
98 }  // namespace chre
99