1 /*
2 * Copyright (c) 2020-2021 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 #include "usb_test.h"
10 #include "device_resource_if.h"
11 #include "hdf_base.h"
12 #include "hdf_device_desc.h"
13 #include "hdf_log.h"
14 #include "osal_mem.h"
15 #include "osal_time.h"
16 #include "usb_ddk_interface.h"
17 #ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY
18 #include "usb_pnp_notify.h"
19 #endif
20
21 #define HDF_LOG_TAG USB_TEST_C
22
23 static struct UsbSession *g_session = NULL;
24 static struct AcmDevice g_deviceService = {0};
25 static struct AcmDevice *g_acm = &g_deviceService;
26 static struct UsbInterface *g_ecmDataIface = NULL;
27 static struct UsbInterface *g_ecmIntIface = NULL;
28 static UsbInterfaceHandle *g_ecmDataDevHandle = NULL;
29 static UsbInterfaceHandle *g_ecmIntDevHandle = NULL;
30 static bool g_initFlag;
31 static bool g_writeBufFlag = 0;
32 static UsbInterfaceHandle *g_acmDataDevHandle[USB_LOOP_NUM];
33
AcmReadBulk(struct UsbRequest * req)34 static void AcmReadBulk(struct UsbRequest *req)
35 {
36 uint32_t size;
37 int32_t status = req->compInfo.status;
38 size = req->compInfo.actualLength;
39 printf("Bulk status:%d,actualLength:%u\n", status, size);
40 switch (status) {
41 case 0:
42 break;
43 case -ECONNRESET:
44 case -ENOENT:
45 case -ESHUTDOWN:
46 return;
47 default:
48 goto EXIT;
49 }
50 EXIT:
51 return;
52 }
53
AcmWriteBulk(struct UsbRequest * req)54 static void AcmWriteBulk(struct UsbRequest *req)
55 {
56 if (req == NULL) {
57 printf("%s:%d req is NULL!", __func__, __LINE__);
58 return;
59 }
60
61 int32_t status = req->compInfo.status;
62 printf("Bulk Write status:%d\n", status);
63 struct AcmWb *wb = (struct AcmWb *)req->compInfo.userData;
64 switch (status) {
65 case 0:
66 wb->use = 0;
67 break;
68 case -ECONNRESET:
69 case -ENOENT:
70 case -ESHUTDOWN:
71 return;
72 default:
73 return;
74 }
75
76 return;
77 }
78
AcmWriteIsoCallback(struct UsbRequest * requestArg)79 static void AcmWriteIsoCallback(struct UsbRequest *requestArg)
80 {
81 struct UsbRequest *req = requestArg;
82 printf("%s:%d status:%d\n", __func__, __LINE__, req->compInfo.status);
83 }
84
AcmWriteBufAllocHandle(const struct AcmDevice * acm)85 static int32_t AcmWriteBufAllocHandle(const struct AcmDevice *acm)
86 {
87 int32_t i;
88 struct AcmWb *wb;
89 for (wb = (struct AcmWb *)&acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
90 wb->buf = (uint8_t *)OsalMemCalloc(acm->writeSize);
91 if (!wb->buf) {
92 while (i > 0) {
93 --i;
94 --wb;
95 OsalMemFree(wb->buf);
96 wb->buf = NULL;
97 }
98 return -HDF_ERR_MALLOC_FAIL;
99 }
100 g_writeBufFlag = true;
101 }
102
103 return HDF_SUCCESS;
104 }
105
AcmWriteBufAlloc(struct AcmDevice * acm)106 static int32_t AcmWriteBufAlloc(struct AcmDevice *acm)
107 {
108 int32_t ret = HDF_SUCCESS;
109
110 if (!g_writeBufFlag) {
111 ret = AcmWriteBufAllocHandle(acm);
112 }
113
114 return ret;
115 }
116
AcmWriteBufFree(struct AcmDevice * acm)117 static void AcmWriteBufFree(struct AcmDevice *acm)
118 {
119 int32_t i;
120 struct AcmWb *wb;
121 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
122 if (wb->buf) {
123 OsalMemFree(wb->buf);
124 wb->buf = NULL;
125 }
126 }
127 g_writeBufFlag = false;
128 }
129
AcmCtrlIrq(struct UsbRequest * req)130 static void AcmCtrlIrq(struct UsbRequest *req)
131 {
132 if (req == NULL) {
133 printf("%s:%d req is NULL!", __func__, __LINE__);
134 return;
135 }
136 int32_t status = req->compInfo.status;
137 unsigned int currentSize = req->compInfo.actualLength;
138 printf("Irqstatus:%d,actualLength:%u\n", status, currentSize);
139 }
140
UsbControlMsg(struct TestControlMsgData msgData)141 static struct UsbControlRequest UsbControlMsg(struct TestControlMsgData msgData)
142 {
143 struct UsbControlRequest dr;
144 dr.target = (UsbRequestTargetType)(msgData.requestType & TARGET_MASK);
145 dr.reqType = (UsbControlRequestType)((msgData.requestType >> USB_TYPE_OFFSET) & REQUEST_TYPE_MASK);
146 dr.directon = (UsbRequestDirection)((msgData.requestType >> USB_DIR_OFFSET) & DIRECTION_MASK);
147 dr.request = msgData.request;
148 dr.value = CPU_TO_LE16(msgData.value);
149 dr.index = CPU_TO_LE16(msgData.index);
150 dr.buffer = msgData.data;
151 dr.length = CPU_TO_LE16(msgData.size);
152 return dr;
153 }
154
CheckHostSdkIfInit001(void)155 static int32_t CheckHostSdkIfInit001(void)
156 {
157 int32_t ret = UsbInitHostSdk(&g_session);
158 if (ret != HDF_SUCCESS) {
159 HDF_LOGE("%s: error", __func__);
160 return HDF_FAILURE;
161 }
162 g_acm->session = g_session;
163 return HDF_SUCCESS;
164 }
165
CheckHostSdkIfExit001(void)166 static int32_t CheckHostSdkIfExit001(void)
167 {
168 int32_t ret = UsbExitHostSdk(g_acm->session);
169 if (ret != HDF_SUCCESS) {
170 HDF_LOGE("%s: error", __func__);
171 return HDF_FAILURE;
172 }
173 g_acm->session = NULL;
174 g_session = g_acm->session;
175 return HDF_SUCCESS;
176 }
177
CheckHostSdkIfInit002(void)178 static int32_t CheckHostSdkIfInit002(void)
179 {
180 int32_t ret = UsbInitHostSdk(NULL);
181 if (ret != HDF_SUCCESS) {
182 HDF_LOGE("%s: error", __func__);
183 return HDF_FAILURE;
184 }
185 return HDF_SUCCESS;
186 }
187
CheckHostSdkIfExit002(void)188 static int32_t CheckHostSdkIfExit002(void)
189 {
190 int32_t ret = UsbExitHostSdk(NULL);
191 if (ret != HDF_SUCCESS) {
192 HDF_LOGE("%s: error", __func__);
193 return HDF_FAILURE;
194 }
195 return HDF_SUCCESS;
196 }
197
CheckHostSdkIfInit003(void)198 static int32_t CheckHostSdkIfInit003(void)
199 {
200 for (int32_t i = 0; i < USB_LOOP_NUM; i++) {
201 int32_t ret = UsbInitHostSdk(&g_session);
202 if (ret != HDF_SUCCESS) {
203 HDF_LOGE("%s: error", __func__);
204 return HDF_FAILURE;
205 }
206 g_acm->session = g_session;
207 ret = UsbExitHostSdk(g_acm->session);
208 if (ret != HDF_SUCCESS) {
209 HDF_LOGE("%s: error", __func__);
210 return HDF_FAILURE;
211 }
212 g_acm->session = NULL;
213 g_session = g_acm->session;
214 }
215 return HDF_SUCCESS;
216 }
217
CheckHostSdkIfInit004(void)218 static int32_t CheckHostSdkIfInit004(void)
219 {
220 for (int32_t i = 0; i < USB_LOOP_NUM; i++) {
221 int32_t ret = UsbInitHostSdk(NULL);
222 if (ret != HDF_SUCCESS) {
223 HDF_LOGE("%s: error", __func__);
224 return HDF_FAILURE;
225 }
226 ret = UsbExitHostSdk(NULL);
227 if (ret != HDF_SUCCESS) {
228 HDF_LOGE("%s: error", __func__);
229 return HDF_FAILURE;
230 }
231 }
232 return HDF_SUCCESS;
233 }
234
CheckHostSdkIfInit005(void)235 static int32_t CheckHostSdkIfInit005(void)
236 {
237 int32_t ret = UsbInitHostSdk(&g_session);
238 if (ret != HDF_SUCCESS) {
239 HDF_LOGE("%s: error", __func__);
240 return HDF_FAILURE;
241 }
242 g_acm->session = g_session;
243 return HDF_SUCCESS;
244 }
245
CheckHostSdkIfClaimInterface001(void)246 static int32_t CheckHostSdkIfClaimInterface001(void)
247 {
248 g_acm->interfaceIndex = 1U;
249
250 g_acm->dataIface =
251 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
252 if (g_acm->dataIface == NULL) {
253 HDF_LOGE("%s: error", __func__);
254 return HDF_FAILURE;
255 }
256 return HDF_SUCCESS;
257 }
258
CheckHostSdkIfReleaseInterface001(void)259 static int32_t CheckHostSdkIfReleaseInterface001(void)
260 {
261 int32_t ret = UsbReleaseInterface(g_acm->dataIface);
262 if (ret != HDF_SUCCESS) {
263 HDF_LOGE("%s: error", __func__);
264 return HDF_FAILURE;
265 }
266 return HDF_SUCCESS;
267 }
268
CheckHostSdkIfClaimInterface002(void)269 static int32_t CheckHostSdkIfClaimInterface002(void)
270 {
271 g_acm->interfaceIndex = 0U;
272
273 g_acm->intIface =
274 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
275 if (g_acm->intIface == NULL) {
276 HDF_LOGE("%s: error", __func__);
277 return HDF_FAILURE;
278 }
279 return HDF_SUCCESS;
280 }
281
CheckHostSdkIfReleaseInterface002(void)282 static int32_t CheckHostSdkIfReleaseInterface002(void)
283 {
284 int32_t ret = UsbReleaseInterface(g_acm->intIface);
285 if (ret != HDF_SUCCESS) {
286 HDF_LOGE("%s: error", __func__);
287 return HDF_FAILURE;
288 }
289 return HDF_SUCCESS;
290 }
291
CheckHostSdkIfClaimInterface003(void)292 static int32_t CheckHostSdkIfClaimInterface003(void)
293 {
294 g_acm->interfaceIndex = USB_CTRL_INTERFACE_ID;
295
296 g_acm->ctrIface =
297 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
298 if (g_acm->ctrIface == NULL) {
299 HDF_LOGE("%s: error", __func__);
300 return HDF_FAILURE;
301 }
302 return HDF_SUCCESS;
303 }
304
CheckHostSdkIfReleaseInterface003(void)305 static int32_t CheckHostSdkIfReleaseInterface003(void)
306 {
307 int32_t ret = UsbReleaseInterface(g_acm->ctrIface);
308 if (ret != HDF_SUCCESS) {
309 HDF_LOGE("%s: error", __func__);
310 return HDF_FAILURE;
311 }
312 return HDF_SUCCESS;
313 }
314
CheckHostSdkIfClaimInterface004(void)315 static int32_t CheckHostSdkIfClaimInterface004(void)
316 {
317 g_acm->interfaceIndex = 2U;
318
319 g_acm->dataIface =
320 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
321 if (g_acm->dataIface == NULL) {
322 HDF_LOGE("%s: error", __func__);
323 return HDF_FAILURE;
324 }
325 return HDF_SUCCESS;
326 }
327
CheckHostSdkIfClaimInterface005(void)328 static int32_t CheckHostSdkIfClaimInterface005(void)
329 {
330 g_acm->interfaceIndex = 3U;
331
332 g_acm->dataIface =
333 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
334 if (g_acm->dataIface == NULL) {
335 HDF_LOGE("%s: error", __func__);
336 return HDF_FAILURE;
337 }
338 return HDF_SUCCESS;
339 }
340
CheckHostSdkIfClaimInterface006(void)341 static int32_t CheckHostSdkIfClaimInterface006(void)
342 {
343 g_acm = &g_deviceService;
344 g_acm->interfaceIndex = 3U;
345 g_acm->dataIface =
346 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
347 if (g_acm->dataIface == NULL) {
348 HDF_LOGE("%s: error", __func__);
349 return HDF_FAILURE;
350 }
351
352 g_acm->interfaceIndex = 2U;
353 g_acm->intIface =
354 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
355 if (g_acm->intIface == NULL) {
356 HDF_LOGE("%s: error", __func__);
357 return HDF_FAILURE;
358 }
359
360 g_acm->interfaceIndex = 0U;
361 g_ecmIntIface =
362 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
363 if (g_ecmIntIface == NULL) {
364 HDF_LOGE("%s: error", __func__);
365 return HDF_FAILURE;
366 }
367
368 g_acm->interfaceIndex = 1U;
369 g_ecmDataIface =
370 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
371 if (g_ecmDataIface == NULL) {
372 HDF_LOGE("%s: error", __func__);
373 return HDF_FAILURE;
374 }
375
376 g_acm->interfaceIndex = USB_CTRL_INTERFACE_ID;
377 g_acm->ctrIface =
378 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
379 if (g_acm->ctrIface == NULL) {
380 HDF_LOGE("%s: error", __func__);
381 return HDF_FAILURE;
382 }
383 return HDF_SUCCESS;
384 }
385
CheckHostSdkIfOpenInterface001(void)386 static int32_t CheckHostSdkIfOpenInterface001(void)
387 {
388 g_acm->data_devHandle = UsbOpenInterface(g_acm->dataIface);
389 if (g_acm->data_devHandle == NULL) {
390 HDF_LOGE("%s: error", __func__);
391 return HDF_FAILURE;
392 }
393 return HDF_SUCCESS;
394 }
395
CheckHostSdkIfCloseInterface001(void)396 static int32_t CheckHostSdkIfCloseInterface001(void)
397 {
398 int32_t ret = UsbCloseInterface(g_acm->data_devHandle);
399 if (ret != HDF_SUCCESS) {
400 HDF_LOGE("%s: error", __func__);
401 return HDF_FAILURE;
402 }
403 return HDF_SUCCESS;
404 }
405
CheckHostSdkIfOpenInterface002(void)406 static int32_t CheckHostSdkIfOpenInterface002(void)
407 {
408 g_acm->int_devHandle = UsbOpenInterface(g_acm->intIface);
409 if (g_acm->int_devHandle == NULL) {
410 HDF_LOGE("%s: error", __func__);
411 return HDF_FAILURE;
412 }
413 return HDF_SUCCESS;
414 }
415
CheckHostSdkIfCloseInterface002(void)416 static int32_t CheckHostSdkIfCloseInterface002(void)
417 {
418 int32_t ret = UsbCloseInterface(g_acm->int_devHandle);
419 if (ret != HDF_SUCCESS) {
420 HDF_LOGE("%s: error", __func__);
421 return HDF_FAILURE;
422 }
423 return HDF_SUCCESS;
424 }
425
CheckHostSdkIfOpenInterface003(void)426 static int32_t CheckHostSdkIfOpenInterface003(void)
427 {
428 g_acm->ctrl_devHandle = UsbOpenInterface(g_acm->ctrIface);
429 if (g_acm->ctrl_devHandle == NULL) {
430 HDF_LOGE("%s: error", __func__);
431 return HDF_FAILURE;
432 }
433 return HDF_SUCCESS;
434 }
435
CheckHostSdkIfCloseInterface003(void)436 static int32_t CheckHostSdkIfCloseInterface003(void)
437 {
438 int32_t ret = UsbCloseInterface(g_acm->ctrl_devHandle);
439 if (ret != HDF_SUCCESS) {
440 HDF_LOGE("%s: error", __func__);
441 return HDF_FAILURE;
442 }
443 return HDF_SUCCESS;
444 }
445
CheckHostSdkIfOpenInterface004(void)446 static int32_t CheckHostSdkIfOpenInterface004(void)
447 {
448 g_acm->data_devHandle = UsbOpenInterface(NULL);
449 if (g_acm->data_devHandle == NULL) {
450 HDF_LOGE("%s: error", __func__);
451 return HDF_SUCCESS;
452 }
453 return HDF_FAILURE;
454 }
455
CheckHostSdkIfOpenInterface005(void)456 static int32_t CheckHostSdkIfOpenInterface005(void)
457 {
458 for (int32_t i = 0; i < USB_LOOP_NUM; i++) {
459 g_acmDataDevHandle[i] = UsbOpenInterface(g_acm->dataIface);
460 if (g_acmDataDevHandle[i] == NULL) {
461 HDF_LOGE("%s:%d i=%d error", __func__, __LINE__, i);
462 return HDF_FAILURE;
463 }
464 }
465 return HDF_SUCCESS;
466 }
467
CheckHostSdkIfCloseInterface005(void)468 static int32_t CheckHostSdkIfCloseInterface005(void)
469 {
470 for (int32_t i = 0; i < USB_LOOP_NUM; i++) {
471 int32_t ret = UsbCloseInterface(g_acmDataDevHandle[i]);
472 if (ret != HDF_SUCCESS) {
473 HDF_LOGE("%s: error", __func__);
474 return HDF_FAILURE;
475 }
476 }
477 return HDF_SUCCESS;
478 }
479
CheckHostSdkIfOpenInterface006(void)480 static int32_t CheckHostSdkIfOpenInterface006(void)
481 {
482 g_acm->data_devHandle = UsbOpenInterface(g_acm->dataIface);
483 if (g_acm->data_devHandle == NULL) {
484 HDF_LOGE("%s: error", __func__);
485 return HDF_FAILURE;
486 }
487 g_acm->int_devHandle = UsbOpenInterface(g_acm->intIface);
488 if (g_acm->int_devHandle == NULL) {
489 HDF_LOGE("%s: error", __func__);
490 return HDF_FAILURE;
491 }
492 g_acm->ctrl_devHandle = UsbOpenInterface(g_acm->ctrIface);
493 if (g_acm->ctrl_devHandle == NULL) {
494 HDF_LOGE("%s: error", __func__);
495 return HDF_FAILURE;
496 }
497 g_ecmDataDevHandle = UsbOpenInterface(g_ecmDataIface);
498 if (g_ecmDataDevHandle == NULL) {
499 HDF_LOGE("%s: error", __func__);
500 return HDF_FAILURE;
501 }
502 g_ecmIntDevHandle = UsbOpenInterface(g_ecmIntIface);
503 if (g_ecmIntDevHandle == NULL) {
504 HDF_LOGE("%s: error", __func__);
505 return HDF_FAILURE;
506 }
507 return HDF_SUCCESS;
508 }
509
CheckHostSdkIfSelectInterfaceSetting001(void)510 static int32_t CheckHostSdkIfSelectInterfaceSetting001(void)
511 {
512 int32_t settingIndex = 0;
513 int32_t ret = UsbSelectInterfaceSetting(g_ecmDataDevHandle, settingIndex, &g_ecmDataIface);
514 if (ret != HDF_SUCCESS) {
515 HDF_LOGE("%s: error", __func__);
516 return HDF_FAILURE;
517 }
518 return HDF_SUCCESS;
519 }
520
CheckHostSdkIfSelectInterfaceSetting002(void)521 static int32_t CheckHostSdkIfSelectInterfaceSetting002(void)
522 {
523 int32_t settingIndex = 10;
524 int32_t ret = UsbSelectInterfaceSetting(g_ecmDataDevHandle, settingIndex, &g_ecmDataIface);
525 if (ret != HDF_SUCCESS) {
526 HDF_LOGE("%s: error", __func__);
527 return HDF_FAILURE;
528 }
529 return HDF_SUCCESS;
530 }
531
CheckHostSdkIfSelectInterfaceSetting003(void)532 static int32_t CheckHostSdkIfSelectInterfaceSetting003(void)
533 {
534 int32_t settingIndex = 100;
535 int32_t ret = UsbSelectInterfaceSetting(g_ecmDataDevHandle, settingIndex, &g_ecmDataIface);
536 if (ret != HDF_SUCCESS) {
537 HDF_LOGE("%s: error", __func__);
538 return HDF_FAILURE;
539 }
540 return HDF_SUCCESS;
541 }
542
CheckHostSdkIfSelectInterfaceSetting004(void)543 static int32_t CheckHostSdkIfSelectInterfaceSetting004(void)
544 {
545 int32_t settingIndex = 200;
546 int32_t ret = UsbSelectInterfaceSetting(g_ecmDataDevHandle, settingIndex, &g_ecmDataIface);
547 if (ret != HDF_SUCCESS) {
548 HDF_LOGE("%s: error", __func__);
549 return HDF_FAILURE;
550 }
551 return HDF_SUCCESS;
552 }
553
CheckHostSdkIfSelectInterfaceSetting005(void)554 static int32_t CheckHostSdkIfSelectInterfaceSetting005(void)
555 {
556 int32_t settingIndex = USB_MAX_BYTE;
557 int32_t ret = UsbSelectInterfaceSetting(g_ecmDataDevHandle, settingIndex, &g_ecmDataIface);
558 if (ret != HDF_SUCCESS) {
559 HDF_LOGE("%s: error", __func__);
560 return HDF_FAILURE;
561 }
562 return HDF_SUCCESS;
563 }
564
CheckHostSdkIfSelectInterfaceSetting006(void)565 static int32_t CheckHostSdkIfSelectInterfaceSetting006(void)
566 {
567 int32_t settingIndex = 1;
568 int32_t ret = UsbSelectInterfaceSetting(g_ecmDataDevHandle, settingIndex, &g_ecmDataIface);
569 if (ret != HDF_SUCCESS) {
570 HDF_LOGE("%s: error", __func__);
571 return HDF_FAILURE;
572 }
573 return HDF_SUCCESS;
574 }
575
CheckHostSdkIfClaimInterface007(void)576 static int32_t CheckHostSdkIfClaimInterface007(void)
577 {
578 g_acm->interfaceIndex = 0U;
579 g_ecmIntIface =
580 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
581 if (g_ecmIntIface == NULL) {
582 HDF_LOGE("%s: error", __func__);
583 return HDF_FAILURE;
584 }
585 return HDF_SUCCESS;
586 }
587
CheckHostSdkIfClaimInterface008(void)588 static int32_t CheckHostSdkIfClaimInterface008(void)
589 {
590 g_acm->interfaceIndex = 1U;
591 g_ecmDataIface =
592 (struct UsbInterface *)UsbClaimInterface(g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->interfaceIndex);
593 if (g_ecmDataIface == NULL) {
594 HDF_LOGE("%s: error", __func__);
595 return HDF_FAILURE;
596 }
597 return HDF_SUCCESS;
598 }
599
CheckHostSdkIfGetPipe001(void)600 static int32_t CheckHostSdkIfGetPipe001(void)
601 {
602 struct UsbPipeInfo p;
603 uint8_t i;
604 for (i = 0; i <= g_acm->dataIface->info.pipeNum; i++) {
605 int32_t ret = UsbGetPipeInfo(NULL, g_acm->dataIface->info.curAltSetting, i, &p);
606 if (ret < 0) {
607 continue;
608 }
609 if ((p.pipeDirection == USB_PIPE_DIRECTION_IN) && (p.pipeType == USB_PIPE_TYPE_BULK)) {
610 struct UsbPipeInfo *pi = (struct UsbPipeInfo *)OsalMemCalloc(sizeof(struct UsbPipeInfo));
611 if (pi == NULL) {
612 HDF_LOGE("%s: error", __func__);
613 return HDF_FAILURE;
614 }
615 p.interfaceId = g_acm->dataIface->info.interfaceIndex;
616 *pi = p;
617 g_acm->dataInPipe = pi;
618 break;
619 }
620 }
621 if (i > g_acm->dataIface->info.pipeNum) {
622 return HDF_FAILURE;
623 }
624 if (g_acm->dataInPipe == NULL) {
625 HDF_LOGE("%s: error", __func__);
626 return HDF_FAILURE;
627 }
628 return HDF_SUCCESS;
629 }
630
CheckHostSdkIfGetPipe002(void)631 static int32_t CheckHostSdkIfGetPipe002(void)
632 {
633 struct UsbPipeInfo p;
634 for (uint8_t i = 0; i <= g_acm->dataIface->info.pipeNum; i++) {
635 int32_t ret = UsbGetPipeInfo(g_acm->data_devHandle, g_acm->dataIface->info.curAltSetting, i, &p);
636 if (ret < 0) {
637 continue;
638 }
639 if ((p.pipeDirection == USB_PIPE_DIRECTION_IN) && (p.pipeType == USB_PIPE_TYPE_BULK)) {
640 struct UsbPipeInfo *pi = (struct UsbPipeInfo *)OsalMemCalloc(sizeof(struct UsbPipeInfo));
641 if (pi == NULL) {
642 return HDF_FAILURE;
643 }
644 p.interfaceId = g_acm->dataIface->info.interfaceIndex;
645 *pi = p;
646 g_acm->dataInPipe = pi;
647 break;
648 }
649 }
650 if (g_acm->dataInPipe == NULL) {
651 HDF_LOGE("%s: error", __func__);
652 return HDF_FAILURE;
653 }
654 return HDF_SUCCESS;
655 }
656
CheckHostSdkIfGetPipe003(void)657 static int32_t CheckHostSdkIfGetPipe003(void)
658 {
659 struct UsbPipeInfo p;
660 uint8_t i;
661 for (i = 0; i <= g_acm->dataIface->info.pipeNum; i++) {
662 int32_t ret = UsbGetPipeInfo(NULL, g_acm->dataIface->info.curAltSetting, i, &p);
663 if (ret < 0) {
664 continue;
665 }
666 if ((p.pipeDirection == USB_PIPE_DIRECTION_OUT) && (p.pipeType == USB_PIPE_TYPE_BULK)) {
667 struct UsbPipeInfo *pi = (struct UsbPipeInfo *)OsalMemCalloc(sizeof(struct UsbPipeInfo));
668 if (pi == NULL) {
669 HDF_LOGE("%s: error", __func__);
670 return HDF_FAILURE;
671 }
672 p.interfaceId = g_acm->dataIface->info.interfaceIndex;
673 *pi = p;
674 g_acm->dataOutPipe = pi;
675 break;
676 }
677 }
678 if (i > g_acm->dataIface->info.pipeNum) {
679 return HDF_FAILURE;
680 }
681 if (g_acm->dataOutPipe == NULL) {
682 HDF_LOGE("%s: error", __func__);
683 return HDF_FAILURE;
684 }
685 return HDF_SUCCESS;
686 }
687
CheckHostSdkIfGetPipe004(void)688 static int32_t CheckHostSdkIfGetPipe004(void)
689 {
690 struct UsbPipeInfo p;
691 for (uint8_t i = 0; i <= g_acm->dataIface->info.pipeNum; i++) {
692 int32_t ret = UsbGetPipeInfo(g_acm->data_devHandle, g_acm->dataIface->info.curAltSetting, i, &p);
693 if (ret < 0) {
694 continue;
695 }
696 if ((p.pipeDirection == USB_PIPE_DIRECTION_OUT) && (p.pipeType == USB_PIPE_TYPE_BULK)) {
697 struct UsbPipeInfo *pi = (struct UsbPipeInfo *)OsalMemCalloc(sizeof(struct UsbPipeInfo));
698 if (pi == NULL) {
699 return HDF_FAILURE;
700 }
701 p.interfaceId = g_acm->dataIface->info.interfaceIndex;
702 *pi = p;
703 g_acm->dataOutPipe = pi;
704 break;
705 }
706 }
707 if (g_acm->dataOutPipe == NULL) {
708 HDF_LOGE("%s: error", __func__);
709 return HDF_FAILURE;
710 }
711 return HDF_SUCCESS;
712 }
713
CheckHostSdkIfGetPipe005(void)714 static int32_t CheckHostSdkIfGetPipe005(void)
715 {
716 struct UsbPipeInfo p;
717 uint8_t i;
718 for (i = 0; i <= g_acm->intIface->info.pipeNum; i++) {
719 int32_t ret = UsbGetPipeInfo(NULL, g_acm->intIface->info.curAltSetting, i, &p);
720 if (ret < 0) {
721 continue;
722 }
723 if ((p.pipeDirection == USB_PIPE_DIRECTION_IN) && (p.pipeType == USB_PIPE_TYPE_INTERRUPT)) {
724 struct UsbPipeInfo *pi = (struct UsbPipeInfo *)OsalMemCalloc(sizeof(struct UsbPipeInfo));
725 if (pi == NULL) {
726 return HDF_FAILURE;
727 }
728 p.interfaceId = g_acm->intIface->info.interfaceIndex;
729 *pi = p;
730 g_acm->intPipe = pi;
731 break;
732 }
733 }
734 if (i > g_acm->intIface->info.pipeNum) {
735 return HDF_FAILURE;
736 }
737 if (g_acm->intPipe == NULL) {
738 HDF_LOGE("%s: error", __func__);
739 return HDF_FAILURE;
740 }
741 return HDF_SUCCESS;
742 }
743
CheckHostSdkIfGetPipe006(void)744 static int32_t CheckHostSdkIfGetPipe006(void)
745 {
746 struct UsbPipeInfo p;
747 for (uint8_t i = 0; i <= g_acm->intIface->info.pipeNum; i++) {
748 int32_t ret = UsbGetPipeInfo(g_acm->int_devHandle, g_acm->intIface->info.curAltSetting, i, &p);
749 if (ret < 0) {
750 continue;
751 }
752 if ((p.pipeDirection == USB_PIPE_DIRECTION_IN) && (p.pipeType == USB_PIPE_TYPE_INTERRUPT)) {
753 struct UsbPipeInfo *pi = (struct UsbPipeInfo *)OsalMemCalloc(sizeof(struct UsbPipeInfo));
754 if (pi == NULL) {
755 return HDF_FAILURE;
756 }
757 p.interfaceId = g_acm->intIface->info.interfaceIndex;
758 *pi = p;
759 g_acm->intPipe = pi;
760 break;
761 }
762 }
763 if (g_acm->intPipe == NULL) {
764 HDF_LOGE("%s: error", __func__);
765 return HDF_FAILURE;
766 }
767 return HDF_SUCCESS;
768 }
769
CheckHostSdkIfGetPipe007(void)770 static int32_t CheckHostSdkIfGetPipe007(void)
771 {
772 struct UsbPipeInfo p;
773 uint8_t i;
774 g_acm->interfaceIndex = USB_CTRL_INTERFACE_ID;
775 for (i = 0; i <= g_acm->ctrIface->info.pipeNum; i++) {
776 int32_t ret = UsbGetPipeInfo(NULL, g_acm->ctrIface->info.curAltSetting, i, &p);
777 if (ret < 0) {
778 continue;
779 }
780 if ((p.pipeDirection == USB_PIPE_DIRECTION_OUT) && (p.pipeType == USB_PIPE_TYPE_CONTROL)) {
781 struct UsbPipeInfo *pi = (struct UsbPipeInfo *)OsalMemCalloc(sizeof(struct UsbPipeInfo));
782 if (pi == NULL) {
783 return HDF_FAILURE;
784 }
785 p.interfaceId = g_acm->interfaceIndex;
786 *pi = p;
787 g_acm->ctrPipe = pi;
788 break;
789 }
790 }
791 if (i > g_acm->ctrIface->info.pipeNum) {
792 return HDF_FAILURE;
793 }
794 if (g_acm->ctrPipe == NULL) {
795 HDF_LOGE("%s: error", __func__);
796 return HDF_FAILURE;
797 }
798 return HDF_SUCCESS;
799 }
800
CheckHostSdkIfGetPipe008(void)801 static int32_t CheckHostSdkIfGetPipe008(void)
802 {
803 struct UsbPipeInfo p;
804 g_acm->interfaceIndex = USB_CTRL_INTERFACE_ID;
805 for (uint8_t i = 0; i <= g_acm->ctrIface->info.pipeNum; i++) {
806 int32_t ret = UsbGetPipeInfo(g_acm->ctrl_devHandle, g_acm->ctrIface->info.curAltSetting, i, &p);
807 if (ret < 0) {
808 continue;
809 }
810 if ((p.pipeDirection == USB_PIPE_DIRECTION_OUT) && (p.pipeType == USB_PIPE_TYPE_CONTROL)) {
811 struct UsbPipeInfo *pi = (struct UsbPipeInfo *)OsalMemCalloc(sizeof(struct UsbPipeInfo));
812 if (pi == NULL) {
813 return HDF_FAILURE;
814 }
815 p.interfaceId = g_acm->interfaceIndex;
816 *pi = p;
817 g_acm->ctrPipe = pi;
818 break;
819 }
820 }
821 if (g_acm->ctrPipe == NULL) {
822 HDF_LOGE("%s: error", __func__);
823 return HDF_FAILURE;
824 }
825 return HDF_SUCCESS;
826 }
827
CheckHostSdkIfAllocRequest001(void)828 static int32_t CheckHostSdkIfAllocRequest001(void)
829 {
830 g_acm->readSize = g_acm->dataInPipe->maxPacketSize;
831 printf("------readSize = [%d]------\n", g_acm->readSize);
832 for (int32_t i = 0; i < ACM_NR; i++) {
833 g_acm->readReq[i] = UsbAllocRequest(NULL, 0, g_acm->readSize);
834 if (g_acm->readReq[i] == NULL) {
835 HDF_LOGE("%s: error", __func__);
836 return HDF_FAILURE;
837 }
838 }
839 return HDF_SUCCESS;
840 }
841
CheckHostSdkIfAllocRequest002(void)842 static int32_t CheckHostSdkIfAllocRequest002(void)
843 {
844 g_acm->readSize = g_acm->dataInPipe->maxPacketSize;
845 printf("------readSize = [%d]------\n", g_acm->readSize);
846 for (int32_t i = 0; i < ACM_NR; i++) {
847 g_acm->readReq[i] = UsbAllocRequest(g_acm->data_devHandle, 0, g_acm->readSize);
848 if (g_acm->readReq[i] == NULL) {
849 HDF_LOGE("%s: error", __func__);
850 return HDF_FAILURE;
851 }
852 }
853 return HDF_SUCCESS;
854 }
855
CheckHostSdkIfFreeRequest001(void)856 static int32_t CheckHostSdkIfFreeRequest001(void)
857 {
858 for (int32_t i = 0; i < ACM_NR; i++) {
859 int32_t ret = UsbFreeRequest(g_acm->readReq[i]);
860 if (ret != HDF_SUCCESS) {
861 HDF_LOGE("%s: error", __func__);
862 return HDF_FAILURE;
863 }
864 g_acm->readReq[i] = NULL;
865 }
866 return HDF_SUCCESS;
867 }
868
CheckHostSdkIfAllocRequest003(void)869 static int32_t CheckHostSdkIfAllocRequest003(void)
870 {
871 g_acm->writeSize = g_acm->dataOutPipe->maxPacketSize;
872 int32_t ret = AcmWriteBufAlloc(g_acm);
873 if (ret != HDF_SUCCESS) {
874 HDF_LOGE("%s: error", __func__);
875 return HDF_FAILURE;
876 }
877 for (int32_t i = 0; i < ACM_NW; i++) {
878 g_acm->wb[i].request = UsbAllocRequest(NULL, 0, g_acm->writeSize);
879 g_acm->wb[i].instance = g_acm;
880 if (g_acm->wb[i].request == NULL) {
881 HDF_LOGE("%s: error", __func__);
882 return HDF_FAILURE;
883 }
884 }
885 return HDF_SUCCESS;
886 }
887
CheckHostSdkIfAllocRequest004(void)888 static int32_t CheckHostSdkIfAllocRequest004(void)
889 {
890 g_acm->writeSize = g_acm->dataOutPipe->maxPacketSize;
891 int32_t ret = AcmWriteBufAlloc(g_acm);
892 if (ret != HDF_SUCCESS) {
893 HDF_LOGE("%s: error", __func__);
894 return HDF_FAILURE;
895 }
896
897 for (int32_t i = 0; i < ACM_NW; i++) {
898 g_acm->wb[i].request = UsbAllocRequest(g_acm->data_devHandle, 0, g_acm->writeSize);
899 g_acm->wb[i].instance = g_acm;
900 if (g_acm->wb[i].request == NULL) {
901 HDF_LOGE("%s: error", __func__);
902 return HDF_FAILURE;
903 }
904 }
905 return HDF_SUCCESS;
906 }
907
CheckHostSdkIfFreeRequest002(void)908 static int32_t CheckHostSdkIfFreeRequest002(void)
909 {
910 for (int32_t i = 0; i < ACM_NR; i++) {
911 int32_t ret = UsbFreeRequest(g_acm->wb[i].request);
912 if (ret != HDF_SUCCESS) {
913 HDF_LOGE("%s: error", __func__);
914 return HDF_FAILURE;
915 }
916 g_acm->wb[i].request = NULL;
917 }
918 AcmWriteBufFree(g_acm);
919 return HDF_SUCCESS;
920 }
921
CheckHostSdkIfAllocRequest005(void)922 static int32_t CheckHostSdkIfAllocRequest005(void)
923 {
924 g_acm->intSize = g_acm->intPipe->maxPacketSize;
925 g_acm->notifyReq = UsbAllocRequest(NULL, 0, g_acm->intSize);
926 if (g_acm->notifyReq == NULL) {
927 HDF_LOGE("%s: error", __func__);
928 return HDF_FAILURE;
929 }
930 return HDF_SUCCESS;
931 }
932
CheckHostSdkIfAllocRequest006(void)933 static int32_t CheckHostSdkIfAllocRequest006(void)
934 {
935 g_acm->intSize = g_acm->intPipe->maxPacketSize;
936 g_acm->notifyReq = UsbAllocRequest(g_acm->int_devHandle, 0, g_acm->intSize);
937 if (g_acm->notifyReq == NULL) {
938 HDF_LOGE("%s: error", __func__);
939 return HDF_FAILURE;
940 }
941 return HDF_SUCCESS;
942 }
943
CheckHostSdkIfFreeRequest003(void)944 static int32_t CheckHostSdkIfFreeRequest003(void)
945 {
946 int32_t ret = UsbFreeRequest(g_acm->notifyReq);
947 if (ret != HDF_SUCCESS) {
948 HDF_LOGE("%s: error", __func__);
949 return HDF_FAILURE;
950 }
951 g_acm->notifyReq = NULL;
952 return HDF_SUCCESS;
953 }
954
CheckHostSdkIfAllocRequest007(void)955 static int32_t CheckHostSdkIfAllocRequest007(void)
956 {
957 g_acm->ctrlSize = sizeof(struct UsbCdcLineCoding);
958 g_acm->ctrlReq = UsbAllocRequest(NULL, 0, g_acm->ctrlSize);
959 if (g_acm->ctrlReq == NULL) {
960 HDF_LOGE("%s: error", __func__);
961 return HDF_SUCCESS;
962 }
963 return HDF_FAILURE;
964 }
965
CheckHostSdkIfAllocRequest008(void)966 static int32_t CheckHostSdkIfAllocRequest008(void)
967 {
968 g_acm->ctrlSize = sizeof(struct UsbCdcLineCoding);
969 g_acm->ctrlReq = UsbAllocRequest(g_acm->ctrl_devHandle, 0, g_acm->ctrlSize);
970 if (g_acm->ctrlReq == NULL) {
971 HDF_LOGE("%s: error", __func__);
972 return HDF_FAILURE;
973 }
974 return HDF_SUCCESS;
975 }
976
CheckHostSdkIfAllocRequest010(void)977 static int32_t CheckHostSdkIfAllocRequest010(void)
978 {
979 size_t size = g_acm->dataOutPipe->maxPacketSize;
980 g_acm->isoReq = UsbAllocRequest(NULL, USB_ISO_PACKAT_CNT, size);
981 if (g_acm->isoReq == NULL) {
982 HDF_LOGE("%s: error", __func__);
983 return HDF_FAILURE;
984 }
985 return HDF_SUCCESS;
986 }
CheckHostSdkIfAllocRequest011(void)987 static int32_t CheckHostSdkIfAllocRequest011(void)
988 {
989 size_t size = g_acm->dataOutPipe->maxPacketSize;
990 g_acm->isoReq = UsbAllocRequest(g_acm->iso_devHandle, USB_ISO_PACKAT_CNT, size);
991 if (g_acm->isoReq == NULL) {
992 HDF_LOGE("%s: error", __func__);
993 return HDF_FAILURE;
994 }
995 return HDF_SUCCESS;
996 }
997
CheckHostSdkIfFreeRequest006(void)998 static int32_t CheckHostSdkIfFreeRequest006(void)
999 {
1000 if (g_acm->isoReq == NULL) {
1001 HDF_LOGE("%s: isoReq is NULL", __func__);
1002 return HDF_FAILURE;
1003 }
1004 int32_t ret = UsbFreeRequest(g_acm->isoReq);
1005 if (ret != HDF_SUCCESS) {
1006 HDF_LOGE("%s: error", __func__);
1007 return HDF_FAILURE;
1008 }
1009 g_acm->isoReq = NULL;
1010 return HDF_SUCCESS;
1011 }
1012
CheckHostSdkIfFillIsoRequest001(void)1013 static int32_t CheckHostSdkIfFillIsoRequest001(void)
1014 {
1015 struct UsbRequestParams parmas = {0};
1016 char sendData[] = {"abcde\0"};
1017 uint32_t size = strlen(sendData) + 1;
1018 if (g_acm->isoPipe == NULL) {
1019 return HDF_FAILURE;
1020 }
1021 parmas.interfaceId = g_acm->isoPipe->interfaceId;
1022 parmas.pipeAddress = g_acm->isoPipe->pipeAddress;
1023 parmas.pipeId = g_acm->isoPipe->pipeId;
1024 parmas.callback = AcmWriteIsoCallback;
1025 parmas.userData = NULL;
1026 parmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1027 parmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1028 parmas.dataReq.numIsoPackets = USB_ISO_PACKAT_CNT;
1029 parmas.dataReq.directon = USB_REQUEST_DIR_TO_DEVICE;
1030 parmas.dataReq.length = (int)size;
1031 parmas.dataReq.buffer = (unsigned char *)sendData;
1032 int32_t ret = UsbFillRequest(g_acm->isoReq, g_acm->iso_devHandle, &parmas);
1033 if (ret != HDF_SUCCESS) {
1034 HDF_LOGE("%s: error", __func__);
1035 return HDF_FAILURE;
1036 }
1037 return HDF_SUCCESS;
1038 }
1039
CheckHostSdkIfFillIsoRequest002(void)1040 static int32_t CheckHostSdkIfFillIsoRequest002(void)
1041 {
1042 struct UsbRequestParams parmas;
1043 char sendData[] = {"abcde\0"};
1044 uint32_t size = strlen(sendData) + 1;
1045 if (g_acm->isoPipe == NULL) {
1046 return HDF_FAILURE;
1047 }
1048 parmas.interfaceId = g_acm->isoPipe->interfaceId;
1049 parmas.pipeAddress = g_acm->isoPipe->pipeAddress;
1050 parmas.pipeId = g_acm->isoPipe->pipeId;
1051 parmas.callback = AcmWriteIsoCallback;
1052 parmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1053 parmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1054 parmas.dataReq.numIsoPackets = USB_ISO_PACKAT_CNT;
1055 parmas.dataReq.directon = USB_REQUEST_DIR_TO_DEVICE;
1056 parmas.dataReq.length = (int)size;
1057 parmas.dataReq.buffer = (unsigned char *)sendData;
1058 int32_t ret = UsbFillRequest(NULL, g_acm->iso_devHandle, &parmas);
1059 if (ret != HDF_SUCCESS) {
1060 HDF_LOGE("%s: error", __func__);
1061 return HDF_FAILURE;
1062 }
1063 return HDF_SUCCESS;
1064 }
1065
CheckHostSdkIfFillIsoRequest003(void)1066 static int32_t CheckHostSdkIfFillIsoRequest003(void)
1067 {
1068 struct UsbRequestParams parmas;
1069 char sendData[] = {"abcde\0"};
1070 uint32_t size = strlen(sendData) + 1;
1071 if (g_acm->isoPipe == NULL) {
1072 return HDF_FAILURE;
1073 }
1074 parmas.interfaceId = g_acm->isoPipe->interfaceId;
1075 parmas.pipeAddress = g_acm->isoPipe->pipeAddress;
1076 parmas.pipeId = g_acm->isoPipe->pipeId;
1077 parmas.callback = AcmWriteIsoCallback;
1078 parmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1079 parmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1080 parmas.dataReq.numIsoPackets = USB_ISO_PACKAT_CNT;
1081 parmas.dataReq.directon = USB_REQUEST_DIR_TO_DEVICE;
1082 parmas.dataReq.length = (int)size;
1083 parmas.dataReq.buffer = (unsigned char *)sendData;
1084 int32_t ret = UsbFillRequest(g_acm->isoReq, NULL, &parmas);
1085 if (ret != HDF_SUCCESS) {
1086 HDF_LOGE("%s: error", __func__);
1087 return HDF_FAILURE;
1088 }
1089 return HDF_SUCCESS;
1090 }
1091
CheckHostSdkIfFillIsoRequest004(void)1092 static int32_t CheckHostSdkIfFillIsoRequest004(void)
1093 {
1094 struct UsbRequestParams parmas;
1095 char sendData[] = {"abcde\0"};
1096 uint32_t size = strlen(sendData) + 1;
1097 if (g_acm->isoPipe == NULL) {
1098 return HDF_FAILURE;
1099 }
1100 parmas.dataReq.numIsoPackets = USB_ISO_PACKAT_CNT;
1101 parmas.dataReq.directon = USB_REQUEST_DIR_TO_DEVICE;
1102 parmas.dataReq.length = (int)size;
1103 parmas.dataReq.buffer = (unsigned char *)sendData;
1104 int32_t ret = UsbFillRequest(g_acm->isoReq, g_acm->iso_devHandle, NULL);
1105 if (ret != HDF_SUCCESS) {
1106 HDF_LOGE("%s: error", __func__);
1107 return HDF_FAILURE;
1108 }
1109 return HDF_SUCCESS;
1110 }
1111
CheckHostSdkIfFillIsoRequest005(void)1112 static int32_t CheckHostSdkIfFillIsoRequest005(void)
1113 {
1114 struct UsbRequestParams parmas;
1115 char sendData[] = {"abcde\0"};
1116 uint32_t size = strlen(sendData) + 1;
1117 if (g_acm->isoPipe == NULL) {
1118 return HDF_FAILURE;
1119 }
1120 parmas.interfaceId = g_acm->isoPipe->interfaceId;
1121 parmas.pipeAddress = g_acm->isoPipe->pipeAddress;
1122 parmas.pipeId = g_acm->isoPipe->pipeId;
1123 parmas.callback = AcmWriteIsoCallback;
1124 parmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1125 parmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1126 parmas.dataReq.numIsoPackets = USB_ISO_PACKAT_CNT;
1127 parmas.dataReq.directon = USB_REQUEST_DIR_TO_DEVICE;
1128 parmas.dataReq.length = (int)size;
1129 parmas.dataReq.buffer = (unsigned char *)sendData;
1130 int32_t ret = UsbFillRequest(NULL, NULL, &parmas);
1131 if (ret != HDF_SUCCESS) {
1132 HDF_LOGE("%s: error", __func__);
1133 return HDF_FAILURE;
1134 }
1135 return HDF_SUCCESS;
1136 }
1137
CheckHostSdkIfFillIsoRequest006(void)1138 static int32_t CheckHostSdkIfFillIsoRequest006(void)
1139 {
1140 struct UsbRequestParams parmas;
1141 char sendData[] = {"abcde\0"};
1142 uint32_t size = strlen(sendData) + 1;
1143 if (g_acm->isoPipe == NULL) {
1144 return HDF_FAILURE;
1145 }
1146 parmas.dataReq.numIsoPackets = USB_ISO_PACKAT_CNT;
1147 parmas.dataReq.directon = USB_REQUEST_DIR_TO_DEVICE;
1148 parmas.dataReq.length = (int)size;
1149 parmas.dataReq.buffer = (unsigned char *)sendData;
1150 int32_t ret = UsbFillRequest(g_acm->isoReq, NULL, NULL);
1151 if (ret != HDF_SUCCESS) {
1152 HDF_LOGE("%s: error", __func__);
1153 return HDF_FAILURE;
1154 }
1155 return HDF_SUCCESS;
1156 }
1157
CheckHostSdkIfFreeRequest004(void)1158 static int32_t CheckHostSdkIfFreeRequest004(void)
1159 {
1160 int32_t ret = UsbFreeRequest(g_acm->ctrlReq);
1161 if (ret != HDF_SUCCESS) {
1162 HDF_LOGE("%s: error", __func__);
1163 return HDF_FAILURE;
1164 }
1165 g_acm->ctrlReq = NULL;
1166 return HDF_SUCCESS;
1167 }
1168
CheckHostSdkIfAllocRequest009(void)1169 static int32_t CheckHostSdkIfAllocRequest009(void)
1170 {
1171 g_acm->readSize = g_acm->dataInPipe->maxPacketSize;
1172 for (int32_t i = 0; i < ACM_NR; i++) {
1173 g_acm->readReq[i] = UsbAllocRequest(g_acm->data_devHandle, 0, g_acm->readSize);
1174 if (g_acm->readReq[i] == NULL) {
1175 HDF_LOGE("%s: error", __func__);
1176 return HDF_FAILURE;
1177 }
1178 }
1179
1180 g_acm->writeSize = g_acm->dataOutPipe->maxPacketSize;
1181 int32_t ret = AcmWriteBufAlloc(g_acm);
1182 if (ret != HDF_SUCCESS) {
1183 HDF_LOGE("%s: error", __func__);
1184 return HDF_FAILURE;
1185 }
1186 for (int32_t i = 0; i < ACM_NW; i++) {
1187 g_acm->wb[i].request = UsbAllocRequest(g_acm->data_devHandle, 0, g_acm->writeSize);
1188 g_acm->wb[i].instance = g_acm;
1189 if (g_acm->wb[i].request == NULL) {
1190 HDF_LOGE("%s: error", __func__);
1191 return HDF_FAILURE;
1192 }
1193 }
1194 g_acm->intSize = g_acm->intPipe->maxPacketSize;
1195 g_acm->notifyReq = UsbAllocRequest(g_acm->int_devHandle, 0, g_acm->intSize);
1196 if (g_acm->notifyReq == NULL) {
1197 HDF_LOGE("%s: error", __func__);
1198 return HDF_FAILURE;
1199 }
1200 g_acm->ctrlSize = sizeof(struct UsbCdcLineCoding);
1201 g_acm->ctrlReq = UsbAllocRequest(g_acm->ctrl_devHandle, 0, g_acm->ctrlSize);
1202 if (g_acm->ctrlReq == NULL) {
1203 HDF_LOGE("%s: error", __func__);
1204 return HDF_FAILURE;
1205 }
1206 return HDF_SUCCESS;
1207 }
1208
CheckHostSdkIfFillRequest001(void)1209 static int32_t CheckHostSdkIfFillRequest001(void)
1210 {
1211 struct UsbRequestParams readParmas;
1212 readParmas.userData = (void *)g_acm;
1213 readParmas.pipeAddress = g_acm->dataInPipe->pipeAddress;
1214 readParmas.pipeId = g_acm->dataInPipe->pipeId;
1215 readParmas.interfaceId = g_acm->dataInPipe->interfaceId;
1216 readParmas.callback = AcmReadBulk;
1217 readParmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1218 readParmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1219 readParmas.dataReq.numIsoPackets = 0;
1220 readParmas.dataReq.directon =
1221 (UsbRequestDirection)(((uint32_t)g_acm->dataInPipe->pipeDirection >> USB_DIR_OFFSET) & DIRECTION_MASK);
1222 readParmas.dataReq.length = (int)g_acm->readSize;
1223 int32_t ret = UsbFillRequest(g_acm->readReq[0], g_acm->data_devHandle, &readParmas);
1224 if (ret != HDF_SUCCESS) {
1225 HDF_LOGE("%s: error", __func__);
1226 return HDF_FAILURE;
1227 }
1228 return HDF_SUCCESS;
1229 }
1230
CheckHostSdkIfFillRequest002(void)1231 static int32_t CheckHostSdkIfFillRequest002(void)
1232 {
1233 struct UsbRequestParams parmas;
1234 char sendData[] = {"abcde\0"};
1235 uint32_t size = strlen(sendData) + 1;
1236 g_acm->writeSize = g_acm->dataOutPipe->maxPacketSize;
1237 size = (size > g_acm->writeSize) ? g_acm->writeSize : size;
1238
1239 g_acm->wb[0].len = (int)size;
1240 int32_t ret = memcpy_s(g_acm->wb[0].buf, g_acm->writeSize, sendData, size);
1241 if (ret != EOK) {
1242 HDF_LOGE("%s: memcpy_s failed", __func__);
1243 return HDF_FAILURE;
1244 }
1245 parmas.interfaceId = g_acm->dataOutPipe->interfaceId;
1246 parmas.pipeAddress = g_acm->dataOutPipe->pipeAddress;
1247 parmas.pipeId = g_acm->dataOutPipe->pipeId;
1248 parmas.callback = AcmWriteBulk;
1249 parmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1250 parmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1251 parmas.dataReq.numIsoPackets = 0;
1252 parmas.userData = (void *)&g_acm->wb[0];
1253 parmas.dataReq.directon = USB_REQUEST_DIR_TO_DEVICE;
1254 parmas.dataReq.length = g_acm->wb[0].len;
1255 parmas.dataReq.buffer = g_acm->wb[0].buf;
1256 ret = UsbFillRequest(g_acm->wb[0].request, g_acm->data_devHandle, &parmas);
1257 if (ret != HDF_SUCCESS) {
1258 HDF_LOGE("%s: error", __func__);
1259 return HDF_FAILURE;
1260 }
1261 return HDF_SUCCESS;
1262 }
1263
CheckHostSdkIfFillRequest003(void)1264 static int32_t CheckHostSdkIfFillRequest003(void)
1265 {
1266 struct UsbRequestParams intParmas;
1267 intParmas.userData = (void *)g_acm;
1268 intParmas.pipeAddress = g_acm->intPipe->pipeAddress;
1269 intParmas.pipeId = g_acm->intPipe->pipeId;
1270 intParmas.interfaceId = g_acm->intPipe->interfaceId;
1271 intParmas.callback = AcmCtrlIrq;
1272 intParmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1273 intParmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1274 intParmas.dataReq.numIsoPackets = 0;
1275 intParmas.dataReq.directon =
1276 (UsbRequestDirection)(((uint32_t)g_acm->intPipe->pipeDirection >> USB_PIPE_DIR_OFFSET) & DIRECTION_MASK);
1277 intParmas.dataReq.length = (int)g_acm->intSize;
1278 intParmas.dataReq.buffer = NULL;
1279 int32_t ret = UsbFillRequest(g_acm->notifyReq, g_acm->int_devHandle, &intParmas);
1280 if (ret != HDF_SUCCESS) {
1281 HDF_LOGE("%s: error", __func__);
1282 return HDF_FAILURE;
1283 }
1284 return HDF_SUCCESS;
1285 }
1286
CheckHostSdkIfFillRequest004(void)1287 static int32_t CheckHostSdkIfFillRequest004(void)
1288 {
1289 struct UsbRequestParams parmas;
1290 uint16_t index = 2;
1291 uint16_t value = 0;
1292 struct TestControlMsgData msgData;
1293 parmas.interfaceId = USB_CTRL_INTERFACE_ID;
1294 parmas.pipeAddress = 0;
1295 parmas.pipeId = 0;
1296 parmas.callback = AcmCtrlIrq;
1297 parmas.requestType = USB_REQUEST_PARAMS_CTRL_TYPE;
1298 parmas.timeout = USB_CTRL_SET_TIMEOUT;
1299 g_acm->lineCoding.dwDTERate = CPU_TO_LE32(DATARATE);
1300 g_acm->lineCoding.bCharFormat = USB_CDC_1_STOP_BITS;
1301 g_acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
1302 g_acm->lineCoding.bDataBits = DATA_BITS_LENGTH;
1303 msgData.request = USB_DDK_CDC_REQ_SET_LINE_CODING;
1304 msgData.requestType = USB_DDK_TYPE_CLASS | USB_DDK_RECIP_INTERFACE;
1305 msgData.value = value;
1306 msgData.index = index;
1307 msgData.data = &g_acm->lineCoding;
1308 msgData.size = sizeof(struct UsbCdcLineCoding);
1309 parmas.ctrlReq = UsbControlMsg(msgData);
1310 parmas.userData = NULL;
1311 int32_t ret = UsbFillRequest(g_acm->ctrlReq, g_acm->ctrl_devHandle, &parmas);
1312 if (ret != HDF_SUCCESS) {
1313 HDF_LOGE("%s: error", __func__);
1314 return HDF_FAILURE;
1315 }
1316 return HDF_SUCCESS;
1317 }
1318
CheckHostSdkIfSubmitRequestSync001(void)1319 static int32_t CheckHostSdkIfSubmitRequestSync001(void)
1320 {
1321 int32_t ret = UsbSubmitRequestSync(g_acm->readReq[0]);
1322 if (ret != HDF_SUCCESS) {
1323 HDF_LOGE("%s: error", __func__);
1324 return HDF_FAILURE;
1325 }
1326 return HDF_SUCCESS;
1327 }
1328
CheckHostSdkIfSubmitRequestSync002(void)1329 static int32_t CheckHostSdkIfSubmitRequestSync002(void)
1330 {
1331 int32_t ret = UsbSubmitRequestSync(g_acm->wb[0].request);
1332 if (ret != HDF_SUCCESS) {
1333 HDF_LOGE("%s: error", __func__);
1334 return HDF_FAILURE;
1335 }
1336 return HDF_SUCCESS;
1337 }
1338
CheckHostSdkIfSubmitRequestSync003(void)1339 static int32_t CheckHostSdkIfSubmitRequestSync003(void)
1340 {
1341 int32_t ret = UsbSubmitRequestSync(g_acm->ctrlReq);
1342 if (ret != HDF_SUCCESS) {
1343 HDF_LOGE("%s: error", __func__);
1344 return HDF_FAILURE;
1345 }
1346 return HDF_SUCCESS;
1347 }
1348
CheckHostSdkIfSubmitRequestSync004(void)1349 static int32_t CheckHostSdkIfSubmitRequestSync004(void)
1350 {
1351 int32_t ret = UsbSubmitRequestSync(g_acm->notifyReq);
1352 if (ret != HDF_SUCCESS) {
1353 HDF_LOGE("%s: error", __func__);
1354 return HDF_FAILURE;
1355 }
1356 return HDF_SUCCESS;
1357 }
1358
CheckHostSdkIfFillRequest005(void)1359 static int32_t CheckHostSdkIfFillRequest005(void)
1360 {
1361 struct UsbRequestParams readParmas;
1362 for (int32_t i = 0; i < ACM_NR; i++) {
1363 readParmas.userData = (void *)g_acm;
1364 readParmas.pipeAddress = g_acm->dataInPipe->pipeAddress;
1365 readParmas.pipeId = g_acm->dataInPipe->pipeId;
1366 readParmas.interfaceId = g_acm->dataInPipe->interfaceId;
1367 readParmas.callback = AcmReadBulk;
1368 readParmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1369 readParmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1370 readParmas.dataReq.numIsoPackets = 0;
1371 readParmas.dataReq.directon =
1372 (UsbRequestDirection)(((uint32_t)g_acm->dataInPipe->pipeDirection >> USB_DIR_OFFSET) & DIRECTION_MASK);
1373 readParmas.dataReq.length = (int)g_acm->readSize;
1374 int32_t ret = UsbFillRequest(g_acm->readReq[i], g_acm->data_devHandle, &readParmas);
1375 if (ret != HDF_SUCCESS) {
1376 HDF_LOGE("%s: error", __func__);
1377 return HDF_FAILURE;
1378 }
1379 }
1380 return HDF_SUCCESS;
1381 }
1382
CheckHostSdkIfFillRequest006(void)1383 static int32_t CheckHostSdkIfFillRequest006(void)
1384 {
1385 struct UsbRequestParams parmas;
1386 char sendData[] = {"abcde\0"};
1387 uint32_t size = strlen(sendData) + 1;
1388 g_acm->writeSize = g_acm->dataOutPipe->maxPacketSize;
1389 size = (size > g_acm->writeSize) ? g_acm->writeSize : size;
1390 for (int32_t i = 0; i < ACM_NR; i++) {
1391 g_acm->wb[i].len = (int)size;
1392 int32_t ret = memcpy_s(g_acm->wb[i].buf, g_acm->writeSize, sendData, size);
1393 if (ret != EOK) {
1394 HDF_LOGE("%s: memcpy_s failed", __func__);
1395 return HDF_FAILURE;
1396 }
1397 parmas.interfaceId = g_acm->dataOutPipe->interfaceId;
1398 parmas.pipeAddress = g_acm->dataOutPipe->pipeAddress;
1399 parmas.pipeId = g_acm->dataOutPipe->pipeId;
1400 parmas.callback = AcmWriteBulk;
1401 parmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1402 parmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1403 parmas.dataReq.numIsoPackets = 0;
1404 parmas.userData = (void *)&g_acm->wb[i];
1405 parmas.dataReq.length = g_acm->wb[i].len;
1406 parmas.dataReq.buffer = g_acm->wb[i].buf;
1407 ret = UsbFillRequest(g_acm->wb[i].request, g_acm->data_devHandle, &parmas);
1408 if (ret != HDF_SUCCESS) {
1409 HDF_LOGE("%s: error", __func__);
1410 return HDF_FAILURE;
1411 }
1412 }
1413 return HDF_SUCCESS;
1414 }
1415
CheckHostSdkIfFillRequest007(void)1416 static int32_t CheckHostSdkIfFillRequest007(void)
1417 {
1418 struct UsbRequestParams intParmas;
1419 intParmas.userData = (void *)g_acm;
1420 intParmas.pipeAddress = g_acm->intPipe->pipeAddress;
1421 intParmas.pipeId = g_acm->intPipe->pipeId;
1422 intParmas.interfaceId = g_acm->intPipe->interfaceId;
1423 intParmas.callback = AcmCtrlIrq;
1424 intParmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE;
1425 intParmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS;
1426 intParmas.dataReq.buffer = NULL;
1427 intParmas.dataReq.numIsoPackets = 0;
1428 intParmas.dataReq.directon =
1429 (UsbRequestDirection)(((uint32_t)g_acm->intPipe->pipeDirection >> USB_PIPE_DIR_OFFSET) & DIRECTION_MASK);
1430 intParmas.dataReq.length = (int)g_acm->intSize;
1431 int32_t ret = UsbFillRequest(g_acm->notifyReq, g_acm->int_devHandle, &intParmas);
1432 if (ret != HDF_SUCCESS) {
1433 HDF_LOGE("%s: error", __func__);
1434 return HDF_FAILURE;
1435 }
1436 return HDF_SUCCESS;
1437 }
1438
CheckHostSdkIfFillRequest008(void)1439 static int32_t CheckHostSdkIfFillRequest008(void)
1440 {
1441 struct UsbRequestParams parmas;
1442 uint16_t index = 2;
1443 uint16_t value = 0;
1444 struct TestControlMsgData msgData;
1445
1446 parmas.interfaceId = USB_CTRL_INTERFACE_ID;
1447 parmas.pipeAddress = 0;
1448 parmas.pipeId = 0;
1449 parmas.callback = AcmCtrlIrq;
1450 parmas.requestType = USB_REQUEST_PARAMS_CTRL_TYPE;
1451 parmas.timeout = USB_CTRL_SET_TIMEOUT;
1452 g_acm->lineCoding.dwDTERate = CPU_TO_LE32(DATARATE);
1453 g_acm->lineCoding.bCharFormat = USB_CDC_1_STOP_BITS;
1454 g_acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
1455 g_acm->lineCoding.bDataBits = DATA_BITS_LENGTH;
1456 msgData.request = USB_DDK_CDC_REQ_SET_LINE_CODING;
1457 msgData.requestType = USB_DDK_TYPE_CLASS | USB_DDK_RECIP_INTERFACE;
1458 msgData.value = value;
1459 msgData.index = index;
1460 msgData.data = &g_acm->lineCoding;
1461 msgData.size = sizeof(struct UsbCdcLineCoding);
1462 parmas.ctrlReq = UsbControlMsg(msgData);
1463 parmas.userData = NULL;
1464 int32_t ret = UsbFillRequest(g_acm->ctrlReq, g_acm->ctrl_devHandle, &parmas);
1465 if (ret != HDF_SUCCESS) {
1466 HDF_LOGE("%s: error", __func__);
1467 return HDF_FAILURE;
1468 }
1469 return HDF_SUCCESS;
1470 }
1471
CheckHostSdkIfSubmitRequestAsync001(void)1472 static int32_t CheckHostSdkIfSubmitRequestAsync001(void)
1473 {
1474 int32_t ret = UsbSubmitRequestAsync(g_acm->readReq[0]);
1475 if (ret != HDF_SUCCESS) {
1476 HDF_LOGE("%s: error", __func__);
1477 return HDF_FAILURE;
1478 }
1479 return HDF_SUCCESS;
1480 }
1481
CheckHostSdkIfCancelRequest001(void)1482 static int32_t CheckHostSdkIfCancelRequest001(void)
1483 {
1484 int32_t ret = UsbCancelRequest(g_acm->readReq[0]);
1485 if (ret != HDF_SUCCESS) {
1486 HDF_LOGE("%s: error", __func__);
1487 return HDF_FAILURE;
1488 }
1489 return HDF_SUCCESS;
1490 }
1491
CheckHostSdkIfSubmitRequestAsync002(void)1492 static int32_t CheckHostSdkIfSubmitRequestAsync002(void)
1493 {
1494 int32_t ret = UsbSubmitRequestAsync(g_acm->wb[0].request);
1495 if (ret != HDF_SUCCESS) {
1496 HDF_LOGE("%s: error", __func__);
1497 return HDF_FAILURE;
1498 }
1499 return HDF_SUCCESS;
1500 }
1501
CheckHostSdkIfCancelRequest002(void)1502 static int32_t CheckHostSdkIfCancelRequest002(void)
1503 {
1504 int32_t ret = UsbCancelRequest(g_acm->wb[0].request);
1505 if (ret != HDF_SUCCESS) {
1506 HDF_LOGE("%s: error", __func__);
1507 return HDF_FAILURE;
1508 }
1509 return HDF_SUCCESS;
1510 }
1511
CheckHostSdkIfSubmitRequestAsync003(void)1512 static int32_t CheckHostSdkIfSubmitRequestAsync003(void)
1513 {
1514 int32_t ret = UsbSubmitRequestAsync(g_acm->notifyReq);
1515 if (ret != HDF_SUCCESS) {
1516 HDF_LOGE("%s: error", __func__);
1517 return HDF_FAILURE;
1518 }
1519 return HDF_SUCCESS;
1520 }
1521
CheckHostSdkIfCancelRequest003(void)1522 static int32_t CheckHostSdkIfCancelRequest003(void)
1523 {
1524 int32_t ret = UsbCancelRequest(g_acm->notifyReq);
1525 if (ret != HDF_SUCCESS) {
1526 HDF_LOGE("%s: error", __func__);
1527 return HDF_FAILURE;
1528 }
1529 return HDF_SUCCESS;
1530 }
1531
CheckHostSdkIfSubmitRequestAsync004(void)1532 static int32_t CheckHostSdkIfSubmitRequestAsync004(void)
1533 {
1534 int32_t ret = UsbSubmitRequestAsync(g_acm->ctrlReq);
1535 if (ret != HDF_SUCCESS) {
1536 HDF_LOGE("%s: error", __func__);
1537 return HDF_FAILURE;
1538 }
1539 return HDF_SUCCESS;
1540 }
1541
CheckHostSdkIfCancelRequest004(void)1542 static int32_t CheckHostSdkIfCancelRequest004(void)
1543 {
1544 int32_t ret = UsbCancelRequest(g_acm->ctrlReq);
1545 if (ret != HDF_SUCCESS) {
1546 HDF_LOGE("%s: error", __func__);
1547 return HDF_FAILURE;
1548 }
1549 return HDF_SUCCESS;
1550 }
1551
CheckHostSdkIfClearInterfaceHalt002(void)1552 static int32_t CheckHostSdkIfClearInterfaceHalt002(void)
1553 {
1554 int32_t ret = UsbClearInterfaceHalt(g_acm->data_devHandle, g_acm->dataOutPipe->pipeAddress);
1555 if (ret != HDF_SUCCESS) {
1556 HDF_LOGE("%s: error", __func__);
1557 return HDF_FAILURE;
1558 }
1559 return HDF_SUCCESS;
1560 }
1561
CheckHostSdkIfClearInterfaceHalt003(void)1562 static int32_t CheckHostSdkIfClearInterfaceHalt003(void)
1563 {
1564 int32_t ret = UsbClearInterfaceHalt(g_acm->int_devHandle, g_acm->intPipe->pipeAddress);
1565 if (ret != HDF_SUCCESS) {
1566 HDF_LOGE("%s: error", __func__);
1567 return HDF_FAILURE;
1568 }
1569 return HDF_SUCCESS;
1570 }
1571
CheckHostSdkIfClearInterfaceHalt004(void)1572 static int32_t CheckHostSdkIfClearInterfaceHalt004(void)
1573 {
1574 int32_t ret = UsbClearInterfaceHalt(g_acm->ctrl_devHandle, g_acm->ctrPipe->pipeAddress);
1575 if (ret != HDF_SUCCESS) {
1576 HDF_LOGE("%s: error", __func__);
1577 return HDF_FAILURE;
1578 }
1579 return HDF_SUCCESS;
1580 }
1581
CheckHostSdkIfRemoveInterface001(void)1582 static int32_t CheckHostSdkIfRemoveInterface001(void)
1583 {
1584 UsbInterfaceStatus status = USB_INTERFACE_STATUS_REMOVE;
1585 int32_t ret = UsbAddOrRemoveInterface(
1586 g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->dataIface->info.interfaceIndex, status);
1587 if (ret != HDF_SUCCESS) {
1588 HDF_LOGE("%s: error", __func__);
1589 return HDF_FAILURE;
1590 }
1591 return HDF_SUCCESS;
1592 }
1593
CheckHostSdkIfAddInterface001(void)1594 static int32_t CheckHostSdkIfAddInterface001(void)
1595 {
1596 UsbInterfaceStatus status = USB_INTERFACE_STATUS_ADD;
1597 OsalSleep(1);
1598 int32_t ret = UsbAddOrRemoveInterface(
1599 g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->dataIface->info.interfaceIndex, status);
1600 if (ret != HDF_SUCCESS) {
1601 HDF_LOGE("%s: error", __func__);
1602 return HDF_FAILURE;
1603 }
1604 return HDF_SUCCESS;
1605 }
1606
CheckHostSdkIfRemoveInterface002(void)1607 static int32_t CheckHostSdkIfRemoveInterface002(void)
1608 {
1609 UsbInterfaceStatus status = USB_INTERFACE_STATUS_REMOVE;
1610 OsalSleep(1);
1611 int32_t ret = UsbAddOrRemoveInterface(
1612 g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->intIface->info.interfaceIndex, status);
1613 if (ret != HDF_SUCCESS) {
1614 HDF_LOGE("%s: error", __func__);
1615 return HDF_FAILURE;
1616 }
1617 return HDF_SUCCESS;
1618 }
1619
CheckHostSdkIfAddInterface002(void)1620 static int32_t CheckHostSdkIfAddInterface002(void)
1621 {
1622 UsbInterfaceStatus status = USB_INTERFACE_STATUS_ADD;
1623 OsalSleep(1);
1624 int32_t ret = UsbAddOrRemoveInterface(
1625 g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->intIface->info.interfaceIndex, status);
1626 if (ret != HDF_SUCCESS) {
1627 HDF_LOGE("%s: error", __func__);
1628 return HDF_FAILURE;
1629 }
1630 return HDF_SUCCESS;
1631 }
1632
CheckHostSdkIfRemoveInterface003(void)1633 static int32_t CheckHostSdkIfRemoveInterface003(void)
1634 {
1635 UsbInterfaceStatus status = USB_INTERFACE_STATUS_REMOVE;
1636
1637 int32_t ret = UsbAddOrRemoveInterface(
1638 g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->ctrIface->info.interfaceIndex, status);
1639 if (ret != HDF_SUCCESS) {
1640 HDF_LOGE("%s: error", __func__);
1641 return HDF_FAILURE;
1642 }
1643 return HDF_SUCCESS;
1644 }
1645
CheckHostSdkIfAddInterface003(void)1646 static int32_t CheckHostSdkIfAddInterface003(void)
1647 {
1648 UsbInterfaceStatus status = USB_INTERFACE_STATUS_ADD;
1649
1650 int32_t ret = UsbAddOrRemoveInterface(
1651 g_acm->session, g_acm->busNum, g_acm->devAddr, g_acm->ctrIface->info.interfaceIndex, status);
1652 if (ret != HDF_SUCCESS) {
1653 HDF_LOGE("%s: error", __func__);
1654 return HDF_FAILURE;
1655 }
1656 return HDF_SUCCESS;
1657 }
1658
CheckHostSdkIfCloseInterface006(void)1659 static int32_t CheckHostSdkIfCloseInterface006(void)
1660 {
1661 int32_t ret = UsbCloseInterface(g_ecmIntDevHandle);
1662 if (ret != HDF_SUCCESS) {
1663 HDF_LOGE("%s: error", __func__);
1664 return HDF_FAILURE;
1665 }
1666 ret = UsbCloseInterface(g_ecmDataDevHandle);
1667 if (ret != HDF_SUCCESS) {
1668 HDF_LOGE("%s: error", __func__);
1669 return HDF_FAILURE;
1670 }
1671 ret = UsbCloseInterface(g_acm->ctrl_devHandle);
1672 if (ret != HDF_SUCCESS) {
1673 HDF_LOGE("%s: error", __func__);
1674 return HDF_FAILURE;
1675 }
1676 ret = UsbCloseInterface(g_acm->int_devHandle);
1677 if (ret != HDF_SUCCESS) {
1678 HDF_LOGE("%s: error", __func__);
1679 return HDF_FAILURE;
1680 }
1681 ret = UsbCloseInterface(g_acm->data_devHandle);
1682 if (ret != HDF_SUCCESS) {
1683 HDF_LOGE("%s: error", __func__);
1684 return HDF_FAILURE;
1685 }
1686 return HDF_SUCCESS;
1687 }
1688
1689 struct UsbTestFunc g_usbTestFunc[] = {
1690 {USB_HOSTSDK_INIT_001_TEST, CheckHostSdkIfInit001 },
1691 {USB_HOSTSDK_EXIT_001_TEST, CheckHostSdkIfExit001 },
1692 {USB_HOSTSDK_INIT_002_TEST, CheckHostSdkIfInit002 },
1693 {USB_HOSTSDK_EXIT_002_TEST, CheckHostSdkIfExit002 },
1694 {USB_HOSTSDK_INIT_003_TEST, CheckHostSdkIfInit003 },
1695 {USB_HOSTSDK_INIT_004_TEST, CheckHostSdkIfInit004 },
1696 {USB_HOSTSDK_INIT_005_TEST, CheckHostSdkIfInit005 },
1697 {USB_HOSTSDK_CLAIM_INTERFACE_001_TEST, CheckHostSdkIfClaimInterface001 },
1698 {USB_HOSTSDK_RELEASE_INTERFACE_001_TEST, CheckHostSdkIfReleaseInterface001 },
1699 {USB_HOSTSDK_CLAIM_INTERFACE_002_TEST, CheckHostSdkIfClaimInterface002 },
1700 {USB_HOSTSDK_RELEASE_INTERFACE_002_TEST, CheckHostSdkIfReleaseInterface002 },
1701 {USB_HOSTSDK_CLAIM_INTERFACE_003_TEST, CheckHostSdkIfClaimInterface003 },
1702 {USB_HOSTSDK_RELEASE_INTERFACE_003_TEST, CheckHostSdkIfReleaseInterface003 },
1703 {USB_HOSTSDK_CLAIM_INTERFACE_004_TEST, CheckHostSdkIfClaimInterface004 },
1704 {USB_HOSTSDK_CLAIM_INTERFACE_005_TEST, CheckHostSdkIfClaimInterface005 },
1705 {USB_HOSTSDK_CLAIM_INTERFACE_006_TEST, CheckHostSdkIfClaimInterface006 },
1706 {USB_HOSTSDK_OPEN_INTERFACE_001_TEST, CheckHostSdkIfOpenInterface001 },
1707 {USB_HOSTSDK_CLOSE_INTERFACE_001_TEST, CheckHostSdkIfCloseInterface001 },
1708 {USB_HOSTSDK_OPEN_INTERFACE_002_TEST, CheckHostSdkIfOpenInterface002 },
1709 {USB_HOSTSDK_CLOSE_INTERFACE_002_TEST, CheckHostSdkIfCloseInterface002 },
1710 {USB_HOSTSDK_OPEN_INTERFACE_003_TEST, CheckHostSdkIfOpenInterface003 },
1711 {USB_HOSTSDK_CLOSE_INTERFACE_003_TEST, CheckHostSdkIfCloseInterface003 },
1712 {USB_HOSTSDK_OPEN_INTERFACE_004_TEST, CheckHostSdkIfOpenInterface004 },
1713 {USB_HOSTSDK_OPEN_INTERFACE_005_TEST, CheckHostSdkIfOpenInterface005 },
1714 {USB_HOSTSDK_CLOSE_INTERFACE_005_TEST, CheckHostSdkIfCloseInterface005 },
1715 {USB_HOSTSDK_OPEN_INTERFACE_006_TEST, CheckHostSdkIfOpenInterface006 },
1716 {USB_HOSTSDK_SELECT_INTERFACE_001_TEST, CheckHostSdkIfSelectInterfaceSetting001},
1717 {USB_HOSTSDK_SELECT_INTERFACE_002_TEST, CheckHostSdkIfSelectInterfaceSetting002},
1718 {USB_HOSTSDK_SELECT_INTERFACE_003_TEST, CheckHostSdkIfSelectInterfaceSetting003},
1719 {USB_HOSTSDK_SELECT_INTERFACE_004_TEST, CheckHostSdkIfSelectInterfaceSetting004},
1720 {USB_HOSTSDK_SELECT_INTERFACE_005_TEST, CheckHostSdkIfSelectInterfaceSetting005},
1721 {USB_HOSTSDK_SELECT_INTERFACE_006_TEST, CheckHostSdkIfSelectInterfaceSetting006},
1722 {USB_HOSTSDK_CLAIM_INTERFACE_007_TEST, CheckHostSdkIfClaimInterface007 },
1723 {USB_HOSTSDK_CLAIM_INTERFACE_008_TEST, CheckHostSdkIfClaimInterface008 },
1724 {USB_HOSTSDK_GET_PIPE_001_TEST, CheckHostSdkIfGetPipe001 },
1725 {USB_HOSTSDK_GET_PIPE_002_TEST, CheckHostSdkIfGetPipe002 },
1726 {USB_HOSTSDK_GET_PIPE_003_TEST, CheckHostSdkIfGetPipe003 },
1727 {USB_HOSTSDK_GET_PIPE_004_TEST, CheckHostSdkIfGetPipe004 },
1728 {USB_HOSTSDK_GET_PIPE_005_TEST, CheckHostSdkIfGetPipe005 },
1729 {USB_HOSTSDK_GET_PIPE_006_TEST, CheckHostSdkIfGetPipe006 },
1730 {USB_HOSTSDK_GET_PIPE_007_TEST, CheckHostSdkIfGetPipe007 },
1731 {USB_HOSTSDK_GET_PIPE_008_TEST, CheckHostSdkIfGetPipe008 },
1732 {USB_HOSTSDK_ALLOC_REQUEST_001_TEST, CheckHostSdkIfAllocRequest001 },
1733 {USB_HOSTSDK_ALLOC_REQUEST_002_TEST, CheckHostSdkIfAllocRequest002 },
1734 {USB_HOSTSDK_FREE_REQUEST_001_TEST, CheckHostSdkIfFreeRequest001 },
1735 {USB_HOSTSDK_ALLOC_REQUEST_003_TEST, CheckHostSdkIfAllocRequest003 },
1736 {USB_HOSTSDK_ALLOC_REQUEST_004_TEST, CheckHostSdkIfAllocRequest004 },
1737 {USB_HOSTSDK_FREE_REQUEST_002_TEST, CheckHostSdkIfFreeRequest002 },
1738 {USB_HOSTSDK_ALLOC_REQUEST_005_TEST, CheckHostSdkIfAllocRequest005 },
1739 {USB_HOSTSDK_ALLOC_REQUEST_006_TEST, CheckHostSdkIfAllocRequest006 },
1740 {USB_HOSTSDK_FREE_REQUEST_003_TEST, CheckHostSdkIfFreeRequest003 },
1741 {USB_HOSTSDK_ALLOC_REQUEST_007_TEST, CheckHostSdkIfAllocRequest007 },
1742 {USB_HOSTSDK_ALLOC_REQUEST_008_TEST, CheckHostSdkIfAllocRequest008 },
1743 {USB_HOSTSDK_ALLOC_REQUEST_010_TEST, CheckHostSdkIfAllocRequest010 },
1744 {USB_HOSTSDK_ALLOC_REQUEST_011_TEST, CheckHostSdkIfAllocRequest011 },
1745 {USB_HOSTSDK_FREE_REQUEST_006_TEST, CheckHostSdkIfFreeRequest006 },
1746 {USB_HOSTSDK_FILL_ISO_REQUEST_001_TEST, CheckHostSdkIfFillIsoRequest001 },
1747 {USB_HOSTSDK_FILL_ISO_REQUEST_002_TEST, CheckHostSdkIfFillIsoRequest002 },
1748 {USB_HOSTSDK_FILL_ISO_REQUEST_003_TEST, CheckHostSdkIfFillIsoRequest003 },
1749 {USB_HOSTSDK_FILL_ISO_REQUEST_004_TEST, CheckHostSdkIfFillIsoRequest004 },
1750 {USB_HOSTSDK_FILL_ISO_REQUEST_005_TEST, CheckHostSdkIfFillIsoRequest005 },
1751 {USB_HOSTSDK_FILL_ISO_REQUEST_006_TEST, CheckHostSdkIfFillIsoRequest006 },
1752 {USB_HOSTSDK_FREE_REQUEST_004_TEST, CheckHostSdkIfFreeRequest004 },
1753 {USB_HOSTSDK_ALLOC_REQUEST_009_TEST, CheckHostSdkIfAllocRequest009 },
1754 {USB_HOSTSDK_FILL_REQUEST_001_TEST, CheckHostSdkIfFillRequest001 },
1755 {USB_HOSTSDK_FILL_REQUEST_002_TEST, CheckHostSdkIfFillRequest002 },
1756 {USB_HOSTSDK_FILL_REQUEST_003_TEST, CheckHostSdkIfFillRequest003 },
1757 {USB_HOSTSDK_FILL_REQUEST_004_TEST, CheckHostSdkIfFillRequest004 },
1758 {USB_HOSTSDK_SUBMIT_REQUEST_SYNC_001_TEST, CheckHostSdkIfSubmitRequestSync001 },
1759 {USB_HOSTSDK_SUBMIT_REQUEST_SYNC_002_TEST, CheckHostSdkIfSubmitRequestSync002 },
1760 {USB_HOSTSDK_SUBMIT_REQUEST_SYNC_003_TEST, CheckHostSdkIfSubmitRequestSync003 },
1761 {USB_HOSTSDK_SUBMIT_REQUEST_SYNC_004_TEST, CheckHostSdkIfSubmitRequestSync004 },
1762 {USB_HOSTSDK_FILL_REQUEST_005_TEST, CheckHostSdkIfFillRequest005 },
1763 {USB_HOSTSDK_FILL_REQUEST_006_TEST, CheckHostSdkIfFillRequest006 },
1764 {USB_HOSTSDK_FILL_REQUEST_007_TEST, CheckHostSdkIfFillRequest007 },
1765 {USB_HOSTSDK_FILL_REQUEST_008_TEST, CheckHostSdkIfFillRequest008 },
1766 {USB_HOSTSDK_SUBMIT_REQUEST_ASYNC_001_TEST, CheckHostSdkIfSubmitRequestAsync001 },
1767 {USB_HOSTSDK_SUBMIT_CANCEL_REQUEST_001_TEST, CheckHostSdkIfCancelRequest001 },
1768 {USB_HOSTSDK_SUBMIT_REQUEST_ASYNC_002_TEST, CheckHostSdkIfSubmitRequestAsync002 },
1769 {USB_HOSTSDK_SUBMIT_CANCEL_REQUEST_002_TEST, CheckHostSdkIfCancelRequest002 },
1770 {USB_HOSTSDK_SUBMIT_REQUEST_ASYNC_003_TEST, CheckHostSdkIfSubmitRequestAsync003 },
1771 {USB_HOSTSDK_SUBMIT_CANCEL_REQUEST_003_TEST, CheckHostSdkIfCancelRequest003 },
1772 {USB_HOSTSDK_SUBMIT_REQUEST_ASYNC_004_TEST, CheckHostSdkIfSubmitRequestAsync004 },
1773 {USB_HOSTSDK_SUBMIT_CANCEL_REQUEST_004_TEST, CheckHostSdkIfCancelRequest004 },
1774 {USB_HOSTSDK_CLEAR_INTERFACE_HALT_002_TEST, CheckHostSdkIfClearInterfaceHalt002 },
1775 {USB_HOSTSDK_CLEAR_INTERFACE_HALT_003_TEST, CheckHostSdkIfClearInterfaceHalt003 },
1776 {USB_HOSTSDK_CLEAR_INTERFACE_HALT_004_TEST, CheckHostSdkIfClearInterfaceHalt004 },
1777 {USB_HOSTSDK_REMOVE_INTERFACE_001_TEST, CheckHostSdkIfRemoveInterface001 },
1778 {USB_HOSTSDK_ADD_INTERFACE_001_TEST, CheckHostSdkIfAddInterface001 },
1779 {USB_HOSTSDK_REMOVE_INTERFACE_002_TEST, CheckHostSdkIfRemoveInterface002 },
1780 {USB_HOSTSDK_ADD_INTERFACE_002_TEST, CheckHostSdkIfAddInterface002 },
1781 {USB_HOSTSDK_REMOVE_INTERFACE_003_TEST, CheckHostSdkIfRemoveInterface003 },
1782 {USB_HOSTSDK_ADD_INTERFACE_003_TEST, CheckHostSdkIfAddInterface003 },
1783 {USB_HOSTSDK_CLOSE_INTERFACE_006_TEST, CheckHostSdkIfCloseInterface006 },
1784 };
1785
UsbTestEntry(int32_t cmd)1786 int32_t UsbTestEntry(int32_t cmd)
1787 {
1788 int32_t i;
1789 int32_t ret = HDF_ERR_NOT_SUPPORT;
1790
1791 if (g_initFlag == false) {
1792 #ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY
1793 struct UsbGetDevicePara paraData;
1794 struct usb_device *usbPnpDevice = NULL;
1795 paraData.type = USB_PNP_DEVICE_VENDOR_PRODUCT_TYPE;
1796 paraData.vendorId = USB_DEVICE_VENDOR_ID;
1797 paraData.productId = USB_DEVICE_PRODUCT_ID;
1798 usbPnpDevice = UsbPnpNotifyGetUsbDevice(paraData);
1799 if (usbPnpDevice == NULL) {
1800 HDF_LOGE("%s:%d UsbPnpNotifyGetUsbDevice is NULL!", __func__, __LINE__);
1801 return HDF_ERR_INVALID_PARAM;
1802 }
1803 g_acm->busNum = usbPnpDevice->address;
1804 g_acm->devAddr = usbPnpDevice->port_no;
1805 HDF_LOGE("%s: busNum %d++devAddr %d", __func__, g_acm->busNum, g_acm->devAddr);
1806 g_initFlag = true;
1807 #else
1808 HDF_LOGE("%s:%d pnp notify module is not support!", __func__, __LINE__);
1809 return HDF_ERR_NOT_SUPPORT;
1810 #endif
1811 }
1812 for (i = 0; i < sizeof(g_usbTestFunc) / sizeof(g_usbTestFunc[0]); i++) {
1813 if (cmd == g_usbTestFunc[i].type && g_usbTestFunc[i].Func != NULL) {
1814 ret = g_usbTestFunc[i].Func();
1815 HDF_LOGE("%s: cmd %d ret %d", __func__, cmd, ret);
1816 break;
1817 }
1818 }
1819 return ret;
1820 }
1821