• 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();
33cconsole.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 = new usb.USBControlParams();
458usb.controlTransfer(devicepipe, param).then((ret) => {
459 console.log(`controlTransfer = ${ret}`);
460})
461```
462
463## usb.bulkTransfer
464
465bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise<number>
466
467Performs bulk transfer.
468
469Before 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.
470
471**System capability**: SystemCapability.USB.USBManager
472
473**Parameters**
474
475| Name| Type| Mandatory| Description|
476| -------- | -------- | -------- | -------- |
477| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
478| endpoint | [USBEndpoint](#usbendpoint) | Yes| USB endpoint, which is used to determine the USB port for data transfer.|
479| buffer | Uint8Array | Yes| Buffer for writing or reading data.|
480| timeout | number | No| Timeout duration in ms. This parameter is optional. The default value is **0**, indicating no timeout.|
481
482**Return value**
483
484| Type| Description|
485| -------- | -------- |
486| 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.|
487
488**Example**
489
490```js
491// Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
492// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
493// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
494usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
495 console.log(`bulkTransfer = ${ret}`);
496});
497```
498
499## usb.closePipe
500
501closePipe(pipe: USBDevicePipe): number
502
503Closes a USB device pipe.
504
505Before 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.
506
507**System capability**: SystemCapability.USB.USBManager
508
509**Parameters**
510
511| Name| Type| Mandatory| Description|
512| -------- | -------- | -------- | -------- |
513| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe.|
514
515**Return value**
516
517| Type| Description|
518| -------- | -------- |
519| number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.|
520
521**Example**
522
523```js
524let ret = usb.closePipe(devicepipe);
525console.log(`closePipe = ${ret}`);
526```
527
528## usb.usbFunctionsFromString
529
530usbFunctionsFromString(funcs: string): number
531
532Converts the USB function list in the string format to a numeric mask in Device mode.
533
534**System API**: This is a system API.
535
536**System capability**: SystemCapability.USB.USBManager
537
538**Parameters**
539
540| Name| Type  | Mandatory| Description                  |
541| ------ | ------ | ---- | ---------------------- |
542| funcs  | string | Yes  | Function list in string format.|
543
544**Return value**
545
546| Type  | Description              |
547| ------ | ------------------ |
548| number | Function list in numeric mask format.|
549
550**Example**
551
552```js
553let funcs = "acm";
554let ret = usb.usbFunctionsFromString(funcs);
555```
556
557## usb.usbFunctionsToString
558
559usbFunctionsToString(funcs: FunctionType): string
560
561Converts the USB function list in the numeric mask format to a string in Device mode.
562
563**System API**: This is a system API.
564
565**System capability**: SystemCapability.USB.USBManager
566
567**Parameters**
568
569| Name| Type                          | Mandatory| Description             |
570| ------ | ------------------------------ | ---- | ----------------- |
571| funcs  | [FunctionType](#functiontype) | Yes  | USB function list in numeric mask format.|
572
573**Return value**
574
575| Type  | Description                          |
576| ------ | ------------------------------ |
577| string | Function list in string format.|
578
579**Example**
580
581```js
582let funcs = usb.ACM | usb.ECM;
583let ret = usb.usbFunctionsToString(funcs);
584```
585
586## usb.setCurrentFunctions
587
588setCurrentFunctions(funcs: FunctionType): Promise\<void\>
589
590Sets the current USB function list in Device mode.
591
592**System API**: This is a system API.
593
594**System capability**: SystemCapability.USB.USBManager
595
596**Parameters**
597
598| Name| Type                          | Mandatory| Description             |
599| ------ | ------------------------------ | ---- | ----------------- |
600| funcs  | [FunctionType](#functiontype) | Yes  | USB function list in numeric mask format.|
601
602**Return value**
603
604| Type           | Description         |
605| --------------- | ------------- |
606| Promise\<void\> | Promise used to return the result.|
607
608**Example**
609
610```js
611let funcs = usb.HDC;
612usb.setCurrentFunctions(funcs).then(() => {
613    console.info('usb setCurrentFunctions successfully.');
614}).catch(err => {
615    console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message);
616});
617```
618
619## usb.getCurrentFunctions
620
621getCurrentFunctions(): FunctionType
622
623Obtains the numeric mask combination for the USB function list in Device mode.
624
625**System API**: This is a system API.
626
627**System capability**: SystemCapability.USB.USBManager
628
629**Return value**
630
631| Type                          | Description                             |
632| ------------------------------ | --------------------------------- |
633| [FunctionType](#functiontype) | Numeric mask combination for the USB function list.|
634
635**Example**
636
637```js
638let ret = usb.getCurrentFunctions();
639```
640
641## usb.getPorts
642
643getPorts(): Array\<USBPort\>
644
645Obtains the list of all physical USB ports.
646
647**System API**: This is a system API.
648
649**System capability**: SystemCapability.USB.USBManager
650
651**Return value**
652
653| Type                         | Description                 |
654| ----------------------------- | --------------------- |
655| [Array\<USBPort\>](#usbport) | List of physical USB ports.|
656
657**Example**
658
659```js
660let ret = usb.getPorts();
661```
662
663## usb.getSupportedModes
664
665getSupportedModes(portId: number): PortModeType
666
667Obtains the mask combination for the supported mode list of a given USB port.
668
669**System API**: This is a system API.
670
671**System capability**: SystemCapability.USB.USBManager
672
673**Parameters**
674
675| Name| Type  | Mandatory| Description    |
676| ------ | ------ | ---- | -------- |
677| portId | number | Yes  | Port number.|
678
679**Return value**
680
681| Type                          | Description                      |
682| ------------------------------ | -------------------------- |
683| [PortModeType](#portmodetype) | Mask combination for the supported mode list.|
684
685**Example**
686
687```js
688let ret = usb.getSupportedModes(0);
689```
690
691## usb.setPortRoles
692
693setPortRoles(portId: number, powerRole: PowerRoleType, dataRole: DataRoleType): Promise\<void\>
694
695Sets the role types supported by a specified port, which can be **powerRole** (for charging) and **dataRole** (for data transfer).
696
697**System API**: This is a system API.
698
699**System capability**: SystemCapability.USB.USBManager
700
701**Parameters**
702
703| Name   | Type                            | Mandatory| Description            |
704| --------- | -------------------------------- | ---- | ---------------- |
705| portId    | number                           | Yes  | Port number.        |
706| powerRole | [PowerRoleType](#powerroletype) | Yes  | Role for charging.    |
707| dataRole  | [DataRoleType](#dataroletype)   | Yes  | Role for data transfer.|
708
709**Return value**
710
711| Type           | Description         |
712| --------------- | ------------- |
713| Promise\<void\> | Promise used to return the result.|
714
715**Example**
716
717```js
718let portId = 1;
719usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
720    console.info('usb setPortRoles successfully.');
721}).catch(err => {
722    console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
723});
724```
725
726## USBEndpoint
727
728Represents the USB endpoint from which data is sent or received. You can obtain the USB endpoint through [USBInterface](#usbinterface).
729
730**System capability**: SystemCapability.USB.USBManager
731
732| Name           | Type                                       | Mandatory           |Description           |
733| ------------- | ------------------------------------------- | ------------- |------------- |
734| address       | number                                      | Yes|Endpoint address.        |
735| attributes    | number                                      | Yes|Endpoint attributes.        |
736| interval      | number                                      | Yes|Endpoint interval.        |
737| maxPacketSize | number                                      | Yes|Maximum size of data packets on the endpoint.   |
738| direction     | [USBRequestDirection](#usbrequestdirection) | Yes|Endpoint direction.       |
739| number        | number                                      | Yes|Endpoint number.         |
740| type          | number                                      | Yes|Endpoint type.        |
741| interfaceId   | number                                      | Yes|Unique ID of the interface to which the endpoint belongs.|
742
743## USBInterface
744
745Represents a USB interface. One [USBConfiguration](#usbconfiguration) object can contain multiple **USBInterface** instances, each providing a specific function.
746
747**System capability**: SystemCapability.USB.USBManager
748
749| Name              | Type                                    | Mandatory           |Description                   |
750| ---------------- | ---------------------------------------- | ------------- |--------------------- |
751| id               | number                                   | Yes|Unique ID of the USB interface.             |
752| protocol         | number                                   | Yes|Interface protocol.               |
753| clazz            | number                                   | Yes|Device type.                |
754| subClass         | number                                   | Yes|Device subclass.                |
755| alternateSetting | number                                   | Yes|Settings for alternating between descriptors of the same USB interface.|
756| name             | string                                   | Yes|Interface name.                |
757| endpoints        | Array&lt;[USBEndpoint](#usbendpoint)&gt; | Yes|Endpoints that belong to the USB interface.          |
758
759## USBConfiguration
760
761Represents the USB configuration. One [USBDevice](#usbdevice) can contain multiple **USBConfig** instances.
762
763**System capability**: SystemCapability.USB.USBManager
764
765| Name            | Type                                            | Mandatory |Description             |
766| -------------- | ------------------------------------------------ | --------------- |--------------- |
767| id             | number                                           | Yes|Unique ID of the USB configuration.       |
768| attributes     | number                                           | Yes|Configuration attributes.         |
769| maxPower       | number                                           | Yes|Maximum power consumption, in mA.   |
770| name           | string                                           | Yes|Configuration name, which can be left empty.    |
771| isRemoteWakeup | boolean                                          | Yes|Support for remote wakeup.|
772| isSelfPowered  | boolean                                          | Yes| Support for independent power supplies.|
773| interfaces     | Array&nbsp;&lt;[USBInterface](#usbinterface)&gt; | Yes|Supported interface attributes.     |
774
775## USBDevice
776
777Represents the USB device information.
778
779**System capability**: SystemCapability.USB.USBManager
780
781| Name              | Type                                | Mandatory        |Description        |
782| ---------------- | ------------------------------------ | ---------- |---------- |
783| busNum           | number                               | Yes|Bus address.     |
784| devAddress       | number                               | Yes|Device address.     |
785| serial           | string                               | Yes|Sequence number.      |
786| name             | string                               | Yes|Device name.     |
787| manufacturerName | string                               | Yes| Device manufacturer.     |
788| productName      | string                               | Yes|Product name.     |
789| version          | string                               | Yes|Version number.       |
790| vendorId         | number                               | Yes|Vendor ID.     |
791| productId        | number                               | Yes|Product ID.     |
792| clazz            | number                               | Yes|Device class.      |
793| subClass         | number                               | Yes|Device subclass.     |
794| protocol         | number                               | Yes|Device protocol code.    |
795| configs          | Array&lt;[USBConfiguration](#usbconfiguration)&gt; | Yes|Device configuration descriptor information.|
796
797## USBDevicePipe
798
799Represents a USB device pipe, which is used to determine a USB device.
800
801**System capability**: SystemCapability.USB.USBManager
802
803| Name        | Type  | Mandatory   |Description   |
804| ---------- | ------ | ----- |----- |
805| busNum     | number |Yes| Bus address.|
806| devAddress | number |Yes| Device address.|
807
808## USBControlParams
809
810Represents control transfer parameters.
811
812**System capability**: SystemCapability.USB.USBManager
813
814| Name     | Type                                           | Mandatory              |Description              |
815| ------- | ----------------------------------------------- | ---------------- |---------------- |
816| request | number                                          | Yes  |Request type.           |
817| target  | [USBRequestTargetType](#usbrequesttargettype)   | Yes  |Request target type.         |
818| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes  |Control request type.         |
819| value   | number                                          | Yes  |Request parameter value.           |
820| index   | number                                          | Yes  |Index of the request parameter value.|
821| data    | Uint8Array                                      | Yes  |Buffer for writing or reading data.    |
822
823## USBPort
824
825Represents a USB port.
826
827**System API**: This is a system API.
828
829**System capability**: SystemCapability.USB.USBManager
830
831| Name          | Type                        | Mandatory     |Description                               |
832| -------------- | ------------------------------- | ------------------- |------------------------ |
833| id             | number                          | Yes  |Unique identifier of a USB port.                  |
834| supportedModes | [PortModeType](#portmodetype)   | Yes  |Numeric mask combination for the supported mode list.|
835| status         | [USBPortStatus](#usbportstatus) | Yes  |USB port role.                      |
836
837## USBPortStatus
838
839Enumerates USB port roles.
840
841**System API**: This is a system API.
842
843**System capability**: SystemCapability.USB.USBManager
844
845| Name            | Type| Mandatory     |Description                  |
846| ---------------- | -------- | ---------------- |---------------------- |
847| currentMode      | number   | Yes|Current USB mode.       |
848| currentPowerRole | number   | Yes  |Current power role.    |
849| currentDataRole  | number   | Yes  |Current data role.|
850
851## USBRequestTargetType
852
853Enumerates request target types.
854
855**System capability**: SystemCapability.USB.USBManager
856
857| Name                        | Value  | Description  |
858| ---------------------------- | ---- | ------ |
859| USB_REQUEST_TARGET_DEVICE    | 0    | Device.|
860| USB_REQUEST_TARGET_INTERFACE | 1    | Interface.|
861| USB_REQUEST_TARGET_ENDPOINT  | 2    | Endpoint.|
862| USB_REQUEST_TARGET_OTHER     | 3    | Other.|
863
864## USBControlRequestType
865
866Enumerates control request types.
867
868**System capability**: SystemCapability.USB.USBManager
869
870| Name                     | Value  | Description  |
871| ------------------------- | ---- | ------ |
872| USB_REQUEST_TYPE_STANDARD | 0    | Standard.|
873| USB_REQUEST_TYPE_CLASS    | 1    | Class.  |
874| USB_REQUEST_TYPE_VENDOR   | 2    | Vendor.|
875
876## USBRequestDirection
877
878Enumerates request directions.
879
880**System capability**: SystemCapability.USB.USBManager
881
882| Name                       | Value  | Description                    |
883| --------------------------- | ---- | ------------------------ |
884| USB_REQUEST_DIR_TO_DEVICE   | 0    | Request for writing data from the host to the device.|
885| USB_REQUEST_DIR_FROM_DEVICE | 0x80 | Request for reading data from the device to the host.|
886
887## FunctionType
888
889Enumerates USB device function types.
890
891**System API**: This is a system API.
892
893**System capability**: SystemCapability.USB.USBManager
894
895| Name        | Value  | Description      |
896| ------------ | ---- | ---------- |
897| NONE         | 0    | No function.|
898| ACM          | 1    | ACM function. |
899| ECM          | 2    | ECM function. |
900| HDC          | 4    | HDC function. |
901| MTP          | 8    | Not supported currently.|
902| PTP          | 16   | Not supported currently.|
903| RNDIS        | 32   | Not supported currently.|
904| MIDI         | 64   | Not supported currently.|
905| AUDIO_SOURCE | 128  | Not supported currently.|
906| NCM          | 256  | Not supported currently.|
907
908## PortModeType
909
910Enumerates USB port mode types.
911
912**System API**: This is a system API.
913
914**System capability**: SystemCapability.USB.USBManager
915
916| Name     | Value  | Description                                                |
917| --------- | ---- | ---------------------------------------------------- |
918| NONE      | 0    | None                                                |
919| UFP       | 1    | Upstream facing port, which functions as the sink of power supply.                            |
920| DFP       | 2    | Downstream facing port, which functions as the source of power supply.                            |
921| DRP       | 3    | Dynamic reconfiguration port (DRP), which can function as the DFP (host) or UFP (device). It is not supported currently.|
922| NUM_MODES | 4    | Not supported currently.                                        |
923
924## PowerRoleType
925
926Enumerates power role types.
927
928**System API**: This is a system API.
929
930**System capability**: SystemCapability.USB.USBManager
931
932| Name  | Value  | Description      |
933| ------ | ---- | ---------- |
934| NONE   | 0    | None      |
935| SOURCE | 1    | External power supply.|
936| SINK   | 2    | Internal power supply.|
937
938## DataRoleType
939
940Enumerates data role types.
941
942**System API**: This is a system API.
943
944**System capability**: SystemCapability.USB.USBManager
945
946| Name  | Value  | Description        |
947| ------ | ---- | ------------ |
948| NONE   | 0    | None        |
949| HOST   | 1    | USB host.|
950| DEVICE | 2    | USB device.|
951