[PATCH 2/4] bluetooth: Add specific form factor for phones

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/19/2013 10:33 AM, Mikel Astiz wrote:
> From: Mikel Astiz <mikel.astiz at bmw-carit.de>
>
> When a phone is paired, use PA_BT_FORM_FACTOR_PHONE to properly specify
> its form factor.
> ---
>   src/modules/bluetooth/bluetooth-util.c | 25 +++++++++++++++++--------
>   src/modules/bluetooth/bluetooth-util.h |  1 +
>   2 files changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
> index faf1c41..bf1c98f 100644
> --- a/src/modules/bluetooth/bluetooth-util.c
> +++ b/src/modules/bluetooth/bluetooth-util.c
> @@ -1799,7 +1799,7 @@ pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hoo
>   }
>
>   pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class) {
> -    unsigned i;
> +    unsigned major, minor;
>       pa_bt_form_factor_t r;
>
>       static const pa_bt_form_factor_t table[] = {
> @@ -1813,16 +1813,23 @@ pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class) {
>           [10] = PA_BT_FORM_FACTOR_HIFI
>       };
>
> -    if (((class >> 8) & 31) != 4)
> -        return PA_BT_FORM_FACTOR_UNKNOWN;
> +    major = (class >> 8) & 31;
> +    minor = (class >> 2) & 63;

Nitpick: prefer hex for bit operations (31 => 0x1f, 63 => 0x3f)

>
> -    if ((i = (class >> 2) & 63) >= PA_ELEMENTSOF(table))
> -        r =  PA_BT_FORM_FACTOR_UNKNOWN;
> -    else
> -        r = table[i];
> +    switch (major) {
> +        case 2:
> +            return PA_BT_FORM_FACTOR_PHONE;
> +        case 4:
> +            break;
> +        default:
> +            pa_log_debug("Unknown Bluetooth major device class %u", major);
> +            return PA_BT_FORM_FACTOR_UNKNOWN;
> +    }

I assume you know these numbers better than I do, so I guess all this is 
correct :-) - but I'll say to you what Tanu just said to me recently: a 
link to the relevant specification wouldn't hurt.

> +
> +    r = minor < PA_ELEMENTSOF(table) ? table[minor] : PA_BT_FORM_FACTOR_UNKNOWN;
>
>       if (!r)
> -        pa_log_debug("Unknown Bluetooth minor device class %u", i);
> +        pa_log_debug("Unknown Bluetooth minor device class %u", minor);
>
>       return r;
>   }
> @@ -1847,6 +1854,8 @@ const char *pa_bt_form_factor_to_string(pa_bt_form_factor_t ff) {
>               return "car";
>           case PA_BT_FORM_FACTOR_HIFI:
>               return "hifi";
> +        case PA_BT_FORM_FACTOR_PHONE:
> +            return "phone";
>       }
>
>       pa_assert_not_reached();
> diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
> index b59255e..3361b0f 100644
> --- a/src/modules/bluetooth/bluetooth-util.h
> +++ b/src/modules/bluetooth/bluetooth-util.h
> @@ -164,6 +164,7 @@ typedef enum pa_bt_form_factor {
>       PA_BT_FORM_FACTOR_PORTABLE,
>       PA_BT_FORM_FACTOR_CAR,
>       PA_BT_FORM_FACTOR_HIFI,
> +    PA_BT_FORM_FACTOR_PHONE,
>   } pa_bt_form_factor_t;
>
>   pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class);
>



-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux