Microchip® Advanced Software Framework

ble_host_sdk/ble_services/ble_mgr/ble_manager.h File Reference

Data Structures

struct  _ble_common_event_cb_t
 
struct  _ble_gap_event_cb_t
 
struct  _ble_gatt_client_event_cb_t
 
struct  _ble_gatt_server_event_cb_t
 
struct  _ble_gatt_transparent_event_cb_t
 
struct  _ble_pairing_event_cb_t
 
struct  ble_mgr_adv_report_event_t
 Advertisement report event data. More...
 
struct  ble_mgr_adv_report_match_param_t
 

Macros

#define DEFAULT_SCAN_INTERVAL   0x0010
 
#define DEFAULT_SCAN_WINDOW   0x0010
 
#define MAX_ADV_PAYLOAD_LEN   31
 
#define MAX_ADV_REPORT_EVENT_LIST   20
 
#define MAX_COMMON_EVENT_SUBSCRIBERS   3
 
#define MAX_EVENT_PAYLOAD_SIZE   1024
 
#define MAX_EVENT_SIZE   10
 
#define MAX_GAP_EVENT_SUBSCRIBERS   3
 
#define MAX_GATT_CLIENT_EVENT_SUBSCRIBERS   3
 
#define MAX_GATT_SERVER_EVENT_SUBSCRIBERS   3
 
#define MAX_GATT_TRANSPARENT_SUBSCRIBERS   3
 
#define MAX_PAIRING_SUBSCRIBERS   3
 

Typedefs

typedef struct
_ble_common_event_cb_t 
ble_common_event_cb_t
 
typedef ble_status_t(* ble_event_callback_t )(event_msg_t *message)
 BLE Event callback generic type. More...
 
typedef struct _ble_gap_event_cb_t ble_gap_event_cb_t
 
typedef struct
_ble_gatt_client_event_cb_t 
ble_gatt_client_event_cb_t
 
typedef struct
_ble_gatt_server_event_cb_t 
ble_gatt_server_event_cb_t
 
typedef struct
_ble_gatt_transparent_event_cb_t 
ble_gatt_transparent_event_cb_t
 
typedef enum
Advertisement_Data_Type 
ble_mgr_adv_data_type
 
typedef struct
_ble_pairing_event_cb_t 
ble_pairing_event_cb_t
 

Enumerations

enum  Advertisement_Data_Type {
  ADV_FLAGS = 0x01,
  ADV_INCOMPLETE_128B_SERVICE_UUIDS = 0x06,
  ADV_COMPLETE_128B_SERVICE_UUIDS,
  ADV_SHORT_NAME,
  ADV_COMPLETE_NAME,
  ADV_TX_POWER_LEVEL,
  ADV_CLASS_OF_DEVICE = 0x0D,
  ADV_SERVICE_DATA = 0x16,
  ADV_ADVERTISING_INTERVAL = 0x1A,
  ADV_MANUFATURER_SPECIFIC_DATA = 0xFF
}
 
enum  ble_mgr_event_t {
  BLE_GAP_EVENT_TYPE,
  BLE_GATT_SERVER_EVENT_TYPE,
  BLE_GATT_CLIENT_EVENT_TYPE,
  BLE_COMMON_EVENT_TYPE,
  BLE_PAIRING_EVENT_TYPE,
  BLE_GATT_TP_EVENT_TYPE,
  BLE_GAP_EVENT_TYPE,
  BLE_GATT_CLIENT_EVENT_TYPE,
  BLE_GATT_SERVER_EVENT_TYPE,
  BLE_L2CAP_EVENT_TYPE,
  BLE_GATT_HTPT_EVENT_TYPE,
  BLE_DTM_EVENT_TYPE,
  BLE_CUSTOM_EVENT_TYPE
}
 BLE Manager event type. More...
 
enum  ble_mgr_handle_value_operation_t {
  BLE_GATT_NONE,
  BLE_GATT_NOTIFY,
  BLE_GATT_INDICATE
}
 
