Merge changes from topic "cherrypicker-L18700000961261875:N88400001378560897" am: 59b018679b am: fb6fbba8b2

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2627570

Change-Id: I7a5c47c991b9d35b117af1b3da543f6e53116a62
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Zhanglong Xia
2023-07-01 01:17:33 +00:00
committed by Automerger Merge Worker
10 changed files with 105 additions and 65 deletions

View File

@@ -834,12 +834,4 @@
<regex-instance>.*</regex-instance> <regex-instance>.*</regex-instance>
</interface> </interface>
</hal> </hal>
<hal format="aidl" optional="true">
<name>android.hardware.threadnetwork</name>
<version>1</version>
<interface>
<name>IThreadChip</name>
<regex-instance>chip[0-9]+</regex-instance>
</interface>
</hal>
</compatibility-matrix> </compatibility-matrix>

View File

@@ -794,4 +794,12 @@
<regex-instance>.*</regex-instance> <regex-instance>.*</regex-instance>
</interface> </interface>
</hal> </hal>
<hal format="aidl" optional="true">
<name>android.hardware.threadnetwork</name>
<version>1</version>
<interface>
<name>IThreadChip</name>
<regex-instance>chip[0-9]+</regex-instance>
</interface>
</hal>
</compatibility-matrix> </compatibility-matrix>

View File

@@ -24,10 +24,6 @@ cc_defaults {
"libutils", "libutils",
], ],
cppflags: [
"-Wno-non-virtual-dtor",
],
static_libs: [ static_libs: [
"openthread-common", "openthread-common",
"openthread-hdlc", "openthread-hdlc",
@@ -48,9 +44,43 @@ cc_binary {
name: "android.hardware.threadnetwork-service.sim", name: "android.hardware.threadnetwork-service.sim",
defaults: ["threadnetwork_service_default"], defaults: ["threadnetwork_service_default"],
init_rc: ["android.hardware.threadnetwork-service.sim.rc"], init_rc: ["android.hardware.threadnetwork-service.sim.rc"],
required: ["ot-rcp"],
} }
cc_binary { cc_binary {
name: "android.hardware.threadnetwork-service", name: "android.hardware.threadnetwork-service",
defaults: ["threadnetwork_service_default"], defaults: ["threadnetwork_service_default"],
} }
cc_fuzz {
name: "android.hardware.threadnetwork-service.fuzzer",
defaults:["service_fuzzer_defaults"],
shared_libs: [
"libbinder_ndk",
],
static_libs: [
"android.hardware.threadnetwork-V1-ndk",
"libbase",
"liblog",
"openthread-common",
"openthread-hdlc",
"openthread-platform",
"openthread-posix",
"openthread-url",
],
srcs: [
"thread_chip.cpp",
"utils.cpp",
"fuzzer.cpp",
],
required: ["ot-rcp"],
fuzz_config: {
cc: [
"zhanglongxia@google.com",
],
},
}

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2023 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,7 +14,19 @@
* limitations under the License. * limitations under the License.
*/ */
#pragma once #include <fuzzbinder/libbinder_ndk_driver.h>
#include <fuzzer/FuzzedDataProvider.h>
#include "thread_chip.hpp"
using aidl::android::hardware::threadnetwork::ThreadChip;
using android::fuzzService;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
char url[] = "spinel+hdlc+forkpty:///vendor/bin/ot-rcp?forkpty-arg=2";
auto service = ndk::SharedRefBase::make<ThreadChip>(url);
fuzzService(service->asBinder().get(), FuzzedDataProvider(data, size));
return 0;
}
#define LOG_TAG "threadnetwork_hal"
#include <utils/Log.h>

View File

