maniacx / Airpod-Battery-Monitor

A Gnome extension for monitoring battery level of AirPods and Beats Bluetooth headset
https://extensions.gnome.org/extension/6778/airpod-battery-monitor/
GNU General Public License v3.0
36 stars 7 forks source link

Mediatek no le device detected #26

Open maniacx opened 1 month ago

maniacx commented 1 month ago

ARdgzC

manufacturer data show is for Airpod pro 2nd gen with ligthning cable. But battery level are reported incorrectly. I also read somewhere that mediatek devices have issues with scanning le when experimental features are enabled. So lets disable kernel expermental feature first.


  1. Which linux distro are you using?

  1. Disable kernel experimental flag in /etc/bluetooth/main.conf. Add a # and space in front. Should look this.
    # Enables kernel experimental features, alternatively a list of UUIDs
    # can be given.
    # Possible values: true,false,<UUID List>
    # Possible UUIDS:
    # d4992530-b9ec-469f-ab01-6c481c47da1c (BlueZ Experimental Debug)
    # 671b10b5-42c0-4696-9227-eb28d1b049d6 (BlueZ Experimental Simultaneous Central and Peripheral)
    # 15c0a148-c273-11ea-b3de-0242ac130004 (BlueZ Experimental LL privacy)
    # 330859bc-7506-492d-9370-9a6f0614037f (BlueZ Experimental Bluetooth Quality Report)
    # a6695ace-ee7f-4fb9-881a-5fac66c629af (BlueZ Experimental Offload Codecs)
    # 6fbaf188-05e0-496a-9885-d6ddfdb4e03e (BlueZ Experimental ISO socket)
    # 69518c4c-b69f-4679-8bc1-c021b47b5733 (BlueZ Experimental Poll Errqueue)
    # Defaults to false.
    # KernelExperimental = true

    Restart laptop


  1. Can copy paste these commands in terminal and post the output here.
    clear
    echo "--------- lsusb | grep -i bluetooth -------"
    lsusb | grep -i bluetooth
    echo""
    echo "--------- bluetooth.service -------"
    cat /lib/systemd/system/bluetooth.service
    echo""
    echo "--------- bluez capabilities -------"
    bluetoothctl show
    echo""
    echo "--------- btmgmt info -------"
    btmgmt info
    echo""
    echo "--------- bluez version -------"
    bluetoothctl version

  1. try the script again. Make sure the airpods are as close as possible to the bluetooth adapter/laptop
ARdgzC commented 1 month ago

Hi, That's my airpods model I have disabled kernel experimental feature my distro: OS: Fedora Linux 40 Kernel: 6.9.9-200.fc40.x86_64

Output

--------- lsusb | grep -i bluetooth -------

