Bluetooth: Host: Move Bluetooth Device address definition to own header
Move the Bluetooth device address definition out of the HCI header file. This definition is used by higher layer which should not have to include the HCI specific header file to get the address definition used by the host API. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
6d9807b31e
commit
063a5342c3
4 changed files with 98 additions and 72 deletions
95
include/bluetooth/addr.h
Normal file
95
include/bluetooth/addr.h
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/** @file
|
||||||
|
* @brief Bluetooth device address definitions and utilities.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_ADDR_H_
|
||||||
|
#define ZEPHYR_INCLUDE_BLUETOOTH_ADDR_H_
|
||||||
|
|
||||||
|
#include <zephyr/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BT_ADDR_LE_PUBLIC 0x00
|
||||||
|
#define BT_ADDR_LE_RANDOM 0x01
|
||||||
|
#define BT_ADDR_LE_PUBLIC_ID 0x02
|
||||||
|
#define BT_ADDR_LE_RANDOM_ID 0x03
|
||||||
|
|
||||||
|
/** Bluetooth Device Address */
|
||||||
|
typedef struct {
|
||||||
|
u8_t val[6];
|
||||||
|
} bt_addr_t;
|
||||||
|
|
||||||
|
/** Bluetooth LE Device Address */
|
||||||
|
typedef struct {
|
||||||
|
u8_t type;
|
||||||
|
bt_addr_t a;
|
||||||
|
} bt_addr_le_t;
|
||||||
|
|
||||||
|
#define BT_ADDR_ANY (&(bt_addr_t) { { 0, 0, 0, 0, 0, 0 } })
|
||||||
|
#define BT_ADDR_NONE (&(bt_addr_t) { \
|
||||||
|
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } })
|
||||||
|
#define BT_ADDR_LE_ANY (&(bt_addr_le_t) { 0, { { 0, 0, 0, 0, 0, 0 } } })
|
||||||
|
#define BT_ADDR_LE_NONE (&(bt_addr_le_t) { 0, \
|
||||||
|
{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } })
|
||||||
|
|
||||||
|
static inline int bt_addr_cmp(const bt_addr_t *a, const bt_addr_t *b)
|
||||||
|
{
|
||||||
|
return memcmp(a, b, sizeof(*a));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int bt_addr_le_cmp(const bt_addr_le_t *a, const bt_addr_le_t *b)
|
||||||
|
{
|
||||||
|
return memcmp(a, b, sizeof(*a));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bt_addr_copy(bt_addr_t *dst, const bt_addr_t *src)
|
||||||
|
{
|
||||||
|
memcpy(dst, src, sizeof(*dst));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bt_addr_le_copy(bt_addr_le_t *dst, const bt_addr_le_t *src)
|
||||||
|
{
|
||||||
|
memcpy(dst, src, sizeof(*dst));
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BT_ADDR_IS_RPA(a) (((a)->val[5] & 0xc0) == 0x40)
|
||||||
|
#define BT_ADDR_IS_NRPA(a) (((a)->val[5] & 0xc0) == 0x00)
|
||||||
|
#define BT_ADDR_IS_STATIC(a) (((a)->val[5] & 0xc0) == 0xc0)
|
||||||
|
|
||||||
|
#define BT_ADDR_SET_RPA(a) ((a)->val[5] = (((a)->val[5] & 0x3f) | 0x40))
|
||||||
|
#define BT_ADDR_SET_NRPA(a) ((a)->val[5] &= 0x3f)
|
||||||
|
#define BT_ADDR_SET_STATIC(a) ((a)->val[5] |= 0xc0)
|
||||||
|
|
||||||
|
int bt_addr_le_create_nrpa(bt_addr_le_t *addr);
|
||||||
|
int bt_addr_le_create_static(bt_addr_le_t *addr);
|
||||||
|
|
||||||
|
static inline bool bt_addr_le_is_rpa(const bt_addr_le_t *addr)
|
||||||
|
{
|
||||||
|
if (addr->type != BT_ADDR_LE_RANDOM) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BT_ADDR_IS_RPA(&addr->a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool bt_addr_le_is_identity(const bt_addr_le_t *addr)
|
||||||
|
{
|
||||||
|
if (addr->type == BT_ADDR_LE_PUBLIC) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BT_ADDR_IS_STATIC(&addr->a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_ADDR_H_ */
|
|
@ -23,6 +23,7 @@
|
||||||
#include <sys/util.h>
|
#include <sys/util.h>
|
||||||
#include <net/buf.h>
|
#include <net/buf.h>
|
||||||
#include <bluetooth/gap.h>
|
#include <bluetooth/gap.h>
|
||||||
|
#include <bluetooth/addr.h>
|
||||||
#include <bluetooth/crypto.h>
|
#include <bluetooth/crypto.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <bluetooth/bluetooth.h>
|
#include <bluetooth/bluetooth.h>
|
||||||
#include <bluetooth/hci.h>
|
#include <bluetooth/hci.h>
|
||||||
|
#include <bluetooth/addr.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -14,88 +14,17 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/util.h>
|
#include <sys/util.h>
|
||||||
#include <net/buf.h>
|
#include <net/buf.h>
|
||||||
|
#include <bluetooth/addr.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BT_ADDR_LE_PUBLIC 0x00
|
|
||||||
#define BT_ADDR_LE_RANDOM 0x01
|
|
||||||
#define BT_ADDR_LE_PUBLIC_ID 0x02
|
|
||||||
#define BT_ADDR_LE_RANDOM_ID 0x03
|
|
||||||
|
|
||||||
/* Special own address types for LL privacy (used in adv & scan parameters) */
|
/* Special own address types for LL privacy (used in adv & scan parameters) */
|
||||||
#define BT_HCI_OWN_ADDR_RPA_OR_PUBLIC 0x02
|
#define BT_HCI_OWN_ADDR_RPA_OR_PUBLIC 0x02
|
||||||
#define BT_HCI_OWN_ADDR_RPA_OR_RANDOM 0x03
|
#define BT_HCI_OWN_ADDR_RPA_OR_RANDOM 0x03
|
||||||
#define BT_HCI_OWN_ADDR_RPA_MASK 0x02
|
#define BT_HCI_OWN_ADDR_RPA_MASK 0x02
|
||||||
|
|
||||||
/** Bluetooth Device Address */
|
|
||||||
typedef struct {
|
|
||||||
u8_t val[6];
|
|
||||||
} bt_addr_t;
|
|
||||||
|
|
||||||
/** Bluetooth LE Device Address */
|
|
||||||
typedef struct {
|
|
||||||
u8_t type;
|
|
||||||
bt_addr_t a;
|
|
||||||
} bt_addr_le_t;
|
|
||||||
|
|
||||||
#define BT_ADDR_ANY (&(bt_addr_t) { { 0, 0, 0, 0, 0, 0 } })
|
|
||||||
#define BT_ADDR_NONE (&(bt_addr_t) { \
|
|
||||||
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } })
|
|
||||||
#define BT_ADDR_LE_ANY (&(bt_addr_le_t) { 0, { { 0, 0, 0, 0, 0, 0 } } })
|
|
||||||
#define BT_ADDR_LE_NONE (&(bt_addr_le_t) { 0, \
|
|
||||||
{ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } })
|
|
||||||
|
|
||||||
static inline int bt_addr_cmp(const bt_addr_t *a, const bt_addr_t *b)
|
|
||||||
{
|
|
||||||
return memcmp(a, b, sizeof(*a));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int bt_addr_le_cmp(const bt_addr_le_t *a, const bt_addr_le_t *b)
|
|
||||||
{
|
|
||||||
return memcmp(a, b, sizeof(*a));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bt_addr_copy(bt_addr_t *dst, const bt_addr_t *src)
|
|
||||||
{
|
|
||||||
memcpy(dst, src, sizeof(*dst));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void bt_addr_le_copy(bt_addr_le_t *dst, const bt_addr_le_t *src)
|
|
||||||
{
|
|
||||||
memcpy(dst, src, sizeof(*dst));
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BT_ADDR_IS_RPA(a) (((a)->val[5] & 0xc0) == 0x40)
|
|
||||||
#define BT_ADDR_IS_NRPA(a) (((a)->val[5] & 0xc0) == 0x00)
|
|
||||||
#define BT_ADDR_IS_STATIC(a) (((a)->val[5] & 0xc0) == 0xc0)
|
|
||||||
|
|
||||||
#define BT_ADDR_SET_RPA(a) ((a)->val[5] = (((a)->val[5] & 0x3f) | 0x40))
|
|
||||||
#define BT_ADDR_SET_NRPA(a) ((a)->val[5] &= 0x3f)
|
|
||||||
#define BT_ADDR_SET_STATIC(a) ((a)->val[5] |= 0xc0)
|
|
||||||
|
|
||||||
int bt_addr_le_create_nrpa(bt_addr_le_t *addr);
|
|
||||||
int bt_addr_le_create_static(bt_addr_le_t *addr);
|
|
||||||
|
|
||||||
static inline bool bt_addr_le_is_rpa(const bt_addr_le_t *addr)
|
|
||||||
{
|
|
||||||
if (addr->type != BT_ADDR_LE_RANDOM) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return BT_ADDR_IS_RPA(&addr->a);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool bt_addr_le_is_identity(const bt_addr_le_t *addr)
|
|
||||||
{
|
|
||||||
if (addr->type == BT_ADDR_LE_PUBLIC) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return BT_ADDR_IS_STATIC(&addr->a);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BT_ENC_KEY_SIZE_MIN 0x07
|
#define BT_ENC_KEY_SIZE_MIN 0x07
|
||||||
#define BT_ENC_KEY_SIZE_MAX 0x10
|
#define BT_ENC_KEY_SIZE_MAX 0x10
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue