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