diff --git a/CHANGELOG.md b/CHANGELOG.md index c216a8ca3..860b17e84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - HID Host: return complete HID report ### Changed +- GAP: return command disallowed if disconnect already requested + ## Release v1.6.1 diff --git a/src/hci.c b/src/hci.c index c20f28938..6284352c1 100644 --- a/src/hci.c +++ b/src/hci.c @@ -9035,13 +9035,23 @@ uint8_t gap_disconnect(hci_con_handle_t handle){ hci_emit_disconnection_complete(handle, 0); return 0; } - // ignore if already disconnected - if (conn->state == RECEIVED_DISCONNECTION_COMPLETE){ - return 0; + uint8_t status = ERROR_CODE_SUCCESS; + switch (conn->state){ + case RECEIVED_DISCONNECTION_COMPLETE: + // ignore if remote just disconnected + break; + case SEND_DISCONNECT: + case SENT_DISCONNECT: + // disconnect already requested or sent + status = ERROR_CODE_COMMAND_DISALLOWED; + break; + default: + // trigger hci_disconnect + conn->state = SEND_DISCONNECT; + hci_run(); + break; } - conn->state = SEND_DISCONNECT; - hci_run(); - return 0; + return status; } int gap_read_rssi(hci_con_handle_t con_handle){