Skip to content

Commit 16fc061

Browse files
committed
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 a7c1c7c commit 16fc061

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ Binary libraries
477477
Bluetooth libraries and services
478478
--------------------------------
479479

480-
|no_changes_yet_note|
480+
* :ref:`hogp_readme` library:
481+
482+
* 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.
481483

482484
Common Application Framework
483485
----------------------------

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: 13 additions & 4 deletions
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,22 @@ static uint8_t rep_notify_process(struct bt_conn *conn,
10261027
LOG_WRN("Data size too big, truncating");
10271028
length = UINT8_MAX;
10281029
}
1029-
/* Zephyr uses the callback with data set to NULL to inform about the
1030-
* subscription removal. Do not update the report size in that case.
1031-
*/
1030+
10321031
if (data != NULL) {
10331032
rep->size = (uint8_t)length;
10341033
}
10351034

1036-
return rep->notify_cb(rep->hogp, rep, 0, data);
1035+
1036+
err = rep->notify_cb(rep->hogp, rep, 0, data);
1037+
1038+
if (data == NULL) {
1039+
/* Zephyr uses the callback with data set to NULL to inform about the
1040+
* subscription removal. Do not update the report size in that case.
1041+
*/
1042+
rep->notify_cb = NULL;
1043+
}
1044+
1045+
return err;
10371046
}
10381047

10391048
int bt_hogp_rep_subscribe(struct bt_hogp *hogp,

0 commit comments

Comments
 (0)