use higher advertisement rate, request slave security, start subscribe after connection is encrypted

This commit is contained in:
matthias.ringwald 2014-06-09 20:12:33 +00:00
parent ce8ecddc86
commit f8f845275e

View File

@ -108,6 +108,7 @@ static uint16_t handle;
typedef enum { typedef enum {
TC_IDLE, TC_IDLE,
TC_W4_ENCRYPTED_CONNECTION,
TC_W4_SERVICE_RESULT, TC_W4_SERVICE_RESULT,
TC_W4_CHARACTERISTIC_RESULT, TC_W4_CHARACTERISTIC_RESULT,
TC_W4_DATA_SOURCE_SUBSCRIBED, TC_W4_DATA_SOURCE_SUBSCRIBED,
@ -125,7 +126,7 @@ static le_characteristic_t ancs_control_point_characteristic;
static le_characteristic_t ancs_data_source_characteristic; static le_characteristic_t ancs_data_source_characteristic;
static int ancs_characteristcs; static int ancs_characteristcs;
static tc_state_t tc_state = TC_IDLE; static tc_state_t tc_state = TC_IDLE;
void handle_gatt_client_event(le_event_t * event){ void handle_gatt_client_event(le_event_t * event){
@ -145,7 +146,7 @@ void handle_gatt_client_event(le_event_t * event){
break; break;
} }
tc_state = TC_W4_CHARACTERISTIC_RESULT; tc_state = TC_W4_CHARACTERISTIC_RESULT;
printf("test client - CHARACTERISTIC for ANCS SERVICE \n"); printf("ANCS Client - Discover characteristics for ANCS SERVICE \n");
gatt_client_discover_characteristics_for_service(&ancs_client_context, &ancs_service); gatt_client_discover_characteristics_for_service(&ancs_client_context, &ancs_service);
break; break;
default: default:
@ -241,8 +242,8 @@ static void gap_run(){
uint8_t adv_type = 0; // default uint8_t adv_type = 0; // default
bd_addr_t null_addr; bd_addr_t null_addr;
memset(null_addr, 0, 6); memset(null_addr, 0, 6);
uint16_t adv_int_min = 0x800; uint16_t adv_int_min = 0x0030;
uint16_t adv_int_max = 0x800; uint16_t adv_int_max = 0x0030;
hci_send_cmd(&hci_le_set_advertising_parameters, adv_int_min, adv_int_max, adv_type, 0, 0, &null_addr, 0x07, 0x00); hci_send_cmd(&hci_le_set_advertising_parameters, adv_int_min, adv_int_max, adv_type, 0, 0, &null_addr, 0x07, 0x00);
return; return;
} }
@ -256,7 +257,7 @@ static void gap_run(){
} }
static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
int connection_encrypted;
switch (packet_type) { switch (packet_type) {
case HCI_EVENT_PACKET: case HCI_EVENT_PACKET:
@ -277,11 +278,11 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
handle = READ_BT_16(packet, 4); handle = READ_BT_16(packet, 4);
printf("Connection handle 0x%04x\n", handle); printf("Connection handle 0x%04x\n", handle);
// let's start // we need to be paired to enable notifications
tc_state = TC_W4_SERVICE_RESULT; tc_state = TC_W4_ENCRYPTED_CONNECTION;
printf("\ntest client - CONNECTED, query primary services\n"); sm_send_security_request();
gatt_client_start(&ancs_client_context, handle); break;
gatt_client_discover_primary_services_by_uuid128(&ancs_client_context, ancs_service_uuid);
break; break;
default: default:
@ -289,6 +290,19 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
} }
break; break;
case HCI_EVENT_ENCRYPTION_CHANGE:
if (handle != READ_BT_16(packet, 3)) break;
connection_encrypted = packet[5];
log_info("Eencryption state change: %u", connection_encrypted);
if (!connection_encrypted) break;
if (tc_state != TC_W4_ENCRYPTED_CONNECTION) break;
// let's start
printf("\nANCS Client - CONNECTED, discover ANCS service\n");
tc_state = TC_W4_SERVICE_RESULT;
gatt_client_start(&ancs_client_context, handle);
gatt_client_discover_primary_services_by_uuid128(&ancs_client_context, ancs_service_uuid);
break;
case HCI_EVENT_DISCONNECTION_COMPLETE: case HCI_EVENT_DISCONNECTION_COMPLETE:
todos = ENABLE_ADVERTISEMENTS; todos = ENABLE_ADVERTISEMENTS;
break; break;