![]() |
BSB Developer Docs
|
Logic representing BSB as a Ble device. More...
#include "ble_connection.h"#include "ble_security.h"#include "../transport/ble_transmitter.h"#include "../../service/ble_service.h"#include <furi.h>Go to the source code of this file.
Typedefs | |
| typedef struct BleDevice | BleDevice |
| Opaque BleDevice type declaration. | |
Enumerations | |
| enum | BleDeviceState { BleDeviceStateIdle , BleDeviceStateAdvertising , BleDeviceStateConnected , BleDeviceStateStopping , BleDeviceStateForgetting , BleDeviceStateError } |
| Enumeration of device states. More... | |
Functions | |
| BleDevice * | ble_device_alloc (BleTransmitter *transmitter) |
| Create ble device instance Only one instance is created at device startup. | |
| void | ble_device_free (BleDevice *instance) |
| Free device instance. | |
| bool | ble_device_register_service (BleDevice *instance, BleServiceObject *service) |
| Performs service registration in device registry and on nwp side. | |
| BleConnectionContext * | ble_device_get_connection_context (BleDevice *instance) |
| Gets context created during connection establishment for further use. | |
| bool | ble_device_connection_open (BleDevice *instance, BleDeviceAddressType type, const uint8_t *peer_addr) |
| Process connection event from nwp. | |
| bool | ble_device_connection_close (BleDevice *instance) |
| Process disconnection event from nwp. | |
| void | ble_device_connection_update (BleDevice *instance, FuriEventLoop *event_loop, BleConnectionUpdateParametersDoneCallback update_done_cb, void *ctx) |
| Start updating parameters after connection was established. | |
| bool | ble_device_disconnect (BleDevice *instance) |
| Force disconnect from the remote. | |
| bool | ble_device_is_connected (BleDevice *instance) |
| Check if device connected. | |
| BleDeviceState | ble_device_get_state (BleDevice *instance) |
| Get device state. | |
| void | ble_device_set_name (BleDevice *instance, const char *name) |
| Set device name. | |
| bool | ble_device_start (BleDevice *instance) |
| Starts device advertising. | |
| bool | ble_device_stop (BleDevice *instance) |
| Stop device advertising. | |
| void | ble_device_set_mtu (BleDevice *instance, uint16_t mtu) |
| Save mtu value received from nwp and calculate max payload size. | |
| bool | ble_device_process_write_request (BleDevice *instance, const uint8_t *remote_addr, const uint16_t handle, const size_t data_size, const void *data) |
| Process all write requests using service registry. | |
| bool | ble_device_process_read_request (BleDevice *instance, uint8_t *addr, uint8_t type, uint16_t handle, uint16_t offset) |
| Process read requests using service registry. | |
| void | ble_device_receive_confirm (BleDevice *instance, uint16_t handle, uint8_t cccd_value) |
| Send confirmation that write request is done. | |
| void | ble_device_send_data (BleDevice *instance, uint16_t handle, uint16_t data_size, const uint8_t *data, uint16_t cccd_value) |
| Send data over ble. | |
| BleSecurityData * | ble_device_get_security_data (BleDevice *instance) |
| Get pointer to security instance. | |
| bool | ble_device_is_paired (BleDevice *instance) |
| Check if BSB is paired or not. | |
| void | ble_device_response_pairing_capabilities (BleDevice *instance) |
| Send respose with pairing capabilities on event from nwp. | |
| void | ble_device_request_pairing (BleDevice *instance) |
| Attempt to request pairing Used in attempt to avoid some pairing corner cases when BSB has pairing but other side does not. | |
| bool | ble_device_send_encryption_response (BleDevice *instance) |
| Send pairing keys data as a respose in format required by nwp. | |
| void | ble_device_handle_encryption_start (BleDevice *instance, rsi_bt_event_encryption_enabled_t *encryption_data) |
| Performs first pairing steps on event from nwp. | |
| bool | ble_device_forget_paired (BleDevice *instance) |
| Delete currently stored pairing data. | |
Logic representing BSB as a Ble device.
| enum BleDeviceState |
Enumeration of device states.
| BleDevice * ble_device_alloc | ( | BleTransmitter * | transmitter | ) |
Create ble device instance Only one instance is created at device startup.
| [in] | transmitter | used internally to control data transmission |
We need this for advertising module. Without this, advertise doesn't want to work
TODO: Read bsb ble features once we find out how to do that
| bool ble_device_connection_close | ( | BleDevice * | instance | ) |
Process disconnection event from nwp.
This function is called when nwp sends event that remote device was disconnected. It destroys connection context, flushes all pending data, because they are not needed anymore and switch device state to idle or advertising depending on state
| [in] | instance | of device |
| bool ble_device_connection_open | ( | BleDevice * | instance, |
| BleDeviceAddressType | type, | ||
| const uint8_t * | peer_addr ) |
Process connection event from nwp.
This function is called when nwp sends event that remote device was connected. It creates connection context and stores parameters.
| [in] | instance | of device |
| [in] | type | of connected device address |
| [in] | peer_addr | connected device address |
| void ble_device_connection_update | ( | BleDevice * | instance, |
| FuriEventLoop * | event_loop, | ||
| BleConnectionUpdateParametersDoneCallback | update_done_cb, | ||
| void * | ctx ) |
Start updating parameters after connection was established.
Calls ble_connection_start_update_parameters under the hood
| [in] | instance | of device |
| [in] | event_loop | instance, through which processing is done |
| [in] | update_done_cb | done callback will be triggered when update done |
| [in] | ctx | done callback context |
| bool ble_device_disconnect | ( | BleDevice * | instance | ) |
Force disconnect from the remote.
| [in] | instance | of device |
| bool ble_device_forget_paired | ( | BleDevice * | instance | ) |
Delete currently stored pairing data.
| [in] | instance | of device |
| void ble_device_free | ( | BleDevice * | instance | ) |
Free device instance.
| [in] | instance | of device |
| BleConnectionContext * ble_device_get_connection_context | ( | BleDevice * | instance | ) |
Gets context created during connection establishment for further use.
| [in] | instance | of device |
| BleSecurityData * ble_device_get_security_data | ( | BleDevice * | instance | ) |
Get pointer to security instance.
| [in] | instance | of device |
| BleDeviceState ble_device_get_state | ( | BleDevice * | instance | ) |
Get device state.
| [in] | instance | of device |
| void ble_device_handle_encryption_start | ( | BleDevice * | instance, |
| rsi_bt_event_encryption_enabled_t * | encryption_data ) |
Performs first pairing steps on event from nwp.
| [in] | instance | of device |
| [in] | encryption_data | from nwp |
| bool ble_device_is_connected | ( | BleDevice * | instance | ) |
Check if device connected.
| [in] | instance | of device |
| bool ble_device_is_paired | ( | BleDevice * | instance | ) |
Check if BSB is paired or not.
| [in] | instance | of device |
| bool ble_device_process_read_request | ( | BleDevice * | instance, |
| uint8_t * | addr, | ||
| uint8_t | type, | ||
| uint16_t | handle, | ||
| uint16_t | offset ) |
Process read requests using service registry.
| [in] | instance | of device |
| [in] | addr | address of the remote sent this request |
| [in] | type | read request type from nwp, should be always 0 |
| [in] | handle | handle of characteristic |
| [in] | offset | byte offset of requested data |
| bool ble_device_process_write_request | ( | BleDevice * | instance, |
| const uint8_t * | remote_addr, | ||
| const uint16_t | handle, | ||
| const size_t | data_size, | ||
| const void * | data ) |
Process all write requests using service registry.
| [in] | instance | of device |
| [in] | remote_addr | address of the remote sent this request |
| [in] | handle | handle of characteristic |
| [in] | data_size | size of data nwp wants to write into characteristic |
| [in] | data | data nwp wants to write into characteristic |
| void ble_device_receive_confirm | ( | BleDevice * | instance, |
| uint16_t | handle, | ||
| uint8_t | cccd_value ) |
Send confirmation that write request is done.
| [in] | instance | device instance |
| [in] | handle | handle of characteristic |
| [in] | cccd_value | property flags for characteristic |
| bool ble_device_register_service | ( | BleDevice * | instance, |
| BleServiceObject * | service ) |
Performs service registration in device registry and on nwp side.
This operation performed once per service during initialization
| [in] | instance | of device |
| [in] | service | to be registered |
| void ble_device_request_pairing | ( | BleDevice * | instance | ) |
Attempt to request pairing Used in attempt to avoid some pairing corner cases when BSB has pairing but other side does not.
| [in] | instance | of device |
| void ble_device_response_pairing_capabilities | ( | BleDevice * | instance | ) |
Send respose with pairing capabilities on event from nwp.
| [in] | instance | of device |
| void ble_device_send_data | ( | BleDevice * | instance, |
| uint16_t | handle, | ||
| uint16_t | data_size, | ||
| const uint8_t * | data, | ||
| uint16_t | cccd_value ) |
Send data over ble.
This function also splits huge chunks using max payload size if needed
| [in] | instance | of device |
| [in] | handle | handle of characteristic |
| [in] | data_size | size of data nwp wants to write into characteristic |
| [in] | data | data nwp wants to write into characteristic |
| [in] | cccd_value | property flags for characteristic |
| bool ble_device_send_encryption_response | ( | BleDevice * | instance | ) |
Send pairing keys data as a respose in format required by nwp.
| [in] | instance | of device |
| void ble_device_set_mtu | ( | BleDevice * | instance, |
| uint16_t | mtu ) |
Save mtu value received from nwp and calculate max payload size.
| [in] | instance | of device |
| [in] | mtu | value from nwp |
| void ble_device_set_name | ( | BleDevice * | instance, |
| const char * | name ) |
Set device name.
| [in] | instance | of device |
| [in] | name | for the device |
| bool ble_device_start | ( | BleDevice * | instance | ) |
Starts device advertising.
| [in] | instance | of device |
| bool ble_device_stop | ( | BleDevice * | instance | ) |
Stop device advertising.
If device was connected, it will perform disconnect first
| [in] | instance | of device |