Skip to content

Commit cf0fbb7

Browse files
nimble: tester: Implement GATT Server BTP Service (ID 0x07)
Work in progress.
1 parent 63db05e commit cf0fbb7

7 files changed

Lines changed: 1156 additions & 1 deletion

File tree

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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
/* TODO: this should be renamed to SVC_CHANGE? */
42+
#define BTP_GATTS_START_SERVER 0x07
43+
struct btp_gatts_start_server_rp {
44+
uint16_t db_attr_off;
45+
uint8_t db_attr_cnt;
46+
} __packed;
47+
48+
#define BTP_GATTS_GET_ATTRIBUTES 0x02
49+
struct btp_gatts_get_attributes_cmd {
50+
uint16_t start_handle;
51+
uint16_t end_handle;
52+
uint8_t type_length;
53+
uint8_t type[0];
54+
} __packed;
55+
struct btp_gatts_get_attributes_rp {
56+
uint8_t attrs_count;
57+
uint8_t attrs[0];
58+
} __packed;
59+
struct btp_gatts_attr {
60+
uint16_t handle;
61+
uint8_t permission;
62+
uint8_t type_length;
63+
uint8_t type[0];
64+
} __packed;
65+
66+
#define BTP_GATTS_GET_ATTRIBUTE_VALUE 0x03
67+
struct btp_gatts_get_attribute_value_cmd {
68+
ble_addr_t address;
69+
uint16_t handle;
70+
} __packed;
71+
struct btp_gatts_get_attribute_value_rp {
72+
uint8_t att_response;
73+
uint16_t value_length;
74+
uint8_t value[0];
75+
} __packed;
76+
77+
#define BTP_GATTS_SET_VALUE 0x04
78+
struct btp_gatts_set_value_cmd {
79+
uint16_t attr_id;
80+
uint16_t len;
81+
uint8_t value[0];
82+
} __packed;
83+
84+
#define BTP_GATTS_SET_MULT_VALUE 0x22
85+
struct btp_gatts_set_mult_val_cmd {
86+
ble_addr_t address;
87+
uint16_t count;
88+
struct btp_notify_hlv hl[BTP_GATT_HL_MAX_CNT];
89+
uint8_t value[0];
90+
} __packed;
91+
92+
#define BTP_GATTS_CHANGE_DATABASE 0x05
93+
struct btp_gatts_change_database_cmd {
94+
uint16_t start_handle;
95+
uint16_t end_handle;
96+
uint8_t visibility;
97+
} __packed;
98+
99+
/* GATTS events */
100+
#define BTP_GATTS_EV_ATTR_VALUE_CHANGED 0x81
101+
struct btp_gatts_attr_value_changed_ev {
102+
uint16_t handle;
103+
uint16_t data_length;
104+
uint8_t data[0];
105+
} __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)