2010-09-23 15:59:13 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2010 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 <errno.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/stk.h>
|
|
|
|
|
|
|
|
#include "gatchat.h"
|
|
|
|
#include "gatresult.h"
|
|
|
|
|
|
|
|
#include "ifxmodem.h"
|
|
|
|
|
|
|
|
struct stk_data {
|
|
|
|
GAtChat *chat;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *none_prefix[] = { NULL };
|
|
|
|
static const char *sate_prefix[] = { "+SATE:", NULL };
|
2011-01-13 13:27:27 +00:00
|
|
|
static const char *xsatk_prefix[] = { "+XSATK:", NULL };
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
static void sate_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_stk_envelope_cb_t cb = cbd->cb;
|
|
|
|
GAtResultIter iter;
|
|
|
|
struct ofono_error error;
|
|
|
|
int sw1, sw2, envelope, event;
|
|
|
|
const guint8 *pdu = NULL;
|
|
|
|
gint len = 0;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
2010-09-26 12:47:19 +00:00
|
|
|
if (!ok)
|
|
|
|
goto done;
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (g_at_result_iter_next(&iter, "+SATE:") == FALSE)
|
2010-09-26 12:47:19 +00:00
|
|
|
goto done;
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
if (g_at_result_iter_next_number(&iter, &sw1) == FALSE)
|
2010-09-26 12:47:19 +00:00
|
|
|
goto done;
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
if (g_at_result_iter_next_number(&iter, &sw2) == FALSE)
|
2010-09-26 12:47:19 +00:00
|
|
|
goto done;
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
if (g_at_result_iter_next_number(&iter, &envelope) == FALSE)
|
2010-09-26 12:47:19 +00:00
|
|
|
goto done;
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
if (g_at_result_iter_next_number(&iter, &event) == FALSE)
|
2010-09-26 12:47:19 +00:00
|
|
|
goto done;
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
DBG("sw1 %d sw2 %d envelope %d event %d", sw1, sw2, envelope, event);
|
|
|
|
|
2010-09-23 16:13:22 +00:00
|
|
|
/* Response data is optional */
|
|
|
|
g_at_result_iter_next_hexstring(&iter, &pdu, &len);
|
2010-09-23 15:59:13 +00:00
|
|
|
|
2010-09-23 16:13:22 +00:00
|
|
|
DBG("len %d", len);
|
|
|
|
|
2010-09-26 12:47:19 +00:00
|
|
|
done:
|
2010-09-23 16:13:22 +00:00
|
|
|
cb(&error, pdu, len, cbd->data);
|
2010-09-23 15:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ifx_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);
|
|
|
|
int len;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (cbd == NULL || buf == NULL)
|
2010-09-23 15:59:13 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
len = sprintf(buf, "AT+SATE=\"");
|
|
|
|
for (; length; length--)
|
|
|
|
len += sprintf(buf + len, "%02hhX", *command++);
|
|
|
|
len += sprintf(buf + len, "\"");
|
|
|
|
|
|
|
|
DBG("%s", buf);
|
|
|
|
|
|
|
|
if (g_at_chat_send(sd->chat, buf, sate_prefix,
|
|
|
|
sate_cb, cbd, g_free) > 0) {
|
|
|
|
g_free(buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
g_free(buf);
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void satr_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_stk_generic_cb_t cb = cbd->cb;
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ifx_stk_terminal_response(struct ofono_stk *stk, int length,
|
|
|
|
const unsigned char *command,
|
|
|
|
ofono_stk_generic_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);
|
|
|
|
int len;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (cbd == NULL || buf == NULL)
|
2010-09-23 15:59:13 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
len = sprintf(buf, "AT+SATR=\"");
|
|
|
|
for (; length; length--)
|
|
|
|
len += sprintf(buf + len, "%02hhX", *command++);
|
|
|
|
len += sprintf(buf + len, "\"");
|
|
|
|
|
|
|
|
DBG("%s", buf);
|
|
|
|
|
|
|
|
if (g_at_chat_send(sd->chat, buf, none_prefix,
|
|
|
|
satr_cb, cbd, g_free) > 0) {
|
|
|
|
g_free(buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
g_free(buf);
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sati_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_stk *stk = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
const guint8 *pdu;
|
|
|
|
gint len;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (g_at_result_iter_next(&iter, "+SATI:") == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DBG("len %d", len);
|
|
|
|
|
|
|
|
ofono_stk_proactive_command_notify(stk, len, pdu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void satn_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2010-10-27 17:23:26 +00:00
|
|
|
struct ofono_stk *stk = user_data;
|
2010-09-23 15:59:13 +00:00
|
|
|
GAtResultIter iter;
|
|
|
|
const guint8 *pdu;
|
|
|
|
gint len;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
2010-10-27 17:23:26 +00:00
|
|
|
/* Proactive command has been handled by the modem. */
|
2010-10-19 10:16:13 +00:00
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
2010-09-23 15:59:13 +00:00
|
|
|
if (g_at_result_iter_next(&iter, "+SATN:") == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
|
|
|
|
return;
|
|
|
|
|
2010-10-27 17:23:26 +00:00
|
|
|
if (len == 0)
|
|
|
|
return;
|
2010-09-23 15:59:13 +00:00
|
|
|
|
2010-10-27 17:23:26 +00:00
|
|
|
ofono_stk_proactive_command_handled_notify(stk, len, pdu);
|
2010-09-23 15:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void satf_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_stk *stk = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
int sw1, sw2;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (g_at_result_iter_next(&iter, "+SATF:") == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_at_result_iter_next_number(&iter, &sw1) == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_at_result_iter_next_number(&iter, &sw2) == FALSE)
|
|
|
|
return;
|
2010-09-23 16:32:21 +00:00
|
|
|
|
2010-09-23 15:59:13 +00:00
|
|
|
DBG("sw1 %d sw2 %d", sw1, sw2);
|
|
|
|
|
2010-10-20 09:57:22 +00:00
|
|
|
if (sw1 == 0x90 && sw2 == 0x00)
|
|
|
|
ofono_stk_proactive_session_end_notify(stk);
|
2010-09-23 15:59:13 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 13:27:27 +00:00
|
|
|
static void xsatk_support_cb(gboolean ok, GAtResult *result,
|
2010-09-23 15:59:13 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_stk *stk = user_data;
|
|
|
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_at_chat_register(sd->chat, "+SATI:", sati_notify, FALSE, stk, NULL);
|
|
|
|
g_at_chat_register(sd->chat, "+SATN:", satn_notify, FALSE, stk, NULL);
|
|
|
|
g_at_chat_register(sd->chat, "+SATF:", satf_notify, FALSE, stk, NULL);
|
|
|
|
|
2011-01-13 13:27:27 +00:00
|
|
|
g_at_chat_send(sd->chat, "AT+XSATK=1,1", none_prefix, NULL, NULL, NULL);
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
ofono_stk_register(stk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ifx_stk_probe(struct ofono_stk *stk, unsigned int vendor, void *data)
|
|
|
|
{
|
|
|
|
GAtChat *chat = data;
|
|
|
|
struct stk_data *sd;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
sd = g_try_new0(struct stk_data, 1);
|
2010-11-27 19:38:56 +00:00
|
|
|
if (sd == NULL)
|
2010-09-23 15:59:13 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sd->chat = g_at_chat_clone(chat);
|
|
|
|
|
|
|
|
ofono_stk_set_data(stk, sd);
|
|
|
|
|
2011-01-13 13:27:27 +00:00
|
|
|
g_at_chat_send(sd->chat, "AT+XSATK=?", xsatk_prefix, xsatk_support_cb,
|
|
|
|
stk, NULL);
|
2010-09-23 15:59:13 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ifx_stk_remove(struct ofono_stk *stk)
|
|
|
|
{
|
|
|
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
ofono_stk_set_data(stk, NULL);
|
|
|
|
|
|
|
|
g_at_chat_unref(sd->chat);
|
|
|
|
g_free(sd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ofono_stk_driver driver = {
|
|
|
|
.name = "ifxmodem",
|
|
|
|
.probe = ifx_stk_probe,
|
|
|
|
.remove = ifx_stk_remove,
|
|
|
|
.envelope = ifx_stk_envelope,
|
|
|
|
.terminal_response = ifx_stk_terminal_response,
|
|
|
|
};
|
|
|
|
|
2011-01-12 10:52:11 +00:00
|
|
|
void ifx_stk_init(void)
|
2010-09-23 15:59:13 +00:00
|
|
|
{
|
|
|
|
ofono_stk_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
2011-01-12 10:52:11 +00:00
|
|
|
void ifx_stk_exit(void)
|
2010-09-23 15:59:13 +00:00
|
|
|
{
|
|
|
|
ofono_stk_driver_unregister(&driver);
|
|
|
|
}
|