Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7684fb6 authored by Zhanglong Xia's avatar Zhanglong Xia
Browse files

Add Thread network HAL

Bug: b/203492431
Test: Build and run the VTS test and run otbr-agent on Android emulator.
Change-Id: I0163ea42054e6869e3fb9f93c1fe1a4b2aaff07c
parent 4ff44567
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ bool ShouldCheckMissingHalsInFcm(const std::string& package) {
            "android.hardware.keymaster",
            "android.hardware.media.bufferpool2",
            "android.hardware.radio",
            "android.hardware.threadnetwork",
            "android.hardware.uwb.fira_android",

            // Fastboot HAL is only used by recovery. Recovery is owned by OEM. Framework
+17 −0
Original line number Diff line number Diff line
aidl_interface {
    name: "android.hardware.threadnetwork",
    host_supported: true,
    vendor_available: true,

    srcs: [
        "android/hardware/threadnetwork/*.aidl",
    ],

    unstable: true,

    backend: {
        ndk: {
            enabled: true,
        },
    },
}
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.threadnetwork;

import android.hardware.threadnetwork.IThreadChipCallback;

/**
 * Controls a Thread radio chip on the device.
 */

interface IThreadChip {
    /**
     * The operation failed for the internal error.
     */
    const int ERROR_FAILED = 1;

    /**
     * Insufficient buffers available to send frames.
     */
    const int ERROR_NO_BUFS = 2;

    /**
     * Service is busy and could not service the operation.
     */
    const int ERROR_BUSY = 3;

    /**
     * This method initializes the Thread HAL instance. If open completes
     * successfully, then the Thread HAL instance is ready to accept spinel
     * messages through sendSpinelFrame() API.
     *
     * @param callback  A IThreadChipCallback callback instance. If multiple
     *                  callbacks are passed in, the open() will return ERROR_BUSY.
     *
     * @throws EX_ILLEGAL_ARGUMENT  if the callback handle is invalid (for example, it is null).
     * @throws ServiceSpecificException with one of the following values:
     *     - ERROR_FAILED        The interface cannot be opened due to an internal error.
     *     - ERROR_BUSY          This interface is in use.
     */
    void open(in IThreadChipCallback callback);

    /**
     * Close the Thread HAL instance. Must free all resources.
     *
     * @throws EX_ILLEGAL_STATE  if the Thread HAL instance is not opened.
     *
     */
    void close();

    /**
     * This method resets the Thread HAL internal state. The callback registered by
     * `open()` won’t be reset and the resource allocated by `open()` won’t be free.
     *
     */
    void reset();

    /**
     * This method sends a spinel frame to the Thread HAL.
     *
     * This method should block until the frame is sent out successfully or
     * the method throws errors immediately.
     *
     * Spinel Protocol:
     *     https://github.com/openthread/openthread/blob/main/src/lib/spinel/spinel.h
     *
     * @param frame  The spinel frame to be sent.
     *
     * @throws ServiceSpecificException with one of the following values:
     *         - ERROR_FAILED The Thread HAL failed to send the frame for an internal reason.
     *         - ERROR_NO_BUFS Insufficient buffer space to send the frame.
     *         - ERROR_BUSY The Thread HAL is busy.
     */
    void sendSpinelFrame(in byte[] frame);
}
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.threadnetwork;

interface IThreadChipCallback {
    /**
     * This method is called when a spinel frame is received. Thread network
     * will process the received spinel frame.
     *
     * Spinel Protocol:
     *     https://github.com/openthread/openthread/blob/main/src/lib/spinel/spinel.h
     *
     * @param frame  The received spinel frame.
     */
    oneway void onReceiveSpinelFrame(in byte[] frame);
}
+54 −0
Original line number Diff line number Diff line
// Copyright (C) 2022 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

cc_defaults {
    name: "threadnetwork_service_default",
    vendor: true,
    relative_install_path: "hw",

    shared_libs: [
        "android.hardware.threadnetwork-ndk",
        "libbase",
        "libbinder_ndk",
        "libcutils",
        "liblog",
        "libutils",
    ],

    static_libs: [
        "openthread-common",
        "openthread-hdlc",
        "openthread-platform",
        "openthread-posix",
        "openthread-url",
    ],

    srcs: [
        "main.cpp",
        "service.cpp",
        "thread_chip.cpp",
        "utils.cpp",
    ],
}

cc_binary {
    name: "android.hardware.threadnetwork-service.sim",
    defaults: ["threadnetwork_service_default"],
    init_rc: ["android.hardware.threadnetwork-service.sim.rc"],
}

cc_binary {
    name: "android.hardware.threadnetwork-service",
    defaults: ["threadnetwork_service_default"],
}
Loading