diff --git a/core/common/src/hdf_attribute.c b/core/common/src/hdf_attribute.c index 83b609fd2519574ba2e4a60e80d3eeadee3aea2d..ce3db466bacb2e1b8b59f6682901cc241111a8ae 100644 --- a/core/common/src/hdf_attribute.c +++ b/core/common/src/hdf_attribute.c @@ -18,6 +18,9 @@ #include "hdf_log.h" #include "osal_mem.h" #include "securec.h" +#ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY +#include "usb_pnp_manager.h" +#endif #define ATTR_HOST_NAME "hostName" #define ATTR_DEV_POLICY "policy" @@ -286,7 +289,7 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h return deviceList; } -bool HdfDeviceListAdd(const char *moduleName, const char *serviceName) +bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData) { struct HdfSListIterator itHost; struct HdfSListIterator itDeviceInfo; @@ -330,6 +333,11 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName) break; } deviceNodeInfo->svcName = svcName; +#ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY + if (!UsbPnpManagerAddPrivateData(deviceNodeInfo, privateData)) { + break; + } +#endif HdfSListAdd(hostClnt->deviceInfos, &deviceNodeInfo->node); hostClnt->devCount++; return true; diff --git a/core/host/include/devsvc_manager_clnt.h b/core/host/include/devsvc_manager_clnt.h index e164d8ae94ee78b4f709841435f44467b3358d13..ec7f7bec7a6a1502e694a7d72d2ac5296b00bf90 100644 --- a/core/host/include/devsvc_manager_clnt.h +++ b/core/host/include/devsvc_manager_clnt.h @@ -21,7 +21,7 @@ int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *ser void DevSvcManagerClntRemoveService(const char *svcName); int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback); int DevSvcManagerClntUnsubscribeService(const char *svcName); -struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName); +struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName, const void *privateData); void HdfUnregisterDevice(const char *moduleName, const char *serviceName); #endif /* DEVSVC_MANAGER_CLNT_H */ diff --git a/core/host/src/devsvc_manager_clnt.c b/core/host/src/devsvc_manager_clnt.c index 7dd4aef7f00542e47668be6a066ca84b4d3d8445..479839b941d54aa39ac819bcdb3383c98ad39033 100644 --- a/core/host/src/devsvc_manager_clnt.c +++ b/core/host/src/devsvc_manager_clnt.c @@ -64,10 +64,10 @@ struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName) return serviceManager->GetObject(serviceManager, svcName); } -struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName) +struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName, const void *privateData) { int ret; - if (!HdfDeviceListAdd(moduleName, serviceName)) { + if (!HdfDeviceListAdd(moduleName, serviceName, privateData)) { HDF_LOGE("%s device info add failed!", __func__); return NULL; } diff --git a/core/host/src/hdf_driver_loader.c b/core/host/src/hdf_driver_loader.c index 5ef03defe4abfcd29512c315638dcc4a2b2a6508..98cfbee6ced8669aa349eba5d482588d8f7d9e0e 100755 --- a/core/host/src/hdf_driver_loader.c +++ b/core/host/src/hdf_driver_loader.c @@ -42,7 +42,7 @@ struct HdfDeviceNode *HdfDriverLoaderLoadNode( devNode->driverEntry = driverEntry; devNode->deviceInfo = deviceInfo; devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetRootNode(), deviceInfo->deviceMatchAttr); - + devNode->deviceObject.priv = (void *)(deviceInfo->private); if (devNode->deviceObject.property == NULL) { HDF_LOGW("failed to load node, property is null, match attr is: %s", deviceInfo->deviceMatchAttr); } diff --git a/core/shared/include/hdf_attribute_manager.h b/core/shared/include/hdf_attribute_manager.h index ec90ee0179bc448c4f5dda79324fad032d9fb4fc..8138a5dbfcd54564f88a28779afb7f766f2b7673 100644 --- a/core/shared/include/hdf_attribute_manager.h +++ b/core/shared/include/hdf_attribute_manager.h @@ -14,7 +14,7 @@ const struct DeviceResourceNode *HdfGetRootNode(void); bool HdfAttributeManagerGetHostList(struct HdfSList *hostList); struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName); -bool HdfDeviceListAdd(const char *moduleName, const char *serviceName); +bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData); void HdfDeviceListDel(const char *moduleName, const char *serviceName); #endif /* HDF_ATTRIBUTE_MANAGER_H */ diff --git a/core/shared/include/hdf_device_info.h b/core/shared/include/hdf_device_info.h index de2f2984d8c95726ccf34531914a3ef98ba13683..aedf9c00b75a6e9062b58423eeea7b58617af236 100755 --- a/core/shared/include/hdf_device_info.h +++ b/core/shared/include/hdf_device_info.h @@ -36,8 +36,13 @@ struct HdfDeviceInfo { const char *moduleName; const char *svcName; const char *deviceMatchAttr; + const void *private; }; +struct HdfPrivateInfo { + uint32_t length; + const void *data; +}; struct HdfDeviceInfo *HdfDeviceInfoNewInstance(void); void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo); void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo); diff --git a/core/shared/include/hdf_usb_pnp_manage.h b/core/shared/include/hdf_usb_pnp_manage.h new file mode 100644 index 0000000000000000000000000000000000000000..e22f7cb1d1978c4f64918920f5d038875df298d2 --- /dev/null +++ b/core/shared/include/hdf_usb_pnp_manage.h @@ -0,0 +1,102 @@ +/* + * 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, +}; + +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 { + 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 { + uint32_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/core/shared/src/hdf_device_info.c b/core/shared/src/hdf_device_info.c index 9228d56fd698d87d332f02f5daf7cf9207fc76b2..1fc5ac93d3b05acd3206decacc3135904f7cf900 100755 --- a/core/shared/src/hdf_device_info.c +++ b/core/shared/src/hdf_device_info.c @@ -29,6 +29,7 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo) deviceInfo->svcName = NULL; deviceInfo->moduleName = NULL; deviceInfo->deviceMatchAttr = NULL; + deviceInfo->private = NULL; } struct HdfDeviceInfo *HdfDeviceInfoNewInstance() @@ -49,6 +50,9 @@ void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo) if (deviceInfo->isDynamic && deviceInfo->svcName != NULL) { OsalMemFree((void *)deviceInfo->svcName); } + if (deviceInfo->private != NULL) { + OsalMemFree((void *)deviceInfo->private); + } OsalMemFree(deviceInfo); } } diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c index 0407f0692213d5230767605e5e373544748bb746..028d802af36cad6543f48250c809580e8a07ce01 100644 --- a/model/input/driver/hdf_input_device_manager.c +++ b/model/input/driver/hdf_input_device_manager.c @@ -52,7 +52,7 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev) return NULL; } - hdfDev = HdfRegisterDevice(moduleName, svcName); + hdfDev = HdfRegisterDevice(moduleName, svcName, NULL); if (hdfDev == NULL) { HDF_LOGE("%s: HdfRegisterDevice failed", __func__); } diff --git a/test/unittest/common/hdf_main_test.c b/test/unittest/common/hdf_main_test.c index 0662cc6c4420c6f7b85d857417ca45ebb902cd6e..af2847f9892a8b0f31170a40f5da4ab1c1820b3e 100644 --- a/test/unittest/common/hdf_main_test.c +++ b/test/unittest/common/hdf_main_test.c @@ -52,6 +52,10 @@ #if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST) #include "hdf_audio_test.h" #endif +#if defined(LOSCFG_DRIVERS_HDF_USB_DDK_DEVICE) || defined(CONFIG_DRIVERS_HDF_USB_DDK_DEVICE) +#include "hdf_usb_device_test.h" +#endif + #define HDF_LOG_TAG hdf_test @@ -98,6 +102,10 @@ HdfTestFuncList g_hdfTestFuncList[] = { #if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST) {TEST_AUDIO_TYPE, HdfAudioEntry}, #endif +#if defined(LOSCFG_DRIVERS_HDF_USB_DDK_DEVICE) || defined(CONFIG_DRIVERS_HDF_USB_DDK_DEVICE) + {TEST_USB_DEVICE_TYPE, HdfUsbDeviceEntry}, +#endif + }; static int32_t HdfTestCaseProcess(struct HdfDeviceIoClient *client, diff --git a/test/unittest/common/hdf_main_test.h b/test/unittest/common/hdf_main_test.h index e2fd3767a3827580ec6c6307ae517469d16b3283..4607834475e7da7cc91bf0c63605590c47919e3b 100644 --- a/test/unittest/common/hdf_main_test.h +++ b/test/unittest/common/hdf_main_test.h @@ -69,6 +69,7 @@ typedef enum { TEST_CONFIG_TYPE = 601, TEST_AUDIO_TYPE = 701, TEST_HDF_FRAME_END = 800, + TEST_USB_DEVICE_TYPE = 900, } HdfTestSubModuleCmd; struct HdfDeviceObject *GetDeviceObject(void); diff --git a/test/unittest/include/hdf_uhdf_test.h b/test/unittest/include/hdf_uhdf_test.h index dcd4f486fc8e4b53bd83c4c8b04cf6e2ea0bfc3b..e5586f6a196548ff80a435ff31b72ea0dc47412a 100644 --- a/test/unittest/include/hdf_uhdf_test.h +++ b/test/unittest/include/hdf_uhdf_test.h @@ -64,6 +64,7 @@ enum HdfTestSubModuleCmd { TEST_WIFI_END = 600, TEST_CONFIG_TYPE = 601, TEST_HDF_FRAME_END = 800, + TEST_USB_DEVICE_TYPE = 900, }; void HdfTestOpenService(void); diff --git a/test/unittest/manager/sample_driver_test.c b/test/unittest/manager/sample_driver_test.c index bf69825f9ae5c655b39f80a63d4d7b6215a313d8..01792677243f67adab222f432af28c311e2f5907 100644 --- a/test/unittest/manager/sample_driver_test.c +++ b/test/unittest/manager/sample_driver_test.c @@ -37,7 +37,7 @@ int32_t SampleDriverRegisterDevice(struct HdfSBuf *data) return HDF_FAILURE; } - struct HdfDeviceObject *devObj = HdfRegisterDevice(moduleName, serviceName); + struct HdfDeviceObject *devObj = HdfRegisterDevice(moduleName, serviceName, NULL); if (devObj == NULL) { return HDF_FAILURE; } diff --git a/test/unittest/model/usb/include/hdf_usb_device_test.h b/test/unittest/model/usb/include/hdf_usb_device_test.h new file mode 100644 index 0000000000000000000000000000000000000000..7d5af872e2830d53fc4a54e8db62a868e30868db --- /dev/null +++ b/test/unittest/model/usb/include/hdf_usb_device_test.h @@ -0,0 +1,141 @@ +/* + * 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_DEVICE_TEST_H +#define HDF_USB_DEVICE_TEST_H + +#include "hdf_base.h" +#include "hdf_main_test.h" + +typedef enum { + USB_DEVICE_CREATE_DEVICE, + USB_DEVICE_CREATE_DEVICE002, + USB_DEVICE_CREATE_DEVICE003, + USB_DEVICE_CREATE_DEVICE004, + USB_DEVICE_CREATE_DEVICE005, + USB_DEVICE_CREATE_DEVICE006, + USB_DEVICE_DEVICE_STATUS, + USB_DEVICE_DEVICE_STATUS002, + USB_DEVICE_DEVICE_STATUS003, + USB_DEVICE_DEVICE_STATUS004, + USB_DEVICE_DEVICE_STATUS005, + USB_DEVICE_DEVICE_STATUS006, + USB_DEVICE_GET_DEVICE, + USB_DEVICE_GET_DEVICE002, + USB_DEVICE_GET_DEVICE003, + USB_DEVICE_GET_DEVICE004, + USB_DEVICE_GET_DEVICE005, + USB_DEVICE_GET_DEVICE006, + USB_DEVICE_GET_INTERFACE, + USB_DEVICE_GET_INTERFACE002, + USB_DEVICE_GET_INTERFACE003, + USB_DEVICE_GET_INTERFACE004, + USB_DEVICE_GET_INTERFACE005, + USB_DEVICE_GET_INTERFACE006, + USB_DEVICE_GET_PIPEINFO, + USB_DEVICE_GET_PIPEINFO002, + USB_DEVICE_GET_PIPEINFO003, + USB_DEVICE_GET_PIPEINFO004, + USB_DEVICE_GET_PIPEINFO005, + USB_DEVICE_GET_PIPEINFO006, + USB_DEVICE_REQUEST_ASYNC, + USB_DEVICE_REQUEST_ASYNC002, + USB_DEVICE_REQUEST_ASYNC003, + USB_DEVICE_REQUEST_ASYNC004, + USB_DEVICE_REQUEST_ASYNC005, + USB_DEVICE_REQUEST_ASYNC006, + USB_DEVICE_REQUEST_SYNC, + USB_DEVICE_REQUEST_SYNC002, + USB_DEVICE_REQUEST_SYNC003, + USB_DEVICE_REQUEST_SYNC004, + USB_DEVICE_REQUEST_SYNC005, + USB_DEVICE_REQUEST_SYNC006, + USB_DEVICE_REGIST_PROP, + USB_DEVICE_REGIST_PROP002, + USB_DEVICE_REGIST_PROP003, + USB_DEVICE_REGIST_PROP004, + USB_DEVICE_REGIST_PROP005, + USB_DEVICE_REGIST_PROP006, + USB_DEVICE_GET_PROP, + USB_DEVICE_GET_PROP002, + USB_DEVICE_GET_PROP003, + USB_DEVICE_GET_PROP004, + USB_DEVICE_GET_PROP005, + USB_DEVICE_GET_PROP006, + USB_DEVICE_SET_PROP, + USB_DEVICE_SET_PROP002, + USB_DEVICE_SET_PROP003, + USB_DEVICE_SET_PROP004, + USB_DEVICE_SET_PROP005, + USB_DEVICE_SET_PROP006, + USB_DEVICE_ALLOC_CTRLREQUEST, + USB_DEVICE_ALLOC_CTRLREQUEST002, + USB_DEVICE_ALLOC_CTRLREQUEST003, + USB_DEVICE_ALLOC_CTRLREQUEST004, + USB_DEVICE_ALLOC_CTRLREQUEST005, + USB_DEVICE_ALLOC_CTRLREQUEST006, + USB_DEVICE_ALLOC_REQUEST, + USB_DEVICE_ALLOC_REQUEST002, + USB_DEVICE_ALLOC_REQUEST003, + USB_DEVICE_ALLOC_REQUEST004, + USB_DEVICE_ALLOC_REQUEST005, + USB_DEVICE_ALLOC_REQUEST006, + USB_DEVICE_FREE_REQUEST, + USB_DEVICE_FREE_REQUEST002, + USB_DEVICE_FREE_REQUEST003, + USB_DEVICE_FREE_REQUEST004, + USB_DEVICE_FREE_REQUEST005, + USB_DEVICE_FREE_REQUEST006, + USB_DEVICE_GET_REQUEST_STATUS, + USB_DEVICE_GET_REQUEST_STATUS002, + USB_DEVICE_GET_REQUEST_STATUS003, + USB_DEVICE_GET_REQUEST_STATUS004, + USB_DEVICE_GET_REQUEST_STATUS005, + USB_DEVICE_GET_REQUEST_STATUS006, + USB_DEVICE_CANCEL_REQUEST, + USB_DEVICE_CANCEL_REQUEST002, + USB_DEVICE_CANCEL_REQUEST003, + USB_DEVICE_CANCEL_REQUEST004, + USB_DEVICE_CANCEL_REQUEST005, + USB_DEVICE_CANCEL_REQUEST006, + USB_DEVICE_STOP_EVENT, + USB_DEVICE_STOP_EVENT002, + USB_DEVICE_STOP_EVENT003, + USB_DEVICE_STOP_EVENT004, + USB_DEVICE_STOP_EVENT005, + USB_DEVICE_STOP_EVENT006, + USB_DEVICE_START_EVENT, + USB_DEVICE_START_EVENT002, + USB_DEVICE_START_EVENT003, + USB_DEVICE_START_EVENT004, + USB_DEVICE_START_EVENT005, + USB_DEVICE_START_EVENT006, + USB_DEVICE_CLOSE_INTERFACE, + USB_DEVICE_CLOSE_INTERFACE002, + USB_DEVICE_CLOSE_INTERFACE003, + USB_DEVICE_CLOSE_INTERFACE004, + USB_DEVICE_CLOSE_INTERFACE005, + USB_DEVICE_CLOSE_INTERFACE006, + USB_DEVICE_OPEN_INTERFACE, + USB_DEVICE_OPEN_INTERFACE002, + USB_DEVICE_OPEN_INTERFACE003, + USB_DEVICE_OPEN_INTERFACE004, + USB_DEVICE_OPEN_INTERFACE005, + USB_DEVICE_OPEN_INTERFACE006, + USB_DEVICE_DELETE_DEVICE, + USB_DEVICE_DELETE_DEVICE002, + USB_DEVICE_DELETE_DEVICE003, + USB_DEVICE_DELETE_DEVICE004, + USB_DEVICE_DELETE_DEVICE005, + USB_DEVICE_DELETE_DEVICE006, + USB_DEVICE_MESSAGE_END = 300, +} HdfUsbDeviceTestCaseCmd; + +int32_t HdfUsbDeviceEntry(HdfTestMsg *msg); + +#endif // HDF_USB_DEVICE_TEST_H \ No newline at end of file diff --git a/test/unittest/model/usb/include/usb_device_lite_cdcacm_test.h b/test/unittest/model/usb/include/usb_device_lite_cdcacm_test.h new file mode 100644 index 0000000000000000000000000000000000000000..bf204e17d3dba3dfd50ff4ddeb407a56e5216adc --- /dev/null +++ b/test/unittest/model/usb/include/usb_device_lite_cdcacm_test.h @@ -0,0 +1,251 @@ +/* + * 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. + */ + +#ifndef USB_DEVICE_LITE_CDCACM_TEST_H +#define USB_DEVICE_LITE_CDCACM_TEST_H + +#include +#include +#include "usbfn_device.h" +#include "usbfn_request.h" +#include "usbfn_interface.h" +#include "osal_atomic.h" +#include "osal_mutex.h" +#include "osal_time.h" + +#define TEST_TIMES 10 + +#define CDC_ACM +#define QUEUE_SIZE 8 +#define PORT_RATE 9600 +#define CHAR_FORMAT 8 + +#define SS_MAX_PACKET_SIZE 1024 +#define MAX_PACKET_SIZE 512 +#define EP_ADD_NOTIFY 1 +#define EP_ADD_DATA_IN 2 +#define EP_ADD_DATA_OUT 3 +#define DATA_EP_NUM 2 +#define NOTIFY_EP_NUM 1 +#define INTF_COUNT 2 + +#define ACM_NOTIFY_INTERVAL 32 /* ms */ +#define ACM_HS_NOTIFY_INTERVAL 9 /* ms */ +#define ACM_NOTIFY_MAXPACKET 10 /* notification + 2 bytes */ + +#define ACM_CTRL_IDX 1 +#define ACM_DATA_IDX 2 +#define ACM_IAD_IDX 3 + + +struct Serial { + struct AcmDevice *acm; + struct UsbCdcLineCoding lineCoding; + struct OsalMutex lock; + struct DListHead readPool; + struct DListHead readQueue; + int32_t readStarted; + int32_t readAllocated; + struct DListHead writePool; + int32_t writeStarted; + int32_t writeAllocated; + bool writeBusy; + + bool suspended; + bool startDelayed; + int refCount; +}; + +struct AcmNotifyMethod { + void (*Connect)(struct AcmDevice *acm); + void (*Disconnect)(struct AcmDevice *acm); + int (*SendBreak)(struct AcmDevice *acm, int duration); +}; + +struct AcmPipe { + uint8_t id; + uint16_t maxPacketSize; + struct UsbFnInterface *ctrlIface; +}; + +struct AcmInterface { + struct UsbFnInterface *fn; + UsbFnInterfaceHandle handle; +}; + +struct AcmDevice { + struct UsbFnDevice *fnDev; + struct AcmInterface ctrlIface; + struct AcmInterface dataIface; + struct AcmPipe notifyPipe; + struct AcmPipe dataInPipe; + struct AcmPipe dataOutPipe; + struct DListHead ctrlPool; + int32_t ctrlReqNum; + struct UsbFnRequest *notifyReq; + struct OsalMutex lock; + bool pending; + bool connect; + bool haved_submit; + uint32_t enableEvtCnt; + char *udcName; + char submit; + char submit_exit; + struct Serial *port; + struct UsbCdcLineCoding lineCoding; + uint16_t serialState; +#define SERIAL_STATE_DCD (1 << 0) +#define SERIAL_STATE_DSR (1 << 1) +#define SERIAL_STATE_BREAK (1 << 2) +#define SERIAL_STATE_RING (1 << 3) +#define SERIAL_STATE_FRAMING (1 << 4) +#define SERIAL_STATE_PARITY (1 << 5) +#define SERIAL_STATE_OVERRUN (1 << 6) + + uint16_t handshakeBits; + /* notification callbacks */ + struct AcmNotifyMethod *notify; +}; + +struct CtrlInfo { + uint8_t request; + struct AcmDevice *acm; +}; + +extern struct UsbFnDeviceDesc g_acmFnDevice; +struct AcmDevice *SetUpAcmDevice(void); +void ReleaseAcmDevice(struct AcmDevice *acm); +void AcmEventCallback(struct UsbFnEvent *event); +void AcmDeviceRelease(struct AcmDevice *acmDevice); + +int32_t UsbFnDviceTestCreate(void); +int32_t UsbFnDviceTestCreate002(void); +int32_t UsbFnDviceTestCreate003(void); +int32_t UsbFnDviceTestCreate004(void); +int32_t UsbFnDviceTestCreate005(void); +int32_t UsbFnDviceTestCreate006(void); +int32_t UsbFnDviceTestStatus(void); +int32_t UsbFnDviceTestStatus002(void); +int32_t UsbFnDviceTestStatus003(void); +int32_t UsbFnDviceTestStatus004(void); +int32_t UsbFnDviceTestStatus005(void); +int32_t UsbFnDviceTestStatus006(void); +int32_t UsbFnDviceTestGetDevice(void); +int32_t UsbFnDviceTestGetDevice002(void); +int32_t UsbFnDviceTestGetDevice003(void); +int32_t UsbFnDviceTestGetDevice004(void); +int32_t UsbFnDviceTestGetDevice005(void); +int32_t UsbFnDviceTestGetDevice006(void); +int32_t UsbFnDviceTestGetInterface(void); +int32_t UsbFnDviceTestGetInterface002(void); +int32_t UsbFnDviceTestGetInterface003(void); +int32_t UsbFnDviceTestGetInterface004(void); +int32_t UsbFnDviceTestGetInterface005(void); +int32_t UsbFnDviceTestGetInterface006(void); +int32_t UsbFnDviceTestGetPipeInfo(void); +int32_t UsbFnDviceTestGetPipeInfo002(void); +int32_t UsbFnDviceTestGetPipeInfo003(void); +int32_t UsbFnDviceTestGetPipeInfo004(void); +int32_t UsbFnDviceTestGetPipeInfo005(void); +int32_t UsbFnDviceTestGetPipeInfo006(void); +int32_t UsbFnDviceTestRequestAsync(void); +int32_t UsbFnDviceTestRequestAsync002(void); +int32_t UsbFnDviceTestRequestAsync003(void); +int32_t UsbFnDviceTestRequestAsync004(void); +int32_t UsbFnDviceTestRequestAsync005(void); +int32_t UsbFnDviceTestRequestAsync006(void); +int32_t UsbFnDviceTestRequestSync(void); +int32_t UsbFnDviceTestRequestSync002(void); +int32_t UsbFnDviceTestRequestSync003(void); +int32_t UsbFnDviceTestRequestSync004(void); +int32_t UsbFnDviceTestRequestSync005(void); +int32_t UsbFnDviceTestRequestSync006(void); +int32_t UsbFnDviceTestRegistProp(void); +int32_t UsbFnDviceTestRegistProp002(void); +int32_t UsbFnDviceTestRegistProp003(void); +int32_t UsbFnDviceTestRegistProp004(void); +int32_t UsbFnDviceTestRegistProp005(void); +int32_t UsbFnDviceTestRegistProp006(void); +int32_t UsbFnDviceTestGetProp(void); +int32_t UsbFnDviceTestGetProp002(void); +int32_t UsbFnDviceTestGetProp003(void); +int32_t UsbFnDviceTestGetProp004(void); +int32_t UsbFnDviceTestGetProp005(void); +int32_t UsbFnDviceTestGetProp006(void); +int32_t UsbFnDviceTestSetProp(void); +int32_t UsbFnDviceTestSetProp002(void); +int32_t UsbFnDviceTestSetProp003(void); +int32_t UsbFnDviceTestSetProp004(void); +int32_t UsbFnDviceTestSetProp005(void); +int32_t UsbFnDviceTestSetProp006(void); +int32_t UsbFnDviceTestAllocCtrlRequest(void); +int32_t UsbFnDviceTestAllocCtrlRequest002(void); +int32_t UsbFnDviceTestAllocCtrlRequest003(void); +int32_t UsbFnDviceTestAllocCtrlRequest004(void); +int32_t UsbFnDviceTestAllocCtrlRequest005(void); +int32_t UsbFnDviceTestAllocCtrlRequest006(void); +int32_t UsbFnDviceTestAllocRequest(void); +int32_t UsbFnDviceTestAllocRequest002(void); +int32_t UsbFnDviceTestAllocRequest003(void); +int32_t UsbFnDviceTestAllocRequest004(void); +int32_t UsbFnDviceTestAllocRequest005(void); +int32_t UsbFnDviceTestAllocRequest006(void); +int32_t UsbFnDviceTestFreeRequest(void); +int32_t UsbFnDviceTestFreeRequest002(void); +int32_t UsbFnDviceTestFreeRequest003(void); +int32_t UsbFnDviceTestFreeRequest004(void); +int32_t UsbFnDviceTestFreeRequest005(void); +int32_t UsbFnDviceTestFreeRequest006(void); +int32_t UsbFnDviceTestGetRequestStatus(void); +int32_t UsbFnDviceTestGetRequestStatus002(void); +int32_t UsbFnDviceTestGetRequestStatus003(void); +int32_t UsbFnDviceTestGetRequestStatus004(void); +int32_t UsbFnDviceTestGetRequestStatus005(void); +int32_t UsbFnDviceTestGetRequestStatus006(void); +int32_t UsbFnDviceTestCancelRequest(void); +int32_t UsbFnDviceTestCancelRequest002(void); +int32_t UsbFnDviceTestCancelRequest003(void); +int32_t UsbFnDviceTestCancelRequest004(void); +int32_t UsbFnDviceTestCancelRequest005(void); +int32_t UsbFnDviceTestCancelRequest006(void); +int32_t UsbFnDviceTestStopReceEvent(void); +int32_t UsbFnDviceTestStopReceEvent002(void); +int32_t UsbFnDviceTestStopReceEvent003(void); +int32_t UsbFnDviceTestStopReceEvent004(void); +int32_t UsbFnDviceTestStopReceEvent005(void); +int32_t UsbFnDviceTestStopReceEvent006(void); +int32_t UsbFnDviceTestStartReceEvent(void); +int32_t UsbFnDviceTestStartReceEvent002(void); +int32_t UsbFnDviceTestStartReceEvent003(void); +int32_t UsbFnDviceTestStartReceEvent004(void); +int32_t UsbFnDviceTestStartReceEvent005(void); +int32_t UsbFnDviceTestStartReceEvent006(void); +int32_t UsbFnDviceTestCloseInterface(void); +int32_t UsbFnDviceTestCloseInterface002(void); +int32_t UsbFnDviceTestCloseInterface003(void); +int32_t UsbFnDviceTestCloseInterface004(void); +int32_t UsbFnDviceTestCloseInterface005(void); +int32_t UsbFnDviceTestCloseInterface006(void); +int32_t UsbFnDviceTestOpenInterface(void); +int32_t UsbFnDviceTestOpenInterface002(void); +int32_t UsbFnDviceTestOpenInterface003(void); +int32_t UsbFnDviceTestOpenInterface004(void); +int32_t UsbFnDviceTestOpenInterface005(void); +int32_t UsbFnDviceTestOpenInterface006(void); +int32_t UsbFnDviceTestRemove(void); +int32_t UsbFnDviceTestRemove002(void); +int32_t UsbFnDviceTestRemove003(void); + +#endif diff --git a/test/unittest/model/usb/src/hdf_usb_device_test.c b/test/unittest/model/usb/src/hdf_usb_device_test.c new file mode 100644 index 0000000000000000000000000000000000000000..cf5848216b541fa95ab6c30512ab1a0c701c32ce --- /dev/null +++ b/test/unittest/model/usb/src/hdf_usb_device_test.c @@ -0,0 +1,154 @@ +/* + * 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. + */ +#include "usb_device_lite_cdcacm_test.h" +#include "hdf_usb_device_test.h" +#include "hdf_module_test.h" +#include "hdf_log.h" +#include "hdf_message_test.h" +#include "osal.h" + +// add test case entry +static HdfTestCaseList g_hdfUsbDeviceTestCaseList[] = { + {USB_DEVICE_CREATE_DEVICE, UsbFnDviceTestCreate}, + {USB_DEVICE_CREATE_DEVICE002, UsbFnDviceTestCreate002}, + {USB_DEVICE_CREATE_DEVICE003, UsbFnDviceTestCreate003}, + {USB_DEVICE_CREATE_DEVICE004, UsbFnDviceTestCreate004}, + {USB_DEVICE_CREATE_DEVICE005, UsbFnDviceTestCreate005}, + {USB_DEVICE_CREATE_DEVICE006, UsbFnDviceTestCreate006}, + {USB_DEVICE_DEVICE_STATUS, UsbFnDviceTestStatus}, + {USB_DEVICE_DEVICE_STATUS002, UsbFnDviceTestStatus002}, + {USB_DEVICE_DEVICE_STATUS003, UsbFnDviceTestStatus003}, + {USB_DEVICE_DEVICE_STATUS004, UsbFnDviceTestStatus004}, + {USB_DEVICE_DEVICE_STATUS005, UsbFnDviceTestStatus005}, + {USB_DEVICE_DEVICE_STATUS006, UsbFnDviceTestStatus006}, + {USB_DEVICE_GET_DEVICE, UsbFnDviceTestGetDevice}, + {USB_DEVICE_GET_DEVICE002, UsbFnDviceTestGetDevice002}, + {USB_DEVICE_GET_DEVICE003, UsbFnDviceTestGetDevice003}, + {USB_DEVICE_GET_DEVICE004, UsbFnDviceTestGetDevice004}, + {USB_DEVICE_GET_DEVICE005, UsbFnDviceTestGetDevice005}, + {USB_DEVICE_GET_DEVICE006, UsbFnDviceTestGetDevice006}, + {USB_DEVICE_GET_INTERFACE, UsbFnDviceTestGetInterface}, + {USB_DEVICE_GET_INTERFACE002, UsbFnDviceTestGetInterface002}, + {USB_DEVICE_GET_INTERFACE003, UsbFnDviceTestGetInterface003}, + {USB_DEVICE_GET_INTERFACE004, UsbFnDviceTestGetInterface004}, + {USB_DEVICE_GET_INTERFACE005, UsbFnDviceTestGetInterface005}, + {USB_DEVICE_GET_INTERFACE006, UsbFnDviceTestGetInterface006}, + {USB_DEVICE_GET_PIPEINFO, UsbFnDviceTestGetPipeInfo}, + {USB_DEVICE_GET_PIPEINFO002, UsbFnDviceTestGetPipeInfo002}, + {USB_DEVICE_GET_PIPEINFO003, UsbFnDviceTestGetPipeInfo003}, + {USB_DEVICE_GET_PIPEINFO004, UsbFnDviceTestGetPipeInfo004}, + {USB_DEVICE_GET_PIPEINFO005, UsbFnDviceTestGetPipeInfo005}, + {USB_DEVICE_GET_PIPEINFO006, UsbFnDviceTestGetPipeInfo006}, + {USB_DEVICE_REQUEST_ASYNC, UsbFnDviceTestRequestAsync}, + {USB_DEVICE_REQUEST_ASYNC002, UsbFnDviceTestRequestAsync002}, + {USB_DEVICE_REQUEST_ASYNC003, UsbFnDviceTestRequestAsync003}, + {USB_DEVICE_REQUEST_ASYNC004, UsbFnDviceTestRequestAsync004}, + {USB_DEVICE_REQUEST_ASYNC005, UsbFnDviceTestRequestAsync005}, + {USB_DEVICE_REQUEST_ASYNC006, UsbFnDviceTestRequestAsync006}, + {USB_DEVICE_REQUEST_SYNC, UsbFnDviceTestRequestSync}, + {USB_DEVICE_REQUEST_SYNC002, UsbFnDviceTestRequestSync002}, + {USB_DEVICE_REQUEST_SYNC003, UsbFnDviceTestRequestSync003}, + {USB_DEVICE_REQUEST_SYNC004, UsbFnDviceTestRequestSync004}, + {USB_DEVICE_REQUEST_SYNC005, UsbFnDviceTestRequestSync005}, + {USB_DEVICE_REQUEST_SYNC006, UsbFnDviceTestRequestSync006}, + {USB_DEVICE_REGIST_PROP, UsbFnDviceTestRegistProp}, + {USB_DEVICE_REGIST_PROP002, UsbFnDviceTestRegistProp002}, + {USB_DEVICE_REGIST_PROP003, UsbFnDviceTestRegistProp003}, + {USB_DEVICE_REGIST_PROP004, UsbFnDviceTestRegistProp004}, + {USB_DEVICE_REGIST_PROP005, UsbFnDviceTestRegistProp005}, + {USB_DEVICE_REGIST_PROP006, UsbFnDviceTestRegistProp006}, + {USB_DEVICE_GET_PROP, UsbFnDviceTestGetProp}, + {USB_DEVICE_GET_PROP002, UsbFnDviceTestGetProp002}, + {USB_DEVICE_GET_PROP003, UsbFnDviceTestGetProp003}, + {USB_DEVICE_GET_PROP004, UsbFnDviceTestGetProp004}, + {USB_DEVICE_GET_PROP005, UsbFnDviceTestGetProp005}, + {USB_DEVICE_GET_PROP006, UsbFnDviceTestGetProp006}, + {USB_DEVICE_SET_PROP, UsbFnDviceTestSetProp}, + {USB_DEVICE_SET_PROP002, UsbFnDviceTestSetProp002}, + {USB_DEVICE_SET_PROP003, UsbFnDviceTestSetProp003}, + {USB_DEVICE_SET_PROP004, UsbFnDviceTestSetProp004}, + {USB_DEVICE_SET_PROP005, UsbFnDviceTestSetProp005}, + {USB_DEVICE_SET_PROP006, UsbFnDviceTestSetProp006}, + {USB_DEVICE_ALLOC_CTRLREQUEST, UsbFnDviceTestAllocCtrlRequest}, + {USB_DEVICE_ALLOC_CTRLREQUEST002, UsbFnDviceTestAllocCtrlRequest002}, + {USB_DEVICE_ALLOC_CTRLREQUEST003, UsbFnDviceTestAllocCtrlRequest003}, + {USB_DEVICE_ALLOC_CTRLREQUEST004, UsbFnDviceTestAllocCtrlRequest004}, + {USB_DEVICE_ALLOC_CTRLREQUEST005, UsbFnDviceTestAllocCtrlRequest005}, + {USB_DEVICE_ALLOC_CTRLREQUEST006, UsbFnDviceTestAllocCtrlRequest006}, + {USB_DEVICE_ALLOC_REQUEST, UsbFnDviceTestAllocRequest}, + {USB_DEVICE_ALLOC_REQUEST002, UsbFnDviceTestAllocRequest002}, + {USB_DEVICE_ALLOC_REQUEST003, UsbFnDviceTestAllocRequest003}, + {USB_DEVICE_ALLOC_REQUEST004, UsbFnDviceTestAllocRequest004}, + {USB_DEVICE_ALLOC_REQUEST005, UsbFnDviceTestAllocRequest005}, + {USB_DEVICE_ALLOC_REQUEST006, UsbFnDviceTestAllocRequest006}, + {USB_DEVICE_FREE_REQUEST, UsbFnDviceTestFreeRequest}, + {USB_DEVICE_FREE_REQUEST002, UsbFnDviceTestFreeRequest002}, + {USB_DEVICE_FREE_REQUEST003, UsbFnDviceTestFreeRequest003}, + {USB_DEVICE_FREE_REQUEST004, UsbFnDviceTestFreeRequest004}, + {USB_DEVICE_FREE_REQUEST005, UsbFnDviceTestFreeRequest005}, + {USB_DEVICE_FREE_REQUEST006, UsbFnDviceTestFreeRequest006}, + {USB_DEVICE_GET_REQUEST_STATUS, UsbFnDviceTestGetRequestStatus}, + {USB_DEVICE_GET_REQUEST_STATUS002, UsbFnDviceTestGetRequestStatus002}, + {USB_DEVICE_GET_REQUEST_STATUS003, UsbFnDviceTestGetRequestStatus003}, + {USB_DEVICE_GET_REQUEST_STATUS004, UsbFnDviceTestGetRequestStatus004}, + {USB_DEVICE_GET_REQUEST_STATUS005, UsbFnDviceTestGetRequestStatus005}, + {USB_DEVICE_GET_REQUEST_STATUS006, UsbFnDviceTestGetRequestStatus006}, + {USB_DEVICE_CANCEL_REQUEST, UsbFnDviceTestCancelRequest}, + {USB_DEVICE_CANCEL_REQUEST002, UsbFnDviceTestCancelRequest002}, + {USB_DEVICE_CANCEL_REQUEST003, UsbFnDviceTestCancelRequest003}, + {USB_DEVICE_CANCEL_REQUEST004, UsbFnDviceTestCancelRequest004}, + {USB_DEVICE_CANCEL_REQUEST005, UsbFnDviceTestCancelRequest005}, + {USB_DEVICE_CANCEL_REQUEST006, UsbFnDviceTestCancelRequest006}, + {USB_DEVICE_STOP_EVENT, UsbFnDviceTestStopReceEvent}, + {USB_DEVICE_STOP_EVENT002, UsbFnDviceTestStopReceEvent002}, + {USB_DEVICE_STOP_EVENT003, UsbFnDviceTestStopReceEvent003}, + {USB_DEVICE_STOP_EVENT004, UsbFnDviceTestStopReceEvent004}, + {USB_DEVICE_STOP_EVENT005, UsbFnDviceTestStopReceEvent005}, + {USB_DEVICE_STOP_EVENT006, UsbFnDviceTestStopReceEvent006}, + {USB_DEVICE_START_EVENT, UsbFnDviceTestStartReceEvent}, + {USB_DEVICE_START_EVENT002, UsbFnDviceTestStartReceEvent002}, + {USB_DEVICE_START_EVENT003, UsbFnDviceTestStartReceEvent003}, + {USB_DEVICE_START_EVENT004, UsbFnDviceTestStartReceEvent004}, + {USB_DEVICE_START_EVENT005, UsbFnDviceTestStartReceEvent005}, + {USB_DEVICE_START_EVENT006, UsbFnDviceTestStartReceEvent006}, + {USB_DEVICE_CLOSE_INTERFACE, UsbFnDviceTestCloseInterface}, + {USB_DEVICE_CLOSE_INTERFACE002, UsbFnDviceTestCloseInterface002}, + {USB_DEVICE_CLOSE_INTERFACE003, UsbFnDviceTestCloseInterface003}, + {USB_DEVICE_CLOSE_INTERFACE004, UsbFnDviceTestCloseInterface004}, + {USB_DEVICE_CLOSE_INTERFACE005, UsbFnDviceTestCloseInterface005}, + {USB_DEVICE_CLOSE_INTERFACE006, UsbFnDviceTestCloseInterface006}, + {USB_DEVICE_OPEN_INTERFACE, UsbFnDviceTestOpenInterface}, + {USB_DEVICE_OPEN_INTERFACE002, UsbFnDviceTestOpenInterface002}, + {USB_DEVICE_OPEN_INTERFACE003, UsbFnDviceTestOpenInterface003}, + {USB_DEVICE_OPEN_INTERFACE004, UsbFnDviceTestOpenInterface004}, + {USB_DEVICE_OPEN_INTERFACE005, UsbFnDviceTestOpenInterface005}, + {USB_DEVICE_OPEN_INTERFACE006, UsbFnDviceTestOpenInterface006}, + {USB_DEVICE_DELETE_DEVICE, UsbFnDviceTestRemove}, + {USB_DEVICE_DELETE_DEVICE002, UsbFnDviceTestRemove002}, + {USB_DEVICE_DELETE_DEVICE003, UsbFnDviceTestRemove003}, +}; + +int32_t HdfUsbDeviceEntry(HdfTestMsg *msg) +{ + int32_t result, i; + + if (msg == NULL) { + HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__); + return HDF_SUCCESS; + } + + for (i = 0; i < sizeof(g_hdfUsbDeviceTestCaseList) / sizeof(g_hdfUsbDeviceTestCaseList[0]); ++i) { + if ((msg->subCmd == g_hdfUsbDeviceTestCaseList[i].subCmd) && (g_hdfUsbDeviceTestCaseList[i].testFunc != NULL)) { + result = g_hdfUsbDeviceTestCaseList[i].testFunc(); + HDF_LOGE("HdfTest:usb device test result[%s-%u]", ((result == 0) ? "pass" : "fail"), msg->subCmd); + msg->result = (result == 0) ? HDF_SUCCESS : HDF_FAILURE; + return HDF_SUCCESS; + } + } + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/test/unittest/model/usb/src/usb_device_lite_cdcacm_test.c b/test/unittest/model/usb/src/usb_device_lite_cdcacm_test.c new file mode 100644 index 0000000000000000000000000000000000000000..fa94ee7b4f29cc04ec8b35a0987255162b158b1e --- /dev/null +++ b/test/unittest/model/usb/src/usb_device_lite_cdcacm_test.c @@ -0,0 +1,770 @@ +/* + * 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_device_lite_cdcacm_test.h" + +static struct UsbInterfaceAssocDescriptor g_acmIadDescriptor = { + .bLength = sizeof(g_acmIadDescriptor), + .bDescriptorType = USB_DDK_DT_INTERFACE_ASSOCIATION, +#ifdef CDC_ECM + .bFirstInterface = 0x02, +#else + .bFirstInterface = 0, +#endif + .bInterfaceCount = INTF_COUNT, + .bFunctionClass = USB_DDK_CLASS_COMM, + .bFunctionSubClass = USB_DDK_CDC_SUBCLASS_ACM, + .bFunctionProtocol = USB_DDK_CDC_ACM_PROTO_AT_V25TER, + .iFunction = ACM_IAD_IDX, +}; + +static struct UsbInterfaceDescriptor g_acmControlInterfaceDesc = { + .bLength = USB_DDK_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DDK_DT_INTERFACE, +#ifdef CDC_ECM + .bInterfaceNumber = 0x02, +#else + .bInterfaceNumber = 0, +#endif + .bAlternateSetting = 0, + .bNumEndpoints = NOTIFY_EP_NUM, + .bInterfaceClass = USB_DDK_CLASS_COMM, + .bInterfaceSubClass = USB_DDK_CDC_SUBCLASS_ACM, + .bInterfaceProtocol = USB_DDK_CDC_ACM_PROTO_AT_V25TER, + .iInterface = ACM_CTRL_IDX, +}; + +static struct UsbInterfaceDescriptor g_acmDataInterfaceDesc = { + .bLength = USB_DDK_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DDK_DT_INTERFACE, +#ifdef CDC_ECM + .bInterfaceNumber = 0x03, +#else + .bInterfaceNumber = 1, +#endif + .bAlternateSetting = 0, + .bNumEndpoints = DATA_EP_NUM, + .bInterfaceClass = USB_DDK_CLASS_CDC_DATA, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 2, + .iInterface = ACM_DATA_IDX, +}; + +static struct UsbCdcHeaderDesc g_acmHeaderDesc = { + .bLength = sizeof(g_acmHeaderDesc), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bDescriptorSubType = USB_DDK_CDC_HEADER_TYPE, + .bcdCDC = CpuToLe16(0x0110), +}; + +static struct UsbCdcCallMgmtDescriptor g_acmCallMgmtDescriptor = { + .bLength = sizeof(g_acmCallMgmtDescriptor), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bDescriptorSubType = USB_DDK_CDC_CALL_MANAGEMENT_TYPE, + .bmCapabilities = 0, + .bDataInterface = 1, +}; + +static struct UsbCdcAcmDescriptor g_acmDescriptor = { + .bLength = sizeof(g_acmDescriptor), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bDescriptorSubType = USB_DDK_CDC_ACM_TYPE, + .bmCapabilities = USB_DDK_CDC_CAP_LINE, +}; + +static struct UsbCdcUnionDesc g_acmUnionDesc = { + .bLength = sizeof(g_acmUnionDesc), + .bDescriptorType = USB_DDK_DT_CS_INTERFACE, + .bDescriptorSubType = USB_DDK_CDC_UNION_TYPE, +#ifdef CDC_ECM + .bMasterInterface0 = 0x02, + .bSlaveInterface0 = 0x03, +#else + .bMasterInterface0 = 0, + .bSlaveInterface0 = 1, +#endif +}; + +static struct UsbEndpointDescriptor g_acmFsNotifyDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_NOTIFY | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_INT, + .wMaxPacketSize = CpuToLe16(ACM_NOTIFY_MAXPACKET), + .bInterval = ACM_NOTIFY_INTERVAL, +}; + +static struct UsbEndpointDescriptor g_acmFsInDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, +}; + +static struct UsbEndpointDescriptor g_acmFsOutDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, +}; + +static struct UsbDescriptorHeader *g_acmFsFunction[] = { + (struct UsbDescriptorHeader *) &g_acmIadDescriptor, + (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmHeaderDesc, + (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *) &g_acmDescriptor, + (struct UsbDescriptorHeader *) &g_acmUnionDesc, + (struct UsbDescriptorHeader *) &g_acmFsNotifyDesc, + (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmFsInDesc, + (struct UsbDescriptorHeader *) &g_acmFsOutDesc, + NULL, +}; + +static struct UsbEndpointDescriptor g_acmHsNotifyDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_NOTIFY | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_INT, + .wMaxPacketSize = CpuToLe16(ACM_NOTIFY_MAXPACKET), + .bInterval = ACM_HS_NOTIFY_INTERVAL, +}; + +static struct UsbEndpointDescriptor g_acmHsInDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CpuToLe16(MAX_PACKET_SIZE), +}; + +static struct UsbEndpointDescriptor g_acmHsOutDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CpuToLe16(MAX_PACKET_SIZE), +}; + +static struct UsbDescriptorHeader *g_acmHsFunction[] = { + (struct UsbDescriptorHeader *) &g_acmIadDescriptor, + (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmHeaderDesc, + (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *) &g_acmDescriptor, + (struct UsbDescriptorHeader *) &g_acmUnionDesc, + (struct UsbDescriptorHeader *) &g_acmHsNotifyDesc, + (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmHsInDesc, + (struct UsbDescriptorHeader *) &g_acmHsOutDesc, + NULL, +}; + +static struct UsbEndpointDescriptor g_acmSsInDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_IN | USB_DDK_DIR_IN, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CpuToLe16(SS_MAX_PACKET_SIZE), +}; + +static struct UsbEndpointDescriptor g_acmSsOutDesc = { + .bLength = USB_DDK_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DDK_DT_ENDPOINT, + .bEndpointAddress = EP_ADD_DATA_OUT | USB_DDK_DIR_OUT, + .bmAttributes = USB_DDK_ENDPOINT_XFER_BULK, + .wMaxPacketSize = CpuToLe16(SS_MAX_PACKET_SIZE), +}; + +static struct UsbSsEpCompDescriptor g_acmSsBulkCompDesc = { + .bLength = sizeof(g_acmSsBulkCompDesc), + .bDescriptorType = USB_DDK_DT_SS_ENDPOINT_COMP, +}; + +static struct UsbDescriptorHeader *g_acmSsFunction[] = { + (struct UsbDescriptorHeader *) &g_acmIadDescriptor, + (struct UsbDescriptorHeader *) &g_acmControlInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmHeaderDesc, + (struct UsbDescriptorHeader *) &g_acmCallMgmtDescriptor, + (struct UsbDescriptorHeader *) &g_acmDescriptor, + (struct UsbDescriptorHeader *) &g_acmUnionDesc, + (struct UsbDescriptorHeader *) &g_acmHsNotifyDesc, + (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, + (struct UsbDescriptorHeader *) &g_acmDataInterfaceDesc, + (struct UsbDescriptorHeader *) &g_acmSsInDesc, + (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, + (struct UsbDescriptorHeader *) &g_acmSsOutDesc, + (struct UsbDescriptorHeader *) &g_acmSsBulkCompDesc, + NULL, +}; + +static struct UsbString g_acmStringDefs[] = { + [0].s = "CDC Abstract Control Model (ACM)", + [1].s = "CDC ACM Data", + [2].s = "CDC Serial", + { } /* end of list */ +}; + +static struct UsbFnStrings g_acmStringTable = { + .language = 0x0409, /* en-us */ + .strings = g_acmStringDefs, +}; + +static struct UsbFnStrings *g_acmStrings[] = { + &g_acmStringTable, + NULL, +}; + +static struct UsbFnFunction g_acmFunction = { + .funcName = "f_generic.0", + .strings = g_acmStrings, + .fsDescriptors = g_acmFsFunction, + .hsDescriptors = g_acmHsFunction, + .ssDescriptors = g_acmSsFunction, + .sspDescriptors = NULL, +}; + +/** device **/ +#define BCD_USB 0x0200 +#define DEVICE_VENDOR_ID 0x12D1 +#define DEVICE_PRODUCT_ID 0x5000 +#define DEVICE_VERSION 0x0223 + +#define USB_MAX_PACKET_SIZE 0x40 +#define POWER 500 + +#define USB_FUNC_CONFIG_IDX USB_FUNC_FIRST_AVAIL_IDX +#define DRIVER_DESC "HDC Device" +#define CONFIG_DESC "hdc" + +static struct UsbDeviceDescriptor g_cdcMasterDeviceDesc = { + .bLength = sizeof(g_cdcMasterDeviceDesc), + .bDescriptorType = USB_DDK_DT_DEVICE, + .bcdUSB = CpuToLe16(BCD_USB), + .bDeviceClass = 0, + .bDeviceSubClass = 0, + .bDeviceProtocol = 0, + .bMaxPacketSize0 = USB_MAX_PACKET_SIZE, + .idVendor = CpuToLe16(DEVICE_VENDOR_ID), + .idProduct = CpuToLe16(DEVICE_PRODUCT_ID), + .bcdDevice = CpuToLe16(DEVICE_VERSION), + .iManufacturer = USB_FUNC_MANUFACTURER_IDX, + .iProduct = USB_FUNC_PRODUCT_IDX, + .iSerialNumber = USB_FUNC_SERIAL_IDX, + .bNumConfigurations = 1, +}; + +static struct UsbString g_stringsDev[] = { + {USB_FUNC_MANUFACTURER_IDX, "HISILICON"}, + {USB_FUNC_PRODUCT_IDX, DRIVER_DESC}, + {USB_FUNC_SERIAL_IDX, "0123456789POPLAR"}, + {USB_FUNC_CONFIG_IDX, CONFIG_DESC}, + { } /* end of list */ +}; + +static struct UsbFnStrings g_stringTabDev = { + .language = 0x0409, /* en-us */ + .strings = g_stringsDev, +}; + +static struct UsbFnStrings *g_devStrings[] = { + &g_stringTabDev, + NULL, +}; + +static struct UsbFnFunction *g_functions[] = { +#ifdef CDC_ECM + &g_ecmFunction, +#endif +#ifdef CDC_ACM + &g_acmFunction, +#endif + NULL +}; + +static struct UsbFnConfiguration g_masterConfig = { + .configurationValue = 1, + .iConfiguration = USB_FUNC_CONFIG_IDX, + .attributes = USB_CFG_BUS_POWERED, + .maxPower = POWER, + .functions = g_functions, +}; + +static struct UsbFnConfiguration *g_configs[] = { + &g_masterConfig, + NULL, +}; + +struct UsbFnDeviceDesc g_acmFnDevice = { + .deviceDesc = &g_cdcMasterDeviceDesc, + .deviceStrings = g_devStrings, + .configs = g_configs, +}; + +static struct Serial *SerialAlloc(void) +{ + struct Serial *port = NULL; + port = (struct Serial *)OsalMemCalloc(sizeof(*port)); + if (port == NULL) { + return NULL; + } + OsalMutexInit(&port->lock); + DListHeadInit(&port->readPool); + DListHeadInit(&port->readQueue); + DListHeadInit(&port->writePool); + + port->lineCoding.dwDTERate = CpuToLe32(PORT_RATE); + port->lineCoding.bCharFormat = CHAR_FORMAT; + port->lineCoding.bParityType = USB_CDC_NO_PARITY; + port->lineCoding.bDataBits = USB_CDC_1_STOP_BITS; + return port; +} + +static int ParseInterfaces(struct AcmDevice *acmDevice) +{ + uint32_t i; + uint32_t j; + struct UsbFnInterface *fnIface = NULL; + UsbFnInterfaceHandle handle = NULL; + int ret; + + for (i = 0; i < acmDevice->fnDev->numInterfaces; i++) { + fnIface = (struct UsbFnInterface *)UsbFnGetInterface(acmDevice->fnDev, i); + if (fnIface == NULL) { + return -1; + } + handle = UsbFnOpenInterface(fnIface); + if (handle == NULL) { + return -1; + } + for (j = 0; j < fnIface->info.numPipes; j++) { + struct UsbFnPipeInfo pipeInfo; + ret = UsbFnGetInterfacePipeInfo(fnIface, j, &pipeInfo); + if (ret != HDF_SUCCESS) { + return -1; + } + if (pipeInfo.type == USB_PIPE_TYPE_INTERRUPT) { + acmDevice->notifyPipe.id = pipeInfo.id; + acmDevice->notifyPipe.maxPacketSize = pipeInfo.maxPacketSize; + acmDevice->ctrlIface.fn = fnIface; + acmDevice->ctrlIface.handle = handle; + } else if (pipeInfo.type == USB_PIPE_TYPE_BULK) { + if (pipeInfo.dir == USB_PIPE_DIRECTION_IN) { + acmDevice->dataInPipe.id = pipeInfo.id; + acmDevice->dataInPipe.maxPacketSize = pipeInfo.maxPacketSize; + acmDevice->dataIface.fn = fnIface; + acmDevice->dataIface.handle = handle; + } else { + acmDevice->dataOutPipe.id = pipeInfo.id; + acmDevice->dataOutPipe.maxPacketSize = pipeInfo.maxPacketSize; + acmDevice->dataIface.fn = fnIface; + acmDevice->dataIface.handle = handle; + } + } + } + } + return 0; +} + +static void CtrlComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + struct CtrlInfo *ctrlInfo = (struct CtrlInfo *)req->context; + struct AcmDevice *acm = ctrlInfo->acm; + + if (req == NULL) { + return; + } + if (USB_REQUEST_COMPLETED != req->status) { + goto out; + } + + if (ctrlInfo->request == USB_DDK_CDC_REQ_SET_LINE_CODING) { + struct UsbCdcLineCoding *value = (struct UsbCdcLineCoding *)req->buf; + if (req->actual == sizeof(*value)) { + acm->lineCoding = *value; + } + acm->connect = true; + } +out: + DListInsertTail(&req->list, &acm->ctrlPool); +} + +static int AllocCtrlRequests(struct AcmDevice *acmDevice) +{ + struct DListHead *head = &acmDevice->ctrlPool; + struct UsbFnRequest *req = NULL; + struct CtrlInfo *ctrlInfo = NULL; + int i; + int count = 2; + + DListHeadInit(&acmDevice->ctrlPool); + acmDevice->ctrlReqNum = 0; + + for (i = 0; i < count; i++) { + ctrlInfo = (struct CtrlInfo *)OsalMemCalloc(sizeof(*ctrlInfo)); + if (NULL == ctrlInfo) { + return -1; + } + ctrlInfo->acm = acmDevice; + req = UsbFnAllocCtrlRequest(acmDevice->ctrlIface.handle, + sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding)); + if (NULL == req) { + return -1; + } + req->complete = CtrlComplete; + req->context = ctrlInfo; + DListInsertTail(&req->list, head); + acmDevice->ctrlReqNum++; + } + + return 0; +} + +static int32_t SendNotifyRequest(struct AcmDevice *acm, uint8_t type, + uint16_t value, void *data, uint32_t length) +{ + struct UsbFnRequest *req = acm->notifyReq; + struct UsbCdcNotification *notify = NULL; + int ret; + if (acm == NULL || req->buf) { + return -1; + } + acm->notifyReq = NULL; + acm->pending = false; + req->length = sizeof(*notify) + length; + + notify = (struct UsbCdcNotification *)req->buf; + notify->bmRequestType = USB_DDK_DIR_IN | USB_DDK_TYPE_CLASS | USB_DDK_RECIP_INTERFACE; + notify->bNotificationType = type; + notify->wValue = CpuToLe16(value); + notify->wIndex = CpuToLe16(acm->ctrlIface.fn->info.index); + notify->wLength = CpuToLe16(length); + memcpy_s((void *)(notify + 1), length, data, length); + + ret = UsbFnSubmitRequestAsync(req); + return ret; +} + +static int32_t NotifySerialState(struct AcmDevice *acm) +{ + int32_t ret = 0; + uint16_t serialState; + + OsalMutexLock(&acm->lock); + if (acm->notifyReq) { + serialState = CpuToLe16(acm->serialState); + ret = SendNotifyRequest(acm, USB_DDK_CDC_NOTIFY_SERIAL_STATE, + 0, &serialState, sizeof(acm->serialState)); + } else { + acm->pending = true; + } + OsalMutexUnlock(&acm->lock); + + return ret; +} + +static void NotifyComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + struct AcmDevice *acm = (struct AcmDevice *)req->context; + bool pending = false; + + if (acm == NULL) { + return; + } + OsalMutexLock(&acm->lock); + if (req->status != USB_REQUEST_NO_DEVICE) { + pending = acm->pending; + } + acm->notifyReq = req; + OsalMutexUnlock(&acm->lock); + if (pending) { + NotifySerialState(acm); + } +} + +static int32_t AllocNotifyRequest(struct AcmDevice *acmDevice) +{ + /* allocate notification request */ + acmDevice->notifyReq = UsbFnAllocRequest(acmDevice->ctrlIface.handle, acmDevice->notifyPipe.id, + sizeof(struct UsbCdcNotification)); + if (acmDevice->notifyReq == NULL) { + return -1; + } + acmDevice->notifyReq->complete = NotifyComplete; + acmDevice->notifyReq->context = acmDevice; + + return HDF_SUCCESS; +} + +static void Connect(struct AcmDevice *acm) +{ + if (acm == NULL) { + return; + } + acm->serialState |= SERIAL_STATE_DSR | SERIAL_STATE_DCD; + NotifySerialState(acm); +} + +static void Disconnect(struct AcmDevice *acm) +{ + if (acm == NULL) { + return; + } + acm->serialState &= ~(SERIAL_STATE_DSR | SERIAL_STATE_DCD); + NotifySerialState(acm); +} + +static int32_t SendBreak(struct AcmDevice *acm, int duration) +{ + uint16_t state; + + if (acm == NULL) { + return -1; + } + state = acm->serialState; + state &= ~SERIAL_STATE_BREAK; + if (duration) + state |= SERIAL_STATE_BREAK; + + acm->serialState = state; + return NotifySerialState(acm); +} + +static struct AcmNotifyMethod g_notifyMethod = { + .Connect = Connect, + .Disconnect = Disconnect, + .SendBreak = SendBreak, +}; + +static uint32_t Enable(struct AcmDevice *acm) +{ + struct Serial *port = acm->port; + OsalMutexLock(&port->lock); + port->acm = acm; + acm->lineCoding = port->lineCoding; + if (port->refCount) { + if (acm->notify && acm->notify->Connect) { + acm->notify->Connect(acm); + } + } else { + if (acm->notify && acm->notify->Disconnect) { + acm->notify->Disconnect(acm); + } + } + OsalMutexUnlock(&port->lock); + + return HDF_SUCCESS; +} + +static uint32_t Disable(struct AcmDevice *acm) +{ + return HDF_SUCCESS; +} + +static struct UsbFnRequest *GetCtrlReq(struct AcmDevice *acm) +{ + struct UsbFnRequest *req = NULL; + struct DListHead *pool = &acm->ctrlPool; + if (!DListIsEmpty(pool)) { + req = DLIST_FIRST_ENTRY(pool, struct UsbFnRequest, list); + DListRemove(&req->list); + } + return req; +} + +static void Setup(struct AcmDevice *acm, struct UsbFnCtrlRequest *setup) +{ + struct UsbFnRequest *req = NULL; + struct CtrlInfo *ctrlInfo = NULL; + uint16_t value = Le16ToCpu(setup->value); + uint16_t length = Le16ToCpu(setup->length); + int ret = 0; + req = GetCtrlReq(acm); + if (req == NULL) { + return; + } + switch (setup->request) { + case USB_DDK_CDC_REQ_SET_LINE_CODING: + if (length != sizeof(struct UsbCdcLineCoding)) { + goto out; + } + ret = length; + break; + case USB_DDK_CDC_REQ_GET_LINE_CODING: + ret = (length > sizeof(struct UsbCdcLineCoding)) ? \ + sizeof(struct UsbCdcLineCoding) : length; + if (acm->lineCoding.dwDTERate == 0) { + acm->lineCoding = acm->port->lineCoding; + } + memcpy_s(req->buf, req->length, &acm->lineCoding, ret); + break; + case USB_DDK_CDC_REQ_SET_CONTROL_LINE_STATE: + ret = 0; + acm->handshakeBits = value; + break; + default: + break; + } + +out: + ctrlInfo = (struct CtrlInfo *)req->context; + ctrlInfo->request = setup->request; + req->length = ret; + ret = UsbFnSubmitRequestAsync(req); +} + +static void Suspend(struct AcmDevice *acm) +{ + struct Serial *port = acm->port; + + OsalMutexLock(&port->lock); + port->suspended = true; + OsalMutexUnlock(&port->lock); +} + +static void Resume(struct AcmDevice *acm) +{ + struct Serial *port = acm->port; + + OsalMutexLock(&port->lock); + port->suspended = false; + if (acm->notify && acm->notify->Connect) { + acm->notify->Connect(acm); + } + port->startDelayed = false; + OsalMutexUnlock(&port->lock); +} + +void AcmEventCallback(struct UsbFnEvent *event) +{ + struct AcmDevice *acm = NULL; + + if (event == NULL || event->context == NULL) + return; + acm = (struct AcmDevice *)event->context; + switch (event->type) { + case USBFN_STATE_BIND: + break; + case USBFN_STATE_UNBIND: + break; + case USBFN_STATE_ENABLE: + Enable(acm); + break; + case USBFN_STATE_DISABLE: + Disable(acm); + acm->enableEvtCnt = 0; + break; + case USBFN_STATE_SETUP: + Setup(acm, event->setup); + break; + case USBFN_STATE_SUSPEND: + Suspend(acm); + break; + case USBFN_STATE_RESUME: + Resume(acm); + break; + default: + break; + } +} + +struct AcmDevice *SetUpAcmDevice(void) +{ + int32_t ret; + + struct AcmDevice *acmDevice = NULL; + struct UsbFnDescriptorData descData; + descData.type = USBFN_DESC_DATA_TYPE_DESC; + descData.descriptor = &g_acmFnDevice; + acmDevice = (struct AcmDevice *)OsalMemCalloc(sizeof(*acmDevice)); + if (acmDevice == NULL) { + return NULL; + } + acmDevice->fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_0", &descData); + if (acmDevice->fnDev == NULL) { + return NULL; + } + acmDevice->port = (struct Serial *)SerialAlloc(); + if (acmDevice->port == NULL) { + return NULL; + } + ret = ParseInterfaces(acmDevice); + if (ret != 0) { + return NULL; + } + ret = AllocCtrlRequests(acmDevice); + if (ret != 0) { + return NULL; + } + ret = AllocNotifyRequest(acmDevice); + if (ret != 0) { + return NULL; + } + ret = UsbFnStartRecvInterfaceEvent(acmDevice->ctrlIface.fn, 0xff, AcmEventCallback, acmDevice); + if (ret != 0) { + return NULL; + } + acmDevice->notify = &g_notifyMethod; + return acmDevice; +} + +static int32_t FreeNotifyRequest(struct AcmDevice *acmDevice) +{ + int ret; + + /* allocate notification request */ + if (acmDevice->notifyReq == NULL) { + HDF_LOGE("%{public}s: notifyReq is NULL", __func__); + return -1; + } + acmDevice->notifyReq->complete = NULL; + acmDevice->notifyReq->context = NULL; + ret = UsbFnFreeRequest(acmDevice->notifyReq); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: free notifyReq failed", __func__); + return -1; + } + return HDF_SUCCESS; +} + +static int FreeCtrlRequests(struct AcmDevice *acmDevice) +{ + struct DListHead *head = &acmDevice->ctrlPool; + struct UsbFnRequest *req = NULL; + + while (!DListIsEmpty(head)) { + req = DLIST_FIRST_ENTRY(head, struct UsbFnRequest, list); + DListRemove(&req->list); + OsalMemFree(req->context); + (void)UsbFnFreeRequest(req); + acmDevice->ctrlReqNum--; + } + return 0; +} + +void ReleaseAcmDevice(struct AcmDevice *acm) +{ + if (acm == NULL) { + HDF_LOGE("%{public}s: acm is NULL", __func__); + return; + } + FreeNotifyRequest(acm); + FreeCtrlRequests(acm); + (void)UsbFnCloseInterface(acm->ctrlIface.handle); + (void)UsbFnCloseInterface(acm->dataIface.handle); + UsbFnStopRecvInterfaceEvent(acm->ctrlIface.fn); + OsalMemFree(acm->port); +} + diff --git a/test/unittest/model/usb/src/usb_device_lite_sdk_if_test.c b/test/unittest/model/usb/src/usb_device_lite_sdk_if_test.c new file mode 100644 index 0000000000000000000000000000000000000000..d116eaba5d42b9a8bd547c1e7d734a7ecb30c2e8 --- /dev/null +++ b/test/unittest/model/usb/src/usb_device_lite_sdk_if_test.c @@ -0,0 +1,2268 @@ +/* + * 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_device_lite_cdcacm_test.h" + +#define HDF_LOG_TAG usb_device_sdk_test + +static struct AcmDevice *g_acmDevice = NULL; +int32_t UsbFnDviceTestCreate(void) +{ + dprintf("%s: start\n", __func__); + g_acmDevice = SetUpAcmDevice(); + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate fail", __func__); + return HDF_FAILURE; + } + dprintf("%s: success\n", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate002(void) +{ + struct UsbFnDevice *fnDev = NULL; + struct UsbFnDescriptorData descData; + + descData.type = USBFN_DESC_DATA_TYPE_DESC; + descData.descriptor = NULL; + fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_0", &descData); + if (fnDev != NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate success!!", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate003(void) +{ + struct UsbFnDevice *fnDev = NULL; + struct UsbFnDescriptorData descData; + + descData.type = USBFN_DESC_DATA_TYPE_PROP; + descData.property = NULL; + fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_0", &descData); + if (fnDev != NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate success!!", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate004(void) +{ + struct UsbFnDevice *fnDev = NULL; + struct UsbFnDescriptorData descData; + + descData.type = USBFN_DESC_DATA_TYPE_DESC; + descData.descriptor = &g_acmFnDevice; + fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_0", &descData); + if (fnDev != NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate success!!", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate005(void) +{ + struct UsbFnDevice *fnDev = NULL; + struct UsbFnDescriptorData descData; + + descData.type = USBFN_DESC_DATA_TYPE_DESC; + descData.descriptor = &g_acmFnDevice; + fnDev = (struct UsbFnDevice *)UsbFnCreateDevice("100e0000.hidwc3_1", &descData); + if (fnDev != NULL) { + HDF_LOGE("%s: UsbFnDviceTestCreate success!!", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCreate006(void) +{ + HDF_LOGI("%s: success", __func__); + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus(void) +{ + int ret; + UsbFnDeviceState devState; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetDeviceState(g_acmDevice->fnDev, &devState); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __LINE__); + return HDF_FAILURE; + } + if (!(devState >= USBFN_STATE_BIND && devState <= USBFN_STATE_RESUME)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus002(void) +{ + int ret; + UsbFnDeviceState devState; + ret = UsbFnGetDeviceState(NULL, &devState); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get status success!!", __LINE__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus003(void) +{ + int ret; + int count = 0; + UsbFnDeviceState devState; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + for (count = 0; count < TEST_TIMES; count++) { + ret = UsbFnGetDeviceState(g_acmDevice->fnDev, &devState); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __LINE__); + return HDF_FAILURE; + } + if (!(devState >= USBFN_STATE_BIND && devState <= USBFN_STATE_RESUME)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus004(void) +{ + int ret; + ret = UsbFnGetDeviceState(NULL, NULL); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get status success!!", __LINE__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus005(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStatus006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = "100e0000.hidwc3_0"; + device = UsbFnGetDevice(udcName); + if (device == NULL) { + HDF_LOGE("%s: get device fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice002(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = "100e0000.hidwc3_1"; + device = UsbFnGetDevice(udcName); + if (device != NULL) { + HDF_LOGE("%s: get device success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice003(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = NULL; + device = UsbFnGetDevice(udcName); + if (device != NULL) { + HDF_LOGE("%s: get device success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice004(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = "100e0000.hidwc3_0 "; + device = UsbFnGetDevice(udcName); + if (device != NULL) { + HDF_LOGE("%s: get device success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice005(void) +{ + const struct UsbFnDevice *device = NULL; + const char *udcName = "100e0000.hidwc3_0\0100e0000.hidwc3_0"; + device = UsbFnGetDevice(udcName); + if (device != NULL) { + HDF_LOGE("%s: get device success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetDevice006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface(void) +{ + struct UsbFnInterface *fnInterface = NULL; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, 0); + if (fnInterface == NULL) { + HDF_LOGE("%s: get interface fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; + +} + +int32_t UsbFnDviceTestGetInterface002(void) +{ + struct UsbFnInterface *fnInterface = NULL; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, 1); + if (fnInterface == NULL) { + HDF_LOGE("%s: get interface fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface003(void) +{ + struct UsbFnInterface *fnInterface = NULL; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + dprintf("%s, %d\n", __func__, __LINE__); + return HDF_FAILURE; + } + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, 0xA); + if (fnInterface != NULL) { + HDF_LOGE("%s: get interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface004(void) +{ + struct UsbFnInterface *fnInterface = NULL; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, 0x20); + if (fnInterface != NULL) { + HDF_LOGE("%s: get interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface005(void) +{ + struct UsbFnInterface *fnInterface = NULL; + struct UsbFnDevice *fnDevice = NULL; + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(fnDevice, 0); + if (fnInterface != NULL) { + HDF_LOGE("%s: get interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetInterface006(void) +{ + struct UsbFnInterface *fnInterface = NULL; + int idCount; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fnDev is invail", __func__); + return HDF_FAILURE; + } + for (idCount = 0; idCount < 0x2; idCount++) { + fnInterface = (struct UsbFnInterface *)UsbFnGetInterface(g_acmDevice->fnDev, idCount); + if (fnInterface == NULL) { + HDF_LOGE("%s: get interface fail", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo(void) +{ + int ret; + struct UsbFnPipeInfo info; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->dataIface.fn, 0, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get pipe info error", __func__); + return HDF_FAILURE; + } + if (info.id != 0) { + HDF_LOGE("%s: get pipe id error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo002(void) +{ + int ret; + struct UsbFnPipeInfo info; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->dataIface.fn, 1, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get pipe info error", __func__); + return HDF_FAILURE; + } + if (info.id != 1) { + HDF_LOGE("%s: get pipe id error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo003(void) +{ + int ret; + struct UsbFnPipeInfo info; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->dataIface.fn, 0xF, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get pipe info success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo004(void) +{ + int ret; + struct UsbFnPipeInfo *info = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->dataIface.fn, 0, info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get pipe info success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo005(void) +{ + int ret; + struct UsbFnPipeInfo info; + struct UsbFnInterface *fn = NULL; + + ret = UsbFnGetInterfacePipeInfo(fn, 0, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get pipe info success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetPipeInfo006(void) +{ + int ret; + struct UsbFnPipeInfo info; + + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfacePipeInfo(g_acmDevice->ctrlIface.fn, 0, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get pipe info error", __func__); + return HDF_FAILURE; + } + if (info.id != 0) { + HDF_LOGE("%s: get pipe id error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static void ReadComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + if (NULL == req) { + return; + } + if (req->actual) { + uint8_t *data = (uint8_t *)req->buf; + data[req->actual] = '\0'; + dprintf("receive [%d] bytes data: %s\n", req->actual, data); + if (strcmp((const char *)data, "q") == 0 || \ + strcmp((const char *)data, "q\n") == 0) { + g_acmDevice->submit_exit = 1; + } + } + g_acmDevice->submit = 1; +} + +int32_t UsbFnDviceTestRequestAsync(void) +{ + struct UsbFnRequest *req = NULL; + int ret; + + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: async Request success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestAsync002(void) +{ + struct UsbFnRequest *req = NULL; + int ret = HDF_SUCCESS; + int ret1 = HDF_SUCCESS; + int waitMs = 100; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("wait receiving data form host, please connect\n"); + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + req->complete = ReadComplete; + req->context = g_acmDevice; + while (g_acmDevice->connect == false) { + OsalMSleep(waitMs); + } + while (1) { + g_acmDevice->submit = 0; + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: async Request error", __func__); + ret = HDF_FAILURE; + break; + } + while(g_acmDevice->submit == 0) { + OsalMSleep(waitMs); + } + if (req->actual > 0) { + break; + } + } + ret1 = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret1) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return ret; +} + +int32_t UsbFnDviceTestRequestAsync003(void) +{ + struct UsbFnRequest *req = NULL; + int ret = HDF_SUCCESS; + int ret1 = HDF_SUCCESS; + int waitMs = 100; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("wait receiving data form host, please connect\n"); + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + req->complete = ReadComplete; + req->context = g_acmDevice; + while (g_acmDevice->connect == false) { + OsalMSleep(waitMs); + } + g_acmDevice->submit_exit = 0; + while (g_acmDevice->submit_exit == 0) { + g_acmDevice->submit = 0; + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: async Request error", __func__); + ret = HDF_FAILURE; + break; + } + while(g_acmDevice->submit == 0) { + OsalMSleep(waitMs); + } + } + ret1 = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret1) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return ret; +} + +static void WriteComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + dprintf("write data status = %d\n", req->status); + g_acmDevice->submit = 1; +} + +int32_t UsbFnDviceTestRequestAsync004(void) +{ + struct UsbFnRequest *req = NULL; + int ret = HDF_SUCCESS; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + req->complete = WriteComplete; + req->context = g_acmDevice; + g_acmDevice->submit = 0; + dprintf("------send \"abc\" to host------\n"); + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")); + req->length = strlen("abc"); + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: async Request error", __func__); + return HDF_FAILURE; + } + while(g_acmDevice->submit == 0) { + OsalMSleep(1); + } + g_acmDevice->submit = 0; + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestAsync005(void) +{ + struct UsbFnRequest *req = NULL; + int loopTime = TEST_TIMES; + int ret = HDF_SUCCESS; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("------send \"xyz\" 10 times to host------\n"); + while (loopTime--) { + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + req->complete = WriteComplete; + req->context = g_acmDevice; + g_acmDevice->submit = 0; + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "xyz", strlen("xyz")); + req->length = strlen("xyz"); + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: async Request error", __func__); + return HDF_FAILURE; + } + while(g_acmDevice->submit == 0) { + OsalMSleep(1); + } + g_acmDevice->submit = 0; + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestAsync006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync(void) +{ + struct UsbFnRequest *req = NULL; + int ret; + ret = UsbFnSubmitRequestSync(req, 0); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: sync Request success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync002(void) +{ + struct UsbFnRequest *req = NULL; + int ret; + uint8_t *data; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("wait receiving data form host\n"); + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSubmitRequestSync(req, 0); + if (ret != 0 || req->actual <= 0 || req->status != USB_REQUEST_COMPLETED) { + HDF_LOGE("%s: Sync Request error", __func__); + return HDF_FAILURE; + } + data = (uint8_t *)req->buf; + data[req->actual] = '\0'; + dprintf("receive data from host: %s\n", data); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync003(void) +{ + struct UsbFnRequest *req = NULL; + int ret; + int submit_exit = 0; + uint8_t *data; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("receive data until 'q' exit\n"); + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + while (submit_exit == 0){ + ret = UsbFnSubmitRequestSync(req, 0); + if (ret != 0 || req->actual <= 0 || req->status != USB_REQUEST_COMPLETED) { + HDF_LOGE("%s: Sync Request error", __func__); + break; + } + data = (uint8_t *)req->buf; + data[req->actual] = '\0'; + if (strcmp((const char *)data, "q") == 0 || \ + strcmp((const char *)data, "q\n") == 0) { + submit_exit = 1; + } + dprintf("receive data from host: %s\n", data); + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync004(void) +{ + struct UsbFnRequest *req = NULL; + int ret = HDF_SUCCESS; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + dprintf("------send \"abc\" to host------\n"); + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")); + req->length = strlen("abc"); + ret = UsbFnSubmitRequestSync(req, 0); + if (HDF_SUCCESS != ret || (req->actual != strlen("abc")) || \ + (req->status != USB_REQUEST_COMPLETED)) { + HDF_LOGE("%s: async Request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync005(void) +{ + struct UsbFnRequest *req = NULL; + int loopTime = TEST_TIMES; + int ret = HDF_SUCCESS; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.fn is invail", __func__); + return HDF_FAILURE; + } + dprintf("------send \"abcdefg\" 10 times to host------\n"); + while (loopTime--) { + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abcdefg", strlen("abcdefg")); + req->length = strlen("abcdefg"); + ret = UsbFnSubmitRequestSync(req, 0); + if (HDF_SUCCESS != ret || (req->actual != strlen("abcdefg")) || \ + (req->status != USB_REQUEST_COMPLETED)) { + HDF_LOGE("%s: async Request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRequestSync007(void) +{ + return HDF_SUCCESS; +} + +static int32_t PropCallBack(const struct UsbFnInterface *intf, const char *name, + const char *value) +{ + if (intf == NULL || name == NULL || value == NULL) { + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp(void) +{ + int ret; + struct UsbFnRegistInfo info; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = "name_test"; + info.value = "test_value"; + info.getProp = PropCallBack; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Regist Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp002(void) +{ + int ret; + struct UsbFnRegistInfo info; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = "name_test"; + info.value = "test_value"; + info.getProp = PropCallBack; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Regist Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp003(void) +{ + int ret; + struct UsbFnRegistInfo info; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = NULL; + info.value = "test_value"; + info.getProp = PropCallBack; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Regist Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp004(void) +{ + int ret; + struct UsbFnRegistInfo info; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = "name_test4"; + info.value = "test_value"; + info.getProp = NULL; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, &info); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Regist Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp005(void) +{ + int ret; + struct UsbFnRegistInfo info; + struct UsbFnInterface *fn = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + info.name = "name_test5"; + info.value = "test_value"; + info.getProp = PropCallBack; + info.setProp = PropCallBack; + ret = UsbFnRegistInterfaceProp(fn, &info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Regist Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRegistProp006(void) +{ + int ret; + struct UsbFnRegistInfo *info = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnRegistInterfaceProp(g_acmDevice->ctrlIface.fn, info); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Regist Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp(void) +{ + int ret; + char buffer[64] = {0}; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "name_test", buffer); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Get Prop error", __func__); + return HDF_FAILURE; + } + if (strcmp(buffer, "test_value")) { + HDF_LOGE("%s: Get Prop value error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp002(void) +{ + int ret; + char buffer[64] = {0}; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "unkown", buffer); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Get Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp003(void) +{ + int ret; + char buffer[64] = {0}; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "idProduct", buffer); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Get Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp004(void) +{ + int ret; + char buffer[64] = {0}; + struct UsbFnInterface *fn = NULL; + + ret = UsbFnGetInterfaceProp(fn, "idProduct", buffer); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Get Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp005(void) +{ + int ret; + char buffer[64] = {0}; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "idVendor", buffer); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Get Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetProp006(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetInterfaceProp(g_acmDevice->ctrlIface.fn, "name_test", NULL); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Get Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(g_acmDevice->ctrlIface.fn, "name_test", "hello"); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: Set Prop error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp002(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(g_acmDevice->ctrlIface.fn, "unkown", "hello"); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Set Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp003(void) +{ + int ret; + struct UsbFnInterface *fn = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(fn, "name_test", "hellotest"); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Set Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp004(void) +{ + int ret; + const char *propName = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(g_acmDevice->ctrlIface.fn, propName, "hellotest"); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Set Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp005(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestSetProp006(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSetInterfaceProp(g_acmDevice->ctrlIface.fn, "bLength", "0x14"); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: Get Prop success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->dataIface.handle, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest002(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding)); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, 0); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest004(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, 0x801); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest005(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + UsbFnInterfaceHandle handle = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(handle, + g_acmDevice->notifyPipe.maxPacketSize); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocCtrlRequest006(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, 0x800); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + sizeof(struct UsbCdcNotification)); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest002(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + 0); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + 0x800); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest004(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + UsbFnInterfaceHandle handle = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(handle, g_acmDevice->notifyPipe.id, 0x800); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest005(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, 0x20, 0x800); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestAllocRequest006(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, + g_acmDevice->notifyPipe.id, 0x801); + if (req != NULL) { + HDF_LOGE("%s: alloc req success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + g_acmDevice->notifyPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest002(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest004(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + g_acmDevice->notifyPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest005(void) +{ + int ret; + int count; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + for (count = 0; count < TEST_TIMES; count++) { + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + g_acmDevice->notifyPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestFreeRequest006(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: free Request success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus(void) +{ + int ret; + UsbRequestStatus status; + struct UsbFnRequest *notifyReq = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + notifyReq = UsbFnAllocRequest(g_acmDevice->ctrlIface.handle, g_acmDevice->notifyPipe.id, + sizeof(struct UsbCdcNotification)); + if (notifyReq == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetRequestStatus(notifyReq, &status); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __func__); + return HDF_FAILURE; + } + if (!(status >= USB_REQUEST_COMPLETED && status <= USB_REQUEST_OVERFLOW)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(notifyReq); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus002(void) +{ + int ret; + UsbRequestStatus status; + struct UsbFnRequest *notifyReq = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + notifyReq = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + sizeof(struct UsbCdcNotification)); + if (notifyReq == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetRequestStatus(notifyReq, &status); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __func__); + dprintf("%s: get status error", __func__); + return HDF_FAILURE; + } + if (!(status >= USB_REQUEST_COMPLETED && status <= USB_REQUEST_OVERFLOW)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(notifyReq); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetRequestStatus(req, NULL); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get status success!!", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus004(void) +{ + int ret; + UsbRequestStatus status; + struct UsbFnRequest *notifyReq = NULL; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + notifyReq = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (notifyReq == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnSubmitRequestAsync(notifyReq); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __func__); + return HDF_FAILURE; + } + ret = UsbFnGetRequestStatus(notifyReq, &status); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: get status error", __func__); + return HDF_FAILURE; + } + if (!(status >= USB_REQUEST_COMPLETED && status <= USB_REQUEST_OVERFLOW)) { + HDF_LOGE("%s: device status error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(notifyReq); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus005(void) +{ + int ret; + UsbRequestStatus status; + struct UsbFnRequest *notifyReq = NULL; + ret = UsbFnGetRequestStatus(notifyReq, &status); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: get status success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestGetRequestStatus006(void) +{ + return HDF_SUCCESS; +} + +static void TestCancelComplete(uint8_t pipe, struct UsbFnRequest *req) +{ + dprintf("%s, req->buf = 0x%x\n", __func__, (uint32_t)req->buf); + g_acmDevice->haved_submit = true; +} + +int32_t UsbFnDviceTestCancelRequest(void) +{ + int ret; + struct UsbFnRequest *notifyReq = NULL; + ret = UsbFnCancelRequest(notifyReq); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: cancel request success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest002(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: CtrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, + sizeof(struct UsbCdcNotification)); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: cancel request success", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest003(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS == ret) { + dprintf("%s: cancel request success\n", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + dprintf("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest004(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS == ret) { + dprintf("%s: cancel request success\n", __func__); + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + dprintf("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest005(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataInPipe.id, + g_acmDevice->dataInPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + g_acmDevice->haved_submit = false; + req->complete = TestCancelComplete; + req->context = g_acmDevice; + dprintf("------send \"abc\" to host------\n"); + memcpy_s(req->buf, g_acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")); + req->length = strlen("abc"); + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: request async error", __func__); + return HDF_FAILURE; + } + while(g_acmDevice->haved_submit == 0) { + OsalMSleep(1); + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS == ret) { + dprintf("%s: cancel request error", __func__); + return HDF_FAILURE; + } + g_acmDevice->haved_submit = false; + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCancelRequest006(void) +{ + int ret; + struct UsbFnRequest *req = NULL; + struct UsbFnRequest *req2 = NULL; + + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + req = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + g_acmDevice->haved_submit = false; + req->complete = TestCancelComplete; + req->context = g_acmDevice; + + req2 = UsbFnAllocRequest(g_acmDevice->dataIface.handle, g_acmDevice->dataOutPipe.id, + g_acmDevice->dataOutPipe.maxPacketSize); + if (req2 == NULL) { + HDF_LOGE("%s: alloc req fail", __func__); + return HDF_FAILURE; + } + g_acmDevice->submit = false; + req2->complete = ReadComplete; + req2->context = g_acmDevice; + ret = UsbFnSubmitRequestAsync(req); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: request async error", __func__); + return HDF_FAILURE; + } + ret = UsbFnSubmitRequestAsync(req2); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: request async error", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req2); + if (HDF_SUCCESS != ret) { + dprintf("%s: cancel request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnCancelRequest(req); + if (HDF_SUCCESS != ret) { + dprintf("%s: cancel request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req); + if (HDF_SUCCESS != ret) { + dprintf("%s: free Request error", __func__); + return HDF_FAILURE; + } + ret = UsbFnFreeRequest(req2); + if (HDF_SUCCESS != ret) { + dprintf("%s: free Request error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStopRecvInterfaceEvent(g_acmDevice->ctrlIface.fn); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: stop receive event error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent002(void) +{ + int ret; + struct UsbFnInterface *fn = NULL; + ret = UsbFnStopRecvInterfaceEvent(fn); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent003(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStopRecvInterfaceEvent(g_acmDevice->ctrlIface.fn); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent004(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStopRecvInterfaceEvent(g_acmDevice->dataIface.fn); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent005(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStopReceEvent006(void) +{ + return HDF_SUCCESS; +} + +static void eventCallback(struct UsbFnEvent *event) +{ + (void)event; +} + +int32_t UsbFnDviceTestStartReceEvent(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, + NULL, g_acmDevice); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event successs!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent002(void) +{ + int ret; + struct UsbFnInterface *fn = NULL; + ret = UsbFnStartRecvInterfaceEvent(fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: stop receive event successs!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent003(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: stop receive event error", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent004(void) +{ + int ret; + int count; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + for (count = 0; count < TEST_TIMES; count++) { + ret = UsbFnStopRecvInterfaceEvent(g_acmDevice->ctrlIface.fn); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: stop receive event error", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: stop receive event error", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent005(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: start receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestStartReceEvent006(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->dataIface.fn, 0xff, + eventCallback, g_acmDevice); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: start receive event success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCloseInterface(g_acmDevice->ctrlIface.handle); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: close interface error", __func__); + return HDF_FAILURE; + } + g_acmDevice->ctrlIface.handle = NULL; + + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface002(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCloseInterface(g_acmDevice->dataIface.handle); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: close interface error", __func__); + return HDF_FAILURE; + } + g_acmDevice->dataIface.handle = NULL; + + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface003(void) +{ + int ret; + + ret = UsbFnCloseInterface(g_acmDevice->ctrlIface.handle); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: close interface success!!", __func__); + return HDF_FAILURE; + } + g_acmDevice->ctrlIface.handle = NULL; + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface004(void) +{ + int ret; + + ret = UsbFnCloseInterface(g_acmDevice->dataIface.handle); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: close interface success!!", __func__); + return HDF_FAILURE; + } + g_acmDevice->dataIface.handle = NULL; + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface005(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestCloseInterface006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface(void) +{ + UsbFnInterfaceHandle handle; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + if (g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + handle = UsbFnOpenInterface(g_acmDevice->ctrlIface.fn); + if (NULL != handle) { + HDF_LOGE("%s: open interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface002(void) +{ + UsbFnInterfaceHandle handle; + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + if (g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + handle = UsbFnOpenInterface(g_acmDevice->dataIface.fn); + if (NULL != handle) { + HDF_LOGE("%s: open interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface003(void) +{ + int ret; + UsbFnInterfaceHandle handle; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.fn is invail", __func__); + return HDF_FAILURE; + } + if (g_acmDevice->ctrlIface.handle == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCloseInterface(g_acmDevice->ctrlIface.handle); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: close interface failed", __func__); + return HDF_FAILURE; + } + g_acmDevice->ctrlIface.handle = NULL; + handle = UsbFnOpenInterface(g_acmDevice->ctrlIface.fn); + if (NULL == handle) { + HDF_LOGE("%s: open interface failed", __func__); + return HDF_FAILURE; + } + g_acmDevice->ctrlIface.handle = handle; + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface004(void) +{ + int ret; + UsbFnInterfaceHandle handle; + if (g_acmDevice == NULL || g_acmDevice->dataIface.fn == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + if (g_acmDevice->dataIface.handle == NULL) { + HDF_LOGE("%s: dataIface.handle is invail", __func__); + return HDF_FAILURE; + } + ret = UsbFnCloseInterface(g_acmDevice->dataIface.handle); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: close interface failed", __func__); + return HDF_FAILURE; + } + g_acmDevice->dataIface.handle = NULL; + handle = UsbFnOpenInterface(g_acmDevice->dataIface.fn); + if (NULL == handle) { + HDF_LOGE("%s: open interface failed", __func__); + return HDF_FAILURE; + } + g_acmDevice->dataIface.handle = handle; + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface005(void) +{ + UsbFnInterfaceHandle handle; + struct UsbFnInterface *fn = NULL; + if (g_acmDevice == NULL || g_acmDevice->ctrlIface.fn == NULL) { + HDF_LOGE("%s: ctrlIface.handle is invail", __func__); + return HDF_FAILURE; + } + handle = UsbFnOpenInterface(fn); + if (NULL != handle) { + HDF_LOGE("%s: open interface success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestOpenInterface006(void) +{ + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRemove(void) +{ + int ret; + struct UsbFnDevice *fnDev = NULL; + + ret = UsbFnRemoveDevice(fnDev); + if (HDF_SUCCESS == ret) { + HDF_LOGE("%s: UsbFnRemoveDevice success!!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRemove002(void) +{ + int ret; + if (g_acmDevice == NULL || g_acmDevice->fnDev == NULL) { + HDF_LOGE("%s: fndev is null", __func__); + return HDF_FAILURE; + } + + ReleaseAcmDevice(g_acmDevice); + ret = UsbFnRemoveDevice(g_acmDevice->fnDev); + if (HDF_SUCCESS != ret) { + HDF_LOGE("%s: UsbFnRemoveDevice fail, ret = %d", __func__, ret); + return HDF_FAILURE; + } + OsalMemFree(g_acmDevice); + + return HDF_SUCCESS; +} + +int32_t UsbFnDviceTestRemove003(void) +{ + return HDF_SUCCESS; +} +