Skip to content

Commit f2071c3

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 63db05e commit f2071c3

File tree

7 files changed

+1148
-1
lines changed

7 files changed

+1148
-1
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ uint8_t
136136
tester_init_gatt_cl(void);
137137
uint8_t
138138
tester_unregister_gatt_cl(void);
139+
uint8_t
140+
tester_init_gatts(void);
141+
uint8_t
142+
tester_unregister_gatts(void);
139143
void
140144
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
141145

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,7 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
14601460
event->subscribe.cur_notify,
14611461
event->subscribe.prev_indicate,
14621462
event->subscribe.cur_indicate);
1463+
/* TODO: implement tester_gatts_subscribe_ev */
14631464
tester_gatt_subscribe_ev(event->subscribe.conn_handle,
14641465
event->subscribe.attr_handle,
14651466
event->subscribe.reason,

apps/bttester/src/btp_gatt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ get_attr_val(const void *cmd, uint16_t cmd_len,
18541854
return status;
18551855
}
18561856

1857-
int
1857+
static int
18581858
notify_multiple(uint16_t conn_handle, void *arg)
18591859
{
18601860
struct notify_mult_cb_data *notify_data =

0 commit comments

Comments
 (0)