zephyr/subsys/bluetooth/controller/ll_sw/ll_addr.c
Vinayak Kariappa Chettimada 28f4c1b703 Bluetooth: controller: split: Rework with defines for adv set states
Review rework, added comments, TODOs, FIXMEs and converted
magic number use in advertising set state flags to defines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00

85 lines
1.7 KiB
C

/*
* Copyright (c) 2016-2018 Nordic Semiconductor ASA
* Copyright (c) 2016 Vinayak Kariappa Chettimada
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stddef.h>
#include <string.h>
#include <zephyr/types.h>
#include <bluetooth/hci.h>
#include <bluetooth/controller.h>
#include "util/util.h"
#include "util/memq.h"
#include "pdu.h"
#include "lll.h"
#include "lll_adv.h"
#include "lll_scan.h"
#include "ull_adv_types.h"
#include "ull_scan_types.h"
#include "ull_adv_internal.h"
#include "ull_scan_internal.h"
static uint8_t pub_addr[BDADDR_SIZE];
static uint8_t rnd_addr[BDADDR_SIZE];
uint8_t *ll_addr_get(uint8_t addr_type, uint8_t *bdaddr)
{
if (addr_type > 1) {
return NULL;
}
if (addr_type) {
if (bdaddr) {
memcpy(bdaddr, rnd_addr, BDADDR_SIZE);
}
return rnd_addr;
}
if (bdaddr) {
memcpy(bdaddr, pub_addr, BDADDR_SIZE);
}
return pub_addr;
}
uint32_t ll_addr_set(uint8_t addr_type, uint8_t const *const bdaddr)
{
if (IS_ENABLED(CONFIG_BT_BROADCASTER)) {
uint32_t status = ull_adv_is_enabled(0);
#if defined(CONFIG_BT_CTLR_ADV_EXT)
if ((status & (ULL_ADV_ENABLED_BITMASK_ENABLED |
ULL_ADV_ENABLED_BITMASK_EXTENDED)) ==
ULL_ADV_ENABLED_BITMASK_ENABLED) {
#else /* !CONFIG_BT_CTLR_ADV_EXT */
if (status) {
#endif /* !CONFIG_BT_CTLR_ADV_EXT */
return BT_HCI_ERR_CMD_DISALLOWED;
}
}
if (IS_ENABLED(CONFIG_BT_OBSERVER) &&
(ull_scan_is_enabled(0) & (BIT(1) | BIT(2)))) {
return BT_HCI_ERR_CMD_DISALLOWED;
}
if (addr_type) {
memcpy(rnd_addr, bdaddr, BDADDR_SIZE);
} else {
memcpy(pub_addr, bdaddr, BDADDR_SIZE);
}
return 0;
}
void bt_ctlr_set_public_addr(const uint8_t *addr)
{
(void)memcpy(pub_addr, addr, sizeof(pub_addr));
}