21#include <bm/bluetooth/ble_common.h>
22#include <bm/softdevice_handler/nrf_sdh_ble.h>
35#define BLE_HIDS_DEF(_name) \
36 static struct ble_hids _name = { \
37 .link_ctx_storage = { \
38 .max_links_cnt = CONFIG_BLE_HIDS_MAX_CLIENTS, \
39 .link_ctx_size = sizeof(uint32_t) * BYTES_TO_WORDS(BLE_HIDS_LINK_CTX_SIZE),\
42 NRF_SDH_BLE_OBSERVER(_name##_obs, ble_hids_on_ble_evt, &_name, HIGH)
45#define BLE_HIDS_CONFIG_SEC_MODE_DEFAULT_MOUSE \
47 .hid_info_char.read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
48 .report_map_char.read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
49 .protocol_mode_char = { \
50 .read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
51 .write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
53 .ctrl_point_char = { \
54 .write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
56 .boot_mouse_inp_rep_char = { \
57 .read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
58 .write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
59 .cccd_write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
64#define BLE_HIDS_CONFIG_SEC_MODE_DEFAULT_KEYBOARD \
66 .hid_info_char.read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
67 .report_map_char.read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
68 .protocol_mode_char = { \
69 .read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
70 .write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
72 .ctrl_point_char = { \
73 .write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
75 .boot_kb_inp_rep_char = { \
76 .read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
77 .write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
78 .cccd_write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
80 .boot_kb_outp_rep_char = { \
81 .read = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
82 .write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
83 .cccd_write = BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM, \
90#define BLE_HIDS_BOOT_KB_INPUT_REPORT_MAX_SIZE 8
94#define BLE_HIDS_BOOT_KB_OUTPUT_REPORT_MAX_SIZE 1
98#define BLE_HIDS_BOOT_MOUSE_INPUT_REPORT_MAX_SIZE 8
193#define BLE_HIDS_LINK_CTX_SIZE \
194 (sizeof(struct ble_hids_client_context) + CONFIG_BLE_HIDS_INPUT_REPORT_MAX_LEN + \
195 CONFIG_BLE_HIDS_OUTPUT_REPORT_MAX_LEN + CONFIG_BLE_HIDS_FEATURE_REPORT_MAX_LEN + \
196 (BLE_HIDS_BOOT_KB_INPUT_REPORT_MAX_SIZE) + (BLE_HIDS_BOOT_KB_OUTPUT_REPORT_MAX_SIZE) + \
197 (BLE_HIDS_BOOT_MOUSE_INPUT_REPORT_MAX_SIZE))
200#define CTX_DATA_POOL_SIZE ((CONFIG_BLE_HIDS_MAX_CLIENTS) * BYTES_TO_WORDS(BLE_HIDS_LINK_CTX_SIZE))
524 ble_gap_conn_sec_mode_t
read;
539 ble_gap_conn_sec_mode_t
write;
548 ble_gap_conn_sec_mode_t
read;
558 ble_gap_conn_sec_mode_t
read;
563 ble_gap_conn_sec_mode_t
write;
578 ble_gap_conn_sec_mode_t
read;
583 ble_gap_conn_sec_mode_t
write;
598 ble_gap_conn_sec_mode_t
read;
603 ble_gap_conn_sec_mode_t
write;
801 uint8_t offset, uint16_t conn_handle, uint8_t *outp_rep);
uint32_t ble_hids_inp_rep_send(struct ble_hids *hids, uint16_t conn_handle, struct ble_hids_input_report *report)
Function for sending Input Report.
ble_hids_report_type
HID report types as defined in the Report Reference Characteristic descriptor.
Definition ble_hids.h:103
@ BLE_HIDS_REPORT_TYPE_FEATURE
Feature report.
Definition ble_hids.h:119
@ BLE_HIDS_REPORT_TYPE_RESERVED
Reserved.
Definition ble_hids.h:107
@ BLE_HIDS_REPORT_TYPE_OUTPUT
Output report.
Definition ble_hids.h:115
@ BLE_HIDS_REPORT_TYPE_INPUT
Input report.
Definition ble_hids.h:111
uint32_t ble_hids_boot_mouse_inp_rep_send(struct ble_hids *hids, uint16_t conn_handle, struct ble_hids_boot_mouse_input_report *report)
Function for sending Boot Mouse Input Report.
void ble_hids_on_ble_evt(const ble_evt_t *ble_evt, void *ble_hids)
Bluetooth LE event handler for the HID Service.
ble_hids_evt_type
HID Service event type.
Definition ble_hids.h:243
@ BLE_HIDS_EVT_REP_CHAR_WRITE
A new value has been written to an Report characteristic.
Definition ble_hids.h:263
@ BLE_HIDS_EVT_HOST_SUSP
Suspend command received.
Definition ble_hids.h:247
@ BLE_HIDS_EVT_REPORT_MODE_ENTERED
Report mode entered.
Definition ble_hids.h:271
@ BLE_HIDS_EVT_BOOT_MODE_ENTERED
Boot mode entered.
Definition ble_hids.h:267
@ BLE_HIDS_EVT_NOTIF_ENABLED
Notification enabled event.
Definition ble_hids.h:255
@ BLE_HIDS_EVT_HOST_EXIT_SUSP
Exit suspend command received.
Definition ble_hids.h:251
@ BLE_HIDS_EVT_NOTIF_DISABLED
Notification disabled event.
Definition ble_hids.h:259
@ BLE_HIDS_EVT_ERROR
Error.
Definition ble_hids.h:279
@ BLE_HIDS_EVT_REPORT_READ
Read with response.
Definition ble_hids.h:275
uint32_t ble_hids_outp_rep_get(struct ble_hids *hids, uint8_t report_index, uint16_t len, uint8_t offset, uint16_t conn_handle, uint8_t *outp_rep)
Function for getting the current value of Output Report from the stack.
void(* ble_hids_evt_handler_t)(struct ble_hids *hids, const struct ble_hids_evt *evt)
HID service event handler type.
Definition ble_hids.h:358
#define CTX_DATA_POOL_SIZE
Size of links context memory pool.
Definition ble_hids.h:200
uint32_t ble_hids_boot_kb_inp_rep_send(struct ble_hids *hids, uint16_t conn_handle, struct ble_hids_boot_keyboard_input_report *report)
Function for sending Boot Keyboard Input Report.
uint32_t ble_hids_init(struct ble_hids *hids, const struct ble_hids_config *hids_cfg)
Function for initializing the HID Service.
uint8_t report_index
Index of the characteristic.
Definition ble_hids.h:237
uint8_t report_type
Type of report.
Definition ble_hids.h:231
uint16_t uuid
Characteristic UUID.
Definition ble_hids.h:225
HID Service characteristic id.
Definition ble_hids.h:221
uint8_t ctrl_pt
HID Control Point.
Definition ble_hids.h:190
uint8_t protocol_mode
Protocol mode.
Definition ble_hids.h:186
HID Host context structure. It keeps information relevant to a single host.
Definition ble_hids.h:182
struct ble_hids_rep_map_config report_map
Information nedeed for initialization of the Report Map characteristic.
Definition ble_hids.h:463
uint8_t output_report_count
Number of Output Report characteristics.
Definition ble_hids.h:447
uint8_t remote_wake
Device can be waked remotely.
Definition ble_hids.h:487
struct ble_hids_config::@82 hid_information
Value of the HID Information characteristic.
const struct ble_hids_report_config * input_report
Information about the Input Report characteristics.
Definition ble_hids.h:443
const struct ble_hids_report_config * output_report
Information about the Output Report characteristics.
Definition ble_hids.h:451
struct ble_hids_config::@83::@89 boot_mouse_inp_rep_char
Security requirements for HID Boot Keyboard Input Report characteristic.
uint16_t * included_services_array
Array of services to include in HID service.
Definition ble_hids.h:501
uint16_t bcd_hid
16-bit unsigned integer representing version number of base USB HID Specification implemented by HID ...
Definition ble_hids.h:472
struct ble_hids_config::@83::@90 boot_kb_inp_rep_char
Security requirements for HID Boot Keyboard Input Report characteristic.
ble_gap_conn_sec_mode_t write
Security requirement for writing HID Service Protocol Mode characteristic value.
Definition ble_hids.h:529
const struct ble_hids_report_config * feature_report
Information about the Feature Report characteristics.
Definition ble_hids.h:459
uint8_t input_report_count
Number of Input Report characteristics.
Definition ble_hids.h:439
struct ble_hids_config::@83::@91 boot_kb_outp_rep_char
Security requirements for HID Boot Keyboard Output Report characteristic.
uint8_t reserved
Reserved.
Definition ble_hids.h:491
struct ble_hids_config::@83::@88 report_map_char
Security requirement for HID service Report Map characteristic.
struct ble_hids_config::@83 sec_mode
Security configuration.
struct ble_hids_config::@83::@87 ctrl_point_char
Security requirement for HID service Control Point characteristic.
ble_gap_conn_sec_mode_t read
Security requirement for reading HID Information characteristic value.
Definition ble_hids.h:514
uint8_t normally_connectable
Device is normally connectable.
Definition ble_hids.h:483
struct ble_hids_config::@83::@85 hid_info_char
Security requirement for HID information characteristic.
uint8_t feature_report_count
Number of Feature Report characteristics.
Definition ble_hids.h:455
ble_gap_conn_sec_mode_t cccd_write
Security requirement for writing HID Boot Mouse Input Report characteristic CCCD.
Definition ble_hids.h:568
struct ble_hids_config::@83::@86 protocol_mode_char
Security requirement for HID service Protocol Mode characteristic.
uint8_t b_country_code
Identifies which country the hardware is localized for. Most hardware is not localized and thus this ...
Definition ble_hids.h:477
ble_hids_evt_handler_t evt_handler
HID service event handler.
Definition ble_hids.h:435
uint8_t included_services_count
Number of services to include in HID service.
Definition ble_hids.h:497
HID service configuration.
Definition ble_hids.h:431
struct ble_hids_evt::@75::@77 notification
Parameters for.
struct ble_hids_evt::@75::@80 error
Parameters for BLE_HIDS_EVT_ERROR.
const uint8_t * data
Incoming data.
Definition ble_hids.h:332
struct ble_hids_evt::@75::@79 char_auth_read
Parameters for BLE_HIDS_EVT_REPORT_READ.
uint16_t offset
Offset of the write operation.
Definition ble_hids.h:324
uint32_t reason
Error reason.
Definition ble_hids.h:350
struct ble_hids_char_id char_id
Characteristic ID.
Definition ble_hids.h:311
uint16_t len
Length of the write operation.
Definition ble_hids.h:328
enum ble_hids_evt_type evt_type
Event type.
Definition ble_hids.h:289
struct ble_hids_evt::@75::@78 char_write
Parameters for BLE_HIDS_EVT_REP_CHAR_WRITE.
const ble_evt_t * ble_evt
Bluetooth LE event.
Definition ble_hids.h:297
uint16_t conn_handle
Connection handle for which the event applies.
Definition ble_hids.h:293
HID Service event.
Definition ble_hids.h:285
const uint16_t link_ctx_size
Context size in bytes for a single link (word-aligned).
Definition ble_hids.h:214
uint32_t ctx_data_pool[((CONFIG_BLE_HIDS_MAX_CLIENTS) *BYTES_TO_WORDS((sizeof(struct ble_hids_client_context)+CONFIG_BLE_HIDS_INPUT_REPORT_MAX_LEN+CONFIG_BLE_HIDS_OUTPUT_REPORT_MAX_LEN+CONFIG_BLE_HIDS_FEATURE_REPORT_MAX_LEN+(8)+(1)+(8))))]
Links context memory pool.
Definition ble_hids.h:206
const uint8_t max_links_cnt
Maximum number of concurrent links.
Definition ble_hids.h:210
Definition ble_hids.h:202
uint16_t ref_handle
Handle of the Report Reference descriptor.
Definition ble_hids.h:425
ble_gatts_char_handles_t char_handles
Handles related to the Report characteristic.
Definition ble_hids.h:421
HID Report characteristic structure.
Definition ble_hids.h:417
uint8_t * data
Report map data.
Definition ble_hids.h:401
uint8_t ext_rep_ref_num
Number of Optional External Report Reference descriptors.
Definition ble_hids.h:409
const ble_uuid_t * ext_rep_ref
Optional External Report Reference descriptor (will be added if != NULL).
Definition ble_hids.h:413
uint16_t len
Length of report map data.
Definition ble_hids.h:405
HID Service Report Map characteristic init structure. This contains all options and data needed for i...
Definition ble_hids.h:397
uint16_t len
Maximum length of characteristic value.
Definition ble_hids.h:365
uint8_t report_id
Non-zero value if there is more than one instance of the same Report Type.
Definition ble_hids.h:369
struct ble_hids_report_config::@81 sec_mode
Security requirements for HID Service Input Report characteristic.
ble_gap_conn_sec_mode_t write
Security requirement for writing HID Service characteristic value.
Definition ble_hids.h:385
ble_gap_conn_sec_mode_t read
Security requirement for reading HID Service characteristic value.
Definition ble_hids.h:381
ble_gap_conn_sec_mode_t cccd_write
Security requirement for writing HID Service characteristic CCCD.
Definition ble_hids.h:389
uint8_t report_type
Type of Report characteristic (see BLE_HIDS_REPORT_TYPE)
Definition ble_hids.h:373
HID Report configuration.
Definition ble_hids.h:361
ble_gatts_char_handles_t rep_map_handles
Handles related to the Report Map characteristic.
Definition ble_hids.h:656
ble_gatts_char_handles_t boot_kb_outp_rep_handles
Handles related to the Boot Keyboard Output Report characteristic (will only be created if struct ble...
Definition ble_hids.h:670
uint8_t feature_report_count
Number of Feature Report characteristics.
Definition ble_hids.h:648
struct ble_hids_link_ctx_storage link_ctx_storage
Link context storage with handles of all current connections and its data context.
Definition ble_hids.h:687
struct ble_hids_rep_char outp_rep_array[CONFIG_BLE_HIDS_OUTPUT_REPORT_MAX_NUM]
Information about the Output Report characteristics.
Definition ble_hids.h:644
uint16_t service_handle
Handle of HID Service (as provided by the Bluetooth LE stack).
Definition ble_hids.h:622
uint16_t rep_map_ext_rep_ref_handle
Handle of the Report Map External Report Reference descriptor.
Definition ble_hids.h:660
struct ble_hids_rep_char inp_rep_array[CONFIG_BLE_HIDS_INPUT_REPORT_MAX_NUM]
Information about the Input Report characteristics.
Definition ble_hids.h:636
ble_gatts_char_handles_t boot_kb_inp_rep_handles
Handles related to the Boot Keyboard Input Report characteristic (will only be created if struct ble_...
Definition ble_hids.h:665
const struct ble_hids_report_config * feature_rep_init_array
Information about the Feature Report characteristics.
Definition ble_hids.h:699
struct ble_hids_rep_char feature_rep_array[CONFIG_BLE_HIDS_FEATURE_REPORT_MAX_NUM]
Information about the Feature Report characteristics.
Definition ble_hids.h:652
uint8_t input_report_count
Number of Input Report characteristics.
Definition ble_hids.h:632
ble_gatts_char_handles_t hid_information_handles
Handles related to the Report Map characteristic.
Definition ble_hids.h:679
ble_gatts_char_handles_t hid_control_point_handles
Handles related to the Report Map characteristic.
Definition ble_hids.h:683
uint8_t output_report_count
Number of Output Report characteristics.
Definition ble_hids.h:640
ble_hids_evt_handler_t evt_handler
Event handler to be called for handling events in the HID Service.
Definition ble_hids.h:618
ble_gatts_char_handles_t boot_mouse_inp_rep_handles
Handles related to the Boot Mouse Input Report characteristic (will only be created if struct ble_hid...
Definition ble_hids.h:675
const struct ble_hids_report_config * outp_rep_init_array
Information about the Output Report characteristics.
Definition ble_hids.h:695
ble_gatts_char_handles_t protocol_mode_handles
Handles related to the Protocol Mode characteristic (will only be created if CONFIG_BLE_HIDS_BOOT_KEY...
Definition ble_hids.h:628
const struct ble_hids_report_config * inp_rep_init_array
Information about the Input Report characteristics.
Definition ble_hids.h:691
HID Service structure. This contains various status information for the service.
Definition ble_hids.h:614