From 8c94c0448e3940a70f8fcb0bae89685e5a7bafd6 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 9 Oct 2018 12:29:07 +0200 Subject: [PATCH] pbap_client: allow to specify phonebook path with pbap_pull_phonebook and pbap_get_phonebook_size --- example/pbap_client_demo.c | 18 ++++++++++-------- src/classic/pbap_client.c | 10 ++++++---- src/classic/pbap_client.h | 6 ++++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/example/pbap_client_demo.c b/example/pbap_client_demo.c index 2366672da..3e6bfb42e 100644 --- a/example/pbap_client_demo.c +++ b/example/pbap_client_demo.c @@ -72,10 +72,12 @@ static bd_addr_t remote_addr; // Nexus 7 "30-85-A9-54-2E-78" // iPhone SE "BC:EC:5D:E6:15:03" // PTS "001BDC080AA5" -static char * remote_addr_string = "BC:EC:5D:E6:15:03"; +static char * remote_addr_string = "001BDC080AA5"; static char * phone_number = "911"; +static const char * phonebook_path = "telecom/pb.vcf"; + static btstack_packet_callback_registration_t hci_event_callback_registration; static uint16_t pbap_cid; @@ -89,11 +91,11 @@ static void show_usage(void){ printf("\n--- Bluetooth PBAP Client (HF) Test Console %s ---\n", bd_addr_to_str(iut_address)); printf("\n"); printf("a - establish PBAP connection to %s\n", bd_addr_to_str(remote_addr)); - printf("b - set phonebook '/telecom/pb'\n"); - printf("c - set phonebook '/SIM1/telecom/pb'\n"); - printf("r - set path to '/root/telecom'\n"); - printf("d - get phonebook size\n"); - printf("e - pull phonebook\n"); + printf("b - set phonebook '/telecom/pb'\n"); + printf("c - set phonebook '/SIM1/telecom/pb'\n"); + printf("r - set path to '/root/telecom'\n"); + printf("d - get size of '%s'\n", phonebook_path); + printf("e - pull phonebook '%s'\n", phonebook_path); printf("f - disconnnect\n"); printf("g - Lookup contact with number '%s'\n", phone_number); printf("p - authenticate using password '0000'\n"); @@ -116,10 +118,10 @@ static void stdin_process(char c){ pbap_set_phonebook(pbap_cid, "SIM1/telecom/pb"); break; case 'd': - pbap_get_phonebook_size(pbap_cid); + pbap_get_phonebook_size(pbap_cid, phonebook_path); break; case 'e': - pbap_pull_phonebook(pbap_cid); + pbap_pull_phonebook(pbap_cid, phonebook_path); break; case 'f': pbap_disconnect(pbap_cid); diff --git a/src/classic/pbap_client.c b/src/classic/pbap_client.c index 364d53b65..385a22705 100644 --- a/src/classic/pbap_client.c +++ b/src/classic/pbap_client.c @@ -66,7 +66,6 @@ static const uint8_t pbap_uuid[] = { 0x79, 0x61, 0x35, 0xf0, 0xf0, 0xc5, 0x11, 0xd8, 0x09, 0x66, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66}; const char * pbap_phonebook_type = "x-bt/phonebook"; -const char * pbap_phonebook_name = "pb.vcf"; const char * pbap_vcard_listing_type = "x-bt/vcard-listing"; const char * pbap_vcard_listing_name = "pb"; @@ -121,6 +120,7 @@ typedef struct pbap_client { int single_response_mode_parameter; const char * current_folder; const char * phone_number; + const char * phonebook_path; uint16_t set_path_offset; uint8_t authentication_options; uint16_t authentication_nonce[16]; @@ -293,7 +293,7 @@ static void pbap_handle_can_send_now(void){ goep_client_add_header_srm_enable(pbap_client->goep_cid); pbap_client->srm_state = SRM_W4_CONFIRM; goep_client_add_header_type(pbap_client->goep_cid, pbap_phonebook_type); - goep_client_add_header_name(pbap_client->goep_cid, pbap_phonebook_name); + goep_client_add_header_name(pbap_client->goep_cid, pbap_client->phonebook_path); if (pbap_client->state == PBAP_W2_GET_PHONEBOOK_SIZE){ // Regular TLV wih 1-byte len application_parameters[0] = PBAP_APPLICATION_PARAMETER_MAX_LIST_COUNT; @@ -733,19 +733,21 @@ uint8_t pbap_disconnect(uint16_t pbap_cid){ return 0; } -uint8_t pbap_get_phonebook_size(uint16_t pbap_cid){ +uint8_t pbap_get_phonebook_size(uint16_t pbap_cid, const char * path){ UNUSED(pbap_cid); if (pbap_client->state != PBAP_CONNECTED) return BTSTACK_BUSY; pbap_client->state = PBAP_W2_GET_PHONEBOOK_SIZE; + pbap_client->phonebook_path = path; pbap_client->request_number = 0; goep_client_request_can_send_now(pbap_client->goep_cid); return 0; } -uint8_t pbap_pull_phonebook(uint16_t pbap_cid){ +uint8_t pbap_pull_phonebook(uint16_t pbap_cid, const char * path){ UNUSED(pbap_cid); if (pbap_client->state != PBAP_CONNECTED) return BTSTACK_BUSY; pbap_client->state = PBAP_W2_PULL_PHONEBOOK; + pbap_client->phonebook_path = path; pbap_client->request_number = 0; goep_client_request_can_send_now(pbap_client->goep_cid); return 0; diff --git a/src/classic/pbap_client.h b/src/classic/pbap_client.h index 54ee8a00e..1a5debc76 100644 --- a/src/classic/pbap_client.h +++ b/src/classic/pbap_client.h @@ -93,16 +93,18 @@ uint8_t pbap_set_phonebook(uint16_t pbap_cid, const char * path); /** * @brief Get size of phone book from PSE * @param pbap_cid + * @param path - note: path is not copied, common path 'telecom/pb.vcf' * @return status */ -uint8_t pbap_get_phonebook_size(uint16_t pbap_cid); +uint8_t pbap_get_phonebook_size(uint16_t pbap_cid, const char * path); /** * @brief Pull phone book from PSE * @param pbap_cid + * @param path - note: path is not copied, common path 'telecom/pb.vcf' * @return status */ -uint8_t pbap_pull_phonebook(uint16_t pbap_cid); +uint8_t pbap_pull_phonebook(uint16_t pbap_cid, const char * path); /** * @brief Lookup contact(s) by phone number