hfp: fix example, fix rfcomm connection establishment

This commit is contained in:
Milanka Ringwald 2015-07-16 10:26:53 +02:00
parent 618d81f09a
commit b93e0a8876
5 changed files with 24 additions and 18 deletions

View File

@ -288,6 +288,7 @@ static void handle_query_rfcomm_event(sdp_query_event_t * event, void * context)
if (connection->rfcomm_channel_nr > 0){
connection->state = HFP_W4_RFCOMM_CONNECTED;
log_info("HFP: SDP_QUERY_COMPLETE context %p, addr %s, state %d", connection, bd_addr_to_str( connection->remote_addr), connection->state);
rfcomm_create_channel_internal(NULL, connection->remote_addr, connection->rfcomm_channel_nr);
break;
}
@ -338,11 +339,10 @@ hfp_connection_t * hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, ui
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
// data: event(8), len(8), status (8), address (48), handle(16), server channel(8), rfcomm_cid(16), max frame size(16)
bt_flip_addr(event_addr, &packet[2]);
bt_flip_addr(event_addr, &packet[3]);
context = provide_hfp_connection_context_for_bd_addr(event_addr);
if (!context || context->state != HFP_W4_RFCOMM_CONNECTED) return context;
if (packet[2]) {
hfp_reset_state(context);
hfp_emit_event(context->callback, HFP_SUBEVENT_AUDIO_CONNECTION_COMPLETE, packet[2]);
@ -351,7 +351,6 @@ hfp_connection_t * hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, ui
context->rfcomm_cid = READ_BT_16(packet, 12);
uint16_t mtu = READ_BT_16(packet, 14);
context->state = HFP_EXCHANGE_SUPPORTED_FEATURES;
printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", context->rfcomm_cid, mtu);
}
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
@ -373,6 +372,8 @@ void hfp_init(uint16_t rfcomm_channel_nr){
void hfp_connect(bd_addr_t bd_addr, uint16_t service_uuid){
hfp_connection_t * connection = provide_hfp_connection_context_for_bd_addr(bd_addr);
log_info("hfp_connect %s, context %p", bd_addr_to_str(bd_addr), connection);
if (!connection) {
log_error("hfp_hf_connect for addr %s failed", bd_addr_to_str(bd_addr));
return;

View File

@ -139,7 +139,7 @@ typedef struct hfp_connection {
uint8_t remote_indicators_nr;
uint16_t remote_indicators[20];
uint32_t remote_indicators_status;
uint8_t remote_hf_indicators_nr;
uint16_t remote_hf_indicators[20];
uint32_t remote_hf_indicators_status;

View File

@ -304,7 +304,8 @@ hfp_connection_t * hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel
if (strncmp((char *)packet, HFP_Support_Call_Hold_And_Multiparty_Services, strlen(HFP_Support_Call_Hold_And_Multiparty_Services)) == 0){
offset = strlen(HFP_Support_Call_Hold_And_Multiparty_Services) + 1; // +1 for =
// TODO
printf("AT+CHLD %s, offset %u, size %u\n", (char *)&packet[offset], offset, size);
context->wait_ok = 1;
return context;
}
@ -365,13 +366,13 @@ static void packet_handler(void * connection, uint8_t packet_type, uint16_t chan
hfp_run(context);
}
void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint8_t * codecs, int codecs_nr, uint16_t * indicators, int indicators_nr, uint8_t indicators_status){
void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint8_t * codecs, int codecs_nr, uint16_t * indicators, int indicators_nr, uint32_t indicators_status){
if (codecs_nr > HFP_MAX_NUM_CODECS){
log_error("hfp_init: codecs_nr (%d) > HFP_MAX_NUM_CODECS (%d)", codecs_nr, HFP_MAX_NUM_CODECS);
return;
}
hfp_init(rfcomm_channel_nr);
rfcomm_register_packet_handler(packet_handler);
hfp_init(rfcomm_channel_nr);
int i;

View File

@ -55,7 +55,7 @@ extern "C" {
void hfp_hf_create_service(uint8_t * service, int rfcomm_channel_nr, const char * name, uint16_t supported_features);
void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint8_t * codecs, int codecs_nr, uint16_t * indicators, int indicators_nr, uint8_t indicators_status);
void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint8_t * codecs, int codecs_nr, uint16_t * indicators, int indicators_nr, uint32_t indicators_status);
void hfp_hf_connect(bd_addr_t bd_addr);
void hfp_hf_disconnect(bd_addr_t bd_addr);

View File

@ -70,11 +70,11 @@
const uint32_t hfp_service_buffer[150/4]; // implicit alignment to 4-byte memory address
const uint8_t rfcomm_channel_nr = 1;
const char hfp_hf_service_name[] = "Headset Test";
const char hfp_hf_service_name[] = "BTstack HF Test";
static bd_addr_t pts_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
static bd_addr_t local_mac = {0x04, 0x0C, 0xCE, 0xE4, 0x85, 0xD3};
// prototypes
static void show_usage();
@ -83,9 +83,9 @@ static void show_usage();
static void show_usage(void){
printf("\n--- Bluetooth HFP Hands-Free (HF) unit Test Console ---\n");
printf("---\n");
printf("p - establish audio connection to PTS module\n");
printf("e - establish audio connection to local mac\n");
printf("d - release audio connection from Bluetooth Speaker\n");
printf("p - establish HFP connection to PTS module\n");
printf("e - establish HFP connection to local mac\n");
printf("d - release HFP connection\n");
printf("---\n");
printf("Ctrl-c - exit\n");
printf("---\n");
@ -97,15 +97,15 @@ static int stdin_process(struct data_source *ds){
switch (buffer){
case 'p':
printf("Establishing audio connection to PTS module %s...\n", bd_addr_to_str(pts_addr));
printf("Establishing HFP connection to PTS module %s...\n", bd_addr_to_str(pts_addr));
hfp_hf_connect(pts_addr);
break;
case 'e':
printf("Establishing audio connection to local mac %s...\n", bd_addr_to_str(local_mac));
printf("Establishing HFP connection to local mac %s...\n", bd_addr_to_str(local_mac));
hfp_hf_connect(local_mac);
break;
case 'd':
printf("Releasing audio connection.\n");
printf("Releasing HFP connection.\n");
hfp_hf_disconnect(pts_addr);
break;
default:
@ -126,10 +126,14 @@ void packet_handler(uint8_t * event, uint16_t event_size){
int btstack_main(int argc, const char * argv[]){
// init L2CAP
uint8_t codecs[1] = {HFP_Codec_CSVD};
uint16_t indicators[1] = {0x01};
l2cap_init();
rfcomm_init();
// TODO: hfp_hf_init(rfcomm_channel_nr);
hfp_hf_init(rfcomm_channel_nr, HFP_Default_HF_Supported_Features, codecs, sizeof(codecs), indicators, sizeof(indicators)/sizeof(uint16_t), 1);
hfp_register_packet_handler(packet_handler);
sdp_init();