diff --git a/src/hfp_ag.c b/src/hfp_ag.c index 609577449..5c16a6320 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -1394,18 +1394,14 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect hfp_gsm_handle_event(HFP_AG_OUTGOING_REDIAL_INITIATED); connection->call_state = HFP_CALL_OUTGOING_INITIATED; - hfp_emit_event(hfp_callback, HFP_SUBEVENT_REDIAL_LAST_NUMBER, 0); - printf("\n** Redial last number\n"); - hfp_gsm_call_t * last_dialed_call = hfp_gsm_last_dialed_call(); + printf("\nRedial last number"); + char * last_dialed_number = hfp_gsm_last_dialed_number(); - if (last_dialed_call){ - printf("Last number exists: accept call %s\n", last_dialed_call->clip_number); - hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER, last_dialed_call->clip_number); - hfp_ag_outgoing_call_accepted(); - // TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now - // hfp_ag_outgoing_call_ringing(); + if (strlen(last_dialed_number) > 0){ + printf("\nLast number exists: accept call"); + hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER, last_dialed_number); } else { - printf("Last number missing: reject call\n"); + printf("\nLast number missing: reject call"); hfp_ag_outgoing_call_rejected(); } break; diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index af9df1053..2f907a2e1 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -62,12 +62,14 @@ #include "hfp_gsm_model.h" #define HFP_GSM_MAX_NR_CALLS 3 +#define HFP_GSM_MAX_CALL_NUMBER_SIZE 25 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 clip_type; -static char clip_number[25]; +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); @@ -75,7 +77,7 @@ 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(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++){ @@ -140,14 +142,16 @@ static int next_call_index(void){ } static void hfp_gsm_set_clip(int index_in_table, uint8_t type, const char * number){ - printf("HFP_AG_SET_CLIP index in table %d, index %d, %d, %s, last dialed %d \n", - index_in_table, gsm_calls[index_in_table].index, type, number, gsm_calls[index_in_table].last_dialed); - + if (strlen(number) == 0) return; + gsm_calls[index_in_table].clip_type = type; - int clip_number_size = sizeof(gsm_calls[index_in_table].clip_number); + int clip_number_size = strlen(number) < HFP_GSM_MAX_CALL_NUMBER_SIZE ? strlen(number) : HFP_GSM_MAX_CALL_NUMBER_SIZE-1; strncpy(gsm_calls[index_in_table].clip_number, number, clip_number_size); - gsm_calls[index_in_table].clip_number[clip_number_size-1] = '\0'; + gsm_calls[index_in_table].clip_number[clip_number_size] = '\0'; + strncpy(last_dialed_number, number, clip_number_size); + last_dialed_number[clip_number_size] = '\0'; + clip_type = 0; memset(clip_number, 0, sizeof(clip_number)); } @@ -167,15 +171,7 @@ static void delete_call(int delete_index_in_table){ gsm_calls[delete_index_in_table].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL; } -static void set_last_dialed(int index_in_table){ - hfp_gsm_clear_last_dialed_number(); - gsm_calls[index_in_table].last_dialed = 1; - int i; - for (i = 0; iindex].status = CALL_INITIATED; - } - break; - } case HFP_AG_OUTGOING_CALL_REJECTED: if (current_call_index != -1){ diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index 25fd15b80..e76f10ae3 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -70,7 +70,6 @@ typedef struct { hfp_enhanced_call_status_t enhanced_status; hfp_enhanced_call_mode_t mode; hfp_enhanced_call_mpty_t mpty; - uint8_t last_dialed; // TODO: sort on drop call, so that index corresponds to table index int index; uint8_t clip_type; @@ -82,7 +81,7 @@ hfp_call_status_t hfp_gsm_call_status(void); hfp_callsetup_status_t hfp_gsm_callsetup_status(void); int hfp_gsm_get_number_of_calls(void); -hfp_gsm_call_t * hfp_gsm_last_dialed_call(void); +char * hfp_gsm_last_dialed_number(void); void hfp_gsm_clear_last_dialed_number(void);