gatt-api: Add MTU property to GattCharacteristic1
Luiz Augusto von Dentz
maintainerPATCH 1/5 gatt-api: Add MTU property to GattCharacteristic1
From: Luiz Augusto von Dentz <[email protected]>
This adds MTU properyt to GattCharacteristic1 which can be used in order to determine how much data can be read/write using non-long procedures which sometimes is the only thing the remote device supports.
--- doc/gatt-api.txt | 6 ++++++ 1 file changed, 6 insertions(+)
doc/gatt-api.txt +6 -0
@@ -281,6 +281,12 @@ Properties string UUID [read-only] shall be used which will cause the allocated handle to be set once registered. + uint16 MTU [read-only] + + Characteristic MTU, this is valid both for ReadValue + and WriteValue but either method can use long + procedures when supported. + Characteristic Descriptors hierarchy ====================================
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH 2/5 gatt: Add implementation of GattCharacteristic1.MTU
From: Luiz Augusto von Dentz <[email protected]>
This implements MTU property in GattCharacteristic1 interface.
--- src/gatt-client.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
src/gatt-client.c +20 -0
@@ -873,6 +873,25 @@ characteristic_notify_acquired_exists(const GDBusPropertyTable *property,return (chrc->props &BT_GATT_CHRC_PROP_NOTIFY ); } +static gboolean characteristic_get_mtu (const GDBusPropertyTable *property, +DBusMessageIter *iter,void *data) +{ +struct characteristic *chrc = data; +struct bt_gatt_client *gatt = chrc->service->client->gatt; +struct bt_att *att; +uint16_t mtu; + + att =bt_gatt_client_get_att (gatt); +if (!att) +return FALSE; + + mtu =bt_att_get_mtu (att); + +dbus_message_iter_append_basic (iter,DBUS_TYPE_UINT16 , &mtu); + +return TRUE; +} +static void write_characteristic_cb (struct gatt_db_attribute *attr,int err,void *user_data) {
@@ -1646,6 +1665,7 @@ static const GDBusPropertyTable characteristic_properties[] = { characteristic_write_acquired_exists }, {"NotifyAcquired" ,"b" , characteristic_get_notify_acquired,NULL , characteristic_notify_acquired_exists }, + { "MTU", "q", characteristic_get_mtu, NULL, NULL }, { } };
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH 3/5 shared/att: Add bt_att_register_exchange
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds bt_att_register_exchange which can be used to register handlers that gets notified when the MTU gets changed via MTU exchange procedure.
--- src/shared/att.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++- src/shared/att.h | 6 ++++ 2 files changed, 99 insertions(+), 1 deletion(-)
src/shared/att.c +93 -1
@@ -64,6 +64,7 @@ struct bt_att {struct queue *notify_list;/* List of registered callbacks */ struct queue *disconn_list;/* List of disconnect handlers */ +struct queue *exchange_list;/* List of MTU changed handlers */ unsigned int next_send_id;/* IDs for "send" ops */ unsigned int next_reg_id;/* IDs for registered callbacks */
@@ -257,6 +258,14 @@ struct att_disconn {void *user_data; }; +struct att_exchange { +unsigned int id; +bool removed; +bt_att_exchange_func_t callback; +bt_att_destroy_func_t destroy; +void *user_data; +}; +static void destroy_att_disconn (void *data) {struct att_disconn *disconn = data;
@@ -267,6 +276,16 @@ static void destroy_att_disconn(void *data)free (disconn); } +static void destroy_att_exchange (void *data) +{ +struct att_exchange *exchange = data; + +if (exchange->destroy) + exchange->destroy (exchange->user_data); + +free (exchange); +} +static bool match_disconn_id (const void *a,const void *b) {const struct att_disconn *disconn = a;
@@ -1116,6 +1135,7 @@ static void bt_att_free(struct bt_att *att)queue_destroy (att->write_queue,NULL );queue_destroy (att->notify_list,NULL );queue_destroy (att->disconn_list,NULL ); +queue_destroy (att->exchange_list,NULL );queue_destroy (att->chans, bt_att_chan_free);free (att);
@@ -1242,6 +1262,7 @@ struct bt_att *bt_att_new(int fd, bool ext_signed) att->write_queue =queue_new (); att->notify_list =queue_new (); att->disconn_list =queue_new (); + att->exchange_list =queue_new ();bt_att_attach_chan (att, chan);
@@ -1357,6 +1378,18 @@ uint16_t bt_att_get_mtu(struct bt_att *att)return att->mtu; } +static void exchange_handler (void *data,void *user_data) +{ +struct att_exchange *exchange = data; +uint16_t mtu =PTR_TO_INT (user_data); + +if (exchange->removed) +return ; + +if (exchange->callback) + exchange->callback (mtu, exchange->user_data); +} +bool bt_att_set_mtu (struct bt_att *att,uint16_t mtu) {struct bt_att_chan *chan;
@@ -1382,8 +1415,11 @@ bool bt_att_set_mtu(struct bt_att *att, uint16_t mtu) chan->mtu = mtu; chan->buf = buf; -if (chan->mtu > att->mtu) +if (chan->mtu > att->mtu) { att->mtu = chan->mtu; +queue_foreach (att->exchange_list, exchange_handler, +INT_TO_PTR (att->mtu)); + }return true; }
@@ -1474,6 +1510,61 @@ bool bt_att_unregister_disconnect(struct bt_att *att, unsigned int id)return true; } +unsigned int bt_att_register_exchange (struct bt_att *att, +bt_att_exchange_func_t callback, +void *user_data, +bt_att_destroy_func_t destroy) +{ +struct att_exchange *mtu; + +if (!att ||queue_isempty (att->chans)) +return 0 ; + + mtu = new0(struct att_exchange, 1); + mtu->callback = callback; + mtu->destroy = destroy; + mtu->user_data = user_data; + +if (att->next_reg_id <1 ) + att->next_reg_id =1 ; + + mtu->id = att->next_reg_id++; + +if (!queue_push_tail (att->exchange_list, mtu)) { +free (att); +return 0 ; + } + +return mtu->id; +} + +bool bt_att_unregister_exchange (struct bt_att *att,unsigned int id) +{ +struct att_exchange *mtu; + +if (!att || !id) +return false; + +/* Check if disconnect is running */ +if (queue_isempty (att->chans)) { + mtu =queue_find (att->exchange_list, match_disconn_id, +UINT_TO_PTR (id)); +if (!mtu) +return false; + + mtu->removed = true; +return true; + } + + mtu =queue_remove_if (att->exchange_list, match_disconn_id, +UINT_TO_PTR (id)); +if (!mtu) +return false; + +destroy_att_exchange (mtu); +return true; +} + unsigned int bt_att_send(struct bt_att *att, uint8_t opcode, const void *pdu, uint16_t length, bt_att_response_func_t callback, void *user_data,
@@ -1785,6 +1876,7 @@ bool bt_att_unregister_all(struct bt_att *att)queue_remove_all (att->notify_list,NULL ,NULL , destroy_att_notify);queue_remove_all (att->disconn_list,NULL ,NULL , destroy_att_disconn); +queue_remove_all (att->exchange_list,NULL ,NULL , destroy_att_exchange);return true; }
src/shared/att.h +6 -0
@@ -43,6 +43,7 @@ typedef void (*bt_att_debug_func_t)(const char *str, void *user_data);typedef void (*bt_att_timeout_func_t )(unsigned int id,uint8_t opcode,void *user_data);typedef void (*bt_att_disconnect_func_t )(int err,void *user_data); +typedef void (*bt_att_exchange_func_t )(uint16_t mtu,void *user_data);typedef bool (*bt_att_counter_func_t )(uint32_t *sign_cnt,void *user_data); bool bt_att_set_debug(struct bt_att *att, uint8_t level,
@@ -88,6 +89,11 @@ unsigned int bt_att_register_disconnect(struct bt_att *att, bt_att_destroy_func_t destroy);bool bt_att_unregister_disconnect (struct bt_att *att,unsigned int id); +unsigned int bt_att_register_exchange (struct bt_att *att, +bt_att_exchange_func_t callback, +void *user_data, +bt_att_destroy_func_t destroy); +bool bt_att_unregister_exchange (struct bt_att *att,unsigned int id);bool bt_att_unregister_all (struct bt_att *att);int bt_att_get_security (struct bt_att *att,uint8_t *enc_size);
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH 4/5 gatt: Emit PropertiesChanged("MTU") when MTU is exchanged
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This notifies client when the ATT MTU changes.
--- src/gatt-client.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
src/gatt-client.c +22 -0
@@ -104,6 +104,7 @@ struct characteristic {char *path;unsigned int ready_id; +unsigned int exchange_id;struct sock_io *write_io;struct sock_io *notify_io;
@@ -1707,6 +1708,8 @@ static void remove_client(void *data)static void characteristic_free (void *data) {struct characteristic *chrc = data; +struct bt_gatt_client *gatt = chrc->service->client->gatt; +struct bt_att *att;/* List should be empty here */ queue_destroy (chrc->descs,NULL );
@@ -1723,15 +1726,29 @@ static void characteristic_free(void *data)queue_destroy (chrc->notify_clients, remove_client); + att =bt_gatt_client_get_att (gatt); +if (att) +bt_att_unregister_exchange (att, chrc->exchange_id); +g_free (chrc->path);free (chrc); } +static void att_exchange (uint16_t mtu,void *user_data) +{ +struct characteristic *chrc = user_data; + +g_dbus_emit_property_changed (btd_get_dbus_connection (), chrc->path, +GATT_CHARACTERISTIC_IFACE ,"MTU" ); +} +static struct characteristic *characteristic_create (struct gatt_db_attribute *attr,struct service *service) {struct characteristic *chrc; +struct bt_gatt_client *gatt = service->client->gatt; +struct bt_att *att;bt_uuid_t uuid; chrc = new0(struct characteristic, 1);
@@ -1770,6 +1787,11 @@ static struct characteristic *characteristic_create(return NULL ; } + att =bt_gatt_client_get_att (gatt); +if (att) + chrc->exchange_id =bt_att_register_exchange (att, att_exchange, + chrc,NULL ); +DBG ("Exported GATT characteristic: %s" , chrc->path);return chrc;
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH 5/5 client: Print MTU on attribute-info
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This prints the MTU of the characteristic when available.
--- client/main.c | 1 + 1 file changed, 1 insertion(+)
client/main.c +1 -0
@@ -2232,6 +2232,7 @@ static void cmd_attribute_info(int argc, char *argv[])print_property (proxy,"Value" );print_property (proxy,"Notifying" );print_property (proxy,"Flags" ); +print_property (proxy,"MTU" );print_property (proxy,"Descriptors" ); }else if (!strcmp (iface,"org.bluez.GattDescriptor1" )) {bt_shell_printf ("Descriptor - %s\n" , text);
Signature · 1 line
2.31.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=554631
---Test result---
Test Summary:
CheckPatch PASS 6.84 seconds GitLint PASS 4.61 seconds Prep - Setup ELL PASS 50.24 seconds Build - Prep PASS 0.49 seconds Build - Configure PASS 9.07 seconds Build - Make PASS 219.53 seconds Make Check PASS 9.21 seconds Make Distcheck PASS 256.90 seconds Build w/ext ELL - Configure PASS 9.34 seconds Build w/ext ELL - Make PASS 205.94 seconds
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi,
Quoted 25 lines · On Tue, Sep 28, 2021 at 6:25 PM <[email protected]> wrote:
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=554631---Test result---
Test Summary:
CheckPatch PASS 6.84 seconds GitLint PASS 4.61 seconds Prep - Setup ELL PASS 50.24 seconds Build - Prep PASS 0.49 seconds Build - Configure PASS 9.07 seconds Build - Make PASS 219.53 seconds Make Check PASS 9.21 seconds Make Distcheck PASS 256.90 seconds Build w/ext ELL - Configure PASS 9.34 seconds Build w/ext ELL - Make PASS 205.94 seconds
Quoted 3 lines
---
Regards,
Linux Bluetooth
Pushed.
Signature · 1 line
Luiz Augusto von Dentz