@@ -2012,7 +2012,7 @@ static bool is_enc_req_pause_tx(struct ll_conn *conn)
2012
2012
}
2013
2013
2014
2014
if (conn -> llcp_req == conn -> llcp_ack ) {
2015
- conn -> llcp .encryption .initiate = 1U ;
2015
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_INIT ;
2016
2016
2017
2017
conn -> llcp_type = LLCP_ENCRYPTION ;
2018
2018
conn -> llcp_ack -= 2U ;
@@ -2503,11 +2503,56 @@ static inline void event_enc_reject_prep(struct ll_conn *conn,
2503
2503
2504
2504
static inline void event_enc_prep (struct ll_conn * conn )
2505
2505
{
2506
+ struct lll_conn * lll = & conn -> lll ;
2506
2507
struct pdu_data * pdu_ctrl_tx ;
2507
2508
struct node_tx * tx ;
2508
- struct lll_conn * lll ;
2509
2509
2510
- if (conn -> llcp .encryption .initiate ) {
2510
+ if (conn -> llcp .encryption .state ) {
2511
+ #if !defined(CONFIG_BT_CTLR_FAST_ENC )
2512
+ if (lll -> role &&
2513
+ (conn -> llcp .encryption .state == LLCP_ENC_STATE_INIT )) {
2514
+ struct node_rx_pdu * rx ;
2515
+ struct pdu_data * pdu ;
2516
+ u8_t err ;
2517
+
2518
+ /* TODO BT Spec. text: may finalize the sending
2519
+ * of additional data channel PDUs queued in the
2520
+ * controller.
2521
+ */
2522
+ err = enc_rsp_send (conn );
2523
+ if (err ) {
2524
+ return ;
2525
+ }
2526
+
2527
+ /* get a rx node for ULL->LL */
2528
+ rx = ll_pdu_rx_alloc ();
2529
+ if (!rx ) {
2530
+ return ;
2531
+ }
2532
+
2533
+ /* prepare enc req structure */
2534
+ rx -> hdr .handle = conn -> lll .handle ;
2535
+ rx -> hdr .type = NODE_RX_TYPE_DC_PDU ;
2536
+ pdu = (void * )rx -> pdu ;
2537
+ pdu -> ll_id = PDU_DATA_LLID_CTRL ;
2538
+ pdu -> len = offsetof(struct pdu_data_llctrl , enc_req ) +
2539
+ sizeof (struct pdu_data_llctrl_enc_req );
2540
+ pdu -> llctrl .opcode = PDU_DATA_LLCTRL_TYPE_ENC_REQ ;
2541
+ memcpy (& pdu -> llctrl .enc_req .rand [0 ],
2542
+ & conn -> llcp_enc .rand [0 ],
2543
+ sizeof (pdu -> llctrl .enc_req .rand ));
2544
+ pdu -> llctrl .enc_req .ediv [0 ] = conn -> llcp_enc .ediv [0 ];
2545
+ pdu -> llctrl .enc_req .ediv [1 ] = conn -> llcp_enc .ediv [1 ];
2546
+
2547
+ /* enqueue enc req structure into rx queue */
2548
+ ll_rx_put (rx -> hdr .link , rx );
2549
+ ll_rx_sched ();
2550
+
2551
+ /* Wait for LTK reply */
2552
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_LTK_WAIT ;
2553
+ }
2554
+ #endif /* !CONFIG_BT_CTLR_FAST_ENC */
2555
+
2511
2556
return ;
2512
2557
}
2513
2558
@@ -2516,8 +2561,6 @@ static inline void event_enc_prep(struct ll_conn *conn)
2516
2561
return ;
2517
2562
}
2518
2563
2519
- lll = & conn -> lll ;
2520
-
2521
2564
pdu_ctrl_tx = (void * )tx -> pdu ;
2522
2565
2523
2566
/* master sends encrypted enc start rsp in control priority */
@@ -2559,7 +2602,7 @@ static inline void event_enc_prep(struct ll_conn *conn)
2559
2602
#if defined(CONFIG_BT_CTLR_FAST_ENC )
2560
2603
else {
2561
2604
#else /* !CONFIG_BT_CTLR_FAST_ENC */
2562
- else if (!conn -> llcp_enc . pause_tx || conn -> llcp_enc . refresh ) {
2605
+ else if (!lll -> enc_rx ) {
2563
2606
#endif /* !CONFIG_BT_CTLR_FAST_ENC */
2564
2607
2565
2608
/* place the reject ind packet as next in tx queue */
@@ -2570,22 +2613,6 @@ static inline void event_enc_prep(struct ll_conn *conn)
2570
2613
}
2571
2614
/* place the start enc req packet as next in tx queue */
2572
2615
else {
2573
-
2574
- #if !defined(CONFIG_BT_CTLR_FAST_ENC )
2575
- u8_t err ;
2576
-
2577
- /* TODO BT Spec. text: may finalize the sending
2578
- * of additional data channel PDUs queued in the
2579
- * controller.
2580
- */
2581
- err = enc_rsp_send (conn );
2582
- if (err ) {
2583
- mem_release (tx , & mem_conn_tx_ctrl .free );
2584
-
2585
- return ;
2586
- }
2587
- #endif /* !CONFIG_BT_CTLR_FAST_ENC */
2588
-
2589
2616
/* calc the Session Key */
2590
2617
ecb_encrypt (& conn -> llcp_enc .ltk [0 ],
2591
2618
& conn -> llcp .encryption .skd [0 ], NULL ,
@@ -5146,8 +5173,28 @@ static inline int ctrl_rx(memq_link_t *link, struct node_rx_pdu **rx,
5146
5173
if (nack ) {
5147
5174
break ;
5148
5175
}
5176
+
5177
+ /* Start Enc Req to be scheduled by LL api */
5178
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_LTK_WAIT ;
5179
+ #else /* CONFIG_BT_CTLR_FAST_ENC */
5180
+ /* back up rand and ediv for deferred generation of Enc Req */
5181
+ memcpy (& conn -> llcp_enc .rand [0 ],
5182
+ & pdu_rx -> llctrl .enc_req .rand [0 ],
5183
+ sizeof (conn -> llcp_enc .rand ));
5184
+ conn -> llcp_enc .ediv [0 ] = pdu_rx -> llctrl .enc_req .ediv [0 ];
5185
+ conn -> llcp_enc .ediv [1 ] = pdu_rx -> llctrl .enc_req .ediv [1 ];
5186
+
5187
+ /* Enc rsp to be scheduled in master prepare */
5188
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_INIT ;
5189
+
5190
+ /* Mark for buffer for release */
5191
+ (* rx )-> hdr .type = NODE_RX_TYPE_DC_PDU_RELEASE ;
5149
5192
#endif /* CONFIG_BT_CTLR_FAST_ENC */
5150
5193
5194
+ /* Enc Setup state machine active */
5195
+ conn -> llcp_type = LLCP_ENCRYPTION ;
5196
+ conn -> llcp_ack -= 2U ;
5197
+
5151
5198
/* things from master stored for session key calculation */
5152
5199
memcpy (& conn -> llcp .encryption .skd [0 ],
5153
5200
& pdu_rx -> llctrl .enc_req .skdm [0 ], 8 );
@@ -5185,20 +5232,15 @@ static inline int ctrl_rx(memq_link_t *link, struct node_rx_pdu **rx,
5185
5232
break ;
5186
5233
5187
5234
case PDU_DATA_LLCTRL_TYPE_START_ENC_REQ :
5188
- if (conn -> lll .role ||
5189
- ((conn -> llcp_req != conn -> llcp_ack ) &&
5190
- (conn -> llcp_type != LLCP_ENCRYPTION )) ||
5235
+ if (conn -> lll .role || (conn -> llcp_req == conn -> llcp_ack ) ||
5236
+ (conn -> llcp_type != LLCP_ENCRYPTION ) ||
5191
5237
!pdu_len_cmp (PDU_DATA_LLCTRL_TYPE_START_ENC_REQ ,
5192
5238
pdu_rx -> len )) {
5193
5239
goto ull_conn_rx_unknown_rsp_send ;
5194
5240
}
5195
5241
5196
5242
/* start enc rsp to be scheduled in master prepare */
5197
- conn -> llcp .encryption .initiate = 0U ;
5198
- if (conn -> llcp_req == conn -> llcp_ack ) {
5199
- conn -> llcp_type = LLCP_ENCRYPTION ;
5200
- conn -> llcp_ack -= 2U ;
5201
- }
5243
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_INPROG ;
5202
5244
5203
5245
/* Mark for buffer for release */
5204
5246
(* rx )-> hdr .type = NODE_RX_TYPE_DC_PDU_RELEASE ;
@@ -5219,11 +5261,12 @@ static inline int ctrl_rx(memq_link_t *link, struct node_rx_pdu **rx,
5219
5261
}
5220
5262
5221
5263
/* start enc rsp to be scheduled in slave prepare */
5222
- conn -> llcp .encryption .initiate = 0U ;
5264
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_INPROG ;
5223
5265
if (conn -> llcp_req == conn -> llcp_ack ) {
5224
5266
conn -> llcp_type = LLCP_ENCRYPTION ;
5225
5267
conn -> llcp_ack -= 2U ;
5226
5268
}
5269
+
5227
5270
#else /* CONFIG_BT_CTLR_FAST_ENC */
5228
5271
nack = start_enc_rsp_send (conn , NULL );
5229
5272
if (nack ) {
0 commit comments