1

I try to have separate ssp modes during connection using Bluetooth btmgmt utility. Basic idea is scan current device OUI and select ssp on/off modes. But I can't get any answer from neither btmgmt con or btmgmt info commands when I put them into .service files. My system is Arch Linux arm 32-bit and bluez stack version is 5.55-1. I tried

[Unit]
Description=check Bluetooth address

[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c '/usr/bin/btmgmt info >> /usr/local/lib/mac 2>&1'

without any success: it just puts nothing in output file. Some tricks like add

User=root
Group=root

or substitute ExecStart with

ExecStart=/bin/bash -c 'echo -e "$(btmgmt con)" >> /usr/local/lib/mac 2>&1

did nothing. I tried changed thing by putting btmgmt stuff in different bash script instead of start them right from service file, i.e.

ExecStart=/usr/local/lib/test1

to no avail. I'm confused completely, because of:

  1. It doesn't seem to be general btmgmt thing problem, because I can set ssp mode from service files in very simple manner, just using

    ExecStart=btmgmt off

or

ExecStart=btmgmt off

even without full path.

  1. It doesn't seem to be redirecting command error as well, because if I add

    ExecStartPre=/usr/bin/bash -c '/usr/bin/fdisk -l > /usr/local/lib/mac 2>&1'

it does work without any problem and I see fdisk info in file (I use fdisk because it requires elevated rights same as btmgmt one). Moreover, btmgmt info works in the same way, i.e. shows nothing in out file. It makes me think something is wrong in output of btmgmt. I talk about output because input parameters work fine in btmgmt ssp on/of commands and journalctl and systemct don't show any errors in btmgmt con/info cases, so it seems to like output generating successfully but then sending somewhere to outer space, but I'm not sure completely. Thanks for any help in advance

  • 1
    Does this help at all? https://stackoverflow.com/a/43830129/7721752 – ukBaz Mar 08 '21 at 21:48
  • Yes, I tried `StandardOutput=file:/usr/local/lib/mac` and it didn't help me, I just forgot to mention that. – Night_prowler Mar 09 '21 at 14:37
  • Moreover, I think it's not redirecting problem at all, because I did a couple of extra checks and found out, that output of commands **btmgmt --help btmgmt --version** is redirected successfully, same for **btmgmt help** as well. But any other command including **btmgmt version** doesn't produce any output (at all maybe?) So its really looks like something screwed up inside **btmgmt** itself. – Night_prowler Mar 09 '21 at 14:54
  • I can imagine that `btmgmt` was never intended to be used in this manner. A better approach might be to have a script that talks directly to the socket as detailed in the docs https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/mgmt-api.txt – ukBaz Mar 09 '21 at 14:59

2 Answers2

1

Well, I make a statement: btmgmt is quite intended to be used for output at any manner, but they tried make a zillion variants of output which directed to exact result it should be: bug is buried somewhere deep inside of bt_shell_printf and struct data. I'm not ready run through all that disgusting documented code (I mean total absence of comments or more-or-less satisfactory mans), so I ended up with a liitte bit hacked version of utility downgraded to simple fprintf in output, leaving only commands I need: con, ssp, power and simplified until only current setting printing info. Everything works fine, and I can use that kind of btmgmt not with systemd only, but even with udev rules (indirectly, of course)

0

I know this is an old question, but I had the same problem, and managed to fix it after hours and hours of trying.

I don't know why in the world this happens to be so hard with btmgmt but here's the fix:

[Unit]
After=bluetooth.service
Description=Bluetooth service

[Service]
ExecStart=<your-process>
Group=root
StandardInput=tty
TTYPath=/dev/tty2
TTYReset=yes
TTYVHangup=yes
Type=simple
User=root

Basically, by occupying a TTY, btmgmt will think it's running in an interactive terminal, and will output as usual.

Hope this saves anyone the hell I've been through!

Peter Willemsen
  • 339
  • 3
  • 13