From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH] rilmodem: add cell broadcast message support
Date: Wed, 18 May 2016 12:15:16 -0500 [thread overview]
Message-ID: <573CA324.5040501@gmail.com> (raw)
In-Reply-To: <1463539162-29043-1-git-send-email-caiwen.zhang@intel.com>
[-- Attachment #1: Type: text/plain, Size: 8085 bytes --]
Hi Caiwen,
On 05/17/2016 09:39 PM, caiwen.zhang(a)intel.com wrote:
> From: Caiwen Zhang <caiwen.zhang@intel.com>
>
> ---
> Makefile.am | 1 +
> drivers/rilmodem/cbs.c | 222 ++++++++++++++++++++++++++++++++++++++++++++
> drivers/rilmodem/rilmodem.c | 2 +
> drivers/rilmodem/rilmodem.h | 3 +
> 4 files changed, 228 insertions(+)
> create mode 100644 drivers/rilmodem/cbs.c
>
> diff --git a/Makefile.am b/Makefile.am
> index 8ab9851..7838d2b 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -152,6 +152,7 @@ builtin_sources += drivers/rilmodem/rilmodem.h \
> drivers/rilmodem/call-barring.c \
> drivers/rilmodem/netmon.c \
> drivers/rilmodem/stk.c \
> + drivers/rilmodem/cbs.c \
> drivers/infineonmodem/infineon_constants.h
> endif
>
> diff --git a/drivers/rilmodem/cbs.c b/drivers/rilmodem/cbs.c
> new file mode 100644
> index 0000000..6505616
> --- /dev/null
> +++ b/drivers/rilmodem/cbs.c
> @@ -0,0 +1,222 @@
> +/*
> + *
> + * oFono - Open Source Telephony
> + *
> + * Copyright (C) 2008-2016 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 <stdio.h>
> +#include <ctype.h>
> +
> +#include <glib.h>
> +
> +#include <ofono/log.h>
> +#include <ofono/modem.h>
> +#include <ofono/cbs.h>
> +#include "util.h"
> +
> +#include <gril.h>
> +#include <parcel.h>
> +
> +#include "rilmodem.h"
> +#include "vendor.h"
> +
> +struct cbs_data {
> + GRil *ril;
> + unsigned int vendor;
> +};
> +
> +static void ril_cbs_set_cb(struct ril_msg *message, gpointer user_data)
> +{
> + struct cb_data *cbd = user_data;
> + ofono_cbs_set_cb_t cb = cbd->cb;
> + struct cbs_data *cd = cbd->user;
> +
> + if (message->error == RIL_E_SUCCESS) {
> + CALLBACK_WITH_SUCCESS(cb, cbd->data);
> + } else {
> + ofono_error("%s RILD reply failure: %s",
> + g_ril_request_id_to_string(cd->ril, message->req),
> + ril_error_to_string(message->error));
> + CALLBACK_WITH_FAILURE(cb, cbd->data);
> + }
> +}
> +
> +static void ril_cbs_set_topics(struct ofono_cbs *cbs, const char *topics,
> + ofono_cbs_set_cb_t cb, void *user_data)
> +{
> + struct cbs_data *cd = ofono_cbs_get_data(cbs);
> + struct cb_data *cbd = cb_data_new(cb, user_data, cd);
> + int count = 0, from, to;
> + const char *p = topics;
> + const char *pto;
> + struct parcel rilp;
> +
> + while (p) {
> + count++;
> + p = strchr(p, ',');
> + if (p)
> + p++;
> + }
> +
It might be simpler to just use g_strsplit here and free the result
after the parcel has been built.
> + p = topics;
> + if (count > 0) {
> + if (atoi(p) == 0 && strchr(p, '0') == NULL) /* empty string */
> + count--;
> + }
The passed in string should not contain any ',' at the very end. So I'm
not sure if this check is really necessary?
> +
> + parcel_init(&rilp);
> + parcel_w_int32(&rilp, count);
> +
> + while (count > 0) {
> + from = atoi(p);
> + to = from;
> +
> + pto = strchr(p, '-');
> + if (pto)
> + to = atoi(pto + 1);
> +
> + parcel_w_int32(&rilp, from);
> + parcel_w_int32(&rilp, to);
> +
> + parcel_w_int32(&rilp, 0);
> + parcel_w_int32(&rilp, 0xFF);
> +
> + parcel_w_int32(&rilp, 1);
> +
> + count--;
> + p = strchr(p, ',');
> + p++;
> + }
> +
> + if (g_ril_send(cd->ril, RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG, &rilp,
> + ril_cbs_set_cb, cbd, g_free) > 0)
> + return;
> +
> + g_free(cbd);
> + CALLBACK_WITH_FAILURE(cb, user_data);
> +}
> +
> +static void ril_cbs_clear_topics(struct ofono_cbs *cbs,
> + ofono_cbs_set_cb_t cb, void *user_data)
> +{
> + ril_cbs_set_topics(cbs, "", cb, user_data);
> +}
> +
> +static void ril_cbs_received(struct ril_msg *message, gpointer user_data)
> +{
> + struct ofono_cbs *cbs = user_data;
> + struct cbs_data *cd = ofono_cbs_get_data(cbs);
> + struct parcel rilp;
> + int pdulen;
> + unsigned char *pdu;
> +
> + g_ril_print_unsol_no_args(cd->ril, message);
> +
> + DBG("req: %d; data_len: %d", message->req, (int) message->buf_len);
> +
> + g_ril_init_parcel(message, &rilp);
> + pdu = parcel_r_raw(&rilp, &pdulen);
> +
> + if (!pdu || pdulen != 88) {
> + ofono_error("%s: it isn't a gsm cell broadcast msg", __func__);
> + return;
> + }
> +
> + ofono_cbs_notify(cbs, pdu, pdulen);
> + g_free(pdu);
> +}
> +
> +static void ril_cbs_register(const struct ofono_error *error, void *data)
> +{
> + struct ofono_cbs *cbs = data;
> + struct cbs_data *cd = ofono_cbs_get_data(cbs);
> +
> + g_ril_register(cd->ril, RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS,
> + ril_cbs_received, cbs);
> +
> + ofono_cbs_register(cbs);
> +}
> +
> +static void get_cbs_config_cb(struct ril_msg *message,
> + gpointer user_data)
> +{
> + struct ofono_cbs *cbs = user_data;
> +
> + if (message->error != RIL_E_SUCCESS) {
> + ofono_error("%s: RIL error %s", __func__,
> + ril_error_to_string(message->error));
> + ofono_cbs_remove(cbs);
> + return;
> + }
> +
> + ril_cbs_clear_topics(cbs, ril_cbs_register, cbs);
> +}
> +
> +static int ril_cbs_probe(struct ofono_cbs *cbs, unsigned int vendor,
> + void *user)
> +{
> + GRil *ril = user;
> + struct cbs_data *data;
> +
> + data = g_new0(struct cbs_data, 1);
> + data->ril = g_ril_clone(ril);
> + data->vendor = vendor;
> +
> + ofono_cbs_set_data(cbs, data);
> +
> + if (g_ril_send(ril, RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG, NULL,
> + get_cbs_config_cb, cbs, NULL) == 0) {
> + ofono_error("%s: send failed", __func__);
> + }
Don't use parentheses around simple expressions.
> +
> + return 0;
> +}
> +
> +static void ril_cbs_remove(struct ofono_cbs *cbs)
> +{
> + struct cbs_data *data = ofono_cbs_get_data(cbs);
> +
> + ofono_cbs_set_data(cbs, NULL);
> +
> + g_ril_unref(data->ril);
> + g_free(data);
> +}
> +
> +static struct ofono_cbs_driver driver = {
> + .name = RILMODEM,
> + .probe = ril_cbs_probe,
> + .remove = ril_cbs_remove,
> + .set_topics = ril_cbs_set_topics,
> + .clear_topics = ril_cbs_clear_topics,
> +};
> +
> +void ril_cbs_init(void)
> +{
> + ofono_cbs_driver_register(&driver);
> +}
> +
> +void ril_cbs_exit(void)
> +{
> + ofono_cbs_driver_unregister(&driver);
> +}
> diff --git a/drivers/rilmodem/rilmodem.c b/drivers/rilmodem/rilmodem.c
> index 9a063a2..ace1621 100644
> --- a/drivers/rilmodem/rilmodem.c
> +++ b/drivers/rilmodem/rilmodem.c
> @@ -53,6 +53,7 @@ static int rilmodem_init(void)
> ril_call_barring_init();
> ril_netmon_init();
> ril_stk_init();
> + ril_cbs_init();
>
> return 0;
> }
> @@ -76,6 +77,7 @@ static void rilmodem_exit(void)
> ril_call_barring_exit();
> ril_netmon_exit();
> ril_stk_exit();
> + ril_cbs_exit();
> }
>
> OFONO_PLUGIN_DEFINE(rilmodem, "RIL modem driver", VERSION,
> diff --git a/drivers/rilmodem/rilmodem.h b/drivers/rilmodem/rilmodem.h
> index 7e47573..cde955e 100644
> --- a/drivers/rilmodem/rilmodem.h
> +++ b/drivers/rilmodem/rilmodem.h
> @@ -75,3 +75,6 @@ extern void ril_netmon_exit(void);
>
> extern void ril_stk_init(void);
> extern void ril_stk_exit(void);
> +
> +extern void ril_cbs_init(void);
> +extern void ril_cbs_exit(void);
>
Regards,
-Denis
next prev parent reply other threads:[~2016-05-18 17:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-18 2:39 [PATCH] rilmodem: add cell broadcast message support caiwen.zhang
2016-05-18 17:15 ` Denis Kenzior [this message]
2016-05-19 3:26 ` Zhang, Caiwen
-- strict thread matches above, loose matches on Subject: below --
2016-05-19 3:02 caiwen.zhang
2016-05-19 15:29 ` 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=573CA324.5040501@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.