1 /** 2 * Copyright (C) 2020 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 <stdbool.h> 18 #include <stdint.h> 19 20 #include "chpp/common/wifi.h" 21 #include "chpp/macros.h" 22 #include "chpp/services/wifi.h" 23 #include "chre/pal/wifi.h" 24 25 static const struct chrePalSystemApi *gSystemApi; 26 static const struct chrePalWifiCallbacks *gCallbacks; 27 28 static bool wifiPalOpen(const struct chrePalSystemApi *systemApi, 29 const struct chrePalWifiCallbacks *callbacks) { 30 gSystemApi = systemApi; 31 gCallbacks = callbacks; 32 33 return true; 34 } 35 36 static void wifiPalClose(void) {} 37 38 static uint32_t wifiPalGetCapabilities(void) { 39 return CHRE_WIFI_CAPABILITIES_SCAN_MONITORING | 40 CHRE_WIFI_CAPABILITIES_ON_DEMAND_SCAN; 41 } 42 43 static bool wifiPalConfigureScanMonitor(bool enable) { 44 // TODO 45 UNUSED_VAR(enable); 46 return true; // If successful 47 } 48 49 static bool wifiPalRequestScan(const struct chreWifiScanParams *params) { 50 // TODO 51 UNUSED_VAR(params); 52 return true; // If successful 53 } 54 55 static void wifiPalReleaseScanEvent(struct chreWifiScanEvent *event) { 56 gSystemApi->memoryFree(CHPP_CONST_CAST_POINTER(event->results)); 57 gSystemApi->memoryFree(event); 58 } 59 60 static bool wifiPalRequestRanging(const struct chreWifiRangingParams *params) { 61 // TODO 62 UNUSED_VAR(params); 63 return true; // If successful 64 } 65 66 static void wifiPalReleaseRangingEvent(struct chreWifiRangingEvent *event) { 67 gSystemApi->memoryFree(CHPP_CONST_CAST_POINTER(event->scannedFreqList)); 68 gSystemApi->memoryFree(CHPP_CONST_CAST_POINTER(event->results)); 69 gSystemApi->memoryFree(event); 70 } 71 72 #ifdef CHPP_SERVICE_ENABLED_WIFI 73 const struct chrePalWifiApi *chrePalWifiGetApi(uint32_t requestedApiVersion) { 74 static const struct chrePalWifiApi api = { 75 .moduleVersion = CHPP_PAL_WIFI_API_VERSION, 76 .open = wifiPalOpen, 77 .close = wifiPalClose, 78 .getCapabilities = wifiPalGetCapabilities, 79 .configureScanMonitor = wifiPalConfigureScanMonitor, 80 .requestScan = wifiPalRequestScan, 81 .releaseScanEvent = wifiPalReleaseScanEvent, 82 .requestRanging = wifiPalRequestRanging, 83 .releaseRangingEvent = wifiPalReleaseRangingEvent, 84 }; 85 86 CHPP_STATIC_ASSERT( 87 CHRE_PAL_WIFI_API_CURRENT_VERSION == CHPP_PAL_WIFI_API_VERSION, 88 "A newer CHRE PAL API version is available. Please update."); 89 90 if (!CHRE_PAL_VERSIONS_ARE_COMPATIBLE(api.moduleVersion, 91 requestedApiVersion)) { 92 return NULL; 93 } else { 94 return &api; 95 } 96 } 97 #endif 98