This commit is contained in:
Matthias Ringwald 2016-02-12 14:53:49 +01:00
commit b272847fe5
2 changed files with 138 additions and 90 deletions

View File

@ -72,69 +72,147 @@ 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;
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 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){
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;
}
}
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 get_enhanced_call_status(index_in_table) == HFP_ENHANCED_CALL_STATUS_ACTIVE;
}
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:
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 void free_call_slot(int index_in_table){
gsm_calls[index_in_table].used_slot = 0;
}
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));
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;
free_call_slot(i);
}
}
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 (gsm_calls[i].status == 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 (gsm_calls[i].status == status) return i;
if (get_enhanced_call_status(i) == enhanced_status) return i;
}
return -1;
}
static inline int get_initiated_call_index(void){
int i ;
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
if (is_enhanced_call_status_initiated(i)) return i;
}
return -1;
}
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){
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){
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){
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){
@ -163,8 +241,8 @@ static void delete_call(int delete_index_in_table){
gsm_calls[i].index--;
}
}
gsm_calls[delete_index_in_table].status = 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;
gsm_calls[delete_index_in_table].clip_number[0] = '\0';
@ -176,7 +254,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_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;
@ -202,27 +280,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;
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->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;
}
}
return call;
}
return NULL;
@ -334,14 +392,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){
gsm_calls[current_call_index].status = CALL_HELD;
set_enhanced_call_status_held(current_call_index);
}
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:
@ -349,27 +407,27 @@ 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;
gsm_calls[initiated_call_index].status = CALL_ACTIVE;
set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
set_enhanced_call_status_active(initiated_call_index);
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){
gsm_calls[current_call_index].status = CALL_HELD;
set_enhanced_call_status_held(current_call_index);
}
gsm_calls[initiated_call_index].status = CALL_ACTIVE;
set_enhanced_call_status_active(initiated_call_index);
break;
case HFP_AG_HELD_CALL_JOINED_BY_AG:
@ -377,14 +435,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;
callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS;
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) {
gsm_calls[held_call_index].status = CALL_ACTIVE;
set_enhanced_call_status_active(held_call_index);
}
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
if (gsm_calls[i].status == CALL_ACTIVE){
if (is_enhanced_call_status_active(i)){
gsm_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
}
}
@ -393,22 +451,22 @@ 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;
gsm_calls[initiated_call_index].status = CALL_ACTIVE;
set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
set_enhanced_call_status_active(initiated_call_index);
break;
case HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG:
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;
gsm_calls[initiated_call_index].status = CALL_RESPONSE_HOLD;
set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
set_enhanced_call_status_response_hold(initiated_call_index);
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_enhanced_call_status_active(get_response_held_call_index());
break;
case HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG:
@ -421,7 +479,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);
@ -433,10 +491,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:
@ -445,7 +503,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++){
@ -455,9 +513,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;
gsm_calls[initiated_call_index].status = CALL_NONE;
gsm_calls[held_call_index].status = CALL_ACTIVE;
set_callsetup_status(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS);
free_call_slot(initiated_call_index);
set_enhanced_call_status_active(held_call_index);
break;
case HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL:
@ -470,41 +528,41 @@ 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 (is_enhanced_call_status_active(i)){
delete_call(i);
}
}
}
if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){
gsm_calls[initiated_call_index].status = CALL_ACTIVE;
set_enhanced_call_status_active(initiated_call_index);
} else {
gsm_calls[held_call_index].status = CALL_ACTIVE;
set_enhanced_call_status_active(held_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_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 (is_enhanced_call_status_active(i) && gsm_calls[i].index != index){
set_enhanced_call_status_held(i);
}
}
if (callsetup_status != HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS){
gsm_calls[initiated_call_index].status = CALL_ACTIVE;
set_enhanced_call_status_active(initiated_call_index);
} else {
gsm_calls[held_call_index].status = CALL_ACTIVE;
set_enhanced_call_status_active(held_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_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){
gsm_calls[i].status = CALL_ACTIVE;
if (gsm_calls[i].used_slot){
set_enhanced_call_status_active(i);
gsm_calls[i].mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
}
}

View File

@ -54,20 +54,10 @@ extern "C" {
#endif
/* API_START */
typedef enum{
CALL_NONE,
CALL_INITIATED,
CALL_RESPONSE_HOLD,
CALL_ACTIVE,
CALL_HELD
} hfp_gsm_call_status_t;
typedef struct {
// TODO: use enhanced_status instead of status
hfp_gsm_call_status_t status;
hfp_enhanced_call_dir_t direction;
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;
// TODO: sort on drop call, so that index corresponds to table index