enum  ble_mgr_match_param_t {
  BLE_MATCHING_PARAM_NONE,
  BLE_MATCHING_PARAM_ADDRESS,
  BLE_MATCHING_PARAM_RSSI,
  BLE_MATCHING_PARAM_PAYLOAD
}
 BLE Manager advertisement report matching parameter to initiate connection. More...
 
enum  ble_mgr_state_t {
  BLE_MGR_STATE_INIT,
  BLE_MGR_STATE_ADVERTISING,
  BLE_MGR_STATE_SCANNING,
  BLE_MGRSTATE_CONNECTING,
  BLE_MGR_STATE_CONNECTED,
  BLE_MGR_STATE_DISCOVERING_SERVICE
}
 

Functions

ble_status_t ble_mgr_adv_start (const uint8_t *adv_data, uint8_t adv_data_length, const uint8_t *scan_data, uint8_t scan_data_len)
 Set advertisement data, scan response data, advertisement parameters and start advertisement. More...
 
ble_status_t ble_mgr_adv_stop (void)
 Stops ongoing advertisement. More...
 
ble_status_t ble_mgr_characteristic_indicate_set (ble_handle_t conn_handle, uint16_t desc_handle, bool enabled)
 Enable/disable characteristic indication. More...
 
ble_status_t ble_mgr_characteristic_notify_set (ble_handle_t conn_handle, uint16_t desc_handle, bool enabled)
 Enable/disable characteristic notification. More...
 
bool ble_mgr_check_match_param (ble_mgr_adv_report_event_t *adv_report)
 Check against the matching parameter set by the user, it could be BLE address, RSSI threshold or advertisement payload. More...
 
ble_status_t ble_mgr_device_init (void)
 Initialize platform, callback events and BLE interface. More...
 
bool ble_mgr_events_register_callback (ble_mgr_event_t event_type, const void *ble_event_handler)
 Register callback functions for BLE events. More...
 
event_status_t ble_mgr_get_event (event_t *event)
 Get BLE events and process them. More...
 
void ble_mgr_peripheral_device_match_params (ble_mgr_adv_report_match_param_t *match_param)
 Sets a matching parameter to find and connect with the device. More...
 
ble_status_t ble_mgr_scan_start (void)
 Sets BLE scan parameters and starts scanning. More...
 
ble_status_t ble_mgr_scan_stop (void)
 Stops the ongoing BLE scan. More...
 
ble_status_t ble_mgr_start_connection (ble_addr_t *address)
 Initiate a connection based on remote device address. More...
 
ble_status_t ble_mgr_transparent_uart_disable (ble_handle_t conn_handle)
 Disables transparentUART with remote device. More...
 
ble_status_t ble_mgr_transparent_uart_enable (ble_handle_t conn_handle)
 Enables transparentUART with remote device. More...
 
ble_status_t ble_mgr_transparent_uart_send (ble_handle_t conn_handle, const uint8_t *data, uint8_t datalen)
 Sends transparentUART data to remote device. More...
 

#define DEFAULT_SCAN_INTERVAL   0x0010

Referenced by ble_mgr_scan_start().

#define DEFAULT_SCAN_WINDOW   0x0010

Referenced by ble_mgr_scan_start().

#define MAX_ADV_PAYLOAD_LEN   31
#define MAX_ADV_REPORT_EVENT_LIST   20
#define MAX_COMMON_EVENT_SUBSCRIBERS   3
#define MAX_EVENT_PAYLOAD_SIZE   1024
#define MAX_EVENT_SIZE   10
#define MAX_GATT_CLIENT_EVENT_SUBSCRIBERS   3
#define MAX_GATT_SERVER_EVENT_SUBSCRIBERS   3
#define MAX_GATT_TRANSPARENT_SUBSCRIBERS   3
#define MAX_PAIRING_SUBSCRIBERS   3

