From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH v2, 5/7] cdmamodem: Add CDMA SMS driver support
Date: Tue, 04 Jan 2011 15:22:13 -0600 [thread overview]
Message-ID: <4D238F85.7080005@gmail.com> (raw)
In-Reply-To: <1292976149-15598-6-git-send-email-lei.2.yu@nokia.com>
[-- Attachment #1: Type: text/plain, Size: 6080 bytes --]
Hi Lei,
On 12/21/2010 06:02 PM, Lei Yu wrote:
> ---
> 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
>
> diff --git a/Makefile.am b/Makefile.am
> index 69ee02d..3035b69 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -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
> diff --git a/drivers/cdmamodem/cdmamodem.c b/drivers/cdmamodem/cdmamodem.c
> index 25bd0f3..34829e1 100644
> --- a/drivers/cdmamodem/cdmamodem.c
> +++ b/drivers/cdmamodem/cdmamodem.c
> @@ -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,
> diff --git a/drivers/cdmamodem/cdmamodem.h b/drivers/cdmamodem/cdmamodem.h
> index 114d1fd..6f1c915 100644
> --- a/drivers/cdmamodem/cdmamodem.h
> +++ b/drivers/cdmamodem/cdmamodem.h
> @@ -20,3 +20,6 @@
> */
>
> #include <drivers/atmodem/atutil.h>
> +
> +extern void cdma_at_sms_init();
> +extern void cdma_at_sms_exit();
> diff --git a/drivers/cdmamodem/sms.c b/drivers/cdmamodem/sms.c
> new file mode 100644
> index 0000000..de90224
> --- /dev/null
> +++ b/drivers/cdmamodem/sms.c
> @@ -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);
> + 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.
> +
> + 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.
> +
> + 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);
> +}
> +
> +void cdma_at_sms_exit()
> +{
> + ofono_cdma_sms_driver_unregister(&driver);
> +}
Regards,
-Denis
next prev parent reply other threads:[~2011-01-04 21:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-22 0:02 [PATCH v2, 5/7] cdmamodem: Add CDMA SMS driver support Lei Yu
2011-01-04 21:22 ` Denis Kenzior [this message]
2011-01-05 17:54 ` Lei Yu
2011-01-05 17:52 ` Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D238F85.7080005@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox