core: add D-Bus property for TxPower
PATCH 1/1 core: add D-Bus property for TxPower
This is presented as a raw property rather than a parsed "PathLoss" property because in the case of many devices, this specific field will not be present and instead the TX power will have to be parsed from manufacturer-specific data anyway.
It's better therefore to document the Path Loss equation rather than hide it.
--- doc/device-api.txt | 12 ++++++++++++ src/adapter.c | 6 ++++-- src/device.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/device.h | 1 + 4 files changed, 58 insertions(+), 2 deletions(-)
doc/device-api.txt +12 -0
@@ -193,3 +193,15 @@ Properties string Address [readonly] Received Signal Strength Indicator of the remote device (inquiry or advertising). + + int16 TxPower [readonly, optional] + + Transmission power claimed by the remote device + (inquiry or advertising). Many devices may not make + this available at all, or may incorporate this data + into a manufacturer or service-specific field instead. + + However the remote transmission power is obtained, + path loss can be calculated by the equation: + + Path Loss = Tx Power - RSSI
src/adapter.c +4 -2
@@ -1585,16 +1585,17 @@ static int compare_sender(gconstpointer a, gconstpointer b)return g_strcmp0 (client->owner, sender); } -static void invalidate_rssi (gpointer a) +static void invalidate_inquiry_data (gpointer a) {struct btd_device *dev = a;device_set_rssi (dev,0 ); +device_set_tx_power (dev,127 ); }static void discovery_cleanup (struct btd_adapter *adapter) { -g_slist_free_full (adapter->discovery_found, invalidate_rssi); +g_slist_free_full (adapter->discovery_found, invalidate_inquiry_data); adapter->discovery_found =NULL ; }
@@ -4715,6 +4716,7 @@ static void update_found_devices(struct btd_adapter *adapter,device_set_legacy (dev, legacy);device_set_rssi (dev, rssi); +device_set_tx_power (dev, eir_data.tx_power);if (eir_data.appearance !=0 )device_set_appearance (dev, eir_data.appearance);
src/device.c +41 -0
65 lines not on this page · raw message
src/device.h +1 -0
@@ -88,6 +88,7 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted);void device_set_bonded (struct btd_device *device,uint8_t bdaddr_type);void device_set_legacy (struct btd_device *device,bool legacy);void device_set_rssi (struct btd_device *device,int8_t rssi); +void device_set_tx_power (struct btd_device *device,int8_t tx_power);bool btd_device_is_connected (struct btd_device *dev);uint8_t btd_device_get_bdaddr_type (struct btd_device *dev);bool device_is_retrying (struct btd_device *device);
Signature · 1 line
2.1.0.rc2.206.gedb03e5
PATCH 1/1 core: add D-Bus property for ManufacturerData
--- doc/device-api.txt | 10 +++++++ src/adapter.c | 1 + src/device.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/device.h | 2 ++ src/eir.c | 30 ++++++++++++++++++++ src/eir.h | 10 +++++++ 6 files changed, 135 insertions(+)
doc/device-api.txt +10 -0
@@ -134,6 +134,16 @@ Properties string Address [readonly] List of 128-bit UUIDs that represents the available remote services. + array{struct of data} ManufacturerData [readonly, optional] + + List of manufacturer-specific data obtained from the + device. Each array member is a struct of uint16 + containing the vendor identifier and an array of bytes + containing the manufacturer data. + + Duplicate entries for a single manufacturer are + permitted. + boolean Paired [readonly] Indicates if the remote device is paired.
src/adapter.c +1 -0
@@ -4739,6 +4739,7 @@ static void update_found_devices(struct btd_adapter *adapter, eir_data.did_version);device_add_eir_uuids (dev, eir_data.services); +device_set_eir_manufacturer_data (dev, eir_data.manufacturer_data);eir_data_free (&eir_data);
src/device.c +82 -0
118 lines not on this page · raw message
src/device.h +2 -0
@@ -72,6 +72,8 @@ void btd_device_gatt_set_service_changed(struct btd_device *device,bool device_attach_attrib (struct btd_device *dev,GIOChannel *io);void btd_device_add_uuid (struct btd_device *device,const char *uuid);void device_add_eir_uuids (struct btd_device *dev,GSList *uuids); +void device_set_eir_manufacturer_data (struct btd_device *dev, +GSList *manufacturer_data);void device_probe_profile (gpointer a,gpointer b);void device_remove_profile (gpointer a,gpointer b);struct btd_adapter *device_get_adapter (struct btd_device *device);
src/eir.c +30 -0
@@ -43,10 +43,19 @@#define EIR_OOB_MIN (2 + 6) +void eir_manufacturer_data_free (struct eir_manufacturer_data *manufacturer_data) +{ +g_free (manufacturer_data->data); + manufacturer_data->data =NULL ; +} +void eir_data_free (struct eir_data *eir) {g_slist_free_full (eir->services, free); eir->services =NULL ; +g_slist_free_full (eir->manufacturer_data, + (GDestroyNotify )eir_manufacturer_data_free); + eir->manufacturer_data =NULL ;g_free (eir->name); eir->name =NULL ;g_free (eir->hash);
@@ -114,6 +123,23 @@ static void eir_parse_uuid128(struct eir_data *eir, const uint8_t *data, } } +static void eir_parse_manufacturer_data (struct eir_data *eir, +const uint8_t *data,uint8_t len) +{ +struct eir_manufacturer_data *manufacturer_data; + +if (len <2 ) +return ; + + manufacturer_data = g_new0(struct eir_manufacturer_data, 1); + manufacturer_data->vendor =get_le16 (data); + manufacturer_data->data =g_memdup (data +2 , len -2 ); + manufacturer_data->len = len -2 ; + + eir->manufacturer_data =g_slist_append (eir->manufacturer_data, + manufacturer_data); +} +static char *name2utf8 (const uint8_t *name,uint8_t len) {char utf8_name[HCI_MAX_NAME_LENGTH +2 ];
@@ -240,6 +266,10 @@ void eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len) eir->did_product = data[4 ] | (data[5 ] <<8 ); eir->did_version = data[6 ] | (data[7 ] <<8 );break ; + +case EIR_MANUFACTURER_DATA : +eir_parse_manufacturer_data (eir, data, data_len); +break ; } eir_data += field_len +1 ;
src/eir.h +10 -0
@@ -37,6 +37,7 @@#define EIR_SSP_RANDOMIZER 0x0F/* SSP Randomizer */ #define EIR_DEVICE_ID 0x10/* device ID */ #define EIR_GAP_APPEARANCE 0x19/* GAP appearance */ +#define EIR_MANUFACTURER_DATA 0xFF/* Manufacturer-specific data */ /* Flags Descriptions */ #define EIR_LIM_DISC 0x01/* LE Limited Discoverable Mode */
@@ -49,6 +50,7 @@struct eir_data {GSList *services; +GSList *manufacturer_data;unsigned int flags;char *name;uint32_t class;
@@ -64,6 +66,14 @@ struct eir_data {uint16_t did_source; }; +struct eir_manufacturer_data { +uint16_t vendor; +uint8_t *data; +uint8_t len; +}; + +void eir_manufacturer_data_free (struct eir_manufacturer_data * + manufacturer_data);void eir_data_free (struct eir_data *eir);void eir_parse (struct eir_data *eir,const uint8_t *eir_data,uint8_t eir_len);int eir_parse_oob (struct eir_data *eir,uint8_t *eir_data,uint16_t eir_len);
Signature · 1 line
2.1.0.rc2.206.gedb03e5
Re: [PATCH] core: add D-Bus property for ManufacturerData
Hi Scott,
Quoted 8 lines · Scott James Remnant
--- doc/device-api.txt | 10 +++++++ src/adapter.c | 1 + src/device.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/device.h | 2 ++ src/eir.c | 30 ++++++++++++++++++++ src/eir.h | 10 +++++++ 6 files changed, 135 insertions(+)
The D-Bus property part of this patch looks ok'ish, however we've already got manufacturer data parsing upstream so that needs to be removed (and the rest adapted to the upstream API for this). The D-Bus documentation should also be split to a separate patch.
Johan
PATCH 1/1 core: add D-Bus property for ServiceData
In reply to Scott James RemnantSince the standard doesn't make any specific requirement that a UUID present in a Service Data field be also present in a specific UUIDs field, the UUIDs are also added to that list as well.
--- doc/device-api.txt | 9 ++++++ src/adapter.c | 1 + src/device.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/device.h | 1 + src/eir.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ src/eir.h | 11 +++++++ 6 files changed, 179 insertions(+)
doc/device-api.txt +9 -0
@@ -134,6 +134,15 @@ Properties string Address [readonly] List of 128-bit UUIDs that represents the available remote services. + array{struct of data} ServiceData [readonly, optional] + + List of service-specific data obtained from the device. + Each array member is a struct of string containing the + 128-bit UUID of the service and an array of bytes + containing the service data. + + Duplicate entries for a single service are permitted. + array{struct of data} ManufacturerData [readonly, optional] List of manufacturer-specific data obtained from the
src/adapter.c +1 -0
@@ -4739,6 +4739,7 @@ static void update_found_devices(struct btd_adapter *adapter, eir_data.did_version);device_add_eir_uuids (dev, eir_data.services); +device_set_eir_service_data (dev, eir_data.service_data);device_set_eir_manufacturer_data (dev, eir_data.manufacturer_data);eir_data_free (&eir_data);
src/device.c +85 -0
115 lines not on this page · raw message
src/device.h +1 -0
@@ -72,6 +72,7 @@ void btd_device_gatt_set_service_changed(struct btd_device *device,bool device_attach_attrib (struct btd_device *dev,GIOChannel *io);void btd_device_add_uuid (struct btd_device *device,const char *uuid);void device_add_eir_uuids (struct btd_device *dev,GSList *uuids); +void device_set_eir_service_data (struct btd_device *dev,GSList *service_data);void device_set_eir_manufacturer_data (struct btd_device *dev,GSList *manufacturer_data);void device_probe_profile (gpointer a,gpointer b);
src/eir.c +72 -0
96 lines not on this page · raw message
src/eir.h +11 -0
@@ -36,6 +36,9 @@#define EIR_SSP_HASH 0x0E/* SSP Hash */ #define EIR_SSP_RANDOMIZER 0x0F/* SSP Randomizer */ #define EIR_DEVICE_ID 0x10/* device ID */ +#define EIR_SERVICE_DATA_UUID16 0x16/* 16-bit UUID with service data */ +#define EIR_SERVICE_DATA_UUID32 0x20/* 32-bit UUID with service data */ +#define EIR_SERVICE_DATA_UUID128 0x21/* 128-bit UUID with service data */ #define EIR_GAP_APPEARANCE 0x19/* GAP appearance */ #define EIR_MANUFACTURER_DATA 0xFF/* Manufacturer-specific data */
@@ -50,6 +53,7 @@struct eir_data {GSList *services; +GSList *service_data;GSList *manufacturer_data;unsigned int flags;char *name;
@@ -66,12 +70,19 @@ struct eir_data {uint16_t did_source; }; +struct eir_service_data { +uuid_t uuid; +uint8_t *data; +uint8_t len; +}; +struct eir_manufacturer_data {uint16_t vendor;uint8_t *data;uint8_t len; }; +void eir_service_data_free (struct eir_service_data *service_data);void eir_manufacturer_data_free (struct eir_manufacturer_data * manufacturer_data);void eir_data_free (struct eir_data *eir);
Signature · 1 line
2.1.0.rc2.206.gedb03e5
Re: [PATCH] core: add D-Bus property for ServiceData
Hi Scott,
Quoted 11 lines · Scott James Remnant
Since the standard doesn't make any specific requirement that a UUID present in a Service Data field be also present in a specific UUIDs field, the UUIDs are also added to that list as well.
--- doc/device-api.txt | 9 ++++++ src/adapter.c | 1 + src/device.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/device.h | 1 + src/eir.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ src/eir.h | 11 +++++++ 6 files changed, 179 insertions(+)
This too looks fine, but the documentation and EIR parsing parts should be split into their own patches.
Johan
Luiz Augusto von Dentz
maintainerRe: [PATCH] core: add D-Bus property for ServiceData
Hi Scott, Johan,
Quoted 15 lines · Johan Hedberg
Hi Scott,
Quoted 11 lines · Scott James Remnant
Since the standard doesn't make any specific requirement that a UUID present in a Service Data field be also present in a specific UUIDs field, the UUIDs are also added to that list as well.
--- doc/device-api.txt | 9 ++++++ src/adapter.c | 1 + src/device.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/device.h | 1 + src/eir.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ src/eir.h | 11 +++++++ 6 files changed, 179 insertions(+)
Quoted 2 lines
This too looks fine, but the documentation and EIR parsing parts should be split into their own patches.
Another possibility would be to add a Data property to org.bluez.GattService1, but then if the service is not gatt based perhaps we need something else. I had actually plans to introduce a generic Service interface as a plugin, it was originally meant to provide a better control over connections for classic, the interface documentation can be found here:
This could be exposed in the same object as org.bluez.GattService1 but we would need to align because right now the paths are different, having another Property would be easy to add and we can mark some properties optional in case they don't make sense in LE.
Signature · 1 line
Luiz Augusto von Dentz
Hi Scott,
Quoted 5 lines · Scott James Remnant
This is presented as a raw property rather than a parsed "PathLoss" property because in the case of many devices, this specific field will not be present and instead the TX power will have to be parsed from manufacturer-specific data anyway.
Quoted 8 lines
It's better therefore to document the Path Loss equation rather than hide it.
--- doc/device-api.txt | 12 ++++++++++++ src/adapter.c | 6 ++++-- src/device.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/device.h | 1 + 4 files changed, 58 insertions(+), 2 deletions(-)
I don't have any particular objections to this patch except that the API documentation should be in a separate patch.
Johan
Luiz Augusto von Dentz
maintainerHi Scott,
Quoted 7 lines · Scott James Remnant
This is presented as a raw property rather than a parsed "PathLoss" property because in the case of many devices, this specific field will not be present and instead the TX power will have to be parsed from manufacturer-specific data anyway.
It's better therefore to document the Path Loss equation rather than hide it.
Im trying to understand your reasoning here, so TxPower is better because is what you can get from manufacturer data? If we have RSSI and Tx Power we could just do the math and expose as PathLoss don't we?
Quoted 151 lines
--- doc/device-api.txt | 12 ++++++++++++ src/adapter.c | 6 ++++-- src/device.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/device.h | 1 + 4 files changed, 58 insertions(+), 2 deletions(-)doc/device-api.txt +12
-0@@ -193,3 +193,15 @@ Properties string Address [readonly] Received Signal Strength Indicator of the remote device (inquiry or advertising). + + int16 TxPower [readonly, optional] + + Transmission power claimed by the remote device + (inquiry or advertising). Many devices may not make + this available at all, or may incorporate this data + into a manufacturer or service-specific field instead. + + However the remote transmission power is obtained, + path loss can be calculated by the equation: + + Path Loss = Tx Power - RSSIsrc/adapter.c +4
-2@@ -1585,16 +1585,17 @@ static int compare_sender(gconstpointer a, gconstpointer b)return g_strcmp0 (client->owner, sender); } -static void invalidate_rssi (gpointer a) +static void invalidate_inquiry_data (gpointer a) {struct btd_device *dev = a;device_set_rssi (dev,0 ); +device_set_tx_power (dev,127 ); }static void discovery_cleanup (struct btd_adapter *adapter) { -g_slist_free_full (adapter->discovery_found, invalidate_rssi); +g_slist_free_full (adapter->discovery_found, invalidate_inquiry_data); adapter->discovery_found =NULL ; }@@ -4715,6 +4716,7 @@ static void update_found_devices(struct btd_adapter *adapter,device_set_legacy (dev, legacy);device_set_rssi (dev, rssi); +device_set_tx_power (dev, eir_data.tx_power);if (eir_data.appearance !=0 )device_set_appearance (dev, eir_data.appearance);src/device.c +41
-0@@ -219,6 +219,7 @@ struct btd_device {bool legacy;int8_t rssi; +int8_t tx_power;GIOChannel *att_io;guint cleanup_id;@@ -812,6 +813,28 @@ static gboolean dev_property_exists_rssi(const GDBusPropertyTable *property,return TRUE; } +static gboolean dev_property_get_tx_power (const GDBusPropertyTable *property, +DBusMessageIter *iter,void *data) +{ +struct btd_device *dev = data; +dbus_int16_t val = dev->tx_power; + +dbus_message_iter_append_basic (iter,DBUS_TYPE_INT16 , &val); + +return TRUE; +} + +static gboolean dev_property_exists_tx_power (const GDBusPropertyTable *property, +void *data) +{ +struct btd_device *dev = data; + +if (dev->tx_power ==127 ) +return FALSE; + +return TRUE; +} +static gboolean dev_property_get_trusted (const GDBusPropertyTable *property,DBusMessageIter *iter,void *data) {@@ -1957,6 +1980,8 @@ static const GDBusPropertyTable device_properties[] = { { "Blocked", "b", dev_property_get_blocked, dev_property_set_blocked }, { "LegacyPairing", "b", dev_property_get_legacy }, { "RSSI", "n", dev_property_get_rssi, NULL, dev_property_exists_rssi }, + { "TxPower", "n", dev_property_get_tx_power, NULL, + dev_property_exists_tx_power }, { "Connected", "b", dev_property_get_connected }, { "UUIDs", "as", dev_property_get_uuids }, { "Modalias", "s", dev_property_get_modalias, NULL,@@ -4107,6 +4132,22 @@ void device_set_rssi(struct btd_device *device, int8_t rssi) DEVICE_INTERFACE, "RSSI"); } +void device_set_tx_power (struct btd_device *device,int8_t tx_power) +{ +if (!device) +return ; + +if (device->tx_power == tx_power) +return ; + +DBG ("tx_power %d" , tx_power); + + device->tx_power = tx_power; + +g_dbus_emit_property_changed (dbus_conn, device->path, +DEVICE_INTERFACE ,"TxPower" ); +} +static gboolean start_discovery (gpointer user_data) {struct btd_device *device = user_data;src/device.h +1
-1@@ -88,6 +88,7 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted);void device_set_bonded (struct btd_device *device,uint8_t bdaddr_type);void device_set_legacy (struct btd_device *device,bool legacy);void device_set_rssi (struct btd_device *device,int8_t rssi); +void device_set_tx_power (struct btd_device *device,int8_t tx_power);bool btd_device_is_connected (struct btd_device *dev);uint8_t btd_device_get_bdaddr_type (struct btd_device *dev);bool device_is_retrying (struct btd_device *device); --2.1.0.rc2.206.gedb03e5
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Luiz Augusto von Dentz