ble_event_callback_t

BLE Event callback generic type.

Enumerator
ADV_FLAGS 
ADV_INCOMPLETE_128B_SERVICE_UUIDS 
ADV_COMPLETE_128B_SERVICE_UUIDS 
ADV_SHORT_NAME 
ADV_COMPLETE_NAME 
ADV_TX_POWER_LEVEL 
ADV_CLASS_OF_DEVICE 
ADV_SERVICE_DATA 
ADV_ADVERTISING_INTERVAL 
ADV_MANUFATURER_SPECIFIC_DATA 

BLE Manager event type.

This event types are used to subscribe the Group of BLE Event callbacks or un-subscribe the group of BLE Event callbacks

Enumerator
BLE_GAP_EVENT_TYPE 
BLE_GATT_SERVER_EVENT_TYPE 
BLE_GATT_CLIENT_EVENT_TYPE 
BLE_COMMON_EVENT_TYPE 
BLE_PAIRING_EVENT_TYPE 
BLE_GATT_TP_EVENT_TYPE 
BLE_GAP_EVENT_TYPE 

BLE GAP Events types.

BLE_GATT_CLIENT_EVENT_TYPE 

BLE GATT Client Event types.

BLE_GATT_SERVER_EVENT_TYPE 

BLE GATT Server Event types.

BLE_L2CAP_EVENT_TYPE 

BLE L2CAP Event types.

BLE_GATT_HTPT_EVENT_TYPE 

BLE HTPT Profile Event types.

BLE_DTM_EVENT_TYPE 

BLE DTM Event types.

BLE_CUSTOM_EVENT_TYPE 

Custom Event types (Application, ISR etc.,)

Enumerator
BLE_GATT_NONE 
BLE_GATT_NOTIFY 
BLE_GATT_INDICATE 

BLE Manager advertisement report matching parameter to initiate connection.

BLE advertisement data types.

Upon matching parameter, the connection will be initiated to remote device.

Enumerator
BLE_MATCHING_PARAM_NONE 
BLE_MATCHING_PARAM_ADDRESS 
BLE_MATCHING_PARAM_RSSI 
BLE_MATCHING_PARAM_PAYLOAD 
Enumerator
BLE_MGR_STATE_INIT 
BLE_MGR_STATE_ADVERTISING 
BLE_MGR_STATE_SCANNING 
BLE_MGRSTATE_CONNECTING 
BLE_MGR_STATE_CONNECTED 
BLE_MGR_STATE_DISCOVERING_SERVICE 

ble_status_t ble_mgr_adv_start ( const uint8_t *  adv_data,
uint8_t  adv_data_length,
const uint8_t *  scan_resp_data,
uint8_t  scan_reap_data_len 
)

Set advertisement data, scan response data, advertisement parameters and start advertisement.

Parameters
adv_dataAdvertisement data.
adv_data_lengthAdvertisement data length.
scan_resp_dataScan response data.
scan_reap_data_lenScan response data length.
Precondition
Platform and BLE interface has to be initialized using ble_mgr_device_init.
Returns
ble_status_t Status of setting advertisement data, scan response data, advertisement parameters or start advertisement operation.

References ble_adv_data_set(), ble_adv_param_set(), ble_adv_start(), BLE_INVALID_COMMAND_PARAMETERS, ble_mgr_state, BLE_MGR_STATE_ADVERTISING, ble_scan_resp_data_set(), BLE_SUCCESS, BM_ADV_CONNECTABLE_UNDIRECTED, DBG_LOG, and NULL.

Referenced by app_disconnected_cb(), and main().

ble_status_t ble_mgr_adv_stop ( void  )

Stops ongoing advertisement.

Parameters
None.
Precondition
Advertisement has to be started already.
Returns
ble_status_t Status of stop advertisement operation.

References ble_adv_stop(), BLE_SUCCESS, and DBG_LOG.

