- When does android show a pairing dialog when using insecure RFCOMM bluetooth sockets?
- «Service discovery failed» from Android Bluetooth Insecure Rfcomm
- Details
- Relevant Code Snippets
- Android Bluetooth Connection Secure Insecure
- «Обнаружение службы не удалось» из Android Bluetooth Небезопасный Rfcomm
- Подробнее
- Соответствующие фрагменты кода
- Is it possible to create an insecure RFCOMM socket between Android and Google Chrome?
- 2 Answers 2
When does android show a pairing dialog when using insecure RFCOMM bluetooth sockets?
I am trying to connect two unpaired android devices via Bluetooth for P2P networking purposes. MitM protection is not required. Android has the createInsecureRfcommSocketToServiceRecord and listenUsingInsecureRfcommWithServiceRecord for this (since API level 10), which works perfectly on modern devices. However, on a Galaxy Ace (Android 2.3.3 = API level 10, connecting with a Galaxy Nexus), it creates a pairing dialog. This happens both on incoming and outgoing connections. (Update: Updating the Galaxy Ace to Android 2.3.6 apparently fixes the problem. Is there a specific Android version that always/never does this?) After the pairing is accepted, the connection works. For this reason, I think this is not related to Issue 40101: createInsecureRfcommSocketToServiceRecord causes pairing dialog on Android 4.2 which should only happen if the service record does not exist. I assume this dialog cannot be avoided on devices where it comes up (if it can, explaining how to do this is a valid answer). For this reason, I would like to know when such a dialog is brought up. I did not find anything in the Android Java source (it goes native pretty quickly). I doubt it has anything to do with the Bluetooth version, since the Ace has Bluetooth 2.1 which is supposed to support the required «just works» connections. If there is anything that would allow me to detect whether a device will support connections without popping the dialog, or if it was clearly fixed to a certain android version, that would immensely help me. Also, I am looking for a way to easily exclude such devices.
For insecure connection i.e., if you use createInsecureRfcommSocketToServiceRecord and listenUsingInsecureRfcommWithServiceRecord, what UUID did you use?
«Service discovery failed» from Android Bluetooth Insecure Rfcomm
Does anyone know how to create an insecure RFCOMM connection between 2 Android devices at API level 2.3.3 while using an arbitrarily declared service name? (not random or changing service name, just a service name that I define myself)
Details
I am trying to create an insecure Rfcomm connection between 2 Android devices: Droid X2 and an Asus Transformer. I am assuming that both of these devices have functionality at the level of Android 2.3.3 to actually gain the ability to use insecure Rfcomm. When I try to create the Bluetooth connection as described here, using the now public createInsecureRfcommSocketToServiceRecord() and listenUsingInsecureRfcommWithServiceRecord(SERVICE, UUID), I get a reported:
java.io.IOException: Service discovery failed at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:377) at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201) at com.s4d.bluenomad.DeviceConnections$ClientThread.run(DeviceConnections.java:406)
I found a related question where someone creating a normal connection was getting this error and used reflection to invoke a private method. However, I have no idea what private method would now correspond to initiating an «insecure» connection. I tried using the solution proposed in that related question, but I am asked by Android to pair the devices which is exactly what I need to avoid. I really do need the insecure approach. I even tried a combination of the official and hacked solutions outlined here
Relevant Code Snippets
Log.i(TAG, "Constructing a ServerThread"); // Use a temporary object that is later assigned to serverSocket, // because serverSocket is final BluetoothServerSocket tmp = null; try < // MY_UUID is the app's UUID string, also used by the client code tmp = btAdapter.listenUsingInsecureRfcommWithServiceRecord(SERVICE_NAME, SERVICE_UUID); Log.i(TAG,"Started listening on insecure RFCOMM channel for service requests for: " + SERVICE_NAME); >catch (IOException e) < >serverSocket = tmp;
BluetoothSocket socket; while(true) < try < socket = serverSocket.accept(); >catch( IOException e) < break; >if( socket != null ) < Log.i(TAG, "Received new socket connection requesting service: " + SERVICE_NAME); >else < Log.i(TAG, "Socket connection attempted, but socket received is NULL."); >>
Log.i(TAG, "Constructing a ClientThread"); BluetoothSocket tmp = null; try < // MY_UUID is the app's UUID string, also used by the server code tmp = device.createInsecureRfcommSocketToServiceRecord(SERVICE_UUID); Log.i(TAG,"Created client socket on insecure RFCOMM channel for service requests for: " + SERVICE_NAME); >catch (IOException e) < Log.i(TAG, "Failed to createInsecureRfcommSocket() against MAC: " + device.getAddress()); >clientSocket = tmp;
try < clientSocket.connect(); >catch( final IOException e) < DeviceConnections.this.runOnUiThread(new Runnable() < @Override public void run() < console.append("Client unable to connect to service."); Log.i(TAG, "Client socket unable to connect() to: " + clientSocket.getRemoteDevice().getAddress()); e.printStackTrace(); >>); >
I do get the log output «Client socket unable to connect() to: [MY_MAC_ADDRESS]», then I get the stacktrace for the «Service discovery failed» exception.
Android Bluetooth Connection Secure Insecure
I have been playing around with the bluetooth API for Android 2.2 (API level 8, HTC Desire) and had an app connecting to an embedded Bluetooth device using:
device.createRfcommSocketToServiceRecord(DEV_UUID);
This generated a pairing request as expected, however to streamline the connection process I wanted to avoid the user interaction when pairing so moved to API level 10 (HTC Desire with CyanogenMod 7) so I could use:
device.createInsecureRfcommSocketToServiceRecord(DEV_UUID);
When testing this also works as expected (connecting without prompting the user to pair), however when I try to create the secure RfcommSocket under API level 10 as before with 2.2 I get a connection refused exception.
java.io.IOException: Connection refused at android.bluetooth.BluetoothSocket.connectNative(Native Method) at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:204)
As far as I can tell this should still work in the same way, prompting the user to pair? EDIT: Just tried again using the following code and the outcome is the same (working for insecure but not for secure), I will try and get my hands on a stock 2.3 device to test on.
try < Method m = dev.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] < UUID.class >); BluetoothSocket bs = (BluetoothSocket)m.invoke(dev, devUUID); Log.d("TEST", "Method Invoked"); bs.connect(); Log.d("TEST", "Connected to socket"); bs.close(); Log.d("TEST", "Closed Socket"); >
«Обнаружение службы не удалось» из Android Bluetooth Небезопасный Rfcomm
Кто-нибудь знает, как создать небезопасное соединение RFCOMM между двумя устройствами Android на уровне API 2.3.3 при использовании произвольно объявленного имени службы? (неслучайное или изменение имени службы, просто имя службы что я сам определяю)
Подробнее
Я пытаюсь создать небезопасное соединение Rfcomm между двумя устройствами Android: Droid X2 и Asus Transformer. Я предполагаю, что оба этих устройства имеют функциональность на уровне Android 2.3.3, чтобы фактически получить возможность использовать небезопасный Rfcomm. Когда я пытаюсь создать соединение Bluetooth, как описано здесь, используя общедоступный createInsecureRfcommSocketToServiceRecord() и listenUsingInsecureRfcommWithServiceRecord (SERVICE, UUID), я получаю сообщение:
java.io.IOException: Service discovery failed at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:377) at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201) at com.s4d.bluenomad.DeviceConnections$ClientThread.run(DeviceConnections.java:406)
Соответствующие фрагменты кода
Log.i(TAG, "Constructing a ServerThread"); // Use a temporary object that is later assigned to serverSocket, // because serverSocket is final BluetoothServerSocket tmp = null; try < // MY_UUID is the app UUID string, also used by the client code tmp = btAdapter.listenUsingInsecureRfcommWithServiceRecord(SERVICE_NAME, SERVICE_UUID); Log.i(TAG,"Started listening on insecure RFCOMM channel for service requests for: " + SERVICE_NAME); >catch (IOException e) < >serverSocket = tmp;
BluetoothSocket socket; while(true) < try < socket = serverSocket.accept(); >catch( IOException e) < break; >if( socket != null ) < Log.i(TAG, "Received new socket connection requesting service: " + SERVICE_NAME); >else < Log.i(TAG, "Socket connection attempted, but socket received is NULL."); >>
Log.i(TAG, "Constructing a ClientThread"); BluetoothSocket tmp = null; try < // MY_UUID is the app UUID string, also used by the server code tmp = device.createInsecureRfcommSocketToServiceRecord(SERVICE_UUID); Log.i(TAG,"Created client socket on insecure RFCOMM channel for service requests for: " + SERVICE_NAME); >catch (IOException e) < Log.i(TAG, "Failed to createInsecureRfcommSocket() against MAC: " + device.getAddress()); >clientSocket = tmp;
try < clientSocket.connect(); >catch( final IOException e) < DeviceConnections.this.runOnUiThread(new Runnable() < @Override public void run() < console.append("Client unable to connect to service."); Log.i(TAG, "Client socket unable to connect() to: " + clientSocket.getRemoteDevice().getAddress()); e.printStackTrace(); >>); >
Я получаю вывод журнала «Не удалось подключиться к сокету клиента: [MY_MAC_ADDRESS]», после чего я получаю стек для исключения «Неудачное обнаружение службы».
привет, Мэтт, как ты? я также застрял здесь в той же проблеме .. означает, что при подключении с одного устройства на другое его подключиться и снова, если я делаю со второго на первое устройство журнала cat отображается сообщение «сбой обнаружения службы», так почему он не подключается с другое устройство, которое я пробовал это, пожалуйста, помогите мне, пожалуйста, UUId ..
@shyam — ты посмотрел мой ответ внизу? Если вы попытаетесь подключиться к услуге, когда ваш адаптер Bluetooth все еще ищет устройства, обнаружение не удастся. У меня также была дополнительная проблема с подключениями, о которой я писал здесь: Моя другая проблема с подключением
Is it possible to create an insecure RFCOMM socket between Android and Google Chrome?
I am trying to create a Bluetooth application where a smartphone (the client) connects to a web browser of another computer (the server). When triggered by a user action on the client, data will be sent to the web browser over the Bluetooth channel. Prior security association is not necessary, and the address of the server will be communicated out of band to the client in advance. Therefore I want to skip the pairing and discovery phase completely. The Android Bluetooth stack allows for the above by creating an insecure RFCOMM connection for clients createInsecureRfcommSocketToServiceRecord method, and correspondingly listenUsingInsecureRfcommWithServiceRecord . It is not clear whether the Chrome Bluetooth Stack offers the same services according to the Bluetooth Javascript API. From what I can tell, there is no way to use listenUsingInsecureRfcommWithServiceRecord , and their examples only show the web browser used as a client. I would like to confirm if this is a possibility with the current state of Google Chrome, or a some other way to enable this type of communication. There have been many questions previously asked about making insecure pairings with Android devices but none with other Bluetooth enabled devices/applications (such as a web browser in this case). None of the previous responses seemed to address the scenario which I describe.
2 Answers 2
This is possible to search for a device and create a socket communication with web bluetooth.
Android implements Bluetooth 4.0, as does Chrome OS, Windows and OS X, and insecure connections are not permitted in that version of the specification.
When the two devices connect, they will both indicate to each other that they support Secure Simple Pairing (SSP) and thus the specification requires that they begin negotiation for Encryption, even if a temporary key is used.
Thus the connection is not «insecure»
Can you please provide more details from where you know that it’s impossible? This is actually a very interesting question. What about to create the client with a chrome extension supporting Chrome bluetooth API and inject it into an Android device? It may be possible to make it work this way.