interface/device_tree: Add AIDL interface for device tree service

Bug: 231151995
Change-Id: I159440f47162e26ad4b07bbd051e07d280284a30
diff --git a/interface/device_tree/com/android/trusty/device_tree/IDeviceTree.aidl b/interface/device_tree/com/android/trusty/device_tree/IDeviceTree.aidl
new file mode 100644
index 0000000..74f0efc
--- /dev/null
+++ b/interface/device_tree/com/android/trusty/device_tree/IDeviceTree.aidl
@@ -0,0 +1,45 @@
+/*
+ * 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 com.android.trusty.device_tree;
+
+import com.android.trusty.device_tree.INodeIterator;
+import com.android.trusty.device_tree.INode;
+
+interface IDeviceTree {
+
+    @utf8InCpp
+    const String PORT = "com.android.trusty.device_tree";
+
+    @utf8InCpp
+    const String KERNEL_PORT = "com.android.kernel.device_tree";
+
+    const int ERROR_NONE = 0;
+    const int ERROR_GENERIC = 1;
+    const int ERROR_INVALID_ARGS = 2;
+    const int ERROR_NO_MEMORY = 3;
+    const int ERROR_NODE_NOT_FOUND = 4;
+    const int ERROR_PROP_NOT_FOUND = 5;
+
+    /**
+     * get_compatible_nodes_from_list() - Get an iterator over nodes with one of
+     *                                    the given compatible strings.
+     * @compatible: A list of null-terminated compatible strings to search for.
+     *
+     * Return: An iterator over the compatible nodes.
+     */
+     INodeIterator get_compatible_nodes_from_list(in @utf8InCpp String[] compatible);
+}
diff --git a/interface/device_tree/com/android/trusty/device_tree/INode.aidl b/interface/device_tree/com/android/trusty/device_tree/INode.aidl
new file mode 100644
index 0000000..b349e75
--- /dev/null
+++ b/interface/device_tree/com/android/trusty/device_tree/INode.aidl
@@ -0,0 +1,60 @@
+/*
+ * 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 com.android.trusty.device_tree;
+
+import com.android.trusty.device_tree.INodeIterator;
+import com.android.trusty.device_tree.IPropIterator;
+import com.android.trusty.device_tree.Property;
+
+interface INode {
+     /**
+      * get_name() - Get a node's name.
+      *
+      * Return: The node's name.
+      */
+     @utf8InCpp String get_name();
+
+     /**
+      * get_subnode() - Get a subnode of the given parent node.
+      * @node_name: A single null-terminated string with the subnode's name.
+      *
+      * Return: A subnode.
+      */
+     INode get_subnode(in @utf8InCpp String node_name);
+
+     /**
+      * get_subnodes() - Get an iterator over the subnodes of the given parent node.
+      *
+      * Return: An iterator over the subnodes.
+      */
+     INodeIterator get_subnodes();
+
+     /**
+      * get_props() - Get an iterator over a node's properties.
+      *
+      * Return: An iterator over the properties.
+      */
+     IPropIterator get_props();
+
+     /**
+      * get_prop() - Get a node's property.
+      * @prop_name: A single null-terminated string with the property's name.
+      *
+      * Return: The property in big-endian
+      */
+     Property get_prop(in @utf8InCpp String prop_name);
+}
diff --git a/interface/device_tree/com/android/trusty/device_tree/INodeIterator.aidl b/interface/device_tree/com/android/trusty/device_tree/INodeIterator.aidl
new file mode 100644
index 0000000..ec12de3
--- /dev/null
+++ b/interface/device_tree/com/android/trusty/device_tree/INodeIterator.aidl
@@ -0,0 +1,28 @@
+/*
+ * 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 com.android.trusty.device_tree;
+
+import com.android.trusty.device_tree.INode;
+
+interface INodeIterator {
+    /**
+     * get_next_node() - Get the iterator's next node.
+     *
+     * Return: The next node's offset.
+     */
+    INode get_next_node();
+}
diff --git a/interface/device_tree/com/android/trusty/device_tree/IPropIterator.aidl b/interface/device_tree/com/android/trusty/device_tree/IPropIterator.aidl
new file mode 100644
index 0000000..c28dd2c
--- /dev/null
+++ b/interface/device_tree/com/android/trusty/device_tree/IPropIterator.aidl
@@ -0,0 +1,28 @@
+/*
+ * 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 com.android.trusty.device_tree;
+
+import com.android.trusty.device_tree.Property;
+
+interface IPropIterator {
+    /**
+     * get_next_prop() - Get the iterator's next property.
+     *
+     * Return: The next property in big-endian.
+     */
+    Property get_next_prop();
+}
diff --git a/interface/device_tree/com/android/trusty/device_tree/Property.aidl b/interface/device_tree/com/android/trusty/device_tree/Property.aidl
new file mode 100644
index 0000000..0c346a8
--- /dev/null
+++ b/interface/device_tree/com/android/trusty/device_tree/Property.aidl
@@ -0,0 +1,23 @@
+/*
+ * 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 com.android.trusty.device_tree;
+
+parcelable Property {
+    @utf8InCpp
+    String name;
+    byte[] value;
+}
diff --git a/interface/device_tree/rules.mk b/interface/device_tree/rules.mk
new file mode 100644
index 0000000..e864c67
--- /dev/null
+++ b/interface/device_tree/rules.mk
@@ -0,0 +1,29 @@
+# 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.
+#
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+MODULE_AIDL_PACKAGE := com/android/trusty/device_tree
+
+MODULE_AIDLS := \
+	$(LOCAL_DIR)/$(MODULE_AIDL_PACKAGE)/IDeviceTree.aidl \
+	$(LOCAL_DIR)/$(MODULE_AIDL_PACKAGE)/INodeIterator.aidl \
+	$(LOCAL_DIR)/$(MODULE_AIDL_PACKAGE)/INode.aidl \
+	$(LOCAL_DIR)/$(MODULE_AIDL_PACKAGE)/IPropIterator.aidl \
+	$(LOCAL_DIR)/$(MODULE_AIDL_PACKAGE)/Property.aidl \
+
+include make/aidl.mk