android/gatt: Store Appearance and Privacy in db
Luiz Augusto von Dentz
maintainerPATCH 1/3 android/gatt: Store Appearance and Privacy in db
From: Luiz Augusto von Dentz <[email protected]>
This stores Appearance and Privacy values in the db itself since they are static and don't depend in any context information.
--- android/gatt.c | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-)
android/gatt.c +29 -20
@@ -6443,24 +6443,6 @@ static void gap_read_cb(struct gatt_db_attribute *attrib, unsigned int id, entry->length =strlen (name);memcpy (entry->value,bt_get_adapter_name (), entry->length); - }else if (attrib == gap_srvc_data.appear) { - entry->value =malloc0 (2 ); -if (!entry->value) { - entry->error =ATT_ECODE_INSUFF_RESOURCES ; - goto done; - } - -put_le16 (APPEARANCE_GENERIC_PHONE , entry->value); - entry->length =sizeof (uint8_t ) *2 ; - }else if (attrib == gap_srvc_data.priv) { - entry->value =malloc0 (1 ); -if (!entry->value) { - entry->error =ATT_ECODE_INSUFF_RESOURCES ; - goto done; - } - - *entry->value =PERIPHERAL_PRIVACY_DISABLE ; - entry->length =sizeof (uint8_t ); }else { entry->error =ATT_ECODE_ATTR_NOT_FOUND ; }
@@ -6471,6 +6453,15 @@ done: entry->state =REQUEST_DONE ; } +static void write_confirm (struct gatt_db_attribute *attrib, +int err,void *user_data) +{ +if (!err) +return ; + +error ("Error writting attribute %p" , attrib); +} +static void register_gap_service (void ) {uint16_t start, end;
@@ -6491,12 +6482,21 @@ static void register_gap_service(void)/* Appearance */ bt_uuid16_create (&uuid,GATT_CHARAC_APPEARANCE ); + gap_srvc_data.appear =gatt_db_service_add_characteristic (gap_srvc_data.srvc, &uuid,GATT_PERM_READ ,GATT_CHR_PROP_READ , - gap_read_cb,NULL , -NULL ); +NULL ,NULL ,NULL ); +if (gap_srvc_data.appear) { +uint16_t value; +/* Store appearance into db */ + value =cpu_to_le16 (APPEARANCE_GENERIC_PHONE ); +gatt_db_attribute_write (gap_srvc_data.appear,0 , + (void *) &value,sizeof (value), +ATT_OP_WRITE_REQ ,NULL , + write_confirm,NULL ); + }/* Pripheral privacy flag */ bt_uuid16_create (&uuid,GATT_CHARAC_PERIPHERAL_PRIV_FLAG );
@@ -6506,6 +6506,15 @@ static void register_gap_service(void)GATT_CHR_PROP_READ , gap_read_cb,NULL , NULL); +if (gap_srvc_data.priv) { +uint8_t value; +/* Store privacy into db */ + value =PERIPHERAL_PRIVACY_DISABLE ; +gatt_db_attribute_write (gap_srvc_data.priv,0 , + &value,sizeof (value), +ATT_OP_WRITE_REQ ,NULL , + write_confirm,NULL ); + }gatt_db_service_set_active (gap_srvc_data.srvc , true);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 2/3 android/gatt: Fix device name characteristic
From: Luiz Augusto von Dentz <[email protected]>
gap_read_cb was never calling gatt_db_attribute_read_result which now cause a timeout after 1 second.
--- android/gatt.c | 58 ++++++++++------------------------------------------------ 1 file changed, 10 insertions(+), 48 deletions(-)
android/gatt.c +10 -48
@@ -4611,13 +4611,6 @@ struct request_processing_data {struct gatt_device *device; }; -static bool match_dev_request_by_attrib (const void *data,const void *user_data) -{ -const struct pending_request *handle_data = data; - -return handle_data->attrib == user_data; -} -static uint8_t check_device_permissions (struct gatt_device *device,uint8_t opcode,uint32_t permissions) {
@@ -6412,45 +6405,15 @@ static struct gap_srvc_handles gap_srvc_data;#define APPEARANCE_GENERIC_PHONE 0x0040#define PERIPHERAL_PRIVACY_DISABLE 0x00 -static void gap_read_cb (struct gatt_db_attribute *attrib,unsigned int id, -uint16_t offset,uint8_t opcode,bdaddr_t *bdaddr, -void *user_data) +static void device_name_read_cb (struct gatt_db_attribute *attrib, +unsigned int id,uint16_t offset, +uint8_t opcode,bdaddr_t *bdaddr, +void *user_data) { -struct pending_request *entry; -struct gatt_device *dev; - -DBG ("" ); +const char *name =bt_get_adapter_name (); - dev =find_device_by_addr (bdaddr); -if (!dev) { -error ("gatt: Could not find device ?!" ); -return ; - } - - entry =queue_find (dev->pending_requests, match_dev_request_by_attrib, - attrib); -if (!entry) -return ; - -if (attrib == gap_srvc_data.dev_name) { -const char *name =bt_get_adapter_name (); - - entry->value =malloc0 (strlen (name)); -if (!entry->value) { - entry->error =ATT_ECODE_INSUFF_RESOURCES ; - goto done; - } - - entry->length =strlen (name); -memcpy (entry->value,bt_get_adapter_name (), entry->length); - }else { - entry->error =ATT_ECODE_ATTR_NOT_FOUND ; - } - - entry->offset = offset; - -done: - entry->state =REQUEST_DONE ; +gatt_db_attribute_read_result (attrib, id,0 , (void *) name, +strlen (name)); } static void write_confirm(struct gatt_db_attribute *attrib,
@@ -6477,8 +6440,8 @@ static void register_gap_service(void)gatt_db_service_add_characteristic (gap_srvc_data.srvc, &uuid,GATT_PERM_READ ,GATT_CHR_PROP_READ , - gap_read_cb,NULL , -NULL ); + device_name_read_cb, +NULL ,NULL );/* Appearance */ bt_uuid16_create (&uuid,GATT_CHARAC_APPEARANCE );
@@ -6504,8 +6467,7 @@ static void register_gap_service(void)gatt_db_service_add_characteristic (gap_srvc_data.srvc, &uuid,GATT_PERM_READ ,GATT_CHR_PROP_READ , - gap_read_cb,NULL , -NULL ); +NULL ,NULL ,NULL );if (gap_srvc_data.priv) {uint8_t value;/* Store privacy into db */
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 3/3 android/gatt: Cleanup unused variables
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- android/gatt.c | 21 --------------------- 1 file changed, 21 deletions(-)
android/gatt.c +0 -21
@@ -6494,15 +6494,8 @@ static void device_info_read_cb(struct gatt_db_attribute *attrib, uint8_t opcode, bdaddr_t *bdaddr, void *user_data) { - struct gatt_device *dev; char *buf = user_data; - dev =find_device_by_addr (bdaddr); -if (!dev) { -error ("gatt: Could not find device ?!" ); -return ; - } -gatt_db_attribute_read_result (attrib, id,0 , user_data,strlen (buf)); }
@@ -6511,15 +6504,8 @@ static void device_info_read_system_id_cb(struct gatt_db_attribute *attrib, uint8_t opcode, bdaddr_t *bdaddr, void *user_data) { - struct gatt_device *dev; uint8_t pdu[8]; - dev =find_device_by_addr (bdaddr); -if (!dev) { -error ("gatt: Could not find device ?!" ); -return ; - } -put_le64 (bt_config_get_system_id (), pdu);gatt_db_attribute_read_result (attrib, id,0 , pdu,sizeof (pdu));
@@ -6530,15 +6516,8 @@ static void device_info_read_pnp_id_cb(struct gatt_db_attribute *attrib, uint8_t opcode, bdaddr_t *bdaddr, void *user_data) { - struct gatt_device *dev; uint8_t pdu[7]; - dev =find_device_by_addr (bdaddr); -if (!dev) { -error ("gatt: Could not find device ?!" ); -return ; - } - pdu[0 ] =bt_config_get_pnp_source ();put_le16 (bt_config_get_pnp_vendor (), &pdu[1 ]);put_le16 (bt_config_get_pnp_product (), &pdu[3 ]);
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerHi,
Quoted 94 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This stores Appearance and Privacy values in the db itself since they are static and don't depend in any context information.
--- android/gatt.c | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-)android/gatt.c +29
-21@@ -6443,24 +6443,6 @@ static void gap_read_cb(struct gatt_db_attribute *attrib, unsigned int id, entry->length =strlen (name);memcpy (entry->value,bt_get_adapter_name (), entry->length); - }else if (attrib == gap_srvc_data.appear) { - entry->value =malloc0 (2 ); -if (!entry->value) { - entry->error =ATT_ECODE_INSUFF_RESOURCES ; - goto done; - } - -put_le16 (APPEARANCE_GENERIC_PHONE , entry->value); - entry->length =sizeof (uint8_t ) *2 ; - }else if (attrib == gap_srvc_data.priv) { - entry->value =malloc0 (1 ); -if (!entry->value) { - entry->error =ATT_ECODE_INSUFF_RESOURCES ; - goto done; - } - - *entry->value =PERIPHERAL_PRIVACY_DISABLE ; - entry->length =sizeof (uint8_t ); }else { entry->error =ATT_ECODE_ATTR_NOT_FOUND ; }@@ -6471,6 +6453,15 @@ done: entry->state =REQUEST_DONE ; } +static void write_confirm (struct gatt_db_attribute *attrib, +int err,void *user_data) +{ +if (!err) +return ; + +error ("Error writting attribute %p" , attrib); +} +static void register_gap_service (void ) {uint16_t start, end;@@ -6491,12 +6482,21 @@ static void register_gap_service(void)/* Appearance */ bt_uuid16_create (&uuid,GATT_CHARAC_APPEARANCE ); + gap_srvc_data.appear =gatt_db_service_add_characteristic (gap_srvc_data.srvc, &uuid,GATT_PERM_READ ,GATT_CHR_PROP_READ , - gap_read_cb,NULL , -NULL ); +NULL ,NULL ,NULL ); +if (gap_srvc_data.appear) { +uint16_t value; +/* Store appearance into db */ + value =cpu_to_le16 (APPEARANCE_GENERIC_PHONE ); +gatt_db_attribute_write (gap_srvc_data.appear,0 , + (void *) &value,sizeof (value), +ATT_OP_WRITE_REQ ,NULL , + write_confirm,NULL ); + }/* Pripheral privacy flag */ bt_uuid16_create (&uuid,GATT_CHARAC_PERIPHERAL_PRIV_FLAG );@@ -6506,6 +6506,15 @@ static void register_gap_service(void)GATT_CHR_PROP_READ , gap_read_cb,NULL , NULL); +if (gap_srvc_data.priv) { +uint8_t value; +/* Store privacy into db */ + value =PERIPHERAL_PRIVACY_DISABLE ; +gatt_db_attribute_write (gap_srvc_data.priv,0 , + &value,sizeof (value), +ATT_OP_WRITE_REQ ,NULL , + write_confirm,NULL ); + }gatt_db_service_set_active (gap_srvc_data.srvc , true); --
Quoted 1 line
1.9.3
This has been applied.
Signature · 1 line
Luiz Augusto von Dentz