Skip to content

Commit 03a7fa7

Browse files
nimble: bttester: Implement GATT Server BTP Service (ID 0x07)
New BTP service is introduced. Most of the changes are just migration of code from btp_gatt.c and btp_gatt.h. Changes also include refactor of how notifications are sent by server: - os_callout_init and functions/variables realted to it are removed. It was responsible for starting a timer when peer has subscribed for notifications/indications and sending notifications right after the timer has expired. - An updated version of gatts_set_value command can be used to set values of one or more characteristics and takes care of sending notifications, indications and multiple handle value notifications
1 parent 9d0217a commit 03a7fa7

File tree

7 files changed

+1164
-8
lines changed

7 files changed

+1164
-8
lines changed

apps/bttester/src/btp/btp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "btp_gap.h"
3232
#include "btp_gatt.h"
3333
#include "btp_gattc.h"
34+
#include "btp_gatts.h"
3435
#include "btp_l2cap.h"
3536
#include "btp_mesh.h"
3637
#include "btp_pacs.h"
@@ -48,6 +49,7 @@
4849
#define BTP_SERVICE_ID_L2CAP 3
4950
#define BTP_SERVICE_ID_MESH 4
5051
#define BTP_SERVICE_ID_GATTC 6
52+
#define BTP_SERVICE_ID_GATTS 7
5153
#define BTP_SERVICE_ID_PACS 12
5254
#define BTP_SERVICE_ID_BAP 14
5355

apps/bttester/src/btp/btp_gatts.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/* btp_gatts.h - Bluetooth tester GATT Server service headers */
21+
22+
/*
23+
* Copyright (c) 2015-2016 Intel Corporation
24+
* Copyright (C) 2025 Codecoup
25+
*
26+
* SPDX-License-Identifier: Apache-2.0
27+
*/
28+
29+
/* GATT Server Service */
30+
#define BTP_GATT_HL_MAX_CNT 16
31+
struct btp_notify_hlv {
32+
uint16_t handle;
33+
uint16_t len;
34+
};
35+
/* commands */
36+
#define BTP_GATTS_READ_SUPPORTED_COMMANDS 0x01
37+
struct btp_gatts_read_supported_commands_rp {
38+
uint8_t data[0];
39+
} __packed;
40+
41+
#define BTP_GATTS_GET_ATTRIBUTES 0x02
42+
struct btp_gatts_get_attributes_cmd {
43+
uint16_t start_handle;
44+
uint16_t end_handle;
45+
uint8_t type_length;
46+
uint8_t type[0];
47+
} __packed;
48+
struct btp_gatts_get_attributes_rp {
49+
uint8_t attrs_count;
50+
uint8_t attrs[0];
51+
} __packed;
52+
struct btp_gatts_attr {
53+
uint16_t handle;
54+
uint8_t permission;
55+
uint8_t type_length;
56+
uint8_t type[0];
57+
} __packed;
58+
59+
#define BTP_GATTS_GET_ATTRIBUTE_VALUE 0x03
60+
struct btp_gatts_get_attribute_value_cmd {
61+
ble_addr_t address;
62+
uint16_t handle;
63+
} __packed;
64+
struct btp_gatts_get_attribute_value_rp {
65+
uint8_t att_response;
66+
uint16_t value_length;
67+
uint8_t value[0];
68+
} __packed;
69+
70+
#define BTP_GATTS_SET_CHRC_VALUE 0x04
71+
struct btp_gatts_set_chrc_value_cmd {
72+
ble_addr_t address;
73+
uint16_t count;
74+
struct btp_notify_hlv hl[BTP_GATT_HL_MAX_CNT];
75+
uint8_t value[0];
76+
} __packed;
77+
78+
#define BTP_GATTS_CHANGE_DATABASE 0x05
79+
struct btp_gatts_change_database_cmd {
80+
uint16_t start_handle;
81+
uint16_t end_handle;
82+
uint8_t visibility;
83+
} __packed;
84+
85+
#define BTP_GATTS_START_SERVER 0x07
86+
struct btp_gatts_start_server_rp {
87+
uint16_t db_attr_off;
88+
uint8_t db_attr_cnt;
89+
} __packed;
90+
91+
/* GATTS events */
92+
#define BTP_GATTS_EV_ATTR_VALUE_CHANGED 0x81
93+
struct btp_gatts_attr_value_changed_ev {
94+
uint16_t handle;
95+
uint16_t data_length;
96+
uint8_t data[0];
97+
} __packed;

