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 "adapter_if.h"
17 #include <dirent.h>
18 #include <endian.h>
19 #include <fcntl.h>
20 #include <poll.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/ioctl.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29
30 #include "usb_handle.h"
31
32 #define HDF_LOG_TAG adapter_if
33 #define SLEEP_TIME 100000
34 #define OPEN_CNT 30
35
36 static struct RawUsbRamTestList *g_usbRamTestHead = NULL;
37 static bool g_usbRamTestFlag = false;
38
UsbFnAdapterOpenFn(void)39 static int32_t UsbFnAdapterOpenFn(void)
40 {
41 int32_t i;
42 int32_t ep;
43 for (i = 0; i < OPEN_CNT; i++) {
44 ep = handle_open("/dev/fconfig");
45 if (ep > 0) {
46 break;
47 }
48 usleep(SLEEP_TIME);
49 }
50 if (ep < 0) {
51 HDF_LOGE("func not alloc!");
52 }
53 return ep;
54 }
55
UsbFnAdapterClosefn(int32_t fd)56 static int32_t UsbFnAdapterClosefn(int32_t fd)
57 {
58 if (fd < 0) {
59 return HDF_ERR_INVALID_PARAM;
60 }
61 return handle_close(fd);
62 }
63
UsbFnAdapterCreateFconfigString(struct FconfigString * const configString,const char * name)64 static int32_t UsbFnAdapterCreateFconfigString(struct FconfigString * const configString, const char *name)
65 {
66 if (configString == NULL || name == NULL) {
67 HDF_LOGE("%{public}s: configName is NULL", __func__);
68 return HDF_ERR_IO;
69 }
70
71 size_t strLen = strlen(name);
72 configString->len = (uint32_t)strLen;
73 configString->s = UsbFnMemCalloc(strLen + 1);
74 if (configString->s == NULL) {
75 HDF_LOGE("%{public}s: UsbFnMemCalloc failed!", __func__);
76 return HDF_ERR_MALLOC_FAIL;
77 }
78
79 int32_t ret = memcpy_s(configString->s, (strLen + 1), name, strLen);
80 if (ret != EOK) {
81 HDF_LOGE("%{public}s: memcpy_s failed!", __func__);
82 UsbFnMemFree(configString->s);
83 return HDF_ERR_MALLOC_FAIL;
84 }
85
86 *(configString->s + configString->len) = '\0';
87 return 0;
88 }
89
UsbFnAdapterWriteGadget(int32_t fd,int32_t cmd,struct FconfigString * gadgetName)90 static int32_t UsbFnAdapterWriteGadget(int32_t fd, int32_t cmd, struct FconfigString *gadgetName)
91 {
92 int32_t ret;
93
94 if (gadgetName == NULL) {
95 HDF_LOGE("%{public}s: udcName is NULL", __func__);
96 return HDF_ERR_IO;
97 }
98 ret = handle_ioctl(fd, cmd, gadgetName);
99 if (ret != 0) {
100 HDF_LOGE("%{public}s: ioctl failed!", __func__);
101 return HDF_ERR_IO;
102 }
103 return 0;
104 }
105
UsbFnAdapterWriteDevDesc(int32_t fd,struct FconfigString * const gadgetName,const struct UsbFnDeviceDesc * const descriptor)106 static int32_t UsbFnAdapterWriteDevDesc(
107 int32_t fd, struct FconfigString * const gadgetName, const struct UsbFnDeviceDesc * const descriptor)
108 {
109 struct FconfigDevDesc devDesc;
110
111 if (gadgetName == NULL || descriptor == NULL) {
112 HDF_LOGE("%{public}s: udcName is NULL", __func__);
113 return HDF_ERR_IO;
114 }
115
116 devDesc.gadgetName.len = gadgetName->len;
117 devDesc.gadgetName.s = gadgetName->s;
118 int32_t ret = memcpy_s(&devDesc.devDesc, sizeof(devDesc.devDesc), descriptor->deviceDesc, sizeof(devDesc.devDesc));
119 if (ret != EOK) {
120 HDF_LOGE("%{public}s: memcpy_s failed!", __func__);
121 return HDF_ERR_MALLOC_FAIL;
122 }
123
124 ret = handle_ioctl(fd, FCONFIG_CMD_WRITE_DEV_DESC, &devDesc);
125 if (ret != 0) {
126 HDF_LOGE("%{public}s: ioctl failed!", __func__);
127 return HDF_ERR_MALLOC_FAIL;
128 }
129
130 return 0;
131 }
132
UsbFnAdapterWriteDevString(int32_t fd,struct FconfigDevStrings * const devStrings,const struct UsbFnStrings * const usbFnString)133 static int32_t UsbFnAdapterWriteDevString(
134 int32_t fd, struct FconfigDevStrings * const devStrings, const struct UsbFnStrings * const usbFnString)
135 {
136 struct UsbString *usbString = NULL;
137 int32_t jCount;
138 int32_t ret;
139
140 devStrings->language = usbFnString->language;
141 devStrings->strCount = 0;
142 usbString = usbFnString->strings;
143 while (usbString->s) {
144 devStrings->strCount++;
145 usbString++;
146 }
147 devStrings->strings = UsbFnMemCalloc((devStrings->strCount + 1) * sizeof(struct FconfigUsbString));
148 if (devStrings->strings == NULL) {
149 HDF_LOGE("%{public}s: UsbFnMemCalloc failed!", __func__);
150 return HDF_ERR_MALLOC_FAIL;
151 }
152 devStrings->strings[devStrings->strCount].str.len = 0;
153 devStrings->strings[devStrings->strCount].str.s = NULL;
154 usbString = usbFnString->strings;
155 for (jCount = 0; jCount < (int)devStrings->strCount; jCount++) {
156 devStrings->strings[jCount].id = usbString[jCount].id;
157 ret = UsbFnAdapterCreateFconfigString(&devStrings->strings[jCount].str, usbString[jCount].s);
158 if (ret != HDF_SUCCESS) {
159 HDF_LOGE("%{public}s: create string failed!", __func__);
160 UsbFnMemFree(devStrings->strings[jCount].str.s);
161 goto FAIL;
162 }
163 }
164 ret = handle_ioctl(fd, FCONFIG_CMD_WRITE_STRINGS, devStrings);
165 if (ret != 0) {
166 HDF_LOGE("%{public}s: ioctl failed!", __func__);
167 goto FAIL;
168 }
169 for (jCount = 0; jCount < (int)devStrings->strCount; jCount++) {
170 UsbFnMemFree(devStrings->strings[jCount].str.s);
171 }
172 UsbFnMemFree(devStrings->strings);
173 return 0;
174 FAIL:
175 while ((--jCount) >= 0) {
176 UsbFnMemFree(devStrings->strings[jCount].str.s);
177 }
178 UsbFnMemFree(devStrings->strings);
179 return -1;
180 }
181
UsbFnAdapterWriteDevStrings(int32_t fd,struct FconfigString * const gadgetName,const struct UsbFnDeviceDesc * descriptor)182 static int32_t UsbFnAdapterWriteDevStrings(
183 int32_t fd, struct FconfigString * const gadgetName, const struct UsbFnDeviceDesc *descriptor)
184 {
185 if (gadgetName == NULL || descriptor == NULL) {
186 HDF_LOGE("%{public}s: udcName is NULL", __func__);
187 return HDF_ERR_IO;
188 }
189
190 struct FconfigDevStrings devStrings;
191 devStrings.gadgetName.len = gadgetName->len;
192 devStrings.gadgetName.s = gadgetName->s;
193 for (uint32_t iCount = 0; descriptor->deviceStrings[iCount]; iCount++) {
194 int32_t ret = UsbFnAdapterWriteDevString(fd, &devStrings, descriptor->deviceStrings[iCount]);
195 if (ret != 0) {
196 HDF_LOGE("%{public}s: UsbFnAdapterWriteDevString failed", __func__);
197 return HDF_ERR_IO;
198 }
199 }
200 return 0;
201 }
202
UsbFnAdapterFillConfigDesc(struct UsbConfigDescriptor * const cfgDesc,struct UsbFnConfiguration * const usbFnConfig)203 static int32_t UsbFnAdapterFillConfigDesc(
204 struct UsbConfigDescriptor * const cfgDesc, struct UsbFnConfiguration * const usbFnConfig)
205 {
206 if (cfgDesc == NULL || usbFnConfig == NULL) {
207 HDF_LOGE("%{public}s: name is NULL", __func__);
208 return HDF_ERR_IO;
209 }
210 cfgDesc->bConfigurationValue = usbFnConfig->configurationValue;
211 cfgDesc->bmAttributes = usbFnConfig->attributes;
212 cfgDesc->bMaxPower = usbFnConfig->maxPower;
213 cfgDesc->iConfiguration = usbFnConfig->iConfiguration;
214 return 0;
215 }
216
UsbFnAdapterOpenPipe(const char * funcName,int32_t epIndex)217 static int32_t UsbFnAdapterOpenPipe(const char *funcName, int32_t epIndex)
218 {
219 int32_t ret;
220 char epName[MAX_NAMELEN];
221 const char *pName = &epName[0];
222 int32_t i;
223 int32_t ep;
224 if (funcName == NULL || epIndex < 0) {
225 return HDF_ERR_INVALID_PARAM;
226 }
227
228 ret = snprintf_s(epName, MAX_NAMELEN, MAX_NAMELEN - 1, "/dev/%s/ep%d", funcName, epIndex);
229 if (ret < 0) {
230 HDF_LOGE("%{public}s: snprintf_s failed", __func__);
231 return HDF_ERR_IO;
232 }
233
234 for (i = 0; i < OPEN_CNT; i++) {
235 ep = handle_open(pName);
236 if (ep > 0) {
237 break;
238 }
239 usleep(SLEEP_TIME);
240 }
241 if (ep < 0) {
242 HDF_LOGE("unable to open %s", epName);
243 return HDF_ERR_IO;
244 }
245 return ep;
246 }
247
UsbFnAdapterClosePipe(int32_t ep)248 static int32_t UsbFnAdapterClosePipe(int32_t ep)
249 {
250 if (ep < 0) {
251 return HDF_ERR_INVALID_PARAM;
252 }
253
254 return handle_close(ep);
255 }
256
GetHeaderStr(struct UsbFnStrings ** const strings,struct UsbFunctionfsStringsHead * headerStr)257 static void GetHeaderStr(struct UsbFnStrings ** const strings, struct UsbFunctionfsStringsHead *headerStr)
258 {
259 uint32_t i, j;
260 uint32_t langCount = 0;
261 uint32_t strCount = 0;
262 uint32_t len = 0;
263 for (i = 0; strings[i] != NULL; i++) {
264 langCount++;
265 for (j = 0; strings[i]->strings[j].s; j++) {
266 len += strlen(strings[i]->strings[j].s) + sizeof(char);
267 }
268 strCount = j;
269 }
270 headerStr->magic = htole32(FUNCTIONFS_STRINGS_MAGIC);
271 headerStr->length = htole32(sizeof(struct UsbFunctionfsStringsHead) + langCount * sizeof(uint16_t) + len);
272 headerStr->strCount = strCount;
273 headerStr->langCount = langCount;
274 }
275
UsbFnWriteStrings(int32_t ep0,struct UsbFnStrings ** const strings)276 static int32_t UsbFnWriteStrings(int32_t ep0, struct UsbFnStrings ** const strings)
277 {
278 uint8_t *str = NULL;
279 uint8_t *whereDec = NULL;
280 uint32_t i, j;
281 int32_t ret;
282 struct UsbFunctionfsStringsHead headerStr = {0};
283
284 GetHeaderStr(strings, &headerStr);
285 str = UsbFnMemCalloc(headerStr.length);
286 if (str == NULL) {
287 return HDF_ERR_MALLOC_FAIL;
288 }
289
290 whereDec = str;
291 ret = memcpy_s(whereDec, headerStr.length, &headerStr, sizeof(struct UsbFunctionfsStringsHead));
292 if (ret != EOK) {
293 goto ERR;
294 }
295 whereDec += sizeof(struct UsbFunctionfsStringsHead);
296
297 for (i = 0; i < headerStr.langCount; i++) {
298 ret = memcpy_s(whereDec, headerStr.length - (whereDec - str), &strings[i]->language, sizeof(uint16_t));
299 if (ret != EOK) {
300 goto ERR;
301 }
302 whereDec += sizeof(uint16_t);
303 for (j = 0; j < headerStr.strCount; j++) {
304 if (strlen(strings[i]->strings[j].s)) {
305 ret = memcpy_s(whereDec, headerStr.length - (whereDec - str), strings[i]->strings[j].s,
306 strlen(strings[i]->strings[j].s));
307 whereDec += strlen(strings[i]->strings[j].s) + sizeof(char);
308 } else {
309 break;
310 }
311 if (ret != EOK) {
312 goto ERR;
313 }
314 }
315 }
316
317 if (handle_write(ep0, str, headerStr.length) < 0) {
318 goto ERR;
319 }
320 UsbFnMemFree(str);
321 return 0;
322 ERR:
323 UsbFnMemFree(str);
324 return HDF_FAILURE;
325 }
326
GetCountAndHead(struct UsbFunctionfsDescsHeadV2 * header,uint32_t * fsCount,uint32_t * hsCount,uint32_t * ssCount,const struct UsbFnFunction * func)327 static void GetCountAndHead(struct UsbFunctionfsDescsHeadV2 *header, uint32_t *fsCount, uint32_t *hsCount,
328 uint32_t *ssCount, const struct UsbFnFunction *func)
329 {
330 int32_t i;
331 uint32_t lenCount = 0;
332 uint32_t lenDes = 0;
333 *fsCount = 0;
334 *hsCount = 0;
335 *ssCount = 0;
336
337 for (i = 0; func->fsDescriptors[i] != NULL; i++) {
338 (*fsCount)++;
339 lenDes += func->fsDescriptors[i]->bLength;
340 }
341 for (i = 0; func->hsDescriptors[i] != NULL; i++) {
342 (*hsCount)++;
343 lenDes += func->hsDescriptors[i]->bLength;
344 }
345 for (i = 0; func->ssDescriptors[i] != NULL; i++) {
346 (*ssCount)++;
347 lenDes += func->ssDescriptors[i]->bLength;
348 }
349
350 if (*fsCount) {
351 lenCount += sizeof(uint32_t);
352 header->flags |= htole32(FUNCTIONFS_HAS_FS_DESC);
353 }
354 if (*hsCount) {
355 lenCount += sizeof(uint32_t);
356 header->flags |= htole32(FUNCTIONFS_HAS_HS_DESC);
357 }
358 if (*ssCount) {
359 lenCount += sizeof(uint32_t);
360 header->flags |= htole32(FUNCTIONFS_HAS_SS_DESC);
361 }
362
363 header->magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2);
364 header->length = htole32(sizeof(struct UsbFunctionfsDescsHeadV2) + lenCount + lenDes);
365 }
366
WriteFuncDescriptors(uint8_t ** const whereDec,struct UsbDescriptorHeader ** const headDes)367 static int32_t WriteFuncDescriptors(uint8_t ** const whereDec, struct UsbDescriptorHeader ** const headDes)
368 {
369 for (uint32_t i = 0; headDes[i] != NULL; i++) {
370 if (memcpy_s(*whereDec, headDes[i]->bLength, headDes[i], headDes[i]->bLength) != EOK) {
371 HDF_LOGE("%{public}s: memcpy_s failed!", __func__);
372 return HDF_FAILURE;
373 }
374 *whereDec += headDes[i]->bLength;
375 }
376 return 0;
377 }
378
CopyCount(uint8_t ** whereDec,uint32_t fsCount,uint32_t hsCount,uint32_t ssCount)379 static int32_t CopyCount(uint8_t **whereDec, uint32_t fsCount, uint32_t hsCount, uint32_t ssCount)
380 {
381 int32_t ret;
382 if (fsCount) {
383 ret = memcpy_s(*whereDec, sizeof(uint32_t), &fsCount, sizeof(uint32_t));
384 if (ret != EOK) {
385 return HDF_FAILURE;
386 }
387 *whereDec += sizeof(uint32_t);
388 }
389 if (hsCount) {
390 ret = memcpy_s(*whereDec, sizeof(uint32_t), &hsCount, sizeof(uint32_t));
391 if (ret != EOK) {
392 return HDF_FAILURE;
393 }
394 *whereDec += sizeof(uint32_t);
395 }
396 if (ssCount) {
397 ret = memcpy_s(*whereDec, sizeof(uint32_t), &ssCount, sizeof(uint32_t));
398 if (ret != EOK) {
399 return HDF_FAILURE;
400 }
401 *whereDec += sizeof(uint32_t);
402 }
403
404 return 0;
405 }
406
UsbFnAdapterCreatPipes(int32_t ep0,const struct UsbFnFunction * func)407 static int32_t UsbFnAdapterCreatPipes(int32_t ep0, const struct UsbFnFunction *func)
408 {
409 uint8_t *dec = NULL;
410 uint8_t *whereDec = NULL;
411 int32_t ret;
412 uint32_t fsCount;
413 uint32_t hsCount;
414 uint32_t ssCount;
415 struct UsbFunctionfsDescsHeadV2 header = {0};
416
417 GetCountAndHead(&header, &fsCount, &hsCount, &ssCount, func);
418
419 dec = UsbFnMemCalloc(header.length);
420 if (dec == NULL) {
421 HDF_LOGE("%{public}s: UsbFnMemCalloc failed!", __func__);
422 return HDF_ERR_MALLOC_FAIL;
423 }
424 whereDec = dec;
425
426 ret = memcpy_s(whereDec, header.length, &header, sizeof(struct UsbFunctionfsDescsHeadV2));
427 if (ret != EOK) {
428 return HDF_FAILURE;
429 }
430 whereDec += sizeof(struct UsbFunctionfsDescsHeadV2);
431
432 ret = CopyCount(&whereDec, fsCount, hsCount, ssCount);
433 if (ret != EOK) {
434 return HDF_FAILURE;
435 }
436
437 ret = WriteFuncDescriptors(&whereDec, func->fsDescriptors);
438 if (ret != EOK) {
439 return HDF_FAILURE;
440 }
441
442 ret = WriteFuncDescriptors(&whereDec, func->hsDescriptors);
443 if (ret != EOK) {
444 return HDF_FAILURE;
445 }
446
447 ret = WriteFuncDescriptors(&whereDec, func->ssDescriptors);
448 if (ret != EOK) {
449 return HDF_FAILURE;
450 }
451
452 if (handle_write(ep0, dec, header.length) < 0) {
453 HDF_LOGE("unable do write descriptors");
454 UsbFnMemFree(dec);
455 return HDF_ERR_IO;
456 }
457
458 UsbFnMemFree(dec);
459 ret = UsbFnWriteStrings(ep0, func->strings);
460 return ret;
461 }
462
UsbFnAdapterWriteFunctions(int32_t fd,struct UsbFnConfiguration * const usbFnConfig,int32_t cmd,struct FconfigString * const gadgetName,struct FconfigString * const configName)463 static int32_t UsbFnAdapterWriteFunctions(int32_t fd, struct UsbFnConfiguration * const usbFnConfig, int32_t cmd,
464 struct FconfigString * const gadgetName, struct FconfigString * const configName)
465 {
466 if (usbFnConfig == NULL || gadgetName == NULL || configName == NULL) {
467 HDF_LOGE("%{public}s: usbFnConfig is NULL", __func__);
468 return HDF_ERR_IO;
469 }
470
471 int32_t fdEp0;
472 struct FconfigFuncInfo funcInfo;
473 funcInfo.gadgetName.len = gadgetName->len;
474 funcInfo.gadgetName.s = gadgetName->s;
475 funcInfo.configName.len = configName->len;
476 funcInfo.configName.s = configName->s;
477 for (uint32_t iCount = 0; usbFnConfig->functions[iCount] != NULL; iCount++) {
478 char tmp[MAX_PATHLEN];
479 if (memset_s(tmp, MAX_PATHLEN, 0, MAX_PATHLEN) != EOK) {
480 HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__);
481 return HDF_FAILURE;
482 }
483 int32_t ret =
484 snprintf_s(tmp, MAX_PATHLEN, MAX_PATHLEN - 1, "generic.%s", usbFnConfig->functions[iCount]->funcName);
485 if (ret < 0) {
486 return HDF_ERR_IO;
487 }
488 ret = UsbFnAdapterCreateFconfigString(&funcInfo.funcName, tmp);
489 if (ret != HDF_SUCCESS) {
490 return HDF_ERR_MALLOC_FAIL;
491 }
492 if (handle_ioctl(fd, cmd, &funcInfo) != 0) {
493 goto FAIL;
494 }
495 UsbFnMemFree(funcInfo.funcName.s);
496 if (cmd == FCONFIG_CMD_DROP_FUNCTION) {
497 continue;
498 }
499
500 fdEp0 = UsbFnAdapterOpenPipe(usbFnConfig->functions[iCount]->funcName, 0);
501 if (fd < 0) {
502 goto FAIL;
503 }
504
505 if (UsbFnAdapterCreatPipes(fdEp0, usbFnConfig->functions[iCount]) != HDF_SUCCESS) {
506 goto FAIL2;
507 }
508
509 if (UsbFnAdapterClosePipe(fdEp0) != HDF_SUCCESS) {
510 goto FAIL2;
511 }
512 }
513 return 0;
514 FAIL2:
515 UsbFnAdapterClosePipe(fdEp0);
516 FAIL:
517 UsbFnMemFree(funcInfo.funcName.s);
518 return -1;
519 }
520
UsbFnAdapterWriteConfigs(int32_t fd,struct FconfigString * const gadgetName,const struct UsbFnDeviceDesc * const descriptor)521 static int32_t UsbFnAdapterWriteConfigs(
522 int32_t fd, struct FconfigString * const gadgetName, const struct UsbFnDeviceDesc * const descriptor)
523 {
524 struct FconfigCfgDesc configDesc;
525 char tmp[MAX_PATHLEN];
526
527 if (gadgetName == NULL || descriptor == NULL || descriptor->configs == NULL) {
528 HDF_LOGE("%{public}s: name is NULL", __func__);
529 return HDF_ERR_IO;
530 }
531 for (uint32_t iCount = 0; descriptor->configs[iCount]; iCount++) {
532 configDesc.gadgetName.len = gadgetName->len;
533 configDesc.gadgetName.s = gadgetName->s;
534 uint8_t confVal = descriptor->configs[iCount]->configurationValue;
535 if (memset_s(tmp, MAX_PATHLEN, 0, MAX_PATHLEN) != EOK) {
536 HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__);
537 return HDF_FAILURE;
538 }
539 int32_t ret = snprintf_s(tmp, MAX_PATHLEN, MAX_PATHLEN - 1, "b.%u", confVal);
540 if (ret < 0) {
541 return HDF_ERR_IO;
542 }
543 ret = UsbFnAdapterCreateFconfigString(&configDesc.configName, tmp);
544 if (ret != HDF_SUCCESS) {
545 HDF_LOGE("%{public}s: create config name failed!", __func__);
546 return HDF_ERR_MALLOC_FAIL;
547 }
548 ret = UsbFnAdapterFillConfigDesc(&configDesc.cfgDesc, descriptor->configs[iCount]);
549 if (ret != HDF_SUCCESS) {
550 HDF_LOGE("%{public}s: UsbFnMemCalloc failed!", __func__);
551 return HDF_ERR_MALLOC_FAIL;
552 }
553 ret = handle_ioctl(fd, FCONFIG_CMD_ADD_CONFIG, &configDesc);
554 if (ret != HDF_SUCCESS) {
555 HDF_LOGE("%{public}s: ioctl failed!", __func__);
556 return HDF_ERR_MALLOC_FAIL;
557 }
558 ret = UsbFnAdapterWriteFunctions(
559 fd, descriptor->configs[iCount], FCONFIG_CMD_MAKE_FUNCTION, gadgetName, &configDesc.configName);
560 if (ret != HDF_SUCCESS) {
561 HDF_LOGE("%{public}s: write func failed!", __func__);
562 return HDF_ERR_MALLOC_FAIL;
563 }
564 UsbFnMemFree(configDesc.configName.s);
565 }
566 return 0;
567 }
568
UsbFnAdapterWriteFcofnigUDC(int32_t fd,int32_t cmd,struct FconfigString * const gadgetName,const char * udcName)569 static int32_t UsbFnAdapterWriteFcofnigUDC(
570 int32_t fd, int32_t cmd, struct FconfigString * const gadgetName, const char *udcName)
571 {
572 int32_t ret;
573 struct FconfigUdcInfo udcInfo;
574
575 if (gadgetName == NULL || udcName == NULL) {
576 return HDF_ERR_INVALID_PARAM;
577 }
578 udcInfo.gadgetName.len = gadgetName->len;
579 udcInfo.gadgetName.s = gadgetName->s;
580 ret = UsbFnAdapterCreateFconfigString(&udcInfo.udcName, udcName);
581 if (ret != HDF_SUCCESS) {
582 HDF_LOGE("%{public}s: create udc_name failed!", __func__);
583 return HDF_ERR_IO;
584 }
585 ret = handle_ioctl(fd, cmd, &udcInfo);
586 if (ret != 0) {
587 HDF_LOGE("%{public}s: ioctl failed!", __func__);
588 }
589 UsbFnMemFree(udcInfo.udcName.s);
590
591 return ret;
592 }
593
UsbFnAdapterCreateDevice(const char * udcName,const char * devName,struct UsbFnDeviceDesc * descriptor)594 static int32_t UsbFnAdapterCreateDevice(const char *udcName, const char *devName, struct UsbFnDeviceDesc *descriptor)
595 {
596 int32_t fd;
597 int32_t ret;
598 struct FconfigString gadgetName;
599
600 fd = UsbFnAdapterOpenFn();
601 if (fd < 0) {
602 return HDF_ERR_IO;
603 }
604 ret = UsbFnAdapterCreateFconfigString(&gadgetName, devName);
605 if (ret != HDF_SUCCESS) {
606 HDF_LOGE("%{public}s: create gadget name failed!", __func__);
607 goto FAIL;
608 }
609 ret = UsbFnAdapterWriteGadget(fd, FCONFIG_CMD_MAKE_GADGET, &gadgetName);
610 if (ret != HDF_SUCCESS) {
611 dprintf("%s: UsbFnAdapterWriteGadget failed!", __func__);
612 goto EXIT;
613 }
614 ret = UsbFnAdapterWriteDevDesc(fd, &gadgetName, descriptor);
615 if (ret != HDF_SUCCESS) {
616 dprintf("%s: UsbFnAdapterWriteDevDesc failed!", __func__);
617 goto EXIT;
618 }
619 ret = UsbFnAdapterWriteDevStrings(fd, &gadgetName, descriptor);
620 if (ret != HDF_SUCCESS) {
621 dprintf("%s: UsbFnAdapterWriteDevStrings failed!", __func__);
622 goto EXIT;
623 }
624 ret = UsbFnAdapterWriteConfigs(fd, &gadgetName, descriptor);
625 if (ret != HDF_SUCCESS) {
626 dprintf("%s: UsbFnAdapterWriteConfigs failed!", __func__);
627 goto EXIT;
628 }
629 ret = UsbFnAdapterWriteFcofnigUDC(fd, FCONFIG_CMD_ENABLE_UDC, &gadgetName, udcName);
630 if (ret != HDF_SUCCESS) {
631 dprintf("%s: UsbFnAdapterWriteFcofnigUDC failed!", __func__);
632 goto EXIT;
633 }
634 dprintf("%s: create device success!\n", __func__);
635 EXIT:
636 UsbFnMemFree(gadgetName.s);
637 FAIL:
638 if (UsbFnAdapterClosefn(fd) != 0) {
639 dprintf("%s[%d] close fconfig failed\n", __func__, __LINE__);
640 }
641
642 return ret;
643 }
644
UsbFnAdapterDelConfigs(int32_t configFd,struct FconfigString * const gadgetName,struct UsbFnDeviceDesc * const descriptor)645 static int32_t UsbFnAdapterDelConfigs(
646 int32_t configFd, struct FconfigString * const gadgetName, struct UsbFnDeviceDesc * const descriptor)
647 {
648 struct FconfigCfgDesc configDesc;
649 struct FconfigString configName;
650 char tmp[MAX_PATHLEN];
651 int32_t ret;
652 int32_t iCount;
653 uint8_t confVal;
654
655 if (gadgetName == NULL || descriptor == NULL) {
656 HDF_LOGE("%{public}s: name is NULL", __func__);
657 return HDF_ERR_INVALID_PARAM;
658 }
659 for (iCount = 0; descriptor->configs[iCount]; iCount++) {
660 configDesc.gadgetName.len = gadgetName->len;
661 configDesc.gadgetName.s = gadgetName->s;
662 confVal = descriptor->configs[iCount]->configurationValue;
663 ret = snprintf_s(tmp, MAX_PATHLEN, MAX_PATHLEN - 1, "b.%u", confVal);
664 if (ret < 0) {
665 HDF_LOGE("%{public}s: snprintf_s failed", __func__);
666 return HDF_ERR_IO;
667 }
668 ret = UsbFnAdapterCreateFconfigString(&configName, tmp);
669 if (ret != HDF_SUCCESS) {
670 HDF_LOGE("%{public}s: create config name failed!", __func__);
671 return HDF_ERR_MALLOC_FAIL;
672 }
673 configDesc.configName.len = configName.len;
674 configDesc.configName.s = configName.s;
675 ret = UsbFnAdapterWriteFunctions(
676 configFd, descriptor->configs[iCount], FCONFIG_CMD_DROP_FUNCTION, gadgetName, &configName);
677 if (ret != HDF_SUCCESS) {
678 HDF_LOGE("%{public}s: write func failed!", __func__);
679 goto FAIL;
680 }
681 ret = UsbFnAdapterFillConfigDesc(&configDesc.cfgDesc, descriptor->configs[iCount]);
682 if (ret != HDF_SUCCESS) {
683 HDF_LOGE("%{public}s: UsbFnMemCalloc failed!", __func__);
684 goto FAIL;
685 }
686 ret = handle_ioctl(configFd, FCONFIG_CMD_REMOVE_CONFIG, &configDesc);
687 if (ret != HDF_SUCCESS) {
688 HDF_LOGE("%{public}s: ioctl failed!", __func__);
689 goto FAIL;
690 }
691 UsbFnMemFree(configName.s);
692 }
693 return 0;
694 FAIL:
695 UsbFnMemFree(configName.s);
696 return -1;
697 }
698
UsbFnAdapterDelDevice(const char * devName,const char * udcName,struct UsbFnDeviceDesc * descriptor)699 static int32_t UsbFnAdapterDelDevice(const char *devName, const char *udcName, struct UsbFnDeviceDesc *descriptor)
700 {
701 int32_t configFd;
702 int32_t ret;
703 struct FconfigString gadgetName;
704
705 if (devName == NULL || udcName == NULL || descriptor == NULL) {
706 return HDF_ERR_INVALID_PARAM;
707 }
708 configFd = UsbFnAdapterOpenFn();
709 if (configFd <= 0) {
710 return HDF_ERR_IO;
711 }
712 ret = UsbFnAdapterCreateFconfigString(&gadgetName, devName);
713 if (ret != HDF_SUCCESS) {
714 HDF_LOGE("%{public}s: create gadget_name failed!", __func__);
715 return HDF_ERR_IO;
716 }
717 ret = UsbFnAdapterWriteFcofnigUDC(configFd, FCONFIG_CMD_DISABLE_UDC, &gadgetName, udcName);
718 if (ret != HDF_SUCCESS) {
719 goto FAIL;
720 }
721 ret = UsbFnAdapterDelConfigs(configFd, &gadgetName, descriptor);
722 if (ret != HDF_SUCCESS) {
723 goto FAIL;
724 }
725 ret = UsbFnAdapterWriteGadget(configFd, FCONFIG_CMD_DROP_GADGET, &gadgetName);
726 if (ret != HDF_SUCCESS) {
727 goto FAIL;
728 }
729 ret = UsbFnAdapterClosefn(configFd);
730
731 FAIL:
732 UsbFnMemFree(gadgetName.s);
733 return ret;
734 }
735
UsbFnAdapterGetPipeInfo(int32_t ep,struct UsbFnPipeInfo * const pipeInfo)736 static int32_t UsbFnAdapterGetPipeInfo(int32_t ep, struct UsbFnPipeInfo * const pipeInfo)
737 {
738 if (ep <= 0 || pipeInfo == NULL) {
739 return HDF_ERR_INVALID_PARAM;
740 }
741
742 struct usb_endpoint_descriptor desc;
743 if (memset_s(&desc, sizeof(desc), 0, sizeof(desc)) != EOK) {
744 HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__);
745 return HDF_FAILURE;
746 }
747
748 int32_t ret = handle_ioctl(ep, GENERIC_CMD_GET_PIPE_INFO, &desc);
749 if (ret != HDF_SUCCESS) {
750 HDF_LOGE("%{public}s: FUNCTIONFS_ENDPOINT_DESC failed!", __func__);
751 return HDF_ERR_IO;
752 }
753
754 pipeInfo->type = desc.bmAttributes;
755 pipeInfo->dir = USB_PIPE_DIRECTION_OUT;
756 if (desc.bEndpointAddress & 0x80) {
757 pipeInfo->dir = USB_PIPE_DIRECTION_IN;
758 }
759
760 pipeInfo->maxPacketSize = (desc.wMaxPacketSize[0] | (desc.wMaxPacketSize[1] << 8));
761 pipeInfo->interval = desc.bInterval;
762
763 return 0;
764 }
765
UsbFnAdapterQueueInit(int32_t ep)766 static int32_t UsbFnAdapterQueueInit(int32_t ep)
767 {
768 (void)ep;
769 return 0;
770 }
771
UsbFnAdapterQueueDel(int32_t ep)772 static int32_t UsbFnAdapterQueueDel(int32_t ep)
773 {
774 (void)ep;
775 return 0;
776 }
777
UsbFnAdapterReleaseBuf(int32_t ep,const struct GenericMemory * mem)778 static int32_t UsbFnAdapterReleaseBuf(int32_t ep, const struct GenericMemory *mem)
779 {
780 return handle_ioctl(ep, GENERIC_CMD_FREE_MEM, &mem);
781 }
782
UsbFnAdapterPipeIo(int32_t ep,struct IoData * const ioData)783 static int32_t UsbFnAdapterPipeIo(int32_t ep, struct IoData * const ioData)
784 {
785 int32_t ret;
786 if (ep <= 0 || ioData == NULL) {
787 return HDF_ERR_INVALID_PARAM;
788 }
789 if (ioData->aio) {
790 ret = handle_write(ep, (void *)ioData->buf, ioData->len);
791 } else {
792 ret = handle_ioctl(ep, GENERIC_CMD_ENDPOINT_IO, ioData);
793 }
794 return ret;
795 }
796
UsbFnAdapterCancelIo(int32_t ep,const struct IoData * const ioData)797 static int32_t UsbFnAdapterCancelIo(int32_t ep, const struct IoData * const ioData)
798 {
799 struct GenericMemory mem;
800
801 mem.buf = ioData->buf;
802 mem.size = ioData->len;
803
804 return handle_ioctl(ep, GENERIC_CMD_CANCEL_REQUEST, &mem);
805 }
806
UsbFnAdapterRequestGetStatus(int32_t ep,const struct IoData * ioData)807 static int32_t UsbFnAdapterRequestGetStatus(int32_t ep, const struct IoData *ioData)
808 {
809 if (ep <= 0 || ioData == NULL) {
810 return HDF_ERR_INVALID_PARAM;
811 }
812 return handle_ioctl(ep, GENERIC_CMD_GET_REQ_STATUS, (void *)ioData);
813 }
814
UsbFnAdapterMapAddr(int32_t ep,uint32_t len)815 static uint8_t *UsbFnAdapterMapAddr(int32_t ep, uint32_t len)
816 {
817 return handle_mmap(ep, len);
818 }
819
UsbFnAdapterUnmapAddr(uint8_t * mapAddr,uint32_t len)820 static int32_t UsbFnAdapterUnmapAddr(uint8_t *mapAddr, uint32_t len)
821 {
822 (void)mapAddr;
823 (void)len;
824 return 0;
825 }
826
Ep0Event(struct UsbFnEventAll * const event,struct FconfigPollFd * const pfds)827 static int32_t Ep0Event(struct UsbFnEventAll * const event, struct FconfigPollFd * const pfds)
828 {
829 int32_t ret;
830 uint8_t i;
831 for (i = 0; i < event->ep0Num; i++) {
832 if (pfds[i].revents & POLLIN) {
833 ret = handle_read(event->ep0[i], &event->ep0Event[i].ctrlEvent, sizeof(struct UsbFnCtrlEvent));
834 if (ret < 0) {
835 HDF_LOGE("unable to read event from ep0");
836 return ret;
837 }
838 event->ep0Event[i].type = USB_EP0_CTRL_EVENT;
839 } else if (pfds[i].revents & POLLOUT) {
840 ret = handle_ioctl(event->ep0[i], GENERIC_CMD_GET_EP0_EVENT, &event->ep0Event[i].reqEvent);
841 if (ret < 0) {
842 HDF_LOGE("unable to read reqEvent from ep0");
843 return ret;
844 }
845 event->ep0Event[i].type = USB_EP0_IO_COMPLETED;
846 }
847 }
848 return 0;
849 }
850
EpEvent(struct UsbFnEventAll * const event,struct FconfigPollFd * const pfds)851 static int32_t EpEvent(struct UsbFnEventAll * const event, struct FconfigPollFd * const pfds)
852 {
853 uint8_t i;
854 int32_t ret;
855 for (i = 0; i < event->epNum; i++) {
856 if ((pfds[i + event->ep0Num].revents & POLLIN)) {
857 ret = handle_read(event->epx[i], event->reqEvent[i], MAX_REQUEST * sizeof(struct UsbFnReqEvent));
858 if (ret < 0) {
859 HDF_LOGE("unable to read event from eps");
860 return ret;
861 }
862 event->numEvent[i] = (uint8_t)(ret / sizeof(struct UsbFnReqEvent));
863 }
864 }
865 return 0;
866 }
867
UsbFnAdapterPollEvent(struct UsbFnEventAll * event,int32_t timeout)868 static int32_t UsbFnAdapterPollEvent(struct UsbFnEventAll *event, int32_t timeout)
869 {
870 uint8_t i;
871 struct FconfigPollFd pfds[16] = {0};
872 struct FconfigPollFd *pfd = &pfds[0];
873 if (event == NULL) {
874 return HDF_ERR_INVALID_PARAM;
875 }
876 if ((event->ep0Num + event->epNum) == 0) {
877 return HDF_ERR_INVALID_PARAM;
878 }
879
880 if (memset_s(&pfds, sizeof(pfds), 0, sizeof(pfds)) != EOK) {
881 HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__);
882 return HDF_FAILURE;
883 }
884
885 for (i = 0; i < event->ep0Num; i++) {
886 if (event->ep0[i] <= 0) {
887 HDF_LOGE("%{public}s: ep[%d] = %d", __func__, i, event->ep0[i]);
888 return HDF_ERR_INVALID_PARAM;
889 }
890 pfds[i].fd = event->ep0[i];
891 pfds[i].events = POLLIN | POLLOUT;
892 }
893 for (i = 0; i < event->epNum; i++) {
894 if (event->epx[i] <= 0) {
895 HDF_LOGE("%{public}s: ep[%d] = %d", __func__, i, event->epx[i]);
896 return HDF_ERR_INVALID_PARAM;
897 }
898 pfds[i + event->ep0Num].fd = event->epx[i];
899 pfds[i + event->ep0Num].events = POLLIN;
900 }
901 for (i = 0; i < (event->ep0Num + event->epNum); i++) {
902 pfds[i].revents = (uint32_t)handle_poll(pfds[i].fd, timeout);
903 if (pfds[i].revents < 0) {
904 HDF_LOGE("%{public}s: handle_poll failed", __func__);
905 return HDF_ERR_INVALID_PARAM;
906 }
907 }
908 if (Ep0Event(event, pfd) < 0) {
909 HDF_LOGE("%{public}s: handle_poll failed", __func__);
910 return HDF_ERR_IO;
911 }
912 if (EpEvent(event, pfd) < 0) {
913 HDF_LOGE("%{public}s: handle_poll failed", __func__);
914 return HDF_ERR_IO;
915 }
916 return 0;
917 }
918
UsbFnAdapterWriteUDC(const char * deviceName,const char * udcName,int32_t enable)919 static int32_t UsbFnAdapterWriteUDC(const char *deviceName, const char *udcName, int32_t enable)
920 {
921 struct FconfigUdcInfo udcInfo;
922
923 int32_t configFd = UsbFnAdapterOpenFn();
924 if (configFd <= 0) {
925 return HDF_ERR_IO;
926 }
927
928 int32_t ret = UsbFnAdapterCreateFconfigString(&udcInfo.gadgetName, deviceName);
929 if (ret != HDF_SUCCESS) {
930 HDF_LOGE("%{public}s: create gadget_name failed!", __func__);
931 return HDF_ERR_IO;
932 }
933
934 int32_t cmd = enable ? FCONFIG_CMD_ENABLE_UDC : FCONFIG_CMD_DISABLE_UDC;
935 ret = UsbFnAdapterWriteFcofnigUDC(configFd, cmd, &udcInfo.gadgetName, udcName);
936 if (ret != HDF_SUCCESS) {
937 return HDF_ERR_IO;
938 }
939
940 ret = UsbFnAdapterClosefn(configFd);
941 if (ret != 0) {
942 HDF_LOGE("%{public}s: close failed!", __func__);
943 }
944 return 0;
945 }
946
UsbFnWriteProp(const char * deviceName,const char * propName,uint32_t propValue)947 static int32_t UsbFnWriteProp(const char *deviceName, const char *propName, uint32_t propValue)
948 {
949 struct FconfigDevdescInfo info;
950 if (deviceName == NULL || propName == NULL) {
951 HDF_LOGE("%{public}s: param invail!", __func__);
952 return HDF_ERR_IO;
953 }
954 int32_t ret = UsbFnAdapterCreateFconfigString(&info.gadgetName, deviceName);
955 if (ret != HDF_SUCCESS) {
956 HDF_LOGE("%{public}s: create gadget name failed!", __func__);
957 return HDF_ERR_IO;
958 }
959 info.prop.propName = propName;
960 info.prop.propValue = (uint32_t)propValue;
961 int32_t configFd = UsbFnAdapterOpenFn();
962 if (configFd <= 0) {
963 ret = HDF_ERR_IO;
964 goto FAIL;
965 }
966 ret = handle_ioctl(configFd, FCONFIG_CMD_CHAGE_DEVINFO, &info);
967 if (ret != 0) {
968 HDF_LOGE("%{public}s: ioctl failed!", __func__);
969 goto FAIL;
970 }
971 ret = UsbFnAdapterClosefn(configFd);
972 if (ret != 0) {
973 HDF_LOGE("%{public}s: close failed!", __func__);
974 }
975 FAIL:
976 UsbFnMemFree(info.gadgetName.s);
977
978 return ret;
979 }
980
UsbFnWriteDesString(const char * deviceName,uint16_t lang,const char * stringName,const char * stringValue)981 static int32_t UsbFnWriteDesString(
982 const char *deviceName, uint16_t lang, const char *stringName, const char *stringValue)
983 {
984 struct FconfigDevDescString info;
985 if (deviceName == NULL || stringName == NULL || stringValue == NULL) {
986 HDF_LOGE("%{public}s: param invail!", __func__);
987 return HDF_ERR_IO;
988 }
989 int32_t ret = UsbFnAdapterCreateFconfigString(&info.gadgetName, deviceName);
990 if (ret != HDF_SUCCESS) {
991 HDF_LOGE("%{public}s: create gadget name failed!", __func__);
992 return HDF_ERR_IO;
993 }
994 info.prop.lang = lang;
995 info.prop.propName = stringName;
996 info.prop.propValue = stringValue;
997 int32_t configFd = UsbFnAdapterOpenFn();
998 if (configFd <= 0) {
999 dprintf("%s, %d\n", __func__, __LINE__);
1000 ret = HDF_ERR_IO;
1001 goto FAIL;
1002 }
1003 ret = handle_ioctl(configFd, FCONFIG_CMD_CHAGE_DEVSTRING, &info);
1004 if (ret != 0) {
1005 HDF_LOGE("%{public}s: ioctl failed!", __func__);
1006 goto FAIL;
1007 }
1008 ret = UsbFnAdapterClosefn(configFd);
1009 if (ret != 0) {
1010 HDF_LOGE("%{public}s: close failed!", __func__);
1011 }
1012 FAIL:
1013 UsbFnMemFree(info.gadgetName.s);
1014
1015 return ret;
1016 }
1017
UsbFnMemAlloc(size_t size)1018 static void *UsbFnMemAlloc(size_t size)
1019 {
1020 return UsbFnMemCalloc(size);
1021 }
1022
UsbFnMemCalloc(size_t size)1023 static void *UsbFnMemCalloc(size_t size)
1024 {
1025 void *buf = OsalMemCalloc(size);
1026 if (buf == NULL) {
1027 HDF_LOGE("%{public}s: %{public}d, OsalMemCalloc failed", __func__, __LINE__);
1028 return NULL;
1029 }
1030
1031 if (g_usbRamTestFlag) {
1032 if (g_usbRamTestHead == NULL) {
1033 g_usbRamTestHead = OsalMemCalloc(sizeof(struct RawUsbRamTestList));
1034 if (g_usbRamTestHead == NULL) {
1035 HDF_LOGE("%{public}s: %{public}d, OsalMemCalloc failed", __func__, __LINE__);
1036 OsalMemFree(buf);
1037 return NULL;
1038 }
1039 OsalMutexInit(&g_usbRamTestHead->lock);
1040 DListHeadInit(&g_usbRamTestHead->list);
1041 }
1042 struct RawUsbRamTestList *testEntry = OsalMemCalloc(sizeof(struct RawUsbRamTestList));
1043 if (testEntry == NULL) {
1044 HDF_LOGE("%{public}s: %{public}d, OsalMemCalloc failed", __func__, __LINE__);
1045 OsalMemFree(buf);
1046 return NULL;
1047 }
1048 testEntry->address = (uintptr_t)buf;
1049 testEntry->size = size;
1050
1051 struct RawUsbRamTestList *pos = NULL;
1052 uint32_t totalSize = 0;
1053 OsalMutexLock(&g_usbRamTestHead->lock);
1054 DListInsertTail(&testEntry->list, &g_usbRamTestHead->list);
1055 DLIST_FOR_EACH_ENTRY(pos, &g_usbRamTestHead->list, struct RawUsbRamTestList, list) {
1056 totalSize += pos->size;
1057 }
1058 OsalMutexUnlock(&g_usbRamTestHead->lock);
1059
1060 HDF_LOGI("%{public}s add size=%{public}d totalSize=%{public}d", __func__, (uint32_t)size, totalSize);
1061 }
1062 return buf;
1063 }
1064
UsbFnMemFree(const void * mem)1065 void UsbFnMemFree(const void *mem)
1066 {
1067 if (mem == NULL) {
1068 HDF_LOGE("%{public}s:%{public}d invalid param mem.", __func__, __LINE__);
1069 return;
1070 }
1071
1072 if (g_usbRamTestFlag && (g_usbRamTestHead != NULL)) {
1073 struct RawUsbRamTestList *pos = NULL;
1074 struct RawUsbRamTestList *tmp = NULL;
1075 uint32_t totalSize = 0;
1076 uint32_t size = 0;
1077 OsalMutexLock(&g_usbRamTestHead->lock);
1078 DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &g_usbRamTestHead->list, struct RawUsbRamTestList, list) {
1079 if (pos->address == (uintptr_t)mem) {
1080 size = pos->size;
1081 DListRemove(&pos->list);
1082 OsalMemFree(pos);
1083 continue;
1084 }
1085 totalSize += pos->size;
1086 }
1087 OsalMutexUnlock(&g_usbRamTestHead->lock);
1088 HDF_LOGE("%{public}s:rm size = %{public}u, totalSize = %{public}u", __func__, size, totalSize);
1089 }
1090
1091 if (mem != NULL) {
1092 OsalMemFree((void *)mem);
1093 }
1094 }
1095
UsbFnAdpMemTestTrigger(bool enable)1096 int32_t UsbFnAdpMemTestTrigger(bool enable)
1097 {
1098 g_usbRamTestFlag = enable;
1099 return HDF_SUCCESS;
1100 }
1101
1102 static struct UsbFnAdapterOps g_usbFnAdapter = {
1103 .createDevice = UsbFnAdapterCreateDevice,
1104 .delDevice = UsbFnAdapterDelDevice,
1105
1106 .openPipe = UsbFnAdapterOpenPipe,
1107 .closePipe = UsbFnAdapterClosePipe,
1108 .getPipeInfo = UsbFnAdapterGetPipeInfo,
1109
1110 .queueInit = UsbFnAdapterQueueInit,
1111 .queueDel = UsbFnAdapterQueueDel,
1112 .releaseBuf = UsbFnAdapterReleaseBuf,
1113 .pipeIo = UsbFnAdapterPipeIo,
1114 .cancelIo = UsbFnAdapterCancelIo,
1115 .getReqStatus = UsbFnAdapterRequestGetStatus,
1116 .mapAddr = UsbFnAdapterMapAddr,
1117 .unmapAddr = UsbFnAdapterUnmapAddr,
1118 .pollEvent = UsbFnAdapterPollEvent,
1119 .writeUDC = UsbFnAdapterWriteUDC,
1120 .writeProp = UsbFnWriteProp,
1121 .writeDesString = UsbFnWriteDesString,
1122 };
1123
UsbFnAdapterGetOps(void)1124 struct UsbFnAdapterOps *UsbFnAdapterGetOps(void)
1125 {
1126 return &g_usbFnAdapter;
1127 }
1128