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
diff --git a/wifi_offload/chre_interface.cpp b/wifi_offload/chre_interface.cpp
index 456e668..448a578 100644
--- a/wifi_offload/chre_interface.cpp
+++ b/wifi_offload/chre_interface.cpp
@@ -142,6 +142,9 @@
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 @@
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 72420af..92cfa5b 100644
--- a/wifi_offload/chre_interface.h
+++ b/wifi_offload/chre_interface.h
@@ -51,6 +51,10 @@
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 88277ec..56e139a 100644
--- a/wifi_offload/offload_server.cpp
+++ b/wifi_offload/offload_server.cpp
@@ -1,8 +1,13 @@
#include "offload_server.h"
#include <android-base/logging.h>
+#include <chre/apps/wifi_offload/flatbuffers_serialization.h>
+#include <chre/apps/wifi_offload/host_message_types.h>
#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 @@
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<uint8_t> 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 @@
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<uint8_t> message(reinterpret_cast<uint8_t*>(buffer),
+ reinterpret_cast<uint8_t*>(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 @@
if (cb != nullptr) {
mEventCallback = cb;
result = true;
- } else {
- LOG(WARNING) << "Invalid callback object";
}
return result;
}