From bdc10744fb338ae197692713a0b48a7ccc36f566 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 26 Apr 2020 10:25:59 +0200 Subject: Add Nimble in libs directory --- src/libs/mynewt-nimble/nimble/include/nimble/ble.h | 304 ++++ .../nimble/include/nimble/ble_hci_trans.h | 192 +++ .../nimble/include/nimble/hci_common.h | 1536 ++++++++++++++++++++ .../nimble/include/nimble/nimble_npl.h | 174 +++ .../nimble/include/nimble/nimble_opt.h | 34 + .../nimble/include/nimble/nimble_opt_auto.h | 117 ++ 6 files changed, 2357 insertions(+) create mode 100644 src/libs/mynewt-nimble/nimble/include/nimble/ble.h create mode 100644 src/libs/mynewt-nimble/nimble/include/nimble/ble_hci_trans.h create mode 100644 src/libs/mynewt-nimble/nimble/include/nimble/hci_common.h create mode 100644 src/libs/mynewt-nimble/nimble/include/nimble/nimble_npl.h create mode 100644 src/libs/mynewt-nimble/nimble/include/nimble/nimble_opt.h create mode 100644 src/libs/mynewt-nimble/nimble/include/nimble/nimble_opt_auto.h (limited to 'src/libs/mynewt-nimble/nimble/include') diff --git a/src/libs/mynewt-nimble/nimble/include/nimble/ble.h b/src/libs/mynewt-nimble/nimble/include/nimble/ble.h new file mode 100644 index 00000000..3fc2902e --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/include/nimble/ble.h @@ -0,0 +1,304 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_BLE_ +#define H_BLE_ + +#include +#include +#include "syscfg/syscfg.h" +#include "os/os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* The number of advertising instances */ +#define BLE_ADV_INSTANCES (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) + 1) + +/* BLE encryption block definitions */ +#define BLE_ENC_BLOCK_SIZE (16) + +/* 4 byte header + 251 byte payload. */ +#define BLE_ACL_MAX_PKT_SIZE 255 + +struct ble_encryption_block +{ + uint8_t key[BLE_ENC_BLOCK_SIZE]; + uint8_t plain_text[BLE_ENC_BLOCK_SIZE]; + uint8_t cipher_text[BLE_ENC_BLOCK_SIZE]; +}; + +/* + * BLE MBUF structure: + * + * The BLE mbuf structure is as follows. Note that this structure applies to + * the packet header mbuf (not mbufs that are part of a "packet chain"): + * struct os_mbuf (16) + * struct os_mbuf_pkthdr (8) + * struct ble_mbuf_hdr (8) + * Data buffer (payload size, in bytes) + * + * The BLE mbuf header contains the following: + * flags: bitfield with the following values + * 0x01: Set if there was a match on the whitelist + * 0x02: Set if a connect request was transmitted upon receiving pdu + * 0x04: Set the first time we transmit the PDU (used to detect retry). + * channel: The logical BLE channel PHY channel # (0 - 39) + * crcok: flag denoting CRC check passed (1) or failed (0). + * rssi: RSSI, in dBm. + */ +struct ble_mbuf_hdr_rxinfo +{ + uint16_t flags; + uint8_t channel; + uint8_t handle; + int8_t rssi; + /* XXX: we could just use single phy_mode field */ + int8_t phy; + uint8_t phy_mode; +#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) + int8_t rpa_index; +#endif +#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) + void *user_data; +#endif +}; + +/* Flag definitions for rxinfo */ +#define BLE_MBUF_HDR_F_IGNORED (0x8000) +#define BLE_MBUF_HDR_F_SCAN_REQ_TXD (0x4000) +#define BLE_MBUF_HDR_F_INITA_RESOLVED (0x2000) +#define BLE_MBUF_HDR_F_TARGETA_RESOLVED (0x2000) +#define BLE_MBUF_HDR_F_EXT_ADV_SEC (0x1000) +#define BLE_MBUF_HDR_F_EXT_ADV (0x0800) +#define BLE_MBUF_HDR_F_RESOLVED (0x0400) +#define BLE_MBUF_HDR_F_AUX_PTR_WAIT (0x0200) +#define BLE_MBUF_HDR_F_AUX_INVALID (0x0100) +#define BLE_MBUF_HDR_F_CRC_OK (0x0080) +#define BLE_MBUF_HDR_F_DEVMATCH (0x0040) +#define BLE_MBUF_HDR_F_MIC_FAILURE (0x0020) +#define BLE_MBUF_HDR_F_SCAN_RSP_TXD (0x0010) +#define BLE_MBUF_HDR_F_SCAN_RSP_RXD (0x0008) +#define BLE_MBUF_HDR_F_RXSTATE_MASK (0x0007) + +/* Transmit info. NOTE: no flags defined */ +struct ble_mbuf_hdr_txinfo +{ + uint8_t flags; + uint8_t offset; + uint8_t pyld_len; + uint8_t hdr_byte; +}; + +struct ble_mbuf_hdr +{ + union { + struct ble_mbuf_hdr_rxinfo rxinfo; + struct ble_mbuf_hdr_txinfo txinfo; + }; + uint32_t beg_cputime; + uint32_t rem_usecs; +}; + +#define BLE_MBUF_HDR_IGNORED(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_IGNORED)) + +#define BLE_MBUF_HDR_SCAN_REQ_TXD(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_SCAN_REQ_TXD)) + +#define BLE_MBUF_HDR_EXT_ADV_SEC(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_EXT_ADV_SEC)) + +#define BLE_MBUF_HDR_EXT_ADV(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_EXT_ADV)) + +#define BLE_MBUF_HDR_DEVMATCH(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_DEVMATCH)) + +#define BLE_MBUF_HDR_SCAN_RSP_RXD(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_SCAN_RSP_RXD)) + +#define BLE_MBUF_HDR_AUX_INVALID(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_AUX_INVALID)) + +#define BLE_MBUF_HDR_WAIT_AUX(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_AUX_PTR_WAIT)) + +#define BLE_MBUF_HDR_CRC_OK(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_CRC_OK)) + +#define BLE_MBUF_HDR_MIC_FAILURE(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_MIC_FAILURE)) + +#define BLE_MBUF_HDR_RESOLVED(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_RESOLVED)) + +#define BLE_MBUF_HDR_INITA_RESOLVED(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_INITA_RESOLVED)) + +#define BLE_MBUF_HDR_TARGETA_RESOLVED(hdr) \ + (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_TARGETA_RESOLVED)) + +#define BLE_MBUF_HDR_RX_STATE(hdr) \ + ((uint8_t)((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_RXSTATE_MASK)) + +#define BLE_MBUF_HDR_PTR(om) \ + (struct ble_mbuf_hdr *)((uint8_t *)om + sizeof(struct os_mbuf) + \ + sizeof(struct os_mbuf_pkthdr)) + +/* BLE mbuf overhead per packet header mbuf */ +#define BLE_MBUF_PKTHDR_OVERHEAD \ + (sizeof(struct os_mbuf_pkthdr) + sizeof(struct ble_mbuf_hdr)) + +#define BLE_MBUF_MEMBLOCK_OVERHEAD \ + (sizeof(struct os_mbuf) + BLE_MBUF_PKTHDR_OVERHEAD) + +/* Length of host user header. Only contains the peer's connection handle. */ +#define BLE_MBUF_HS_HDR_LEN (2) + +#define BLE_DEV_ADDR_LEN (6) +extern uint8_t g_dev_addr[BLE_DEV_ADDR_LEN]; +extern uint8_t g_random_addr[BLE_DEV_ADDR_LEN]; + +/* BLE Error Codes (Core v4.2 Vol 2 part D) */ +enum ble_error_codes +{ + /* An "error" code of 0x0 means success */ + BLE_ERR_SUCCESS = 0x00, + BLE_ERR_UNKNOWN_HCI_CMD = 0x01, + BLE_ERR_UNK_CONN_ID = 0x02, + BLE_ERR_HW_FAIL = 0x03, + BLE_ERR_PAGE_TMO = 0x04, + BLE_ERR_AUTH_FAIL = 0x05, + BLE_ERR_PINKEY_MISSING = 0x06, + BLE_ERR_MEM_CAPACITY = 0x07, + BLE_ERR_CONN_SPVN_TMO = 0x08, + BLE_ERR_CONN_LIMIT = 0x09, + BLE_ERR_SYNCH_CONN_LIMIT = 0x0a, + BLE_ERR_ACL_CONN_EXISTS = 0x0b, + BLE_ERR_CMD_DISALLOWED = 0x0c, + BLE_ERR_CONN_REJ_RESOURCES = 0x0d, + BLE_ERR_CONN_REJ_SECURITY = 0x0e, + BLE_ERR_CONN_REJ_BD_ADDR = 0x0f, + BLE_ERR_CONN_ACCEPT_TMO = 0x10, + BLE_ERR_UNSUPPORTED = 0x11, + BLE_ERR_INV_HCI_CMD_PARMS = 0x12, + BLE_ERR_REM_USER_CONN_TERM = 0x13, + BLE_ERR_RD_CONN_TERM_RESRCS = 0x14, + BLE_ERR_RD_CONN_TERM_PWROFF = 0x15, + BLE_ERR_CONN_TERM_LOCAL = 0x16, + BLE_ERR_REPEATED_ATTEMPTS = 0x17, + BLE_ERR_NO_PAIRING = 0x18, + BLE_ERR_UNK_LMP = 0x19, + BLE_ERR_UNSUPP_REM_FEATURE = 0x1a, + BLE_ERR_SCO_OFFSET = 0x1b, + BLE_ERR_SCO_ITVL = 0x1c, + BLE_ERR_SCO_AIR_MODE = 0x1d, + BLE_ERR_INV_LMP_LL_PARM = 0x1e, + BLE_ERR_UNSPECIFIED = 0x1f, + BLE_ERR_UNSUPP_LMP_LL_PARM = 0x20, + BLE_ERR_NO_ROLE_CHANGE = 0x21, + BLE_ERR_LMP_LL_RSP_TMO = 0x22, + BLE_ERR_LMP_COLLISION = 0x23, + BLE_ERR_LMP_PDU = 0x24, + BLE_ERR_ENCRYPTION_MODE = 0x25, + BLE_ERR_LINK_KEY_CHANGE = 0x26, + BLE_ERR_UNSUPP_QOS = 0x27, + BLE_ERR_INSTANT_PASSED = 0x28, + BLE_ERR_UNIT_KEY_PAIRING = 0x29, + BLE_ERR_DIFF_TRANS_COLL = 0x2a, + /* BLE_ERR_RESERVED = 0x2b */ + BLE_ERR_QOS_PARM = 0x2c, + BLE_ERR_QOS_REJECTED = 0x2d, + BLE_ERR_CHAN_CLASS = 0x2e, + BLE_ERR_INSUFFICIENT_SEC = 0x2f, + BLE_ERR_PARM_OUT_OF_RANGE = 0x30, + /* BLE_ERR_RESERVED = 0x31 */ + BLE_ERR_PENDING_ROLE_SW = 0x32, + /* BLE_ERR_RESERVED = 0x33 */ + BLE_ERR_RESERVED_SLOT = 0x34, + BLE_ERR_ROLE_SW_FAIL = 0x35, + BLE_ERR_INQ_RSP_TOO_BIG = 0x36, + BLE_ERR_SEC_SIMPLE_PAIR = 0x37, + BLE_ERR_HOST_BUSY_PAIR = 0x38, + BLE_ERR_CONN_REJ_CHANNEL = 0x39, + BLE_ERR_CTLR_BUSY = 0x3a, + BLE_ERR_CONN_PARMS = 0x3b, + BLE_ERR_DIR_ADV_TMO = 0x3c, + BLE_ERR_CONN_TERM_MIC = 0x3d, + BLE_ERR_CONN_ESTABLISHMENT = 0x3e, + BLE_ERR_MAC_CONN_FAIL = 0x3f, + BLE_ERR_COARSE_CLK_ADJ = 0x40, + BLE_ERR_TYPE0_SUBMAP_NDEF = 0x41, + BLE_ERR_UNK_ADV_INDENT = 0x42, + BLE_ERR_LIMIT_REACHED = 0x43, + BLE_ERR_OPERATION_CANCELLED = 0x44, + BLE_ERR_PACKET_TOO_LONG = 0x45, + BLE_ERR_MAX = 0xff +}; + +/* HW error codes */ +#define BLE_HW_ERR_DO_NOT_USE (0) /* XXX: reserve this one for now */ +#define BLE_HW_ERR_HCI_SYNC_LOSS (1) + +/* Own Bluetooth Device address type */ +#define BLE_OWN_ADDR_PUBLIC (0x00) +#define BLE_OWN_ADDR_RANDOM (0x01) +#define BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT (0x02) +#define BLE_OWN_ADDR_RPA_RANDOM_DEFAULT (0x03) + +/* Bluetooth Device address type */ +#define BLE_ADDR_PUBLIC (0x00) +#define BLE_ADDR_RANDOM (0x01) +#define BLE_ADDR_PUBLIC_ID (0x02) +#define BLE_ADDR_RANDOM_ID (0x03) + +#define BLE_ADDR_ANY (&(ble_addr_t) { 0, {0, 0, 0, 0, 0, 0} }) + +#define BLE_ADDR_IS_RPA(addr) (((addr)->type == BLE_ADDR_RANDOM) && \ + ((addr)->val[5] & 0xc0) == 0x40) +#define BLE_ADDR_IS_NRPA(addr) (((addr)->type == BLE_ADDR_RANDOM) && \ + ((addr)->val[5] & 0xc0) == 0x00) +#define BLE_ADDR_IS_STATIC(addr) (((addr)->type == BLE_ADDR_RANDOM) && \ + ((addr)->val[5] & 0xc0) == 0xc0) + +typedef struct { + uint8_t type; + uint8_t val[6]; +} ble_addr_t; + + +static inline int ble_addr_cmp(const ble_addr_t *a, const ble_addr_t *b) +{ + int type_diff; + + type_diff = a->type - b->type; + if (type_diff != 0) { + return type_diff; + } + + return memcmp(a->val, b->val, sizeof(a->val)); +} + +#ifdef __cplusplus +} +#endif + +#endif /* H_BLE_ */ diff --git a/src/libs/mynewt-nimble/nimble/include/nimble/ble_hci_trans.h b/src/libs/mynewt-nimble/nimble/include/nimble/ble_hci_trans.h new file mode 100644 index 00000000..e8d3ec03 --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/include/nimble/ble_hci_trans.h @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_HCI_TRANSPORT_ +#define H_HCI_TRANSPORT_ + +#include +#include "os/os_mempool.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct os_mbuf; + +#define BLE_HCI_TRANS_CMD_SZ 260 + +/*** Type of buffers for holding commands and events. */ +/** + * Controller-to-host event buffers. Events have one of two priorities: + * o Low-priority (BLE_HCI_TRANS_BUF_EVT_LO) + * o High-priority (BLE_HCI_TRANS_BUF_EVT_HI) + * + * Low-priority event buffers are only used for advertising reports. If there + * are no free low-priority event buffers, then an incoming advertising report + * will get dropped. + * + * High-priority event buffers are for everything except advertising reports. + * If there are no free high-priority event buffers, a request to allocate one + * will try to allocate a low-priority buffer instead. + * + * If you want all events to be given equal treatment, then you should allocate + * low-priority events only. + * + * Event priorities solve the problem of critical events getting dropped due to + * a flood of advertising reports. This solution is likely temporary: when + * HCI flow control is added, event priorities may become obsolete. + * + * Not all transports distinguish between low and high priority events. If the + * transport does not have separate settings for low and high buffer counts, + * then it treats all events with equal priority. + */ +#define BLE_HCI_TRANS_BUF_EVT_LO 1 +#define BLE_HCI_TRANS_BUF_EVT_HI 2 + +/* Host-to-controller command. */ +#define BLE_HCI_TRANS_BUF_CMD 3 + +/** Callback function types; executed when HCI packets are received. */ +typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg); +typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg); + +/** + * Sends an HCI event from the controller to the host. + * + * @param cmd The HCI event to send. This buffer must be + * allocated via ble_hci_trans_buf_alloc(). + * + * @return 0 on success; + * A BLE_ERR_[...] error code on failure. + */ +int ble_hci_trans_ll_evt_tx(uint8_t *hci_ev); + +/** + * Sends ACL data from controller to host. + * + * @param om The ACL data packet to send. + * + * @return 0 on success; + * A BLE_ERR_[...] error code on failure. + */ +int ble_hci_trans_ll_acl_tx(struct os_mbuf *om); + +/** + * Sends an HCI command from the host to the controller. + * + * @param cmd The HCI command to send. This buffer must be + * allocated via ble_hci_trans_buf_alloc(). + * + * @return 0 on success; + * A BLE_ERR_[...] error code on failure. + */ +int ble_hci_trans_hs_cmd_tx(uint8_t *cmd); + +/** + * Sends ACL data from host to controller. + * + * @param om The ACL data packet to send. + * + * @return 0 on success; + * A BLE_ERR_[...] error code on failure. + */ +int ble_hci_trans_hs_acl_tx(struct os_mbuf *om); + +/** + * Allocates a flat buffer of the specified type. + * + * @param type The type of buffer to allocate; one of the + * BLE_HCI_TRANS_BUF_[...] constants. + * + * @return The allocated buffer on success; + * NULL on buffer exhaustion. + */ +uint8_t *ble_hci_trans_buf_alloc(int type); + +/** + * Frees the specified flat buffer. The buffer must have been allocated via + * ble_hci_trans_buf_alloc(). + * + * @param buf The buffer to free. + */ +void ble_hci_trans_buf_free(uint8_t *buf); + +/** + * Configures a callback to get executed whenever an ACL data packet is freed. + * The function is called immediately before the free occurs. + * + * @param cb The callback to configure. + * @param arg An optional argument to pass to the callback. + * + * @return 0 on success; + * BLE_ERR_UNSUPPORTED if the transport does not + * support this operation. + */ +int ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg); + +/** + * Configures the HCI transport to operate with a controller. The transport + * will execute specified callbacks upon receiving HCI packets from the host. + * + * @param cmd_cb The callback to execute upon receiving an HCI + * command. + * @param cmd_arg Optional argument to pass to the command + * callback. + * @param acl_cb The callback to execute upon receiving ACL + * data. + * @param acl_arg Optional argument to pass to the ACL + * callback. + */ +void ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb, + void *cmd_arg, + ble_hci_trans_rx_acl_fn *acl_cb, + void *acl_arg); + +/** + * Configures the HCI transport to operate with a host. The transport will + * execute specified callbacks upon receiving HCI packets from the controller. + * + * @param evt_cb The callback to execute upon receiving an HCI + * event. + * @param evt_arg Optional argument to pass to the event + * callback. + * @param acl_cb The callback to execute upon receiving ACL + * data. + * @param acl_arg Optional argument to pass to the ACL + * callback. + */ +void ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb, + void *evt_arg, + ble_hci_trans_rx_acl_fn *acl_cb, + void *acl_arg); + +/** + * Resets the HCI module to a clean state. Frees all buffers and reinitializes + * the underlying transport. + * + * @return 0 on success; + * A BLE_ERR_[...] error code on failure. + */ +int ble_hci_trans_reset(void); + +#ifdef __cplusplus +} +#endif + +#endif /* H_HCI_TRANSPORT_ */ diff --git a/src/libs/mynewt-nimble/nimble/include/nimble/hci_common.h b/src/libs/mynewt-nimble/nimble/include/nimble/hci_common.h new file mode 100644 index 00000000..c79abb31 --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/include/nimble/hci_common.h @@ -0,0 +1,1536 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_BLE_HCI_COMMON_ +#define H_BLE_HCI_COMMON_ + +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BLE_HCI_MAX_DATA_LEN (MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE) - \ + sizeof(struct ble_hci_ev)) + +/* Generic command header */ +struct ble_hci_cmd { + uint16_t opcode; + uint8_t length; + uint8_t data[0]; +} __attribute__((packed)); + +/* Generic event header */ +struct ble_hci_ev { + uint8_t opcode; + uint8_t length; + uint8_t data[0]; +} __attribute__((packed)); + +#define BLE_HCI_OPCODE_NOP (0) + +/* Set opcode based on OCF and OGF */ +#define BLE_HCI_OP(ogf, ocf) ((ocf) | ((ogf) << 10)) + +/* Get the OGF and OCF from the opcode in the command */ +#define BLE_HCI_OGF(opcode) (((opcode) >> 10) & 0x003F) +#define BLE_HCI_OCF(opcode) ((opcode) & 0x03FF) + +/* Opcode Group definitions (note: 0x07 not defined in spec) */ +#define BLE_HCI_OGF_LINK_CTRL (0x01) +#define BLE_HCI_OGF_LINK_POLICY (0x02) +#define BLE_HCI_OGF_CTLR_BASEBAND (0x03) +#define BLE_HCI_OGF_INFO_PARAMS (0x04) +#define BLE_HCI_OGF_STATUS_PARAMS (0x05) +#define BLE_HCI_OGF_TESTING (0x06) +#define BLE_HCI_OGF_LE (0x08) +#define BLE_HCI_OGF_VENDOR (0x3F) + +/* + * Number of LE commands. NOTE: this is really just used to size the array + * containing the lengths of the LE commands. + */ +#define BLE_HCI_NUM_LE_CMDS (79) + +/* List of OCF for Link Control commands (OGF=0x01) */ +#define BLE_HCI_OCF_DISCONNECT_CMD (0x0006) +struct ble_hci_lc_disconnect_cp { + uint16_t conn_handle; + uint8_t reason; +} __attribute__((packed)); + +#define BLE_HCI_OCF_RD_REM_VER_INFO (0x001D) +struct ble_hci_rd_rem_ver_info_cp { + uint16_t conn_handle; +} __attribute__((packed)); + +/* List of OCF for Controller and Baseband commands (OGF=0x03) */ +#define BLE_HCI_OCF_CB_SET_EVENT_MASK (0x0001) +struct ble_hci_cb_set_event_mask_cp { + uint64_t event_mask; +} __attribute__((packed)); + +#define BLE_HCI_OCF_CB_RESET (0x0003) + +#define BLE_HCI_OCF_CB_READ_TX_PWR (0x002D) +struct ble_hci_cb_read_tx_pwr_cp { + uint16_t conn_handle; + uint8_t type; +} __attribute__((packed)); + +struct ble_hci_cb_read_tx_pwr_rp { + uint16_t conn_handle; + int8_t tx_level; +} __attribute__((packed)); + + +#define BLE_HCI_OCF_CB_SET_CTLR_TO_HOST_FC (0x0031) +struct ble_hci_cb_ctlr_to_host_fc_cp { + uint8_t enable; +} __attribute__((packed)); + +#define BLE_HCI_OCF_CB_HOST_BUF_SIZE (0x0033) +struct ble_hci_cb_host_buf_size_cp { + uint16_t acl_data_len; + uint16_t sco_data_len; + uint16_t acl_num; + uint16_t sco_num; +} __attribute__((packed)); + +#define BLE_HCI_OCF_CB_HOST_NUM_COMP_PKTS (0x0035) +struct ble_hci_cb_host_num_comp_pkts_entry { + uint16_t handle; + uint16_t count; +} __attribute__((packed)); +struct ble_hci_cb_host_num_comp_pkts_cp { + uint8_t handles; + struct ble_hci_cb_host_num_comp_pkts_entry h[0]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_CB_SET_EVENT_MASK2 (0x0063) +struct ble_hci_cb_set_event_mask2_cp { + uint64_t event_mask2; +} __attribute__((packed)); + +#define BLE_HCI_OCF_CB_RD_AUTH_PYLD_TMO (0x007B) +struct ble_hci_cb_rd_auth_pyld_tmo_cp { + uint16_t conn_handle; +} __attribute__((packed)); +struct ble_hci_cb_rd_auth_pyld_tmo_rp { + uint16_t conn_handle; + uint16_t tmo; +} __attribute__((packed)); + +#define BLE_HCI_OCF_CB_WR_AUTH_PYLD_TMO (0x007C) +struct ble_hci_cb_wr_auth_pyld_tmo_cp { + uint16_t conn_handle; + uint16_t tmo; +} __attribute__((packed)); +struct ble_hci_cb_wr_auth_pyld_tmo_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +/* List of OCF for Info Param commands (OGF=0x04) */ +#define BLE_HCI_OCF_IP_RD_LOCAL_VER (0x0001) +struct ble_hci_ip_rd_local_ver_rp { + uint8_t hci_ver; + uint16_t hci_rev; + uint8_t lmp_ver; + uint16_t manufacturer; + uint16_t lmp_subver; +} __attribute__((packed)); + +#define BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD (0x0002) +struct ble_hci_ip_rd_loc_supp_cmd_rp { + uint8_t commands[64]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT (0x0003) +struct ble_hci_ip_rd_loc_supp_feat_rp { + uint64_t features; +} __attribute__((packed)); + +#define BLE_HCI_OCF_IP_RD_BUF_SIZE (0x0005) +struct ble_hci_ip_rd_buf_size_rp { + uint16_t acl_data_len; + uint8_t sco_data_len; + uint16_t acl_num; + uint16_t sco_num; +} __attribute__((packed)); + +#define BLE_HCI_OCF_IP_RD_BD_ADDR (0x0009) +struct ble_hci_ip_rd_bd_addr_rp { + uint8_t addr[6]; +} __attribute__((packed)); + +/* List of OCF for Status parameters commands (OGF = 0x05) */ +#define BLE_HCI_OCF_RD_RSSI (0x0005) +struct ble_hci_rd_rssi_cp { + uint16_t handle; +} __attribute__((packed)); +struct ble_hci_rd_rssi_rp { + uint16_t handle; + int8_t rssi; +} __attribute__((packed)); + +/* List of OCF for LE commands (OGF = 0x08) */ +#define BLE_HCI_OCF_LE_SET_EVENT_MASK (0x0001) +struct ble_hci_le_set_event_mask_cp { + uint64_t event_mask; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_BUF_SIZE (0x0002) +struct ble_hci_le_rd_buf_size_rp { + uint16_t data_len; + uint8_t data_packets; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT (0x0003) +struct ble_hci_le_rd_loc_supp_feat_rp { + uint64_t features; +} __attribute__((packed)); + +/* NOTE: 0x0004 is intentionally left undefined */ +#define BLE_HCI_OCF_LE_SET_RAND_ADDR (0x0005) +struct ble_hci_le_set_rand_addr_cp { + uint8_t addr[6]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_ADV_PARAMS (0x0006) +struct ble_hci_le_set_adv_params_cp { + uint16_t min_interval; + uint16_t max_interval; + uint8_t type; + uint8_t own_addr_type; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t chan_map; + uint8_t filter_policy; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR (0x0007) +struct ble_hci_le_rd_adv_chan_txpwr_rp { + int8_t power_level; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_ADV_DATA (0x0008) +#define BLE_HCI_MAX_ADV_DATA_LEN (31) +struct ble_hci_le_set_adv_data_cp { + uint8_t adv_data_len; + uint8_t adv_data[BLE_HCI_MAX_ADV_DATA_LEN]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA (0x0009) +#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN (31) +struct ble_hci_le_set_scan_rsp_data_cp { + uint8_t scan_rsp_len; + uint8_t scan_rsp[BLE_HCI_MAX_SCAN_RSP_DATA_LEN]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_ADV_ENABLE (0x000A) +struct ble_hci_le_set_adv_enable_cp { + uint8_t enable; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_SCAN_PARAMS (0x000B) +struct ble_hci_le_set_scan_params_cp { + uint8_t scan_type; + uint16_t scan_itvl; + uint16_t scan_window; + uint8_t own_addr_type; + uint8_t filter_policy; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_SCAN_ENABLE (0x000C) +struct ble_hci_le_set_scan_enable_cp { + uint8_t enable; + uint8_t filter_duplicates; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_CREATE_CONN (0x000D) +struct ble_hci_le_create_conn_cp { + uint16_t scan_itvl; + uint16_t scan_window; + uint8_t filter_policy; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t own_addr_type; + uint16_t min_conn_itvl; + uint16_t max_conn_itvl; + uint16_t conn_latency; + uint16_t tmo; + uint16_t min_ce; + uint16_t max_ce; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_CREATE_CONN_CANCEL (0x000E) + +#define BLE_HCI_OCF_LE_RD_WHITE_LIST_SIZE (0x000F) +struct ble_hci_le_rd_white_list_rp { + uint8_t size; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_CLEAR_WHITE_LIST (0x0010) + +#define BLE_HCI_OCF_LE_ADD_WHITE_LIST (0x0011) +struct ble_hci_le_add_whte_list_cp { + uint8_t addr_type; + uint8_t addr[6]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RMV_WHITE_LIST (0x0012) +struct ble_hci_le_rmv_white_list_cp { + uint8_t addr_type; + uint8_t addr[6]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_CONN_UPDATE (0x0013) +struct ble_hci_le_conn_update_cp { + uint16_t conn_handle; + uint16_t conn_itvl_min; + uint16_t conn_itvl_max; + uint16_t conn_latency; + uint16_t supervision_timeout; + uint16_t min_ce_len; + uint16_t max_ce_len; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS (0x0014) +struct ble_hci_le_set_host_chan_class_cp { + uint8_t chan_map[5]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_CHAN_MAP (0x0015) +struct ble_hci_le_rd_chan_map_cp { + uint16_t conn_handle; +} __attribute__((packed)); +struct ble_hci_le_rd_chan_map_rp { + uint16_t conn_handle; + uint8_t chan_map[5]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_REM_FEAT (0x0016) +struct ble_hci_le_rd_rem_feat_cp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_ENCRYPT (0x0017) +struct ble_hci_le_encrypt_cp { + uint8_t key[16]; + uint8_t data[16]; +} __attribute__((packed)); +struct ble_hci_le_encrypt_rp { + uint8_t data[16]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RAND (0x0018) +struct ble_hci_le_rand_rp { + uint64_t random_number; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_START_ENCRYPT (0x0019) +struct ble_hci_le_start_encrypt_cp { + uint16_t conn_handle; + uint64_t rand; + uint16_t div; + uint8_t ltk[16]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY (0x001A) +struct ble_hci_le_lt_key_req_reply_cp { + uint16_t conn_handle; + uint8_t ltk[16]; +} __attribute__((packed)); +struct ble_hci_le_lt_key_req_reply_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY (0x001B) +struct ble_hci_le_lt_key_req_neg_reply_cp { + uint16_t conn_handle; +} __attribute__((packed)); +struct ble_hci_le_lt_key_req_neg_reply_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_SUPP_STATES (0x001C) +struct ble_hci_le_rd_supp_states_rp { + uint64_t states; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RX_TEST (0x001D) +struct ble_hci_le_rx_test_cp { + uint8_t rx_chan; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_TX_TEST (0x001E) +struct ble_hci_le_tx_test_cp { + uint8_t tx_chan; + uint8_t test_data_len; + uint8_t payload; +} __attribute__((packed)); +#if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS) +struct ble_hci_le_tx_test_ext_cp { + uint8_t tx_chan; + uint8_t test_data_len; + uint8_t payload; + uint16_t interval; + uint16_t pkt_count; +} __attribute__((packed)); +#endif + +#define BLE_HCI_OCF_LE_TEST_END (0x001F) +struct ble_hci_le_test_end_rp { + uint16_t num_packets; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_REM_CONN_PARAM_RR (0x0020) +struct ble_hci_le_rem_conn_param_rr_cp { + uint16_t conn_handle; + uint16_t conn_itvl_min; + uint16_t conn_itvl_max; + uint16_t conn_latency; + uint16_t supervision_timeout; + uint16_t min_ce; + uint16_t max_ce; +} __attribute__((packed)); +struct ble_hci_le_rem_conn_param_rr_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR (0x0021) +struct ble_hci_le_rem_conn_params_nrr_cp { + uint16_t conn_handle; + uint8_t reason; +} __attribute__((packed)); +struct ble_hci_le_rem_conn_params_nrr_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_DATA_LEN (0x0022) +struct ble_hci_le_set_data_len_cp { + uint16_t conn_handle; + uint16_t tx_octets; + uint16_t tx_time; +} __attribute__((packed)); +struct ble_hci_le_set_data_len_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN (0x0023) +struct ble_hci_le_rd_sugg_def_data_len_rp { + uint16_t max_tx_octets; + uint16_t max_tx_time; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN (0x0024) +struct ble_hci_le_wr_sugg_def_data_len_cp { + uint16_t max_tx_octets; + uint16_t max_tx_time; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_P256_PUBKEY (0x0025) + +#define BLE_HCI_OCF_LE_GEN_DHKEY (0x0026) +struct ble_hci_le_gen_dhkey_cp { + uint8_t pkey[64]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_ADD_RESOLV_LIST (0x0027) +struct ble_hci_le_add_resolv_list_cp { + uint8_t peer_addr_type; + uint8_t peer_id_addr[6]; + uint8_t peer_irk[16]; + uint8_t local_irk[16]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RMV_RESOLV_LIST (0x0028) +struct ble_hci_le_rmv_resolve_list_cp { + uint8_t peer_addr_type; + uint8_t peer_id_addr[6]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_CLR_RESOLV_LIST (0x0029) + +#define BLE_HCI_OCF_LE_RD_RESOLV_LIST_SIZE (0x002A) +struct ble_hci_le_rd_resolv_list_size_rp { + uint8_t size; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_PEER_RESOLV_ADDR (0x002B) +struct ble_hci_le_rd_peer_recolv_addr_cp { + uint8_t peer_addr_type; + uint8_t peer_id_addr[6]; +} __attribute__((packed)); +struct ble_hci_le_rd_peer_recolv_addr_rp { + uint8_t rpa[6]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_LOCAL_RESOLV_ADDR (0x002C) +struct ble_hci_le_rd_local_recolv_addr_cp { + uint8_t peer_addr_type; + uint8_t peer_id_addr[6]; +} __attribute__((packed)); +struct ble_hci_le_rd_local_recolv_addr_rp { + uint8_t rpa[6]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_ADDR_RES_EN (0x002D) +struct ble_hci_le_set_addr_res_en_cp { + uint8_t enable; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_RPA_TMO (0x002E) +struct ble_hci_le_set_rpa_tmo_cp { + uint16_t rpa_timeout; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_MAX_DATA_LEN (0x002F) +struct ble_hci_le_rd_max_data_len_rp { + uint16_t max_tx_octests; + uint16_t max_tx_time; + uint16_t max_rx_octests; + uint16_t max_rx_time; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_PHY (0x0030) +struct ble_hci_le_rd_phy_cp { + uint16_t conn_handle; +} __attribute__((packed)); +struct ble_hci_le_rd_phy_rp { + uint16_t conn_handle; + uint8_t tx_phy; + uint8_t rx_phy; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_DEFAULT_PHY (0x0031) +struct ble_hci_le_set_default_phy_cp { + uint8_t all_phys; + uint8_t tx_phys; + uint8_t rx_phys; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_PHY (0x0032) +struct ble_hci_le_set_phy_cp { + uint16_t conn_handle; + uint8_t all_phys; + uint8_t tx_phys; + uint8_t rx_phys; + uint16_t phy_options; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RX_TEST_V2 (0x0033) +struct ble_hci_le_rx_test_v2_cp { + uint8_t rx_chan; + uint8_t phy; + uint8_t index; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_TX_TEST_V2 (0x0034) +struct ble_hci_le_tx_test_v2_cp { + uint8_t tx_chan; + uint8_t test_data_len; + uint8_t payload; + uint8_t phy; +} __attribute__((packed)); +#if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS) +struct ble_hci_le_tx_test_v2_ext_cp { + uint8_t tx_chan; + uint8_t test_data_len; + uint8_t payload; + uint8_t phy; + uint16_t interval; + uint16_t pkt_count; +} __attribute__((packed)); +#endif + +#define BLE_HCI_OCF_LE_SET_ADV_SET_RND_ADDR (0x0035) +struct ble_hci_le_set_adv_set_rnd_addr_cp { + uint8_t adv_handle; + uint8_t addr[6]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_EXT_ADV_PARAM (0x0036) +struct ble_hci_le_set_ext_adv_params_cp { + uint8_t adv_handle; + uint16_t props; + uint8_t pri_itvl_min[3]; + uint8_t pri_itvl_max[3]; + uint8_t pri_chan_map; + uint8_t own_addr_type; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t filter_policy; + int8_t tx_power; + uint8_t pri_phy; + uint8_t sec_max_skip; + uint8_t sec_phy; + uint8_t sid; + uint8_t scan_req_notif; +} __attribute__((packed)); +struct ble_hci_le_set_ext_adv_params_rp { + int8_t tx_power; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_EXT_ADV_DATA (0x0037) +struct ble_hci_le_set_ext_adv_data_cp { + uint8_t adv_handle; + uint8_t operation; + uint8_t fragment_pref; + uint8_t adv_data_len; + uint8_t adv_data[0]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_EXT_SCAN_RSP_DATA (0x0038) +struct ble_hci_le_set_ext_scan_rsp_data_cp { + uint8_t adv_handle; + uint8_t operation; + uint8_t fragment_pref; + uint8_t scan_rsp_len; + uint8_t scan_rsp[0]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_EXT_ADV_ENABLE (0x0039) +struct adv_set { + uint8_t adv_handle; + uint16_t duration; + uint8_t max_events; +} __attribute__((packed)); +struct ble_hci_le_set_ext_adv_enable_cp { + uint8_t enable; + uint8_t num_sets; + struct adv_set sets[0]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_MAX_ADV_DATA_LEN (0x003A) +struct ble_hci_le_rd_max_adv_data_len_rp { + uint16_t max_adv_data_len; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_NUM_OF_ADV_SETS (0x003B) +struct ble_hci_le_rd_num_of_adv_sets_rp { + uint8_t num_sets; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_REMOVE_ADV_SET (0x003C) +struct ble_hci_le_remove_adv_set_cp { + uint8_t adv_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_CLEAR_ADV_SETS (0x003D) + +#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS (0x003E) +struct ble_hci_le_set_periodic_adv_params_cp { + uint8_t adv_handle; + uint16_t min_itvl; + uint16_t max_itvl; + uint16_t props; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_DATA (0x003F) +struct ble_hci_le_set_periodic_adv_data_cp { + uint8_t adv_handle; + uint8_t operation; + uint8_t adv_data_len; + uint8_t adv_data[0]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE (0x0040) +struct ble_hci_le_set_periodic_adv_enable_cp { + uint8_t enable; + uint8_t adv_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_EXT_SCAN_PARAM (0x0041) +struct scan_params { + uint8_t type; + uint16_t itvl; + uint16_t window; +} __attribute__((packed)); +struct ble_hci_le_set_ext_scan_params_cp { + uint8_t own_addr_type; + uint8_t filter_policy; + uint8_t phys; + struct scan_params scans[0]; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_EXT_SCAN_ENABLE (0x0042) +struct ble_hci_le_set_ext_scan_enable_cp { + uint8_t enable; + uint8_t filter_dup; + uint16_t duration; + uint16_t period; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_EXT_CREATE_CONN (0x0043) +struct conn_params { + uint16_t scan_itvl; + uint16_t scan_window; + uint16_t conn_min_itvl; + uint16_t conn_max_itvl; + uint16_t conn_latency; + uint16_t supervision_timeout; + uint16_t min_ce; + uint16_t max_ce; +} __attribute__((packed)); +struct ble_hci_le_ext_create_conn_cp { + uint8_t filter_policy; + uint8_t own_addr_type; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t init_phy_mask; + struct conn_params conn_params[0]; +} __attribute__((packed)); + +#define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_FILTER 0x01 +#define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DISABLED 0x02 + +#define BLE_HCI_OCF_LE_PERIODIC_ADV_CREATE_SYNC (0x0044) +struct ble_hci_le_periodic_adv_create_sync_cp { + uint8_t options; + uint8_t sid; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint16_t skip; + uint16_t sync_timeout; + uint8_t sync_cte_type; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL (0x0045) + +#define BLE_HCI_OCF_LE_PERIODIC_ADV_TERM_SYNC (0x0046) +struct ble_hci_le_periodic_adv_term_sync_cp { + uint16_t sync_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_ADD_DEV_TO_PERIODIC_ADV_LIST (0x0047) +struct ble_hci_le_add_dev_to_periodic_adv_list_cp { + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t sid; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_REM_DEV_FROM_PERIODIC_ADV_LIST (0x0048) +struct ble_hci_le_rem_dev_from_periodic_adv_list_cp { + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t sid; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_CLEAR_PERIODIC_ADV_LIST (0x0049) + +#define BLE_HCI_OCF_LE_RD_PERIODIC_ADV_LIST_SIZE (0x004A) +struct ble_hci_le_rd_periodic_adv_list_size_rp { + uint8_t list_size; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_TRANSMIT_POWER (0x004B) +struct ble_hci_le_rd_transmit_power_rp { + int8_t min_tx_power; + int8_t max_tx_power; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RD_RF_PATH_COMPENSATION (0x004C) +struct ble_hci_le_rd_rf_path_compensation_rp { + int16_t tx_path_compensation; + int16_t rx_path_compensation; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_WR_RF_PATH_COMPENSATION (0x004D) +struct ble_hci_le_wr_rf_path_compensation_cp { + int16_t tx_path_compensation; + int16_t rx_path_compensation; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_PRIVACY_MODE (0x004E) +struct ble_hci_le_set_privacy_mode_cp { + uint8_t peer_id_addr_type; + uint8_t peer_id_addr[6]; + uint8_t mode; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_RX_TEST_V3 (0x004F) +#define BLE_HCI_OCF_LE_TX_TEST_V3 (0x0050) +#define BLE_HCI_OCF_LE_SET_CONNLESS_CTE_TX_PARAMS (0x0051) +#define BLE_HCI_OCF_LE_SET_CONNLESS_CTE_TX_ENABLE (0x0052) +#define BLE_HCI_OCF_LE_SET_CONNLESS_IQ_SAMPLING_ENABLE (0x0053) +#define BLE_HCI_OCF_LE_SET_CONN_CTE_RX_PARAMS (0x0054) +#define BLE_HCI_OCF_LE_SET_CONN_CTE_TX_PARAMS (0x0055) +#define BLE_HCI_OCF_LE_SET_CONN_CTE_REQ_ENABLE (0x0056) +#define BLE_HCI_OCF_LE_SET_CONN_CTE_RESP_ENABLE (0x0057) +#define BLE_HCI_OCF_LE_RD_ANTENNA_INFO (0x0058) + +#define BLE_HCI_OCF_LE_PERIODIC_ADV_RECEIVE_ENABLE (0x0059) +struct ble_hci_le_periodic_adv_receive_enable_cp { + uint16_t sync_handle; + uint8_t enable; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_PERIODIC_ADV_SYNC_TRANSFER (0x005A) +struct ble_hci_le_periodic_adv_sync_transfer_cp { + uint16_t conn_handle; + uint16_t service_data; + uint16_t sync_handle; +} __attribute__((packed)); +struct ble_hci_le_periodic_adv_sync_transfer_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_PERIODIC_ADV_SET_INFO_TRANSFER (0x005B) +struct ble_hci_le_periodic_adv_set_info_transfer_cp { + uint16_t conn_handle; + uint16_t service_data; + uint8_t adv_handle; +} __attribute__((packed)); +struct ble_hci_le_periodic_adv_set_info_transfer_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_PERIODIC_ADV_SYNC_TRANSFER_PARAMS (0x005C) +struct ble_hci_le_periodic_adv_sync_transfer_params_cp { + uint16_t conn_handle; + uint8_t mode; + uint16_t skip; + uint16_t sync_timeout; + uint8_t sync_cte_type; +} __attribute__((packed)); +struct ble_hci_le_periodic_adv_sync_transfer_params_rp { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_SET_DEFAULT_SYNC_TRANSFER_PARAMS (0x005D) +struct ble_hci_le_set_default_periodic_sync_transfer_params_cp { + uint8_t mode; + uint16_t skip; + uint16_t sync_timeout; + uint8_t sync_cte_type; +} __attribute__((packed)); + +#define BLE_HCI_OCF_LE_GENERATE_DHKEY_V2 (0x005E) +#define BLE_HCI_OCF_LE_MODIFY_SCA (0x005F) + +#define BLE_HCI_OCF_LE_SET_HOST_FEAT (0x0074) +struct ble_hci_le_set_host_feat_cp { + uint8_t bit_num; + uint8_t val; +} __attribute__((packed)); + +/* Command Specific Definitions */ +/* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */ +#define BLE_HCI_CTLR_TO_HOST_FC_OFF (0) +#define BLE_HCI_CTLR_TO_HOST_FC_ACL (1) +#define BLE_HCI_CTLR_TO_HOST_FC_SYNC (2) +#define BLE_HCI_CTLR_TO_HOST_FC_BOTH (3) + +/* --- LE set advertising parameters (OCF 0x0006) */ +/* Advertising types */ +#define BLE_HCI_ADV_TYPE_ADV_IND (0) +#define BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD (1) +#define BLE_HCI_ADV_TYPE_ADV_SCAN_IND (2) +#define BLE_HCI_ADV_TYPE_ADV_NONCONN_IND (3) +#define BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD (4) +#define BLE_HCI_ADV_TYPE_MAX (4) + +#define BLE_HCI_ADV_CONN_MASK (0x0001) +#define BLE_HCI_ADV_SCAN_MASK (0x0002) +#define BLE_HCI_ADV_DIRECT_MASK (0x0004) +#define BLE_HCI_ADV_SCAN_RSP_MASK (0x0008) +#define BLE_HCI_ADV_LEGACY_MASK (0x0010) + +#define BLE_HCI_ADV_DATA_STATUS_COMPLETE (0x0000) +#define BLE_HCI_ADV_DATA_STATUS_INCOMPLETE (0x0020) +#define BLE_HCI_ADV_DATA_STATUS_TRUNCATED (0x0040) +#define BLE_HCI_ADV_DATA_STATUS_MASK (0x0060) + +/* Own address types */ +#define BLE_HCI_ADV_OWN_ADDR_PUBLIC (0) +#define BLE_HCI_ADV_OWN_ADDR_RANDOM (1) +#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB (2) +#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND (3) +#define BLE_HCI_ADV_OWN_ADDR_MAX (3) + +/* Advertisement peer address Type */ +#define BLE_HCI_ADV_PEER_ADDR_PUBLIC (0) +#define BLE_HCI_ADV_PEER_ADDR_RANDOM (1) +#define BLE_HCI_ADV_PEER_ADDR_MAX (1) + +/* --- LE advertising channel tx power (OCF 0x0007) */ +#define BLE_HCI_ADV_CHAN_TXPWR_MIN (-20) +#define BLE_HCI_ADV_CHAN_TXPWR_MAX (10) + +/* --- LE set scan enable (OCF 0x000c) */ + +/* Connect peer address type */ +#define BLE_HCI_CONN_PEER_ADDR_PUBLIC (0) +#define BLE_HCI_CONN_PEER_ADDR_RANDOM (1) +#define BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT (2) +#define BLE_HCI_CONN_PEER_ADDR_RANDOM_IDENT (3) +#define BLE_HCI_CONN_PEER_ADDR_MAX (3) + +/* + * Advertising filter policy + * + * Determines how an advertiser filters scan and connection requests. + * + * NONE: no filtering (default value). No whitelist used. + * SCAN: process all connection requests but only scans from white list. + * CONN: process all scan request but only connection requests from white list + * BOTH: ignore all scan and connection requests unless in white list. + */ +#define BLE_HCI_ADV_FILT_NONE (0) +#define BLE_HCI_ADV_FILT_SCAN (1) +#define BLE_HCI_ADV_FILT_CONN (2) +#define BLE_HCI_ADV_FILT_BOTH (3) +#define BLE_HCI_ADV_FILT_MAX (3) + +#define BLE_HCI_ADV_FILT_DEF (BLE_HCI_ADV_FILT_NONE) + +/* Advertising interval */ +#define BLE_HCI_ADV_ITVL (625) /* usecs */ +#define BLE_HCI_ADV_ITVL_MIN (32) /* units */ +#define BLE_HCI_ADV_ITVL_MAX (16384) /* units */ +#define BLE_HCI_ADV_ITVL_NONCONN_MIN (160) /* units */ + +#define BLE_HCI_ADV_ITVL_DEF (0x800) /* 1.28 seconds */ +#define BLE_HCI_ADV_CHANMASK_DEF (0x7) /* all channels */ + +/* Set scan parameters */ +#define BLE_HCI_SCAN_TYPE_PASSIVE (0) +#define BLE_HCI_SCAN_TYPE_ACTIVE (1) + +/* Scan interval and scan window timing */ +#define BLE_HCI_SCAN_ITVL (625) /* usecs */ +#define BLE_HCI_SCAN_ITVL_MIN (4) /* units */ +#define BLE_HCI_SCAN_ITVL_MAX (16384) /* units */ +#define BLE_HCI_SCAN_ITVL_DEF (16) /* units */ +#define BLE_HCI_SCAN_WINDOW_MIN (4) /* units */ +#define BLE_HCI_SCAN_WINDOW_MAX (16384) /* units */ +#define BLE_HCI_SCAN_WINDOW_DEF (16) /* units */ + +/* + * Scanning filter policy + * NO_WL: + * Scanner processes all advertising packets (white list not used) except + * directed, connectable advertising packets not sent to the scanner. + * USE_WL: + * Scanner processes advertisements from white list only. A connectable, + * directed advertisment is ignored unless it contains scanners address. + * NO_WL_INITA: + * Scanner process all advertising packets (white list not used). A + * connectable, directed advertisement shall not be ignored if the InitA + * is a resolvable private address. + * USE_WL_INITA: + * Scanner process advertisements from white list only. A connectable, + * directed advertisement shall not be ignored if the InitA is a + * resolvable private address. + */ +#define BLE_HCI_SCAN_FILT_NO_WL (0) +#define BLE_HCI_SCAN_FILT_USE_WL (1) +#define BLE_HCI_SCAN_FILT_NO_WL_INITA (2) +#define BLE_HCI_SCAN_FILT_USE_WL_INITA (3) +#define BLE_HCI_SCAN_FILT_MAX (3) + +/* Whitelist commands */ +#define BLE_HCI_ADD_WHITE_LIST_LEN (7) +#define BLE_HCI_RMV_WHITE_LIST_LEN (7) + +/* Create Connection */ +#define BLE_HCI_CREATE_CONN_LEN (25) +#define BLE_HCI_CONN_ITVL (1250) /* usecs */ +#define BLE_HCI_CONN_FILT_NO_WL (0) +#define BLE_HCI_CONN_FILT_USE_WL (1) +#define BLE_HCI_CONN_FILT_MAX (1) +#define BLE_HCI_CONN_ITVL_MIN (0x0006) +#define BLE_HCI_CONN_ITVL_MAX (0x0c80) +#define BLE_HCI_CONN_LATENCY_MIN (0x0000) +#define BLE_HCI_CONN_LATENCY_MAX (0x01f3) +#define BLE_HCI_CONN_SPVN_TIMEOUT_MIN (0x000a) +#define BLE_HCI_CONN_SPVN_TIMEOUT_MAX (0x0c80) +#define BLE_HCI_CONN_SPVN_TMO_UNITS (10) /* msecs */ +#define BLE_HCI_INITIATOR_FILT_POLICY_MAX (1) + +/* Peer Address Type */ +#define BLE_HCI_CONN_PEER_ADDR_PUBLIC (0) +#define BLE_HCI_CONN_PEER_ADDR_RANDOM (1) +#define BLE_HCI_CONN_PEER_ADDR_PUB_ID (2) +#define BLE_HCI_CONN_PEER_ADDR_RAND_ID (3) +#define BLE_HCI_CONN_PEER_ADDR_MAX (3) + + +/* --- LE set data length (OCF 0x0022) */ +#define BLE_HCI_SET_DATALEN_TX_OCTETS_MIN (0x001b) +#define BLE_HCI_SET_DATALEN_TX_OCTETS_MAX (0x00fb) +#define BLE_HCI_SET_DATALEN_TX_TIME_MIN (0x0148) +#define BLE_HCI_SET_DATALEN_TX_TIME_MAX (0x4290) + +/* --- LE read maximum default PHY (OCF 0x0030) */ +#define BLE_HCI_LE_PHY_1M (1) +#define BLE_HCI_LE_PHY_2M (2) +#define BLE_HCI_LE_PHY_CODED (3) + +/* --- LE set default PHY (OCF 0x0031) */ +#define BLE_HCI_LE_PHY_NO_TX_PREF_MASK (0x01) +#define BLE_HCI_LE_PHY_NO_RX_PREF_MASK (0x02) +#define BLE_HCI_LE_PHY_1M_PREF_MASK (0x01) +#define BLE_HCI_LE_PHY_2M_PREF_MASK (0x02) +#define BLE_HCI_LE_PHY_CODED_PREF_MASK (0x04) + +#define BLE_HCI_LE_PHY_PREF_MASK_ALL \ + (BLE_HCI_LE_PHY_1M_PREF_MASK | BLE_HCI_LE_PHY_2M_PREF_MASK | \ + BLE_HCI_LE_PHY_CODED_PREF_MASK) + +/* --- LE set PHY (OCF 0x0032) */ +#define BLE_HCI_LE_PHY_CODED_ANY (0x0000) +#define BLE_HCI_LE_PHY_CODED_S2_PREF (0x0001) +#define BLE_HCI_LE_PHY_CODED_S8_PREF (0x0002) + +/* --- LE enhanced receiver test (OCF 0x0033) */ +#define BLE_HCI_LE_PHY_1M (1) +#define BLE_HCI_LE_PHY_2M (2) +#define BLE_HCI_LE_PHY_CODED (3) + +/* --- LE enhanced transmitter test (OCF 0x0034) */ +#define BLE_HCI_LE_PHY_CODED_S8 (3) +#define BLE_HCI_LE_PHY_CODED_S2 (4) + +/* --- LE set extended advertising parameters (OCF 0x0036) */ +#define BLE_HCI_LE_SET_EXT_ADV_PROP_CONNECTABLE (0x0001) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_SCANNABLE (0x0002) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_DIRECTED (0x0004) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_HD_DIRECTED (0x0008) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY (0x0010) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV (0x0020) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_INC_TX_PWR (0x0040) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_MASK (0x7F) + +#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_IND (0x0013) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_LD_DIR (0x0015) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_HD_DIR (0x001d) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_SCAN (0x0012) +#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_NONCONN (0x0010) + +/* --- LE set extended advertising data (OCF 0x0037) */ +#define BLE_HCI_MAX_EXT_ADV_DATA_LEN (251) + +#define BLE_HCI_LE_SET_DATA_OPER_INT (0) +#define BLE_HCI_LE_SET_DATA_OPER_FIRST (1) +#define BLE_HCI_LE_SET_DATA_OPER_LAST (2) +#define BLE_HCI_LE_SET_DATA_OPER_COMPLETE (3) +#define BLE_HCI_LE_SET_DATA_OPER_UNCHANGED (4) + +/* --- LE set extended scan response data (OCF 0x0038) */ +#define BLE_HCI_MAX_EXT_SCAN_RSP_DATA_LEN (251) + +/* --- LE set periodic advertising parameters (OCF 0x003E) */ +#define BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR (0x0040) +#define BLE_HCI_LE_SET_PERIODIC_ADV_PROP_MASK (0x0040) + +/* --- LE set periodic advertising data (OCF 0x003F) */ +#define BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN (252) + +/* --- LE remove device from periodic advertising list (OCF 0x0048) */ +#define BLE_HCI_PERIODIC_DATA_STATUS_COMPLETE 0x00 +#define BLE_HCI_PERIODIC_DATA_STATUS_INCOMPLETE 0x01 +#define BLE_HCI_PERIODIC_DATA_STATUS_TRUNCATED 0x02 + +/* --- LE set privacy mode (OCF 0x004E) */ +#define BLE_HCI_PRIVACY_NETWORK (0) +#define BLE_HCI_PRIVACY_DEVICE (1) + +/* Event Codes */ +#define BLE_HCI_EVCODE_INQUIRY_CMP (0x01) +#define BLE_HCI_EVCODE_INQUIRY_RESULT (0x02) +#define BLE_HCI_EVCODE_CONN_DONE (0x03) +#define BLE_HCI_EVCODE_CONN_REQUEST (0x04) +#define BLE_HCI_EVCODE_DISCONN_CMP (0x05) +struct ble_hci_ev_disconn_cmp { + uint8_t status; + uint16_t conn_handle; + uint8_t reason; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_AUTH_CMP (0x06) +#define BLE_HCI_EVCODE_REM_NAME_REQ_CMP (0x07) + +#define BLE_HCI_EVCODE_ENCRYPT_CHG (0x08) +struct ble_hci_ev_enrypt_chg { + uint8_t status; + uint16_t connection_handle; + uint8_t enabled; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_CHG_LINK_KEY_CMP (0x09) +#define BLE_HCI_EVCODE_MASTER_LINK_KEY_CMP (0x0A) +#define BLE_HCI_EVCODE_RD_REM_SUPP_FEAT_CMP (0x0B) +#define BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP (0x0C) +struct ble_hci_ev_rd_rem_ver_info_cmp { + uint8_t status; + uint16_t conn_handle; + uint8_t version; + uint16_t manufacturer; + uint16_t subversion; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_QOS_SETUP_CMP (0x0D) + +#define BLE_HCI_EVCODE_COMMAND_COMPLETE (0x0E) +struct ble_hci_ev_command_complete { + uint8_t num_packets; + uint16_t opcode; + uint8_t status; + uint8_t return_params[0]; +} __attribute__((packed)); +/* NOP is exception and has no return parameters */ +struct ble_hci_ev_command_complete_nop { + uint8_t num_packets; + uint16_t opcode; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_COMMAND_STATUS (0x0F) +struct ble_hci_ev_command_status { + uint8_t status; + uint8_t num_packets; + uint16_t opcode; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_HW_ERROR (0x10) +struct ble_hci_ev_hw_error { + uint8_t hw_code; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_NUM_COMP_PKTS (0x13) +struct comp_pkt { + uint16_t handle; + uint16_t packets; +} __attribute__((packed));; +struct ble_hci_ev_num_comp_pkts { + uint8_t count; + struct comp_pkt completed[0]; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_MODE_CHANGE (0x14) +#define BLE_HCI_EVCODE_RETURN_LINK_KEYS (0x15) +#define BLE_HCI_EVCODE_PIN_CODE_REQ (0x16) +#define BLE_HCI_EVCODE_LINK_KEY_REQ (0x17) +#define BLE_HCI_EVCODE_LINK_KEY_NOTIFY (0x18) +#define BLE_HCI_EVCODE_LOOPBACK_CMD (0x19) + +#define BLE_HCI_EVCODE_DATA_BUF_OVERFLOW (0x1A) +struct ble_hci_ev_data_buf_overflow { + uint8_t link_type; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_MAX_SLOTS_CHG (0x1B) +#define BLE_HCI_EVCODE_READ_CLK_OFF_COMP (0x1C) +#define BLE_HCI_EVCODE_CONN_PKT_TYPE_CHG (0x1D) +#define BLE_HCI_EVCODE_QOS_VIOLATION (0x1E) +/* NOTE: 0x1F not defined */ +#define BLE_HCI_EVCODE_PSR_MODE_CHG (0x20) +#define BLE_HCI_EVCODE_FLOW_SPEC_COMP (0x21) +#define BLE_HCI_EVCODE_INQ_RESULT_RSSI (0x22) +#define BLE_HCI_EVCODE_READ_REM_EXT_FEAT (0x23) +/* NOTE: 0x24 - 0x2B not defined */ +#define BLE_HCI_EVCODE_SYNCH_CONN_COMP (0x2C) +#define BLE_HCI_EVCODE_SYNCH_CONN_CHG (0x2D) +#define BLE_HCI_EVCODE_SNIFF_SUBRATING (0x2E) +#define BLE_HCI_EVCODE_EXT_INQ_RESULT (0x2F) + +#define BLE_HCI_EVCODE_ENC_KEY_REFRESH (0x30) +struct ble_hci_ev_enc_key_refresh { + uint8_t status; + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_EVOCDE_IO_CAP_REQ (0x31) +#define BLE_HCI_EVCODE_IO_CAP_RSP (0x32) +#define BLE_HCI_EVCODE_USER_CONFIRM_REQ (0x33) +#define BLE_HCI_EVCODE_PASSKEY_REQ (0x34) +#define BLE_HCI_EVCODE_REM_OOB_DATA_REQ (0x35) +#define BLE_HCI_EVCODE_SIMPLE_PAIR_COMP (0x36) +/* NOTE: 0x37 not defined */ +#define BLE_HCI_EVCODE_LNK_SPVN_TMO_CHG (0x38) +#define BLE_HCI_EVCODE_ENH_FLUSH_COMP (0x39) +#define BLE_HCI_EVCODE_USER_PASSKEY_NOTIFY (0x3B) +#define BLE_HCI_EVCODE_KEYPRESS_NOTIFY (0x3C) +#define BLE_HCI_EVCODE_REM_HOST_SUPP_FEAT (0x3D) + +#define BLE_HCI_EVCODE_LE_META (0x3E) +struct ble_hci_ev_le_meta { + uint8_t subevent; + uint8_t data[0]; +} __attribute__((packed)); + +/* NOTE: 0x3F not defined */ +#define BLE_HCI_EVCODE_PHYS_LINK_COMP (0x40) +#define BLE_HCI_EVCODE_CHAN_SELECTED (0x41) +#define BLE_HCI_EVCODE_DISCONN_PHYS_LINK (0x42) +#define BLE_HCI_EVCODE_PHYS_LINK_LOSS_EARLY (0x43) +#define BLE_HCI_EVCODE_PHYS_LINK_RECOVERY (0x44) +#define BLE_HCI_EVCODE_LOGICAL_LINK_COMP (0x45) +#define BLE_HCI_EVCODE_DISCONN_LOGICAL_LINK (0x46) +#define BLE_HCI_EVCODE_FLOW_SPEC_MODE_COMP (0x47) +#define BLE_HCI_EVCODE_NUM_COMP_DATA_BLKS (0x48) +#define BLE_HCI_EVCODE_AMP_START_TEST (0x49) +#define BLE_HCI_EVOCDE_AMP_TEST_END (0x4A) +#define BLE_HCI_EVOCDE_AMP_RCVR_REPORT (0x4B) +#define BLE_HCI_EVCODE_SHORT_RANGE_MODE_CHG (0x4C) +#define BLE_HCI_EVCODE_AMP_STATUS_CHG (0x4D) +#define BLE_HCI_EVCODE_TRIG_CLK_CAPTURE (0x4E) +#define BLE_HCI_EVCODE_SYNCH_TRAIN_COMP (0x4F) +#define BLE_HCI_EVCODE_SYNCH_TRAIN_RCVD (0x50) +#define BLE_HCI_EVCODE_SLAVE_BCAST_RX (0x51) +#define BLE_HCI_EVCODE_SLAVE_BCAST_TMO (0x52) +#define BLE_HCI_EVCODE_TRUNC_PAGE_COMP (0x53) +#define BLE_HCI_EVCODE_SLAVE_PAGE_RSP_TMO (0x54) +#define BLE_HCI_EVCODE_SLAVE_BCAST_CHAN_MAP (0x55) +#define BLE_HCI_EVCODE_INQ_RSP_NOTIFY (0x56) + +#define BLE_HCI_EVCODE_AUTH_PYLD_TMO (0x57) +struct ble_hci_ev_auth_pyld_tmo { + uint16_t conn_handle; +} __attribute__((packed)); + +#define BLE_HCI_EVCODE_SAM_STATUS_CHG (0x58) + +#define BLE_HCI_EVCODE_VENDOR_DEBUG (0xFF) +struct ble_hci_ev_vendor_debug { + uint8_t id; + uint8_t data[0]; +}__attribute__((packed)); + +/* LE sub-event codes */ +#define BLE_HCI_LE_SUBEV_CONN_COMPLETE (0x01) +struct ble_hci_ev_le_subev_conn_complete { + uint8_t subev_code; + uint8_t status; + uint16_t conn_handle; + uint8_t role; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint16_t conn_itvl; + uint16_t conn_latency; + uint16_t supervision_timeout; + uint8_t mca; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_ADV_RPT (0x02) +struct adv_report { + uint8_t type; + uint8_t addr_type; + uint8_t addr[6]; + uint8_t data_len; + uint8_t data[0]; +} __attribute__((packed)); +struct ble_hci_ev_le_subev_adv_rpt { + uint8_t subev_code; + uint8_t num_reports; + struct adv_report reports[0]; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE (0x03) +struct ble_hci_ev_le_subev_conn_upd_complete { + uint8_t subev_code; + uint8_t status; + uint16_t conn_handle; + uint16_t conn_itvl; + uint16_t conn_latency; + uint16_t supervision_timeout; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT (0x04) +struct ble_hci_ev_le_subev_rd_rem_used_feat { + uint8_t subev_code; + uint8_t status; + uint16_t conn_handle; + uint8_t features[8]; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_LT_KEY_REQ (0x05) +struct ble_hci_ev_le_subev_lt_key_req { + uint8_t subev_code; + uint16_t conn_handle; + uint64_t rand; + uint16_t div; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ (0x06) +struct ble_hci_ev_le_subev_rem_conn_param_req { + uint8_t subev_code; + uint16_t conn_handle; + uint16_t min_interval; + uint16_t max_interval; + uint16_t latency; + uint16_t timeout; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_DATA_LEN_CHG (0x07) +struct ble_hci_ev_le_subev_data_len_chg { + uint8_t subev_code; + uint16_t conn_handle; + uint16_t max_tx_octets; + uint16_t max_tx_time; + uint16_t max_rx_octets; + uint16_t max_rx_time; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_RD_LOC_P256_PUBKEY (0x08) +struct ble_hci_ev_le_subev_rd_loc_p256_pubkey { + uint8_t subev_code; + uint8_t status; + uint8_t public_key[64]; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_GEN_DHKEY_COMPLETE (0x09) +struct ble_hci_ev_le_subev_gen_dhkey_complete { + uint8_t subev_code; + uint8_t status; + uint8_t dh_key[32]; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE (0x0A) +struct ble_hci_ev_le_subev_enh_conn_complete { + uint8_t subev_code; + uint8_t status; + uint16_t conn_handle; + uint8_t role; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t local_rpa[6]; + uint8_t peer_rpa[6]; + uint16_t conn_itvl; + uint16_t conn_latency; + uint16_t supervision_timeout; + uint8_t mca; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT (0x0B) +struct dir_adv_report { + uint8_t type; + uint8_t addr_type; + uint8_t addr[6]; + uint8_t dir_addr_type; + uint8_t dir_addr[6]; + int8_t rssi; +} __attribute__((packed)); +struct ble_hci_ev_le_subev_direct_adv_rpt { + uint8_t subev_code; + uint8_t num_reports; + struct dir_adv_report reports[0]; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE (0x0C) +struct ble_hci_ev_le_subev_phy_update_complete { + uint8_t subev_code; + uint8_t status; + uint16_t conn_handle; + uint8_t tx_phy; + uint8_t rx_phy; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_EXT_ADV_RPT (0x0D) +struct ext_adv_report { + uint16_t evt_type; + uint8_t addr_type; + uint8_t addr[6]; + uint8_t pri_phy; + uint8_t sec_phy; + uint8_t sid; + int8_t tx_power; + int8_t rssi; + uint16_t periodic_itvl; + uint8_t dir_addr_type; + uint8_t dir_addr[6]; + uint8_t data_len; + uint8_t data[0]; +} __attribute__((packed)); +struct ble_hci_ev_le_subev_ext_adv_rpt { + uint8_t subev_code; + uint8_t num_reports; + struct ext_adv_report reports[0]; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_ESTAB (0x0E) +struct ble_hci_ev_le_subev_periodic_adv_sync_estab { + uint8_t subev_code; + uint8_t status; + uint16_t sync_handle; + uint8_t sid; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t phy; + uint16_t interval; + uint8_t aca; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT (0x0F) +struct ble_hci_ev_le_subev_periodic_adv_rpt { + uint8_t subev_code; + uint16_t sync_handle; + int8_t tx_power; + int8_t rssi; + uint8_t cte_type; + uint8_t data_status; + uint8_t data_len; + uint8_t data[0]; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_LOST (0x10) +struct ble_hci_ev_le_subev_periodic_adv_sync_lost { + uint8_t subev_code; + uint16_t sync_handle; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_SCAN_TIMEOUT (0x11) +struct ble_hci_ev_le_subev_scan_timeout { + uint8_t subev_code; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_ADV_SET_TERMINATED (0x12) +struct ble_hci_ev_le_subev_adv_set_terminated { + uint8_t subev_code; + uint8_t status; + uint8_t adv_handle; + uint16_t conn_handle; + uint8_t num_events; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_SCAN_REQ_RCVD (0x13) +struct ble_hci_ev_le_subev_scan_req_rcvd { + uint8_t subev_code; + uint8_t adv_handle; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_CHAN_SEL_ALG (0x14) +struct ble_hci_ev_le_subev_chan_sel_alg { + uint8_t subev_code; + uint16_t conn_handle; + uint8_t csa; +} __attribute__((packed)); + +#define BLE_HCI_LE_SUBEV_CONNLESS_IQ_RPT (0x15) +#define BLE_HCI_LE_SUBEV_CONN_IQ_RPT (0x16) +#define BLE_HCI_LE_SUBEV_CTE_REQ_FAILED (0x17) + +#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_TRANSFER (0x18) +struct ble_hci_ev_le_subev_periodic_adv_sync_transfer { + uint8_t subev_code; + uint8_t status; + uint16_t conn_handle; + uint16_t service_data; + uint16_t sync_handle; + uint8_t sid; + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + uint8_t phy; + uint16_t interval; + uint8_t aca; +} __attribute__((packed)); + +/* Data buffer overflow event */ +#define BLE_HCI_EVENT_ACL_BUF_OVERFLOW (0x01) + +/* Advertising report */ +#define BLE_HCI_ADV_RPT_EVTYPE_ADV_IND (0) +#define BLE_HCI_ADV_RPT_EVTYPE_DIR_IND (1) +#define BLE_HCI_ADV_RPT_EVTYPE_SCAN_IND (2) +#define BLE_HCI_ADV_RPT_EVTYPE_NONCONN_IND (3) +#define BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP (4) + +/* Bluetooth 5, Vol 2, Part E, 7.7.65.13 */ +#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_IND (0x13) +#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_DIRECT_IND (0x15) +#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_SCAN_IND (0x12) +#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_NONCON_IND (0x10) +#define BLE_HCI_LEGACY_ADV_EVTYPE_SCAN_RSP_ADV_IND (0x1b) +#define BLE_HCI_LEGACY_ADV_EVTYPE_SCAN_RSP_ADV_SCAN_IND (0x1a) + +/* LE connection complete event (sub event 0x01) */ +#define BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER (0x00) +#define BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE (0x01) + +/* Maximum valid connection handle value */ +#define BLE_HCI_LE_CONN_HANDLE_MAX (0x0eff) + +/* LE advertising report event. (sub event 0x02) */ +#define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN (1) +#define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX (0x19) + +/* Bluetooth Assigned numbers for version information.*/ +#define BLE_HCI_VER_BCS_1_0b (0) +#define BLE_HCI_VER_BCS_1_1 (1) +#define BLE_HCI_VER_BCS_1_2 (2) +#define BLE_HCI_VER_BCS_2_0_EDR (3) +#define BLE_HCI_VER_BCS_2_1_EDR (4) +#define BLE_HCI_VER_BCS_3_0_HCS (5) +#define BLE_HCI_VER_BCS_4_0 (6) +#define BLE_HCI_VER_BCS_4_1 (7) +#define BLE_HCI_VER_BCS_4_2 (8) +#define BLE_HCI_VER_BCS_5_0 (9) +#define BLE_HCI_VER_BCS_5_1 (10) +#define BLE_HCI_VER_BCS_5_2 (11) + +#define BLE_LMP_VER_BCS_1_0b (0) +#define BLE_LMP_VER_BCS_1_1 (1) +#define BLE_LMP_VER_BCS_1_2 (2) +#define BLE_LMP_VER_BCS_2_0_EDR (3) +#define BLE_LMP_VER_BCS_2_1_EDR (4) +#define BLE_LMP_VER_BCS_3_0_HCS (5) +#define BLE_LMP_VER_BCS_4_0 (6) +#define BLE_LMP_VER_BCS_4_1 (7) +#define BLE_LMP_VER_BCS_4_2 (8) +#define BLE_LMP_VER_BCS_5_0 (9) +#define BLE_LMP_VER_BCS_5_1 (10) +#define BLE_LMP_VER_BCS_5_2 (11) + +/* selected HCI and LMP version */ +#if MYNEWT_VAL(BLE_VERSION) == 50 +#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_0 +#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_0 +#elif MYNEWT_VAL(BLE_VERSION) == 51 +#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_1 +#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_1 +#elif MYNEWT_VAL(BLE_VERSION) == 52 +#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_2 +#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_2 + +#endif + +#define BLE_HCI_DATA_HDR_SZ 4 +#define BLE_HCI_DATA_HANDLE(handle_pb_bc) (((handle_pb_bc) & 0x0fff) >> 0) +#define BLE_HCI_DATA_PB(handle_pb_bc) (((handle_pb_bc) & 0x3000) >> 12) +#define BLE_HCI_DATA_BC(handle_pb_bc) (((handle_pb_bc) & 0xc000) >> 14) + +struct hci_data_hdr +{ + uint16_t hdh_handle_pb_bc; + uint16_t hdh_len; +}; + +#define BLE_HCI_PB_FIRST_NON_FLUSH 0 +#define BLE_HCI_PB_MIDDLE 1 +#define BLE_HCI_PB_FIRST_FLUSH 2 +#define BLE_HCI_PB_FULL 3 + +#ifdef __cplusplus +} +#endif + +#endif /* H_BLE_HCI_COMMON_ */ diff --git a/src/libs/mynewt-nimble/nimble/include/nimble/nimble_npl.h b/src/libs/mynewt-nimble/nimble/include/nimble/nimble_npl.h new file mode 100644 index 00000000..5935b740 --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/include/nimble/nimble_npl.h @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NIMBLE_NPL_H_ +#define _NIMBLE_NPL_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct ble_npl_event; +typedef void ble_npl_event_fn(struct ble_npl_event *ev); + +enum ble_npl_error { + BLE_NPL_OK = 0, + BLE_NPL_ENOMEM = 1, + BLE_NPL_EINVAL = 2, + BLE_NPL_INVALID_PARAM = 3, + BLE_NPL_MEM_NOT_ALIGNED = 4, + BLE_NPL_BAD_MUTEX = 5, + BLE_NPL_TIMEOUT = 6, + BLE_NPL_ERR_IN_ISR = 7, + BLE_NPL_ERR_PRIV = 8, + BLE_NPL_OS_NOT_STARTED = 9, + BLE_NPL_ENOENT = 10, + BLE_NPL_EBUSY = 11, + BLE_NPL_ERROR = 12, +}; + +typedef enum ble_npl_error ble_npl_error_t; + +/* Include OS-specific definitions */ +#include "nimble/nimble_npl_os.h" + +/* + * Generic + */ + +bool ble_npl_os_started(void); + +void *ble_npl_get_current_task_id(void); + +/* + * Event queue + */ + +void ble_npl_eventq_init(struct ble_npl_eventq *evq); + +struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq, + ble_npl_time_t tmo); + +void ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev); + +void ble_npl_eventq_remove(struct ble_npl_eventq *evq, + struct ble_npl_event *ev); + +void ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, + void *arg); + +bool ble_npl_event_is_queued(struct ble_npl_event *ev); + +void *ble_npl_event_get_arg(struct ble_npl_event *ev); + +void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg); + +bool ble_npl_eventq_is_empty(struct ble_npl_eventq *evq); + +void ble_npl_event_run(struct ble_npl_event *ev); + +/* + * Mutexes + */ + +ble_npl_error_t ble_npl_mutex_init(struct ble_npl_mutex *mu); + +ble_npl_error_t ble_npl_mutex_pend(struct ble_npl_mutex *mu, + ble_npl_time_t timeout); + +ble_npl_error_t ble_npl_mutex_release(struct ble_npl_mutex *mu); + +/* + * Semaphores + */ + +ble_npl_error_t ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens); + +ble_npl_error_t ble_npl_sem_pend(struct ble_npl_sem *sem, + ble_npl_time_t timeout); + +ble_npl_error_t ble_npl_sem_release(struct ble_npl_sem *sem); + +uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem); + +/* + * Callouts + */ + +void ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, void *ev_arg); + +ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *co, + ble_npl_time_t ticks); + +void ble_npl_callout_stop(struct ble_npl_callout *co); + +bool ble_npl_callout_is_active(struct ble_npl_callout *co); + +ble_npl_time_t ble_npl_callout_get_ticks(struct ble_npl_callout *co); + +ble_npl_time_t ble_npl_callout_remaining_ticks(struct ble_npl_callout *co, + ble_npl_time_t time); + +void ble_npl_callout_set_arg(struct ble_npl_callout *co, + void *arg); +/* + * Time functions + */ + +ble_npl_time_t ble_npl_time_get(void); + +ble_npl_error_t ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks); + +ble_npl_error_t ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms); + +ble_npl_time_t ble_npl_time_ms_to_ticks32(uint32_t ms); + +uint32_t ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks); + +void ble_npl_time_delay(ble_npl_time_t ticks); + +/* + * Hardware-specific + * + * These symbols should be most likely defined by application since they are + * specific to hardware, not to OS. + */ + +#if NIMBLE_CFG_CONTROLLER + +void ble_npl_hw_set_isr(int irqn, void (*addr)(void)); + +#endif + +uint32_t ble_npl_hw_enter_critical(void); + +void ble_npl_hw_exit_critical(uint32_t ctx); + +bool ble_npl_hw_is_in_critical(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _NIMBLE_NPL_H_ */ diff --git a/src/libs/mynewt-nimble/nimble/include/nimble/nimble_opt.h b/src/libs/mynewt-nimble/nimble/include/nimble/nimble_opt.h new file mode 100644 index 00000000..f0e988b2 --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/include/nimble/nimble_opt.h @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_NIMBLE_OPT_ +#define H_NIMBLE_OPT_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Include automatically-generated settings. */ +#include "nimble/nimble_opt_auto.h" + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/libs/mynewt-nimble/nimble/include/nimble/nimble_opt_auto.h b/src/libs/mynewt-nimble/nimble/include/nimble/nimble_opt_auto.h new file mode 100644 index 00000000..33a1e2aa --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/include/nimble/nimble_opt_auto.h @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_NIMBLE_OPT_AUTO_ +#define H_NIMBLE_OPT_AUTO_ + +#include "syscfg/syscfg.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*** + * Automatic options. + * + * These settings are generated automatically from the user-specified syscfg + * settings. + */ + +#undef NIMBLE_BLE_ADVERTISE +#define NIMBLE_BLE_ADVERTISE \ + (MYNEWT_VAL(BLE_ROLE_BROADCASTER) || MYNEWT_VAL(BLE_ROLE_PERIPHERAL)) + +#undef NIMBLE_BLE_SCAN +#define NIMBLE_BLE_SCAN \ + (MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)) + +#undef NIMBLE_BLE_CONNECT +#define NIMBLE_BLE_CONNECT \ + (MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_PERIPHERAL)) + + +/** Supported client ATT commands. */ + +#undef NIMBLE_BLE_ATT_CLT_FIND_INFO +#define NIMBLE_BLE_ATT_CLT_FIND_INFO \ + (MYNEWT_VAL(BLE_GATT_DISC_ALL_DSCS)) + +#undef NIMBLE_BLE_ATT_CLT_FIND_TYPE +#define NIMBLE_BLE_ATT_CLT_FIND_TYPE \ + (MYNEWT_VAL(BLE_GATT_DISC_SVC_UUID)) + +#undef NIMBLE_BLE_ATT_CLT_READ_TYPE +#define NIMBLE_BLE_ATT_CLT_READ_TYPE \ + (MYNEWT_VAL(BLE_GATT_FIND_INC_SVCS) || \ + MYNEWT_VAL(BLE_GATT_DISC_ALL_CHRS) || \ + MYNEWT_VAL(BLE_GATT_DISC_CHRS_UUID) || \ + MYNEWT_VAL(BLE_GATT_READ_UUID)) + +#undef NIMBLE_BLE_ATT_CLT_READ +#define NIMBLE_BLE_ATT_CLT_READ \ + (MYNEWT_VAL(BLE_GATT_READ) || \ + MYNEWT_VAL(BLE_GATT_READ_LONG) || \ + MYNEWT_VAL(BLE_GATT_FIND_INC_SVCS)) + +#undef NIMBLE_BLE_ATT_CLT_READ_BLOB +#define NIMBLE_BLE_ATT_CLT_READ_BLOB \ + (MYNEWT_VAL(BLE_GATT_READ_LONG)) + +#undef NIMBLE_BLE_ATT_CLT_READ_MULT +#define NIMBLE_BLE_ATT_CLT_READ_MULT \ + (MYNEWT_VAL(BLE_GATT_READ_MULT)) + +#undef NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE +#define NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE \ + (MYNEWT_VAL(BLE_GATT_DISC_ALL_SVCS)) + +#undef NIMBLE_BLE_ATT_CLT_WRITE +#define NIMBLE_BLE_ATT_CLT_WRITE \ + (MYNEWT_VAL(BLE_GATT_WRITE)) + +#undef NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP +#define NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP \ + (MYNEWT_VAL(BLE_GATT_WRITE_NO_RSP)) + +#undef NIMBLE_BLE_ATT_CLT_PREP_WRITE +#define NIMBLE_BLE_ATT_CLT_PREP_WRITE \ + (MYNEWT_VAL(BLE_GATT_WRITE_LONG)) + +#undef NIMBLE_BLE_ATT_CLT_EXEC_WRITE +#define NIMBLE_BLE_ATT_CLT_EXEC_WRITE \ + (MYNEWT_VAL(BLE_GATT_WRITE_LONG)) + +#undef NIMBLE_BLE_ATT_CLT_NOTIFY +#define NIMBLE_BLE_ATT_CLT_NOTIFY \ + (MYNEWT_VAL(BLE_GATT_NOTIFY)) + +#undef NIMBLE_BLE_ATT_CLT_INDICATE +#define NIMBLE_BLE_ATT_CLT_INDICATE \ + (MYNEWT_VAL(BLE_GATT_INDICATE)) + +/** Security manager settings. */ + +#undef NIMBLE_BLE_SM +#define NIMBLE_BLE_SM (MYNEWT_VAL(BLE_SM_LEGACY) || MYNEWT_VAL(BLE_SM_SC)) + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.2.3