1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "osal_mem.h"
17 #include "osal_time.h"
18 #include "securec.h"
19 #include "hdf_base.h"
20 #include "hdf_log.h"
21 #include "hdf_usb_pnp_manage.h"
22 #include "hdf_base.h"
23 #include "hdf_log.h"
24 #include "osal_mem.h"
25 #include "osal_time.h"
26 #include "securec.h"
27 #include "usb_interface.h"
28 #include "hdf_usb_pnp_manage.h"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <errno.h>
33 #include <string.h>
34 #include <dirent.h>
35 #include <sys/ioctl.h>
36 #include <sys/mman.h>
37 #include <fcntl.h>
38 #include <stdlib.h>
39 #include <sys/time.h>
40 #include <signal.h>
41 #include <sys/mman.h>
42 #include <osal_thread.h>
43 #include "usbhost_sdkraw_speed.h"
44
45 #define HDF_LOG_TAG USB_HOST_ACM_RAW_API
46
47 #define USB_CTRL_REQ_SIZE 64
48 #define USB_IO_THREAD_STACK_SIZE 8192
49 #define USB_RAW_IO_SLEEP_MS_TIME 500
50 #define USB_RAW_IO_STOP_WAIT_MAX_TIME 2
51
52 static struct AcmDevice *acm = NULL;
53 static bool g_stopIoThreadFlag = false;
54 static unsigned int g_speedFlag = 0;
55 static uint64_t g_send_count = 0;
56 static uint64_t g_recv_count = 0;
57 static uint64_t g_byteTotal = 0;
58 static bool g_writeOrRead = TEST_WRITE;
59 static bool g_printData = false;
60 static struct OsalSem sem;
61
62 static void AcmTestBulkCallback(const void *requestArg);
63 static int32_t SerialBegin(struct AcmDevice *acm);
64
UsbIoThread(void * data)65 static int UsbIoThread(void *data)
66 {
67 int ret;
68 struct AcmDevice *acm = (struct AcmDevice *)data;
69
70 for (;;) {
71 if (acm == NULL) {
72 HDF_LOGE("%s:%d acm is NULL", __func__, __LINE__);
73 OsalMSleep(USB_RAW_IO_SLEEP_MS_TIME);
74 continue;
75 }
76
77 if (acm->devHandle == NULL) {
78 HDF_LOGE("%s:%d acm->devHandle is NULL!", __func__, __LINE__);
79 OsalMSleep(USB_RAW_IO_SLEEP_MS_TIME);
80 continue;
81 }
82
83 ret = UsbRawHandleRequests(acm->devHandle);
84 if (ret < 0) {
85 HDF_LOGE("%s:%d UsbRawHandleRequests failed, ret=%d ", \
86 __func__, __LINE__, ret);
87 if (ret == USB_REQUEST_NO_DEVICE) {
88 HDF_LOGE("%s:%d, ret=%d", __func__, __LINE__, ret);
89 OsalMSleep(USB_RAW_IO_SLEEP_MS_TIME);
90 }
91 }
92
93 if (g_stopIoThreadFlag == true) {
94 HDF_LOGD("%s:%d", __func__, __LINE__);
95 g_stopIoThreadFlag = false;
96 break;
97 }
98 }
99
100 HDF_LOGD("%s:%d exit", __func__, __LINE__);
101
102 return HDF_SUCCESS;
103 }
104
UsbIoSendThread(void * data)105 static int UsbIoSendThread(void *data)
106 {
107 struct AcmDevice *acm = (struct AcmDevice *)data;
108
109 for (;;) {
110 OsalSemWait(&sem, HDF_WAIT_FOREVER);
111 if (!g_speedFlag) {
112 SerialBegin(acm);
113 g_send_count++;
114 }
115 }
116 }
117
UsbStartIo(struct AcmDevice * acm)118 static int UsbStartIo(struct AcmDevice *acm)
119 {
120 struct OsalThreadParam threadCfg;
121 int ret;
122
123 HDF_LOGI("%s start", __func__);
124
125 /* creat Io thread */
126 (void)memset_s(&threadCfg, sizeof(threadCfg), 0, sizeof(threadCfg));
127 threadCfg.name = "usb io thread";
128 threadCfg.priority = OSAL_THREAD_PRI_DEFAULT;
129 threadCfg.stackSize = USB_IO_THREAD_STACK_SIZE;
130
131 ret = OsalThreadCreate(&acm->ioThread, \
132 (OsalThreadEntry)UsbIoThread, (void *)acm);
133 if (ret != HDF_SUCCESS) {
134 HDF_LOGE("%s:%d OsalThreadCreate faile, ret=%d ",
135 __func__, __LINE__, ret);
136 return ret;
137 }
138
139 ret = OsalThreadStart(&acm->ioThread, &threadCfg);
140 if (ret != HDF_SUCCESS) {
141 HDF_LOGE("%s:%d OsalThreadStart faile, ret=%d ",
142 __func__, __LINE__, ret);
143 return ret;
144 }
145
146 (void)memset_s(&threadCfg, sizeof(threadCfg), 0, sizeof(threadCfg));
147 threadCfg.name = "usb io send thread";
148 threadCfg.priority = OSAL_THREAD_PRI_DEFAULT;
149 threadCfg.stackSize = USB_IO_THREAD_STACK_SIZE;
150 ret = OsalThreadCreate(&acm->ioSendThread, \
151 (OsalThreadEntry)UsbIoSendThread, (void *)acm);
152 if (ret != HDF_SUCCESS) {
153 HDF_LOGE("%s:%d OsalThreadCreate faile, ret=%d ",
154 __func__, __LINE__, ret);
155 return ret;
156 }
157
158 ret = OsalThreadStart(&acm->ioSendThread, &threadCfg);
159 if (ret != HDF_SUCCESS) {
160 HDF_LOGE("%s:%d OsalThreadStart faile, ret=%d ",
161 __func__, __LINE__, ret);
162 return ret;
163 }
164
165 return HDF_SUCCESS;
166 }
167
UsbStopIo(struct AcmDevice * acm)168 static int UsbStopIo(struct AcmDevice *acm)
169 {
170 int ret;
171 int32_t i = 0;
172
173 HDF_LOGD("%s:%d", __func__, __LINE__);
174 if (g_stopIoThreadFlag == false) {
175 HDF_LOGD("%s:%d", __func__, __LINE__);
176 g_stopIoThreadFlag = true;
177 }
178 HDF_LOGD("%s:%d", __func__, __LINE__);
179
180 while (g_stopIoThreadFlag) {
181 i++;
182 OsalMSleep(USB_RAW_IO_SLEEP_MS_TIME);
183 if (i > USB_RAW_IO_STOP_WAIT_MAX_TIME) {
184 HDF_LOGD("%s:%d", __func__, __LINE__);
185 g_stopIoThreadFlag = false;
186 }
187 }
188 HDF_LOGD("%s:%d", __func__, __LINE__);
189
190 ret = OsalThreadDestroy(&acm->ioThread);
191 if (ret != HDF_SUCCESS) {
192 HDF_LOGE("%s:%d OsalThreadDestroy faile, ret=%d ",
193 __func__, __LINE__, ret);
194 return ret;
195 }
196
197 ret = OsalThreadDestroy(&acm->ioSendThread);
198 if (ret != HDF_SUCCESS) {
199 HDF_LOGE("%s:%d OsalThreadDestroy faile, ret=%d ",
200 __func__, __LINE__, ret);
201 return ret;
202 }
203
204 return HDF_SUCCESS;
205 }
206
UsbGetConfigDescriptor(UsbRawHandle * devHandle,struct UsbRawConfigDescriptor ** config)207 static int UsbGetConfigDescriptor(UsbRawHandle *devHandle, struct UsbRawConfigDescriptor **config)
208 {
209 UsbRawDevice *dev = NULL;
210 int activeConfig;
211 int ret;
212
213 if (devHandle == NULL) {
214 HDF_LOGE("%s:%d devHandle is NULL",
215 __func__, __LINE__);
216 return HDF_ERR_INVALID_PARAM;
217 }
218
219 ret = UsbRawGetConfiguration(devHandle, &activeConfig);
220 if (ret) {
221 HDF_LOGE("%s:%d UsbRawGetConfiguration failed, ret=%d",
222 __func__, __LINE__, ret);
223 return HDF_FAILURE;
224 }
225 HDF_LOGE("%s:%d activeConfig=%d", __func__, __LINE__, activeConfig);
226 dev = UsbRawGetDevice(devHandle);
227 if (dev == NULL) {
228 HDF_LOGE("%s:%d UsbRawGetDevice failed",
229 __func__, __LINE__);
230 return HDF_FAILURE;
231 }
232
233 ret = UsbRawGetConfigDescriptor(dev, activeConfig, config);
234 if (ret) {
235 HDF_LOGE("UsbRawGetConfigDescriptor failed, ret=%d\n", ret);
236 return HDF_FAILURE;
237 }
238
239 return HDF_SUCCESS;
240 }
241
UsbParseConfigDescriptor(struct AcmDevice * acm,struct UsbRawConfigDescriptor * config)242 static int UsbParseConfigDescriptor(struct AcmDevice *acm, struct UsbRawConfigDescriptor *config)
243 {
244 uint8_t i;
245 uint8_t j;
246 int ret;
247
248 if ((acm == NULL) || (config == NULL)) {
249 HDF_LOGE("%s:%d acm or config is NULL",
250 __func__, __LINE__);
251 return HDF_ERR_INVALID_PARAM;
252 }
253
254 for (i = 0; i < acm->interfaceCnt; i++) {
255 uint8_t interfaceIndex = acm->interfaceIndex[i];
256 const struct UsbRawInterface *interface = config->interface[interfaceIndex];
257 uint8_t ifaceClass = interface->altsetting->interfaceDescriptor.bInterfaceClass;
258 uint8_t numEndpoints = interface->altsetting->interfaceDescriptor.bNumEndpoints;
259
260 ret = UsbRawClaimInterface(acm->devHandle, interfaceIndex);
261 if (ret) {
262 HDF_LOGE("%s:%d claim interface %u failed",
263 __func__, __LINE__, i);
264 return ret;
265 }
266
267 switch (ifaceClass) {
268 case USB_DDK_CLASS_COMM:
269 acm->ctrlIface = interfaceIndex;
270 acm->notifyEp = OsalMemAlloc(sizeof(struct UsbEndpoint));
271 if (acm->notifyEp == NULL) {
272 HDF_LOGE("%s:%d allocate endpoint failed",
273 __func__, __LINE__);
274 break;
275 }
276 /* get the first endpoint by default */
277 acm->notifyEp->addr = interface->altsetting->endPoint[0].endpointDescriptor.bEndpointAddress;
278 acm->notifyEp->interval = interface->altsetting->endPoint[0].endpointDescriptor.bInterval;
279 acm->notifyEp->maxPacketSize = interface->altsetting->endPoint[0].endpointDescriptor.wMaxPacketSize;
280 break;
281 case USB_DDK_CLASS_CDC_DATA:
282 acm->dataIface = interfaceIndex;
283 for (j = 0; j < numEndpoints; j++) {
284 const struct UsbRawEndpointDescriptor *endPoint = &interface->altsetting->endPoint[j];
285
286 /* get bulk in endpoint */
287 if ((endPoint->endpointDescriptor.bEndpointAddress & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_IN) {
288 acm->dataInEp = OsalMemAlloc(sizeof(struct UsbEndpoint));
289 if (acm->dataInEp == NULL) {
290 HDF_LOGE("%s:%d allocate dataInEp failed",
291 __func__, __LINE__);
292 break;
293 }
294 acm->dataInEp->addr = endPoint->endpointDescriptor.bEndpointAddress;
295 acm->dataInEp->interval = endPoint->endpointDescriptor.bInterval;
296 acm->dataInEp->maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize;
297 } else { /* get bulk out endpoint */
298 acm->dataOutEp = OsalMemAlloc(sizeof(struct UsbEndpoint));
299 if (acm->dataOutEp == NULL) {
300 HDF_LOGE("%s:%d allocate dataOutEp failed",
301 __func__, __LINE__);
302 break;
303 }
304 acm->dataOutEp->addr = endPoint->endpointDescriptor.bEndpointAddress;
305 acm->dataOutEp->interval = endPoint->endpointDescriptor.bInterval;
306 acm->dataOutEp->maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize;
307 }
308 }
309 break;
310 default:
311 HDF_LOGE("%s:%d wrong descriptor type", __func__, __LINE__);
312 break;
313 }
314 }
315
316 return HDF_SUCCESS;
317 }
318
UsbAllocDataRequests(struct AcmDevice * acm)319 static int UsbAllocDataRequests(struct AcmDevice *acm)
320 {
321 int i;
322 int ret;
323 for (i = 0; i < TEST_CYCLE; i++) {
324 struct AcmDb *snd = &acm->db[i];
325 snd->request = UsbRawAllocRequest(acm->devHandle, 0, acm->dataEp->maxPacketSize);
326 snd->instance = acm;
327 if (snd->request == NULL) {
328 HDF_LOGE("%s: UsbRawAllocRequest faild", __func__);
329 return HDF_ERR_MALLOC_FAIL;
330 }
331 struct UsbRawFillRequestData reqData;
332 reqData.endPoint = acm->dataEp->addr;
333 reqData.numIsoPackets = 0;
334 reqData.callback = AcmTestBulkCallback;
335 reqData.userData = (void *)snd;
336 reqData.timeout = USB_CTRL_SET_TIMEOUT;
337 reqData.buffer = snd->buf;
338 reqData.length = acm->dataSize;
339
340 ret = UsbRawFillBulkRequest(snd->request, acm->devHandle, &reqData);
341 if (ret) {
342 HDF_LOGE("%s: FillInterruptRequest faile, ret=%d",
343 __func__, ret);
344 return HDF_FAILURE;
345 }
346 }
347
348 return HDF_SUCCESS;
349 }
UsbSerialDeviceAlloc(struct AcmDevice * acm)350 static int32_t UsbSerialDeviceAlloc(struct AcmDevice *acm)
351 {
352 struct SerialDevice *port = NULL;
353
354 if (acm == NULL) {
355 HDF_LOGE("%s: acm null pointer", __func__);
356 return HDF_FAILURE;
357 }
358
359 port = (struct SerialDevice *)OsalMemCalloc(sizeof(*port));
360 if (port == NULL) {
361 HDF_LOGE("%s: Alloc usb serial port failed", __func__);
362 return HDF_FAILURE;
363 }
364 if (OsalMutexInit(&port->lock) != HDF_SUCCESS) {
365 HDF_LOGE("%s: init lock fail!", __func__);
366 return HDF_FAILURE;
367 }
368 port->lineCoding.dwDTERate = CpuToLe32(DATARATE);
369 port->lineCoding.bCharFormat = CHARFORMAT;
370 port->lineCoding.bParityType = USB_CDC_NO_PARITY;
371 port->lineCoding.bDataBits = USB_CDC_1_STOP_BITS;
372 acm->lineCoding = port->lineCoding;
373 acm->port = port;
374 port->acm = acm;
375
376 return HDF_SUCCESS;
377 }
378
AcmDbAlloc(struct AcmDevice * acm)379 static int AcmDbAlloc(struct AcmDevice *acm)
380 {
381 struct AcmDb *db = NULL;
382 int i;
383
384 for (i = 0; i < TEST_CYCLE; i++) {
385 db = &acm->db[i];
386 if (!db->use) {
387 db->use = 1;
388 db->len = 0;
389 return i;
390 }
391 }
392 return -1;
393 }
394
AcmDbIsAvail(struct AcmDevice * acm)395 static int AcmDbIsAvail(struct AcmDevice *acm)
396 {
397 int i;
398 int n = TEST_CYCLE;
399
400 for (i = 0; i < TEST_CYCLE; i++) {
401 n -= acm->db[i].use;
402 }
403 return n;
404 }
405
AcmStartdb(struct AcmDevice * acm,struct AcmDb * db)406 static int AcmStartdb(struct AcmDevice *acm, struct AcmDb *db)
407 {
408 int ret;
409 ret = UsbRawSubmitRequest(db->request);
410 if (ret) {
411 HDF_LOGE("UsbRawSubmitRequest failed, ret=%d", ret);
412 db->use = 0;
413 }
414 return ret;
415 }
416
AcmDataBufAlloc(struct AcmDevice * acm)417 static int AcmDataBufAlloc(struct AcmDevice *acm)
418 {
419 struct AcmDb *db = &acm->db[0];
420 int i;
421
422 for (i = 0; i < TEST_CYCLE; i++, db++) {
423 db->buf = OsalMemCalloc(acm->dataEp->maxPacketSize);
424 if (!db->buf) {
425 while (i != 0) {
426 --i;
427 --db;
428 OsalMemFree(db->buf);
429 db->buf = NULL;
430 }
431 return -HDF_ERR_MALLOC_FAIL;
432 }
433 else {
434 memset_s(db->buf, acm->dataSize, 'b', acm->dataSize);
435 db->instance = acm;
436 }
437 }
438 return HDF_SUCCESS;
439 }
440
AcmTestBulkCallback(const void * requestArg)441 static void AcmTestBulkCallback(const void *requestArg)
442 {
443 struct UsbRawRequest *req = (struct UsbRawRequest *)requestArg;
444 struct itimerval new_value, old_value;
445 if (req == NULL) {
446 HDF_LOGE("%s:%{pulib}d req is NULL!", __func__, __LINE__);
447 return;
448 }
449 struct AcmDb *db = (struct AcmDb *)req->userData;
450 if (db == NULL) {
451 HDF_LOGE("%s:%{pulib}d userData(db) is NULL!", __func__, __LINE__);
452 return;
453 }
454
455 if (req->status == USB_REQUEST_COMPLETED) {
456 if (g_byteTotal == 0) {
457 new_value.it_value.tv_sec = TEST_PRINT_TIME;
458 new_value.it_value.tv_usec = 0;
459 new_value.it_interval.tv_sec = TEST_PRINT_TIME;
460 new_value.it_interval.tv_usec = 0;
461 setitimer(ITIMER_REAL, &new_value, &old_value);
462 }
463 g_recv_count++;
464 g_byteTotal += req->actualLength;
465 } else {
466 printf("status error\n");
467 }
468
469 if (g_printData == true) {
470 for (int i = 0; i < req->actualLength; i++)
471 printf("%c", req->buffer[i]);
472 fflush(stdout);
473 } else if (g_recv_count % 10000 == 0) {
474 printf("#");
475 fflush(stdout);
476 }
477
478 db->use = 0;
479 OsalSemPost(&sem);
480 }
481
SerialBegin(struct AcmDevice * acm)482 static int32_t SerialBegin(struct AcmDevice *acm)
483 {
484 uint32_t size = acm->dataSize;
485 int32_t ret;
486 struct AcmDb *db = NULL;
487 int dbn;
488 if (AcmDbIsAvail(acm)) {
489 dbn = AcmDbAlloc(acm);
490 } else {
491 HDF_LOGE("no buf\n");
492 return 0;
493 }
494 if (dbn < 0) {
495 HDF_LOGE("AcmDbAlloc failed\n");
496 return HDF_FAILURE;
497 }
498 db = &acm->db[dbn];
499 db->len = acm->dataSize;
500 if (g_writeOrRead == TEST_READ) {
501 memset_s(db->buf, TEST_LENGTH, '0', TEST_LENGTH);
502 }
503 struct UsbRawFillRequestData reqData;
504 reqData.endPoint = acm->dataEp->addr;
505 reqData.numIsoPackets = 0;
506 reqData.callback = AcmTestBulkCallback;
507 reqData.userData = (void *)db;
508 reqData.timeout = USB_CTRL_SET_TIMEOUT;
509 reqData.buffer = db->buf;
510 reqData.length = acm->dataSize;
511
512 ret = UsbRawFillBulkRequest(db->request, acm->devHandle, &reqData);
513 if (ret) {
514 HDF_LOGE("%s: FillInterruptRequest faile, ret=%d",
515 __func__, ret);
516 return HDF_FAILURE;
517 }
518
519 ret = AcmStartdb(acm, db);
520 return size;
521 }
522
SignalHandler(int signo)523 void SignalHandler(int signo)
524 {
525 static uint32_t sigCnt = 0;
526 struct itimerval new_value, old_value;
527 double speed = 0;
528 switch (signo) {
529 case SIGALRM:
530 sigCnt++;
531 if (sigCnt * TEST_PRINT_TIME >= TEST_TIME) {
532 g_speedFlag = 1;
533 break;
534 }
535
536 speed = (g_byteTotal * 1.0) / (sigCnt * TEST_PRINT_TIME * 1024 * 1024);
537 printf("\nSpeed:%f MB/s\n", speed);
538 new_value.it_value.tv_sec = TEST_PRINT_TIME;
539 new_value.it_value.tv_usec = 0;
540 new_value.it_interval.tv_sec = TEST_PRINT_TIME;
541 new_value.it_interval.tv_usec = 0;
542 setitimer(ITIMER_REAL, &new_value, &old_value);
543 break;
544 case SIGINT:
545 g_speedFlag = 1;
546 break;
547 default:
548 break;
549 }
550 }
551
ShowHelp(char * name)552 static void ShowHelp(char *name)
553 {
554 printf(">> usage:\n");
555 printf(">> %s [<busNum> <devAddr>] <ifaceNum> <w>/<r> [printdata]> \n", name);
556 printf("\n");
557 }
558
main(int argc,char * argv[])559 int main(int argc, char *argv[])
560 {
561 struct UsbSession *session = NULL;
562 UsbRawHandle *devHandle = NULL;
563 int32_t ret = HDF_SUCCESS;
564 int busNum = 1;
565 int devAddr = 2;
566 int ifaceNum = 3;
567 struct timeval time;
568 int i = 0;
569 if (argc == 6) {
570 busNum = atoi(argv[1]);
571 devAddr = atoi(argv[2]);
572 ifaceNum = atoi(argv[3]);
573 g_writeOrRead = (strncmp(argv[4], "r", 1))?TEST_WRITE:TEST_READ;
574 if (g_writeOrRead == TEST_READ)
575 {
576 g_printData = (strncmp(argv[5], "printdata", 1))?false:true;
577 }
578 } else if (argc == 5) {
579 busNum = atoi(argv[1]);
580 devAddr = atoi(argv[2]);
581 ifaceNum = atoi(argv[3]);
582 g_writeOrRead = (strncmp(argv[4], "r", 1))?TEST_WRITE:TEST_READ;
583 } else if (argc == 3) {
584 ifaceNum = atoi(argv[1]);
585 g_writeOrRead = (strncmp(argv[2], "r", 1))?TEST_WRITE:TEST_READ;
586 } else {
587 printf("Error: parameter error!\n\n");
588 ShowHelp(argv[0]);
589 ret = HDF_FAILURE;
590 goto end;
591 }
592 OsalSemInit(&sem, 0);
593
594 acm = (struct AcmDevice *)OsalMemCalloc(sizeof(*acm));
595 if (acm == NULL) {
596 HDF_LOGE("%s: Alloc usb serial device failed", __func__);
597 ret = HDF_FAILURE;
598 goto end;
599 }
600
601 acm->busNum = busNum;
602 acm->devAddr = devAddr;
603 acm->interfaceCnt = 1;
604 acm->interfaceIndex[0] = ifaceNum;
605
606 ret = UsbRawInit(&session);
607 if (ret) {
608 HDF_LOGE("%s: UsbRawInit faild", __func__);
609 return HDF_ERR_IO;
610 goto end;
611 }
612
613 ret = UsbSerialDeviceAlloc(acm);
614 if (ret != HDF_SUCCESS) {
615 HDF_LOGE("%s: UsbSerialDeviceAlloc faild", __func__);
616 ret = HDF_FAILURE;
617 goto end;
618 }
619
620 devHandle = UsbRawOpenDevice(session, acm->busNum, acm->devAddr);
621 if (devHandle == NULL) {
622 HDF_LOGE("%s: UsbRawOpenDevice faild", __func__);
623 ret = HDF_FAILURE;
624 goto end;
625 }
626 acm->devHandle = devHandle;
627 ret = UsbGetConfigDescriptor(devHandle, &acm->config);
628 if (ret) {
629 HDF_LOGE("%s: UsbGetConfigDescriptor faild", __func__);
630 ret = HDF_FAILURE;
631 goto end;
632 }
633 ret = UsbParseConfigDescriptor(acm, acm->config);
634 if (ret != HDF_SUCCESS) {
635 HDF_LOGE("%s: UsbParseConfigDescriptor faild", __func__);
636 ret = HDF_FAILURE;
637 goto end;
638 }
639 acm->dataSize = TEST_LENGTH;
640 acm->dataEp = (g_writeOrRead == TEST_WRITE)?acm->dataOutEp:acm->dataInEp;
641
642 ret = AcmDataBufAlloc(acm);
643 if (ret < 0) {
644 HDF_LOGE("%s: AcmDataBufAlloc faild", __func__);
645 ret = HDF_FAILURE;
646 goto end;
647 }
648 ret = UsbAllocDataRequests(acm);
649 if (ret < 0) {
650 HDF_LOGE("%s: UsbAllocDataRequests faild", __func__);
651 ret = HDF_FAILURE;
652 goto end;
653 }
654
655 ret = UsbStartIo(acm);
656 if (ret) {
657 HDF_LOGE("%s: UsbAllocReadRequests faild", __func__);
658 goto end;
659 }
660
661 signal(SIGINT, SignalHandler);
662 signal(SIGALRM, SignalHandler);
663 gettimeofday(&time, NULL);
664
665 printf("test SDK rawAPI [%s]\n", g_writeOrRead?"write":"read");
666 printf("Start: sec%ld usec%ld\n", time.tv_sec, time.tv_usec);
667
668 for (i = 0; i < TEST_CYCLE; i++) {
669 SerialBegin(acm);
670 g_send_count++;
671 }
672
673 while (!g_speedFlag) {
674 OsalMSleep(10);
675 }
676
677 (void)UsbStopIo(acm);
678 end:
679 if (ret != HDF_SUCCESS) {
680 printf("please check whether usb drv so is existing or not,like acm, ecm, if not, remove it and test again!\n");
681 }
682 return ret;
683 }
684