Merge "Thread: simulate radio over Ethernet on Cuttlefish" into main

This commit is contained in:
Yakun Xu 2024-05-17 03:52:14 +00:00 committed by Gerrit Code Review
commit ca7d810a50
2 changed files with 32 additions and 4 deletions

View file

@ -18,7 +18,11 @@
#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <netinet/in.h>
#include <net/if.h>
#include <utils/Log.h>
#include <cutils/properties.h>
#include <sys/stat.h>
#include "service.hpp"
#include "thread_chip.hpp"
@ -26,6 +30,8 @@
using aidl::android::hardware::threadnetwork::IThreadChip;
using aidl::android::hardware::threadnetwork::ThreadChip;
#define THREADNETWORK_COPROCESSOR_SIMULATION_PATH "/apex/com.android.hardware.threadnetwork/bin/ot-rcp"
namespace {
void addThreadChip(int id, const char* url) {
binder_status_t status;
@ -41,14 +47,36 @@ void addThreadChip(int id, const char* url) {
status = AServiceManager_addService(threadChip->asBinder().get(), serviceName.c_str());
CHECK_EQ(status, STATUS_OK);
}
void addSimulatedThreadChip() {
char local_interface[PROP_VALUE_MAX];
CHECK_GT(property_get("persist.vendor.otsim.local_interface",
local_interface, "eth1"), 0);
int node_id = property_get_int32("ro.boot.openthread_node_id", 0);
CHECK_GT(node_id,0);
std::string url = std::string("spinel+hdlc+forkpty://" \
THREADNETWORK_COPROCESSOR_SIMULATION_PATH "?forkpty-arg=-L") \
+ local_interface + "&forkpty-arg=" + std::to_string(node_id);
addThreadChip(0, url.c_str());
}
}
int main(int argc, char* argv[]) {
CHECK_GT(argc, 1);
aidl::android::hardware::threadnetwork::Service service;
for (int id = 0; id < argc - 1; id++) {
addThreadChip(id, argv[id + 1]);
if (argc > 1) {
for (int id = 0; id < argc - 1; id++) {
addThreadChip(id, argv[id + 1]);
}
} else {
struct stat sb;
CHECK_EQ(stat(THREADNETWORK_COPROCESSOR_SIMULATION_PATH, &sb), 0);
CHECK(sb.st_mode & S_IXUSR);
addSimulatedThreadChip();
}
ALOGI("Thread Network HAL is running");

View file

@ -1,3 +1,3 @@
service vendor.threadnetwork_hal /apex/com.android.hardware.threadnetwork/bin/hw/android.hardware.threadnetwork-service spinel+hdlc+forkpty:///apex/com.android.hardware.threadnetwork/bin/ot-rcp?forkpty-arg=1
service vendor.threadnetwork_hal /apex/com.android.hardware.threadnetwork/bin/hw/android.hardware.threadnetwork-service
class hal
user thread_network