Skip to content

Commit 6d81c97

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 6d81c97

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,10 @@ 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.
483+
Also, the notification callback is no longer called with NULL data when the subscription is removed.
481484

482485
Common Application Framework
483486
----------------------------

include/bluetooth/services/hogp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ int bt_hogp_rep_subscribe(struct bt_hogp *hogp,
407407
/**
408408
* @brief Remove the subscription for a selected report.
409409
*
410+
* When the subscription removal is completed, the callback function
411+
* will be called with data set to NULL.
412+
*
410413
* @param hogp HOGP object.
411414
* @param rep Report object.
412415
*

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)