Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5595334pxu; Tue, 22 Dec 2020 23:56:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7Kd2eOwWuZz9t0qRr2n/svAjp7ynUveyRwV85GWoxSukglYM3M2P4zDwpLvgdSZgndZdq X-Received: by 2002:a05:6402:1a52:: with SMTP id bf18mr23525976edb.143.1608710196234; Tue, 22 Dec 2020 23:56:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608710196; cv=none; d=google.com; s=arc-20160816; b=1B1SkA2Avw92HWEOOP+n29G4EEkjyuRIFmXlN7mMDouY3R8qDlG6HHH/Cq28Z2f03g e6XSoZzK+PlFoqEt3uBLCJ+fK/aP3BFCDrRTtFZbLKUPT1Dx+yGG1JhietB7Bj2oMZan wQg1BSEQBoWRKXXCAc6N5qt1N7DHxpvusJggPgSY+775N+sCRFv0LD+Slv0tYCqj1Xhl O0p7LYGGE6JGEriyPsHF7Np+txMwHUsxIDAwcUXtbEwce2ESArSUi7InzCV9kCdhmI4Z 1BJYLL8J2sGIVu+BJJ4asI3SkC2HQVOIXgKUtu20zYmY0MvSWs97QiMcXBo6mllKaHVa 8sEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nvds22pi5MEw2ZW5T62SoKKKSYY5H17iYaJRDS7x/JU=; b=XxdfKfoYqzAdcDPHiaiw+w4tBnnAul1nSPuA1Wbl6WTzQ2v1ICiQW1fNecDvBhgBfJ lwIUVnI/M5vhpAJChXEfJd62nf59YayJIrLPtj9SiFKvimZWvklIHQ3HIaLbdIBFfqkf 91jtYbhyTMg9TQW1IW2DiCviw+qUVZ9e0IkBeZT/SMVF/vsIwBEN/nCK+oxUTZ9ft2is vapZ2FpiMcXZj5JPyK1MzuGJFXtpLArtg45TRud7gbAYg9bAchpC3HeCPWPrvgv8KdLK dSNj48OLZJlU/pthzoYBwHFJ11yGK2ljXmqyzfXOLLe9W1t+thGnq+73iVv57ktCi21I UkaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GIj0NMVn; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e24si10673043edc.290.2020.12.22.23.55.59; Tue, 22 Dec 2020 23:56:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GIj0NMVn; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727441AbgLWHy2 (ORCPT + 99 others); Wed, 23 Dec 2020 02:54:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbgLWHy2 (ORCPT ); Wed, 23 Dec 2020 02:54:28 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA3CC0613D3 for ; Tue, 22 Dec 2020 23:53:47 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id o19so38106100lfo.1 for ; Tue, 22 Dec 2020 23:53:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nvds22pi5MEw2ZW5T62SoKKKSYY5H17iYaJRDS7x/JU=; b=GIj0NMVn5UTSkYHLvII8fk4jEq5p05+ATlhU62PIA+F1ybnyOk1b3tBMfVpr/6yoqk reRUyHTyyMEDIBbvIZ3KFLjNn+lF3VqECY8xyc0QvXVqT9cCBcsf8b33oSAKAaHjOkb0 E8khP48aJSRGaruivF8F+i4AxGcnsMESKBM6Un8yqSWeMWqX1R8hThrtEahNbb334mOh 5LkTS6DAezkk9jcOg9GQPf0G++WiFu7RGWwNla5PidbeT7QwW1Jn3GQccmZKWLJzveDr KGnSQphSrkJvQC5Tm3kd1lyWH8Rs6h99HXVMobLtKd9pSO4ikP9eQMecytgoiCuN1HW0 xvpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nvds22pi5MEw2ZW5T62SoKKKSYY5H17iYaJRDS7x/JU=; b=RBO4+Kt5R59hjtuwOaq7rmkMnJeil43Yc/dWfdjwwsU4PkVMYQfzXb95CIAXb0jno9 eN3FVhjRKUGJfIteB7Os00JwdHBB5rvMEoaqtAJ4hIKDC9PX4xDIRxJkZ8vNYbVvQyy3 ynwMxWsjfaXoC4b1Eea3a/c+dQMg0u1DeqAZIK+FvD8jxtg0RFEies13pgO/Qr4WpLWs H3XaaV/GfqzFbe8eAOHoIgnCc+7cEYwv3yayxazA+YgMGzUGPrrL2O7Go4W9JT09yd/2 nZAXRlvxpFiq959NTcMAhB4TJ6apTVTvNhio4yusQWzd79qky3hyqfCokZCiJLrh8BZD LmCA== X-Gm-Message-State: AOAM533Pncmzb+vjD6Zl+Uj30Mth3wyi1gximuet+UL9yNwhvfAOrR2o OwN+n1mRWlZnF+nvATpPG8NU5lZ9ng4jJzZ6SR4= X-Received: by 2002:ac2:4946:: with SMTP id o6mr9760013lfi.412.1608710026498; Tue, 22 Dec 2020 23:53:46 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Barry Byford <31baz66@gmail.com> Date: Wed, 23 Dec 2020 07:53:34 +0000 Message-ID: Subject: Re: Request for help with btmgmt To: KeithG Cc: Bluez mailing list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hello Keith, On Wed, 23 Dec 2020 at 00:34, KeithG wrote: > > I am developing a RPi based audio player. We are trying to add > bluetooth capability to this player. We use alsa and not pulse-audio, > so we need a bit more granular info to get it to run. I have written a > script which is designed to be triggered by udev when a BT device is > added or removed. This script will then use bluetoothctl to get the > capabilities of the device and also add or remove it from a dynamic > database list of MACs in redis. I have a simple script working as I > want from the cli. The key command I am using is 'btmgmt con' which is > the only command I have found that tells me what MACs are currently > connected. I can run this command from the command line as root. I can > set the setuid bit of btmgmt and also get it to run as a user (http in > this case). I cannot, ever, get this command to run when triggered > from udev. I get no response and no error. > > 1) Why is this particular command (query attached BT MACs) not part of > bluetoothctl? Is there a security issue? > 2) Why can I not run 'btmgmt con' in a script (bash or php) triggered > by udev when the device is added or removed? > 3) is there a 'better way' for me to know what device MAC addresses > are attached? I have not found another simple way to get this info. > > What I am doing in the script is: if an audio source is attached, I > want to run a bluealsa-aplay service. When an audio sink is attached, > I want to re-set my audio output to the bluealsa device. If it is not > an audio device, I do not care, but do keep track of what is attached > in my database so that the next time the script runs that it is not > queried and is 'known'. > > Thanks for the help. > > Keith I would suggest that the D-Bus API would be a more appropriate way to get the information you want. The "get managed objects" functionality is a good way to iterate through all the devices that BlueZ knows about. There are examples at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/bluezutils.py https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/list-devices The D-Bus API also allows your code to execute callbacks when a device is added or its connection state changes. This is done with the InterfacesAdded and PropertiesChanged signals. If you are going to use Python I would suggest the https://pypi.org/project/pydbus/ library is a more "Pythonic" set of D-Bus bindings. The API is documented at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc Regards, Barry