platform_wifi.cc revision d74b2f8991a8dfae2e24ccb0cc84264c48731d55
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 mWifiApi->close(); 49 } 50} 51 52uint32_t PlatformWifi::getCapabilities() { 53 if (mWifiApi != nullptr) { 54 return mWifiApi->getCapabilities(); 55 } else { 56 return CHRE_WIFI_CAPABILITIES_NONE; 57 } 58} 59 60bool PlatformWifi::configureScanMonitor(bool enable) { 61 if (mWifiApi != nullptr) { 62 return mWifiApi->configureScanMonitor(enable); 63 } else { 64 return false; 65 } 66} 67 68void PlatformWifiBase::scanMonitorStatusChangeCallback(bool enabled, 69 uint8_t errorCode) { 70 EventLoopManagerSingleton::get()->getWifiRequestManager() 71 .handleScanMonitorStateChange(enabled, errorCode); 72} 73 74void PlatformWifiBase::scanResponseCallback(bool pending, uint8_t errorCode) { 75 EventLoopManagerSingleton::get()->getWifiRequestManager() 76 .handleScanResponse(pending, errorCode); 77} 78 79void PlatformWifiBase::scanEventCallback(struct chreWifiScanEvent *event) { 80 EventLoopManagerSingleton::get()->getWifiRequestManager() 81 .handleScanEvent(event); 82} 83 84} // namespace chre 85