Bluetooth: controller: Fix LLCP enc. execution ctx
rp_enc_state_wait_ltk_reply() is executed in thread context, so it is not allowed to move the encryption state machine forward. Defer LTK reply handling to next prepare event by introducing a continue state. Update the unit test to reflect this, and remove the TODO that actually said there was an issue in the first place. Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
This commit is contained in:
parent
d1504ff66f
commit
00c5edd411
2 changed files with 28 additions and 6 deletions
|
@ -99,6 +99,7 @@ enum {
|
|||
RP_ENC_STATE_WAIT_RX_ENC_REQ,
|
||||
RP_ENC_STATE_WAIT_TX_ENC_RSP,
|
||||
RP_ENC_STATE_WAIT_LTK_REPLY,
|
||||
RP_ENC_STATE_WAIT_LTK_REPLY_CONTINUE,
|
||||
RP_ENC_STATE_WAIT_TX_START_ENC_REQ,
|
||||
RP_ENC_STATE_WAIT_TX_REJECT_IND,
|
||||
RP_ENC_STATE_WAIT_RX_START_ENC_RSP,
|
||||
|
@ -981,13 +982,28 @@ static void rp_enc_state_wait_ltk_reply(struct ll_conn *conn, struct proc_ctx *c
|
|||
{
|
||||
switch (evt) {
|
||||
case RP_ENC_EVT_LTK_REQ_REPLY:
|
||||
rp_enc_send_start_enc_req(conn, ctx, evt, param);
|
||||
/* Continue procedure in next prepare run */
|
||||
ctx->state = RP_ENC_STATE_WAIT_LTK_REPLY_CONTINUE;
|
||||
break;
|
||||
case RP_ENC_EVT_LTK_REQ_NEG_REPLY:
|
||||
ctx->data.enc.error = BT_HCI_ERR_PIN_OR_KEY_MISSING;
|
||||
ctx->reject_ext_ind.reject_opcode = PDU_DATA_LLCTRL_TYPE_ENC_REQ;
|
||||
ctx->reject_ext_ind.error_code = BT_HCI_ERR_PIN_OR_KEY_MISSING;
|
||||
rp_enc_send_reject_ind(conn, ctx, evt, param);
|
||||
/* Send reject in next prepare run */
|
||||
ctx->state = RP_ENC_STATE_WAIT_TX_REJECT_IND;
|
||||
break;
|
||||
default:
|
||||
/* Ignore other evts */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void rp_enc_state_wait_ltk_reply_continue(struct ll_conn *conn, struct proc_ctx *ctx,
|
||||
uint8_t evt, void *param)
|
||||
{
|
||||
switch (evt) {
|
||||
case RP_ENC_EVT_RUN:
|
||||
rp_enc_send_start_enc_req(conn, ctx, evt, param);
|
||||
break;
|
||||
default:
|
||||
/* Ignore other evts */
|
||||
|
@ -1148,6 +1164,9 @@ static void rp_enc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8
|
|||
case RP_ENC_STATE_WAIT_LTK_REPLY:
|
||||
rp_enc_state_wait_ltk_reply(conn, ctx, evt, param);
|
||||
break;
|
||||
case RP_ENC_STATE_WAIT_LTK_REPLY_CONTINUE:
|
||||
rp_enc_state_wait_ltk_reply_continue(conn, ctx, evt, param);
|
||||
break;
|
||||
case RP_ENC_STATE_WAIT_TX_START_ENC_REQ:
|
||||
rp_enc_state_wait_tx_start_enc_req(conn, ctx, evt, param);
|
||||
break;
|
||||
|
|
|
@ -1224,7 +1224,7 @@ ZTEST(encryption_start, test_encryption_start_periph_rem)
|
|||
ull_cp_ltk_req_reply(&conn, ltk);
|
||||
|
||||
/* Check state */
|
||||
CHECK_RX_PE_STATE(conn, PAUSED, ENCRYPTED); /* Rx paused & enc. */
|
||||
CHECK_RX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Rx paused & unenc. */
|
||||
CHECK_TX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Tx paused & unenc. */
|
||||
|
||||
/* Prepare */
|
||||
|
@ -1684,9 +1684,8 @@ ZTEST(encryption_start, test_encryption_start_periph_rem_no_ltk)
|
|||
ull_cp_ltk_req_neq_reply(&conn);
|
||||
|
||||
/* Check state */
|
||||
/* TODO(thoh): THIS IS WRONG! */
|
||||
CHECK_RX_PE_STATE(conn, RESUMED, UNENCRYPTED); /* Rx unenc. */
|
||||
CHECK_TX_PE_STATE(conn, RESUMED, UNENCRYPTED); /* Tx unenc. */
|
||||
CHECK_RX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Rx paused & unenc. */
|
||||
CHECK_TX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Tx paused & unenc. */
|
||||
|
||||
/* Prepare */
|
||||
event_prepare(&conn);
|
||||
|
@ -2125,6 +2124,10 @@ ZTEST(encryption_pause, test_encryption_pause_periph_rem)
|
|||
/* LTK request reply */
|
||||
ull_cp_ltk_req_reply(&conn, ltk);
|
||||
|
||||
/* Check state */
|
||||
CHECK_RX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Rx paused & unenc. */
|
||||
CHECK_TX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Tx paused & unenc. */
|
||||
|
||||
/* Prepare */
|
||||
event_prepare(&conn);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue