com.btchip.comm.BTChipTransport Java Examples

The following examples show how to use com.btchip.comm.BTChipTransport. 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: RequestLoginActivity.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void tagDiscovered(final Tag t) {
    Log.d(TAG, "tagDiscovered " + t);
    mTag = t;
    if (mTransportFuture == null)
        return;

    final BTChipTransport transport = getTransport(t);
    if (transport == null)
        return;

    if (mTransportFuture.set(transport)) {
        if (mNfcWaitDialog == null)
            return;

        runOnUiThread(new Runnable() { public void run() { mNfcWaitDialog.hide(); } });
    }
}
 
Example #2
Source File: RequestLoginActivity.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
private BTChipTransport getTransport(final Tag t) {
    BTChipTransport transport = null;
    if (t != null) {
        AndroidCard card = null;
        Log.d(TAG, "Start checking NFC transport");
        try {
            card = AndroidCard.get(t);
            transport = new BTChipTransportAndroidNFC(card);
            transport.setDebug(BuildConfig.DEBUG);
            transport.exchange(DUMMY_COMMAND).get();
            Log.d(TAG, "NFC transport checked");
        }
        catch (final Exception e) {
            Log.d(TAG, "Tag was lost", e);
            if (card != null) {
                try {
                    transport.close();
                }
                catch (final Exception e1) {
                }
                transport = null;
            }
        }
    }
    return transport;
}
 
Example #3
Source File: BTChipTransportAndroidHID.java    From xmrwallet with Apache License 2.0 6 votes vote down vote up
public static BTChipTransport open(UsbManager manager, UsbDevice device) throws IOException {
    UsbDeviceConnection connection = manager.openDevice(device);
    if (connection == null) throw new IOException("Device not connected");
    // Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
    // Important if enumerating, rather than being awaken by the intent notification
    UsbInterface dongleInterface = device.getInterface(0);
    UsbEndpoint in = null;
    UsbEndpoint out = null;
    for (int i = 0; i < dongleInterface.getEndpointCount(); i++) {
        UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
        if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
            in = tmpEndpoint;
        } else {
            out = tmpEndpoint;
        }
    }
    connection.claimInterface(dongleInterface, true);
    return new BTChipTransportAndroidHID(connection, dongleInterface, in, out);
}
 
Example #4
Source File: BTChipTransportAndroid.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static BTChipTransport open(UsbManager manager, UsbDevice device) {
	// Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
	// Important if enumerating, rather than being awaken by the intent notification
	UsbInterface dongleInterface = device.getInterface(0);
       UsbEndpoint in = null;
       UsbEndpoint out = null;
       boolean ledger; 
       for (int i=0; i<dongleInterface.getEndpointCount(); i++) {
           UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
           if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
               in = tmpEndpoint;
           }
           else {
               out = tmpEndpoint;
           }
       }
       UsbDeviceConnection connection = manager.openDevice(device);
       if (connection == null) {
           return null;
       }
       connection.claimInterface(dongleInterface, true);
       ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON)
	|| (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) || (device.getProductId() == PID_NANOX));
       if (device.getProductId() == PID_WINUSB) {
       	return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT);
       }
       else {
       	return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger);
       }
}
 
Example #5
Source File: BTChipTransportAndroid.java    From WalletCordova with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static BTChipTransport open(UsbManager manager, UsbDevice device) {
	// Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
	// Important if enumerating, rather than being awaken by the intent notification
	UsbInterface dongleInterface = device.getInterface(0);
       UsbEndpoint in = null;
       UsbEndpoint out = null;
       boolean ledger; 
       for (int i=0; i<dongleInterface.getEndpointCount(); i++) {
           UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
           if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
               in = tmpEndpoint;
           }
           else {
               out = tmpEndpoint;
           }
       }
       UsbDeviceConnection connection = manager.openDevice(device);
       connection.claimInterface(dongleInterface, true);
       ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON)
	|| (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE));
       if (device.getProductId() == PID_WINUSB) {
       	return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT);
       }
       else {
       	return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger);
       }
}
 
