---
 Makefile.am                    |    7 ++
 configure.ac                   |    5 ++
 drivers/cdma-atmodem/atmodem.c |   47 ++++++++++++
 drivers/cdma-atmodem/atmodem.h |   23 ++++++
 drivers/cdma-atmodem/atutil.c  |   45 ++++++++++++
 drivers/cdma-atmodem/atutil.h  |   64 +++++++++++++++++
 drivers/cdma-atmodem/sms.c     |  151 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 342 insertions(+), 0 deletions(-)
 create mode 100644 drivers/cdma-atmodem/atmodem.c
 create mode 100644 drivers/cdma-atmodem/atmodem.h
 create mode 100644 drivers/cdma-atmodem/atutil.c
 create mode 100644 drivers/cdma-atmodem/atutil.h
 create mode 100644 drivers/cdma-atmodem/sms.c

diff --git a/Makefile.am b/Makefile.am
index b7dc5ee..400d4c0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -242,6 +242,13 @@ conf_DATA += plugins/phonesim.conf
 endif
 endif
 
+if CDMA_ATMODEM
+builtin_modules += cdma_atmodem
+builtin_sources += drivers/cdma-atmodem/atmodem.h \
+                       drivers/cdma-atmodem/atmodem.c \
+                       drivers/cdma-atmodem/sms.c
+endif
+
 builtin_modules += g1
 builtin_sources += plugins/g1.c
 
