nordic spp server service: update Makefile, update service name, use correct handle for notify

This commit is contained in:
Milanka Ringwald 2018-10-31 09:57:09 +01:00
parent 10e0e23cd2
commit ba7944be54
9 changed files with 45 additions and 25 deletions

View File

@ -338,6 +338,9 @@ clean:
rm -f ancs_client_demo.h profile.h spp_and_le_counter.h le_counter.h le_streamer.h hog_keyboard_demo.h hog_mouse_demo.h
rm -f gatt_battery_query.h gatt_browser.h sm_pairing_peripheral.h spp_and_le_streamer.h
rm -f le_data_channel_server.h sm_pairing_central.h
rm -f nordic_spp_le_counter.h nordic_spp_le_streamer.h nordic_spp_le_counter nordic_spp_le_streamer
rm -f le_streamer_and_counter_client.h le_streamer_and_counter_client
rm -f sco_output.msbc sco_input.msbc
rm -rf *.dSYM
rm -rf ${BTSTACK_ROOT}/src/*.o
rm -rf ${BTSTACK_ROOT}/src/ble/*.o

View File

@ -48,7 +48,7 @@
#include <stdlib.h>
#include <string.h>
#include "nordic_le_counter.h"
#include "nordic_spp_le_counter.h"
#include "btstack.h"
#include "ble/gatt-service/nordic_spp_service_server.h"
@ -76,7 +76,7 @@ const uint8_t adv_data[] = {
// Flags general discoverable, BR/EDR not supported
2, BLUETOOTH_DATA_TYPE_FLAGS, 0x06,
// Name
6, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'A', 'M', 'B', 'E', 'R',
8, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'n', 'R', 'F',' ', 'S', 'P', 'P',
// UUID ...
17, BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS, 0x6e, 0x40, 0x0, 0x1, 0xc3, 0x52, 0x11, 0xe5, 0x95, 0x3d, 0x0, 0x2, 0xa5, 0xd5, 0xc5, 0x1b,
};

View File

@ -1,4 +1,4 @@
PRIMARY_SERVICE, GAP_SERVICE
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "Nordic"
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "Nordic SPP Counter"
#import <nordic_spp_service.gatt>

View File

@ -73,7 +73,7 @@ const uint8_t adv_data[] = {
// Flags general discoverable, BR/EDR not supported
2, BLUETOOTH_DATA_TYPE_FLAGS, 0x06,
// Name
6, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'A', 'M', 'B', 'E', 'R',
8, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'n', 'R', 'F',' ', 'S', 'P', 'P',
// UUID ...
17, BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS, 0x6e, 0x40, 0x0, 0x1, 0xc3, 0x52, 0x11, 0xe5, 0x95, 0x3d, 0x0, 0x2, 0xa5, 0xd5, 0xc5, 0x1b,
};
@ -280,9 +280,7 @@ static void nordic_data_received(hci_con_handle_t tx_con_handle, const uint8_t *
}
int btstack_main(void);
int btstack_main(void)
{
int btstack_main(void){
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);

View File

@ -1,4 +1,4 @@
PRIMARY_SERVICE, GAP_SERVICE
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "Nordic"
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "Nordic SPP Streamer"
#import <nordic_spp_service.gatt>

View File

@ -77,3 +77,7 @@ spp_counter
spp_streamer
spp_streamer_client
build*
nordic_spp_le_counter
nordic_spp_le_counter.h
nordic_spp_le_streamer
nordic_spp_le_streamer.h

View File

@ -6,4 +6,6 @@ SRC_BLE_GATT-SERVICE_FILES = \
heart_rate_service_server.c \
hids_device.c \
nordic_spp_service_server.c \
ublox_spp_service_server.c \

View File

@ -2,6 +2,6 @@
// Nordic SPP-like
PRIMARY_SERVICE, 6E400001-B5A3-F393-E0A9-E50E24DCCA9E
CHARACTERISTIC, 6E400002-B5A3-F393-E0A9-E50E24DCCA9E, DYNAMIC | NOTIFY,
CHARACTERISTIC, 6E400003-B5A3-F393-E0A9-E50E24DCCA9E, DYNAMIC | WRITE | WRITE_WITHOUT_RESPONSE,
CHARACTERISTIC, 6E400002-B5A3-F393-E0A9-E50E24DCCA9E, DYNAMIC | WRITE | WRITE_WITHOUT_RESPONSE,
CHARACTERISTIC, 6E400003-B5A3-F393-E0A9-E50E24DCCA9E, DYNAMIC | NOTIFY,

View File

@ -44,11 +44,17 @@
* and call all functions below. All strings and blobs need to stay valid after calling the functions.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "btstack_defines.h"
#include "ble/att_db.h"
#include "ble/att_server.h"
#include "btstack_util.h"
#include "bluetooth_gatt.h"
#include "btstack_debug.h"
#include "ble/gatt-service/nordic_spp_service_server.h"
@ -60,18 +66,19 @@ static const uint8_t nordic_spp_tx_uuid128[] = { 0x6E, 0x40, 0x00, 0x03, 0xB5
static att_service_handler_t nordic_spp_service;
static void (*client_callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size);
static uint16_t nordic_spp_tx_value_handle;
static uint16_t nordic_spp_rx_value_handle;
static uint16_t nordic_spp_rx_client_configuration_handle;
static uint16_t nordic_spp_rx_client_configuration_value;
static uint16_t nordic_spp_tx_value_handle;
static uint16_t nordic_spp_tx_client_configuration_handle;
static uint16_t nordic_spp_tx_client_configuration_value;
static uint16_t nordic_spp_service_read_callback(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
UNUSED(con_handle);
UNUSED(offset);
UNUSED(buffer_size);
if (attribute_handle == nordic_spp_rx_client_configuration_handle){
if (attribute_handle == nordic_spp_tx_client_configuration_handle){
if (buffer){
little_endian_store_16(buffer, 0, nordic_spp_rx_client_configuration_value);
little_endian_store_16(buffer, 0, nordic_spp_tx_client_configuration_value);
}
return 2;
}
@ -83,15 +90,17 @@ static int nordic_spp_service_write_callback(hci_con_handle_t con_handle, uint16
UNUSED(offset);
UNUSED(buffer_size);
if (attribute_handle == nordic_spp_tx_value_handle){
if (attribute_handle == nordic_spp_rx_value_handle){
printf_hexdump(buffer, buffer_size);
client_callback(con_handle, &buffer[0], buffer_size);
}
if (attribute_handle == nordic_spp_rx_client_configuration_handle){
nordic_spp_rx_client_configuration_value = little_endian_read_16(buffer, 0);
if (nordic_spp_rx_client_configuration_value){
if (attribute_handle == nordic_spp_tx_client_configuration_handle){
nordic_spp_tx_client_configuration_value = little_endian_read_16(buffer, 0);
if (nordic_spp_tx_client_configuration_value){
client_callback(con_handle, NULL, 0);
}
}
return 0;
}
@ -104,14 +113,18 @@ void nordic_spp_service_server_init(void (*callback)(hci_con_handle_t con_handle
// get service handle range
uint16_t start_handle = 0;
uint16_t end_handle = 0xfff;
uint16_t end_handle = 0xffff;
int service_found = gatt_server_get_get_handle_range_for_service_with_uuid128(nordic_spp_profile_uuid128, &start_handle, &end_handle);
if (!service_found) return;
// get characteristic value handle and client configuration handle
nordic_spp_tx_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid128(start_handle, end_handle, nordic_spp_tx_uuid128);
nordic_spp_rx_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid128(start_handle, end_handle, nordic_spp_rx_uuid128);
nordic_spp_rx_client_configuration_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid128(start_handle, end_handle, nordic_spp_rx_uuid128);
nordic_spp_tx_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid128(start_handle, end_handle, nordic_spp_tx_uuid128);
nordic_spp_tx_client_configuration_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid128(start_handle, end_handle, nordic_spp_tx_uuid128);
log_info("nordic_spp_rx_value_handle 0x%02x", nordic_spp_rx_value_handle);
log_info("nordic_spp_tx_value_handle 0x%02x", nordic_spp_tx_value_handle);
log_info("nordic_spp_tx_client_configuration_handle 0x%02x", nordic_spp_tx_client_configuration_handle);
// register service with ATT Server
nordic_spp_service.start_handle = start_handle;
@ -137,6 +150,6 @@ void nordic_spp_service_server_request_can_send_now(btstack_context_callback_reg
* @param size
*/
int nordic_spp_service_server_send(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size){
return att_server_notify(con_handle, nordic_spp_rx_value_handle, &data[0], size);
return att_server_notify(con_handle, nordic_spp_tx_value_handle, (uint8_t *)&data[0], size);
}