diff --git a/usb/ddk/BUILD.gn b/usb/ddk/BUILD.gn old mode 100755 new mode 100644 index 0aeb6338a7a9f0fb6c39379a8c9a925606ab4f35..c5edb670810a7f79573dbd257b9261e7e25b02e3 --- a/usb/ddk/BUILD.gn +++ b/usb/ddk/BUILD.gn @@ -18,6 +18,7 @@ group("libusb_core") { deps = [ ":libusb_ddk_device", ":libusb_ddk_host", + ":libusb_pnp_manager", ] } @@ -53,6 +54,28 @@ ohos_shared_library("libusb_ddk_host") { subsystem_name = "hdf" } +ohos_shared_library("libusb_pnp_manager") { + include_dirs = [ "$hdf_framework_path/model/usb/include" ] + sources = [ + "$hdf_framework_path/model/usb/src/usb_ddk_pnp_loader.c", + "host/src/usb_pnp_manager.c", + ] + + deps = [ + "$hdf_uhdf_path/host:libhdf_host", + "$hdf_uhdf_path/utils:libhdf_utils", + "//utils/native/base:utils", + ] + + if (is_standard_system) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } else { + external_deps = [ "hilog:libhilog" ] + } + + subsystem_name = "hdf" +} + ohos_shared_library("libusb_ddk_device") { include_dirs = [ "device/include", diff --git a/usb/ddk/device/src/usbfn_cfg_mgr.c b/usb/ddk/device/src/usbfn_cfg_mgr.c index 7aa917bd31f4c0a695a0a0ab4e4e006aa1472237..2088a9b02f93257719dcb83e424876d690116672 100755 --- a/usb/ddk/device/src/usbfn_cfg_mgr.c +++ b/usb/ddk/device/src/usbfn_cfg_mgr.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include "usbfn_dev_mgr.h" diff --git a/usb/ddk/host/src/usb_pnp_manager.c b/usb/ddk/host/src/usb_pnp_manager.c new file mode 100644 index 0000000000000000000000000000000000000000..0dd8eb61b003b2dffbd9d6a7f16f16742b5e4e86 --- /dev/null +++ b/usb/ddk/host/src/usb_pnp_manager.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2021 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 "usb_pnp_manager.h" +#include "devsvc_manager_clnt.h" +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "hdf_io_service_if.h" +#include "hdf_log.h" +#include "osal_mem.h" +#include "securec.h" +#include "usb_ddk_pnp_loader.h" + +#define HDF_LOG_TAG usb_pnp_manager + +bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName) +{ + char modName[128] = {0}; + + if (sprintf_s(modName, sizeof(modName) - 1, "lib%s.z.so", moduleName) < 0) { + HDF_LOGE("%s: sprintf_s modName fail", __func__); + return false; + } + + return HdfSbufWriteString(sbuf, modName); +} + +static int32_t UsbPnpManagerDispatch(struct HdfDeviceIoClient *client, int cmd, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + (void)client; + (void)cmd; + (void)data; + (void)reply; + + HDF_LOGI("received cmd = %d", cmd); + return HDF_SUCCESS; +} + +static int32_t UsbPnpManagerBind(struct HdfDeviceObject *device) +{ + static struct IDeviceIoService pnpLoaderService = { + .Dispatch = UsbPnpManagerDispatch, + }; + + if (device == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + + device->service = &pnpLoaderService; + HDF_LOGI("usb pnp manager bind success\n"); + + return HDF_SUCCESS; +} + +static int32_t UsbPnpManagerInit(struct HdfDeviceObject *device) +{ + int status; + struct HdfIoService *usbPnpServ = HdfIoServiceBind(USB_PNP_NOTIFY_SERVICE_NAME); + static struct HdfDevEventlistener usbPnpListener = { + .callBack = UsbDdkPnpLoaderEventReceived, + }; + usbPnpListener.priv = (void *)(device); + + if (usbPnpServ == NULL) { + HDF_LOGE("HdfIoServiceBind failed"); + return HDF_ERR_INVALID_OBJECT; + } + + status = HdfDeviceRegisterEventListener(usbPnpServ, &usbPnpListener); + if (status != HDF_SUCCESS) { + HDF_LOGE("HdfDeviceRegisterEventListener faile status=%d", status); + return status; + } + + HDF_LOGE("UsbPnpManagerInit done"); + return UsbDdkPnpLoaderEventHandle(); +} + +static void UsbPnpManagerRelease(struct HdfDeviceObject *device) +{ + (void)device; + return; +} + +struct HdfDriverEntry g_usbPnpManagerEntry = { + .moduleVersion = 1, + .Bind = UsbPnpManagerBind, + .Init = UsbPnpManagerInit, + .Release = UsbPnpManagerRelease, + .moduleName = "HDF_USB_PNP_MANAGER", +}; + +HDF_INIT(g_usbPnpManagerEntry); +