Is Bluez (bluetoothd) not sending DBUS method_call SelectConfiguration upon Connection? If so, how do I catch it? - dbus

UPDATE: not solved yet, but part of a solution. See below.
I am attempting to connect my iPod or other smart device to my laptop (Kubuntu 13.10) via bluetooth and stream a2dp-encoded music to a bluetooth speaker. Never mind why I don't connect them directly. I had a lot of trouble getting the devices to actually pair then connect at the same time, but now I'm able to do that. There are a million posts out there that describe different ways to connect BT headsets by changing .asoundrc, /etc/bluetooth/audio.conf, and loading a loopback module through PulseAudio's controller. However, I could never get PulseAudio to consistently load the sources and sinks, so I scratched that idea and started following this great post by James B: http://jamesbond3142.no-ip.org/blog/?viewCat=Bluetooth
I got the code compiled. It uses the (newer?) DBus API for BlueZ. Following his instructions, I was able to pipe music into the a2dp "server" or out of it, but there is no sound. In the code, he waits for two DBUS method_calls, SelectConfiguration and SetConfiguration in order to obtain the "transport", which I think is a handle or file descriptor that describes where the audio should go to/from. However, the handlers for these events are never called. I set up dbus-monitor to listen on the system bus for these calls using this guide: https://wiki.ubuntu.com/DebuggingDBus. However, the method calls don't show. Then again, I tried listening to ANY method calls on the system bus and there are some that don't show in dbus-monitor that I know are being called. (i.e. RegisterEndpoint)
I see signals from org.bluez, but no method calls. When running bluetoothd in verbose mode I get something like this when I connect my device:
bluetoothd[12118]: audio/a2dp.c:setup_ref() 0x7f9e8ffbdac0: ref=2
bluetoothd[12118]: audio/avdtp.c:avdtp_set_configuration() 0x7f9e8ffd03f0: int_seid=1, acp_seid=1
bluetoothd[12118]: audio/a2dp.c:setup_unref() 0x7f9e8ffbdac0: ref=1
bluetoothd[12118]: audio/avdtp.c:session_cb()
bluetoothd[12118]: audio/avdtp.c:avdtp_parse_resp() SET_CONFIGURATION request succeeded
bluetoothd[12118]: audio/a2dp.c:setconf_cfm() Source 0x7f9e8ffa4600: Set_Configuration_Cfm
bluetoothd[12118]: audio/avdtp.c:avdtp_sep_set_state() stream state changed: IDLE -> CONFIGURED
bluetoothd[12118]: audio/avdtp.c:session_cb()
bluetoothd[12118]: audio/avdtp.c:avdtp_parse_resp() OPEN request succeeded
but on another post I saw that someone had this:
bluetoothd[8315]: audio/a2dp.c:setup_ref() 0x7f1f8300b000: ref=2
bluetoothd[8315]: audio/avdtp.c:avdtp_set_configuration() 0x7f1f83012250: int_seid=2, acp_seid=1
bluetoothd[8315]: audio/a2dp.c:setup_unref() 0x7f1f8300b000: ref=1
bluetoothd[8315]: audio/avdtp.c:session_cb()
bluetoothd[8315]: audio/avdtp.c:avdtp_parse_resp() SET_CONFIGURATION request succeeded
bluetoothd[8315]: audio/a2dp.c:setconf_cfm() Sink 0x7f1f82fc3210: Set_Configuration_Cfm
bluetoothd[8315]: audio/media.c:media_endpoint_async_call() Calling SetConfiguration: name = :1.65 path = /MediaEndpoint/A2DPSink
bluetoothd[8315]: audio/avdtp.c:avdtp_sep_set_state() stream state changed: IDLE -> CONFIGURED
bluetoothd[8315]: audio/avdtp.c:session_cb()
bluetoothd[8315]: audio/avdtp.c:avdtp_parse_resp() OPEN request succeeded
At this point I have two theories:
1) BlueZ isn't sending this to the bus I'm watching when my device is connected
2) I'm not watching correctly (do method_calls also need to be added with dbus_bus_add_match () ?)
I find it hard to believe the second one, since James B's code worked for him and I didn't modify it. I'm using bluez version 4.101. (same as he, I think)
It's hard to find the exact conditions under which BlueZ calls these methods.
My syslog says something like this when I start the program:
bluetoothd[8519]: Endpoint registered: sender=:1.166 path=/MediaEndpoint/A2DPSource
and unregisters as well when the program exits.
I can't think of other details to add at the moment, but I'm happy to if I haven't provided enough. Thanks in advance.
UPDATE
A little embarrassing, but I racked my brain today about why a LINUX SYSTEM wouldn't get a file handle...hmmm...so I appended sudo to the program call (James B's a2dp-alsa program) and it worked. At least for the input device. Still nothing for the output (BT speaker), but I'll try to figure that out soon and post the result here.
Where do I collect my noob badge? :(

I did not continue with BlueZ 4. I upgraded to BlueZ 5 and PulseAudio 5, which work better together than the previous versions. After, I was able to finally use the pactl loopback module. (See this post for more details.)

Related

How can i receive a pairing request event via dbus, glib?

I'm currently making a Bluetooth app with BlueZ
I need to get a Pairing request.
Using BlueZ DBus API, i've made my Agent into NoInputOutput mode, and i succeed the first pairing with my phone.
However, if i delete the linux device(which uses my bluetooth app that i am developing) from my phone and try to re-connect, i can't pair it together.
I searched Python code examples that...
From BlueZ's DBus API, calling RequestAuthorization method to pair and successes it, then deleting the device and re-pairing works fine.
But in case of smartphone's pairing request, i think i should call RequestAuthorization method WHEN SOME EVENT(S) is received. And i have no idea for that.
Conclusion: How can i get a pairing request event using dbus and glib loop?
I've already checked
bluez pairing before exchange
apparently, gdbus is a combination of dbus and glib.
However, i'm using dbus and glib separated since i can sorted some codes that i do not need.
More, now i think it doesn't have any relations with deleting devices from the list.

dbus: ConnectProfile method: error host is down

Actually I'm using D-Feet (D-Feet can be used to inspect D-Bus interfaces of running programs and invoke methods on those interfaces) to connect to a BLE peripheral that advertises proximity profile.
When I try the Connect() method on the remote object /org/bluez/hci0/dev_88_6B_0F_00_C4_3A every thing is fine and the connection succeed but when I try to connect only the proximity profile using ConnectProfile("0x1802") method an error occurs saying that the host is down:
g-io-error-quark: GDBus.Error:org.bluez.Error.Failed: Host is down
(36)
Can anyone help me solving this problem (I'm blocked for 2 weeks and there still to much to deal with in the project :/)
ConnectProfile("0x1802")
ConnectProfile (and the Bluez API in general) does not deal with handles, only UUIDs. Your input argument does not look like a UUID: I suggest you find the remote service UUID that matches the handle (I'm assuming your current input argument is a handle).
I believe you can find the UUID with d-feet (after Connect() the service objects should be there) or with bluez command line tools.

Setting Cinterion BGS2-W modem certificates in code

I'm trying to use AT commands to setup a BGS2-W modem on a custom board to connect to a site over TLS, but the modem is not reacting to my commands and no certificates are being set.
I'm using the command
AT^SBNW
to send the commands as documented in Transport Layer Security for Client
TCP/IP Services doc (https://ptelectronics.ru/wp-content/uploads/organizatsiya_bezopasnogo_ssl-soedineniya.pdf#page=8).
Unfortunately, the document provides no examples, and I haven't been able to find any samples showing the usage of this command online.
The document linked has a java commandline tool attached that will send a cert from a PC, however I am unable to use this tool (I don't have the connection to the modem).
If anyone has any idea's on how to use this command I could very much use the help.
Note: I'm trying to set the certificates from within code running on a PIC18 - this isn't a final incarnation, I just need the certificates loaded so I can connect to our secure server.
Well, guess this one isn't going to find an answer anytime soon :)
So, its fairly easy to capture the output from the javatool - I'm using Com0Com to emulate 2 connected ports, then using termite to manually input on one port while telling the java app to connect to the other.
The first query from the java app expects an "OK" response, I find it easiest to send the response before starting the java app (I guess it gets cached in the recv buffer of the emulated port).
The javatool then sends "AT^SBNW=is_cert,1\r", and you can type in the reply in termite "SECURE CMD READY: SEND COMMAND ..."
After this a large binary dump comes through. You can decode the dump using the structure described in Application Note 62 (https://ptelectronics.ru/wp-content/uploads/organizatsiya_bezopasnogo_ssl-soedineniya.pdf). That should get all the data required to generate the same binary within code.

Bluez D-Bus: Bluetooth speaker Play/Pause/Next/Previous button handling

I am working on the Bluetooth media player feature of an internet radio project written in C on Linux platform.
The idea is:
Connect to a nearby BT speaker which is supporting AVRCP profile
Transmit audio through BT to the BT speaker
Handle button push events
Initially I was following the MPRIS D-Bus Interface Specification: https://specifications.freedesktop.org/mpris-spec/latest/
If I understand it well, the specification tells the following:
Request a unique bus name which looks like this: org.mpris.MediaPlayer2.AnyName
Expose the /org/mpris/MediaPlayer2 object path
Implement the following interfaces:
org.mpris.MediaPlayer2
org.mpris.MediaPlayer2.Player
All these steps are done. I am using the D-Feet D-bus tool to test property queries, method calls and all of them are working properly.
Now my problem is, that when I connect to a BT speaker and I push the buttons, the application is not getting the events.
Can you please point out what I am missing and what should I do next?
Thanks in advance!
PM: Sorry if I am not clear, I am a newborn programmer and Stackoverflow user. Please ask me if you need more information. I will appreciate any advice you have :)
EDIT1: The source I have is 1200 line long and I dont know what can I extract from the code for you. But FYI I am using the High-level D-Bus Support of GLib: https://developer.gnome.org/gio/stable/gdbus-convenience.html
uinput module is used to write AVRCP key commands, hence you will require a client to read from uinput when BT headset(A2DP) is connected, check in profiles/audio/avctp.c::uinput_create(), when a avrcp profile is connected, keys are send from handle_panel_passthrough() function to uinput module in kernel

C - ioctl wlan operstate, link quality, and tx/rx status

I borrowed from this gentleman in order to request the signal strength of a wireless connection on my device. I would also like to use ioctl to get the operstate and whether or not there's up/down stream information flowing over the connection.
Basically, I'm attempting to modernize the look of this device, adding to it real-time status icons of link operability, quality, and activity. Originally, I was using popen() to cat and parse /proc/net/wireless and /sys/class/net/wlan0/operstate. The only issue was that occasionally that would fail (I assume because the OS had locked the file) so it was causing crashes.
So, my questions are two:
One, can I use ioctl in a way similar to the one described in the link above to monitor the operstate and connection activity? The information I could find pertaining to this was only for ifreq, not iwreq.
Two, it occurred to me while writing this that I should probably just have the kernel telling my application when the status of the wireless device changes, shouldn't I? I can't imagine various desktops' system trays have polling loops in them.
Actual Two: is there a way to have the kernel feed information into my application about operstate, link quality, and link activity in real-time?
Thank you in advance. =)

Resources