cdmamodem: Add CDMA SMS driver support
PATCH v2 5/7 cdmamodem: Add CDMA SMS driver support
--- Makefile.am | 3 +- drivers/cdmamodem/cdmamodem.c | 2 + drivers/cdmamodem/cdmamodem.h | 3 + drivers/cdmamodem/sms.c | 153 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 1 deletions(-) create mode 100644 drivers/cdmamodem/sms.c
Makefile.am +2 -1
@@ -245,7 +245,8 @@ endif if CDMA_ATMODEM builtin_modules += cdma_atmodem builtin_sources += drivers/cdmamodem/cdmamodem.h \ - drivers/cdmamodem/cdmamodem.c + drivers/cdmamodem/cdmamodem.c \ + drivers/cdmamodem/sms.c endif builtin_modules += g1
drivers/cdmamodem/cdmamodem.c +2 -0
@@ -34,11 +34,13 @@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,
drivers/cdmamodem/cdmamodem.h +3 -0
@@ -20,3 +20,6 @@*/ #include <drivers/atmodem/atutil.h> + +extern void cdma_at_sms_init (); +extern void cdma_at_sms_exit ();
drivers/cdmamodem/sms.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Hi Lei,
Quoted 165 lines · Lei Yu
--- Makefile.am | 3 +- drivers/cdmamodem/cdmamodem.c | 2 + drivers/cdmamodem/cdmamodem.h | 3 + drivers/cdmamodem/sms.c | 153 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 1 deletions(-) create mode 100644 drivers/cdmamodem/sms.cMakefile.am +2
-1@@ -245,7 +245,8 @@ endif if CDMA_ATMODEM builtin_modules += cdma_atmodem builtin_sources += drivers/cdmamodem/cdmamodem.h \ - drivers/cdmamodem/cdmamodem.c + drivers/cdmamodem/cdmamodem.c \ + drivers/cdmamodem/sms.c endif builtin_modules += g1drivers/cdmamodem/cdmamodem.c +2
-0@@ -34,11 +34,13 @@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,drivers/cdmamodem/cdmamodem.h +3
-0@@ -20,3 +20,6 @@*/ #include <drivers/atmodem/atutil.h> + +extern void cdma_at_sms_init (); +extern void cdma_at_sms_exit ();drivers/cdmamodem/sms.c new file +108
-0@@ -0,0 +1,153 @@ +/* +* +* 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 "cdmamodem.h" + +struct cdma_sms_data { +unsigned int vendor; +GAtChat *chat; +}; + +static gboolean 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 at_cmt_notify (GAtResult *result,gpointer user_data) +{ +struct ofono_cdma_sms *cdma_sms = user_data; +const char *hexpdu; +long pdu_len; +int tpdu_len; +unsigned char pdu[256 ]; + +if (!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_cdma_sms_deliver_notify (cdma_sms, pdu, pdu_len); +} + +static void at_sms_initialized (struct ofono_cdma_sms *cdma_sms) +{ +struct cdma_sms_data *data =ofono_cdma_sms_get_data (cdma_sms); + +g_at_chat_register (data->chat,"+CMT:" , + at_cmt_notify, TRUE, cdma_sms,NULL ); + +ofono_cdma_sms_register (cdma_sms); +} + +static int at_sms_probe (struct ofono_cdma_sms *cdma_sms, +unsigned int vendor,void *user) +{
drivers/cdmamodem/sms.c line 118
Quoted 10 lines
drivers/cdmamodem/sms.c new file +10
-0+GAtChat *chat = user; +struct cdma_sms_data *data; + + data = g_new0(struct cdma_sms_data, 1); +if (data ==NULL ) +return -ENOMEM ; + + data->chat =g_at_chat_clone (chat); +if (data->chat ==NULL ) +return -ENOMEM ;
Are you forgetting to do something here? Hint: Memory leak.
drivers/cdmamodem/sms.c line 124
Quoted 6 lines
drivers/cdmamodem/sms.c new file +6
-0+ + data->vendor = vendor; + +ofono_cdma_sms_set_data (cdma_sms, data); + +at_sms_initialized (cdma_sms);
Currently it is not possible to call the register method from within probe. So you need to either use g_idle_add or run an AT command before registering the cdma_sms atom. See how other drivers do this.
Quoted 19 lines
drivers/cdmamodem/sms.c new file +19
-0+ +return 0 ; +} + +static void at_sms_remove (struct ofono_cdma_sms *cdma_sms) +{ +struct cdma_sms_data *data =ofono_cdma_sms_get_data (cdma_sms); + +ofono_cdma_sms_set_data (cdma_sms,NULL ); + +g_at_chat_unref (data->chat); +g_free (data); +} + +static struct ofono_cdma_sms_driver driver = { + .name ="cdmamodem" , + .probe = at_sms_probe, + .remove = at_sms_remove, +};
drivers/cdmamodem/sms.c line 153
Quoted 10 lines
drivers/cdmamodem/sms.c new file +10
-0+ +void cdma_at_sms_init () +{ +ofono_cdma_sms_driver_register (&driver); +} + +void cdma_at_sms_exit () +{ +ofono_cdma_sms_driver_unregister (&driver); +}
Regards,
-Denis
Hi Denis,
Quoted 172 lines · ext Denis Kenzior
Hi Lei,
Quoted 169 lines · Lei Yu
--- Makefile.am | 3 +- drivers/cdmamodem/cdmamodem.c | 2 + drivers/cdmamodem/cdmamodem.h | 3 + drivers/cdmamodem/sms.c | 153 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 1 deletions(-)create mode 100644
drivers/cdmamodem/sms.cMakefile.am +2
-1@@ -245,7 +245,8 @@ endif if CDMA_ATMODEM builtin_modules += cdma_atmodem builtin_sources += drivers/cdmamodem/cdmamodem.h \ - drivers/cdmamodem/cdmamodem.c + drivers/cdmamodem/cdmamodem.c \ + drivers/cdmamodem/sms.c endif builtin_modules += g1drivers/cdmamodem/cdmamodem.c +2
-0@@ -34,11 +34,13 @@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,drivers/cdmamodem/cdmamodem.h +3
-0@@ -20,3 +20,6 @@*/ #include <drivers/atmodem/atutil.h> + +extern void cdma_at_sms_init (); +extern void cdma_at_sms_exit ();drivers/cdmamodem/sms.c new file +112
-0@@ -0,0 +1,153 @@ +/* +* +* 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 "cdmamodem.h" + +struct cdma_sms_data { +unsigned int vendor; +GAtChat *chat; +}; + +static gboolean 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 at_cmt_notify (GAtResult *result,gpointer user_data) +{ +struct ofono_cdma_sms *cdma_sms = user_data; +const char *hexpdu; +long pdu_len; +int tpdu_len; +unsigned char pdu[256 ]; + +if (!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_cdma_sms_deliver_notify (cdma_sms, pdu, pdu_len); +} + +static void at_sms_initialized (struct ofono_cdma_sms *cdma_sms) +{ +struct cdma_sms_data *data =ofono_cdma_sms_get_data (cdma_sms); + +g_at_chat_register (data->chat,"+CMT:" , + at_cmt_notify, TRUE, cdma_sms,NULL ); + +ofono_cdma_sms_register (cdma_sms); +} + +static int at_sms_probe (struct ofono_cdma_sms *cdma_sms, +unsigned int vendor,void *user) +{ +GAtChat *chat = user; +struct cdma_sms_data *data; + + data = g_new0(struct cdma_sms_data, 1);
Quoted 9 lines
drivers/cdmamodem/sms.c line 118
Quoted 6 lines
drivers/cdmamodem/sms.c new file +6
-0+if (data ==NULL ) +return -ENOMEM ; + + data->chat =g_at_chat_clone (chat); +if (data->chat ==NULL ) +return -ENOMEM ;Are you forgetting to do something here? Hint: Memory leak.
Yep. Answer: Need to de-allocate data. :-)
Quoted 11 lines
drivers/cdmamodem/sms.c line 124
Quoted 6 lines
drivers/cdmamodem/sms.c new file +6
-0+ + data->vendor = vendor; + +ofono_cdma_sms_set_data (cdma_sms, data); + +at_sms_initialized (cdma_sms);Currently it is not possible to call the register method from within probe. So you need to either use
g_idle_addor run an AT command before registering thecdma_smsatom. See how other drivers do this.
Will fix. Could you pls explain why it is not possible to do this sync way but have to force this into async? I have tested and it worked. Or this is just a general architecture rule between atom and driver?
Quoted 24 lines
Quoted 24 lines
drivers/cdmamodem/sms.c new file +24
-0+ +return 0 ; +} + +static void at_sms_remove (struct ofono_cdma_sms *cdma_sms) +{ +struct cdma_sms_data *data =ofono_cdma_sms_get_data (cdma_sms); + +ofono_cdma_sms_set_data (cdma_sms,NULL ); + +g_at_chat_unref (data->chat); +g_free (data); +} + +static struct ofono_cdma_sms_driver driver = { + .name ="cdmamodem" , + .probe = at_sms_probe, + .remove = at_sms_remove, +}; + +void cdma_at_sms_init () +{ +ofono_cdma_sms_driver_register (&driver); +}
Quoted 8 lines
drivers/cdmamodem/sms.c line 153
Quoted 5 lines
drivers/cdmamodem/sms.c new file +5
-0+ +void cdma_at_sms_exit () +{ +ofono_cdma_sms_driver_unregister (&driver); +}Regards,
-Denis
Regards,
-Lei
Hi Lei,
Quoted 12 lines
Quoted 11 lines
drivers/cdmamodem/sms.c line 124
Quoted 6 lines
drivers/cdmamodem/sms.c new file +6
-0+ + data->vendor = vendor; + +ofono_cdma_sms_set_data (cdma_sms, data); + +at_sms_initialized (cdma_sms);Currently it is not possible to call the register method from within probe. So you need to either use
g_idle_addor run an AT command before registering thecdma_smsatom. See how other drivers do this.
Quoted 4 lines
Will fix. Could you pls explain why it is not possible to do this sync way but have to force this into async? I have tested and it worked. Or this is just a general architecture rule between atom and driver?
This is a general rule. The core atom implementation reserves the right to start calling driver functions as soon as the atom is registered. If the atom is registered within probe, then atom driver is still NULL. This results in a crash.
Regards,
-Denis