diff --git a/configure.ac b/configure.ac
index 5c18f68..abbd8cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,6 +166,11 @@ AC_ARG_ENABLE(phonesim, 
AC_HELP_STRING([--disable-phonesim],
 AM_CONDITIONAL(PHONESIM, test "${enable_phonesim}" != "no" &&
                                        test "${enable_atmodem}" != "no")
 
+AC_ARG_ENABLE(cdmaatmodem, AC_HELP_STRING([--disable-cdma-atmodem],
+                               [disable CDMA AT modem support]),
+                                       [enable_cdma_atmodem=${enableval}])
+AM_CONDITIONAL(CDMA_ATMODEM, test "${enable_cdma_atmodem}" != "no")
+
 AC_ARG_ENABLE(isimodem, AC_HELP_STRING([--disable-isimodem],
                                [disable PhoNet/ISI modem support]),
                                        [enable_isimodem=${enableval}])
diff --git a/drivers/cdma-atmodem/atmodem.c b/drivers/cdma-atmodem/atmodem.c
new file mode 100644
index 0000000..fac9069
--- /dev/null
+++ b/drivers/cdma-atmodem/atmodem.c
@@ -0,0 +1,47 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Nokia 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
+
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/types.h>
+
+#include "atmodem.h"
+
+static int cdma_atmodem_init(void)
+{
+       cdma_at_sms_init();
+
+       return 0;
+}
+
+static void cdma_atmodem_exit(void)
+{
+       cdma_at_sms_exit();
+}
+
+OFONO_PLUGIN_DEFINE(cdma_atmodem, "CDMA AT modem driver", VERSION,
+       OFONO_PLUGIN_PRIORITY_DEFAULT, cdma_atmodem_init, cdma_atmodem_exit)
diff --git a/drivers/cdma-atmodem/atmodem.h b/drivers/cdma-atmodem/atmodem.h
new file mode 100644
index 0000000..28d3d63
--- /dev/null
+++ b/drivers/cdma-atmodem/atmodem.h
@@ -0,0 +1,23 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Nokia 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
+ *
+ */
+
+extern void cdma_at_sms_init();
+extern void cdma_at_sms_exit();
diff --git a/drivers/cdma-atmodem/atutil.c b/drivers/cdma-atmodem/atutil.c
new file mode 100644
index 0000000..f0da2d0
--- /dev/null
+++ b/drivers/cdma-atmodem/atutil.c
@@ -0,0 +1,45 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Nokia 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
+
+ *  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
+
+#include <glib.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/log.h>
+#include <ofono/types.h>
+
+#include "atutil.h"
+
+void decode_at_error(struct ofono_error *error, const char *final)
+{
+       if (!strcmp(final, "OK")) {
+               error->type = OFONO_ERROR_TYPE_NO_ERROR;
+               error->error = 0;
+       } else {
+               error->type = OFONO_ERROR_TYPE_FAILURE;
+               error->error = 0;
+       }
+}
diff --git a/drivers/cdma-atmodem/atutil.h b/drivers/cdma-atmodem/atutil.h
new file mode 100644
index 0000000..6b5c77a
--- /dev/null
+++ b/drivers/cdma-atmodem/atutil.h
@@ -0,0 +1,64 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Nokia 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
+ *
+ */
+
+#ifndef __AT_UTIL_H
+#define __AT_UTIL_H
+
+void decode_at_error(struct ofono_error *error, const char *final);
+
+struct cb_data {
+       void *cb;
+       void *data;
+       void *user;
+};
+
+static inline struct cb_data *cb_data_new(void *cb, void *data)
+{
+       struct cb_data *ret;
+
+       ret = g_try_new0(struct cb_data, 1);
+       if (ret == NULL)
+               return ret;
+
+       ret->cb = cb;
+       ret->data = data;
+
+       return ret;
+}
+
+#define CALLBACK_WITH_FAILURE(cb, args...)             \
+       do {                                            \
+               struct ofono_error cb_e;                \
+               cb_e.type = OFONO_ERROR_TYPE_FAILURE;   \
+               cb_e.error = 0;                         \
+                                                       \
+               cb(&cb_e, ##args);                      \
+       } while (0)                                     \
+
+#define CALLBACK_WITH_SUCCESS(f, args...)              \
+       do {                                            \
+               struct ofono_error e;                   \
+               e.type = OFONO_ERROR_TYPE_NO_ERROR;     \
+               e.error = 0;                            \
+               f(&e, ##args);                          \
+       } while (0)                                     \
+
+#endif /* __AT_UTIL_H */
diff --git a/drivers/cdma-atmodem/sms.c b/drivers/cdma-atmodem/sms.c
new file mode 100644
index 0000000..ffa371c
--- /dev/null
+++ b/drivers/cdma-atmodem/sms.c
@@ -0,0 +1,151 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010  Nokia 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/cdma-sms.h>
+#include "util.h"
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "atmodem.h"
+
+struct cdmasms_data {
+       unsigned int vendor;
+       GAtChat *chat;
+};
+
+static gboolean cdma_at_parse_pdu_common(GAtResult *result, const char *prefix,
+                                                                               
        const char **pdu, int *pdulen)
+{
+       GAtResultIter iter;
+
+       g_at_result_iter_init(&iter, result);
+
+       if (!g_at_result_iter_next(&iter, prefix))
+               return FALSE;
+
+       if (!strcmp(prefix, "+CMT:") && !g_at_result_iter_skip_next(&iter))
+               return FALSE;
+
+       if (!g_at_result_iter_next_number(&iter, pdulen))
+               return FALSE;
+
+       *pdu = g_at_result_pdu(result);
+
+       return TRUE;
+}
+
+static void cdma_at_cmt_notify(GAtResult *result, gpointer user_data)
+{
+       struct ofono_cdmasms *cdmasms = user_data;
+       const char *hexpdu;
+       long pdu_len;
+       int tpdu_len;
+       unsigned char pdu[256];
+
+       if (!cdma_at_parse_pdu_common(result, "+CMT:", &hexpdu, &tpdu_len)) {
+               ofono_error("Unable to parse CMT notification");
+               return;
+       }
+
+       if (strlen(hexpdu) > sizeof(pdu) * 2) {
+               ofono_error("Bad PDU length in CMT notification");
+               return;
+       }
+
+       DBG("Got new SMS Deliver PDU via CMT: %s, %d", hexpdu, tpdu_len);
+
+       decode_hex_own_buf(hexpdu, -1, &pdu_len, 0, pdu);
+       ofono_cdmasms_deliver_notify(cdmasms, pdu, pdu_len);
+}
+
+static void cdma_at_sms_initialized(struct ofono_cdmasms *cdmasms)
+{
+       struct cdmasms_data *data = ofono_cdmasms_get_data(cdmasms);
+
+       g_at_chat_register(data->chat, "+CMT:", cdma_at_cmt_notify, TRUE,
+                               cdmasms, NULL);
+
+       ofono_cdmasms_register(cdmasms);
+}
+
+static int cdma_at_sms_probe(struct ofono_cdmasms *cdmasms, unsigned int 
vendor,
+                                                               void *user)
+{
+       GAtChat *chat = user;
+       struct cdmasms_data *data;
+
+       data = g_new0(struct cdmasms_data, 1);
+       if (data == NULL)
+               return -ENOMEM;
+
+       data->chat = g_at_chat_clone(chat);
+       if (data->chat == NULL)
+               return -ENOMEM;
+
+       data->vendor = vendor;
+
+       ofono_cdmasms_set_data(cdmasms, data);
+
+       cdma_at_sms_initialized(cdmasms);
+
+       return 0;
+}
+
+static void cdma_at_sms_remove(struct ofono_cdmasms *cdmasms)
+{
+       struct cdmasms_data *data = ofono_cdmasms_get_data(cdmasms);
+
+       ofono_cdmasms_set_data(cdmasms, NULL);
+
+       g_at_chat_unref(data->chat);
+       g_free(data);
+}
+
+static struct ofono_cdmasms_driver driver = {
+       .name           = "cdma-atmodem",
+       .probe          = cdma_at_sms_probe,
+       .remove         = cdma_at_sms_remove,
+};
+
+void cdma_at_sms_init()
+{
+       ofono_cdmasms_driver_register(&driver);
+}
+
+void cdma_at_sms_exit()
+{
+       ofono_cdmasms_driver_unregister(&driver);
+}
-- 
1.7.0.4

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to