2009-08-24 12:47:17 +00:00
|
|
|
/*
|
|
|
|
*
|
2010-10-14 07:50:08 +00:00
|
|
|
* oFono - Open Source Telephony
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
2010-10-14 07:50:08 +00:00
|
|
|
* Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
2010-10-14 07:50:08 +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.
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
2010-10-14 07:50:08 +00:00
|
|
|
* 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.
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
2010-10-14 07:50:08 +00:00
|
|
|
* 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
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-02-09 18:27:22 +00:00
|
|
|
#include <sys/uio.h>
|
2009-08-24 12:47:17 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <gisi/client.h>
|
|
|
|
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/ussd.h>
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
#include "smsutil.h"
|
|
|
|
#include "util.h"
|
2009-08-24 12:47:17 +00:00
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
#include "isimodem.h"
|
|
|
|
#include "isiutil.h"
|
|
|
|
#include "ss.h"
|
|
|
|
#include "debug.h"
|
2009-08-24 12:47:17 +00:00
|
|
|
|
|
|
|
struct ussd_data {
|
|
|
|
GIsiClient *client;
|
2010-09-16 17:32:49 +00:00
|
|
|
int mt_session;
|
2009-08-24 12:47:17 +00:00
|
|
|
};
|
|
|
|
|
2010-09-16 17:32:49 +00:00
|
|
|
static void ussd_notify_ack(struct ussd_data *ud)
|
2010-02-09 18:27:22 +00:00
|
|
|
{
|
2010-09-16 17:32:49 +00:00
|
|
|
const unsigned char msg[] = {
|
|
|
|
SS_GSM_USSD_SEND_REQ,
|
|
|
|
SS_GSM_USSD_NOTIFY,
|
|
|
|
0x00 /* subblock count */
|
|
|
|
};
|
|
|
|
|
|
|
|
g_isi_send(ud->client, msg, sizeof(msg), SS_TIMEOUT, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ussd_ind_cb(GIsiClient *client,
|
|
|
|
const void *restrict data, size_t len,
|
|
|
|
uint16_t object, void *opaque)
|
|
|
|
{
|
|
|
|
const unsigned char *msg = data;
|
|
|
|
struct ofono_ussd *ussd = opaque;
|
|
|
|
struct ussd_data *ud = ofono_ussd_get_data(ussd);
|
|
|
|
int dcs;
|
|
|
|
int type;
|
|
|
|
size_t ussdlen;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!msg || len < 4 || msg[0] != SS_GSM_USSD_RECEIVE_IND)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dcs = msg[1];
|
|
|
|
type = msg[2];
|
|
|
|
ussdlen = msg[3];
|
|
|
|
|
|
|
|
if (len < 4 + ussdlen)
|
|
|
|
ussdlen = len - 4;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
switch (type) {
|
2010-09-16 17:32:49 +00:00
|
|
|
case 0:
|
|
|
|
/* Nothing - this is response to NOTIFY_ACK REQ */
|
|
|
|
return;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
case SS_GSM_USSD_MT_REPLY:
|
2010-09-16 17:32:49 +00:00
|
|
|
/* This never happens, but.. */
|
|
|
|
status = OFONO_USSD_STATUS_LOCAL_CLIENT_RESPONDED;
|
|
|
|
break;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
case SS_GSM_USSD_COMMAND:
|
2010-09-16 17:32:49 +00:00
|
|
|
if (ud->mt_session)
|
|
|
|
/* Ignore, we get SS_GSM_USSD_REQUEST, too */
|
|
|
|
return;
|
|
|
|
status = OFONO_USSD_STATUS_ACTION_REQUIRED;
|
|
|
|
break;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
case SS_GSM_USSD_NOTIFY:
|
2010-09-16 17:32:49 +00:00
|
|
|
status = OFONO_USSD_STATUS_NOTIFY;
|
|
|
|
ussd_notify_ack(ud);
|
|
|
|
break;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
case SS_GSM_USSD_END:
|
2010-09-16 17:32:49 +00:00
|
|
|
status = OFONO_USSD_STATUS_TERMINATED;
|
|
|
|
ud->mt_session = 0;
|
|
|
|
break;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
case SS_GSM_USSD_REQUEST:
|
2010-09-16 17:32:49 +00:00
|
|
|
ud->mt_session = 1;
|
|
|
|
status = OFONO_USSD_STATUS_ACTION_REQUIRED;
|
|
|
|
break;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
default:
|
2010-09-16 17:32:49 +00:00
|
|
|
status = OFONO_USSD_STATUS_NOT_SUPPORTED;
|
2010-02-09 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 18:53:26 +00:00
|
|
|
DBG("type: %u %s, dcs: 0x%02x, len: %zu",
|
2010-09-16 17:32:49 +00:00
|
|
|
type, ss_ussd_type_name(type), dcs, ussdlen);
|
2010-02-09 18:27:22 +00:00
|
|
|
|
2010-09-16 17:32:49 +00:00
|
|
|
ofono_ussd_notify(ussd, status, dcs, msg + 4, ussdlen);
|
2010-02-09 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:12:46 +00:00
|
|
|
static gboolean ussd_send_resp_cb(GIsiClient *client,
|
|
|
|
const void *restrict data, size_t len,
|
|
|
|
uint16_t object, void *opaque)
|
2010-02-09 18:27:22 +00:00
|
|
|
{
|
|
|
|
const unsigned char *msg = data;
|
|
|
|
struct isi_cb_data *cbd = opaque;
|
|
|
|
ofono_ussd_cb_t cb = cbd->cb;
|
|
|
|
|
|
|
|
if (!msg) {
|
|
|
|
DBG("ISI client error: %d", g_isi_client_error(client));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len < 3)
|
2010-05-27 16:12:46 +00:00
|
|
|
return FALSE;
|
2010-02-09 18:27:22 +00:00
|
|
|
|
|
|
|
if (msg[0] == SS_SERVICE_FAILED_RESP)
|
|
|
|
goto error;
|
|
|
|
|
2010-09-16 17:32:49 +00:00
|
|
|
if (msg[0] != SS_GSM_USSD_SEND_RESP)
|
2010-05-27 16:12:46 +00:00
|
|
|
return FALSE;
|
2010-02-09 18:27:22 +00:00
|
|
|
|
|
|
|
CALLBACK_WITH_SUCCESS(cb, cbd->data);
|
|
|
|
|
2010-09-01 12:03:43 +00:00
|
|
|
return TRUE;
|
2010-02-09 18:27:22 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
CALLBACK_WITH_FAILURE(cb, cbd->data);
|
2010-05-27 16:12:46 +00:00
|
|
|
return TRUE;
|
2010-09-01 12:03:43 +00:00
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 17:32:49 +00:00
|
|
|
static void isi_request(struct ofono_ussd *ussd, int dcs,
|
|
|
|
const unsigned char *pdu, int len,
|
|
|
|
ofono_ussd_cb_t cb, void *data)
|
2010-02-09 18:27:22 +00:00
|
|
|
{
|
2010-09-16 17:32:49 +00:00
|
|
|
struct ussd_data *ud = ofono_ussd_get_data(ussd);
|
|
|
|
struct isi_cb_data *cbd = isi_cb_data_new(ussd, cb, data);
|
2010-02-09 18:27:22 +00:00
|
|
|
const uint8_t msg[] = {
|
|
|
|
SS_GSM_USSD_SEND_REQ,
|
2010-09-16 17:32:49 +00:00
|
|
|
ud->mt_session
|
|
|
|
? SS_GSM_USSD_MT_REPLY
|
|
|
|
: SS_GSM_USSD_COMMAND,
|
2010-08-25 10:03:27 +00:00
|
|
|
0x01, /* subblock count */
|
2010-02-09 18:27:22 +00:00
|
|
|
SS_GSM_USSD_STRING,
|
2010-08-25 10:03:27 +00:00
|
|
|
4 + len + 3, /* subblock length */
|
2010-09-14 21:23:14 +00:00
|
|
|
dcs, /* DCS */
|
2010-08-25 10:03:27 +00:00
|
|
|
len, /* string length */
|
2010-02-09 18:27:22 +00:00
|
|
|
/* USSD string goes here */
|
|
|
|
};
|
|
|
|
const struct iovec iov[2] = {
|
|
|
|
{ (uint8_t *)msg, sizeof(msg) },
|
2010-09-16 17:32:49 +00:00
|
|
|
{ (uint8_t *)pdu, len }
|
2010-02-09 18:27:22 +00:00
|
|
|
};
|
|
|
|
|
2010-10-19 08:28:06 +00:00
|
|
|
if (!cbd || !ud)
|
2010-02-09 18:27:22 +00:00
|
|
|
goto error;
|
|
|
|
|
2010-09-16 17:32:49 +00:00
|
|
|
if (g_isi_vsend(ud->client, iov, 2, SS_TIMEOUT,
|
|
|
|
ussd_send_resp_cb, cbd, g_free))
|
2010-02-09 18:27:22 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
g_free(cbd);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isi_cancel(struct ofono_ussd *ussd,
|
|
|
|
ofono_ussd_cb_t cb, void *data)
|
|
|
|
{
|
2010-02-09 18:27:22 +00:00
|
|
|
struct ussd_data *ud = ofono_ussd_get_data(ussd);
|
|
|
|
struct isi_cb_data *cbd = isi_cb_data_new(ussd, cb, data);
|
|
|
|
|
|
|
|
const unsigned char msg[] = {
|
|
|
|
SS_GSM_USSD_SEND_REQ,
|
|
|
|
SS_GSM_USSD_END,
|
2010-08-25 10:03:27 +00:00
|
|
|
0x00 /* subblock count */
|
2010-02-09 18:27:22 +00:00
|
|
|
};
|
|
|
|
|
2010-10-19 08:28:06 +00:00
|
|
|
if (!cbd || !ud)
|
2010-02-09 18:27:22 +00:00
|
|
|
goto error;
|
|
|
|
|
2010-09-01 12:03:43 +00:00
|
|
|
if (g_isi_send(ud->client, msg, sizeof(msg), SS_TIMEOUT,
|
|
|
|
ussd_send_resp_cb, cbd, g_free))
|
2010-02-09 18:27:22 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
g_free(cbd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean isi_ussd_register(gpointer user)
|
|
|
|
{
|
|
|
|
struct ofono_ussd *ussd = user;
|
|
|
|
struct ussd_data *ud = ofono_ussd_get_data(ussd);
|
|
|
|
|
|
|
|
const char *debug = getenv("OFONO_ISI_DEBUG");
|
|
|
|
|
|
|
|
if (debug && (strcmp(debug, "all") == 0 || strcmp(debug, "ussd") == 0))
|
|
|
|
g_isi_client_set_debug(ud->client, ss_debug, NULL);
|
|
|
|
|
|
|
|
g_isi_subscribe(ud->client, SS_GSM_USSD_RECEIVE_IND, ussd_ind_cb, ussd);
|
|
|
|
ofono_ussd_register(ussd);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-27 16:12:46 +00:00
|
|
|
static void ussd_reachable_cb(GIsiClient *client,
|
|
|
|
gboolean alive, uint16_t object,
|
2010-02-09 18:27:22 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
struct ofono_ussd *ussd = opaque;
|
|
|
|
|
|
|
|
if (!alive) {
|
2010-03-22 15:05:46 +00:00
|
|
|
DBG("Unable to bootstrap ussd driver");
|
2010-02-09 18:27:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG("%s (v%03d.%03d) reachable",
|
|
|
|
pn_resource_name(g_isi_client_resource(client)),
|
|
|
|
g_isi_version_major(client),
|
|
|
|
g_isi_version_minor(client));
|
|
|
|
|
|
|
|
g_idle_add(isi_ussd_register, ussd);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 02:39:02 +00:00
|
|
|
static int isi_ussd_probe(struct ofono_ussd *ussd, unsigned int vendor,
|
|
|
|
void *user)
|
2009-08-24 12:47:17 +00:00
|
|
|
{
|
2009-09-01 23:00:58 +00:00
|
|
|
GIsiModem *idx = user;
|
2010-02-09 18:27:22 +00:00
|
|
|
struct ussd_data *ud = g_try_new0(struct ussd_data, 1);
|
2009-08-24 12:47:17 +00:00
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
if (!ud)
|
2009-08-24 12:47:17 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
ud->client = g_isi_client_create(idx, PN_SS);
|
|
|
|
if (!ud->client)
|
2009-08-24 12:47:17 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-02-09 18:27:22 +00:00
|
|
|
ofono_ussd_set_data(ussd, ud);
|
|
|
|
g_isi_verify(ud->client, ussd_reachable_cb, ussd);
|
2009-08-24 12:47:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 03:27:08 +00:00
|
|
|
static void isi_ussd_remove(struct ofono_ussd *ussd)
|
2009-08-24 12:47:17 +00:00
|
|
|
{
|
|
|
|
struct ussd_data *data = ofono_ussd_get_data(ussd);
|
|
|
|
|
2010-04-27 12:10:55 +00:00
|
|
|
if (!data)
|
|
|
|
return;
|
2010-02-09 18:27:22 +00:00
|
|
|
|
2010-04-27 12:10:55 +00:00
|
|
|
ofono_ussd_set_data(ussd, NULL);
|
|
|
|
g_isi_client_destroy(data->client);
|
2010-02-09 18:27:22 +00:00
|
|
|
g_free(data);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ofono_ussd_driver driver = {
|
2009-09-02 03:35:14 +00:00
|
|
|
.name = "isimodem",
|
2009-08-24 12:47:17 +00:00
|
|
|
.probe = isi_ussd_probe,
|
|
|
|
.remove = isi_ussd_remove,
|
|
|
|
.request = isi_request,
|
|
|
|
.cancel = isi_cancel
|
|
|
|
};
|
|
|
|
|
|
|
|
void isi_ussd_init()
|
|
|
|
{
|
|
|
|
ofono_ussd_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void isi_ussd_exit()
|
|
|
|
{
|
|
|
|
ofono_ussd_driver_unregister(&driver);
|
|
|
|
}
|