hfp: HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED emited with connection handle

This commit is contained in:
Milanka Ringwald 2016-04-08 17:04:40 +02:00
parent daf17d1f25
commit a0653c3b5c
11 changed files with 47 additions and 66 deletions

View File

@ -259,7 +259,7 @@ static void show_usage(void);
// Testig User Interface
static void show_usage(void){
printf("\n--- Bluetooth HFP Hands-Free (HF) unit Test Console ---\n");
printf("\n--- Bluetooth HFP Audiogateway (AG) unit Test Console ---\n");
printf("---\n");
printf("a - establish HFP connection to PTS module\n");
@ -548,19 +548,7 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
#endif
static void packet_handler(uint8_t * event, uint16_t event_size){
if (event[0] == RFCOMM_EVENT_CHANNEL_OPENED){
handle = little_endian_read_16(event, 9);
printf("RFCOMM_EVENT_CHANNEL_OPENED received for handle 0x%04x\n", handle);
return;
}
switch (event[0]){
case RFCOMM_EVENT_CHANNEL_OPENED:
handle = little_endian_read_16(event, 9);
printf("RFCOMM_EVENT_CHANNEL_OPENED received for handle 0x%04x\n", handle);
return;
switch (event[0]){
case HCI_EVENT_INQUIRY_RESULT:
case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI:
case HCI_EVENT_INQUIRY_COMPLETE:
@ -585,6 +573,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
printf("Service level connection established.\n");
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:

View File

@ -445,15 +445,11 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
#endif
static void packet_handler(uint8_t * event, uint16_t event_size){
if (event[0] == RFCOMM_EVENT_CHANNEL_OPENED){
handle = little_endian_read_16(event, 9);
printf("RFCOMM_EVENT_CHANNEL_OPENED received for handle 0x%04x\n", handle);
return;
}
if (event[0] != HCI_EVENT_HFP_META) return;
switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
printf("Service level connection established.\n\n");
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:

View File

@ -890,9 +890,10 @@ typedef uint8_t sm_key_t[16];
/** HFP Subevent */
/**
* @format 11
* @format 11H
* @param subevent_code
* @param status 0 == OK
* @param con_handle
*/
#define HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED 0x01

View File

@ -2640,6 +2640,15 @@ static inline const uint8_t * hsp_subevent_ag_indication_get_value(const uint8_t
static inline uint8_t hfp_subevent_service_level_connection_established_get_status(const uint8_t * event){
return event[3];
}
/**
* @brief Get field con_handle from event HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED
* @param event packet
* @return con_handle
* @note: btstack_type H
*/
static inline hci_con_handle_t hfp_subevent_service_level_connection_established_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 4);
}
/**

View File

@ -203,6 +203,17 @@ void hfp_emit_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t valu
(*callback)(event, sizeof(event));
}
void hfp_emit_connection_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t status, hci_con_handle_t con_handle){
if (!callback) return;
uint8_t event[6];
event[0] = HCI_EVENT_HFP_META;
event[1] = sizeof(event) - 2;
event[2] = event_subtype;
event[3] = status; // status 0 == OK
little_endian_store_16(event, 4, con_handle);
(*callback)(event, sizeof(event));
}
void hfp_emit_string_event(hfp_callback_t callback, uint8_t event_subtype, const char * value){
if (!callback) return;
uint8_t event[40];
@ -215,17 +226,6 @@ void hfp_emit_string_event(hfp_callback_t callback, uint8_t event_subtype, const
(*callback)(event, sizeof(event));
}
static void hfp_emit_audio_connection_established_event(hfp_callback_t callback, uint8_t value, uint16_t sco_handle){
if (!callback) return;
uint8_t event[6];
event[0] = HCI_EVENT_HFP_META;
event[1] = sizeof(event) - 2;
event[2] = HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED;
event[3] = value; // status 0 == OK
little_endian_store_16(event, 4, sco_handle);
(*callback)(event, sizeof(event));
}
btstack_linked_list_t * hfp_get_connections(void){
return (btstack_linked_list_t *) &hfp_connections;
}
@ -471,7 +471,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet
if (!hfp_connection || hfp_connection->state != HFP_W4_RFCOMM_CONNECTED) return;
if (status) {
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, status);
hfp_emit_connection_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, status, rfcomm_event_channel_opened_get_con_handle(packet));
remove_hfp_connection_context(hfp_connection);
} else {
hfp_connection->acl_handle = rfcomm_event_channel_opened_get_con_handle(packet);
@ -578,7 +578,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet
hfp_connection->sco_handle = sco_handle;
hfp_connection->establish_audio_connection = 0;
hfp_connection->state = HFP_AUDIO_CONNECTION_ESTABLISHED;
hfp_emit_audio_connection_established_event(hfp_callback, packet[2], sco_handle);
hfp_emit_connection_event(hfp_callback, HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED, packet[2], sco_handle);
break;
}

View File

@ -630,6 +630,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet
void hfp_emit_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t value);
void hfp_emit_simple_event(hfp_callback_t callback, uint8_t event_subtype);
void hfp_emit_string_event(hfp_callback_t callback, uint8_t event_subtype, const char * value);
void hfp_emit_connection_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t status, hci_con_handle_t con_handle);
hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid);
hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr);

View File

@ -620,8 +620,8 @@ static void hfp_init_link_settings(hfp_connection_t * hfp_connection){
static void hfp_ag_slc_established(hfp_connection_t * hfp_connection){
hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0);
hfp_emit_connection_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0, hfp_connection->acl_handle);
hfp_init_link_settings(hfp_connection);
// if active call exist, set per-hfp_connection state active, too (when audio is on)

View File

@ -834,7 +834,7 @@ static void hfp_init_link_settings(hfp_connection_t * hfp_connection){
static void hfp_ag_slc_established(hfp_connection_t * hfp_connection){
hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0);
hfp_emit_connection_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0, hfp_connection->acl_handle);
hfp_init_link_settings(hfp_connection);
// restore volume settings
hfp_connection->speaker_gain = hfp_hf_speaker_gain;

View File

@ -349,13 +349,6 @@ static void simulate_test_sequence(hfp_test_item_t * test_item){
}
void packet_handler(uint8_t * event, uint16_t event_size){
if (event[0] == RFCOMM_EVENT_CHANNEL_OPENED){
handle = little_endian_read_16(event, 9);
printf("RFCOMM_EVENT_CHANNEL_OPENED received for handle 0x%04x\n", handle);
return;
}
if (event[0] != HCI_EVENT_HFP_META) return;
if (event[3]
@ -368,6 +361,7 @@ void packet_handler(uint8_t * event, uint16_t event_size){
switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
printf("Service level connection established.\n");
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:

View File

@ -72,8 +72,8 @@ const uint8_t rfcomm_channel_nr = 1;
const char hfp_ag_service_name[] = "BTstack HFP AG Test";
static bd_addr_t device_addr;
static bd_addr_t pts_addr = {0x00,0x15,0x83,0x5F,0x9D,0x46};
//static bd_addr_t pts_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
//static bd_addr_t pts_addr = {0x00,0x15,0x83,0x5F,0x9D,0x46};
static bd_addr_t pts_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
static bd_addr_t speaker_addr = {0x00, 0x21, 0x3C, 0xAC, 0xF7, 0x38};
static uint8_t codecs[1] = {HFP_CODEC_CVSD};
static uint16_t handle = -1;
@ -268,7 +268,10 @@ static void inquiry_packet_handler (uint8_t packet_type, uint8_t *packet, uint16
// Testig User Interface
static void show_usage(void){
printf("\n--- Bluetooth HFP Hands-Free (HF) unit Test Console ---\n");
bd_addr_t iut_address;
gap_local_bd_addr(iut_address);
printf("\n--- Bluetooth HFP Audiogateway (AG) unit Test Console %s ---\n", bd_addr_to_str(iut_address));
printf("---\n");
printf("a - establish HFP connection to PTS module\n");
@ -533,7 +536,7 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
break;
case 't':
log_info("USER:\'%c\'", cmd);
printf("Terminate HCI connection.\n");
printf("Terminate HCI connection. 0x%2x\n", handle);
gap_disconnect(handle);
break;
case 'u':
@ -567,26 +570,13 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
static void packet_handler(uint8_t * event, uint16_t event_size){
if (event[0] == RFCOMM_EVENT_CHANNEL_OPENED){
handle = little_endian_read_16(event, 9);
printf("RFCOMM_EVENT_CHANNEL_OPENED received for handle 0x%04x\n", handle);
return;
}
switch (event[0]){
case RFCOMM_EVENT_CHANNEL_OPENED:
handle = little_endian_read_16(event, 9);
printf("RFCOMM_EVENT_CHANNEL_OPENED received for handle 0x%04x\n", handle);
return;
case HCI_EVENT_INQUIRY_RESULT:
case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI:
case HCI_EVENT_INQUIRY_COMPLETE:
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
inquiry_packet_handler(HCI_EVENT_PACKET, event, event_size);
break;
default:
break;
}
@ -604,6 +594,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
printf("Service level connection established.\n");
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:

View File

@ -63,6 +63,7 @@
#include "hci.h"
#include "l2cap.h"
#include "btstack_event.h"
#include "classic/rfcomm.h"
#include "sdp_server.h"
#include "btstack_debug.h"
@ -89,7 +90,10 @@ static void show_usage(void);
// Testig User Interface
static void show_usage(void){
printf("\n--- Bluetooth HFP Hands-Free (HF) unit Test Console ---\n");
bd_addr_t iut_address;
gap_local_bd_addr(iut_address);
printf("\n--- Bluetooth HFP Hands-Free (HF) unit Test Console %s ---\n", bd_addr_to_str(iut_address));
printf("---\n");
printf("z - use iPhone as Audiogateway\n");
@ -459,15 +463,11 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
static void packet_handler(uint8_t * event, uint16_t event_size){
if (event[0] == RFCOMM_EVENT_CHANNEL_OPENED){
handle = little_endian_read_16(event, 9);
printf("RFCOMM_EVENT_CHANNEL_OPENED received for handle 0x%04x\n", handle);
return;
}
if (event[0] != HCI_EVENT_HFP_META) return;
switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
printf("Service level connection established.\n\n");
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED: