From c6a44dded806066dbccef51df0907d561f27ca69 Mon Sep 17 00:00:00 2001 From: Michal Gorecki Date: Tue, 21 Jan 2025 13:10:30 +0100 Subject: [PATCH] wip encryption works --- nimble/drivers/nrf54l15/src/ble_hw.c | 28 ++- nimble/drivers/nrf54l15/src/ble_phy.c | 289 +++++++++++++------------- nimble/drivers/nrf54l15/src/phy.c | 6 +- nimble/drivers/nrf54l15/src/phy_ppi.h | 11 +- 4 files changed, 180 insertions(+), 154 deletions(-) diff --git a/nimble/drivers/nrf54l15/src/ble_hw.c b/nimble/drivers/nrf54l15/src/ble_hw.c index 257b46224..e8a34cd2d 100644 --- a/nimble/drivers/nrf54l15/src/ble_hw.c +++ b/nimble/drivers/nrf54l15/src/ble_hw.c @@ -63,6 +63,13 @@ uint16_t g_nrf_aar_output[127]; #endif +struct nrf_ecb_job_list { + nrf_vdma_job_t in[2]; + nrf_vdma_job_t out[2]; +}; + +static struct nrf_ecb_job_list g_ecb_job_list; + #define NRF_ECB NRF_ECB00 #define NRF_AAR NRF_AAR00 @@ -255,14 +262,29 @@ ble_hw_encrypt_block(struct ble_encryption_block *ecb) uint32_t end; uint32_t err; + /* Init job lists */ + g_ecb_job_list.in[0].p_buffer = ecb->plain_text; + g_ecb_job_list.in[0].attributes = NRF_VDMA_ATTRIBUTE_CRC; + g_ecb_job_list.in[0].size = BLE_ENC_BLOCK_SIZE; + memset(&g_ecb_job_list.in[1], 0, sizeof(g_ecb_job_list.in[1])); + + g_ecb_job_list.out[0].p_buffer = ecb->cipher_text; + g_ecb_job_list.out[0].attributes = NRF_VDMA_ATTRIBUTE_CRC; + g_ecb_job_list.out[0].size = BLE_ENC_BLOCK_SIZE; + memset(&g_ecb_job_list.out[1], 0, sizeof(g_ecb_job_list.out[1])); + /* Stop ECB */ nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STOP); /* XXX: does task stop clear these counters? Anyway to do this quicker? */ NRF_ECB->EVENTS_END = 0; NRF_ECB->EVENTS_ERROR = 0; - NRF_ECB->IN.PTR = (uint32_t)ecb->plain_text; - NRF_ECB->OUT.PTR = (uint32_t)ecb->cipher_text; - memcpy((void *)NRF_ECB->KEY.VALUE, ecb->key, sizeof(uint32_t) * 4); + NRF_ECB->IN.PTR = (uint32_t)g_ecb_job_list.in; + NRF_ECB->OUT.PTR = (uint32_t)g_ecb_job_list.out; + + NRF_ECB->KEY.VALUE[3] = get_be32(&ecb->key[0]); + NRF_ECB->KEY.VALUE[2] = get_be32(&ecb->key[4]); + NRF_ECB->KEY.VALUE[1] = get_be32(&ecb->key[8]); + NRF_ECB->KEY.VALUE[0] = get_be32(&ecb->key[12]); /* Start ECB */ nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_START); diff --git a/nimble/drivers/nrf54l15/src/ble_phy.c b/nimble/drivers/nrf54l15/src/ble_phy.c index 074ee6ff5..efd7d1528 100644 --- a/nimble/drivers/nrf54l15/src/ble_phy.c +++ b/nimble/drivers/nrf54l15/src/ble_phy.c @@ -132,12 +132,16 @@ struct nrf_aar_job_list { #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) struct nrf_ccm_job_list { - nrf_vdma_job_t alen; - nrf_vdma_job_t mlen; - nrf_vdma_job_t adata; - nrf_vdma_job_t mdata; - nrf_vdma_job_t list_terminator; + uint16_t in_alen; + uint16_t in_mlen; + uint8_t in_mlen_msb; + uint8_t out_mlen_msb; + uint16_t out_alen; + nrf_vdma_job_t in[6]; + nrf_vdma_job_t out[6]; }; + +struct nrf_ccm_job_list g_ccm_job_list; #endif /* BLE PHY data structure */ @@ -327,31 +331,6 @@ STATS_NAME_END(ble_phy_stats) * bit in the NVIC just to be sure when we disable the PHY. */ -#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) - -/* - * Per nordic, the number of bytes needed for scratch is 16 + MAX_PKT_SIZE. - * However, when I used a smaller size it still overwrote the scratchpad. Until - * I figure this out I am just going to allocate 67 words so we have enough - * space for 267 bytes of scratch. I used 268 bytes since not sure if this - * needs to be aligned and burning a byte is no big deal. - */ -//#define NRF_ENC_SCRATCH_WORDS (((MYNEWT_VAL(BLE_LL_MAX_PKT_SIZE) + 16) + 3) / 4) -#define NRF_ENC_SCRATCH_WORDS (67) - -static uint32_t g_nrf_encrypt_scratchpad[NRF_ENC_SCRATCH_WORDS]; - -struct nrf_ccm_data -{ - uint8_t key[16]; - uint64_t pkt_counter; - uint8_t dir_bit; - uint8_t iv[8]; -} __attribute__((packed)); - -struct nrf_ccm_data g_nrf_ccm_data; -#endif - #if MYNEWT_VAL(BLE_LL_PHY) /* Packet start offset (in usecs). This is the preamble plus access address. @@ -605,7 +584,7 @@ ble_phy_set_start_time(uint32_t cputime, uint8_t rem_us, bool tx) * If FEM is enabled, turn on time may be a bit longer, so we also allow to * adjust by 3 ticks so up to 90us which should be enough. If needed, we * can extend this by another tick but having FEM with turn on time >90us - * means transition may become tricky. TODO(m) + * means transition may become tricky. */ if (min_rem_us <= -30) { @@ -837,51 +816,85 @@ static void ble_phy_rx_xcvr_setup(void) { uint8_t *dptr; -#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) - static struct nrf_ccm_job_list ccm_jobs; - static const uint16_t alen = 0; - uint16_t dlen; -#endif dptr = (uint8_t *)&g_ble_phy_rx_buf[0]; dptr += 3; #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) if (g_ble_phy_data.phy_encrypted) { - dlen = g_ble_phy_rx_buf[1]; //TODO(m): check if this is accurate - - ccm_jobs.alen.size = 2; - ccm_jobs.alen.attributes = NRF_VDMA_ATTRIBUTE_CRC; - ccm_jobs.alen.p_buffer = (uint8_t *) &alen; - - ccm_jobs.adata.size = alen; - ccm_jobs.adata.p_buffer = NULL; - ccm_jobs.adata.attributes = NRF_VDMA_ATTRIBUTE_PLAIN_DATA_BUF_WRITE; - - ccm_jobs.mlen.size = 2; - ccm_jobs.mlen.attributes = NRF_VDMA_ATTRIBUTE_STATIC_ADDR; - ccm_jobs.mlen.p_buffer = (uint8_t *) &dlen; - - ccm_jobs.mdata.size = dlen; - ccm_jobs.mdata.p_buffer = (uint8_t *) &g_ble_phy_enc_buf; - ccm_jobs.mdata.attributes = 14; //TODO(m): ??? + /* AAD length */ + g_ccm_job_list.in_alen = 1; + g_ccm_job_list.in[0].p_buffer = (uint8_t *) &g_ccm_job_list.in_alen; + g_ccm_job_list.in[0].size = sizeof(g_ccm_job_list.in_alen); + g_ccm_job_list.in[0].attributes = 11; + + /* Encrypted message length LSB */ + g_ccm_job_list.in[1].p_buffer = ((uint8_t *)g_ble_phy_enc_buf) + 1; + g_ccm_job_list.in[1].size = 1; + g_ccm_job_list.in[1].attributes = 12; + + /* Encrypted message length MSB */ + g_ccm_job_list.in[2].p_buffer = &g_ccm_job_list.in_mlen_msb; + g_ccm_job_list.in[2].size = sizeof(g_ccm_job_list.in_mlen_msb); + g_ccm_job_list.in[2].attributes = 12; + + /* AAD */ + g_ccm_job_list.in[3].p_buffer = ((uint8_t *)g_ble_phy_enc_buf); + g_ccm_job_list.in[3].size = 1; + g_ccm_job_list.in[3].attributes = 13; + + /* Encrypted message */ + g_ccm_job_list.in[4].p_buffer = ((uint8_t *)g_ble_phy_enc_buf) + 3; + g_ccm_job_list.in[4].size = NRF_MAXLEN; + g_ccm_job_list.in[4].attributes = 14; + + /* Job list terminator */ + memset(&g_ccm_job_list.in[5], 0, sizeof(g_ccm_job_list.in[5])); + + /* AAD length */ + g_ccm_job_list.out[0].p_buffer = (uint8_t *) &g_ccm_job_list.out_alen; + g_ccm_job_list.out[0].size = sizeof(g_ccm_job_list.out_alen); + g_ccm_job_list.out[0].attributes = 11; + + /* Decrypted message length LSB */ + g_ccm_job_list.out[1].p_buffer = &dptr[1]; + g_ccm_job_list.out[1].size = 1; + g_ccm_job_list.out[1].attributes = 12; + + /* Decrypted message length MSB */ + g_ccm_job_list.out[2].p_buffer = &g_ccm_job_list.out_mlen_msb; + g_ccm_job_list.out[2].size = sizeof(g_ccm_job_list.out_mlen_msb); + g_ccm_job_list.out[2].attributes = 12; + + /* AAD */ + g_ccm_job_list.out[3].p_buffer = &dptr[0]; + g_ccm_job_list.out[3].size = 1; + g_ccm_job_list.out[3].attributes = 13; + + /* Decrypted message */ + g_ccm_job_list.out[4].p_buffer = &dptr[3]; + g_ccm_job_list.out[4].size = NRF_MAXLEN - 4; + g_ccm_job_list.out[4].attributes = 14; + + /* Job list terminator */ + memset(&g_ccm_job_list.out[5], 0, sizeof(g_ccm_job_list.out[5])); NRF_RADIO->PACKETPTR = (uint32_t)&g_ble_phy_enc_buf[0]; - NRF_CCM->IN.PTR = (uint32_t)&g_ble_phy_enc_buf[0]; - NRF_CCM->OUT.PTR = (uint32_t)dptr; -// NRF_CCM->SCRATCHPTR = (uint32_t)&g_nrf_encrypt_scratchpad[0]; - NRF_CCM->MODE = CCM_MODE_MACLEN_Pos | CCM_MODE_MODE_Decryption | + NRF_CCM->IN.PTR = (uint32_t)g_ccm_job_list.in; + NRF_CCM->OUT.PTR = (uint32_t)g_ccm_job_list.out; + + NRF_CCM->MODE = (CCM_MODE_MACLEN_M4 << CCM_MODE_MACLEN_Pos) | CCM_MODE_MODE_Decryption | ble_phy_get_ccm_datarate(); - memcpy((uint8_t *)NRF_CCM->KEY.VALUE, &g_nrf_ccm_data.key, sizeof(g_nrf_ccm_data.key)); + NRF_CCM->EVENTS_ERROR = 0; NRF_CCM->EVENTS_END = 0; - nrf_ccm_task_trigger(NRF_CCM, NRF_CCM_TASK_START); + phy_ppi_radio_address_to_ccm_crypt_enable(); } else { - NRF_RADIO->PACKETPTR = (uint32_t)dptr; + NRF_RADIO->PACKETPTR = (uint32_t)&dptr[0]; } #else - NRF_RADIO->PACKETPTR = (uint32_t)dptr; + NRF_RADIO->PACKETPTR = (uint32_t)&dptr[0]; #endif #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) @@ -899,7 +912,7 @@ ble_phy_rx_xcvr_setup(void) /* Turn off trigger TXEN on output compare match and AAR on bcmatch */ phy_ppi_timer0_compare0_to_radio_txen_disable(); - phy_ppi_radio_bcmatch_to_aar_start_disable(); + //phy_ppi_radio_bcmatch_to_aar_start_disable(); TODO(m): this was disabling CCM RADIO SUBSCRIBTION because peripherals share memory. think later what to do with it /* Reset the rx started flag. Used for the wait for response */ g_ble_phy_data.phy_rx_started = 0; @@ -1485,9 +1498,7 @@ ble_phy_init(void) #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) nrf_ccm_int_disable(NRF_CCM, 0xffffffff); -// NRF_CCM->SHORTS = CCM_SHORTS_ENDKSGEN_CRYPT_Msk; NRF_CCM->EVENTS_ERROR = 0; - memset(g_nrf_encrypt_scratchpad, 0, sizeof(g_nrf_encrypt_scratchpad)); #endif #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) @@ -1586,40 +1597,34 @@ ble_phy_rx(void) void ble_phy_encrypt_enable(const uint8_t *key) { - memcpy(g_nrf_ccm_data.key, key, 16); + NRF_CCM->KEY.VALUE[0] = get_be32(&key[12]); + NRF_CCM->KEY.VALUE[1] = get_be32(&key[8]); + NRF_CCM->KEY.VALUE[2] = get_be32(&key[4]); + NRF_CCM->KEY.VALUE[3] = get_be32(&key[0]); + g_ble_phy_data.phy_encrypted = 1; NRF_AAR->ENABLE = AAR_ENABLE_ENABLE_Disabled; NRF_CCM->ENABLE = CCM_ENABLE_ENABLE_Enabled; -#ifdef NRF5340_XXAA - NRF_CCM->HEADERMASK = BLE_LL_PDU_HEADERMASK_DATA; -#endif -#if PHY_USE_HEADERMASK_WORKAROUND - g_ble_phy_data.phy_headermask = BLE_LL_PDU_HEADERMASK_DATA; -#endif } void ble_phy_encrypt_header_mask_set(uint8_t mask) { -#ifdef NRF5340_XXAA - NRF_CCM->HEADERMASK = mask; -#endif -#if PHY_USE_HEADERMASK_WORKAROUND - g_ble_phy_data.phy_headermask = mask; -#endif + NRF_CCM->ADATAMASK = mask; } void ble_phy_encrypt_iv_set(const uint8_t *iv) { - memcpy(g_nrf_ccm_data.iv, iv, 8); + NRF_CCM->NONCE.VALUE[1] = get_be32(iv); + NRF_CCM->NONCE.VALUE[0] = get_be32(iv + 4); } void ble_phy_encrypt_counter_set(uint64_t counter, uint8_t dir_bit) { - g_nrf_ccm_data.pkt_counter = counter; - g_nrf_ccm_data.dir_bit = dir_bit; + NRF_CCM->NONCE.VALUE[3] = ((uint8_t *)&counter)[0]; + NRF_CCM->NONCE.VALUE[2] = get_be32(&((uint8_t *)&counter)[1]) | ((!!dir_bit) << 7); } void @@ -1742,28 +1747,6 @@ ble_phy_rx_set_start_time(uint32_t cputime, uint8_t rem_usecs) return rc; } -static void -ble_phy_ccm_job_list_init(struct nrf_ccm_job_list *job_list, uint16_t *alen, - uint16_t *dlen, uint8_t *dbuff) -{ - job_list->alen.size = 2; - job_list->alen.attributes = NRF_VDMA_ATTRIBUTE_CRC; - job_list->alen.p_buffer = (uint8_t *) alen; - - job_list->adata.size = *alen; - job_list->adata.p_buffer = NULL; - job_list->adata.attributes = NRF_VDMA_ATTRIBUTE_PLAIN_DATA_BUF_WRITE; - - job_list->mlen.size = 2; - job_list->mlen.attributes = NRF_VDMA_ATTRIBUTE_STATIC_ADDR; - job_list->mlen.p_buffer = (uint8_t *) dlen; - - job_list->mdata.size = *dlen; - job_list->mdata.p_buffer = (uint8_t *) dbuff; - job_list->mdata.attributes = 14; - -} - int ble_phy_tx(ble_phy_tx_pducb_t pducb, void *pducb_arg, uint8_t end_trans) { @@ -1774,12 +1757,6 @@ ble_phy_tx(ble_phy_tx_pducb_t pducb, void *pducb_arg, uint8_t end_trans) uint8_t hdr_byte; uint32_t state; uint32_t shortcuts; -#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) - static struct nrf_ccm_job_list ccm_jobs_in; - static struct nrf_ccm_job_list ccm_jobs_out; - static const uint16_t alen = 0; - uint16_t dlen; -#endif if (g_ble_phy_data.phy_transition_late) { ble_phy_disable(); @@ -1808,12 +1785,11 @@ ble_phy_tx(ble_phy_tx_pducb_t pducb, void *pducb_arg, uint8_t end_trans) if (g_ble_phy_data.phy_encrypted) { dptr = (uint8_t *)&g_ble_phy_enc_buf[0]; pktptr = (uint8_t *)&g_ble_phy_tx_buf[0]; - NRF_CCM->IN.PTR = (uint32_t)dptr; - NRF_CCM->OUT.PTR = (uint32_t)pktptr; -// NRF_CCM->SCRATCHPTR = (uint32_t)&g_nrf_encrypt_scratchpad[0]; + NRF_CCM->IN.PTR = (uint32_t)&g_ccm_job_list.in; + NRF_CCM->OUT.PTR = (uint32_t)&g_ccm_job_list.out; + NRF_CCM->EVENTS_ERROR = 0; - NRF_CCM->MODE = CCM_MODE_MACLEN_Pos | ble_phy_get_ccm_datarate(); - memcpy((uint8_t *)NRF_CCM->KEY.VALUE, &g_nrf_ccm_data.key, sizeof(g_nrf_ccm_data.key)); + NRF_CCM->MODE = CCM_MODE_MODE_Encryption | (CCM_MODE_MACLEN_M4 << CCM_MODE_MACLEN_Pos) | ble_phy_get_ccm_datarate(); } else { #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) NRF_AAR->IN.PTR = (uint32_t)&g_nrf_irk_list[0]; @@ -1836,39 +1812,60 @@ ble_phy_tx(ble_phy_tx_pducb_t pducb, void *pducb_arg, uint8_t end_trans) #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) if (g_ble_phy_data.phy_encrypted) { - ccm_jobs_in.alen.size = 2; - ccm_jobs_in.alen.attributes = NRF_VDMA_ATTRIBUTE_CRC; - ccm_jobs_in.alen.p_buffer = (uint8_t *) &alen; - - ccm_jobs_in.adata.size = alen; - ccm_jobs_in.adata.p_buffer = NULL; - ccm_jobs_in.adata.attributes = NRF_VDMA_ATTRIBUTE_PLAIN_DATA_BUF_WRITE; - - ccm_jobs_in.mlen.size = 2; - ccm_jobs_in.mlen.attributes = NRF_VDMA_ATTRIBUTE_STATIC_ADDR; - ccm_jobs_in.mlen.p_buffer = (uint8_t *) &dlen; - - ccm_jobs_in.mdata.size = dlen; - ccm_jobs_in.mdata.p_buffer = (uint8_t *) dptr; - ccm_jobs_in.mdata.attributes = 14; - - ccm_jobs_out.alen.size = 2; - ccm_jobs_out.alen.attributes = 11; - ccm_jobs_out.alen.p_buffer = (uint8_t *) &alen; - - ccm_jobs_out.adata.size = alen; - ccm_jobs_out.adata.attributes = 13; - ccm_jobs_out.adata.p_buffer = NULL; - - ccm_jobs_out.mlen.size = 2; - ccm_jobs_out.mlen.attributes = 12; - ccm_jobs_out.mlen.p_buffer = (uint8_t *) &dlen; - - ccm_jobs_out.mdata.size = dlen; - ccm_jobs_out.mdata.attributes = 14; - ccm_jobs_out.mdata.p_buffer = (uint8_t *) pktptr; - - /* Start key-stream generation and encryption (via short) */ + /* AAD length */ + g_ccm_job_list.in_alen = 1; + g_ccm_job_list.in[0].p_buffer = (uint8_t *) &g_ccm_job_list.in_alen; + g_ccm_job_list.in[0].size = sizeof(g_ccm_job_list.in_alen); + g_ccm_job_list.in[0].attributes = 11; + + /* Unencrypted message length */ + g_ccm_job_list.in_mlen = payload_len; + g_ccm_job_list.in[1].p_buffer = (uint8_t *) &g_ccm_job_list.in_mlen; + g_ccm_job_list.in[1].size = sizeof(g_ccm_job_list.in_mlen); + g_ccm_job_list.in[1].attributes = 12; + + /* AAD */ + g_ccm_job_list.in[2].p_buffer = (uint8_t *) &dptr[0]; + g_ccm_job_list.in[2].size = 1; + g_ccm_job_list.in[2].attributes = 13; + + /* Unencrypted message */ + g_ccm_job_list.in[3].p_buffer = (uint8_t *) &dptr[3]; + g_ccm_job_list.in[3].size = payload_len; + g_ccm_job_list.in[3].attributes = 14; + + /* Job list terminator */ + memset(&g_ccm_job_list.in[4], 0, sizeof(g_ccm_job_list.in[4])); + + /* AAD length */ + g_ccm_job_list.out[0].p_buffer = (uint8_t *) &g_ccm_job_list.out_alen; + g_ccm_job_list.out[0].size = sizeof(g_ccm_job_list.out_alen); + g_ccm_job_list.out[0].attributes = 11; + + /* Encrypted message length LSB */ + g_ccm_job_list.out[1].p_buffer = (uint8_t *) &pktptr[1]; + g_ccm_job_list.out[1].size = 1; + g_ccm_job_list.out[1].attributes = 12; + + /* Encrypted message length MSB */ + g_ccm_job_list.out[2].p_buffer = (uint8_t *) &g_ccm_job_list.out_mlen_msb; + g_ccm_job_list.out[2].size = sizeof(g_ccm_job_list.out_mlen_msb); + g_ccm_job_list.out[2].attributes = 12; + + /* AAD */ + g_ccm_job_list.out[3].p_buffer = (uint8_t *) &pktptr[0]; + g_ccm_job_list.out[3].size = 1; + g_ccm_job_list.out[3].attributes = 13; + + /* Encrypted message */ + g_ccm_job_list.out[4].p_buffer = (uint8_t *) &pktptr[3]; + g_ccm_job_list.out[4].size = payload_len + 4; + g_ccm_job_list.out[4].attributes = 14; + + /* Job list terminator */ + memset(&g_ccm_job_list.out[5], 0, sizeof(g_ccm_job_list.out[5])); + + /* Start encryption */ nrf_ccm_task_trigger(NRF_CCM, NRF_CCM_TASK_START); } #endif diff --git a/nimble/drivers/nrf54l15/src/phy.c b/nimble/drivers/nrf54l15/src/phy.c index 68b85abd5..8fc18b36d 100644 --- a/nimble/drivers/nrf54l15/src/phy.c +++ b/nimble/drivers/nrf54l15/src/phy.c @@ -229,13 +229,17 @@ phy_ppi_init(void) NRF_TIMER0->PUBLISH_COMPARE[0] = DPPI_CH_PUB(TIMER0_EVENTS_COMPARE_0); NRF_TIMER0->PUBLISH_COMPARE[3] = DPPI_CH_PUB(TIMER0_EVENTS_COMPARE_3); NRF_RADIO->PUBLISH_PHYEND = DPPI_CH_PUB(RADIO_EVENTS_END); -// NRF_RADIO->PUBLISH_END = DPPI_CH_PUB(RADIO_EVENTS_END); + NRF_RADIO->PUBLISH_PAYLOAD = DPPI_CH_PUB(RADIO_EVENTS_PAYLOAD_RADIO); NRF_RADIO->PUBLISH_BCMATCH = DPPI_CH_PUB(RADIO_EVENTS_BCMATCH); NRF_RADIO->PUBLISH_ADDRESS = DPPI_CH_PUB(RADIO_EVENTS_ADDRESS); NRF_RTC0->PUBLISH_COMPARE[0] = DPPI_CH_PUB(RTC0_EVENTS_COMPARE_0); + NRF_PPIB10->SUBSCRIBE_SEND[0] = DPPI_CH_PUB(RADIO_EVENTS_PAYLOAD_RADIO); + NRF_PPIB00->PUBLISH_RECEIVE[0] = DPPI_CH_PUB(RADIO_EVENTS_PAYLOAD_CCM); + /* Enable channels we publish on */ NRF_DPPIC->CHENSET = DPPI_CH_ENABLE_ALL; + NRF_DPPIC00->CHENSET = DPPIC_CHEN_CH0_Msk; /* radio_address_to_timer0_capture1 */ NRF_TIMER0->SUBSCRIBE_CAPTURE[1] = DPPI_CH_SUB(RADIO_EVENTS_ADDRESS); diff --git a/nimble/drivers/nrf54l15/src/phy_ppi.h b/nimble/drivers/nrf54l15/src/phy_ppi.h index 087aa0e4b..5ccd85b78 100644 --- a/nimble/drivers/nrf54l15/src/phy_ppi.h +++ b/nimble/drivers/nrf54l15/src/phy_ppi.h @@ -30,6 +30,8 @@ * Channels 7..9 are used for GPIO debugging (optionally). */ +#define DPPI_CH_RADIO_EVENTS_PAYLOAD_CCM 0 + #define DPPI_CH_TIMER0_EVENTS_COMPARE_0 0 #define DPPI_CH_TIMER0_EVENTS_COMPARE_3 1 #define DPPI_CH_RADIO_EVENTS_END 2 @@ -40,6 +42,7 @@ #define DPPI_CH_RADIO_EVENTS_DISABLED 7 #define DPPI_CH_RADIO_EVENTS_READY 8 #define DPPI_CH_RADIO_EVENTS_RXREADY 9 +#define DPPI_CH_RADIO_EVENTS_PAYLOAD_RADIO 10 #define DPPI_CH_IPCT130_EVENTS_RECEIVE_0 0 #define DPPI_CH_IPCT130_EVENTS_RECEIVE_1 1 @@ -50,7 +53,7 @@ #define DPPI_CH_ENABLE_ALL (DPPIC_CHEN_CH0_Msk | DPPIC_CHEN_CH1_Msk | \ DPPIC_CHEN_CH2_Msk | DPPIC_CHEN_CH3_Msk | \ - DPPIC_CHEN_CH4_Msk | DPPIC_CHEN_CH5_Msk) + DPPIC_CHEN_CH4_Msk | DPPIC_CHEN_CH5_Msk | DPPIC_CHEN_CH10_Msk) #define DPPI_CH_MASK_FEM (DPPI_CH_MASK(TIMER0_EVENTS_COMPARE_2) | \ DPPI_CH_MASK(RADIO_EVENTS_DISABLED)) @@ -96,13 +99,13 @@ phy_ppi_timer0_compare0_to_radio_rxen_disable(void) static inline void phy_ppi_radio_address_to_ccm_crypt_enable(void) { - NRF_CCM->SUBSCRIBE_START = DPPI_CH_SUB(RADIO_EVENTS_ADDRESS); + NRF_CCM->SUBSCRIBE_START = DPPI_CH_SUB(RADIO_EVENTS_PAYLOAD_CCM); } static inline void phy_ppi_radio_address_to_ccm_crypt_disable(void) { - NRF_CCM->SUBSCRIBE_START = DPPI_CH_UNSUB(RADIO_EVENTS_ADDRESS); + NRF_CCM->SUBSCRIBE_START = DPPI_CH_UNSUB(RADIO_EVENTS_PAYLOAD_CCM); } static inline void @@ -158,7 +161,7 @@ phy_ppi_disable(void) NRF_RADIO->SUBSCRIBE_TXEN = DPPI_CH_UNSUB(TIMER0_EVENTS_COMPARE_0); NRF_RADIO->SUBSCRIBE_RXEN = DPPI_CH_UNSUB(TIMER0_EVENTS_COMPARE_0); NRF_AAR->SUBSCRIBE_START = DPPI_CH_UNSUB(RADIO_EVENTS_BCMATCH); - NRF_CCM->SUBSCRIBE_START = DPPI_CH_UNSUB(RADIO_EVENTS_ADDRESS); + NRF_CCM->SUBSCRIBE_START = DPPI_CH_UNSUB(RADIO_EVENTS_PAYLOAD_CCM); phy_ppi_fem_disable(); }