Hello Lin,

Keng-Yu Lin [2011-02-24 14:49 +0800]:
> +btusbget() {
> +    local dev usb
> +    usb="/sys/bus/usb/devices"
> +    for dev in "$usb"/*; do
> +     [[ -f "${dev}/bDeviceClass" ]] || continue
> +     [[ "$(cat "${dev}/bDeviceClass")" = "e0" ]] || continue # Wireless
> +     [[ -f "${dev}/bDeviceProtocol" ]] || continue
> +     [[ "$(cat "${dev}/bDeviceProtocol")" = "01" ]] || continue # Bluetooth
> +     case $1 in
> +         vendor) echo "$(cat "${dev}/idVendor")" ;;
> +         device) echo "$(cat "${dev}/idProduct")" ;;
> +     esac
> +     break
> +    done
> +}

This should still be improved, as it will run hundreds of cat
subprocesses, iterate through the device tree twice, and also stop at
the first bluetooth adapter instead of testing all of them.

A nice trick for this is to use udevadm trigger. This works on my
system (with a different adapter which I added to $quirks for
testing):

---------------- 8< --------------------
quirks="0a5c:219c 0a5c:21bc 413c:8187"

for usbid in $quirks; do
    vendor=${usbid%:*}
    product=${usbid#*:}
    
    DEVS=$(udevadm trigger --verbose --dry-run \
        --attr-match=bDeviceClass=e0 --attr-match=bDeviceProtocol=01 \
        --attr-match=idVendor=$vendor --attr-match=idProduct=$product)
    if [ -n "$DEVS" ]; then
        echo add_parameters --quirk-bluetooth-service-off
    fi
done
---------------- 8< --------------------

This will consider all bluetooth adapters and only do one external
program call. Can you please confirm that this still works on your
system? This should also be forwarded upstream, but Michael and I can
also take care of that.

Thanks,

Martin
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)

Attachment: signature.asc
Description: Digital signature

Reply via email to