From e8c7151f452dbf2749c1125f80ed62c8bee9f574 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 28 Jul 2015 15:42:44 +0200 Subject: [PATCH] add toggle for connectable/non-connectable advertisements --- test/pts/ble_central_test.c | 59 ++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/test/pts/ble_central_test.c b/test/pts/ble_central_test.c index e3e9f4c55..eed0d2d72 100644 --- a/test/pts/ble_central_test.c +++ b/test/pts/ble_central_test.c @@ -88,6 +88,7 @@ static uint8_t test_irk[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0 static int gap_privacy = 0; static int gap_bondable = 0; static char gap_device_name[20]; +static int gap_connectable = 0; static char * sm_io_capabilities = NULL; static int sm_mitm_protection = 0; @@ -185,6 +186,32 @@ static void handle_advertising_event(uint8_t * packet, int size){ printf_hexdump(adv_data, adv_size); } +static uint8_t gap_adv_type(void){ + // if (gap_scannable) return 0x02; + // if (gap_directed_connectable) return 0x01; + if (!gap_connectable) return 0x03; + return 0x00; +} + +static void test_set_advertisment_params(void){ + uint8_t adv_type = gap_adv_type(); + bd_addr_t null_addr; + memset(null_addr, 0, 6); + uint16_t adv_int_min = 0x800; + uint16_t adv_int_max = 0x800; + switch (adv_type){ + case 0: + case 2: + case 3: + hci_le_advertisements_set_params(&hci_le_set_advertising_parameters, adv_int_min, adv_int_max, adv_type, 0, &null_addr, 0x07, 0x00); + break; + case 1: + case 4: + hci_le_advertisements_set_params(&hci_le_set_advertising_parameters, adv_int_min, adv_int_max, adv_type, tester_address_type, &tester_address, 0x07, 0x00); + break; + } +} + static void gap_run(void){ if (!hci_can_send_command_packet_now()) return; } @@ -318,6 +345,7 @@ int scanning_active = 0; void show_usage(void){ printf("\e[1;1H\e[2J"); printf("--- CLI for LE Central ---\n"); + printf("GAP: connectable %u\n"); printf("SM: %s, MITM protection %u, OOB data %u, key range [%u..16]\n", sm_io_capabilities, sm_mitm_protection, sm_have_oob_data, sm_min_key_size); printf("Privacy %u\n", gap_privacy); @@ -325,6 +353,8 @@ void show_usage(void){ printf("Value Handle: %x\n", value_handle); printf("Attribute Size: %u\n", attribute_size); printf("---\n"); + printf("c/C - connectable off\n"); + printf("---\n"); printf("s/S - passive/active scanning\n"); printf("a - enable Advertisements\n"); printf("n - query GATT Device Name\n"); @@ -431,23 +461,7 @@ int stdin_process(struct data_source *ds){ printf("Sending l2cap connection update parameter request\n"); l2cap_le_request_connection_parameter_update(handle, 50, 120, 0, 550); break; - case 'j': - printf("Create L2CAP Connection to %s\n", bd_addr_to_str(tester_address)); - hci_send_cmd(&hci_le_create_connection, - 1000, // scan interval: 625 ms - 1000, // scan interval: 625 ms - 0, // don't use whitelist - 0, // peer address type: public - tester_address, // remote bd addr - tester_address_type, // random or public - 80, // conn interval min - 80, // conn interval max (3200 * 0.625) - 0, // conn latency - 2000, // supervision timeout - 0, // min ce length - 1000 // max ce length - ); - break; + case 'd': printf("Discover all primary services\n"); gatt_client_discover_primary_services(gc_id, handle); @@ -464,7 +478,16 @@ int stdin_process(struct data_source *ds){ case 'a': hci_send_cmd(&hci_le_set_advertise_enable, 1); break; - + case 'c': + printf("GAP: Connectable = 1\n"); + gap_connectable = 1; + test_set_advertisment_params(); + break; + case 'C': + printf("GAP: Connectable = 0\n"); + gap_connectable = 0; + test_set_advertisment_params(); + break; case 'n': central_state = CENTRAL_W4_NAME_QUERY_COMPLETE; gatt_client_discover_characteristics_for_handle_range_by_uuid16(gc_id, handle, 1, 0xffff, 0x2a00);