From 5e76b1a0c8972e0ac85ac431b1cbafa6937ba7dd Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 14 Jan 2016 17:11:40 +0100 Subject: [PATCH 1/6] hfp cleanup --- src/hfp_ag.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/hfp_ag.c b/src/hfp_ag.c index eaae04444..8378187b0 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -94,10 +94,6 @@ static void hfp_run_for_context(hfp_connection_t *context); static void hfp_ag_setup_audio_connection(hfp_connection_t * connection); static void hfp_ag_hf_start_ringing(hfp_connection_t * context); -static hfp_call_status_t get_hfp_ag_call_state(void){ - return hfp_gsm_call_status(); -} - static hfp_callsetup_status_t get_hfp_ag_callsetup_state(void){ return hfp_ag_callsetup_state; //return hfp_gsm_callsetup_status(); @@ -638,11 +634,11 @@ static void hfp_ag_slc_established(hfp_connection_t * context){ hfp_init_link_settings(context); // if active call exist, set per-connection state active, too (when audio is on) - if (get_hfp_ag_call_state() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ + if (hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ context->call_state = HFP_CALL_W4_AUDIO_CONNECTION_FOR_ACTIVE; } // if AG is ringing, also start ringing on the HF - if (get_hfp_ag_call_state() == HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS && + if (hfp_gsm_call_status() == HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS && get_hfp_ag_callsetup_state() == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){ hfp_ag_hf_start_ringing(context); } @@ -1141,7 +1137,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect //printf("hfp_ag_call_sm event %d \n", event); switch (event){ case HFP_AG_INCOMING_CALL: - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: switch (get_hfp_ag_callsetup_state()){ case HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS: @@ -1171,7 +1167,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG: // clear CLIP clip_type = 0; - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: switch (get_hfp_ag_callsetup_state()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: @@ -1203,7 +1199,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect break; case HFP_AG_HELD_CALL_JOINED_BY_AG: - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: switch (get_hfp_ag_callheld_state()){ case HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED: @@ -1225,7 +1221,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF: // clear CLIP clip_type = 0; - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: switch (get_hfp_ag_callsetup_state()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: @@ -1248,7 +1244,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG: // clear CLIP clip_type = 0; - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: switch (get_hfp_ag_callsetup_state()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: @@ -1274,7 +1270,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF: // clear CLIP clip_type = 0; - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: switch (get_hfp_ag_callsetup_state()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: @@ -1324,7 +1320,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_TERMINATE_CALL_BY_HF: // clear CLIP clip_type = 0; - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: switch (get_hfp_ag_callsetup_state()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: @@ -1357,7 +1353,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_TERMINATE_CALL_BY_AG: // clear CLIP clip_type = 0; - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: switch (get_hfp_ag_callsetup_state()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: @@ -1383,7 +1379,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_CALL_DROPPED: // clear CLIP clip_type = 0; - switch (get_hfp_ag_call_state()){ + switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: switch (get_hfp_ag_callsetup_state()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: @@ -1470,7 +1466,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect connection->call_state = HFP_CALL_OUTGOING_DIALING; // trigger callsetup to be - int put_call_on_hold = get_hfp_ag_call_state() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT; + int put_call_on_hold = hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT; hfp_gsm_handle_event(HFP_AG_OUTGOING_CALL_ACCEPTED); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE); From 7e36ba55d81e18ad7ae768717901b5bc7cedd424 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 14 Jan 2016 17:14:42 +0100 Subject: [PATCH 2/6] hfp cleanup --- src/hfp_ag.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/hfp_ag.c b/src/hfp_ag.c index 8378187b0..62588cc0c 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -94,16 +94,6 @@ static void hfp_run_for_context(hfp_connection_t *context); static void hfp_ag_setup_audio_connection(hfp_connection_t * connection); static void hfp_ag_hf_start_ringing(hfp_connection_t * context); -static hfp_callsetup_status_t get_hfp_ag_callsetup_state(void){ - return hfp_ag_callsetup_state; - //return hfp_gsm_callsetup_status(); -} - -static hfp_callheld_status_t get_hfp_ag_callheld_state(void){ - return hfp_ag_callheld_state; - // return hfp_gsm_callheld_status(); -} - hfp_generic_status_indicator_t * get_hfp_generic_status_indicators(); int get_hfp_generic_status_indicators_nr(); void set_hfp_generic_status_indicators(hfp_generic_status_indicator_t * indicators, int indicator_nr); @@ -639,7 +629,7 @@ static void hfp_ag_slc_established(hfp_connection_t * context){ } // if AG is ringing, also start ringing on the HF if (hfp_gsm_call_status() == HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS && - get_hfp_ag_callsetup_state() == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){ + hfp_gsm_callsetup_status() == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){ hfp_ag_hf_start_ringing(context); } } @@ -1139,7 +1129,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_INCOMING_CALL: switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_INCOMING_CALL); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS); @@ -1151,7 +1141,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect } break; case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_INCOMING_CALL); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS); @@ -1169,7 +1159,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect clip_type = 0; switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG); hfp_ag_set_call_indicator(); @@ -1182,7 +1172,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect } break; case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: printf("AG: current call is placed on hold, incoming call gets active\n"); hfp_gsm_handle_event(HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG); @@ -1201,7 +1191,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_HELD_CALL_JOINED_BY_AG: switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: - switch (get_hfp_ag_callheld_state()){ + switch (hfp_gsm_callheld_status()){ case HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED: printf("AG: joining held call with active call\n"); hfp_gsm_handle_event(HFP_AG_HELD_CALL_JOINED_BY_AG); @@ -1223,7 +1213,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect clip_type = 0; switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); @@ -1246,7 +1236,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect clip_type = 0; switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG); hfp_ag_response_and_hold_active = 1; @@ -1272,7 +1262,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect clip_type = 0; switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF); hfp_ag_response_and_hold_active = 1; @@ -1322,7 +1312,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect clip_type = 0; switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_TERMINATE_CALL_BY_HF); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); @@ -1355,7 +1345,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect clip_type = 0; switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_TERMINATE_CALL_BY_AG); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); @@ -1381,7 +1371,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect clip_type = 0; switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - switch (get_hfp_ag_callsetup_state()){ + switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_ag_stop_ringing(); printf("Incoming call interrupted\n"); @@ -1510,7 +1500,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect break; } - int CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS = get_hfp_ag_callheld_state() == HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS; + int CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS = hfp_gsm_callheld_status() == HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS; hfp_gsm_handle_event(HFP_AG_OUTGOING_CALL_ESTABLISHED); connection->call_state = HFP_CALL_ACTIVE; hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); @@ -1533,8 +1523,8 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect break; case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:{ - int call_setup_in_progress = get_hfp_ag_callsetup_state() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - int call_held = get_hfp_ag_callheld_state() != HFP_CALLHELD_STATUS_NO_CALLS_HELD; + int call_setup_in_progress = hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + int call_held = hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD; // Releases all active calls (if any exist) and accepts the other (held or waiting) call. if (call_setup_in_progress){ @@ -1555,7 +1545,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect break; } case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:{ - int call_setup_in_progress = get_hfp_ag_callsetup_state() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + int call_setup_in_progress = hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; // Places all active calls (if any exist) on hold and accepts the other (held or waiting) call. // only update if callsetup changed if (call_setup_in_progress){ @@ -1573,7 +1563,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect } case HFP_AG_CALL_HOLD_ADD_HELD_CALL: // Adds a held call to the conversation. - if (get_hfp_ag_callheld_state() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){ + if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){ printf("AG: Join 3-way-call\n"); hfp_gsm_handle_event(HFP_AG_CALL_HOLD_ADD_HELD_CALL); hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_NO_CALLS_HELD); From 26f0fa9d417c5228ef92f1077ae5d57e44e074ce Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 15 Jan 2016 12:29:10 +0100 Subject: [PATCH 3/6] hfp cleanup: remove callheld state --- src/hfp.h | 1 + src/hfp_ag.c | 90 +++++++++++++++++++++++++------------ src/hfp_gsm_model.c | 106 ++++++++++++++++++++++++++++++++++---------- src/hfp_gsm_model.h | 1 + 4 files changed, 146 insertions(+), 52 deletions(-) diff --git a/src/hfp.h b/src/hfp.h index 47f9d9af5..953c327c6 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -599,6 +599,7 @@ typedef struct hfp_connection { uint8_t clcc_mode; uint8_t clcc_mpty; + uint8_t call_index; // also used for CLCC if set uint8_t bnip_type; // 0 == not set char bnip_number[25]; // diff --git a/src/hfp_ag.c b/src/hfp_ag.c index 62588cc0c..c5e6152eb 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -77,7 +77,6 @@ static char *hfp_ag_call_hold_services[6]; static hfp_callback_t hfp_callback; static hfp_callsetup_status_t hfp_ag_callsetup_state; -static hfp_callheld_status_t hfp_ag_callheld_state; static hfp_response_and_hold_state_t hfp_ag_response_and_hold_state; static int hfp_ag_response_and_hold_active = 0; @@ -1033,15 +1032,6 @@ static void hfp_ag_set_callsetup_state(hfp_callsetup_status_t state){ indicator->status = state; } -static void hfp_ag_set_callheld_state(hfp_callheld_status_t state){ - hfp_ag_callheld_state = state; - hfp_ag_indicator_t * indicator = get_ag_indicator_for_name("callheld"); - if (!indicator){ - log_error("hfp_ag_set_callheld_state: callheld indicator is missing"); - }; - indicator->status = state; -} - static void hfp_ag_set_callheld_indicator(){ hfp_ag_indicator_t * indicator = get_ag_indicator_for_name("callheld"); if (!indicator){ @@ -1177,7 +1167,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect printf("AG: current call is placed on hold, incoming call gets active\n"); hfp_gsm_handle_event(HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); - hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED); + hfp_ag_set_callheld_indicator(); hfp_ag_transfer_callsetup_state(); hfp_ag_transfer_callheld_state(); break; @@ -1195,7 +1185,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED: printf("AG: joining held call with active call\n"); hfp_gsm_handle_event(HFP_AG_HELD_CALL_JOINED_BY_AG); - hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_NO_CALLS_HELD); + hfp_ag_set_callheld_indicator(); hfp_ag_transfer_callheld_state(); hfp_emit_event(hfp_callback, HFP_SUBEVENT_CONFERENCE_CALL, 0); break; @@ -1466,7 +1456,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect // put current call on hold if active if (put_call_on_hold){ printf("AG putting current call on hold for new outgoing call\n"); - hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS); + hfp_ag_set_callheld_indicator(); indicator_index = get_ag_indicator_index_for_name("callheld"); hfp_ag_transfer_ag_indicators_status_cmd(connection->rfcomm_cid, &hfp_ag_indicators[indicator_index]); } @@ -1508,7 +1498,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect hfp_ag_transfer_call_state(); hfp_ag_transfer_callsetup_state(); if (CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS){ - hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED); + hfp_ag_set_callheld_indicator(); hfp_ag_transfer_callheld_state(); } break; @@ -1525,8 +1515,13 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:{ int call_setup_in_progress = hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; int call_held = hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD; - + // Releases all active calls (if any exist) and accepts the other (held or waiting) call. + if (call_held || call_setup_in_progress){ + hfp_gsm_handle_event_with_call_index(HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL, connection->call_index); + + } + if (call_setup_in_progress){ printf("AG: Call Dropped, Accept new call\n"); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); @@ -1535,19 +1530,31 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect printf("AG: Call Dropped, Resume held call\n"); } if (call_held){ - hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_NO_CALLS_HELD); + hfp_ag_set_callheld_indicator(); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callheld_indicator_index, 1); } - if (call_held || call_setup_in_progress){ - hfp_gsm_handle_event(HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL); - } + connection->call_state = HFP_CALL_ACTIVE; + + if ( (hfp_ag_callsetup_state != hfp_gsm_callsetup_status()) ){ + printf("event HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL\n"); + exit(1); + } + break; } + case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:{ - int call_setup_in_progress = hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; // Places all active calls (if any exist) on hold and accepts the other (held or waiting) call. // only update if callsetup changed + int call_setup_in_progress = hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + + printf("Before change, event HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL\n"); + printf("call %d \n", hfp_gsm_call_status()); + printf("callsetup %d - %d \n", hfp_ag_callsetup_state, hfp_gsm_callsetup_status()); + + hfp_gsm_handle_event_with_call_index(HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL, connection->call_index); + if (call_setup_in_progress){ printf("AG: Call on Hold, Accept new call\n"); hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); @@ -1555,18 +1562,32 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect } else { printf("AG: Swap calls\n"); } - hfp_gsm_handle_event(HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL); - hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED); + + hfp_ag_set_callheld_indicator(); + // hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED); + printf("set callheld state to: %d == %d\n", HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED, hfp_gsm_callheld_status()); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callheld_indicator_index, 1); connection->call_state = HFP_CALL_ACTIVE; + + printf("After change\n"); + printf("call %d \n", hfp_gsm_call_status()); + printf("callsetup %d - %d \n", hfp_ag_callsetup_state, hfp_gsm_callsetup_status()); + + // if ( (hfp_ag_callsetup_state != hfp_gsm_callsetup_status()) || + // (hfp_ag_callheld_state != hfp_gsm_callheld_status()) ){ + // printf("event HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL\n"); + // exit(1); + // } + break; } + case HFP_AG_CALL_HOLD_ADD_HELD_CALL: // Adds a held call to the conversation. if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){ printf("AG: Join 3-way-call\n"); hfp_gsm_handle_event(HFP_AG_CALL_HOLD_ADD_HELD_CALL); - hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_NO_CALLS_HELD); + hfp_ag_set_callheld_indicator(); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callheld_indicator_index, 1); hfp_emit_event(hfp_callback, HFP_SUBEVENT_CONFERENCE_CALL, 0); } @@ -1577,7 +1598,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect hfp_gsm_handle_event(HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS); printf("AG: Transfer call -> Connect two calls and disconnect\n"); hfp_ag_set_call_indicator(); - hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_NO_CALLS_HELD); + hfp_ag_set_callheld_indicator(); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, call_indicator_index, 1); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callheld_indicator_index, 1); connection->call_state = HFP_CALL_IDLE; @@ -1587,6 +1608,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect break; } + } static void hfp_run_for_context(hfp_connection_t *context){ @@ -1859,21 +1881,35 @@ static void hfp_handle_rfcomm_data(uint8_t packet_type, uint16_t channel, uint8_ log_error("HFP: unhandled call hold type %c", context->line_buffer[0]); context->command = HFP_CMD_NONE; context->ok_pending = 1; - + context->call_index = 0; + + if (context->line_buffer[1] != '\0'){ + context->call_index = atoi((char *)&context->line_buffer[1]); + } + switch (context->line_buffer[0]){ case '0': + // Releases all held calls or sets User Determined User Busy (UDUB) for a waiting call. hfp_ag_call_sm(HFP_AG_CALL_HOLD_USER_BUSY, context); break; case '1': + // Releases all active calls (if any exist) and accepts the other (held or waiting) call. + // Where both a held and a waiting call exist, the above procedures shall apply to the + // waiting call (i.e., not to the held call) in conflicting situation. hfp_ag_call_sm(HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL, context); break; case '2': + // Places all active calls (if any exist) on hold and accepts the other (held or waiting) call. + // Where both a held and a waiting call exist, the above procedures shall apply to the + // waiting call (i.e., not to the held call) in conflicting situation. hfp_ag_call_sm(HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL, context); break; case '3': + // Adds a held call to the conversation. hfp_ag_call_sm(HFP_AG_CALL_HOLD_ADD_HELD_CALL, context); break; case '4': + // Connects the two calls and disconnects the subscriber from both calls (Explicit Call Transfer). hfp_ag_call_sm(HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS, context); break; default: @@ -1977,9 +2013,7 @@ 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_callsetup_state = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - hfp_ag_callheld_state = HFP_CALLHELD_STATUS_NO_CALLS_HELD; - - + hfp_ag_response_and_hold_active = 0; clip_type = 0; // 0 == not set memset(clip_number,0,sizeof(clip_number)); diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 5a49f3f0b..b9a239225 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -74,12 +74,14 @@ typedef enum{ typedef struct { hfp_gsm_call_status_t status; + int index; uint8_t clip_type; char clip_number[25]; } hfp_gsm_call_t; - + 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; void hfp_gsm_init(void){ memset(gsm_calls, 0, sizeof(gsm_calls)); @@ -106,7 +108,7 @@ static int get_call_index_with_status(hfp_gsm_call_status_t status){ return -1; } -static inline int get_none_call_index(){ +static inline int get_next_free_slot(){ return get_call_index_with_status(CALL_NONE); } @@ -134,6 +136,10 @@ 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); } @@ -142,6 +148,32 @@ static inline int get_number_response_held_calls(){ return get_number_calls_with_status(CALL_RESPONSE_HOLD); } +static int next_call_index(){ + return HFP_GSM_MAX_NR_CALLS + 1 - get_number_none_calls(); +} + +static void delete_call(int delete_index_in_table){ + int i ; + for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ + if (gsm_calls[i].index > gsm_calls[delete_index_in_table].index){ + gsm_calls[i].index--; + } + } + + gsm_calls[delete_index_in_table].status = CALL_NONE; + gsm_calls[delete_index_in_table].clip_type = 0; + gsm_calls[delete_index_in_table].index = 0; + gsm_calls[delete_index_in_table].clip_number[0] = '\0'; +} + +static void create_call(){ + int next_free_slot = get_next_free_slot(); + gsm_calls[next_free_slot].index = next_call_index(); + 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'; +} + hfp_call_status_t hfp_gsm_call_status(){ if (get_number_active_calls() + get_number_held_calls() + get_number_response_held_calls()){ return HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT; @@ -173,10 +205,15 @@ int hfp_gsm_call_possible(void){ } void hfp_gsm_handle_event(hfp_ag_call_event_t event){ - int next_free_slot = get_none_call_index(); + hfp_gsm_handle_event_with_call_index(event, 0); +} + +void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t index){ + 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(); + printf("hfp_gsm_handle_event %d \n", event); switch (event){ case HFP_AG_OUTGOING_CALL_INITIATED: @@ -185,11 +222,13 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ log_error("gsm: max call nr exceeded"); return; } + create_call(); break; case HFP_AG_OUTGOING_CALL_REJECTED: if (current_call_index != -1){ - gsm_calls[current_call_index].status = CALL_NONE; + // gsm_calls[current_call_index].status = CALL_NONE; + delete_call(current_call_index); } callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; break; @@ -198,7 +237,7 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ if (current_call_index != -1){ gsm_calls[current_call_index].status = CALL_HELD; } - gsm_calls[next_free_slot].status = CALL_INITIATED; + create_call(); callsetup_status = HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE; break; @@ -217,8 +256,7 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ case HFP_AG_INCOMING_CALL: if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS) break; callsetup_status = HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS; - gsm_calls[next_free_slot].status = CALL_INITIATED; - gsm_calls[next_free_slot].clip_type = 0; + create_call(); break; case HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG: @@ -272,7 +310,8 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG: case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_HF: if (!hfp_gsm_response_held_active()) break; - gsm_calls[get_response_held_call_index()].status = CALL_NONE; + // gsm_calls[get_response_held_call_index()].status = CALL_NONE; + delete_call(get_response_held_call_index()); break; @@ -282,7 +321,8 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; break; case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: - gsm_calls[current_call_index].status = CALL_NONE; + // gsm_calls[current_call_index].status = CALL_NONE; + delete_call(current_call_index); break; } break; @@ -295,7 +335,8 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ break; case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - gsm_calls[current_call_index].status = CALL_NONE; + // gsm_calls[current_call_index].status = CALL_NONE; + delete_call(current_call_index); break; default: break; @@ -308,9 +349,7 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ int i ; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - gsm_calls[i].status = CALL_NONE; - gsm_calls[i].clip_type = 0; - gsm_calls[i].clip_number[0] = '\0'; + delete_call(i); } } break; @@ -322,32 +361,49 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ break; case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:{ + printf("HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL \n"); int i ; - for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].status == CALL_ACTIVE){ - gsm_calls[i].clip_type = 0; - gsm_calls[i].clip_number[0] = '\0'; - gsm_calls[i].status = CALL_NONE; + printf("Number of calls 1: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); + 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){ + delete_call(i); + continue; + } } + } else { + for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ + if (gsm_calls[i].status == CALL_ACTIVE){ + delete_call(i); + } + } } - + + printf("Number of calls 2: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){ gsm_calls[initiated_call_index].status = CALL_ACTIVE; + printf("HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL initiated_call_index %d\n", initiated_call_index); } else { gsm_calls[held_call_index].status = CALL_ACTIVE; + printf("HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL initiated_call_index %d\n", initiated_call_index); } + + printf("Number of calls 3: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); 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 ; + printf("Number of calls 1: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].status == CALL_ACTIVE){ + if (gsm_calls[i].status == CALL_ACTIVE && gsm_calls[i].index != index){ gsm_calls[i].clip_type = 0; gsm_calls[i].clip_number[0] = '\0'; gsm_calls[i].status = CALL_HELD; } } + printf("Number of calls 2: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){ gsm_calls[initiated_call_index].status = CALL_ACTIVE; @@ -355,8 +411,11 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ gsm_calls[held_call_index].status = CALL_ACTIVE; } callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + printf("Number of calls 3: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); + break; - } + } + case HFP_AG_CALL_HOLD_ADD_HELD_CALL:{ if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){ int i ; @@ -372,12 +431,11 @@ void hfp_gsm_handle_event(hfp_ag_call_event_t event){ break; } + case HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS:{ int i ; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - gsm_calls[i].clip_type = 0; - gsm_calls[i].clip_number[0] = '\0'; - gsm_calls[i].status = CALL_NONE; + delete_call(i); } break; diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index f19ba026e..426f9754c 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -67,6 +67,7 @@ int hfp_gsm_call_possible(void); void hfp_gsm_init(void); +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); // /** From b0ae5518fda1130f04702be92a33fd9ae84fcf20 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 15 Jan 2016 12:36:44 +0100 Subject: [PATCH 4/6] hfp cleanup: remove callsetup from ag --- src/hfp_ag.c | 71 ++++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/src/hfp_ag.c b/src/hfp_ag.c index c5e6152eb..cf0a47773 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -76,7 +76,6 @@ static int hfp_ag_call_hold_services_nr = 0; static char *hfp_ag_call_hold_services[6]; static hfp_callback_t hfp_callback; -static hfp_callsetup_status_t hfp_ag_callsetup_state; static hfp_response_and_hold_state_t hfp_ag_response_and_hold_state; static int hfp_ag_response_and_hold_active = 0; @@ -1023,13 +1022,12 @@ static void hfp_ag_trigger_terminate_call(void){ hfp_emit_event(hfp_callback, HFP_SUBEVENT_CALL_TERMINATED, 0); } -static void hfp_ag_set_callsetup_state(hfp_callsetup_status_t state){ - hfp_ag_callsetup_state = state; +static void hfp_ag_set_callsetup_indicator(){ hfp_ag_indicator_t * indicator = get_ag_indicator_for_name("callsetup"); if (!indicator){ - log_error("hfp_ag_set_callsetup_state: callsetup indicator is missing"); + log_error("hfp_ag_set_callsetup_indicator: callsetup indicator is missing"); }; - indicator->status = state; + indicator->status = hfp_gsm_callsetup_status(); } static void hfp_ag_set_callheld_indicator(){ @@ -1122,7 +1120,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_INCOMING_CALL); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_trigger_incoming_call(); printf("AG rings\n"); break; @@ -1134,7 +1132,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_INCOMING_CALL); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_trigger_incoming_call(); printf("AG call waiting\n"); break; @@ -1153,7 +1151,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG); hfp_ag_set_call_indicator(); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_ag_accept_call(); printf("AG answers call, accept call by GSM\n"); break; @@ -1166,7 +1164,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: printf("AG: current call is placed on hold, incoming call gets active\n"); hfp_gsm_handle_event(HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_set_callheld_indicator(); hfp_ag_transfer_callsetup_state(); hfp_ag_transfer_callheld_state(); @@ -1206,7 +1204,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_set_call_indicator(); hfp_ag_hf_accept_call(connection); printf("HF answers call, accept call by GSM\n"); @@ -1234,7 +1232,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect hfp_ag_send_response_and_hold_state(hfp_ag_response_and_hold_state); // as with regualr call hfp_ag_set_call_indicator(); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_ag_accept_call(); printf("AG response and hold - hold by AG\n"); break; @@ -1260,7 +1258,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect hfp_ag_send_response_and_hold_state(hfp_ag_response_and_hold_state); // as with regualr call hfp_ag_set_call_indicator(); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_hf_accept_call(connection); printf("AG response and hold - hold by HF\n"); break; @@ -1305,7 +1303,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_TERMINATE_CALL_BY_HF); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_transfer_callsetup_state(); hfp_ag_trigger_reject_call(); printf("HF Rejected Incoming call, AG terminate call\n"); @@ -1313,7 +1311,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE: case HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE: hfp_gsm_handle_event(HFP_AG_TERMINATE_CALL_BY_HF); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_transfer_callsetup_state(); printf("AG terminate outgoing call process\n"); default: @@ -1338,7 +1336,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect switch (hfp_gsm_callsetup_status()){ case HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS: hfp_gsm_handle_event(HFP_AG_TERMINATE_CALL_BY_AG); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_trigger_reject_call(); printf("AG Rejected Incoming call, AG terminate call\n"); break; @@ -1347,7 +1345,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect } case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: hfp_gsm_handle_event(HFP_AG_TERMINATE_CALL_BY_AG); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_set_call_indicator(); hfp_ag_trigger_terminate_call(); printf("AG terminate call\n"); @@ -1375,7 +1373,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect break; } hfp_gsm_handle_event(HFP_AG_CALL_DROPPED); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_transfer_callsetup_state(); break; case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: @@ -1385,7 +1383,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect hfp_ag_send_response_and_hold_state(hfp_ag_response_and_hold_state); } hfp_gsm_handle_event(HFP_AG_CALL_DROPPED); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_set_call_indicator(); hfp_ag_trigger_terminate_call(); printf("AG notify call dropped\n"); @@ -1449,7 +1447,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect int put_call_on_hold = hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT; hfp_gsm_handle_event(HFP_AG_OUTGOING_CALL_ACCEPTED); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE); + hfp_ag_set_callsetup_indicator(); indicator_index = get_ag_indicator_index_for_name("callsetup"); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, indicator_index, 1); @@ -1475,7 +1473,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect hfp_gsm_handle_event(HFP_AG_OUTGOING_CALL_RINGING); connection->call_state = HFP_CALL_OUTGOING_RINGING; - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE); + hfp_ag_set_callsetup_indicator(); hfp_ag_transfer_callsetup_state(); break; @@ -1493,7 +1491,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect int CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS = hfp_gsm_callheld_status() == HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS; hfp_gsm_handle_event(HFP_AG_OUTGOING_CALL_ESTABLISHED); connection->call_state = HFP_CALL_ACTIVE; - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); hfp_ag_set_call_indicator(); hfp_ag_transfer_call_state(); hfp_ag_transfer_callsetup_state(); @@ -1506,7 +1504,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect case HFP_AG_CALL_HOLD_USER_BUSY: hfp_gsm_handle_event(HFP_AG_CALL_HOLD_USER_BUSY); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callsetup_indicator_index, 1); connection->call_state = HFP_CALL_ACTIVE; printf("AG: Call Waiting, User Busy\n"); @@ -1524,7 +1522,7 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect if (call_setup_in_progress){ printf("AG: Call Dropped, Accept new call\n"); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callsetup_indicator_index, 1); } else { printf("AG: Call Dropped, Resume held call\n"); @@ -1535,12 +1533,6 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect } connection->call_state = HFP_CALL_ACTIVE; - - if ( (hfp_ag_callsetup_state != hfp_gsm_callsetup_status()) ){ - printf("event HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL\n"); - exit(1); - } - break; } @@ -1548,16 +1540,11 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect // Places all active calls (if any exist) on hold and accepts the other (held or waiting) call. // only update if callsetup changed int call_setup_in_progress = hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - - printf("Before change, event HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL\n"); - printf("call %d \n", hfp_gsm_call_status()); - printf("callsetup %d - %d \n", hfp_ag_callsetup_state, hfp_gsm_callsetup_status()); - hfp_gsm_handle_event_with_call_index(HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL, connection->call_index); if (call_setup_in_progress){ printf("AG: Call on Hold, Accept new call\n"); - hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_callsetup_indicator(); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callsetup_indicator_index, 1); } else { printf("AG: Swap calls\n"); @@ -1565,20 +1552,8 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect hfp_ag_set_callheld_indicator(); // hfp_ag_set_callheld_state(HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED); - printf("set callheld state to: %d == %d\n", HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED, hfp_gsm_callheld_status()); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callheld_indicator_index, 1); connection->call_state = HFP_CALL_ACTIVE; - - printf("After change\n"); - printf("call %d \n", hfp_gsm_call_status()); - printf("callsetup %d - %d \n", hfp_ag_callsetup_state, hfp_gsm_callsetup_status()); - - // if ( (hfp_ag_callsetup_state != hfp_gsm_callsetup_status()) || - // (hfp_ag_callheld_state != hfp_gsm_callheld_status()) ){ - // printf("event HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL\n"); - // exit(1); - // } - break; } @@ -2012,8 +1987,6 @@ void hfp_ag_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, hfp_ag_call_hold_services_nr = call_hold_services_nr; memcpy(hfp_ag_call_hold_services, call_hold_services, call_hold_services_nr * sizeof(char *)); - hfp_ag_callsetup_state = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - hfp_ag_response_and_hold_active = 0; clip_type = 0; // 0 == not set memset(clip_number,0,sizeof(clip_number)); From e29731ecdbc9d58860c13b2e1026d83d5cd27ba4 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 15 Jan 2016 12:38:16 +0100 Subject: [PATCH 5/6] remove printfs --- src/hfp_gsm_model.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index b9a239225..908555d51 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -214,7 +214,6 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind int initiated_call_index = get_initiated_call_index(); int held_call_index = get_held_call_index(); - printf("hfp_gsm_handle_event %d \n", event); switch (event){ case HFP_AG_OUTGOING_CALL_INITIATED: case HFP_AG_OUTGOING_REDIAL_INITIATED: @@ -361,9 +360,7 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind break; case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:{ - printf("HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL \n"); int i ; - printf("Number of calls 1: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); 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){ @@ -379,23 +376,18 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind } } - printf("Number of calls 2: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){ gsm_calls[initiated_call_index].status = CALL_ACTIVE; - printf("HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL initiated_call_index %d\n", initiated_call_index); } else { gsm_calls[held_call_index].status = CALL_ACTIVE; - printf("HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL initiated_call_index %d\n", initiated_call_index); } - printf("Number of calls 3: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); 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 ; - printf("Number of calls 1: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); 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,16 +395,13 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind gsm_calls[i].status = CALL_HELD; } } - printf("Number of calls 2: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); - + if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){ gsm_calls[initiated_call_index].status = CALL_ACTIVE; } else { gsm_calls[held_call_index].status = CALL_ACTIVE; } callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - printf("Number of calls 3: initiated %d, active %d, held %d\n", get_number_initiated_calls(), get_number_active_calls(), get_number_held_calls()); - break; } From 60b37999d9f3a83fd5d2a5b33d7ce585c7470447 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 15 Jan 2016 14:57:14 +0100 Subject: [PATCH 6/6] hfp cleanup: remove clip_type and clip_number from ag --- src/hfp.h | 3 +- src/hfp_ag.c | 43 +++------------ src/hfp_gsm_model.c | 131 +++++++++++++++++++++++++++++++++----------- src/hfp_gsm_model.h | 4 ++ 4 files changed, 113 insertions(+), 68 deletions(-) diff --git a/src/hfp.h b/src/hfp.h index 953c327c6..2173372c6 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -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; diff --git a/src/hfp_ag.c b/src/hfp_ag.c index cf0a47773..2bd9145ae 100644 --- a/src/hfp_ag.c +++ b/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){ diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 908555d51..09d50ebf8 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -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; } diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index 426f9754c..7d5faf671 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -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);