mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-20 18:40:31 +00:00
hfp: renamed connect and disconnect functions
This commit is contained in:
parent
8e5b880140
commit
eeb00e0651
56
src/hfp.c
56
src/hfp.c
@ -121,6 +121,33 @@ int send_str_over_rfcomm(uint16_t cid, char * command){
|
||||
return err;
|
||||
}
|
||||
|
||||
void hfp_set_codec(hfp_connection_t * context, uint8_t *packet, uint16_t size){
|
||||
// parse available codecs
|
||||
int pos = 0;
|
||||
int i;
|
||||
for (i=0; i<size; i++){
|
||||
pos+=8;
|
||||
if (packet[pos] > context->negotiated_codec){
|
||||
context->negotiated_codec = packet[pos];
|
||||
}
|
||||
}
|
||||
printf("Negotiated Codec 0x%02x\n", context->negotiated_codec);
|
||||
}
|
||||
|
||||
// UTILS
|
||||
int get_bit(uint16_t bitmap, int position){
|
||||
return (bitmap >> position) & 1;
|
||||
}
|
||||
|
||||
int store_bit(uint32_t bitmap, int position, uint8_t value){
|
||||
if (value){
|
||||
bitmap |= 1 << position;
|
||||
} else {
|
||||
bitmap &= ~ (1 << position);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
int join(char * buffer, int buffer_size, uint8_t * values, int values_nr){
|
||||
if (buffer_size < values_nr * 3) return 0;
|
||||
int i;
|
||||
@ -558,7 +585,7 @@ void hfp_init(uint16_t rfcomm_channel_nr){
|
||||
sdp_query_rfcomm_register_callback(handle_query_rfcomm_event, NULL);
|
||||
}
|
||||
|
||||
void hfp_connect(bd_addr_t bd_addr, uint16_t service_uuid){
|
||||
void hfp_establish_service_level_connection(bd_addr_t bd_addr, uint16_t service_uuid){
|
||||
hfp_connection_t * context = provide_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
log_info("hfp_connect %s, context %p", bd_addr_to_str(bd_addr), context);
|
||||
|
||||
@ -575,7 +602,7 @@ void hfp_connect(bd_addr_t bd_addr, uint16_t service_uuid){
|
||||
sdp_query_rfcomm_channel_and_name_for_uuid(context->remote_addr, service_uuid);
|
||||
}
|
||||
|
||||
hfp_connection_t * hfp_disconnect(bd_addr_t bd_addr){
|
||||
hfp_connection_t * hfp_release_service_level_connection(bd_addr_t bd_addr){
|
||||
hfp_connection_t * context = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
if (!context) {
|
||||
log_error("hfp_disconnect for addr %s failed", bd_addr_to_str(bd_addr));
|
||||
@ -595,29 +622,4 @@ hfp_connection_t * hfp_disconnect(bd_addr_t bd_addr){
|
||||
return context;
|
||||
}
|
||||
|
||||
void hfp_set_codec(hfp_connection_t * context, uint8_t *packet, uint16_t size){
|
||||
// parse available codecs
|
||||
int pos = 0;
|
||||
int i;
|
||||
for (i=0; i<size; i++){
|
||||
pos+=8;
|
||||
if (packet[pos] > context->negotiated_codec){
|
||||
context->negotiated_codec = packet[pos];
|
||||
}
|
||||
}
|
||||
printf("Negotiated Codec 0x%02x\n", context->negotiated_codec);
|
||||
}
|
||||
|
||||
// UTILS
|
||||
int get_bit(uint16_t bitmap, int position){
|
||||
return (bitmap >> position) & 1;
|
||||
}
|
||||
|
||||
int store_bit(uint32_t bitmap, int position, uint8_t value){
|
||||
if (value){
|
||||
bitmap |= 1 << position;
|
||||
} else {
|
||||
bitmap &= ~ (1 << position);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
29
src/hfp.h
29
src/hfp.h
@ -217,25 +217,24 @@ typedef struct hfp_connection {
|
||||
|
||||
} hfp_connection_t;
|
||||
|
||||
|
||||
void hfp_create_service(uint8_t * service, uint16_t service_uuid, int rfcomm_channel_nr, const char * name, uint16_t supported_features);
|
||||
void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
void hfp_emit_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t value);
|
||||
|
||||
void hfp_init(uint16_t rfcomm_channel_nr);
|
||||
|
||||
void hfp_connect(bd_addr_t bd_addr, uint16_t service_uuid);
|
||||
hfp_connection_t * hfp_disconnect(bd_addr_t bd_addr);
|
||||
|
||||
hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid);
|
||||
linked_list_t * hfp_get_connections();
|
||||
void hfp_parse(hfp_connection_t * context, uint8_t byte);
|
||||
|
||||
// TODO: move to utils
|
||||
// UTILS_START : TODO move to utils
|
||||
int send_str_over_rfcomm(uint16_t cid, char * command);
|
||||
int join(char * buffer, int buffer_size, uint8_t * values, int values_nr);
|
||||
int get_bit(uint16_t bitmap, int position);
|
||||
int store_bit(uint32_t bitmap, int position, uint8_t value);
|
||||
// UTILS_END
|
||||
|
||||
void hfp_create_service(uint8_t * service, uint16_t service_uuid, int rfcomm_channel_nr, const char * name, uint16_t supported_features);
|
||||
void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
void hfp_emit_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t value);
|
||||
hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid);
|
||||
linked_list_t * hfp_get_connections();
|
||||
void hfp_parse(hfp_connection_t * context, uint8_t byte);
|
||||
|
||||
void hfp_init(uint16_t rfcomm_channel_nr);
|
||||
void hfp_establish_service_level_connection(bd_addr_t bd_addr, uint16_t service_uuid);
|
||||
hfp_connection_t * hfp_release_service_level_connection(bd_addr_t bd_addr);
|
||||
|
||||
|
||||
const char * hfp_hf_feature(int index);
|
||||
const char * hfp_ag_feature(int index);
|
||||
|
@ -496,12 +496,12 @@ void hfp_ag_init(uint16_t rfcomm_channel_nr, uint32_t supported_features,
|
||||
memcpy(hfp_ag_call_hold_services, call_hold_services, call_hold_services_nr * sizeof(char *));
|
||||
}
|
||||
|
||||
void hfp_ag_connect(bd_addr_t bd_addr){
|
||||
hfp_connect(bd_addr, SDP_Handsfree);
|
||||
void hfp_ag_establish_service_level_connection(bd_addr_t bd_addr){
|
||||
hfp_establish_service_level_connection(bd_addr, SDP_Handsfree);
|
||||
}
|
||||
|
||||
void hfp_ag_disconnect(bd_addr_t bd_addr){
|
||||
hfp_connection_t * connection = hfp_disconnect(bd_addr);
|
||||
void hfp_ag_release_service_level_connection(bd_addr_t bd_addr){
|
||||
hfp_connection_t * connection = hfp_release_service_level_connection(bd_addr);
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,8 @@ void hfp_ag_init(uint16_t rfcomm_channel_nr, uint32_t supported_features,
|
||||
char *call_hold_services[], int call_hold_services_nr);
|
||||
void hfp_ag_register_packet_handler(hfp_callback_t callback);
|
||||
|
||||
void hfp_ag_connect(bd_addr_t bd_addr);
|
||||
void hfp_ag_disconnect(bd_addr_t bd_addr);
|
||||
void hfp_ag_establish_service_level_connection(bd_addr_t bd_addr);
|
||||
void hfp_ag_release_service_level_connection(bd_addr_t bd_addr);
|
||||
|
||||
void hfp_ag_supported_features_exchange(uint16_t supported_features);
|
||||
|
||||
|
@ -416,11 +416,11 @@ void hfp_hf_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, uint8_
|
||||
}
|
||||
}
|
||||
|
||||
void hfp_hf_connect(bd_addr_t bd_addr){
|
||||
hfp_connect(bd_addr, SDP_HandsfreeAudioGateway);
|
||||
void hfp_hf_establish_service_level_connection(bd_addr_t bd_addr){
|
||||
hfp_establish_service_level_connection(bd_addr, SDP_HandsfreeAudioGateway);
|
||||
}
|
||||
|
||||
void hfp_hf_disconnect(bd_addr_t bd_addr){
|
||||
hfp_connection_t * connection = hfp_disconnect(bd_addr);
|
||||
void hfp_hf_release_service_level_connection(bd_addr_t bd_addr){
|
||||
hfp_connection_t * connection = hfp_release_service_level_connection(bd_addr);
|
||||
hfp_run_for_context(connection);
|
||||
}
|
@ -56,8 +56,10 @@ 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, uint32_t indicators_status);
|
||||
void hfp_hf_register_packet_handler(hfp_callback_t callback);
|
||||
void hfp_hf_connect(bd_addr_t bd_addr);
|
||||
void hfp_hf_disconnect(bd_addr_t bd_addr);
|
||||
|
||||
void hfp_hf_establish_service_level_connection(bd_addr_t bd_addr);
|
||||
void hfp_hf_release_service_level_connection(bd_addr_t bd_addr);
|
||||
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
|
@ -116,16 +116,16 @@ static int stdin_process(struct data_source *ds){
|
||||
read(ds->fd, &buffer, 1);
|
||||
switch (buffer){
|
||||
case 'p':
|
||||
printf("Establishing HFP connection to PTS module %s...\n", bd_addr_to_str(pts_addr));
|
||||
hfp_ag_connect(pts_addr);
|
||||
printf("Establishing HFP service level connection to PTS module %s...\n", bd_addr_to_str(pts_addr));
|
||||
hfp_ag_establish_service_level_connection(pts_addr);
|
||||
break;
|
||||
case 'e':
|
||||
printf("Establishing HFP connection to %s...\n", bd_addr_to_str(speaker));
|
||||
hfp_ag_connect(speaker);
|
||||
printf("Establishing HFP service level connection to %s...\n", bd_addr_to_str(speaker));
|
||||
hfp_ag_establish_service_level_connection(speaker);
|
||||
break;
|
||||
case 'd':
|
||||
printf("Releasing HFP connection.\n");
|
||||
hfp_ag_disconnect(speaker);
|
||||
printf("Releasing HFP service level connection.\n");
|
||||
hfp_ag_release_service_level_connection(speaker);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
@ -183,7 +183,5 @@ int btstack_main(int argc, const char * argv[]){
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
btstack_stdin_setup(stdin_process);
|
||||
printf("Establishing HFP connection to %s...\n", bd_addr_to_str(speaker));
|
||||
hfp_ag_connect(speaker);
|
||||
return 0;
|
||||
}
|
||||
|
@ -99,16 +99,16 @@ static int stdin_process(struct data_source *ds){
|
||||
read(ds->fd, &buffer, 1);
|
||||
switch (buffer){
|
||||
case 'p':
|
||||
printf("Establishing HFP connection to PTS module %s...\n", bd_addr_to_str(pts_addr));
|
||||
hfp_hf_connect(pts_addr);
|
||||
printf("Establishing HFP service level connection to PTS module %s...\n", bd_addr_to_str(pts_addr));
|
||||
hfp_hf_establish_service_level_connection(pts_addr);
|
||||
break;
|
||||
case 'e':
|
||||
printf("Establishing HFP connection to %s...\n", bd_addr_to_str(phone));
|
||||
hfp_hf_connect(phone);
|
||||
printf("Establishing HFP service level connection to %s...\n", bd_addr_to_str(phone));
|
||||
hfp_hf_establish_service_level_connection(phone);
|
||||
break;
|
||||
case 'd':
|
||||
printf("Releasing HFP connection.\n");
|
||||
hfp_hf_disconnect(phone);
|
||||
printf("Releasing HFP service level connection.\n");
|
||||
hfp_hf_release_service_level_connection(phone);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
|
Loading…
x
Reference in New Issue
Block a user