Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98ab4619 authored by Casper Bonde's avatar Casper Bonde Committed by Pavlin Radoslavov
Browse files

SAP: Make it possible to enforce a 16-digit pin code (3/5)



This change enable the posibility to enforce using a
16-digit pin or MITM for a RFCOMM or L2CAP connection.

This is needed for the SIM access profile.

Change-Id: I42ada9b36d24d43697a2010eccbc0103f15af77d
Signed-off-by: default avatarCasper Bonde <c.bonde@samsung.com>
parent e80c5aea
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -350,7 +350,8 @@ static void discovery_state_changed_callback(bt_discovery_state_t state) {
    checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
    checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
}
}


static void pin_request_callback(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t cod) {
static void pin_request_callback(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t cod,
        bool min_16_digits) {
    jbyteArray addr, devname;
    jbyteArray addr, devname;
    if (!checkCallbackThread()) {
    if (!checkCallbackThread()) {
       ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
       ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
@@ -370,7 +371,8 @@ static void pin_request_callback(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint


    callbackEnv->SetByteArrayRegion(devname, 0, sizeof(bt_bdname_t), (jbyte*)bdname);
    callbackEnv->SetByteArrayRegion(devname, 0, sizeof(bt_bdname_t), (jbyte*)bdname);


    callbackEnv->CallVoidMethod(sJniCallbacksObj, method_pinRequestCallback, addr, devname, cod);
    callbackEnv->CallVoidMethod(sJniCallbacksObj, method_pinRequestCallback, addr, devname, cod,
            min_16_digits);


    checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
    checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
    callbackEnv->DeleteLocalRef(addr);
    callbackEnv->DeleteLocalRef(addr);
@@ -619,7 +621,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
                                                            "([B[I[[B)V");
                                                            "([B[I[[B)V");
    method_deviceFoundCallback = env->GetMethodID(jniCallbackClass, "deviceFoundCallback", "([B)V");
    method_deviceFoundCallback = env->GetMethodID(jniCallbackClass, "deviceFoundCallback", "([B)V");
    method_pinRequestCallback = env->GetMethodID(jniCallbackClass, "pinRequestCallback",
    method_pinRequestCallback = env->GetMethodID(jniCallbackClass, "pinRequestCallback",
                                                 "([B[BI)V");
                                                 "([B[BIZ)V");
    method_sspRequestCallback = env->GetMethodID(jniCallbackClass, "sspRequestCallback",
    method_sspRequestCallback = env->GetMethodID(jniCallbackClass, "sspRequestCallback",
                                                 "([B[BIII)V");
                                                 "([B[BIII)V");


+4 −1
Original line number Original line Diff line number Diff line
@@ -1671,7 +1671,10 @@ public class AdapterService extends Service {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                       "Need BLUETOOTH ADMIN permission");
                                       "Need BLUETOOTH ADMIN permission");
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp == null || deviceProp.getBondState() != BluetoothDevice.BOND_BONDING) {
        // Only allow setting a pin in bonding state, or bonded state in case of security upgrade.
        if (deviceProp == null ||
            (deviceProp.getBondState() != BluetoothDevice.BOND_BONDING &&
             deviceProp.getBondState() != BluetoothDevice.BOND_BONDED)) {
            return false;
            return false;
        }
        }


+13 −5
Original line number Original line Diff line number Diff line
@@ -235,10 +235,16 @@ final class BondStateMachine extends StateMachine {
                                 BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN);
                                 BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN);
                        break;
                        break;
                    }
                    }

                    if (msg.arg2 == 1) { // Minimum 16 digit pin required here
                        sendDisplayPinIntent(devProp.getAddress(), 0,
                                BluetoothDevice.PAIRING_VARIANT_PIN_16_DIGITS);
                    } else {
                        // In PIN_REQUEST, there is no passkey to display.So do not send the
                        // In PIN_REQUEST, there is no passkey to display.So do not send the
                        // EXTRA_PAIRING_KEY type in the intent( 0 in SendDisplayPinIntent() )
                        // EXTRA_PAIRING_KEY type in the intent( 0 in SendDisplayPinIntent() )
                        sendDisplayPinIntent(devProp.getAddress(), 0,
                        sendDisplayPinIntent(devProp.getAddress(), 0,
                                              BluetoothDevice.PAIRING_VARIANT_PIN);
                                              BluetoothDevice.PAIRING_VARIANT_PIN);
                    }


                    break;
                    break;
                default:
                default:
@@ -402,8 +408,9 @@ final class BondStateMachine extends StateMachine {
        sendMessage(msg);
        sendMessage(msg);
    }
    }


    void pinRequestCallback(byte[] address, byte[] name, int cod) {
    void pinRequestCallback(byte[] address, byte[] name, int cod, boolean min16Digits) {
        //TODO(BT): Get wakelock and update name and cod
        //TODO(BT): Get wakelock and update name and cod

        BluetoothDevice bdDevice = mRemoteDevices.getDevice(address);
        BluetoothDevice bdDevice = mRemoteDevices.getDevice(address);
        if (bdDevice == null) {
        if (bdDevice == null) {
            mRemoteDevices.addDeviceProperties(address);
            mRemoteDevices.addDeviceProperties(address);
@@ -413,6 +420,7 @@ final class BondStateMachine extends StateMachine {


        Message msg = obtainMessage(PIN_REQUEST);
        Message msg = obtainMessage(PIN_REQUEST);
        msg.obj = bdDevice;
        msg.obj = bdDevice;
        msg.arg2 = min16Digits ? 1 : 0; // Use arg2 to pass the min16Digit boolean


        sendMessage(msg);
        sendMessage(msg);
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -58,8 +58,8 @@ final class JniCallbacks {
        mRemoteDevices.deviceFoundCallback(address);
        mRemoteDevices.deviceFoundCallback(address);
    }
    }


    void pinRequestCallback(byte[] address, byte[] name, int cod) {
    void pinRequestCallback(byte[] address, byte[] name, int cod, boolean min16Digits) {
        mBondStateMachine.pinRequestCallback(address, name, cod);
        mBondStateMachine.pinRequestCallback(address, name, cod, min16Digits);
    }
    }


    void bondStateChangeCallback(int status, byte[] address, int newState) {
    void bondStateChangeCallback(int status, byte[] address, int newState) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -146,7 +146,7 @@ public class SapService extends ProfileService {
                // TODO: Consider reusing the mServerSocket - it is indented to be reused
                // TODO: Consider reusing the mServerSocket - it is indented to be reused
                //       for multiple connections.
                //       for multiple connections.
                mServerSocket = mAdapter.listenUsingRfcommOn(
                mServerSocket = mAdapter.listenUsingRfcommOn(
                        BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, true);
                        BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, true, true);
                if (mSdpHandle >= 0) {
                if (mSdpHandle >= 0) {
                    SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
                    SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
                    if (VERBOSE) Log.d(TAG, "Removing SDP record");
                    if (VERBOSE) Log.d(TAG, "Removing SDP record");
Loading