/** **************************************************************************************** * * @file ble_gapc.h * * @brief BLE GAPC API * **************************************************************************************** * @attention #####Copyright (c) 2019 GOODIX All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of GOODIX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************************************************************************************** */ /** * @addtogroup BLE * @{ * @brief Definitions and prototypes for the BLE SDK interface. */ /** * @addtogroup BLE_GAP Generic Access Profile (GAP) * @{ * @brief Definitions and prototypes for the GAP interface. */ /** * @defgroup BLE_GAPC Generic Access Profile (GAP) Connection Control * @{ * @brief Definitions and prototypes for the GAP Connection Control interface. */ #ifndef __BLE_GAPC_H__ #define __BLE_GAPC_H__ #include // Standard Integer #include #include "gr55xx_sys_cfg.h" /** * @defgroup BLE_GAPC_DEFINES Defines * @{ */ #define GAP_CHNL_MAP_LEN 0x05 /**< The length of channel map. */ #define GAP_FEATS_LEN 0x08 /**< The length of features. */ #define GAP_ADDR_LEN 0x06 /**< The length of address. */ #define GAP_INVALID_CONN_INDEX 0xFF /**< Invalid connection index. */ /**@defgroup BLE_GAP_ADDR_TYPES GAP Address types * @{ */ #define BLE_GAP_ADDR_TYPE_PUBLIC 0x00 /**< Public (identity) address.*/ #define BLE_GAP_ADDR_TYPE_RANDOM_STATIC 0x01 /**< Random static (identity) address. */ /**@} */ /**@defgroup BLE_GAP_PHY_OPTIONS GAP PHY OPTIONS (bitmask) * @{ */ #define PHY_OPT_NO_CODING 0x00 /**< The Host has no preferred coding when transmitting on the LE Coded PHY. */ #define PHY_OPT_S2_CODING 0x01 /**< The Host prefers that S=2 coding be used when transmitting on the LE Coded PHY. */ #define PHY_OPT_S8_CODING 0x02 /**< The Host prefers that S=8 coding be used when transmitting on the LE Coded PHY. */ /**@} */ /** @} */ /** * @defgroup BLE_SDK_GAP_ENUM Enumerations * @{ */ /** @brief The operation code used to get connection info */ typedef enum { GAP_GET_CON_RSSI = 0, /**< Get connection RSSI info. */ GAP_GET_CON_CHANNEL_MAP, /**< Get connection channel map. */ GAP_GET_PHY, /**< Get connection PHY. */ GAP_GET_CHAN_SEL_ALGO /**< Get selection algorithm for connection channel. */ } gap_get_conn_info_op_t; /**@brief The operation code used to get peer device info. */ typedef enum { GAP_GET_PEER_VERSION = 0, /**< Get peer device version info. */ GAP_GET_PEER_FEATURES /**< Get peer device features info. */ } gap_get_peer_info_op_t; /** @brief Advertising report type. */ typedef enum { GAP_REPORT_TYPE_ADV_EXT = 0, /**< Extended advertising report. */ GAP_REPORT_TYPE_ADV_LEG, /**< Legacy advertising report. */ GAP_REPORT_TYPE_SCAN_RSP_EXT, /**< Extended scan response report. */ GAP_REPORT_TYPE_SCAN_RSP_LEG, /**< Legacy scan response report. */ GAP_REPORT_TYPE_PER_ADV, /**< Periodic advertising report. */ } gap_adv_report_type_t; /** @brief Advertising report information. */ typedef enum { GAP_REPORT_INFO_COMPLETE_BIT = (1 << 0), /**< Report is complete. */ GAP_REPORT_INFO_CONN_ADV_BIT = (1 << 1), /**< Connectable advertising. */ GAP_REPORT_INFO_SCAN_ADV_BIT = (1 << 2), /**< Scannable advertising. */ GAP_REPORT_INFO_DIR_ADV_BIT = (1 << 3), /**< Directed advertising. */ } gap_adv_report_info_t; /** @brief Stop reason code. */ typedef enum { GAP_STOPPED_REASON_TIMEOUT = 0, /**< Stop with timeout. */ GAP_STOPPED_REASON_ON_USER, /**< Stop with user stopping it actively. */ GAP_STOPPED_REASON_CONN_EST /**< Stop with connection established. */ } gap_stopped_reason_t; /** @brief Device role of LL layer type */ typedef enum { GAP_LL_ROLE_MASTER = 0, /**< Master role. */ GAP_LL_ROLE_SLAVE = 1, /**< Slave role. */ } gap_ll_role_type_t; /** * @brief Operation code used to set param(s). */ typedef enum { GAP_OPCODE_CHNL_MAP_SET, /**< Set Channel Map. */ GAP_OPCODE_WHITELIST_SET, /**< Set white list. */ GAP_OPCODE_PER_ADV_LIST_SET, /**< Set periodic advertising list. */ GAP_OPCODE_PRIVACY_MODE_SET, /**< Set privacy mode for peer device. */ } gap_param_set_op_id_t; /** * @brief Operation code used to read resolvable address. */ typedef enum { GAP_OPCODE_LOCAL_RSLV_ADDR_READ, /**< Local resolvable address operation. */ GAP_OPCODE_PEER_RSLV_ADDR_READ, /**< Peer resolvable address operation. */ } gap_rslv_addr_read_op_id_t; /** * @brief Operation code used for LEPSM manager. */ typedef enum { GAP_OPCODE_LEPSM_REGISTER, /**< LEPSM register operation. */ GAP_OPCODE_LEPSM_UNREGISTER, /**< LEPSM unregister operation. */ } gap_psm_manager_op_id_t; /** * @brief The specified reason for terminating a connection. */ typedef enum { GAP_HCI_AUTHENTICATION_FAILURE = 0x05, /**< Authentication Failure. */ GAP_HCI_REMOTE_USER_TERMINATED_CONNECTION = 0x13, /**< Remote User Terminated Connection. */ GAP_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES = 0x14, /**< Remote Device Terminated Connection due to Low Resources . */ GAP_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF = 0x15, /**< Remote Device Terminated Connection due to Power Off. */ GAP_HCI_UNSUPPORTED_REMOTE_FEATURE = 0x1A, /**< Unsupported Remote Feature. */ GAP_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED = 0X29, /**< Pairing With Unit Key Not Supported. */ GAP_HCI_CONN_INTERVAL_UNACCEPTABLE = 0x3B, /**< Unacceptable Connection Parameters. */ } gap_disconn_reason_t; /** @} */ /** * @defgroup BLE_GAPC_STRUCT Structures * @{ */ /** @brief The struct of device version. */ typedef struct { uint8_t hci_ver; /**< HCI version. */ uint8_t lmp_ver; /**< LMP version. */ uint8_t host_ver; /**< Host version. */ uint16_t hci_subver; /**< HCI subversion. */ uint16_t lmp_subver; /**< LMP subversion. */ uint16_t host_subver; /**< Host subversion. */ uint16_t manuf_name; /**< Manufacturer name. */ } gap_dev_version_ind_t; /** @brief The struct of address. */ typedef struct { uint8_t addr[GAP_ADDR_LEN]; /**< 6-byte array address value. */ } gap_addr_t; /** @brief The struct of broadcast address with broadcast type. */ typedef struct { gap_addr_t gap_addr; /**< Device BD Address. */ uint8_t addr_type; /**< Address type of the device: 0=public/1=random. please @ref BLE_GAP_ADDR_TYPES. */ } gap_bdaddr_t; /** @brief Get broadcast address struct. */ typedef struct { uint8_t index; /**< Advertsing index. The valid range is: 0 - 4. */ gap_bdaddr_t bd_addr; /**< BD address. */ } gap_get_bd_addr_t; /** @brief TX power info struct. */ typedef struct { int8_t power_lvl; /**< Advertising channel TX power level. Range: -20 to 10. Unit: dBm. Accuracy: +/-4dB. */ } gap_dev_adv_tx_power_t; /** @brief TX power info struct. */ typedef struct { int8_t min_tx_pwr; /**< MIN of TX power. Size: 1 octet (signed integer). Range: -127 to +126. Unit: dBm. */ int8_t max_tx_pwr; /**< MAX of TX power. Size: 1 octet (signed integer). Range: -127 to +126. Unit: dBm. */ } gap_dev_tx_power_t; /** @brief Max data length info struct. */ typedef struct { uint16_t suppted_max_tx_octets; /**< Maximum number of payload octets that the local Controller supports for transmission of a single Link Layer packet on a data connection. Range: 0x001B-0x00FB (all other values reserved for future use). */ uint16_t suppted_max_tx_time; /**< Maximum time, in microseconds, that the local Controller supports for transmission of a single Link Layer packet on a data connection. Range: 0x0148-0x4290 (all other values reserved for future use). */ uint16_t suppted_max_rx_octets; /**< Maximum number of payload octets that the local Controller supports for reception of a single Link Layer packet on a data connection. Range: 0x001B-0x00FB (all other values reserved for future use). */ uint16_t suppted_max_rx_time; /**< Maximum time, in microseconds, that the local Controller supports for reception of a single Link Layer packet on a data connection. Range: 0x0148-0x4290 (all other values reserved for future use). */ } gap_max_data_len_t; /** @brief Suggested default data length info. */ typedef struct { uint16_t suggted_max_tx_octets; /**< The Host's suggested value for the Controller's maximum transmitted number of payload octets to be used for new connections. Range: 0x001B-0x00FB (all other values reserved for future use), default: 0x001B */ uint16_t suggted_max_tx_time; /**< The Host's suggested value for the Controller's maximum packet transmissiontime to be used for new connections. Range: 0x0148-0x4290 (all other values reserved for future use), default: 0x0148 */ } gap_sugg_dflt_data_len_t; /** @brief Number of available advertising sets info. */ typedef struct { uint8_t nb_adv_sets; /**< Number of available advertising sets. */ } gap_nb_adv_sets_t; /** @brief Maximum advertising data length info. */ typedef struct { uint16_t length; /**< Maximum advertising data length supported by controller. */ } gap_max_adv_data_len_ind_t; /** @brief RF path compensation values info. */ typedef struct { uint16_t tx_path_comp; /**< RF TX path compensation. */ uint16_t rx_path_comp; /**< RF RX path compensation. */ } gap_dev_rf_path_comp_ind_t; /** @brief Device info. */ typedef union { gap_dev_version_ind_t dev_version; /**< Version info. */ gap_get_bd_addr_t get_bd_addr; /**< Device BD address info. */ gap_dev_adv_tx_power_t adv_tx_power; /**< Advertising TX power info. */ gap_sugg_dflt_data_len_t sugg_dflt_data_len; /**< Suggested default data length info. */ gap_max_data_len_t max_data_len; /**< Suggested MAX data length info. */ gap_nb_adv_sets_t nb_adv_sets; /**< Number of available advertising sets. */ gap_max_adv_data_len_ind_t max_adv_data_len; /**< Maximum advertising data length info. */ gap_dev_tx_power_t dev_tx_power; /**< Device TX power info. */ gap_dev_rf_path_comp_ind_t dev_rf_path_comp; /**< RF path compensation values. */ } gap_dev_info_t; /** @brief Get device info operation struct. */ typedef struct { uint8_t operation; /**< Operation code. @see enum gap_dev_info_get_type_t. */ gap_dev_info_t dev_info; /**< Device info. */ } gap_dev_info_get_t; /** @brief Read resolvable address info struct. */ typedef struct { uint8_t op_code; /**< Operation code. @see enum gap_rslv_addr_read_op_id_t. */ gap_addr_t gap_addr; /**< Resolvable address info. */ } gap_rslv_addr_read_t; /** @brief Sync established indication. */ typedef struct { uint8_t phy; /**< PHY on which synchronization has been established. @see gap_phy_type. */ uint16_t intv; /**< Periodic advertising interval (in unit of 1.25ms, min is 7.5ms). */ uint8_t adv_sid; /**< Advertising SID. */ uint8_t clk_acc; /**< Advertiser clock accuracy. @see enum gapm_clk_acc. */ gap_bdaddr_t bd_addr; /**< Advertiser address. */ uint16_t sync_hdl; /**< Sync handle. */ } gap_sync_established_ind_t; /** @brief APP receives the extended advertising report indication info struct. */ typedef struct { uint8_t adv_type; /**< Advertising type. @see enum gap_adv_report_type_t. */ uint8_t adv_info; /**< Bit field providing information about the received report. @see enum gap_adv_report_info_t. */ gap_bdaddr_t broadcaster_addr; /**< Broadcaster device address. */ gap_bdaddr_t direct_addr; /**< Target address (in case of a directed advertising report). */ int8_t tx_pwr; /**< TX power (in dBm). */ int8_t rssi; /**< RSSI (between -127 and +20 dBm). */ uint8_t phy_prim; /**< Primary PHY on which advertising report has been received. */ uint8_t phy_second; /**< Secondary PHY on which advertising report has been received. */ uint8_t adv_sid; /**< Advertising SID , valid only for periodic advertising report. */ uint16_t period_adv_intv; /**< Periodic advertising interval (in unit of 1.25ms, min is 7.5ms), valid only for periodic advertising report. */ uint8_t per_sync_idx; /**< Periodic syncronization index, valid only for periodic advertising report. */ uint16_t length; /**< Report length. */ uint8_t data[ARRAY_EMPTY]; /**< Report. */ } gap_ext_adv_report_ind_t; /** @brief Name of peer device indication. */ typedef struct { gap_addr_t peer_addr; /**< Peer device bd address. */ uint8_t addr_type; /**< Peer device address type. */ uint8_t name_len; /**< Peer device name length. */ uint8_t name[ARRAY_EMPTY]; /**< Peer device name. */ } gap_peer_name_ind_t; /** @brief Connection parameter used to update connection parameters. */ typedef struct { uint16_t interval; /**< Connection interval. Range: 0x0006 to 0x0C80. Unit: 1.25 ms. Time range: 7.5 ms to 4 s. */ uint16_t latency; /**< Latency for the connection in number of connection events. Range: 0x0000 to 0x01F3. */ uint16_t sup_timeout; /**< Supervision timeout for the LE link. Range: 0x000A to 0x0C80, unit: 10 ms, time range: 100 ms to 32 s. */ } gap_conn_update_cmp_t; /** @brief The parameter of connection. */ typedef struct { uint16_t interval_min; /**< Minimum value for the connection interval. This shall be less than or equal to Conn_Interval_Max. Range: 0x0006 to 0x0C80, unit: 1.25 ms, time range: 7.5 ms to 4 s */ uint16_t interval_max; /**< Maximum value for the connection interval. This shall be greater than or equal to Conn_Interval_Min. Range: 0x0006 to 0x0C80, unit: 1.25 ms, time range: 7.5 ms to 4 s. */ uint16_t slave_latency; /**< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3. */ uint16_t sup_timeout; /**< Supervision timeout for the LE link. Range: 0x000A to 0x0C80, unit: 10 ms, time range: 100 ms to 32 s. */ } gap_conn_param_t; /** @brief The parameter of update connection. */ typedef struct { uint16_t interval_min; /**< Minimum value for the connection interval. This shall be less than or equal to Conn_Interval_Max. Range: 0x0006 to 0x0C80, unit: 1.25 ms, time range: 7.5 ms to 4 s */ uint16_t interval_max; /**< Maximum value for the connection interval. This shall be greater than or equal to Conn_Interval_Min. Range: 0x0006 to 0x0C80, unit: 1.25 ms, time range: 7.5 ms to 4 s. */ uint16_t slave_latency; /**< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3. */ uint16_t sup_timeout; /**< Supervision timeout for the LE link. range: 0x000A to 0x0C80, unit: 10 ms, Time range: 100 ms to 32 s. */ uint16_t ce_len; /**< The length of connection event needed for this LE connection. Range: 0x0002 to 0xFFFF, unit: 0.625 ms, time Range: 1.25 ms to 40.9 s. recommended value: 0x0002 for 1M phy, 0x0006 for coded phy */ } gap_conn_update_param_t; /** @brief Connection complete info. */ typedef struct { uint16_t conhdl; /**< Connection_Handle. Range: 0x0000-0x0EFF (all other values reserved for future use). */ uint16_t con_interval; /**< Connection interval. Range: 0x0006 to 0x0C80, unit: 1.25 ms, time range: 7.5 ms to 4 s. */ uint16_t con_latency; /**< Latency for the connection in number of connection events. Range: 0x0000 to 0x01F3. */ uint16_t sup_to; /**< Connection supervision timeout. Range: 0x000A to 0x0C80, unit: 10 ms, time range: 100 ms to 32 s. */ uint8_t clk_accuracy; /**< Clock accuracy (0x00: 500 ppm, 0x01: 250 ppm, 0x02: 150 ppm, 0x03: 100 ppm, 0x04: 75 ppm, 0x05:50 ppm, 0x06:30 ppm, 0x07:20 ppm, others: reserved for future use). */ uint8_t peer_addr_type; /**< Peer address type(0x00: Public Device Address, 0x01 : Random Device Address, others: reserved for future use). */ gap_addr_t peer_addr; /**< Peer BT address. */ gap_ll_role_type_t ll_role; /**< Device Role of LL Layer. */ } gap_conn_cmp_t; /** @brief Channel map structure. */ typedef struct { uint8_t map[GAP_CHNL_MAP_LEN]; /**< This parameter contains 37 1-bit fields. The nth bit (n is in the range of 0 to 36) contains the value for the link layer channel index n. Channel n is unused = 0, channel n is used = 1. The most significant bits are reserved for future use. */ } gap_chnl_map_t; /** @brief PHY info. */ typedef struct { uint8_t tx_phy; /**< LE PHY for data transmission. @see BLE_GAP_PHYS. */ uint8_t rx_phy; /**< LE PHY for data reception. @see BLE_GAP_PHYS. */ } gap_le_phy_ind_t; /** @brief Connection info. */ typedef union { int8_t rssi; /**< RSSI. */ gap_chnl_map_t chnl_map; /**< channel map. */ gap_le_phy_ind_t phy; /**< PHY indicaiton. */ uint8_t chan_sel_algo; /**< Chanel Selection algorithm, 0x00: LE Channel Selection Algorithm #1 is used. 0x01: LE Channel Selection Algorithm #2 is used.\n 0x02-0xFF: reserved. */ } gap_conn_info_t; /** @brief The info of connecting operation. */ typedef struct { uint8_t opcode; /**< Operation code. See @ref gap_get_conn_info_op_t. */ gap_conn_info_t info; /**< Connection info. */ } gap_conn_info_param_t; /** @brief Peer version info. */ typedef struct { uint16_t compid; /**