Bluetooth: Add support for vendor-specific events
Add an event handler for HCI vendor-specific events with the event code BT_HCI_EVT_VENDOR. A vendor defined callback can be registered to be called when vendor-Specific events are received in the stack. The callback can then decode and handle the event; if not the stack will decode and handle the event. Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
This commit is contained in:
parent
b800737f72
commit
5e1de1a983
3 changed files with 66 additions and 0 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <misc/util.h>
|
#include <misc/util.h>
|
||||||
|
#include <net/buf.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -1914,6 +1915,28 @@ int bt_hci_cmd_send(u16_t opcode, struct net_buf *buf);
|
||||||
int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf,
|
int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf,
|
||||||
struct net_buf **rsp);
|
struct net_buf **rsp);
|
||||||
|
|
||||||
|
/** @typedef bt_hci_vnd_evt_cb_t
|
||||||
|
* @brief Callback type for vendor handling of HCI Vendor-Specific Events.
|
||||||
|
*
|
||||||
|
* A function of this type is registered with bt_hci_register_vnd_evt_cb()
|
||||||
|
* and will be called for any HCI Vendor-Specific Event.
|
||||||
|
*
|
||||||
|
* @param buf Buffer containing event parameters.
|
||||||
|
*
|
||||||
|
* @return true if the function handles the event or false to defer the
|
||||||
|
* handling of this event back to the stack.
|
||||||
|
*/
|
||||||
|
typedef bool bt_hci_vnd_evt_cb_t(struct net_buf_simple *buf);
|
||||||
|
|
||||||
|
/** Register user callback for HCI Vendor-Specific Events
|
||||||
|
*
|
||||||
|
* @param cb Callback to be called when the stack receives a
|
||||||
|
* HCI Vendor-Specific Event.
|
||||||
|
*
|
||||||
|
* @return 0 on success or negative error value on failure.
|
||||||
|
*/
|
||||||
|
int bt_hci_register_vnd_evt_cb(bt_hci_vnd_evt_cb_t cb);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -590,3 +590,9 @@ config BT_PAGE_TIMEOUT
|
||||||
(N * 0.625) ms.
|
(N * 0.625) ms.
|
||||||
|
|
||||||
endif # BT_BREDR
|
endif # BT_BREDR
|
||||||
|
|
||||||
|
config BT_HCI_VS_EVT_USER
|
||||||
|
bool "User Vendor-Specific event handling"
|
||||||
|
help
|
||||||
|
Enable registering a callback for delegating to the user the handling of
|
||||||
|
VS events that are not known to the stack
|
||||||
|
|
|
@ -83,6 +83,10 @@ static bt_ready_cb_t ready_cb;
|
||||||
|
|
||||||
static bt_le_scan_cb_t *scan_dev_found_cb;
|
static bt_le_scan_cb_t *scan_dev_found_cb;
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_HCI_VS_EVT_USER)
|
||||||
|
static bt_hci_vnd_evt_cb_t *hci_vnd_evt_cb;
|
||||||
|
#endif /* CONFIG_BT_HCI_VS_EVT_USER */
|
||||||
|
|
||||||
#if defined(CONFIG_BT_ECC)
|
#if defined(CONFIG_BT_ECC)
|
||||||
static u8_t pub_key[64];
|
static u8_t pub_key[64];
|
||||||
static struct bt_pub_key_cb *pub_key_cb;
|
static struct bt_pub_key_cb *pub_key_cb;
|
||||||
|
@ -3370,6 +3374,37 @@ static void le_adv_report(struct net_buf *buf)
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_OBSERVER */
|
#endif /* CONFIG_BT_OBSERVER */
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_HCI_VS_EVT_USER)
|
||||||
|
int bt_hci_register_vnd_evt_cb(bt_hci_vnd_evt_cb_t cb)
|
||||||
|
{
|
||||||
|
hci_vnd_evt_cb = cb;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BT_HCI_VS_EVT_USER */
|
||||||
|
|
||||||
|
static void hci_vendor_event(struct net_buf *buf)
|
||||||
|
{
|
||||||
|
bool handled = false;
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_HCI_VS_EVT_USER)
|
||||||
|
if (hci_vnd_evt_cb) {
|
||||||
|
struct net_buf_simple_state state;
|
||||||
|
|
||||||
|
net_buf_simple_save(&buf->b, &state);
|
||||||
|
|
||||||
|
handled = hci_vnd_evt_cb(&buf->b);
|
||||||
|
|
||||||
|
net_buf_simple_restore(&buf->b, &state);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BT_HCI_VS_EVT_USER */
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_BT_HCI_VS_EXT) && !handled) {
|
||||||
|
/* do nothing at present time */
|
||||||
|
BT_WARN("Unhandled vendor-specific event: %s",
|
||||||
|
bt_hex(buf->data, buf->len));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const struct event_handler meta_events[] = {
|
static const struct event_handler meta_events[] = {
|
||||||
#if defined(CONFIG_BT_OBSERVER)
|
#if defined(CONFIG_BT_OBSERVER)
|
||||||
EVENT_HANDLER(BT_HCI_EVT_LE_ADVERTISING_REPORT, le_adv_report,
|
EVENT_HANDLER(BT_HCI_EVT_LE_ADVERTISING_REPORT, le_adv_report,
|
||||||
|
@ -3422,6 +3457,8 @@ static void hci_le_meta_event(struct net_buf *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct event_handler normal_events[] = {
|
static const struct event_handler normal_events[] = {
|
||||||
|
EVENT_HANDLER(BT_HCI_EVT_VENDOR, hci_vendor_event,
|
||||||
|
sizeof(struct bt_hci_evt_vs)),
|
||||||
EVENT_HANDLER(BT_HCI_EVT_LE_META_EVENT, hci_le_meta_event,
|
EVENT_HANDLER(BT_HCI_EVT_LE_META_EVENT, hci_le_meta_event,
|
||||||
sizeof(struct bt_hci_evt_le_meta_event)),
|
sizeof(struct bt_hci_evt_le_meta_event)),
|
||||||
#if defined(CONFIG_BT_BREDR)
|
#if defined(CONFIG_BT_BREDR)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue