From 6bee1f95fcbd2c107ea94467ee676a82f774cc24 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 20 Jun 2019 15:47:09 +0200 Subject: [PATCH] le_counter: setup GATT over BR/EDR --- example/Makefile.inc | 8 ++++++-- example/le_counter.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/example/Makefile.inc b/example/Makefile.inc index cff504d4c..614b6c448 100644 --- a/example/Makefile.inc +++ b/example/Makefile.inc @@ -64,6 +64,7 @@ COMMON += \ CLASSIC += \ btstack_link_key_db_memory.c \ sdp_util.c \ + gatt_sdp.c \ spp_server.c \ rfcomm.c \ bnep.c \ @@ -237,7 +238,7 @@ sdp_bnep_query: ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} ${SDP_CLIENT} sdp_bnep_ spp_counter: ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} spp_counter.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ -le_counter: le_counter.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} battery_service_server.o le_counter.c +le_counter: le_counter.h ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} battery_service_server.o le_counter.c ${CC} $(filter-out le_counter.h,$^) ${CFLAGS} ${LDFLAGS} -o $@ att_delayed_response: att_delayed_response.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} att_delayed_response.c @@ -255,7 +256,10 @@ sm_pairing_peripheral: sm_pairing_peripheral.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_O sm_pairing_central: sm_pairing_central.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} sm_pairing_central.o ${CC} $(filter-out sm_pairing_central.h,$^) ${CFLAGS} ${LDFLAGS} -o $@ -le_streamer: le_streamer.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} le_streamer.c +le_counter: le_counter.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${CLASSIC_OBJ} battery_service_server.o le_counter.c + ${CC} $(filter-out le_counter.h,$^) ${CFLAGS} ${LDFLAGS} -o $@ + +le_streamer: le_streamer.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${CLASSIC_OBJ} le_streamer.c ${CC} $(filter-out le_streamer.h,$^) ${CFLAGS} ${LDFLAGS} -o $@ le_streamer_client: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_CLIENT_OBJ} le_streamer_client.c diff --git a/example/le_counter.c b/example/le_counter.c index 63fc804a2..9f26dc282 100644 --- a/example/le_counter.c +++ b/example/le_counter.c @@ -77,6 +77,10 @@ static btstack_packet_callback_registration_t hci_event_callback_registration; static hci_con_handle_t con_handle; static uint8_t battery = 100; +#ifdef ENABLE_GATT_OVER_CLASSIC +static uint8_t gatt_service_buffer[70]; +#endif + static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size); static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size); @@ -103,6 +107,20 @@ static void le_counter_setup(void){ // setup SM: Display only sm_init(); +#ifdef ENABLE_GATT_OVER_CLASSIC + // init SDP, create record for GATT and register with SDP + sdp_init(); + memset(gatt_service_buffer, 0, sizeof(gatt_service_buffer)); + gatt_create_sdp_record(gatt_service_buffer, 0x10001, ATT_SERVICE_GATT_SERVICE_START_HANDLE, ATT_SERVICE_GATT_SERVICE_END_HANDLE); + sdp_register_service(gatt_service_buffer); + printf("SDP service record size: %u\n", de_get_len(gatt_service_buffer)); + + // configure Classic GAP + gap_set_local_name("GATT Counter BR/EDR 00:00:00:00:00:00"); + gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO); + gap_discoverable_control(1); +#endif + // setup ATT server att_server_init(profile_data, att_read_callback, att_write_callback);