Skip to content

Commit bd98f5e

Browse files
bluetooth: services: lbs: update security configuration
Update security configuration for LBS service. Signed-off-by: Eivind Jølsgard <[email protected]>
1 parent c2c2090 commit bd98f5e

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Bluetooth LE Services
142142
* :ref:`lib_ble_service_dis` service.
143143
* :ref:`lib_ble_service_hids` service.
144144
* :ref:`lib_ble_service_hrs` service.
145+
* :ref:`lib_ble_service_lbs` service.
145146

146147
* :ref:`lib_ble_service_nus` service:
147148

include/bm/bluetooth/services/ble_lbs.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <stdint.h>
1616
#include <ble.h>
17+
#include <bm/bluetooth/services/common.h>
1718
#include <bm/softdevice_handler/nrf_sdh_ble.h>
1819

1920
#ifdef __cplusplus
@@ -41,6 +42,19 @@ struct ble_lbs;
4142
extern void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *lbs_instance); \
4243
NRF_SDH_BLE_OBSERVER(_name ## _obs, ble_lbs_on_ble_evt, &_name, BLE_LBS_BLE_OBSERVER_PRIO)
4344

45+
/** @brief Default security configuration. */
46+
#define BLE_LBS_CONFIG_SEC_MODE_DEFAULT \
47+
{ \
48+
.lbs_button_char = { \
49+
.read = BLE_GAP_CONN_SEC_MODE_OPEN, \
50+
.cccd_write = BLE_GAP_CONN_SEC_MODE_OPEN, \
51+
}, \
52+
.lbs_led_char = { \
53+
.read = BLE_GAP_CONN_SEC_MODE_OPEN, \
54+
.write = BLE_GAP_CONN_SEC_MODE_OPEN, \
55+
}, \
56+
}
57+
4458
enum ble_lbs_evt_type {
4559
BLE_LBS_EVT_LED_WRITE,
4660
};
@@ -68,6 +82,22 @@ typedef void (*lbs_evt_handler_t)(struct ble_lbs *lbs, const struct ble_lbs_evt
6882
struct ble_lbs_config {
6983
/** @brief Event handler to be called when the LED Characteristic is written. */
7084
lbs_evt_handler_t evt_handler;
85+
/** Security configuration. */
86+
struct {
87+
/** LBS Button characteristic */
88+
struct {
89+
/** Security requirement for reading LBS button characteristic value. */
90+
ble_gap_conn_sec_mode_t read;
91+
/** Security requirement for writing LBS button characteristic CCCD. */
92+
ble_gap_conn_sec_mode_t cccd_write;
93+
} lbs_button_char;
94+
struct {
95+
/** Security requirement for reading LBS LED characteristic value. */
96+
ble_gap_conn_sec_mode_t read;
97+
/** Security requirement for wtiring LBS LED characteristic value. */
98+
ble_gap_conn_sec_mode_t write;
99+
} lbs_led_char;
100+
} sec_mode;
71101
};
72102

73103
/**

samples/bluetooth/ble_lbs/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ int main(void)
139139
};
140140
struct ble_lbs_config lbs_cfg = {
141141
.evt_handler = lbs_evt_handler,
142+
.sec_mode = BLE_LBS_CONFIG_SEC_MODE_DEFAULT,
142143
};
143144
struct ble_dis_config dis_config = {
144145
.sec_mode = BLE_DIS_CONFIG_SEC_MODE_DEFAULT,

subsys/bluetooth/services/ble_lbs/lbs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
9292
};
9393
ble_gatts_attr_md_t cccd_md = {
9494
.vloc = BLE_GATTS_VLOC_STACK,
95+
.read_perm = BLE_GAP_CONN_SEC_MODE_OPEN,
96+
.write_perm = cfg->sec_mode.lbs_button_char.cccd_write,
9597
};
9698
ble_gatts_char_md_t char_md = {
9799
.char_props = {
@@ -102,6 +104,7 @@ uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
102104
};
103105
ble_gatts_attr_md_t attr_md = {
104106
.vloc = BLE_GATTS_VLOC_STACK,
107+
.read_perm = cfg->sec_mode.lbs_button_char.read,
105108
};
106109
ble_gatts_attr_t attr_char_value = {
107110
.p_uuid = &char_uuid,
@@ -110,9 +113,6 @@ uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
110113
.init_len = sizeof(uint8_t),
111114
.max_len = sizeof(uint8_t),
112115
};
113-
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
114-
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
115-
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
116116

117117
nrf_err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value,
118118
&lbs->button_char_handles);
@@ -135,6 +135,8 @@ uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
135135
};
136136
attr_md = (ble_gatts_attr_md_t){
137137
.vloc = BLE_GATTS_VLOC_STACK,
138+
.read_perm = cfg->sec_mode.lbs_led_char.read,
139+
.write_perm = cfg->sec_mode.lbs_led_char.write,
138140
};
139141
attr_char_value = (ble_gatts_attr_t){
140142
.p_uuid = &char_uuid,
@@ -143,8 +145,6 @@ uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
143145
.init_len = sizeof(uint8_t),
144146
.max_len = sizeof(uint8_t),
145147
};
146-
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
147-
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
148148

149149
nrf_err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value,
150150
&lbs->led_char_handles);

0 commit comments

Comments
 (0)