Bluetooth: controller: implementing state check for ENC reply API
Now checking that encryption procedure is in correct state to accept a reply from host. Signed-off-by: Erik Brockhoff <erbr@oticon.com>
This commit is contained in:
parent
06078ee54e
commit
025b9745d3
5 changed files with 21 additions and 22 deletions
|
@ -838,27 +838,31 @@ uint8_t ull_cp_data_length_update(struct ll_conn *conn, uint16_t max_tx_octets,
|
|||
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_LE_ENC)
|
||||
void ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16])
|
||||
uint8_t ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16])
|
||||
{
|
||||
/* TODO(thoh): Call rp_enc to query if LTK request reply is allowed */
|
||||
struct proc_ctx *ctx;
|
||||
|
||||
ctx = llcp_rr_peek(conn);
|
||||
if (ctx && (ctx->proc == PROC_ENCRYPTION_START || ctx->proc == PROC_ENCRYPTION_PAUSE)) {
|
||||
if (ctx && (ctx->proc == PROC_ENCRYPTION_START || ctx->proc == PROC_ENCRYPTION_PAUSE) &&
|
||||
llcp_rp_enc_ltk_req_reply_allowed(conn, ctx)) {
|
||||
memcpy(ctx->data.enc.ltk, ltk, sizeof(ctx->data.enc.ltk));
|
||||
llcp_rp_enc_ltk_req_reply(conn, ctx);
|
||||
return BT_HCI_ERR_SUCCESS;
|
||||
}
|
||||
return BT_HCI_ERR_CMD_DISALLOWED;
|
||||
}
|
||||
|
||||
void ull_cp_ltk_req_neq_reply(struct ll_conn *conn)
|
||||
uint8_t ull_cp_ltk_req_neq_reply(struct ll_conn *conn)
|
||||
{
|
||||
/* TODO(thoh): Call rp_enc to query if LTK negative request reply is allowed */
|
||||
struct proc_ctx *ctx;
|
||||
|
||||
ctx = llcp_rr_peek(conn);
|
||||
if (ctx && (ctx->proc == PROC_ENCRYPTION_START || ctx->proc == PROC_ENCRYPTION_PAUSE)) {
|
||||
if (ctx && (ctx->proc == PROC_ENCRYPTION_START || ctx->proc == PROC_ENCRYPTION_PAUSE) &&
|
||||
llcp_rp_enc_ltk_req_reply_allowed(conn, ctx)) {
|
||||
llcp_rp_enc_ltk_req_neg_reply(conn, ctx);
|
||||
return BT_HCI_ERR_SUCCESS;
|
||||
}
|
||||
return BT_HCI_ERR_CMD_DISALLOWED;
|
||||
}
|
||||
#endif /* CONFIG_BT_CTLR_LE_ENC */
|
||||
|
||||
|
|
|
@ -102,11 +102,11 @@ uint8_t ull_cp_encryption_paused(struct ll_conn *conn);
|
|||
|
||||
/**
|
||||
*/
|
||||
void ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16]);
|
||||
uint8_t ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16]);
|
||||
|
||||
/**
|
||||
*/
|
||||
void ull_cp_ltk_req_neq_reply(struct ll_conn *conn);
|
||||
uint8_t ull_cp_ltk_req_neq_reply(struct ll_conn *conn);
|
||||
|
||||
/**
|
||||
* @brief Initiate a PHY Update Procedure.
|
||||
|
|
|
@ -1200,6 +1200,11 @@ void llcp_rp_enc_ltk_req_neg_reply(struct ll_conn *conn, struct proc_ctx *ctx)
|
|||
rp_enc_execute_fsm(conn, ctx, RP_ENC_EVT_LTK_REQ_NEG_REPLY, NULL);
|
||||
}
|
||||
|
||||
bool llcp_rp_enc_ltk_req_reply_allowed(struct ll_conn *conn, struct proc_ctx *ctx)
|
||||
{
|
||||
return (ctx->state == RP_ENC_STATE_WAIT_LTK_REPLY);
|
||||
}
|
||||
|
||||
void llcp_rp_enc_run(struct ll_conn *conn, struct proc_ctx *ctx, void *param)
|
||||
{
|
||||
rp_enc_execute_fsm(conn, ctx, RP_ENC_EVT_RUN, param);
|
||||
|
|
|
@ -391,7 +391,9 @@ void llcp_rp_enc_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_p
|
|||
void llcp_rp_enc_init_proc(struct proc_ctx *ctx);
|
||||
void llcp_rp_enc_ltk_req_reply(struct ll_conn *conn, struct proc_ctx *ctx);
|
||||
void llcp_rp_enc_ltk_req_neg_reply(struct ll_conn *conn, struct proc_ctx *ctx);
|
||||
bool llcp_rp_enc_ltk_req_reply_allowed(struct ll_conn *conn, struct proc_ctx *ctx);
|
||||
void llcp_rp_enc_run(struct ll_conn *conn, struct proc_ctx *ctx, void *param);
|
||||
|
||||
#endif /* CONFIG_BT_CTLR_LE_ENC */
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PHY)
|
||||
|
|
|
@ -612,22 +612,10 @@ uint8_t ll_start_enc_req_send(uint16_t handle, uint8_t error_code,
|
|||
conn->llcp.encryption.state = LLCP_ENC_STATE_INPROG;
|
||||
}
|
||||
#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */
|
||||
/*
|
||||
* TODO: add info to the conn-structure
|
||||
* - refresh
|
||||
* - no procedure in progress
|
||||
* - procedure type
|
||||
* and use that info to decide if the cmd is allowed
|
||||
* or if we should terminate the connection
|
||||
* see BT 5.2 Vol. 6 part B chapter 5.1.3
|
||||
* see also ull_periph.c line 395-439
|
||||
*
|
||||
* TODO: the ull_cp_ltx_req* functions should return success/fail status
|
||||
*/
|
||||
if (error_code) {
|
||||
ull_cp_ltk_req_neq_reply(conn);
|
||||
return ull_cp_ltk_req_neq_reply(conn);
|
||||
} else {
|
||||
ull_cp_ltk_req_reply(conn, ltk);
|
||||
return ull_cp_ltk_req_reply(conn, ltk);
|
||||
}
|
||||
#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue