From 75e7db3fc38b4da1cef11aebde388cac6a4193d8 Mon Sep 17 00:00:00 2001 From: Sohani Rao Date: Wed, 26 Jul 2017 15:05:44 -0700 Subject: [PATCH] Offload HAL Service: Send messages to CHRE The following messages are to be sent to the nano app in response to invocation of the Offload HAL APIs from the client - subscribe, unsubsuscribe, configure scans CHRE interface will send the following commands to context hub - Get hub info and nano app list requests The callbacks from the socket will handle responses to these requests Bug: 32842314 Test: VTS Change-Id: I441522f5014317b7ac625742ab9782eeba5d78c8 Merged-In: I441522f5014317b7ac625742ab9782eeba5d78c8 --- wifi_offload/chre_interface.cpp | 26 +++++++++++++++++++ wifi_offload/chre_interface.h | 4 +++ wifi_offload/offload_server.cpp | 46 +++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/wifi_offload/chre_interface.cpp b/wifi_offload/chre_interface.cpp index 456e6682..448a5782 100644 --- a/wifi_offload/chre_interface.cpp +++ b/wifi_offload/chre_interface.cpp @@ -142,6 +142,9 @@ void ChreInterface::reportConnectionEvent(ChreInterfaceCallbacks::ConnectionEven switch (event) { case ChreInterfaceCallbacks::ConnectionEvent::CONNECTED: connectionStatus = true; + if (!getHubInfo() || !getNanoAppList()) { + LOG(WARNING) << "Unable to get platform and nano app info"; + } break; case ChreInterfaceCallbacks::ConnectionEvent::DISCONNECTED: case ChreInterfaceCallbacks::ConnectionEvent::CONNECTION_ABORT: @@ -181,6 +184,29 @@ void ChreInterface::handleMessage(uint32_t messageType, const void* messageData, mServerCallbacks->handleMessage(messageType, message); } +bool ChreInterface::getHubInfo() { + LOG(VERBOSE) << "getHubInfo"; + + FlatBufferBuilder builder(chre_constants::kHubInfoRequestBufLen); + HostProtocolHost::encodeHubInfoRequest(builder); + if (!mClient.sendMessage(builder.GetBufferPointer(), builder.GetSize())) { + LOG(WARNING) << "Failed to send Hub Info request"; + return false; + } + return true; +} + +bool ChreInterface::getNanoAppList() { + LOG(VERBOSE) << "getNanoAppList"; + FlatBufferBuilder builder(chre_constants::kNanoAppListRequestBufLen); + HostProtocolHost::encodeNanoappListRequest(builder); + + if (!mClient.sendMessage(builder.GetBufferPointer(), builder.GetSize())) { + LOG(WARNING) << "Unable to send Nano app List request"; + return false; + } + return true; +} } // namespace implementation } // namespace V1_0 } // namespace offload diff --git a/wifi_offload/chre_interface.h b/wifi_offload/chre_interface.h index 72420af5..92cfa5b6 100644 --- a/wifi_offload/chre_interface.h +++ b/wifi_offload/chre_interface.h @@ -51,6 +51,10 @@ class SocketCallbacks void handleUnloadNanoappResponse(const ::chre::fbs::UnloadNanoappResponseT& response) override; private: + /* Requests Hub Information, returns true if Hub Info request was sent */ + bool getHubInfo(); + /* Request list of Nano apps, returns true if Nano app List request was sent */ + bool getNanoAppList(); ChreInterface* mParent; }; diff --git a/wifi_offload/offload_server.cpp b/wifi_offload/offload_server.cpp index 88277ec5..56e139a1 100644 --- a/wifi_offload/offload_server.cpp +++ b/wifi_offload/offload_server.cpp @@ -1,8 +1,13 @@ #include "offload_server.h" #include +#include +#include #include "offload_status_util.h" +#include "offload_utils.h" + +using namespace android::hardware::wifi::offload::V1_0::implementation::chre_constants; namespace android { namespace hardware { @@ -21,6 +26,25 @@ OffloadServer::OffloadServer(ChreInterfaceFactory* factory) OffloadStatus OffloadServer::configureScans(const ScanParam& param, const ScanFilter& filter) { LOG(INFO) << "configureScans"; + if (!mChreInterface->isConnected()) { + return createOffloadStatus(OffloadStatusCode::ERROR, + "Not connected to hardware implementation"); + } + wifi_offload::ScanConfig scanConfig; + if (!offload_utils::ToChreScanConfig(param, filter, &scanConfig)) { + return createOffloadStatus(OffloadStatusCode::ERROR, + "Unable to convert scan configuration"); + } + uint8_t buffer[kMaxMessageLen]; + size_t result_size = wifi_offload::fbs::Serialize(scanConfig, buffer, kMaxMessageLen); + if (result_size <= 0) { + return createOffloadStatus(OffloadStatusCode::ERROR, "Scan config serialization failed"); + } + std::vector message(buffer, buffer + result_size); + if (!mChreInterface->sendCommandToApp(wifi_offload::HostMessageType::HOST_CMD_CONFIG_SCANS, + message)) { + return createOffloadStatus(OffloadStatusCode::ERROR, "Unable to send config message"); + } return createOffloadStatus(OffloadStatusCode::OK); } @@ -32,11 +56,31 @@ std::pair OffloadServer::getScanStats() { OffloadStatus OffloadServer::subscribeScanResults(uint32_t delayMs) { LOG(INFO) << "subscribeScanResults with delay:" << delayMs; + if (!mChreInterface->isConnected()) { + return createOffloadStatus(OffloadStatusCode::ERROR, "Not connected to hardware"); + } + uint32_t* buffer = &delayMs; + std::vector message(reinterpret_cast(buffer), + reinterpret_cast(buffer) + kSubscriptionDelayMsBufLen); + if (!mChreInterface->sendCommandToApp( + wifi_offload::HostMessageType::HOST_CMD_SUBSCRIBE_SCAN_RESULTS, message)) { + return createOffloadStatus(OffloadStatusCode::ERROR, "Unable to request scans"); + } return createOffloadStatus(OffloadStatusCode::OK); } bool OffloadServer::unsubscribeScanResults() { + bool result = false; LOG(INFO) << "unsubscribeScanResults"; + if (!mChreInterface->isConnected()) { + LOG(WARNING) << "Failed to send unsubscribe scan results message"; + return false; + } + if (!mChreInterface->sendCommandToApp( + wifi_offload::HostMessageType::HOST_CMD_UNSUBSCRIBE_SCAN_RESULTS, {})) { + LOG(WARNING) << "Failed to send unsubscribe scan results message"; + return false; + } return true; } @@ -46,8 +90,6 @@ bool OffloadServer::setEventCallback(const sp& cb) { if (cb != nullptr) { mEventCallback = cb; result = true; - } else { - LOG(WARNING) << "Invalid callback object"; } return result; }