Example #6
Source File: BTChipTransportAndroid.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public static BTChipTransport open(UsbManager manager, UsbDevice device) {
	// Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
	// Important if enumerating, rather than being awaken by the intent notification
	UsbInterface dongleInterface = device.getInterface(0);
       UsbEndpoint in = null;
       UsbEndpoint out = null;
       boolean ledger; 
       for (int i=0; i<dongleInterface.getEndpointCount(); i++) {
           UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
           if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
               in = tmpEndpoint;
           }
           else {
               out = tmpEndpoint;
           }
       }
       UsbDeviceConnection connection = manager.openDevice(device);
       if (connection == null) {
           return null;
       }
       connection.claimInterface(dongleInterface, true);
       ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON)
	|| (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE));
       if (device.getProductId() == PID_WINUSB) {
       	return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT);
       }
       else {
       	return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger);
       }
}
 
Example #7
Source File: BTChipHWWallet.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public void setTransport(final BTChipTransport transport) {
    mDongle.setTransport(transport);
    try {
            mDongle.verifyPin(mPin.getBytes());
    }
    catch(final Exception e) {
    }
}
 
Example #8
Source File: Ledger.java    From xmrwallet with Apache License 2.0 5 votes vote down vote up
private Ledger(UsbManager usbManager, UsbDevice usbDevice) throws IOException {
    final BTChipTransport transport = BTChipTransportAndroidHID.open(usbManager, usbDevice);
    Timber.d("transport opened = %s", transport.toString());
    transport.setDebug(BuildConfig.DEBUG);
    this.transport = transport;
    this.name = usbDevice.getManufacturerName() + " " + usbDevice.getProductName();
    initKey();
}
 
Example #9
Source File: LedgerTransportTEEProxyFactory.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BTChipTransport getTransport() {
	if (transport == null) {
		transport = new LedgerTransportTEEProxy(context);
	}
	return transport;
}
 
Example #10
Source File: BTChipDongle.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public BTChipDongle(BTChipTransport transport) {
	this.transport = transport;
}
 
Example #11
Source File: BTChipDongle.java    From WalletCordova with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void setTransport(BTChipTransport transport) {
	this.transport = transport;
}
 
Example #12
Source File: BTChipDongle.java    From WalletCordova with GNU Lesser General Public License v2.1 4 votes vote down vote up
public BTChipTransport getTransport() {
	return transport;
}
 
Example #13
Source File: BTChipDongle.java    From WalletCordova with GNU Lesser General Public License v2.1 4 votes vote down vote up
public BTChipDongle(BTChipTransport transport, boolean understandsMultipleOutputs) {
	this.transport = transport;
	this.mUnderstandsMultipleOutputs = understandsMultipleOutputs;
}
 
Example #14
Source File: BTChipDongle.java    From WalletCordova with GNU Lesser General Public License v2.1 4 votes vote down vote up
public BTChipDongle(BTChipTransport transport) {
	this.transport = transport;
}
 
Example #15
Source File: BTChipTransportAndroid.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BTChipTransport getTransport() {
	return transport;
}
 
Example #16
Source File: BTChipTransportAndroid.java    From WalletCordova with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public BTChipTransport getTransport() {
	return transport;
}
 
Example #17
Source File: BTChipDongle.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public void setTransport(BTChipTransport transport) {
	this.transport = transport;
}
 
Example #18
Source File: BTChipDongle.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public BTChipTransport getTransport() {
	return transport;
}
 
Example #19
Source File: BTChipDongle.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public BTChipDongle(BTChipTransport transport, boolean understandsMultipleOutputs) {
	this.transport = transport;
	this.mUnderstandsMultipleOutputs = understandsMultipleOutputs;
}
 
Example #20
Source File: BTChipDongle.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
public BTChipDongle(BTChipTransport transport, boolean supportScreen) {
	this.transport = transport;
	this.supportScreen = supportScreen;
}
 
Example #21
Source File: BTChipTransportAndroid.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BTChipTransport getTransport() {
	return transport;
}
 
Example #22
Source File: BTChipDongle.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
public BTChipTransport getTransport() {
	return transport;
}
 
Example #23
Source File: BTChipDongle.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
public void setTransport(BTChipTransport transport) {
	this.transport = transport;
}
 
