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