mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-25 09:02:30 +00:00
support writable device name
This commit is contained in:
parent
4a4f3f5816
commit
01a8aec568
@ -84,6 +84,7 @@ static int gap_bondable = 0;
|
|||||||
static int gap_directed_connectable = 0;
|
static int gap_directed_connectable = 0;
|
||||||
static int gap_privacy = 0;
|
static int gap_privacy = 0;
|
||||||
static int gap_scannable = 0;
|
static int gap_scannable = 0;
|
||||||
|
static char gap_device_name[20];
|
||||||
|
|
||||||
static bd_addr_t gap_reconnection_address;
|
static bd_addr_t gap_reconnection_address;
|
||||||
|
|
||||||
@ -281,7 +282,8 @@ static void app_run(){
|
|||||||
static uint16_t att_read_callback(uint16_t handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
|
static uint16_t att_read_callback(uint16_t handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
|
||||||
|
|
||||||
printf("READ Callback, handle %04x, offset %u, buffer size %u\n", handle, offset, buffer_size);
|
printf("READ Callback, handle %04x, offset %u, buffer size %u\n", handle, offset, buffer_size);
|
||||||
|
uint16_t att_value_len;
|
||||||
|
|
||||||
uint16_t uuid16 = att_uuid_for_handle(handle);
|
uint16_t uuid16 = att_uuid_for_handle(handle);
|
||||||
switch (uuid16){
|
switch (uuid16){
|
||||||
case 0x2902:
|
case 0x2902:
|
||||||
@ -289,11 +291,20 @@ static uint16_t att_read_callback(uint16_t handle, uint16_t offset, uint8_t * bu
|
|||||||
buffer[0] = client_configuration;
|
buffer[0] = client_configuration;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
case 0x2a00:
|
||||||
|
att_value_len = strlen(gap_device_name);
|
||||||
|
if (buffer) {
|
||||||
|
memcpy(buffer, gap_device_name, att_value_len);
|
||||||
|
}
|
||||||
|
return att_value_len;
|
||||||
case 0x2A03:
|
case 0x2A03:
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
bt_flip_addr(buffer, gap_reconnection_address);
|
bt_flip_addr(buffer, gap_reconnection_address);
|
||||||
}
|
}
|
||||||
return 6;
|
return 6;
|
||||||
|
|
||||||
|
// handle device name
|
||||||
|
// handle appearance
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -301,7 +312,6 @@ static uint16_t att_read_callback(uint16_t handle, uint16_t offset, uint8_t * bu
|
|||||||
// find attribute
|
// find attribute
|
||||||
int index = att_attribute_for_handle(handle);
|
int index = att_attribute_for_handle(handle);
|
||||||
uint8_t * att_value;
|
uint8_t * att_value;
|
||||||
uint16_t att_value_len;
|
|
||||||
if (index < 0){
|
if (index < 0){
|
||||||
// not written before
|
// not written before
|
||||||
if (att_default_value_long){
|
if (att_default_value_long){
|
||||||
@ -343,10 +353,17 @@ static int att_write_callback(uint16_t handle, uint16_t transaction_mode, uint16
|
|||||||
client_configuration_handle = handle;
|
client_configuration_handle = handle;
|
||||||
printf("Client Configuration set to %u for handle %04x\n", client_configuration, handle);
|
printf("Client Configuration set to %u for handle %04x\n", client_configuration, handle);
|
||||||
return 0; // ok
|
return 0; // ok
|
||||||
|
case 0x2a00:
|
||||||
|
memcpy(gap_device_name, buffer, buffer_size);
|
||||||
|
gap_device_name[buffer_size]=0;
|
||||||
|
printf("Setting device name to '%s'\n", gap_device_name);
|
||||||
|
return 0;
|
||||||
case 0x2A03:
|
case 0x2A03:
|
||||||
bt_flip_addr(gap_reconnection_address, buffer);
|
bt_flip_addr(gap_reconnection_address, buffer);
|
||||||
printf("Setting Reconnection Address to %s\n", bd_addr_to_str(gap_reconnection_address));
|
printf("Setting Reconnection Address to %s\n", bd_addr_to_str(gap_reconnection_address));
|
||||||
return 0;
|
return 0;
|
||||||
|
// handle device name
|
||||||
|
// handle appearance
|
||||||
}
|
}
|
||||||
|
|
||||||
// check transaction mode
|
// check transaction mode
|
||||||
@ -877,7 +894,7 @@ int main(void)
|
|||||||
|
|
||||||
gap_random_address_set_update_period(300000);
|
gap_random_address_set_update_period(300000);
|
||||||
gap_random_address_set_mode(GAP_RANDOM_ADDRESS_RESOLVABLE);
|
gap_random_address_set_mode(GAP_RANDOM_ADDRESS_RESOLVABLE);
|
||||||
|
strcpy(gap_device_name, "BTstack");
|
||||||
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
|
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
|
||||||
sm_io_capabilities = "IO_CAPABILITY_NO_INPUT_NO_OUTPUT";
|
sm_io_capabilities = "IO_CAPABILITY_NO_INPUT_NO_OUTPUT";
|
||||||
sm_set_authentication_requirements(0);
|
sm_set_authentication_requirements(0);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
PRIMARY_SERVICE, GAP_SERVICE
|
PRIMARY_SERVICE, GAP_SERVICE
|
||||||
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "BTstack"
|
CHARACTERISTIC, GAP_DEVICE_NAME, READ | WRITE | DYNAMIC,
|
||||||
CHARACTERISTIC, GAP_APPEARANCE, READ, 00 00
|
CHARACTERISTIC, GAP_APPEARANCE, READ | WRITE | DYNAMIC,
|
||||||
|
|
||||||
// GAP Peripheral Privacy Flag
|
// GAP Peripheral Privacy Flag
|
||||||
CHARACTERISTIC, 2A02, READ | WRITE | DYNAMIC, 00
|
CHARACTERISTIC, 2A02, READ | WRITE | DYNAMIC, 00
|
||||||
|
Loading…
x
Reference in New Issue
Block a user