Skip to content

Commit b21d678

Browse files
ahasztagnordicjm
authored andcommitted
bluetooth: hogp: Fix bt_hogp_rep_unsubscribe issue
The bt_hogp_rep_unsubscribe did not reset the rep->notify_cb, while bt_hogp_rep_subscribe returned an error if notify_cb was not null. Thus, it would be impossible to subscribe again to the report notification after unsubscribing. This commit fixes this. Signed-off-by: Artur Hadasz <artur.hadasz@nordicsemi.no>
1 parent fc70eff commit b21d678

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ Bluetooth libraries and services
534534

535535
* Fixed missing ATT write length validation in the GATT write handler for the Fast Pair Additional Data characteristic, used by the experimental Personalized Name extension (:kconfig:option:`CONFIG_BT_FAST_PAIR_PN`).
536536

537+
* :ref:`hogp_readme` library:
538+
539+
* Fixed an issue where the :c:func:`bt_hogp_rep_unsubscribe` function did not clear the notification callback, which prevented the :c:func:`bt_hogp_rep_subscribe` function from succeeding after unsubscribing.
540+
537541
Common Application Framework
538542
----------------------------
539543

include/bluetooth/services/hogp.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct bt_hogp_rep_info;
3838
* @param hogp HOGP object.
3939
* @param rep Report object.
4040
* @param err ATT error code.
41-
* @param data Pointer to the received data.
41+
* @param data Pointer to the received data or NULL to indicate
42+
* that the subscription has been cleared.
4243
*
4344
* @retval BT_GATT_ITER_STOP Stop notification.
4445
* @retval BT_GATT_ITER_CONTINUE Continue notification.
@@ -407,6 +408,11 @@ int bt_hogp_rep_subscribe(struct bt_hogp *hogp,
407408
/**
408409
* @brief Remove the subscription for a selected report.
409410
*
411+
* When the subscription has been cleared the callback function
412+
* will be called with data set to NULL.
413+
* This will happen both on successful unsubscription as well as
414+
* on CCC write error.
415+
*
410416
* @param hogp HOGP object.
411417
* @param rep Report object.
412418
*

subsys/bluetooth/services/hogp.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ static uint8_t rep_notify_process(struct bt_conn *conn,
10141014
const void *data, uint16_t length)
10151015
{
10161016
struct bt_hogp_rep_info *rep;
1017+
uint8_t err = 0;
10171018

10181019
rep = CONTAINER_OF(params,
10191020
struct bt_hogp_rep_info,
@@ -1026,14 +1027,26 @@ static uint8_t rep_notify_process(struct bt_conn *conn,
10261027
LOG_WRN("Data size too big, truncating");
10271028
length = UINT8_MAX;
10281029
}
1030+
10291031
/* Zephyr uses the callback with data set to NULL to inform about the
10301032
* subscription removal. Do not update the report size in that case.
10311033
*/
10321034
if (data != NULL) {
10331035
rep->size = (uint8_t)length;
10341036
}
10351037

1036-
return rep->notify_cb(rep->hogp, rep, 0, data);
1038+
1039+
err = rep->notify_cb(rep->hogp, rep, 0, data);
1040+
1041+
if (data == NULL) {
1042+
/* Zephyr uses the callback with data set to NULL to inform about the
1043+
* subscription removal.
1044+
* The notification callback can be safely cleared.
1045+
*/
1046+
rep->notify_cb = NULL;
1047+
}
1048+
1049+
return err;
10371050
}
10381051

10391052
int bt_hogp_rep_subscribe(struct bt_hogp *hogp,

0 commit comments

Comments
 (0)