@@ -703,28 +703,43 @@ void lll_conn_tx_pkt_set(struct lll_conn *lll, struct pdu_data *pdu_data_tx)
703
703
#endif /* CONFIG_BT_CTLR_LE_ENC */
704
704
} else {
705
705
// Whisper added for MFI.
706
+ struct pdu_data * tx_pkt = pdu_data_tx ;
707
+
706
708
#if defined(CONFIG_BT_CTLR_LE_ENC )
707
- if (lll -> mode2_tx_enabled ) {
709
+ if (lll -> mode2_tx_enabled ) {
708
710
// if mode 2 is enabled we need to encrypt the packet using mode 2
709
711
// encryption before transmitting
710
712
ccm_soft_data_t ccm_params ;
711
713
714
+ // the output of the encryption needs to go to the radio's scratch packet area
715
+ // so that we don't overwrite the non-encrypted pdu_tx which still needs to be
716
+ // used later for processing acks
717
+ struct pdu_data * scratch_pkt = radio_pkt_scratch_get ();
718
+ scratch_pkt -> ll_id = pdu_data_tx -> ll_id ;
719
+ scratch_pkt -> nesn = pdu_data_tx -> nesn ;
720
+ scratch_pkt -> sn = pdu_data_tx -> sn ;
721
+ scratch_pkt -> md = pdu_data_tx -> md ;
722
+ scratch_pkt -> rfu = pdu_data_tx -> rfu ;
723
+ scratch_pkt -> len = pdu_data_tx -> len ;
724
+
712
725
// Note that the event counter is already incremented before this code is called
713
726
// so the event counter we want is actually (event_counter - 1)
714
727
lll -> ccm_mode2_nonce_tx .counter = lll -> event_counter - 1 ;
715
728
ccm_params .p_nonce = (uint8_t * )& lll -> ccm_mode2_nonce_tx ;
716
729
ccm_params .p_m = pdu_data_tx -> lldata ;
717
730
ccm_params .m_len = pdu_data_tx -> len ;
718
- ccm_params .p_out = pdu_data_tx -> lldata ;
731
+ ccm_params .p_out = scratch_pkt -> lldata ;
719
732
ccm_params .p_key = lll -> ccm_tx .key ;
720
733
721
734
ccm_mode2_soft_encrypt (& ccm_params );
735
+
736
+ tx_pkt = scratch_pkt ;
722
737
}
723
738
#endif /* CONFIG_BT_CTLR_LE_ENC */
724
739
725
740
radio_pkt_configure (RADIO_PKT_CONF_LENGTH_8BIT , max_tx_octets , pkt_flags );
726
741
727
- radio_pkt_tx_set (pdu_data_tx );
742
+ radio_pkt_tx_set (tx_pkt );
728
743
}
729
744
}
730
745
0 commit comments