Example #24
Source File: RequestLoginActivity.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
private void onLedgerConnected(final BTChipTransport transport, final String pin) {
    runOnUiThread(new Runnable() { public void run() { UI.show(mLoginProgress); } });

    final SettableFuture<Integer> pinCB = SettableFuture.create();

    final boolean havePin = !TextUtils.isEmpty(pin);
    Log.d(TAG, "Creating HW wallet" + (havePin ? " with PIN" : ""));
    if (havePin)
        mHwWallet = new BTChipHWWallet(transport, pin, pinCB, mService.getNetwork());
    else
        mHwWallet = new BTChipHWWallet(transport, mService.getNetwork());

    // Try to log in once we are connected
    Futures.addCallback(Futures.transformAsync(mService.onConnected, new AsyncFunction<Void, LoginData>() {
        @Override
        public ListenableFuture<LoginData> apply(final Void input) {
            if (!havePin)
                return mService.login(mHwWallet); // Login directly

            // Otherwise, log in once the users PIN is correct
            return Futures.transformAsync(pinCB, new AsyncFunction<Integer, LoginData>() {
                @Override
                public ListenableFuture<LoginData> apply(final Integer remainingAttempts) {
                    if (remainingAttempts == -1)
                        return mService.login(mHwWallet); // -1 means success, so login

                    final String msg;
                    if (remainingAttempts > 0)
                        msg = getString(R.string.btchipInvalidPIN, remainingAttempts);
                    else
                        msg = getString(R.string.btchipNotSetup);

                    runOnUiThread(new Runnable() {
                        public void run() {
                            toast(msg);
                            finish();
                        }
                    });
                    return Futures.immediateFuture(null);
                }
            });
        }
    }), mOnLoggedIn);
}
 
Example #25
Source File: RequestLoginActivity.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
private void setupLedgerConnection() {
    showInstructions(R.string.logging_in);
    final String pin = mPin;
    mPin = null;

    final BTChipTransport transport;
    if (mUsb != null) {
        transport = BTChipTransportAndroid.open(mUsbManager, mUsb);
        if (transport == null) {
            showInstructions(R.string.hw_wallet_reconnect);
            return;
        }
    } else if ((transport = getTransport(mTag)) == null) {
        showInstructions(R.string.hw_wallet_headline);

        // Prompt the user to tap
        runOnUiThread(new Runnable() {
            public void run() {
                mNfcWaitDialog = new MaterialDialog.Builder(RequestLoginActivity.this)
                    .title(R.string.btchip).content(R.string.please_tap_card).build();
                mNfcWaitDialog.show();
            }
        });
        return;
    }

    transport.setDebug(BuildConfig.DEBUG);
    try {
        final BTChipFirmware fw = (new BTChipDongle(transport, true)).getFirmwareVersion();
        final int major = fw.getMajor(), minor = fw.getMinor(), patch = fw.getPatch();

        Log.d(TAG, "BTChip/Ledger firmware version " + fw.toString() + '(' +
                major + '.' + minor + '.' + patch + ')');

        boolean isFirmwareOutdated = false;
        if (mVendorId == VENDOR_BTCHIP) {
            isFirmwareOutdated = major < 0x2001 ||
                (major == 0x2001 && minor < 0) || // Just for consistency in checking code
                (major == 0x2001 && minor == 0 && patch < 4);
        } else if (mVendorId == VENDOR_LEDGER) {
            isFirmwareOutdated = major < 0x3001 ||
                (major == 0x3001 && minor < 2) ||
                (major == 0x3001 && minor == 2 && patch < 5);
        }

        if (!isFirmwareOutdated) {
            onLedgerConnected(transport, pin);
            return;
        }

        showFirmwareOutdated(R.string.ledger_firmware_outdated,
                             new Runnable() { public void run() { onLedgerConnected(transport, pin); } });
    } catch (final BTChipException e) {
        if (e.getSW() != BTChipConstants.SW_INS_NOT_SUPPORTED)
            e.printStackTrace();
        // We are in dashboard mode, prompt the user to open the btcoin app.
        showInstructions(R.string.ledger_open_bitcoin_app);
    }
}
 
Example #26
Source File: BTChipHWWallet.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public BTChipHWWallet(final BTChipTransport transport, final Network network) {
    this(transport, null, network);
}
 
Example #27
Source File: BTChipHWWallet.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
private BTChipHWWallet(final BTChipTransport transport, final String pin, final Network network) {
    mDongle = new BTChipDongle(transport);
    mPin = pin;
    mAddrn = new LinkedList<>();
    mNetwork = network;
}