Adding new mbimcli option to open/close DSS channels?

Aleksander Morgado aleksander at aleksander.es
Tue Mar 4 11:37:33 PST 2014


Hey Scott,

> 
> Could you please review this patch?
> Thanks so much for your attention to this matter.
> 
> Best regards,
> Scott

Thanks for the patch; I've pushed it as is, and then included some more
follow-up commits. Let me know if I broke anything :)

BTW, I've added the UUID parser method in the public API as
mbim_uuid_from_printable(), and fixed some things I found in the
implementation.


> 
> diff --git a/src/mbimcli/Makefile.am b/src/mbimcli/Makefile.am
> index 2e5956e..224feb0 100644
> --- a/src/mbimcli/Makefile.am
> +++ b/src/mbimcli/Makefile.am
> @@ -14,7 +14,8 @@ mbimcli_SOURCES = \
>  	mbimcli.c \
>  	mbimcli-basic-connect.c \
>  	mbimcli-phonebook.c \
> -	mbimcli-ms-firmware-id.c
> +	mbimcli-ms-firmware-id.c \
> +	mbimcli-dss.c
>  
>  mbimcli_LDADD = \
>  	$(MBIMCLI_LIBS) \
> diff --git a/src/mbimcli/mbimcli-dss.c b/src/mbimcli/mbimcli-dss.c
> new file mode 100644
> index 0000000..38ac514
> --- /dev/null
> +++ b/src/mbimcli/mbimcli-dss.c
> @@ -0,0 +1,325 @@
> +/*
> + * mbimcli -- Command line interface to control MBIM devices
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + *
> + * Copyright (C) 2014 NVIDIA CORPORATION
> + */
> +
> +#include "config.h"
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <locale.h>
> +#include <string.h>
> +
> +#include <glib.h>
> +#include <gio/gio.h>
> +
> +#include <libmbim-glib.h>
> +
> +#include "mbimcli.h"
> +
> +/* Context */
> +typedef struct {
> +    MbimDevice *device;
> +    GCancellable *cancellable;
> +} Context;
> +static Context *ctx;
> +
> +/* Options */
> +static gchar    *set_connect_activate_str;
> +static gchar    *set_connect_deactivate_str;
> +
> +static GOptionEntry entries[] = {
> +    { "dss-connect", 0, 0, G_OPTION_ARG_STRING, &set_connect_activate_str,
> +      "DSS Connect (DeviceServiceId, DssSessionId)",
> +      "[(UUID),(Session)]"
> +    },
> +    { "dss-disconnect", 0, 0, G_OPTION_ARG_STRING, &set_connect_deactivate_str,
> +      "DSS Disconnect (DeviceServiceId, DssSessionId)",
> +      "[(UUID),(Session)]"
> +    },
> +    { NULL }
> +};
> +
> +GOptionGroup *
> +mbimcli_dss_get_option_group (void)
> +{
> +    GOptionGroup *group;
> +
> +    group = g_option_group_new ("dss",
> +                                "Device Service Stream options",
> +                                "Show Device Service Stream options",
> +                                NULL,
> +                                NULL);
> +    g_option_group_add_entries (group, entries);
> +
> +	return group;
> +}
> +
> +gboolean
> +mbimcli_dss_options_enabled (void)
> +{
> +    static guint n_actions = 0;
> +    static gboolean checked = FALSE;
> +
> +    if (checked)
> +        return !!n_actions;
> +
> +    n_actions = (!!set_connect_activate_str +
> +                 !!set_connect_deactivate_str );
> +
> +    if (n_actions > 1) {
> +        g_printerr ("error: too many DSS actions requested\n");
> +        exit (EXIT_FAILURE);
> +    }
> +
> +    checked = TRUE;
> +    return !!n_actions;
> +}
> +
> +static void
> +context_free (Context *context)
> +{
> +    if (!context)
> +        return;
> +
> +    if (context->cancellable)
> +        g_object_unref (context->cancellable);
> +    if (context->device)
> +        g_object_unref (context->device);
> +    g_slice_free (Context, context);
> +}
> +
> +static void
> +shutdown (gboolean operation_status)
> +{
> +    /* Cleanup context and finish async operation */
> +    context_free (ctx);
> +    mbimcli_async_operation_done (operation_status);
> +}
> +
> +enum {
> +    CONNECT,
> +    DISCONNECT
> +};
> +
> +static void
> +set_dss_ready (MbimDevice   *device,
> +               GAsyncResult *res,
> +               gpointer user_data)
> +{
> +    MbimMessage *response;
> +    GError *error = NULL;
> +
> +    response = mbim_device_command_finish (device, res, &error);
> +    if (!response || !mbim_message_command_done_get_result (response, &error)) {
> +        g_printerr ("error: operation failed: %s\n", error->message);
> +        g_error_free (error);
> +        shutdown (FALSE);
> +        return;
> +    }
> +
> +    if (!mbim_message_dss_connect_response_parse (
> +            response,
> +            &error)) {
> +        g_printerr ("error: couldn't parse response message: %s\n", error->message);
> +        g_error_free (error);
> +        shutdown (FALSE);
> +        return;
> +    }
> +
> +    switch (GPOINTER_TO_UINT (user_data)) {
> +    case CONNECT:
> +        g_print ("[%s] Successfully connected\n\n",
> +                 mbim_device_get_path_display (device));
> +        break;
> +    case DISCONNECT:
> +        g_print ("[%s] Successfully disconnected\n\n",
> +                 mbim_device_get_path_display (device));
> +        break;
> +    default:
> +        break;
> +    }
> +
> +    mbim_message_unref (response);
> +    shutdown (TRUE);
> +}
> +
> +static gboolean parse_uuid(const gchar *str, MbimUuid* uuid)
> +{
> +    guint a0, a1, a2, a3;
> +    guint b0, b1;
> +    guint c0, c1;
> +    guint d0, d1;
> +    guint e0, e1, e2, e3, e4, e5;
> +
> +    if ( (strlen(str) != 36) ||
> +         (0 == sscanf(str, "%02x%02x%02x%02x-"
> +                           "%02x%02x-"
> +                           "%02x%02x-"
> +                           "%02x%02x-"
> +                           "%02x%02x%02x%02x%02x%02x",
> +                           &a0, &a1, &a2, &a3,
> +                           &b0, &b1,
> +                           &c0, &c1,
> +                           &d0, &d1,
> +                           &e0, &e1, &e2, &e3, &e4, &e5)) )
> +        return FALSE;
> +
> +    uuid->a[0] = a0; uuid->a[1] = a1; uuid->a[2] = a2; uuid->a[3] = a3;
> +    uuid->b[0] = b0; uuid->b[1] = b1;
> +    uuid->c[0] = c0; uuid->c[1] = c1;
> +    uuid->d[0] = d0; uuid->d[1] = d1;
> +    uuid->e[0] = e0; uuid->e[1] = e1; uuid->e[2] = e2; uuid->e[3] = e3; uuid->e[4] = e4; uuid->e[5] = e5;
> +    return TRUE;
> +}
> +
> +static gboolean parse_uint(const gchar *str, guint32 *u)
> +{
> +    guint32 t;
> +
> +    if (0 == sscanf(str, "%u", &t))
> +        return FALSE;
> +
> +    *u = t;
> +    return TRUE;
> +}
> +
> +static gboolean
> +set_dss_command_parse (const gchar *str,
> +                       MbimUuid    *dsid,
> +                       guint32     *ssid)
> +{
> +    gchar **split;
> +
> +    g_assert (dsid != NULL);
> +    g_assert (ssid != NULL);
> +
> +    /* Format of the string is:
> +     * [(DevSrvID),(SessionId)]
> +     */
> +    split = g_strsplit (str, ",", -1);
> +
> +    if (g_strv_length (split) > 2) {
> +        g_printerr ("error: couldn't parse input string, too many arguments\n");
> +        g_strfreev (split);
> +        return FALSE;
> +    }
> +
> +    if (g_strv_length (split) < 1) {
> +        g_printerr ("error: couldn't parse input string, missing arguments\n");
> +        g_strfreev (split);
> +        return FALSE;
> +    }
> +
> +    /* DeviceServiceId */
> +    if (parse_uuid(split[0], dsid) == FALSE) {
> +        g_printerr ("error: couldn't parse UUID, should be xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");
> +        g_strfreev (split);
> +        return FALSE;
> +    }
> +
> +    /* SessionId */
> +    if (parse_uint(split[1], ssid) == FALSE) {
> +        g_printerr ("error: couldn't parse Session ID, should be a number\n");
> +        g_strfreev (split);
> +        return FALSE;
> +    }
> +
> +    g_strfreev (split);
> +    return TRUE;
> +}
> +
> +void
> +mbimcli_dss_run (MbimDevice   *device,
> +                 GCancellable *cancellable)
> +{
> +    MbimMessage *request;
> +    GError *error = NULL;
> +    MbimUuid service_id;
> +    guint32  session_id;
> +
> +    /* Initialize context */
> +    ctx = g_slice_new (Context);
> +    ctx->device = g_object_ref (device);
> +    if (cancellable)
> +        ctx->cancellable = g_object_ref (cancellable);
> +
> +    /* Connect? */
> +    if (set_connect_activate_str) 
> +    {
> +        if (!set_dss_command_parse (set_connect_activate_str,
> +                                    &service_id,
> +                                    &session_id)) {
> +            shutdown (FALSE);
> +            return;
> +        }
> +
> +        request = mbim_message_dss_connect_set_new (&service_id,
> +                                                    session_id,
> +                                                    MBIM_DSS_LINK_STATE_ACTIVATE,
> +                                                    &error);
> +
> +        if (!request) {
> +            g_printerr ("error: couldn't create request: %s\n", error->message);
> +            g_error_free (error);
> +            shutdown (FALSE);
> +            return;
> +        }
> +
> +        mbim_device_command (ctx->device,
> +                             request,
> +                             10,
> +                             ctx->cancellable,
> +                             (GAsyncReadyCallback)set_dss_ready,
> +                             GUINT_TO_POINTER (CONNECT));
> +        mbim_message_unref (request);
> +        return;
> +    }
> +
> +    /* Disconnect? */
> +    if (set_connect_deactivate_str) 
> +    {
> +        if (!set_dss_command_parse (set_connect_deactivate_str,
> +                                    &service_id,
> +                                    &session_id)) {
> +            shutdown (FALSE);
> +            return;
> +        }
> +
> +        request = mbim_message_dss_connect_set_new (&service_id,
> +                                                    session_id,
> +                                                    MBIM_DSS_LINK_STATE_DEACTIVATE,
> +                                                    &error);
> +        if (!request) {
> +            g_printerr ("error: couldn't create request: %s\n", error->message);
> +            g_error_free (error);
> +            shutdown (FALSE);
> +            return;
> +        }
> +
> +        mbim_device_command (ctx->device,
> +                             request,
> +                             10,
> +                             ctx->cancellable,
> +                             (GAsyncReadyCallback)set_dss_ready,
> +                             GUINT_TO_POINTER (DISCONNECT));
> +        mbim_message_unref (request);
> +        return;
> +    }
> +
> +    g_warn_if_reached ();
> +}
> diff --git a/src/mbimcli/mbimcli.c b/src/mbimcli/mbimcli.c
> index d95363d..08fdd8e 100644
> --- a/src/mbimcli/mbimcli.c
> +++ b/src/mbimcli/mbimcli.c
> @@ -260,6 +260,9 @@ device_open_ready (MbimDevice   *dev,
>      case MBIM_SERVICE_MS_FIRMWARE_ID:
>          mbimcli_ms_firmware_id_run (dev, cancellable);
>          return;
> +    case MBIM_SERVICE_DSS:
> +        mbimcli_dss_run (dev, cancellable);
> +        return;
>      default:
>          g_assert_not_reached ();
>      }
> @@ -341,6 +344,9 @@ parse_actions (void)
>      } else if (mbimcli_ms_firmware_id_options_enabled ()) {
>          service = MBIM_SERVICE_MS_FIRMWARE_ID;
>          actions_enabled++;
> +    } else if (mbimcli_dss_options_enabled ()) {
> +        service = MBIM_SERVICE_DSS;
> +        actions_enabled++;
>      }
>  
>      /* Noop */
> @@ -380,6 +386,8 @@ int main (int argc, char **argv)
>  	                            mbimcli_phonebook_get_option_group ());
>      g_option_context_add_group (context,
>                                  mbimcli_ms_firmware_id_get_option_group ());
> +    g_option_context_add_group (context,
> +	                            mbimcli_dss_get_option_group ());
>      g_option_context_add_main_entries (context, main_entries, NULL);
>      if (!g_option_context_parse (context, &argc, &argv, &error)) {
>          g_printerr ("error: %s\n",
> diff --git a/src/mbimcli/mbimcli.h b/src/mbimcli/mbimcli.h
> index 5959249..06c00e9 100644
> --- a/src/mbimcli/mbimcli.h
> +++ b/src/mbimcli/mbimcli.h
> @@ -32,14 +32,20 @@ void mbimcli_async_operation_done (gboolean operation_status);
>  GOptionGroup *mbimcli_basic_connect_get_option_group  (void);
>  GOptionGroup *mbimcli_phonebook_get_option_group      (void);
>  GOptionGroup *mbimcli_ms_firmware_id_get_option_group (void);
> +GOptionGroup *mbimcli_dss_get_option_group            (void);
> +
>  gboolean      mbimcli_basic_connect_options_enabled   (void);
>  gboolean      mbimcli_phonebook_options_enabled       (void);
>  gboolean      mbimcli_ms_firmware_id_options_enabled  (void);
> +gboolean      mbimcli_dss_options_enabled             (void);
> +
>  void          mbimcli_basic_connect_run               (MbimDevice *device,
>                                                         GCancellable *cancellable);
>  void          mbimcli_phonebook_run                   (MbimDevice *device,
>                                                         GCancellable *cancellable);
>  void          mbimcli_ms_firmware_id_run              (MbimDevice *device,
>                                                         GCancellable *cancellable);
> +void          mbimcli_dss_run                         (MbimDevice *device,
> +                                                       GCancellable *cancellable);
>  
>  #endif /* __MBIMCLI_H__ */
> 
> 
> 
> -----Original Message-----
> From: Aleksander Morgado [mailto:aleksander at aleksander.es] 
> Sent: Monday, February 24, 2014 8:42 PM
> To: Scott Lee
> Cc: libmbim-devel at lists.freedesktop.org
> Subject: Re: Adding new mbimcli option to open/close DSS channels?
> 
> Hey Scott,
> 
> On Mon, Feb 24, 2014 at 12:03 PM, Scott Lee <sclee at nvidia.com> wrote:
>> We’re working on our LTE modem to support MBIM interface.
>>
>> We need to open DSS channels and we find there’s 
>> “mbim_message_dss_connect_set_new” function in “mbim-dss.c”.
>>
>> However it’s not available in any mbimcli options.
>>
>> Would you please suggest whether it’s under developing, or we could 
>> submit a patch for it?
>>
>> If we could do it, is it good to add a new group “dss” or we should 
>> add it into existing group such as “basic-connect”?
> 
> There were plans to add it to mbimcli, but nothing was done yet. If added, it should go to its own 'dss' group.
> 
> Cheers,
> 
> --
> Aleksander
> https://aleksander.es
> 
> -----------------------------------------------------------------------------------
> This email message is for the sole use of the intended recipient(s) and may contain
> confidential information.  Any unauthorized review, use, disclosure or distribution
> is prohibited.  If you are not the intended recipient, please contact the sender by
> reply email and destroy all copies of the original message.
> -----------------------------------------------------------------------------------
> 


-- 
Aleksander
https://aleksander.es


More information about the libmbim-devel mailing list