apps/bttester/src/btp/bttester.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ tester_gatt_subscribe_ev(uint16_t conn_handle,
119119
uint8_t prev_indicate,
120120
uint8_t cur_indicate);
121121

122+
int
123+
tester_gatts_subscribe_ev(uint16_t conn_handle,
124+
uint16_t attr_handle,
125+
uint8_t reason,
126+
uint8_t prev_notify,
127+
uint8_t cur_notify,
128+
uint8_t prev_indicate,
129+
uint8_t cur_indicate);
130+
122131
#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
123132
uint8_t
124133
tester_init_l2cap(void);
@@ -136,6 +145,10 @@ uint8_t
136145
tester_init_gatt_cl(void);
137146
uint8_t
138147
tester_unregister_gatt_cl(void);
148+
uint8_t
149+
tester_init_gatts(void);
150+
uint8_t
151+
tester_unregister_gatts(void);
139152
void
140153
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
141154

apps/bttester/src/btp_core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ register_service(const void *cmd, uint16_t cmd_len,
115115
case BTP_SERVICE_ID_GATTC:
116116
status = tester_init_gatt_cl();
117117
break;
118+
case BTP_SERVICE_ID_GATTS:
119+
status = tester_init_gatts();
120+
break;
118121
default:
119122
status = BTP_STATUS_FAILED;
120123
break;
@@ -164,6 +167,9 @@ unregister_service(const void *cmd, uint16_t cmd_len,
164167
case BTP_SERVICE_ID_GATTC:
165168
status = tester_unregister_gatt_cl();
166169
break;
170+
case BTP_SERVICE_ID_GATTS:
171+
status = tester_unregister_gatts();
172+
break;
167173
#if MYNEWT_VAL(BLE_ISO_BROADCAST_SOURCE)
168174
case BTP_SERVICE_ID_BAP:
169175
status = tester_unregister_bap();

apps/bttester/src/btp_gap.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,13 +1475,14 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
14751475
event->subscribe.cur_notify,
14761476
event->subscribe.prev_indicate,
14771477
event->subscribe.cur_indicate);
1478-
tester_gatt_subscribe_ev(event->subscribe.conn_handle,
1479-
event->subscribe.attr_handle,
1480-
event->subscribe.reason,
1481-
event->subscribe.prev_notify,
1482-
event->subscribe.cur_notify,
1483-
event->subscribe.prev_indicate,
1484-
event->subscribe.cur_indicate);
1478+
/* TODO: implement tester_gatts_subscribe_ev */
1479+
tester_gatts_subscribe_ev(event->subscribe.conn_handle,
1480+
event->subscribe.attr_handle,
1481+
event->subscribe.reason,
1482+
event->subscribe.prev_notify,
1483+
event->subscribe.cur_notify,
1484+
event->subscribe.prev_indicate,
1485+
event->subscribe.cur_indicate);
14851486
break;
14861487
case BLE_GAP_EVENT_REPEAT_PAIRING:
14871488
console_printf("repeat pairing event; conn_handle=%d "

apps/bttester/src/btp_gatt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ get_attr_val(const void *cmd, uint16_t cmd_len,
18911891
return status;
18921892
}
18931893

1894-
int
1894+
static int
18951895
notify_multiple(uint16_t conn_handle, void *arg)
18961896
{
18971897
struct notify_mult_cb_data *notify_data =

0 commit comments

Comments
 (0)