@@ -2068,3 +2068,11 @@ done:
return true;
}
+
+struct queue *bt_att_get_chans(struct bt_att *att)
+{
+ if (!att)
+ return NULL;
+
+ return att->chans;
+}
\ No newline at end of file
@@ -111,3 +111,5 @@ bool bt_att_set_remote_key(struct bt_att *att,
uint8_t sign_key[16],
bt_att_counter_func_t func, void *user_data);
bool bt_att_has_crypto(struct bt_att *att);
bool bt_att_set_retry(struct bt_att *att, unsigned int id, bool retry);
+
+struct queue *bt_att_get_chans(struct bt_att *att);
\ No newline at end of file
@@ -790,7 +790,21 @@ static void write_complete_cb(struct
gatt_db_attribute *attr, int err,
handle = gatt_db_attribute_get_handle(attr);
if (err)
- bt_att_chan_send_error_rsp(op->chan, op->opcode, handle, err);
+ {
+ // Only call bt_att_chan_send_error_rsp if the channel
+ // is still valid
+ struct bt_att *att = bt_gatt_server_get_att(server);
+ struct queue *chans = bt_att_get_chans(att);
+ const struct queue_entry *entry;
+ for (entry = queue_get_entries(chans); entry; entry =
entry->next)
+ {
+ if (entry->data == op->chan)
+ {
+ bt_att_chan_send_error_rsp(op->chan,
op->opcode, handle, err);
+ break;
+ }
+ }
+ }