mirror of git://git.sysmocom.de/ofono
calypsomodem: Cleanup of SIM Toolkit support
This commit is contained in:
parent
adf2ffd38b
commit
27018b1a55
|
@ -27,6 +27,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
@ -43,19 +44,20 @@ struct stk_data {
|
||||||
GAtChat *chat;
|
GAtChat *chat;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *sate_prefix[] = { "%SATE:", NULL };
|
|
||||||
static const char *none_prefix[] = { NULL };
|
static const char *none_prefix[] = { NULL };
|
||||||
|
static const char *sate_prefix[] = { "%SATE:", NULL };
|
||||||
|
|
||||||
static void calypso_sate_cb(gboolean ok, GAtResult *result,
|
static void sate_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
struct cb_data *cbd = user_data;
|
struct cb_data *cbd = user_data;
|
||||||
ofono_stk_envelope_cb_t cb = cbd->cb;
|
ofono_stk_envelope_cb_t cb = cbd->cb;
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
struct ofono_error error;
|
struct ofono_error error;
|
||||||
const guint8 *pdu = { 0 };
|
const guint8 *pdu = NULL;
|
||||||
gint len = 0;
|
gint len = 0;
|
||||||
|
|
||||||
|
DBG("");
|
||||||
|
|
||||||
decode_at_error(&error, g_at_result_final_response(result));
|
decode_at_error(&error, g_at_result_final_response(result));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -78,9 +80,13 @@ static void calypso_sate_cb(gboolean ok, GAtResult *result,
|
||||||
|
|
||||||
g_at_result_iter_init(&iter, result);
|
g_at_result_iter_init(&iter, result);
|
||||||
|
|
||||||
if (g_at_result_iter_next(&iter, "%SATE:"))
|
if (g_at_result_iter_next(&iter, "%SATE:") == FALSE)
|
||||||
if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
|
goto error;
|
||||||
goto error;
|
|
||||||
|
/* Response data is optional */
|
||||||
|
g_at_result_iter_next_hexstring(&iter, &pdu, &len);
|
||||||
|
|
||||||
|
DBG("len %d", len);
|
||||||
|
|
||||||
cb(&error, pdu, len, cbd->data);
|
cb(&error, pdu, len, cbd->data);
|
||||||
return;
|
return;
|
||||||
|
@ -96,26 +102,25 @@ static void calypso_stk_envelope(struct ofono_stk *stk, int length,
|
||||||
struct stk_data *sd = ofono_stk_get_data(stk);
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
||||||
struct cb_data *cbd = cb_data_new(cb, data);
|
struct cb_data *cbd = cb_data_new(cb, data);
|
||||||
char *buf = g_try_new(char, 64 + length * 2);
|
char *buf = g_try_new(char, 64 + length * 2);
|
||||||
int len, ret;
|
int len;
|
||||||
|
|
||||||
|
DBG("");
|
||||||
|
|
||||||
if (!cbd || !buf)
|
if (!cbd || !buf)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
len = sprintf(buf, "AT%%SATE=\"");
|
len = sprintf(buf, "AT%%SATE=\"");
|
||||||
|
|
||||||
for (; length; length--)
|
for (; length; length--)
|
||||||
len += sprintf(buf + len, "%02hhX", *command++);
|
len += sprintf(buf + len, "%02hhX", *command++);
|
||||||
|
|
||||||
len += sprintf(buf + len, "\"");
|
len += sprintf(buf + len, "\"");
|
||||||
|
|
||||||
ret = g_at_chat_send(sd->chat, buf, sate_prefix,
|
DBG("%s", buf);
|
||||||
calypso_sate_cb, cbd, g_free);
|
|
||||||
|
|
||||||
g_free(buf);
|
if (g_at_chat_send(sd->chat, buf, sate_prefix,
|
||||||
buf = NULL;
|
sate_cb, cbd, g_free) > 0) {
|
||||||
|
g_free(buf);
|
||||||
if (ret > 0)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
|
@ -124,13 +129,14 @@ error:
|
||||||
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void calypso_satr_cb(gboolean ok, GAtResult *result,
|
static void satr_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
struct cb_data *cbd = user_data;
|
struct cb_data *cbd = user_data;
|
||||||
ofono_stk_generic_cb_t cb = cbd->cb;
|
ofono_stk_generic_cb_t cb = cbd->cb;
|
||||||
struct ofono_error error;
|
struct ofono_error error;
|
||||||
|
|
||||||
|
DBG("");
|
||||||
|
|
||||||
decode_at_error(&error, g_at_result_final_response(result));
|
decode_at_error(&error, g_at_result_final_response(result));
|
||||||
cb(&error, cbd->data);
|
cb(&error, cbd->data);
|
||||||
}
|
}
|
||||||
|
@ -143,26 +149,25 @@ static void calypso_stk_terminal_response(struct ofono_stk *stk, int length,
|
||||||
struct stk_data *sd = ofono_stk_get_data(stk);
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
||||||
struct cb_data *cbd = cb_data_new(cb, data);
|
struct cb_data *cbd = cb_data_new(cb, data);
|
||||||
char *buf = g_try_new(char, 64 + length * 2);
|
char *buf = g_try_new(char, 64 + length * 2);
|
||||||
int len, ret;
|
int len;
|
||||||
|
|
||||||
|
DBG("");
|
||||||
|
|
||||||
if (!cbd || !buf)
|
if (!cbd || !buf)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
len = sprintf(buf, "AT%%SATR=\"");
|
len = sprintf(buf, "AT%%SATR=\"");
|
||||||
|
|
||||||
for (; length; length--)
|
for (; length; length--)
|
||||||
len += sprintf(buf + len, "%02hhX", *command++);
|
len += sprintf(buf + len, "%02hhX", *command++);
|
||||||
|
|
||||||
len += sprintf(buf + len, "\"");
|
len += sprintf(buf + len, "\"");
|
||||||
|
|
||||||
ret = g_at_chat_send(sd->chat, buf, none_prefix,
|
DBG("%s", buf);
|
||||||
calypso_satr_cb, cbd, g_free);
|
|
||||||
|
|
||||||
g_free(buf);
|
if (g_at_chat_send(sd->chat, buf, none_prefix,
|
||||||
buf = NULL;
|
satr_cb, cbd, g_free) > 0) {
|
||||||
|
g_free(buf);
|
||||||
if (ret > 0)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
|
@ -179,6 +184,8 @@ static void sati_notify(GAtResult *result, gpointer user_data)
|
||||||
gint len;
|
gint len;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
|
DBG("");
|
||||||
|
|
||||||
g_at_result_iter_init(&iter, result);
|
g_at_result_iter_init(&iter, result);
|
||||||
|
|
||||||
if (!g_at_result_iter_next(&iter, "%SATI:"))
|
if (!g_at_result_iter_next(&iter, "%SATI:"))
|
||||||
|
@ -200,11 +207,15 @@ static void sati_notify(GAtResult *result, gpointer user_data)
|
||||||
|
|
||||||
static void sata_notify(GAtResult *result, gpointer user_data)
|
static void sata_notify(GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
DBG("");
|
||||||
|
|
||||||
/* TODO: Pending call alert */
|
/* TODO: Pending call alert */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void satn_notify(GAtResult *result, gpointer user_data)
|
static void satn_notify(GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
DBG("");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Proactive command has been handled by the modem. Should
|
* Proactive command has been handled by the modem. Should
|
||||||
* the core be notified? For now we just ignore it because
|
* the core be notified? For now we just ignore it because
|
||||||
|
@ -212,12 +223,14 @@ static void satn_notify(GAtResult *result, gpointer user_data)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void calypso_stk_register(gboolean ok,
|
static void calypso_stk_register(gboolean ok, GAtResult *result,
|
||||||
GAtResult *result, gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
struct ofono_stk *stk = user_data;
|
struct ofono_stk *stk = user_data;
|
||||||
struct stk_data *sd = ofono_stk_get_data(stk);
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
||||||
|
|
||||||
|
DBG("");
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -234,7 +247,12 @@ static int calypso_stk_probe(struct ofono_stk *stk,
|
||||||
GAtChat *chat = data;
|
GAtChat *chat = data;
|
||||||
struct stk_data *sd;
|
struct stk_data *sd;
|
||||||
|
|
||||||
sd = g_new0(struct stk_data, 1);
|
DBG("");
|
||||||
|
|
||||||
|
sd = g_try_new0(struct stk_data, 1);
|
||||||
|
if (!sd)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
sd->chat = g_at_chat_clone(chat);
|
sd->chat = g_at_chat_clone(chat);
|
||||||
|
|
||||||
ofono_stk_set_data(stk, sd);
|
ofono_stk_set_data(stk, sd);
|
||||||
|
@ -258,6 +276,8 @@ static void calypso_stk_remove(struct ofono_stk *stk)
|
||||||
{
|
{
|
||||||
struct stk_data *sd = ofono_stk_get_data(stk);
|
struct stk_data *sd = ofono_stk_get_data(stk);
|
||||||
|
|
||||||
|
DBG("");
|
||||||
|
|
||||||
ofono_stk_set_data(stk, NULL);
|
ofono_stk_set_data(stk, NULL);
|
||||||
|
|
||||||
g_at_chat_unref(sd->chat);
|
g_at_chat_unref(sd->chat);
|
||||||
|
|
Loading…
Reference in New Issue