From 9fcd0827fd267bb5c57fa48a79f92b2a40cd01df Mon Sep 17 00:00:00 2001 From: Vinayak Chettimada Date: Wed, 26 Apr 2017 23:49:58 +0200 Subject: [PATCH] Bluetooth: controller: Explicit AC and DC packet configure In the Controller's radio hal, explicitly differentiate between Advertisement and Data channel packet configuration. Also, remove nRF5x specific extra overhead in Advertisement PDU structure. Change-id: I942b88a160af78f8900d7e49fb5f36c8aa493b97 Signed-off-by: Vinayak Chettimada --- subsys/bluetooth/controller/hal/nrf5/radio.c | 50 ++++++++++++-------- subsys/bluetooth/controller/hal/radio.h | 2 +- subsys/bluetooth/controller/ll_sw/ctrl.c | 10 ++-- subsys/bluetooth/controller/ll_sw/ll.c | 4 -- subsys/bluetooth/controller/ll_sw/pdu.h | 7 ++- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/subsys/bluetooth/controller/hal/nrf5/radio.c b/subsys/bluetooth/controller/hal/nrf5/radio.c index b4fa3e1ce83..e7c9a9c07e2 100644 --- a/subsys/bluetooth/controller/hal/nrf5/radio.c +++ b/subsys/bluetooth/controller/hal/nrf5/radio.c @@ -94,31 +94,41 @@ void radio_aa_set(u8_t *aa) NRF_RADIO->BASE0 = (aa[2] << 24) | (aa[1] << 16) | (aa[0] << 8); } -void radio_pkt_configure(u8_t preamble16, u8_t bits_len, u8_t max_len) +void radio_pkt_configure(u8_t bits_len, u8_t max_len, u8_t flags) { -#if defined(CONFIG_SOC_SERIES_NRF51X) - ARG_UNUSED(preamble16); + u8_t p16 = (flags >> 1) & 0x01; /* 16-bit preamble */ + u8_t dc = flags & 0x01; /* Adv or Data channel */ + u32_t extra; - if (bits_len == 8) { +#if defined(CONFIG_SOC_SERIES_NRF51X) + ARG_UNUSED(p16); + + extra = 0; + + /* nRF51 supports only 27 byte PDU when using h/w CCM for encryption. */ + if (dc) { bits_len = 5; } -#endif +#else /* !CONFIG_SOC_SERIES_NRF51X */ + extra = (((p16) ? RADIO_PCNF0_PLEN_16bit : RADIO_PCNF0_PLEN_8bit) << + RADIO_PCNF0_PLEN_Pos) & RADIO_PCNF0_PLEN_Msk; - NRF_RADIO->PCNF0 = ((((1UL) << RADIO_PCNF0_S0LEN_Pos) & - RADIO_PCNF0_S0LEN_Msk) | - ((((u32_t)bits_len) << RADIO_PCNF0_LFLEN_Pos) & - RADIO_PCNF0_LFLEN_Msk) | -#if !defined(CONFIG_SOC_SERIES_NRF51X) - (((RADIO_PCNF0_S1INCL_Include) << - RADIO_PCNF0_S1INCL_Pos) & - RADIO_PCNF0_S1INCL_Msk) | - ((((preamble16) ? RADIO_PCNF0_PLEN_16bit : - RADIO_PCNF0_PLEN_8bit) << RADIO_PCNF0_PLEN_Pos) & - RADIO_PCNF0_PLEN_Msk) | -#endif - ((((u32_t)8-bits_len) << - RADIO_PCNF0_S1LEN_Pos) & - RADIO_PCNF0_S1LEN_Msk)); + /* To use same Data Channel PDU structure with nRF5 specific overhead + * byte, include the S1 field in radio packet configuration. + */ + if (dc) { + extra |= (RADIO_PCNF0_S1INCL_Include << + RADIO_PCNF0_S1INCL_Pos) & RADIO_PCNF0_S1INCL_Msk; + } +#endif /* !CONFIG_SOC_SERIES_NRF51X */ + + NRF_RADIO->PCNF0 = (((1UL) << RADIO_PCNF0_S0LEN_Pos) & + RADIO_PCNF0_S0LEN_Msk) | + ((((u32_t)bits_len) << RADIO_PCNF0_LFLEN_Pos) & + RADIO_PCNF0_LFLEN_Msk) | + ((((u32_t)8-bits_len) << RADIO_PCNF0_S1LEN_Pos) & + RADIO_PCNF0_S1LEN_Msk) | + extra; NRF_RADIO->PCNF1 = (((((u32_t)max_len) << RADIO_PCNF1_MAXLEN_Pos) & RADIO_PCNF1_MAXLEN_Msk) | diff --git a/subsys/bluetooth/controller/hal/radio.h b/subsys/bluetooth/controller/hal/radio.h index 95e416dceb7..d66e26995ee 100644 --- a/subsys/bluetooth/controller/hal/radio.h +++ b/subsys/bluetooth/controller/hal/radio.h @@ -31,7 +31,7 @@ void radio_tx_power_set(u32_t power); void radio_freq_chan_set(u32_t chan); void radio_whiten_iv_set(u32_t iv); void radio_aa_set(u8_t *aa); -void radio_pkt_configure(u8_t preamble16, u8_t bits_len, u8_t max_len); +void radio_pkt_configure(u8_t bits_len, u8_t max_len, u8_t flags); void radio_pkt_rx_set(void *rx_packet); void radio_pkt_tx_set(void *tx_packet); void radio_rx_enable(void); diff --git a/subsys/bluetooth/controller/ll_sw/ctrl.c b/subsys/bluetooth/controller/ll_sw/ctrl.c index 8a8707c78e3..b9eb36d84b0 100644 --- a/subsys/bluetooth/controller/ll_sw/ctrl.c +++ b/subsys/bluetooth/controller/ll_sw/ctrl.c @@ -4309,7 +4309,7 @@ static void adv_obs_configure(u8_t phy) adv_obs_conn_configure(phy); radio_aa_set((u8_t *)&aa); - radio_pkt_configure(phy, 6, 37); + radio_pkt_configure(8, PDU_AC_PAYLOAD_SIZE_MAX, (phy << 1)); radio_crc_configure(((0x5bUL) | ((0x06UL) << 8) | ((0x00UL) << 16)), 0x555555); } @@ -6112,12 +6112,12 @@ static void rx_packet_set(struct connection *conn, struct pdu_data *pdu_data_rx) phy = RADIO_PHY_CONN; if (conn->enc_rx) { - radio_pkt_configure(phy, 8, (max_rx_octets + 4)); + radio_pkt_configure(8, (max_rx_octets + 4), (phy << 1) | 0x01); radio_pkt_rx_set(radio_ccm_rx_pkt_set(&conn->ccm_rx, pdu_data_rx)); } else { - radio_pkt_configure(phy, 8, max_rx_octets); + radio_pkt_configure(8, max_rx_octets, (phy << 1) | 0x01); radio_pkt_rx_set(pdu_data_rx); } @@ -6136,12 +6136,12 @@ static void tx_packet_set(struct connection *conn, struct pdu_data *pdu_data_tx) phy = RADIO_PHY_CONN; if (conn->enc_tx) { - radio_pkt_configure(phy, 8, (max_tx_octets + 4)); + radio_pkt_configure(8, (max_tx_octets + 4), (phy << 1) | 0x01); radio_pkt_tx_set(radio_ccm_tx_pkt_set(&conn->ccm_tx, pdu_data_tx)); } else { - radio_pkt_configure(phy, 8, max_tx_octets); + radio_pkt_configure(8, max_tx_octets, (phy << 1) | 0x01); radio_pkt_tx_set(pdu_data_tx); } diff --git a/subsys/bluetooth/controller/ll_sw/ll.c b/subsys/bluetooth/controller/ll_sw/ll.c index 4afd135ec39..a529a93eff9 100644 --- a/subsys/bluetooth/controller/ll_sw/ll.c +++ b/subsys/bluetooth/controller/ll_sw/ll.c @@ -324,7 +324,6 @@ void ll_adv_params_set(u16_t interval, u8_t adv_type, pdu->len = BDADDR_SIZE; } pdu->rx_addr = _ll_adv_params.rx_addr; - pdu->resv = 0; /* update the current scan data */ radio_adv_data = radio_scan_data_get(); @@ -337,7 +336,6 @@ void ll_adv_params_set(u16_t interval, u8_t adv_type, if (pdu->len == 0) { pdu->len = BDADDR_SIZE; } - pdu->resv = 0; } void ll_adv_data_set(u8_t len, u8_t const *const data) @@ -384,7 +382,6 @@ void ll_adv_data_set(u8_t len, u8_t const *const data) memcpy(&pdu->payload.adv_ind.data[0], data, len); pdu->len = BDADDR_SIZE + len; } - pdu->resv = 0; /* commit the update so controller picks it. */ radio_adv_data->last = last; @@ -418,7 +415,6 @@ void ll_scan_data_set(u8_t len, u8_t const *const data) memcpy(&pdu->payload.scan_rsp.addr[0], &_ll_adv_params.adv_addr[0], BDADDR_SIZE); memcpy(&pdu->payload.scan_rsp.data[0], data, len); - pdu->resv = 0; /* commit the update so controller picks it. */ radio_scan_data->last = last; diff --git a/subsys/bluetooth/controller/ll_sw/pdu.h b/subsys/bluetooth/controller/ll_sw/pdu.h index 86e6eef57bd..4ba91905cc4 100644 --- a/subsys/bluetooth/controller/ll_sw/pdu.h +++ b/subsys/bluetooth/controller/ll_sw/pdu.h @@ -12,8 +12,9 @@ /* PDU Sizes */ #define PDU_EM_SIZE_MAX 3 -#define PDU_AC_SIZE_OVERHEAD 3 -#define PDU_AC_SIZE_MAX (37 + PDU_AC_SIZE_OVERHEAD) +#define PDU_AC_SIZE_OVERHEAD 2 +#define PDU_AC_PAYLOAD_SIZE_MAX 37 +#define PDU_AC_SIZE_MAX (PDU_AC_PAYLOAD_SIZE_MAX + PDU_AC_SIZE_OVERHEAD) struct pdu_adv_payload_adv_ind { u8_t addr[BDADDR_SIZE]; @@ -79,8 +80,6 @@ struct pdu_adv { u8_t len:8; - u8_t resv:8; /* TODO: remove nRF specific code */ - union { struct pdu_adv_payload_adv_ind adv_ind; struct pdu_adv_payload_direct_ind direct_ind;