Programmatically enable/disable Bluetooth profiles
<p>I'm running Rasbian Jessie Lite on Raspberry Pi 3 with a USB/Bluetooth dongle (blueZ) 5.4.</p>

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

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

<p>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.</p>

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

<p>Any thought about?</p>

<p>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:</p>

<p><code>sdptool add A2SRC</code></p>

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

<pre><code>sdptool del A2SRC
</code></pre>

<p>More info can be found using help of sdptool</p>

<pre><code>    sdptool - SDP tool v5.37
Usage:
    sdptool [options] &lt;command&gt; [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 
</code></pre>

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

<p>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. </p>

<p>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: </p>

<blockquote>
  <p><a href="http://unix.stackexchange.com/questions/92255/how-do-i-connect-and-send-data-to-a-bluetooth-serial-port-on-linux">http://unix.stackexchange.com/questions/92255/how-do-i-connect-and-send-data-to-a-bluetooth-serial-port-on-linux</a></p>
</blockquote>

<p>Let me know if any further clarification you need on this. </p>

python linux bluetooth a2dp hfp