diff --git a/usb/bundle.json b/usb/bundle.json
index 4ba09eb8bc9772a2a9deecdbd3eac5f54cad123b..d9b0190910e0e6bf8ddc07c1b0ada583500c49bf 100644
--- a/usb/bundle.json
+++ b/usb/bundle.json
@@ -31,7 +31,8 @@
"build": {
"sub_component": [
"//drivers/interface/usb/v1_0:usb_idl_target",
- "//drivers/interface/usb/gadget/mtp/v1_0:usbfn_mtp_idl_target"
+ "//drivers/interface/usb/gadget/mtp/v1_0:usbfn_mtp_idl_target",
+ "//drivers/interface/usb/ddk/v1_0:usb_ddk_idl_target"
],
"test": [],
"inner_kits": [
@@ -76,6 +77,27 @@
"header_files": [],
"header_base": "//drivers/interface/usb/gadget/mtp"
}
+ },
+ {
+ "name": "//drivers/interface/usb/ddk/v1_0:libusb_ddk_proxy_1.0",
+ "header": {
+ "header_files": [],
+ "header_base": "//drivers/interface/usb/ddk"
+ }
+ },
+ {
+ "name": "//drivers/interface/usb/ddk/v1_0:libusb_ddk_stub_1.0",
+ "header": {
+ "header_files": [],
+ "header_base": "//drivers/interface/usb/ddk"
+ }
+ },
+ {
+ "name": "//drivers/interface/usb/ddk/v1_0:usb_ddk_idl_headers",
+ "header": {
+ "header_files": [],
+ "header_base": "//drivers/interface/usb/ddk"
+ }
}
]
}
diff --git a/usb/ddk/v1_0/BUILD.gn b/usb/ddk/v1_0/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..94b53ba9ad51a344a607bb33bff9049cafac9260
--- /dev/null
+++ b/usb/ddk/v1_0/BUILD.gn
@@ -0,0 +1,27 @@
+# Copyright (c) 2023 Huawei Device Co., Ltd.
+# 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.
+
+import("//drivers/hdf_core/adapter/uhdf2/hdi.gni")
+hdi("usb_ddk") {
+ module_name = "usb_ddk"
+
+ sources = [
+ "IUsbDdk.idl",
+ "UsbDdkTypes.idl",
+ ]
+
+ language = "cpp"
+ mode = "ipc"
+ subsystem_name = "hdf"
+ part_name = "drivers_interface_usb"
+}
diff --git a/usb/ddk/v1_0/IUsbDdk.idl b/usb/ddk/v1_0/IUsbDdk.idl
new file mode 100644
index 0000000000000000000000000000000000000000..ea075e09350c87efb368ce78e19a8f41ac2bbe9e
--- /dev/null
+++ b/usb/ddk/v1_0/IUsbDdk.idl
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * 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.
+ */
+
+/* *
+ * @addtogroup HdiUsbDdk
+ * @{
+ *
+ * @brief Provides USB DDK APIs to open and close USB interfaces, perform non-isochronous and isochronous\n
+ * data transfer over USB pipes, and implement control transfer and interrupt transfer, etc.
+ * @since 4.0
+ */
+
+/* *
+ * @file IUsbDdk.idl
+ *
+ * @brief Declares the USB DDK APIs used by the USB host to access USB devices.
+ *
+ * @since 4.0
+ * @version 1.0
+ */
+
+package ohos.hdi.usb.ddk.v1_0;
+
+import ohos.hdi.usb.ddk.v1_0.UsbDdkTypes;
+
+/* *
+ * @brief Declares the USB DDK APIs used by the USB host to access USB devices.
+ */
+interface IUsbDdk
+{
+
+ /* *
+ * @brief Initializes the DDK.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ Init();
+
+ /* *
+ * @brief Releases the DDK.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ Release();
+
+ /* *
+ * @brief Obtains the USB device descriptor.
+ *
+ * @param deviceId ID of the device whose descriptor is to be obtained.
+ * @param desc Standard device descriptor defined in the USB protocol.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ GetDeviceDescriptor([in] unsigned long deviceId, [out] struct UsbDeviceDescriptor desc);
+
+ /* *
+ * @brief Obtains the configuration descriptor.
+ *
+ * @param deviceId ID of the device whose configuration descriptor is to be obtained.
+ * @param configIndex Configuration index, which corresponds to bConfigurationValue in the USB protocol.
+ * @param configDesc Configuration descriptor, which includes the standard configuration descriptor defined in the\n
+ * USB protocol and the associated interface descriptor and endpoint descriptor.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ GetConfigDescriptor([in] unsigned long deviceId, [in] unsigned char configIndex, [out] List configDesc);
+
+ /* *
+ * @brief Claims a USB interface.
+ *
+ * @param deviceId ID of the device to be operated.
+ * @param interfaceIndex Interface index, which corresponds to bInterfaceNumber in the USB protocol.
+ * @param interfaceHandle Interface operation handle. After the interface is claimed successfully, a value will be\n
+ * assigned to this parameter.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ ClaimInterface([in] unsigned long deviceId, [in] unsigned char interfaceIndex, [out] unsigned long interfaceHandle);
+
+ /* *
+ * @brief Releases a USB interface.
+ *
+ * @param interfaceHandle Interface operation handle.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ ReleaseInterface([in] unsigned long interfaceHandle);
+
+ /* *
+ * @brief Activates the alternate setting of the USB interface.
+ *
+ * @param interfaceHandle Interface operation handle.
+ * @param settingIndex Index of the alternate setting, which corresponds to bAlternateSetting\n
+ * in the USB protocol.
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ SelectInterfaceSetting([in] unsigned long interfaceHandle, [in] unsigned char settingIndex);
+
+ /* *
+ * @brief Obtains the activated alternate setting of the USB interface.
+ *
+ * @param interfaceHandle Interface operation handle.
+ * @param settingIndex Index of the alternate setting, which corresponds to bAlternateSetting\n
+ * in the USB protocol.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ GetCurrentInterfaceSetting([in] unsigned long interfaceHandle, [out] unsigned char settingIndex);
+
+ /* *
+ * @brief Sends a control read transfer request. This API works in a synchronous manner.
+ *
+ * @param interfaceHandle Interface operation handle.
+ * @param setup Request data, which corresponds to Setup Data in the USB protocol.
+ * @param timeout Timeout duration, in milliseconds.
+ * @param data Data to be transferred.
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ SendControlReadRequest([in] unsigned long interfaceHandle, [in] struct UsbControlRequestSetup setup, [in] unsigned int timeout, [out] List data);
+
+ /* *
+ * @brief Sends a control write transfer request. This API works in a synchronous manner.
+ *
+ * @param interfaceHandle Interface operation handle.
+ * @param setup Request data, which corresponds to Setup Data in the USB protocol.
+ * @param timeout Timeout duration, in milliseconds.
+ * @param data Data to be transferred.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ SendControlWriteRequest([in] unsigned long interfaceHandle, [in] struct UsbControlRequestSetup setup, [in] unsigned int timeout, [in] List data);
+
+ /* *
+ * @brief Sends a pipe request. This API works in a synchronous manner. This API applies to interrupt transfer\n
+ * and bulk transfer.
+ *
+ * @param pipe Pipe used to transfer data.
+ * @param size Buffer size.
+ * @param offset Offset of the used buffer. The default value is 0, indicating that there is no offset\n
+ * and the buffer starts from the specified address.
+ * @param length Length of the used buffer. By default, the value is equal to the size, indicating that\n
+ * the entire buffer is used.
+ * @param transferredLength Length of the transferred data.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ SendPipeRequest([in] struct UsbRequestPipe pipe, [in] unsigned int size, [in] unsigned int offset, [in] unsigned int length, [out] unsigned int transferedLength);
+
+ /* *
+ * @brief Gets the file descriptor for memory mapping.
+ *
+ * @param deviceId ID of the device to be operated.
+ * @param fd The file descriptor obtained for memory mapping.
+ *
+ * @return 0 if the operation is successful; a negative value otherwise.
+ * @since 4.0
+ */
+ GetDeviceMemMapFd([in] unsigned long deviceId, [out] FileDescriptor fd);
+}
diff --git a/usb/ddk/v1_0/UsbDdkTypes.idl b/usb/ddk/v1_0/UsbDdkTypes.idl
new file mode 100644
index 0000000000000000000000000000000000000000..033752c8cd158c9404e705c243b5965a70cf55d9
--- /dev/null
+++ b/usb/ddk/v1_0/UsbDdkTypes.idl
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * 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.
+ */
+
+/* *
+ * @addtogroup HdiUsbDdk
+ * @{
+ *
+ * @brief Provides USB DDK types and declares the macros, enumerated variables, and\n
+ * data structures required by the USB DDK APIs.
+ *
+ * @since 4.0
+ */
+
+/**
+ * @file UsbDdkTypes.idl
+ *
+ * @brief Provides the enumerated variables, structures, and macros used in USB DDK APIs.
+ *
+ * @since 4.0
+ * @version 1.0
+ */
+
+package ohos.hdi.usb.ddk.v1_0;
+
+/* *
+ * @brief Setup data for control transfer. It corresponds to Setup Data in the USB protocol.
+ */
+struct UsbControlRequestSetup {
+ /** Request type, corresponding to bmRequestType in the USB protocol. */
+ unsigned char requestType;
+ /** Request command, corresponding to bRequest in the USB protocol. */
+ unsigned char requestCmd;
+ /** Value corresponding to wValue in the USB protocol. Its meaning varies according to the request. */
+ unsigned short value;
+ /** Index corresponding to wIndex in the USB protocol. It is usually used to transfer the index or offset.\n
+ * Its meaning varies according to the request.
+ */
+ unsigned short index;
+ /** Data length, corresponding to wLength in the USB protocol. If data is transferred,\n
+ * this field indicates the number of transferred bytes.
+ */
+ unsigned short length;
+};
+
+/* *
+ * @brief Standard device descriptor, corresponding to Standard Device Descriptor in the USB protocol.
+ */
+struct UsbDeviceDescriptor {
+ /** Size of the descriptor, in bytes. */
+ unsigned char bLength;
+ /** Descriptor type. */
+ unsigned char bDescriptorType;
+ /** USB protocol release number. */
+ unsigned short bcdUSB;
+ /** Device class code allocated by the USB-IF. */
+ unsigned char bDeviceClass;
+ /** Device subclass code allocated by USB-IF. The value is limited by that of bDeviceClass. */
+ unsigned char bDeviceSubClass;
+ /** Protocol code allocated by USB-IF. The value is limited by that of bDeviceClass and bDeviceSubClass. */
+ unsigned char bDeviceProtocol;
+ /** Maximum packet size of endpoint 0. Only values 8, 16, 32, and 64 are valid. */
+ unsigned char bMaxPacketSize0;
+ /** Vendor ID allocated by USB-IF. */
+ unsigned short idVendor;
+ /** Product ID allocated by the vendor. */
+ unsigned short idProduct;
+ /** Device release number. */
+ unsigned short bcdDevice;
+ /** Index of the string descriptor that describes the vendor. */
+ unsigned char iManufacturer;
+ /** Index of the string descriptor that describes the product. */
+ unsigned char iProduct;
+ /** Index of the string descriptor that describes the device SN. */
+ unsigned char iSerialNumber;
+ /** Configuration quantity. */
+ unsigned char bNumConfigurations;
+};
+
+
+/**
+ * @brief Request pipe.
+ */
+struct UsbRequestPipe {
+ /** Interface operation handle. */
+ unsigned long interfaceHandle;
+ /** Timeout duration, in milliseconds. */
+ unsigned int timeout;
+ /** Endpoint address. */
+ unsigned char endpoint;
+};
\ No newline at end of file