2010-05-12 01:21:17 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
2011-10-10 20:39:48 +00:00
|
|
|
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
|
2010-05-12 01:21:17 +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>
|
2010-09-23 16:05:26 +00:00
|
|
|
#include <errno.h>
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/stk.h>
|
|
|
|
|
|
|
|
#include "gatchat.h"
|
|
|
|
#include "gatresult.h"
|
|
|
|
|
|
|
|
#include "mbmmodem.h"
|
|
|
|
|
|
|
|
struct stk_data {
|
|
|
|
GAtChat *chat;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *none_prefix[] = { NULL };
|
2010-09-23 16:07:03 +00:00
|
|
|
static const char *stke_prefix[] = { "*STKE:", NULL };
|
2010-05-12 01:21:17 +00:00
|
|
|
|
2010-09-23 16:05:26 +00:00
|
|
|
static void stke_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
2010-05-12 01:21:17 +00:00
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_stk_envelope_cb_t cb = cbd->cb;
|
|
|
|
GAtResultIter iter;
|
|
|
|
struct ofono_error error;
|
2010-06-17 13:42:11 +00:00
|
|
|
const guint8 *pdu = NULL;
|
|
|
|
gint len = 0;
|
2010-05-12 01:21:17 +00:00
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2010-05-12 01:21:17 +00:00
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
2010-09-26 12:38:48 +00:00
|
|
|
if (!ok)
|
|
|
|
goto done;
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
2010-09-23 16:13:01 +00:00
|
|
|
if (g_at_result_iter_next(&iter, "*STKE:") == FALSE)
|
2010-09-26 12:38:48 +00:00
|
|
|
goto done;
|
2010-09-23 16:13:01 +00:00
|
|
|
|
2010-09-26 12:43:57 +00:00
|
|
|
/* Response data is optional */
|
2010-09-23 16:13:01 +00:00
|
|
|
g_at_result_iter_next_hexstring(&iter, &pdu, &len);
|
|
|
|
|
|
|
|
DBG("len %d", len);
|
2010-05-12 01:21:17 +00:00
|
|
|
|
2010-09-26 12:38:48 +00:00
|
|
|
done:
|
2010-05-12 01:21:17 +00:00
|
|
|
cb(&error, pdu, len, cbd->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mbm_stk_envelope(struct ofono_stk *stk, int length,
|
|
|
|
const unsigned char *command,
|
|
|
|
ofono_stk_envelope_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
char *buf = g_try_new(char, 64 + length * 2);
|
2010-09-23 16:05:26 +00:00
|
|
|
int len;
|
2010-05-12 01:21:17 +00:00
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2011-01-29 13:34:41 +00:00
|
|
|
if (buf == NULL)
|
2010-05-12 01:21:17 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
len = sprintf(buf, "AT*STKE=\"");
|
|
|
|
for (; length; length--)
|
|
|
|
len += sprintf(buf + len, "%02hhX", *command++);
|
|
|
|
len += sprintf(buf + len, "\"");
|
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("%s", buf);
|
|
|
|
|
2010-09-23 16:05:26 +00:00
|
|
|
if (g_at_chat_send(sd->chat, buf, stke_prefix,
|
|
|
|
stke_cb, cbd, g_free) > 0) {
|
|
|
|
g_free(buf);
|
2010-05-12 01:21:17 +00:00
|
|
|
return;
|
2010-09-23 16:05:26 +00:00
|
|
|
}
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
error:
|
2010-05-12 18:09:08 +00:00
|
|
|
g_free(buf);
|
|
|
|
g_free(cbd);
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
|
|
|
}
|
|
|
|
|
2010-09-23 16:05:26 +00:00
|
|
|
static void stkr_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
2010-05-12 01:21:17 +00:00
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_stk_generic_cb_t cb = cbd->cb;
|
|
|
|
struct ofono_error error;
|
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2010-05-12 01:21:17 +00:00
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
2010-05-12 18:42:19 +00:00
|
|
|
cb(&error, cbd->data);
|
2010-05-12 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mbm_stk_terminal_response(struct ofono_stk *stk, int length,
|
2010-05-12 18:08:35 +00:00
|
|
|
const unsigned char *command,
|
|
|
|
ofono_stk_generic_cb_t cb, void *data)
|
2010-05-12 01:21:17 +00:00
|
|
|
{
|
|
|
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
char *buf = g_try_new(char, 64 + length * 2);
|
2010-09-23 16:05:26 +00:00
|
|
|
int len;
|
2010-05-12 01:21:17 +00:00
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2011-01-29 13:34:41 +00:00
|
|
|
if (buf == NULL)
|
2010-05-12 01:21:17 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
len = sprintf(buf, "AT*STKR=\"");
|
|
|
|
for (; length; length--)
|
|
|
|
len += sprintf(buf + len, "%02hhX", *command++);
|
|
|
|
len += sprintf(buf + len, "\"");
|
|
|
|
|
2010-09-23 16:05:26 +00:00
|
|
|
DBG("%s", buf);
|
2010-05-12 01:21:17 +00:00
|
|
|
|
2010-09-23 16:05:26 +00:00
|
|
|
if (g_at_chat_send(sd->chat, buf, none_prefix,
|
|
|
|
stkr_cb, cbd, g_free) > 0) {
|
|
|
|
g_free(buf);
|
2010-05-12 01:21:17 +00:00
|
|
|
return;
|
2010-09-23 16:05:26 +00:00
|
|
|
}
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
error:
|
2010-05-12 18:09:08 +00:00
|
|
|
g_free(buf);
|
|
|
|
g_free(cbd);
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stki_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_stk *stk = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
const guint8 *pdu;
|
|
|
|
gint len;
|
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2010-05-12 01:21:17 +00:00
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "*STKI:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_hexstring(&iter, &pdu, &len))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ofono_stk_proactive_command_notify(stk, len, pdu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stkn_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2010-10-27 17:20:37 +00:00
|
|
|
struct ofono_stk *stk = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
const guint8 *pdu;
|
|
|
|
gint len;
|
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2010-10-27 17:20:37 +00:00
|
|
|
/* Proactive command has been handled by the modem. */
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (g_at_result_iter_next(&iter, "*STKN:") == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ofono_stk_proactive_command_handled_notify(stk, len, pdu);
|
2010-05-12 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void stkend_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2010-07-06 22:38:57 +00:00
|
|
|
struct ofono_stk *stk = user_data;
|
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2010-07-06 22:38:57 +00:00
|
|
|
ofono_stk_proactive_session_end_notify(stk);
|
2010-05-12 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mbm_stkc_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2010-06-16 08:38:08 +00:00
|
|
|
struct ofono_stk *stk = user_data;
|
2010-05-12 01:21:17 +00:00
|
|
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2010-06-16 08:38:08 +00:00
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
2010-05-12 01:21:17 +00:00
|
|
|
g_at_chat_register(sd->chat, "*STKI:", stki_notify, FALSE, stk, NULL);
|
|
|
|
g_at_chat_register(sd->chat, "*STKN:", stkn_notify, FALSE, stk, NULL);
|
|
|
|
g_at_chat_register(sd->chat, "*STKEND",
|
2010-05-12 18:08:35 +00:00
|
|
|
stkend_notify, FALSE, stk, NULL);
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
ofono_stk_register(stk);
|
|
|
|
}
|
|
|
|
|
2010-05-12 18:08:35 +00:00
|
|
|
static int mbm_stk_probe(struct ofono_stk *stk, unsigned int vendor, void *data)
|
2010-05-12 01:21:17 +00:00
|
|
|
{
|
|
|
|
GAtChat *chat = data;
|
|
|
|
struct stk_data *sd;
|
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2010-09-23 16:05:26 +00:00
|
|
|
sd = g_try_new0(struct stk_data, 1);
|
2010-11-27 19:38:56 +00:00
|
|
|
if (sd == NULL)
|
2010-09-23 16:05:26 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-08-13 04:40:00 +00:00
|
|
|
sd->chat = g_at_chat_clone(chat);
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
ofono_stk_set_data(stk, sd);
|
2010-06-16 08:38:08 +00:00
|
|
|
|
|
|
|
/* Perform PROFILE DOWNLOAD and enable *STKI / *STKN */
|
|
|
|
g_at_chat_send(sd->chat, "AT*STKC=1,\"19E1FFFF0000FF7FFF03FEFF\"",
|
|
|
|
none_prefix, mbm_stkc_cb, stk, NULL);
|
2010-05-12 01:21:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mbm_stk_remove(struct ofono_stk *stk)
|
|
|
|
{
|
|
|
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
|
|
|
|
2010-08-11 18:18:44 +00:00
|
|
|
DBG("");
|
|
|
|
|
2010-05-12 01:21:17 +00:00
|
|
|
ofono_stk_set_data(stk, NULL);
|
|
|
|
|
2010-08-13 04:40:00 +00:00
|
|
|
g_at_chat_unref(sd->chat);
|
2010-05-12 01:21:17 +00:00
|
|
|
g_free(sd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ofono_stk_driver driver = {
|
|
|
|
.name = "mbmmodem",
|
|
|
|
.probe = mbm_stk_probe,
|
|
|
|
.remove = mbm_stk_remove,
|
|
|
|
.envelope = mbm_stk_envelope,
|
|
|
|
.terminal_response = mbm_stk_terminal_response,
|
|
|
|
};
|
|
|
|
|
2011-01-12 10:52:06 +00:00
|
|
|
void mbm_stk_init(void)
|
2010-05-12 01:21:17 +00:00
|
|
|
{
|
|
|
|
ofono_stk_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
2011-01-12 10:52:06 +00:00
|
|
|
void mbm_stk_exit(void)
|
2010-05-12 01:21:17 +00:00
|
|
|
{
|
|
|
|
ofono_stk_driver_unregister(&driver);
|
|
|
|
}
|