@@ -2766,7 +2766,30 @@ isr_rx_conn_pkt_ctrl(struct radio_pdu_node_rx *node_rx,
2766
2766
if (nack ) {
2767
2767
break ;
2768
2768
}
2769
- #endif /* CONFIG_BT_CTLR_FAST_ENC */
2769
+
2770
+ /* enqueue the enc req */
2771
+ * rx_enqueue = 1U ;
2772
+
2773
+ /* Start Enc Req to be scheduled by LL api */
2774
+ _radio .conn_curr -> llcp .encryption .state =
2775
+ LLCP_ENC_STATE_LTK_WAIT ;
2776
+ #else /* !CONFIG_BT_CTLR_FAST_ENC */
2777
+ /* back up rand and ediv for deferred generation of Enc Req */
2778
+ memcpy (& _radio .conn_curr -> llcp_enc .rand [0 ],
2779
+ & pdu_data_rx -> llctrl .enc_req .rand [0 ],
2780
+ sizeof (_radio .conn_curr -> llcp_enc .rand ));
2781
+ _radio .conn_curr -> llcp_enc .ediv [0 ] =
2782
+ pdu_data_rx -> llctrl .enc_req .ediv [0 ];
2783
+ _radio .conn_curr -> llcp_enc .ediv [1 ] =
2784
+ pdu_data_rx -> llctrl .enc_req .ediv [1 ];
2785
+
2786
+ /* Enc rsp to be scheduled in master prepare */
2787
+ _radio .conn_curr -> llcp .encryption .state = LLCP_ENC_STATE_INIT ;
2788
+ #endif /* !CONFIG_BT_CTLR_FAST_ENC */
2789
+
2790
+ /* Enc Setup requested */
2791
+ _radio .conn_curr -> llcp_type = LLCP_ENCRYPTION ;
2792
+ _radio .conn_curr -> llcp_ack -- ;
2770
2793
2771
2794
/* things from master stored for session key calculation */
2772
2795
memcpy (& _radio .conn_curr -> llcp .encryption .skd [0 ],
@@ -2782,9 +2805,6 @@ isr_rx_conn_pkt_ctrl(struct radio_pdu_node_rx *node_rx,
2782
2805
*/
2783
2806
_radio .conn_curr -> procedure_expire =
2784
2807
_radio .conn_curr -> procedure_reload ;
2785
-
2786
- /* enqueue the enc req */
2787
- * rx_enqueue = 1U ;
2788
2808
break ;
2789
2809
2790
2810
case PDU_DATA_LLCTRL_TYPE_ENC_RSP :
@@ -2806,18 +2826,16 @@ isr_rx_conn_pkt_ctrl(struct radio_pdu_node_rx *node_rx,
2806
2826
2807
2827
case PDU_DATA_LLCTRL_TYPE_START_ENC_REQ :
2808
2828
if (_radio .conn_curr -> role ||
2809
- (( _radio .conn_curr -> llcp_req ! =
2810
- _radio .conn_curr -> llcp_ack ) &&
2811
- (_radio .conn_curr -> llcp_type != LLCP_ENCRYPTION ) ) ||
2829
+ (_radio .conn_curr -> llcp_req = =
2830
+ _radio .conn_curr -> llcp_ack ) ||
2831
+ (_radio .conn_curr -> llcp_type != LLCP_ENCRYPTION ) ||
2812
2832
!pdu_len_cmp (PDU_DATA_LLCTRL_TYPE_START_ENC_REQ ,
2813
2833
pdu_data_rx -> len )) {
2814
2834
goto isr_rx_conn_unknown_rsp_send ;
2815
2835
}
2816
2836
2817
2837
/* start enc rsp to be scheduled in master prepare */
2818
- _radio .conn_curr -> llcp .encryption .initiate = 0U ;
2819
- _radio .conn_curr -> llcp_type = LLCP_ENCRYPTION ;
2820
- _radio .conn_curr -> llcp_ack -- ;
2838
+ _radio .conn_curr -> llcp .encryption .state = LLCP_ENC_STATE_INPROG ;
2821
2839
break ;
2822
2840
2823
2841
case PDU_DATA_LLCTRL_TYPE_START_ENC_RSP :
@@ -2835,7 +2853,8 @@ isr_rx_conn_pkt_ctrl(struct radio_pdu_node_rx *node_rx,
2835
2853
}
2836
2854
2837
2855
/* start enc rsp to be scheduled in slave prepare */
2838
- _radio .conn_curr -> llcp .encryption .initiate = 0U ;
2856
+ _radio .conn_curr -> llcp .encryption .state =
2857
+ LLCP_ENC_STATE_INPROG ;
2839
2858
_radio .conn_curr -> llcp_type = LLCP_ENCRYPTION ;
2840
2859
_radio .conn_curr -> llcp_ack -- ;
2841
2860
#else /* CONFIG_BT_CTLR_FAST_ENC */
@@ -7671,7 +7690,54 @@ static inline void event_enc_prep(struct connection *conn)
7671
7690
struct radio_pdu_node_tx * node_tx ;
7672
7691
struct pdu_data * pdu_ctrl_tx ;
7673
7692
7674
- if (conn -> llcp .encryption .initiate ) {
7693
+ if (conn -> llcp .encryption .state ) {
7694
+ #if !defined(CONFIG_BT_CTLR_FAST_ENC ) && defined(CONFIG_BT_PERIPHERAL )
7695
+ if (conn -> role &&
7696
+ (conn -> llcp .encryption .state == LLCP_ENC_STATE_INIT )) {
7697
+ struct radio_pdu_node_rx * node_rx ;
7698
+ struct pdu_data * pdu_ctrl_rx ;
7699
+ u8_t err ;
7700
+
7701
+ /* TODO BT Spec. text: may finalize the sending
7702
+ * of additional data channel PDUs queued in the
7703
+ * controller.
7704
+ */
7705
+ err = enc_rsp_send (conn );
7706
+ if (err ) {
7707
+ return ;
7708
+ }
7709
+
7710
+ /* Prepare the rx packet structure */
7711
+ node_rx = packet_rx_reserve_get (2 );
7712
+ LL_ASSERT (node_rx );
7713
+
7714
+ node_rx -> hdr .handle = conn -> handle ;
7715
+ node_rx -> hdr .type = NODE_RX_TYPE_DC_PDU ;
7716
+
7717
+ /* prepare enc req structure */
7718
+ pdu_ctrl_rx = (void * )node_rx -> pdu_data ;
7719
+ pdu_ctrl_rx -> ll_id = PDU_DATA_LLID_CTRL ;
7720
+ pdu_ctrl_rx -> len =
7721
+ offsetof(struct pdu_data_llctrl , enc_req ) +
7722
+ sizeof (struct pdu_data_llctrl_enc_req );
7723
+ pdu_ctrl_rx -> llctrl .opcode =
7724
+ PDU_DATA_LLCTRL_TYPE_ENC_REQ ;
7725
+ memcpy (& pdu_ctrl_rx -> llctrl .enc_req .rand [0 ],
7726
+ & conn -> llcp_enc .rand [0 ],
7727
+ sizeof (pdu_ctrl_rx -> llctrl .enc_req .rand ));
7728
+ pdu_ctrl_rx -> llctrl .enc_req .ediv [0 ] =
7729
+ conn -> llcp_enc .ediv [0 ];
7730
+ pdu_ctrl_rx -> llctrl .enc_req .ediv [1 ] =
7731
+ conn -> llcp_enc .ediv [1 ];
7732
+
7733
+ /* enqueue enc req structure into rx queue */
7734
+ packet_rx_enqueue ();
7735
+
7736
+ /* Wait for LTK reply */
7737
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_LTK_WAIT ;
7738
+ }
7739
+ #endif /* !CONFIG_BT_CTLR_FAST_ENC && CONFIG_BT_PERIPHERAL */
7740
+
7675
7741
return ;
7676
7742
}
7677
7743
@@ -7719,7 +7785,7 @@ static inline void event_enc_prep(struct connection *conn)
7719
7785
#if defined(CONFIG_BT_CTLR_FAST_ENC )
7720
7786
else {
7721
7787
#else /* !CONFIG_BT_CTLR_FAST_ENC */
7722
- else if (!conn -> pause_tx || conn -> refresh ) {
7788
+ else if (!conn -> enc_rx ) {
7723
7789
#endif /* !CONFIG_BT_CTLR_FAST_ENC */
7724
7790
7725
7791
/* place the reject ind packet as next in tx queue */
@@ -7728,22 +7794,6 @@ static inline void event_enc_prep(struct connection *conn)
7728
7794
}
7729
7795
/* place the start enc req packet as next in tx queue */
7730
7796
else {
7731
-
7732
- #if !defined(CONFIG_BT_CTLR_FAST_ENC )
7733
- u8_t err ;
7734
-
7735
- /* TODO BT Spec. text: may finalize the sending
7736
- * of additional data channel PDUs queued in the
7737
- * controller.
7738
- */
7739
- err = enc_rsp_send (conn );
7740
- if (err ) {
7741
- mem_release (node_tx , & _radio .pkt_tx_ctrl_free );
7742
-
7743
- return ;
7744
- }
7745
- #endif /* !CONFIG_BT_CTLR_FAST_ENC */
7746
-
7747
7797
/* calc the Session Key */
7748
7798
ecb_encrypt (& conn -> llcp_enc .ltk [0 ],
7749
7799
& conn -> llcp .encryption .skd [0 ], NULL ,
@@ -9912,7 +9962,7 @@ static bool is_enc_req_pause_tx(struct connection *conn)
9912
9962
}
9913
9963
9914
9964
if (conn -> llcp_req == conn -> llcp_ack ) {
9915
- conn -> llcp .encryption .initiate = 1U ;
9965
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_INIT ;
9916
9966
9917
9967
conn -> llcp_type = LLCP_ENCRYPTION ;
9918
9968
conn -> llcp_ack -- ;
@@ -12279,15 +12329,13 @@ u8_t ll_start_enc_req_send(u16_t handle, u8_t error_code,
12279
12329
12280
12330
if (error_code ) {
12281
12331
if (conn -> refresh == 0 ) {
12282
- if (conn -> llcp_req != conn -> llcp_ack ) {
12332
+ if ((conn -> llcp_req == conn -> llcp_ack ) ||
12333
+ (conn -> llcp_type != LLCP_ENCRYPTION )) {
12283
12334
return BT_HCI_ERR_CMD_DISALLOWED ;
12284
12335
}
12285
12336
12286
12337
conn -> llcp .encryption .error_code = error_code ;
12287
- conn -> llcp .encryption .initiate = 0U ;
12288
-
12289
- conn -> llcp_type = LLCP_ENCRYPTION ;
12290
- conn -> llcp_req ++ ;
12338
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_INPROG ;
12291
12339
} else {
12292
12340
if (conn -> llcp_terminate .ack !=
12293
12341
conn -> llcp_terminate .req ) {
@@ -12299,18 +12347,16 @@ u8_t ll_start_enc_req_send(u16_t handle, u8_t error_code,
12299
12347
conn -> llcp_terminate .req ++ ;
12300
12348
}
12301
12349
} else {
12302
- if (conn -> llcp_req != conn -> llcp_ack ) {
12350
+ if ((conn -> llcp_req == conn -> llcp_ack ) ||
12351
+ (conn -> llcp_type != LLCP_ENCRYPTION )) {
12303
12352
return BT_HCI_ERR_CMD_DISALLOWED ;
12304
12353
}
12305
12354
12306
12355
memcpy (& conn -> llcp_enc .ltk [0 ], ltk ,
12307
12356
sizeof (conn -> llcp_enc .ltk ));
12308
12357
12309
12358
conn -> llcp .encryption .error_code = 0U ;
12310
- conn -> llcp .encryption .initiate = 0U ;
12311
-
12312
- conn -> llcp_type = LLCP_ENCRYPTION ;
12313
- conn -> llcp_req ++ ;
12359
+ conn -> llcp .encryption .state = LLCP_ENC_STATE_INPROG ;
12314
12360
}
12315
12361
12316
12362
return 0 ;
0 commit comments