Referenced by main().

ble_status_t ble_mgr_characteristic_indicate_set ( ble_handle_t  conn_handle,
uint16_t  desc_handle,
bool  enabled 
)

Enable/disable characteristic indication.

Parameters
conn_handleConnection handle.
desc_handleClient characteristic config descriptor handle.
enabledEnable/disable the indication.
Precondition
None.
Returns
bool Status of enable/disable indication.

References ble_characteristic_write_with_response(), BLE_GATT_INDICATE, and BLE_GATT_NONE.

ble_status_t ble_mgr_characteristic_notify_set ( ble_handle_t  conn_handle,
uint16_t  desc_handle,
bool  enabled 
)

Enable/disable characteristic notification.

Parameters
conn_handleConnection handle.
desc_handleClient characteristic config descriptor handle.
enabledEnable/disable the notification.
Precondition
None.
Returns
bool Status of enable/disable notification.

References ble_characteristic_write_with_response(), BLE_GATT_NONE, and BLE_GATT_NOTIFY.

Referenced by main().

bool ble_mgr_check_match_param ( ble_mgr_adv_report_event_t adv_report)

Check against the matching parameter set by the user, it could be BLE address, RSSI threshold or advertisement payload.

Parameters
adv_reportAdvertisement report info got from scanning operation.
Precondition
Peripheral matching parameter has to be set using ble_mgr_peripheral_device_match_params.
Returns
bool Status of checking against matching parameter.

References ble_mgr_adv_report_event_t::addr, ble_mgr_adv_report_match_param_t::addr, BLE_MATCHING_PARAM_ADDRESS, BLE_MATCHING_PARAM_PAYLOAD, BLE_MATCHING_PARAM_RSSI, ble_mgr_adv_report_event_t::data, ble_mgr_adv_report_match_param_t::data, ble_mgr_adv_report_match_param_t::data_len, ble_mgr_adv_report_match_param_t::data_start, ble_mgr_adv_report_match_param_t::matching_param, ble_mgr_adv_report_event_t::rssi, and ble_mgr_adv_report_match_param_t::rssi.

Referenced by ble_mgr_adv_report_cb().

ble_status_t ble_mgr_device_init ( void  )

Initialize platform, callback events and BLE interface.

Parameters
None.
Precondition
None.
Returns
ble_status_t Status of the BLE interface initialization.

References ble_init(), ble_mgr_init(), BLE_SUCCESS, BM_MODE_Init(), DBG_LOG, and platform_init().

Referenced by main().

bool ble_mgr_events_register_callback ( ble_mgr_event_t  event_type,
const void *  ble_event_handler 
)

Register callback functions for BLE events.

Parameters
event_typeType of event, like GAP, GATT-Client, GATT-Server... etc.
ble_event_handlerFunction pointer to group of event handler callbacks.
scan_resp_dataScan response data.
scan_reap_data_lenScan response data length.
Precondition
Platform and BLE interface has to be initialized using ble_mgr_device_init.
Returns
ble_status_t Status of setting advertisement data, scan response data, advertisement parameters or start advertisement operation.

References BLE_COMMON_EVENT_TYPE, BLE_GAP_EVENT_TYPE, BLE_GATT_CLIENT_EVENT_TYPE, BLE_GATT_SERVER_EVENT_TYPE, BLE_GATT_TP_EVENT_TYPE, BLE_PAIRING_EVENT_TYPE, MAX_COMMON_EVENT_SUBSCRIBERS, MAX_GAP_EVENT_SUBSCRIBERS, MAX_GATT_CLIENT_EVENT_SUBSCRIBERS, MAX_GATT_SERVER_EVENT_SUBSCRIBERS, MAX_GATT_TRANSPARENT_SUBSCRIBERS, MAX_PAIRING_SUBSCRIBERS, and NULL.

Referenced by app_init(), and ble_mgr_init().

event_status_t ble_mgr_get_event ( event_t event)

