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 <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2021-02-09 20:04:35 +01:00 committed by Anas Nashif
commit abd470cbe6

View file

@ -377,21 +377,21 @@ static int cmd_write(const struct shell *shell, size_t argc, char *argv[])
handle = strtoul(argv[1], NULL, 16);
offset = strtoul(argv[2], NULL, 16);
write_params.data = gatt_write_buf;
write_params.handle = handle;
write_params.offset = offset;
write_params.func = write_func;
write_params.length = hex2bin(argv[3], strlen(argv[3]),
gatt_write_buf, sizeof(gatt_write_buf));
if (write_params.length == 0) {
shell_error(shell, "No data set");
return -ENOEXEC;
}
write_params.data = gatt_write_buf;
write_params.handle = handle;
write_params.offset = offset;
write_params.func = write_func;
err = bt_gatt_write(default_conn, &write_params);
if (err) {
write_params.func = NULL;
shell_error(shell, "Write failed (err %d)", err);
} else {
shell_print(shell, "Write pending");