2009-06-01 19:03:24 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2009 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 <glib.h>
|
|
|
|
|
|
|
|
#include <ofono/log.h>
|
2009-07-29 19:33:58 +00:00
|
|
|
#include <ofono/modem.h>
|
2009-08-18 03:42:17 +00:00
|
|
|
#include <ofono/sms.h>
|
2009-06-04 22:13:09 +00:00
|
|
|
#include "smsutil.h"
|
|
|
|
#include "util.h"
|
2009-09-02 23:35:40 +00:00
|
|
|
#include "vendor.h"
|
2009-06-01 19:03:24 +00:00
|
|
|
|
|
|
|
#include "gatchat.h"
|
|
|
|
#include "gatresult.h"
|
|
|
|
|
2009-09-04 19:05:15 +00:00
|
|
|
#include "atmodem.h"
|
2009-06-01 19:03:24 +00:00
|
|
|
|
2009-06-04 17:35:17 +00:00
|
|
|
static const char *csca_prefix[] = { "+CSCA:", NULL };
|
|
|
|
static const char *csms_prefix[] = { "+CSMS:", NULL };
|
|
|
|
static const char *cmgf_prefix[] = { "+CMGF:", NULL };
|
|
|
|
static const char *cpms_prefix[] = { "+CPMS:", NULL };
|
|
|
|
static const char *cnmi_prefix[] = { "+CNMI:", NULL };
|
2009-06-20 02:11:42 +00:00
|
|
|
static const char *cmgs_prefix[] = { "+CMGS:", NULL };
|
2009-06-04 22:13:09 +00:00
|
|
|
static const char *none_prefix[] = { NULL };
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
static gboolean set_cmgf(gpointer user_data);
|
|
|
|
static gboolean set_cpms(gpointer user_data);
|
|
|
|
|
|
|
|
#define MAX_CMGF_RETRIES 10
|
|
|
|
#define MAX_CPMS_RETRIES 10
|
|
|
|
|
|
|
|
static const char *storages[] = {
|
|
|
|
"SM",
|
|
|
|
"ME",
|
2009-07-16 16:42:15 +00:00
|
|
|
"MT",
|
2009-06-04 02:07:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SM_STORE 0
|
|
|
|
#define ME_STORE 1
|
2009-07-16 16:42:15 +00:00
|
|
|
#define MT_STORE 2
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
struct sms_data {
|
|
|
|
int store;
|
2009-07-16 16:42:15 +00:00
|
|
|
int incoming;
|
2009-06-04 02:07:25 +00:00
|
|
|
int retries;
|
|
|
|
gboolean cnma_enabled;
|
2009-06-04 22:13:09 +00:00
|
|
|
char *cnma_ack_pdu;
|
|
|
|
int cnma_ack_pdu_len;
|
2009-08-18 03:42:17 +00:00
|
|
|
GAtChat *chat;
|
2009-09-02 02:39:02 +00:00
|
|
|
unsigned int vendor;
|
2009-06-04 02:07:25 +00:00
|
|
|
};
|
|
|
|
|
2009-07-16 16:42:15 +00:00
|
|
|
struct cpms_request {
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms;
|
2009-07-16 16:42:15 +00:00
|
|
|
int store;
|
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
2009-06-01 19:03:24 +00:00
|
|
|
static void at_csca_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
2009-08-18 03:42:17 +00:00
|
|
|
ofono_sms_sca_set_cb_t cb = cbd->cb;
|
2009-06-01 19:03:24 +00:00
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
dump_response("csca_set_cb", ok, result);
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
static void at_csca_set(struct ofono_sms *sms,
|
2009-06-01 19:03:24 +00:00
|
|
|
const struct ofono_phone_number *sca,
|
2009-08-18 03:42:17 +00:00
|
|
|
ofono_sms_sca_set_cb_t cb, void *user_data)
|
2009-06-01 19:03:24 +00:00
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-08-19 23:15:46 +00:00
|
|
|
struct cb_data *cbd = cb_data_new(cb, user_data);
|
2009-06-01 19:03:24 +00:00
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
sprintf(buf, "AT+CSCA=\"%s\",%d", sca->number, sca->type);
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
if (g_at_chat_send(data->chat, buf, csca_prefix,
|
2009-06-01 19:03:24 +00:00
|
|
|
at_csca_set_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (cbd)
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
{
|
|
|
|
DECLARE_FAILURE(error);
|
2009-08-18 03:42:17 +00:00
|
|
|
cb(&error, user_data);
|
2009-06-01 19:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void at_csca_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
GAtResultIter iter;
|
2009-08-18 03:42:17 +00:00
|
|
|
ofono_sms_sca_query_cb_t cb = cbd->cb;
|
2009-06-01 19:03:24 +00:00
|
|
|
struct ofono_error error;
|
|
|
|
struct ofono_phone_number sca;
|
|
|
|
const char *number;
|
|
|
|
|
|
|
|
dump_response("at_csca_cb", ok, result);
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
cb(&error, NULL, cbd->data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CSCA:"))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_string(&iter, &number))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (number[0] == '+') {
|
|
|
|
number = number + 1;
|
|
|
|
sca.type = 145;
|
|
|
|
} else
|
|
|
|
sca.type = 129;
|
|
|
|
|
|
|
|
strncpy(sca.number, number, OFONO_MAX_PHONE_NUMBER_LENGTH);
|
|
|
|
sca.number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0';
|
|
|
|
|
|
|
|
g_at_result_iter_next_number(&iter, &sca.type);
|
|
|
|
|
|
|
|
ofono_debug("csca_query_cb: %s, %d", sca.number, sca.type);
|
|
|
|
|
|
|
|
cb(&error, &sca, cbd->data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
{
|
|
|
|
DECLARE_FAILURE(error);
|
|
|
|
cb(&error, NULL, cbd->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
static void at_csca_query(struct ofono_sms *sms, ofono_sms_sca_query_cb_t cb,
|
|
|
|
void *user_data)
|
2009-06-01 19:03:24 +00:00
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-08-19 23:15:46 +00:00
|
|
|
struct cb_data *cbd = cb_data_new(cb, user_data);
|
2009-06-01 19:03:24 +00:00
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
goto error;
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
if (g_at_chat_send(data->chat, "AT+CSCA?", csca_prefix,
|
2009-06-01 19:03:24 +00:00
|
|
|
at_csca_query_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (cbd)
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
{
|
|
|
|
DECLARE_FAILURE(error);
|
2009-08-18 03:42:17 +00:00
|
|
|
cb(&error, NULL, user_data);
|
2009-06-01 19:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-20 02:11:42 +00:00
|
|
|
static void at_cmgs_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
ofono_sms_submit_cb_t cb = cbd->cb;
|
|
|
|
struct ofono_error error;
|
|
|
|
int mr;
|
|
|
|
|
|
|
|
dump_response("at_cmgs_cb", ok, result);
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
cb(&error, -1, cbd->data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CMGS:"))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &mr))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ofono_debug("Got MR: %d", mr);
|
|
|
|
|
|
|
|
cb(&error, mr, cbd->data);
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
{
|
|
|
|
DECLARE_FAILURE(error);
|
|
|
|
cb(&error, -1, cbd->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
static void at_cmgs(struct ofono_sms *sms, unsigned char *pdu, int pdu_len,
|
2009-07-24 23:16:14 +00:00
|
|
|
int tpdu_len, int mms, ofono_sms_submit_cb_t cb,
|
2009-08-18 03:42:17 +00:00
|
|
|
void *user_data)
|
2009-06-20 02:11:42 +00:00
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-08-19 23:15:46 +00:00
|
|
|
struct cb_data *cbd = cb_data_new(cb, user_data);
|
2009-06-20 02:11:42 +00:00
|
|
|
char buf[512];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
goto error;
|
|
|
|
|
2009-07-24 23:16:14 +00:00
|
|
|
if (mms) {
|
|
|
|
sprintf(buf, "AT+CMMS=%d", mms);
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, none_prefix,
|
2009-06-20 02:11:42 +00:00
|
|
|
NULL, NULL, NULL);
|
2009-07-24 23:16:14 +00:00
|
|
|
}
|
2009-06-20 02:11:42 +00:00
|
|
|
|
|
|
|
len = sprintf(buf, "AT+CMGS=%d\r", tpdu_len);
|
|
|
|
encode_hex_own_buf(pdu, pdu_len, 0, buf+len);
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
if (g_at_chat_send(data->chat, buf, cmgs_prefix,
|
2009-06-20 02:11:42 +00:00
|
|
|
at_cmgs_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (cbd)
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
{
|
|
|
|
DECLARE_FAILURE(error);
|
2009-08-18 03:42:17 +00:00
|
|
|
cb(&error, -1, user_data);
|
2009-06-20 02:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-04 22:13:09 +00:00
|
|
|
static void at_cnma_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
if (!ok)
|
|
|
|
ofono_error("CNMA acknowledgement failed: "
|
|
|
|
"Further SMS reception is not guaranteed");
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean at_parse_pdu_common(GAtResult *result, const char *prefix,
|
|
|
|
const char **pdu, int *pdulen)
|
|
|
|
{
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
2009-06-20 02:11:42 +00:00
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
2009-06-04 22:13:09 +00:00
|
|
|
if (!g_at_result_iter_next(&iter, prefix))
|
|
|
|
return FALSE;
|
|
|
|
|
2009-06-20 02:11:42 +00:00
|
|
|
if (!strcmp(prefix, "+CMT:") && !g_at_result_iter_skip_next(&iter))
|
2009-06-04 22:13:09 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, pdulen))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*pdu = g_at_result_pdu(result);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
static void at_cbm_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2009-06-04 22:13:09 +00:00
|
|
|
int pdulen;
|
|
|
|
const char *pdu;
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
dump_response("at_cbm_notify", TRUE, result);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
|
|
|
if (!at_parse_pdu_common(result, "+CBM:", &pdu, &pdulen)) {
|
|
|
|
ofono_error("Unable to parse CBM notification");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofono_debug("Got new Cell Broadcast via CBM: %s, %d", pdu, pdulen);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void at_cds_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 22:13:09 +00:00
|
|
|
int pdulen;
|
|
|
|
const char *pdu;
|
|
|
|
char buf[256];
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
dump_response("at_cds_notify", TRUE, result);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
|
|
|
if (!at_parse_pdu_common(result, "+CDS:", &pdu, &pdulen)) {
|
|
|
|
ofono_error("Unable to parse CDS notification");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofono_debug("Got new Status-Report PDU via CDS: %s, %d", pdu, pdulen);
|
|
|
|
|
|
|
|
/* We must acknowledge the PDU using CNMA */
|
2009-08-18 03:42:17 +00:00
|
|
|
if (data->cnma_ack_pdu)
|
|
|
|
sprintf(buf, "AT+CNMA=1,%d\r%s", data->cnma_ack_pdu_len,
|
|
|
|
data->cnma_ack_pdu);
|
2009-06-04 22:13:09 +00:00
|
|
|
else
|
|
|
|
sprintf(buf, "AT+CNMA=0"); /* Should be a safe fallback */
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, none_prefix, at_cnma_cb, NULL, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void at_cmt_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-13 02:32:39 +00:00
|
|
|
const char *hexpdu;
|
|
|
|
long pdu_len;
|
|
|
|
int tpdu_len;
|
|
|
|
unsigned char pdu[164];
|
2009-06-04 22:13:09 +00:00
|
|
|
char buf[256];
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
dump_response("at_cmt_notify", TRUE, result);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
2009-06-13 02:32:39 +00:00
|
|
|
if (!at_parse_pdu_common(result, "+CMT:", &hexpdu, &tpdu_len)) {
|
2009-06-04 22:13:09 +00:00
|
|
|
ofono_error("Unable to parse CMT notification");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-15 18:48:28 +00:00
|
|
|
ofono_debug("Got new SMS Deliver PDU via CMT: %s, %d", hexpdu, tpdu_len);
|
2009-06-13 02:32:39 +00:00
|
|
|
|
|
|
|
decode_hex_own_buf(hexpdu, -1, &pdu_len, 0, pdu);
|
2009-08-18 03:42:17 +00:00
|
|
|
ofono_sms_deliver_notify(sms, pdu, pdu_len, tpdu_len);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
|
|
|
/* We must acknowledge the PDU using CNMA */
|
2009-08-18 03:42:17 +00:00
|
|
|
if (data->cnma_ack_pdu)
|
|
|
|
sprintf(buf, "AT+CNMA=1,%d\r%s", data->cnma_ack_pdu_len,
|
|
|
|
data->cnma_ack_pdu);
|
2009-06-04 22:13:09 +00:00
|
|
|
else
|
|
|
|
sprintf(buf, "AT+CNMA=0"); /* Should be a safe fallback */
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, none_prefix, at_cnma_cb, NULL, NULL);
|
2009-06-04 22:13:09 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 20:45:52 +00:00
|
|
|
static void at_cmgr_notify(GAtResult *result, gpointer user_data)
|
2009-06-04 22:13:09 +00:00
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
2009-06-04 22:13:09 +00:00
|
|
|
GAtResultIter iter;
|
2009-06-13 02:32:39 +00:00
|
|
|
const char *hexpdu;
|
|
|
|
unsigned char pdu[164];
|
|
|
|
long pdu_len;
|
|
|
|
int tpdu_len;
|
2009-06-04 22:13:09 +00:00
|
|
|
|
2009-06-15 20:45:52 +00:00
|
|
|
dump_response("at_cmgr_notify", TRUE, result);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CMGR:"))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_skip_next(&iter))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_skip_next(&iter))
|
|
|
|
goto err;
|
|
|
|
|
2009-06-13 02:32:39 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, &tpdu_len))
|
2009-06-04 22:13:09 +00:00
|
|
|
goto err;
|
|
|
|
|
2009-06-15 20:45:52 +00:00
|
|
|
hexpdu = g_at_result_pdu(result);
|
2009-06-13 02:32:39 +00:00
|
|
|
|
|
|
|
ofono_debug("Got PDU: %s, with len: %d", hexpdu, tpdu_len);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
2009-06-13 02:32:39 +00:00
|
|
|
decode_hex_own_buf(hexpdu, -1, &pdu_len, 0, pdu);
|
2009-08-18 03:42:17 +00:00
|
|
|
ofono_sms_deliver_notify(sms, pdu, pdu_len, tpdu_len);
|
2009-06-04 22:13:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
ofono_error("Unable to parse CMGR response");
|
|
|
|
}
|
|
|
|
|
2009-06-15 20:45:52 +00:00
|
|
|
static void at_cmgr_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
if (!ok)
|
|
|
|
ofono_error("Received a CMTI indication but CMGR failed!");
|
|
|
|
}
|
|
|
|
|
2009-06-04 22:13:09 +00:00
|
|
|
static void at_cmgd_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
if (!ok)
|
|
|
|
ofono_error("Unable to delete received SMS");
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 16:42:15 +00:00
|
|
|
static void at_cmti_cpms_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cpms_request *req = user_data;
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = req->sms;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-07-16 16:42:15 +00:00
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
ofono_error("Received CMTI, but CPMS request failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
data->store = req->store;
|
2009-07-16 16:42:15 +00:00
|
|
|
|
|
|
|
sprintf(buf, "AT+CMGR=%d", req->index);
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, none_prefix, at_cmgr_cb, NULL, NULL);
|
2009-07-16 16:42:15 +00:00
|
|
|
|
|
|
|
/* We don't buffer SMS on the SIM/ME, send along a CMGD as well */
|
|
|
|
sprintf(buf, "AT+CMGD=%d", req->index);
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, none_prefix, at_cmgd_cb, NULL, NULL);
|
2009-07-16 16:42:15 +00:00
|
|
|
}
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
static void at_cmti_notify(GAtResult *result, gpointer user_data)
|
2009-06-01 19:03:24 +00:00
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-07-16 16:42:15 +00:00
|
|
|
const char *strstore;
|
|
|
|
int store;
|
2009-06-04 22:13:09 +00:00
|
|
|
GAtResultIter iter;
|
|
|
|
int index;
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
dump_response("at_cmti_notify", TRUE, result);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CMTI:"))
|
|
|
|
goto err;
|
|
|
|
|
2009-07-16 16:42:15 +00:00
|
|
|
if (!g_at_result_iter_next_string(&iter, &strstore))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!strcmp(strstore, "ME"))
|
|
|
|
store = ME_STORE;
|
|
|
|
else if (!strcmp(strstore, "SM"))
|
|
|
|
store = SM_STORE;
|
|
|
|
else
|
2009-06-04 22:13:09 +00:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &index))
|
|
|
|
goto err;
|
|
|
|
|
2009-07-16 16:42:15 +00:00
|
|
|
ofono_debug("Got a CMTI indication at %s, index: %d", strstore, index);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
if (store == data->store) {
|
2009-07-16 16:42:15 +00:00
|
|
|
struct cpms_request req;
|
2009-06-04 22:13:09 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
req.sms = sms;
|
2009-07-16 16:42:15 +00:00
|
|
|
req.store = store;
|
|
|
|
req.index = index;
|
2009-06-04 22:13:09 +00:00
|
|
|
|
2009-07-16 16:42:15 +00:00
|
|
|
at_cmti_cpms_cb(TRUE, NULL, &req);
|
|
|
|
} else {
|
|
|
|
char buf[128];
|
2009-08-18 03:42:17 +00:00
|
|
|
const char *incoming = storages[data->incoming];
|
2009-07-16 16:42:15 +00:00
|
|
|
struct cpms_request *req = g_new(struct cpms_request, 1);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
req->sms = sms;
|
2009-07-16 16:42:15 +00:00
|
|
|
req->store = store;
|
|
|
|
req->index = index;
|
|
|
|
|
|
|
|
sprintf(buf, "AT+CPMS=\"%s\",\"%s\",\"%s\"",
|
|
|
|
strstore, strstore, incoming);
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, cpms_prefix, at_cmti_cpms_cb,
|
2009-07-16 16:42:15 +00:00
|
|
|
req, g_free);
|
|
|
|
}
|
2009-06-04 22:13:09 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
ofono_error("Unable to parse CMTI notification");
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
static void at_sms_initialized(struct ofono_sms *sms)
|
2009-06-04 02:07:25 +00:00
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_register(data->chat, "+CMTI:", at_cmti_notify, FALSE,
|
|
|
|
sms, NULL);
|
|
|
|
g_at_chat_register(data->chat, "+CMT:", at_cmt_notify, TRUE,
|
|
|
|
sms, NULL);
|
|
|
|
g_at_chat_register(data->chat, "+CDS:", at_cds_notify, TRUE,
|
|
|
|
sms, NULL);
|
|
|
|
g_at_chat_register(data->chat, "+CBM:", at_cbm_notify, TRUE,
|
|
|
|
sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-06-15 20:45:52 +00:00
|
|
|
/* We treat CMGR just like a notification */
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_register(data->chat, "+CMGR:", at_cmgr_notify, TRUE,
|
|
|
|
sms, NULL);
|
2009-06-15 20:45:52 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
ofono_sms_register(sms);
|
2009-06-01 19:03:24 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
static void at_sms_not_supported(struct ofono_sms *sms)
|
2009-06-04 02:07:25 +00:00
|
|
|
{
|
|
|
|
ofono_error("SMS not supported by this modem. If this is in error"
|
|
|
|
" please submit patches to support this hardware");
|
2009-08-18 03:42:17 +00:00
|
|
|
|
|
|
|
ofono_sms_remove(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void at_cnmi_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
if (!ok)
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_sms_not_supported(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
at_sms_initialized(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline char wanted_cnmi(int supported, const char *pref)
|
|
|
|
{
|
|
|
|
while (*pref) {
|
|
|
|
if (supported & (1 << (*pref - '0')))
|
|
|
|
return *pref;
|
|
|
|
|
|
|
|
pref++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean append_cnmi_element(char *buf, int *len, int cap,
|
|
|
|
const char *wanted,
|
|
|
|
gboolean last)
|
|
|
|
{
|
|
|
|
char setting = wanted_cnmi(cap, wanted);
|
|
|
|
|
|
|
|
if (!setting)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
buf[*len] = setting;
|
|
|
|
|
|
|
|
if (last)
|
|
|
|
buf[*len + 1] = '\0';
|
|
|
|
else
|
|
|
|
buf[*len + 1] = ',';
|
|
|
|
|
|
|
|
*len += 2;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean build_cnmi_string(char *buf, int *cnmi_opts,
|
2009-09-02 23:35:40 +00:00
|
|
|
struct sms_data *data)
|
2009-06-04 02:07:25 +00:00
|
|
|
{
|
2009-09-02 23:35:40 +00:00
|
|
|
const char *mode;
|
2009-06-04 02:07:25 +00:00
|
|
|
int len = sprintf(buf, "AT+CNMI=");
|
|
|
|
|
2009-09-02 23:35:40 +00:00
|
|
|
if (data->vendor == OFONO_VENDOR_HTC_G1)
|
|
|
|
/* The G1 advertises support for mode 2, but returns an error
|
|
|
|
* if we attempt to actually use it. */
|
|
|
|
mode = "1";
|
|
|
|
else
|
|
|
|
/* Sounds like 2 is the sanest mode */
|
|
|
|
mode = "2310";
|
|
|
|
|
|
|
|
if (!append_cnmi_element(buf, &len, cnmi_opts[0], mode, FALSE))
|
2009-06-04 02:07:25 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Prefer to deliver SMS via +CMT if CNMA is supported */
|
|
|
|
if (!append_cnmi_element(buf, &len, cnmi_opts[1],
|
2009-09-02 23:35:40 +00:00
|
|
|
data->cnma_enabled ? "21" : "1", FALSE))
|
2009-06-04 02:07:25 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Always deliver CB via +CBM, otherwise don't deliver at all */
|
|
|
|
if (!append_cnmi_element(buf, &len, cnmi_opts[2], "20", FALSE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Always deliver Status-Reports via +CDS or don't deliver at all */
|
|
|
|
if (!append_cnmi_element(buf, &len, cnmi_opts[3], "10", FALSE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Don't care about buffering, 0 seems safer */
|
|
|
|
if (!append_cnmi_element(buf, &len, cnmi_opts[4], "01", TRUE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-04 22:13:09 +00:00
|
|
|
static void construct_ack_pdu(struct sms_data *d)
|
|
|
|
{
|
|
|
|
struct sms ackpdu;
|
|
|
|
unsigned char pdu[164];
|
|
|
|
int len;
|
|
|
|
int tpdu_len;
|
|
|
|
|
|
|
|
memset(&ackpdu, 0, sizeof(ackpdu));
|
|
|
|
|
|
|
|
ackpdu.type = SMS_TYPE_DELIVER_REPORT_ACK;
|
|
|
|
|
2009-06-05 18:29:03 +00:00
|
|
|
if (!sms_encode(&ackpdu, &len, &tpdu_len, pdu))
|
2009-06-04 22:13:09 +00:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Constructing an <ackpdu> according to 27.005 Section 4.6 */
|
|
|
|
if (len != tpdu_len)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
d->cnma_ack_pdu = encode_hex(pdu, tpdu_len, 0);
|
|
|
|
|
|
|
|
if (!d->cnma_ack_pdu)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
d->cnma_ack_pdu_len = tpdu_len;
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
ofono_error("Unable to construct Deliver ACK PDU");
|
|
|
|
}
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
static void at_cnmi_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
GAtResultIter iter;
|
|
|
|
int cnmi_opts[5]; /* See 27.005 Section 3.4.1 */
|
|
|
|
int opt;
|
|
|
|
int mode;
|
|
|
|
gboolean supported = FALSE;
|
|
|
|
char buf[128];
|
|
|
|
|
2009-07-15 16:29:38 +00:00
|
|
|
dump_response("at_cnmi_query_cb", ok, result);
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
if (!ok)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
memset(cnmi_opts, 0, sizeof(cnmi_opts));
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CNMI:"))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (opt = 0; opt < 5; opt++) {
|
2009-07-15 16:44:37 +00:00
|
|
|
int min, max;
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
if (!g_at_result_iter_open_list(&iter))
|
|
|
|
goto out;
|
|
|
|
|
2009-07-15 16:44:37 +00:00
|
|
|
while (g_at_result_iter_next_range(&iter, &min, &max)) {
|
|
|
|
for (mode = min; mode <= max; mode++)
|
|
|
|
cnmi_opts[opt] |= 1 << mode;
|
|
|
|
}
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
if (!g_at_result_iter_close_list(&iter))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-09-02 23:35:40 +00:00
|
|
|
if (build_cnmi_string(buf, cnmi_opts, data))
|
2009-06-04 02:07:25 +00:00
|
|
|
supported = TRUE;
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
if (data->cnma_enabled)
|
|
|
|
construct_ack_pdu(data);
|
2009-06-04 22:13:09 +00:00
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
out:
|
|
|
|
if (!supported)
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_sms_not_supported(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, cnmi_prefix,
|
|
|
|
at_cnmi_set_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
static void at_query_cnmi(struct ofono_sms *sms)
|
2009-06-04 02:07:25 +00:00
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, "AT+CNMI=?", cnmi_prefix,
|
|
|
|
at_cnmi_query_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void at_cpms_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-07-15 16:29:38 +00:00
|
|
|
dump_response("at_cpms_set_cb", ok, result);
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
if (ok)
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_query_cnmi(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
data->retries += 1;
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
if (data->retries == MAX_CPMS_RETRIES) {
|
2009-06-04 02:07:25 +00:00
|
|
|
ofono_error("Unable to set preferred storage");
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_sms_not_supported(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_timeout_add_seconds(1, set_cpms, sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean set_cpms(gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
|
|
|
const char *store = storages[data->store];
|
|
|
|
const char *incoming = storages[data->incoming];
|
2009-06-04 02:07:25 +00:00
|
|
|
char buf[128];
|
|
|
|
|
2009-07-16 16:42:15 +00:00
|
|
|
sprintf(buf, "AT+CPMS=\"%s\",\"%s\",\"%s\"", store, store, incoming);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, cpms_prefix,
|
|
|
|
at_cpms_set_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void at_cmgf_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-07-15 16:29:38 +00:00
|
|
|
dump_response("at_cmgf_set_cb", ok, result);
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
if (ok) {
|
2009-08-18 03:42:17 +00:00
|
|
|
data->retries = 0;
|
|
|
|
set_cpms(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
data->retries += 1;
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
if (data->retries == MAX_CMGF_RETRIES) {
|
2009-06-04 02:07:25 +00:00
|
|
|
ofono_debug("Unable to enter PDU mode");
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_sms_not_supported(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_timeout_add_seconds(1, set_cmgf, sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean set_cmgf(gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, "AT+CMGF=0", cmgf_prefix,
|
|
|
|
at_cmgf_set_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void at_cpms_query_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
gboolean supported = FALSE;
|
|
|
|
|
2009-07-15 16:29:38 +00:00
|
|
|
dump_response("cpms_query_cb", ok, result);
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
if (ok) {
|
|
|
|
int mem = 0;
|
|
|
|
GAtResultIter iter;
|
|
|
|
const char *store;
|
|
|
|
gboolean me_supported[3];
|
|
|
|
gboolean sm_supported[3];
|
2009-07-16 16:42:15 +00:00
|
|
|
gboolean mt_supported[3];
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
memset(me_supported, 0, sizeof(me_supported));
|
|
|
|
memset(sm_supported, 0, sizeof(sm_supported));
|
2009-07-16 16:42:15 +00:00
|
|
|
memset(mt_supported, 0, sizeof(mt_supported));
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CPMS:"))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (mem = 0; mem < 3; mem++) {
|
|
|
|
if (!g_at_result_iter_open_list(&iter))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
while (g_at_result_iter_next_string(&iter, &store)) {
|
|
|
|
if (!strcmp(store, "ME"))
|
|
|
|
me_supported[mem] = TRUE;
|
|
|
|
else if (!strcmp(store, "SM"))
|
|
|
|
sm_supported[mem] = TRUE;
|
2009-07-16 16:42:15 +00:00
|
|
|
else if (!strcmp(store, "MT"))
|
|
|
|
mt_supported[mem] = TRUE;
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_at_result_iter_close_list(&iter))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-07-16 16:42:15 +00:00
|
|
|
if (!sm_supported[2] && !me_supported[2] && !mt_supported[2])
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (sm_supported[0] && sm_supported[1]) {
|
2009-06-04 02:07:25 +00:00
|
|
|
supported = TRUE;
|
2009-08-18 03:42:17 +00:00
|
|
|
data->store = SM_STORE;
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 16:42:15 +00:00
|
|
|
if (me_supported[0] && me_supported[1]) {
|
2009-06-04 02:07:25 +00:00
|
|
|
supported = TRUE;
|
2009-08-18 03:42:17 +00:00
|
|
|
data->store = ME_STORE;
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
2009-07-16 16:42:15 +00:00
|
|
|
|
|
|
|
/* This seems to be a special case, where the modem will
|
|
|
|
* pick & route the SMS to any of the storages supported by
|
|
|
|
* mem1
|
|
|
|
*/
|
|
|
|
if (mt_supported[2] && (sm_supported[0] || me_supported[0]))
|
2009-08-18 03:42:17 +00:00
|
|
|
data->incoming = MT_STORE;
|
2009-07-16 16:42:15 +00:00
|
|
|
|
|
|
|
if (sm_supported[2])
|
2009-08-18 03:42:17 +00:00
|
|
|
data->incoming = SM_STORE;
|
2009-07-16 16:42:15 +00:00
|
|
|
|
|
|
|
if (me_supported[2])
|
2009-08-18 03:42:17 +00:00
|
|
|
data->incoming = ME_STORE;
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (!supported)
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_sms_not_supported(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
set_cmgf(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void at_cmgf_query_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
gboolean supported = FALSE;
|
|
|
|
|
2009-07-15 16:29:38 +00:00
|
|
|
dump_response("cmgf_query_cb", ok, result);
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
if (ok) {
|
|
|
|
GAtResultIter iter;
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CMGF:"))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_open_list(&iter))
|
|
|
|
goto out;
|
|
|
|
|
2009-07-15 15:19:27 +00:00
|
|
|
/* Look for mode 0 (PDU mode) */
|
2009-06-04 02:07:25 +00:00
|
|
|
while (g_at_result_iter_next_number(&iter, &mode))
|
2009-07-15 15:19:27 +00:00
|
|
|
if (mode == 0)
|
2009-06-04 02:07:25 +00:00
|
|
|
supported = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (!supported)
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_sms_not_supported(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, "AT+CPMS=?", cpms_prefix,
|
|
|
|
at_cpms_query_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void at_csms_status_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
gboolean supported = FALSE;
|
|
|
|
|
2009-07-15 16:29:38 +00:00
|
|
|
dump_response("csms_status_cb", ok, result);
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
if (ok) {
|
|
|
|
GAtResultIter iter;
|
|
|
|
int service;
|
|
|
|
int mt;
|
|
|
|
int mo;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CSMS:"))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &service))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &mt))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &mo))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (service == 1)
|
2009-08-18 03:42:17 +00:00
|
|
|
data->cnma_enabled = TRUE;
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
if (mt == 1 && mo == 1)
|
|
|
|
supported = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (!supported)
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_sms_not_supported(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
/* Now query supported text format */
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, "AT+CMGF=?", cmgf_prefix,
|
|
|
|
at_cmgf_query_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void at_csms_set_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, "AT+CSMS?", csms_prefix,
|
|
|
|
at_csms_status_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void at_csms_query_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct ofono_sms *sms = user_data;
|
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
gboolean cnma_supported = FALSE;
|
|
|
|
GAtResultIter iter;
|
|
|
|
int status;
|
|
|
|
char buf[128];
|
|
|
|
|
2009-07-15 16:29:38 +00:00
|
|
|
dump_response("csms_query_cb", ok, result);
|
|
|
|
|
2009-06-04 02:07:25 +00:00
|
|
|
if (!ok)
|
2009-08-18 03:42:17 +00:00
|
|
|
return at_sms_not_supported(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CSMS:"))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_open_list(&iter))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
while (g_at_result_iter_next_number(&iter, &status))
|
|
|
|
if (status == 1)
|
|
|
|
cnma_supported = TRUE;
|
|
|
|
|
|
|
|
ofono_debug("CSMS query parsed successfully");
|
|
|
|
|
|
|
|
out:
|
|
|
|
sprintf(buf, "AT+CSMS=%d", cnma_supported ? 1 : 0);
|
2009-08-18 03:42:17 +00:00
|
|
|
g_at_chat_send(data->chat, buf, csms_prefix,
|
|
|
|
at_csms_set_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 02:39:02 +00:00
|
|
|
static int at_sms_probe(struct ofono_sms *sms, unsigned int vendor,
|
|
|
|
void *user)
|
2009-06-04 02:07:25 +00:00
|
|
|
{
|
2009-09-01 22:39:29 +00:00
|
|
|
GAtChat *chat = user;
|
2009-08-18 03:42:17 +00:00
|
|
|
struct sms_data *data;
|
|
|
|
|
|
|
|
data = g_new0(struct sms_data, 1);
|
|
|
|
data->chat = chat;
|
2009-09-01 22:39:29 +00:00
|
|
|
data->vendor = vendor;
|
2009-08-18 03:42:17 +00:00
|
|
|
|
|
|
|
ofono_sms_set_data(sms, data);
|
|
|
|
|
|
|
|
g_at_chat_send(chat, "AT+CSMS=?", csms_prefix,
|
|
|
|
at_csms_query_cb, sms, NULL);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
return 0;
|
2009-06-04 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:27:08 +00:00
|
|
|
static void at_sms_remove(struct ofono_sms *sms)
|
2009-06-01 19:03:24 +00:00
|
|
|
{
|
2009-08-18 03:42:17 +00:00
|
|
|
struct sms_data *data = ofono_sms_get_data(sms);
|
2009-06-04 02:07:25 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
if (data->cnma_ack_pdu)
|
|
|
|
g_free(data->cnma_ack_pdu);
|
|
|
|
|
|
|
|
g_free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ofono_sms_driver driver = {
|
2009-09-02 03:33:05 +00:00
|
|
|
.name = "atmodem",
|
2009-08-18 03:42:17 +00:00
|
|
|
.probe = at_sms_probe,
|
|
|
|
.remove = at_sms_remove,
|
|
|
|
.sca_query = at_csca_query,
|
|
|
|
.sca_set = at_csca_set,
|
|
|
|
.submit = at_cmgs,
|
|
|
|
};
|
2009-06-13 00:40:51 +00:00
|
|
|
|
2009-08-18 03:42:17 +00:00
|
|
|
void at_sms_init()
|
|
|
|
{
|
|
|
|
ofono_sms_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void at_sms_exit()
|
|
|
|
{
|
|
|
|
ofono_sms_driver_unregister(&driver);
|
2009-06-01 19:03:24 +00:00
|
|
|
}
|