• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# usb_ddk_api.h
2<!--Kit: Driver Development Kit-->
3<!--Subsystem: Driver-->
4<!--Owner: @lixinsheng2-->
5<!--Designer: @w00373942-->
6<!--Tester: @dong-dongzhen-->
7<!--Adviser: @w_Machine_cc-->
8
9## Overview
10
11Declares the USB DDK APIs used by the USB host to access USB devices.
12
13**File to include**: <usb/usb_ddk_api.h>
14
15**Library**: libusb_ndk.z.so
16
17**System capability**: SystemCapability.Driver.USB.Extension
18
19**Since**: 10
20
21**Related module**: [UsbDDK](capi-usbddk.md)
22
23## Summary
24
25### Functions
26
27| Name| Description|
28| -- | -- |
29| [int32_t OH_Usb_Init(void)](#oh_usb_init) | Initializes the DDK.|
30| [void OH_Usb_Release(void)](#oh_usb_release) | Releases the USB DDK.|
31| [int32_t OH_Usb_ReleaseResource(void)](#oh_usb_releaseresource) | Releases the USB DDK.|
32| [int32_t OH_Usb_GetDeviceDescriptor(uint64_t deviceId, struct UsbDeviceDescriptor *desc)](#oh_usb_getdevicedescriptor) | Obtains the device descriptor.|
33| [int32_t OH_Usb_GetConfigDescriptor(uint64_t deviceId, uint8_t configIndex, struct UsbDdkConfigDescriptor ** const config)](#oh_usb_getconfigdescriptor) | Obtains the configuration descriptor. To avoid memory leakage, use [OH_Usb_FreeConfigDescriptor](capi-usb-ddk-api-h.md#oh_usb_freeconfigdescriptor) to release a descriptor after use.|
34| [void OH_Usb_FreeConfigDescriptor(const struct UsbDdkConfigDescriptor * const config)](#oh_usb_freeconfigdescriptor) | Releases the configuration descriptor. To avoid memory leakage, release a descriptor after use.|
35| [int32_t OH_Usb_ClaimInterface(uint64_t deviceId, uint8_t interfaceIndex, uint64_t *interfaceHandle)](#oh_usb_claiminterface) | Declares a USB interface.|
36| [int32_t OH_Usb_ReleaseInterface(uint64_t interfaceHandle)](#oh_usb_releaseinterface) | Releases a USB interface.|
37| [int32_t OH_Usb_SelectInterfaceSetting(uint64_t interfaceHandle, uint8_t settingIndex)](#oh_usb_selectinterfacesetting) | Activates the alternate setting of a USB interface.|
38| [int32_t OH_Usb_GetCurrentInterfaceSetting(uint64_t interfaceHandle, uint8_t *settingIndex)](#oh_usb_getcurrentinterfacesetting) | Obtains the activated alternate setting of a USB interface.|
39| [int32_t OH_Usb_SendControlReadRequest(uint64_t interfaceHandle, const struct UsbControlRequestSetup *setup,uint32_t timeout, uint8_t *data, uint32_t *dataLen)](#oh_usb_sendcontrolreadrequest) | Sends a control read transfer request. This API works in a synchronous manner.|
40| [int32_t OH_Usb_SendControlWriteRequest(uint64_t interfaceHandle, const struct UsbControlRequestSetup *setup,uint32_t timeout, const uint8_t *data, uint32_t dataLen)](#oh_usb_sendcontrolwriterequest) | Sends a control write transfer request. This API works in a synchronous manner.|
41| [int32_t OH_Usb_SendPipeRequest(const struct UsbRequestPipe *pipe, UsbDeviceMemMap *devMmap)](#oh_usb_sendpiperequest) | Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.|
42| [int32_t OH_Usb_SendPipeRequestWithAshmem(const struct UsbRequestPipe *pipe, DDK_Ashmem *ashmem)](#oh_usb_sendpiperequestwithashmem) | Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.|
43| [int32_t OH_Usb_CreateDeviceMemMap(uint64_t deviceId, size_t size, UsbDeviceMemMap **devMmap)](#oh_usb_createdevicememmap) | Creates a buffer. To avoid resource leakage, use [OH_Usb_DestroyDeviceMemMap](capi-usb-ddk-api-h.md#oh_usb_destroydevicememmap) to destroy a buffer after use.|
44| [void OH_Usb_DestroyDeviceMemMap(UsbDeviceMemMap *devMmap)](#oh_usb_destroydevicememmap) | Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use.|
45| [int32_t OH_Usb_GetDevices(struct Usb_DeviceArray *devices)](#oh_usb_getdevices) | Obtains the USB device ID list. Ensure that the input pointer is valid and the number of devices does not exceed 128. To prevent resource leakage, release the member memory after usage. Besides, make sure that the obtained USB device ID has been filtered by **vid** in the driver configuration information.|
46
47## Function Description
48
49### OH_Usb_Init()
50
51```
52int32_t OH_Usb_Init(void)
53```
54
55**Description**
56
57Initializes the DDK.
58
59**Required permissions**: ohos.permission.ACCESS_DDK_USB
60
61**Since**: 10
62
63**Returns**
64
65| Type| Description|
66| -- | -- |
67| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_MEMORY_ERROR](capi-usb-ddk-types-h.md#usbddkerrcode): The memory allocation fails.|
68
69### OH_Usb_Release()
70
71```
72void OH_Usb_Release(void)
73```
74
75**Description**
76
77Releases the USB DDK.
78
79**Required permissions**: ohos.permission.ACCESS_DDK_USB
80
81**Since**: 10
82
83### OH_Usb_ReleaseResource()
84
85```
86int32_t OH_Usb_ReleaseResource(void)
87```
88
89**Description**
90
91Releases the USB DDK.
92
93**Required permissions**: ohos.permission.ACCESS_DDK_USB
94
95**Since**: 18
96
97**Returns**
98
99| Type| Description|
100| -- | -- |
101| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.|
102
103### OH_Usb_GetDeviceDescriptor()
104
105```
106int32_t OH_Usb_GetDeviceDescriptor(uint64_t deviceId, struct UsbDeviceDescriptor *desc)
107```
108
109**Description**
110
111Obtains the device descriptor.
112
113**Required permissions**: ohos.permission.ACCESS_DDK_USB
114
115**Since**: 10
116
117
118**Parameters**
119
120| Name| Description|
121| -- | -- |
122| uint64_t deviceId | Device ID.|
123| [struct UsbDeviceDescriptor](capi-usbddk-usbdevicedescriptor.md) *desc | Device descriptor. For details, see [UsbDeviceDescriptor](capi-usbddk-usbdevicedescriptor.md).|
124
125**Returns**
126
127| Type| Description|
128| -- | -- |
129| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **desc** is a null pointer.|
130
131### OH_Usb_GetConfigDescriptor()
132
133```
134int32_t OH_Usb_GetConfigDescriptor(uint64_t deviceId, uint8_t configIndex, struct UsbDdkConfigDescriptor ** const config)
135```
136
137**Description**
138
139Obtains the configuration descriptor. To avoid memory leakage, use [OH_Usb_FreeConfigDescriptor](capi-usb-ddk-api-h.md#oh_usb_freeconfigdescriptor) to release a descriptor after use.
140
141**Required permissions**: ohos.permission.ACCESS_DDK_USB
142
143**Since**: 10
144
145
146**Parameters**
147
148| Name                                              | Description|
149|---------------------------------------------------| -- |
150| uint64_t deviceId                                 | Device ID.|
151| uint8_t configIndex                               | Configuration index, which corresponds to {@link bConfigurationValue} in the USB protocol.|
152| struct [UsbDdkConfigDescriptor](capi-usbddk-usbddkconfigdescriptor.md) ** const config | Configuration descriptor, which includes the standard configuration descriptor defined in the USB protocol and the associated interface descriptor and endpoint descriptor.|
153
154**Returns**
155
156| Type| Description|
157| -- | -- |
158| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **config** is a null pointer.<br>         {@link USB_DDK_IO_FAILED}: An I/O exception occurs.<br>         [USB_DDK_MEMORY_ERROR](capi-usb-ddk-types-h.md#usbddkerrcode): The memory allocation fails.|
159
160### OH_Usb_FreeConfigDescriptor()
161
162```
163void OH_Usb_FreeConfigDescriptor(const struct UsbDdkConfigDescriptor * const config)
164```
165
166**Description**
167
168Releases the configuration descriptor. To avoid memory leakage, release a descriptor after use.
169
170**Required permissions**: ohos.permission.ACCESS_DDK_USB
171
172**Since**: 10
173
174
175**Parameters**
176
177| Name| Description|
178| -- | -- |
179| const struct [UsbDdkConfigDescriptor](capi-usbddk-usbddkconfigdescriptor.md) * const config | Configuration descriptor, which is obtained by calling [OH_Usb_GetConfigDescriptor](capi-usb-ddk-api-h.md#oh_usb_getconfigdescriptor).|
180
181### OH_Usb_ClaimInterface()
182
183```
184int32_t OH_Usb_ClaimInterface(uint64_t deviceId, uint8_t interfaceIndex, uint64_t *interfaceHandle)
185```
186
187**Description**
188
189Declares a USB interface.
190
191**Required permissions**: ohos.permission.ACCESS_DDK_USB
192
193**Since**: 10
194
195
196**Parameters**
197
198| Name| Description|
199| -- | -- |
200| uint64_t deviceId | Device ID.|
201| uint8_t interfaceIndex | Interface index, which corresponds to [bInterfaceNumber](capi-usbddk-usbinterfacedescriptor.md) in the USB protocol.|
202| uint64_t *interfaceHandle | Interface operation handle. After the interface is claimed successfully, a value will be assigned to this parameter.|
203
204**Returns**
205
206| Type| Description|
207| -- | -- |
208| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **interfaceHandle** is a null pointer.<br>         [USB_DDK_MEMORY_ERROR](capi-usb-ddk-types-h.md#usbddkerrcode): The memory to be allocated exceeds the limit.|
209
210### OH_Usb_ReleaseInterface()
211
212```
213int32_t OH_Usb_ReleaseInterface(uint64_t interfaceHandle)
214```
215
216**Description**
217
218Releases a USB interface.
219
220**Required permissions**: ohos.permission.ACCESS_DDK_USB
221
222**Since**: 10
223
224
225**Parameters**
226
227| Name| Description|
228| -- | -- |
229| uint64_t interfaceHandle | Interface operation handle.|
230
231**Returns**
232
233| Type| Description|
234| -- | -- |
235| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): One or more parameters are invalid.|
236
237### OH_Usb_SelectInterfaceSetting()
238
239```
240int32_t OH_Usb_SelectInterfaceSetting(uint64_t interfaceHandle, uint8_t settingIndex)
241```
242
243**Description**
244
245Activates the alternate setting of a USB interface.
246
247**Required permissions**: ohos.permission.ACCESS_DDK_USB
248
249**Since**: 10
250
251
252**Parameters**
253
254| Name| Description|
255| -- | -- |
256| uint64_t interfaceHandle | Interface operation handle.|
257| uint8_t settingIndex | Index of the alternate setting, which corresponds to {@link bAlternateSetting} in the USB protocol.|
258
259**Returns**
260
261| Type| Description|
262| -- | -- |
263| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): One or more parameters are invalid.|
264
265### OH_Usb_GetCurrentInterfaceSetting()
266
267```
268int32_t OH_Usb_GetCurrentInterfaceSetting(uint64_t interfaceHandle, uint8_t *settingIndex)
269```
270
271**Description**
272
273Obtains the activated alternate setting of a USB interface.
274
275**Required permissions**: ohos.permission.ACCESS_DDK_USB
276
277**Since**: 10
278
279
280**Parameters**
281
282| Name| Description|
283| -- | -- |
284| uint64_t interfaceHandle | Interface operation handle.|
285| uint8_t *settingIndex | Index of the alternate setting, which corresponds to {@link bAlternateSetting} in the USB protocol.|
286
287**Returns**
288
289| Type| Description|
290| -- | -- |
291| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **settingIndex** is a null pointer.|
292
293### OH_Usb_SendControlReadRequest()
294
295```
296int32_t OH_Usb_SendControlReadRequest(uint64_t interfaceHandle, const struct UsbControlRequestSetup *setup,uint32_t timeout, uint8_t *data, uint32_t *dataLen)
297```
298
299**Description**
300
301Sends a control read transfer request. This API works in a synchronous manner.
302
303**Required permissions**: ohos.permission.ACCESS_DDK_USB
304
305**Since**: 10
306
307
308**Parameters**
309
310| Name| Description|
311| -- | -- |
312| uint64_t interfaceHandle | Interface operation handle.|
313| [const struct UsbControlRequestSetup](capi-usbddk-usbcontrolrequestsetup.md) *setup | Request parameters. For details, see [UsbControlRequestSetup](capi-usbddk-usbcontrolrequestsetup.md).|
314| uint32_t timeout | Timeout duration, in ms.|
315| uint8_t *data | Data to transfer.|
316| uint32_t *dataLen | Data length. The return value indicates the length of the actually read data.|
317
318**Returns**
319
320| Type| Description|
321| -- | -- |
322| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         [USB_DDK_FAILED](capi-usb-ddk-types-h.md#usbddkerrcode): The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **setup**, **data**, or **dataLen** is a null pointer, or the value of **datalen** is less than the length of the read data.<br>         [USB_DDK_MEMORY_ERROR](capi-usb-ddk-types-h.md#usbddkerrcode): The attempt to copy the memory that stores the read data fails.<br>         USB_DDK_IO_FAILED: An I/O exception occurs.<br>         [USB_DDK_TIMEOUT](capi-usb-ddk-types-h.md#usbddkerrcode): The operation times out.|
323
324### OH_Usb_SendControlWriteRequest()
325
326```
327int32_t OH_Usb_SendControlWriteRequest(uint64_t interfaceHandle, const struct UsbControlRequestSetup *setup,uint32_t timeout, const uint8_t *data, uint32_t dataLen)
328```
329
330**Description**
331
332Sends a control write transfer request. This API works in a synchronous manner.
333
334**Required permissions**: ohos.permission.ACCESS_DDK_USB
335
336**Since**: 10
337
338
339**Parameters**
340
341| Name| Description|
342| -- | -- |
343| uint64_t interfaceHandle | Interface operation handle.|
344| [const struct UsbControlRequestSetup](capi-usbddk-usbcontrolrequestsetup.md) *setup | Request parameters. For details, see [UsbControlRequestSetup](capi-usbddk-usbcontrolrequestsetup.md).|
345| uint32_t timeout | Timeout duration, in ms.|
346| const uint8_t *data | Data to transfer.|
347| uint32_t dataLen | Data length.|
348
349**Returns**
350
351| Type| Description|
352| -- | -- |
353| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         [USB_DDK_FAILED](capi-usb-ddk-types-h.md#usbddkerrcode): The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **setup** or **data** is a null pointer.<br>         [USB_DDK_MEMORY_ERROR](capi-usb-ddk-types-h.md#usbddkerrcode): The attempt to copy the memory that stores the read data fails.<br>         USB_DDK_IO_FAILED: An I/O exception occurs.<br>         [USB_DDK_TIMEOUT](capi-usb-ddk-types-h.md#usbddkerrcode): The operation times out.|
354
355### OH_Usb_SendPipeRequest()
356
357```
358int32_t OH_Usb_SendPipeRequest(const struct UsbRequestPipe *pipe, UsbDeviceMemMap *devMmap)
359```
360
361**Description**
362
363Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.
364
365**Required permissions**: ohos.permission.ACCESS_DDK_USB
366
367**Since**: 10
368
369
370**Parameters**
371
372| Name| Description|
373| -- | -- |
374| [const struct UsbRequestPipe](capi-usbddk-usbrequestpipe.md) *pipe | Pipe used to transfer data.|
375| [UsbDeviceMemMap](capi-usbddk-usbdevicememmap.md) *devMmap | Data buffer, which can be obtained by calling [OH_Usb_CreateDeviceMemMap](capi-usb-ddk-api-h.md#oh_usb_createdevicememmap).|
376
377**Returns**
378
379| Type| Description|
380| -- | -- |
381| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **pipe** or **devMmap** is a null pointer, or the **devMmap** address is null.<br>         [USB_DDK_MEMORY_ERROR](capi-usb-ddk-types-h.md#usbddkerrcode): The attempt to copy the memory that stores the read data fails.<br>         USB_DDK_IO_FAILED: An I/O exception occurs.<br>         [USB_DDK_TIMEOUT](capi-usb-ddk-types-h.md#usbddkerrcode): The operation times out.|
382
383### OH_Usb_SendPipeRequestWithAshmem()
384
385```
386int32_t OH_Usb_SendPipeRequestWithAshmem(const struct UsbRequestPipe *pipe, DDK_Ashmem *ashmem)
387```
388
389**Description**
390
391Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.
392
393**Required permissions**: ohos.permission.ACCESS_DDK_USB
394
395**Since**: 12
396
397
398**Parameters**
399
400| Name                                                        | Description|
401|-------------------------------------------------------------| -- |
402| [const struct UsbRequestPipe](capi-usbddk-usbrequestpipe.md) *pipe | Pipe used to transfer data.|
403| [DDK_Ashmem](capi-baseddk-ddk-ashmem.md) *ashmem            | Shared memory, which can be obtained by calling {@link OH_DDK_CreateAshmem}.|
404
405**Returns**
406
407| Type| Description|
408| -- | -- |
409| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **pipe** or **ashmem** is a null pointer, or the **ashmem** address is null.<br>         [USB_DDK_MEMORY_ERROR](capi-usb-ddk-types-h.md#usbddkerrcode): The attempt to copy the memory that stores the read data fails.<br>         USB_DDK_IO_FAILED: An I/O exception occurs.<br>         [USB_DDK_TIMEOUT](capi-usb-ddk-types-h.md#usbddkerrcode): The operation times out.|
410
411### OH_Usb_CreateDeviceMemMap()
412
413```
414int32_t OH_Usb_CreateDeviceMemMap(uint64_t deviceId, size_t size, UsbDeviceMemMap **devMmap)
415```
416
417**Description**
418
419Creates a buffer. To avoid resource leakage, use [OH_Usb_DestroyDeviceMemMap](capi-usb-ddk-api-h.md#oh_usb_destroydevicememmap) to destroy a buffer after use.
420
421**Required permissions**: ohos.permission.ACCESS_DDK_USB
422
423**Since**: 10
424
425
426**Parameters**
427
428| Name| Description|
429| -- | -- |
430| uint64_t deviceId | Device ID.|
431| size_t size | Buffer size.|
432| [UsbDeviceMemMap](capi-usbddk-usbdevicememmap.md) **devMmap | Data memory map, through which the created buffer is returned to the caller.|
433
434**Returns**
435
436| Type| Description|
437| -- | -- |
438| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **devMmap** is a null pointer.<br>         [USB_DDK_MEMORY_ERROR](capi-usb-ddk-types-h.md#usbddkerrcode): The memory mapping fails, or the memory allocation of **devMmap** fails.|
439
440### OH_Usb_DestroyDeviceMemMap()
441
442```
443void OH_Usb_DestroyDeviceMemMap(UsbDeviceMemMap *devMmap)
444```
445
446**Description**
447
448Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use.
449
450**Required permissions**: ohos.permission.ACCESS_DDK_USB
451
452**Since**: 10
453
454
455**Parameters**
456
457| Name| Description|
458| -- | -- |
459| [UsbDeviceMemMap](capi-usbddk-usbdevicememmap.md) *devMmap | Destroys the buffer created by calling [OH_Usb_CreateDeviceMemMap](capi-usb-ddk-api-h.md#oh_usb_createdevicememmap).|
460
461### OH_Usb_GetDevices()
462
463```
464int32_t OH_Usb_GetDevices(struct Usb_DeviceArray *devices)
465```
466
467**Description**
468
469Obtains the USB device ID list. Ensure that the input pointer is valid and the number of devices does not exceed 128. To prevent resource leakage, release the member memory after usage. Besides, make sure that the obtained USB device ID has been filtered by **vid** in the driver configuration information.
470
471**Required permissions**: ohos.permission.ACCESS_DDK_USB
472
473**Since**: 18
474
475
476**Parameters**
477
478| Name| Description|
479| -- | -- |
480| [struct Usb_DeviceArray](capi-usbddk-usb-devicearray.md) *devices | Device memory address, which is used to store the obtained device ID list and quantity.|
481
482**Returns**
483
484| Type| Description|
485| -- | -- |
486| int32_t | [USB_DDK_SUCCESS](capi-usb-ddk-types-h.md#usbddkerrcode): The operation is successful.<br>         USB_DDK_NO_PERM: The permission check fails.<br>         [USB_DDK_INVALID_OPERATION](capi-usb-ddk-types-h.md#usbddkerrcode): The USB DDK service connection fails, or an internal error occurs.<br>         [USB_DDK_INVALID_PARAMETER](capi-usb-ddk-types-h.md#usbddkerrcode): The input **devices** is a null pointer.|
487