Files
hpw421/component/ble/ip/ble/api/xc_gap_api.h
T
2026-07-03 18:08:25 +08:00

631 lines
30 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
****************************************************************************************
* @file xc_gap_api.h
* @brief GAP API.
* Copyright (c) 2022 - 2025, XinChip
* All rights reserved.
****************************************************************************************
*/
#ifndef __XC_GAP_API_H__
#define __XC_GAP_API_H__
#include "gapc_msg.h"
#include "gapm_msg.h"
#include "ke_msg.h"
/*
* DEFINES
****************************************************************************************
*/
#define CE_LEN_MIN 2
#define CE_LEN_MAX 4
#define DEVICE_NAME_MAX_LEN 18
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Called only in the app_init(). It's used to reset the device but setting\n
* device configuration is still required to use host stack.\n
* Software reset: This will initialize the RW-BLE Host stack rearrange to default settings the ATT, GAP, GATT,\n
* L2CAP and SMP blocks. Furthermore, this will cause the host to send a reset command down to the link\n
* layer part.
* Platform reset: Use platform mechanism to reset hardware.
* @note Trigger GAPM_CMP_EVT, operation is GAPM_RESET
*****************************************************************************************
*/
void xc_ble_gapm_reset(void);
/**
****************************************************************************************
* @brief Set the device configuration such as:\n
* Device role\n
* Manage device address type: Public, Private static or Generated for Privacy\n
* Internal IRK used to generate resolvable random address.\n
* Set Internal GAP / GATT service start.\n
* Set specific write permissions on the appearance and name attributes in internal GAP database.\n
* Manage presence of some attribute.\n
* Configure Data Length Extension features.\n
* The set device configuration first resets the device to close all active link and configured profiles.\n
* This command must be sent before adding profiles and start air activities.
* @note
* Trigger GAPM_CMP_EVT, operation is GAPM_SET_DEV_CONFIG.
*
* @param[in] cfg_param Pointer to the device configurtion
* structure.
*
****************************************************************************************
*/
void xc_ble_set_dev_config(struct gapm_set_dev_config_cmd *cfg_param);
/**
****************************************************************************************
* @brief Get information about local device such as:\n
* Local Device Name\n
* Local Device Version\n
* Local Device Public BD Address\n
* Data Length Extension parameters\n
* Antenna information
*
* @note
* operation is:\n
* GAPM_DEV_VERSION_IND: If local device version is requested.\n
* GAPM_DEV_BDADDR_IND: if local device public BD Address is requested.\n
* GAPM_DEV_ADV_TX_POWER_IND: If advertising TX power level is requested.\n
* GAPM_DBG_MEM_INFO_IND: if memory information are requested (DEBUG ONLY).\n
* GAPM_SUGG_DFLT_DATA_LEN_IND: if suggested Default Data Length is requested.\n
* GAPM_MAX_DATA_LEN_IND: if Maximum Data Length is requested.\n
* GAPM_NB_ADV_SETS_IND: if number of advertising sets is requested.\n
* GAPM_MAX_ADV_DATA_LEN_IND: if maximum advertising data length is requested.\n
* GAPM_ANTENNA_INF_IND: if antenna information requested.\n
* GAPM_CMP_EVT: When operation completed.\n
*
* @param[in] cmd Command for information
*
****************************************************************************************
*/
void xc_ble_get_dev_info(struct gapm_get_dev_info_cmd *cmd);
/**
****************************************************************************************
* @brief Resolve provided random address using array of Identity Resolution Key (IRK) exchanged and bonded with\n
* devices during pairing operations.\n
* Operation will complete successfully if address has been correctly resolved and GAPM_ADDR_SOLVED_IND\n
* message will be triggered to inform which key has been used to perform resolution.\n
* Else operation complete with GAP_ERR_NOT_FOUND error status code.
*
* @note
* GAPM_ADDR_SOLVED_IND: triggered if address correctly resolved.\n
* GAPM_CMP_EVT: When operation completed, operation is GAPM_RESOLV_ADDR.
*
* @param[in] nb_key Number of provided IRK (sahlle be > 0).
* @param[in] addr Pointer to resolvable random address to solve.
* @param[in] irk Pointer to array of IRK used for address resolution (MSB -> LSB).
*
****************************************************************************************
*/
void xc_ble_resolve_addr(uint8_t nb_key,gap_addr_t *addr,uint8_t *irk);
/**
****************************************************************************************
* @brief Generate a random device address without starting any air operation. This can be useful for privacy in order\n
* to generate the reconnection address on demand.
*
* @note
* GAPM_DEV_BDADDR_IND: triggered when address generated.\n
* GAPM_CMP_EVT: When operation completed, operation is GAPM_GEN_RAND_ADDR.
*
* @param[in] p_param random address type. @see enum random_addr_type
****************************************************************************************
*/
void xc_ble_gen_random_addr(struct gapm_gen_rand_addr_cmd *p_param);
/**
****************************************************************************************
* @brief Read the local P-256 Public Key. This key is renewed each time this command is called by\n
* requester and so each pairing using secure connection.
*
* @note
* GAPM_PUB_KEY_IND: triggered when P-256 Public Key properly read\n
* GAPM_CMP_EVT: When operation completed, operation is GAPM_GET_PUB_KEY.
*
****************************************************************************************
*/
void xc_ble_get_pub_key(void);
/**
****************************************************************************************
* @brief Used to generate an 8-byte random number. This can be useful to generate LTK\n
* random number before distributing it.
*
* @note
* GAPM_GEN_RAND_NB_IND: triggered when random number is generated.\n
* GAPM_CMP_EVT: When operation completed, operation is GAPM_GEN_RAND_NB.
*
****************************************************************************************
*/
void xc_ble_gen_random_nb(void);
/**
****************************************************************************************
* @brief Command to change the current IRK for a renewed one, it can be used every time\n
* no air operation is being performed.
* @note
* GAPM_CMP_EVT: When operation completed,
*
* @note This can only be called during no air operation, operation is GAPM_SET_IRK.
*
* @param[out] p_param Pointer to a security key data structure.
*
****************************************************************************************
*/
void xc_ble_set_irk(gap_sec_key_t *irk);
/**
****************************************************************************************
* @brief Get local or peer resolvable private address
*
* @note operation is:\n
* GAPM_GET_RAL_LOC_ADDR: Get resolving local address\n
* GAPM_GET_RAL_PEER_ADDR: Get resolving peer address\n
*
* @note
* GAPM_RAL_ADDR_IND: Return requested address.\n
* GAPM_CMP_EVT: When operation has been completed.
*
* @param[in] p_param Pointer Read local or peer address cmd ptr.
*
****************************************************************************************
*/
void xc_ble_get_ral_addr(struct gapm_get_ral_addr_cmd *p_param);
/**
****************************************************************************************
* @brief Request to set the content of the Resolving List. The current content of the indicated list will be cleared\n
* and replaced by the indicated content.\n
* If number of addresses to be added in the list is greater than list size, a GAP_ERR_INSUFF_RESOURCES status\n
* is returned in the GAPM_CMP_EVT message.\n
* A device can be present only once in the list. If not the case a GAP_ERR_INVALID_PARAM status is returned.
*
* @note
* GAPM_CMP_EVT: When operation has been completed, operation is GAPM_SET_RAL.
*
* @note This will overwrite the current resolving list.
*
* @param[in] size Number of entries to be added in the list. 0 means that list content has to be cleared.
* @param[in] ral_info Pointer to list of entries to be added in the list.
*
****************************************************************************************
*/
void xc_ble_set_ral_list(uint8_t size, struct gap_ral_dev_info *ral_info);
/**
****************************************************************************************
* @brief Request to set the content of the White List. The current content of the indicated list will be cleared\n
* and replaced by the indicated content.\n
* If number of addresses to be added in the list is greater than list size, a GAP_ERR_INSUFF_RESOURCES status\n
* is returned in the GAPM_CMP_EVT message.\n
* A device can be present only once in the list. If not the case a GAP_ERR_INVALID_PARAM status is returned.
*
* @note
* GAPM_CMP_EVT: When operation has been completed, operation is GAPM_SET_WL.
*
* @note This will overwrite the current white list.
*
* @param[in] size Number of entries to be added in the list. 0 means that list content has to be cleared.
* @param[in] wl_info Pointer to list of entries to be added in the list.
*
****************************************************************************************
*/
void xc_ble_set_white_list(uint8_t size, gap_bdaddr_t *wl_info);
/**
****************************************************************************************
* @brief Create an advertising activity.
* @note The number of activities that can be created in parallel is limited. If the limit has been reached and a new\n
* activity cannot be created, a GAP_ERR_INSUFF_RESOURCES status will be returned in the GAPM_CMT_EVT message.
* @note
* GAPM_ACTIVITY_CREATED_IND: Once the requested activity has been successfully created.\n
* GAPM_CMP_EVT: When operation has been completed, operation is GAPM_CREATE_ADV_ACTIVITY.
*
* @param[in] adv_creat_param Pointer to activity create
*structure.
*
****************************************************************************************
*/
void xc_ble_advertise_create(struct gapm_activity_create_adv_cmd *adv_creat_param);
/**
****************************************************************************************
* @brief Set advertising data for a given previously created advertising activity identified by its\n
* activity identifier.
* @note If the provided identifier appears not to identify an existing advertising activity, GAPM_CMP_EVT message\n
* will be returned with a GAP_ERR_INVALID_PARAM status.
*
* @note
* GAPM_CMP_EVT: When operation completed, operation is GAPM_SET_ADV_DATA.
*
* @param[in] actv_idx Activity identifier
* @param[in] adv_data_length ADV data length
* @param[in] p_adv_data Pointer to adv data
*
****************************************************************************************
*/
void xc_ble_set_adv_data(uint8_t actv_idx, uint16_t adv_data_length, uint8_t *p_adv_data);
/**
****************************************************************************************
* @brief Set Scan response data for a given previously created advertising activity identified by its\n
* activity identifier.
* @note If the provided identifier appears not to identify an existing advertising activity, GAPM_CMP_EVT message\n
* will be returned with a GAP_ERR_INVALID_PARAM status.
*
* @note
* GAPM_CMP_EVT: When operation completed, operation is GAPM_SET_SCAN_RSP_DATA.
*
* @param[in] actv_idx Activity identifier
* @param[in] scan_rsp_data_length Scan response data length
* @param[in] p_scan_rsp_data Pointer to scan response data.
*
*
****************************************************************************************
*/
void xc_ble_set_scan_rsp_data(uint8_t actv_idx, uint16_t scan_rsp_data_length, uint8_t *p_scan_rsp_data);
/**
****************************************************************************************
* @brief Start an advertising activity.
* @note Several advertising activities can be started in parallel.
*
* @note
* GAPM_CMP_EVT: When operation has well been started or if an error has been detected, operation is GAPM_START_ACTIVITY.
* @param[in] adv_start_param Pointer to activity start structure.
*
****************************************************************************************
*/
void xc_ble_advertise_start(struct gapm_activity_start_cmd *adv_start_param);
/**
****************************************************************************************
* @brief Create a scanning activity.
* @note
* The number of activities that can be created in parallel is limited. If the limit has been reached and a new\n
* activity cannot be created, a GAP_ERR_INSUFF_RESOURCES status will be returned in the GAPM_CMT_EVT message.
* @note
* GAPM_ACTIVITY_CREATED_IND: Once the requested activity has been successfully created.\n
* GAPM_CMP_EVT: When operation has been completed, operation is GAPM_CREATE_SCAN_ACTIVITY.
*
* @param[in] scan_creat_param Pointer to activity create
*structure.
*
****************************************************************************************
*/
void xc_ble_scan_create(struct gapm_activity_create_cmd *scan_creat_param);
/**
****************************************************************************************
* @brief Start a scanning activity.
*
* @note it is not possible to start several scanning or several initiating activities as controller only\n
* supports one scanning and one initiating procedure to be run in parallel.\n
* It is then application responsibility to decide which scanning/initiating activity can be started.\n
* If this rule is not respected, GAPM_CMP_EVT message will be returned with a\n
* GAP_ERR_COMMAND_DISALLOWED status.
*
* @note
* GAPM_CMP_EVT: When operation has well been started or if an error has been detected, operation is GAPM_START_ACTIVITY.
* @param[in] scan_start_param Pointer to activity start structure.
*
****************************************************************************************
*/
void xc_ble_scan_start(struct gapm_activity_start_cmd *scan_start_param);
/**
****************************************************************************************
* @brief Create a initiating activity.
*
* @note
* GAPM_ACTIVITY_CREATED_IND: Once the requested activity has been successfully created.\n
* GAPM_CMP_EVT: When operation has been completed, operation is GAPM_CREATE_INIT_ACTIVITY.\n
* The number of activities that can be created in parallel is limited. If the limit has been reached and a new\n
* activity cannot be created, a GAP_ERR_INSUFF_RESOURCES status will be returned in the GAPM_CMT_EVT message.
* @param[in] init_creat_param Pointer to activity create
*structure.
*
****************************************************************************************
*/
void xc_ble_init_create(struct gapm_activity_create_cmd *init_create_param);
/**
****************************************************************************************
* @brief Start a initiating activity.
*
* @note
* GAPM_CMP_EVT: When operation has well been started or if an error has been detected, operation is GAPM_ACTIVITY_START_CMD.\n
* it is not possible to start several scanning or\n
* several initiating activities as controller only supports one scanning and one initiating procedure to be run in parallel.\n
* It is then application responsibility to decide which scanning/initiating activity can be started.\n
* If this rule is not respected, GAPM_CMP_EVT message will be returned with a\n
* GAP_ERR_COMMAND_DISALLOWED status.
* @param[in] init_start_param Pointer to activity start structure.
*
****************************************************************************************
*/
void xc_ble_init_start(struct gapm_activity_start_cmd *init_start_param);
/**
****************************************************************************************
* @brief Stop an activity or all activities.
*
* @note Request the host to stop a started activity identified by its activity identifier.\n
* If the requested activity does not exist, GAPM_CMP_EVT message is returned with a\n
* GAP_ERR_INVALID_PARAM status. If the activity exists but was not started, error GAP_ERR_COMMAND_DISALLOWED\n
* is and no GAPM_ACTIVITY_STOPPED_IND message is sent.
*
* @note
* GAPM_ACTIVITY_STOPPED_IND: Once the requested activity has been successfully stopped.\n
* GAPM_CMP_EVT: When operation has been completed, operation is GAPM_ACTIVITY_START_CMD or GAPM_STOP_ALL_ACTIVITIES.
*
* @param[in] actv_idx Activity index ,If less than 0, stop all
*activities
*
****************************************************************************************
*/
void xc_ble_activity_stop(int actv_idx);
/**
****************************************************************************************
* @brief Delete an activity or all activities
*
* @note Request the host to delete either an activity identified by its activity identifier or all currently existing\n
* activities.\n
* If selected activity is not stopped (GAPM_DELETE_ACTIVITY operation) or if at least one activity is still\n
* running (GAPM_DELETE_ALL_ACTIVITIES), a GAP_ERR_COMMAND_DISALLOWED status will be returned in the\n
* GAPM_CMP_EVT message.
*
* @note
* GAPM_CMP_EVT: When operation has been completed, operation is GAPM_DELETE_ACTIVITY or GAPM_DELETE_ALL_ACTIVITIES.
*
* @param[in] actv_idx Activity index , If less than 0, stop all activities.
*activities
*
****************************************************************************************
*/
void xc_ble_activity_delete(int actv_idx);
/**
****************************************************************************************
* @brief Request for disconnection of the link. This can be requested by master or slave of the connection.
* @note
* Reason of disconnection shall be a valid disconnection reason @see enum co_error
* @note
* Either master or slave can call this function.
*
* @param[in] conidx Connection index.
* @param[in] reason Reason of disconnection, 0x13:User on the remote device terminated the connnection
*
****************************************************************************************
*/
void xc_ble_disconnect(int conidx, uint32_t reason);
/**
****************************************************************************************
* @brief Update connection paramters
*
* @note
* GAPC_PARAM_UPDATED_IND: event triggered if connection parameters are updated.\n
* GAPC_CMP_EVT: When operation completed, operation is GAPC_UPDATE_PARAMS.
*
* @note: Can be used by both master and slave
*
* @param[in] conidx Connection index
* @param[in] p_conn_param Pointer to update parameters structure.
*
****************************************************************************************
*/
void xc_ble_update_param(int conidx, uint16_t intv_min, uint16_t intv_max,
uint16_t latency, uint16_t time_out);
/**
****************************************************************************************
* @brief Confirm connection request\n
* Set specific link security configuration and bonding data,\n
* Set connection bond data,\n
* Authentication and authorization link configuration.\n
* This confirmation message shall be sent by application after receiving a GAPC_CONNECTION_REQ_IND in\n
* order to enables local attribute tasks and security manager for the connection.\n
* It can be resent later if peer device information is retrieved later (for instance when a master initiates an\n
* encryption, information of the LTK can be used to identify peer device). In fact, when encryption is initiated\n
* by master device, it uses a couple of encryption diversifier (ediv) and random number (rand_nb) that can be\n
* used to retrieve corresponding encryption Long Term Key (LTK) that has been exchanged during a previous\n
* connection. By retrieving the LTK, we retrieve a known device and in that case before terminating encryption\n
* procedure, application shall update connection parameters.
* @note This is to response to the event "GAP_EVT_CONN_REQ". Application can\n
* call this API in the call back.\n
* If authentication parameter is marked has “Not Bonded”, other parameters are ignored and peer\n
* device is considered as an unknown device.
*
* @param[in] conidx Connection index
* @param[in] p_cfm Pointer to comfirm parameters structure.
*
****************************************************************************************
*/
void xc_ble_conn_cfm(int conidx, struct gapc_connection_cfm *p_cfm);
/**
****************************************************************************************
* @brief Retrieve information about peer device or about the current active link.
*
* @note
* Getting rssi information about peer device:\n
* operation is :
* GAPC_PEER_ATT_INFO_IND: Event triggered when peer device attribute DB info such as device name,\n
* appearance, slave preferred parameters or address resolution supported is requested.\n
* GAPC_PEER_VERSION_IND: Event triggered when peer device version is requested\n
* GAPC_PEER_FEATURES_IND: Event triggered when peer device features are requested\n
* GAPC_CON_RSSI_IND: Event triggered when connection RSSI is requested\n
* GAPC_CON_CHANNEL_MAP_IND: Event triggered when connection channel map is requested\n
* GAPC_LE_PING_TO_VAL_IND: Event triggered when LE Ping timeout value is requested\n
* GAPC_LE_PHY_IND: Event triggered when RX/TX PHYs are requested\n
* GAPC_CHAN_SEL_ALGO_IND: Event triggered when current channel selection algorithm is requested.\n
* GAPC_LOC_TX_PWR_IND: Event trigger when reading local TX power value\n
* GAPC_PEER_TX_PWR_IND: Event trigger when reading peer TX power value\n
* GAPC_CMP_EVT: When operation completed.
*
* @param[in] conidx Connection index
* @param[in] get_info Pointer to parameters structure operation
*
****************************************************************************************
*/
void xc_ble_get_peer_info(int conidx, struct gapc_get_info_cmd *get_info);
/**
****************************************************************************************
* @brief Used by to accept or refuse connection parameters proposed by peer device.
*
* @param[in] conidx Connection index
* @param[in] update_cfm Pointer to parameters structure.
*
****************************************************************************************
*/
void xc_ble_param_update_cfm(int conidx, struct gapc_param_update_cfm *update_cfm);
/**
****************************************************************************************
* @brief Requested by master of the link in order to initiate the bond procedure. It\n
* contains pairing requirement of initiator.
*
* @note
* GAPC_BOND_REQ_IND: Triggered if some information should be provided by device during the pairing.\n
* GAPC_BOND_IND: Triggered in order to receive key exchanged by peer device and get pairing status.\n
* GAPC_CMP_EVT: When operation completed, operation is GAPC_BOND.
*
* @param[in] conidx Connection index
* @param[in] p_bond Pointer to pairing requirement of initiator.
*
****************************************************************************************
*/
void xc_ble_bond(int conidx, struct gapc_bond_cmd *p_param);
/**
****************************************************************************************
* @brief Confirm bond request.
* @note
* Confirmation message to send after receiving a GAPC_BOND_REQ_IND message\n
* This message can contain:\n
* Slave pairing information\n
* Pairing temporary key (TK)\n
* Key to provide to the peer device during key exchange.
*
* @param[in] conidx Connection index
* @param[in] p_cfm Pointer to bond confirm data structure.
*
****************************************************************************************
*/
void xc_ble_bond_cfm(int conidx, struct gapc_bond_cfm *p_param);
/**
****************************************************************************************
* @brief Called when the peer device obtains information about the local device.\n
* Device Name,\n
* Device Appearance,\n
* Icon Device Slave preferred parameters,\n
* Device Central address resolution,\n
* Device database hash value,\n
* Resolvable Private address only after bond.\n
*
* @param[in] conidx Connection index
* @param[in] p_param Pointer to data structure.
****************************************************************************************
*/
void xc_ble_get_dev_info_cfm(int conidx, struct gapc_get_dev_info_cfm *p_param);
/**
****************************************************************************************
* @brief Send the write confirmation to the stack.
*
* @param[in] conidx Connection index
* @param[in] p_param Pointer to data structure.
****************************************************************************************
*/
void xc_ble_set_dev_info_cfm(int conidx, struct gapc_set_dev_info_cfm *p_param);
/**
****************************************************************************************
* @brief This operation can be requested only by master of the link in order to initiate encryption procedure. It\n
* contains Long Term Key that should be used during the encryption.
*
* @note
* GAPC_ENCRYPT_IND: Triggered if encryption operation succeed.\n
* GAPC_CMP_EVT: When operation completed. operation is GAPC_ENCRYPT.
*
* @param[in] conidx Connection index
* @param[in] p_param Pointer to data structure.
****************************************************************************************
*/
void xc_ble_encrypt(int conidx, struct gapc_encrypt_cmd *p_param);
/**
****************************************************************************************
* @brief Confirmation message to send after receiving a GAPC_ENCRYPT_REQ_IND message\n
* This message can is used to inform if encryption key has been found, if yes found Long Term Key and its size\n
* shall be provided.
*
* @param[in] conidx Connection index
* @param[in] p_param Pointer to data structure
****************************************************************************************
*/
void xc_ble_encrypt_cfm(int conidx, struct gapc_encrypt_cfm *p_param);
/**
****************************************************************************************
* @brief This operation can be requested only by slave of the link in order to initiate security request procedure. It\n
* contains authentication level requested by current device.
*
* @note
* GAPC_CMP_EVT: When operation completed. operation is GAPC_SECURITY_REQ.
*
* @param[in] conidx Connection index
* @param[in] p_param Pointer to data structure.
****************************************************************************************
*/
void xc_ble_req_security(int conidx, uint8_t sec_auth);
/**
****************************************************************************************
* @brief This operation to define the preferred packet length to be used by the controller\n
*
* @note
* GAPC_CMP_EVT: When operation completed. operation is GAPC_SECURITY_REQ.
* GAPC_LE_PKT_SIZE_IND: Event triggered with the new values
*
* @param[in] conidx Connection index
* @param[in] tx_octets Preferred maximum number of payload octets that the local Controller should include in\n
* a single Link Layer Data Channel PDU.
* @param[in] tx_time Preferred maximum number of microseconds that the local Controller should use to transmit\n
* a single Link Layer Data Channel PDU
****************************************************************************************
*/
void xc_ble_set_pkt_size(int conidx, uint16_t tx_octets, uint16_t tx_time);
/**
****************************************************************************************
* @brief This operation can be requested only by master of the link in order to set the channel map of the device.\n
*
* @note
* GAPC_CMP_EVT: When operation completed. operation is GAPC_SECURITY_REQ.
*
* @param[in] p_param Pointer to data structure.
****************************************************************************************
*/
void xc_ble_set_channel_map(struct gapm_set_channel_map_cmd *p_param);
#endif // __XC_GAP_API_H__