Skip to content

Commit abd470c

Browse files
joerchannashif
authored andcommitted
Bluetooth: shell: Fix gatt write command not cleanup up on error
Fix gatt write command returned "write in progress" when either hex2bin or bt_gatt_write returned an error. The write_params.func should not be set if the write command was not successful. Signed-off-by: Joakim Andersson <[email protected]>
1 parent e831792 commit abd470c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

subsys/bluetooth/shell/gatt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,21 +377,21 @@ static int cmd_write(const struct shell *shell, size_t argc, char *argv[])
377377
handle = strtoul(argv[1], NULL, 16);
378378
offset = strtoul(argv[2], NULL, 16);
379379

380-
write_params.data = gatt_write_buf;
381-
write_params.handle = handle;
382-
write_params.offset = offset;
383-
write_params.func = write_func;
384-
385380
write_params.length = hex2bin(argv[3], strlen(argv[3]),
386381
gatt_write_buf, sizeof(gatt_write_buf));
387-
388382
if (write_params.length == 0) {
389383
shell_error(shell, "No data set");
390384
return -ENOEXEC;
391385
}
392386

387+
write_params.data = gatt_write_buf;
388+
write_params.handle = handle;
389+
write_params.offset = offset;
390+
write_params.func = write_func;
391+
393392
err = bt_gatt_write(default_conn, &write_params);
394393
if (err) {
394+
write_params.func = NULL;
395395
shell_error(shell, "Write failed (err %d)", err);
396396
} else {
397397
shell_print(shell, "Write pending");

0 commit comments

Comments
 (0)