Bluetooth+arduino and android authentication - android

I have a device. I use microcontroller arduino. I have connected my device with my android application via bluetooth. And I want to do that only my application can connect to my device. What is the best way to do this authentification? Can I do this with bluetooth's special AT commands? If yes how? Or must I send some key to the arduino from the application and check it?

By defaukt bluetooth adapters accept all connections (no binding), so you have tobcheck if this is the right device explicitly. You can store data persistently in eeprom on microcontroller, where you should keep your app key. When new phone try to connect to your device you should check if device passed that key and if not, do nothing in response.

Related

Securely connect Bluetooth device to Android

I am developing a device that needs to communicate securely to an Android app via Bluetooth. I need that only a predefined phone to be able to communicate with my device for security reason. And I also need to assure that this is not an intruder device that is trying to communicate falsified data to the app.
Looking at Bluetooth specs, I had the impression the only way to do that is with out of band (OOB) authentication with a pre-provisioning temporary key (TK). This looked very promising but after trying to find how to use OOB on an Android app, it seems like it is not supported.
Is it still possible to use OOB authentification on Android ?
If no, is there another alternative to solve my issue ?
This is doable but it depends on the BLE peripheral that you are developing and the features that it supports. Namely, your device needs to support Whitelisting and bonding. This is how it should work.
Upon first connection to the BLE device, the BLE device should accept the connection regardless.
Once the connection is made, the central device (Android phone) needs to initiate bonding. This doesn't need to be Out of Band (OOB) bonding, and the standard Just Works bonding should do.
Once bonding is succesful, the BLE peripheral should add the Android device's IRK to the list of whitelisted devices.
From this point onwards, the BLE peripheral will activate the whitelist, and therefore only devices in the whitelist will be able to connect to your BLE peripheral, and in your case it will be the Android phone that you used to make the very first connection.
It is not straight-forward and requires an initial secure-less connection with the target phone, but if that is not an issue then this should work.
You can find more information about this in the links below:-
Set and activate whitelist with Android phone
Android BLE server - allow only previously connected device to connect
Whitelisting with resolvable random addresses

Android Peripheral Requires Pairing

I am writing an Android app that acts as a BLE peripheral.
When I connect to it using another device it always requests pairing. How do I make it so that it won't require pairing?
I have a single service and single characteristic and the permission on it are just normal read and write. I am not requesting any encrypted version of those.
Every device has mac address, connection is made by using mac addresss.
Connect to device and Save connected device mac address in shread preference so every time it will connect to that save device only.
So it will not ask pairing every time.
If you want to disconnect that device , in disconnect method clear mac address from shread preference.
I hope this will work for you.

Connect Android to another device on bluetooth and send data

I want to create a connection between my Android and a PC (or another device) just like in the Bluetooth menu from settings.
I have manage to get the list of all bt devices in my range and get their MAC addresses.
So, I have the BluetoothDevice, how can i connect to it or pair with it? I saw a lot of stuff about creating a server on PC, but I don't want that, i just wanna connect with the device.
My attempt were to get the UUID of the device and use createRfcommSocketToServiceRecord...but when i try socket.connect() it cannot connect (because I don't have a server). So practically I need to make the same structure that the OS is doing (connect with the device, if the connected device is trying to send i can receive the info and so on).
If I managed to connect with the device, I want to listen all that it is emitting, no matter the data...I haven't researched this topic, but any advice will be nice.
The connection must be made with any device that supports bluetooth, and I don't have access to it (of course the device is giving me the permission to connect).
Grab the Android sample projects by doing this http://developer.android.com/tools/samples/index.html
They have an app called BluetoothChat that pretty much does just what you want.
The thing about the 'server' is just in the connection, one side needs to open a listening port and that side is arbitrarily the 'server'. Once they are connected they are merely peers and you can write/read data till the cows come home.

Bluetooth communication between an Android phone and a hardware device supporting bluetooth

I'am trying to make an app that receives some binary data from a other device which is not running android. The Android phone should not transfer any data to this device. So over to my questions:
Should the phone act as the server which establishes the RCOMM channel?
Is it possible to connect the phone and this device without paring, as long as I know the MAC-address of the device? If so, how?
And yes, I have read http://developer.android.com/guide/topics/connectivity/bluetooth.html so no need to only answer with that link. :)
Thanks in advance!
1)
Phone should act as a receiver.
I found that the tricky part is to use correct UUID.
If you connect two phones you should be generating those and everything work fine, but on your hardware you can't change UUID that easily.
Take a look at these reserved UUIDs.
For a Serial Port Profile's (SPP) communication use UUID 00001101-0000-1000-8000-00805F9B34FB.
2)
You can connect to a device without pairing if you already know the MAC address, you don't even need to use BlueTooth discovery.
To get device using MAC address call getRemoteDevice(String)
and then createRfcommSocketToServiceRecord(UUID) to get BlueToothSocket.
Also take a look at checkBluetoothAddress(String) to validate MAC address.

Bluetooth Serial Comms Without Pairing

Can someone point me in the right direction please?!
I am trying to connect to an industrial product using Android over Bluetooth. The device does not support pairing. I have written an application in WM6.5 and that works fine.
The sequence of events is:
Discover device and establish a Bluetooth Serial connection (the device does not support passkeys/pairing).
Request a key from the product (by sending a hex string)
Read string and send back a response based on the key and a user entered password (by responding with another hex string).
Is there an example anywhere that I can download?
I have downloaded some BT serial terminal emulators but they all want to pair with the device.
In Windows 7 you can simply search, connect and choose to connect without pairing and then the device appear as a BT serial port.
Thanks in advance.
Pairing is not something that a remote device either supports or doesn't support. Your Android can pair to any Bluetooth device it finds. This only means that it records the device's MAC address and friendly name for future reference. If your device has a PIN you may need to enter that at pairing time and the Android will record that too.

Categories

Resources