sms: split SMS part handling into common and 3GPP-specific

This commit is contained in:
Aleksander Morgado
2013-07-18 14:45:58 +02:00
parent e90ff4155c
commit df986c076d
12 changed files with 1252 additions and 1181 deletions

View File

@@ -30,7 +30,9 @@ libmodem_helpers_la_SOURCES = \
mm-charsets.c \
mm-charsets.h \
mm-sms-part.h \
mm-sms-part.c
mm-sms-part.c \
mm-sms-part-3gpp.h \
mm-sms-part-3gpp.c
# Additional QMI support in libmodem-helpers
if WITH_QMI
@@ -191,8 +193,6 @@ ModemManager_SOURCES = \
mm-base-modem-at.c \
mm-base-modem.h \
mm-base-modem.c \
mm-sms-part.h \
mm-sms-part.c \
mm-sms.h \
mm-sms.c \
mm-sms-list.h \

View File

@@ -36,6 +36,7 @@
#include "mm-iface-modem.h"
#include "mm-iface-modem-3gpp.h"
#include "mm-iface-modem-messaging.h"
#include "mm-sms-part-3gpp.h"
static void iface_modem_init (MMIfaceModem *iface);
static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface);
@@ -2407,10 +2408,10 @@ add_sms_part (MMBroadbandModemMbim *self,
MMSmsPart *part;
GError *error = NULL;
part = mm_sms_part_new_from_binary_pdu (pdu->message_index,
pdu->pdu_data,
pdu->pdu_data_size,
&error);
part = mm_sms_part_3gpp_new_from_binary_pdu (pdu->message_index,
pdu->pdu_data,
pdu->pdu_data_size,
&error);
if (part) {
mm_dbg ("Correctly parsed PDU (%d)", pdu->message_index);
mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self),

View File

@@ -40,6 +40,7 @@
#include "mm-sim-qmi.h"
#include "mm-bearer-qmi.h"
#include "mm-sms-qmi.h"
#include "mm-sms-part-3gpp.h"
static void iface_modem_init (MMIfaceModem *iface);
static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface);
@@ -6858,10 +6859,10 @@ add_new_read_sms_part (MMIfaceModemMessaging *self,
MMSmsPart *part;
GError *error = NULL;
part = mm_sms_part_new_from_binary_pdu (index,
(guint8 *)data->data,
data->len,
&error);
part = mm_sms_part_3gpp_new_from_binary_pdu (index,
(guint8 *)data->data,
data->len,
&error);
if (part) {
mm_dbg ("Correctly parsed PDU (%d)",
index);

View File

@@ -42,6 +42,7 @@
#include "mm-broadband-bearer.h"
#include "mm-bearer-list.h"
#include "mm-sms-list.h"
#include "mm-sms-part-3gpp.h"
#include "mm-sim.h"
#include "mm-log.h"
#include "mm-modem-helpers.h"
@@ -5575,7 +5576,7 @@ sms_part_ready (MMBroadbandModem *self,
{
MMSmsPart *part;
gint rv, status, tpdu_len;
gchar pdu[SMS_MAX_PDU_LEN + 1];
gchar pdu[MM_SMS_PART_3GPP_MAX_PDU_LEN + 1];
const gchar *response;
GError *error = NULL;
@@ -5593,7 +5594,7 @@ sms_part_ready (MMBroadbandModem *self,
return;
}
rv = sscanf (response, "+CMGR: %d,,%d %" G_STRINGIFY (SMS_MAX_PDU_LEN) "s",
rv = sscanf (response, "+CMGR: %d,,%d %" G_STRINGIFY (MM_SMS_PART_3GPP_MAX_PDU_LEN) "s",
&status, &tpdu_len, pdu);
if (rv != 3) {
error = g_error_new (MM_CORE_ERROR,
@@ -5605,7 +5606,7 @@ sms_part_ready (MMBroadbandModem *self,
return;
}
part = mm_sms_part_new_from_pdu (ctx->idx, pdu, &error);
part = mm_sms_part_3gpp_new_from_pdu (ctx->idx, pdu, &error);
if (part) {
mm_dbg ("Correctly parsed PDU (%d)", ctx->idx);
mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self),
@@ -5715,7 +5716,7 @@ cds_received (MMAtSerialPort *port,
if (!pdu)
return;
part = mm_sms_part_new_from_pdu (SMS_PART_INVALID_INDEX, pdu, &error);
part = mm_sms_part_3gpp_new_from_pdu (SMS_PART_INVALID_INDEX, pdu, &error);
if (part) {
mm_dbg ("Correctly parsed non-stored PDU");
mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self),
@@ -6082,7 +6083,7 @@ sms_pdu_part_list_ready (MMBroadbandModem *self,
MM3gppPduInfo *info = l->data;
MMSmsPart *part;
part = mm_sms_part_new_from_pdu (info->index, info->pdu, &error);
part = mm_sms_part_3gpp_new_from_pdu (info->index, info->pdu, &error);
if (part) {
mm_dbg ("Correctly parsed PDU (%d)", info->index);
mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self),

View File

@@ -29,6 +29,7 @@
#include "mm-sms-mbim.h"
#include "mm-base-modem.h"
#include "mm-log.h"
#include "mm-sms-part-3gpp.h"
G_DEFINE_TYPE (MMSmsMbim, mm_sms_mbim, MM_TYPE_SMS)
@@ -154,7 +155,7 @@ sms_send_next_part (SmsSendContext *ctx)
}
/* Get PDU */
pdu = mm_sms_part_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error);
pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error);
if (!pdu) {
g_simple_async_result_take_error (ctx->result, error);
sms_send_context_complete_and_free (ctx);

1160
src/mm-sms-part-3gpp.c Normal file

File diff suppressed because it is too large Load Diff

54
src/mm-sms-part-3gpp.h Normal file
View File

@@ -0,0 +1,54 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2011 - 2012 Red Hat, Inc.
* Copyright (C) 2013 Google, Inc.
*/
#ifndef MM_SMS_PART_3GPP_H
#define MM_SMS_PART_3GPP_H
#include <glib.h>
#include <ModemManager-enums.h>
#include "mm-sms-part.h"
#define MM_SMS_PART_3GPP_MAX_PDU_LEN 344
MMSmsPart *mm_sms_part_3gpp_new_from_pdu (guint index,
const gchar *hexpdu,
GError **error);
MMSmsPart *mm_sms_part_3gpp_new_from_binary_pdu (guint index,
const guint8 *pdu,
gsize pdu_len,
GError **error);
guint8 *mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part,
guint *out_pdulen,
guint *out_msgstart,
GError **error);
/* For testcases only */
guint mm_sms_part_3gpp_encode_address (const gchar *address,
guint8 *buf,
gsize buflen,
gboolean is_smsc);
gchar **mm_sms_part_3gpp_util_split_text (const gchar *text,
MMSmsEncoding *encoding);
GByteArray **mm_sms_part_3gpp_util_split_data (const guint8 *data,
gsize data_len);
#endif /* MM_SMS_PART_3GPP_H */

File diff suppressed because it is too large Load Diff

View File

@@ -29,25 +29,12 @@ typedef enum {
typedef struct _MMSmsPart MMSmsPart;
#define SMS_MAX_PDU_LEN 344
#define SMS_PART_INVALID_INDEX G_MAXUINT
MMSmsPart *mm_sms_part_new (guint index,
MMSmsPduType type);
MMSmsPart *mm_sms_part_new_from_pdu (guint index,
const gchar *hexpdu,
GError **error);
MMSmsPart *mm_sms_part_new_from_binary_pdu (guint index,
const guint8 *pdu,
gsize pdu_len,
GError **error);
void mm_sms_part_free (MMSmsPart *part);
guint8 *mm_sms_part_get_submit_pdu (MMSmsPart *part,
guint *out_pdulen,
guint *out_msgstart,
GError **error);
guint mm_sms_part_get_index (MMSmsPart *part);
void mm_sms_part_set_index (MMSmsPart *part,
guint index);
@@ -129,16 +116,4 @@ void mm_sms_part_set_concat_sequence (MMSmsPart *part,
gboolean mm_sms_part_should_concat (MMSmsPart *part);
/* For testcases only */
guint mm_sms_part_encode_address (const gchar *address,
guint8 *buf,
gsize buflen,
gboolean is_smsc);
gchar **mm_sms_part_util_split_text (const gchar *text,
MMSmsEncoding *encoding);
GByteArray **mm_sms_part_util_split_data (const guint8 *data,
gsize data_len);
#endif /* MM_SMS_PART_H */

View File

@@ -28,6 +28,7 @@
#include "mm-iface-modem-messaging.h"
#include "mm-sms-qmi.h"
#include "mm-base-modem.h"
#include "mm-sms-part-3gpp.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMSmsQmi, mm_sms_qmi, MM_TYPE_SMS);
@@ -173,7 +174,7 @@ sms_store_next_part (SmsStoreContext *ctx)
}
/* Get PDU */
pdu = mm_sms_part_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error);
pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error);
if (!pdu) {
/* 'error' should already be set */
g_simple_async_result_take_error (ctx->result, error);
@@ -332,7 +333,7 @@ sms_send_generic (SmsSendContext *ctx)
GError *error = NULL;
/* Get PDU */
pdu = mm_sms_part_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error);
pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error);
if (!pdu) {
g_simple_async_result_take_error (ctx->result, error);
sms_send_context_complete_and_free (ctx);

View File

@@ -30,6 +30,7 @@
#include "mm-iface-modem.h"
#include "mm-iface-modem-messaging.h"
#include "mm-sms.h"
#include "mm-sms-part-3gpp.h"
#include "mm-base-modem-at.h"
#include "mm-base-modem.h"
#include "mm-log.h"
@@ -123,7 +124,7 @@ generate_submit_pdus (MMSms *self,
g_assert (!(text != NULL && data != NULL));
if (text) {
split_text = mm_sms_part_util_split_text (text, &encoding);
split_text = mm_sms_part_3gpp_util_split_text (text, &encoding);
if (!split_text) {
g_set_error (error,
MM_CORE_ERROR,
@@ -134,7 +135,7 @@ generate_submit_pdus (MMSms *self,
n_parts = g_strv_length (split_text);
} else if (data) {
encoding = MM_SMS_ENCODING_8BIT;
split_data = mm_sms_part_util_split_data (data, data_len);
split_data = mm_sms_part_3gpp_util_split_data (data, data_len);
g_assert (split_data != NULL);
/* noop within the for */
for (n_parts = 0; split_data[n_parts]; n_parts++);
@@ -703,7 +704,7 @@ sms_get_store_or_send_command (MMSmsPart *part,
/* AT+CMGW=<length>[, <stat>]<CR> PDU can be entered. <CTRL-Z>/<ESC> */
pdu = mm_sms_part_get_submit_pdu (part, &pdulen, &msgstart, error);
pdu = mm_sms_part_3gpp_get_submit_pdu (part, &pdulen, &msgstart, error);
if (!pdu)
/* 'error' should already be set */
return FALSE;

View File

@@ -23,7 +23,7 @@
#define _LIBMM_INSIDE_MM
#include <libmm-glib.h>
#include "mm-sms-part.h"
#include "mm-sms-part-3gpp.h"
#include "mm-log.h"
/* If defined will print debugging traces */
@@ -58,7 +58,7 @@ common_test_part_from_hexpdu (const gchar *hexpdu,
MMSmsPart *part;
GError *error = NULL;
part = mm_sms_part_new_from_pdu (0, hexpdu, &error);
part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, &error);
g_assert_no_error (error);
g_assert (part != NULL);
@@ -356,7 +356,7 @@ test_pdu_insufficient_data (void)
};
hexpdu = mm_utils_bin2hexstr (pdu, sizeof (pdu));
part = mm_sms_part_new_from_pdu (0, hexpdu, &error);
part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, &error);
g_assert (part == NULL);
/* We don't care for the specific error type */
g_assert (error != NULL);
@@ -464,7 +464,7 @@ common_test_address_encode (const gchar *address,
guint8 buf[20];
gsize enclen;
enclen = mm_sms_part_encode_address (address, buf, sizeof (buf), smsc);
enclen = mm_sms_part_3gpp_encode_address (address, buf, sizeof (buf), smsc);
g_assert_cmpuint (enclen, ==, expected_size);
g_assert_cmpint (memcmp (buf, expected, expected_size), ==, 0);
}
@@ -531,7 +531,7 @@ common_test_create_pdu (const gchar *smsc,
MMSmsEncoding encoding = MM_SMS_ENCODING_UNKNOWN;
/* Detect best encoding */
mm_sms_part_util_split_text (text, &encoding);
mm_sms_part_3gpp_util_split_text (text, &encoding);
mm_sms_part_set_text (part, text);
mm_sms_part_set_encoding (part, encoding);
}
@@ -540,10 +540,10 @@ common_test_create_pdu (const gchar *smsc,
if (class >= 0)
mm_sms_part_set_class (part, class);
pdu = mm_sms_part_get_submit_pdu (part,
&len,
&msgstart,
&error);
pdu = mm_sms_part_3gpp_get_submit_pdu (part,
&len,
&msgstart,
&error);
trace_pdu (pdu, len);
@@ -716,7 +716,7 @@ common_test_text_split (const gchar *text,
MMSmsEncoding out_encoding = MM_SMS_ENCODING_UNKNOWN;
guint i;
out = mm_sms_part_util_split_text (text, &out_encoding);
out = mm_sms_part_3gpp_util_split_text (text, &out_encoding);
g_assert (out != NULL);
g_assert (out_encoding != MM_SMS_ENCODING_UNKNOWN);