• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.usbManager (USB Manager)
2
3The **usbManager** module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control on the host side as well as port management, and function switch and query on the device side.
4
5>  **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```js
12import usb from "@ohos.usbManager";
13```
14
15## usb.getDevices
16
17getDevices(): Array<Readonly<USBDevice>>
18
19Obtains the list of USB devices connected to the host. If no device is connected, an empty list is returned.
20
21**System capability**: SystemCapability.USB.USBManager
22
23**Return value**
24
25| Type                                                  | Description     |
26| ---------------------------------------------------- | ------- |
27| Array<Readonly<[USBDevice](#usbdevice)>> | USB device list.|
28
29**Example**
30
31```js
32let devicesList = usb.getDevices();
33console.log(`devicesList = ${devicesList}`);
34// devicesList is a list of USB devices.
35// A simple example of devicesList is provided as follows:
36[
37  {
38    name: "1-1",
39    serial: "",
40    manufacturerName: "",
41    productName: "",
42    version: "",
43    vendorId: 7531,
44    productId: 2,
45    clazz: 9,
46    subClass: 0,
47    protocol: 1,
48    devAddress: 1,
49    busNum: 1,
50    configs: [
51      {
52        id: 1,
53        attributes: 224,
54        isRemoteWakeup: true,
55        isSelfPowered: true,
56        maxPower: 0,
57        name: "1-1",
58        interfaces: [
59          {
60            id: 0,
61            protocol: 0,
62            clazz: 9,
63            subClass: 0,
64            alternateSetting: 0,
65            name: "1-1",
66            endpoints: [
67              {
68                address: 129,
69                attributes: 3,
70                interval: 12,
71                maxPacketSize: 4,
72                direction: 128,
73                number: 1,
74                type: 3,
75                interfaceId: 0,
76              },
77            ],
78          },
79        ],
80      },
81    ],
82  },
83]
84```
85
86## usb.connectDevice
87
88connectDevice(device: USBDevice): Readonly<USBDevicePipe>
89
90Connects to the USB device based on the device information returned by **getDevices()**.
91
92Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and device information, and then call [usb.requestRight](#usbrequestright) to request the device access permission.
93
94**System capability**: SystemCapability.USB.USBManager
95
96**Parameters**
97
98| Name| Type| Mandatory| Description|
99| -------- | -------- | -------- | -------- |
100| device | [USBDevice](#usbdevice) | Yes| USB device information.|
101
102**Return value**
103
104| Type| Description|
105| -------- | -------- |
106| Readonly<[USBDevicePipe](#usbdevicepipe)> | USB device pipe for data transfer.|
107
108**Error codes**
109
110For details about the error codes, see [USB Error Codes](../errorcodes/errorcode-usb.md).
111
112| ID| Error Message|
113| -------- | -------- |
114| 14400001 |Permission denied. Need call requestRight to get permission. |
115
116**Example**
117
118```js
119let devicesList = usb.getDevices();
120if (devicesList.length == 0) {
121  console.log(`device list is empty`);
122}
123
124let device = devicesList[0];
125usb.requestRight(device.name);
126let devicepipe = usb.connectDevice(device);
127console.log(`devicepipe = ${devicepipe}`);
128```
129
130## usb.hasRight
131
132hasRight(deviceName: string): boolean
133
134Checks whether the application has the permission to access the device.
135
136Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise.
137
138**System capability**: SystemCapability.USB.USBManager
139
140**Parameters**
141
142| Name| Type| Mandatory| Description|
143| -------- | -------- | -------- | -------- |
144| deviceName | string | Yes| Device name.|
145
146**Return value**
147
148| Type| Description|
149| -------- | -------- |
150| boolean | Returns **true** if the application has the permission to access the device; returns **false** otherwise.|
151
152**Example**
153
154```js
155let devicesName="1-1";
156let bool = usb.hasRight(devicesName);
157console.log(`${bool}`);
158```
159
160## usb.requestRight
161
162requestRight(deviceName: string): Promise<boolean>
163
164Requests the temporary permission for the application to access a USB device. This API uses a promise to return the result.
165
166**System capability**: SystemCapability.USB.USBManager
167
168**Parameters**
169
170| Name| Type| Mandatory| Description|
171| -------- | -------- | -------- | -------- |
172| deviceName | string | Yes| Device name.|
173
174**Return value**
175
176| Type| Description|
177| -------- | -------- |
178| Promise<boolean> | Promise used to return the result. The value **true** indicates that the temporary device access permissions are granted; and the value **false** indicates the opposite.|
179
180**Example**
181
182```js
183let devicesName="1-1";
184usb.requestRight(devicesName).then((ret) => {
185  console.log(`requestRight = ${ret}`);
186});
187```
188
189## usb.removeRight
190
191removeRight(deviceName: string): boolean
192
193Removes the permission for the application to access a USB device.
194
195**System capability**: SystemCapability.USB.USBManager
196
197**Parameters**
198
199| Name| Type| Mandatory| Description|
200| -------- | -------- | -------- | -------- |
201| deviceName | string | Yes| Device name.|
202
203**Return value**
204
205| Type| Description|
206| -------- | -------- |
207| boolean | Permission removal result. The value **true** indicates that the access permission is removed successfully; and the value **false** indicates the opposite.|
208
209**Example**
210
211```js
212let devicesName="1-1";
213if (usb.removeRight(devicesName)) {
214  console.log(`Succeed in removing right`);
215}
216```
217
218## usb.addRight
219
220addRight(bundleName: string, deviceName: string): boolean
221
222Adds the permission for the application to access a USB device.
223
224[requestRight](#usbrequestright) triggers a dialog box to request for user authorization, whereas **addRight** adds the access permission directly without displaying a dialog box.
225
226**System API**: This is a system API.
227
228**System capability**: SystemCapability.USB.USBManager
229
230**Parameters**
231
232| Name| Type| Mandatory| Description|
233| -------- | -------- | -------- | -------- |
234| deviceName | string | Yes| Device name.|
235| bundleName | string | Yes| Bundle name of the application.|
236
237**Return value**
238
239| Type| Description|
240| -------- | -------- |
241| boolean | Permission addition result. The value **true** indicates that the access permission is added successfully; and the value **false** indicates the opposite.|
242
243**Example**
244
245```js
246let devicesName = "1-1";
247let bundleName = "com.example.hello";
248if (usb.addRight(bundleName, devicesName)) {
249  console.log(`Succeed in adding right`);
250}
251```
252
253## usb.claimInterface
254
255claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): number
256
257Claims a USB interface.
258
259Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and USB interfaces, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter.
260
261**System capability**: SystemCapability.USB.USBManager
262
263**Parameters**
264
265| Name| Type| Mandatory| Description|
266| -------- | -------- | -------- | -------- |
267| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
268| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to claim.|
269| force | boolean | No| Whether to forcibly claim the USB interface. The default value is **false**, indicating not to forcibly claim the USB interface.|
270
271**Return value**
272
273| Type| Description|
274| -------- | -------- |
275| number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise.|
276
277**Example**
278
279```js
280let ret = usb.claimInterface(devicepipe, interfaces);
281console.log(`claimInterface = ${ret}`);
282```
283
284## usb.releaseInterface
285
286releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number
287
288Releases a USB interface.
289
290Before you do this, ensure that you have claimed the interface by calling [usb.claimInterface](#usbclaiminterface).
291
292**System capability**: SystemCapability.USB.USBManager
293
294**Parameters**
295
296| Name| Type| Mandatory| Description|
297| -------- | -------- | -------- | -------- |
298| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
299| iface | [USBInterface](#usbinterface) | Yes| USB interface, which is used to determine the index of the interface to release.|
300
301**Return value**
302
303| Type| Description|
304| -------- | -------- |
305| number | Returns **0** if the USB interface is successfully released; returns an error code otherwise.|
306
307**Example**
308
309```js
310let ret = usb.releaseInterface(devicepipe, interfaces);
311console.log(`releaseInterface = ${ret}`);
312```
313
314## usb.setConfiguration
315
316setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number
317
318Sets the device configuration.
319
320Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and device configuration, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter.
321
322**System capability**: SystemCapability.USB.USBManager
323
324**Parameters**
325
326| Name| Type| Mandatory| Description|
327| -------- | -------- | -------- | -------- |
328| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
329| config | [USBConfiguration](#usbconfiguration) | Yes| USB configuration to set.|
330
331**Return value**
332
333| Type| Description|
334| -------- | -------- |
335| number | Returns **0** if the USB configuration is successfully set; returns an error code otherwise.|
336
337**Example**
338
339```js
340let ret = usb.setConfiguration(devicepipe, config);
341console.log(`setConfiguration = ${ret}`);
342```
343
344## usb.setInterface
345
346setInterface(pipe: USBDevicePipe, iface: USBInterface): number
347
348Sets a USB interface.
349
350Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and interfaces, call [usb.requestRight](#usbrequestright) to request the device access permission, call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter, and call [usb.claimInterface](#usbclaiminterface) to claim the USB interface.
351
352**System capability**: SystemCapability.USB.USBManager
353
354**Parameters**
355
356| Name  | Type                             | Mandatory | Description           |
357| ----- | ------------------------------- | --- | ------------- |
358| pipe  | [USBDevicePipe](#usbdevicepipe) | Yes  | Device pipe, which is used to determine the bus number and device address.|
359| iface | [USBInterface](#usbinterface)   | Yes  | USB interface to set. |
360
361**Return value**
362
363| Type| Description|
364| -------- | -------- |
365| number | Returns **0** if the USB interface is successfully set; returns an error code otherwise.|
366
367**Example**
368
369```js
370let ret = usb.setInterface(devicepipe, interfaces);
371console.log(`setInterface = ${ret}`);
372```
373
374## usb.getRawDescriptor
375
376getRawDescriptor(pipe: USBDevicePipe): Uint8Array
377
378Obtains the raw USB descriptor.
379
380Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter.
381
382**System capability**: SystemCapability.USB.USBManager
383
384**Parameters**
385
386| Name| Type| Mandatory| Description|
387| -------- | -------- | -------- | -------- |
388| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
389
390**Return value**
391
392| Type| Description|
393| -------- | -------- |
394| Uint8Array | Returns the raw USB descriptor if the operation is successful; returns **undefined** otherwise.|
395
396**Example**
397
398```js
399let ret = usb.getRawDescriptor(devicepipe);
400```
401
402## usb.getFileDescriptor
403
404getFileDescriptor(pipe: USBDevicePipe): number
405
406Obtains the file descriptor.
407
408Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter.
409
410**System capability**: SystemCapability.USB.USBManager
411
412**Parameters**
413
414| Name| Type| Mandatory| Description|
415| -------- | -------- | -------- | -------- |
416| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| Device pipe, which is used to determine the bus number and device address.|
417
418**Return value**
419
420| Type    | Description                  |
421| ------ | -------------------- |
422| number | Returns the file descriptor of the USB device if the operation is successful; returns **-1** otherwise.|
423
424**Example**
425
426```js
427let ret = usb.getFileDescriptor(devicepipe);
428```
429
430## usb.controlTransfer
431
432controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: number): Promise<number>
433
434Performs control transfer.
435
436Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter.
437
438**System capability**: SystemCapability.USB.USBManager
439
440**Parameters**
441
442| Name| Type| Mandatory| Description|
443| -------- | -------- | -------- | -------- |
444| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
445| controlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.|
446| timeout | number | No| Timeout duration in ms. This parameter is optional. The default value is **0**, indicating no timeout.|
447
448**Return value**
449
450| Type| Description|
451| -------- | -------- |
452| Promise<number> | Promise used to return the result, which is the size of the transmitted or received data block if the transfer is successful, or **-1** if an exception has occurred.|
453
454**Example**
455
456```js
457let param = {
458  request: 0,
459  reqType: 0,
460  target:0,
461  value: 0,
462  index: 0,
463  data: null
464};
465usb.controlTransfer(devicepipe, param).then((ret) => {
466 console.log(`controlTransfer = ${ret}`);
467})
468```
469
470## usb.bulkTransfer
471
472bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise<number>
473
474Performs bulk transfer.
475
476Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and endpoints, call [usb.requestRight](#usbrequestright) to request the device access permission, call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter, and call [usb.claimInterface](#usbclaiminterface) to claim the USB interface.
477
478**System capability**: SystemCapability.USB.USBManager
479
480**Parameters**
481
482| Name| Type| Mandatory| Description|
483| -------- | -------- | -------- | -------- |
484| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
485| endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer.|
486| buffer | Uint8Array | Yes| Buffer for writing or reading data.|
487| timeout | number | No| Timeout duration in ms. This parameter is optional. The default value is **0**, indicating no timeout.|
488
489**Return value**
490
491| Type| Description|
492| -------- | -------- |
493| Promise<number> | Promise used to return the result, which is the size of the transmitted or received data block if the transfer is successful, or **-1** if an exception has occurred.|
494
495**Example**
496
497```js
498// Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
499// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
500// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
501usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
502 console.log(`bulkTransfer = ${ret}`);
503});
504```
505
506## usb.closePipe
507
508closePipe(pipe: USBDevicePipe): number
509
510Closes a USB device pipe.
511
512Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list, call [usb.requestRight](#usbrequestright) to request the device access permission, and call [usb.connectDevice](#usbconnectdevice) to obtain **devicepipe** as an input parameter.
513
514**System capability**: SystemCapability.USB.USBManager
515
516**Parameters**
517
518| Name| Type| Mandatory| Description|
519| -------- | -------- | -------- | -------- |
520| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe.|
521
522**Return value**
523
524| Type| Description|
525| -------- | -------- |
526| number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.|
527
528**Example**
529
530```js
531let ret = usb.closePipe(devicepipe);
532console.log(`closePipe = ${ret}`);
533```
534
535## usb.usbFunctionsFromString
536
537usbFunctionsFromString(funcs: string): number
538
539Converts the USB function list in the string format to a numeric mask in Device mode.
540
541**System API**: This is a system API.
542
543**System capability**: SystemCapability.USB.USBManager
544
545**Parameters**
546
547| Name| Type  | Mandatory| Description                  |
548| ------ | ------ | ---- | ---------------------- |
549| funcs  | string | Yes  | Function list in string format.|
550
551**Return value**
552
553| Type  | Description              |
554| ------ | ------------------ |
555| number | Function list in numeric mask format.|
556
557**Example**
558
559```js
560let funcs = "acm";
561let ret = usb.usbFunctionsFromString(funcs);
562```
563
564## usb.usbFunctionsToString
565
566usbFunctionsToString(funcs: FunctionType): string
567
568Converts the USB function list in the numeric mask format to a string in Device mode.
569
570**System API**: This is a system API.
571
572**System capability**: SystemCapability.USB.USBManager
573
574**Parameters**
575
576| Name| Type                          | Mandatory| Description             |
577| ------ | ------------------------------ | ---- | ----------------- |
578| funcs  | [FunctionType](#functiontype) | Yes  | USB function list in numeric mask format.|
579
580**Return value**
581
582| Type  | Description                          |
583| ------ | ------------------------------ |
584| string | Function list in string format.|
585
586**Example**
587
588```js
589let funcs = usb.FunctionType.ACM | usb.FunctionType.ECM;
590let ret = usb.usbFunctionsToString(funcs);
591```
592
593## usb.setCurrentFunctions
594
595setCurrentFunctions(funcs: FunctionType): Promise\<void\>
596
597Sets the current USB function list in Device mode.
598
599**System API**: This is a system API.
600
601**System capability**: SystemCapability.USB.USBManager
602
603**Parameters**
604
605| Name| Type                          | Mandatory| Description             |
606| ------ | ------------------------------ | ---- | ----------------- |
607| funcs  | [FunctionType](#functiontype) | Yes  | USB function list in numeric mask format.|
608
609**Return value**
610
611| Type           | Description         |
612| --------------- | ------------- |
613| Promise\<void\> | Promise used to return the result.|
614
615**Example**
616
617```js
618let funcs = usb.FunctionType.HDC;
619usb.setCurrentFunctions(funcs).then(() => {
620    console.info('usb setCurrentFunctions successfully.');
621}).catch(err => {
622    console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message);
623});
624```
625
626## usb.getCurrentFunctions
627
628getCurrentFunctions(): FunctionType
629
630Obtains the numeric mask combination for the USB function list in Device mode.
631
632**System API**: This is a system API.
633
634**System capability**: SystemCapability.USB.USBManager
635
636**Return value**
637
638| Type                          | Description                             |
639| ------------------------------ | --------------------------------- |
640| [FunctionType](#functiontype) | Numeric mask combination for the USB function list.|
641
642**Example**
643
644```js
645let ret = usb.getCurrentFunctions();
646```
647
648## usb.getPorts
649
650getPorts(): Array\<USBPort\>
651
652Obtains the list of all physical USB ports.
653
654**System API**: This is a system API.
655
656**System capability**: SystemCapability.USB.USBManager
657
658**Return value**
659
660| Type                         | Description                 |
661| ----------------------------- | --------------------- |
662| [Array\<USBPort\>](#usbport) | List of physical USB ports.|
663
664**Example**
665
666```js
667let ret = usb.getPorts();
668```
669
670## usb.getSupportedModes
671
672getSupportedModes(portId: number): PortModeType
673
674Obtains the mask combination for the supported mode list of a given USB port.
675
676**System API**: This is a system API.
677
678**System capability**: SystemCapability.USB.USBManager
679
680**Parameters**
681
682| Name| Type  | Mandatory| Description    |
683| ------ | ------ | ---- | -------- |
684| portId | number | Yes  | Port number.|
685
686**Return value**
687
688| Type                          | Description                      |
689| ------------------------------ | -------------------------- |
690| [PortModeType](#portmodetype) | Mask combination for the supported mode list.|
691
692**Example**
693
694```js
695let ret = usb.getSupportedModes(0);
696```
697
698## usb.setPortRoles
699
700setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise\<void\>
701
702Sets the role types supported by a specified port, which can be **powerRole** (for charging) and **dataRole** (for data transfer).
703
704**System API**: This is a system API.
705
706**System capability**: SystemCapability.USB.USBManager
707
708**Parameters**
709
710| Name   | Type                            | Mandatory| Description            |
711| --------- | -------------------------------- | ---- | ---------------- |
712| portId    | number                           | Yes  | Port number.        |
713| powerRole | [PowerRoleType](#powerroletype) | Yes  | Role for charging.    |
714| dataRole  | [DataRoleType](#dataroletype)   | Yes  | Role for data transfer.|
715
716**Return value**
717
718| Type           | Description         |
719| --------------- | ------------- |
720| Promise\<void\> | Promise used to return the result.|
721
722**Example**
723
724```js
725let portId = 1;
726usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
727    console.info('usb setPortRoles successfully.');
728}).catch(err => {
729    console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
730});
731```
732
733## USBEndpoint
734
735Represents the USB endpoint from which data is sent or received. You can obtain the USB endpoint through [USBInterface](#usbinterface).
736
737**System capability**: SystemCapability.USB.USBManager
738
739| Name           | Type                                       | Mandatory           |Description           |
740| ------------- | ------------------------------------------- | ------------- |------------- |
741| address       | number                                      | Yes|Endpoint address.        |
742| attributes    | number                                      | Yes|Endpoint attributes.        |
743| interval      | number                                      | Yes|Endpoint interval.        |
744| maxPacketSize | number                                      | Yes|Maximum size of data packets on the endpoint.   |
745| direction     | [USBRequestDirection](#usbrequestdirection) | Yes|Endpoint direction.       |
746| number        | number                                      | Yes|Endpoint number.         |
747| type          | number                                      | Yes|Endpoint type.        |
748| interfaceId   | number                                      | Yes|Unique ID of the interface to which the endpoint belongs.|
749
750## USBInterface
751
752Represents a USB interface. One [USBConfiguration](#usbconfiguration) object can contain multiple **USBInterface** instances, each providing a specific function.
753
754**System capability**: SystemCapability.USB.USBManager
755
756| Name              | Type                                    | Mandatory           |Description                   |
757| ---------------- | ---------------------------------------- | ------------- |--------------------- |
758| id               | number                                   | Yes|Unique ID of the USB interface.             |
759| protocol         | number                                   | Yes|Interface protocol.               |
760| clazz            | number                                   | Yes|Device type.                |
761| subClass         | number                                   | Yes|Device subclass.                |
762| alternateSetting | number                                   | Yes|Settings for alternating between descriptors of the same USB interface.|
763| name             | string                                   | Yes|Interface name.                |
764| endpoints        | Array&lt;[USBEndpoint](#usbendpoint)&gt; | Yes|Endpoints that belong to the USB interface.          |
765
766## USBConfiguration
767
768Represents the USB configuration. One [USBDevice](#usbdevice) can contain multiple **USBConfig** instances.
769
770**System capability**: SystemCapability.USB.USBManager
771
772| Name            | Type                                            | Mandatory |Description             |
773| -------------- | ------------------------------------------------ | --------------- |--------------- |
774| id             | number                                           | Yes|Unique ID of the USB configuration.       |
775| attributes     | number                                           | Yes|Configuration attributes.         |
776| maxPower       | number                                           | Yes|Maximum power consumption, in mA.   |
777| name           | string                                           | Yes|Configuration name, which can be left empty.    |
778| isRemoteWakeup | boolean                                          | Yes|Support for remote wakeup.|
779| isSelfPowered  | boolean                                          | Yes| Support for independent power supplies.|
780| interfaces     | Array&nbsp;&lt;[USBInterface](#usbinterface)&gt; | Yes|Supported interface attributes.     |
781
782## USBDevice
783
784Represents the USB device information.
785
786**System capability**: SystemCapability.USB.USBManager
787
788| Name              | Type                                | Mandatory        |Description        |
789| ---------------- | ------------------------------------ | ---------- |---------- |
790| busNum           | number                               | Yes|Bus address.     |
791| devAddress       | number                               | Yes|Device address.     |
792| serial           | string                               | Yes|Sequence number.      |
793| name             | string                               | Yes|Device name.     |
794| manufacturerName | string                               | Yes| Device manufacturer.     |
795| productName      | string                               | Yes|Product name.     |
796| version          | string                               | Yes|Version number.       |
797| vendorId         | number                               | Yes|Vendor ID.     |
798| productId        | number                               | Yes|Product ID.     |
799| clazz            | number                               | Yes|Device class.      |
800| subClass         | number                               | Yes|Device subclass.     |
801| protocol         | number                               | Yes|Device protocol code.    |
802| configs          | Array&lt;[USBConfiguration](#usbconfiguration)&gt; | Yes|Device configuration descriptor information.|
803
804## USBDevicePipe
805
806Represents a USB device pipe, which is used to determine a USB device.
807
808**System capability**: SystemCapability.USB.USBManager
809
810| Name        | Type  | Mandatory   |Description   |
811| ---------- | ------ | ----- |----- |
812| busNum     | number |Yes| Bus address.|
813| devAddress | number |Yes| Device address.|
814
815## USBControlParams
816
817Represents control transfer parameters.
818
819**System capability**: SystemCapability.USB.USBManager
820
821| Name     | Type                                           | Mandatory              |Description              |
822| ------- | ----------------------------------------------- | ---------------- |---------------- |
823| request | number                                          | Yes  |Request type.           |
824| target  | [USBRequestTargetType](#usbrequesttargettype)   | Yes  |Request target type.         |
825| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes  |Control request type.         |
826| value   | number                                          | Yes  |Request parameter value.           |
827| index   | number                                          | Yes  |Index of the request parameter value.|
828| data    | Uint8Array                                      | Yes  |Buffer for writing or reading data.    |
829
830## USBPort
831
832Represents a USB port.
833
834**System API**: This is a system API.
835
836**System capability**: SystemCapability.USB.USBManager
837
838| Name          | Type                        | Mandatory     |Description                               |
839| -------------- | ------------------------------- | ------------------- |------------------------ |
840| id             | number                          | Yes  |Unique identifier of a USB port.                  |
841| supportedModes | [PortModeType](#portmodetype)   | Yes  |Numeric mask combination for the supported mode list.|
842| status         | [USBPortStatus](#usbportstatus) | Yes  |USB port role.                      |
843
844## USBPortStatus
845
846Enumerates USB port roles.
847
848**System API**: This is a system API.
849
850**System capability**: SystemCapability.USB.USBManager
851
852| Name            | Type| Mandatory     |Description                  |
853| ---------------- | -------- | ---------------- |---------------------- |
854| currentMode      | number   | Yes|Current USB mode.       |
855| currentPowerRole | number   | Yes  |Current power role.    |
856| currentDataRole  | number   | Yes  |Current data role.|
857
858## USBRequestTargetType
859
860Enumerates request target types.
861
862**System capability**: SystemCapability.USB.USBManager
863
864| Name                        | Value  | Description  |
865| ---------------------------- | ---- | ------ |
866| USB_REQUEST_TARGET_DEVICE    | 0    | Device.|
867| USB_REQUEST_TARGET_INTERFACE | 1    | Interface.|
868| USB_REQUEST_TARGET_ENDPOINT  | 2    | Endpoint.|
869| USB_REQUEST_TARGET_OTHER     | 3    | Other.|
870
871## USBControlRequestType
872
873Enumerates control request types.
874
875**System capability**: SystemCapability.USB.USBManager
876
877| Name                     | Value  | Description  |
878| ------------------------- | ---- | ------ |
879| USB_REQUEST_TYPE_STANDARD | 0    | Standard.|
880| USB_REQUEST_TYPE_CLASS    | 1    | Class.  |
881| USB_REQUEST_TYPE_VENDOR   | 2    | Vendor.|
882
883## USBRequestDirection
884
885Enumerates request directions.
886
887**System capability**: SystemCapability.USB.USBManager
888
889| Name                       | Value  | Description                    |
890| --------------------------- | ---- | ------------------------ |
891| USB_REQUEST_DIR_TO_DEVICE   | 0    | Request for writing data from the host to the device.|
892| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | Request for reading data from the device to the host.|
893
894## FunctionType
895
896Enumerates USB device function types.
897
898**System API**: This is a system API.
899
900**System capability**: SystemCapability.USB.USBManager
901
902| Name        | Value  | Description      |
903| ------------ | ---- | ---------- |
904| NONE         | 0    | No function.|
905| ACM          | 1    | ACM function. |
906| ECM          | 2    | ECM function. |
907| HDC          | 4    | HDC function. |
908| MTP          | 8    | Not supported currently.|
909| PTP          | 16   | Not supported currently.|
910| RNDIS        | 32   | Not supported currently.|
911| MIDI         | 64   | Not supported currently.|
912| AUDIO_SOURCE | 128  | Not supported currently.|
913| NCM          | 256  | Not supported currently.|
914
915## PortModeType
916
917Enumerates USB port mode types.
918
919**System API**: This is a system API.
920
921**System capability**: SystemCapability.USB.USBManager
922
923| Name     | Value  | Description                                                |
924| --------- | ---- | ---------------------------------------------------- |
925| NONE      | 0    | None                                                |
926| UFP       | 1    | Upstream facing port, which functions as the sink of power supply.                            |
927| DFP       | 2    | Downstream facing port, which functions as the source of power supply.                            |
928| DRP       | 3    | Dynamic reconfiguration port (DRP), which can function as the DFP (host) or UFP (device). It is not supported currently.|
929| NUM_MODES | 4    | Not supported currently.                                        |
930
931## PowerRoleType
932
933Enumerates power role types.
934
935**System API**: This is a system API.
936
937**System capability**: SystemCapability.USB.USBManager
938
939| Name  | Value  | Description      |
940| ------ | ---- | ---------- |
941| NONE   | 0    | None      |
942| SOURCE | 1    | External power supply.|
943| SINK   | 2    | Internal power supply.|
944
945## DataRoleType
946
947Enumerates data role types.
948
949**System API**: This is a system API.
950
951**System capability**: SystemCapability.USB.USBManager
952
953| Name  | Value  | Description        |
954| ------ | ---- | ------------ |
955| NONE   | 0    | None        |
956| HOST   | 1    | USB host.|
957| DEVICE | 2    | USB device.|
958