1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef USB_DEVICE_LITE_CDCACM_TEST_H 10 #define USB_DEVICE_LITE_CDCACM_TEST_H 11 12 #include <unistd.h> 13 #include <stdlib.h> 14 #include "usbfn_device.h" 15 #include "usbfn_request.h" 16 #include "usbfn_interface.h" 17 #include "osal_atomic.h" 18 #include "osal_mutex.h" 19 #include "osal_time.h" 20 21 #define TEST_TIMES 10 22 #define WAIT_TIMES 60 23 #define BUFFER_LEN 64 24 #define WAIT_100MS 100 25 #define SYNC_5000MS 5000 26 #define CDC_ACM 27 #define QUEUE_SIZE 8 28 #define PORT_RATE 9600 29 #define DATA_BIT 8 30 31 #define SS_MAX_PACKET_SIZE 1024 32 #define MAX_PACKET_SIZE 512 33 #define EP_ADD_NOTIFY 1 34 #define EP_ADD_DATA_IN 2 35 #define EP_ADD_DATA_OUT 3 36 #define DATA_EP_NUM 2 37 #define NOTIFY_EP_NUM 1 38 #define INTF_COUNT 2 39 40 #define ACM_NOTIFY_INTERVAL 32 /* ms */ 41 #define ACM_HS_NOTIFY_INTERVAL 9 /* ms */ 42 #define ACM_NOTIFY_MAXPACKET 10 /* notification + 2 bytes */ 43 44 #define ACM_CTRL_IDX 1 45 #define ACM_DATA_IDX 2 46 #define ACM_IAD_IDX 3 47 48 #define REQUEST_ALLOC_PIPE ((uint8_t)(0x20)) 49 #define REQUEST_ALLOC_LENGTH ((uint32_t)(0x0800)) 50 51 struct Serial { 52 struct AcmDevice *acm; 53 struct UsbCdcLineCoding lineCoding; 54 struct OsalMutex lock; 55 struct DListHead readPool; 56 struct DListHead readQueue; 57 int32_t readStarted; 58 int32_t readAllocated; 59 struct DListHead writePool; 60 int32_t writeStarted; 61 int32_t writeAllocated; 62 bool writeBusy; 63 bool suspended; 64 bool startDelayed; 65 int32_t refCount; 66 }; 67 68 struct AcmNotifyMethod { 69 void (*Connect)(struct AcmDevice *acm); 70 void (*Disconnect)(struct AcmDevice *acm); 71 int32_t (*SendBreak)(struct AcmDevice *acm, int32_t duration); 72 }; 73 74 struct AcmPipe { 75 uint8_t id; 76 uint16_t maxPacketSize; 77 struct UsbFnInterface *ctrlIface; 78 }; 79 80 struct AcmInterface { 81 struct UsbFnInterface *fn; 82 UsbFnInterfaceHandle handle; 83 }; 84 85 struct AcmDevice { 86 struct UsbFnDevice *fnDev; 87 struct AcmInterface ctrlIface; 88 struct AcmInterface dataIface; 89 struct AcmPipe notifyPipe; 90 struct AcmPipe dataInPipe; 91 struct AcmPipe dataOutPipe; 92 struct DListHead ctrlPool; 93 int32_t ctrlReqNum; 94 struct UsbFnRequest *notifyReq; 95 struct OsalMutex lock; 96 bool pending; 97 bool connect; 98 bool havedSubmit; 99 uint32_t enableEvtCnt; 100 char *udcName; 101 char submit; 102 char submitExit; 103 struct Serial *port; 104 struct UsbCdcLineCoding lineCoding; 105 uint16_t serialState; 106 #define SERIAL_STATE_DCD (1 << 0) 107 #define SERIAL_STATE_DSR (1 << 1) 108 #define SERIAL_STATE_BREAK (1 << 2) 109 #define SERIAL_STATE_RING (1 << 3) 110 #define SERIAL_STATE_FRAMING (1 << 4) 111 #define SERIAL_STATE_PARITY (1 << 5) 112 #define SERIAL_STATE_OVERRUN (1 << 6) 113 114 uint16_t handshakeBits; 115 /* notification callbacks */ 116 struct AcmNotifyMethod *notify; 117 }; 118 119 struct CtrlInfo { 120 uint8_t request; 121 struct AcmDevice *acm; 122 }; 123 124 struct AcmDevice *SetUpAcmDevice(void); 125 void ReleaseAcmDevice(struct AcmDevice *acm); 126 void AcmEventCallback(struct UsbFnEvent *event); 127 void AcmDeviceRelease(struct AcmDevice *acmDevice); 128 int32_t RemoveUsbDevice(void); 129 130 struct AcmDevice *UsbGetAcmDevice(void); 131 int32_t UsbFnDviceTestCreate(void); 132 int32_t UsbFnDviceTestCreate002(void); 133 int32_t UsbFnDviceTestCreate003(void); 134 int32_t UsbFnDviceTestCreate004(void); 135 int32_t UsbFnDviceTestCreate005(void); 136 int32_t UsbFnDviceTestCreate006(void); 137 int32_t UsbFnDviceTestStatus(void); 138 int32_t UsbFnDviceTestStatus002(void); 139 int32_t UsbFnDviceTestStatus003(void); 140 int32_t UsbFnDviceTestStatus004(void); 141 int32_t UsbFnDviceTestStatus005(void); 142 int32_t UsbFnDviceTestGetDevice(void); 143 int32_t UsbFnDviceTestGetDevice002(void); 144 int32_t UsbFnDviceTestGetDevice003(void); 145 int32_t UsbFnDviceTestGetDevice004(void); 146 int32_t UsbFnDviceTestGetDevice005(void); 147 int32_t UsbFnDviceTestGetDevice006(void); 148 int32_t UsbFnDviceTestGetInterface(void); 149 int32_t UsbFnDviceTestGetInterface002(void); 150 int32_t UsbFnDviceTestGetInterface003(void); 151 int32_t UsbFnDviceTestGetInterface004(void); 152 int32_t UsbFnDviceTestGetInterface005(void); 153 int32_t UsbFnDviceTestGetInterface006(void); 154 int32_t UsbFnDviceTestGetPipeInfo(void); 155 int32_t UsbFnDviceTestGetPipeInfo002(void); 156 int32_t UsbFnDviceTestGetPipeInfo003(void); 157 int32_t UsbFnDviceTestGetPipeInfo004(void); 158 int32_t UsbFnDviceTestGetPipeInfo005(void); 159 int32_t UsbFnDviceTestGetPipeInfo006(void); 160 int32_t UsbFnDviceTestRequestAsync(void); 161 int32_t UsbFnDviceTestRequestAsync002(void); 162 int32_t UsbFnDviceTestRequestAsync003(void); 163 int32_t UsbFnDviceTestRequestAsync004(void); 164 int32_t UsbFnDviceTestRequestAsync005(void); 165 int32_t UsbFnDviceTestRequestAsync006(void); 166 int32_t UsbFnDviceTestRequestSync(void); 167 int32_t UsbFnDviceTestRequestSync002(void); 168 int32_t UsbFnDviceTestRequestSync003(void); 169 int32_t UsbFnDviceTestRequestSync004(void); 170 int32_t UsbFnDviceTestRequestSync005(void); 171 int32_t UsbFnDviceTestRequestSync006(void); 172 int32_t UsbFnDviceTestRequestSync007(void); 173 int32_t UsbFnDviceTestRegistProp(void); 174 int32_t UsbFnDviceTestRegistProp002(void); 175 int32_t UsbFnDviceTestRegistProp003(void); 176 int32_t UsbFnDviceTestRegistProp004(void); 177 int32_t UsbFnDviceTestRegistProp005(void); 178 int32_t UsbFnDviceTestRegistProp006(void); 179 int32_t UsbFnDviceTestRegistProp007(void); 180 int32_t UsbFnDviceTestGetProp(void); 181 int32_t UsbFnDviceTestGetProp002(void); 182 int32_t UsbFnDviceTestGetProp003(void); 183 int32_t UsbFnDviceTestGetProp004(void); 184 int32_t UsbFnDviceTestGetProp005(void); 185 int32_t UsbFnDviceTestGetProp006(void); 186 int32_t UsbFnDviceTestGetProp007(void); 187 int32_t UsbFnDviceTestGetProp008(void); 188 int32_t UsbFnDviceTestSetProp(void); 189 int32_t UsbFnDviceTestSetProp002(void); 190 int32_t UsbFnDviceTestSetProp003(void); 191 int32_t UsbFnDviceTestSetProp004(void); 192 int32_t UsbFnDviceTestSetProp005(void); 193 int32_t UsbFnDviceTestSetProp006(void); 194 int32_t UsbFnDviceTestSetProp007(void); 195 int32_t UsbFnDviceTestAllocCtrlRequest(void); 196 int32_t UsbFnDviceTestAllocCtrlRequest002(void); 197 int32_t UsbFnDviceTestAllocCtrlRequest003(void); 198 int32_t UsbFnDviceTestAllocCtrlRequest004(void); 199 int32_t UsbFnDviceTestAllocCtrlRequest005(void); 200 int32_t UsbFnDviceTestAllocCtrlRequest006(void); 201 int32_t UsbFnDviceTestAllocCtrlRequest007(void); 202 int32_t UsbFnDviceTestAllocCtrlRequest008(void); 203 int32_t UsbFnDviceTestAllocRequest(void); 204 int32_t UsbFnDviceTestAllocRequest002(void); 205 int32_t UsbFnDviceTestAllocRequest003(void); 206 int32_t UsbFnDviceTestAllocRequest004(void); 207 int32_t UsbFnDviceTestAllocRequest005(void); 208 int32_t UsbFnDviceTestAllocRequest006(void); 209 int32_t UsbFnDviceTestAllocRequest007(void); 210 int32_t UsbFnDviceTestAllocRequest008(void); 211 int32_t UsbFnDviceTestAllocRequest009(void); 212 int32_t UsbFnDviceTestFreeRequest(void); 213 int32_t UsbFnDviceTestFreeRequest002(void); 214 int32_t UsbFnDviceTestFreeRequest003(void); 215 int32_t UsbFnDviceTestFreeRequest004(void); 216 int32_t UsbFnDviceTestFreeRequest005(void); 217 int32_t UsbFnDviceTestFreeRequest006(void); 218 int32_t UsbFnDviceTestGetRequestStatus(void); 219 int32_t UsbFnDviceTestGetRequestStatus002(void); 220 int32_t UsbFnDviceTestGetRequestStatus003(void); 221 int32_t UsbFnDviceTestGetRequestStatus004(void); 222 int32_t UsbFnDviceTestGetRequestStatus005(void); 223 int32_t UsbFnDviceTestGetRequestStatus006(void); 224 int32_t UsbFnDviceTestCancelRequest(void); 225 int32_t UsbFnDviceTestCancelRequest002(void); 226 int32_t UsbFnDviceTestCancelRequest003(void); 227 int32_t UsbFnDviceTestCancelRequest004(void); 228 int32_t UsbFnDviceTestCancelRequest005(void); 229 int32_t UsbFnDviceTestCancelRequest006(void); 230 int32_t UsbFnDviceTestStopReceEvent(void); 231 int32_t UsbFnDviceTestStopReceEvent002(void); 232 int32_t UsbFnDviceTestStopReceEvent003(void); 233 int32_t UsbFnDviceTestStopReceEvent004(void); 234 int32_t UsbFnDviceTestStartReceEvent(void); 235 int32_t UsbFnDviceTestStartReceEvent002(void); 236 int32_t UsbFnDviceTestStartReceEvent003(void); 237 int32_t UsbFnDviceTestStartReceEvent004(void); 238 int32_t UsbFnDviceTestStartReceEvent005(void); 239 int32_t UsbFnDviceTestStartReceEvent006(void); 240 int32_t UsbFnDviceTestStartReceEvent007(void); 241 int32_t UsbFnDviceTestCloseInterface(void); 242 int32_t UsbFnDviceTestCloseInterface002(void); 243 int32_t UsbFnDviceTestCloseInterface003(void); 244 int32_t UsbFnDviceTestCloseInterface004(void); 245 int32_t UsbFnDviceTestOpenInterface(void); 246 int32_t UsbFnDviceTestOpenInterface002(void); 247 int32_t UsbFnDviceTestOpenInterface003(void); 248 int32_t UsbFnDviceTestOpenInterface004(void); 249 int32_t UsbFnDviceTestOpenInterface005(void); 250 int32_t UsbFnDviceTestRemove(void); 251 int32_t UsbFnDviceTestRemove002(void); 252 253 #endif 254