Skip to content

Commit 025b974

Browse files
erbr-otcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 06078ee commit 025b974

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

subsys/bluetooth/controller/ll_sw/ull_llcp.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,27 +838,31 @@ uint8_t ull_cp_data_length_update(struct ll_conn *conn, uint16_t max_tx_octets,
838838
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */
839839

840840
#if defined(CONFIG_BT_CTLR_LE_ENC)
841-
void ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16])
841+
uint8_t ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16])
842842
{
843-
/* TODO(thoh): Call rp_enc to query if LTK request reply is allowed */
844843
struct proc_ctx *ctx;
845844

846845
ctx = llcp_rr_peek(conn);
847-
if (ctx && (ctx->proc == PROC_ENCRYPTION_START || ctx->proc == PROC_ENCRYPTION_PAUSE)) {
846+
if (ctx && (ctx->proc == PROC_ENCRYPTION_START || ctx->proc == PROC_ENCRYPTION_PAUSE) &&
847+
llcp_rp_enc_ltk_req_reply_allowed(conn, ctx)) {
848848
memcpy(ctx->data.enc.ltk, ltk, sizeof(ctx->data.enc.ltk));
849849
llcp_rp_enc_ltk_req_reply(conn, ctx);
850+
return BT_HCI_ERR_SUCCESS;
850851
}
852+
return BT_HCI_ERR_CMD_DISALLOWED;
851853
}
852854

853-
void ull_cp_ltk_req_neq_reply(struct ll_conn *conn)
855+
uint8_t ull_cp_ltk_req_neq_reply(struct ll_conn *conn)
854856
{
855-
/* TODO(thoh): Call rp_enc to query if LTK negative request reply is allowed */
856857
struct proc_ctx *ctx;
857858

858859
ctx = llcp_rr_peek(conn);
859-
if (ctx && (ctx->proc == PROC_ENCRYPTION_START || ctx->proc == PROC_ENCRYPTION_PAUSE)) {
860+
if (ctx && (ctx->proc == PROC_ENCRYPTION_START || ctx->proc == PROC_ENCRYPTION_PAUSE) &&
861+
llcp_rp_enc_ltk_req_reply_allowed(conn, ctx)) {
860862
llcp_rp_enc_ltk_req_neg_reply(conn, ctx);
863+
return BT_HCI_ERR_SUCCESS;
861864
}
865+
return BT_HCI_ERR_CMD_DISALLOWED;
862866
}
863867
#endif /* CONFIG_BT_CTLR_LE_ENC */
864868

subsys/bluetooth/controller/ll_sw/ull_llcp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ uint8_t ull_cp_encryption_paused(struct ll_conn *conn);
102102

103103
/**
104104
*/
105-
void ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16]);
105+
uint8_t ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16]);
106106

107107
/**
108108
*/
109-
void ull_cp_ltk_req_neq_reply(struct ll_conn *conn);
109+
uint8_t ull_cp_ltk_req_neq_reply(struct ll_conn *conn);
110110

111111
/**
112112
* @brief Initiate a PHY Update Procedure.

subsys/bluetooth/controller/ll_sw/ull_llcp_enc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,11 @@ void llcp_rp_enc_ltk_req_neg_reply(struct ll_conn *conn, struct proc_ctx *ctx)
12001200
rp_enc_execute_fsm(conn, ctx, RP_ENC_EVT_LTK_REQ_NEG_REPLY, NULL);
12011201
}
12021202

1203+
bool llcp_rp_enc_ltk_req_reply_allowed(struct ll_conn *conn, struct proc_ctx *ctx)
1204+
{
1205+
return (ctx->state == RP_ENC_STATE_WAIT_LTK_REPLY);
1206+
}
1207+
12031208
void llcp_rp_enc_run(struct ll_conn *conn, struct proc_ctx *ctx, void *param)
12041209
{
12051210
rp_enc_execute_fsm(conn, ctx, RP_ENC_EVT_RUN, param);

subsys/bluetooth/controller/ll_sw/ull_llcp_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ void llcp_rp_enc_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_p
391391
void llcp_rp_enc_init_proc(struct proc_ctx *ctx);
392392
void llcp_rp_enc_ltk_req_reply(struct ll_conn *conn, struct proc_ctx *ctx);
393393
void llcp_rp_enc_ltk_req_neg_reply(struct ll_conn *conn, struct proc_ctx *ctx);
394+
bool llcp_rp_enc_ltk_req_reply_allowed(struct ll_conn *conn, struct proc_ctx *ctx);
394395
void llcp_rp_enc_run(struct ll_conn *conn, struct proc_ctx *ctx, void *param);
396+
395397
#endif /* CONFIG_BT_CTLR_LE_ENC */
396398

397399
#if defined(CONFIG_BT_CTLR_PHY)

subsys/bluetooth/controller/ll_sw/ull_peripheral.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -612,22 +612,10 @@ uint8_t ll_start_enc_req_send(uint16_t handle, uint8_t error_code,
612612
conn->llcp.encryption.state = LLCP_ENC_STATE_INPROG;
613613
}
614614
#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */
615-
/*
616-
* TODO: add info to the conn-structure
617-
* - refresh
618-
* - no procedure in progress
619-
* - procedure type
620-
* and use that info to decide if the cmd is allowed
621-
* or if we should terminate the connection
622-
* see BT 5.2 Vol. 6 part B chapter 5.1.3
623-
* see also ull_periph.c line 395-439
624-
*
625-
* TODO: the ull_cp_ltx_req* functions should return success/fail status
626-
*/
627615
if (error_code) {
628-
ull_cp_ltk_req_neq_reply(conn);
616+
return ull_cp_ltk_req_neq_reply(conn);
629617
} else {
630-
ull_cp_ltk_req_reply(conn, ltk);
618+
return ull_cp_ltk_req_reply(conn, ltk);
631619
}
632620
#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */
633621

0 commit comments

Comments
 (0)