@@ -14,14 +14,37 @@
* limitations under the License. * limitations under the License.
*/ */
#include <aidl/android/hardware/threadnetwork/IThreadChip.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <utils/Log.h>
#include "service.hpp" #include "service.hpp"
#include "utils.hpp" #include "thread_chip.hpp"
using aidl::android::hardware::threadnetwork::IThreadChip;
using aidl::android::hardware::threadnetwork::ThreadChip;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
CHECK_GT(argc, 1); CHECK_GT(argc, 1);
aidl::android::hardware::threadnetwork::Service service(&argv[1], argc - 1); std::vector<std::shared_ptr<ThreadChip>> threadChips;
aidl::android::hardware::threadnetwork::Service service;
for (int id = 0; id < argc - 1; id++) {
binder_status_t status;
const std::string serviceName(std::string() + IThreadChip::descriptor + "/chip" +
std::to_string(id));
auto threadChip = ndk::SharedRefBase::make<ThreadChip>(argv[id + 1]);
CHECK_NE(threadChip, nullptr);
status = AServiceManager_addService(threadChip->asBinder().get(), serviceName.c_str());
CHECK_EQ(status, STATUS_OK);
ALOGI("ServiceName: %s, Url: %s", serviceName.c_str(), argv[id + 1]);
threadChips.push_back(std::move(threadChip));
}
ALOGI("Thread Network HAL is running"); ALOGI("Thread Network HAL is running");

View File

