support clear/set privacy flag, classic connection

This commit is contained in:
Matthias Ringwald 2015-08-12 11:17:50 +02:00
parent 264d2bd80e
commit 198f965c3c

View File

@ -101,6 +101,7 @@ static int sm_mitm_protection = 0;
static int sm_have_oob_data = 0;
static uint8_t * sm_oob_data = (uint8_t *) "0123456789012345"; // = { 0x30...0x39, 0x30..0x35}
static int sm_min_key_size = 7;
static uint8_t pts_privacy_flag;
static int peer_addr_type;
static bd_addr_t peer_address;
@ -317,7 +318,6 @@ void use_public_pts_address(void){
void handle_gatt_client_event(le_event_t * event){
le_characteristic_value_event_t * value;
uint8_t address_type;
uint8_t privacy_flag = 0;
bd_addr_t flipped_address;
switch(event->type){
case GATT_SERVICE_QUERY_RESULT:
@ -358,9 +358,13 @@ void handle_gatt_client_event(le_event_t * event){
break;
case CENTRAL_W4_PERIPHERAL_PRIVACY_FLAG_QUERY_COMPLETE:
central_state = CENTRAL_IDLE;
gatt_client_write_value_of_characteristic(gc_id, handle, gap_peripheral_privacy_flag_characteristic.value_handle, 1, &privacy_flag);
use_public_pts_address();
printf("Peripheral Privacy Flag set to FALSE, connecting to public PTS address again\n");
gatt_client_write_value_of_characteristic(gc_id, handle, gap_peripheral_privacy_flag_characteristic.value_handle, 1, &pts_privacy_flag);
if (pts_privacy_flag){
printf("Peripheral Privacy Flag set to TRUE\n");
} else {
use_public_pts_address();
printf("Peripheral Privacy Flag set to FALSE, connecting to public PTS address again\n");
}
break;
default:
break;
@ -415,6 +419,8 @@ void show_usage(void){
printf("---\n");
printf("1 - enable privacy using random non-resolvable private address\n");
printf("2 - clear Peripheral Privacy Flag on PTS\n");
printf("3 - set Peripheral Privacy Flag on PTS\n");
printf("9 - create HCI Classic connection to addr %s\n", bd_addr_to_str(public_pts_address));
printf("s/S - passive/active scanning\n");
printf("a - enable Advertisements\n");
printf("b - start bonding\n");
@ -456,6 +462,20 @@ int stdin_process(struct data_source *ds){
update_advertisment_params();
show_usage();
break;
case '2':
pts_privacy_flag = 0;
central_state = CENTRAL_W4_PERIPHERAL_PRIVACY_FLAG_QUERY_COMPLETE;
gatt_client_discover_characteristics_for_handle_range_by_uuid16(gc_id, handle, 1, 0xffff, GAP_PERIPHERAL_PRIVACY_FLAG);
break;
case '3':
pts_privacy_flag = 1;
central_state = CENTRAL_W4_PERIPHERAL_PRIVACY_FLAG_QUERY_COMPLETE;
gatt_client_discover_characteristics_for_handle_range_by_uuid16(gc_id, handle, 1, 0xffff, GAP_PERIPHERAL_PRIVACY_FLAG);
break;
case '9':
printf("Creating HCI Classic Connection to %s\n", bd_addr_to_str(public_pts_address));
hci_send_cmd(&hci_create_connection, public_pts_address, hci_usable_acl_packet_types(), 0, 0, 0, 1);
break;
case 'a':
hci_send_cmd(&hci_le_set_advertise_enable, 1);
show_usage();
@ -487,10 +507,6 @@ int stdin_process(struct data_source *ds){
central_state = CENTRAL_W4_NAME_QUERY_COMPLETE;
gatt_client_discover_characteristics_for_handle_range_by_uuid16(gc_id, handle, 1, 0xffff, GAP_DEVICE_NAME_UUID);
break;
case '2':
central_state = CENTRAL_W4_PERIPHERAL_PRIVACY_FLAG_QUERY_COMPLETE;
gatt_client_discover_characteristics_for_handle_range_by_uuid16(gc_id, handle, 1, 0xffff, GAP_PERIPHERAL_PRIVACY_FLAG);
break;
case 'o':
central_state = CENTRAL_W4_RECONNECTION_ADDRESS_QUERY_COMPLETE;
gatt_client_discover_characteristics_for_handle_range_by_uuid16(gc_id, handle, 1, 0xffff, GAP_RECONNECTION_ADDRESS_UUID);