nimble/phy: Add setting for header mask for encryption

ISO PDUs require different bits to be masked out in PDU header than
standard data PDUs (Core 5.3, Vol 6, Part E, 2.2) when generating
keystream for encryption/decrytpion so we need to be able to set such
mask.

For now this only works on nRF5340 as it has dedicated support for that.

Header mask is always reset to default (data PDU) to avoid changing lots
of old code.
This commit is contained in:
Andrzej Kaczmarek
2023-02-02 23:25:32 +01:00
parent 511ad6a9e6
commit 5f7ca70628
3 changed files with 18 additions and 0 deletions
@@ -26,6 +26,11 @@
extern "C" {
#endif
/* Header mask for keystream generation */
#define BLE_LL_PDU_HEADERMASK_DATA (0xe3)
#define BLE_LL_PDU_HEADERMASK_BIS (0xc3)
#define BLE_LL_PDU_HEADERMASK_CIS (0xa3)
#define BLE_LL_PDU_PREAMBLE_1M_LEN (1)
#define BLE_LL_PDU_PREAMBLE_2M_LEN (2)
#define BLE_LL_PDU_AA_LEN (4)
@@ -165,6 +165,8 @@ uint32_t ble_phy_access_addr_get(void);
/* Enable encryption */
void ble_phy_encrypt_enable(const uint8_t *key);
/* Set mask for PDU header (see Core 5.3, Vol 6, Part E, 2.2) */
void ble_phy_encrypt_header_mask_set(uint8_t mask);
/* Set encryption IV */
void ble_phy_encrypt_iv_set(const uint8_t *iv);
/* Set encryption packet counter and direction bit */
+11
View File
@@ -1700,6 +1700,17 @@ ble_phy_encrypt_enable(const uint8_t *key)
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
}
void
ble_phy_encrypt_header_mask_set(uint8_t mask)
{
#ifdef NRF5340_XXAA
NRF_CCM->HEADERMASK = mask;
#endif
}
void