@@ -44,6 +44,26 @@ extern "C" {
4444/** Length of encoded HID Information. */
4545#define BT_HIDS_INFORMATION_LEN 4
4646
47+ #if defined(CONFIG_BT_HIDS_SCI ) || defined(CONFIG_BT_HOGP_SCI )
48+ /** Maximum number of connection interval groups in HID SCI Information. */
49+ #if defined(CONFIG_BT_HIDS_SCI_INFORMATION_MAX_GROUPS_COUNT_CUSTOM )
50+ #define BT_HIDS_SCI_INFORMATION_MAX_GROUPS CONFIG_BT_HIDS_SCI_INFORMATION_MAX_GROUPS_COUNT
51+ #else
52+ #define BT_HIDS_SCI_INFORMATION_MAX_GROUPS BT_CONN_LE_MAX_CONN_INTERVAL_GROUPS
53+ #endif
54+
55+ /** Max length of encoded HID SCI Information based on the HIDS specification:
56+ * Minimum supported conn interval (1B) + Num groups (1B) +
57+ * Num groups * (Group Min (2B) + Group Max (2B) + Group Stride (2B)).
58+ */
59+ #define BT_HIDS_SCI_INFORMATION_MAX_LEN (1 + 1 + BT_HIDS_SCI_INFORMATION_MAX_GROUPS * (2 + 2 + 2))
60+ #define BT_HIDS_SCI_INFORMATION_MIN_LEN 2
61+
62+ /** The transport interval which the device must support to be compliant
63+ * with the HID specification (chapter 7.4). */
64+ #define BT_HIDS_MAX_MINIMAL_TRANSPORT_INTERVAL_US 1250
65+ #endif
66+
4767/**
4868 * @brief Declare a HIDS instance.
4969 *
@@ -116,6 +136,10 @@ enum bt_hids_flags {
116136 BT_HIDS_REMOTE_WAKE = BIT (0 ),
117137 /** Device advertises when bonded but not connected. */
118138 BT_HIDS_NORMALLY_CONNECTABLE = BIT (1 ),
139+ /** Device is capable of supporting the HID SCI feature */
140+ BT_HIDS_SCI_CAPABLE = BIT (2 ),
141+ /** Device is capable of supporting the HID SCI Low Power mode feature */
142+ BT_HIDS_SCI_LOW_POWER_MODE_CAPABLE = BIT (3 ),
119143};
120144
121145/** @brief HID Control Point settings. */
@@ -124,7 +148,32 @@ enum bt_hids_control_point {
124148 BT_HIDS_CONTROL_POINT_SUSPEND = 0x00 ,
125149
126150 /** Exit suspend value for Control Point.*/
127- BT_HIDS_CONTROL_POINT_EXIT_SUSPEND = 0x01
151+ BT_HIDS_CONTROL_POINT_EXIT_SUSPEND = 0x01 ,
152+ /** Request SCI default mode value for Control Point. */
153+ BT_HIDS_CONTROL_POINT_SCI_DEFAULT_REQ = 0x02 ,
154+
155+ /** Request SCI fast mode value for Control Point. */
156+ BT_HIDS_CONTROL_POINT_SCI_FAST_REQ = 0x03 ,
157+
158+ /** Request SCI low power mode value for Control Point. */
159+ BT_HIDS_CONTROL_POINT_SCI_LOW_POWER_REQ = 0x04 ,
160+
161+ /** Request SCI Full Range mode value for Control Point. */
162+ BT_HIDS_CONTROL_POINT_SCI_FULL_RANGE_REQ = 0x05 ,
163+ };
164+
165+ /** @brief HID SCI Mode values */
166+ enum bt_hids_sci_mode_value {
167+ /** SCI None mode. */
168+ BT_HIDS_SCI_MODE_NONE = 0x00 ,
169+ /** SCI Default mode. */
170+ BT_HIDS_SCI_MODE_DEFAULT = 0x02 ,
171+ /** SCI Fast mode. */
172+ BT_HIDS_SCI_MODE_FAST = 0x03 ,
173+ /** SCI Low Power mode. */
174+ BT_HIDS_SCI_MODE_LOW_POWER = 0x04 ,
175+ /** SCI Full Range mode. */
176+ BT_HIDS_SCI_MODE_FULL_RANGE = 0x05 ,
128177};
129178
130179/** HID Service Protocol Mode events. */
@@ -141,6 +190,14 @@ enum bt_hids_cp_evt {
141190 BT_HIDS_CP_EVT_HOST_SUSP ,
142191 /** Exit suspend command received. */
143192 BT_HIDS_CP_EVT_HOST_EXIT_SUSP ,
193+ /** SCI Default mode request received. */
194+ BT_HIDS_CP_EVT_HOST_SCI_DEFAULT_REQ ,
195+ /** SCI Fast mode request received. */
196+ BT_HIDS_CP_EVT_HOST_SCI_FAST_REQ ,
197+ /** SCI Low Power mode request received. */
198+ BT_HIDS_CP_EVT_HOST_SCI_LOW_POWER_REQ ,
199+ /** SCI Full Range mode request received. */
200+ BT_HIDS_CP_EVT_HOST_SCI_FULL_RANGE_REQ ,
144201};
145202
146203/** HID notification events. */
@@ -393,6 +450,34 @@ struct bt_hids_cp {
393450 bt_hids_cp_evt_handler_t evt_handler ;
394451};
395452
453+ #if defined(CONFIG_BT_HIDS_SCI )
454+ /** @brief Function to be called when the SCI mode is updated. */
455+ typedef void (* bt_hids_sci_mode_update_handler_t ) (struct bt_conn * conn ,
456+ enum bt_hids_sci_mode_value mode );
457+
458+ /** @brief SCI mode.
459+ */
460+ struct bt_hids_sci_mode_data {
461+ /** CCC descriptor. */
462+ struct bt_gatt_ccc_managed_user_data ccc ;
463+
464+ /** Index in the service attribute array. */
465+ uint8_t att_ind ;
466+
467+ /** Callback with new SCI mode. */
468+ bt_hids_sci_mode_update_handler_t update_handler ;
469+ };
470+
471+ /** @brief SCI Information data. */
472+ struct bt_hids_sci_info_data {
473+ /** Pointer to the SCI information. */
474+ uint8_t sci_info [BT_HIDS_SCI_INFORMATION_MAX_LEN ];
475+
476+ /** Size of the SCI information. */
477+ ssize_t sci_info_len ;
478+ };
479+ #endif
480+
396481/** @brief HID initialization.
397482 */
398483struct bt_hids_init_param {
@@ -414,7 +499,9 @@ struct bt_hids_init_param {
414499 /** Callback for Protocol Mode characteristic. */
415500 bt_hids_pm_evt_handler_t pm_evt_handler ;
416501
417- /** Callback for Control Point characteristic. */
502+ /** Callback for Control Point (suspend and exit-suspend only;
503+ * mode requests are handled internally).
504+ */
418505 bt_hids_cp_evt_handler_t cp_evt_handler ;
419506
420507 /** Callback for Boot Mouse Input Report. */
@@ -426,6 +513,11 @@ struct bt_hids_init_param {
426513 /** Callback for Boot Keyboard Output Report. */
427514 bt_hids_rep_handler_t boot_kb_outp_rep_handler ;
428515
516+ #if defined(CONFIG_BT_HIDS_SCI )
517+ /** Callback for SCI mode update. */
518+ bt_hids_sci_mode_update_handler_t sci_mode_update_handler ;
519+ #endif
520+
429521 /** Flag indicating that the device has mouse capabilities. */
430522 bool is_mouse ;
431523
@@ -466,6 +558,13 @@ struct bt_hids {
466558 /** Control Point. */
467559 struct bt_hids_cp cp ;
468560
561+ #if defined(CONFIG_BT_HIDS_SCI )
562+ /** SCI mode data. */
563+ struct bt_hids_sci_mode_data sci_mode_data ;
564+
565+ /** HID SCI Information data. */
566+ struct bt_hids_sci_info_data sci_info_data ;
567+ #endif
469568 /** Buffer with encoded HID Information. */
470569 uint8_t info [BT_HIDS_INFORMATION_LEN ];
471570
@@ -502,6 +601,14 @@ struct bt_hids_conn_data {
502601
503602 /** Pointer to Feature Reports Context data. */
504603 uint8_t * feat_rep_ctx ;
604+
605+ #if defined(CONFIG_BT_HIDS_SCI )
606+ /** Pending SCI mode value. */
607+ uint8_t pending_sci_mode ;
608+
609+ /** SCI mode value. */
610+ uint8_t sci_mode ;
611+ #endif
505612};
506613
507614
0 commit comments