pbap_client: emit PBAP_SUBEVENT_CARD_RESULT, show in demo app

This commit is contained in:
Matthias Ringwald 2018-09-27 09:38:18 +02:00
parent ad51486062
commit 83f1bca067
3 changed files with 48 additions and 9 deletions

View File

@ -140,6 +140,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
UNUSED(size); UNUSED(size);
int i; int i;
uint8_t status; uint8_t status;
char buffer[32];
switch (packet_type){ switch (packet_type){
case HCI_EVENT_PACKET: case HCI_EVENT_PACKET:
switch (hci_event_packet_get_type(packet)) { switch (hci_event_packet_get_type(packet)) {
@ -152,7 +153,12 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
case HCI_EVENT_PBAP_META: case HCI_EVENT_PBAP_META:
switch (hci_event_pbap_meta_get_subevent_code(packet)){ switch (hci_event_pbap_meta_get_subevent_code(packet)){
case PBAP_SUBEVENT_CONNECTION_OPENED: case PBAP_SUBEVENT_CONNECTION_OPENED:
printf("[+] Connected\n"); status = pbap_subevent_connection_opened_get_status(packet);
if (status){
printf("[!] Connection failed, status 0x%02x\n", status);
} else {
printf("[+] Connected\n");
}
break; break;
case PBAP_SUBEVENT_CONNECTION_CLOSED: case PBAP_SUBEVENT_CONNECTION_CLOSED:
printf("[+] Connection closed\n"); printf("[+] Connection closed\n");
@ -166,11 +172,19 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
case PBAP_SUBEVENT_PHONEBOOK_SIZE: case PBAP_SUBEVENT_PHONEBOOK_SIZE:
status = pbap_subevent_phonebook_size_get_status(packet); status = pbap_subevent_phonebook_size_get_status(packet);
if (status){ if (status){
printf("[+] Get Phonebook size error: 0x%x\n", status); printf("[!] Get Phonebook size error: 0x%x\n", status);
} else { } else {
printf("[+] Phonebook size: %u\n", pbap_subevent_phonebook_size_get_phoneboook_size(packet)); printf("[+] Phonebook size: %u\n", pbap_subevent_phonebook_size_get_phoneboook_size(packet));
} }
break; break;
case PBAP_SUBEVENT_CARD_RESULT:
memcpy(buffer, pbap_subevent_card_result_get_name(packet), pbap_subevent_card_result_get_name_len(packet));
buffer[pbap_subevent_card_result_get_name_len(packet)] = 0;
printf("[-] Name: '%s'\n", buffer);
memcpy(buffer, pbap_subevent_card_result_get_handle(packet), pbap_subevent_card_result_get_handle_len(packet));
buffer[pbap_subevent_card_result_get_handle_len(packet)] = 0;
printf("[-] Handle: '%s'\n", buffer);
break;
default: default:
break; break;
} }

View File

@ -82,8 +82,6 @@
#include "classic/goep_client.h" #include "classic/goep_client.h"
#include "classic/pbap_client.h" #include "classic/pbap_client.h"
#define PBAP_MAX_PHONE_NUMBER_LEN 30
// 796135f0-f0c5-11d8-0966- 0800200c9a66 // 796135f0-f0c5-11d8-0966- 0800200c9a66
uint8_t pbap_uuid[] = { 0x79, 0x61, 0x35, 0xf0, 0xf0, 0xc5, 0x11, 0xd8, 0x09, 0x66, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66}; uint8_t pbap_uuid[] = { 0x79, 0x61, 0x35, 0xf0, 0xf0, 0xc5, 0x11, 0xd8, 0x09, 0x66, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66};
@ -221,6 +219,26 @@ static void pbap_client_emit_authentication_event(pbap_client_t * context, uint8
context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos); context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos);
} }
static void pbap_client_emit_card_result_event(pbap_client_t * context, const char * name, const char * handle){
uint8_t event[5 + PBAP_MAX_NAME_LEN + PBAP_MAX_HANDLE_LEN];
int pos = 0;
event[pos++] = HCI_EVENT_PBAP_META;
pos++; // skip len
event[pos++] = PBAP_SUBEVENT_CARD_RESULT;
little_endian_store_16(event,pos,context->cid);
pos+=2;
int name_len = btstack_min(PBAP_MAX_NAME_LEN, strlen(name));
event[pos++] = name_len;
memcpy(&event[pos], name, name_len);
pos += name_len;
int handle_len = btstack_min(PBAP_MAX_HANDLE_LEN, strlen(handle));
event[pos++] = handle_len;
memcpy(&event[pos], handle, handle_len);
pos += handle_len;
event[1] = pos - 2;
context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos);
}
static const uint8_t collon = (uint8_t) ':'; static const uint8_t collon = (uint8_t) ':';
static void pbap_handle_can_send_now(void){ static void pbap_handle_can_send_now(void){
@ -528,7 +546,6 @@ static void pbap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *
pbap_client_emit_phonebook_size_event(pbap_client, OBEX_UNKNOWN_ERROR, 0); pbap_client_emit_phonebook_size_event(pbap_client, OBEX_UNKNOWN_ERROR, 0);
break; break;
case PBAP_W4_GET_CARD_LIST_COMPLETE: case PBAP_W4_GET_CARD_LIST_COMPLETE:
printf("PBAP_W4_GET_CARD_LIST_COMPLETE\n");
if (packet[0] == OBEX_RESP_CONTINUE){ if (packet[0] == OBEX_RESP_CONTINUE){
pbap_client->state = PBAP_W2_GET_CARD_LIST; pbap_client->state = PBAP_W2_GET_CARD_LIST;
goep_client_request_can_send_now(pbap_client->goep_cid); goep_client_request_can_send_now(pbap_client->goep_cid);
@ -543,8 +560,8 @@ static void pbap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *
int card_found = 0; int card_found = 0;
int name_found = 0; int name_found = 0;
int handle_found = 0; int handle_found = 0;
char name[32]; char name[PBAP_MAX_NAME_LEN];
char handle[16]; char handle[PBAP_MAX_HANDLE_LEN];
name[0] = 0; name[0] = 0;
handle[0] = 0; handle[0] = 0;
while (data_len--){ while (data_len--){
@ -555,8 +572,7 @@ static void pbap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *
break; break;
case YXML_ELEMEND: case YXML_ELEMEND:
if (card_found){ if (card_found){
printf("Name: '%s'\n", name); pbap_client_emit_card_result_event(pbap_client, name, handle);
printf("Handle: '%s'\n", handle);
} }
card_found = 0; card_found = 0;
break; break;
@ -595,6 +611,7 @@ static void pbap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *
} }
// //
pbap_client->state = PBAP_CONNECTED; pbap_client->state = PBAP_CONNECTED;
pbap_client_emit_operation_complete_event(pbap_client, 0);
} }
} }

View File

@ -44,6 +44,14 @@ extern "C" {
#include "btstack_config.h" #include "btstack_config.h"
#include <stdint.h> #include <stdint.h>
// max len of phone number used for lookup in pbap_lookup_by_number
#define PBAP_MAX_PHONE_NUMBER_LEN 32
// max len of name reported in PBAP_SUBEVENT_CARD_RESULT
#define PBAP_MAX_NAME_LEN 32
// max len of vcard handle reported in PBAP_SUBEVENT_CARD_RESULT
#define PBAP_MAX_HANDLE_LEN 16
/* API_START */ /* API_START */
/** /**