mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2025-07-31 19:31:05 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
|
|
@ -0,0 +1,65 @@
|
|||
/** @file
|
||||
* @brief Attribute Protocol handling.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_ATT_H
|
||||
#define __BT_ATT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <misc/slist.h>
|
||||
|
||||
/* Error codes for Error response PDU */
|
||||
#define BT_ATT_ERR_INVALID_HANDLE 0x01
|
||||
#define BT_ATT_ERR_READ_NOT_PERMITTED 0x02
|
||||
#define BT_ATT_ERR_WRITE_NOT_PERMITTED 0x03
|
||||
#define BT_ATT_ERR_INVALID_PDU 0x04
|
||||
#define BT_ATT_ERR_AUTHENTICATION 0x05
|
||||
#define BT_ATT_ERR_NOT_SUPPORTED 0x06
|
||||
#define BT_ATT_ERR_INVALID_OFFSET 0x07
|
||||
#define BT_ATT_ERR_AUTHORIZATION 0x08
|
||||
#define BT_ATT_ERR_PREPARE_QUEUE_FULL 0x09
|
||||
#define BT_ATT_ERR_ATTRIBUTE_NOT_FOUND 0x0a
|
||||
#define BT_ATT_ERR_ATTRIBUTE_NOT_LONG 0x0b
|
||||
#define BT_ATT_ERR_ENCRYPTION_KEY_SIZE 0x0c
|
||||
#define BT_ATT_ERR_INVALID_ATTRIBUTE_LEN 0x0d
|
||||
#define BT_ATT_ERR_UNLIKELY 0x0e
|
||||
#define BT_ATT_ERR_INSUFFICIENT_ENCRYPTION 0x0f
|
||||
#define BT_ATT_ERR_UNSUPPORTED_GROUP_TYPE 0x10
|
||||
#define BT_ATT_ERR_INSUFFICIENT_RESOURCES 0x11
|
||||
|
||||
/* Common Profile Error Codes (from CSS) */
|
||||
#define BT_ATT_ERR_WRITE_REQ_REJECTED 0xfc
|
||||
#define BT_ATT_ERR_CCC_IMPROPER_CONF 0xfd
|
||||
#define BT_ATT_ERR_PROCEDURE_IN_PROGRESS 0xfe
|
||||
#define BT_ATT_ERR_OUT_OF_RANGE 0xff
|
||||
|
||||
typedef void (*bt_att_func_t)(struct bt_conn *conn, u8_t err,
|
||||
const void *pdu, u16_t length,
|
||||
void *user_data);
|
||||
typedef void (*bt_att_destroy_t)(void *user_data);
|
||||
|
||||
/* ATT request context */
|
||||
struct bt_att_req {
|
||||
sys_snode_t node;
|
||||
bt_att_func_t func;
|
||||
bt_att_destroy_t destroy;
|
||||
struct net_buf_simple_state state;
|
||||
struct net_buf *buf;
|
||||
#if defined(CONFIG_BT_SMP)
|
||||
bool retrying;
|
||||
#endif /* CONFIG_BT_SMP */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __BT_ATT_H */
|
||||
|
|
@ -0,0 +1,488 @@
|
|||
/** @file
|
||||
* @brief Bluetooth subsystem core APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2015-2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_BLUETOOTH_H
|
||||
#define __BT_BLUETOOTH_H
|
||||
|
||||
/**
|
||||
* @brief Bluetooth APIs
|
||||
* @defgroup bluetooth Bluetooth APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <misc/printk.h>
|
||||
#include <net/buf.h>
|
||||
#include <misc/util.h>
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/crypto.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Generic Access Profile
|
||||
* @defgroup bt_gap Generic Access Profile
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef bt_ready_cb_t
|
||||
* @brief Callback for notifying that Bluetooth has been enabled.
|
||||
*
|
||||
* @param err zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
typedef void (*bt_ready_cb_t)(int err);
|
||||
|
||||
/** @brief Enable Bluetooth
|
||||
*
|
||||
* Enable Bluetooth. Must be the called before any calls that
|
||||
* require communication with the local Bluetooth hardware.
|
||||
*
|
||||
* @param cb Callback to notify completion or NULL to perform the
|
||||
* enabling synchronously.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_enable(bt_ready_cb_t cb);
|
||||
|
||||
/* Advertising API */
|
||||
|
||||
/** Description of different data types that can be encoded into
|
||||
* advertising data. Used to form arrays that are passed to the
|
||||
* bt_le_adv_start() function.
|
||||
*/
|
||||
struct bt_data {
|
||||
u8_t type;
|
||||
u8_t data_len;
|
||||
const u8_t *data;
|
||||
};
|
||||
|
||||
/** @brief Helper to declare elements of bt_data arrays
|
||||
*
|
||||
* This macro is mainly for creating an array of struct bt_data
|
||||
* elements which is then passed to bt_le_adv_start().
|
||||
*
|
||||
* @param _type Type of advertising data field
|
||||
* @param _data Pointer to the data field payload
|
||||
* @param _data_len Number of bytes behind the _data pointer
|
||||
*/
|
||||
#define BT_DATA(_type, _data, _data_len) \
|
||||
{ \
|
||||
.type = (_type), \
|
||||
.data_len = (_data_len), \
|
||||
.data = (const u8_t *)(_data), \
|
||||
}
|
||||
|
||||
/** @brief Helper to declare elements of bt_data arrays
|
||||
*
|
||||
* This macro is mainly for creating an array of struct bt_data
|
||||
* elements which is then passed to bt_le_adv_start().
|
||||
*
|
||||
* @param _type Type of advertising data field
|
||||
* @param _bytes Variable number of single-byte parameters
|
||||
*/
|
||||
#define BT_DATA_BYTES(_type, _bytes...) \
|
||||
BT_DATA(_type, ((u8_t []) { _bytes }), \
|
||||
sizeof((u8_t []) { _bytes }))
|
||||
|
||||
/** Advertising options */
|
||||
enum {
|
||||
/** Convenience value when no options are specified. */
|
||||
BT_LE_ADV_OPT_NONE = 0,
|
||||
|
||||
/** Advertise as connectable. Type of advertising is determined by
|
||||
* providing SCAN_RSP data and/or enabling local privacy support.
|
||||
*/
|
||||
BT_LE_ADV_OPT_CONNECTABLE = BIT(0),
|
||||
|
||||
/** Don't try to resume connectable advertising after a connection.
|
||||
* This option is only meaningful when used together with
|
||||
* BT_LE_ADV_OPT_CONNECTABLE. If set the advertising will be stopped
|
||||
* when bt_le_adv_stop() is called or when an incoming (slave)
|
||||
* connection happens. If this option is not set the stack will
|
||||
* take care of keeping advertising enabled even as connections
|
||||
* occur.
|
||||
*/
|
||||
BT_LE_ADV_OPT_ONE_TIME = BIT(1),
|
||||
};
|
||||
|
||||
/** LE Advertising Parameters. */
|
||||
struct bt_le_adv_param {
|
||||
/** Bit-field of advertising options */
|
||||
u8_t options;
|
||||
|
||||
/** Minimum Advertising Interval (N * 0.625) */
|
||||
u16_t interval_min;
|
||||
|
||||
/** Maximum Advertising Interval (N * 0.625) */
|
||||
u16_t interval_max;
|
||||
|
||||
/** Optional predefined (random) own address. Currently
|
||||
* the only permitted use of this is for NRPA with
|
||||
* non-connectable advertising.
|
||||
*/
|
||||
const bt_addr_t *own_addr;
|
||||
};
|
||||
|
||||
/** Helper to declare advertising parameters inline
|
||||
*
|
||||
* @param _options Advertising Options
|
||||
* @param _int_min Minimum advertising interval
|
||||
* @param _int_max Maximum advertising interval
|
||||
*/
|
||||
#define BT_LE_ADV_PARAM(_options, _int_min, _int_max) \
|
||||
(&(struct bt_le_adv_param) { \
|
||||
.options = (_options), \
|
||||
.interval_min = (_int_min), \
|
||||
.interval_max = (_int_max), \
|
||||
})
|
||||
|
||||
#define BT_LE_ADV_CONN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE, \
|
||||
BT_GAP_ADV_FAST_INT_MIN_2, \
|
||||
BT_GAP_ADV_FAST_INT_MAX_2)
|
||||
|
||||
#define BT_LE_ADV_NCONN BT_LE_ADV_PARAM(0, BT_GAP_ADV_FAST_INT_MIN_2, \
|
||||
BT_GAP_ADV_FAST_INT_MAX_2)
|
||||
|
||||
/** @brief Start advertising
|
||||
*
|
||||
* Set advertisement data, scan response data, advertisement parameters
|
||||
* and start advertising.
|
||||
*
|
||||
* @param param Advertising parameters.
|
||||
* @param ad Data to be used in advertisement packets.
|
||||
* @param ad_len Number of elements in ad
|
||||
* @param sd Data to be used in scan response packets.
|
||||
* @param sd_len Number of elements in sd
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_le_adv_start(const struct bt_le_adv_param *param,
|
||||
const struct bt_data *ad, size_t ad_len,
|
||||
const struct bt_data *sd, size_t sd_len);
|
||||
|
||||
/** @brief Stop advertising
|
||||
*
|
||||
* Stops ongoing advertising.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_le_adv_stop(void);
|
||||
|
||||
/** @typedef bt_le_scan_cb_t
|
||||
* @brief Callback type for reporting LE scan results.
|
||||
*
|
||||
* A function of this type is given to the bt_le_scan_start() function
|
||||
* and will be called for any discovered LE device.
|
||||
*
|
||||
* @param addr Advertiser LE address and type.
|
||||
* @param rssi Strength of advertiser signal.
|
||||
* @param adv_type Type of advertising response from advertiser.
|
||||
* @param data Buffer containing advertiser data.
|
||||
*/
|
||||
typedef void bt_le_scan_cb_t(const bt_addr_le_t *addr, s8_t rssi,
|
||||
u8_t adv_type, struct net_buf_simple *buf);
|
||||
|
||||
/** LE scan parameters */
|
||||
struct bt_le_scan_param {
|
||||
/** Scan type (BT_HCI_LE_SCAN_ACTIVE or BT_HCI_LE_SCAN_PASSIVE) */
|
||||
u8_t type;
|
||||
|
||||
/** Duplicate filtering (BT_HCI_LE_SCAN_FILTER_DUP_ENABLE or
|
||||
* BT_HCI_LE_SCAN_FILTER_DUP_DISABLE)
|
||||
*/
|
||||
u8_t filter_dup;
|
||||
|
||||
/** Scan interval (N * 0.625 ms) */
|
||||
u16_t interval;
|
||||
|
||||
/** Scan window (N * 0.625 ms) */
|
||||
u16_t window;
|
||||
};
|
||||
|
||||
/** Helper to declare scan parameters inline
|
||||
*
|
||||
* @param _type Scan Type (BT_HCI_LE_SCAN_ACTIVE/BT_HCI_LE_SCAN_PASSIVE)
|
||||
* @param _filter Filter Duplicates
|
||||
* @param _interval Scan Interval (N * 0.625 ms)
|
||||
* @param _window Scan Window (N * 0.625 ms)
|
||||
*/
|
||||
#define BT_LE_SCAN_PARAM(_type, _filter, _interval, _window) \
|
||||
(&(struct bt_le_scan_param) { \
|
||||
.type = (_type), \
|
||||
.filter_dup = (_filter), \
|
||||
.interval = (_interval), \
|
||||
.window = (_window), \
|
||||
})
|
||||
|
||||
/** Helper macro to enable active scanning to discover new devices. */
|
||||
#define BT_LE_SCAN_ACTIVE BT_LE_SCAN_PARAM(BT_HCI_LE_SCAN_ACTIVE, \
|
||||
BT_HCI_LE_SCAN_FILTER_DUP_ENABLE, \
|
||||
BT_GAP_SCAN_FAST_INTERVAL, \
|
||||
BT_GAP_SCAN_FAST_WINDOW)
|
||||
|
||||
/** Helper macro to enable passive scanning to discover new devices.
|
||||
*
|
||||
* This macro should be used if information required for device identification
|
||||
* (e.g., UUID) are known to be placed in Advertising Data.
|
||||
*/
|
||||
#define BT_LE_SCAN_PASSIVE BT_LE_SCAN_PARAM(BT_HCI_LE_SCAN_PASSIVE, \
|
||||
BT_HCI_LE_SCAN_FILTER_DUP_ENABLE, \
|
||||
BT_GAP_SCAN_FAST_INTERVAL, \
|
||||
BT_GAP_SCAN_FAST_WINDOW)
|
||||
|
||||
/** @brief Start (LE) scanning
|
||||
*
|
||||
* Start LE scanning with given parameters and provide results through
|
||||
* the specified callback.
|
||||
*
|
||||
* @param param Scan parameters.
|
||||
* @param cb Callback to notify scan results.
|
||||
*
|
||||
* @return Zero on success or error code otherwise, positive in case
|
||||
* of protocol error or negative (POSIX) in case of stack internal error
|
||||
*/
|
||||
int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb);
|
||||
|
||||
/** @brief Stop (LE) scanning.
|
||||
*
|
||||
* Stops ongoing LE scanning.
|
||||
*
|
||||
* @return Zero on success or error code otherwise, positive in case
|
||||
* of protocol error or negative (POSIX) in case of stack internal error
|
||||
*/
|
||||
int bt_le_scan_stop(void);
|
||||
|
||||
struct bt_le_oob {
|
||||
/** LE address. If local privacy is enabled this is Resolvable Private
|
||||
* Address.
|
||||
*/
|
||||
bt_addr_le_t addr;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get LE local Out Of Band information
|
||||
*
|
||||
* This function allows to get local information that are useful for Out Of Band
|
||||
* pairing or connection creation process.
|
||||
*
|
||||
* If privacy is enabled this will result in generating new Resolvable Private
|
||||
* Address that is valid for CONFIG_BT_RPA_TIMEOUT seconds. This address
|
||||
* will be used for advertising, active scanning and connection creation.
|
||||
*
|
||||
* @param oob LE related information
|
||||
*/
|
||||
int bt_le_oob_get_local(struct bt_le_oob *oob);
|
||||
|
||||
/** @brief BR/EDR discovery result structure */
|
||||
struct bt_br_discovery_result {
|
||||
/** private */
|
||||
u8_t _priv[4];
|
||||
|
||||
/** Remote device address */
|
||||
bt_addr_t addr;
|
||||
|
||||
/** RSSI from inquiry */
|
||||
s8_t rssi;
|
||||
|
||||
/** Class of Device */
|
||||
u8_t cod[3];
|
||||
|
||||
/** Extended Inquiry Response */
|
||||
u8_t eir[240];
|
||||
};
|
||||
|
||||
/** @typedef bt_br_discovery_cb_t
|
||||
* @brief Callback type for reporting BR/EDR discovery (inquiry)
|
||||
* results.
|
||||
*
|
||||
* A callback of this type is given to the bt_br_discovery_start()
|
||||
* function and will be called at the end of the discovery with
|
||||
* information about found devices populated in the results array.
|
||||
*
|
||||
* @param results Storage used for discovery results
|
||||
* @param count Number of valid discovery results.
|
||||
*/
|
||||
typedef void bt_br_discovery_cb_t(struct bt_br_discovery_result *results,
|
||||
size_t count);
|
||||
|
||||
/** BR/EDR discovery parameters */
|
||||
struct bt_br_discovery_param {
|
||||
/** Maximum length of the discovery in units of 1.28 seconds.
|
||||
* Valid range is 0x01 - 0x30.
|
||||
*/
|
||||
u8_t length;
|
||||
|
||||
/** True if limited discovery procedure is to be used. */
|
||||
bool limited;
|
||||
};
|
||||
|
||||
/** @brief Start BR/EDR discovery
|
||||
*
|
||||
* Start BR/EDR discovery (inquiry) and provide results through the specified
|
||||
* callback. When bt_br_discovery_cb_t is called it indicates that discovery
|
||||
* has completed. If more inquiry results were received during session than
|
||||
* fits in provided result storage, only ones with highest RSSI will be
|
||||
* reported.
|
||||
*
|
||||
* @param param Discovery parameters.
|
||||
* @param results Storage for discovery results.
|
||||
* @param count Number of results in storage. Valid range: 1-255.
|
||||
* @param cb Callback to notify discovery results.
|
||||
*
|
||||
* @return Zero on success or error code otherwise, positive in case
|
||||
* of protocol error or negative (POSIX) in case of stack internal error
|
||||
*/
|
||||
int bt_br_discovery_start(const struct bt_br_discovery_param *param,
|
||||
struct bt_br_discovery_result *results, size_t count,
|
||||
bt_br_discovery_cb_t cb);
|
||||
|
||||
/** @brief Stop BR/EDR discovery.
|
||||
*
|
||||
* Stops ongoing BR/EDR discovery. If discovery was stopped by this call
|
||||
* results won't be reported
|
||||
*
|
||||
* @return Zero on success or error code otherwise, positive in case
|
||||
* of protocol error or negative (POSIX) in case of stack internal error
|
||||
*/
|
||||
int bt_br_discovery_stop(void);
|
||||
|
||||
struct bt_br_oob {
|
||||
/** BR/EDR address. */
|
||||
bt_addr_t addr;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get BR/EDR local Out Of Band information
|
||||
*
|
||||
* This function allows to get local controller information that are useful
|
||||
* for Out Of Band pairing or connection creation process.
|
||||
*
|
||||
* @param oob Out Of Band information
|
||||
*/
|
||||
int bt_br_oob_get_local(struct bt_br_oob *oob);
|
||||
|
||||
/** @def BT_ADDR_STR_LEN
|
||||
*
|
||||
* @brief Recommended length of user string buffer for Bluetooth address
|
||||
*
|
||||
* @details The recommended length guarantee the output of address
|
||||
* conversion will not lose valuable information about address being
|
||||
* processed.
|
||||
*/
|
||||
#define BT_ADDR_STR_LEN 18
|
||||
|
||||
/** @def BT_ADDR_LE_STR_LEN
|
||||
*
|
||||
* @brief Recommended length of user string buffer for Bluetooth LE address
|
||||
*
|
||||
* @details The recommended length guarantee the output of address
|
||||
* conversion will not lose valuable information about address being
|
||||
* processed.
|
||||
*/
|
||||
#define BT_ADDR_LE_STR_LEN 27
|
||||
|
||||
/** @brief Converts binary Bluetooth address to string.
|
||||
*
|
||||
* @param addr Address of buffer containing binary Bluetooth address.
|
||||
* @param str Address of user buffer with enough room to store formatted
|
||||
* string containing binary address.
|
||||
* @param len Length of data to be copied to user string buffer. Refer to
|
||||
* BT_ADDR_STR_LEN about recommended value.
|
||||
*
|
||||
* @return Number of successfully formatted bytes from binary address.
|
||||
*/
|
||||
static inline int bt_addr_to_str(const bt_addr_t *addr, char *str, size_t len)
|
||||
{
|
||||
return snprintk(str, len, "%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
addr->val[5], addr->val[4], addr->val[3],
|
||||
addr->val[2], addr->val[1], addr->val[0]);
|
||||
}
|
||||
|
||||
/** @brief Converts binary LE Bluetooth address to string.
|
||||
*
|
||||
* @param addr Address of buffer containing binary LE Bluetooth address.
|
||||
* @param str Address of user buffer with enough room to store
|
||||
* formatted string containing binary LE address.
|
||||
* @param len Length of data to be copied to user string buffer. Refer to
|
||||
* BT_ADDR_LE_STR_LEN about recommended value.
|
||||
*
|
||||
* @return Number of successfully formatted bytes from binary address.
|
||||
*/
|
||||
static inline int bt_addr_le_to_str(const bt_addr_le_t *addr, char *str,
|
||||
size_t len)
|
||||
{
|
||||
char type[10];
|
||||
|
||||
switch (addr->type) {
|
||||
case BT_ADDR_LE_PUBLIC:
|
||||
strcpy(type, "public");
|
||||
break;
|
||||
case BT_ADDR_LE_RANDOM:
|
||||
strcpy(type, "random");
|
||||
break;
|
||||
case BT_ADDR_LE_PUBLIC_ID:
|
||||
strcpy(type, "public id");
|
||||
break;
|
||||
case BT_ADDR_LE_RANDOM_ID:
|
||||
strcpy(type, "random id");
|
||||
break;
|
||||
default:
|
||||
snprintk(type, sizeof(type), "0x%02x", addr->type);
|
||||
break;
|
||||
}
|
||||
|
||||
return snprintk(str, len, "%02X:%02X:%02X:%02X:%02X:%02X (%s)",
|
||||
addr->a.val[5], addr->a.val[4], addr->a.val[3],
|
||||
addr->a.val[2], addr->a.val[1], addr->a.val[0], type);
|
||||
}
|
||||
|
||||
/** @brief Enable/disable set controller in discoverable state.
|
||||
*
|
||||
* Allows make local controller to listen on INQUIRY SCAN channel and responds
|
||||
* to devices making general inquiry. To enable this state it's mandatory
|
||||
* to first be in connectable state.
|
||||
*
|
||||
* @param enable Value allowing/disallowing controller to become discoverable.
|
||||
*
|
||||
* @return Negative if fail set to requested state or requested state has been
|
||||
* already set. Zero if done successfully.
|
||||
*/
|
||||
int bt_br_set_discoverable(bool enable);
|
||||
|
||||
/** @brief Enable/disable set controller in connectable state.
|
||||
*
|
||||
* Allows make local controller to be connectable. It means the controller
|
||||
* start listen to devices requests on PAGE SCAN channel. If disabled also
|
||||
* resets discoverability if was set.
|
||||
*
|
||||
* @param enable Value allowing/disallowing controller to be connectable.
|
||||
*
|
||||
* @return Negative if fail set to requested state or requested state has been
|
||||
* already set. Zero if done successfully.
|
||||
*/
|
||||
int bt_br_set_connectable(bool enable);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_BLUETOOTH_H */
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/** @file
|
||||
* @brief Bluetooth data buffer API
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef __BT_BUF_H
|
||||
#define __BT_BUF_H
|
||||
|
||||
/**
|
||||
* @brief Data buffers
|
||||
* @defgroup bt_buf Data buffers
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <net/buf.h>
|
||||
#include <bluetooth/hci.h>
|
||||
|
||||
/** Possible types of buffers passed around the Bluetooth stack */
|
||||
enum bt_buf_type {
|
||||
/** HCI command */
|
||||
BT_BUF_CMD,
|
||||
/** HCI event */
|
||||
BT_BUF_EVT,
|
||||
/** Outgoing ACL data */
|
||||
BT_BUF_ACL_OUT,
|
||||
/** Incoming ACL data */
|
||||
BT_BUF_ACL_IN,
|
||||
};
|
||||
|
||||
/** Minimum amount of user data size for buffers passed to the stack. */
|
||||
#define BT_BUF_USER_DATA_MIN 4
|
||||
|
||||
/** Data size neeed for HCI RX buffers */
|
||||
#define BT_BUF_RX_SIZE (CONFIG_BT_HCI_RESERVE + CONFIG_BT_RX_BUF_LEN)
|
||||
|
||||
/** Allocate a buffer for incoming data
|
||||
*
|
||||
* This will set the buffer type so bt_buf_set_type() does not need to
|
||||
* be explicitly called before bt_recv_prio().
|
||||
*
|
||||
* @param type Type of buffer. Only BT_BUF_EVT and BT_BUF_ACL_IN are
|
||||
* allowed.
|
||||
* @param timeout Timeout in milliseconds, or one of the special values
|
||||
* K_NO_WAIT and K_FOREVER.
|
||||
* @return A new buffer.
|
||||
*/
|
||||
struct net_buf *bt_buf_get_rx(enum bt_buf_type type, s32_t timeout);
|
||||
|
||||
/** Allocate a buffer for an HCI Command Complete/Status Event
|
||||
*
|
||||
* This will set the buffer type so bt_buf_set_type() does not need to
|
||||
* be explicitly called before bt_recv_prio().
|
||||
*
|
||||
* @param timeout Timeout in milliseconds, or one of the special values
|
||||
* K_NO_WAIT and K_FOREVER.
|
||||
* @return A new buffer.
|
||||
*/
|
||||
struct net_buf *bt_buf_get_cmd_complete(s32_t timeout);
|
||||
|
||||
/** Set the buffer type
|
||||
*
|
||||
* @param buf Bluetooth buffer
|
||||
* @param type The BT_* type to set the buffer to
|
||||
*/
|
||||
static inline void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
|
||||
{
|
||||
*(u8_t *)net_buf_user_data(buf) = type;
|
||||
}
|
||||
|
||||
/** Get the buffer type
|
||||
*
|
||||
* @param buf Bluetooth buffer
|
||||
*
|
||||
* @return The BT_* type to of the buffer
|
||||
*/
|
||||
static inline enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
|
||||
{
|
||||
return *(u8_t *)net_buf_user_data(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_BUF_H */
|
||||
516
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/conn.h
Normal file
516
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/conn.h
Normal file
|
|
@ -0,0 +1,516 @@
|
|||
/** @file
|
||||
* @brief Bluetooth connection handling
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015-2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_CONN_H
|
||||
#define __BT_CONN_H
|
||||
|
||||
/**
|
||||
* @brief Connection management
|
||||
* @defgroup bt_conn Connection management
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
|
||||
/** Opaque type representing a connection to a remote device */
|
||||
struct bt_conn;
|
||||
|
||||
/** Connection parameters for LE connections */
|
||||
struct bt_le_conn_param {
|
||||
u16_t interval_min;
|
||||
u16_t interval_max;
|
||||
u16_t latency;
|
||||
u16_t timeout;
|
||||
};
|
||||
|
||||
/** Helper to declare connection parameters inline
|
||||
*
|
||||
* @param int_min Minimum Connection Interval (N * 1.25 ms)
|
||||
* @param int_max Maximum Connection Interval (N * 1.25 ms)
|
||||
* @param lat Connection Latency
|
||||
* @param to Supervision Timeout (N * 10 ms)
|
||||
*/
|
||||
#define BT_LE_CONN_PARAM(int_min, int_max, lat, to) \
|
||||
(&(struct bt_le_conn_param) { \
|
||||
.interval_min = (int_min), \
|
||||
.interval_max = (int_max), \
|
||||
.latency = (lat), \
|
||||
.timeout = (to), \
|
||||
})
|
||||
|
||||
/** Default LE connection parameters:
|
||||
* Connection Interval: 30-50 ms
|
||||
* Latency: 0
|
||||
* Timeout: 4 s
|
||||
*/
|
||||
#define BT_LE_CONN_PARAM_DEFAULT BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, \
|
||||
BT_GAP_INIT_CONN_INT_MAX, \
|
||||
0, 400)
|
||||
|
||||
/** @brief Increment a connection's reference count.
|
||||
*
|
||||
* Increment the reference count of a connection object.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*
|
||||
* @return Connection object with incremented reference count.
|
||||
*/
|
||||
struct bt_conn *bt_conn_ref(struct bt_conn *conn);
|
||||
|
||||
/** @brief Decrement a connection's reference count.
|
||||
*
|
||||
* Decrement the reference count of a connection object.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*/
|
||||
void bt_conn_unref(struct bt_conn *conn);
|
||||
|
||||
/** @brief Look up an existing connection by address.
|
||||
*
|
||||
* Look up an existing connection based on the remote address.
|
||||
*
|
||||
* @param peer Remote address.
|
||||
*
|
||||
* @return Connection object or NULL if not found. The caller gets a
|
||||
* new reference to the connection object which must be released with
|
||||
* bt_conn_unref() once done using the object.
|
||||
*/
|
||||
struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer);
|
||||
|
||||
/** @brief Get destination (peer) address of a connection.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*
|
||||
* @return Destination address.
|
||||
*/
|
||||
const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn);
|
||||
|
||||
/** Connection Type */
|
||||
enum {
|
||||
/** LE Connection Type */
|
||||
BT_CONN_TYPE_LE,
|
||||
/** BR/EDR Connection Type */
|
||||
BT_CONN_TYPE_BR,
|
||||
/** SCO Connection Type */
|
||||
BT_CONN_TYPE_SCO,
|
||||
};
|
||||
|
||||
/** LE Connection Info Structure */
|
||||
struct bt_conn_le_info {
|
||||
const bt_addr_le_t *src; /** Source Address */
|
||||
const bt_addr_le_t *dst; /** Destination Address */
|
||||
u16_t interval; /** Connection interval */
|
||||
u16_t latency; /** Connection slave latency */
|
||||
u16_t timeout; /** Connection supervision timeout */
|
||||
};
|
||||
|
||||
/** BR/EDR Connection Info Structure */
|
||||
struct bt_conn_br_info {
|
||||
const bt_addr_t *dst; /** Destination BR/EDR address */
|
||||
};
|
||||
|
||||
/** Connection role (master or slave) */
|
||||
enum {
|
||||
BT_CONN_ROLE_MASTER,
|
||||
BT_CONN_ROLE_SLAVE,
|
||||
};
|
||||
|
||||
/** @brief Connection Info Structure
|
||||
*
|
||||
*
|
||||
* @param type Connection Type
|
||||
* @param role Connection Role
|
||||
* @param le LE Connection specific Info
|
||||
* @param br BR/EDR Connection specific Info
|
||||
*/
|
||||
struct bt_conn_info {
|
||||
u8_t type;
|
||||
|
||||
u8_t role;
|
||||
|
||||
union {
|
||||
struct bt_conn_le_info le;
|
||||
|
||||
struct bt_conn_br_info br;
|
||||
};
|
||||
};
|
||||
|
||||
/** @brief Get connection info
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param info Connection info object.
|
||||
*
|
||||
* @return Zero on success or (negative) error code on failure.
|
||||
*/
|
||||
int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info);
|
||||
|
||||
/** @brief Update the connection parameters.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param param Updated connection parameters.
|
||||
*
|
||||
* @return Zero on success or (negative) error code on failure.
|
||||
*/
|
||||
int bt_conn_le_param_update(struct bt_conn *conn,
|
||||
const struct bt_le_conn_param *param);
|
||||
|
||||
/** @brief Disconnect from a remote device or cancel pending connection.
|
||||
*
|
||||
* Disconnect an active connection with the specified reason code or cancel
|
||||
* pending outgoing connection.
|
||||
*
|
||||
* @param conn Connection to disconnect.
|
||||
* @param reason Reason code for the disconnection.
|
||||
*
|
||||
* @return Zero on success or (negative) error code on failure.
|
||||
*/
|
||||
int bt_conn_disconnect(struct bt_conn *conn, u8_t reason);
|
||||
|
||||
/** @brief Initiate an LE connection to a remote device.
|
||||
*
|
||||
* Allows initiate new LE link to remote peer using its address.
|
||||
* Returns a new reference that the the caller is responsible for managing.
|
||||
*
|
||||
* @param peer Remote address.
|
||||
* @param param Initial connection parameters.
|
||||
*
|
||||
* @return Valid connection object on success or NULL otherwise.
|
||||
*/
|
||||
struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer,
|
||||
const struct bt_le_conn_param *param);
|
||||
|
||||
/** @brief Automatically connect to remote device if it's in range.
|
||||
*
|
||||
* This function enables/disables automatic connection initiation.
|
||||
* Every time the device loses the connection with peer, this connection
|
||||
* will be re-established if connectable advertisement from peer is received.
|
||||
*
|
||||
* @param addr Remote Bluetooth address.
|
||||
* @param param If non-NULL, auto connect is enabled with the given
|
||||
* parameters. If NULL, auto connect is disabled.
|
||||
*
|
||||
* @return Zero on success or error code otherwise.
|
||||
*/
|
||||
int bt_le_set_auto_conn(bt_addr_le_t *addr,
|
||||
const struct bt_le_conn_param *param);
|
||||
|
||||
/** @brief Initiate directed advertising to a remote device
|
||||
*
|
||||
* Allows initiating a new LE connection to remote peer with the remote
|
||||
* acting in central role and the local device in peripheral role.
|
||||
*
|
||||
* The advertising type must be either BT_LE_ADV_DIRECT_IND or
|
||||
* BT_LE_ADV_DIRECT_IND_LOW_DUTY.
|
||||
*
|
||||
* In case of high duty cycle this will result in a callback with
|
||||
* connected() with a new connection or with an error.
|
||||
*
|
||||
* The advertising may be canceled with bt_conn_disconnect().
|
||||
*
|
||||
* Returns a new reference that the the caller is responsible for managing.
|
||||
*
|
||||
* @param peer Remote address.
|
||||
* @param param Directed advertising parameters.
|
||||
*
|
||||
* @return Valid connection object on success or NULL otherwise.
|
||||
*/
|
||||
struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
|
||||
const struct bt_le_adv_param *param);
|
||||
|
||||
/** Security level. */
|
||||
typedef enum __packed {
|
||||
/** Only for BR/EDR special cases, like SDP */
|
||||
BT_SECURITY_NONE,
|
||||
/** No encryption and no authentication. */
|
||||
BT_SECURITY_LOW,
|
||||
/** Encryption and no authentication (no MITM). */
|
||||
BT_SECURITY_MEDIUM,
|
||||
/** Encryption and authentication (MITM). */
|
||||
BT_SECURITY_HIGH,
|
||||
/** Authenticated Secure Connections */
|
||||
BT_SECURITY_FIPS,
|
||||
} bt_security_t;
|
||||
|
||||
/** @brief Set security level for a connection.
|
||||
*
|
||||
* This function enable security (encryption) for a connection. If device is
|
||||
* already paired with sufficiently strong key encryption will be enabled. If
|
||||
* link is already encrypted with sufficiently strong key this function does
|
||||
* nothing.
|
||||
*
|
||||
* If device is not paired pairing will be initiated. If device is paired and
|
||||
* keys are too weak but input output capabilities allow for strong enough keys
|
||||
* pairing will be initiated.
|
||||
*
|
||||
* This function may return error if required level of security is not possible
|
||||
* to achieve due to local or remote device limitation (e.g., input output
|
||||
* capabilities).
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param sec Requested security level.
|
||||
*
|
||||
* @return 0 on success or negative error
|
||||
*/
|
||||
int bt_conn_security(struct bt_conn *conn, bt_security_t sec);
|
||||
|
||||
/** @brief Get encryption key size.
|
||||
*
|
||||
* This function gets encryption key size.
|
||||
* If there is no security (encryption) enabled 0 will be returned.
|
||||
*
|
||||
* @param conn Existing connection object.
|
||||
*
|
||||
* @return Encryption key size.
|
||||
*/
|
||||
u8_t bt_conn_enc_key_size(struct bt_conn *conn);
|
||||
|
||||
/** @brief Connection callback structure.
|
||||
*
|
||||
* This structure is used for tracking the state of a connection.
|
||||
* It is registered with the help of the bt_conn_cb_register() API.
|
||||
* It's permissible to register multiple instances of this @ref bt_conn_cb
|
||||
* type, in case different modules of an application are interested in
|
||||
* tracking the connection state. If a callback is not of interest for
|
||||
* an instance, it may be set to NULL and will as a consequence not be
|
||||
* used for that instance.
|
||||
*/
|
||||
struct bt_conn_cb {
|
||||
/** @brief A new connection has been established.
|
||||
*
|
||||
* This callback notifies the application of a new connection.
|
||||
* In case the err parameter is non-zero it means that the
|
||||
* connection establishment failed.
|
||||
*
|
||||
* @param conn New connection object.
|
||||
* @param err HCI error. Zero for success, non-zero otherwise.
|
||||
*/
|
||||
void (*connected)(struct bt_conn *conn, u8_t err);
|
||||
|
||||
/** @brief A connection has been disconnected.
|
||||
*
|
||||
* This callback notifies the application that a connection
|
||||
* has been disconnected.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param reason HCI reason for the disconnection.
|
||||
*/
|
||||
void (*disconnected)(struct bt_conn *conn, u8_t reason);
|
||||
|
||||
/** @brief LE connection parameter update request.
|
||||
*
|
||||
* This callback notifies the application that a remote device
|
||||
* is requesting to update the connection parameters. The
|
||||
* application accepts the parameters by returning true, or
|
||||
* rejects them by returning false. Before accepting, the
|
||||
* application may also adjust the parameters to better suit
|
||||
* its needs.
|
||||
*
|
||||
* It is recommended for an application to have just one of these
|
||||
* callbacks for simplicity. However, if an application registers
|
||||
* multiple it needs to manage the potentially different
|
||||
* requirements for each callback. Each callback gets the
|
||||
* parameters as returned by previous callbacks, i.e. they are not
|
||||
* necessarily the same ones as the remote originally sent.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param param Proposed connection parameters.
|
||||
*
|
||||
* @return true to accept the parameters, or false to reject them.
|
||||
*/
|
||||
bool (*le_param_req)(struct bt_conn *conn,
|
||||
struct bt_le_conn_param *param);
|
||||
|
||||
/** @brief The parameters for an LE connection have been updated.
|
||||
*
|
||||
* This callback notifies the application that the connection
|
||||
* parameters for an LE connection have been updated.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param interval Connection interval.
|
||||
* @param latency Connection latency.
|
||||
* @param timeout Connection supervision timeout.
|
||||
*/
|
||||
void (*le_param_updated)(struct bt_conn *conn, u16_t interval,
|
||||
u16_t latency, u16_t timeout);
|
||||
#if defined(CONFIG_BT_SMP)
|
||||
/** @brief Remote Identity Address has been resolved.
|
||||
*
|
||||
* This callback notifies the application that a remote
|
||||
* Identity Address has been resolved
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param rpa Resolvable Private Address.
|
||||
* @param identity Identity Address.
|
||||
*/
|
||||
void (*identity_resolved)(struct bt_conn *conn,
|
||||
const bt_addr_le_t *rpa,
|
||||
const bt_addr_le_t *identity);
|
||||
#endif /* CONFIG_BT_SMP */
|
||||
#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)
|
||||
/** @brief The security level of a connection has changed.
|
||||
*
|
||||
* This callback notifies the application that the security level
|
||||
* of a connection has changed.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param level New security level of the connection.
|
||||
*/
|
||||
void (*security_changed)(struct bt_conn *conn, bt_security_t level);
|
||||
#endif /* defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) */
|
||||
struct bt_conn_cb *_next;
|
||||
};
|
||||
|
||||
/** @brief Register connection callbacks.
|
||||
*
|
||||
* Register callbacks to monitor the state of connections.
|
||||
*
|
||||
* @param cb Callback struct.
|
||||
*/
|
||||
void bt_conn_cb_register(struct bt_conn_cb *cb);
|
||||
|
||||
/** Authenticated pairing callback structure */
|
||||
struct bt_conn_auth_cb {
|
||||
void (*passkey_display)(struct bt_conn *conn, unsigned int passkey);
|
||||
void (*passkey_entry)(struct bt_conn *conn);
|
||||
void (*passkey_confirm)(struct bt_conn *conn, unsigned int passkey);
|
||||
void (*cancel)(struct bt_conn *conn);
|
||||
void (*pairing_confirm)(struct bt_conn *conn);
|
||||
#if defined(CONFIG_BT_BREDR)
|
||||
void (*pincode_entry)(struct bt_conn *conn, bool highsec);
|
||||
#endif
|
||||
};
|
||||
|
||||
/** @brief Register authentication callbacks.
|
||||
*
|
||||
* Register callbacks to handle authenticated pairing. Passing NULL unregisters
|
||||
* previous callbacks structure.
|
||||
*
|
||||
* @param cb Callback struct.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int bt_conn_auth_cb_register(const struct bt_conn_auth_cb *cb);
|
||||
|
||||
/** @brief Reply with entered passkey.
|
||||
*
|
||||
* This function should be called only after passkey_entry callback from
|
||||
* bt_conn_auth_cb structure was called.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param passkey Entered passkey.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
|
||||
|
||||
/** @brief Cancel ongoing authenticated pairing.
|
||||
*
|
||||
* This function allows to cancel ongoing authenticated pairing.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int bt_conn_auth_cancel(struct bt_conn *conn);
|
||||
|
||||
/** @brief Reply if passkey was confirmed to match by user.
|
||||
*
|
||||
* This function should be called only after passkey_confirm callback from
|
||||
* bt_conn_auth_cb structure was called.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int bt_conn_auth_passkey_confirm(struct bt_conn *conn);
|
||||
|
||||
/** @brief Reply if incoming pairing was confirmed by user.
|
||||
*
|
||||
* This function should be called only after pairing_confirm callback from
|
||||
* bt_conn_auth_cb structure was called if user confirmed incoming pairing.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int bt_conn_auth_pairing_confirm(struct bt_conn *conn);
|
||||
|
||||
/** @brief Reply with entered PIN code.
|
||||
*
|
||||
* This function should be called only after PIN code callback from
|
||||
* bt_conn_auth_cb structure was called. It's for legacy 2.0 devices.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param pin Entered PIN code.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int bt_conn_auth_pincode_entry(struct bt_conn *conn, const char *pin);
|
||||
|
||||
/** Connection parameters for BR/EDR connections */
|
||||
struct bt_br_conn_param {
|
||||
bool allow_role_switch;
|
||||
};
|
||||
|
||||
/** Helper to declare BR/EDR connection parameters inline
|
||||
*
|
||||
* @param role_switch True if role switch is allowed
|
||||
*/
|
||||
#define BT_BR_CONN_PARAM(role_switch) \
|
||||
(&(struct bt_br_conn_param) { \
|
||||
.allow_role_switch = (role_switch), \
|
||||
})
|
||||
|
||||
/** Default BR/EDR connection parameters:
|
||||
* Role switch allowed
|
||||
*/
|
||||
#define BT_BR_CONN_PARAM_DEFAULT BT_BR_CONN_PARAM(true)
|
||||
|
||||
|
||||
/** @brief Initiate an BR/EDR connection to a remote device.
|
||||
*
|
||||
* Allows initiate new BR/EDR link to remote peer using its address.
|
||||
* Returns a new reference that the the caller is responsible for managing.
|
||||
*
|
||||
* @param peer Remote address.
|
||||
* @param param Initial connection parameters.
|
||||
*
|
||||
* @return Valid connection object on success or NULL otherwise.
|
||||
*/
|
||||
struct bt_conn *bt_conn_create_br(const bt_addr_t *peer,
|
||||
const struct bt_br_conn_param *param);
|
||||
|
||||
/** @brief Initiate an SCO connection to a remote device.
|
||||
*
|
||||
* Allows initiate new SCO link to remote peer using its address.
|
||||
* Returns a new reference that the the caller is responsible for managing.
|
||||
*
|
||||
* @param peer Remote address.
|
||||
*
|
||||
* @return Valid connection object on success or NULL otherwise.
|
||||
*/
|
||||
struct bt_conn *bt_conn_create_sco(const bt_addr_t *peer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_CONN_H */
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/** @file
|
||||
* @brief Bluetooth subsystem crypto APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2015-2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_CRYPTO_H
|
||||
#define __BT_CRYPTO_H
|
||||
|
||||
/**
|
||||
* @brief Cryptography
|
||||
* @defgroup bt_crypto Cryptography
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Generate random data.
|
||||
*
|
||||
* A random number generation helper which utilizes the Bluetooth
|
||||
* controller's own RNG.
|
||||
*
|
||||
* @param buf Buffer to insert the random data
|
||||
* @param len Length of random data to generate
|
||||
*
|
||||
* @return Zero on success or error code otherwise, positive in case
|
||||
* of protocol error or negative (POSIX) in case of stack internal error
|
||||
*/
|
||||
int bt_rand(void *buf, size_t len);
|
||||
|
||||
/** @brief AES encrypt little-endian data.
|
||||
*
|
||||
* An AES encrypt helper is used to request the Bluetooth controller's own
|
||||
* hardware to encrypt the plaintext using the key and returns the encrypted
|
||||
* data.
|
||||
*
|
||||
* @param key 128 bit LS byte first key for the encryption of the plaintext
|
||||
* @param plaintext 128 bit LS byte first plaintext data block to be encrypted
|
||||
* @param enc_data 128 bit LS byte first encrypted data block
|
||||
*
|
||||
* @return Zero on success or error code otherwise.
|
||||
*/
|
||||
int bt_encrypt_le(const u8_t key[16], const u8_t plaintext[16],
|
||||
u8_t enc_data[16]);
|
||||
|
||||
/** @brief AES encrypt big-endian data.
|
||||
*
|
||||
* An AES encrypt helper is used to request the Bluetooth controller's own
|
||||
* hardware to encrypt the plaintext using the key and returns the encrypted
|
||||
* data.
|
||||
*
|
||||
* @param key 128 bit MS byte first key for the encryption of the plaintext
|
||||
* @param plaintext 128 bit MS byte first plaintext data block to be encrypted
|
||||
* @param enc_data 128 bit MS byte first encrypted data block
|
||||
*
|
||||
* @return Zero on success or error code otherwise.
|
||||
*/
|
||||
int bt_encrypt_be(const u8_t key[16], const u8_t plaintext[16],
|
||||
u8_t enc_data[16]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_CRYPTO_H */
|
||||
1074
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/gatt.h
Normal file
1074
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/gatt.h
Normal file
File diff suppressed because it is too large
Load diff
1821
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/hci.h
Normal file
1821
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/hci.h
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,54 @@
|
|||
/** @file
|
||||
* @brief Bluetooth HCI RAW channel handling
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_HCI_RAW_H
|
||||
#define __BT_HCI_RAW_H
|
||||
|
||||
/**
|
||||
* @brief HCI RAW channel
|
||||
* @defgroup hci_raw HCI RAW channel
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Send packet to the Bluetooth controller
|
||||
*
|
||||
* Send packet to the Bluetooth controller. Caller needs to
|
||||
* implement netbuf pool.
|
||||
*
|
||||
* @param buf netbuf packet to be send
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_send(struct net_buf *buf);
|
||||
|
||||
/** @brief Enable Bluetooth RAW channel
|
||||
*
|
||||
* Enable Bluetooth RAW HCI channel.
|
||||
*
|
||||
* @param rx_queue netbuf queue where HCI packets received from the Bluetooth
|
||||
* controller are to be queued. The queue is defined in the caller while
|
||||
* the available buffers pools are handled in the stack.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_enable_raw(struct k_fifo *rx_queue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_HCI_RAW_H */
|
||||
170
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/hci_vs.h
Normal file
170
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/hci_vs.h
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/* hci_vs.h - Bluetooth Host Control Interface Vendor Specific definitions */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015-2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_HCI_VS_H
|
||||
#define __BT_HCI_VS_H
|
||||
|
||||
#include <bluetooth/hci.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BT_HCI_VS_HW_PLAT_INTEL 0x0001
|
||||
#define BT_HCI_VS_HW_PLAT_NORDIC 0x0002
|
||||
#define BT_HCI_VS_HW_PLAT_NXP 0x0003
|
||||
|
||||
#define BT_HCI_VS_HW_VAR_NORDIC_NRF51X 0x0001
|
||||
#define BT_HCI_VS_HW_VAR_NORDIC_NRF52X 0x0002
|
||||
|
||||
#define BT_HCI_VS_FW_VAR_STANDARD_CTLR 0x0001
|
||||
#define BT_HCI_VS_FW_VAR_VS_CTLR 0x0002
|
||||
#define BT_HCI_VS_FW_VAR_FW_LOADER 0x0003
|
||||
#define BT_HCI_VS_FW_VAR_RESCUE_IMG 0x0004
|
||||
#define BT_HCI_OP_VS_READ_VERSION_INFO BT_OP(BT_OGF_VS, 0x0001)
|
||||
struct bt_hci_rp_vs_read_version_info {
|
||||
u8_t status;
|
||||
u16_t hw_platform;
|
||||
u16_t hw_variant;
|
||||
u8_t fw_variant;
|
||||
u8_t fw_version;
|
||||
u16_t fw_revision;
|
||||
u32_t fw_build;
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_OP_VS_READ_SUPPORTED_COMMANDS BT_OP(BT_OGF_VS, 0x0002)
|
||||
struct bt_hci_rp_vs_read_supported_commands {
|
||||
u8_t status;
|
||||
u8_t commands[64];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_OP_VS_READ_SUPPORTED_FEATURES BT_OP(BT_OGF_VS, 0x0003)
|
||||
struct bt_hci_rp_vs_read_supported_features {
|
||||
u8_t status;
|
||||
u8_t features[8];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_OP_VS_SET_EVENT_MASK BT_OP(BT_OGF_VS, 0x0004)
|
||||
struct bt_hci_cp_vs_set_event_mask {
|
||||
u8_t event_mask[8];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_VS_RESET_SOFT 0x00
|
||||
#define BT_HCI_VS_RESET_HARD 0x01
|
||||
#define BT_HCI_OP_VS_RESET BT_OP(BT_OGF_VS, 0x0005)
|
||||
struct bt_hci_cp_vs_reset {
|
||||
u8_t type;
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_OP_VS_WRITE_BD_ADDR BT_OP(BT_OGF_VS, 0x0006)
|
||||
struct bt_hci_cp_vs_write_bd_addr {
|
||||
bt_addr_t bdaddr;
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_VS_TRACE_DISABLED 0x00
|
||||
#define BT_HCI_VS_TRACE_ENABLED 0x01
|
||||
|
||||
#define BT_HCI_VS_TRACE_HCI_EVTS 0x00
|
||||
#define BT_HCI_VS_TRACE_VDC 0x01
|
||||
#define BT_HCI_OP_VS_SET_TRACE_ENABLE BT_OP(BT_OGF_VS, 0x0007)
|
||||
struct bt_hci_cp_vs_set_trace_enable {
|
||||
u8_t enable;
|
||||
u8_t type;
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_OP_VS_READ_BUILD_INFO BT_OP(BT_OGF_VS, 0x0008)
|
||||
struct bt_hci_rp_vs_read_build_info {
|
||||
u8_t status;
|
||||
u8_t info[0];
|
||||
} __packed;
|
||||
|
||||
struct bt_hci_vs_static_addr {
|
||||
bt_addr_t bdaddr;
|
||||
u8_t ir[16];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_OP_VS_READ_STATIC_ADDRS BT_OP(BT_OGF_VS, 0x0009)
|
||||
struct bt_hci_rp_vs_read_static_addrs {
|
||||
u8_t status;
|
||||
u8_t num_addrs;
|
||||
struct bt_hci_vs_static_addr a[0];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_OP_VS_READ_KEY_HIERARCHY_ROOTS BT_OP(BT_OGF_VS, 0x000a)
|
||||
struct bt_hci_rp_vs_read_key_hierarchy_roots {
|
||||
u8_t status;
|
||||
u8_t ir[16];
|
||||
u8_t er[16];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_OP_VS_READ_CHIP_TEMP BT_OP(BT_OGF_VS, 0x000b)
|
||||
struct bt_hci_rp_vs_read_chip_temp {
|
||||
u8_t status;
|
||||
s8_t temps;
|
||||
} __packed;
|
||||
|
||||
struct bt_hci_vs_cmd {
|
||||
u16_t vendor_id;
|
||||
u16_t opcode_base;
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_VS_VID_ANDROID 0x0001
|
||||
#define BT_HCI_VS_VID_MICROSOFT 0x0002
|
||||
#define BT_HCI_OP_VS_READ_HOST_STACK_CMDS BT_OP(BT_OGF_VS, 0x000c)
|
||||
struct bt_hci_rp_vs_read_host_stack_cmds {
|
||||
u8_t status;
|
||||
u8_t num_cmds;
|
||||
struct bt_hci_vs_cmd c[0];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_VS_SCAN_REQ_REPORTS_DISABLED 0x00
|
||||
#define BT_HCI_VS_SCAN_REQ_REPORTS_ENABLED 0x01
|
||||
#define BT_HCI_OP_VS_SET_SCAN_REQ_REPORTS BT_OP(BT_OGF_VS, 0x000d)
|
||||
struct bt_hci_cp_vs_set_scan_req_reports {
|
||||
u8_t enable;
|
||||
} __packed;
|
||||
|
||||
/* Events */
|
||||
|
||||
struct bt_hci_evt_vs {
|
||||
u8_t subevent;
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_EVT_VS_FATAL_ERROR 0x02
|
||||
struct bt_hci_evt_vs_fatal_error {
|
||||
u64_t pc;
|
||||
u8_t err_info[0];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_VS_TRACE_LMP_TX 0x01
|
||||
#define BT_HCI_VS_TRACE_LMP_RX 0x02
|
||||
#define BT_HCI_VS_TRACE_LLCP_TX 0x03
|
||||
#define BT_HCI_VS_TRACE_LLCP_RX 0x04
|
||||
#define BT_HCI_VS_TRACE_LE_CONN_IND 0x05
|
||||
#define BT_HCI_EVT_VS_TRACE_INFO 0x03
|
||||
struct bt_hci_evt_vs_trace_info {
|
||||
u8_t type;
|
||||
u8_t data[0];
|
||||
} __packed;
|
||||
|
||||
#define BT_HCI_EVT_VS_SCAN_REQ_RX 0x04
|
||||
struct bt_hci_evt_vs_scan_req_rx {
|
||||
bt_addr_le_t addr;
|
||||
s8_t rssi;
|
||||
} __packed;
|
||||
|
||||
/* Event mask bits */
|
||||
|
||||
#define BT_EVT_MASK_VS_FATAL_ERROR BT_EVT_BIT(1)
|
||||
#define BT_EVT_MASK_VS_TRACE_INFO BT_EVT_BIT(2)
|
||||
#define BT_EVT_MASK_VS_SCAN_REQ_RX BT_EVT_BIT(3)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __BT_HCI_VS_H */
|
||||
315
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/l2cap.h
Normal file
315
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/l2cap.h
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
/** @file
|
||||
* @brief Bluetooth L2CAP handling
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015-2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_L2CAP_H
|
||||
#define __BT_L2CAP_H
|
||||
|
||||
/**
|
||||
* @brief L2CAP
|
||||
* @defgroup bt_l2cap L2CAP
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <atomic.h>
|
||||
#include <bluetooth/buf.h>
|
||||
#include <bluetooth/conn.h>
|
||||
#include <bluetooth/hci.h>
|
||||
|
||||
/* L2CAP header size, used for buffer size calculations */
|
||||
#define BT_L2CAP_HDR_SIZE 4
|
||||
|
||||
/** @def BT_L2CAP_BUF_SIZE
|
||||
*
|
||||
* Helper to calculate needed outgoing buffer size, useful e.g. for
|
||||
* creating buffer pools.
|
||||
*
|
||||
* @param mtu Needed L2CAP MTU.
|
||||
*
|
||||
* @return Needed buffer size to match the requested L2CAP MTU.
|
||||
*/
|
||||
#define BT_L2CAP_BUF_SIZE(mtu) (CONFIG_BT_HCI_RESERVE + \
|
||||
BT_HCI_ACL_HDR_SIZE + BT_L2CAP_HDR_SIZE + \
|
||||
(mtu))
|
||||
|
||||
struct bt_l2cap_chan;
|
||||
|
||||
/** @typedef bt_l2cap_chan_destroy_t
|
||||
* @brief Channel destroy callback
|
||||
*
|
||||
* @param chan Channel object.
|
||||
*/
|
||||
typedef void (*bt_l2cap_chan_destroy_t)(struct bt_l2cap_chan *chan);
|
||||
|
||||
/** @brief Life-span states of L2CAP CoC channel. Used only by internal APIs
|
||||
* dealing with setting channel to proper state depending on operational
|
||||
* context.
|
||||
*/
|
||||
typedef enum bt_l2cap_chan_state {
|
||||
/** Channel disconnected */
|
||||
BT_L2CAP_DISCONNECTED,
|
||||
/** Channel in connecting state */
|
||||
BT_L2CAP_CONNECT,
|
||||
/** Channel in config state, BR/EDR specific */
|
||||
BT_L2CAP_CONFIG,
|
||||
/** Channel ready for upper layer traffic on it */
|
||||
BT_L2CAP_CONNECTED,
|
||||
/** Channel in disconnecting state */
|
||||
BT_L2CAP_DISCONNECT,
|
||||
} __packed bt_l2cap_chan_state_t;
|
||||
|
||||
/** @brief L2CAP Channel structure. */
|
||||
struct bt_l2cap_chan {
|
||||
/** Channel connection reference */
|
||||
struct bt_conn *conn;
|
||||
/** Channel operations reference */
|
||||
struct bt_l2cap_chan_ops *ops;
|
||||
sys_snode_t node;
|
||||
bt_l2cap_chan_destroy_t destroy;
|
||||
/* Response Timeout eXpired (RTX) timer */
|
||||
struct k_delayed_work rtx_work;
|
||||
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
|
||||
bt_l2cap_chan_state_t state;
|
||||
/** Remote PSM to be connected */
|
||||
u16_t psm;
|
||||
/** Helps match request context during CoC */
|
||||
u8_t ident;
|
||||
bt_security_t required_sec_level;
|
||||
#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
|
||||
};
|
||||
|
||||
/** @brief LE L2CAP Endpoint structure. */
|
||||
struct bt_l2cap_le_endpoint {
|
||||
/** Endpoint CID */
|
||||
u16_t cid;
|
||||
/** Endpoint Maximum Transmission Unit */
|
||||
u16_t mtu;
|
||||
/** Endpoint Maximum PDU payload Size */
|
||||
u16_t mps;
|
||||
/** Endpoint initial credits */
|
||||
u16_t init_credits;
|
||||
/** Endpoint credits */
|
||||
struct k_sem credits;
|
||||
};
|
||||
|
||||
/** @brief LE L2CAP Channel structure. */
|
||||
struct bt_l2cap_le_chan {
|
||||
/** Common L2CAP channel reference object */
|
||||
struct bt_l2cap_chan chan;
|
||||
/** Channel Receiving Endpoint */
|
||||
struct bt_l2cap_le_endpoint rx;
|
||||
/** Channel Transmission Endpoint */
|
||||
struct bt_l2cap_le_endpoint tx;
|
||||
/** Channel Transmission queue */
|
||||
struct k_fifo tx_queue;
|
||||
/** Channel Pending Transmission buffer */
|
||||
struct net_buf *tx_buf;
|
||||
/** Segment SDU packet from upper layer */
|
||||
struct net_buf *_sdu;
|
||||
u16_t _sdu_len;
|
||||
};
|
||||
|
||||
/** @def BT_L2CAP_LE_CHAN(_ch)
|
||||
* @brief Helper macro getting container object of type bt_l2cap_le_chan
|
||||
* address having the same container chan member address as object in question.
|
||||
*
|
||||
* @param _ch Address of object of bt_l2cap_chan type
|
||||
*
|
||||
* @return Address of in memory bt_l2cap_le_chan object type containing
|
||||
* the address of in question object.
|
||||
*/
|
||||
#define BT_L2CAP_LE_CHAN(_ch) CONTAINER_OF(_ch, struct bt_l2cap_le_chan, chan)
|
||||
|
||||
/** @brief BREDR L2CAP Endpoint structure. */
|
||||
struct bt_l2cap_br_endpoint {
|
||||
/** Endpoint CID */
|
||||
u16_t cid;
|
||||
/** Endpoint Maximum Transmission Unit */
|
||||
u16_t mtu;
|
||||
};
|
||||
|
||||
/** @brief BREDR L2CAP Channel structure. */
|
||||
struct bt_l2cap_br_chan {
|
||||
/** Common L2CAP channel reference object */
|
||||
struct bt_l2cap_chan chan;
|
||||
/** Channel Receiving Endpoint */
|
||||
struct bt_l2cap_br_endpoint rx;
|
||||
/** Channel Transmission Endpoint */
|
||||
struct bt_l2cap_br_endpoint tx;
|
||||
/* For internal use only */
|
||||
atomic_t flags[1];
|
||||
};
|
||||
|
||||
/** @brief L2CAP Channel operations structure. */
|
||||
struct bt_l2cap_chan_ops {
|
||||
/** Channel connected callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* connection completes.
|
||||
*
|
||||
* @param chan The channel that has been connected
|
||||
*/
|
||||
void (*connected)(struct bt_l2cap_chan *chan);
|
||||
|
||||
/** Channel disconnected callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* channel is disconnected, including when a connection gets
|
||||
* rejected.
|
||||
*
|
||||
* @param chan The channel that has been Disconnected
|
||||
*/
|
||||
void (*disconnected)(struct bt_l2cap_chan *chan);
|
||||
|
||||
/** Channel encrypt_change callback
|
||||
*
|
||||
* If this callback is provided it will be called whenever the
|
||||
* security level changed (indirectly link encryption done) or
|
||||
* authentication procedure fails. In both cases security initiator
|
||||
* and responder got the final status (HCI status) passed by
|
||||
* related to encryption and authentication events from local host's
|
||||
* controller.
|
||||
*
|
||||
* @param chan The channel which has made encryption status changed.
|
||||
* @param status HCI status of performed security procedure caused
|
||||
* by channel security requirements. The value is populated
|
||||
* by HCI layer and set to 0 when success and to non-zero (reference to
|
||||
* HCI Error Codes) when security/authentication failed.
|
||||
*/
|
||||
void (*encrypt_change)(struct bt_l2cap_chan *chan, u8_t hci_status);
|
||||
|
||||
/** Channel alloc_buf callback
|
||||
*
|
||||
* If this callback is provided the channel will use it to allocate
|
||||
* buffers to store incoming data.
|
||||
*
|
||||
* @param chan The channel requesting a buffer.
|
||||
*
|
||||
* @return Allocated buffer.
|
||||
*/
|
||||
struct net_buf *(*alloc_buf)(struct bt_l2cap_chan *chan);
|
||||
|
||||
/** Channel recv callback
|
||||
*
|
||||
* @param chan The channel receiving data.
|
||||
* @param buf Buffer containing incoming data.
|
||||
*/
|
||||
void (*recv)(struct bt_l2cap_chan *chan, struct net_buf *buf);
|
||||
};
|
||||
|
||||
/** @def BT_L2CAP_CHAN_SEND_RESERVE
|
||||
* @brief Headroom needed for outgoing buffers
|
||||
*/
|
||||
#define BT_L2CAP_CHAN_SEND_RESERVE (CONFIG_BT_HCI_RESERVE + 4 + 4)
|
||||
|
||||
/** @brief L2CAP Server structure. */
|
||||
struct bt_l2cap_server {
|
||||
/** Server PSM */
|
||||
u16_t psm;
|
||||
|
||||
/** Required minimim security level */
|
||||
bt_security_t sec_level;
|
||||
|
||||
/** Server accept callback
|
||||
*
|
||||
* This callback is called whenever a new incoming connection requires
|
||||
* authorization.
|
||||
*
|
||||
* @param conn The connection that is requesting authorization
|
||||
* @param chan Pointer to received the allocated channel
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int (*accept)(struct bt_conn *conn, struct bt_l2cap_chan **chan);
|
||||
|
||||
sys_snode_t node;
|
||||
};
|
||||
|
||||
/** @brief Register L2CAP server.
|
||||
*
|
||||
* Register L2CAP server for a PSM, each new connection is authorized using
|
||||
* the accept() callback which in case of success shall allocate the channel
|
||||
* structure to be used by the new connection.
|
||||
*
|
||||
* @param server Server structure.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int bt_l2cap_server_register(struct bt_l2cap_server *server);
|
||||
|
||||
/** @brief Register L2CAP server on BR/EDR oriented connection.
|
||||
*
|
||||
* Register L2CAP server for a PSM, each new connection is authorized using
|
||||
* the accept() callback which in case of success shall allocate the channel
|
||||
* structure to be used by the new connection.
|
||||
*
|
||||
* @param server Server structure.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int bt_l2cap_br_server_register(struct bt_l2cap_server *server);
|
||||
|
||||
/** @brief Connect L2CAP channel
|
||||
*
|
||||
* Connect L2CAP channel by PSM, once the connection is completed channel
|
||||
* connected() callback will be called. If the connection is rejected
|
||||
* disconnected() callback is called instead.
|
||||
* Channel object passed (over an address of it) as second parameter shouldn't
|
||||
* be instantiated in application as standalone. Instead of, application should
|
||||
* create transport dedicated L2CAP objects, i.e. type of bt_l2cap_le_chan for
|
||||
* LE and/or type of bt_l2cap_br_chan for BR/EDR. Then pass to this API
|
||||
* the location (address) of bt_l2cap_chan type object which is a member
|
||||
* of both transport dedicated objects.
|
||||
*
|
||||
* @param conn Connection object.
|
||||
* @param chan Channel object.
|
||||
* @param psm Channel PSM to connect to.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int bt_l2cap_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
|
||||
u16_t psm);
|
||||
|
||||
/** @brief Disconnect L2CAP channel
|
||||
*
|
||||
* Disconnect L2CAP channel, if the connection is pending it will be
|
||||
* canceled and as a result the channel disconnected() callback is called.
|
||||
* Regarding to input parameter, to get details see reference description
|
||||
* to bt_l2cap_chan_connect() API above.
|
||||
*
|
||||
* @param chan Channel object.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int bt_l2cap_chan_disconnect(struct bt_l2cap_chan *chan);
|
||||
|
||||
/** @brief Send data to L2CAP channel
|
||||
*
|
||||
* Send data from buffer to the channel. If credits are not available, buf will
|
||||
* be queued and sent as and when credits are received from peer.
|
||||
* Regarding to first input parameter, to get details see reference description
|
||||
* to bt_l2cap_chan_connect() API above.
|
||||
*
|
||||
* @return Bytes sent in case of success or negative value in case of error.
|
||||
*/
|
||||
int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_L2CAP_H */
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh Profile APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_MESH_H
|
||||
#define __BT_MESH_H
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
#include <net/buf.h>
|
||||
|
||||
#include <bluetooth/mesh/access.h>
|
||||
#include <bluetooth/mesh/main.h>
|
||||
#include <bluetooth/mesh/cfg_srv.h>
|
||||
#include <bluetooth/mesh/health_srv.h>
|
||||
|
||||
#if defined(CONFIG_BT_MESH_CFG_CLI)
|
||||
#include <bluetooth/mesh/cfg_cli.h>
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_MESH_HEALTH_CLI)
|
||||
#include <bluetooth/mesh/health_cli.h>
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_MESH_GATT_PROXY)
|
||||
#include <bluetooth/mesh/proxy.h>
|
||||
#endif
|
||||
|
||||
#endif /* __BT_MESH_H */
|
||||
|
|
@ -0,0 +1,401 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh Access Layer APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_MESH_ACCESS_H
|
||||
#define __BT_MESH_ACCESS_H
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Access Layer
|
||||
* @defgroup bt_mesh_access Bluetooth Mesh Access Layer
|
||||
* @ingroup bt_mesh
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define BT_MESH_ADDR_UNASSIGNED 0x0000
|
||||
#define BT_MESH_ADDR_ALL_NODES 0xffff
|
||||
#define BT_MESH_ADDR_PROXIES 0xfffc
|
||||
#define BT_MESH_ADDR_FRIENDS 0xfffd
|
||||
#define BT_MESH_ADDR_RELAYS 0xfffe
|
||||
|
||||
#define BT_MESH_KEY_UNUSED 0xffff
|
||||
#define BT_MESH_KEY_DEV 0xfffe
|
||||
|
||||
/** Helper to define a mesh element within an array.
|
||||
*
|
||||
* In case the element has no SIG or Vendor models the helper
|
||||
* macro BT_MESH_MODEL_NONE can be given instead.
|
||||
*
|
||||
* @param _loc Location Descriptor.
|
||||
* @param _mods Array of models.
|
||||
* @param _vnd_mods Array of vendor models.
|
||||
*/
|
||||
#define BT_MESH_ELEM(_loc, _mods, _vnd_mods) \
|
||||
{ \
|
||||
.loc = (_loc), \
|
||||
.model_count = ARRAY_SIZE(_mods), \
|
||||
.models = (_mods), \
|
||||
.vnd_model_count = ARRAY_SIZE(_vnd_mods), \
|
||||
.vnd_models = (_vnd_mods), \
|
||||
}
|
||||
|
||||
/** Abstraction that describes a Mesh Element */
|
||||
struct bt_mesh_elem {
|
||||
/* Unicast Address. Set at runtime during provisioning. */
|
||||
u16_t addr;
|
||||
|
||||
/* Location Descriptor (GATT Bluetooth Namespace Descriptors) */
|
||||
const u16_t loc;
|
||||
|
||||
const u8_t model_count;
|
||||
const u8_t vnd_model_count;
|
||||
|
||||
struct bt_mesh_model * const models;
|
||||
struct bt_mesh_model * const vnd_models;
|
||||
};
|
||||
|
||||
/* Foundation Models */
|
||||
#define BT_MESH_MODEL_ID_CFG_SRV 0x0000
|
||||
#define BT_MESH_MODEL_ID_CFG_CLI 0x0001
|
||||
#define BT_MESH_MODEL_ID_HEALTH_SRV 0x0002
|
||||
#define BT_MESH_MODEL_ID_HEALTH_CLI 0x0003
|
||||
|
||||
/* Models from the Mesh Model Specification */
|
||||
#define BT_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000
|
||||
#define BT_MESH_MODEL_ID_GEN_ONOFF_CLI 0x1001
|
||||
#define BT_MESH_MODEL_ID_GEN_LEVEL_SRV 0x1002
|
||||
#define BT_MESH_MODEL_ID_GEN_LEVEL_CLI 0x1003
|
||||
#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV 0x1004
|
||||
#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI 0x1005
|
||||
#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV 0x1006
|
||||
#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007
|
||||
#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI 0x1008
|
||||
#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV 0x1009
|
||||
#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a
|
||||
#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI 0x100b
|
||||
#define BT_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c
|
||||
#define BT_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d
|
||||
#define BT_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e
|
||||
#define BT_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV 0x100f
|
||||
#define BT_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010
|
||||
#define BT_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011
|
||||
#define BT_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012
|
||||
#define BT_MESH_MODEL_ID_GEN_USER_PROP_SRV 0x1013
|
||||
#define BT_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV 0x1014
|
||||
#define BT_MESH_MODEL_ID_GEN_PROP_CLI 0x1015
|
||||
#define BT_MESH_MODEL_ID_SENSOR_SRV 0x1100
|
||||
#define BT_MESH_MODEL_ID_SENSOR_SETUP_SRV 0x1101
|
||||
#define BT_MESH_MODEL_ID_SENSOR_CLI 0x1102
|
||||
#define BT_MESH_MODEL_ID_TIME_SRV 0x1200
|
||||
#define BT_MESH_MODEL_ID_TIME_SETUP_SRV 0x1201
|
||||
#define BT_MESH_MODEL_ID_TIME_CLI 0x1202
|
||||
#define BT_MESH_MODEL_ID_SCENE_SRV 0x1203
|
||||
#define BT_MESH_MODEL_ID_SCENE_SETUP_SRV 0x1204
|
||||
#define BT_MESH_MODEL_ID_SCENE_CLI 0x1205
|
||||
#define BT_MESH_MODEL_ID_SCHEDULER_SRV 0x1206
|
||||
#define BT_MESH_MODEL_ID_SCHEDULER_SETUP_SRV 0x1207
|
||||
#define BT_MESH_MODEL_ID_SCHEDULER_CLI 0x1208
|
||||
#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV 0x1300
|
||||
#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301
|
||||
#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI 0x1302
|
||||
#define BT_MESH_MODEL_ID_LIGHT_CTL_SRV 0x1303
|
||||
#define BT_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV 0x1304
|
||||
#define BT_MESH_MODEL_ID_LIGHT_CTL_CLI 0x1305
|
||||
#define BT_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV 0x1306
|
||||
#define BT_MESH_MODEL_ID_LIGHT_HSL_SRV 0x1307
|
||||
#define BT_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV 0x1308
|
||||
#define BT_MESH_MODEL_ID_LIGHT_HSL_CLI 0x1309
|
||||
#define BT_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV 0x130a
|
||||
#define BT_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV 0x130b
|
||||
#define BT_MESH_MODEL_ID_LIGHT_XYL_SRV 0x130c
|
||||
#define BT_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d
|
||||
#define BT_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e
|
||||
#define BT_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
|
||||
#define BT_MESH_MODEL_ID_LIGHT_LC_SETUPSRV 0x1310
|
||||
#define BT_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
|
||||
|
||||
/** Message sending context. */
|
||||
struct bt_mesh_msg_ctx {
|
||||
/** NetKey Index of the subnet to send the message on. */
|
||||
u16_t net_idx;
|
||||
|
||||
/** AppKey Index to encrypt the message with. */
|
||||
u16_t app_idx;
|
||||
|
||||
/** Remote address. */
|
||||
u16_t addr;
|
||||
|
||||
/** Received TTL value. Not used for sending. */
|
||||
u8_t recv_ttl:7;
|
||||
|
||||
/** Force sending reliably by using segment acknowledgement */
|
||||
u8_t send_rel:1;
|
||||
|
||||
/** TTL, or BT_MESH_TTL_DEFAULT for default TTL. */
|
||||
u8_t send_ttl;
|
||||
};
|
||||
|
||||
struct bt_mesh_model_op {
|
||||
/* OpCode encoded using the BT_MESH_MODEL_OP_* macros */
|
||||
const u32_t opcode;
|
||||
|
||||
/* Minimum required message length */
|
||||
const size_t min_len;
|
||||
|
||||
/* Message handler for the opcode */
|
||||
void (*const func)(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
};
|
||||
|
||||
#define BT_MESH_MODEL_OP_1(b0) (b0)
|
||||
#define BT_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1))
|
||||
#define BT_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid))
|
||||
|
||||
#define BT_MESH_MODEL_OP_END { 0, 0, NULL }
|
||||
#define BT_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \
|
||||
{ BT_MESH_MODEL_OP_END })
|
||||
|
||||
/** Helper to define an empty model array */
|
||||
#define BT_MESH_MODEL_NONE ((struct bt_mesh_model []){})
|
||||
|
||||
#define BT_MESH_MODEL(_id, _op, _pub, _user_data) \
|
||||
{ \
|
||||
.id = (_id), \
|
||||
.op = _op, \
|
||||
.keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \
|
||||
BT_MESH_KEY_UNUSED }, \
|
||||
.pub = _pub, \
|
||||
.groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \
|
||||
BT_MESH_ADDR_UNASSIGNED }, \
|
||||
.user_data = _user_data, \
|
||||
}
|
||||
|
||||
#define BT_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data) \
|
||||
{ \
|
||||
.vnd.company = (_company), \
|
||||
.vnd.id = (_id), \
|
||||
.op = _op, \
|
||||
.pub = _pub, \
|
||||
.keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \
|
||||
BT_MESH_KEY_UNUSED }, \
|
||||
.groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \
|
||||
BT_MESH_ADDR_UNASSIGNED }, \
|
||||
.user_data = _user_data, \
|
||||
}
|
||||
|
||||
/** @def BT_MESH_TRANSMIT
|
||||
*
|
||||
* @brief Encode transmission count & interval steps.
|
||||
*
|
||||
* @param count Number of retransmissions (first transmission is excluded).
|
||||
* @param int_ms Interval steps in milliseconds. Must be greater than 0
|
||||
* and a multiple of 10.
|
||||
*
|
||||
* @return Mesh transmit value that can be used e.g. for the default
|
||||
* values of the configuration model data.
|
||||
*/
|
||||
#define BT_MESH_TRANSMIT(count, int_ms) ((count) | (((int_ms / 10) - 1) << 3))
|
||||
|
||||
/** @def BT_MESH_TRANSMIT_COUNT
|
||||
*
|
||||
* @brief Decode transmit count from a transmit value.
|
||||
*
|
||||
* @param transmit Encoded transmit count & interval value.
|
||||
*
|
||||
* @return Transmission count (actual transmissions is N + 1).
|
||||
*/
|
||||
#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (u8_t)BIT_MASK(3)))
|
||||
|
||||
/** @def BT_MESH_TRANSMIT_INT
|
||||
*
|
||||
* @brief Decode transmit interval from a transmit value.
|
||||
*
|
||||
* @param transmit Encoded transmit count & interval value.
|
||||
*
|
||||
* @return Transmission interval in milliseconds.
|
||||
*/
|
||||
#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
|
||||
|
||||
/** @def BT_MESH_PUB_TRANSMIT
|
||||
*
|
||||
* @brief Encode Publish Retransmit count & interval steps.
|
||||
*
|
||||
* @param count Number of retransmissions (first transmission is excluded).
|
||||
* @param int_ms Interval steps in milliseconds. Must be greater than 0
|
||||
* and a multiple of 50.
|
||||
*
|
||||
* @return Mesh transmit value that can be used e.g. for the default
|
||||
* values of the configuration model data.
|
||||
*/
|
||||
#define BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, \
|
||||
(int_ms) / 5)
|
||||
|
||||
/** @def BT_MESH_PUB_TRANSMIT_COUNT
|
||||
*
|
||||
* @brief Decode Pubhlish Retransmit count from a given value.
|
||||
*
|
||||
* @param transmit Encoded Publish Retransmit count & interval value.
|
||||
*
|
||||
* @return Retransmission count (actual transmissions is N + 1).
|
||||
*/
|
||||
#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit)
|
||||
|
||||
/** @def BT_MESH_PUB_TRANSMIT_INT
|
||||
*
|
||||
* @brief Decode Publish Retransmit interval from a given value.
|
||||
*
|
||||
* @param transmit Encoded Publish Retransmit count & interval value.
|
||||
*
|
||||
* @return Transmission interval in milliseconds.
|
||||
*/
|
||||
#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
|
||||
|
||||
/** Model publication context. */
|
||||
struct bt_mesh_model_pub {
|
||||
/** The model the context belongs to. Initialized by the stack. */
|
||||
struct bt_mesh_model *mod;
|
||||
|
||||
u16_t addr; /**< Publish Address. */
|
||||
u16_t key; /**< Publish AppKey Index. */
|
||||
|
||||
u8_t ttl; /**< Publish Time to Live. */
|
||||
u8_t retransmit; /**< Retransmit Count & Interval Steps. */
|
||||
u8_t period; /**< Publish Period. */
|
||||
u8_t period_div:4, /**< Divisor for the Period. */
|
||||
cred:1, /**< Friendship Credentials Flag. */
|
||||
count:3; /**< Retransmissions left. */
|
||||
|
||||
u32_t period_start; /**< Start of the current period. */
|
||||
|
||||
/** @brief Publication buffer, containing the publication message.
|
||||
*
|
||||
* The application is expected to initialize this with
|
||||
* a valid net_buf_simple pointer, with the help of e.g.
|
||||
* the NET_BUF_SIMPLE() macro. The publication buffer must
|
||||
* contain a valid publication message before calling the
|
||||
* bt_mesh_model_publish() API or after the publication's
|
||||
* @ref bt_mesh_model_pub.update callback has been called
|
||||
* and returned success. The buffer must be created outside
|
||||
* of function context, i.e. it must not be on the stack.
|
||||
* This is most conveniently acheived by creating it inline
|
||||
* when declaring the publication context:
|
||||
*
|
||||
* static struct bt_mesh_model_pub my_pub = {
|
||||
* .msg = NET_BUF_SIMPLE(size),
|
||||
* };
|
||||
*/
|
||||
struct net_buf_simple *msg;
|
||||
|
||||
/** @brief Callback for updating the publication buffer.
|
||||
*
|
||||
* When set to NULL, the model is assumed not to support
|
||||
* periodic publishing. When set to non-NULL the callback
|
||||
* will be called periodically and is expected to update
|
||||
* @ref bt_mesh_model_pub.msg with a valid publication
|
||||
* message.
|
||||
*
|
||||
* @param mod The Model the Publication Context belogs to.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int (*update)(struct bt_mesh_model *mod);
|
||||
|
||||
/** Publish Period Timer. Only for stack-internal use. */
|
||||
struct k_delayed_work timer;
|
||||
};
|
||||
|
||||
/** Abstraction that describes a Mesh Model instance */
|
||||
struct bt_mesh_model {
|
||||
union {
|
||||
const u16_t id;
|
||||
struct {
|
||||
u16_t company;
|
||||
u16_t id;
|
||||
} vnd;
|
||||
};
|
||||
|
||||
/* The Element this Model belongs to */
|
||||
struct bt_mesh_elem *elem;
|
||||
|
||||
/* Model Publication */
|
||||
struct bt_mesh_model_pub * const pub;
|
||||
|
||||
/* AppKey List */
|
||||
u16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT];
|
||||
|
||||
/* Subscription List (group or virtual addresses) */
|
||||
u16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT];
|
||||
|
||||
const struct bt_mesh_model_op * const op;
|
||||
|
||||
/* Model-specific user data */
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
struct bt_mesh_send_cb {
|
||||
void (*start)(u16_t duration, int err, void *cb_data);
|
||||
void (*end)(int err, void *cb_data);
|
||||
};
|
||||
|
||||
void bt_mesh_model_msg_init(struct net_buf_simple *msg, u32_t opcode);
|
||||
|
||||
/** Special TTL value to request using configured default TTL */
|
||||
#define BT_MESH_TTL_DEFAULT 0xff
|
||||
|
||||
/** Maximum allowed TTL value */
|
||||
#define BT_MESH_TTL_MAX 0x7f
|
||||
|
||||
/**
|
||||
* @brief Send an Access Layer message.
|
||||
*
|
||||
* @param model Mesh (client) Model that the message belongs to.
|
||||
* @param ctx Message context, includes keys, TTL, etc.
|
||||
* @param msg Access Layer payload (the actual message to be sent).
|
||||
* @param cb Optional "message sent" callback.
|
||||
* @param cb_data User data to be passed to the callback.
|
||||
*
|
||||
* @return 0 on success, or (negative) error code on failure.
|
||||
*/
|
||||
int bt_mesh_model_send(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *msg,
|
||||
const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data);
|
||||
|
||||
/**
|
||||
* @brief Send a model publication message.
|
||||
*
|
||||
* Before calling this function, the user needs to ensure that the model
|
||||
* publication message (@ref bt_mesh_model_pub.msg) contains a valid
|
||||
* message to be sent. Note that this API is only to be used for
|
||||
* non-period publishing. For periodic publishing the app only needs
|
||||
* to make sure that @ref bt_mesh_model_pub.msg contains a valid message
|
||||
* whenever the @ref bt_mesh_model_pub.update callback is called.
|
||||
*
|
||||
* @param model Mesh (client) Model that's publishing the message.
|
||||
*
|
||||
* @return 0 on success, or (negative) error code on failure.
|
||||
*/
|
||||
int bt_mesh_model_publish(struct bt_mesh_model *model);
|
||||
|
||||
/** Node Composition */
|
||||
struct bt_mesh_comp {
|
||||
u16_t cid;
|
||||
u16_t pid;
|
||||
u16_t vid;
|
||||
|
||||
size_t elem_count;
|
||||
struct bt_mesh_elem *elem;
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_MESH_ACCESS_H */
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh Configuration Client Model APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_MESH_CFG_CLI_H
|
||||
#define __BT_MESH_CFG_CLI_H
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh
|
||||
* @defgroup bt_mesh_cfg_cli Bluetooth Mesh Configuration Client Model
|
||||
* @ingroup bt_mesh
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Mesh Configuration Client Model Context */
|
||||
struct bt_mesh_cfg_cli {
|
||||
struct bt_mesh_model *model;
|
||||
|
||||
struct k_sem op_sync;
|
||||
u32_t op_pending;
|
||||
void *op_param;
|
||||
};
|
||||
|
||||
extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
|
||||
|
||||
#define BT_MESH_MODEL_CFG_CLI(cli_data) \
|
||||
BT_MESH_MODEL(BT_MESH_MODEL_ID_CFG_CLI, \
|
||||
bt_mesh_cfg_cli_op, NULL, cli_data)
|
||||
|
||||
int bt_mesh_cfg_comp_data_get(u16_t net_idx, u16_t addr, u8_t page,
|
||||
u8_t *status, struct net_buf_simple *comp);
|
||||
|
||||
int bt_mesh_cfg_beacon_get(u16_t net_idx, u16_t addr, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_beacon_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_ttl_get(u16_t net_idx, u16_t addr, u8_t *ttl);
|
||||
|
||||
int bt_mesh_cfg_ttl_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *ttl);
|
||||
|
||||
int bt_mesh_cfg_friend_get(u16_t net_idx, u16_t addr, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_friend_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_gatt_proxy_get(u16_t net_idx, u16_t addr, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_gatt_proxy_set(u16_t net_idx, u16_t addr, u8_t val,
|
||||
u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_relay_get(u16_t net_idx, u16_t addr, u8_t *status,
|
||||
u8_t *transmit);
|
||||
|
||||
int bt_mesh_cfg_relay_set(u16_t net_idx, u16_t addr, u8_t new_relay,
|
||||
u8_t new_transmit, u8_t *status, u8_t *transmit);
|
||||
|
||||
int bt_mesh_cfg_net_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
|
||||
const u8_t net_key[16], u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
|
||||
u16_t key_app_idx, const u8_t app_key[16],
|
||||
u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t mod_app_idx, u16_t mod_id, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_app_bind_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t mod_app_idx, u16_t mod_id, u16_t cid,
|
||||
u8_t *status);
|
||||
|
||||
struct bt_mesh_cfg_mod_pub {
|
||||
u16_t addr;
|
||||
u16_t app_idx;
|
||||
bool cred_flag;
|
||||
u8_t ttl;
|
||||
u8_t period;
|
||||
u8_t transmit;
|
||||
};
|
||||
|
||||
int bt_mesh_cfg_mod_pub_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t mod_id, struct bt_mesh_cfg_mod_pub *pub,
|
||||
u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_pub_get_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t mod_id, u16_t cid,
|
||||
struct bt_mesh_cfg_mod_pub *pub, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_pub_set(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t mod_id, struct bt_mesh_cfg_mod_pub *pub,
|
||||
u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_pub_set_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t mod_id, u16_t cid,
|
||||
struct bt_mesh_cfg_mod_pub *pub, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_add(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t sub_addr, u16_t mod_id, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_add_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t sub_addr, u16_t mod_id, u16_t cid,
|
||||
u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_del(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t sub_addr, u16_t mod_id, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_del_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t sub_addr, u16_t mod_id, u16_t cid,
|
||||
u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_overwrite(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
u16_t sub_addr, u16_t mod_id, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_overwrite_vnd(u16_t net_idx, u16_t addr,
|
||||
u16_t elem_addr, u16_t sub_addr,
|
||||
u16_t mod_id, u16_t cid, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_va_add(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
const u8_t label[16], u16_t mod_id,
|
||||
u16_t *virt_addr, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_va_add_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
const u8_t label[16], u16_t mod_id,
|
||||
u16_t cid, u16_t *virt_addr, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_va_del(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
const u8_t label[16], u16_t mod_id,
|
||||
u16_t *virt_addr, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_va_del_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
const u8_t label[16], u16_t mod_id,
|
||||
u16_t cid, u16_t *virt_addr, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_va_overwrite(u16_t net_idx, u16_t addr,
|
||||
u16_t elem_addr, const u8_t label[16],
|
||||
u16_t mod_id, u16_t *virt_addr,
|
||||
u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_mod_sub_va_overwrite_vnd(u16_t net_idx, u16_t addr,
|
||||
u16_t elem_addr, const u8_t label[16],
|
||||
u16_t mod_id, u16_t cid,
|
||||
u16_t *virt_addr, u8_t *status);
|
||||
|
||||
struct bt_mesh_cfg_hb_sub {
|
||||
u16_t src;
|
||||
u16_t dst;
|
||||
u8_t period;
|
||||
u8_t count;
|
||||
u8_t min;
|
||||
u8_t max;
|
||||
};
|
||||
|
||||
int bt_mesh_cfg_hb_sub_set(u16_t net_idx, u16_t addr,
|
||||
struct bt_mesh_cfg_hb_sub *sub, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_hb_sub_get(u16_t net_idx, u16_t addr,
|
||||
struct bt_mesh_cfg_hb_sub *sub, u8_t *status);
|
||||
|
||||
struct bt_mesh_cfg_hb_pub {
|
||||
u16_t dst;
|
||||
u8_t count;
|
||||
u8_t period;
|
||||
u8_t ttl;
|
||||
u16_t feat;
|
||||
u16_t net_idx;
|
||||
};
|
||||
|
||||
int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr,
|
||||
const struct bt_mesh_cfg_hb_pub *pub, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr,
|
||||
struct bt_mesh_cfg_hb_pub *pub, u8_t *status);
|
||||
|
||||
s32_t bt_mesh_cfg_cli_timeout_get(void);
|
||||
void bt_mesh_cfg_cli_timeout_set(s32_t timeout);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_MESH_CFG_CLI_H */
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh Configuration Server Model APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_MESH_CFG_SRV_H
|
||||
#define __BT_MESH_CFG_SRV_H
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh
|
||||
* @defgroup bt_mesh_cfg_srv Bluetooth Mesh Configuration Server Model
|
||||
* @ingroup bt_mesh
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Mesh Configuration Server Model Context */
|
||||
struct bt_mesh_cfg_srv {
|
||||
struct bt_mesh_model *model;
|
||||
|
||||
u8_t net_transmit; /* Network Transmit state */
|
||||
u8_t relay; /* Relay Mode state */
|
||||
u8_t relay_retransmit; /* Relay Retransmit state */
|
||||
u8_t beacon; /* Secure Network Beacon state */
|
||||
u8_t gatt_proxy; /* GATT Proxy state */
|
||||
u8_t frnd; /* Friend state */
|
||||
u8_t default_ttl; /* Default TTL */
|
||||
|
||||
/* Heartbeat Publication */
|
||||
struct {
|
||||
struct k_delayed_work timer;
|
||||
|
||||
u16_t dst;
|
||||
u16_t count;
|
||||
u8_t period;
|
||||
u8_t ttl;
|
||||
u16_t feat;
|
||||
u16_t net_idx;
|
||||
} hb_pub;
|
||||
|
||||
/* Heartbeat Subscription */
|
||||
struct {
|
||||
s64_t expiry;
|
||||
|
||||
u16_t src;
|
||||
u16_t dst;
|
||||
u16_t count;
|
||||
u8_t min_hops;
|
||||
u8_t max_hops;
|
||||
|
||||
/* Optional subscription tracking function */
|
||||
void (*func)(u8_t hops, u16_t feat);
|
||||
} hb_sub;
|
||||
};
|
||||
|
||||
extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[];
|
||||
|
||||
#define BT_MESH_MODEL_CFG_SRV(srv_data) \
|
||||
BT_MESH_MODEL(BT_MESH_MODEL_ID_CFG_SRV, \
|
||||
bt_mesh_cfg_srv_op, NULL, srv_data)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_MESH_CFG_SRV_H */
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh Health Client Model APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_MESH_HEALTH_CLI_H
|
||||
#define __BT_MESH_HEALTH_CLI_H
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh
|
||||
* @defgroup bt_mesh_health_cli Bluetooth Mesh Health Client Model
|
||||
* @ingroup bt_mesh
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Mesh Health Client Model Context */
|
||||
struct bt_mesh_health_cli {
|
||||
struct bt_mesh_model *model;
|
||||
|
||||
void (*current_status)(struct bt_mesh_health_cli *cli, u16_t addr,
|
||||
u8_t test_id, u16_t cid, u8_t *faults,
|
||||
size_t fault_count);
|
||||
|
||||
struct k_sem op_sync;
|
||||
u32_t op_pending;
|
||||
void *op_param;
|
||||
};
|
||||
|
||||
extern const struct bt_mesh_model_op bt_mesh_health_cli_op[];
|
||||
|
||||
#define BT_MESH_MODEL_HEALTH_CLI(cli_data) \
|
||||
BT_MESH_MODEL(BT_MESH_MODEL_ID_HEALTH_CLI, \
|
||||
bt_mesh_health_cli_op, NULL, cli_data)
|
||||
|
||||
int bt_mesh_health_cli_set(struct bt_mesh_model *model);
|
||||
|
||||
int bt_mesh_health_fault_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u16_t cid, u8_t *test_id, u8_t *faults,
|
||||
size_t *fault_count);
|
||||
|
||||
int bt_mesh_health_fault_clear(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u16_t cid, u8_t *test_id, u8_t *faults,
|
||||
size_t *fault_count);
|
||||
|
||||
int bt_mesh_health_fault_test(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u16_t cid, u8_t test_id, u8_t *faults,
|
||||
size_t *fault_count);
|
||||
|
||||
int bt_mesh_health_period_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t *divisor);
|
||||
|
||||
int bt_mesh_health_period_set(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t divisor, u8_t *updated_divisor);
|
||||
|
||||
int bt_mesh_health_attention_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t *attention);
|
||||
|
||||
int bt_mesh_health_attention_set(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t attention, u8_t *updated_attention);
|
||||
|
||||
s32_t bt_mesh_health_cli_timeout_get(void);
|
||||
void bt_mesh_health_cli_timeout_set(s32_t timeout);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_MESH_HEALTH_CLI_H */
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh Health Server Model APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_MESH_HEALTH_SRV_H
|
||||
#define __BT_MESH_HEALTH_SRV_H
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Health Server Model
|
||||
* @defgroup bt_mesh_health_srv Bluetooth Mesh Health Server Model
|
||||
* @ingroup bt_mesh
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct bt_mesh_health_srv_cb {
|
||||
/* Fetch current faults */
|
||||
int (*fault_get_cur)(struct bt_mesh_model *model, u8_t *test_id,
|
||||
u16_t *company_id, u8_t *faults,
|
||||
u8_t *fault_count);
|
||||
|
||||
/* Fetch registered faults */
|
||||
int (*fault_get_reg)(struct bt_mesh_model *model, u16_t company_id,
|
||||
u8_t *test_id, u8_t *faults,
|
||||
u8_t *fault_count);
|
||||
|
||||
/* Clear registered faults */
|
||||
int (*fault_clear)(struct bt_mesh_model *model, u16_t company_id);
|
||||
|
||||
/* Run a specific test */
|
||||
int (*fault_test)(struct bt_mesh_model *model, u8_t test_id,
|
||||
u16_t company_id);
|
||||
|
||||
/* Attention on */
|
||||
void (*attn_on)(struct bt_mesh_model *model);
|
||||
|
||||
/* Attention off */
|
||||
void (*attn_off)(struct bt_mesh_model *model);
|
||||
};
|
||||
|
||||
/** @def BT_MESH_HEALTH_FAULT_MSG
|
||||
*
|
||||
* A helper to define a health fault message.
|
||||
*
|
||||
* @param max_faults Maximum number of faults the element can have.
|
||||
*
|
||||
* @return a New net_buf_simple of the needed size.
|
||||
*/
|
||||
#define BT_MESH_HEALTH_FAULT_MSG(max_faults) \
|
||||
NET_BUF_SIMPLE(1 + 3 + (max_faults))
|
||||
|
||||
/** Mesh Health Server Model Context */
|
||||
struct bt_mesh_health_srv {
|
||||
struct bt_mesh_model *model;
|
||||
|
||||
/* Optional callback struct */
|
||||
const struct bt_mesh_health_srv_cb *cb;
|
||||
|
||||
/* Attention Timer state */
|
||||
struct k_delayed_work attn_timer;
|
||||
};
|
||||
|
||||
int bt_mesh_fault_update(struct bt_mesh_elem *elem);
|
||||
|
||||
extern const struct bt_mesh_model_op bt_mesh_health_srv_op[];
|
||||
|
||||
/** @def BT_MESH_MODEL_HEALTH_SRV
|
||||
*
|
||||
* Define a new health server model. Note that this API needs to be
|
||||
* repeated for each element that the application wants to have a
|
||||
* health server model on. Each instance also needs a unique
|
||||
* bt_mesh_health_srv and bt_mesh_model_pub context.
|
||||
*
|
||||
* @param srv Pointer to a unique struct bt_mesh_health_srv.
|
||||
* @param pub Pointer to a unique struct bt_mesh_model_pub.
|
||||
*
|
||||
* @return New mesh model instance.
|
||||
*/
|
||||
#define BT_MESH_MODEL_HEALTH_SRV(srv, pub) \
|
||||
BT_MESH_MODEL(BT_MESH_MODEL_ID_HEALTH_SRV, \
|
||||
bt_mesh_health_srv_op, pub, srv)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_MESH_HEALTH_SRV_H */
|
||||
|
|
@ -0,0 +1,323 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh Profile APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_MESH_MAIN_H
|
||||
#define __BT_MESH_MAIN_H
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Provisioning
|
||||
* @defgroup bt_mesh_prov Bluetooth Mesh Provisioning
|
||||
* @ingroup bt_mesh
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
BT_MESH_NO_OUTPUT = 0,
|
||||
BT_MESH_BLINK = BIT(0),
|
||||
BT_MESH_BEEP = BIT(1),
|
||||
BT_MESH_VIBRATE = BIT(2),
|
||||
BT_MESH_DISPLAY_NUMBER = BIT(3),
|
||||
BT_MESH_DISPLAY_STRING = BIT(4),
|
||||
} bt_mesh_output_action_t;
|
||||
|
||||
typedef enum {
|
||||
BT_MESH_NO_INPUT = 0,
|
||||
BT_MESH_PUSH = BIT(0),
|
||||
BT_MESH_TWIST = BIT(1),
|
||||
BT_MESH_ENTER_NUMBER = BIT(2),
|
||||
BT_MESH_ENTER_STRING = BIT(3),
|
||||
} bt_mesh_input_action_t;
|
||||
|
||||
typedef enum {
|
||||
BT_MESH_PROV_ADV = BIT(0),
|
||||
BT_MESH_PROV_GATT = BIT(1),
|
||||
} bt_mesh_prov_bearer_t;
|
||||
|
||||
/** Provisioning properties & capabilities. */
|
||||
struct bt_mesh_prov {
|
||||
/** The UUID that's used when advertising as unprovisioned */
|
||||
const u8_t *uuid;
|
||||
|
||||
/** Static OOB value */
|
||||
const u8_t *static_val;
|
||||
/** Static OOB value length */
|
||||
u8_t static_val_len;
|
||||
|
||||
/** Maximum size of Output OOB supported */
|
||||
u8_t output_size;
|
||||
/** Supported Output OOB Actions */
|
||||
u16_t output_actions;
|
||||
|
||||
/* Maximum size of Input OOB supported */
|
||||
u8_t input_size;
|
||||
/** Supported Input OOB Actions */
|
||||
u16_t input_actions;
|
||||
|
||||
/** @brief Output of a number is requested.
|
||||
*
|
||||
* This callback notifies the application that it should
|
||||
* output the given number using the given action.
|
||||
*
|
||||
* @param act Action for outputting the number.
|
||||
* @param num Number to be outputted.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int (*output_number)(bt_mesh_output_action_t act, u32_t num);
|
||||
|
||||
/** @brief Output of a string is requested.
|
||||
*
|
||||
* This callback notifies the application that it should
|
||||
* display the given string to the user.
|
||||
*
|
||||
* @param str String to be displayed.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int (*output_string)(const char *str);
|
||||
|
||||
/** @brief Input is requested.
|
||||
*
|
||||
* This callback notifies the application that it should
|
||||
* request input from the user using the given action. The
|
||||
* requested input will either be a string or a number, and
|
||||
* the application needs to consequently call the
|
||||
* bt_mesh_input_string() or bt_mesh_input_number() functions
|
||||
* once the data has been acquired from the user.
|
||||
*
|
||||
* @param act Action for inputting data.
|
||||
* @param num Maximum size of the inputted data.
|
||||
*
|
||||
* @return Zero on success or negative error code otherwise
|
||||
*/
|
||||
int (*input)(bt_mesh_input_action_t act, u8_t size);
|
||||
|
||||
/** @brief Provisioning link has been opened.
|
||||
*
|
||||
* This callback notifies the application that a provisioning
|
||||
* link has been opened on the given provisioning bearer.
|
||||
*
|
||||
* @param bearer Provisioning bearer.
|
||||
*/
|
||||
void (*link_open)(bt_mesh_prov_bearer_t bearer);
|
||||
|
||||
/** @brief Provisioning link has been closed.
|
||||
*
|
||||
* This callback notifies the application that a provisioning
|
||||
* link has been closed on the given provisioning bearer.
|
||||
*
|
||||
* @param bearer Provisioning bearer.
|
||||
*/
|
||||
void (*link_close)(bt_mesh_prov_bearer_t bearer);
|
||||
|
||||
/** @brief Provisioning is complete.
|
||||
*
|
||||
* This callback notifies the application that provisioning has
|
||||
* been successfully completed, and that the local node has been
|
||||
* assigned the specified NetKeyIndex and primary element address.
|
||||
*
|
||||
* @param net_idx NetKeyIndex given during provisioning.
|
||||
* @param addr Primary element address.
|
||||
*/
|
||||
void (*complete)(u16_t net_idx, u16_t addr);
|
||||
|
||||
/** @brief Node has been reset.
|
||||
*
|
||||
* This callback notifies the application that the local node
|
||||
* has been reset and needs to be reprovisioned. The node will
|
||||
* not automatically advertise as unprovisioned, rather the
|
||||
* bt_mesh_prov_enable() API needs to be called to enable
|
||||
* unprovisioned advertising on one or more provisioning bearers.
|
||||
*/
|
||||
void (*reset)(void);
|
||||
};
|
||||
|
||||
/** @brief Provide provisioning input OOB string.
|
||||
*
|
||||
* This is intended to be called after the bt_mesh_prov input callback
|
||||
* has been called with BT_MESH_ENTER_STRING as the action.
|
||||
*
|
||||
* @param str String.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_input_string(const char *str);
|
||||
|
||||
/** @brief Provide provisioning input OOB number.
|
||||
*
|
||||
* This is intended to be called after the bt_mesh_prov input callback
|
||||
* has been called with BT_MESH_ENTER_NUMBER as the action.
|
||||
*
|
||||
* @param num Number.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_input_number(u32_t num);
|
||||
|
||||
/** @brief Enable specific provisioning bearers
|
||||
*
|
||||
* Enable one or more provisioning bearers.
|
||||
*
|
||||
* @param bearers Bit-wise or of provisioning bearers.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers);
|
||||
|
||||
/** @brief Disable specific provisioning bearers
|
||||
*
|
||||
* Disable one or more provisioning bearers.
|
||||
*
|
||||
* @param bearers Bit-wise or of provisioning bearers.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh
|
||||
* @defgroup bt_mesh Bluetooth Mesh
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Primary Network Key index */
|
||||
#define BT_MESH_NET_PRIMARY 0x000
|
||||
|
||||
#define BT_MESH_RELAY_DISABLED 0x00
|
||||
#define BT_MESH_RELAY_ENABLED 0x01
|
||||
#define BT_MESH_RELAY_NOT_SUPPORTED 0x02
|
||||
|
||||
#define BT_MESH_BEACON_DISABLED 0x00
|
||||
#define BT_MESH_BEACON_ENABLED 0x01
|
||||
|
||||
#define BT_MESH_GATT_PROXY_DISABLED 0x00
|
||||
#define BT_MESH_GATT_PROXY_ENABLED 0x01
|
||||
#define BT_MESH_GATT_PROXY_NOT_SUPPORTED 0x02
|
||||
|
||||
#define BT_MESH_FRIEND_DISABLED 0x00
|
||||
#define BT_MESH_FRIEND_ENABLED 0x01
|
||||
#define BT_MESH_FRIEND_NOT_SUPPORTED 0x02
|
||||
|
||||
#define BT_MESH_NODE_IDENTITY_STOPPED 0x00
|
||||
#define BT_MESH_NODE_IDENTITY_RUNNING 0x01
|
||||
#define BT_MESH_NODE_IDENTITY_NOT_SUPPORTED 0x02
|
||||
|
||||
/* Features */
|
||||
#define BT_MESH_FEAT_RELAY BIT(0)
|
||||
#define BT_MESH_FEAT_PROXY BIT(1)
|
||||
#define BT_MESH_FEAT_FRIEND BIT(2)
|
||||
#define BT_MESH_FEAT_LOW_POWER BIT(3)
|
||||
|
||||
/** @brief Initialize Mesh support
|
||||
*
|
||||
* After calling this API, the node will not automatically advertise as
|
||||
* unprovisioned, rather the bt_mesh_prov_enable() API needs to be called
|
||||
* to enable unprovisioned advertising on one or more provisioning bearers.
|
||||
*
|
||||
* @param prov Node provisioning information.
|
||||
* @param comp Node Composition.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_init(const struct bt_mesh_prov *prov,
|
||||
const struct bt_mesh_comp *comp);
|
||||
|
||||
/** @brief Reset the state of the local Mesh node.
|
||||
*
|
||||
* Resets the state of the node, which means that it needs to be
|
||||
* reprovisioned to become an active node in a Mesh network again.
|
||||
*
|
||||
* After calling this API, the node will not automatically advertise as
|
||||
* unprovisioned, rather the bt_mesh_prov_enable() API needs to be called
|
||||
* to enable unprovisioned advertising on one or more provisioning bearers.
|
||||
*
|
||||
*/
|
||||
void bt_mesh_reset(void);
|
||||
|
||||
/** @brief Provision the local Mesh Node.
|
||||
*
|
||||
* This API should normally not be used directly by the application. The
|
||||
* only exception is for testing purposes where manual provisioning is
|
||||
* desired without an actual external provisioner.
|
||||
*
|
||||
* @param net_key Network Key
|
||||
* @param net_idx Network Key Index
|
||||
* @param flags Provisioning Flags
|
||||
* @param iv_index IV Index
|
||||
* @param seq Sequence Number (0 if newly provisioned).
|
||||
* @param addr Primary element address
|
||||
* @param dev_key Device Key
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx,
|
||||
u8_t flags, u32_t iv_index, u32_t seq,
|
||||
u16_t addr, const u8_t dev_key[16]);
|
||||
|
||||
/** @brief Toggle the IV Update test mode
|
||||
*
|
||||
* This API is only available if the IV Update test mode has been enabled
|
||||
* in Kconfig. It is needed for passing most of the IV Update qualification
|
||||
* test cases.
|
||||
*
|
||||
* @param enable true to enable IV Update test mode, false to disable it.
|
||||
*/
|
||||
void bt_mesh_iv_update_test(bool enable);
|
||||
|
||||
/** @brief Toggle the IV Update state
|
||||
*
|
||||
* This API is only available if the IV Update test mode has been enabled
|
||||
* in Kconfig. It is needed for passing most of the IV Update qualification
|
||||
* test cases.
|
||||
*
|
||||
* @return true if IV Update In Progress state was entered, false otherwise.
|
||||
*/
|
||||
bool bt_mesh_iv_update(void);
|
||||
|
||||
/** @brief Toggle the Low Power feature of the local device
|
||||
*
|
||||
* Enables or disables the Low Power feature of the local device. This is
|
||||
* exposed as a run-time feature, since the device might want to change
|
||||
* this e.g. based on being plugged into a stable power source or running
|
||||
* from a battery power source.
|
||||
*
|
||||
* @param enable true to enable LPN functionality, false to disable it.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_lpn_set(bool enable);
|
||||
|
||||
/** @brief Send out a Friend Poll message.
|
||||
*
|
||||
* Send a Friend Poll message to the Friend of this node. If there is no
|
||||
* established Friendship the function will return an error.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_lpn_poll(void);
|
||||
|
||||
/** @brief Register a callback for Friendship changes.
|
||||
*
|
||||
* Registers a callback that will be called whenever Friendship gets
|
||||
* established or is lost.
|
||||
*
|
||||
* @param cb Function to call when the Friendship status changes.
|
||||
*/
|
||||
void bt_mesh_lpn_set_cb(void (*cb)(u16_t friend_addr, bool established));
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_MESH_MAIN_H */
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh Proxy APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_MESH_PROXY_H
|
||||
#define __BT_MESH_PROXY_H
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Proxy
|
||||
* @defgroup bt_mesh_proxy Bluetooth Mesh Proxy
|
||||
* @ingroup bt_mesh
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Enable advertising with Node Identity.
|
||||
*
|
||||
* This API requires that GATT Proxy support has been enabled. Once called
|
||||
* each subnet will start advertising using Node Identity for the next
|
||||
* 60 seconds.
|
||||
*
|
||||
* @return 0 on success, or (negative) error code on failure.
|
||||
*/
|
||||
int bt_mesh_proxy_identity_enable(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_MESH_PROXY_H */
|
||||
612
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/sdp.h
Normal file
612
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/sdp.h
Normal file
|
|
@ -0,0 +1,612 @@
|
|||
/** @file
|
||||
* @brief Service Discovery Protocol handling.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_SDP_H
|
||||
#define __BT_SDP_H
|
||||
|
||||
/**
|
||||
* @brief Service Discovery Protocol (SDP)
|
||||
* @defgroup bt_sdp Service Discovery Protocol (SDP)
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/conn.h>
|
||||
|
||||
/*
|
||||
* All definitions are based on Bluetooth Assigned Numbers
|
||||
* of the Bluetooth Specification
|
||||
*/
|
||||
|
||||
/*
|
||||
* Service class identifiers of standard services and service groups
|
||||
*/
|
||||
#define BT_SDP_SDP_SERVER_SVCLASS 0x1000
|
||||
#define BT_SDP_BROWSE_GRP_DESC_SVCLASS 0x1001
|
||||
#define BT_SDP_PUBLIC_BROWSE_GROUP 0x1002
|
||||
#define BT_SDP_SERIAL_PORT_SVCLASS 0x1101
|
||||
#define BT_SDP_LAN_ACCESS_SVCLASS 0x1102
|
||||
#define BT_SDP_DIALUP_NET_SVCLASS 0x1103
|
||||
#define BT_SDP_IRMC_SYNC_SVCLASS 0x1104
|
||||
#define BT_SDP_OBEX_OBJPUSH_SVCLASS 0x1105
|
||||
#define BT_SDP_OBEX_FILETRANS_SVCLASS 0x1106
|
||||
#define BT_SDP_IRMC_SYNC_CMD_SVCLASS 0x1107
|
||||
#define BT_SDP_HEADSET_SVCLASS 0x1108
|
||||
#define BT_SDP_CORDLESS_TELEPHONY_SVCLASS 0x1109
|
||||
#define BT_SDP_AUDIO_SOURCE_SVCLASS 0x110a
|
||||
#define BT_SDP_AUDIO_SINK_SVCLASS 0x110b
|
||||
#define BT_SDP_AV_REMOTE_TARGET_SVCLASS 0x110c
|
||||
#define BT_SDP_ADVANCED_AUDIO_SVCLASS 0x110d
|
||||
#define BT_SDP_AV_REMOTE_SVCLASS 0x110e
|
||||
#define BT_SDP_AV_REMOTE_CONTROLLER_SVCLASS 0x110f
|
||||
#define BT_SDP_INTERCOM_SVCLASS 0x1110
|
||||
#define BT_SDP_FAX_SVCLASS 0x1111
|
||||
#define BT_SDP_HEADSET_AGW_SVCLASS 0x1112
|
||||
#define BT_SDP_WAP_SVCLASS 0x1113
|
||||
#define BT_SDP_WAP_CLIENT_SVCLASS 0x1114
|
||||
#define BT_SDP_PANU_SVCLASS 0x1115
|
||||
#define BT_SDP_NAP_SVCLASS 0x1116
|
||||
#define BT_SDP_GN_SVCLASS 0x1117
|
||||
#define BT_SDP_DIRECT_PRINTING_SVCLASS 0x1118
|
||||
#define BT_SDP_REFERENCE_PRINTING_SVCLASS 0x1119
|
||||
#define BT_SDP_IMAGING_SVCLASS 0x111a
|
||||
#define BT_SDP_IMAGING_RESPONDER_SVCLASS 0x111b
|
||||
#define BT_SDP_IMAGING_ARCHIVE_SVCLASS 0x111c
|
||||
#define BT_SDP_IMAGING_REFOBJS_SVCLASS 0x111d
|
||||
#define BT_SDP_HANDSFREE_SVCLASS 0x111e
|
||||
#define BT_SDP_HANDSFREE_AGW_SVCLASS 0x111f
|
||||
#define BT_SDP_DIRECT_PRT_REFOBJS_SVCLASS 0x1120
|
||||
#define BT_SDP_REFLECTED_UI_SVCLASS 0x1121
|
||||
#define BT_SDP_BASIC_PRINTING_SVCLASS 0x1122
|
||||
#define BT_SDP_PRINTING_STATUS_SVCLASS 0x1123
|
||||
#define BT_SDP_HID_SVCLASS 0x1124
|
||||
#define BT_SDP_HCR_SVCLASS 0x1125
|
||||
#define BT_SDP_HCR_PRINT_SVCLASS 0x1126
|
||||
#define BT_SDP_HCR_SCAN_SVCLASS 0x1127
|
||||
#define BT_SDP_CIP_SVCLASS 0x1128
|
||||
#define BT_SDP_VIDEO_CONF_GW_SVCLASS 0x1129
|
||||
#define BT_SDP_UDI_MT_SVCLASS 0x112a
|
||||
#define BT_SDP_UDI_TA_SVCLASS 0x112b
|
||||
#define BT_SDP_AV_SVCLASS 0x112c
|
||||
#define BT_SDP_SAP_SVCLASS 0x112d
|
||||
#define BT_SDP_PBAP_PCE_SVCLASS 0x112e
|
||||
#define BT_SDP_PBAP_PSE_SVCLASS 0x112f
|
||||
#define BT_SDP_PBAP_SVCLASS 0x1130
|
||||
#define BT_SDP_MAP_MSE_SVCLASS 0x1132
|
||||
#define BT_SDP_MAP_MCE_SVCLASS 0x1133
|
||||
#define BT_SDP_MAP_SVCLASS 0x1134
|
||||
#define BT_SDP_GNSS_SVCLASS 0x1135
|
||||
#define BT_SDP_GNSS_SERVER_SVCLASS 0x1136
|
||||
#define BT_SDP_MPS_SC_SVCLASS 0x113a
|
||||
#define BT_SDP_MPS_SVCLASS 0x113b
|
||||
#define BT_SDP_PNP_INFO_SVCLASS 0x1200
|
||||
#define BT_SDP_GENERIC_NETWORKING_SVCLASS 0x1201
|
||||
#define BT_SDP_GENERIC_FILETRANS_SVCLASS 0x1202
|
||||
#define BT_SDP_GENERIC_AUDIO_SVCLASS 0x1203
|
||||
#define BT_SDP_GENERIC_TELEPHONY_SVCLASS 0x1204
|
||||
#define BT_SDP_UPNP_SVCLASS 0x1205
|
||||
#define BT_SDP_UPNP_IP_SVCLASS 0x1206
|
||||
#define BT_SDP_UPNP_PAN_SVCLASS 0x1300
|
||||
#define BT_SDP_UPNP_LAP_SVCLASS 0x1301
|
||||
#define BT_SDP_UPNP_L2CAP_SVCLASS 0x1302
|
||||
#define BT_SDP_VIDEO_SOURCE_SVCLASS 0x1303
|
||||
#define BT_SDP_VIDEO_SINK_SVCLASS 0x1304
|
||||
#define BT_SDP_VIDEO_DISTRIBUTION_SVCLASS 0x1305
|
||||
#define BT_SDP_HDP_SVCLASS 0x1400
|
||||
#define BT_SDP_HDP_SOURCE_SVCLASS 0x1401
|
||||
#define BT_SDP_HDP_SINK_SVCLASS 0x1402
|
||||
#define BT_SDP_GENERIC_ACCESS_SVCLASS 0x1800
|
||||
#define BT_SDP_GENERIC_ATTRIB_SVCLASS 0x1801
|
||||
#define BT_SDP_APPLE_AGENT_SVCLASS 0x2112
|
||||
|
||||
/*
|
||||
* Attribute identifier codes
|
||||
*/
|
||||
#define BT_SDP_SERVER_RECORD_HANDLE 0x0000
|
||||
|
||||
/*
|
||||
* Possible values for attribute-id are listed below.
|
||||
* See SDP Spec, section "Service Attribute Definitions" for more details.
|
||||
*/
|
||||
#define BT_SDP_ATTR_RECORD_HANDLE 0x0000
|
||||
#define BT_SDP_ATTR_SVCLASS_ID_LIST 0x0001
|
||||
#define BT_SDP_ATTR_RECORD_STATE 0x0002
|
||||
#define BT_SDP_ATTR_SERVICE_ID 0x0003
|
||||
#define BT_SDP_ATTR_PROTO_DESC_LIST 0x0004
|
||||
#define BT_SDP_ATTR_BROWSE_GRP_LIST 0x0005
|
||||
#define BT_SDP_ATTR_LANG_BASE_ATTR_ID_LIST 0x0006
|
||||
#define BT_SDP_ATTR_SVCINFO_TTL 0x0007
|
||||
#define BT_SDP_ATTR_SERVICE_AVAILABILITY 0x0008
|
||||
#define BT_SDP_ATTR_PROFILE_DESC_LIST 0x0009
|
||||
#define BT_SDP_ATTR_DOC_URL 0x000a
|
||||
#define BT_SDP_ATTR_CLNT_EXEC_URL 0x000b
|
||||
#define BT_SDP_ATTR_ICON_URL 0x000c
|
||||
#define BT_SDP_ATTR_ADD_PROTO_DESC_LIST 0x000d
|
||||
|
||||
#define BT_SDP_ATTR_GROUP_ID 0x0200
|
||||
#define BT_SDP_ATTR_IP_SUBNET 0x0200
|
||||
#define BT_SDP_ATTR_VERSION_NUM_LIST 0x0200
|
||||
#define BT_SDP_ATTR_SUPPORTED_FEATURES_LIST 0x0200
|
||||
#define BT_SDP_ATTR_GOEP_L2CAP_PSM 0x0200
|
||||
#define BT_SDP_ATTR_SVCDB_STATE 0x0201
|
||||
|
||||
#define BT_SDP_ATTR_MPSD_SCENARIOS 0x0200
|
||||
#define BT_SDP_ATTR_MPMD_SCENARIOS 0x0201
|
||||
#define BT_SDP_ATTR_MPS_DEPENDENCIES 0x0202
|
||||
|
||||
#define BT_SDP_ATTR_SERVICE_VERSION 0x0300
|
||||
#define BT_SDP_ATTR_EXTERNAL_NETWORK 0x0301
|
||||
#define BT_SDP_ATTR_SUPPORTED_DATA_STORES_LIST 0x0301
|
||||
#define BT_SDP_ATTR_DATA_EXCHANGE_SPEC 0x0301
|
||||
#define BT_SDP_ATTR_NETWORK 0x0301
|
||||
#define BT_SDP_ATTR_FAX_CLASS1_SUPPORT 0x0302
|
||||
#define BT_SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL 0x0302
|
||||
#define BT_SDP_ATTR_MCAP_SUPPORTED_PROCEDURES 0x0302
|
||||
#define BT_SDP_ATTR_FAX_CLASS20_SUPPORT 0x0303
|
||||
#define BT_SDP_ATTR_SUPPORTED_FORMATS_LIST 0x0303
|
||||
#define BT_SDP_ATTR_FAX_CLASS2_SUPPORT 0x0304
|
||||
#define BT_SDP_ATTR_AUDIO_FEEDBACK_SUPPORT 0x0305
|
||||
#define BT_SDP_ATTR_NETWORK_ADDRESS 0x0306
|
||||
#define BT_SDP_ATTR_WAP_GATEWAY 0x0307
|
||||
#define BT_SDP_ATTR_HOMEPAGE_URL 0x0308
|
||||
#define BT_SDP_ATTR_WAP_STACK_TYPE 0x0309
|
||||
#define BT_SDP_ATTR_SECURITY_DESC 0x030a
|
||||
#define BT_SDP_ATTR_NET_ACCESS_TYPE 0x030b
|
||||
#define BT_SDP_ATTR_MAX_NET_ACCESSRATE 0x030c
|
||||
#define BT_SDP_ATTR_IP4_SUBNET 0x030d
|
||||
#define BT_SDP_ATTR_IP6_SUBNET 0x030e
|
||||
#define BT_SDP_ATTR_SUPPORTED_CAPABILITIES 0x0310
|
||||
#define BT_SDP_ATTR_SUPPORTED_FEATURES 0x0311
|
||||
#define BT_SDP_ATTR_SUPPORTED_FUNCTIONS 0x0312
|
||||
#define BT_SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY 0x0313
|
||||
#define BT_SDP_ATTR_SUPPORTED_REPOSITORIES 0x0314
|
||||
#define BT_SDP_ATTR_MAS_INSTANCE_ID 0x0315
|
||||
#define BT_SDP_ATTR_SUPPORTED_MESSAGE_TYPES 0x0316
|
||||
#define BT_SDP_ATTR_PBAP_SUPPORTED_FEATURES 0x0317
|
||||
#define BT_SDP_ATTR_MAP_SUPPORTED_FEATURES 0x0317
|
||||
|
||||
#define BT_SDP_ATTR_SPECIFICATION_ID 0x0200
|
||||
#define BT_SDP_ATTR_VENDOR_ID 0x0201
|
||||
#define BT_SDP_ATTR_PRODUCT_ID 0x0202
|
||||
#define BT_SDP_ATTR_VERSION 0x0203
|
||||
#define BT_SDP_ATTR_PRIMARY_RECORD 0x0204
|
||||
#define BT_SDP_ATTR_VENDOR_ID_SOURCE 0x0205
|
||||
|
||||
#define BT_SDP_ATTR_HID_DEVICE_RELEASE_NUMBER 0x0200
|
||||
#define BT_SDP_ATTR_HID_PARSER_VERSION 0x0201
|
||||
#define BT_SDP_ATTR_HID_DEVICE_SUBCLASS 0x0202
|
||||
#define BT_SDP_ATTR_HID_COUNTRY_CODE 0x0203
|
||||
#define BT_SDP_ATTR_HID_VIRTUAL_CABLE 0x0204
|
||||
#define BT_SDP_ATTR_HID_RECONNECT_INITIATE 0x0205
|
||||
#define BT_SDP_ATTR_HID_DESCRIPTOR_LIST 0x0206
|
||||
#define BT_SDP_ATTR_HID_LANG_ID_BASE_LIST 0x0207
|
||||
#define BT_SDP_ATTR_HID_SDP_DISABLE 0x0208
|
||||
#define BT_SDP_ATTR_HID_BATTERY_POWER 0x0209
|
||||
#define BT_SDP_ATTR_HID_REMOTE_WAKEUP 0x020a
|
||||
#define BT_SDP_ATTR_HID_PROFILE_VERSION 0x020b
|
||||
#define BT_SDP_ATTR_HID_SUPERVISION_TIMEOUT 0x020c
|
||||
#define BT_SDP_ATTR_HID_NORMALLY_CONNECTABLE 0x020d
|
||||
#define BT_SDP_ATTR_HID_BOOT_DEVICE 0x020e
|
||||
|
||||
/*
|
||||
* These identifiers are based on the SDP spec stating that
|
||||
* "base attribute id of the primary (universal) language must be 0x0100"
|
||||
*
|
||||
* Other languages should have their own offset; e.g.:
|
||||
* #define XXXLangBase yyyy
|
||||
* #define AttrServiceName_XXX 0x0000+XXXLangBase
|
||||
*/
|
||||
#define BT_SDP_PRIMARY_LANG_BASE 0x0100
|
||||
|
||||
#define BT_SDP_ATTR_SVCNAME_PRIMARY (0x0000 + BT_SDP_PRIMARY_LANG_BASE)
|
||||
#define BT_SDP_ATTR_SVCDESC_PRIMARY (0x0001 + BT_SDP_PRIMARY_LANG_BASE)
|
||||
#define BT_SDP_ATTR_PROVNAME_PRIMARY (0x0002 + BT_SDP_PRIMARY_LANG_BASE)
|
||||
|
||||
/*
|
||||
* The Data representation in SDP PDUs (pps 339, 340 of BT SDP Spec)
|
||||
* These are the exact data type+size descriptor values
|
||||
* that go into the PDU buffer.
|
||||
*
|
||||
* The datatype (leading 5bits) + size descriptor (last 3 bits)
|
||||
* is 8 bits. The size descriptor is critical to extract the
|
||||
* right number of bytes for the data value from the PDU.
|
||||
*
|
||||
* For most basic types, the datatype+size descriptor is
|
||||
* straightforward. However for constructed types and strings,
|
||||
* the size of the data is in the next "n" bytes following the
|
||||
* 8 bits (datatype+size) descriptor. Exactly what the "n" is
|
||||
* specified in the 3 bits of the data size descriptor.
|
||||
*
|
||||
* TextString and URLString can be of size 2^{8, 16, 32} bytes
|
||||
* DataSequence and DataSequenceAlternates can be of size 2^{8, 16, 32}
|
||||
* The size are computed post-facto in the API and are not known apriori
|
||||
*/
|
||||
#define BT_SDP_DATA_NIL 0x00
|
||||
#define BT_SDP_UINT8 0x08
|
||||
#define BT_SDP_UINT16 0x09
|
||||
#define BT_SDP_UINT32 0x0a
|
||||
#define BT_SDP_UINT64 0x0b
|
||||
#define BT_SDP_UINT128 0x0c
|
||||
#define BT_SDP_INT8 0x10
|
||||
#define BT_SDP_INT16 0x11
|
||||
#define BT_SDP_INT32 0x12
|
||||
#define BT_SDP_INT64 0x13
|
||||
#define BT_SDP_INT128 0x14
|
||||
#define BT_SDP_UUID_UNSPEC 0x18
|
||||
#define BT_SDP_UUID16 0x19
|
||||
#define BT_SDP_UUID32 0x1a
|
||||
#define BT_SDP_UUID128 0x1c
|
||||
#define BT_SDP_TEXT_STR_UNSPEC 0x20
|
||||
#define BT_SDP_TEXT_STR8 0x25
|
||||
#define BT_SDP_TEXT_STR16 0x26
|
||||
#define BT_SDP_TEXT_STR32 0x27
|
||||
#define BT_SDP_BOOL 0x28
|
||||
#define BT_SDP_SEQ_UNSPEC 0x30
|
||||
#define BT_SDP_SEQ8 0x35
|
||||
#define BT_SDP_SEQ16 0x36
|
||||
#define BT_SDP_SEQ32 0x37
|
||||
#define BT_SDP_ALT_UNSPEC 0x38
|
||||
#define BT_SDP_ALT8 0x3d
|
||||
#define BT_SDP_ALT16 0x3e
|
||||
#define BT_SDP_ALT32 0x3f
|
||||
#define BT_SDP_URL_STR_UNSPEC 0x40
|
||||
#define BT_SDP_URL_STR8 0x45
|
||||
#define BT_SDP_URL_STR16 0x46
|
||||
#define BT_SDP_URL_STR32 0x47
|
||||
|
||||
#define BT_SDP_TYPE_DESC_MASK 0xf8
|
||||
#define BT_SDP_SIZE_DESC_MASK 0x07
|
||||
#define BT_SDP_SIZE_INDEX_OFFSET 5
|
||||
|
||||
/** @brief SDP Generic Data Element Value. */
|
||||
struct bt_sdp_data_elem {
|
||||
u8_t type;
|
||||
u32_t data_size;
|
||||
u32_t total_size;
|
||||
const void *data;
|
||||
};
|
||||
|
||||
/** @brief SDP Attribute Value. */
|
||||
struct bt_sdp_attribute {
|
||||
u16_t id; /* Attribute ID */
|
||||
struct bt_sdp_data_elem val; /* Attribute data */
|
||||
};
|
||||
|
||||
/** @brief SDP Service Record Value. */
|
||||
struct bt_sdp_record {
|
||||
u32_t handle; /* Redundant, for quick ref */
|
||||
struct bt_sdp_attribute *attrs; /* Base addr of attr array */
|
||||
size_t attr_count; /* Number of attributes */
|
||||
u8_t index; /* Index of the record in LL */
|
||||
struct bt_sdp_record *next;
|
||||
};
|
||||
|
||||
/*
|
||||
* --------------------------------------------------- ------------------
|
||||
* | Service Hdl | Attr list ptr | Attr count | Next | -> | Service Hdl | ...
|
||||
* --------------------------------------------------- ------------------
|
||||
*/
|
||||
|
||||
/** @def BT_SDP_ARRAY_8
|
||||
* @brief Declare an array of 8-bit elements in an attribute.
|
||||
*/
|
||||
#define BT_SDP_ARRAY_8(...) ((u8_t[]) {__VA_ARGS__})
|
||||
|
||||
/** @def BT_SDP_ARRAY_16
|
||||
* @brief Declare an array of 16-bit elements in an attribute.
|
||||
*/
|
||||
#define BT_SDP_ARRAY_16(...) ((u16_t[]) {__VA_ARGS__})
|
||||
|
||||
/** @def BT_SDP_ARRAY_32
|
||||
* @brief Declare an array of 32-bit elements in an attribute.
|
||||
*/
|
||||
#define BT_SDP_ARRAY_32(...) ((u32_t[]) {__VA_ARGS__})
|
||||
|
||||
/** @def BT_SDP_TYPE_SIZE
|
||||
* @brief Declare a fixed-size data element header.
|
||||
*
|
||||
* @param _type Data element header containing type and size descriptors.
|
||||
*/
|
||||
#define BT_SDP_TYPE_SIZE(_type) .type = _type, \
|
||||
.data_size = BIT(_type & BT_SDP_SIZE_DESC_MASK), \
|
||||
.total_size = BIT(_type & BT_SDP_SIZE_DESC_MASK) + 1
|
||||
|
||||
/** @def BT_SDP_TYPE_SIZE_VAR
|
||||
* @brief Declare a variable-size data element header.
|
||||
*
|
||||
* @param _type Data element header containing type and size descriptors.
|
||||
* @param _size The actual size of the data.
|
||||
*/
|
||||
#define BT_SDP_TYPE_SIZE_VAR(_type, _size) .type = _type, \
|
||||
.data_size = _size, \
|
||||
.total_size = BIT((_type & BT_SDP_SIZE_DESC_MASK) - \
|
||||
BT_SDP_SIZE_INDEX_OFFSET) + _size + 1
|
||||
|
||||
/** @def BT_SDP_DATA_ELEM_LIST
|
||||
* @brief Declare a list of data elements.
|
||||
*/
|
||||
#define BT_SDP_DATA_ELEM_LIST(...) ((struct bt_sdp_data_elem[]) {__VA_ARGS__})
|
||||
|
||||
|
||||
/** @def BT_SDP_NEW_SERVICE
|
||||
* @brief SDP New Service Record Declaration Macro.
|
||||
*
|
||||
* Helper macro to declare a new service record.
|
||||
* Default attributes: Record Handle, Record State,
|
||||
* Language Base, Root Browse Group
|
||||
*
|
||||
*/
|
||||
#define BT_SDP_NEW_SERVICE \
|
||||
{ \
|
||||
BT_SDP_ATTR_RECORD_HANDLE, \
|
||||
{ BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(0) } \
|
||||
}, \
|
||||
{ \
|
||||
BT_SDP_ATTR_RECORD_STATE, \
|
||||
{ BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(0) } \
|
||||
}, \
|
||||
{ \
|
||||
BT_SDP_ATTR_LANG_BASE_ATTR_ID_LIST, \
|
||||
{ BT_SDP_TYPE_SIZE_VAR(BT_SDP_SEQ8, 9), \
|
||||
BT_SDP_DATA_ELEM_LIST( \
|
||||
{ BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_8('n', 'e') }, \
|
||||
{ BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_16(106) }, \
|
||||
{ BT_SDP_TYPE_SIZE(BT_SDP_UINT16), \
|
||||
BT_SDP_ARRAY_16(BT_SDP_PRIMARY_LANG_BASE) } \
|
||||
), \
|
||||
} \
|
||||
}, \
|
||||
{ \
|
||||
BT_SDP_ATTR_BROWSE_GRP_LIST, \
|
||||
{ BT_SDP_TYPE_SIZE_VAR(BT_SDP_SEQ8, 3), \
|
||||
BT_SDP_DATA_ELEM_LIST( \
|
||||
{ BT_SDP_TYPE_SIZE(BT_SDP_UUID16), \
|
||||
BT_SDP_ARRAY_16(BT_SDP_PUBLIC_BROWSE_GROUP) }, \
|
||||
), \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/** @def BT_SDP_LIST
|
||||
* @brief Generic SDP List Attribute Declaration Macro.
|
||||
*
|
||||
* Helper macro to declare a list attribute.
|
||||
*
|
||||
* @param _att_id List Attribute ID.
|
||||
* @param _data_elem_seq Data element sequence for the list.
|
||||
* @param _type_size SDP type and size descriptor.
|
||||
*/
|
||||
#define BT_SDP_LIST(_att_id, _type_size, _data_elem_seq) \
|
||||
{ \
|
||||
_att_id, { _type_size, _data_elem_seq } \
|
||||
}
|
||||
|
||||
/** @def BT_SDP_SERVICE_ID
|
||||
* @brief SDP Service ID Attribute Declaration Macro.
|
||||
*
|
||||
* Helper macro to declare a service ID attribute.
|
||||
*
|
||||
* @param _uuid Service ID 16bit UUID.
|
||||
*/
|
||||
#define BT_SDP_SERVICE_ID(_uuid) \
|
||||
{ \
|
||||
BT_SDP_ATTR_SERVICE_ID, \
|
||||
{ BT_SDP_TYPE_SIZE(BT_SDP_UUID16), &((struct bt_uuid_16) _uuid) } \
|
||||
}
|
||||
|
||||
/** @def BT_SDP_SERVICE_NAME
|
||||
* @brief SDP Name Attribute Declaration Macro.
|
||||
*
|
||||
* Helper macro to declare a service name attribute.
|
||||
*
|
||||
* @param _name Service name as a string (up to 256 chars).
|
||||
*/
|
||||
#define BT_SDP_SERVICE_NAME(_name) \
|
||||
{ \
|
||||
BT_SDP_ATTR_SVCNAME_PRIMARY, \
|
||||
{ BT_SDP_TYPE_SIZE_VAR(BT_SDP_TEXT_STR8, (sizeof(_name)-1)), _name } \
|
||||
}
|
||||
|
||||
/** @def BT_SDP_SUPPORTED_FEATURES
|
||||
* @brief SDP Supported Features Attribute Declaration Macro.
|
||||
*
|
||||
* Helper macro to declare supported features of a profile/protocol.
|
||||
*
|
||||
* @param _features Feature mask as 16bit unsigned integer.
|
||||
*/
|
||||
#define BT_SDP_SUPPORTED_FEATURES(_features) \
|
||||
{ \
|
||||
BT_SDP_ATTR_SUPPORTED_FEATURES, \
|
||||
{ BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_16(_features) } \
|
||||
}
|
||||
|
||||
/** @def BT_SDP_RECORD
|
||||
* @brief SDP Service Declaration Macro.
|
||||
*
|
||||
* Helper macro to declare a service.
|
||||
*
|
||||
* @param _attrs List of attributes for the service record.
|
||||
*/
|
||||
#define BT_SDP_RECORD(_attrs) \
|
||||
{ \
|
||||
.attrs = _attrs, \
|
||||
.attr_count = ARRAY_SIZE((_attrs)), \
|
||||
}
|
||||
|
||||
/* Server API */
|
||||
|
||||
/** @brief Register a Service Record.
|
||||
*
|
||||
* Register a Service Record. Applications can make use of
|
||||
* macros such as BT_SDP_DECLARE_SERVICE, BT_SDP_LIST,
|
||||
* BT_SDP_SERVICE_ID, BT_SDP_SERVICE_NAME, etc.
|
||||
* A service declaration must start with BT_SDP_NEW_SERVICE.
|
||||
*
|
||||
* @param service Service record declared using BT_SDP_DECLARE_SERVICE.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int bt_sdp_register_service(struct bt_sdp_record *service);
|
||||
|
||||
/* Client API */
|
||||
|
||||
/** @brief Generic SDP Client Query Result data holder */
|
||||
struct bt_sdp_client_result {
|
||||
/* buffer containing unparsed SDP record result for given UUID */
|
||||
struct net_buf *resp_buf;
|
||||
/* flag pointing that there are more result chunks for given UUID */
|
||||
bool next_record_hint;
|
||||
/* Reference to UUID object on behalf one discovery was started */
|
||||
const struct bt_uuid *uuid;
|
||||
};
|
||||
|
||||
/** @brief Helper enum to be used as return value of bt_sdp_discover_func_t.
|
||||
* The value informs the caller to perform further pending actions or stop them.
|
||||
*/
|
||||
enum {
|
||||
BT_SDP_DISCOVER_UUID_STOP = 0,
|
||||
BT_SDP_DISCOVER_UUID_CONTINUE,
|
||||
};
|
||||
|
||||
/** @typedef bt_sdp_discover_func_t
|
||||
*
|
||||
* @brief Callback type reporting to user that there is a resolved result
|
||||
* on remote for given UUID and the result record buffer can be used by user
|
||||
* for further inspection.
|
||||
*
|
||||
* A function of this type is given by the user to the bt_sdp_discover_params
|
||||
* object. It'll be called on each valid record discovery completion for given
|
||||
* UUID. When UUID resolution gives back no records then NULL is passed
|
||||
* to the user. Otherwise user can get valid record(s) and then the internal
|
||||
* hint 'next record' is set to false saying the UUID resolution is complete or
|
||||
* the hint can be set by caller to true meaning that next record is available
|
||||
* for given UUID.
|
||||
* The returned function value allows the user to control retrieving follow-up
|
||||
* resolved records if any. If the user doesn't want to read more resolved
|
||||
* records for given UUID since current record data fulfills its requirements
|
||||
* then should return BT_SDP_DISCOVER_UUID_STOP. Otherwise returned value means
|
||||
* more subcall iterations are allowable.
|
||||
*
|
||||
* @param conn Connection object identifying connection to queried remote.
|
||||
* @param result Object pointing to logical unparsed SDP record collected on
|
||||
* base of response driven by given UUID.
|
||||
*
|
||||
* @return BT_SDP_DISCOVER_UUID_STOP in case of no more need to read next
|
||||
* record data and continue discovery for given UUID. By returning
|
||||
* BT_SDP_DISCOVER_UUID_CONTINUE user allows this discovery continuation.
|
||||
*/
|
||||
typedef u8_t (*bt_sdp_discover_func_t)
|
||||
(struct bt_conn *conn, struct bt_sdp_client_result *result);
|
||||
|
||||
/** @brief Main user structure used in SDP discovery of remote. */
|
||||
struct bt_sdp_discover_params {
|
||||
sys_snode_t _node;
|
||||
/** UUID (service) to be discovered on remote SDP entity */
|
||||
const struct bt_uuid *uuid;
|
||||
/** Discover callback to be called on resolved SDP record */
|
||||
bt_sdp_discover_func_t func;
|
||||
/** Memory buffer enabled by user for SDP query results */
|
||||
struct net_buf_pool *pool;
|
||||
};
|
||||
|
||||
/** @brief Allows user to start SDP discovery session.
|
||||
*
|
||||
* The function performs SDP service discovery on remote server driven by user
|
||||
* delivered discovery parameters. Discovery session is made as soon as
|
||||
* no SDP transaction is ongoing between peers and if any then this one
|
||||
* is queued to be processed at discovery completion of previous one.
|
||||
* On the service discovery completion the callback function will be
|
||||
* called to get feedback to user about findings.
|
||||
*
|
||||
* @param conn Object identifying connection to remote.
|
||||
* @param params SDP discovery parameters.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
|
||||
int bt_sdp_discover(struct bt_conn *conn,
|
||||
const struct bt_sdp_discover_params *params);
|
||||
|
||||
/** @brief Release waiting SDP discovery request.
|
||||
*
|
||||
* It can cancel valid waiting SDP client request identified by SDP discovery
|
||||
* parameters object.
|
||||
*
|
||||
* @param conn Object identifying connection to remote.
|
||||
* @param params SDP discovery parameters.
|
||||
*
|
||||
* @return 0 in case of success or negative value in case of error.
|
||||
*/
|
||||
int bt_sdp_discover_cancel(struct bt_conn *conn,
|
||||
const struct bt_sdp_discover_params *params);
|
||||
|
||||
|
||||
/* Helper types & functions for SDP client to get essential data from server */
|
||||
|
||||
/** @brief Protocols to be asked about specific parameters */
|
||||
enum bt_sdp_proto {
|
||||
BT_SDP_PROTO_RFCOMM = BT_UUID_RFCOMM_VAL,
|
||||
BT_SDP_PROTO_L2CAP = BT_UUID_L2CAP_VAL,
|
||||
};
|
||||
|
||||
/** @brief Give to user parameter value related to given stacked protocol UUID.
|
||||
*
|
||||
* API extracts specific parameter associated with given protocol UUID
|
||||
* available in Protocol Descriptor List attribute.
|
||||
*
|
||||
* @param buf Original buffered raw record data.
|
||||
* @param proto Known protocol to be checked like RFCOMM or L2CAP.
|
||||
* @param param On success populated by found parameter value.
|
||||
*
|
||||
* @return 0 on success when specific parameter associated with given protocol
|
||||
* value is found, or negative if error occurred during processing.
|
||||
*/
|
||||
int bt_sdp_get_proto_param(const struct net_buf *buf, enum bt_sdp_proto proto,
|
||||
u16_t *param);
|
||||
|
||||
/** @brief Get profile version.
|
||||
*
|
||||
* Helper API extracting remote profile version number. To get it proper
|
||||
* generic profile parameter needs to be selected usually listed in SDP
|
||||
* Interoperability Requirements section for given profile specification.
|
||||
*
|
||||
* @param buf Original buffered raw record data.
|
||||
* @param profile Profile family identifier the profile belongs.
|
||||
* @param version On success populated by found version number.
|
||||
*
|
||||
* @return 0 on success, negative value if error occurred during processing.
|
||||
*/
|
||||
int bt_sdp_get_profile_version(const struct net_buf *buf, u16_t profile,
|
||||
u16_t *version);
|
||||
|
||||
/** @brief Get SupportedFeatures attribute value
|
||||
*
|
||||
* Allows if exposed by remote retrieve SupportedFeature attribute.
|
||||
*
|
||||
* @param buf Buffer holding original raw record data from remote.
|
||||
* @param features On success object to be populated with SupportedFeature
|
||||
* mask.
|
||||
*
|
||||
* @return 0 on success if feature found and valid, negative in case any error
|
||||
*/
|
||||
int bt_sdp_get_features(const struct net_buf *buf, u16_t *features);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_SDP_H */
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
/** @file
|
||||
* @brief Bluetooth subsystem persistent storage APIs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_STORAGE_H
|
||||
#define __BT_STORAGE_H
|
||||
|
||||
/**
|
||||
* @brief Persistent Storage
|
||||
* @defgroup bt_storage Persistent Storage
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Well known storage keys */
|
||||
enum {
|
||||
/** Identity Address.
|
||||
* Type: bt_addr_le_t (7 bytes)
|
||||
*/
|
||||
BT_STORAGE_ID_ADDR,
|
||||
|
||||
/** Local Identity Resolving Key.
|
||||
* Type: u8_t key[16]
|
||||
*/
|
||||
BT_STORAGE_LOCAL_IRK,
|
||||
|
||||
/** List of addresses of remote devices.
|
||||
* Type: bt_addr_le_t addrs[n] (length is variable).
|
||||
*
|
||||
* This is only used for reading. Modification of the list happens
|
||||
* implicitly by writing entries for each remote device. This value
|
||||
* is only used with the local storage, i.e. NULL as the target
|
||||
* bt_addr_le_t passed to the read callback.
|
||||
*/
|
||||
BT_STORAGE_ADDRESSES,
|
||||
|
||||
/** Slave Long Term Key for legacy pairing.
|
||||
* Type: struct bt_storage_ltk
|
||||
*/
|
||||
BT_STORAGE_SLAVE_LTK,
|
||||
|
||||
/** Long Term Key for legacy pairing.
|
||||
* Type: struct bt_storage_ltk
|
||||
*/
|
||||
BT_STORAGE_LTK,
|
||||
|
||||
/** Identity Resolving Key
|
||||
* Type: u8_t key[16]
|
||||
*/
|
||||
BT_STORAGE_IRK,
|
||||
};
|
||||
|
||||
/** LTK key flags */
|
||||
enum {
|
||||
/* Key has been generated with MITM protection */
|
||||
BT_STORAGE_LTK_AUTHENTICATED = BIT(0),
|
||||
|
||||
/* Key has been generated using the LE Secure Connection pairing */
|
||||
BT_STORAGE_LTK_SC = BIT(1),
|
||||
};
|
||||
|
||||
struct bt_storage_ltk {
|
||||
u8_t flags;
|
||||
/* Encryption key size used to generate key */
|
||||
u8_t size;
|
||||
u16_t ediv;
|
||||
u8_t rand[8];
|
||||
u8_t val[16];
|
||||
};
|
||||
|
||||
struct bt_storage {
|
||||
/** Read the value of a key from storage.
|
||||
*
|
||||
* @param addr Remote address or NULL for local storage
|
||||
* @param key BT_STORAGE_* key to read
|
||||
* @param data Memory location to place the data
|
||||
* @param length Maximum number of bytes to read
|
||||
*
|
||||
* @return Number of bytes read or negative error value on
|
||||
* failure.
|
||||
*/
|
||||
ssize_t (*read)(const bt_addr_le_t *addr, u16_t key,
|
||||
void *data, size_t length);
|
||||
|
||||
/** Write the value of a key to storage.
|
||||
*
|
||||
* @param addr Remote address or NULL for local storage
|
||||
* @param key BT_STORAGE_* key to write
|
||||
* @param data Memory location of the data
|
||||
* @param length Number of bytes to write
|
||||
*
|
||||
* @return Number of bytes written or negative error value on
|
||||
* failure.
|
||||
*/
|
||||
ssize_t (*write)(const bt_addr_le_t *addr, u16_t key,
|
||||
const void *data, size_t length);
|
||||
|
||||
/** Clear all keys for a specific address
|
||||
*
|
||||
* @param addr Remote address, BT_ADDR_LE_ANY for all
|
||||
* remote devices, or NULL for local storage.
|
||||
*
|
||||
* @return 0 on success or negative error value on failure.
|
||||
*/
|
||||
int (*clear)(const bt_addr_le_t *addr);
|
||||
|
||||
};
|
||||
|
||||
/** Register callbacks for storage handling.
|
||||
*
|
||||
* @param storage Callback struct.
|
||||
*/
|
||||
void bt_storage_register(const struct bt_storage *storage);
|
||||
|
||||
/** Clear all storage keys for a specific address
|
||||
*
|
||||
* @param addr Remote address, NULL for local storage or
|
||||
* BT_ADDR_LE_ANY to clear all remote devices.
|
||||
*
|
||||
* @return 0 on success or negative error value on failure.
|
||||
*/
|
||||
int bt_storage_clear(const bt_addr_le_t *addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_STORAGE_H */
|
||||
580
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/uuid.h
Normal file
580
Living_SDK/kernel/protocols/bluetooth/include/bluetooth/uuid.h
Normal file
|
|
@ -0,0 +1,580 @@
|
|||
/** @file
|
||||
* @brief Bluetooth UUID handling
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015-2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_UUID_H
|
||||
#define __BT_UUID_H
|
||||
|
||||
/**
|
||||
* @brief UUIDs
|
||||
* @defgroup bt_uuid UUIDs
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <misc/util.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Bluetooth UUID types */
|
||||
enum {
|
||||
BT_UUID_TYPE_16,
|
||||
BT_UUID_TYPE_32,
|
||||
BT_UUID_TYPE_128,
|
||||
};
|
||||
|
||||
/** @brief This is a 'tentative' type and should be used as a pointer only */
|
||||
struct bt_uuid {
|
||||
u8_t type;
|
||||
};
|
||||
|
||||
struct bt_uuid_16 {
|
||||
struct bt_uuid uuid;
|
||||
u16_t val;
|
||||
};
|
||||
|
||||
struct bt_uuid_32 {
|
||||
struct bt_uuid uuid;
|
||||
u32_t val;
|
||||
};
|
||||
|
||||
struct bt_uuid_128 {
|
||||
struct bt_uuid uuid;
|
||||
u8_t val[16];
|
||||
};
|
||||
|
||||
#define BT_UUID_INIT_16(value) \
|
||||
{ \
|
||||
.uuid.type = BT_UUID_TYPE_16, \
|
||||
.val = (value), \
|
||||
}
|
||||
|
||||
#define BT_UUID_INIT_32(value) \
|
||||
{ \
|
||||
.uuid.type = BT_UUID_TYPE_32, \
|
||||
.val = (value), \
|
||||
}
|
||||
|
||||
#define BT_UUID_INIT_128(value...) \
|
||||
{ \
|
||||
.uuid.type = BT_UUID_TYPE_128, \
|
||||
.val = { value }, \
|
||||
}
|
||||
|
||||
#define BT_UUID_DECLARE_16(value) \
|
||||
((struct bt_uuid *) (&(struct bt_uuid_16) BT_UUID_INIT_16(value)))
|
||||
#define BT_UUID_DECLARE_32(value) \
|
||||
((struct bt_uuid *) (&(struct bt_uuid_32) BT_UUID_INIT_32(value)))
|
||||
#define BT_UUID_DECLARE_128(value...) \
|
||||
((struct bt_uuid *) (&(struct bt_uuid_128) BT_UUID_INIT_128(value)))
|
||||
|
||||
#define BT_UUID_16(__u) CONTAINER_OF(__u, struct bt_uuid_16, uuid)
|
||||
#define BT_UUID_32(__u) CONTAINER_OF(__u, struct bt_uuid_32, uuid)
|
||||
#define BT_UUID_128(__u) CONTAINER_OF(__u, struct bt_uuid_128, uuid)
|
||||
|
||||
/** @def BT_UUID_GAP
|
||||
* @brief Generic Access
|
||||
*/
|
||||
#define BT_UUID_GAP BT_UUID_DECLARE_16(0x1800)
|
||||
#define BT_UUID_GAP_VAL 0x1800
|
||||
/** @def BT_UUID_GATT
|
||||
* @brief Generic Attribute
|
||||
*/
|
||||
#define BT_UUID_GATT BT_UUID_DECLARE_16(0x1801)
|
||||
#define BT_UUID_GATT_VAL 0x1801
|
||||
/** @def BT_UUID_CTS
|
||||
* @brief Current Time Service
|
||||
*/
|
||||
#define BT_UUID_CTS BT_UUID_DECLARE_16(0x1805)
|
||||
#define BT_UUID_CTS_VAL 0x1805
|
||||
/** @def BT_UUID_DIS
|
||||
* @brief Device Information Service
|
||||
*/
|
||||
#define BT_UUID_DIS BT_UUID_DECLARE_16(0x180a)
|
||||
#define BT_UUID_DIS_VAL 0x180a
|
||||
/** @def BT_UUID_HRS
|
||||
* @brief Heart Rate Service
|
||||
*/
|
||||
#define BT_UUID_HRS BT_UUID_DECLARE_16(0x180d)
|
||||
#define BT_UUID_HRS_VAL 0x180d
|
||||
/** @def BT_UUID_BAS
|
||||
* @brief Battery Service
|
||||
*/
|
||||
#define BT_UUID_BAS BT_UUID_DECLARE_16(0x180f)
|
||||
#define BT_UUID_BAS_VAL 0x180f
|
||||
/** @def BT_UUID_HIDS
|
||||
* @brief HID Service
|
||||
*/
|
||||
#define BT_UUID_HIDS BT_UUID_DECLARE_16(0x1812)
|
||||
#define BT_UUID_HIDS_VAL 0x1812
|
||||
/** @def BT_UUID_CSC
|
||||
* @brief Cycling Speed and Cadence Service
|
||||
*/
|
||||
#define BT_UUID_CSC BT_UUID_DECLARE_16(0x1816)
|
||||
#define BT_UUID_CSC_VAL 0x1816
|
||||
/** @def BT_UUID_ESS
|
||||
* @brief Environmental Sensing Service
|
||||
*/
|
||||
#define BT_UUID_ESS BT_UUID_DECLARE_16(0x181a)
|
||||
#define BT_UUID_ESS_VAL 0x181a
|
||||
/** @def BT_UUID_IPSS
|
||||
* @brief IP Support Service
|
||||
*/
|
||||
#define BT_UUID_IPSS BT_UUID_DECLARE_16(0x1820)
|
||||
#define BT_UUID_IPSS_VAL 0x1820
|
||||
/** @def BT_UUID_MESH_PROV
|
||||
* @brief Mesh Provisioning Service
|
||||
*/
|
||||
#define BT_UUID_MESH_PROV BT_UUID_DECLARE_16(0x1827)
|
||||
#define BT_UUID_MESH_PROV_VAL 0x1827
|
||||
/** @def BT_UUID_MESH_PROXY
|
||||
* @brief Mesh Proxy Service
|
||||
*/
|
||||
#define BT_UUID_MESH_PROXY BT_UUID_DECLARE_16(0x1828)
|
||||
#define BT_UUID_MESH_PROXY_VAL 0x1828
|
||||
/** @def BT_UUID_GATT_PRIMARY
|
||||
* @brief GATT Primary Service
|
||||
*/
|
||||
#define BT_UUID_GATT_PRIMARY BT_UUID_DECLARE_16(0x2800)
|
||||
#define BT_UUID_GATT_PRIMARY_VAL 0x2800
|
||||
/** @def BT_UUID_GATT_SECONDARY
|
||||
* @brief GATT Secondary Service
|
||||
*/
|
||||
#define BT_UUID_GATT_SECONDARY BT_UUID_DECLARE_16(0x2801)
|
||||
#define BT_UUID_GATT_SECONDARY_VAL 0x2801
|
||||
/** @def BT_UUID_GATT_INCLUDE
|
||||
* @brief GATT Include Service
|
||||
*/
|
||||
#define BT_UUID_GATT_INCLUDE BT_UUID_DECLARE_16(0x2802)
|
||||
#define BT_UUID_GATT_INCLUDE_VAL 0x2802
|
||||
/** @def BT_UUID_GATT_CHRC
|
||||
* @brief GATT Characteristic
|
||||
*/
|
||||
#define BT_UUID_GATT_CHRC BT_UUID_DECLARE_16(0x2803)
|
||||
#define BT_UUID_GATT_CHRC_VAL 0x2803
|
||||
/** @def BT_UUID_GATT_CEP
|
||||
* @brief GATT Characteristic Extended Properties
|
||||
*/
|
||||
#define BT_UUID_GATT_CEP BT_UUID_DECLARE_16(0x2900)
|
||||
#define BT_UUID_GATT_CEP_VAL 0x2900
|
||||
/** @def BT_UUID_GATT_CUD
|
||||
* @brief GATT Characteristic User Description
|
||||
*/
|
||||
#define BT_UUID_GATT_CUD BT_UUID_DECLARE_16(0x2901)
|
||||
#define BT_UUID_GATT_CUD_VAL 0x2901
|
||||
/** @def BT_UUID_GATT_CCC
|
||||
* @brief GATT Client Characteristic Configuration
|
||||
*/
|
||||
#define BT_UUID_GATT_CCC BT_UUID_DECLARE_16(0x2902)
|
||||
#define BT_UUID_GATT_CCC_VAL 0x2902
|
||||
/** @def BT_UUID_GATT_SCC
|
||||
* @brief GATT Server Characteristic Configuration
|
||||
*/
|
||||
#define BT_UUID_GATT_SCC BT_UUID_DECLARE_16(0x2903)
|
||||
#define BT_UUID_GATT_SCC_VAL 0x2903
|
||||
/** @def BT_UUID_GATT_CPF
|
||||
* @brief GATT Characteristic Presentation Format
|
||||
*/
|
||||
#define BT_UUID_GATT_CPF BT_UUID_DECLARE_16(0x2904)
|
||||
#define BT_UUID_GATT_CPF_VAL 0x2904
|
||||
/** @def BT_UUID_VALID_RANGE
|
||||
* @brief Valid Range Descriptor
|
||||
*/
|
||||
#define BT_UUID_VALID_RANGE BT_UUID_DECLARE_16(0x2906)
|
||||
#define BT_UUID_VALID_RANGE_VAL 0x2906
|
||||
/** @def BT_UUID_HIDS_EXT_REPORT
|
||||
* @brief HID External Report Descriptor
|
||||
*/
|
||||
#define BT_UUID_HIDS_EXT_REPORT BT_UUID_DECLARE_16(0x2907)
|
||||
#define BT_UUID_HIDS_EXT_REPORT_VAL 0x2907
|
||||
/** @def BT_UUID_HIDS_REPORT_REF
|
||||
* @brief HID Report Reference Descriptor
|
||||
*/
|
||||
#define BT_UUID_HIDS_REPORT_REF BT_UUID_DECLARE_16(0x2908)
|
||||
#define BT_UUID_HIDS_REPORT_REF_VAL 0x2908
|
||||
/** @def BT_UUID_ES_CONFIGURATION
|
||||
* @brief Environmental Sensing Configuration Descriptor
|
||||
*/
|
||||
#define BT_UUID_ES_CONFIGURATION BT_UUID_DECLARE_16(0x290b)
|
||||
#define BT_UUID_ES_CONFIGURATION_VAL 0x290b
|
||||
/** @def BT_UUID_ES_MEASUREMENT
|
||||
* @brief Environmental Sensing Measurement Descriptor
|
||||
*/
|
||||
#define BT_UUID_ES_MEASUREMENT BT_UUID_DECLARE_16(0x290c)
|
||||
#define BT_UUID_ES_MEASUREMENT_VAL 0x290c
|
||||
/** @def BT_UUID_ES_TRIGGER_SETTING
|
||||
* @brief Environmental Sensing Trigger Setting Descriptor
|
||||
*/
|
||||
#define BT_UUID_ES_TRIGGER_SETTING BT_UUID_DECLARE_16(0x290d)
|
||||
#define BT_UUID_ES_TRIGGER_SETTING_VAL 0x290d
|
||||
/** @def BT_UUID_GAP_DEVICE_NAME
|
||||
* @brief GAP Characteristic Device Name
|
||||
*/
|
||||
#define BT_UUID_GAP_DEVICE_NAME BT_UUID_DECLARE_16(0x2a00)
|
||||
#define BT_UUID_GAP_DEVICE_NAME_VAL 0x2a00
|
||||
/** @def BT_UUID_GAP_APPEARANCE
|
||||
* @brief GAP Characteristic Appearance
|
||||
*/
|
||||
#define BT_UUID_GAP_APPEARANCE BT_UUID_DECLARE_16(0x2a01)
|
||||
#define BT_UUID_GAP_APPEARANCE_VAL 0x2a01
|
||||
/** @def BT_UUID_GAP_PPCP
|
||||
* @brief GAP Characteristic Peripheral Preferred Connection Parameters
|
||||
*/
|
||||
#define BT_UUID_GAP_PPCP BT_UUID_DECLARE_16(0x2a04)
|
||||
#define BT_UUID_GAP_PPCP_VAL 0x2a04
|
||||
/** @def BT_UUID_GATT_SC
|
||||
* @brief GATT Characteristic Service Changed
|
||||
*/
|
||||
#define BT_UUID_GATT_SC BT_UUID_DECLARE_16(0x2a05)
|
||||
#define BT_UUID_GATT_SC_VAL 0x2a05
|
||||
/** @def BT_UUID_BAS_BATTERY_LEVEL
|
||||
* @brief BAS Characteristic Battery Level
|
||||
*/
|
||||
#define BT_UUID_BAS_BATTERY_LEVEL BT_UUID_DECLARE_16(0x2a19)
|
||||
#define BT_UUID_BAS_BATTERY_LEVEL_VAL 0x2a19
|
||||
/** @def BT_UUID_DIS_SYSTEM_ID
|
||||
* @brief DIS Characteristic System ID
|
||||
*/
|
||||
#define BT_UUID_DIS_SYSTEM_ID BT_UUID_DECLARE_16(0x2a23)
|
||||
#define BT_UUID_DIS_SYSTEM_ID_VAL 0x2a23
|
||||
/** @def BT_UUID_DIS_MODEL_NUMBER
|
||||
* @brief DIS Characteristic Model Number String
|
||||
*/
|
||||
#define BT_UUID_DIS_MODEL_NUMBER BT_UUID_DECLARE_16(0x2a24)
|
||||
#define BT_UUID_DIS_MODEL_NUMBER_VAL 0x2a24
|
||||
/** @def BT_UUID_DIS_SERIAL_NUMBER
|
||||
* @brief DIS Characteristic Serial Number String
|
||||
*/
|
||||
#define BT_UUID_DIS_SERIAL_NUMBER BT_UUID_DECLARE_16(0x2a25)
|
||||
#define BT_UUID_DIS_SERIAL_NUMBER_VAL 0x2a25
|
||||
/** @def BT_UUID_DIS_FIRMWARE_REVISION
|
||||
* @brief DIS Characteristic Firmware Revision String
|
||||
*/
|
||||
#define BT_UUID_DIS_FIRMWARE_REVISION BT_UUID_DECLARE_16(0x2a26)
|
||||
#define BT_UUID_DIS_FIRMWARE_REVISION_VAL 0x2a26
|
||||
/** @def BT_UUID_DIS_HARDWARE_REVISION
|
||||
* @brief DIS Characteristic Hardware Revision String
|
||||
*/
|
||||
#define BT_UUID_DIS_HARDWARE_REVISION BT_UUID_DECLARE_16(0x2a27)
|
||||
#define BT_UUID_DIS_HARDWARE_REVISION_VAL 0x2a27
|
||||
/** @def BT_UUID_DIS_SOFTWARE_REVISION
|
||||
* @brief DIS Characteristic Software Revision String
|
||||
*/
|
||||
#define BT_UUID_DIS_SOFTWARE_REVISION BT_UUID_DECLARE_16(0x2a28)
|
||||
#define BT_UUID_DIS_SOFTWARE_REVISION_VAL 0x2a28
|
||||
/** @def BT_UUID_DIS_MANUFACTURER_NAME
|
||||
* @brief DIS Characteristic Manufacturer Name String
|
||||
*/
|
||||
#define BT_UUID_DIS_MANUFACTURER_NAME BT_UUID_DECLARE_16(0x2a29)
|
||||
#define BT_UUID_DIS_MANUFACTURER_NAME_VAL 0x2a29
|
||||
/** @def BT_UUID_DIS_PNP_ID
|
||||
* @brief DIS Characteristic PnP ID
|
||||
*/
|
||||
#define BT_UUID_DIS_PNP_ID BT_UUID_DECLARE_16(0x2a50)
|
||||
#define BT_UUID_DIS_PNP_ID_VAL 0x2a50
|
||||
/** @def BT_UUID_CTS_CURRENT_TIME
|
||||
* @brief CTS Characteristic Current Time
|
||||
*/
|
||||
#define BT_UUID_CTS_CURRENT_TIME BT_UUID_DECLARE_16(0x2a2b)
|
||||
#define BT_UUID_CTS_CURRENT_TIME_VAL 0x2a2b
|
||||
/** @def BT_UUID_MAGN_DECLINATION
|
||||
* @brief Magnetic Declination Characteristic
|
||||
*/
|
||||
#define BT_UUID_MAGN_DECLINATION BT_UUID_DECLARE_16(0x2a2c)
|
||||
#define BT_UUID_MAGN_DECLINATION_VAL 0x2a2c
|
||||
/** @def BT_UUID_HRS_MEASUREMENT
|
||||
* @brief HRS Characteristic Measurement Interval
|
||||
*/
|
||||
#define BT_UUID_HRS_MEASUREMENT BT_UUID_DECLARE_16(0x2a37)
|
||||
#define BT_UUID_HRS_MEASUREMENT_VAL 0x2a37
|
||||
/** @def BT_UUID_HRS_BODY_SENSOR
|
||||
* @brief HRS Characteristic Body Sensor Location
|
||||
*/
|
||||
#define BT_UUID_HRS_BODY_SENSOR BT_UUID_DECLARE_16(0x2a38)
|
||||
#define BT_UUID_HRS_BODY_SENSOR_VAL 0x2a38
|
||||
/** @def BT_UUID_HRS_CONTROL_POINT
|
||||
* @brief HRS Characteristic Control Point
|
||||
*/
|
||||
#define BT_UUID_HRS_CONTROL_POINT BT_UUID_DECLARE_16(0x2a39)
|
||||
#define BT_UUID_HRS_CONTROL_POINT_VAL 0x2a39
|
||||
/** @def BT_UUID_HIDS_INFO
|
||||
* @brief HID Information Characteristic
|
||||
*/
|
||||
#define BT_UUID_HIDS_INFO BT_UUID_DECLARE_16(0x2a4a)
|
||||
#define BT_UUID_HIDS_INFO_VAL 0x2a4a
|
||||
/** @def BT_UUID_HIDS_REPORT_MAP
|
||||
* @brief HID Report Map Characteristic
|
||||
*/
|
||||
#define BT_UUID_HIDS_REPORT_MAP BT_UUID_DECLARE_16(0x2a4b)
|
||||
#define BT_UUID_HIDS_REPORT_MAP_VAL 0x2a4b
|
||||
/** @def BT_UUID_HIDS_CTRL_POINT
|
||||
* @brief HID Control Point Characteristic
|
||||
*/
|
||||
#define BT_UUID_HIDS_CTRL_POINT BT_UUID_DECLARE_16(0x2a4c)
|
||||
#define BT_UUID_HIDS_CTRL_POINT_VAL 0x2a4c
|
||||
/** @def BT_UUID_HIDS_REPORT
|
||||
* @brief HID Report Characteristic
|
||||
*/
|
||||
#define BT_UUID_HIDS_REPORT BT_UUID_DECLARE_16(0x2a4d)
|
||||
#define BT_UUID_HIDS_REPORT_VAL 0x2a4d
|
||||
/** @def BT_UUID_CSC_MEASUREMENT
|
||||
* @brief CSC Measurement Characteristic
|
||||
*/
|
||||
#define BT_UUID_CSC_MEASUREMENT BT_UUID_DECLARE_16(0x2a5b)
|
||||
#define BT_UUID_CSC_MEASUREMENT_VAL 0x2a5b
|
||||
/** @def BT_UUID_CSC_FEATURE
|
||||
* @brief CSC Feature Characteristic
|
||||
*/
|
||||
#define BT_UUID_CSC_FEATURE BT_UUID_DECLARE_16(0x2a5c)
|
||||
#define BT_UUID_CSC_FEATURE_VAL 0x2a5c
|
||||
/** @def BT_UUID_SENSOR_LOCATION
|
||||
* @brief Sensor Location Characteristic
|
||||
*/
|
||||
#define BT_UUID_SENSOR_LOCATION BT_UUID_DECLARE_16(0x2a5d)
|
||||
#define BT_UUID_SENSOR_LOCATION_VAL 0x2a5d
|
||||
/** @def BT_UUID_SC_CONTROL_POINT
|
||||
* @brief SC Control Point Characteristic
|
||||
*/
|
||||
#define BT_UUID_SC_CONTROL_POINT BT_UUID_DECLARE_16(0x2a55)
|
||||
#define BT_UUID_SC_CONTROL_POINT_VAl 0x2a55
|
||||
/** @def BT_UUID_ELEVATION
|
||||
* @brief Elevation Characteristic
|
||||
*/
|
||||
#define BT_UUID_ELEVATION BT_UUID_DECLARE_16(0x2a6c)
|
||||
#define BT_UUID_ELEVATION_VAL 0x2a6c
|
||||
/** @def BT_UUID_PRESSURE
|
||||
* @brief Pressure Characteristic
|
||||
*/
|
||||
#define BT_UUID_PRESSURE BT_UUID_DECLARE_16(0x2a6d)
|
||||
#define BT_UUID_PRESSURE_VAL 0x2a6d
|
||||
/** @def BT_UUID_TEMPERATURE
|
||||
* @brief Temperature Characteristic
|
||||
*/
|
||||
#define BT_UUID_TEMPERATURE BT_UUID_DECLARE_16(0x2a6e)
|
||||
#define BT_UUID_TEMPERATURE_VAL 0x2a6e
|
||||
/** @def BT_UUID_HUMIDITY
|
||||
* @brief Humidity Characteristic
|
||||
*/
|
||||
#define BT_UUID_HUMIDITY BT_UUID_DECLARE_16(0x2a6f)
|
||||
#define BT_UUID_HUMIDITY_VAL 0x2a6f
|
||||
/** @def BT_UUID_TRUE_WIND_SPEED
|
||||
* @brief True Wind Speed Characteristic
|
||||
*/
|
||||
#define BT_UUID_TRUE_WIND_SPEED BT_UUID_DECLARE_16(0x2a70)
|
||||
#define BT_UUID_TRUE_WIND_SPEED_VAL 0x2a70
|
||||
/** @def BT_UUID_TRUE_WIND_DIR
|
||||
* @brief True Wind Direction Characteristic
|
||||
*/
|
||||
#define BT_UUID_TRUE_WIND_DIR BT_UUID_DECLARE_16(0x2a71)
|
||||
#define BT_UUID_TRUE_WIND_DIR_VAL 0x2a71
|
||||
/** @def BT_UUID_APPARENT_WIND_SPEED
|
||||
* @brief Apparent Wind Speed Characteristic
|
||||
*/
|
||||
#define BT_UUID_APPARENT_WIND_SPEED BT_UUID_DECLARE_16(0x2a72)
|
||||
#define BT_UUID_APPARENT_WIND_SPEED_VAL 0x2a72
|
||||
/** @def BT_UUID_APPARENT_WIND_DIR
|
||||
* @brief Apparent Wind Direction Characteristic
|
||||
*/
|
||||
#define BT_UUID_APPARENT_WIND_DIR BT_UUID_DECLARE_16(0x2a73)
|
||||
#define BT_UUID_APPARENT_WIND_DIR_VAL 0x2a73
|
||||
/** @def BT_UUID_GUST_FACTOR
|
||||
* @brief Gust Factor Characteristic
|
||||
*/
|
||||
#define BT_UUID_GUST_FACTOR BT_UUID_DECLARE_16(0x2a74)
|
||||
#define BT_UUID_GUST_FACTOR_VAL 0x2a74
|
||||
/** @def BT_UUID_POLLEN_CONCENTRATION
|
||||
* @brief Pollen Concentration Characteristic
|
||||
*/
|
||||
#define BT_UUID_POLLEN_CONCENTRATION BT_UUID_DECLARE_16(0x2a75)
|
||||
#define BT_UUID_POLLEN_CONCENTRATION_VAL 0x2a75
|
||||
/** @def BT_UUID_UV_INDEX
|
||||
* @brief UV Index Characteristic
|
||||
*/
|
||||
#define BT_UUID_UV_INDEX BT_UUID_DECLARE_16(0x2a76)
|
||||
#define BT_UUID_UV_INDEX_VAL 0x2a76
|
||||
/** @def BT_UUID_IRRADIANCE
|
||||
* @brief Irradiance Characteristic
|
||||
*/
|
||||
#define BT_UUID_IRRADIANCE BT_UUID_DECLARE_16(0x2a77)
|
||||
#define BT_UUID_IRRADIANCE_VAL 0x2a77
|
||||
/** @def BT_UUID_RAINFALL
|
||||
* @brief Rainfall Characteristic
|
||||
*/
|
||||
#define BT_UUID_RAINFALL BT_UUID_DECLARE_16(0x2a78)
|
||||
#define BT_UUID_RAINFALL_VAL 0x2a78
|
||||
/** @def BT_UUID_WIND_CHILL
|
||||
* @brief Wind Chill Characteristic
|
||||
*/
|
||||
#define BT_UUID_WIND_CHILL BT_UUID_DECLARE_16(0x2a79)
|
||||
#define BT_UUID_WIND_CHILL_VAL 0x2a79
|
||||
/** @def BT_UUID_HEAT_INDEX
|
||||
* @brief Heat Index Characteristic
|
||||
*/
|
||||
#define BT_UUID_HEAT_INDEX BT_UUID_DECLARE_16(0x2a7a)
|
||||
#define BT_UUID_HEAT_INDEX_VAL 0x2a7a
|
||||
/** @def BT_UUID_DEW_POINT
|
||||
* @brief Dew Point Characteristic
|
||||
*/
|
||||
#define BT_UUID_DEW_POINT BT_UUID_DECLARE_16(0x2a7b)
|
||||
#define BT_UUID_DEW_POINT_VAL 0x2a7b
|
||||
/** @def BT_UUID_DESC_VALUE_CHANGED
|
||||
* @brief Descriptor Value Changed Characteristic
|
||||
*/
|
||||
#define BT_UUID_DESC_VALUE_CHANGED BT_UUID_DECLARE_16(0x2a7d)
|
||||
#define BT_UUID_DESC_VALUE_CHANGED_VAL 0x2a7d
|
||||
/** @def BT_UUID_MAGN_FLUX_DENSITY_2D
|
||||
* @brief Magnetic Flux Density - 2D Characteristic
|
||||
*/
|
||||
#define BT_UUID_MAGN_FLUX_DENSITY_2D BT_UUID_DECLARE_16(0x2aa0)
|
||||
#define BT_UUID_MAGN_FLUX_DENSITY_2D_VAL 0x2aa0
|
||||
/** @def BT_UUID_MAGN_FLUX_DENSITY_3D
|
||||
* @brief Magnetic Flux Density - 3D Characteristic
|
||||
*/
|
||||
#define BT_UUID_MAGN_FLUX_DENSITY_3D BT_UUID_DECLARE_16(0x2aa1)
|
||||
#define BT_UUID_MAGN_FLUX_DENSITY_3D_VAL 0x2aa1
|
||||
/** @def BT_UUID_BAR_PRESSURE_TREND
|
||||
* @brief Barometric Pressure Trend Characteristic
|
||||
*/
|
||||
#define BT_UUID_BAR_PRESSURE_TREND BT_UUID_DECLARE_16(0x2aa3)
|
||||
#define BT_UUID_BAR_PRESSURE_TREND_VAL 0x2aa3
|
||||
/** @def BT_UUID_MESH_PROV_DATA_IN
|
||||
* @brief Mesh Provisioning Data In
|
||||
*/
|
||||
#define BT_UUID_MESH_PROV_DATA_IN BT_UUID_DECLARE_16(0x2adb)
|
||||
#define BT_UUID_MESH_PROV_DATA_IN_VAL 0x2adb
|
||||
/** @def BT_UUID_MESH_PROV_DATA_OUT
|
||||
* @brief Mesh Provisioning Data Out
|
||||
*/
|
||||
#define BT_UUID_MESH_PROV_DATA_OUT BT_UUID_DECLARE_16(0x2adc)
|
||||
#define BT_UUID_MESH_PROV_DATA_OUT_VAL 0x2adc
|
||||
/** @def BT_UUID_MESH_PROXY_DATA_IN
|
||||
* @brief Mesh Proxy Data In
|
||||
*/
|
||||
#define BT_UUID_MESH_PROXY_DATA_IN BT_UUID_DECLARE_16(0x2add)
|
||||
#define BT_UUID_MESH_PROXY_DATA_IN_VAL 0x2add
|
||||
/** @def BT_UUID_MESH_PROXY_DATA_OUT
|
||||
* @brief Mesh Proxy Data Out
|
||||
*/
|
||||
#define BT_UUID_MESH_PROXY_DATA_OUT BT_UUID_DECLARE_16(0x2ade)
|
||||
#define BT_UUID_MESH_PROXY_DATA_OUT_VAL 0x2ade
|
||||
|
||||
/*
|
||||
* Protocol UUIDs
|
||||
*/
|
||||
#define BT_UUID_SDP BT_UUID_DECLARE_16(0x0001)
|
||||
#define BT_UUID_SDP_VAL 0x0001
|
||||
#define BT_UUID_UDP BT_UUID_DECLARE_16(0x0002)
|
||||
#define BT_UUID_UDP_VAL 0x0002
|
||||
#define BT_UUID_RFCOMM BT_UUID_DECLARE_16(0x0003)
|
||||
#define BT_UUID_RFCOMM_VAL 0x0003
|
||||
#define BT_UUID_TCP BT_UUID_DECLARE_16(0x0004)
|
||||
#define BT_UUID_TCP_VAL 0x0004
|
||||
#define BT_UUID_TCS_BIN BT_UUID_DECLARE_16(0x0005)
|
||||
#define BT_UUID_TCS_BIN_VAL 0x0005
|
||||
#define BT_UUID_TCS_AT BT_UUID_DECLARE_16(0x0006)
|
||||
#define BT_UUID_TCS_AT_VAL 0x0006
|
||||
#define BT_UUID_ATT BT_UUID_DECLARE_16(0x0007)
|
||||
#define BT_UUID_ATT_VAL 0x0007
|
||||
#define BT_UUID_OBEX BT_UUID_DECLARE_16(0x0008)
|
||||
#define BT_UUID_OBEX_VAL 0x0008
|
||||
#define BT_UUID_IP BT_UUID_DECLARE_16(0x0009)
|
||||
#define BT_UUID_IP_VAL 0x0009
|
||||
#define BT_UUID_FTP BT_UUID_DECLARE_16(0x000a)
|
||||
#define BT_UUID_FTP_VAL 0x000a
|
||||
#define BT_UUID_HTTP BT_UUID_DECLARE_16(0x000c)
|
||||
#define BT_UUID_HTTP_VAL 0x000c
|
||||
#define BT_UUID_BNEP BT_UUID_DECLARE_16(0x000f)
|
||||
#define BT_UUID_BNEP_VAL 0x000f
|
||||
#define BT_UUID_UPNP BT_UUID_DECLARE_16(0x0010)
|
||||
#define BT_UUID_UPNP_VAL 0x0010
|
||||
#define BT_UUID_HIDP BT_UUID_DECLARE_16(0x0011)
|
||||
#define BT_UUID_HIDP_VAL 0x0011
|
||||
#define BT_UUID_HCRP_CTRL BT_UUID_DECLARE_16(0x0012)
|
||||
#define BT_UUID_HCRP_CTRL_VAL 0x0012
|
||||
#define BT_UUID_HCRP_DATA BT_UUID_DECLARE_16(0x0014)
|
||||
#define BT_UUID_HCRP_DATA_VAL 0x0014
|
||||
#define BT_UUID_HCRP_NOTE BT_UUID_DECLARE_16(0x0016)
|
||||
#define BT_UUID_HCRP_NOTE_VAL 0x0016
|
||||
#define BT_UUID_AVCTP BT_UUID_DECLARE_16(0x0017)
|
||||
#define BT_UUID_AVCTP_VAL 0x0017
|
||||
#define BT_UUID_AVDTP BT_UUID_DECLARE_16(0x0019)
|
||||
#define BT_UUID_AVDTP_VAL 0x0019
|
||||
#define BT_UUID_CMTP BT_UUID_DECLARE_16(0x001b)
|
||||
#define BT_UUID_CMTP_VAL 0x001b
|
||||
#define BT_UUID_UDI BT_UUID_DECLARE_16(0x001d)
|
||||
#define BT_UUID_UDI_VAL 0x001d
|
||||
#define BT_UUID_MCAP_CTRL BT_UUID_DECLARE_16(0x001e)
|
||||
#define BT_UUID_MCAP_CTRL_VAL 0x001e
|
||||
#define BT_UUID_MCAP_DATA BT_UUID_DECLARE_16(0x001f)
|
||||
#define BT_UUID_MCAP_DATA_VAL 0x001f
|
||||
#define BT_UUID_L2CAP BT_UUID_DECLARE_16(0x0100)
|
||||
#define BT_UUID_L2CAP_VAL 0x0100
|
||||
|
||||
|
||||
/** @brief Compare Bluetooth UUIDs.
|
||||
*
|
||||
* Compares 2 Bluetooth UUIDs, if the types are different both UUIDs are
|
||||
* first converted to 128 bits format before comparing.
|
||||
*
|
||||
* @param u1 First Bluetooth UUID to compare
|
||||
* @param u2 Second Bluetooth UUID to compare
|
||||
*
|
||||
* @return negative value if @a u1 < @a u2, 0 if @a u1 == @a u2, else positive
|
||||
*/
|
||||
int bt_uuid_cmp(const struct bt_uuid *u1, const struct bt_uuid *u2);
|
||||
|
||||
#if defined(CONFIG_BT_DEBUG)
|
||||
/** @brief Convert Bluetooth UUID to string.
|
||||
*
|
||||
* Converts Bluetooth UUID to string. UUID has to be in 16 bits or 128 bits
|
||||
* format.
|
||||
*
|
||||
* @param uuid Bluetooth UUID
|
||||
* @param str pointer where to put converted string
|
||||
* @param len length of str
|
||||
*
|
||||
* @return N/A
|
||||
*/
|
||||
void bt_uuid_to_str(const struct bt_uuid *uuid, char *str, size_t len);
|
||||
|
||||
/** @brief Convert Bluetooth UUID to string in place.
|
||||
*
|
||||
* Converts Bluetooth UUID to string in place. UUID has to be in 16 bits or
|
||||
* 128 bits format.
|
||||
*
|
||||
* @param uuid Bluetooth UUID
|
||||
*
|
||||
* @return String representation of the UUID given
|
||||
*/
|
||||
const char *bt_uuid_str(const struct bt_uuid *uuid);
|
||||
#else
|
||||
static inline void bt_uuid_to_str(const struct bt_uuid *uuid, char *str,
|
||||
size_t len)
|
||||
{
|
||||
if (len > 0) {
|
||||
str[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char *bt_uuid_str(const struct bt_uuid *uuid)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
#endif /* CONFIG_BT_DEBUG */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_UUID_H */
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
/** @file
|
||||
* @brief Bluetooth HCI driver API.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015-2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __BT_HCI_DRIVER_H
|
||||
#define __BT_HCI_DRIVER_H
|
||||
|
||||
/**
|
||||
* @brief HCI drivers
|
||||
* @defgroup bt_hci_driver HCI drivers
|
||||
* @ingroup bluetooth
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <net/buf.h>
|
||||
#include <bluetooth/buf.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Check if an HCI event is high priority or not.
|
||||
*
|
||||
* Helper for the HCI driver to know which events are ok to be passed
|
||||
* through the RX thread and which must be given to bt_recv_prio() from
|
||||
* another context (e.g. ISR). If this function returns true it's safe
|
||||
* to pass the event through the RX thread, however if it returns false
|
||||
* then this risks a deadlock.
|
||||
*
|
||||
* @param evt HCI event code.
|
||||
*
|
||||
* @return true if the event can be processed in the RX thread, false
|
||||
* if it cannot.
|
||||
*/
|
||||
static inline bool bt_hci_evt_is_prio(u8_t evt)
|
||||
{
|
||||
switch (evt) {
|
||||
case BT_HCI_EVT_CMD_COMPLETE:
|
||||
case BT_HCI_EVT_CMD_STATUS:
|
||||
#if defined(CONFIG_BT_CONN)
|
||||
case BT_HCI_EVT_NUM_COMPLETED_PACKETS:
|
||||
#endif
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive data from the controller/HCI driver.
|
||||
*
|
||||
* This is the main function through which the HCI driver provides the
|
||||
* host with data from the controller. The buffer needs to have its type
|
||||
* set with the help of bt_buf_set_type() before calling this API. This API
|
||||
* should not be used for so-called high priority HCI events, which should
|
||||
* instead be delivered to the host stack through bt_recv_prio().
|
||||
*
|
||||
* @param buf Network buffer containing data from the controller.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
int bt_recv(struct net_buf *buf);
|
||||
|
||||
/**
|
||||
* @brief Receive high priority data from the controller/HCI driver.
|
||||
*
|
||||
* This is the same as bt_recv(), except that it should be used for
|
||||
* so-called high priority HCI events. There's a separate
|
||||
* bt_hci_evt_is_prio() helper that can be used to identify which events
|
||||
* are high priority.
|
||||
*
|
||||
* As with bt_recv(), the buffer needs to have its type set with the help of
|
||||
* bt_buf_set_type() before calling this API. The only exception is so called
|
||||
* high priority HCI events which should be delivered to the host stack through
|
||||
* bt_recv_prio() instead.
|
||||
*
|
||||
* @param buf Network buffer containing data from the controller.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
int bt_recv_prio(struct net_buf *buf);
|
||||
|
||||
/** Possible values for the 'bus' member of the bt_hci_driver struct */
|
||||
enum bt_hci_driver_bus {
|
||||
BT_HCI_DRIVER_BUS_VIRTUAL = 0,
|
||||
BT_HCI_DRIVER_BUS_USB = 1,
|
||||
BT_HCI_DRIVER_BUS_PCCARD = 2,
|
||||
BT_HCI_DRIVER_BUS_UART = 3,
|
||||
BT_HCI_DRIVER_BUS_RS232 = 4,
|
||||
BT_HCI_DRIVER_BUS_PCI = 5,
|
||||
BT_HCI_DRIVER_BUS_SDIO = 6,
|
||||
BT_HCI_DRIVER_BUS_SPI = 7,
|
||||
BT_HCI_DRIVER_BUS_I2C = 8,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Abstraction which represents the HCI transport to the controller.
|
||||
*
|
||||
* This struct is used to represent the HCI transport to the Bluetooth
|
||||
* controller.
|
||||
*/
|
||||
struct bt_hci_driver {
|
||||
/** Name of the driver */
|
||||
const char *name;
|
||||
|
||||
/** Bus of the transport (BT_HCI_DRIVER_BUS_*) */
|
||||
enum bt_hci_driver_bus bus;
|
||||
|
||||
/**
|
||||
* @brief Open the HCI transport.
|
||||
*
|
||||
* Opens the HCI transport for operation. This function must not
|
||||
* return until the transport is ready for operation, meaning it
|
||||
* is safe to start calling the send() handler.
|
||||
*
|
||||
* If the driver uses its own RX thread, i.e.
|
||||
* CONFIG_BT_RECV_IS_RX_THREAD is set, then this
|
||||
* function is expected to start that thread.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
int (*open)(void);
|
||||
|
||||
/**
|
||||
* @brief Send HCI buffer to controller.
|
||||
*
|
||||
* Send an HCI command or ACL data to the controller. The exact
|
||||
* type of the data can be checked with the help of bt_buf_get_type().
|
||||
*
|
||||
* @note This function must only be called from a cooperative thread.
|
||||
*
|
||||
* @param buf Buffer containing data to be sent to the controller.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
int (*send)(struct net_buf *buf);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Register a new HCI driver to the Bluetooth stack.
|
||||
*
|
||||
* This needs to be called before any application code runs. The bt_enable()
|
||||
* API will fail if there is no driver registered.
|
||||
*
|
||||
* @param drv A bt_hci_driver struct representing the driver.
|
||||
*
|
||||
* @return 0 on success or negative error number on failure.
|
||||
*/
|
||||
int bt_hci_driver_register(const struct bt_hci_driver *drv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __BT_HCI_DRIVER_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue