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