From ccb2e1df97bed0abc2c630a8dbd096c8e7946061 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 11 Feb 2016 13:59:00 +0100 Subject: [PATCH 01/16] gsm: cleanup --- src/hfp_gsm_model.c | 20 +++++++++++++++----- src/hfp_gsm_model.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 2f907a2e1..6a96c2c6c 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -73,6 +73,15 @@ static char last_dialed_number[HFP_GSM_MAX_CALL_NUMBER_SIZE]; static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number); +static void set_call_status_none(int index_in_table){ + gsm_calls[index_in_table].status = CALL_NONE; + gsm_calls[index_in_table].used_slot = 0; +} + +static int is_call_status_none(int index_in_table){ + return gsm_calls[index_in_table].status == CALL_NONE; +} + void hfp_gsm_init(void){ callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; clip_type = 0; @@ -81,7 +90,7 @@ void hfp_gsm_init(void){ 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; + set_call_status_none(i); } } @@ -163,8 +172,8 @@ static void delete_call(int delete_index_in_table){ gsm_calls[i].index--; } } - - gsm_calls[delete_index_in_table].status = CALL_NONE; + set_call_status_none(delete_index_in_table); + 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'; @@ -456,7 +465,8 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_USER_BUSY: // Held or waiting call gets active, callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - gsm_calls[initiated_call_index].status = CALL_NONE; + set_call_status_none(initiated_call_index); + gsm_calls[held_call_index].status = CALL_ACTIVE; break; @@ -503,7 +513,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_ADD_HELD_CALL: if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){ for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].status != CALL_NONE){ + if (!is_call_status_none(i)){ gsm_calls[i].status = CALL_ACTIVE; gsm_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL; } diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index e76f10ae3..c085123a3 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -65,6 +65,7 @@ typedef enum{ typedef struct { // TODO: use enhanced_status instead of status + uint8_t used_slot; hfp_gsm_call_status_t status; hfp_enhanced_call_dir_t direction; hfp_enhanced_call_status_t enhanced_status; From 79d3c2ada78bfa23bc47212c37f94bc911799473 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 11 Feb 2016 14:41:37 +0100 Subject: [PATCH 02/16] hfp gsm cleanup --- src/hfp.h | 4 +- src/hfp_gsm_model.c | 91 +++++++++++++++++++++++++++------------------ src/hfp_gsm_model.h | 2 +- 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/hfp.h b/src/hfp.h index 94c13f2a8..dffba6544 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -381,7 +381,9 @@ typedef enum{ HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING, HFP_ENHANCED_CALL_STATUS_INCOMING, HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING, - HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD + HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD, + // used only internally + HFP_ENHANCED_CALL_STATUS_NONE } hfp_enhanced_call_status_t; typedef enum{ diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 6a96c2c6c..08e600e7c 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -73,15 +73,15 @@ static char last_dialed_number[HFP_GSM_MAX_CALL_NUMBER_SIZE]; static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number); -static void set_call_status_none(int index_in_table){ - gsm_calls[index_in_table].status = CALL_NONE; - gsm_calls[index_in_table].used_slot = 0; +static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ + gsm_calls[index_in_table].status = status; } -static int is_call_status_none(int index_in_table){ - return gsm_calls[index_in_table].status == CALL_NONE; +static int get_call_status(int index_in_table){ + return gsm_calls[index_in_table].status; } + void hfp_gsm_init(void){ callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; clip_type = 0; @@ -90,14 +90,30 @@ void hfp_gsm_init(void){ memset(gsm_calls, 0, sizeof(gsm_calls)); int i; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - set_call_status_none(i); + set_call_status(i, CALL_NONE); } } +static int get_number_calls_with_enhanced_status(hfp_enhanced_call_status_t status){ + int i, count = 0; + for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ + if (gsm_calls[i].enhanced_status == status) count++; + } + return count; +} + +static int get_call_index_with_enhanced_status(hfp_enhanced_call_status_t status){ + int i ; + for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ + if (gsm_calls[i].enhanced_status == status) return i; + } + return -1; +} + static int get_number_calls_with_status(hfp_gsm_call_status_t status){ int i, count = 0; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].status == status) count++; + if (get_call_status(i) == status) count++; } return count; } @@ -105,7 +121,7 @@ static int get_number_calls_with_status(hfp_gsm_call_status_t status){ static int get_call_index_with_status(hfp_gsm_call_status_t status){ int i ; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].status == status) return i; + if (get_call_status(i) == status) return i; } return -1; } @@ -172,7 +188,7 @@ static void delete_call(int delete_index_in_table){ gsm_calls[i].index--; } } - set_call_status_none(delete_index_in_table); + set_call_status(delete_index_in_table, CALL_NONE); gsm_calls[delete_index_in_table].clip_type = 0; gsm_calls[delete_index_in_table].index = 0; @@ -185,7 +201,7 @@ static void create_call(hfp_enhanced_call_dir_t direction){ int next_free_slot = get_next_free_slot(); gsm_calls[next_free_slot].direction = direction; gsm_calls[next_free_slot].index = next_call_index(); - gsm_calls[next_free_slot].status = CALL_INITIATED; + set_call_status(next_free_slot, CALL_INITIATED); gsm_calls[next_free_slot].clip_type = 0; gsm_calls[next_free_slot].clip_number[0] = '\0'; gsm_calls[next_free_slot].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL; @@ -214,12 +230,11 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){ if (call->index != call_index) continue; - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; - - if (call->status == CALL_ACTIVE) call->enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; - if (call->status == CALL_HELD) call->enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; - - if (call->status == CALL_INITIATED){ + if (call->status == CALL_ACTIVE){ + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; + } else if (call->status == CALL_HELD) { + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; + } else if (call->status == CALL_INITIATED){ if (call->direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; @@ -231,6 +246,8 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){ } call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; } + } else { + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; } return call; } @@ -348,7 +365,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_OUTGOING_CALL_ACCEPTED: if (current_call_index != -1){ - gsm_calls[current_call_index].status = CALL_HELD; + set_call_status(current_call_index, CALL_HELD); } callsetup_status = HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE; break; @@ -362,7 +379,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty break; case HFP_AG_OUTGOING_CALL_ESTABLISHED: callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - gsm_calls[initiated_call_index].status = CALL_ACTIVE; + set_call_status(initiated_call_index, CALL_ACTIVE); break; case HFP_AG_INCOMING_CALL: @@ -376,9 +393,9 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; if (hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ - gsm_calls[current_call_index].status = CALL_HELD; + set_call_status(current_call_index, CALL_HELD); } - gsm_calls[initiated_call_index].status = CALL_ACTIVE; + set_call_status(initiated_call_index, CALL_ACTIVE); break; case HFP_AG_HELD_CALL_JOINED_BY_AG: @@ -386,14 +403,14 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty // TODO: is following condition correct? Can we join incoming call before it is answered? if (callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){ - gsm_calls[initiated_call_index].status = CALL_ACTIVE; + set_call_status(initiated_call_index, CALL_ACTIVE); callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; } else if (hfp_gsm_callheld_status() == HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED) { - gsm_calls[held_call_index].status = CALL_ACTIVE; + set_call_status(held_call_index, CALL_ACTIVE); } for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].status == CALL_ACTIVE){ + if (get_call_status(i) == CALL_ACTIVE){ gsm_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL; } } @@ -403,7 +420,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break; if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break; callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - gsm_calls[initiated_call_index].status = CALL_ACTIVE; + set_call_status(initiated_call_index, CALL_ACTIVE); break; case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG: @@ -411,13 +428,13 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break; if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break; callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - gsm_calls[initiated_call_index].status = CALL_RESPONSE_HOLD; + set_call_status(initiated_call_index, CALL_RESPONSE_HOLD); break; case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_AG: case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_HF: if (!hfp_gsm_response_held_active()) break; - gsm_calls[get_response_held_call_index()].status = CALL_ACTIVE; + set_call_status(get_response_held_call_index(), CALL_ACTIVE); break; case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG: @@ -465,9 +482,9 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_USER_BUSY: // Held or waiting call gets active, callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - set_call_status_none(initiated_call_index); + set_call_status(initiated_call_index, CALL_NONE); - gsm_calls[held_call_index].status = CALL_ACTIVE; + set_call_status(held_call_index, CALL_ACTIVE); break; case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL: @@ -480,16 +497,16 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty } } else { for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].status == CALL_ACTIVE){ + if (get_call_status(i) == CALL_ACTIVE){ delete_call(i); } } } if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){ - gsm_calls[initiated_call_index].status = CALL_ACTIVE; + set_call_status(initiated_call_index, CALL_ACTIVE); } else { - gsm_calls[held_call_index].status = CALL_ACTIVE; + set_call_status(held_call_index, CALL_ACTIVE); } callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; @@ -497,15 +514,15 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty 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].status = CALL_HELD; + if (get_call_status(i) == CALL_ACTIVE && gsm_calls[i].index != index){ + set_call_status(i, CALL_HELD); } } if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){ - gsm_calls[initiated_call_index].status = CALL_ACTIVE; + set_call_status(initiated_call_index, CALL_ACTIVE); } else { - gsm_calls[held_call_index].status = CALL_ACTIVE; + set_call_status(held_call_index, CALL_ACTIVE); } callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; break; @@ -513,8 +530,8 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_ADD_HELD_CALL: if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){ for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (!is_call_status_none(i)){ - gsm_calls[i].status = CALL_ACTIVE; + if (get_call_status(i) != CALL_NONE){ + set_call_status(i, CALL_ACTIVE); gsm_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL; } } diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index c085123a3..f7ececa31 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -65,7 +65,7 @@ typedef enum{ typedef struct { // TODO: use enhanced_status instead of status - uint8_t used_slot; + //uint8_t used_slot; hfp_gsm_call_status_t status; hfp_enhanced_call_dir_t direction; hfp_enhanced_call_status_t enhanced_status; From 915fbfcbc0133cc09b9c50cb0c80ce265363853b Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 11 Feb 2016 16:44:16 +0100 Subject: [PATCH 03/16] hfp gsm cleanup --- src/hfp.h | 4 +-- src/hfp_gsm_model.c | 84 ++++++++++++++++++++++++--------------------- src/hfp_gsm_model.h | 3 +- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/hfp.h b/src/hfp.h index dffba6544..94c13f2a8 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -381,9 +381,7 @@ typedef enum{ HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING, HFP_ENHANCED_CALL_STATUS_INCOMING, HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING, - HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD, - // used only internally - HFP_ENHANCED_CALL_STATUS_NONE + HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD } hfp_enhanced_call_status_t; typedef enum{ diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 08e600e7c..ac6b0d5c2 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -75,12 +75,17 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ gsm_calls[index_in_table].status = status; + gsm_calls[index_in_table].used_slot = 1; } static int get_call_status(int index_in_table){ return gsm_calls[index_in_table].status; } +static void free_call_slot(int index_in_table){ + gsm_calls[index_in_table].used_slot = 0; + gsm_calls[index_in_table].status = CALL_NONE; +} void hfp_gsm_init(void){ callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; @@ -90,26 +95,10 @@ void hfp_gsm_init(void){ memset(gsm_calls, 0, sizeof(gsm_calls)); int i; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - set_call_status(i, CALL_NONE); + free_call_slot(i); } } -static int get_number_calls_with_enhanced_status(hfp_enhanced_call_status_t status){ - int i, count = 0; - for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].enhanced_status == status) count++; - } - return count; -} - -static int get_call_index_with_enhanced_status(hfp_enhanced_call_status_t status){ - int i ; - for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (gsm_calls[i].enhanced_status == status) return i; - } - return -1; -} - static int get_number_calls_with_status(hfp_gsm_call_status_t status){ int i, count = 0; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ @@ -127,7 +116,11 @@ static int get_call_index_with_status(hfp_gsm_call_status_t status){ } static inline int get_next_free_slot(void){ - return get_call_index_with_status(CALL_NONE); + int i ; + for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ + if (!gsm_calls[i].used_slot) return i; + } + return -1; } static inline int get_active_call_index(void){ @@ -147,7 +140,11 @@ static inline int get_response_held_call_index(void){ } static inline int get_number_none_calls(void){ - return get_number_calls_with_status(CALL_NONE); + int i, count = 0; + for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ + if (!gsm_calls[i].used_slot) count++; + } + return count; } static inline int get_number_active_calls(void){ @@ -188,7 +185,7 @@ static void delete_call(int delete_index_in_table){ gsm_calls[i].index--; } } - set_call_status(delete_index_in_table, CALL_NONE); + free_call_slot(delete_index_in_table); gsm_calls[delete_index_in_table].clip_type = 0; gsm_calls[delete_index_in_table].index = 0; @@ -230,24 +227,33 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){ if (call->index != call_index) continue; - if (call->status == CALL_ACTIVE){ - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; - } else if (call->status == CALL_HELD) { - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; - } else if (call->status == CALL_INITIATED){ - if (call->direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ - if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; + switch (call->status){ + case CALL_ACTIVE: + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; + break; + case CALL_HELD: + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; + break; + case CALL_INITIATED: + if (call->direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ + if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; + } + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING; + } else { + if (get_number_active_calls() > 0){ + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; + } + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; } - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING; - } else { - if (get_number_active_calls() > 0){ - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; - } - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; - } - } else { - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; + break; + case CALL_RESPONSE_HOLD: + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; + break; + default: + log_error("no call status"); + break; + } return call; } @@ -482,8 +488,8 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_USER_BUSY: // Held or waiting call gets active, callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - set_call_status(initiated_call_index, CALL_NONE); - + // set_call_status(initiated_call_index, CALL_NONE); + free_call_slot(initiated_call_index); set_call_status(held_call_index, CALL_ACTIVE); break; diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index f7ececa31..4ca5f3a7a 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -65,7 +65,8 @@ typedef enum{ typedef struct { // TODO: use enhanced_status instead of status - //uint8_t used_slot; + uint8_t initiated; + uint8_t used_slot; hfp_gsm_call_status_t status; hfp_enhanced_call_dir_t direction; hfp_enhanced_call_status_t enhanced_status; From 19d39eec25a2c7ef69e181a4fdbeea537e7e38fb Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 11 Feb 2016 16:45:57 +0100 Subject: [PATCH 04/16] hfp gsm cleanup --- src/hfp_gsm_model.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index ac6b0d5c2..4f170d5fc 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -488,7 +488,6 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_USER_BUSY: // Held or waiting call gets active, callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; - // set_call_status(initiated_call_index, CALL_NONE); free_call_slot(initiated_call_index); set_call_status(held_call_index, CALL_ACTIVE); break; @@ -536,7 +535,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_ADD_HELD_CALL: if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){ for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (get_call_status(i) != CALL_NONE){ + if (gsm_calls[i].used_slot){ set_call_status(i, CALL_ACTIVE); gsm_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL; } From a70c22075539cef93e0e225e6c94ec1f70b0ccde Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 11 Feb 2016 16:51:24 +0100 Subject: [PATCH 05/16] hfp gsm cleanup --- src/hfp_gsm_model.c | 2 +- src/hfp_gsm_model.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 4f170d5fc..305f7e445 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -79,12 +79,12 @@ static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ } static int get_call_status(int index_in_table){ + if (!gsm_calls[index_in_table].used_slot) return -1; return gsm_calls[index_in_table].status; } static void free_call_slot(int index_in_table){ gsm_calls[index_in_table].used_slot = 0; - gsm_calls[index_in_table].status = CALL_NONE; } void hfp_gsm_init(void){ diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index 4ca5f3a7a..c81c4b2ca 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -56,7 +56,6 @@ extern "C" { /* API_START */ typedef enum{ - CALL_NONE, CALL_INITIATED, CALL_RESPONSE_HOLD, CALL_ACTIVE, From bacea99514b852e0bf8f5936c14d02fc4b6f85f4 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 11:38:45 +0100 Subject: [PATCH 06/16] hfp gsm: set active and hold enhanced states on state change --- src/hfp_gsm_model.c | 39 ++++++++++++++++++++++++++++++--------- src/hfp_gsm_model.h | 13 ++++++++++--- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 305f7e445..ce401908a 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -74,10 +74,40 @@ static char last_dialed_number[HFP_GSM_MAX_CALL_NUMBER_SIZE]; static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number); static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ + switch (status){ + case CALL_RESPONSE_HOLD: + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; + break; + case CALL_ACTIVE: + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; + break; + case CALL_HELD: + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; + break; + default: + break; + } gsm_calls[index_in_table].status = status; gsm_calls[index_in_table].used_slot = 1; } +static int get_call_status_for_enhanced_status(hfp_enhanced_call_status_t enhanced_status){ + switch(enhanced_status){ + case HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING: + case HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING: + case HFP_ENHANCED_CALL_STATUS_INCOMING: + case HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING: + return CALL_INITIATED; + case HFP_ENHANCED_CALL_STATUS_ACTIVE: + return CALL_ACTIVE; + case HFP_ENHANCED_CALL_STATUS_HELD: + return CALL_HELD; + case HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD: + return CALL_RESPONSE_HOLD; + } +} + + static int get_call_status(int index_in_table){ if (!gsm_calls[index_in_table].used_slot) return -1; return gsm_calls[index_in_table].status; @@ -228,12 +258,6 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){ if (call->index != call_index) continue; switch (call->status){ - case CALL_ACTIVE: - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; - break; - case CALL_HELD: - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; - break; case CALL_INITIATED: if (call->direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ @@ -247,9 +271,6 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){ call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; } break; - case CALL_RESPONSE_HOLD: - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; - break; default: log_error("no call status"); break; diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index c81c4b2ca..af5e6f27a 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -57,18 +57,25 @@ extern "C" { typedef enum{ CALL_INITIATED, + + // CALL_ENHANCED_CALL_STATUS_OUTGOING_DIALING, + // CALL_ENHANCED_CALL_STATUS_OUTGOING_ALERTING, + // CALL_ENHANCED_CALL_STATUS_INCOMING, + // CALL_ENHANCED_CALL_STATUS_INCOMING_WAITING, + CALL_RESPONSE_HOLD, CALL_ACTIVE, CALL_HELD } hfp_gsm_call_status_t; typedef struct { - // TODO: use enhanced_status instead of status - uint8_t initiated; uint8_t used_slot; + + // TODO: use enhanced_status instead of status hfp_gsm_call_status_t status; - hfp_enhanced_call_dir_t direction; hfp_enhanced_call_status_t enhanced_status; + + hfp_enhanced_call_dir_t direction; hfp_enhanced_call_mode_t mode; hfp_enhanced_call_mpty_t mpty; // TODO: sort on drop call, so that index corresponds to table index From 17d2322f1c6a2d9ca7c26771d5236d9e8a36a4e6 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 11:42:19 +0100 Subject: [PATCH 07/16] hfp gsm: set incoming enhanced states on state change --- src/hfp_gsm_model.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index ce401908a..8d0ec0fed 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -84,6 +84,14 @@ static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ case CALL_HELD: gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; break; + case CALL_INITIATED: + if (gsm_calls[index_in_table].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ + if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; + } + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING; + } + break; default: break; } @@ -259,12 +267,7 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){ switch (call->status){ case CALL_INITIATED: - if (call->direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ - if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; - } - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING; - } else { + if (call->direction == HFP_ENHANCED_CALL_DIR_INCOMING){ if (get_number_active_calls() > 0){ call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; } From 74ac0b603138f9e93a1a3ce2ea79499f25792b2a Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 11:57:09 +0100 Subject: [PATCH 08/16] hfp gsm: setter for callsetup status --- src/hfp_gsm_model.c | 74 +++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 8d0ec0fed..0792018d8 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -72,6 +72,11 @@ static char clip_number[HFP_GSM_MAX_CALL_NUMBER_SIZE]; static char last_dialed_number[HFP_GSM_MAX_CALL_NUMBER_SIZE]; static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number); +static inline int get_number_active_calls(void); + +static void set_callsetup_status(hfp_callsetup_status_t status){ + callsetup_status = status; +} static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ switch (status){ @@ -85,13 +90,16 @@ static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; break; case CALL_INITIATED: - if (gsm_calls[index_in_table].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ - if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ - gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; - } - gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING; - } - break; + if (gsm_calls[index_in_table].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING; + } else { + if (get_number_active_calls() > 0){ + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; + } else { + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; + } + } + break; default: break; } @@ -126,7 +134,7 @@ static void free_call_slot(int index_in_table){ } void hfp_gsm_init(void){ - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); clip_type = 0; memset(clip_number, 0, sizeof(clip_number)); memset(last_dialed_number, 0, sizeof(last_dialed_number)); @@ -267,12 +275,18 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){ switch (call->status){ case CALL_INITIATED: - if (call->direction == HFP_ENHANCED_CALL_DIR_INCOMING){ - if (get_number_active_calls() > 0){ - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; - } - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; - } + if (call->direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ + if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ + call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; + } + } + // } else { + // if (get_number_active_calls() > 0){ + // call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; + // } else { + // call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; + // } + // } break; default: log_error("no call status"); @@ -390,14 +404,14 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty if (current_call_index != -1){ delete_call(current_call_index); } - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); break; case HFP_AG_OUTGOING_CALL_ACCEPTED: if (current_call_index != -1){ set_call_status(current_call_index, CALL_HELD); } - callsetup_status = HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE; + set_callsetup_status(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE); break; case HFP_AG_OUTGOING_CALL_RINGING: @@ -405,22 +419,22 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty log_error("gsm: no active call"); return; } - callsetup_status = HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE; + set_callsetup_status(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE); break; case HFP_AG_OUTGOING_CALL_ESTABLISHED: - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); set_call_status(initiated_call_index, CALL_ACTIVE); break; 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; + set_callsetup_status(HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS); create_call(HFP_ENHANCED_CALL_DIR_INCOMING); break; case HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG: if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break; - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); if (hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ set_call_status(current_call_index, CALL_HELD); @@ -434,7 +448,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty // TODO: is following condition correct? Can we join incoming call before it is answered? if (callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){ set_call_status(initiated_call_index, CALL_ACTIVE); - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); } else if (hfp_gsm_callheld_status() == HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED) { set_call_status(held_call_index, CALL_ACTIVE); } @@ -449,7 +463,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF: if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break; if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break; - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); set_call_status(initiated_call_index, CALL_ACTIVE); break; @@ -457,7 +471,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF: if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break; if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break; - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); set_call_status(initiated_call_index, CALL_RESPONSE_HOLD); break; @@ -477,7 +491,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_TERMINATE_CALL_BY_HF: switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); break; case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: delete_call(current_call_index); @@ -489,10 +503,10 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty switch (hfp_gsm_call_status()){ case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break; - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); break; case HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT: - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); delete_call(current_call_index); break; default: @@ -501,7 +515,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty break; case HFP_AG_CALL_DROPPED: - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_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++){ @@ -511,7 +525,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_USER_BUSY: // Held or waiting call gets active, - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); free_call_slot(initiated_call_index); set_call_status(held_call_index, CALL_ACTIVE); break; @@ -538,7 +552,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty set_call_status(held_call_index, CALL_ACTIVE); } - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); break; case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL: @@ -553,7 +567,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty } else { set_call_status(held_call_index, CALL_ACTIVE); } - callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); break; case HFP_AG_CALL_HOLD_ADD_HELD_CALL: From 65bb457efa3d5ed918a33e9185f15e8a01b0e6c8 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 12:12:22 +0100 Subject: [PATCH 09/16] hfp gsm: remove status field from hfp_gsm_call_t, use enhanced_status instead --- src/hfp_gsm_model.c | 40 ++++++++++++++++------------------------ src/hfp_gsm_model.h | 17 ----------------- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 0792018d8..c55fbc7b1 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -64,6 +64,13 @@ #define HFP_GSM_MAX_NR_CALLS 3 #define HFP_GSM_MAX_CALL_NUMBER_SIZE 25 +typedef enum{ + CALL_INITIATED, + CALL_RESPONSE_HOLD, + CALL_ACTIVE, + CALL_HELD +} hfp_gsm_call_status_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; @@ -76,6 +83,14 @@ static inline int get_number_active_calls(void); static void set_callsetup_status(hfp_callsetup_status_t status){ callsetup_status = status; + if (callsetup_status != HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE) return; + + int i ; + for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ + if (gsm_calls[i].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ + gsm_calls[i].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; + } + } } static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ @@ -103,7 +118,6 @@ static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ default: break; } - gsm_calls[index_in_table].status = status; gsm_calls[index_in_table].used_slot = 1; } @@ -126,7 +140,7 @@ static int get_call_status_for_enhanced_status(hfp_enhanced_call_status_t enhanc static int get_call_status(int index_in_table){ if (!gsm_calls[index_in_table].used_slot) return -1; - return gsm_calls[index_in_table].status; + return get_call_status_for_enhanced_status(gsm_calls[index_in_table].enhanced_status); } static void free_call_slot(int index_in_table){ @@ -270,29 +284,7 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){ for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ hfp_gsm_call_t * call = &gsm_calls[i]; - if (call->index != call_index) continue; - - switch (call->status){ - case CALL_INITIATED: - if (call->direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ - if (callsetup_status == HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE){ - call->enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING; - } - } - // } else { - // if (get_number_active_calls() > 0){ - // call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; - // } else { - // call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; - // } - // } - break; - default: - log_error("no call status"); - break; - - } return call; } return NULL; diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index af5e6f27a..ad1cc8176 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -54,25 +54,8 @@ extern "C" { #endif /* API_START */ - -typedef enum{ - CALL_INITIATED, - - // CALL_ENHANCED_CALL_STATUS_OUTGOING_DIALING, - // CALL_ENHANCED_CALL_STATUS_OUTGOING_ALERTING, - // CALL_ENHANCED_CALL_STATUS_INCOMING, - // CALL_ENHANCED_CALL_STATUS_INCOMING_WAITING, - - CALL_RESPONSE_HOLD, - CALL_ACTIVE, - CALL_HELD -} hfp_gsm_call_status_t; - typedef struct { uint8_t used_slot; - - // TODO: use enhanced_status instead of status - hfp_gsm_call_status_t status; hfp_enhanced_call_status_t enhanced_status; hfp_enhanced_call_dir_t direction; From fe1a8d500e95a3e1b81fe426240cb46a8fd68298 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 12:32:44 +0100 Subject: [PATCH 10/16] hfp gsm: use set_enhanced_call_status_active --- src/hfp_gsm_model.c | 48 +++++++++++++++++++++++++++++++++------------ src/hfp_gsm_model.h | 1 - 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index c55fbc7b1..07471ad14 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -93,6 +93,30 @@ static void set_callsetup_status(hfp_callsetup_status_t status){ } } +static inline void set_enhanced_call_status_active(int index_in_table){ + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; +} + +static inline void set_enhanced_call_status_held(int index_in_table){ + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; +} + +static inline void set_enhanced_call_status_response_hold(int index_in_table){ + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; +} + +static inline void set_enhanced_call_status_initiated(int index_in_table){ + if (gsm_calls[index_in_table].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING; + } else { + if (get_number_active_calls() > 0){ + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; + } else { + gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; + } + } +} + static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ switch (status){ case CALL_RESPONSE_HOLD: @@ -415,7 +439,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty break; case HFP_AG_OUTGOING_CALL_ESTABLISHED: set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); - set_call_status(initiated_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(initiated_call_index); break; case HFP_AG_INCOMING_CALL: @@ -431,7 +455,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty if (hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ set_call_status(current_call_index, CALL_HELD); } - set_call_status(initiated_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(initiated_call_index); break; case HFP_AG_HELD_CALL_JOINED_BY_AG: @@ -439,10 +463,10 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty // TODO: is following condition correct? Can we join incoming call before it is answered? if (callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){ - set_call_status(initiated_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(initiated_call_index); set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); } else if (hfp_gsm_callheld_status() == HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED) { - set_call_status(held_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(held_call_index); } for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ @@ -456,7 +480,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break; if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break; set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); - set_call_status(initiated_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(initiated_call_index); break; case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG: @@ -470,7 +494,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_AG: case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_HF: if (!hfp_gsm_response_held_active()) break; - set_call_status(get_response_held_call_index(), CALL_ACTIVE); + set_enhanced_call_status_active(get_response_held_call_index()); break; case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG: @@ -519,7 +543,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty // Held or waiting call gets active, set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); free_call_slot(initiated_call_index); - set_call_status(held_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(held_call_index); break; case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL: @@ -539,9 +563,9 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty } if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){ - set_call_status(initiated_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(initiated_call_index); } else { - set_call_status(held_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(held_call_index); } set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); @@ -555,9 +579,9 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty } if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){ - set_call_status(initiated_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(initiated_call_index); } else { - set_call_status(held_call_index, CALL_ACTIVE); + set_enhanced_call_status_active(held_call_index); } set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); break; @@ -566,7 +590,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty if (hfp_gsm_callheld_status() != HFP_CALLHELD_STATUS_NO_CALLS_HELD){ for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ if (gsm_calls[i].used_slot){ - set_call_status(i, CALL_ACTIVE); + set_enhanced_call_status_active(i); gsm_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL; } } diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index ad1cc8176..f66d67831 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -57,7 +57,6 @@ extern "C" { typedef struct { uint8_t used_slot; hfp_enhanced_call_status_t enhanced_status; - hfp_enhanced_call_dir_t direction; hfp_enhanced_call_mode_t mode; hfp_enhanced_call_mpty_t mpty; From e5db645c869adcf3c6769ae31f801e0485162557 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 13:23:48 +0100 Subject: [PATCH 11/16] hfp gsm: use set_enhanced_call_status_held --- src/hfp_gsm_model.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 07471ad14..e53583a19 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -425,7 +425,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_OUTGOING_CALL_ACCEPTED: if (current_call_index != -1){ - set_call_status(current_call_index, CALL_HELD); + set_enhanced_call_status_held(current_call_index); } set_callsetup_status(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE); break; @@ -453,7 +453,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); if (hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ - set_call_status(current_call_index, CALL_HELD); + set_enhanced_call_status_held(current_call_index); } set_enhanced_call_status_active(initiated_call_index); break; @@ -574,7 +574,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL: for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ if (get_call_status(i) == CALL_ACTIVE && gsm_calls[i].index != index){ - set_call_status(i, CALL_HELD); + set_enhanced_call_status_held(i); } } From 0436e65c89e917c57ba919cf37b7d0a3c6fe0dde Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 13:24:40 +0100 Subject: [PATCH 12/16] hfp gsm: use set_enhanced_call_status_response_hold --- src/hfp_gsm_model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index e53583a19..6866f69ae 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -488,7 +488,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty if (hfp_gsm_callsetup_status() != HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) break; if (hfp_gsm_call_status() != HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) break; set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); - set_call_status(initiated_call_index, CALL_RESPONSE_HOLD); + set_enhanced_call_status_response_hold(initiated_call_index); break; case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_AG: From 9dce5e79b77b572ece5febeb2bf7f3ecf9470af4 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 13:26:47 +0100 Subject: [PATCH 13/16] hfp gsm: use set_enhanced_call_status_INITIATED --- src/hfp_gsm_model.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 6866f69ae..0f99cf3b9 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -95,14 +95,17 @@ static void set_callsetup_status(hfp_callsetup_status_t status){ static inline void set_enhanced_call_status_active(int index_in_table){ gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; + gsm_calls[index_in_table].used_slot = 1; } static inline void set_enhanced_call_status_held(int index_in_table){ gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; + gsm_calls[index_in_table].used_slot = 1; } static inline void set_enhanced_call_status_response_hold(int index_in_table){ gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; + gsm_calls[index_in_table].used_slot = 1; } static inline void set_enhanced_call_status_initiated(int index_in_table){ @@ -115,33 +118,6 @@ static inline void set_enhanced_call_status_initiated(int index_in_table){ gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; } } -} - -static void set_call_status(int index_in_table, hfp_gsm_call_status_t status){ - switch (status){ - case CALL_RESPONSE_HOLD: - gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; - break; - case CALL_ACTIVE: - gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_ACTIVE; - break; - case CALL_HELD: - gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_HELD; - break; - case CALL_INITIATED: - if (gsm_calls[index_in_table].direction == HFP_ENHANCED_CALL_DIR_OUTGOING){ - gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING; - } else { - if (get_number_active_calls() > 0){ - gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING; - } else { - gsm_calls[index_in_table].enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING; - } - } - break; - default: - break; - } gsm_calls[index_in_table].used_slot = 1; } @@ -282,7 +258,7 @@ static void create_call(hfp_enhanced_call_dir_t direction){ int next_free_slot = get_next_free_slot(); gsm_calls[next_free_slot].direction = direction; gsm_calls[next_free_slot].index = next_call_index(); - set_call_status(next_free_slot, CALL_INITIATED); + set_enhanced_call_status_initiated(next_free_slot); gsm_calls[next_free_slot].clip_type = 0; gsm_calls[next_free_slot].clip_number[0] = '\0'; gsm_calls[next_free_slot].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL; From 49170286cad8daf6f45677fdc64f64c9db3abc9f Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 13:57:44 +0100 Subject: [PATCH 14/16] hfp gsm: introduced enhanced status functions --- src/hfp_gsm_model.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 0f99cf3b9..2c7eba4bb 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -121,6 +121,30 @@ static inline void set_enhanced_call_status_initiated(int index_in_table){ gsm_calls[index_in_table].used_slot = 1; } +static inline int is_enhanced_call_status_active(int index_in_table){ + return gsm_calls[index_in_table].enhanced_status == HFP_ENHANCED_CALL_STATUS_ACTIVE; +} + +static inline int is_enhanced_call_status_held(int index_in_table){ + return gsm_calls[index_in_table].enhanced_status == HFP_ENHANCED_CALL_STATUS_HELD; +} + +static inline int is_enhanced_call_status_response_hold(int index_in_table){ + return gsm_calls[index_in_table].enhanced_status == HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; +} + +static inline int is_enhanced_call_status_initiated(int index_in_table){ + switch (gsm_calls[index_in_table].enhanced_status){ + case HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING: + case HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING: + case HFP_ENHANCED_CALL_STATUS_INCOMING: + case HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING: + return 1; + default: + return 0; + } +} + static int get_call_status_for_enhanced_status(hfp_enhanced_call_status_t enhanced_status){ switch(enhanced_status){ case HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING: @@ -137,6 +161,10 @@ static int get_call_status_for_enhanced_status(hfp_enhanced_call_status_t enhanc } } +static int get_enhanced_call_status(int index_in_table){ + if (!gsm_calls[index_in_table].used_slot) return -1; + return gsm_calls[index_in_table].enhanced_status; +} static int get_call_status(int index_in_table){ if (!gsm_calls[index_in_table].used_slot) return -1; @@ -175,6 +203,14 @@ static int get_call_index_with_status(hfp_gsm_call_status_t status){ return -1; } +static int get_enhanced_call_index_with_status(hfp_enhanced_call_status_t enhanced_status){ + int i ; + for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ + if (get_enhanced_call_status(i) == enhanced_status) return i; + } + return -1; +} + static inline int get_next_free_slot(void){ int i ; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ From 0195afd67a2b89a17e02548cdc06d3eb6c301f8f Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 14:26:17 +0100 Subject: [PATCH 15/16] hfp gsm: remove status enum --- src/hfp_gsm_model.c | 80 ++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 2c7eba4bb..66828820e 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -64,13 +64,6 @@ #define HFP_GSM_MAX_NR_CALLS 3 #define HFP_GSM_MAX_CALL_NUMBER_SIZE 25 -typedef enum{ - CALL_INITIATED, - CALL_RESPONSE_HOLD, - CALL_ACTIVE, - CALL_HELD -} hfp_gsm_call_status_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; @@ -121,20 +114,25 @@ static inline void set_enhanced_call_status_initiated(int index_in_table){ gsm_calls[index_in_table].used_slot = 1; } +static int get_enhanced_call_status(int index_in_table){ + if (!gsm_calls[index_in_table].used_slot) return -1; + return gsm_calls[index_in_table].enhanced_status; +} + static inline int is_enhanced_call_status_active(int index_in_table){ - return gsm_calls[index_in_table].enhanced_status == HFP_ENHANCED_CALL_STATUS_ACTIVE; + return get_enhanced_call_status(index_in_table) == HFP_ENHANCED_CALL_STATUS_ACTIVE; } static inline int is_enhanced_call_status_held(int index_in_table){ - return gsm_calls[index_in_table].enhanced_status == HFP_ENHANCED_CALL_STATUS_HELD; + return get_enhanced_call_status(index_in_table) == HFP_ENHANCED_CALL_STATUS_HELD; } static inline int is_enhanced_call_status_response_hold(int index_in_table){ - return gsm_calls[index_in_table].enhanced_status == HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; + return get_enhanced_call_status(index_in_table) == HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; } static inline int is_enhanced_call_status_initiated(int index_in_table){ - switch (gsm_calls[index_in_table].enhanced_status){ + switch (get_enhanced_call_status(index_in_table)){ case HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING: case HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING: case HFP_ENHANCED_CALL_STATUS_INCOMING: @@ -145,32 +143,6 @@ static inline int is_enhanced_call_status_initiated(int index_in_table){ } } -static int get_call_status_for_enhanced_status(hfp_enhanced_call_status_t enhanced_status){ - switch(enhanced_status){ - case HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING: - case HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING: - case HFP_ENHANCED_CALL_STATUS_INCOMING: - case HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING: - return CALL_INITIATED; - case HFP_ENHANCED_CALL_STATUS_ACTIVE: - return CALL_ACTIVE; - case HFP_ENHANCED_CALL_STATUS_HELD: - return CALL_HELD; - case HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD: - return CALL_RESPONSE_HOLD; - } -} - -static int get_enhanced_call_status(int index_in_table){ - if (!gsm_calls[index_in_table].used_slot) return -1; - return gsm_calls[index_in_table].enhanced_status; -} - -static int get_call_status(int index_in_table){ - if (!gsm_calls[index_in_table].used_slot) return -1; - return get_call_status_for_enhanced_status(gsm_calls[index_in_table].enhanced_status); -} - static void free_call_slot(int index_in_table){ gsm_calls[index_in_table].used_slot = 0; } @@ -187,26 +159,26 @@ void hfp_gsm_init(void){ } } -static int get_number_calls_with_status(hfp_gsm_call_status_t status){ +static int get_number_calls_with_enhanced_status(hfp_enhanced_call_status_t enhanced_status){ int i, count = 0; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (get_call_status(i) == status) count++; + if (get_enhanced_call_status(i) == enhanced_status) count++; } return count; } -static int get_call_index_with_status(hfp_gsm_call_status_t status){ +static int get_call_index_with_enhanced_status(hfp_enhanced_call_status_t enhanced_status){ int i ; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (get_call_status(i) == status) return i; + if (get_enhanced_call_status(i) == enhanced_status) return i; } return -1; } -static int get_enhanced_call_index_with_status(hfp_enhanced_call_status_t enhanced_status){ +static inline int get_initiated_call_index(void){ int i ; for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (get_enhanced_call_status(i) == enhanced_status) return i; + if (is_enhanced_call_status_initiated(i)) return i; } return -1; } @@ -220,19 +192,15 @@ static inline int get_next_free_slot(void){ } static inline int get_active_call_index(void){ - return get_call_index_with_status(CALL_ACTIVE); -} - -static inline int get_initiated_call_index(void){ - return get_call_index_with_status(CALL_INITIATED); + return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_ACTIVE); } static inline int get_held_call_index(void){ - return get_call_index_with_status(CALL_HELD); + return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_HELD); } static inline int get_response_held_call_index(void){ - return get_call_index_with_status(CALL_RESPONSE_HOLD); + return get_call_index_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD); } static inline int get_number_none_calls(void){ @@ -244,15 +212,15 @@ static inline int get_number_none_calls(void){ } static inline int get_number_active_calls(void){ - return get_number_calls_with_status(CALL_ACTIVE); + return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_ACTIVE); } static inline int get_number_held_calls(void){ - return get_number_calls_with_status(CALL_HELD); + return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_HELD); } static inline int get_number_response_held_calls(void){ - return get_number_calls_with_status(CALL_RESPONSE_HOLD); + return get_number_calls_with_enhanced_status(HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD); } static int next_call_index(void){ @@ -482,7 +450,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty } for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (get_call_status(i) == CALL_ACTIVE){ + if (is_enhanced_call_status_active(i)){ gsm_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL; } } @@ -568,7 +536,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty } } else { for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (get_call_status(i) == CALL_ACTIVE){ + if (is_enhanced_call_status_active(i)){ delete_call(i); } } @@ -585,7 +553,7 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty case HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL: for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){ - if (get_call_status(i) == CALL_ACTIVE && gsm_calls[i].index != index){ + if (is_enhanced_call_status_active(i) && gsm_calls[i].index != index){ set_enhanced_call_status_held(i); } } From 9188a3b7e0065e4f881c710beeaa6841984e5460 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 12 Feb 2016 14:28:08 +0100 Subject: [PATCH 16/16] hfp gsm: remove unsed functions --- src/hfp_gsm_model.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 66828820e..11699a553 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -123,14 +123,6 @@ static inline int is_enhanced_call_status_active(int index_in_table){ return get_enhanced_call_status(index_in_table) == HFP_ENHANCED_CALL_STATUS_ACTIVE; } -static inline int is_enhanced_call_status_held(int index_in_table){ - return get_enhanced_call_status(index_in_table) == HFP_ENHANCED_CALL_STATUS_HELD; -} - -static inline int is_enhanced_call_status_response_hold(int index_in_table){ - return get_enhanced_call_status(index_in_table) == HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD; -} - static inline int is_enhanced_call_status_initiated(int index_in_table){ switch (get_enhanced_call_status(index_in_table)){ case HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING: