fix unit test

This commit is contained in:
Milanka Ringwald 2015-11-12 14:16:20 +01:00
parent 0fcfc79931
commit 8c72a38b3b
4 changed files with 43 additions and 30 deletions

View File

@ -311,6 +311,7 @@ static hfp_connection_t * provide_hfp_connection_context_for_bd_addr(bd_addr_t b
hfp_connection_t * context = get_hfp_connection_context_for_bd_addr(bd_addr);
if (context) return context;
context = create_hfp_connection_context();
printf("created context for address %s\n", bd_addr_to_str(bd_addr));
memcpy(context->remote_addr, bd_addr, 6);
return context;
}
@ -439,6 +440,8 @@ void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t
uint16_t rfcomm_cid, handle;
hfp_connection_t * context = NULL;
// printf("AG packet_handler type %u, packet[0] %x, size %u\n", packet_type, packet[0], size);
switch (packet[0]) {
case BTSTACK_EVENT_STATE:
// bt stack activated, get started
@ -502,8 +505,6 @@ void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t
case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE:{
bt_flip_addr(event_addr, &packet[5]);
printf("SCO Complete packet_handler type %u (HCI = %u), packet[0] %x, size %u\n", packet_type, HCI_EVENT_PACKET, packet[0], size);
int index = 2;
uint8_t status = packet[index++];
@ -529,7 +530,7 @@ void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t
switch (link_type){
case 0x00:
log_info("SCO Connection established. \n");
log_info("SCO Connection established.");
if (transmission_interval != 0) log_error("SCO Connection: transmission_interval not zero: %d.", transmission_interval);
if (retransmission_interval != 0) log_error("SCO Connection: retransmission_interval not zero: %d.", retransmission_interval);
if (rx_packet_length != 0) log_error("SCO Connection: rx_packet_length not zero: %d.", rx_packet_length);
@ -543,18 +544,18 @@ void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t
break;
}
log_info("sco_handle 0x%2x, address %s, transmission_interval %u slots, retransmission_interval %u slots, "
" rx_packet_length %u bytes, tx_packet_length %u bytes, air_mode 0x%2x (0x02 == CVSD)", sco_handle,
" rx_packet_length %u bytes, tx_packet_length %u bytes, air_mode 0x%2x (0x02 == CVSD)\n", sco_handle,
bd_addr_to_str(event_addr), transmission_interval, retransmission_interval, rx_packet_length, tx_packet_length, air_mode);
context = get_hfp_connection_context_for_bd_addr(event_addr);
if (!context) {
log_error("SCO link created, context not found.");
log_error("SCO link created, context for address %s not found.", bd_addr_to_str(event_addr));
break;
}
if (context->state == HFP_W4_CONNECTION_ESTABLISHED_TO_SHUTDOWN){
log_info("sco about to disconnect: HFP_W4_CONNECTION_ESTABLISHED_TO_SHUTDOWN");
log_info("SCO about to disconnect: HFP_W4_CONNECTION_ESTABLISHED_TO_SHUTDOWN");
context->state = HFP_W2_DISCONNECT_SCO;
break;
}

View File

@ -670,14 +670,6 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
default:
break;
}
if (done) return done;
if (context->establish_audio_connection){
context->state = HFP_W4_SCO_CONNECTED;
hci_send_cmd(&hci_setup_synchronous_connection, context->con_handle, 8000, 8000, 0xFFFF, hci_get_sco_voice_setting(), 0xFF, 0x003F);
done = 1;
return done;
}
break;
case HFP_W2_DISCONNECT_SCO:
@ -685,7 +677,7 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
gap_disconnect(context->sco_handle);
done = 1;
return done;
case HFP_AUDIO_CONNECTION_ESTABLISHED:
if (context->release_audio_connection){
context->state = HFP_W4_SCO_DISCONNECTED;
@ -699,7 +691,25 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
}
if (done) return done;
if (context->establish_audio_connection){
if (context->state < HFP_SLE_W4_EXCHANGE_COMMON_CODEC){
printf("hfp_ag_establish_audio_connection ag_trigger_codec_connection_setup");
context->ag_trigger_codec_connection_setup = 0;
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
context->suggested_codec = hfp_ag_suggest_codec(context);
hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec);
done = 1;
return done;
} else {
printf("create sco");
context->state = HFP_W4_SCO_CONNECTED;
hci_send_cmd(&hci_setup_synchronous_connection, context->con_handle, 8000, 8000, 0xFFFF, hci_get_sco_voice_setting(), 0xFF, 0x003F);
done = 1;
return done;
}
}
if (context->release_audio_connection){
context->state = HFP_W4_SCO_DISCONNECTED;
gap_disconnect(context->sco_handle);
@ -953,7 +963,7 @@ void hfp_ag_establish_audio_connection(bd_addr_t bd_addr){
hfp_ag_establish_service_level_connection(bd_addr);
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
if (!has_codec_negotiation_feature(connection)){
log_info("hfp_ag_establish_audio_connection 1 - no codec negotiation");
log_info("hfp_ag_establish_audio_connection - no codec negotiation feature");
return;
}
@ -961,9 +971,10 @@ void hfp_ag_establish_audio_connection(bd_addr_t bd_addr){
if (connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED) return;
if (connection->state >= HFP_W2_DISCONNECT_SCO) return;
log_info("hfp_ag_establish_audio_connection 2");
log_info("hfp_ag_establish_audio_connection");
connection->establish_audio_connection = 1;
if (connection->state < HFP_SLE_W4_EXCHANGE_COMMON_CODEC){
log_info("hfp_ag_establish_audio_connection ag_trigger_codec_connection_setup");
connection->command = HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP;

View File

@ -212,8 +212,9 @@ TEST(HFPClient, HFAudioConnectionEstablished){
CHECK_EQUAL(codecs_connection_established, 1);
hfp_ag_establish_audio_connection(device_addr);
CHECK_EQUAL(audio_connection_established, 1);
hfp_ag_release_audio_connection(device_addr);
CHECK_EQUAL(audio_connection_established, 1);
hfp_ag_release_audio_connection(device_addr);
CHECK_EQUAL(audio_connection_established, 0);
}

View File

@ -64,6 +64,7 @@ static uint16_t sco_handle = 10;
static uint8_t rfcomm_payload[200];
static uint16_t rfcomm_payload_len;
void * active_connection;
hfp_connection_t * hfp_context;
void (*registered_rfcomm_packet_handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
void (*registered_sdp_app_callback)(sdp_query_event_t * event, void * context);
@ -142,15 +143,14 @@ int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){
}
static void hci_event_sco_complete(){
uint8_t event[20];
uint8_t event[19];
uint8_t pos = 0;
event[pos++] = HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE;
event[pos++] = sizeof(event) - 2;
event[pos++] = 0; //status
bt_store_16(event, pos, sco_handle); pos += 2; // sco handle
bt_flip_addr(&event[pos], dev_addr); pos += 6;
printf("hci_event_sco_complete sco_handle 0x%02x, address %s\n", sco_handle, bd_addr_to_str(&event[pos-6]));
bt_flip_addr(&event[pos], dev_addr); pos += 6;
event[pos++] = 0; // link_type
event[pos++] = 0; // transmission_interval
@ -160,11 +160,11 @@ static void hci_event_sco_complete(){
bt_store_16(event, pos, 0); pos += 2; // tx_packet_length
event[pos++] = 0; // air_mode
(*registered_rfcomm_packet_handler)(0, HCI_EVENT_PACKET, 0, event, sizeof(event));
(*registered_rfcomm_packet_handler)(active_connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
}
int hci_send_cmd(const hci_cmd_t *cmd, ...){
// printf("hci_send_cmd opcode 0x%02x\n", cmd->opcode);
printf("hci_send_cmd opcode 0x%02x\n", cmd->opcode);
if (cmd->opcode == 0x428){
hci_event_sco_complete();
}
@ -203,7 +203,6 @@ void sdp_query_rfcomm_channel_and_name_for_uuid(bd_addr_t remote, uint16_t uuid)
void rfcomm_create_channel_internal(void * connection, bd_addr_t addr, uint8_t channel){
// RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE
// printf("rfcomm_create_channel_internal\n");
active_connection = connection;
uint8_t event[16];
uint8_t pos = 0;
@ -211,15 +210,16 @@ void rfcomm_create_channel_internal(void * connection, bd_addr_t addr, uint8_t c
event[pos++] = sizeof(event) - 2;
event[pos++] = 0;
bt_flip_addr(&event[pos], addr); pos += 6;
bt_flip_addr(dev_addr, addr);
bt_flip_addr(&event[pos], addr);
memcpy(dev_addr, addr, 6);
pos += 6;
bt_store_16(event, pos, 1); pos += 2;
event[pos++] = 0;
bt_store_16(event, pos, rfcomm_cid); pos += 2; // channel ID
bt_store_16(event, pos, 200); pos += 2; // max frame size
(*registered_rfcomm_packet_handler)(connection, HCI_EVENT_PACKET, 0, (uint8_t *) event, pos);
(*registered_rfcomm_packet_handler)(active_connection, HCI_EVENT_PACKET, 0, (uint8_t *) event, pos);
}
int rfcomm_can_send_packet_now(uint16_t rfcomm_cid){
@ -259,7 +259,7 @@ void hci_emit_disconnection_complete(uint16_t handle, uint8_t reason){
event[2] = 0; // status = OK
bt_store_16(event, 3, handle);
event[5] = reason;
(*registered_rfcomm_packet_handler)(0, HCI_EVENT_PACKET, 0, event, sizeof(event));
(*registered_rfcomm_packet_handler)(active_connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
}
le_command_status_t gap_disconnect(hci_con_handle_t handle){