• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# USB DDK
2
3
4## Overview
5
6Provides USB DDK APIs to open and close USB interfaces, perform non-isochronous and isochronous data transfer over USB pipes, and implement control transfer and interrupt transfer, etc.
7
8**System capability**: SystemCapability.Driver.USB.Extension
9
10**Since**
11
1210
13
14## Summary
15
16
17### File
18
19| Name| Description|
20| -------- | -------- |
21| [usb_ddk_api.h](usb__ddk__api_8h.md) | Declares the USB DDK APIs used by the USB host to access USB devices.<br>File to include: &lt;usb/usb_ddk_api.h&gt;<br>Library: libusb_ndk.z.so|
22| [usb_ddk_types.h](usb__ddk__types_8h.md) | Provides the enumerated variables, structures, and macros used in USB DDK APIs.<br>File to include: &lt;usb/usb_ddk_types.h&gt; <br>Library: libusb_ndk.z.so|
23
24
25### Structs
26
27| Name| Description|
28| -------- | -------- |
29| [UsbControlRequestSetup](_usb_control_request_setup.md) | Setup data for control transfer. It corresponds to **Setup Data** in the USB protocol.|
30| [UsbDeviceDescriptor](_usb_device_descriptor.md) | Standard device descriptor, corresponding to **Standard Device Descriptor** in the USB protocol.|
31| [UsbConfigDescriptor](_usb_config_descriptor.md) | Standard configuration descriptor, corresponding to **Standard Configuration Descriptor** in the USB protocol.|
32| [UsbInterfaceDescriptor](_usb_interface_descriptor.md) | Standard interface descriptor, corresponding to **Standard Interface Descriptor** in the USB protocol.|
33| [UsbEndpointDescriptor](_usb_endpoint_descriptor.md) | Standard endpoint descriptor, corresponding to **Standard Endpoint Descriptor** in the USB protocol.|
34| [UsbDdkEndpointDescriptor](_usb_ddk_endpoint_descriptor.md) | Endpoint descriptor.|
35| [UsbDdkInterfaceDescriptor](_usb_ddk_interface_descriptor.md) | Interface descriptor.|
36| [UsbDdkInterface](_usb_ddk_interface.md) | USB DDK interface, which is a collection of alternate settings for a particular USB interface.|
37| [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md) | Configuration descriptor.|
38| [UsbRequestPipe](_usb_request_pipe.md) | Request pipe.|
39| [UsbDeviceMemMap](_usb_device_mem_map.md) | Device memory map created by calling [OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap). A buffer using the device memory map can provide better performance.|
40| [Usb_DeviceArray](_usb_device_array.md) | Defines the device ID list, which is used to store the device IDs and device quantity obtained using [OH_Usb_GetDevices()](oh_usb_getdevices16).|
41
42### Enums
43
44| Name| Description|
45| -------- | -------- |
46| [UsbDdkErrCode](#usbddkerrcode) {<br>USB_DDK_SUCCESS = 0, USB_DDK_NO_PERM = 201, USB_DDK_INVALID_PARAMETER = 401, USB_DDK_MEMORY_ERROR = 27400001,<br>USB_DDK_INVALID_OPERATION = 27400002, USB_DDK_IO_FAILED = 27400003, USB_DDK_TIMEOUT = 27400004<br>} | USB DDK error code definitions.|
47
48
49### Functions
50
51| Name| Description|
52| -------- | -------- |
53| [OH_Usb_Init](#oh_usb_init) (void) | Initializes the DDK.|
54| [OH_Usb_Release](#oh_usb_release) (void) | Releases the DDK.|
55| [OH_Usb_ReleaseResource](#oh_usb_releaseresource14) (void) | Releases the DDK.|
56| [OH_Usb_GetDeviceDescriptor](#oh_usb_getdevicedescriptor) (uint64_t deviceId, struct [UsbDeviceDescriptor](_usb_device_descriptor.md) \*desc) | Obtains the device descriptor.|
57| [OH_Usb_GetConfigDescriptor](#oh_usb_getconfigdescriptor) (uint64_t deviceId, uint8_t configIndex, struct [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md) \*\*const config) | Obtains the configuration descriptor. To avoid memory leakage, use **OH_Usb_FreeConfigDescriptor** to release a descriptor after use.|
58| [OH_Usb_FreeConfigDescriptor](#oh_usb_freeconfigdescriptor) (const struct [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md) \*const config) | Releases the configuration descriptor. To avoid memory leakage, release a descriptor after use.|
59| [OH_Usb_ClaimInterface](#oh_usb_claiminterface) (uint64_t deviceId, uint8_t interfaceIndex, uint64_t \*[interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | Declares a USB interface.|
60| [OH_Usb_ReleaseInterface](#oh_usb_releaseinterface) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | Releases a USB interface.|
61| [OH_Usb_SelectInterfaceSetting](#oh_usb_selectinterfacesetting) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle), uint8_t settingIndex) | Activates the alternate setting of a USB interface.|
62| [OH_Usb_GetCurrentInterfaceSetting](#oh_usb_getcurrentinterfacesetting) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle), uint8_t \*settingIndex) | Obtains the activated alternate setting of a USB interface.|
63| [OH_Usb_SendControlReadRequest](#oh_usb_sendcontrolreadrequest) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle), const struct [UsbControlRequestSetup](_usb_control_request_setup.md) \*setup, uint32_t [timeout](usb__ddk__types_8h.md#timeout), uint8_t \*data, uint32_t \*dataLen) | Sends a control read transfer request. This API works in a synchronous manner.|
64| [OH_Usb_SendControlWriteRequest](#oh_usb_sendcontrolwriterequest) (uint64_t [interfaceHandle](usb__ddk__types_8h.md#interfacehandle), const struct [UsbControlRequestSetup](_usb_control_request_setup.md) \*setup, uint32_t [timeout](usb__ddk__types_8h.md#timeout), const uint8_t \*data, uint32_t dataLen) | Sends a control write transfer request. This API works in a synchronous manner.|
65| [OH_Usb_SendPipeRequest](#oh_usb_sendpiperequest) (const struct [UsbRequestPipe](_usb_request_pipe.md) \*pipe, [UsbDeviceMemMap](_usb_device_mem_map.md) \*devMmap) | Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.|
66| [OH_Usb_SendPipeRequestWithAshmem](#oh_usb_sendpiperequestwithashmem12) (const struct [UsbRequestPipe](_usb_request_pipe.md) \*pipe, [DDK_Ashmem](_ddk_ashmem.md) \*ashmem) | Sends a pipe request for the shared memory. This API returns the result synchronously. It applies to interrupt transfer and bulk transfer.|
67| [OH_Usb_CreateDeviceMemMap](#oh_usb_createdevicememmap) (uint64_t deviceId, size_t size, [UsbDeviceMemMap](_usb_device_mem_map.md) \*\*devMmap) | Creates a buffer. To avoid memory leakage, use [OH_Usb_DestroyDeviceMemMap()](#oh_usb_destroydevicememmap) to destroy a buffer after use.|
68| [OH_Usb_DestroyDeviceMemMap](#oh_usb_destroydevicememmap) ([UsbDeviceMemMap](_usb_device_mem_map.md) \*devMmap) | Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use.|
69| [OH_Usb_GetDevices](#oh_usb_getdevices16) ([Usb_DeviceArray](_usb_device_array.md) \*devices) | 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.|
70
71#### deviceId Description
72
73You can call **queryDevices()** to obtain the device ID, that is, **deviceId**.
74For details, see [Peripheral Management Development](../../device/driver/externaldevice-guidelines.md).
75
76#### deviceId Conversion
77
78The **deviceId** obtained through **queryDevices()** cannot be directly used as the input parameter for functions such as [OH_Usb_GetDeviceDescriptor](#oh_usb_getdevicedescriptor).
79<p>Specifically, you need to extract its first 32 bits as the input parameter **deviceId** for C APIs.</p>
80<p>The following code is for reference only: </p>
81
82 ~~~
83uint64_t JsDeviceIdToNative(uint64_t deviceId)
84{
85    uint32_t busNum = (uint32_t)(deviceId >> 48);
86    uint32_t devNum = (uint32_t)((deviceId & 0x0000FFFF00000000) >> 32);
87    return (((static_cast<uint64_t>(busNum)) << 32) | devNum);
88}
89~~~
90
91## Type Description
92
93### UsbDdkEndpointDescriptor
94
95```
96typedef struct UsbDdkEndpointDescriptor UsbDdkEndpointDescriptor
97```
98
99**Description**
100
101Endpoint descriptor.
102
103**Since**: 10
104
105### UsbDdkInterfaceDescriptor
106
107```
108typedef struct UsbDdkInterfaceDescriptor UsbDdkInterfaceDescriptor
109```
110
111**Description**
112
113Interface descriptor.
114
115**Since**: 10
116
117### UsbDdkInterface
118
119```
120typedef struct UsbDdkInterface UsbDdkInterface
121```
122
123**Description**
124
125USB API.
126
127**Since**: 10
128
129### UsbDdkConfigDescriptor
130
131```
132typedef struct UsbDdkConfigDescriptor UsbDdkConfigDescriptor
133```
134
135**Description**
136
137Configuration descriptor.
138
139**Since**: 10
140
141### UsbDeviceMemMap
142
143```
144typedef struct UsbDeviceMemMap UsbDeviceMemMap
145```
146
147**Description**
148
149 Device memory map created by calling [OH_Usb_CreateDeviceMemMap()](_usb_ddk.md#oh_usb_createdevicememmap). A buffer using the device memory map can provide better performance.
150
151**Since**: 10
152
153### Usb_DeviceArray
154
155```
156typedef struct Usb_DeviceArray usb_DeviceArray
157```
158
159**Description**
160
161Defines the device ID list, which is used to store the device IDs and device quantity obtained using [OH_Usb_GetDevices()](_usb_ddk.md#oh_usb_getdevices16).
162
163**Since**: 10
164
165## Enum Description
166
167### UsbDdkErrCode
168
169
170```
171enum UsbDdkErrCode
172```
173
174**Description**
175
176USB DDK error code definitions.
177
178| Enum| Value| Description|
179| -------- | -------- |-------- |
180| USB_DDK_SUCCESS | 0 | Operation successful.|
181| USB_DDK_NO_PERM | 201 | Operation failed.|
182| USB_DDK_INVALID_PARAMETER | 401 | Invalid parameter.|
183| USB_DDK_MEMORY_ERROR | 27400001 | Memory-related error, for example, insufficient memory, memory data copy failure, or memory application failure.|
184| USB_DDK_INVALID_OPERATION | 27400002 | Invalid operation.|
185| USB_DDK_IO_FAILED | 27400003 | The device I/O operation fails.|
186| USB_DDK_TIMEOUT | 27400004 | Transfer timed out.|
187
188
189## Function Description
190
191
192### OH_Usb_ClaimInterface()
193
194
195```
196int32_t OH_Usb_ClaimInterface (uint64_t deviceId, uint8_t interfaceIndex, uint64_t * interfaceHandle)
197```
198
199**Description**
200
201Declares a USB interface.
202
203**Required permissions**: ohos.permission.ACCESS_DDK_USB
204
205**Parameters**
206
207| Name| Description|
208| -------- | -------- |
209| deviceId | Device ID.|
210| interfaceIndex | Interface index, which corresponds to [bInterfaceNumber](_usb_interface_descriptor.md#binterfacenumber) in the USB protocol.|
211| interfaceHandle | Interface operation handle. After the interface is claimed successfully, a value will be assigned to this parameter.|
212
213**Returns**
214
215- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
216- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
217- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
218- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The input **interfaceHandle** is a null pointer.
219
220
221### OH_Usb_CreateDeviceMemMap()
222
223
224```
225int32_t OH_Usb_CreateDeviceMemMap (uint64_t deviceId, size_t size, UsbDeviceMemMap ** devMmap)
226```
227
228**Description**
229
230Creates a buffer. To avoid memory leakage, use [OH_Usb_DestroyDeviceMemMap()](#oh_usb_destroydevicememmap) to destroy a buffer after use.
231
232**Required permissions**: ohos.permission.ACCESS_DDK_USB
233
234**Parameters**
235
236| Name| Description|
237| -------- | -------- |
238| deviceId | Device ID.|
239| size | Buffer size.|
240| devMmap | Data memory map, through which the created buffer is returned to the caller.|
241
242**Returns**
243
244- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
245- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
246- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The input **devMmap** is a null pointer.
247- [USB_DDK_MEMORY_ERROR](#usbddkerrcode): indicates that the mmap fails or the memory space of the devMmap fails to be applied for.
248
249
250### OH_Usb_DestroyDeviceMemMap()
251
252
253```
254void OH_Usb_DestroyDeviceMemMap (UsbDeviceMemMap * devMmap)
255```
256
257**Description**
258
259Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use.
260
261**Required permissions**: ohos.permission.ACCESS_DDK_USB
262
263**Parameters**
264
265| Name| Description|
266| -------- | -------- |
267| devMmap | Destroys the buffer created by [OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap).|
268
269
270### OH_Usb_FreeConfigDescriptor()
271
272
273```
274void OH_Usb_FreeConfigDescriptor (struct UsbDdkConfigDescriptor *const config)
275```
276
277**Description**
278
279Releases the configuration descriptor. To avoid memory leakage, use **OH_Usb_FreeConfigDescriptor** to release a descriptor after use.
280
281**Required permissions**: ohos.permission.ACCESS_DDK_USB
282
283**Parameters**
284
285| Name| Description|
286| -------- | -------- |
287| config | Configuration descriptor obtained by calling [OH_Usb_GetConfigDescriptor()](#oh_usb_getconfigdescriptor).|
288
289
290### OH_Usb_GetConfigDescriptor()
291
292
293```
294int32_t OH_Usb_GetConfigDescriptor (uint64_t deviceId, uint8_t configIndex, struct UsbDdkConfigDescriptor **const config)
295```
296
297**Description**
298
299Obtains the configuration descriptor. To avoid memory leakage, use **OH_Usb_FreeConfigDescriptor** to release a descriptor after use.
300
301**Required permissions**: ohos.permission.ACCESS_DDK_USB
302
303**Parameters**
304
305| Name| Description|
306| -------- | -------- |
307| deviceId | Device ID.|
308| configIndex | Configuration ID, which corresponds to [bConfigurationValue](_usb_config_descriptor.md#bconfigurationvalue) in the USB protocol.|
309| config | Configuration descriptor, which includes the standard configuration descriptor defined in the USB protocol and the associated interface descriptor and endpoint descriptor.|
310
311**Returns**
312
313- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
314- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
315- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
316- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The input **config** is a null pointer.
317- [USB_DDK_IO_FAILED](#usbddkerrcode): The device I/O operation fails.
318
319
320### OH_Usb_GetCurrentInterfaceSetting()
321
322
323```
324int32_t OH_Usb_GetCurrentInterfaceSetting (uint64_t interfaceHandle, uint8_t * settingIndex)
325```
326
327**Description**
328
329Obtains the activated alternate setting of a USB interface.
330
331**Required permissions**: ohos.permission.ACCESS_DDK_USB
332
333**Parameters**
334
335| Name| Description|
336| -------- | -------- |
337| interfaceHandle | Interface operation handle.|
338| settingIndex | Index of the alternate setting, which corresponds to [bAlternateSetting](_usb_interface_descriptor.md#balternatesetting) in the USB protocol.|
339
340**Returns**
341
342- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
343- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
344- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
345- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The input **settingIndex** is a null pointer.
346
347
348### OH_Usb_GetDeviceDescriptor()
349
350
351```
352int32_t OH_Usb_GetDeviceDescriptor (uint64_t deviceId, struct UsbDeviceDescriptor * desc)
353```
354
355**Description**
356
357Obtains the device descriptor.
358
359**Required permissions**: ohos.permission.ACCESS_DDK_USB
360
361**Parameters**
362
363| Name| Description|
364| -------- | -------- |
365| deviceId | Device ID.|
366| desc | Device descriptor. For details, see [UsbDeviceDescriptor](_usb_device_descriptor.md).|
367
368**Returns**
369
370- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
371- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
372- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
373- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The input **desc** is a null pointer.
374
375### OH_Usb_Init()
376
377
378```
379int32_t OH_Usb_Init (void )
380```
381
382**Description**
383
384Initializes the DDK.
385
386**Required permissions**: ohos.permission.ACCESS_DDK_USB
387
388**Returns**
389
390- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
391- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
392- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
393
394### OH_Usb_Release()
395
396
397```
398void OH_Usb_Release (void)
399```
400
401**Description**
402
403Releases the DDK.
404
405**Required permissions**: ohos.permission.ACCESS_DDK_USB
406
407### OH_Usb_ReleaseResource()<sup>14+</sup>
408
409```
410int32_t OH_Usb_ReleaseResource (void)
411```
412
413**Description**
414
415Releases the DDK.
416
417**Required permissions**: ohos.permission.ACCESS_DDK_USB
418
419**Returns**
420
421- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
422- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
423- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
424
425### OH_Usb_ReleaseInterface()
426
427```
428int32_t OH_Usb_ReleaseInterface (uint64_t interfaceHandle)
429```
430
431**Description**
432
433Releases a USB interface.
434
435**Required permissions**: ohos.permission.ACCESS_DDK_USB
436
437**Parameters**
438
439| Name| Description|
440| -------- | -------- |
441| interfaceHandle | Interface operation handle.|
442
443**Returns**
444
445- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
446- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
447- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
448
449
450### OH_Usb_SelectInterfaceSetting()
451
452
453```
454int32_t OH_Usb_SelectInterfaceSetting (uint64_t interfaceHandle, uint8_t settingIndex)
455```
456
457**Description**
458
459Activates the alternate setting of a USB interface.
460
461**Required permissions**: ohos.permission.ACCESS_DDK_USB
462
463**Parameters**
464
465| Name| Description|
466| -------- | -------- |
467| interfaceHandle | Interface operation handle.|
468| settingIndex | Index of the alternate setting, which corresponds to [bAlternateSetting](_usb_interface_descriptor.md#balternatesetting) in the USB protocol.|
469
470**Returns**
471
472- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
473- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
474- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
475
476
477### OH_Usb_SendControlReadRequest()
478
479
480```
481int32_t OH_Usb_SendControlReadRequest (uint64_t interfaceHandle, const struct UsbControlRequestSetup * setup, uint32_t timeout, uint8_t * data, uint32_t * dataLen)
482```
483
484**Description**
485
486Sends a control read transfer request. This API works in a synchronous manner.
487
488**Required permissions**: ohos.permission.ACCESS_DDK_USB
489
490**Parameters**
491
492| Name| Description|
493| -------- | -------- |
494| interfaceHandle | Interface operation handle.|
495| setup | Request parameters. For details, see [UsbControlRequestSetup](_usb_control_request_setup.md).|
496| timeout | Timeout duration, in milliseconds.|
497| data | Data to be transferred.|
498| dataLen | Data length. The return value indicates the length of the actually read data.|
499
500**Returns**
501
502- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
503- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
504- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
505- [USB_DDK_INVALID_PARAMETER](#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.
506- [USB_DDK_MEMORY_ERROR](#usbddkerrcode): The attempt to copy the memory that stores the read data fails.
507- [USB_DDK_IO_FAILED](#usbddkerrcode): The device I/O operation fails.
508- [USB_DDK_TIMEOUT] (#usbddkerrcode): The request times out.
509
510
511### OH_Usb_SendControlWriteRequest()
512
513
514```
515int32_t OH_Usb_SendControlWriteRequest (uint64_t interfaceHandle, const struct UsbControlRequestSetup * setup, uint32_t timeout, const uint8_t * data, uint32_t dataLen)
516```
517
518**Description**
519
520Sends a control write transfer request. This API works in a synchronous manner.
521
522**Required permissions**: ohos.permission.ACCESS_DDK_USB
523
524**Parameters**
525
526| Name| Description|
527| -------- | -------- |
528| interfaceHandle | Interface operation handle.|
529| setup | Request parameters. For details, see [UsbControlRequestSetup](_usb_control_request_setup.md).|
530| timeout | Timeout duration, in milliseconds.|
531| data | Data to be transferred.|
532| dataLen | Data length.|
533
534**Returns**
535
536- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
537- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
538- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
539- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The input **setup** or **data** is a null pointer.
540- [USB_DDK_IO_FAILED](#usbddkerrcode): The device I/O operation fails.
541- [USB_DDK_TIMEOUT] (#usbddkerrcode): The request times out.
542
543
544### OH_Usb_SendPipeRequest()
545
546
547```
548int32_t OH_Usb_SendPipeRequest (const struct UsbRequestPipe * pipe, UsbDeviceMemMap * devMmap)
549```
550
551**Description**
552
553Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.
554
555**Required permissions**: ohos.permission.ACCESS_DDK_USB
556
557**Parameters**
558
559| Name| Description|
560| -------- | -------- |
561| pipe | Pipe used to transfer data.|
562| devMmap | Device memory map, which can be obtained by calling [OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap).|
563
564**Returns**
565
566- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
567- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
568- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
569- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The input **pipe**, **devMmap**, or **devMmap** address is a null pointer.
570- [USB_DDK_IO_FAILED](#usbddkerrcode): The device I/O operation fails.
571- [USB_DDK_TIMEOUT] (#usbddkerrcode): The request times out.
572
573### OH_Usb_SendPipeRequestWithAshmem()<sup>12+</sup>
574
575
576```
577int32_t OH_Usb_SendPipeRequestWithAshmem(const struct UsbRequestPipe *pipe, DDK_Ashmem *ashmem)
578```
579
580**Description**
581
582Sends a pipe request for the shared memory. This API returns the result synchronously. It applies to interrupt transfer and bulk transfer.
583
584**Required permissions**: ohos.permission.ACCESS_DDK_USB
585
586**Parameters**
587
588| Name| Description|
589| -------- | -------- |
590| pipe | Pipe used to transfer data.|
591| ashmem | Shared memory, which can be obtained through [OH_DDK_CreateAshmem()](_base_ddk.md#oh_ddk_createashmem).|
592
593**Returns**
594
595- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
596- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
597- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
598- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The input **pipe**, **ashmem**, or **ashmem** address is a null pointer.
599- [USB_DDK_IO_FAILED](#usbddkerrcode): The device I/O operation fails.
600- [USB_DDK_TIMEOUT] (#usbddkerrcode): The request times out.
601
602### OH_Usb_GetDevices()<sup>16+</sup>
603
604
605```
606int32_t OH_Usb_GetDevices(struct Usb_DeviceArray *devices)
607```
608
609**Description**
610
611Obtains 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.
612
613**Required permissions**: ohos.permission.ACCESS_DDK_USB
614
615**Parameters**
616
617| Name| Description|
618| -------- | -------- |
619| devices | Device memory address, which is used to store the obtained device ID list and quantity.|
620
621**Returns**
622
623- [USB_DDK_SUCCESS] (#usbddkerrcode): The API call is successful.
624- [USB_DDK_NO_PERM](#usbddkerrcode): The permission verification fails.
625- [USB_DDK_INVALID_OPERATION](#usbddkerrcode): The usb_ddk service connection fails.
626- [USB_DDK_INVALID_PARAMETER](#usbddkerrcode): The address of **devices** is a null pointer.
627