Bluetooth: GATT: Fix not queuing writes to CCC

In order to properly queue request there need to be a bt_att_req
storage but none of the calls to gatt_write_ccc were using the params
causing gatt_send to use bt_att_send and not bt_att_req_send.

To fix this now all the callers of gatt_write_ccc do set the params
properly but this means that bt_gatt_unsubscribe has to wait for it
to be completed before the application can reuse the
bt_gatt_subscribe_params.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2017-05-30 11:24:37 +03:00 committed by Johan Hedberg
commit 7b9013140d
3 changed files with 13 additions and 7 deletions

View file

@ -1030,7 +1030,8 @@ int bt_gatt_subscribe(struct bt_conn *conn,
*
* This procedure unsubscribe to value notification using the Client
* Characteristic Configuration handle. Notification callback with NULL data
* will not be called if subscription was removed by this call.
* will be called if subscription was removed by this call, until then the
* parameters cannot be reused.
*
* @param conn Connection object.
* @param params Subscribe parameters.

View file

@ -1665,6 +1665,9 @@ static void gatt_write_ccc_rsp(struct bt_conn *conn, u8_t err,
prev = node;
}
} else if (!params->value) {
/* Notify with NULL data to complete unsubscribe */
params->notify(conn, params, NULL, 0);
}
}
@ -1725,7 +1728,7 @@ int bt_gatt_subscribe(struct bt_conn *conn,
int err;
err = gatt_write_ccc(conn, params->ccc_handle, params->value,
gatt_write_ccc_rsp, NULL);
gatt_write_ccc_rsp, params);
if (err) {
return err;
}
@ -1777,10 +1780,15 @@ int bt_gatt_unsubscribe(struct bt_conn *conn,
}
if (has_subscription) {
/* Notify with NULL data to complete unsubscribe */
params->notify(conn, params, NULL, 0);
return 0;
}
return gatt_write_ccc(conn, params->ccc_handle, 0x0000, NULL, NULL);
params->value = 0x0000;
return gatt_write_ccc(conn, params->ccc_handle, params->value,
gatt_write_ccc_rsp, params);
}
void bt_gatt_cancel(struct bt_conn *conn, void *params)
@ -1802,7 +1810,7 @@ static void add_subscriptions(struct bt_conn *conn)
* it properly.
*/
gatt_write_ccc(conn, params->ccc_handle, params->value,
NULL, NULL);
NULL, params);
}
}

View file

@ -1433,9 +1433,6 @@ static int cmd_gatt_unsubscribe(int argc, char *argv[])
printk("Unsubscribe success\n");
}
/* Clear subscribe_params to reuse it */
memset(&subscribe_params, 0, sizeof(subscribe_params));
return 0;
}
#endif /* CONFIG_BLUETOOTH_GATT_CLIENT */