--------- bluetooth.service -------
[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/libexec/bluetooth/bluetoothd
NotifyAccess=main
#WatchdogSec=10
#Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1

# Filesystem lockdown
ProtectHome=true
ProtectSystem=strict
PrivateTmp=true
ProtectKernelTunables=true
ProtectControlGroups=true
StateDirectory=bluetooth
StateDirectoryMode=0700
ConfigurationDirectory=bluetooth
ConfigurationDirectoryMode=0555

# Execute Mappings
MemoryDenyWriteExecute=true

# Privilege escalation
NoNewPrivileges=true

# Real-time
RestrictRealtime=true

[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service

--------- bluez capabilities -------
Controller EC:2E:98:CB:D3:BC (public)
    Manufacturer: 0x0046 (70)
    Version: 0x0b (11)
    Name: Rigel
    Alias: Rigel
    Class: 0x006c010c (7078156)
    Powered: yes
    PowerState: on
    Discoverable: no
    DiscoverableTimeout: 0x000000b4 (180)
    Pairable: no
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
    UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (03b80e5a-ede8-4b33-a751-6ce34ec4c700)
    UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
    Modalias: usb:v1D6Bp0246d054D
    Discovering: no
    Roles: central
    Roles: peripheral
Advertising Features:
    ActiveInstances: 0x00 (0)
    SupportedInstances: 0x14 (20)
    SupportedIncludes: tx-power
    SupportedIncludes: appearance
    SupportedIncludes: local-name
    SupportedSecondaryChannels: 1M
    SupportedSecondaryChannels: 2M
    SupportedSecondaryChannels: Coded
    SupportedCapabilities.MinTxPower: 0xfffffff2 (-14)
    SupportedCapabilities.MaxTxPower: 0x000d (13)
    SupportedCapabilities.MaxAdvLen: 0xfb (251)
    SupportedCapabilities.MaxScnRspLen: 0xfb (251)
    SupportedFeatures: CanSetTxPower
    SupportedFeatures: HardwareOffload

--------- btmgmt info -------
Index list with 1 item
hci0:   Primary controller
    addr EC:2E:98:CB:D3:BC version 11 manufacturer 70 class 0x6c010c
    supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr le advertising secure-conn debug-keys privacy configuration static-addr phy-configuration wide-band-speech cis-central cis-peripheral 
    current settings: powered ssp br/edr le secure-conn wide-band-speech cis-central cis-peripheral iso-broadcaster sync-receiver 
    name Rigel
    short name 
hci0:   Configuration options
    supported options: public-address 
    missing options: 

--------- bluez version -------
Version 5.77

Curiously, I only get information from the airpods with the script and scan when they are not paired.

[bluetooth]# [CHG] Device 74:15:F5:07:4F:48 ManufacturerData.Key: 0x004c (76)
[bluetooth]# [CHG] Device 74:15:F5:07:4F:48 ManufacturerData.Value:
[bluetooth]#   07 19 07 14 20 95 e4 e4 23 79 de cc b0 66 3d 39  .... ...#y...f=9
[bluetooth]#   27 ff da dd c9 81 58 0c b8 24 95                 '.....X..$.     
[bluetooth]# [CHG] Device 74:15:F5:07:4F:48 RSSI: 0xffffffd4 (-44)
[bluetooth]# [CHG] Device 74:15:F5:07:4F:48 ManufacturerData.Key: 0x004c (76)
[bluetooth]# [CHG] Device 74:15:F5:07:4F:48 ManufacturerData.Value:
[bluetooth]#   07 19 07 14 20 95 e4 e4 23 39 de cc b0 66 3d 39  .... ...#9...f=9
[bluetooth]#   27 ff da dd c9 81 58 0c b8 24 95                 '.....X..$.     
Gjs-Message: 21:24:22.828: JS LOG: StartDiscoveryAsync
Gjs-Message: 21:24:37.836: JS LOG: Scanning Bluetooth devices...
Gjs-Message: 21:24:37.836: JS LOG: Device = 13 AddressType = public rssi = -42 connected = false
Gjs-Message: 21:24:37.836: JS LOG:  
Gjs-Message: 21:24:37.836: JS LOG:  
Gjs-Message: 21:24:37.837: JS LOG: rawData.length = 27
Gjs-Message: 21:24:37.837: JS LOG: ------------------------------------------
Gjs-Message: 21:24:37.837: JS LOG: Device                             : 13
Gjs-Message: 21:24:37.837: JS LOG: ManufacturerData                   : 071907142095e4e42371deccb0663d3927ffdaddc981580cb82495
Gjs-Message: 21:24:37.837: JS LOG: Rssi                               : -42
Gjs-Message: 21:24:37.837: JS LOG: Model 4 Character                  : 1420
Gjs-Message: 21:24:37.837: JS LOG: Model 1 Character                  : 4
Gjs-Message: 21:24:37.837: JS LOG: Left Battery Level                 : 40
Gjs-Message: 21:24:37.837: JS LOG: Right Battery Level                : 100
Gjs-Message: 21:24:37.837: JS LOG: Case Battery Level                 : 40
Gjs-Message: 21:24:37.837: JS LOG: Single Battery Level               : 40
Gjs-Message: 21:24:37.837: JS LOG: Left Battery Charging Status       : false
Gjs-Message: 21:24:37.837: JS LOG: Right Battery Charging Status      : true
Gjs-Message: 21:24:37.837: JS LOG: Case Battery Charging Status       : true
Gjs-Message: 21:24:37.837: JS LOG: Single Battery Charging Status     : false
Gjs-Message: 21:24:37.837: JS LOG: ------------------------------------------
Gjs-Message: 21:24:37.837: JS LOG: Device = 16 AddressType = public rssi = -70 connected = false
Gjs-Message: 21:24:37.838: JS LOG:  
Gjs-Message: 21:24:37.838: JS LOG:  
Gjs-Message: 21:24:42.828: JS LOG: StopDiscoveryAsync
maniacx commented 1 month ago

I also do not know why this is happening.

For user thapa-sabin who also has mediatek chipset The extension and script works in on Debian But not working in Fedora.

I can only guess what could be the issue, could be one of the following.

  1. Could be an bluez experimental enabled I know that Debian by default comes with Bluez experimental features Disabled. I know that Fedora by default comes with Bluez experimental features Enabled. I also read an very old post that le scan breaks when experimental features are Enabled, but was a very old post and a lot may have changed by then.

Now the problem with Fedora, I did not find a way to Disable Bluez Experimental Feature. I also use Fedora and want to test how to disable it but couldn;t. I posted on the Matrix channel there was not response. On Fedora Forums, you can see the discussion here. https://forums.fedoraforum.org/showthread.php?332958-Disable-Bluez-experimental-feature

Last suggestion was to compile Bluez from source with flag disabled and try it, but I didnt try that.

  1. It could also be a kernel update breaks, enables or disable a feature that doesnt result in BLE scanning, that makes it work in Debian but not in Fedora.

If you really want to go to the trouble of finding out you could boot usb with live ubuntu iso. Like Debian, Ubuntu also shipped with bluez experimental feaure disabled. Although it is a pain to download and create the iso as it is around 6GB download

Run the script

You can even install run the extension wthout install extension.manager app, as it is a pain to install any app or packages on live enviroment but for extension it is easy. Connect to wifi and run the command

busctl --user call org.gnome.Shell.Extensions /org/gnome/Shell/Extensions org.gnome.Shell.Extensions InstallRemoteExtension s Airpod-Battery-Monitor@maniacx.github.com

It will directly install and enable the extension and there is no need to log out / relogin.

Check if the script / extension works. (with experimental feature disable, it is disable by default on ubuntu)

If it works Enable Bluez experimental feature and restart bluetooth service. Do not reboot the system. It will lose everything and you will have to

sudo  systemctl restart bluetooth

And check again if the script or extension work.

ARdgzC commented 1 month ago

I tried with the latest ubuntu iso on a live usb but I got the same results, I guess i can try with Debian

Update It worked on debian after changin to dual mode

maniacx commented 1 month ago

hmmm. So it doesn't work on ubuntu as well?

Can you do some test.

Run debian

Run these command and post the output here

bluetoothctl version
bluetoothctl show
btmgmt info
uname -r

Switch to dual mode in /etc/bluetooth/main.conf and check and make sure bluez experimental is disabled by experimental flag=false or commented Make sure the extension works.

Switch experimental flag=true in /etc/bluetooth/main.conf restart bluetooth service. Check if the extension works.

ARdgzC commented 1 month ago

It did not work until I uncommented ControllerMode = dual Screenshot from 2024-07-24 13-05-26

Output:

user@debian:~$ bluetoothctl version
Version 5.66
user@debian:~$ bluetoothctl show
Controller EC:2E:98:CB:D3:BC (public)
    Name: debian
    Alias: debian
    Class: 0x007c010c
    Powered: yes
    Discoverable: no
    DiscoverableTimeout: 0x000000b4
    Pairable: no
    UUID: Message Notification Se.. (00001133-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: OBEX Object Push          (00001105-0000-1000-8000-00805f9b34fb)
    UUID: Message Access Server     (00001132-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: IrMC Sync                 (00001104-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (00005005-0000-1000-8000-0002ee000001)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Phonebook Access Server   (0000112f-0000-1000-8000-00805f9b34fb)
    UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
    UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
    UUID: OBEX File Transfer        (00001106-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
    Modalias: usb:v1D6Bp0246d0542
    Discovering: yes
    Roles: central
    Roles: peripheral
Advertising Features:
    ActiveInstances: 0x00 (0)
    SupportedInstances: 0x14 (20)
    SupportedIncludes: tx-power
    SupportedIncludes: appearance
    SupportedIncludes: local-name
    SupportedSecondaryChannels: 1M
    SupportedSecondaryChannels: 2M
    SupportedSecondaryChannels: Coded
user@debian:~$ btmgmt info
Index list with 1 item
hci0:   Primary controller
    addr EC:2E:98:CB:D3:BC version 11 manufacturer 70 class 0x7c010c
    supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy configuration static-addr phy-configuration wide-band-speech 
    current settings: powered ssp br/edr le secure-conn 
    name debian
    short name 
hci0:   Configuration options
    supported options: public-address 
    missing options: 
user@debian:~$ uname -r
6.1.0-22-amd64

Changing to experimental it still worked Screenshot from 2024-07-24 13-07-25

maniacx commented 1 month ago

Comparing. btmgmt info for both Fedora and Debian seems like Fedora has some new feature enabled . I wonder if that could be the issue


Supported settings` for Fedora

supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr le advertising secure-conn debug-keys privacy configuration static-addr phy-configuration wide-band-speech cis-central cis-peripheral 

supported settings for Debian

supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy configuration static-addr phy-configuration wide-band-speech 

current settings for Fedora

current settings: powered ssp br/edr le secure-conn wide-band-speech cis-central cis-peripheral iso-broadcaster sync-receiver

current settings for Debian

current settings: powered ssp br/edr le secure-conn

In Fedora we have additional feature supported and enabled cis-central cis-peripheral iso-broadcaster sync-receiver

But I dont know what they do and how to disable just for testing in Fedora. If you know how to disable them try it in Fedora, If I find out I will let you know.

maniacx commented 1 month ago

If you still have Fedora, could you disable Kernel Experimental flag on /etc/bluetooth/main.conf. Remove the #

# Enables kernel experimental features, alternatively a list of UUIDs
# can be given.
# Possible values: true,false,<UUID List>
# Possible UUIDS:
# d4992530-b9ec-469f-ab01-6c481c47da1c (BlueZ Experimental Debug)
# 671b10b5-42c0-4696-9227-eb28d1b049d6 (BlueZ Experimental Simultaneous Central and Peripheral)
# 15c0a148-c273-11ea-b3de-0242ac130004 (BlueZ Experimental LL privacy)
# 330859bc-7506-492d-9370-9a6f0614037f (BlueZ Experimental Bluetooth Quality Report)
# a6695ace-ee7f-4fb9-881a-5fac66c629af (BlueZ Experimental Offload Codecs)
# 6fbaf188-05e0-496a-9885-d6ddfdb4e03e (BlueZ Experimental ISO socket)
# 69518c4c-b69f-4679-8bc1-c021b47b5733 (BlueZ Experimental Poll Errqueue)
# Defaults to false.
KernelExperimental = false
sudo systemctl restart bluetooth

And then

btmgmt info

Post the output here and try the extension Also check in bluettoothctl and scan on and see if it post manufacturing data when connected.

ARdgzC commented 1 month ago

This is the output after changing KernelExperimental = false. the extension still not working and there is no manufacturer data in scan on

[ardgzc@rigel:~]$ btmgmt info
Index list with 1 item
hci0:   Primary controller
    addr EC:2E:98:CB:D3:BC version 11 manufacturer 70 class 0x6c010c
    supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr le advertising secure-conn debug-keys privacy configuration static-addr phy-configuration wide-band-speech cis-central cis-peripheral 
    current settings: powered ssp br/edr le secure-conn wide-band-speech cis-central cis-peripheral iso-broadcaster sync-receiver 
    name Rigel
    short name 
hci0:   Configuration options
    supported options: public-address 
    missing options: 
maniacx commented 1 month ago

I submitted an issue here.

https://github.com/bluez/bluez/issues/913#issuecomment-2252977511

I was hoping that we could disable this, just for testing but no luck. Seems like on Fedora they have propably compiled bluez with everything enabled, experimental and kernel experimental.