Java Code Examples for android.hardware.usb.UsbConstants#USB_ENDPOINT_XFER_INT
The following examples show how to use
android.hardware.usb.UsbConstants#USB_ENDPOINT_XFER_INT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UsbHidDevice.java From UsbHid with MIT License | 6 votes |
private UsbHidDevice(UsbDevice usbDevice, UsbInterface usbInterface, UsbManager usbManager) { mUsbDevice = usbDevice; mUsbInterface = usbInterface; mUsbManager= usbManager; for (int i = 0; i < mUsbInterface.getEndpointCount(); i++) { UsbEndpoint endpoint = mUsbInterface.getEndpoint(i); int dir = endpoint.getDirection(); int type = endpoint.getType(); if (mInUsbEndpoint == null && dir == UsbConstants.USB_DIR_IN && type == UsbConstants.USB_ENDPOINT_XFER_INT) { mInUsbEndpoint = endpoint; } if (mOutUsbEndpoint == null && dir == UsbConstants.USB_DIR_OUT && type == UsbConstants.USB_ENDPOINT_XFER_INT) { mOutUsbEndpoint = endpoint; } } }
Example 2
Source File: CdcAcmSerialDriver.java From usb-serial-for-android with GNU Lesser General Public License v2.1 | 6 votes |
private void openSingleInterface() throws IOException { // the following code is inspired by the cdc-acm driver in the linux kernel mControlIndex = 0; mControlInterface = mDevice.getInterface(0); mDataInterface = mDevice.getInterface(0); if (!mConnection.claimInterface(mControlInterface, true)) { throw new IOException("Could not claim shared control/data interface"); } for (int i = 0; i < mControlInterface.getEndpointCount(); ++i) { UsbEndpoint ep = mControlInterface.getEndpoint(i); if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT)) { mControlEndpoint = ep; } else if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { mReadEndpoint = ep; } else if ((ep.getDirection() == UsbConstants.USB_DIR_OUT) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { mWriteEndpoint = ep; } } if (mControlEndpoint == null) { throw new IOException("No control endpoint"); } }
Example 3
Source File: UsbHelper.java From sample-usbenum with Apache License 2.0 | 5 votes |
public static String nameForEndpointType(int type) { switch (type) { case UsbConstants.USB_ENDPOINT_XFER_BULK: return "Bulk"; case UsbConstants.USB_ENDPOINT_XFER_CONTROL: return "Control"; case UsbConstants.USB_ENDPOINT_XFER_INT: return "Interrupt"; case UsbConstants.USB_ENDPOINT_XFER_ISOC: return "Isochronous"; default: return "Unknown Type"; } }
Example 4
Source File: Trezor.java From green_android with GNU General Public License v3.0 | 4 votes |
public static Trezor getDevice(final Context context) { final UsbManager manager = (UsbManager)context.getSystemService(Context.USB_SERVICE); for (final UsbDevice device: manager.getDeviceList().values()) { // Check if the device is TREZOR (or AvalonWallet or BWALLET) final int vendorId = device.getVendorId(); final int productId = device.getProductId(); if ((vendorId != 0x534c || productId != 0x0001) && (vendorId != 0x1209 || productId != 0x53c0) && (vendorId != 0x1209 || productId != 0x53c1) && (vendorId != 0x10c4 || productId != 0xea80)) { continue; } Log.d(TAG, "Hardware Wallet device found"); if (device.getInterfaceCount() < 1) { Log.e(TAG, "Wrong interface count"); continue; } // Use first interface final UsbInterface iface = device.getInterface(0); // Try to find read/write endpoints UsbEndpoint readEndpoint = null, writeEndpoint = null; for (int i = 0; i < iface.getEndpointCount(); ++i) { final UsbEndpoint ep = iface.getEndpoint(i); if (readEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && ep.getAddress() == 0x81) { // number = 1 ; dir = USB_DIR_IN readEndpoint = ep; continue; } if (writeEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && (ep.getAddress() == 0x01 || ep.getAddress() == 0x02)) { // number = 1 ; dir = USB_DIR_OUT writeEndpoint = ep; continue; } Log.d(TAG, String.format("ep %d", ep.getAddress())); } if (isEndpointBad(readEndpoint, "read") || isEndpointBad(writeEndpoint, "write")) continue; // Try to open the device final UsbDeviceConnection conn = manager.openDevice(device); if (conn == null || !conn.claimInterface(iface, true)) { Log.e(TAG, conn == null ? "Could not open connection" : "Could not claim interface"); continue; } // All OK - return the class return new Trezor(device, conn, readEndpoint, writeEndpoint); } return null; }
Example 5
Source File: CdcAcmSerialDriver.java From Chorus-RF-Laptimer with MIT License | 4 votes |
private void openSingleInterface() throws IOException { // the following code is inspired by the cdc-acm driver // in the linux kernel mControlInterface = mDevice.getInterface(0); Log.d(TAG, "Control iface=" + mControlInterface); mDataInterface = mDevice.getInterface(0); Log.d(TAG, "data iface=" + mDataInterface); if (!mConnection.claimInterface(mControlInterface, true)) { throw new IOException("Could not claim shared control/data interface."); } int endCount = mControlInterface.getEndpointCount(); if (endCount < 3) { Log.d(TAG,"not enough endpoints - need 3. count=" + mControlInterface.getEndpointCount()); throw new IOException("Insufficient number of endpoints(" + mControlInterface.getEndpointCount() + ")"); } // Analyse endpoints for their properties mControlEndpoint = null; mReadEndpoint = null; mWriteEndpoint = null; for (int i = 0; i < endCount; ++i) { UsbEndpoint ep = mControlInterface.getEndpoint(i); if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT)) { Log.d(TAG,"Found controlling endpoint"); mControlEndpoint = ep; } else if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { Log.d(TAG,"Found reading endpoint"); mReadEndpoint = ep; } else if ((ep.getDirection() == UsbConstants.USB_DIR_OUT) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { Log.d(TAG,"Found writing endpoint"); mWriteEndpoint = ep; } if ((mControlEndpoint != null) && (mReadEndpoint != null) && (mWriteEndpoint != null)) { Log.d(TAG,"Found all required endpoints"); break; } } if ((mControlEndpoint == null) || (mReadEndpoint == null) || (mWriteEndpoint == null)) { Log.d(TAG,"Could not establish all endpoints"); throw new IOException("Could not establish all endpoints"); } }
Example 6
Source File: CdcAcmSerialDriver.java From OkUSB with Apache License 2.0 | 4 votes |
private void openSingleInterface() throws IOException { // the following code is inspired by the cdc-acm driver // in the linux kernel mControlInterface = mDevice.getInterface(0); Log.d(TAG, "Control iface=" + mControlInterface); mDataInterface = mDevice.getInterface(0); Log.d(TAG, "data iface=" + mDataInterface); if (!mConnection.claimInterface(mControlInterface, true)) { throw new IOException("Could not claim shared control/data interface."); } int endCount = mControlInterface.getEndpointCount(); if (endCount < 3) { Log.d(TAG,"not enough endpoints - need 3. count=" + mControlInterface.getEndpointCount()); throw new IOException("Insufficient number of endpoints(" + mControlInterface.getEndpointCount() + ")"); } // Analyse endpoints for their properties mControlEndpoint = null; mReadEndpoint = null; mWriteEndpoint = null; for (int i = 0; i < endCount; ++i) { UsbEndpoint ep = mControlInterface.getEndpoint(i); if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT)) { Log.d(TAG,"Found controlling endpoint"); mControlEndpoint = ep; } else if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { Log.d(TAG,"Found reading endpoint"); mReadEndpoint = ep; } else if ((ep.getDirection() == UsbConstants.USB_DIR_OUT) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { Log.d(TAG,"Found writing endpoint"); mWriteEndpoint = ep; } if ((mControlEndpoint != null) && (mReadEndpoint != null) && (mWriteEndpoint != null)) { Log.d(TAG,"Found all required endpoints"); break; } } if ((mControlEndpoint == null) || (mReadEndpoint == null) || (mWriteEndpoint == null)) { Log.d(TAG,"Could not establish all endpoints"); throw new IOException("Could not establish all endpoints"); } }
Example 7
Source File: CdcAcmSerialDriver.java From usb-with-serial-port with Apache License 2.0 | 4 votes |
private void openSingleInterface() throws IOException { // the following code is inspired by the cdc-acm driver // in the linux kernel mControlInterface = mDevice.getInterface(0); Log.d(TAG, "Control iface=" + mControlInterface); mDataInterface = mDevice.getInterface(0); Log.d(TAG, "data iface=" + mDataInterface); if (!mConnection.claimInterface(mControlInterface, true)) { throw new IOException("Could not claim shared control/data interface."); } int endCount = mControlInterface.getEndpointCount(); if (endCount < 3) { Log.d(TAG, "not enough endpoints - need 3. count=" + mControlInterface.getEndpointCount()); throw new IOException("Insufficient number of endpoints(" + mControlInterface.getEndpointCount() + ")"); } // Analyse endpoints for their properties mControlEndpoint = null; mReadEndpoint = null; mWriteEndpoint = null; for (int i = 0; i < endCount; ++i) { UsbEndpoint ep = mControlInterface.getEndpoint(i); if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT)) { Log.d(TAG, "Found controlling endpoint"); mControlEndpoint = ep; } else if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { Log.d(TAG, "Found reading endpoint"); mReadEndpoint = ep; } else if ((ep.getDirection() == UsbConstants.USB_DIR_OUT) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { Log.d(TAG, "Found writing endpoint"); mWriteEndpoint = ep; } if ((mControlEndpoint != null) && (mReadEndpoint != null) && (mWriteEndpoint != null)) { Log.d(TAG, "Found all required endpoints"); break; } } if ((mControlEndpoint == null) || (mReadEndpoint == null) || (mWriteEndpoint == null)) { Log.d(TAG, "Could not establish all endpoints"); throw new IOException("Could not establish all endpoints"); } }
Example 8
Source File: Trezor.java From GreenBits with GNU General Public License v3.0 | 4 votes |
public static Trezor getDevice(final Context context, final TrezorGUICallback guiFn, final Network network) { final UsbManager manager = (UsbManager)context.getSystemService(Context.USB_SERVICE); for (final UsbDevice device: manager.getDeviceList().values()) { // Check if the device is TREZOR (or AvalonWallet or BWALLET) final int vendorId = device.getVendorId(); final int productId = device.getProductId(); if ((vendorId != 0x534c || productId != 0x0001) && (vendorId != 0x1209 || productId != 0x53c0) && (vendorId != 0x1209 || productId != 0x53c1) && (vendorId != 0x10c4 || productId != 0xea80)) { continue; } Log.i(TAG, "Hardware Wallet device found"); if (device.getInterfaceCount() < 1) { Log.e(TAG, "Wrong interface count"); continue; } // Use first interface final UsbInterface iface = device.getInterface(0); // Try to find read/write endpoints UsbEndpoint readEndpoint = null, writeEndpoint = null; for (int i = 0; i < iface.getEndpointCount(); ++i) { final UsbEndpoint ep = iface.getEndpoint(i); if (readEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && ep.getAddress() == 0x81) { // number = 1 ; dir = USB_DIR_IN readEndpoint = ep; continue; } if (writeEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && (ep.getAddress() == 0x01 || ep.getAddress() == 0x02)) { // number = 1 ; dir = USB_DIR_OUT writeEndpoint = ep; continue; } Log.e(TAG, String.format("ep %d", ep.getAddress())); } if (!isEndpointOK(readEndpoint, "read") || !isEndpointOK(writeEndpoint, "write")) continue; // Try to open the device final UsbDeviceConnection conn = manager.openDevice(device); if (conn == null || !conn.claimInterface(iface, true)) { Log.e(TAG, conn == null ? "Could not open connection" : "Could not claim interface"); continue; } // All OK - return the class return new Trezor(guiFn, device, conn, readEndpoint, writeEndpoint, network); } return null; }
Example 9
Source File: UsbIpService.java From USBIPServerForAndroid with GNU General Public License v3.0 | 4 votes |
private int detectSpeed(UsbDevice dev, UsbDeviceDescriptor devDesc) { int possibleSpeeds = FLAG_POSSIBLE_SPEED_LOW | FLAG_POSSIBLE_SPEED_FULL | FLAG_POSSIBLE_SPEED_HIGH; for (int i = 0; i < dev.getInterfaceCount(); i++) { UsbInterface iface = dev.getInterface(i); for (int j = 0; j < iface.getEndpointCount(); j++) { UsbEndpoint endpoint = iface.getEndpoint(j); if ((endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) || (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_ISOC)) { // Low speed devices can't implement bulk or iso endpoints possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL) { if (endpoint.getMaxPacketSize() > 8) { // Low speed devices can't use control transfer sizes larger than 8 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getMaxPacketSize() < 64) { // High speed devices can't use control transfer sizes smaller than 64 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) { if (endpoint.getMaxPacketSize() > 8) { // Low speed devices can't use interrupt transfer sizes larger than 8 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getMaxPacketSize() > 64) { // Full speed devices can't use interrupt transfer sizes larger than 64 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_FULL; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { // A bulk endpoint alone can accurately distiniguish between // full and high speed devices if (endpoint.getMaxPacketSize() == 512) { // High speed devices can only use 512 byte bulk transfers possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH; } else { // Otherwise it must be full speed possibleSpeeds = FLAG_POSSIBLE_SPEED_FULL; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_ISOC) { // If the transfer size is 1024, it must be high speed if (endpoint.getMaxPacketSize() == 1024) { possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH; } } } } if (devDesc != null) { if (devDesc.bcdUSB < 0x200) { // High speed only supported on USB 2.0 or higher possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH; } } // Return the lowest speed that we're compatible with System.out.printf("Speed heuristics for device %d left us with 0x%x\n", dev.getDeviceId(), possibleSpeeds); if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_LOW) != 0) { return UsbIpDevice.USB_SPEED_LOW; } else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_FULL) != 0) { return UsbIpDevice.USB_SPEED_FULL; } else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_HIGH) != 0) { return UsbIpDevice.USB_SPEED_HIGH; } else { // Something went very wrong in speed detection return UsbIpDevice.USB_SPEED_UNKNOWN; } }
Example 10
Source File: CdcAcmSerialDriver.java From usb-serial-for-android with GNU Lesser General Public License v2.1 | 4 votes |
private void openInterface() throws IOException { Log.d(TAG, "claiming interfaces, count=" + mDevice.getInterfaceCount()); int controlInterfaceCount = 0; int dataInterfaceCount = 0; mControlInterface = null; mDataInterface = null; for (int i = 0; i < mDevice.getInterfaceCount(); i++) { UsbInterface usbInterface = mDevice.getInterface(i); if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_COMM) { if(controlInterfaceCount == mPortNumber) { mControlIndex = i; mControlInterface = usbInterface; } controlInterfaceCount++; } if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) { if(dataInterfaceCount == mPortNumber) { mDataInterface = usbInterface; } dataInterfaceCount++; } } if(mControlInterface == null) { throw new IOException("No control interface"); } Log.d(TAG, "Control iface=" + mControlInterface); if (!mConnection.claimInterface(mControlInterface, true)) { throw new IOException("Could not claim control interface"); } mControlEndpoint = mControlInterface.getEndpoint(0); if (mControlEndpoint.getDirection() != UsbConstants.USB_DIR_IN || mControlEndpoint.getType() != UsbConstants.USB_ENDPOINT_XFER_INT) { throw new IOException("Invalid control endpoint"); } if(mDataInterface == null) { throw new IOException("No data interface"); } Log.d(TAG, "data iface=" + mDataInterface); if (!mConnection.claimInterface(mDataInterface, true)) { throw new IOException("Could not claim data interface"); } for (int i = 0; i < mDataInterface.getEndpointCount(); i++) { UsbEndpoint ep = mDataInterface.getEndpoint(i); if (ep.getDirection() == UsbConstants.USB_DIR_IN && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) mReadEndpoint = ep; if (ep.getDirection() == UsbConstants.USB_DIR_OUT && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) mWriteEndpoint = ep; } }