summaryrefslogtreecommitdiffstats
path: root/core/java/android/bluetooth
diff options
context:
space:
mode:
authorMathias Jeppsson <mathias.jeppsson@sonyericsson.com>2011-03-21 15:06:52 +0100
committerJohan Redestig <johan.redestig@sonyericsson.com>2011-05-17 07:52:15 +0200
commite3b9dc107ea10645e064581460829d262c911f1c (patch)
tree1d1a4d6a643d0b2d64c68c2a876a7cb619ec16d8 /core/java/android/bluetooth
parentf247e545b521584bb778e79710c1e60ab814839e (diff)
downloadframeworks_base-e3b9dc107ea10645e064581460829d262c911f1c.zip
frameworks_base-e3b9dc107ea10645e064581460829d262c911f1c.tar.gz
frameworks_base-e3b9dc107ea10645e064581460829d262c911f1c.tar.bz2
Require bonding and encryption for PBAP server
The Phonebook Access Profile specification requires bonding and encryption. For devices not supporting SSP (Secure Simple Pairing), InsecureRfcomm will require neither. Adding EncryptedRfcomm to force bonding and encryption but not requiring authenticated link key. Change-Id: If47cca9c5ffd89358bcd61d64f7785d17e0ca7cc
Diffstat (limited to 'core/java/android/bluetooth')
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java66
1 files changed, 63 insertions, 3 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index a7175e3..66a7450 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -799,10 +799,10 @@ public final class BluetoothAdapter {
/**
* Create a listening, insecure RFCOMM Bluetooth socket with Service Record.
- * <p>The link key will be unauthenticated i.e the communication is
+ * <p>The link key is not required to be authenticated, i.e the communication may be
* vulnerable to Man In the Middle attacks. For Bluetooth 2.1 devices,
- * the link key will be encrypted, as encryption is mandartory.
- * For legacy devices (pre Bluetooth 2.1 devices) the link key will not
+ * the link will be encrypted, as encryption is mandartory.
+ * For legacy devices (pre Bluetooth 2.1 devices) the link will not
* be encrypted. Use {@link #listenUsingRfcommWithServiceRecord}, if an
* encrypted and authenticated communication channel is desired.
* <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming
@@ -828,6 +828,44 @@ public final class BluetoothAdapter {
return createNewRfcommSocketAndRecord(name, uuid, false, false);
}
+ /**
+ * Create a listening, encrypted,
+ * RFCOMM Bluetooth socket with Service Record.
+ * <p>The link will be encrypted, but the link key is not required to be authenticated
+ * i.e the communication is vulnerable to Man In the Middle attacks. Use
+ * {@link #listenUsingRfcommWithServiceRecord}, to ensure an authenticated link key.
+ * <p> Use this socket if authentication of link key is not possible.
+ * For example, for Bluetooth 2.1 devices, if any of the devices does not have
+ * an input and output capability or just has the ability to display a numeric key,
+ * a secure socket connection is not possible and this socket can be used.
+ * Use {@link #listenUsingInsecureRfcommWithServiceRecord}, if encryption is not required.
+ * For Bluetooth 2.1 devices, the link will be encrypted, as encryption is mandartory.
+ * For more details, refer to the Security Model section 5.2 (vol 3) of
+ * Bluetooth Core Specification version 2.1 + EDR.
+ * <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming
+ * connections from a listening {@link BluetoothServerSocket}.
+ * <p>The system will assign an unused RFCOMM channel to listen on.
+ * <p>The system will also register a Service Discovery
+ * Protocol (SDP) record with the local SDP server containing the specified
+ * UUID, service name, and auto-assigned channel. Remote Bluetooth devices
+ * can use the same UUID to query our SDP server and discover which channel
+ * to connect to. This SDP record will be removed when this socket is
+ * closed, or if this application closes unexpectedly.
+ * <p>Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to
+ * connect to this socket from another device using the same {@link UUID}.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+ * @param name service name for SDP record
+ * @param uuid uuid for SDP record
+ * @return a listening RFCOMM BluetoothServerSocket
+ * @throws IOException on error, for example Bluetooth not available, or
+ * insufficient permissions, or channel in use.
+ * @hide
+ */
+ public BluetoothServerSocket listenUsingEncryptedRfcommWithServiceRecord(
+ String name, UUID uuid) throws IOException {
+ return createNewRfcommSocketAndRecord(name, uuid, false, true);
+ }
+
private BluetoothServerSocket createNewRfcommSocketAndRecord(String name, UUID uuid,
boolean auth, boolean encrypt) throws IOException {
RfcommChannelPicker picker = new RfcommChannelPicker(uuid);
@@ -898,6 +936,28 @@ public final class BluetoothAdapter {
return socket;
}
+ /**
+ * Construct an encrypted, RFCOMM server socket.
+ * Call #accept to retrieve connections to this socket.
+ * @return An RFCOMM BluetoothServerSocket
+ * @throws IOException On error, for example Bluetooth not available, or
+ * insufficient permissions.
+ * @hide
+ */
+ public BluetoothServerSocket listenUsingEncryptedRfcommOn(int port)
+ throws IOException {
+ BluetoothServerSocket socket = new BluetoothServerSocket(
+ BluetoothSocket.TYPE_RFCOMM, false, true, port);
+ int errno = socket.mSocket.bindListen();
+ if (errno != 0) {
+ try {
+ socket.close();
+ } catch (IOException e) {}
+ socket.mSocket.throwErrnoNative(errno);
+ }
+ return socket;
+ }
+
/**
* Construct a SCO server socket.
* Call #accept to retrieve connections to this socket.