13b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao/* 23b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * Copyright (C) 2016 The Android Open Source Project 33b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * 43b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * Licensed under the Apache License, Version 2.0 (the "License"); 53b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * you may not use this file except in compliance with the License. 63b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * You may obtain a copy of the License at 73b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * 83b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * http://www.apache.org/licenses/LICENSE-2.0 93b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * 103b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * Unless required by applicable law or agreed to in writing, software 113b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * distributed under the License is distributed on an "AS IS" BASIS, 123b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * See the License for the specific language governing permissions and 143b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao * limitations under the License. 153b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao */ 163b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao#ifndef WIFICOND_OFFLOAD_SCAN_MANAGER_H_ 173b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao#define WIFICOND_OFFLOAD_SCAN_MANAGER_H_ 183b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 193b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao#include <android/hardware/wifi/offload/1.0/IOffload.h> 203b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao#include "wificond/scanning/offload/offload_callback.h" 2126e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao#include "wificond/scanning/offload/offload_callback_handlers.h" 2269f61f7fd15d44dd32a107d850f05f0eb933ab2cSohani Rao#include "wificond/scanning/offload_scan_callback_interface_impl.h" 233b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 243b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao#include <vector> 253b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 263b558d191c4237e137429ffeeaf686e34e5da98bSohani Raonamespace com { 273b558d191c4237e137429ffeeaf686e34e5da98bSohani Raonamespace android { 283b558d191c4237e137429ffeeaf686e34e5da98bSohani Raonamespace server { 293b558d191c4237e137429ffeeaf686e34e5da98bSohani Raonamespace wifi { 303b558d191c4237e137429ffeeaf686e34e5da98bSohani Raonamespace wificond { 313b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 323b558d191c4237e137429ffeeaf686e34e5da98bSohani Raoclass NativeScanResult; 33f33517d79737dd96e5d86ed45ab095be3a4c4773Sohani Raoclass NativeScanStats; 343b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 353b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao} // namespace wificond 363b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao} // namespace wifi 373b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao} // namespace server 383b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao} // namespace android 393b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao} // namespace com 403b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 413b558d191c4237e137429ffeeaf686e34e5da98bSohani Raonamespace android { 423b558d191c4237e137429ffeeaf686e34e5da98bSohani Raonamespace wificond { 433b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 4426e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Raoclass OffloadScanManager; 4569f61f7fd15d44dd32a107d850f05f0eb933ab2cSohani Raoclass OffloadDeathRecipient; 4669f61f7fd15d44dd32a107d850f05f0eb933ab2cSohani Raoclass OffloadServiceUtils; 4726e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao 4826e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao// Provides callback interface implementation from Offload HAL 4926e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Raoclass OffloadCallbackHandlersImpl : public OffloadCallbackHandlers { 5026e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao public: 5126e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao OffloadCallbackHandlersImpl(OffloadScanManager* parent); 5226e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao ~OffloadCallbackHandlersImpl() override; 5326e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao 5416b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao void OnScanResultHandler( 5516b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>& 5616b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao scanResult) override; 5716b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao void OnErrorHandler( 58e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao const android::hardware::wifi::offload::V1_0::OffloadStatus& status) 59e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao override; 6026e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao 6126e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao private: 6226e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao OffloadScanManager* offload_scan_manager_; 6326e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao}; 6426e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao 653b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao// Provides methods to interact with Offload HAL 663b558d191c4237e137429ffeeaf686e34e5da98bSohani Raoclass OffloadScanManager { 673b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao public: 6826e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao enum StatusCode { 69e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao /* Corresponds to OffloadStatusCode::OK */ 7016b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao kNoError, 7116b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao /* Offload HAL service not avaialble */ 7216b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao kNoService, 73e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao /* Corresponds to OffloadStatusCode::NO_CONNECTION */ 7416b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao kNotConnected, 75e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao /* Corresponds to OffloadStatusCode::TIMEOUT */ 7616b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao kTimeOut, 77e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao /* Corresponds to OffloadStatusCode::ERROR */ 7816b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao kError 7926e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao }; 8026e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao 812a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao enum ReasonCode { 8216b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao /* Default value */ 8316b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao kNone, 84e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao /* Offload HAL scans is not available */ 8516b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao kNotAvailable, 86e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao /* Offload HAL requested operation failure */ 87e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao kOperationFailed, 88e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao /* Binder failed to deliver message to Offload HAL*/ 89e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao kTransactionFailed, 902a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao }; 912a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao 92e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao explicit OffloadScanManager( 93e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao std::weak_ptr<OffloadServiceUtils> utils, 94e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao std::shared_ptr<OffloadScanCallbackInterface> callback); 953b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao virtual ~OffloadScanManager(); 962a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao /* Request start of offload scans with scan parameters and scan filter 972a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao * settings. Internally calls Offload HAL service with configureScans() 98e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao * and subscribeScanResults() APIs. Reason code indicates failure reason. 992a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao */ 1008f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao virtual bool startScan( 1018f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao uint32_t /* interval_ms */, int32_t /* rssi_threshold */, 1028f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao const std::vector<std::vector<uint8_t>>& /* scan_ssids */, 1038f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao const std::vector<std::vector<uint8_t>>& /* match_ssids */, 1048f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao const std::vector<uint8_t>& /* match_security */, 1058f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao const std::vector<uint32_t>& /* freqs */, 1068f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao ReasonCode* /* failure reason */); 107e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao /* Request stop of offload scans, returns true if the operation succeeds 108e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao * Otherwise, returns false. Reason code is updated in case of failure. 1092a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao */ 1108f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao virtual bool stopScan(ReasonCode* /* failure reason */); 111f33517d79737dd96e5d86ed45ab095be3a4c4773Sohani Rao /* Get statistics for scans performed by Offload HAL */ 1128f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao virtual bool getScanStats( 113f33517d79737dd96e5d86ed45ab095be3a4c4773Sohani Rao ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */); 1142a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao /* Otain status of the Offload HAL service */ 1158f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao virtual StatusCode getOffloadStatus() const; 116e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao /* Returns the most recent scan result available from Offload HAL */ 1178f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao virtual bool getScanResults( 118e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao std::vector<::com::android::server::wifi::wificond::NativeScanResult>* 119e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao out_scan_results); 1203b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 1213b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao private: 12216b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao void ReportScanResults( 123e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>& 12416b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao scanResult); 12516b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao void ReportError( 126e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao const android::hardware::wifi::offload::V1_0::OffloadStatus& status); 127e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao bool VerifyAndConvertHIDLStatus( 128e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao std::pair<android::hardware::wifi::offload::V1_0::OffloadStatus, bool> 129e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao result, 130e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao OffloadScanManager::ReasonCode* reason_code); 131e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao bool GetScanStats( 132e10ec9e1f15007331afe569d7c13790eae5b40deSohani Rao ::com::android::server::wifi::wificond::NativeScanStats* stats); 1338f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao bool SubscribeScanResults( 1348f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao OffloadScanManager::ReasonCode* reason_code); 1358f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao bool ConfigureScans( 1368f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao android::hardware::wifi::offload::V1_0::ScanParam, 1378f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao android::hardware::wifi::offload::V1_0::ScanFilter, 1388f574ac480a39accc9fe5a5f065f4212e8175bd5Sohani Rao OffloadScanManager::ReasonCode* reason_code); 1397439bcacc8805ae85bf1440d5f28df88dd1aee56Sohani Rao bool InitServiceIfNeeded(); 1407439bcacc8805ae85bf1440d5f28df88dd1aee56Sohani Rao bool InitService(); 1417439bcacc8805ae85bf1440d5f28df88dd1aee56Sohani Rao 1427739aa7fba23503a5d6646b7b198bef0944ac5d8Sohani Rao /* Handle binder death */ 1437739aa7fba23503a5d6646b7b198bef0944ac5d8Sohani Rao void OnObjectDeath(uint64_t /* cookie */); 14416b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao 14516b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao android::sp<android::hardware::wifi::offload::V1_0::IOffload> 14616b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao wifi_offload_hal_; 1473b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao android::sp<OffloadCallback> wifi_offload_callback_; 1487739aa7fba23503a5d6646b7b198bef0944ac5d8Sohani Rao android::sp<OffloadDeathRecipient> death_recipient_; 14926e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao StatusCode offload_status_; 1503aeba6c3b4f09c29b75ec8c18b46507ecd69293cSohani Rao std::vector<::com::android::server::wifi::wificond::NativeScanResult> 151e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao cached_scan_results_; 1527439bcacc8805ae85bf1440d5f28df88dd1aee56Sohani Rao bool service_available_; 1532a270852b006b16d500ca11a6e30d3a1a16ba200Sohani Rao 1547439bcacc8805ae85bf1440d5f28df88dd1aee56Sohani Rao const std::weak_ptr<OffloadServiceUtils> offload_service_utils_; 15569f61f7fd15d44dd32a107d850f05f0eb933ab2cSohani Rao const std::shared_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_; 156e15c0edc98c9e6e906b9c53d1691a6bcfae5c61dSohani Rao std::shared_ptr<OffloadScanCallbackInterface> event_callback_; 15726e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao 15826e97959c7b5bf8a2b259b2aa665ae4a807f3030Sohani Rao friend class OffloadCallbackHandlersImpl; 1593b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao}; 1603b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 1613b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao} // namespace wificond 1623b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao} // namespace android 1633b558d191c4237e137429ffeeaf686e34e5da98bSohani Rao 16416b75e6e37fa9567be23e18c8a98e4132fc9d91cSohani Rao#endif // WIFICOND_OFFLOAD_SCAN_MANAGER_H_ 165