diff --git a/drivers/hfpmodem/voicecall.c b/drivers/hfpmodem/voicecall.c index e0da3fc1..39d81f1f 100644 --- a/drivers/hfpmodem/voicecall.c +++ b/drivers/hfpmodem/voicecall.c @@ -43,6 +43,7 @@ #define POLL_CLCC_INTERVAL 2000 #define POLL_CLCC_DELAY 50 +#define EXPECT_RELEASE_DELAY 50 #define CLIP_TIMEOUT 500 static const char *none_prefix[] = { NULL }; @@ -57,6 +58,7 @@ struct voicecall_data { int cind_val[HFP_INDICATOR_LAST]; unsigned int local_release; unsigned int clcc_source; + unsigned int expect_release_source; unsigned int clip_source; }; @@ -194,6 +196,11 @@ static void release_with_status(struct ofono_voicecall *vc, int status) c = c->next; g_slist_free_1(t); } + + if (vd->expect_release_source) { + g_source_remove(vd->expect_release_source); + vd->expect_release_source = 0; + } } static void clcc_poll_cb(gboolean ok, GAtResult *result, gpointer user_data) @@ -471,13 +478,47 @@ static void hfp_set_udub(struct ofono_voicecall *vc, CALLBACK_WITH_FAILURE(cb, data); } +static gboolean expect_release(gpointer user_data) +{ + struct ofono_voicecall *vc = user_data; + struct voicecall_data *vd = ofono_voicecall_get_data(vc); + + g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix, + clcc_poll_cb, vc, NULL); + + vd->expect_release_source = 0; + + return FALSE; +} + +static void release_all_active_cb(gboolean ok, GAtResult *result, + gpointer user_data) +{ + struct change_state_req *req = user_data; + struct voicecall_data *vd = ofono_voicecall_get_data(req->vc); + + if (!ok) + goto out; + + if (vd->expect_release_source) + g_source_remove(vd->expect_release_source); + + vd->expect_release_source = g_timeout_add(EXPECT_RELEASE_DELAY, + expect_release, + req->vc); + +out: + generic_cb(ok, result, user_data); +} + static void hfp_release_all_active(struct ofono_voicecall *vc, ofono_voicecall_cb_t cb, void *data) { struct voicecall_data *vd = ofono_voicecall_get_data(vc); if (vd->ag_mpty_features & AG_CHLD_1) { - hfp_template("AT+CHLD=1", vc, generic_cb, 0x1, cb, data); + hfp_template("AT+CHLD=1", vc, release_all_active_cb, 0x1, cb, + data); return; } @@ -1111,6 +1152,9 @@ static void hfp_voicecall_remove(struct ofono_voicecall *vc) if (vd->clip_source) g_source_remove(vd->clip_source); + if (vd->expect_release_source) + g_source_remove(vd->expect_release_source); + g_slist_foreach(vd->calls, (GFunc) g_free, NULL); g_slist_free(vd->calls);