2

I'm running Rasbian Jessie Lite on Raspberry Pi 3 with a USB/Bluetooth dongle (blueZ) 5.4.

The /etc/bluetooth/main.conf has Class = 0x0c0408. I have a Qt5 application which enables the Bluetooth device and accepts any incoming pairing requests.

I can successfully connect from my smartphone to all enabled Bluetooth profiles: A2DP and HFP.

Now I want to let the users select which profile(s) should be enabled. Thus I'm looking for a way to enable/disable on-the-fly A2DP and HFP. It's ok from C++, bash or python script.

I can't just change the Class value because I cannot restart the bluetooth service - I MUST keep running the GATT server.

Any thought about?

Mark
  • 4,338
  • 7
  • 58
  • 120
  • Mark, did you find a working solution for your problem? – wojciii Jan 17 '18 at 09:42
  • Not really. I've ended up using a commercial BT stack and anyway I have to select the available services before the connection (or let the user to disconnected from them manually). – Mark Jan 17 '18 at 10:33

1 Answers1

2

Enabling and disabling any profile/service in Bluez can be done using sdptool command. If you want to enable any profile/service you can use:

sdptool add A2SRC

In the same way to disable any service/profile you can use:

sdptool del A2SRC

More info can be found using help of sdptool

    sdptool - SDP tool v5.37
Usage:
    sdptool [options] <command> [command parameters]
Options:
    -h      Display help
    -i      Specify source interface
Commands:
    search      Search for a service
    browse      Browse all available services
    records     Request all records
    add         Add local service
    del         Delete local service
    get         Get local service
    setattr     Set/Add attribute to a SDP record
    setseq      Set/Add attribute sequence to a SDP record

Services:
    DID SP DUN LAN FAX OPUSH FTP PRINT HS HSAG HF HFAG SAP PBAP MAP 
    NAP GN PANU HCRP HID KEYB WIIMOTE CIP CTP A2SRC A2SNK AVRCT AVRTG 
    UDIUE UDITE SEMCHLA SR1 SYNCML SYNCMLSERV ACTIVESYNC HOTSYNC 
    PALMOS NOKID PCSUITE NFTP NSYNCML NGAGE APPLE IAP ISYNC GATT 

Now, this is how you can enable and disable any profile/services.

Moving to your second question, how to remotely let the user of smartphone to enable and disable the profile. This you can achieve through the serial port profile(SPP) in Bluetooth. Just to brief you, SPP is serial port emulation over Bluetooth. It is based on RFcomm protocol and can be used in parallel with A2DP and HFP.

So here the idea is to create SPP connection from smartphone to RSP and then send command to enable and disable profiles. SPP can be used from command line using rfcomm command available with Bluez. More info on how to use the command can be found here:

https://unix.stackexchange.com/questions/92255/how-do-i-connect-and-send-data-to-a-bluetooth-serial-port-on-linux

Let me know if any further clarification you need on this.

Community
  • 1
  • 1
aksonlyaks
  • 193
  • 7
  • Thanks for the answer. I'm going to try the sdptool commands. About the remote commands, I'm already use the GATT server to do this. That's why I need to keep it running! – Mark Oct 15 '16 at 06:59
  • Good to know you are able to resolve remote commands problem. All the best with your project.. – aksonlyaks Oct 15 '16 at 13:41
  • 1
    I think that this answer is wrong. If you read the man page for sdptool it contains "del record_handle .. NOTE: Local adapters configuration will not be updated and this command should only be used for SDP testing" (Ubuntu 16.04). I see that removing a service has no effect whatsoever when looking at output from hcidump where a connecting device happily connects to the profiles that I just removed using "sdptool del". – wojciii Jan 17 '18 at 09:41