Get BLE events and process them.

Parameters
eventCarries event ID, parameters and length.
Precondition
Platform and BLE interface has to be initialized using ble_mgr_device_init.
Returns
event_status_t Status of event get operation.

References ble_event_get(), BLE_EVENT_SUCCESS, and ble_mgr_event_manager().

Referenced by main().

void ble_mgr_peripheral_device_match_params ( ble_mgr_adv_report_match_param_t match_param)

Sets a matching parameter to find and connect with the device.

Parameters
match_paramMatching parameter, it could be BLE address, RSSI threshold or advertisement payload.
Precondition
None.
Returns
None.

Referenced by main().

ble_status_t ble_mgr_scan_start ( void  )

Sets BLE scan parameters and starts scanning.

Parameters
None.
Precondition
Platform and BLE interface has to be initialized using ble_mgr_device_init.
Returns
ble_status_t Status of the setting scan parameter or scan start operation.

References ble_mgr_state, BLE_MGR_STATE_SCANNING, BLE_SCAN_ACTIVE, BLE_SCAN_DUPLICATE_FILTER_ENABLED, BLE_SCAN_ENABLED, ble_scan_param_set(), ble_scan_start(), BLE_SUCCESS, DBG_LOG, DEFAULT_SCAN_INTERVAL, and DEFAULT_SCAN_WINDOW.

Referenced by app_disconnected_cb(), and main().

ble_status_t ble_mgr_scan_stop ( void  )

Stops the ongoing BLE scan.

Parameters
None.
Precondition
Platform and BLE interface has to be initialized using ble_mgr_device_init.
Returns
ble_status_t Status of the scan stop operation.

References ble_mgr_state, BLE_MGR_STATE_INIT, BLE_SCAN_DISABLED, BLE_SCAN_DUPLICATE_FILTER_ENABLED, ble_scan_start(), BLE_SUCCESS, and DBG_LOG.

Referenced by app_disconnected_cb(), and main().

ble_status_t ble_mgr_start_connection ( ble_addr_t address)

Initiate a connection based on remote device address.

Parameters
addressAddress of remote device.
Precondition
None.
Returns
bool Status of connection request.

References BLE_CONN_WHITELIST_FILTER_DISABLED, ble_create_connection(), BLE_SUCCESS, and DBG_LOG.

ble_status_t ble_mgr_transparent_uart_disable ( ble_handle_t  conn_handle)

Disables transparentUART with remote device.

Parameters
conn_handleConnection handle of remote device.
Precondition
Connection is established with remote device and transparentUART is enabled.
Returns
ble_status_t Status of transparentUART enable operation.

References BLE_SUCCESS, ble_transparent_uart_enable(), PACKED::conn_handle, and DBG_LOG.

Referenced by app_disconnected_cb().

ble_status_t ble_mgr_transparent_uart_enable ( ble_handle_t  conn_handle)

Enables transparentUART with remote device.

Parameters
conn_handleConnection handle of remote device.
Precondition
Connection is established with remote device.
Returns
ble_status_t Status of transparentUART enable operation.

References BLE_SUCCESS, ble_transparent_uart_enable(), PACKED::conn_handle, and DBG_LOG.

Referenced by app_connected_cb().

ble_status_t ble_mgr_transparent_uart_send ( ble_handle_t  conn_handle,
const uint8_t *  data,
uint8_t  datalen 
)

Sends transparentUART data to remote device.

Parameters
conn_handleConnection handle of remote device.
dataData that needs to be sent to remote device.
datalenLength of data that needs to be sent to remote device.
Precondition
TransparentUART is enabled with remote device using ble_mgr_transparent_uart_enable.
Returns
ble_status_t Status of transparentUART send data operation.

References BLE_SUCCESS, ble_transparent_uart_data_send(), DBG_LOG, and DBG_LOG_CONT.

Referenced by app_send_transparent_uart_data().