mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-17 11:42:34 +00:00
hfp cleanup: remove clip_type and clip_number from ag
This commit is contained in:
parent
e29731ecdb
commit
60b37999d9
@ -281,7 +281,8 @@ typedef enum {
|
||||
HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL,
|
||||
HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL,
|
||||
HFP_AG_CALL_HOLD_ADD_HELD_CALL,
|
||||
HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS
|
||||
HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS,
|
||||
HFP_AG_SET_CLIP
|
||||
} hfp_ag_call_event_t;
|
||||
|
||||
|
||||
|
43
src/hfp_ag.c
43
src/hfp_ag.c
@ -79,10 +79,6 @@ static hfp_callback_t hfp_callback;
|
||||
static hfp_response_and_hold_state_t hfp_ag_response_and_hold_state;
|
||||
static int hfp_ag_response_and_hold_active = 0;
|
||||
|
||||
// CLIP feature
|
||||
static uint8_t clip_type; // 0 == not set
|
||||
static char clip_number[25]; //
|
||||
|
||||
// Subcriber information entries
|
||||
static hfp_phone_number_t * subscriber_numbers = NULL;
|
||||
static int subscriber_numbers_count = 0;
|
||||
@ -212,11 +208,8 @@ static int hfp_ag_ring(uint16_t cid){
|
||||
}
|
||||
|
||||
static int hfp_ag_send_clip(uint16_t cid){
|
||||
if (!clip_type){
|
||||
clip_number[0] = 0;
|
||||
}
|
||||
char buffer[50];
|
||||
sprintf(buffer, "\r\n%s: \"%s\",%u\r\n", HFP_ENABLE_CLIP, clip_number, clip_type);
|
||||
sprintf(buffer, "\r\n%s: \"%s\",%u\r\n", HFP_ENABLE_CLIP, hfp_gsm_clip_number(), hfp_gsm_clip_type());
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
@ -228,16 +221,13 @@ static int hfp_send_subscriber_number_cmd(uint16_t cid, uint8_t type, const char
|
||||
|
||||
static int hfp_ag_send_phone_number_for_voice_tag_cmd(uint16_t cid){
|
||||
char buffer[50];
|
||||
sprintf(buffer, "\r\n%s: %s\r\n", HFP_PHONE_NUMBER_FOR_VOICE_TAG, clip_number);
|
||||
sprintf(buffer, "\r\n%s: %s\r\n", HFP_PHONE_NUMBER_FOR_VOICE_TAG, hfp_gsm_clip_number());
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
static int hfp_ag_send_call_waiting_notification(uint16_t cid){
|
||||
if (!clip_type){
|
||||
clip_number[0] = 0;
|
||||
}
|
||||
char buffer[50];
|
||||
sprintf(buffer, "\r\n+CCWA: \"%s\",%u\r\n", clip_number, clip_type);
|
||||
sprintf(buffer, "\r\n+CCWA: \"%s\",%u\r\n", hfp_gsm_clip_number(), hfp_gsm_clip_type());
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
@ -829,7 +819,7 @@ static void hfp_timeout_handler(timer_source_t * timer){
|
||||
|
||||
log_info("HFP start ring timeout, con handle 0x%02x", context->con_handle);
|
||||
context->ag_ring = 1;
|
||||
context->ag_send_clip = clip_type && context->clip_enabled;
|
||||
context->ag_send_clip = hfp_gsm_clip_type() && context->clip_enabled;
|
||||
|
||||
run_loop_set_timer(&context->hfp_timeout, 2000); // 5 seconds timeout
|
||||
run_loop_add_timer(&context->hfp_timeout);
|
||||
@ -860,7 +850,7 @@ static void hfp_ag_hf_start_ringing(hfp_connection_t * context){
|
||||
} else {
|
||||
hfp_timeout_start(context);
|
||||
context->ag_ring = 1;
|
||||
context->ag_send_clip = clip_type && context->clip_enabled;
|
||||
context->ag_send_clip = hfp_gsm_clip_type() && context->clip_enabled;
|
||||
context->call_state = HFP_CALL_RINGING;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_START_RINGINIG, 0);
|
||||
}
|
||||
@ -1084,7 +1074,7 @@ static int call_setup_state_machine(hfp_connection_t * connection){
|
||||
// we got event: audio connection established
|
||||
hfp_timeout_start(connection);
|
||||
connection->ag_ring = 1;
|
||||
connection->ag_send_clip = clip_type && connection->clip_enabled;
|
||||
connection->ag_send_clip = hfp_gsm_clip_type() && connection->clip_enabled;
|
||||
connection->call_state = HFP_CALL_RINGING;
|
||||
connection->call_state = HFP_CALL_RINGING;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_START_RINGINIG, 0);
|
||||
@ -1143,8 +1133,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
|
||||
}
|
||||
break;
|
||||
case HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG:
|
||||
// clear CLIP
|
||||
clip_type = 0;
|
||||
switch (hfp_gsm_call_status()){
|
||||
case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
|
||||
switch (hfp_gsm_callsetup_status()){
|
||||
@ -1197,8 +1185,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
|
||||
break;
|
||||
|
||||
case HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF:
|
||||
// clear CLIP
|
||||
clip_type = 0;
|
||||
switch (hfp_gsm_call_status()){
|
||||
case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
|
||||
switch (hfp_gsm_callsetup_status()){
|
||||
@ -1220,8 +1206,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
|
||||
break;
|
||||
|
||||
case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG:
|
||||
// clear CLIP
|
||||
clip_type = 0;
|
||||
switch (hfp_gsm_call_status()){
|
||||
case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
|
||||
switch (hfp_gsm_callsetup_status()){
|
||||
@ -1246,8 +1230,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
|
||||
break;
|
||||
|
||||
case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF:
|
||||
// clear CLIP
|
||||
clip_type = 0;
|
||||
switch (hfp_gsm_call_status()){
|
||||
case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
|
||||
switch (hfp_gsm_callsetup_status()){
|
||||
@ -1296,8 +1278,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
|
||||
break;
|
||||
|
||||
case HFP_AG_TERMINATE_CALL_BY_HF:
|
||||
// clear CLIP
|
||||
clip_type = 0;
|
||||
switch (hfp_gsm_call_status()){
|
||||
case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
|
||||
switch (hfp_gsm_callsetup_status()){
|
||||
@ -1329,8 +1309,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
|
||||
break;
|
||||
|
||||
case HFP_AG_TERMINATE_CALL_BY_AG:
|
||||
// clear CLIP
|
||||
clip_type = 0;
|
||||
switch (hfp_gsm_call_status()){
|
||||
case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
|
||||
switch (hfp_gsm_callsetup_status()){
|
||||
@ -1355,8 +1333,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
|
||||
}
|
||||
break;
|
||||
case HFP_AG_CALL_DROPPED:
|
||||
// clear CLIP
|
||||
clip_type = 0;
|
||||
switch (hfp_gsm_call_status()){
|
||||
case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS:
|
||||
switch (hfp_gsm_callsetup_status()){
|
||||
@ -1988,8 +1964,6 @@ 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 *));
|
||||
|
||||
hfp_ag_response_and_hold_active = 0;
|
||||
clip_type = 0; // 0 == not set
|
||||
memset(clip_number,0,sizeof(clip_number));
|
||||
subscriber_numbers = NULL;
|
||||
subscriber_numbers_count = 0;
|
||||
|
||||
@ -2087,10 +2061,7 @@ void hfp_ag_incoming_call(void){
|
||||
* @brief number is stored.
|
||||
*/
|
||||
void hfp_ag_set_clip(uint8_t type, const char * number){
|
||||
clip_type = type;
|
||||
// copy and terminate
|
||||
strncpy(clip_number, number, sizeof(clip_number));
|
||||
clip_number[sizeof(clip_number)-1] = '\0';
|
||||
hfp_gsm_handle_event_with_clip(HFP_AG_SET_CLIP, type, number);
|
||||
}
|
||||
|
||||
void hfp_ag_call_dropped(void){
|
||||
|
@ -81,15 +81,22 @@ typedef struct {
|
||||
|
||||
static hfp_gsm_call_t gsm_calls[HFP_GSM_MAX_NR_CALLS];
|
||||
static hfp_callsetup_status_t callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
|
||||
static uint8_t call_index = 0;
|
||||
|
||||
static uint8_t clip_type;
|
||||
static char clip_number[25];
|
||||
|
||||
static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number);
|
||||
|
||||
void hfp_gsm_init(void){
|
||||
callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
|
||||
clip_type = 0;
|
||||
memset(clip_number, 0, sizeof(clip_number));
|
||||
|
||||
memset(gsm_calls, 0, sizeof(gsm_calls));
|
||||
int i;
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
gsm_calls[i].status = CALL_NONE;
|
||||
}
|
||||
callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int get_number_calls_with_status(hfp_gsm_call_status_t status){
|
||||
@ -136,10 +143,6 @@ static inline int get_number_active_calls(){
|
||||
return get_number_calls_with_status(CALL_ACTIVE);
|
||||
}
|
||||
|
||||
static inline int get_number_initiated_calls(){
|
||||
return get_number_calls_with_status(CALL_INITIATED);
|
||||
}
|
||||
|
||||
static inline int get_number_held_calls(){
|
||||
return get_number_calls_with_status(CALL_HELD);
|
||||
}
|
||||
@ -152,6 +155,14 @@ static int next_call_index(){
|
||||
return HFP_GSM_MAX_NR_CALLS + 1 - get_number_none_calls();
|
||||
}
|
||||
|
||||
static void hfp_gsm_set_clip(int index_in_table, uint8_t type, const char * number){
|
||||
gsm_calls[index_in_table].clip_type = type;
|
||||
|
||||
int clip_number_size = sizeof(gsm_calls[index_in_table].clip_number);
|
||||
strncpy(gsm_calls[index_in_table].clip_number, number, clip_number_size);
|
||||
gsm_calls[index_in_table].clip_number[clip_number_size-1] = '\0';
|
||||
}
|
||||
|
||||
static void delete_call(int delete_index_in_table){
|
||||
int i ;
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
@ -172,6 +183,51 @@ static void create_call(){
|
||||
gsm_calls[next_free_slot].status = CALL_INITIATED;
|
||||
gsm_calls[next_free_slot].clip_type = 0;
|
||||
gsm_calls[next_free_slot].clip_number[0] = '\0';
|
||||
|
||||
if (clip_type != 0){
|
||||
hfp_gsm_set_clip(next_free_slot, clip_type, clip_number);
|
||||
clip_type = 0;
|
||||
memset(clip_number, 0, sizeof(clip_number));
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t hfp_gsm_clip_type(){
|
||||
if (clip_type != 0) return clip_type;
|
||||
|
||||
int initiated_call_index = get_initiated_call_index();
|
||||
if (initiated_call_index != -1){
|
||||
if (gsm_calls[initiated_call_index].clip_type != 0) {
|
||||
return gsm_calls[initiated_call_index].clip_type;
|
||||
}
|
||||
}
|
||||
|
||||
int active_call_index = get_active_call_index();
|
||||
if (active_call_index != -1){
|
||||
if (gsm_calls[active_call_index].clip_type != 0) {
|
||||
return gsm_calls[active_call_index].clip_type;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char * hfp_gsm_clip_number(){
|
||||
if (clip_type != 0) return clip_number;
|
||||
|
||||
int initiated_call_index = get_initiated_call_index();
|
||||
if (initiated_call_index != -1){
|
||||
if (gsm_calls[initiated_call_index].clip_type != 0) {
|
||||
return gsm_calls[initiated_call_index].clip_number;
|
||||
}
|
||||
}
|
||||
|
||||
int active_call_index = get_active_call_index();
|
||||
if (active_call_index != -1){
|
||||
if (gsm_calls[active_call_index].clip_type != 0) {
|
||||
return gsm_calls[active_call_index].clip_number;
|
||||
}
|
||||
}
|
||||
clip_number[0] = 0;
|
||||
return clip_number;
|
||||
}
|
||||
|
||||
hfp_call_status_t hfp_gsm_call_status(){
|
||||
@ -205,15 +261,24 @@ int hfp_gsm_call_possible(void){
|
||||
}
|
||||
|
||||
void hfp_gsm_handle_event(hfp_ag_call_event_t event){
|
||||
hfp_gsm_handle_event_with_call_index(event, 0);
|
||||
hfp_gsm_handler(event, 0, 0, NULL);
|
||||
}
|
||||
|
||||
void hfp_gsm_handle_event_with_clip(hfp_ag_call_event_t event, uint8_t type, const char * number){
|
||||
hfp_gsm_handler(event, 0, type, number);
|
||||
}
|
||||
|
||||
void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t index){
|
||||
hfp_gsm_handler(event, index, 0, NULL);
|
||||
}
|
||||
|
||||
static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number){
|
||||
int next_free_slot = get_next_free_slot();
|
||||
int current_call_index = get_active_call_index();
|
||||
int initiated_call_index = get_initiated_call_index();
|
||||
int held_call_index = get_held_call_index();
|
||||
|
||||
int i;
|
||||
|
||||
switch (event){
|
||||
case HFP_AG_OUTGOING_CALL_INITIATED:
|
||||
case HFP_AG_OUTGOING_REDIAL_INITIATED:
|
||||
@ -342,16 +407,15 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind
|
||||
}
|
||||
break;
|
||||
|
||||
case HFP_AG_CALL_DROPPED:{
|
||||
callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
|
||||
if (hfp_gsm_call_status() != HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT) break;
|
||||
|
||||
int i ;
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
delete_call(i);
|
||||
}
|
||||
case HFP_AG_CALL_DROPPED:
|
||||
callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
|
||||
if (hfp_gsm_call_status() != HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT) break;
|
||||
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
delete_call(i);
|
||||
}
|
||||
break;
|
||||
|
||||
case HFP_AG_CALL_HOLD_USER_BUSY:
|
||||
// Held or waiting call gets active,
|
||||
callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
|
||||
@ -359,8 +423,7 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind
|
||||
gsm_calls[held_call_index].status = CALL_ACTIVE;
|
||||
break;
|
||||
|
||||
case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:{
|
||||
int i ;
|
||||
case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
|
||||
if (index != 0 && index <= HFP_GSM_MAX_NR_CALLS ){
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
if (gsm_calls[i].index == index){
|
||||
@ -384,10 +447,8 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind
|
||||
|
||||
callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
|
||||
break;
|
||||
}
|
||||
|
||||
case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:{
|
||||
int i ;
|
||||
case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
if (gsm_calls[i].status == CALL_ACTIVE && gsm_calls[i].index != index){
|
||||
gsm_calls[i].clip_type = 0;
|
||||
@ -403,11 +464,9 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind
|
||||
}
|
||||
callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
|
||||
break;
|
||||
}
|
||||
|
||||
case HFP_AG_CALL_HOLD_ADD_HELD_CALL:{
|
||||
|
||||
case HFP_AG_CALL_HOLD_ADD_HELD_CALL:
|
||||
if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){
|
||||
int i ;
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
if (gsm_calls[i].status == CALL_HELD){
|
||||
gsm_calls[i].clip_type = 0;
|
||||
@ -417,18 +476,28 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind
|
||||
}
|
||||
}
|
||||
gsm_calls[initiated_call_index].status = CALL_ACTIVE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS:{
|
||||
int i ;
|
||||
case HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS:
|
||||
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
|
||||
delete_call(i);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case HFP_AG_SET_CLIP:
|
||||
if (initiated_call_index != -1){
|
||||
hfp_gsm_set_clip(initiated_call_index, type, number);
|
||||
break;
|
||||
}
|
||||
if (current_call_index != -1){
|
||||
hfp_gsm_set_clip(current_call_index, type, number);
|
||||
break;
|
||||
}
|
||||
clip_type = type;
|
||||
strncpy(clip_number, number, sizeof(clip_number));
|
||||
clip_number[sizeof(clip_number)-1] = '\0';
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -65,8 +65,12 @@ hfp_callsetup_status_t hfp_gsm_callsetup_status();
|
||||
|
||||
int hfp_gsm_call_possible(void);
|
||||
|
||||
uint8_t hfp_gsm_clip_type();
|
||||
char * hfp_gsm_clip_number();
|
||||
|
||||
void hfp_gsm_init(void);
|
||||
|
||||
void hfp_gsm_handle_event_with_clip(hfp_ag_call_event_t event, uint8_t type, const char * number);
|
||||
void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t index);
|
||||
void hfp_gsm_handle_event(hfp_ag_call_event_t event);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user