Skip to content

Commit bfbd776

Browse files
kevin-whisperNahal Farhi
authored and
Nahal Farhi
committed
Use radio scratch area when doing soft encryption for tx (zephyrproject-rtos#16)
1 parent 5ca7e7f commit bfbd776

File tree

1 file changed

+18
-3
lines changed
  • subsys/bluetooth/controller/ll_sw/nordic/lll

1 file changed

+18
-3
lines changed

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -703,28 +703,43 @@ void lll_conn_tx_pkt_set(struct lll_conn *lll, struct pdu_data *pdu_data_tx)
703703
#endif /* CONFIG_BT_CTLR_LE_ENC */
704704
} else {
705705
// Whisper added for MFI.
706+
struct pdu_data *tx_pkt = pdu_data_tx;
707+
706708
#if defined(CONFIG_BT_CTLR_LE_ENC)
707-
if(lll->mode2_tx_enabled) {
709+
if (lll->mode2_tx_enabled) {
708710
// if mode 2 is enabled we need to encrypt the packet using mode 2
709711
// encryption before transmitting
710712
ccm_soft_data_t ccm_params;
711713

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+
712725
// Note that the event counter is already incremented before this code is called
713726
// so the event counter we want is actually (event_counter - 1)
714727
lll->ccm_mode2_nonce_tx.counter = lll->event_counter - 1;
715728
ccm_params.p_nonce = (uint8_t *)&lll->ccm_mode2_nonce_tx;
716729
ccm_params.p_m = pdu_data_tx->lldata;
717730
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;
719732
ccm_params.p_key = lll->ccm_tx.key;
720733

721734
ccm_mode2_soft_encrypt(&ccm_params);
735+
736+
tx_pkt = scratch_pkt;
722737
}
723738
#endif /* CONFIG_BT_CTLR_LE_ENC */
724739

725740
radio_pkt_configure(RADIO_PKT_CONF_LENGTH_8BIT, max_tx_octets, pkt_flags);
726741

727-
radio_pkt_tx_set(pdu_data_tx);
742+
radio_pkt_tx_set(tx_pkt);
728743
}
729744
}
730745

0 commit comments

Comments
 (0)