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 #include "usb_device_lite_cdcacm_test.h"
10
11 #define HDF_LOG_TAG usb_device_sdk_test
12
ReadComplete(uint8_t pipe,struct UsbFnRequest * req)13 static void ReadComplete(uint8_t pipe, struct UsbFnRequest *req)
14 {
15 struct AcmDevice *acmDevice = UsbGetAcmDevice();
16 if ((req == NULL) || (acmDevice == NULL)) {
17 return;
18 }
19 if (req->actual) {
20 uint8_t *data = (uint8_t *)req->buf;
21 data[req->actual] = '\0';
22 dprintf("receive [%d] bytes data: %s\n", req->actual, data);
23 if (strcmp((const char *)data, "q") == 0 || \
24 strcmp((const char *)data, "q\n") == 0) {
25 acmDevice->submitExit = 1;
26 }
27 }
28 acmDevice->submit = 1;
29 }
30
UsbFnDviceTestRequestAsync(void)31 int32_t UsbFnDviceTestRequestAsync(void)
32 {
33 struct UsbFnRequest *req = NULL;
34 int32_t ret;
35
36 ret = UsbFnSubmitRequestAsync(req);
37 if (HDF_SUCCESS == ret) {
38 HDF_LOGE("%s: async Request success!!", __func__);
39 return HDF_FAILURE;
40 }
41 return HDF_SUCCESS;
42 }
43
UsbFnDviceTestRequestAsync002(void)44 int32_t UsbFnDviceTestRequestAsync002(void)
45 {
46 struct UsbFnRequest *req = NULL;
47 int32_t ret = HDF_SUCCESS;
48 int32_t ret1;
49 struct AcmDevice *acmDevice = UsbGetAcmDevice();
50 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
51 HDF_LOGE("%s: dataIface.fn is invail", __func__);
52 return HDF_FAILURE;
53 }
54 dprintf("wait receiving data form host, please connect\n");
55 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id,
56 acmDevice->dataOutPipe.maxPacketSize);
57 if (req == NULL) {
58 HDF_LOGE("%s: alloc req fail", __func__);
59 return HDF_FAILURE;
60 }
61 req->complete = ReadComplete;
62 req->context = acmDevice;
63 while (acmDevice->connect == false) {
64 OsalMSleep(WAIT_100MS);
65 }
66 while (1) {
67 acmDevice->submit = 0;
68 ret = UsbFnSubmitRequestAsync(req);
69 if (HDF_SUCCESS != ret) {
70 HDF_LOGE("%s: async Request error", __func__);
71 ret = HDF_FAILURE;
72 break;
73 }
74 while (acmDevice->submit == 0) {
75 OsalMSleep(WAIT_100MS);
76 }
77 if (req->actual > 0) {
78 break;
79 }
80 }
81 ret1 = UsbFnFreeRequest(req);
82 if (HDF_SUCCESS != ret1) {
83 HDF_LOGE("%s: free Request error", __func__);
84 return HDF_FAILURE;
85 }
86 return ret;
87 }
88
UsbFnDviceTestRequestAsync003(void)89 int32_t UsbFnDviceTestRequestAsync003(void)
90 {
91 struct UsbFnRequest *req = NULL;
92 int32_t ret = HDF_SUCCESS;
93 int32_t ret1;
94 struct AcmDevice *acmDevice = UsbGetAcmDevice();
95 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
96 HDF_LOGE("%s: dataIface.fn is invail", __func__);
97 return HDF_FAILURE;
98 }
99 dprintf("wait receiving data form host, please connect\n");
100 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id,
101 acmDevice->dataOutPipe.maxPacketSize);
102 if (req == NULL) {
103 HDF_LOGE("%s: alloc req fail", __func__);
104 return HDF_FAILURE;
105 }
106 req->complete = ReadComplete;
107 req->context = acmDevice;
108 while (acmDevice->connect == false) {
109 OsalMSleep(WAIT_100MS);
110 }
111 acmDevice->submitExit = 0;
112 while (acmDevice->submitExit == 0) {
113 acmDevice->submit = 0;
114 ret = UsbFnSubmitRequestAsync(req);
115 if (HDF_SUCCESS != ret) {
116 HDF_LOGE("%s: async Request error", __func__);
117 ret = HDF_FAILURE;
118 break;
119 }
120 while (acmDevice->submit == 0) {
121 OsalMSleep(WAIT_100MS);
122 }
123 }
124 ret1 = UsbFnFreeRequest(req);
125 if (HDF_SUCCESS != ret1) {
126 HDF_LOGE("%s: free Request error", __func__);
127 return HDF_FAILURE;
128 }
129 return ret;
130 }
131
WriteComplete(uint8_t pipe,struct UsbFnRequest * req)132 static void WriteComplete(uint8_t pipe, struct UsbFnRequest *req)
133 {
134 struct AcmDevice *acmDevice = UsbGetAcmDevice();
135 if (acmDevice == NULL) {
136 return;
137 }
138 dprintf("write data status = %d\n", req->status);
139 acmDevice->submit = 1;
140 }
141
UsbFnDviceTestRequestAsync004(void)142 int32_t UsbFnDviceTestRequestAsync004(void)
143 {
144 struct UsbFnRequest *req = NULL;
145 int32_t ret;
146 struct AcmDevice *acmDevice = UsbGetAcmDevice();
147
148 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
149 HDF_LOGE("%s: dataIface.fn is invail", __func__);
150 return HDF_FAILURE;
151 }
152 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id,
153 acmDevice->dataInPipe.maxPacketSize);
154 if (req == NULL) {
155 HDF_LOGE("%s: alloc req fail", __func__);
156 return HDF_FAILURE;
157 }
158 req->complete = WriteComplete;
159 req->context = acmDevice;
160 acmDevice->submit = 0;
161 dprintf("------send \"abc\" to host------\n");
162 if (acmDevice->dataInPipe.maxPacketSize < strlen("abc")) {
163 ret = UsbFnFreeRequest(req);
164 if (HDF_SUCCESS != ret) {
165 HDF_LOGE("%s: free Request error", __func__);
166 }
167 return HDF_FAILURE;
168 }
169 if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")) != EOK) {
170 HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
171 }
172 req->length = strlen("abc");
173 ret = UsbFnSubmitRequestAsync(req);
174 if (HDF_SUCCESS != ret) {
175 HDF_LOGE("%s: async Request error", __func__);
176 return HDF_FAILURE;
177 }
178 while (acmDevice->submit == 0) {
179 OsalMSleep(1);
180 }
181 acmDevice->submit = 0;
182 ret = UsbFnFreeRequest(req);
183 if (HDF_SUCCESS != ret) {
184 HDF_LOGE("%s: free Request error", __func__);
185 return HDF_FAILURE;
186 }
187 return HDF_SUCCESS;
188 }
189
UsbFnDviceTestRequestAsync005(void)190 int32_t UsbFnDviceTestRequestAsync005(void)
191 {
192 struct UsbFnRequest *req = NULL;
193 int32_t loopTime = TEST_TIMES;
194 int32_t ret;
195 struct AcmDevice *acmDevice = UsbGetAcmDevice();
196
197 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
198 HDF_LOGE("%s: dataIface.fn is invail", __func__);
199 return HDF_FAILURE;
200 }
201 dprintf("------send \"xyz\" 10 times to host------\n");
202 while (loopTime--) {
203 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id,
204 acmDevice->dataInPipe.maxPacketSize);
205 if (req == NULL) {
206 HDF_LOGE("%s: alloc req fail", __func__);
207 return HDF_FAILURE;
208 }
209 req->complete = WriteComplete;
210 req->context = acmDevice;
211 acmDevice->submit = 0;
212 if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "xyz", strlen("xyz")) != EOK) {
213 HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
214 }
215 req->length = strlen("xyz");
216 ret = UsbFnSubmitRequestAsync(req);
217 if (HDF_SUCCESS != ret) {
218 HDF_LOGE("%s: async Request error", __func__);
219 return HDF_FAILURE;
220 }
221 while (acmDevice->submit == 0) {
222 OsalMSleep(1);
223 }
224 acmDevice->submit = 0;
225 ret = UsbFnFreeRequest(req);
226 if (HDF_SUCCESS != ret) {
227 HDF_LOGE("%s: free Request error", __func__);
228 return HDF_FAILURE;
229 }
230 }
231 return HDF_SUCCESS;
232 }
233
UsbFnDviceTestRequestAsync006(void)234 int32_t UsbFnDviceTestRequestAsync006(void)
235 {
236 return HDF_SUCCESS;
237 }
238
UsbFnDviceTestRequestSync(void)239 int32_t UsbFnDviceTestRequestSync(void)
240 {
241 struct UsbFnRequest *req = NULL;
242 int32_t ret;
243 ret = UsbFnSubmitRequestSync(req, 0);
244 if (HDF_SUCCESS == ret) {
245 HDF_LOGE("%s: sync Request success!!", __func__);
246 return HDF_FAILURE;
247 }
248 return HDF_SUCCESS;
249 }
250
UsbFnDviceTestRequestSync002(void)251 int32_t UsbFnDviceTestRequestSync002(void)
252 {
253 struct UsbFnRequest *req = NULL;
254 int32_t ret;
255 uint8_t *data = NULL;
256 struct AcmDevice *acmDevice = UsbGetAcmDevice();
257 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
258 HDF_LOGE("%s: dataIface.fn is invail", __func__);
259 return HDF_FAILURE;
260 }
261 dprintf("wait receiving data form host\n");
262 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id,
263 acmDevice->dataOutPipe.maxPacketSize);
264 if (req == NULL) {
265 HDF_LOGE("%s: alloc req fail", __func__);
266 return HDF_FAILURE;
267 }
268 ret = UsbFnSubmitRequestSync(req, 0);
269 if (ret != 0 || req->actual <= 0 || req->status != USB_REQUEST_COMPLETED) {
270 HDF_LOGE("%s: Sync Request error", __func__);
271 return HDF_FAILURE;
272 }
273 data = (uint8_t *)req->buf;
274 data[req->actual] = '\0';
275 dprintf("receive data from host: %s\n", data);
276 ret = UsbFnFreeRequest(req);
277 if (HDF_SUCCESS != ret) {
278 HDF_LOGE("%s: free Request error", __func__);
279 return HDF_FAILURE;
280 }
281 return HDF_SUCCESS;
282 }
283
UsbFnDviceTestRequestSync003(void)284 int32_t UsbFnDviceTestRequestSync003(void)
285 {
286 struct UsbFnRequest *req = NULL;
287 int32_t ret;
288 int32_t submitExit = 0;
289 uint8_t *data = NULL;
290 struct AcmDevice *acmDevice = UsbGetAcmDevice();
291 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
292 HDF_LOGE("%s: dataIface.fn is invail", __func__);
293 return HDF_FAILURE;
294 }
295 dprintf("receive data until 'q' exit\n");
296 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id,
297 acmDevice->dataOutPipe.maxPacketSize);
298 if (req == NULL) {
299 HDF_LOGE("%s: alloc req fail", __func__);
300 return HDF_FAILURE;
301 }
302 while (submitExit == 0) {
303 ret = UsbFnSubmitRequestSync(req, 0);
304 if (ret != 0 || req->actual <= 0 || req->status != USB_REQUEST_COMPLETED) {
305 HDF_LOGE("%s: Sync Request error", __func__);
306 break;
307 }
308 data = (uint8_t *)req->buf;
309 data[req->actual] = '\0';
310 if (strcmp((const char *)data, "q") == 0 || \
311 strcmp((const char *)data, "q\n") == 0) {
312 submitExit = 1;
313 }
314 dprintf("receive data from host: %s\n", data);
315 }
316 ret = UsbFnFreeRequest(req);
317 if (HDF_SUCCESS != ret) {
318 HDF_LOGE("%s: free Request error", __func__);
319 return HDF_FAILURE;
320 }
321 return HDF_SUCCESS;
322 }
323
UsbFnDviceTestRequestSync004(void)324 int32_t UsbFnDviceTestRequestSync004(void)
325 {
326 struct UsbFnRequest *req = NULL;
327 int32_t ret;
328 struct AcmDevice *acmDevice = UsbGetAcmDevice();
329
330 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
331 HDF_LOGE("%s: dataIface.fn is invail", __func__);
332 return HDF_FAILURE;
333 }
334 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id,
335 acmDevice->dataInPipe.maxPacketSize);
336 if (req == NULL) {
337 HDF_LOGE("%s: alloc req fail", __func__);
338 return HDF_FAILURE;
339 }
340 dprintf("------send \"abc\" to host------\n");
341 if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")) != EOK) {
342 HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
343 }
344 req->length = strlen("abc");
345 ret = UsbFnSubmitRequestSync(req, 0);
346 if (HDF_SUCCESS != ret || (req->actual != strlen("abc")) || \
347 (req->status != USB_REQUEST_COMPLETED)) {
348 HDF_LOGE("%s: async Request error", __func__);
349 return HDF_FAILURE;
350 }
351 ret = UsbFnFreeRequest(req);
352 if (HDF_SUCCESS != ret) {
353 HDF_LOGE("%s: free Request error", __func__);
354 return HDF_FAILURE;
355 }
356 return HDF_SUCCESS;
357 }
358
UsbFnDviceTestRequestSync005(void)359 int32_t UsbFnDviceTestRequestSync005(void)
360 {
361 struct UsbFnRequest *req = NULL;
362 int32_t loopTime = TEST_TIMES;
363 int32_t ret;
364 struct AcmDevice *acmDevice = UsbGetAcmDevice();
365
366 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
367 HDF_LOGE("%s: dataIface.fn is invail", __func__);
368 return HDF_FAILURE;
369 }
370 dprintf("------send \"abcdefg\" 10 times to host------\n");
371 while (loopTime--) {
372 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id,
373 acmDevice->dataInPipe.maxPacketSize);
374 if (req == NULL) {
375 HDF_LOGE("%s: alloc req fail", __func__);
376 return HDF_FAILURE;
377 }
378 if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "abcdefg", strlen("abcdefg")) != EOK) {
379 HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
380 }
381 req->length = strlen("abcdefg");
382 ret = UsbFnSubmitRequestSync(req, 0);
383 if (HDF_SUCCESS != ret || (req->actual != strlen("abcdefg")) || \
384 (req->status != USB_REQUEST_COMPLETED)) {
385 HDF_LOGE("%s: async Request error", __func__);
386 return HDF_FAILURE;
387 }
388 ret = UsbFnFreeRequest(req);
389 if (HDF_SUCCESS != ret) {
390 HDF_LOGE("%s: free Request error", __func__);
391 return HDF_FAILURE;
392 }
393 }
394 return HDF_SUCCESS;
395 }
396
UsbFnDviceTestRequestSync006(void)397 int32_t UsbFnDviceTestRequestSync006(void)
398 {
399 struct UsbFnRequest *req = NULL;
400 int32_t ret;
401 struct AcmDevice *acmDevice = UsbGetAcmDevice();
402 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
403 HDF_LOGE("%s: dataIface.fn is invail", __func__);
404 return HDF_FAILURE;
405 }
406 dprintf("test sync timeout 5s:\n");
407 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id,
408 acmDevice->dataOutPipe.maxPacketSize);
409 if (req == NULL) {
410 HDF_LOGE("%s: alloc req fail", __func__);
411 return HDF_FAILURE;
412 }
413 ret = UsbFnSubmitRequestSync(req, SYNC_5000MS);
414 if (ret == 0) {
415 HDF_LOGE("%s: Sync Request success", __func__);
416 return HDF_FAILURE;
417 }
418 ret = UsbFnFreeRequest(req);
419 if (HDF_SUCCESS != ret) {
420 HDF_LOGE("%s: free Request error", __func__);
421 return HDF_FAILURE;
422 }
423 return HDF_SUCCESS;
424 }
425
UsbFnDviceTestRequestSync007(void)426 int32_t UsbFnDviceTestRequestSync007(void)
427 {
428 struct UsbFnRequest *req = NULL;
429 int32_t ret;
430
431 ret = UsbFnSubmitRequestSync(req, SYNC_5000MS);
432 if (ret == 0) {
433 HDF_LOGE("%s: Sync Request error", __func__);
434 return HDF_FAILURE;
435 }
436 return HDF_SUCCESS;
437 }
438
TestCancelComplete(uint8_t pipe,struct UsbFnRequest * req)439 static void TestCancelComplete(uint8_t pipe, struct UsbFnRequest *req)
440 {
441 struct AcmDevice *acmDevice = UsbGetAcmDevice();
442 if (acmDevice == NULL) {
443 return;
444 }
445
446 acmDevice->havedSubmit = true;
447 }
448
UsbFnDviceTestCancelRequest(void)449 int32_t UsbFnDviceTestCancelRequest(void)
450 {
451 int32_t ret;
452 struct UsbFnRequest *notifyReq = NULL;
453 ret = UsbFnCancelRequest(notifyReq);
454 if (HDF_SUCCESS == ret) {
455 HDF_LOGE("%s: cancel request success!!", __func__);
456 return HDF_FAILURE;
457 }
458 return HDF_SUCCESS;
459 }
460
UsbFnDviceTestCancelRequest002(void)461 int32_t UsbFnDviceTestCancelRequest002(void)
462 {
463 int32_t ret;
464 struct UsbFnRequest *req = NULL;
465 struct AcmDevice *acmDevice = UsbGetAcmDevice();
466
467 if (acmDevice == NULL || acmDevice->ctrlIface.handle == NULL) {
468 HDF_LOGE("%s: CtrlIface.handle is invail", __func__);
469 return HDF_FAILURE;
470 }
471 req = UsbFnAllocCtrlRequest(acmDevice->ctrlIface.handle,
472 sizeof(struct UsbCdcNotification));
473 if (req == NULL) {
474 HDF_LOGE("%s: alloc req fail", __func__);
475 return HDF_FAILURE;
476 }
477 ret = UsbFnCancelRequest(req);
478 if (HDF_SUCCESS == ret) {
479 HDF_LOGE("%s: cancel request success", __func__);
480 ret = UsbFnFreeRequest(req);
481 if (HDF_SUCCESS != ret) {
482 HDF_LOGE("%s: free Request error", __func__);
483 return HDF_FAILURE;
484 }
485 return HDF_FAILURE;
486 }
487 ret = UsbFnFreeRequest(req);
488 if (HDF_SUCCESS != ret) {
489 HDF_LOGE("%s: free Request error", __func__);
490 return HDF_FAILURE;
491 }
492 return HDF_SUCCESS;
493 }
494
UsbFnDviceTestCancelRequest003(void)495 int32_t UsbFnDviceTestCancelRequest003(void)
496 {
497 int32_t ret;
498 struct UsbFnRequest *req = NULL;
499 struct AcmDevice *acmDevice = UsbGetAcmDevice();
500
501 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
502 HDF_LOGE("%s: dataIface.handle is invail", __func__);
503 return HDF_FAILURE;
504 }
505 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id,
506 acmDevice->dataInPipe.maxPacketSize);
507 if (req == NULL) {
508 HDF_LOGE("%s: alloc req fail", __func__);
509 return HDF_FAILURE;
510 }
511 ret = UsbFnCancelRequest(req);
512 if (HDF_SUCCESS == ret) {
513 dprintf("%s: cancel request success\n", __func__);
514 ret = UsbFnFreeRequest(req);
515 if (HDF_SUCCESS != ret) {
516 dprintf("%s: free Request error", __func__);
517 return HDF_FAILURE;
518 }
519 return HDF_FAILURE;
520 }
521 ret = UsbFnFreeRequest(req);
522 if (HDF_SUCCESS != ret) {
523 HDF_LOGE("%s: free Request error", __func__);
524 return HDF_FAILURE;
525 }
526 return HDF_SUCCESS;
527 }
528
UsbFnDviceTestCancelRequest004(void)529 int32_t UsbFnDviceTestCancelRequest004(void)
530 {
531 int32_t ret;
532 struct UsbFnRequest *req = NULL;
533 struct AcmDevice *acmDevice = UsbGetAcmDevice();
534
535 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
536 HDF_LOGE("%s: dataIface.handle is invail", __func__);
537 return HDF_FAILURE;
538 }
539 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id,
540 acmDevice->dataInPipe.maxPacketSize);
541 if (req == NULL) {
542 HDF_LOGE("%s: alloc req fail", __func__);
543 return HDF_FAILURE;
544 }
545 ret = UsbFnCancelRequest(req);
546 if (HDF_SUCCESS == ret) {
547 dprintf("%s: cancel request success\n", __func__);
548 ret = UsbFnFreeRequest(req);
549 if (HDF_SUCCESS != ret) {
550 dprintf("%s: free Request error", __func__);
551 return HDF_FAILURE;
552 }
553 return HDF_FAILURE;
554 }
555 ret = UsbFnFreeRequest(req);
556 if (HDF_SUCCESS != ret) {
557 HDF_LOGE("%s: free Request error", __func__);
558 return HDF_FAILURE;
559 }
560 return HDF_SUCCESS;
561 }
562
UsbFnDviceTestCancelRequest005(void)563 int32_t UsbFnDviceTestCancelRequest005(void)
564 {
565 int32_t ret;
566 struct UsbFnRequest *req = NULL;
567 struct AcmDevice *acmDevice = UsbGetAcmDevice();
568
569 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
570 HDF_LOGE("%s: dataIface.handle is invail", __func__);
571 return HDF_FAILURE;
572 }
573 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id,
574 acmDevice->dataInPipe.maxPacketSize);
575 if (req == NULL) {
576 HDF_LOGE("%s: alloc req fail", __func__);
577 return HDF_FAILURE;
578 }
579 acmDevice->havedSubmit = false;
580 req->complete = TestCancelComplete;
581 req->context = acmDevice;
582 dprintf("------send \"abc\" to host------\n");
583 if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")) != EOK) {
584 HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
585 }
586 req->length = strlen("abc");
587 ret = UsbFnSubmitRequestAsync(req);
588 if (HDF_SUCCESS != ret) {
589 HDF_LOGE("%s: request async error", __func__);
590 return HDF_FAILURE;
591 }
592 while (acmDevice->havedSubmit == 0) {
593 OsalMSleep(1);
594 }
595 ret = UsbFnCancelRequest(req);
596 if (HDF_SUCCESS == ret) {
597 dprintf("%s: cancel request error", __func__);
598 return HDF_FAILURE;
599 }
600 acmDevice->havedSubmit = false;
601 ret = UsbFnFreeRequest(req);
602 if (HDF_SUCCESS != ret) {
603 HDF_LOGE("%s: free Request error", __func__);
604 return HDF_FAILURE;
605 }
606 return HDF_SUCCESS;
607 }
608
TestCancelRequest(struct UsbFnRequest * req,struct UsbFnRequest * req2)609 int32_t TestCancelRequest(struct UsbFnRequest *req, struct UsbFnRequest *req2)
610 {
611 int32_t ret;
612 ret = UsbFnSubmitRequestAsync(req2);
613 if (HDF_SUCCESS != ret) {
614 HDF_LOGE("%s: request async error", __func__);
615 return HDF_FAILURE;
616 }
617 ret = UsbFnCancelRequest(req2);
618 if (HDF_SUCCESS != ret) {
619 dprintf("%s: cancel request error", __func__);
620 return HDF_FAILURE;
621 }
622 ret = UsbFnCancelRequest(req);
623 if (HDF_SUCCESS != ret) {
624 dprintf("%s: cancel request error", __func__);
625 return HDF_FAILURE;
626 }
627 ret = UsbFnFreeRequest(req);
628 if (HDF_SUCCESS != ret) {
629 dprintf("%s: free Request error", __func__);
630 return HDF_FAILURE;
631 }
632 ret = UsbFnFreeRequest(req2);
633 if (HDF_SUCCESS != ret) {
634 dprintf("%s: free Request error", __func__);
635 return HDF_FAILURE;
636 }
637 return HDF_SUCCESS;
638 }
639
UsbFnDviceTestCancelRequest006(void)640 int32_t UsbFnDviceTestCancelRequest006(void)
641 {
642 int32_t ret;
643 struct UsbFnRequest *req = NULL;
644 struct UsbFnRequest *req2 = NULL;
645 struct AcmDevice *acmDevice = UsbGetAcmDevice();
646
647 if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
648 HDF_LOGE("%s: dataIface.handle is invail", __func__);
649 return HDF_FAILURE;
650 }
651 req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id,
652 acmDevice->dataOutPipe.maxPacketSize);
653 if (req == NULL) {
654 HDF_LOGE("%s: alloc req fail", __func__);
655 return HDF_FAILURE;
656 }
657 acmDevice->havedSubmit = false;
658 req->complete = TestCancelComplete;
659 req->context = acmDevice;
660
661 req2 = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id,
662 acmDevice->dataOutPipe.maxPacketSize);
663 if (req2 == NULL) {
664 HDF_LOGE("%s: alloc req fail", __func__);
665 return HDF_FAILURE;
666 }
667 acmDevice->submit = false;
668 req2->complete = ReadComplete;
669 req2->context = acmDevice;
670 ret = UsbFnSubmitRequestAsync(req);
671 if (HDF_SUCCESS != ret) {
672 HDF_LOGE("%s: request async error", __func__);
673 return HDF_FAILURE;
674 }
675 return TestCancelRequest(req, req2);
676 }
677
678