@@ -18,25 +18,14 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include <utils/Log.h>
#include "thread_chip.hpp"
#include "utils.hpp"
namespace aidl { namespace aidl {
namespace android { namespace android {
namespace hardware { namespace hardware {
namespace threadnetwork { namespace threadnetwork {
Service::Service(char* urls[], int numUrls) : mBinderFd(-1) { Service::Service(void) : mBinderFd(-1) {
CHECK_NE(urls, nullptr);
CHECK_GT(numUrls, 0);
for (int i = 0; i < numUrls; i++) {
auto threadChip = ndk::SharedRefBase::make<ThreadChip>(i, urls[i]);
CHECK_NE(threadChip, nullptr);
mThreadChips.push_back(std::move(threadChip));
}
binder_status_t status = ABinderProcess_setupPolling(&mBinderFd); binder_status_t status = ABinderProcess_setupPolling(&mBinderFd);
CHECK_EQ(status, ::STATUS_OK); CHECK_EQ(status, ::STATUS_OK);
CHECK_GE(mBinderFd, 0); CHECK_GE(mBinderFd, 0);

View File

@@ -15,7 +15,6 @@
*/ */
#include "mainloop.hpp" #include "mainloop.hpp"
#include "thread_chip.hpp"
namespace aidl { namespace aidl {
namespace android { namespace android {
@@ -24,7 +23,7 @@ namespace threadnetwork {
class Service : public ot::Posix::Mainloop::Source { class Service : public ot::Posix::Mainloop::Source {
public: public:
Service(char* urls[], int numUrls); Service(void);
void Update(otSysMainloopContext& context) override; void Update(otSysMainloopContext& context) override;
void Process(const otSysMainloopContext& context) override; void Process(const otSysMainloopContext& context) override;
@@ -32,7 +31,6 @@ class Service : public ot::Posix::Mainloop::Source {
private: private:
int mBinderFd; int mBinderFd;
std::vector<std::shared_ptr<ThreadChip>> mThreadChips;
}; };
} // namespace threadnetwork } // namespace threadnetwork
} // namespace hardware } // namespace hardware

View File

@@ -19,26 +19,19 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include <utils/Log.h>
#include "utils.hpp"
namespace aidl { namespace aidl {
namespace android { namespace android {
namespace hardware { namespace hardware {
namespace threadnetwork { namespace threadnetwork {
ThreadChip::ThreadChip(uint8_t id, char* url) ThreadChip::ThreadChip(char* url)
: mUrl(), : mUrl(),
mInterface(handleReceivedFrame, this, mRxFrameBuffer), mInterface(handleReceivedFrame, this, mRxFrameBuffer),
mRxFrameBuffer(), mRxFrameBuffer(),
mCallback(nullptr) { mCallback(nullptr) {
const std::string name(std::string() + IThreadChip::descriptor + "/chip" + std::to_string(id));
binder_status_t status;
ALOGI("ServiceName: %s, Url: %s", name.c_str(), url);
CHECK_EQ(mUrl.Init(url), 0); CHECK_EQ(mUrl.Init(url), 0);
status = AServiceManager_addService(asBinder().get(), name.c_str());
CHECK_EQ(status, STATUS_OK);
} }
void ThreadChip::clientDeathCallback(void* context) { void ThreadChip::clientDeathCallback(void* context) {
@@ -85,17 +78,13 @@ ndk::ScopedAStatus ThreadChip::open(const std::shared_ptr<IThreadChipCallback>&
status = ndk::ScopedAStatus::ok(); status = ndk::ScopedAStatus::ok();
exit: exit:
if (!status.isOk()) if (!status.isOk()) {
{ if (mBinderDeathRecipient != nullptr) {
if (mBinderDeathRecipient != nullptr) AIBinder_DeathRecipient_delete(mBinderDeathRecipient);
{ mBinderDeathRecipient = nullptr;
AIBinder_DeathRecipient_delete(mBinderDeathRecipient);
mBinderDeathRecipient = nullptr;
} }
ALOGW("Open failed, error: %s", status.getDescription().c_str()); ALOGW("Open failed, error: %s", status.getDescription().c_str());
} } else {
else
{
ALOGI("open()"); ALOGI("open()");
} }
@@ -137,8 +126,7 @@ ndk::ScopedAStatus ThreadChip::sendSpinelFrame(const std::vector<uint8_t>& in_fr
} }
exit: exit:
if (!status.isOk()) if (!status.isOk()) {
{
ALOGW("Send spinel frame failed, error: %s", status.getDescription().c_str()); ALOGW("Send spinel frame failed, error: %s", status.getDescription().c_str());
} }
@@ -146,25 +134,20 @@ exit:
} }
ndk::ScopedAStatus ThreadChip::reset() { ndk::ScopedAStatus ThreadChip::reset() {
mInterface.OnRcpReset(); mInterface.HardwareReset();
ALOGI("reset()"); ALOGI("reset()");
return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok();
} }
void ThreadChip::Update(otSysMainloopContext& context) { void ThreadChip::Update(otSysMainloopContext& context) {
if (mCallback != nullptr) { if (mCallback != nullptr) {
mInterface.UpdateFdSet(context.mReadFdSet, context.mWriteFdSet, context.mMaxFd, mInterface.UpdateFdSet(&context);
context.mTimeout);
} }
} }
void ThreadChip::Process(const otSysMainloopContext& context) { void ThreadChip::Process(const otSysMainloopContext& context) {
struct RadioProcessContext radioContext;
if (mCallback != nullptr) { if (mCallback != nullptr) {
radioContext.mReadFdSet = &context.mReadFdSet; mInterface.Process(&context);
radioContext.mWriteFdSet = &context.mWriteFdSet;
mInterface.Process(radioContext);
} }
} }

View File

@@ -33,7 +33,7 @@ namespace threadnetwork {
class ThreadChip : public BnThreadChip, ot::Posix::Mainloop::Source { class ThreadChip : public BnThreadChip, ot::Posix::Mainloop::Source {
public: public:
ThreadChip(uint8_t id, char* url); ThreadChip(char* url);
ndk::ScopedAStatus open(const std::shared_ptr<IThreadChipCallback>& in_callback) override; ndk::ScopedAStatus open(const std::shared_ptr<IThreadChipCallback>& in_callback) override;
ndk::ScopedAStatus close() override; ndk::ScopedAStatus close() override;

View File

@@ -15,9 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
#include "utils.hpp" #include <openthread/instance.h>
#include <openthread/logging.h> #include <openthread/logging.h>
#include <openthread/platform/alarm-milli.h>
#include <utils/Log.h>
void otLogCritPlat(const char* format, ...) { void otLogCritPlat(const char* format, ...) {
va_list args; va_list args;
@@ -34,3 +35,7 @@ void otLogWarnPlat(const char* format, ...) {
__android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, args); __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, args);
va_end(args); va_end(args);
} }
OT_TOOL_WEAK void otPlatAlarmMilliFired(otInstance* aInstance) {
OT_UNUSED_VARIABLE(aInstance);
}