From 7b9dc45bb3dba0af5664a87c1e32ab4db02d4741 Mon Sep 17 00:00:00 2001 From: dufresne_andy Date: Fri, 15 Mar 2024 16:53:17 +0800 Subject: [PATCH 1/3] Description:enhance host management to device Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: dufresne_andy --- usb/ddk/host/include/linux_adapter.h | 2 + usb/ddk/host/include/usb_raw_api_library.h | 1 + usb/ddk/host/src/linux_adapter.c | 22 +- usb/ddk/host/src/usb_interface_pool.c | 36 ++ usb/ddk/host/src/usb_raw_api_library.c | 15 + usb/hdi_service/BUILD.gn | 10 +- usb/hdi_service/include/usb_impl.h | 14 +- usb/hdi_service/include/usbd.h | 8 +- usb/hdi_service/include/usbd_dispatcher.h | 10 +- usb/hdi_service/include/usbd_function.h | 12 +- .../include/usbd_load_usb_service.h | 4 +- usb/hdi_service/include/usbd_port.h | 18 +- usb/hdi_service/src/usb_impl.cpp | 38 ++- usb/hdi_service/src/usb_interface_driver.cpp | 9 +- usb/hdi_service/src/usbd_dispatcher.cpp | 4 +- usb/hdi_service/src/usbd_function.cpp | 2 +- usb/hdi_service/src/usbd_load_usb_service.cpp | 4 +- usb/hdi_service/src/usbd_port.cpp | 4 +- usb/interfaces/ddk/host/usb_ddk_interface.h | 4 +- usb/test/benchmarktest/BUILD.gn | 8 +- usb/test/fuzztest/usb_fuzzer/BUILD.gn | 2 +- usb/test/unittest/hal/BUILD.gn | 53 ++- .../hal/include/usbd_device_status_test.h | 38 +++ .../hal/src/usbd_device_status_test.cpp | 314 ++++++++++++++++++ usb/test/unittest/mock/BUILD.gn | 8 +- 25 files changed, 564 insertions(+), 76 deletions(-) create mode 100644 usb/test/unittest/hal/include/usbd_device_status_test.h create mode 100644 usb/test/unittest/hal/src/usbd_device_status_test.cpp diff --git a/usb/ddk/host/include/linux_adapter.h b/usb/ddk/host/include/linux_adapter.h index 9aa869d030..507cd56229 100644 --- a/usb/ddk/host/include/linux_adapter.h +++ b/usb/ddk/host/include/linux_adapter.h @@ -145,6 +145,8 @@ struct UsbOsAdapterOps { int32_t (*detachKernelDriver)(const struct UsbDeviceHandle *devHandle, uint8_t interfaceNumber); int32_t (*usbControlMsg)(const struct UsbDeviceHandle *devHandle, struct UsbControlRequestData *ctrlData); int32_t (*getUsbSpeed)(const struct UsbDeviceHandle *handle); + bool (*getInterfaceActiveStatus)(const struct UsbDeviceHandle *devHandle, uint8_t interfaceNumber); + int32_t (*getDeviceSpeed)(const struct UsbDeviceHandle *devHandle); }; #ifdef __cplusplus extern "C" { diff --git a/usb/ddk/host/include/usb_raw_api_library.h b/usb/ddk/host/include/usb_raw_api_library.h index 4a298031fd..f5386816a0 100644 --- a/usb/ddk/host/include/usb_raw_api_library.h +++ b/usb/ddk/host/include/usb_raw_api_library.h @@ -144,6 +144,7 @@ int32_t RawDetachInterface(struct UsbDeviceHandle *devHandle, uint32_t interface int32_t RawUsbControlMsg(const struct UsbDeviceHandle *devHandle, struct UsbControlRequestData *ctrlData); int32_t RawUsbGetUsbSpeed(const struct UsbDeviceHandle *devHandle); +bool RawGetInterfaceActiveStatus(struct UsbDeviceHandle *devHandle, uint32_t interfaceNumber); #ifdef __cplusplus } #endif diff --git a/usb/ddk/host/src/linux_adapter.c b/usb/ddk/host/src/linux_adapter.c index f82ec6a647..e714501b86 100644 --- a/usb/ddk/host/src/linux_adapter.c +++ b/usb/ddk/host/src/linux_adapter.c @@ -377,8 +377,9 @@ static int32_t AdapterGetUsbSpeed(const struct UsbDeviceHandle *handle) HDF_LOGE("%{public}s:%{public}d invalid param", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } - - return ioctl(handle->fd, USBDEVFS_GET_SPEED, NULL); + int32_t ret = ioctl(handle->fd, USBDEVFS_GET_SPEED, NULL); + HDF_LOGI("%{public}s:%{public}d speed = %{public}d", __func__, __LINE__, ret); + return ret; } static void OsFreeIsoUrbs(struct UsbHostRequest *request) @@ -1469,6 +1470,20 @@ static int32_t AdapterUrbCompleteHandle(const struct UsbDeviceHandle *devHandle) return ret; } +static bool AdapterGetInterfaceActiveStatus(const struct UsbDeviceHandle *devHandle, uint8_t interfaceNumber) +{ + bool ret; + if (devHandle == NULL) { + return HDF_ERR_INVALID_PARAM; + } + struct UsbAdapterGetdriver getDriver = {interfaceNumber, {0}}; + ret = ioctl(devHandle->fd, USBDEVFS_GETDRIVER, &getDriver); + if (ret == 0 && strcmp(getDriver.driver, "usbfs") == 0) { + return false; + } + return true; +} + static struct UsbOsAdapterOps g_usbAdapter = { .init = AdapterInit, .exit = AdapterExit, @@ -1493,7 +1508,8 @@ static struct UsbOsAdapterOps g_usbAdapter = { .attachKernelDriver = AdapterAttachKernelDriver, .detachKernelDriver = AdapterDetachKernelDriver, .usbControlMsg = AdapterUsbControlMsg, - .getUsbSpeed = AdapterGetUsbSpeed + .getUsbSpeed = AdapterGetUsbSpeed, + .getInterfaceActiveStatus = AdapterGetInterfaceActiveStatus, }; static void OsSignalHandler(int32_t signo) diff --git a/usb/ddk/host/src/usb_interface_pool.c b/usb/ddk/host/src/usb_interface_pool.c index cc372c562c..99066d1afb 100644 --- a/usb/ddk/host/src/usb_interface_pool.c +++ b/usb/ddk/host/src/usb_interface_pool.c @@ -1828,3 +1828,39 @@ int32_t UsbMemTestTrigger(bool enable) { return RawUsbMemTestTrigger(enable); } + +bool UsbGetInterfaceActiveStatus( + const struct UsbSession *session, uint8_t busNum, uint8_t usbAddr, uint8_t interfaceIndex) +{ + struct UsbPoolQueryPara poolQueryPara = {0}; + struct UsbInterfacePool *interfacePool = NULL; + struct UsbInterfaceQueryPara interfaceQueryPara = {USB_INTERFACE_INTERFACE_INDEX_TYPE, interfaceIndex, 0}; + struct UsbSdkInterface *interfaceObj = NULL; + struct UsbDeviceHandle *devHandle = NULL; + struct UsbSession *realSession = RawGetSession(session); + bool claimFlag = false; + bool unactivated; + if (realSession == NULL) { + return NULL; + } + SetPoolQueryPara(&poolQueryPara, busNum, usbAddr); + interfacePool = IfFindInterfacePool(realSession, poolQueryPara, true); + if (interfacePool == NULL || interfacePool->device == NULL) { + interfacePool = IfGetInterfacePool(&devHandle, realSession, busNum, usbAddr); + if (interfacePool == NULL || interfacePool->device == NULL) { + HDF_LOGE("%{public}s:%{public}d interfacePool or interfacePool->device is null", __func__, __LINE__); + return NULL; + } + } + + interfaceObj = IfFindInterfaceObj(interfacePool, interfaceQueryPara, true, &claimFlag, true); + if (interfaceObj == NULL) { + HDF_LOGE("%{public}s:%{public}d interfaceObj is null", __func__, __LINE__); + return NULL; + } + + devHandle = interfacePool->device->devHandle; + unactivated = RawGetInterfaceActiveStatus(devHandle, interfaceIndex); + + return unactivated; +} \ No newline at end of file diff --git a/usb/ddk/host/src/usb_raw_api_library.c b/usb/ddk/host/src/usb_raw_api_library.c index cd4de1a365..7410ed9679 100644 --- a/usb/ddk/host/src/usb_raw_api_library.c +++ b/usb/ddk/host/src/usb_raw_api_library.c @@ -1709,3 +1709,18 @@ void RawUsbMemFree(void *mem) OsalMemFree(mem); } } + +bool RawGetInterfaceActiveStatus(struct UsbDeviceHandle *devHandle, uint32_t interfaceNumber) +{ + struct UsbOsAdapterOps *osAdapterOps = UsbAdapterGetOps(); + if (devHandle == NULL || interfaceNumber >= USB_MAXINTERFACES || osAdapterOps->claimInterface == NULL) { + HDF_LOGE("%{public}s:%d HDF_ERR_INVALID_PARAM", __func__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + HDF_LOGI("interfaceNumber = %{public}u", interfaceNumber); + + OsalMutexLock(&devHandle->lock); + bool ret = osAdapterOps->getInterfaceActiveStatus(devHandle, interfaceNumber); + + return ret; +} \ No newline at end of file diff --git a/usb/hdi_service/BUILD.gn b/usb/hdi_service/BUILD.gn index f8dbc8e3a6..bde4e2c84a 100644 --- a/usb/hdi_service/BUILD.gn +++ b/usb/hdi_service/BUILD.gn @@ -35,7 +35,7 @@ config("usbd_public_config") { ] } -ohos_shared_library("libusb_interface_service_1.0") { +ohos_shared_library("libusb_interface_service_1.1") { sanitize = { integer_overflow = true ubsan = true @@ -107,7 +107,7 @@ ohos_shared_library("libusb_driver") { sources = [ "src/usb_interface_driver.cpp" ] - public_deps = [ ":libusb_interface_service_1.0" ] + public_deps = [ ":libusb_interface_service_1.1" ] shlib_type = "hdi" @@ -118,7 +118,7 @@ ohos_shared_library("libusb_driver") { if (is_standard_system) { external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_stub_1.0", + "drivers_interface_usb:libusb_stub_1.1", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", @@ -129,7 +129,7 @@ ohos_shared_library("libusb_driver") { ] } else { external_deps = [ - "drivers_interface_usb:libusb_stub_1.0", + "drivers_interface_usb:libusb_stub_1.1", "hilog:libhilog", "ipc:ipc_single", ] @@ -143,6 +143,6 @@ ohos_shared_library("libusb_driver") { group("hdi_usb_service") { deps = [ ":libusb_driver", - ":libusb_interface_service_1.0", + ":libusb_interface_service_1.1", ] } diff --git a/usb/hdi_service/include/usb_impl.h b/usb/hdi_service/include/usb_impl.h index 028313621e..7d30a9ea69 100644 --- a/usb/hdi_service/include/usb_impl.h +++ b/usb/hdi_service/include/usb_impl.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_HDI_USB_V1_0_USBIMPL_H -#define OHOS_HDI_USB_V1_0_USBIMPL_H +#ifndef OHOS_HDI_USB_V1_1_USBIMPL_H +#define OHOS_HDI_USB_V1_1_USBIMPL_H #include "hdf_slist.h" #include "hdf_usb_pnp_manage.h" @@ -24,7 +24,7 @@ #include "usb_session.h" #include "usbd.h" #include "usbd_load_usb_service.h" -#include "v1_0/iusb_interface.h" +#include "v1_1/iusb_interface.h" #define BASE_CLASS_HUB 0x09 @@ -33,7 +33,7 @@ constexpr uint8_t MAX_INTERFACEID = 0xFF; namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { class UsbImpl : public IUsbInterface { public: OsalMutex lock_; @@ -135,6 +135,8 @@ private: static int32_t UsbdPnpNotifyAddAndRemoveDevice(HdfSBuf *data, UsbdSubscriber *usbdSubscriber, uint32_t id); static int32_t UsbdPnpLoaderEventReceived(void *priv, uint32_t id, HdfSBuf *data); static int32_t UsbdLoadServiceCallback(void *priv, uint32_t id, HdfSBuf *data); + int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool &unactivated) override; + int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t &speed) override; class UsbDeathRecipient : public IRemoteObject::DeathRecipient { public: explicit UsbDeathRecipient(const sptr &deathSubscriber) : deathSubscriber_(deathSubscriber) {}; @@ -156,8 +158,8 @@ private: static UsbdLoadService loadUsbService_; static UsbdLoadService loadHdfEdm_; }; -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS -#endif // OHOS_HDI_USB_V1_0_USBIMPL_H +#endif // OHOS_HDI_USB_V1_1_USBIMPL_H diff --git a/usb/hdi_service/include/usbd.h b/usb/hdi_service/include/usbd.h index 3f7282dfa4..f9fffde78c 100644 --- a/usb/hdi_service/include/usbd.h +++ b/usb/hdi_service/include/usbd.h @@ -26,7 +26,7 @@ #include "usb_ddk_interface.h" #include "usb_session.h" #include "usbd_type.h" -#include "v1_0/iusb_interface.h" +#include "v1_1/iusb_interface.h" #include "v1_0/iusbd_bulk_callback.h" #define USB_MAX_INTERFACES 32 @@ -40,7 +40,7 @@ namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { struct UsbdBulkASyncReqList; struct UsbdBulkASyncList; class UsbImpl; @@ -75,7 +75,7 @@ struct UsbdBulkASyncList { struct HostDevice *instance; struct UsbdBulkASyncList *next; UsbInterfaceHandle *ifHandle; - sptr cb; + sptr cb; struct UsbdBulkASyncReqList rList; struct UsbPipeInfo pipe; struct UsbRequestParams params; @@ -177,7 +177,7 @@ struct UsbdSubscriber { sptr remote; void *deathRecipient; }; -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS diff --git a/usb/hdi_service/include/usbd_dispatcher.h b/usb/hdi_service/include/usbd_dispatcher.h index e9bdabe322..2aea4e34fa 100644 --- a/usb/hdi_service/include/usbd_dispatcher.h +++ b/usb/hdi_service/include/usbd_dispatcher.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_HDI_USB_V1_0_USBD_DISPATCHER_H -#define OHOS_HDI_USB_V1_0_USBD_DISPATCHER_H +#ifndef OHOS_HDI_USB_V1_1_USBD_DISPATCHER_H +#define OHOS_HDI_USB_V1_1_USBD_DISPATCHER_H #include "usbd.h" @@ -62,7 +62,7 @@ enum UsbdReqNodeStatus { namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { class UsbImpl; class UsbdDispatcher { public: @@ -134,8 +134,8 @@ public: static int32_t UsbdBulkASyncReqWriteSubmit(UsbdBulkASyncReqNode *req); static int32_t UsbdBulkASyncReqReadSubmit(UsbdBulkASyncReqNode *db); }; -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS -#endif // OHOS_HDI_USB_V1_0_USBD_DISPATCHER_H +#endif // OHOS_HDI_USB_V1_1_USBD_DISPATCHER_H diff --git a/usb/hdi_service/include/usbd_function.h b/usb/hdi_service/include/usbd_function.h index de43b9a533..483d5387f1 100644 --- a/usb/hdi_service/include/usbd_function.h +++ b/usb/hdi_service/include/usbd_function.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_HDI_USB_V1_0_USBD_FUNCTION_H -#define OHOS_HDI_USB_V1_0_USBD_FUNCTION_H +#ifndef OHOS_HDI_USB_V1_1_USBD_FUNCTION_H +#define OHOS_HDI_USB_V1_1_USBD_FUNCTION_H #include #include @@ -64,7 +64,7 @@ namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { class UsbdFunction { public: UsbdFunction() = default; @@ -91,11 +91,11 @@ private: static int32_t UsbdRegisterDevice(const std::string &serviceName); static int32_t InitMtp(); static int32_t ReleaseMtp(); - + static uint32_t currentFuncs_; }; -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS -#endif // OHOS_HDI_USB_V1_0_USBD_FUNCTION_H +#endif // OHOS_HDI_USB_V1_1_USBD_FUNCTION_H diff --git a/usb/hdi_service/include/usbd_load_usb_service.h b/usb/hdi_service/include/usbd_load_usb_service.h index 5637f7a9bc..ed1036a6b1 100644 --- a/usb/hdi_service/include/usbd_load_usb_service.h +++ b/usb/hdi_service/include/usbd_load_usb_service.h @@ -28,7 +28,7 @@ namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { class OnDemandLoadCallback : public SystemAbilityLoadCallbackStub { public: std::atomic_bool loading_ {false}; @@ -50,7 +50,7 @@ private: sptr loadCallback_ {nullptr}; int32_t saId_ {0}; }; -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS diff --git a/usb/hdi_service/include/usbd_port.h b/usb/hdi_service/include/usbd_port.h index 25ef2cb576..4b9f2b5696 100644 --- a/usb/hdi_service/include/usbd_port.h +++ b/usb/hdi_service/include/usbd_port.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_HDI_USB_V1_0_USBD_PORT_H -#define OHOS_HDI_USB_V1_0_USBD_PORT_H +#ifndef OHOS_HDI_USB_V1_1_USBD_PORT_H +#define OHOS_HDI_USB_V1_1_USBD_PORT_H #include #include @@ -43,21 +43,21 @@ #define PORT_MODE_DEVICE 1 #define PORT_MODE_HOST 2 -using OHOS::HDI::Usb::V1_0::PortInfo; +using OHOS::HDI::Usb::V1_1::PortInfo; -using OHOS::HDI::Usb::V1_0::IUsbdSubscriber; +using OHOS::HDI::Usb::V1_1::IUsbdSubscriber; namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { class UsbdPort { public: static UsbdPort &GetInstance(); int32_t SetPort(int32_t portId, int32_t powerRole, int32_t dataRole, UsbdSubscriber *usbdSubscribers, uint32_t len); int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode); - int32_t UpdatePort(int32_t mode, const sptr &subscriber); + int32_t UpdatePort(int32_t mode, const sptr &subscriber); void setPortPath(const std::string &path); private: @@ -73,11 +73,11 @@ private: int32_t WritePortFile(int32_t powerRole, int32_t dataRole, int32_t mode); int32_t ReadPortFile(int32_t &powerRole, int32_t &dataRole, int32_t &mode); int32_t SetPortInit(int32_t portId, int32_t powerRole, int32_t dataRole); - HDI::Usb::V1_0::PortInfo currentPortInfo_ = {DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE, PORT_MODE_DEVICE}; + HDI::Usb::V1_1::PortInfo currentPortInfo_ = {DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE, PORT_MODE_DEVICE}; std::string path_; }; -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS -#endif // OHOS_HDI_USB_V1_0_USBD_PORT_H +#endif // OHOS_HDI_USB_V1_1_USBD_PORT_H diff --git a/usb/hdi_service/src/usb_impl.cpp b/usb/hdi_service/src/usb_impl.cpp index 3581f5dacd..dbe9837c7a 100644 --- a/usb/hdi_service/src/usb_impl.cpp +++ b/usb/hdi_service/src/usb_impl.cpp @@ -42,7 +42,7 @@ constexpr double USB_RECOGNITION_FAIL_RATE_BASE = 100.00; namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { HdfDevEventlistener UsbImpl::listenerForLoadService_ = {nullptr}; UsbdLoadService UsbImpl::loadUsbService_ = {USB_SYSTEM_ABILITY_ID}; UsbdLoadService UsbImpl::loadHdfEdm_ = {HDF_EXTERNAL_DEVICE_MANAGER_SA_ID}; @@ -53,7 +53,7 @@ uint32_t UsbImpl::attachFailedCount_ = 0; extern "C" IUsbInterface *UsbInterfaceImplGetInstance(void) { - using OHOS::HDI::Usb::V1_0::UsbImpl; + using OHOS::HDI::Usb::V1_1::UsbImpl; UsbImpl *service = new (std::nothrow) UsbImpl(); if (service == nullptr) { return nullptr; @@ -1940,7 +1940,39 @@ int32_t UsbImpl::BulkCancel(const UsbDev &dev, const UsbPipe &pipe) list->cb = tcb; return HDF_SUCCESS; } -} // namespace V1_0 + +int32_t UsbImpl::GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool &unactivated) +{ + HostDevice *port = FindDevFromService(dev.busNum, dev.devAddr); + if (port == nullptr) { + HDF_LOGE("%{public}s:FindDevFromService failed", __func__); + return HDF_DEV_ERR_NO_DEVICE; + } + if (interfaceId >= USB_MAX_INTERFACES) { + HDF_LOGE("%{public}s:interfaceId larger then max num", __func__); + return HDF_ERR_INVALID_PARAM; + } + + unactivated = UsbGetInterfaceActiveStatus(port->service->session_, port->busNum, port->devAddr, interfaceId); + return HDF_SUCCESS; +} + +int32_t UsbImpl::GetDeviceSpeed(const UsbDev &dev, uint8_t &speed) +{ + HostDevice *port = FindDevFromService(dev.busNum, dev.devAddr); + if (port == nullptr) { + HDF_LOGE("%{public}s:FindDevFromService failed", __func__); + return HDF_DEV_ERR_NO_DEVICE; + } + UsbInterfaceHandleEntity *handle = reinterpret_cast(port->ctrDevHandle); + int32_t ret = RawUsbGetUsbSpeed(handle->devHandle); + speed = (uint8_t)ret; + HDF_LOGE("%{public}s:GetDeviceSpeed, speed=%{public}u", __func__, speed); + return HDF_SUCCESS; +} + + +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS diff --git a/usb/hdi_service/src/usb_interface_driver.cpp b/usb/hdi_service/src/usb_interface_driver.cpp index e50175c593..ff67398bc5 100644 --- a/usb/hdi_service/src/usb_interface_driver.cpp +++ b/usb/hdi_service/src/usb_interface_driver.cpp @@ -21,12 +21,12 @@ #include "hdf_usb_pnp_manage.h" #include "usb_impl.h" #include "usbd_dispatcher.h" -#include "v1_0/usb_interface_stub.h" +#include "v1_1/usb_interface_stub.h" #include "usbd_wrapper.h" #define HDF_LOG_TAG Usbd -using namespace OHOS::HDI::Usb::V1_0; +using namespace OHOS::HDI::Usb::V1_1; struct HdfUsbInterfaceHost { struct IDeviceIoService ioService; @@ -79,7 +79,7 @@ static int HdfUsbInterfaceDriverBind(struct HdfDeviceObject * const deviceObject hdfUsbInterfaceHost->ioService.Open = nullptr; hdfUsbInterfaceHost->ioService.Release = nullptr; - auto serviceImpl = IUsbInterface::Get(true); + auto serviceImpl = OHOS::HDI::Usb::V1_1::IUsbInterface::Get(true); if (serviceImpl == nullptr) { HDF_LOGE("%{public}s: failed to get of implement service", __func__); delete hdfUsbInterfaceHost; @@ -87,7 +87,8 @@ static int HdfUsbInterfaceDriverBind(struct HdfDeviceObject * const deviceObject } hdfUsbInterfaceHost->stub = - OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, IUsbInterface::GetDescriptor()); + OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, + OHOS::HDI::Usb::V1_1::IUsbInterface::GetDescriptor()); if (hdfUsbInterfaceHost->stub == nullptr) { HDF_LOGE("%{public}s: failed to get stub object", __func__); delete hdfUsbInterfaceHost; diff --git a/usb/hdi_service/src/usbd_dispatcher.cpp b/usb/hdi_service/src/usbd_dispatcher.cpp index 6f27a64dc0..3729f5498b 100644 --- a/usb/hdi_service/src/usbd_dispatcher.cpp +++ b/usb/hdi_service/src/usbd_dispatcher.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { int32_t UsbdDispatcher::UsbdAllocFifo(DataFifo *fifo, uint32_t size) { if (!DataFifoIsInitialized(fifo)) { @@ -1488,7 +1488,7 @@ int32_t UsbdDispatcher::UsbdBulkASyncReqReadSubmit(UsbdBulkASyncReqNode *db) } return ret; } -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS diff --git a/usb/hdi_service/src/usbd_function.cpp b/usb/hdi_service/src/usbd_function.cpp index f7aa971001..bc480b45a2 100644 --- a/usb/hdi_service/src/usbd_function.cpp +++ b/usb/hdi_service/src/usbd_function.cpp @@ -36,7 +36,7 @@ namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { uint32_t UsbdFunction::currentFuncs_ = USB_FUNCTION_HDC; using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; diff --git a/usb/hdi_service/src/usbd_load_usb_service.cpp b/usb/hdi_service/src/usbd_load_usb_service.cpp index f98fc13eca..4810ed6d0c 100644 --- a/usb/hdi_service/src/usbd_load_usb_service.cpp +++ b/usb/hdi_service/src/usbd_load_usb_service.cpp @@ -33,7 +33,7 @@ using namespace std; namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { OnDemandLoadCallback::OnDemandLoadCallback() {} void OnDemandLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) @@ -82,7 +82,7 @@ int32_t UsbdLoadService::LoadService() } return HDF_SUCCESS; } -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS diff --git a/usb/hdi_service/src/usbd_port.cpp b/usb/hdi_service/src/usbd_port.cpp index 4d749fd284..360720ad85 100644 --- a/usb/hdi_service/src/usbd_port.cpp +++ b/usb/hdi_service/src/usbd_port.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace HDI { namespace Usb { -namespace V1_0 { +namespace V1_1 { UsbdPort &UsbdPort::GetInstance() { static UsbdPort instance; @@ -228,7 +228,7 @@ int32_t UsbdPort::UpdatePort(int32_t mode, const sptr &subscrib subscriber->PortChangedEvent(currentPortInfo_); return HDF_SUCCESS; } -} // namespace V1_0 +} // namespace V1_1 } // namespace Usb } // namespace HDI } // namespace OHOS diff --git a/usb/interfaces/ddk/host/usb_ddk_interface.h b/usb/interfaces/ddk/host/usb_ddk_interface.h index 58a513346b..0cf161ef79 100644 --- a/usb/interfaces/ddk/host/usb_ddk_interface.h +++ b/usb/interfaces/ddk/host/usb_ddk_interface.h @@ -489,7 +489,7 @@ int32_t UsbFillRequestByMmap( const struct UsbRequest *request, const UsbInterfaceHandle *interfaceHandle, const struct UsbRequestParams *params); /** * @brief Cancels an asynchronous USB request. - + * @param request Indicates the pointer to the USB request. * * @return Returns UsbInterfaceHandle if the operation is successful; returns NULL otherwise. @@ -509,6 +509,8 @@ int32_t UsbMemTestTrigger(bool enable); int32_t GetInterfaceByHandle(const UsbInterfaceHandle *interfaceHandle, struct UsbInterface **interface); int32_t UsbGetInterfaceSetting(const UsbInterfaceHandle *interfaceHandle, uint8_t *settingIndex); int32_t UsbGetDeviceMemMapFd(const struct UsbSession *session, uint8_t busNum, uint8_t usbAddr); +bool UsbGetInterfaceActiveStatus(const struct UsbSession *session, uint8_t busNum, uint8_t usbAddr, + uint8_t interfaceIndex); #ifdef __cplusplus } #endif diff --git a/usb/test/benchmarktest/BUILD.gn b/usb/test/benchmarktest/BUILD.gn index e80deab263..69f353572f 100644 --- a/usb/test/benchmarktest/BUILD.gn +++ b/usb/test/benchmarktest/BUILD.gn @@ -25,7 +25,7 @@ ohos_benchmarktest("hdf_usb_benchmark_function_test") { sources = [ "usb_benchmark_function_test.cpp" ] deps = [ - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/benchmark", "//third_party/googletest:gtest_main", ] @@ -56,7 +56,7 @@ ohos_benchmarktest("hdf_usb_benchmark_device_test") { ] deps = [ - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/benchmark", "//third_party/googletest:gtest_main", ] @@ -87,7 +87,7 @@ ohos_benchmarktest("hdf_usb_benchmark_request_test") { ] deps = [ - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/benchmark", "//third_party/googletest:gtest_main", ] @@ -118,7 +118,7 @@ ohos_benchmarktest("hdf_usb_benchmark_transfer_test") { ] deps = [ - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/benchmark", "//third_party/googletest:gtest_main", ] diff --git a/usb/test/fuzztest/usb_fuzzer/BUILD.gn b/usb/test/fuzztest/usb_fuzzer/BUILD.gn index 685e583fb0..f2383bef59 100644 --- a/usb/test/fuzztest/usb_fuzzer/BUILD.gn +++ b/usb/test/fuzztest/usb_fuzzer/BUILD.gn @@ -32,7 +32,7 @@ ohos_fuzztest("UsbFuzzTest") { external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_stub_1.0", + "drivers_interface_usb:libusb_stub_1.1", "hdf_core:libhdf_utils", "hdf_core:libhdi", "hilog:libhilog", diff --git a/usb/test/unittest/hal/BUILD.gn b/usb/test/unittest/hal/BUILD.gn index fdbb54dae4..d09efbee52 100644 --- a/usb/test/unittest/hal/BUILD.gn +++ b/usb/test/unittest/hal/BUILD.gn @@ -38,13 +38,13 @@ ohos_unittest("test_transfer") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_proxy_1.0", + "drivers_interface_usb:libusb_proxy_1.1", "eventhandler:libeventhandler", "hdf_core:libhdf_utils", "hilog:libhilog", @@ -69,13 +69,13 @@ ohos_unittest("test_device") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_proxy_1.0", + "drivers_interface_usb:libusb_proxy_1.1", "eventhandler:libeventhandler", "hdf_core:libhdf_utils", "hilog:libhilog", @@ -93,13 +93,13 @@ ohos_unittest("test_function") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_proxy_1.0", + "drivers_interface_usb:libusb_proxy_1.1", "eventhandler:libeventhandler", "hdf_core:libhdf_host", "hdf_core:libhdf_utils", @@ -127,13 +127,13 @@ ohos_unittest("test_request") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_proxy_1.0", + "drivers_interface_usb:libusb_proxy_1.1", "eventhandler:libeventhandler", "hdf_core:libhdf_utils", "hilog:libhilog", @@ -152,13 +152,13 @@ ohos_unittest("test_usbfnmtp") { deps = [ "${usb_driver_path}/ddk:libusb_core", "${usb_driver_path}/gadget/function/mtp:libusbfn_mtp_interface_service_1.0", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_proxy_1.0", + "drivers_interface_usb:libusb_proxy_1.1", "drivers_interface_usb:libusbfn_mtp_proxy_1.0", "eventhandler:libeventhandler", "hdf_core:libhdf_host", @@ -181,13 +181,42 @@ ohos_unittest("test_manageinterface") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", - "drivers_interface_usb:libusb_proxy_1.0", + "drivers_interface_usb:libusb_proxy_1.1", + "eventhandler:libeventhandler", + "hdf_core:libhdf_utils", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + module_out_path = module_output_path +} + +ohos_unittest("test_devicestatus") { + sources = [ + "${usb_driver_path}/test/UsbSubscriberTest/UsbSubscriberTest.cpp", + "src/usbd_device_status_test.cpp", + ] + + include_dirs = [ "${usb_driver_path}/test/UsbSubscriberTest" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${usb_driver_path}/ddk:libusb_core", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "drivers_interface_usb:libusb_proxy_1.1", "eventhandler:libeventhandler", "hdf_core:libhdf_utils", "hilog:libhilog", diff --git a/usb/test/unittest/hal/include/usbd_device_status_test.h b/usb/test/unittest/hal/include/usbd_device_status_test.h new file mode 100644 index 0000000000..9de0f8cfca --- /dev/null +++ b/usb/test/unittest/hal/include/usbd_device_status_test.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-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. + */ +#ifndef USBD_DEVICE_STATUS_TEST_H +#define USBD_DEVICE_STATUS_TEST_H + +#include +#include "UsbSubscriberTest.h" +#include "v1_0/iusbd_subscriber.h" +#include "v1_0/usb_types.h" + +using OHOS::HDI::Usb::V1_0::UsbDev; +namespace OHOS { +namespace USB { +class UsbdDeviceStatusTest: public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + + static UsbDev dev_; + static OHOS::sptr subscriber_; +}; +} // USB +} // OHOS +#endif // USBD_MANAGE_INTERFACE_TEST_H \ No newline at end of file diff --git a/usb/test/unittest/hal/src/usbd_device_status_test.cpp b/usb/test/unittest/hal/src/usbd_device_status_test.cpp new file mode 100644 index 0000000000..88ec17b971 --- /dev/null +++ b/usb/test/unittest/hal/src/usbd_device_status_test.cpp @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2021-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. + */ + +#include "usbd_device_status_test.h" + +#include +#include + +#include "UsbSubscriberTest.h" +#include "hdf_log.h" +#include "usbd_type.h" +#include "v1_1/iusb_interface.h" + +const int SLEEP_TIME = 3; +const uint8_t BUS_NUM_INVALID = 255; +const uint8_t DEV_ADDR_INVALID = 255; +const uint8_t INTERFACEID_OK = 1; +const uint8_t INTERFACEID_OK_NEW = 0; +const uint8_t INTERFACEID_INVALID = 255; + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::USB; +using namespace std; +using namespace OHOS::HDI::Usb::V1_1; +namespace OHOS { +namespace USB { +UsbDev UsbdDeviceStatusTest::dev_ = {0, 0}; +sptr UsbdDeviceStatusTest::subscriber_ = nullptr; +sptr g_usbInterface = nullptr; + +int32_t SwitchErrCode(int32_t ret) +{ + return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret; +} + +void UsbdDeviceStatusTest::SetUpTestCase(void) +{ + g_usbInterface = OHOS::HDI::Usb::V1_1::IUsbInterface::Get(); + if (g_usbInterface == nullptr) { + HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__); + exit(0); + } + auto ret = g_usbInterface->SetPortRole(1, 1, 1); + sleep(SLEEP_TIME); + HDF_LOGI("UsbdDeviceStatusTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret); + ret = SwitchErrCode(ret); + ASSERT_EQ(0, ret); + if (ret != 0) { + exit(0); + } + + subscriber_ = new UsbSubscriberTest(); + if (g_usbInterface->BindUsbdSubscriber(subscriber_) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: bind usbd subscriber_ failed", __func__); + exit(0); + } + + std::cout << "please connect device, press enter to continue" << std::endl; + int c; + while ((c = getchar()) != '\n' && c != EOF) {} + dev_ = {subscriber_->busNum_, subscriber_->devAddr_}; + + ret = g_usbInterface->OpenDevice(dev_); + HDF_LOGI("UsbdDeviceStatusTest::%{public}d OpenDevice=%{public}d", __LINE__, ret); + ASSERT_EQ(0, ret); +} + +void UsbdDeviceStatusTest::TearDownTestCase(void) +{ + g_usbInterface->UnbindUsbdSubscriber(subscriber_); + dev_ = {subscriber_->busNum_, subscriber_->devAddr_}; + auto ret = g_usbInterface->CloseDevice(dev_); + HDF_LOGI("UsbdDeviceStatusTest::%{public}d Close=%{public}d", __LINE__, ret); + ASSERT_EQ(0, ret); +} + +void UsbdDeviceStatusTest::SetUp(void) {} + +void UsbdDeviceStatusTest::TearDown(void) {} + +/** + * @tc.name: UsbdGetDeviceSpeed001 + * @tc.desc: Test functions to GetDeviceSpeed + * @tc.desc: int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed); + * @tc.desc: Positive test: parameters correctly + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed001, TestSize.Level1) +{ + struct UsbDev dev = dev_; + int32_t ret = -1; + uint8_t speed = 0; + ret = g_usbInterface->GetDeviceSpeed(dev, speed); + HDF_LOGI("UsbdGetDeviceSpeed001 %{public}d GetDeviceSpeed=%{public}d, speed=%{public}d", __LINE__, ret, speed); + ASSERT_EQ(0, ret); +} + +/** + * @tc.name: UsbdGetDeviceSpeed002 + * @tc.desc: Test functions to GetDeviceSpeed + * @tc.desc: int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed); + * @tc.desc: Negative test: parameters exception, busNum error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed002, TestSize.Level1) +{ + struct UsbDev dev = dev_; + dev.busNum = BUS_NUM_INVALID; + uint8_t speed = 0; + auto ret = g_usbInterface->GetDeviceSpeed(dev, speed); + HDF_LOGI("UsbdGetDeviceSpeed002 %{public}d ret=%{public}d, speed=%{public}d", __LINE__, ret, speed); + ASSERT_NE(ret, 0); +} + + +/** + * @tc.name: UsbdGetDeviceSpeed003 + * @tc.desc: Test functions to GetDeviceSpeed + * @tc.desc: int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed); + * @tc.desc: Negative test: parameters exception, devAddr error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed003, TestSize.Level1) +{ + struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID}; + uint8_t speed = 0; + auto ret = g_usbInterface->GetDeviceSpeed(dev, speed); + HDF_LOGI("UsbdGetDeviceSpeed003 %{public}d, ret=%{public}d, speed=%{public}d", __LINE__, ret, speed); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: UsbdGetDeviceSpeed004 + * @tc.desc: Test functions to GetDeviceSpeed + * @tc.desc: int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed); + * @tc.desc: Negative test: parameters exception, busNum && devAddr error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed004, TestSize.Level1) +{ + uint8_t speed = 0; + struct UsbDev dev = {BUS_NUM_INVALID, DEV_ADDR_INVALID}; + auto ret = g_usbInterface->GetDeviceSpeed(dev, speed); + HDF_LOGI("UsbdGetDeviceSpeed004 %{public}d, ret=%{public}d, speed=%{public}d", __LINE__, ret, speed); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: UsbdGetInterfaceActiveStatus001 + * @tc.desc: Test functions to GetInterfaceActiveStatus + * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived); + * @tc.desc: Positive test: parameters correctly + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus001, TestSize.Level1) +{ + uint8_t interfaceId = INTERFACEID_OK_NEW; + struct UsbDev dev = dev_; + int32_t ret = -1; + bool unactived = 1; + for (; interfaceId < INTERFACEID_INVALID; interfaceId++) { + ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived); + if (ret == 0) { + break; + } + } + HDF_LOGI("UsbdGetInterfaceActiveStatus001 %{public}d GetInterfaceActiveStatus=%{public}d, unactived=%{public}d", + __LINE__, ret,unactived); + ASSERT_EQ(0, ret); +} + +/** + * @tc.name: UsbdGetInterfaceActiveStatus002 + * @tc.desc: Test functions to GetInterfaceActiveStatus + * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived); + * @tc.desc: Negative test: parameters exception, busNum error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus002, TestSize.Level1) +{ + uint8_t interfaceId = INTERFACEID_OK; + struct UsbDev dev = dev_; + dev.busNum = BUS_NUM_INVALID; + bool unactived = 1; + auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived); + HDF_LOGI("UsbdGetInterfaceActiveStatus002 %{public}d ret=%{public}d, unactived=%{public}d", + __LINE__, ret, unactived); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: UsbdGetInterfaceActiveStatus003 + * @tc.desc: Test functions to GetInterfaceActiveStatus + * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived); + * @tc.desc: Negative test: parameters exception, devAddr error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus003, TestSize.Level1) +{ + uint8_t interfaceId = INTERFACEID_OK; + struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID}; + bool unactived = 1; + auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived); + HDF_LOGI("UsbdGetInterfaceActiveStatus003 %{public}d, ret=%{public}d, unactived=%{public}d", + __LINE__, ret, unactived); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: UsbdGetInterfaceActiveStatus004 + * @tc.desc: Test functions to GetInterfaceActiveStatus + * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived); + * @tc.desc: Negative test: parameters exception, interfaceid error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus004, TestSize.Level1) +{ + uint8_t interfaceId = INTERFACEID_OK; + struct UsbDev dev = dev_; + interfaceId = INTERFACEID_INVALID; + bool unactived = 1; + auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived); + HDF_LOGI("UsbdGetInterfaceActiveStatus004 %{public}d, ret=%{public}d, unactived=%{public}d", + __LINE__, ret, unactived); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: UsbdGetInterfaceActiveStatus005 + * @tc.desc: Test functions to GetInterfaceActiveStatus + * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived); + * @tc.desc: Negative test: parameters exception, busNum && devAddr error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus005, TestSize.Level1) +{ + uint8_t interfaceId = INTERFACEID_OK; + bool unactived = 1; + struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID}; + auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived); + HDF_LOGI("UsbdGetInterfaceActiveStatus005 %{public}d, ret=%{public}d, unactived=%{public}d", + __LINE__, ret, unactived); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: UsbdGetInterfaceActiveStatus006 + * @tc.desc: Test functions to GetInterfaceActiveStatus + * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived); + * @tc.desc: Negative test: parameters exception, busNum && interfaceid error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus006, TestSize.Level1) +{ + uint8_t interfaceId = INTERFACEID_INVALID; + bool unactived = 1; + struct UsbDev dev = {BUS_NUM_INVALID, dev_.devAddr}; + auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived); + HDF_LOGI("UsbdGetInterfaceActiveStatus006 %{public}d, ret=%{public}d, unactived=%{public}d", + __LINE__, ret, unactived); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: UsbdGetInterfaceActiveStatus007 + * @tc.desc: Test functions to GetInterfaceActiveStatus + * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived); + * @tc.desc: Negative test: parameters exception, devAddr && interfaceid error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus007, TestSize.Level1) +{ + uint8_t interfaceId = INTERFACEID_INVALID; + bool unactived = 1; + struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID}; + auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived); + HDF_LOGI("UsbdGetInterfaceActiveStatus007 %{public}d, ret=%{public}d, unactived=%{public}d", + __LINE__, ret, unactived); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: UsbdGetInterfaceActiveStatus008 + * @tc.desc: Test functions to GetInterfaceActiveStatus + * @tc.desc: int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived); + * @tc.desc: Negative test: parameters exception, busNum && devAddr && interfaceid error + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus008, TestSize.Level1) +{ + uint8_t interfaceId = INTERFACEID_INVALID; + bool unactived = 1; + struct UsbDev dev = {BUS_NUM_INVALID, DEV_ADDR_INVALID}; + auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived); + HDF_LOGI("UsbdGetInterfaceActiveStatus008 %{public}d, ret=%{public}d, unactived=%{public}d", + __LINE__, ret, unactived); + ASSERT_NE(ret, 0); +} + +} // USB +} // OHOS \ No newline at end of file diff --git a/usb/test/unittest/mock/BUILD.gn b/usb/test/unittest/mock/BUILD.gn index a90bcd2e6c..73e5f2fcbc 100644 --- a/usb/test/unittest/mock/BUILD.gn +++ b/usb/test/unittest/mock/BUILD.gn @@ -40,7 +40,7 @@ ohos_unittest("transfer_auto_test") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -74,7 +74,7 @@ ohos_unittest("device_auto_test") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -102,7 +102,7 @@ ohos_unittest("request_auto_test") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -127,7 +127,7 @@ ohos_unittest("function_auto_test") { deps = [ "${usb_driver_path}/ddk:libusb_core", - "${usb_driver_path}/hdi_service:libusb_interface_service_1.0", + "${usb_driver_path}/hdi_service:libusb_interface_service_1.1", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] -- Gitee From 1f24d9928c3eb20d6cddfe5239fbd20816a244f9 Mon Sep 17 00:00:00 2001 From: dufresne_andy Date: Fri, 15 Mar 2024 22:19:40 +0800 Subject: [PATCH 2/3] Description:slove inconsistent parts Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: dufresne_andy --- usb/hdf_usb/include/hdf_usb_net_manager.h | 72 ++++++++++++++ usb/hdf_usb/include/hdf_usb_pnp_manage.h | 109 ++++++++++++++++++++++ usb/hdf_usb/include/usb_ddk_pnp_loader.h | 79 ++++++++++++++++ usb/hdf_usb/include/usb_pnp_manager.h | 27 ++++++ usb/hdf_usb/include/usb_wrapper.h | 22 +++++ usb/hdi_service/BUILD.gn | 2 +- 6 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 usb/hdf_usb/include/hdf_usb_net_manager.h create mode 100644 usb/hdf_usb/include/hdf_usb_pnp_manage.h create mode 100644 usb/hdf_usb/include/usb_ddk_pnp_loader.h create mode 100644 usb/hdf_usb/include/usb_pnp_manager.h create mode 100644 usb/hdf_usb/include/usb_wrapper.h diff --git a/usb/hdf_usb/include/hdf_usb_net_manager.h b/usb/hdf_usb/include/hdf_usb_net_manager.h new file mode 100644 index 0000000000..652b579151 --- /dev/null +++ b/usb/hdf_usb/include/hdf_usb_net_manager.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 Archermind Technology (Nanjing) Co. Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef HDF_USB_NET_MANAGE_H +#define HDF_USB_NET_MANAGE_H + +#include "hdf_base.h" +#include "hdf_device_desc.h" + + +#define MAC_ADDR_SIZE 6 +#define IFNAMSIZ 16 + +/* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */ +#define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */ +#define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */ +#define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */ + +#define HDF_FLAG_NO_SETINT 0x0010 /* device can't set_interface() */ +#define HDF_FLAG_ETHER 0x0020 /* maybe use "eth%d" names */ + +#define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */ +#define FLAG_WLAN 0x0080 /* use "wlan%d" names */ +#define FLAG_AVOID_UNLINK_URBS 0x0100 /* don't unlink urbs at usbnet_stop() */ +#define FLAG_SEND_ZLP 0x0200 /* hw requires ZLPs are sent */ +#define FLAG_WWAN 0x0400 /* use "wwan%d" names */ + +#define FLAG_LINK_INTR 0x0800 /* updates link (carrier) status */ +#define HDF_FLAG_POINTTOPOINT 0x1000 /* possibly use "usb%d" names */ + +/* + * Indicates to usbnet, that USB driver accumulates multiple IP packets. + * Affects statistic (counters) and short packet handling. + */ +#define FLAG_MULTI_PACKET 0x2000 +#define FLAG_RX_ASSEMBLE 0x4000 /* rx packets may span >1 frames */ +#define FLAG_NOARP 0x8000 /* device can't do ARP */ + +enum UsbnetServiceCmd { + USB_NET_REGISTER_NET, + USB_NET_CLOSE_NET, + USB_NET_SEND_DATA_TO_USB, + USB_NET_RECIVE_DATA_FROM_USB, + USB_NET_OPEN_USB, + USB_NET_CLOSE_USB, + USB_NET_UPDATE_FLAGS, + USB_NET_UPDATE_MAXQLEN +}; + +struct UsbnetTransInfo { + uint8_t isBindDevice; + char name[IFNAMSIZ]; /**< Network device name {@link IFNAMSIZ} */ + uint8_t isGetmacAddr; + uint8_t macAddr[MAC_ADDR_SIZE]; /**< MAC address {@link MAC_ADDR_SIZE} */ + uint32_t flags; /**< Network port status */ + uint32_t mtu; /**< Maximum transmission unit */ + uint16_t hardHeaderLen; /**< Header length */ + uint8_t link; + uint8_t needReset; + uint32_t usbFlags; /**< usb device match flags */ + uint32_t rxUrbSize; /* size for rx urbs */ + uint32_t hardMtu; /* count any extra framing */ + uint32_t maxpacket; + int txQlen; +}; + +#endif \ No newline at end of file diff --git a/usb/hdf_usb/include/hdf_usb_pnp_manage.h b/usb/hdf_usb/include/hdf_usb_pnp_manage.h new file mode 100644 index 0000000000..943707dda9 --- /dev/null +++ b/usb/hdf_usb/include/hdf_usb_pnp_manage.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef HDF_USB_PNP_MANAGE_H +#define HDF_USB_PNP_MANAGE_H + +#include "hdf_base.h" + +#define USB_PNP_NOTIFY_TEST_MODE false +#define USB_PNP_INFO_MAX_INTERFACES 32 + +enum UsbPnpNotifyServiceCmd { + USB_PNP_NOTIFY_ADD_INTERFACE, + USB_PNP_NOTIFY_REMOVE_INTERFACE, + USB_PNP_NOTIFY_REPORT_INTERFACE, + USB_PNP_NOTIFY_ADD_DEVICE, + USB_PNP_NOTIFY_REMOVE_DEVICE, + #if USB_PNP_NOTIFY_TEST_MODE == true + USB_PNP_NOTIFY_ADD_TEST, + USB_PNP_NOTIFY_REMOVE_TEST, + #endif + USB_PNP_DRIVER_REGISTER_DEVICE, + USB_PNP_DRIVER_UNREGISTER_DEVICE, + USB_PNP_DRIVER_GETDEVICES = 20, + USB_PNP_DRIVER_GADGET_ADD = 30, + USB_PNP_DRIVER_GADGET_REMOVE, + USB_PNP_DRIVER_PORT_HOST = 40, + USB_PNP_DRIVER_PORT_DEVICE, + USB_PNP_DRIVER_GET_GADGET_LINK_STATUS, +}; + +enum UsbPnpNotifyRemoveType { + USB_PNP_NOTIFY_REMOVE_BUS_DEV_NUM, + USB_PNP_NOTIFY_REMOVE_INTERFACE_NUM, +}; + +enum { + USB_PNP_NOTIFY_MATCH_VENDOR = 0x0001, + USB_PNP_NOTIFY_MATCH_PRODUCT = 0x0002, + USB_PNP_NOTIFY_MATCH_DEV_LOW = 0x0004, + USB_PNP_NOTIFY_MATCH_DEV_HIGH = 0x0008, + USB_PNP_NOTIFY_MATCH_DEV_CLASS = 0x0010, + USB_PNP_NOTIFY_MATCH_DEV_SUBCLASS = 0x0020, + USB_PNP_NOTIFY_MATCH_DEV_PROTOCOL = 0x0040, + USB_PNP_NOTIFY_MATCH_INT_CLASS = 0x0080, + USB_PNP_NOTIFY_MATCH_INT_SUBCLASS = 0x0100, + USB_PNP_NOTIFY_MATCH_INT_PROTOCOL = 0x0200, + USB_PNP_NOTIFY_MATCH_INT_NUMBER = 0x0400, +}; + +struct UsbPnpNotifyServiceInfo { + uint8_t curInterfaceNumber; + uint32_t length; + + int32_t devNum; + int32_t busNum; + + int32_t interfaceLength; + uint8_t interfaceNumber[USB_PNP_INFO_MAX_INTERFACES]; +} __attribute__ ((packed)); + +struct UsbPnpNotifyInterfaceInfo { + uint8_t interfaceClass; + uint8_t interfaceSubClass; + uint8_t interfaceProtocol; + + uint8_t interfaceNumber; +}; + +struct UsbPnpNotifyDeviceInfo { + uint16_t vendorId; + uint16_t productId; + + uint16_t bcdDeviceLow; + uint16_t bcdDeviceHigh; + + uint8_t deviceClass; + uint8_t deviceSubClass; + uint8_t deviceProtocol; +}; + +struct UsbPnpNotifyMatchInfoTable { + uint64_t usbDevAddr; + int32_t devNum; + int32_t busNum; + + struct UsbPnpNotifyDeviceInfo deviceInfo; + + uint8_t removeType; + uint8_t numInfos; + + struct UsbPnpNotifyInterfaceInfo interfaceInfo[USB_PNP_INFO_MAX_INTERFACES]; +}; + +struct UsbPnpAddRemoveInfo { + int32_t devNum; + int32_t busNum; + uint8_t interfaceNumber; + uint8_t interfaceClass; + uint8_t interfaceSubClass; + uint8_t interfaceProtocol; +}; + +#endif /* HDF_USB_PNP_MANAGE_H */ diff --git a/usb/hdf_usb/include/usb_ddk_pnp_loader.h b/usb/hdf_usb/include/usb_ddk_pnp_loader.h new file mode 100644 index 0000000000..02e0575230 --- /dev/null +++ b/usb/hdf_usb/include/usb_ddk_pnp_loader.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef USB_DDK_PNP_LOADER_H +#define USB_DDK_PNP_LOADER_H + +#include "hdf_dlist.h" +#include "hdf_sbuf.h" +#include "hdf_usb_pnp_manage.h" + +typedef enum { USB_PNP_NORMAL_STATUS, USB_PNP_ADD_STATUS, USB_PNP_REMOVE_STATUS } UsbPnpDriverStatus; + +struct UsbPnpMatchIdTable { + const char *moduleName; + const char *serviceName; + const char *deviceMatchAttr; + + int32_t interfaceClassLength; + uint32_t interfaceClassMask; + int32_t interfaceSubClassLength; + uint32_t interfaceSubClassMask; + int32_t interfaceProtocolLength; + uint32_t interfaceProtocolMask; + int32_t interfaceLength; + uint32_t interfaceMask; + + uint8_t pnpMatchFlag; + + uint8_t length; + + uint16_t matchFlag; + + uint16_t vendorId; + uint16_t productId; + + uint16_t bcdDeviceLow; + uint16_t bcdDeviceHigh; + + uint8_t deviceClass; + uint8_t deviceSubClass; + uint8_t deviceProtocol; + + uint8_t interfaceClass[USB_PNP_INFO_MAX_INTERFACES]; + uint8_t interfaceSubClass[USB_PNP_INFO_MAX_INTERFACES]; + uint8_t interfaceProtocol[USB_PNP_INFO_MAX_INTERFACES]; + + uint8_t interfaceNumber[USB_PNP_INFO_MAX_INTERFACES]; +}; + +struct UsbPnpDeviceListTable { + struct DListHead list; + const char *moduleName; + const char *serviceName; + const char *deviceMatchAttr; + UsbPnpDriverStatus status; + uint64_t usbDevAddr; + int32_t devNum; + int32_t busNum; + int32_t interfaceLength; + uint8_t interfaceNumber[USB_PNP_INFO_MAX_INTERFACES]; +}; + +struct UsbPnpRemoveInfo { + uint8_t removeType; + uint64_t usbDevAddr; + int32_t devNum; + int32_t busNum; + uint8_t interfaceNum; +}; + +int32_t UsbDdkPnpLoaderEventReceived(void *usbPnpManagerPtr, uint32_t id, struct HdfSBuf *data); +int32_t UsbDdkPnpLoaderEventHandle(void); + +#endif /* USB_DDK_PNP_LOADER_H */ diff --git a/usb/hdf_usb/include/usb_pnp_manager.h b/usb/hdf_usb/include/usb_pnp_manager.h new file mode 100644 index 0000000000..9c5a25791d --- /dev/null +++ b/usb/hdf_usb/include/usb_pnp_manager.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef USB_PNP_MANAGE_H +#define USB_PNP_MANAGE_H + +#include "hdf_base.h" +#include "hdf_sbuf.h" + +struct UsbPnpManagerDeviceInfo { + struct HdfDeviceObject *usbPnpManager; + const char *moduleName; + const char *serviceName; + const char *deviceMatchAttr; + const void *privateData; + bool isReg; +}; + +bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName); +int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo); + +#endif /* USB_PNP_MANAGE_H */ diff --git a/usb/hdf_usb/include/usb_wrapper.h b/usb/hdf_usb/include/usb_wrapper.h new file mode 100644 index 0000000000..e8128001f7 --- /dev/null +++ b/usb/hdf_usb/include/usb_wrapper.h @@ -0,0 +1,22 @@ + /* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef USB_WRAPPER_H +#define USB_WRAPPER_H +#include "hdf_base.h" + +#ifdef __cplusplus +extern "C" { +#endif +#ifndef __LITEOS__ +void UsbDDKDriverMatchFailEvent(const struct UsbPnpNotifyMatchInfoTable *infoTable); +#endif +#ifdef __cplusplus +}; +#endif +#endif diff --git a/usb/hdi_service/BUILD.gn b/usb/hdi_service/BUILD.gn index bde4e2c84a..f6bff297a7 100644 --- a/usb/hdi_service/BUILD.gn +++ b/usb/hdi_service/BUILD.gn @@ -27,7 +27,7 @@ config("usbd_public_config") { "${usb_driver_path}/interfaces/ddk/common", "${usb_driver_path}/gadget/function/include", "${usb_driver_path}/gadget/function/mtp/include", - "./../../../hdf_core/framework/model/usb/include", + "${usb_driver_path}/hdf_usb/include", "${usb_driver_path}/hdi_service", "${usb_driver_path}/interfaces/ddk/common/include", "${usb_driver_path}/interfaces/ddk/device", -- Gitee From 61bf9590f01e2bd4bf7a32a73b49a07aed0cbd97 Mon Sep 17 00:00:00 2001 From: dufresne_andy Date: Fri, 15 Mar 2024 22:21:54 +0800 Subject: [PATCH 3/3] Description:slove inconsistent parts Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: dufresne_andy --- usb/hdf_usb/include/hdf_usb_pnp_manage.h | 2 +- usb/hdf_usb/include/usb_ddk_pnp_loader.h | 2 +- usb/hdf_usb/include/usb_pnp_manager.h | 2 +- usb/hdf_usb/include/usb_wrapper.h | 8 ++++---- usb/test/unittest/hal/include/usbd_device_status_test.h | 2 +- usb/test/unittest/hal/src/usbd_device_status_test.cpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/usb/hdf_usb/include/hdf_usb_pnp_manage.h b/usb/hdf_usb/include/hdf_usb_pnp_manage.h index 943707dda9..5e64e1b0f1 100644 --- a/usb/hdf_usb/include/hdf_usb_pnp_manage.h +++ b/usb/hdf_usb/include/hdf_usb_pnp_manage.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/usb/hdf_usb/include/usb_ddk_pnp_loader.h b/usb/hdf_usb/include/usb_ddk_pnp_loader.h index 02e0575230..4e0f733b7b 100644 --- a/usb/hdf_usb/include/usb_ddk_pnp_loader.h +++ b/usb/hdf_usb/include/usb_ddk_pnp_loader.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023 Huawei Device Co., Ltd. + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/usb/hdf_usb/include/usb_pnp_manager.h b/usb/hdf_usb/include/usb_pnp_manager.h index 9c5a25791d..32dfe58adb 100644 --- a/usb/hdf_usb/include/usb_pnp_manager.h +++ b/usb/hdf_usb/include/usb_pnp_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/usb/hdf_usb/include/usb_wrapper.h b/usb/hdf_usb/include/usb_wrapper.h index e8128001f7..6926adbb09 100644 --- a/usb/hdf_usb/include/usb_wrapper.h +++ b/usb/hdf_usb/include/usb_wrapper.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. * See the LICENSE file in the root of this repository for complete details. */ - + #ifndef USB_WRAPPER_H #define USB_WRAPPER_H #include "hdf_base.h" @@ -13,9 +13,9 @@ #ifdef __cplusplus extern "C" { #endif -#ifndef __LITEOS__ +#ifndef __LITEOS__ void UsbDDKDriverMatchFailEvent(const struct UsbPnpNotifyMatchInfoTable *infoTable); -#endif +#endif #ifdef __cplusplus }; #endif diff --git a/usb/test/unittest/hal/include/usbd_device_status_test.h b/usb/test/unittest/hal/include/usbd_device_status_test.h index 9de0f8cfca..3b9aaf8cc4 100644 --- a/usb/test/unittest/hal/include/usbd_device_status_test.h +++ b/usb/test/unittest/hal/include/usbd_device_status_test.h @@ -23,7 +23,7 @@ using OHOS::HDI::Usb::V1_0::UsbDev; namespace OHOS { namespace USB { -class UsbdDeviceStatusTest: public testing::Test { +class UsbdDeviceStatusTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); diff --git a/usb/test/unittest/hal/src/usbd_device_status_test.cpp b/usb/test/unittest/hal/src/usbd_device_status_test.cpp index 88ec17b971..b839f7743f 100644 --- a/usb/test/unittest/hal/src/usbd_device_status_test.cpp +++ b/usb/test/unittest/hal/src/usbd_device_status_test.cpp @@ -178,7 +178,7 @@ HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus001, TestSize.Level1) } } HDF_LOGI("UsbdGetInterfaceActiveStatus001 %{public}d GetInterfaceActiveStatus=%{public}d, unactived=%{public}d", - __LINE__, ret,unactived); + __LINE__, ret, unactived); ASSERT_EQ(0, ret); } -- Gitee