0

I'm coding an app with Master-Slave design for Bluetooth on Android. Master in piconet can have up to 7 active slaves. I've read Android Bluetooth dev guide and BluetoothSocket.java source code, however there is no maximum number of slaves mentioned. So I tried to accept more than 7 slaves in the following code:

private void startServerSocket(String name) {
    BluetoothServerSocket serverSocket = null;
    try {
        serverSocket = mAdapter.listenUsingInsecureRfcommWithServiceRecord(macMap.get(name), uuidMap.get(name));
        for (int i = 0; i < 8; i++) {
            BluetoothSocket socket = null;

            Log.d(TAG, i + " waitting for " + name + " to accpet...");
            socket = serverSocket.accept();
            Log.d(TAG, i + " " + name + " accepted");

            // corresponding slave thread on master side
            MasterSocketThread mst = new MasterSocketThread(socket, socket.getRemoteDevice().getName());
            mst.start();

            // register slave thread to master manager
            mCallback.registerSocketThread(mst);
        }
        serverSocket.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

As a result at 8th iteration I get this exception from accept() method:

android io.IOException: Connection failure, wrong signal size: 27763

My question is whether it's related to Bluetooth standard(7 active slaves) or there is another occurence that I am not aware of?

tmowojtek
  • 43
  • 1
  • 3
  • 7

2 Answers2

0

After tests with different devices (tablets, smartfons), this error is related to Bluetooth Core specification (I reviewed 4.2 spec. version) that allows only 8 active devices in piconet (master + max. 7 slaves).

Fun fact: I created app using Java's BlueCove library for my laptop that acts as master in piconet and it doesn't limit slave devices to 7. I managed to connect 9 slaves, being active at the same time. That is not what Bluetooth specification says. To fix that I programatically set limit to 7 slaves.

tmowojtek
  • 43
  • 1
  • 3
  • 7
0

I don't think this error is related to the Bluetooth Core specification. It would be impossible to have more than 7 active slaves since the LT_ADDR is a 3-bit value, where 0 is reserved for broadcast.

From the specification Vol.2 Part B Section 4.2

Each slave active in a piconet is assigned a primary 3-bit logical transport address (LT_ADDR). [...] The LT_ADDR shall only be valid for as long as a slave is in the active mode.

Also from Section 6.4.1

This field [LT_ADDR] indicates the destination slave (or slaves in the case of a broadcast) for a packet in a master-to-slave transmission slot and indicates the source slave for a slave-to-master transmission slot.

The key, I think, is the word active. Section 8.6 defines Active Mode and active slaves. I think you managed to have more than 7 slaves because not all of them are in active mode, some may be put in sniff mode, for example. Or some other trick may be done by the Bluetooth controller on your master device.

To understand what's going on, I suggest you to check the HCI log on the master which you can retrieve as described here.

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Šatov
  • 323
  • 3
  • 9
  • You are right. After taking a look at HCI log on mobile device, packets from master (laptop) clearly shows that it manages active/sniff modes for those 9 connected devices. – tmowojtek Nov 07 '17 at 10:45
  • Albeit in my opinion when master is a mobile device, android system probably lets user maintain and manage connections with active devices only, unlike Bluetooth implementation for laptop. – tmowojtek Nov 07 '17 at 11:25