2009-10-28 11:01:24 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
2011-10-10 20:39:48 +00:00
|
|
|
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
|
2009-10-28 11:01:24 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
2011-07-20 19:55:31 +00:00
|
|
|
#include <gatchat.h>
|
|
|
|
#include <gatresult.h>
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/voicecall.h>
|
2011-07-20 19:55:31 +00:00
|
|
|
|
2011-02-05 13:03:00 +00:00
|
|
|
#include "common.h"
|
2014-03-19 15:24:57 +00:00
|
|
|
#include "hfp.h"
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
#include "hfpmodem.h"
|
2011-07-20 19:55:31 +00:00
|
|
|
#include "slc.h"
|
2009-10-28 11:01:24 +00:00
|
|
|
|
2009-12-09 00:59:13 +00:00
|
|
|
#define POLL_CLCC_INTERVAL 2000
|
2011-07-25 14:42:19 +00:00
|
|
|
#define POLL_CLCC_DELAY 50
|
hfpmodem: Fix release-and-swap without +CIEV
Some phones do not send the corresponding call state update (+CIEV)
after a successful release-and-swap operation (AT+CHLD=1).
This has been observed with a Nokia 500, while testing ReleaseAndSwap()
while an active and a held call exist:
ofonod[20414]: > AT+CLCC\r
ofonod[20414]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20414]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20414]: < \r\nOK\r\n
ofonod[20414]: > AT+CHLD=1\r
ofonod[20414]: < \r\nOK\r\n
After this, no +CIEV is received, but the call has been hung up.
The proposed approach to solve this consists of using AT+CLCC, unless
a call release has been received within a specific time period.
The result fixes the problem as can be seen below:
ofonod[20847]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CHLD=1\r
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CLCC\r
ofonod[20847]: < \r\n+CLCC: 1,0,0,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: < \r\n+CIEV: 5,2\r\n
ofonod[20847]: < \r\n+CIEV: 5,0\r\n
2013-01-21 15:30:24 +00:00
|
|
|
#define EXPECT_RELEASE_DELAY 50
|
2009-12-09 05:07:35 +00:00
|
|
|
#define CLIP_TIMEOUT 500
|
2014-05-30 17:25:23 +00:00
|
|
|
#define EXPECT_RING_DELAY 200
|
2009-12-09 00:59:13 +00:00
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
static const char *none_prefix[] = { NULL };
|
2009-11-13 11:28:32 +00:00
|
|
|
static const char *clcc_prefix[] = { "+CLCC:", NULL };
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
struct voicecall_data {
|
|
|
|
GAtChat *chat;
|
|
|
|
GSList *calls;
|
|
|
|
unsigned int ag_features;
|
|
|
|
unsigned int ag_mpty_features;
|
|
|
|
unsigned char cind_pos[HFP_INDICATOR_LAST];
|
|
|
|
int cind_val[HFP_INDICATOR_LAST];
|
|
|
|
unsigned int local_release;
|
2009-12-09 00:59:13 +00:00
|
|
|
unsigned int clcc_source;
|
hfpmodem: Fix release-and-swap without +CIEV
Some phones do not send the corresponding call state update (+CIEV)
after a successful release-and-swap operation (AT+CHLD=1).
This has been observed with a Nokia 500, while testing ReleaseAndSwap()
while an active and a held call exist:
ofonod[20414]: > AT+CLCC\r
ofonod[20414]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20414]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20414]: < \r\nOK\r\n
ofonod[20414]: > AT+CHLD=1\r
ofonod[20414]: < \r\nOK\r\n
After this, no +CIEV is received, but the call has been hung up.
The proposed approach to solve this consists of using AT+CLCC, unless
a call release has been received within a specific time period.
The result fixes the problem as can be seen below:
ofonod[20847]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CHLD=1\r
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CLCC\r
ofonod[20847]: < \r\n+CLCC: 1,0,0,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: < \r\n+CIEV: 5,2\r\n
ofonod[20847]: < \r\n+CIEV: 5,0\r\n
2013-01-21 15:30:24 +00:00
|
|
|
unsigned int expect_release_source;
|
2009-12-09 05:07:35 +00:00
|
|
|
unsigned int clip_source;
|
2009-10-28 11:01:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct release_id_req {
|
|
|
|
struct ofono_voicecall *vc;
|
|
|
|
ofono_voicecall_cb_t cb;
|
|
|
|
void *data;
|
|
|
|
int id;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct change_state_req {
|
|
|
|
struct ofono_voicecall *vc;
|
|
|
|
ofono_voicecall_cb_t cb;
|
|
|
|
void *data;
|
|
|
|
int affected_types;
|
|
|
|
};
|
|
|
|
|
2009-12-09 00:59:13 +00:00
|
|
|
static gboolean poll_clcc(gpointer user_data);
|
|
|
|
|
2009-11-16 17:15:31 +00:00
|
|
|
static GSList *find_dialing(GSList *calls)
|
|
|
|
{
|
|
|
|
GSList *c;
|
|
|
|
|
|
|
|
c = g_slist_find_custom(calls, GINT_TO_POINTER(CALL_STATUS_DIALING),
|
|
|
|
at_util_call_compare_by_status);
|
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (c == NULL)
|
2009-11-16 17:15:31 +00:00
|
|
|
c = g_slist_find_custom(calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_ALERTING),
|
|
|
|
at_util_call_compare_by_status);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2013-01-21 15:30:22 +00:00
|
|
|
static void voicecall_notify(gpointer value, gpointer user)
|
|
|
|
{
|
|
|
|
struct ofono_call *call = value;
|
|
|
|
struct ofono_voicecall *vc = user;
|
|
|
|
|
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
}
|
|
|
|
|
2009-12-04 22:26:42 +00:00
|
|
|
static struct ofono_call *create_call(struct ofono_voicecall *vc, int type,
|
2009-10-28 11:01:24 +00:00
|
|
|
int direction, int status,
|
|
|
|
const char *num, int num_type, int clip)
|
|
|
|
{
|
2009-12-04 22:26:42 +00:00
|
|
|
struct voicecall_data *d = ofono_voicecall_get_data(vc);
|
2009-10-28 11:01:24 +00:00
|
|
|
struct ofono_call *call;
|
|
|
|
|
|
|
|
/* Generate a call structure for the waiting call */
|
2011-02-01 17:12:46 +00:00
|
|
|
call = g_try_new(struct ofono_call, 1);
|
2010-11-27 19:38:56 +00:00
|
|
|
if (call == NULL)
|
2009-10-28 11:01:24 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-02-01 17:12:46 +00:00
|
|
|
ofono_call_init(call);
|
|
|
|
|
2009-12-04 22:26:42 +00:00
|
|
|
call->id = ofono_voicecall_get_next_callid(vc);
|
2009-10-28 11:01:24 +00:00
|
|
|
call->type = type;
|
|
|
|
call->direction = direction;
|
|
|
|
call->status = status;
|
|
|
|
|
|
|
|
if (clip != 2) {
|
|
|
|
strncpy(call->phone_number.number, num,
|
|
|
|
OFONO_MAX_PHONE_NUMBER_LENGTH);
|
2017-10-28 20:24:54 +00:00
|
|
|
call->phone_number.number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0';
|
2009-10-28 11:01:24 +00:00
|
|
|
call->phone_number.type = num_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->calls = g_slist_insert_sorted(d->calls, call, at_util_call_compare);
|
|
|
|
|
|
|
|
call->clip_validity = clip;
|
|
|
|
|
|
|
|
return call;
|
|
|
|
}
|
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
static void release_call(struct ofono_voicecall *vc, struct ofono_call *call)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
enum ofono_disconnect_reason reason;
|
|
|
|
|
|
|
|
if (call == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (vd->local_release & (1 << call->id))
|
|
|
|
reason = OFONO_DISCONNECT_REASON_LOCAL_HANGUP;
|
|
|
|
else
|
|
|
|
reason = OFONO_DISCONNECT_REASON_REMOTE_HANGUP;
|
|
|
|
|
|
|
|
ofono_voicecall_disconnected(vc, call->id, reason, NULL);
|
|
|
|
vd->local_release &= ~(1 << call->id);
|
|
|
|
|
|
|
|
g_free(call);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_all_calls(struct ofono_voicecall *vc)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
GSList *l;
|
|
|
|
struct ofono_call *call;
|
|
|
|
|
|
|
|
for (l = vd->calls; l; l = l->next) {
|
|
|
|
call = l->data;
|
|
|
|
|
|
|
|
release_call(vc, call);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(vd->calls);
|
|
|
|
vd->calls = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_with_status(struct ofono_voicecall *vc, int status)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
GSList *p = NULL;
|
|
|
|
GSList *c = vd->calls;
|
2009-11-16 16:09:48 +00:00
|
|
|
GSList *t;
|
2009-11-14 04:47:10 +00:00
|
|
|
struct ofono_call *call;
|
|
|
|
|
|
|
|
while (c) {
|
|
|
|
call = c->data;
|
|
|
|
|
|
|
|
if (call->status != status) {
|
|
|
|
p = c;
|
|
|
|
c = c->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
release_call(vc, call);
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
p->next = c->next;
|
|
|
|
else
|
|
|
|
vd->calls = c->next;
|
|
|
|
|
2009-11-16 16:09:48 +00:00
|
|
|
t = c;
|
|
|
|
c = c->next;
|
|
|
|
g_slist_free_1(t);
|
2009-11-14 04:47:10 +00:00
|
|
|
}
|
hfpmodem: Fix release-and-swap without +CIEV
Some phones do not send the corresponding call state update (+CIEV)
after a successful release-and-swap operation (AT+CHLD=1).
This has been observed with a Nokia 500, while testing ReleaseAndSwap()
while an active and a held call exist:
ofonod[20414]: > AT+CLCC\r
ofonod[20414]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20414]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20414]: < \r\nOK\r\n
ofonod[20414]: > AT+CHLD=1\r
ofonod[20414]: < \r\nOK\r\n
After this, no +CIEV is received, but the call has been hung up.
The proposed approach to solve this consists of using AT+CLCC, unless
a call release has been received within a specific time period.
The result fixes the problem as can be seen below:
ofonod[20847]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CHLD=1\r
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CLCC\r
ofonod[20847]: < \r\n+CLCC: 1,0,0,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: < \r\n+CIEV: 5,2\r\n
ofonod[20847]: < \r\n+CIEV: 5,0\r\n
2013-01-21 15:30:24 +00:00
|
|
|
|
|
|
|
if (vd->expect_release_source) {
|
|
|
|
g_source_remove(vd->expect_release_source);
|
|
|
|
vd->expect_release_source = 0;
|
|
|
|
}
|
2009-11-14 04:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void clcc_poll_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_voicecall *vc = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
GSList *calls;
|
|
|
|
GSList *n, *o;
|
|
|
|
struct ofono_call *nc, *oc;
|
2009-12-09 00:59:13 +00:00
|
|
|
unsigned int num_active = 0;
|
|
|
|
unsigned int num_held = 0;
|
2013-01-21 15:30:23 +00:00
|
|
|
GSList *notify_calls = NULL;
|
2013-09-10 15:58:14 +00:00
|
|
|
unsigned int mpty_ids;
|
2009-11-14 04:47:10 +00:00
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
2013-09-10 15:58:14 +00:00
|
|
|
calls = at_util_parse_clcc(result, &mpty_ids);
|
2009-11-14 04:47:10 +00:00
|
|
|
|
|
|
|
n = calls;
|
|
|
|
o = vd->calls;
|
|
|
|
|
|
|
|
while (n || o) {
|
|
|
|
nc = n ? n->data : NULL;
|
|
|
|
oc = o ? o->data : NULL;
|
|
|
|
|
2009-12-09 00:59:13 +00:00
|
|
|
if (nc && (nc->status == CALL_STATUS_ACTIVE))
|
|
|
|
num_active++;
|
|
|
|
|
|
|
|
if (nc && (nc->status == CALL_STATUS_HELD))
|
|
|
|
num_held++;
|
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (oc && (nc == NULL || (nc->id > oc->id))) {
|
2009-11-14 04:47:10 +00:00
|
|
|
enum ofono_disconnect_reason reason;
|
|
|
|
|
2011-02-05 14:29:07 +00:00
|
|
|
if (vd->local_release & (1 << oc->id))
|
2009-11-14 04:47:10 +00:00
|
|
|
reason = OFONO_DISCONNECT_REASON_LOCAL_HANGUP;
|
|
|
|
else
|
|
|
|
reason = OFONO_DISCONNECT_REASON_REMOTE_HANGUP;
|
|
|
|
|
|
|
|
if (!oc->type)
|
|
|
|
ofono_voicecall_disconnected(vc, oc->id,
|
|
|
|
reason, NULL);
|
|
|
|
|
|
|
|
vd->local_release &= ~(1 << oc->id);
|
|
|
|
|
|
|
|
o = o->next;
|
2010-11-27 19:38:56 +00:00
|
|
|
} else if (nc && (oc == NULL || (nc->id < oc->id))) {
|
2009-11-14 04:47:10 +00:00
|
|
|
/* new call, signal it */
|
|
|
|
if (nc->type == 0)
|
2013-01-21 15:30:23 +00:00
|
|
|
notify_calls = g_slist_append(notify_calls, nc);
|
2009-11-14 04:47:10 +00:00
|
|
|
|
|
|
|
n = n->next;
|
|
|
|
} else {
|
|
|
|
/* Always use the clip_validity from old call
|
|
|
|
* the only place this is truly told to us is
|
|
|
|
* in the CLIP notify, the rest are fudged
|
|
|
|
* anyway. Useful when RING, CLIP is used,
|
|
|
|
* and we're forced to use CLCC and clip_validity
|
|
|
|
* is 1
|
|
|
|
*/
|
|
|
|
nc->clip_validity = oc->clip_validity;
|
|
|
|
|
2009-12-09 08:41:16 +00:00
|
|
|
if (memcmp(nc, oc, sizeof(struct ofono_call)) &&
|
|
|
|
!nc->type)
|
2013-01-21 15:30:23 +00:00
|
|
|
notify_calls = g_slist_prepend(notify_calls,
|
|
|
|
nc);
|
2009-11-14 04:47:10 +00:00
|
|
|
|
|
|
|
n = n->next;
|
|
|
|
o = o->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 15:30:23 +00:00
|
|
|
/*
|
|
|
|
* Disconnections were already reported, so process the rest of the
|
|
|
|
* notifications. Note that the new calls are placed at the end of the
|
|
|
|
* list, after other state changes
|
|
|
|
*/
|
|
|
|
g_slist_foreach(notify_calls, voicecall_notify, vc);
|
|
|
|
g_slist_free(notify_calls);
|
|
|
|
|
2013-09-10 15:58:14 +00:00
|
|
|
ofono_voicecall_mpty_hint(vc, mpty_ids);
|
|
|
|
|
2016-04-22 13:10:06 +00:00
|
|
|
g_slist_free_full(vd->calls, g_free);
|
2009-11-14 04:47:10 +00:00
|
|
|
|
|
|
|
vd->calls = calls;
|
2009-12-09 00:59:13 +00:00
|
|
|
|
|
|
|
/* If either active/held call is more than 1, we are in mpty calls.
|
|
|
|
* we won't get indicator update if any of them is released by CHLD=1x.
|
|
|
|
* So we have to poll it.
|
|
|
|
*/
|
2014-06-27 07:56:07 +00:00
|
|
|
if ((num_active > 1 || num_held > 1) && !vd->clcc_source)
|
2009-12-09 00:59:13 +00:00
|
|
|
vd->clcc_source = g_timeout_add(POLL_CLCC_INTERVAL, poll_clcc,
|
|
|
|
vc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean poll_clcc(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->clcc_source = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
2009-11-14 04:47:10 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
static void generic_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);
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
if (ok && req->affected_types) {
|
|
|
|
GSList *l;
|
|
|
|
struct ofono_call *call;
|
|
|
|
|
|
|
|
for (l = vd->calls; l; l = l->next) {
|
|
|
|
call = l->data;
|
|
|
|
|
2009-11-07 07:22:59 +00:00
|
|
|
if (req->affected_types & (1 << call->status))
|
|
|
|
vd->local_release |= (1 << call->id);
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-05 12:36:09 +00:00
|
|
|
if (!ok && vd->calls)
|
|
|
|
g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix,
|
|
|
|
clcc_poll_cb, req->vc, NULL);
|
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
req->cb(&error, req->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void atd_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
struct ofono_voicecall *vc = cbd->user;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
ofono_voicecall_cb_t cb = cbd->cb;
|
|
|
|
int type = 128;
|
|
|
|
int validity = 2;
|
|
|
|
struct ofono_error error;
|
|
|
|
struct ofono_call *call;
|
2009-11-14 04:47:10 +00:00
|
|
|
GSList *l;
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
/* On a success, make sure to put all active calls on hold */
|
|
|
|
for (l = vd->calls; l; l = l->next) {
|
|
|
|
call = l->data;
|
|
|
|
|
2011-02-05 13:03:00 +00:00
|
|
|
if (call->status != CALL_STATUS_ACTIVE)
|
2009-11-14 04:47:10 +00:00
|
|
|
continue;
|
|
|
|
|
2009-11-16 17:19:23 +00:00
|
|
|
call->status = CALL_STATUS_HELD;
|
2009-11-14 04:47:10 +00:00
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
}
|
|
|
|
|
2009-12-04 22:26:42 +00:00
|
|
|
call = create_call(vc, 0, 0, CALL_STATUS_DIALING, NULL, type, validity);
|
2010-11-27 19:38:56 +00:00
|
|
|
if (call == NULL) {
|
2009-10-28 11:01:24 +00:00
|
|
|
ofono_error("Unable to allocate call, "
|
|
|
|
"call tracking will fail!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_dial(struct ofono_voicecall *vc,
|
|
|
|
const struct ofono_phone_number *ph,
|
2011-01-26 22:17:52 +00:00
|
|
|
enum ofono_clir_option clir, ofono_voicecall_cb_t cb,
|
|
|
|
void *data)
|
2009-10-28 11:01:24 +00:00
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
cbd->user = vc;
|
|
|
|
if (ph->type == 145)
|
2010-02-05 18:00:14 +00:00
|
|
|
snprintf(buf, sizeof(buf), "ATD+%s", ph->number);
|
2009-10-28 11:01:24 +00:00
|
|
|
else
|
2010-02-05 18:00:14 +00:00
|
|
|
snprintf(buf, sizeof(buf), "ATD%s", ph->number);
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
strcat(buf, ";");
|
|
|
|
|
|
|
|
if (g_at_chat_send(vd->chat, buf, none_prefix,
|
|
|
|
atd_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
2010-08-16 20:06:00 +00:00
|
|
|
g_free(cbd);
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2017-10-31 08:39:34 +00:00
|
|
|
static void hfp_dial_last(struct ofono_voicecall *vc, ofono_voicecall_cb_t cb,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
|
|
|
cbd->user = vc;
|
|
|
|
|
|
|
|
if (g_at_chat_send(vd->chat, "AT+BLDN", none_prefix,
|
|
|
|
atd_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
|
|
|
|
}
|
2018-02-12 18:37:17 +00:00
|
|
|
|
|
|
|
static void hfp_dial_memory(struct ofono_voicecall *vc,
|
|
|
|
unsigned int memory_location,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
cbd->user = vc;
|
|
|
|
DBG("Calling memory location %d\n", memory_location);
|
2018-02-13 19:08:52 +00:00
|
|
|
snprintf(buf, sizeof(buf), "ATD>%d;", memory_location);
|
2018-02-12 18:37:17 +00:00
|
|
|
|
|
|
|
if (g_at_chat_send(vd->chat, buf, none_prefix,
|
|
|
|
atd_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
DBG("at_chat_failed");
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
static void hfp_template(const char *cmd, struct ofono_voicecall *vc,
|
|
|
|
GAtResultFunc result_cb, unsigned int affected_types,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
struct change_state_req *req = g_try_new0(struct change_state_req, 1);
|
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (req == NULL)
|
2009-10-28 11:01:24 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
req->vc = vc;
|
|
|
|
req->cb = cb;
|
|
|
|
req->data = data;
|
|
|
|
req->affected_types = affected_types;
|
|
|
|
|
|
|
|
if (g_at_chat_send(vd->chat, cmd, none_prefix,
|
|
|
|
result_cb, req, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:06:00 +00:00
|
|
|
g_free(req);
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_answer(struct ofono_voicecall *vc,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
hfp_template("ATA", vc, generic_cb, 0, cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_hangup(struct ofono_voicecall *vc,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
2013-08-25 06:21:23 +00:00
|
|
|
unsigned int affected = (1 << CALL_STATUS_INCOMING) |
|
|
|
|
(1 << CALL_STATUS_DIALING) |
|
|
|
|
(1 << CALL_STATUS_ALERTING) |
|
|
|
|
(1 << CALL_STATUS_ACTIVE);
|
|
|
|
|
2009-12-08 10:13:09 +00:00
|
|
|
/* Hangup current active call */
|
2013-08-25 06:21:23 +00:00
|
|
|
hfp_template("AT+CHUP", vc, generic_cb, affected, cb, data);
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
static void hfp_hold_all_active(struct ofono_voicecall *vc,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
|
2014-03-19 15:24:57 +00:00
|
|
|
if (vd->ag_mpty_features & HFP_AG_CHLD_2) {
|
2009-11-14 04:47:10 +00:00
|
|
|
hfp_template("AT+CHLD=2", vc, generic_cb, 0, cb, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_release_all_held(struct ofono_voicecall *vc,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
2011-02-05 13:03:00 +00:00
|
|
|
unsigned int held_status = 1 << CALL_STATUS_HELD;
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2014-03-19 15:24:57 +00:00
|
|
|
if (vd->ag_mpty_features & HFP_AG_CHLD_0) {
|
2009-12-09 08:41:16 +00:00
|
|
|
hfp_template("AT+CHLD=0", vc, generic_cb, held_status,
|
|
|
|
cb, data);
|
2009-11-14 04:47:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_set_udub(struct ofono_voicecall *vc,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
2013-08-25 06:25:28 +00:00
|
|
|
unsigned int incoming_or_waiting = 1 << CALL_STATUS_WAITING;
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2014-03-19 15:24:57 +00:00
|
|
|
if (vd->ag_mpty_features & HFP_AG_CHLD_0) {
|
2009-11-14 04:47:10 +00:00
|
|
|
hfp_template("AT+CHLD=0", vc, generic_cb, incoming_or_waiting,
|
|
|
|
cb, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
hfpmodem: Fix release-and-swap without +CIEV
Some phones do not send the corresponding call state update (+CIEV)
after a successful release-and-swap operation (AT+CHLD=1).
This has been observed with a Nokia 500, while testing ReleaseAndSwap()
while an active and a held call exist:
ofonod[20414]: > AT+CLCC\r
ofonod[20414]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20414]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20414]: < \r\nOK\r\n
ofonod[20414]: > AT+CHLD=1\r
ofonod[20414]: < \r\nOK\r\n
After this, no +CIEV is received, but the call has been hung up.
The proposed approach to solve this consists of using AT+CLCC, unless
a call release has been received within a specific time period.
The result fixes the problem as can be seen below:
ofonod[20847]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CHLD=1\r
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CLCC\r
ofonod[20847]: < \r\n+CLCC: 1,0,0,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: < \r\n+CIEV: 5,2\r\n
ofonod[20847]: < \r\n+CIEV: 5,0\r\n
2013-01-21 15:30:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-30 17:25:23 +00:00
|
|
|
static gboolean expect_ring(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->clip_source = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
hfpmodem: Fix release-and-swap without +CIEV
Some phones do not send the corresponding call state update (+CIEV)
after a successful release-and-swap operation (AT+CHLD=1).
This has been observed with a Nokia 500, while testing ReleaseAndSwap()
while an active and a held call exist:
ofonod[20414]: > AT+CLCC\r
ofonod[20414]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20414]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20414]: < \r\nOK\r\n
ofonod[20414]: > AT+CHLD=1\r
ofonod[20414]: < \r\nOK\r\n
After this, no +CIEV is received, but the call has been hung up.
The proposed approach to solve this consists of using AT+CLCC, unless
a call release has been received within a specific time period.
The result fixes the problem as can be seen below:
ofonod[20847]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CHLD=1\r
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CLCC\r
ofonod[20847]: < \r\n+CLCC: 1,0,0,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: < \r\n+CIEV: 5,2\r\n
ofonod[20847]: < \r\n+CIEV: 5,0\r\n
2013-01-21 15:30:24 +00:00
|
|
|
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);
|
|
|
|
|
2013-01-21 15:41:27 +00:00
|
|
|
/*
|
|
|
|
* Some phones, like Nokia 500, do not send CIEV after accepting
|
|
|
|
* the CHLD=1 command, even though the spec states that they should.
|
|
|
|
* So simply poll to force the status update if the AG is misbehaving.
|
|
|
|
*/
|
hfpmodem: Fix release-and-swap without +CIEV
Some phones do not send the corresponding call state update (+CIEV)
after a successful release-and-swap operation (AT+CHLD=1).
This has been observed with a Nokia 500, while testing ReleaseAndSwap()
while an active and a held call exist:
ofonod[20414]: > AT+CLCC\r
ofonod[20414]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20414]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20414]: < \r\nOK\r\n
ofonod[20414]: > AT+CHLD=1\r
ofonod[20414]: < \r\nOK\r\n
After this, no +CIEV is received, but the call has been hung up.
The proposed approach to solve this consists of using AT+CLCC, unless
a call release has been received within a specific time period.
The result fixes the problem as can be seen below:
ofonod[20847]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CHLD=1\r
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CLCC\r
ofonod[20847]: < \r\n+CLCC: 1,0,0,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: < \r\n+CIEV: 5,2\r\n
ofonod[20847]: < \r\n+CIEV: 5,0\r\n
2013-01-21 15:30:24 +00:00
|
|
|
vd->expect_release_source = g_timeout_add(EXPECT_RELEASE_DELAY,
|
|
|
|
expect_release,
|
|
|
|
req->vc);
|
|
|
|
|
|
|
|
out:
|
|
|
|
generic_cb(ok, result, user_data);
|
|
|
|
}
|
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
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);
|
|
|
|
|
2014-03-19 15:24:57 +00:00
|
|
|
if (vd->ag_mpty_features & HFP_AG_CHLD_1) {
|
hfpmodem: Fix release-and-swap without +CIEV
Some phones do not send the corresponding call state update (+CIEV)
after a successful release-and-swap operation (AT+CHLD=1).
This has been observed with a Nokia 500, while testing ReleaseAndSwap()
while an active and a held call exist:
ofonod[20414]: > AT+CLCC\r
ofonod[20414]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20414]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20414]: < \r\nOK\r\n
ofonod[20414]: > AT+CHLD=1\r
ofonod[20414]: < \r\nOK\r\n
After this, no +CIEV is received, but the call has been hung up.
The proposed approach to solve this consists of using AT+CLCC, unless
a call release has been received within a specific time period.
The result fixes the problem as can be seen below:
ofonod[20847]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CHLD=1\r
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CLCC\r
ofonod[20847]: < \r\n+CLCC: 1,0,0,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: < \r\n+CIEV: 5,2\r\n
ofonod[20847]: < \r\n+CIEV: 5,0\r\n
2013-01-21 15:30:24 +00:00
|
|
|
hfp_template("AT+CHLD=1", vc, release_all_active_cb, 0x1, cb,
|
|
|
|
data);
|
2009-11-14 04:47:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2009-12-09 00:55:55 +00:00
|
|
|
static void release_id_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct release_id_req *req = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(req->vc);
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
vd->local_release |= (1 << req->id);
|
|
|
|
|
|
|
|
req->cb(&error, req->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_release_specific(struct ofono_voicecall *vc, int id,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
struct release_id_req *req = NULL;
|
|
|
|
char buf[32];
|
|
|
|
|
2014-03-19 15:24:57 +00:00
|
|
|
if (!(vd->ag_mpty_features & HFP_AG_CHLD_1x))
|
2009-12-09 00:55:55 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
req = g_try_new0(struct release_id_req, 1);
|
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (req == NULL)
|
2009-12-09 00:55:55 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
req->vc = vc;
|
|
|
|
req->cb = cb;
|
|
|
|
req->data = data;
|
|
|
|
req->id = id;
|
|
|
|
|
2010-02-05 18:00:14 +00:00
|
|
|
snprintf(buf, sizeof(buf), "AT+CHLD=1%d", id);
|
2009-12-09 00:55:55 +00:00
|
|
|
|
|
|
|
if (g_at_chat_send(vd->chat, buf, none_prefix,
|
|
|
|
release_id_cb, req, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:06:00 +00:00
|
|
|
g_free(req);
|
2009-12-09 00:55:55 +00:00
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2009-12-09 02:16:53 +00:00
|
|
|
static void hfp_private_chat(struct ofono_voicecall *vc, int id,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
char buf[32];
|
|
|
|
|
2014-03-19 15:24:57 +00:00
|
|
|
if (vd->ag_mpty_features & HFP_AG_CHLD_2x) {
|
2010-02-05 18:00:14 +00:00
|
|
|
snprintf(buf, sizeof(buf), "AT+CHLD=2%d", id);
|
2009-12-09 02:16:53 +00:00
|
|
|
|
|
|
|
hfp_template(buf, vc, generic_cb, 0, cb, data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_create_multiparty(struct ofono_voicecall *vc,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
|
2014-03-19 15:24:57 +00:00
|
|
|
if (vd->ag_mpty_features & HFP_AG_CHLD_3) {
|
2009-12-09 02:16:53 +00:00
|
|
|
hfp_template("AT+CHLD=3", vc, generic_cb, 0, cb, data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_transfer(struct ofono_voicecall *vc,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
/* Transfer can puts held & active calls together and disconnects
|
2010-09-14 03:06:01 +00:00
|
|
|
* from both. However, some networks support transferring of
|
2009-12-09 02:16:53 +00:00
|
|
|
* dialing/ringing calls as well.
|
|
|
|
*/
|
|
|
|
unsigned int transfer = 0x1 | 0x2 | 0x4 | 0x8;
|
|
|
|
|
2014-03-19 15:24:57 +00:00
|
|
|
if (vd->ag_mpty_features & HFP_AG_CHLD_4) {
|
2009-12-09 02:16:53 +00:00
|
|
|
hfp_template("AT+CHLD=4", vc, generic_cb, transfer, cb, data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2009-12-04 03:22:14 +00:00
|
|
|
static void hfp_send_dtmf(struct ofono_voicecall *vc, const char *dtmf,
|
|
|
|
ofono_voicecall_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
struct change_state_req *req = g_try_new0(struct change_state_req, 1);
|
2014-06-20 08:03:51 +00:00
|
|
|
int len = strlen(dtmf);
|
2009-12-04 03:22:14 +00:00
|
|
|
char *buf;
|
|
|
|
int s;
|
2014-06-20 08:03:51 +00:00
|
|
|
int i;
|
2009-12-04 03:22:14 +00:00
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (req == NULL)
|
2009-12-04 03:22:14 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
req->vc = vc;
|
|
|
|
req->cb = cb;
|
|
|
|
req->data = data;
|
|
|
|
req->affected_types = 0;
|
|
|
|
|
2014-06-20 08:03:51 +00:00
|
|
|
/* strlen("AT") + (n-1) * strlen("+VTS=T;") + strlen(+VTS=T) + null */
|
|
|
|
buf = g_try_new(char, len * 7 + 2);
|
2010-11-27 19:38:56 +00:00
|
|
|
if (buf == NULL)
|
2009-12-04 03:22:14 +00:00
|
|
|
goto error;
|
|
|
|
|
2014-06-20 08:03:51 +00:00
|
|
|
s = sprintf(buf, "AT+VTS=%c", dtmf[0]);
|
|
|
|
|
|
|
|
for (i = 1; i < len; i++)
|
|
|
|
s += sprintf(buf + s, ";+VTS=%c", dtmf[i]);
|
2009-12-04 03:22:14 +00:00
|
|
|
|
|
|
|
s = g_at_chat_send(vd->chat, buf, none_prefix,
|
|
|
|
generic_cb, req, g_free);
|
|
|
|
|
|
|
|
g_free(buf);
|
|
|
|
|
|
|
|
if (s > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:06:00 +00:00
|
|
|
g_free(req);
|
2009-12-04 03:22:14 +00:00
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
static void no_carrier_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
DBG("");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ccwa_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_voicecall *vc = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
GAtResultIter iter;
|
|
|
|
const char *num;
|
|
|
|
int num_type, validity;
|
|
|
|
struct ofono_call *call;
|
|
|
|
|
hfp: Handle +CCWA at HFP connection setup
Some phones with an active and waiting call at the time of HFP SLC
establishment, may send call waiting notification before all calls
are synchronized. This will lead to call Id mismatch because call
object is created with assumed Id 1 and not Id assigned by the phone.
In example below waiting call is created with Id 1 but in AT+CLCC
this phone returns active call as call with Id 1, and waiting as 2.
< \r\n+CCWA: "+1234567890",145\r\n
< \r\n+CIEV: 2,1\r\n
drivers/hfpmodem/voicecall.c:ccwa_notify() ccwa_notify: +1234567890 145 0
src/voicecall.c:ofono_voicecall_notify() Got a voicecall event, status: 5, id: 1, number: +1234567890 called_number: , called_name
src/voicecall.c:ofono_voicecall_notify() Did not find a call with id: 1
> AT+CIND?\r
< \r\n+CIND: 1,1,1,4,0,2,0\r\n\r\nOK\r\n
src/network.c:ofono_netreg_status_notify() /hfp/org/bluez/hci0/dev_60_AF_6D_F7_8E_37 status 1 tech -1
> AT+VGS=7\r
< \r\nOK\r\n
> AT+VGM=7\r
< \r\nOK\r\n
> AT+CLCC\r
< \r\n+CLCC: 1,1,0,0,0,"+9876543210",145\r\n
< \r\n+CLCC: 2,1,5,0,0,"+1234567890",145\r\n\r\nOK\r\n
src/voicecall.c:ofono_voicecall_notify() Got a voicecall event, status: 0, id: 1, number: +9876543210 called_number: , called_name
src/voicecall.c:ofono_voicecall_notify() Found call with id: 1
src/voicecall.c:ofono_voicecall_notify() Got a voicecall event, status: 5, id: 2, number: +1234567890 called_number: , called_name
src/voicecall.c:ofono_voicecall_notify() Did not find a call with id: 2
src/voicecall.c:ofono_voicecall_mpty_hint() ids: 0
2016-04-04 08:36:25 +00:00
|
|
|
/* Waiting call notification makes no sense, when there are
|
|
|
|
* no calls at all. This can happen when a phone already has
|
|
|
|
* waiting and active calls and is being connected over HFP
|
|
|
|
* but it first sends +CCWA before we manage to synchronize
|
|
|
|
* calls with AT+CLCC.
|
|
|
|
*/
|
|
|
|
if (!vd->calls)
|
|
|
|
return;
|
|
|
|
|
2009-11-16 14:12:43 +00:00
|
|
|
/* CCWA can repeat, ignore if we already have an waiting call */
|
|
|
|
if (g_slist_find_custom(vd->calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_WAITING),
|
|
|
|
at_util_call_compare_by_status))
|
|
|
|
return;
|
|
|
|
|
hfp: Handle extra CCWA event
When a call is waitng, CCWA event is sent and call object
in state WAITING is created. on ReleaseAndAnswer it is
promoted to INCOMING and later to ACTIVE.
iPhones send an extra CCWA event when active call is ended.
This extra event is creating a second call object in state
WAITING. It is not possible to have two WAITING calls, but
previously waiting call was already promoted to INCOMING.
For a brief time we have two calls from the same number,
one INCOMING and one WAITING. Later WAITING one is removed.
As we cannot have a waiting and incoming call at the same
time, ignore CCWA when there is already an INCOMING call.
< \r\n+CIEV: 3,3\r\n
< \r\n+CIEV: 2,1\r\n
< \r\n+CIEV: 3,0\r\n
< \r\n+CCWA: "01234567890",129,1,"Me"\r\n
< \r\n+CIEV: 3,1\r\n
> AT+CLCC\r
< \r\n+CLCC: 1,0,0,0,0,"09876543210",129,"Me"\r\n
< \r\n+CLCC: 2,1,5,0,0,"01234567890",129,"Me"\r\n
< \r\nOK\r\n
< \r\n+CIEV: 2,0\r\n
< \r\n+CCWA: "01234567890",129,1,"Me"\r\n
< \r\n+CIEV: 2,1\r\n
< \r\n+CIEV: 3,0\r\n
> AT+CLCC\r
< \r\n+CLCC: 2,1,0,0,0,"01234567890",129,"Me"\r\n
< \r\nOK\r\n
2015-08-18 17:53:28 +00:00
|
|
|
/* some phones may send extra CCWA after active call is ended
|
|
|
|
* this would trigger creation of second call in state 'WAITING'
|
|
|
|
* as our previous WAITING call has been promoted to INCOMING
|
|
|
|
*/
|
|
|
|
if (g_slist_find_custom(vd->calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_INCOMING),
|
|
|
|
at_util_call_compare_by_status))
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CCWA:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_string(&iter, &num))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &num_type))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (strlen(num) > 0)
|
|
|
|
validity = 0;
|
|
|
|
else
|
|
|
|
validity = 2;
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("ccwa_notify: %s %d %d", num, num_type, validity);
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2011-02-05 13:03:00 +00:00
|
|
|
call = create_call(vc, 0, 1, CALL_STATUS_WAITING, num, num_type,
|
2011-03-17 21:11:02 +00:00
|
|
|
validity);
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (call == NULL) {
|
2009-12-09 08:41:16 +00:00
|
|
|
ofono_error("malloc call struct failed. "
|
|
|
|
"Call management is fubar");
|
2009-11-14 04:47:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
}
|
|
|
|
|
2009-12-09 05:07:35 +00:00
|
|
|
static gboolean clip_timeout(gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_voicecall *vc = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
GSList *l;
|
|
|
|
struct ofono_call *call;
|
|
|
|
|
|
|
|
l = g_slist_find_custom(vd->calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_INCOMING),
|
|
|
|
at_util_call_compare_by_status);
|
|
|
|
|
|
|
|
if (l == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
call = l->data;
|
|
|
|
|
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
|
|
|
|
vd->clip_source = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
static void ring_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_voicecall *vc = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
struct ofono_call *call;
|
2009-11-14 04:47:10 +00:00
|
|
|
GSList *waiting;
|
2009-10-28 11:01:24 +00:00
|
|
|
|
2014-05-30 17:25:23 +00:00
|
|
|
if (vd->clip_source) {
|
|
|
|
g_source_remove(vd->clip_source);
|
|
|
|
vd->clip_source = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
/* RING can repeat, ignore if we already have an incoming call */
|
|
|
|
if (g_slist_find_custom(vd->calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_INCOMING),
|
|
|
|
at_util_call_compare_by_status))
|
|
|
|
return;
|
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
waiting = g_slist_find_custom(vd->calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_WAITING),
|
|
|
|
at_util_call_compare_by_status);
|
|
|
|
|
|
|
|
/* If we started receiving RINGS but have a waiting call, most
|
|
|
|
* likely all other calls were dropped and we just didn't get
|
|
|
|
* notified yet, drop all other calls and update the status to
|
|
|
|
* incoming
|
|
|
|
*/
|
|
|
|
if (waiting) {
|
|
|
|
DBG("Triggering waiting -> incoming cleanup code");
|
|
|
|
|
|
|
|
vd->calls = g_slist_remove_link(vd->calls, waiting);
|
|
|
|
release_all_calls(vc);
|
|
|
|
vd->calls = waiting;
|
|
|
|
|
|
|
|
call = waiting->data;
|
|
|
|
call->status = CALL_STATUS_INCOMING;
|
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
return;
|
2009-11-14 04:47:10 +00:00
|
|
|
}
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
/* Generate an incoming call of voice type */
|
2009-12-04 22:26:42 +00:00
|
|
|
call = create_call(vc, 0, 1, CALL_STATUS_INCOMING, NULL, 128, 2);
|
2009-10-28 11:01:24 +00:00
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (call == NULL)
|
2009-10-28 11:01:24 +00:00
|
|
|
ofono_error("Couldn't create call, call management is fubar!");
|
2009-12-09 05:07:35 +00:00
|
|
|
|
|
|
|
/* We don't know the number must wait for CLIP to arrive before
|
|
|
|
* announcing the call. If timeout, we notify the call as it is.
|
|
|
|
*/
|
|
|
|
vd->clip_source = g_timeout_add(CLIP_TIMEOUT, clip_timeout, vc);
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void clip_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_voicecall *vc = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
GAtResultIter iter;
|
|
|
|
const char *num;
|
|
|
|
int type, validity;
|
|
|
|
GSList *l;
|
|
|
|
struct ofono_call *call;
|
|
|
|
|
|
|
|
l = g_slist_find_custom(vd->calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_INCOMING),
|
|
|
|
at_util_call_compare_by_status);
|
|
|
|
|
|
|
|
if (l == NULL) {
|
|
|
|
ofono_error("CLIP for unknown call");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CLIP:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_string(&iter, &num))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &type))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (strlen(num) > 0)
|
|
|
|
validity = 0;
|
|
|
|
else
|
|
|
|
validity = 2;
|
|
|
|
|
|
|
|
/* Skip subaddr, satype, alpha and validity */
|
|
|
|
g_at_result_iter_skip_next(&iter);
|
|
|
|
g_at_result_iter_skip_next(&iter);
|
|
|
|
g_at_result_iter_skip_next(&iter);
|
|
|
|
g_at_result_iter_skip_next(&iter);
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("clip_notify: %s %d %d", num, type, validity);
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
call = l->data;
|
|
|
|
|
|
|
|
strncpy(call->phone_number.number, num,
|
|
|
|
OFONO_MAX_PHONE_NUMBER_LENGTH);
|
|
|
|
call->phone_number.number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0';
|
|
|
|
call->phone_number.type = type;
|
|
|
|
call->clip_validity = validity;
|
|
|
|
|
|
|
|
ofono_voicecall_notify(vc, call);
|
2009-12-09 05:07:35 +00:00
|
|
|
|
|
|
|
if (vd->clip_source) {
|
|
|
|
g_source_remove(vd->clip_source);
|
|
|
|
vd->clip_source = 0;
|
|
|
|
}
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ciev_call_notify(struct ofono_voicecall *vc,
|
2009-10-29 00:23:25 +00:00
|
|
|
unsigned int value)
|
2009-10-28 11:01:24 +00:00
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
2009-11-14 04:47:10 +00:00
|
|
|
struct ofono_call *call;
|
2009-10-28 11:01:24 +00:00
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
switch (value) {
|
|
|
|
case 0:
|
2009-11-14 04:47:10 +00:00
|
|
|
/* If call goes to 0, then we have no held or active calls
|
|
|
|
* in the system. The waiting calls are promoted to incoming
|
2009-11-16 17:45:03 +00:00
|
|
|
* calls, dialing calls are kept. This also handles the
|
|
|
|
* situation when dialing and waiting calls exist
|
2009-11-14 04:47:10 +00:00
|
|
|
*/
|
2009-11-16 17:45:03 +00:00
|
|
|
release_with_status(vc, CALL_STATUS_HELD);
|
|
|
|
release_with_status(vc, CALL_STATUS_ACTIVE);
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2009-11-16 17:45:03 +00:00
|
|
|
/* Promote waiting to incoming if it is the last call */
|
|
|
|
if (vd->calls && vd->calls->next == NULL) {
|
|
|
|
call = vd->calls->data;
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2009-11-16 17:45:03 +00:00
|
|
|
if (call->status == CALL_STATUS_WAITING) {
|
|
|
|
call->status = CALL_STATUS_INCOMING;
|
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
}
|
|
|
|
}
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
break;
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
case 1:
|
2009-11-14 04:47:10 +00:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
/* In this case either dialing/alerting or the incoming call
|
|
|
|
* is promoted to active
|
|
|
|
*/
|
|
|
|
for (l = vd->calls; l; l = l->next) {
|
|
|
|
call = l->data;
|
|
|
|
|
|
|
|
if (call->status == CALL_STATUS_DIALING ||
|
|
|
|
call->status == CALL_STATUS_ALERTING ||
|
|
|
|
call->status == CALL_STATUS_INCOMING) {
|
|
|
|
call->status = CALL_STATUS_ACTIVE;
|
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
break;
|
2009-11-14 04:47:10 +00:00
|
|
|
}
|
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 17:26:08 +00:00
|
|
|
vd->cind_val[HFP_INDICATOR_CALL] = value;
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ciev_callsetup_notify(struct ofono_voicecall *vc,
|
2009-10-29 00:23:25 +00:00
|
|
|
unsigned int value)
|
2009-10-28 11:01:24 +00:00
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
2009-11-03 17:26:08 +00:00
|
|
|
unsigned int ciev_call = vd->cind_val[HFP_INDICATOR_CALL];
|
2009-11-14 04:47:10 +00:00
|
|
|
unsigned int ciev_callheld = vd->cind_val[HFP_INDICATOR_CALLHELD];
|
|
|
|
GSList *dialing;
|
|
|
|
GSList *waiting;
|
|
|
|
|
2009-11-16 17:15:31 +00:00
|
|
|
dialing = find_dialing(vd->calls);
|
2009-11-14 04:47:10 +00:00
|
|
|
|
|
|
|
waiting = g_slist_find_custom(vd->calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_WAITING),
|
|
|
|
at_util_call_compare_by_status);
|
|
|
|
|
|
|
|
/* This is a truly bizarre case not covered at all by the specification
|
|
|
|
* (yes, they are complete idiots). Here we assume the other side is
|
|
|
|
* semi sane and will send callsetup updates in case the dialing call
|
|
|
|
* connects or the call waiting drops. In which case we must poll
|
|
|
|
*/
|
|
|
|
if (waiting && dialing) {
|
|
|
|
g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix,
|
|
|
|
clcc_poll_cb, vc, NULL);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-28 11:01:24 +00:00
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
/* call=0 and callsetup=1: reject an incoming call
|
|
|
|
* call=0 and callsetup=2,3: interrupt an outgoing call
|
|
|
|
*/
|
2009-11-14 04:47:10 +00:00
|
|
|
if (ciev_call == 0) {
|
|
|
|
release_all_calls(vc);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-11-16 17:15:31 +00:00
|
|
|
/* If call=1 and no call is waiting or dialing, the call is
|
|
|
|
* active and we moved it to active state when call=1 arrived
|
|
|
|
*/
|
2009-11-16 14:10:54 +00:00
|
|
|
if (waiting == NULL && dialing == NULL)
|
|
|
|
goto out;
|
|
|
|
|
2011-03-17 21:11:02 +00:00
|
|
|
/*
|
2009-11-14 04:47:10 +00:00
|
|
|
* If call=1, in the waiting case we have to poll, since we
|
|
|
|
* have no idea whether a waiting call gave up or we accepted
|
|
|
|
* using release+accept or hold+accept
|
|
|
|
*
|
|
|
|
* If call=1, in the dialing + held case we have to poll as
|
|
|
|
* well, we have no idea whether the call connected, or released
|
|
|
|
*/
|
|
|
|
if (waiting == NULL && ciev_callheld == 0) {
|
|
|
|
struct ofono_call *call = dialing->data;
|
|
|
|
|
|
|
|
/* We assume that the implementation follows closely
|
|
|
|
* the sequence of events in Figure 4.21. That is
|
|
|
|
* call=1 arrives first, then callsetup=0
|
|
|
|
*/
|
|
|
|
|
|
|
|
call->status = CALL_STATUS_ACTIVE;
|
|
|
|
ofono_voicecall_notify(vc, call);
|
2009-12-18 03:44:09 +00:00
|
|
|
} else {
|
2009-11-14 04:47:10 +00:00
|
|
|
g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix,
|
|
|
|
clcc_poll_cb, vc, NULL);
|
2009-12-18 03:44:09 +00:00
|
|
|
}
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
break;
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
case 1:
|
2014-05-30 17:25:23 +00:00
|
|
|
/*
|
|
|
|
* Handled in RING/CCWA most of the time, however sometimes
|
|
|
|
* the call is answered before the RING unsolicited
|
|
|
|
* notification has a chance to be generated on the device.
|
|
|
|
* In this case, we use a failsafe CLCC poll in expect_ring
|
|
|
|
* callback.
|
|
|
|
* */
|
|
|
|
vd->clip_source = g_timeout_add(EXPECT_RING_DELAY,
|
|
|
|
expect_ring, vc);
|
2009-11-13 11:28:32 +00:00
|
|
|
break;
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
case 2:
|
|
|
|
/* two cases of outgoing call: dial from HF or AG.
|
|
|
|
* from HF: query and sync the phone number.
|
|
|
|
* from AG: query and create call.
|
|
|
|
*/
|
2009-11-14 04:47:10 +00:00
|
|
|
g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix,
|
hfpmodem: use full CLCC handling in dialing case
A call that moves from the dialing to active state before the +CLCC response
will not properly be added as a voicecall. This is because the dialing callback
was using simplified handling and only looked for calls in the dialing or
alerting state.
AT sequence that exhibited the failure (AG device was an iPhone accessing
visual voicemail):
> +CIND: ("service",(0-1)),("call",(0-1)),("callsetup",(0-3)),
("battchg",(0-5)),("signal",(0-5)),("roam",(0-1)),("callheld",(0-2))
...
> +CIEV: 3,2
< AT+CLCC
> +CIEV: 2,1
> +CIEV: 3,0
> +CLCC: 1,0,0,0,0,"**21153**",129,"Voicemail"
2012-04-11 19:36:38 +00:00
|
|
|
clcc_poll_cb, vc, NULL);
|
2009-11-13 11:28:32 +00:00
|
|
|
break;
|
2009-11-14 04:47:10 +00:00
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
case 3:
|
2009-11-14 04:47:10 +00:00
|
|
|
{
|
|
|
|
GSList *o = g_slist_find_custom(vd->calls,
|
|
|
|
GINT_TO_POINTER(CALL_STATUS_DIALING),
|
|
|
|
at_util_call_compare_by_status);
|
|
|
|
|
|
|
|
if (o) {
|
|
|
|
struct ofono_call *call = o->data;
|
2009-12-09 08:41:16 +00:00
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
call->status = CALL_STATUS_ALERTING;
|
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
}
|
2009-12-09 08:41:16 +00:00
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 04:47:10 +00:00
|
|
|
out:
|
2009-11-03 17:26:08 +00:00
|
|
|
vd->cind_val[HFP_INDICATOR_CALLSETUP] = value;
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
2009-11-13 11:28:32 +00:00
|
|
|
static void ciev_callheld_notify(struct ofono_voicecall *vc,
|
|
|
|
unsigned int value)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
2009-11-14 04:47:10 +00:00
|
|
|
GSList *l;
|
|
|
|
struct ofono_call *call;
|
|
|
|
unsigned int callheld = vd->cind_val[HFP_INDICATOR_CALLHELD];
|
|
|
|
|
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
/* We have to poll here, we have no idea whether the call was
|
|
|
|
* dropped using CHLD=0 or simply retrieved, or the two calls
|
|
|
|
* were merged
|
|
|
|
*/
|
|
|
|
g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix,
|
|
|
|
clcc_poll_cb, vc, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2011-07-25 14:42:19 +00:00
|
|
|
if (vd->clcc_source) {
|
|
|
|
g_source_remove(vd->clcc_source);
|
|
|
|
vd->clcc_source = 0;
|
|
|
|
}
|
|
|
|
|
2009-11-18 06:55:15 +00:00
|
|
|
/* We have to poll here, we have no idea whether the call was
|
|
|
|
* accepted by CHLD=1 or swapped by CHLD=2 or one call was
|
|
|
|
* chosed for private chat by CHLD=2x
|
|
|
|
*/
|
|
|
|
g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix,
|
|
|
|
clcc_poll_cb, vc, NULL);
|
2009-11-14 04:47:10 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (callheld == 0) {
|
|
|
|
for (l = vd->calls; l; l = l->next) {
|
|
|
|
call = l->data;
|
|
|
|
|
|
|
|
if (call->status != CALL_STATUS_ACTIVE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
call->status = CALL_STATUS_HELD;
|
|
|
|
ofono_voicecall_notify(vc, call);
|
|
|
|
}
|
2009-12-18 03:44:09 +00:00
|
|
|
} else if (callheld == 1) {
|
2011-07-25 14:42:19 +00:00
|
|
|
if (vd->clcc_source)
|
|
|
|
g_source_remove(vd->clcc_source);
|
|
|
|
|
|
|
|
/* We have to schedule a poll here, we have no idea
|
|
|
|
* whether active call was dropped by remote or if this
|
|
|
|
* is an intermediate state during call swap
|
|
|
|
*/
|
|
|
|
vd->clcc_source = g_timeout_add(POLL_CLCC_DELAY,
|
|
|
|
poll_clcc, vc);
|
hfpmodem: Handle repeated held call indicator
An issue with iPhone 5C iOS 9.2 triggers desynchronization in call
states. When an active call is put on hold and another call arrives,
it is in WAITING state. It should be possible to answer it by issuing
AT+CHLD=2 but the phone changes its state to INCOMING so ATA should be
used. This change is advertised by sending callheld:2 event, but it is
not handled. This event can be used to trigger CLCC poll to synchronize
call states.
+CIEV: 3,1 <- first call arrives
AT+CLCC
+CLCC: 1,1,4,0,0,"01234567890",129
OK
RING
+CLIP: "01234567890",129
ATA
OK
+CIEV: 2,1
+CIEV: 3,0.
AT+CHLD=2.$ <- first call is put on hold
OK
+CIEV: 7,2 <- notification confirming that call #1 is on hold
+CCWA: "09876543210",129,1 <- second call arrives
+CIEV: 7,2
+CIEV: 3,1
AT+CLCC
+CLCC: 1,1,1,0,0,"01234567890",129
+CLCC: 2,1,5,0,0,"09876543210",129 <- new call is still in WAITING state
OK
+CIEV: 7,2 <- phone iternally promotes WAITING call to INCOMING
AT+CHLD=2 <- there is no WAITING call anymore, ATA should be used
+CME ERROR:3
2016-01-12 15:03:29 +00:00
|
|
|
} else {
|
|
|
|
if (vd->clcc_source)
|
|
|
|
g_source_remove(vd->clcc_source);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We got a notification that there is a held call
|
|
|
|
* and no active call but we already are in such state.
|
|
|
|
* Let's schedule a poll to see what happened.
|
|
|
|
*/
|
|
|
|
vd->clcc_source = g_timeout_add(POLL_CLCC_DELAY,
|
|
|
|
poll_clcc, vc);
|
2009-12-18 03:44:09 +00:00
|
|
|
}
|
2009-11-14 04:47:10 +00:00
|
|
|
}
|
2009-11-13 11:28:32 +00:00
|
|
|
|
|
|
|
vd->cind_val[HFP_INDICATOR_CALLHELD] = value;
|
|
|
|
}
|
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
static void ciev_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_voicecall *vc = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
int index;
|
|
|
|
int value;
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CIEV:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &index))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &value))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (index == vd->cind_pos[HFP_INDICATOR_CALL])
|
2009-11-14 04:47:10 +00:00
|
|
|
ciev_call_notify(vc, value);
|
2009-10-28 11:01:24 +00:00
|
|
|
else if (index == vd->cind_pos[HFP_INDICATOR_CALLSETUP])
|
2009-11-14 04:47:10 +00:00
|
|
|
ciev_callsetup_notify(vc, value);
|
2009-11-13 11:28:32 +00:00
|
|
|
else if (index == vd->cind_pos[HFP_INDICATOR_CALLHELD])
|
2009-11-14 04:47:10 +00:00
|
|
|
ciev_callheld_notify(vc, value);
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 22:51:53 +00:00
|
|
|
static void hfp_clcc_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_voicecall *vc = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
2013-09-10 15:58:14 +00:00
|
|
|
unsigned int mpty_ids;
|
2015-06-03 17:25:50 +00:00
|
|
|
GSList *n;
|
|
|
|
struct ofono_call *nc;
|
|
|
|
unsigned int num_active = 0;
|
|
|
|
unsigned int num_held = 0;
|
2009-12-04 22:51:53 +00:00
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
2013-09-10 15:58:14 +00:00
|
|
|
vd->calls = at_util_parse_clcc(result, &mpty_ids);
|
2009-12-04 22:51:53 +00:00
|
|
|
|
2013-01-21 15:30:22 +00:00
|
|
|
g_slist_foreach(vd->calls, voicecall_notify, vc);
|
2013-09-10 15:58:14 +00:00
|
|
|
ofono_voicecall_mpty_hint(vc, mpty_ids);
|
2015-06-03 17:25:50 +00:00
|
|
|
|
|
|
|
n = vd->calls;
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
nc = n->data;
|
|
|
|
|
|
|
|
if (nc->status == CALL_STATUS_ACTIVE)
|
|
|
|
num_active++;
|
|
|
|
else if (nc->status == CALL_STATUS_HELD)
|
|
|
|
num_held++;
|
|
|
|
|
|
|
|
n = n->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((num_active > 1 || num_held > 1) && !vd->clcc_source)
|
|
|
|
vd->clcc_source = g_timeout_add(POLL_CLCC_INTERVAL, poll_clcc, vc);
|
2009-12-04 22:51:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
static void hfp_voicecall_initialized(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_voicecall *vc = user_data;
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("hfp_voicecall_init: registering to notifications");
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
g_at_chat_register(vd->chat, "RING", ring_notify, FALSE, vc, NULL);
|
|
|
|
g_at_chat_register(vd->chat, "+CLIP:", clip_notify, FALSE, vc, NULL);
|
|
|
|
g_at_chat_register(vd->chat, "+CIEV:", ciev_notify, FALSE, vc, NULL);
|
2009-11-14 04:47:10 +00:00
|
|
|
g_at_chat_register(vd->chat, "+CCWA:", ccwa_notify, FALSE, vc, NULL);
|
|
|
|
|
|
|
|
g_at_chat_register(vd->chat, "NO CARRIER",
|
|
|
|
no_carrier_notify, FALSE, vc, NULL);
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
ofono_voicecall_register(vc);
|
2009-12-04 22:51:53 +00:00
|
|
|
|
|
|
|
/* Populate the call list */
|
|
|
|
g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix, hfp_clcc_cb, vc, NULL);
|
2009-10-28 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hfp_voicecall_probe(struct ofono_voicecall *vc, unsigned int vendor,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-07-20 19:55:31 +00:00
|
|
|
struct hfp_slc_info *info = user_data;
|
2009-10-28 11:01:24 +00:00
|
|
|
struct voicecall_data *vd;
|
|
|
|
|
|
|
|
vd = g_new0(struct voicecall_data, 1);
|
2009-10-28 22:40:06 +00:00
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
vd->chat = g_at_chat_clone(info->chat);
|
|
|
|
vd->ag_features = info->ag_features;
|
|
|
|
vd->ag_mpty_features = info->ag_mpty_features;
|
2009-10-28 22:40:06 +00:00
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
memcpy(vd->cind_pos, info->cind_pos, HFP_INDICATOR_LAST);
|
|
|
|
memcpy(vd->cind_val, info->cind_val, HFP_INDICATOR_LAST);
|
2009-10-28 11:01:24 +00:00
|
|
|
|
|
|
|
ofono_voicecall_set_data(vc, vd);
|
|
|
|
|
2015-02-20 16:30:21 +00:00
|
|
|
g_at_chat_send(vd->chat, "AT+CLIP=1", none_prefix, NULL, NULL, NULL);
|
|
|
|
g_at_chat_send(vd->chat, "AT+CCWA=1", none_prefix,
|
2009-10-28 11:01:24 +00:00
|
|
|
hfp_voicecall_initialized, vc, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_voicecall_remove(struct ofono_voicecall *vc)
|
|
|
|
{
|
|
|
|
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
|
|
|
|
|
2009-12-09 00:59:13 +00:00
|
|
|
if (vd->clcc_source)
|
|
|
|
g_source_remove(vd->clcc_source);
|
|
|
|
|
2009-12-09 05:07:35 +00:00
|
|
|
if (vd->clip_source)
|
|
|
|
g_source_remove(vd->clip_source);
|
|
|
|
|
hfpmodem: Fix release-and-swap without +CIEV
Some phones do not send the corresponding call state update (+CIEV)
after a successful release-and-swap operation (AT+CHLD=1).
This has been observed with a Nokia 500, while testing ReleaseAndSwap()
while an active and a held call exist:
ofonod[20414]: > AT+CLCC\r
ofonod[20414]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20414]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20414]: < \r\nOK\r\n
ofonod[20414]: > AT+CHLD=1\r
ofonod[20414]: < \r\nOK\r\n
After this, no +CIEV is received, but the call has been hung up.
The proposed approach to solve this consists of using AT+CLCC, unless
a call release has been received within a specific time period.
The result fixes the problem as can be seen below:
ofonod[20847]: < \r\n+CLCC: 1,0,1,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\n+CLCC: 2,0,0,0,0,"<number2>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CHLD=1\r
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: > AT+CLCC\r
ofonod[20847]: < \r\n+CLCC: 1,0,0,0,0,"<number1>",145\r\n
ofonod[20847]: < \r\nOK\r\n
ofonod[20847]: < \r\n+CIEV: 5,2\r\n
ofonod[20847]: < \r\n+CIEV: 5,0\r\n
2013-01-21 15:30:24 +00:00
|
|
|
if (vd->expect_release_source)
|
|
|
|
g_source_remove(vd->expect_release_source);
|
|
|
|
|
2016-04-22 13:10:06 +00:00
|
|
|
g_slist_free_full(vd->calls, g_free);
|
2009-11-12 16:31:03 +00:00
|
|
|
|
|
|
|
ofono_voicecall_set_data(vc, NULL);
|
|
|
|
|
2011-08-04 12:48:02 +00:00
|
|
|
g_at_chat_unref(vd->chat);
|
2009-10-28 11:01:24 +00:00
|
|
|
g_free(vd);
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:36:10 +00:00
|
|
|
static const struct ofono_voicecall_driver driver = {
|
2009-10-28 11:01:24 +00:00
|
|
|
.name = "hfpmodem",
|
|
|
|
.probe = hfp_voicecall_probe,
|
|
|
|
.remove = hfp_voicecall_remove,
|
|
|
|
.dial = hfp_dial,
|
2017-10-31 08:39:34 +00:00
|
|
|
.dial_last = hfp_dial_last,
|
2018-02-12 18:37:17 +00:00
|
|
|
.dial_memory = hfp_dial_memory,
|
2009-10-28 11:01:24 +00:00
|
|
|
.answer = hfp_answer,
|
2010-08-09 21:18:37 +00:00
|
|
|
.hangup_active = hfp_hangup,
|
2009-11-14 04:47:10 +00:00
|
|
|
.hold_all_active = hfp_hold_all_active,
|
|
|
|
.release_all_held = hfp_release_all_held,
|
|
|
|
.set_udub = hfp_set_udub,
|
|
|
|
.release_all_active = hfp_release_all_active,
|
2009-12-09 00:55:55 +00:00
|
|
|
.release_specific = hfp_release_specific,
|
2009-12-09 02:16:53 +00:00
|
|
|
.private_chat = hfp_private_chat,
|
|
|
|
.create_multiparty = hfp_create_multiparty,
|
|
|
|
.transfer = hfp_transfer,
|
2009-10-28 11:01:24 +00:00
|
|
|
.deflect = NULL,
|
|
|
|
.swap_without_accept = NULL,
|
2009-12-04 03:22:14 +00:00
|
|
|
.send_tones = hfp_send_dtmf
|
2009-10-28 11:01:24 +00:00
|
|
|
};
|
|
|
|
|
2011-01-12 10:52:07 +00:00
|
|
|
void hfp_voicecall_init(void)
|
2009-10-28 11:01:24 +00:00
|
|
|
{
|
|
|
|
ofono_voicecall_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
2011-01-12 10:52:07 +00:00
|
|
|
void hfp_voicecall_exit(void)
|
2009-10-28 11:01:24 +00:00
|
|
|
{
|
|
|
|
ofono_voicecall_driver_unregister(&driver);
|
|
|
|
}
|