Merge remote-tracking branch 'cros/upstream' into 'cros/master'
Change-Id: I0aae7ddf8283e9c7228358875f48cce7dca1ad92
diff --git a/PRESUBMIT.cfg b/PRESUBMIT.cfg
new file mode 100644
index 0000000..51d8dd6
--- /dev/null
+++ b/PRESUBMIT.cfg
@@ -0,0 +1,9 @@
+# This sample config file disables all of the ChromiumOS source style checks.
+# Comment out the disable-flags for any checks you want to leave enabled.
+
+[Hook Overrides]
+stray_whitespace_check: false
+long_line_check: false
+cros_license_check: false
+tab_check: false
+
diff --git a/README.chromium b/README.chromium
new file mode 100644
index 0000000..5f73a1c
--- /dev/null
+++ b/README.chromium
@@ -0,0 +1,20 @@
+DESCRIPTION="Broadband modem support daemon (new API)"
+HOMEPAGE="http://projects.gnome.org/NetworkManager/"
+UPSTREAM_REPO="git://anongit.freedesktop.org/ModemManager/ModemManager"
+LOCAL_GIT_REPO="http://git.chromium.org/chromiumos/third_party/modemmanager-next.git"
+UPSTREAM_BUGSDB="https://bugzilla.gnome.org/enter_bug.cgi?product=NetworkManager"
+LOCAL_BUGSDB="http://crosbug.com"
+LICENSE="GPLv2"
+LICENSE_FILE="COPYING"
+
+Description:
+
+ModemManager provides a DBus interface to control broadband modem
+devices. The intended user is a network manager program, such as
+NetworkManager, flimflam, or shill.
+
+This repository mirrors the 0.6-api branch of the upstream repository
+while it is under active development as a branch.
+
+Local changes should be minimal, but support for particular modems may
+make it here before they make it upstream.
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 0467869..d7a0e40 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -43,6 +43,7 @@
libmm-plugin-gobi.la \
libmm-plugin-motorola.la \
libmm-plugin-novatel.la \
+ libmm-plugin-samsung.la \
libmm-plugin-option.la \
libmm-plugin-hso.la \
libmm-plugin-anydata.la \
@@ -249,6 +250,17 @@
#libmm_plugin_samsung_la_LIBADD = $(builddir)/libicera-utils.la
#
+# Samsung modem
+libmm_plugin_samsung_la_SOURCES = \
+ samsung/mm-plugin-samsung.c \
+ samsung/mm-plugin-samsung.h \
+ samsung/mm-broadband-modem-samsung.c \
+ samsung/mm-broadband-modem-samsung.h \
+ samsung/mm-broadband-bearer-samsung.c \
+ samsung/mm-broadband-bearer-samsung.h
+libmm_plugin_samsung_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)
+libmm_plugin_samsung_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
+
# Cinterion (previously Siemens) modem
libmm_plugin_cinterion_la_SOURCES = \
cinterion/mm-plugin-cinterion.c \
diff --git a/plugins/samsung/mm-broadband-bearer-samsung.c b/plugins/samsung/mm-broadband-bearer-samsung.c
new file mode 100644
index 0000000..9b36d71
--- /dev/null
+++ b/plugins/samsung/mm-broadband-bearer-samsung.c
@@ -0,0 +1,612 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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:
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <ModemManager.h>
+#include <libmm-common.h>
+
+#include "mm-base-modem-at.h"
+#include "mm-broadband-bearer-samsung.h"
+#include "mm-log.h"
+#include "mm-modem-helpers.h"
+#include "mm-utils.h"
+
+G_DEFINE_TYPE (MMBroadbandBearerSamsung, mm_broadband_bearer_samsung, MM_TYPE_BROADBAND_BEARER);
+
+/*****************************************************************************/
+
+
+typedef struct {
+ MMBroadbandBearerSamsung *self;
+ MMBaseModem *modem;
+ MMAtSerialPort *primary;
+ GCancellable *cancellable;
+ GSimpleAsyncResult *result;
+
+ guint cid;
+ guint timeout_id;
+} DialContext;
+
+typedef struct {
+ MMBroadbandBearerSamsung *self;
+ GSimpleAsyncResult *result;
+ guint timeout_id;
+} DisconnectContext;
+
+struct _MMBroadbandBearerSamsungPrivate {
+ guint connected_cid;
+ DialContext *pending_dial;
+ DisconnectContext *pending_disconnect;
+};
+
+static DialContext *
+dial_context_new (MMBroadbandBearerSamsung *self,
+ MMBaseModem *modem,
+ MMAtSerialPort *primary,
+ GCancellable *cancellable,
+ guint cid,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ DialContext *ctx;
+
+ ctx = g_new0 (DialContext, 1);
+ ctx->self = g_object_ref (self);
+ ctx->modem = g_object_ref (modem);
+ ctx->primary = g_object_ref (primary);
+ ctx->cancellable = g_object_ref (cancellable);
+ ctx->result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ dial_context_new);
+ ctx->cid = cid;
+ ctx->timeout_id = 0;
+ return ctx;
+}
+
+static void
+dial_context_complete_and_free (DialContext *ctx)
+{
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+ g_object_unref (ctx->cancellable);
+ g_object_unref (ctx->primary);
+ g_object_unref (ctx->modem);
+ g_object_unref (ctx->self);
+ g_free (ctx);
+}
+
+/*
+ * "dial" steps:
+ * %IPDPCFG=<cid>,0,0,"",""
+ * or %IPDPCFG=<cid>,0,1,"username","password" (may need a retry)
+ * %IPDPACT=<cid>,0 (optional, generates annoying error message)
+ * %IPDPACT=<cid>,1
+ * wait for unsolicited %IPDPACT=<cid>,1
+ */
+
+static gboolean
+dial_3gpp_finish (MMBroadbandBearer *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+
+static gboolean
+dial_3gpp_timeout (DialContext *ctx)
+{
+ MMBroadbandBearerSamsung *self = ctx->self;
+
+ g_simple_async_result_set_error (ctx->result,
+ MM_SERIAL_ERROR,
+ MM_SERIAL_ERROR_RESPONSE_TIMEOUT,
+ "Timed out waiting for connection to complete");
+ dial_context_complete_and_free (ctx);
+ self->priv->connected_cid = 0;
+ self->priv->pending_dial = NULL;
+
+ return FALSE;
+}
+
+
+static void
+dial_3gpp_done (MMBroadbandBearerSamsung *self,
+ DialContext *ctx)
+{
+
+ self->priv->connected_cid = self->priv->pending_dial->cid;
+
+ if (ctx->timeout_id) {
+ g_source_remove (ctx->timeout_id);
+ ctx->timeout_id = 0;
+ }
+
+ dial_context_complete_and_free (ctx);
+ self->priv->pending_dial = NULL;
+}
+
+static void
+dial_3gpp_get_error_done (MMBaseModem *modem,
+ GAsyncResult *res,
+ DialContext *ctx)
+{
+ MMBroadbandBearerSamsung *self = ctx->self;
+ const gchar *response;
+ int activation_err;
+ GError *error = NULL;
+
+ response = mm_base_modem_at_command_finish (modem, res, &error);
+
+ if (error) {
+ g_simple_async_result_take_error (ctx->result, error);
+ dial_context_complete_and_free (ctx);
+ return;
+ }
+
+ response = mm_strip_tag (response, "%IER:");
+ if (sscanf (response, " %*d,%*d,%d", &activation_err) &&
+ (activation_err == 27 || activation_err == 33)) {
+ g_simple_async_result_set_error (ctx->result,
+ MM_MOBILE_EQUIPMENT_ERROR,
+ MM_MOBILE_EQUIPMENT_ERROR_GPRS_SERVICE_OPTION_NOT_SUBSCRIBED,
+ "Missing or unknown APN");
+ } else {
+ g_simple_async_result_set_error (ctx->result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Call setup failed");
+ }
+
+ dial_context_complete_and_free (ctx);
+ self->priv->connected_cid = 0;
+ self->priv->pending_dial = NULL;
+}
+
+static void
+dial_3gpp_get_error (MMBroadbandBearerSamsung *self,
+ DialContext *ctx)
+{
+ mm_dbg("checking what the error was");
+ if (ctx->timeout_id) {
+ g_source_remove (ctx->timeout_id);
+ ctx->timeout_id = 0;
+ }
+
+ mm_base_modem_at_command (ctx->modem,
+ "%IER?",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)dial_3gpp_get_error_done,
+ ctx);
+}
+
+static void
+disconnect_3gpp_done (MMBroadbandBearerSamsung *self,
+ DisconnectContext *result);
+
+static void
+ipdpact_received (MMAtSerialPort *port,
+ GMatchInfo *info,
+ MMBroadbandBearerSamsung *self)
+{
+ char *str;
+ int cid, status;
+
+ str = g_match_info_fetch (info, 1);
+ g_return_if_fail (str != NULL);
+ cid = atoi (str);
+ g_free (str);
+
+ if (cid != self->priv->connected_cid) {
+ mm_warn ("Recieved %%IPDPACT message for CID other than the current one (%d).",
+ self->priv->connected_cid);
+ return;
+ }
+
+ str = g_match_info_fetch (info, 2);
+ g_return_if_fail (str != NULL);
+ status = atoi (str);
+ g_free (str);
+
+ switch (status) {
+ case 0:
+ /* deactivated */
+ if (self->priv->pending_disconnect == NULL) {
+ mm_dbg ("Recieved spontaneous %%IPDPACT disconnect.");
+ mm_bearer_report_disconnection (MM_BEARER (self));
+ return;
+ }
+ disconnect_3gpp_done (self, self->priv->pending_disconnect);
+ break;
+ case 1:
+ /* activated */
+ if (self->priv->pending_dial == NULL) {
+ mm_warn ("Recieved %%IPDPACT connect while not connecting.");
+ return;
+ }
+ dial_3gpp_done (self, self->priv->pending_dial);
+ break;
+ case 2:
+ /* activating */
+ break;
+ case 3:
+ /* activation failed */
+ if (self->priv->pending_dial == NULL) {
+ mm_warn ("Recieved %%IPDPACT failure while not connecting.");
+ return;
+ }
+ dial_3gpp_get_error (self, self->priv->pending_dial);
+ break;
+ default:
+ mm_warn ("Unknown connect status %d", status);
+ break;
+ }
+}
+
+static void
+dial_3gpp_wait (MMBaseModem *modem,
+ GAsyncResult *res,
+ DialContext *ctx)
+{
+ GError *error = NULL;
+
+ mm_base_modem_at_command_finish (modem, res, &error);
+
+ if (error) {
+ g_simple_async_result_take_error (ctx->result, error);
+ dial_context_complete_and_free (ctx);
+ return;
+ }
+
+ /* Set a 60-second connection-failure timeout */
+ ctx->timeout_id = g_timeout_add_seconds (60, (GSourceFunc)dial_3gpp_timeout, ctx);
+}
+
+static void
+dial_3gpp_activate (MMBaseModem *modem,
+ GAsyncResult *res,
+ DialContext *ctx)
+{
+ gchar *command;
+
+ /*
+ * Ignore any error here; %IPDPACT=ctx,0 will produce an error 767
+ * if the context is not, in fact, connected. This is annoying but
+ * harmless.
+ */
+ mm_base_modem_at_command_finish (modem, res, NULL);
+
+ command = g_strdup_printf ("%%IPDPACT=%d,1", ctx->cid);
+ mm_base_modem_at_command (
+ ctx->modem,
+ command,
+ 60,
+ FALSE,
+ (GAsyncReadyCallback)dial_3gpp_wait,
+ ctx);
+ g_free (command);
+
+ /* The unsolicited response to %IPDPACT may come before the OK does */
+ ctx->self->priv->pending_dial = ctx;
+ ctx->self->priv->connected_cid = ctx->cid;
+}
+
+static void
+dial_3gpp_prepare (MMBaseModem *modem,
+ GAsyncResult *res,
+ DialContext *ctx)
+{
+ gchar *command;
+ GError *error = NULL;
+
+ mm_base_modem_at_command_finish (modem, res, &error);
+
+ if (error) {
+ /* TODO(njw): retry up to 3 times with a 1-second delay */
+ /* Return an error */
+ g_simple_async_result_take_error (ctx->result, error);
+ dial_context_complete_and_free (ctx);
+ return;
+ }
+
+ /*
+ * Deactivate the context we want to use before we try to activate
+ * it. This handles the case where ModemManager crashed while
+ * connected and is now trying to reconnect. (Should some part of
+ * the core or modem driver have made sure of this already?)
+ */
+ command = g_strdup_printf ("%%IPDPACT=%d,0", ctx->cid);
+ mm_base_modem_at_command (
+ ctx->modem,
+ command,
+ 60,
+ FALSE,
+ (GAsyncReadyCallback)dial_3gpp_activate,
+ ctx);
+ g_free (command);
+}
+
+static void
+dial_3gpp (MMBroadbandBearer *self,
+ MMBaseModem *modem,
+ MMAtSerialPort *primary,
+ guint cid,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ DialContext *ctx;
+ gchar *command;
+ const gchar *user, *password;
+ MMBearerProperties *config;
+
+ ctx = dial_context_new (MM_BROADBAND_BEARER_SAMSUNG (self),
+ modem,
+ primary,
+ cancellable,
+ cid,
+ callback,
+ user_data);
+
+ config = mm_bearer_peek_config (MM_BEARER (ctx->self));
+ user = mm_bearer_properties_get_user (config);
+ password = mm_bearer_properties_get_password (config);
+
+ if (!user && !password) {
+ command = g_strdup_printf ("%%IPDPCFG=%d,0,0,\"\",\"\"", cid);
+ } else {
+ gchar *quoted_user, *quoted_password;
+ quoted_user = mm_at_serial_port_quote_string (user);
+ quoted_password = mm_at_serial_port_quote_string (password);
+ command = g_strdup_printf ("%%IPDPCFG=%d,0,1,%s,%s",
+ cid, user, password);
+ g_free (quoted_user);
+ g_free (quoted_password);
+ }
+
+ mm_base_modem_at_command (
+ ctx->modem,
+ command,
+ 60,
+ FALSE,
+ (GAsyncReadyCallback)dial_3gpp_prepare,
+ ctx);
+ g_free (command);
+}
+
+static gboolean
+disconnect_3gpp_finish (MMBroadbandBearer *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static gboolean
+disconnect_3gpp_timeout (DisconnectContext *ctx)
+{
+ MMBroadbandBearerSamsung *self = ctx->self;
+
+ g_simple_async_result_set_error (ctx->result,
+ MM_SERIAL_ERROR,
+ MM_SERIAL_ERROR_RESPONSE_TIMEOUT,
+ "Timed out waiting for connection to complete");
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+
+ self->priv->pending_disconnect = NULL;
+ g_free (ctx);
+
+ return FALSE;
+}
+
+static void
+disconnect_3gpp_done (MMBroadbandBearerSamsung *self,
+ DisconnectContext *ctx)
+{
+ if (ctx->timeout_id) {
+ g_source_remove (ctx->timeout_id);
+ ctx->timeout_id = 0;
+ }
+
+ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+
+ self->priv->pending_disconnect = NULL;
+ self->priv->connected_cid = 0;
+ g_free (ctx);
+}
+
+static void
+disconnect_3gpp_ready (MMBaseModem *modem,
+ GAsyncResult *res,
+ DisconnectContext *ctx)
+{
+ GError *error = NULL;
+
+ mm_base_modem_at_command_finish (MM_BASE_MODEM (modem), res, &error);
+ if (error) {
+ mm_dbg ("PDP context deactivation failed: %s", error->message);
+ g_simple_async_result_take_error (ctx->result, error);
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+ if (ctx->timeout_id) {
+ g_source_remove (ctx->timeout_id);
+ ctx->timeout_id = 0;
+ }
+ ctx->self->priv->pending_disconnect = NULL;
+ g_free (ctx);
+ return;
+ }
+}
+
+static void
+disconnect_3gpp (MMBroadbandBearer *bearer,
+ MMBroadbandModem *modem,
+ MMAtSerialPort *primary,
+ MMAtSerialPort *secondary,
+ MMPort *data,
+ guint cid,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ MMBroadbandBearerSamsung *self = MM_BROADBAND_BEARER_SAMSUNG (bearer);
+ gchar *command;
+ DisconnectContext *ctx;
+
+ ctx = g_new0 (DisconnectContext, 1);
+ ctx->self = self;
+ ctx->result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ disconnect_3gpp);
+
+ command = g_strdup_printf ("%%IPDPACT=%d,0", self->priv->connected_cid);
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (modem),
+ command,
+ 60,
+ FALSE,
+ (GAsyncReadyCallback)disconnect_3gpp_ready,
+ ctx);
+ g_free (command);
+
+ self->priv->pending_disconnect = ctx;
+
+ /* Set a 60-second disconnection-failure timeout */
+ ctx->timeout_id = g_timeout_add_seconds (
+ 60, (GSourceFunc)disconnect_3gpp_timeout, ctx);
+}
+
+static void
+set_unsolicited_result_codes (MMBroadbandBearerSamsung *self, gboolean enable)
+{
+ MMBroadbandModemSamsung *modem;
+ MMAtSerialPort *ports[2];
+ GRegex *ipdpact_regex;
+ guint i;
+
+ g_object_get (self,
+ MM_BEARER_MODEM, &modem,
+ NULL);
+ g_assert (modem != NULL);
+
+ ipdpact_regex = g_regex_new(
+ "\\r\\n%IPDPACT:\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)\\r\\n",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE,
+ 0,
+ NULL);
+
+ ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (modem));
+ ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (modem));
+ for (i = 0; ports[i] && i < 2; i++) {
+ mm_at_serial_port_add_unsolicited_msg_handler (
+ ports[i],
+ ipdpact_regex,
+ enable ? (MMAtSerialUnsolicitedMsgFn) ipdpact_received : NULL,
+ enable ? self : NULL,
+ NULL);
+ }
+ g_object_unref (modem);
+ g_regex_unref (ipdpact_regex);
+}
+
+static void
+dispose (GObject *object)
+{
+ MMBroadbandBearerSamsung *self = MM_BROADBAND_BEARER_SAMSUNG (object);
+
+ set_unsolicited_result_codes (self, FALSE);
+
+ G_OBJECT_CLASS (mm_broadband_bearer_samsung_parent_class)->dispose (object);
+}
+
+static void
+mm_broadband_bearer_samsung_init (MMBroadbandBearerSamsung *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
+ MM_TYPE_BROADBAND_BEARER_SAMSUNG,
+ MMBroadbandBearerSamsungPrivate);
+
+ /* Set defaults */
+ self->priv->connected_cid = 0;
+ self->priv->pending_dial = NULL;
+ self->priv->pending_disconnect = NULL;
+}
+
+static void
+mm_broadband_bearer_samsung_class_init (MMBroadbandBearerSamsungClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ MMBroadbandBearerClass *broadband_bearer_class = MM_BROADBAND_BEARER_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (MMBroadbandBearerSamsungPrivate));
+
+ object_class->dispose = dispose;
+
+ broadband_bearer_class->dial_3gpp = dial_3gpp;
+ broadband_bearer_class->dial_3gpp_finish = dial_3gpp_finish;
+ broadband_bearer_class->disconnect_3gpp = disconnect_3gpp;
+ broadband_bearer_class->disconnect_3gpp_finish = disconnect_3gpp_finish;
+}
+
+MMBearer *
+mm_broadband_bearer_samsung_new_finish (GAsyncResult *res,
+ GError **error)
+{
+ GObject *source;
+ GObject *bearer;
+
+ source = g_async_result_get_source_object (res);
+ bearer = g_async_initable_new_finish (G_ASYNC_INITABLE (source), res, error);
+ g_object_unref (source);
+
+ if (!bearer)
+ return NULL;
+
+ set_unsolicited_result_codes (MM_BROADBAND_BEARER_SAMSUNG (bearer), TRUE);
+
+ /* Only export valid bearers */
+ mm_bearer_export (MM_BEARER (bearer));
+
+ return MM_BEARER (bearer);
+}
+
+void mm_broadband_bearer_samsung_new (MMBroadbandModemSamsung *modem,
+ MMBearerProperties *config,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_async_initable_new_async (
+ MM_TYPE_BROADBAND_BEARER_SAMSUNG,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ callback,
+ user_data,
+ MM_BEARER_MODEM, modem,
+ MM_BEARER_CONFIG, config,
+ NULL);
+}
diff --git a/plugins/samsung/mm-broadband-bearer-samsung.h b/plugins/samsung/mm-broadband-bearer-samsung.h
new file mode 100644
index 0000000..bbc5947
--- /dev/null
+++ b/plugins/samsung/mm-broadband-bearer-samsung.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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:
+ *
+ * Author: Nathan Williams <njw@google.com>
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#ifndef MM_BROADBAND_BEARER_SAMSUNG_H
+#define MM_BROADBAND_BEARER_SAMSUNG_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <libmm-common.h>
+
+#include "mm-broadband-bearer.h"
+#include "mm-broadband-modem-samsung.h"
+
+#define MM_TYPE_BROADBAND_BEARER_SAMSUNG (mm_broadband_bearer_samsung_get_type ())
+#define MM_BROADBAND_BEARER_SAMSUNG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_BEARER_SAMSUNG, MMBroadbandBearerSamsung))
+#define MM_BROADBAND_BEARER_SAMSUNG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_BEARER_SAMSUNG, MMBroadbandBearerSamsungClass))
+#define MM_IS_BROADBAND_BEARER_SAMSUNG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_BEARER_SAMSUNG))
+#define MM_IS_BROADBAND_BEARER_SAMSUNG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_BEARER_SAMSUNG))
+#define MM_BROADBAND_BEARER_SAMSUNG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_BEARER_SAMSUNG, MMBroadbandBearerSamsungClass))
+
+#define MM_BROADBAND_BEARER_SAMSUNG_USER "broadband-bearer-samsung-user"
+#define MM_BROADBAND_BEARER_SAMSUNG_PASSWORD "broadband-bearer-samsung-password"
+
+typedef struct _MMBroadbandBearerSamsung MMBroadbandBearerSamsung;
+typedef struct _MMBroadbandBearerSamsungClass MMBroadbandBearerSamsungClass;
+typedef struct _MMBroadbandBearerSamsungPrivate MMBroadbandBearerSamsungPrivate;
+
+struct _MMBroadbandBearerSamsung {
+ MMBroadbandBearer parent;
+ MMBroadbandBearerSamsungPrivate *priv;
+};
+
+struct _MMBroadbandBearerSamsungClass {
+ MMBroadbandBearerClass parent;
+};
+
+GType mm_broadband_bearer_samsung_get_type (void);
+
+/* Default 3GPP bearer creation implementation */
+void mm_broadband_bearer_samsung_new (MMBroadbandModemSamsung *modem,
+ MMBearerProperties *properties,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMBearer *mm_broadband_bearer_samsung_new_finish (GAsyncResult *res,
+ GError **error);
+
+#endif /* MM_BROADBAND_BEARER_SAMSUNG_H */
diff --git a/plugins/samsung/mm-broadband-modem-samsung.c b/plugins/samsung/mm-broadband-modem-samsung.c
new file mode 100644
index 0000000..5c7e91b
--- /dev/null
+++ b/plugins/samsung/mm-broadband-modem-samsung.c
@@ -0,0 +1,1179 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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:
+ *
+ *
+ * Copyright (C) 2012 Google Inc.
+ * Author: Nathan Williams <njw@google.com>
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "ModemManager.h"
+#include "mm-base-modem-at.h"
+#include "mm-broadband-bearer-samsung.h"
+#include "mm-broadband-modem-samsung.h"
+#include "mm-iface-modem.h"
+#include "mm-iface-modem-3gpp.h"
+#include "mm-modem-helpers.h"
+#include "mm-log.h"
+
+static void iface_modem_init (MMIfaceModem *iface);
+static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface);
+
+static MMIfaceModem3gpp *iface_modem_3gpp_parent;
+
+G_DEFINE_TYPE_EXTENDED (MMBroadbandModemSamsung, mm_broadband_modem_samsung, MM_TYPE_BROADBAND_MODEM, 0,
+ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)
+ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init));
+
+struct _MMBroadbandModemSamsungPrivate {
+ GRegex *nwstate_regex;
+
+ /* Cache of the most recent value seen by the unsolicited-message handler */
+ MMModemAccessTechnology last_act;
+};
+
+/*****************************************************************************/
+
+static gboolean
+load_access_technologies_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ MMModemAccessTechnology *access_technologies,
+ guint *mask,
+ GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return FALSE;
+
+ *access_technologies = (MMModemAccessTechnology) GPOINTER_TO_UINT (
+ g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (res)));
+ *mask = MM_MODEM_ACCESS_TECHNOLOGY_ANY;
+ return TRUE;
+}
+
+static MMModemAccessTechnology
+nwstate_to_act (const char *str)
+{
+ /* small 'g' means CS, big 'G' means PS */
+ if (!strcmp (str, "2g"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_GSM;
+ else if (!strcmp (str, "2G-GPRS"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_GPRS;
+ else if (!strcmp (str, "2G-EDGE"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_EDGE;
+ else if (!strcmp (str, "3G"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_UMTS;
+ else if (!strcmp (str, "3g"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_UMTS;
+ else if (!strcmp (str, "R99"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_UMTS;
+ else if (!strcmp (str, "3G-HSDPA") || !strcmp (str, "HSDPA"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_HSDPA;
+ else if (!strcmp (str, "3G-HSUPA") || !strcmp (str, "HSUPA"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_HSUPA;
+ else if (!strcmp (str, "3G-HSDPA-HSUPA") || !strcmp (str, "HSDPA-HSUPA"))
+ return MM_MODEM_ACCESS_TECHNOLOGY_HSPA;
+
+ return MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+}
+
+static void
+load_access_technologies_ready (MMIfaceModem *modem,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ MMBroadbandModemSamsung *self = MM_BROADBAND_MODEM_SAMSUNG (modem);
+ const gchar *response;
+ GError *error = NULL;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ mm_dbg ("Couldn't query access technology: '%s'", error->message);
+ g_simple_async_result_take_error (operation_result, error);
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+ return;
+ }
+
+ /*
+ * The unsolicited message handler will already have run and
+ * removed the NWSTATE response, so we use the result from there.
+ */
+ g_simple_async_result_set_op_res_gpointer (operation_result,
+ GUINT_TO_POINTER (self->priv->last_act),
+ NULL);
+ g_simple_async_result_complete_in_idle (operation_result);
+ g_object_unref (operation_result);
+}
+
+static void
+load_access_technologies (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_access_technologies);
+
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "%NWSTATE",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)load_access_technologies_ready,
+ result);
+}
+
+typedef struct {
+ MMModemBand band;
+ const char *name;
+} BandTable;
+
+static BandTable modem_bands[] = {
+ /* Sort 3G first since it's preferred */
+ { MM_MODEM_BAND_U2100, "FDD_BAND_I" },
+ { MM_MODEM_BAND_U1900, "FDD_BAND_II" },
+ /*
+ * Several bands are forbidden to set and will always read as
+ * disabled, so we won't present them to the rest of
+ * modemmanager.
+ */
+ /* { MM_MODEM_BAND_U1800, "FDD_BAND_III" }, */
+ /* { MM_MODEM_BAND_U17IV, "FDD_BAND_IV" }, */
+ /* { MM_MODEM_BAND_U800, "FDD_BAND_VI" }, */
+ { MM_MODEM_BAND_U850, "FDD_BAND_V" },
+ { MM_MODEM_BAND_U900, "FDD_BAND_VIII" },
+ { MM_MODEM_BAND_G850, "G850" },
+ /* 2G second */
+ { MM_MODEM_BAND_DCS, "DCS" },
+ { MM_MODEM_BAND_EGSM, "EGSM" },
+ { MM_MODEM_BAND_PCS, "PCS" },
+ /* And ANY last since it's most inclusive */
+ { MM_MODEM_BAND_ANY, "ANY" },
+};
+
+
+static GArray *
+load_supported_bands_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ /* Never fails */
+ return (GArray *) g_array_ref (g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+static void
+load_supported_bands (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ GArray *bands;
+ guint i;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_supported_bands);
+
+ /*
+ * The modem doesn't support telling us what bands are supported;
+ * list everything we know about.
+ */
+ bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), G_N_ELEMENTS (modem_bands));
+ for (i = 0 ; i < G_N_ELEMENTS (modem_bands) ; i++) {
+ if (modem_bands[i].band != MM_MODEM_BAND_ANY)
+ g_array_append_val(bands, modem_bands[i].band);
+ }
+
+ g_simple_async_result_set_op_res_gpointer (result,
+ bands,
+ (GDestroyNotify)g_array_unref);
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
+static GArray *
+load_current_bands_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return NULL;
+ return (GArray *) g_array_ref (g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+static void
+load_current_bands_ready (MMIfaceModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ GRegex *r;
+ GMatchInfo *info;
+ GArray *bands;
+ const gchar *response;
+ GError *error = NULL;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ mm_dbg ("Couldn't query supported bands: '%s'", error->message);
+ g_simple_async_result_take_error (operation_result, error);
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+ return;
+ }
+
+ /*
+ * Response is a number of lines of the form:
+ * "EGSM": 0
+ * "FDD_BAND_I": 1
+ * ...
+ * with 1 and 0 indicating whether the particular band is enabled or not.
+ */
+ r = g_regex_new ("^\"(\\w+)\": (\\d)",
+ G_REGEX_MULTILINE, G_REGEX_MATCH_NEWLINE_ANY,
+ NULL);
+ g_assert (r != NULL);
+
+ bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand),
+ G_N_ELEMENTS (modem_bands));
+
+ g_regex_match (r, response, 0, &info);
+ while (g_match_info_matches (info)) {
+ gchar *band, *enabled;
+
+ band = g_match_info_fetch (info, 1);
+ enabled = g_match_info_fetch (info, 2);
+ if (enabled[0] == '1') {
+ guint i;
+ for (i = 0 ; i < G_N_ELEMENTS (modem_bands); i++) {
+ if (!strcmp (band, modem_bands[i].name)) {
+ g_array_append_val (bands, modem_bands[i].band);
+ break;
+ }
+ }
+ }
+ g_free (band);
+ g_free (enabled);
+ g_match_info_next (info, NULL);
+ }
+ g_match_info_free (info);
+ g_regex_unref (r);
+
+ g_simple_async_result_set_op_res_gpointer (operation_result,
+ bands,
+ (GDestroyNotify)g_array_unref);
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+}
+
+static void
+load_current_bands (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_current_bands);
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "%IPBM?",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)load_current_bands_ready,
+ result);
+}
+
+
+typedef struct {
+ GSimpleAsyncResult *result;
+ guint bandbits;
+ guint enablebits;
+ guint disablebits;
+} SetBandsContext;
+
+/*
+ * The modem's band-setting command (%IPBM=) enables or disables one
+ * band at a time, and one band must always be enabled. Here, we first
+ * get the set of enabled bands, compute the difference between that
+ * set and the requested set, enable any added bands, and finally
+ * disable any removed bands.
+ */
+static gboolean
+set_bands_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void set_one_band (MMIfaceModem *self, SetBandsContext *ctx);
+
+static void
+set_bands_context_complete_and_free (SetBandsContext *ctx)
+{
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+ g_free (ctx);
+}
+
+static void
+set_bands_next (MMIfaceModem *self,
+ GAsyncResult *res,
+ SetBandsContext *ctx)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error)) {
+ mm_dbg ("Couldn't set bands: '%s'", error->message);
+ g_simple_async_result_take_error (ctx->result, error);
+ set_bands_context_complete_and_free (ctx);
+ return;
+ }
+
+ set_one_band (self, ctx);
+}
+
+static void
+set_one_band (MMIfaceModem *self,
+ SetBandsContext *ctx)
+{
+ guint enable, band;
+ gchar *command;
+
+ /* Find the next band to enable or disable, always doing enables first */
+ enable = 1;
+ band = ffs (ctx->enablebits);
+ if (band == 0) {
+ enable = 0;
+ band = ffs (ctx->disablebits);
+ }
+ if (band == 0) {
+ /* Both enabling and disabling are done */
+ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
+ set_bands_context_complete_and_free (ctx);
+ return;
+ }
+
+ /* Note that ffs() returning 2 corresponds to 1 << 1, not 1 << 2 */
+ band--;
+ mm_dbg("1. enablebits %x disablebits %x band %d enable %d",
+ ctx->enablebits, ctx->disablebits, band, enable);
+
+ if (enable)
+ ctx->enablebits &= ~(1 << band);
+ else
+ ctx->disablebits &= ~(1 << band);
+ mm_dbg("2. enablebits %x disablebits %x",
+ ctx->enablebits, ctx->disablebits);
+
+ command = g_strdup_printf ("%%IPBM=\"%s\",%d",
+ modem_bands[band].name,
+ enable);
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ command,
+ 10,
+ FALSE,
+ (GAsyncReadyCallback)set_bands_next,
+ ctx);
+ g_free (command);
+}
+
+static guint
+band_array_to_bandbits (GArray *bands)
+{
+ MMModemBand band;
+ guint i, j, bandbits;
+
+ bandbits = 0;
+ for (i = 0 ; i < bands->len ; i++) {
+ band = g_array_index (bands, MMModemBand, i);
+ for (j = 0 ; j < G_N_ELEMENTS (modem_bands) ; j++) {
+ if (modem_bands[j].band == band) {
+ bandbits |= 1 << j;
+ break;
+ }
+ }
+ g_assert (j < G_N_ELEMENTS (modem_bands));
+ }
+
+ return bandbits;
+}
+
+static void
+set_bands_got_current_bands (MMIfaceModem *self,
+ GAsyncResult *res,
+ SetBandsContext *ctx)
+{
+ GArray *bands;
+ GError *error = NULL;
+ guint currentbits;
+
+ bands = load_current_bands_finish (self, res, &error);
+ if (!bands) {
+ g_simple_async_result_take_error (ctx->result, error);
+ set_bands_context_complete_and_free (ctx);
+ return;
+ }
+
+ currentbits = band_array_to_bandbits (bands);
+ ctx->enablebits = ctx->bandbits & ~currentbits;
+ ctx->disablebits = currentbits & ~ctx->bandbits;
+
+ set_one_band (self, ctx);
+}
+
+static void
+set_bands (MMIfaceModem *self,
+ GArray *bands_array,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ SetBandsContext *ctx;
+
+ ctx = g_new0 (SetBandsContext, 1);
+ ctx->result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ set_bands);
+ ctx->bandbits = band_array_to_bandbits (bands_array);
+ /*
+ * For the sake of efficiency, convert "ANY" to the actual set of
+ * bands; this matches what we get from load_current_bands and
+ * minimizes the number of changes we need to make.
+ *
+ * This requires that ANY is last in modem_bands and that all the
+ * other bits are valid.
+ */
+ if (ctx->bandbits == (1 << (G_N_ELEMENTS (modem_bands) - 1)))
+ ctx->bandbits--; /* clear the top bit, set all lower bits */
+ load_current_bands (self,
+ (GAsyncReadyCallback)set_bands_got_current_bands,
+ ctx);
+}
+
+static MMModemMode
+load_supported_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return (MMModemMode) GPOINTER_TO_UINT (g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+static void
+load_supported_modes (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_supported_modes);
+
+ g_simple_async_result_set_op_res_gpointer (result,
+ GUINT_TO_POINTER (MM_MODEM_MODE_2G |
+ MM_MODEM_MODE_3G),
+ NULL);
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
+typedef struct {
+ MMModemMode allowed;
+ MMModemMode preferred;
+} ModePair;
+
+static gboolean
+load_allowed_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ MMModemMode *allowed,
+ MMModemMode *preferred,
+ GError **error)
+{
+ ModePair *pair;
+
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return FALSE;
+
+ pair = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+ *allowed = pair->allowed;
+ *preferred = pair->preferred;
+ return TRUE;
+}
+
+static void
+load_allowed_modes_ready (MMIfaceModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ const gchar *response;
+ GError *error = NULL;
+ MMModemMode allowed, preferred;
+ int mode, domain;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ g_simple_async_result_take_error (operation_result, error);
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+ return;
+ }
+
+ allowed = preferred = MM_MODEM_MODE_NONE;
+ response = mm_strip_tag (response, "%IPSYS:");
+
+ if (sscanf (response, " %d,%d", &mode, &domain)) {
+ switch (mode) {
+ case 0:
+ allowed = preferred = MM_MODEM_MODE_2G;
+ break;
+ case 1:
+ allowed = preferred = MM_MODEM_MODE_3G;
+ break;
+ case 2:
+ allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G;
+ preferred = MM_MODEM_MODE_2G;
+ break;
+ case 3:
+ allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G;
+ preferred = MM_MODEM_MODE_3G;
+ break;
+ case 5:
+ allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G;
+ break;
+ }
+ }
+
+ if (allowed == MM_MODEM_MODE_NONE) {
+ g_simple_async_result_set_error (operation_result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Invalid supported modes response: '%s'",
+ response);
+ } else {
+ ModePair *pair;
+
+ pair = g_new0 (ModePair, 1);
+ pair->allowed = allowed;
+ pair->preferred = preferred;
+ g_simple_async_result_set_op_res_gpointer (operation_result,
+ pair,
+ g_free);
+ }
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+}
+
+static void
+load_allowed_modes (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_allowed_modes);
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "%IPSYS?",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)load_allowed_modes_ready,
+ result);
+}
+
+static gboolean
+set_allowed_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+set_allowed_modes_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error))
+ /* Let the error be critical */
+ g_simple_async_result_take_error (operation_result, error);
+ else
+ g_simple_async_result_set_op_res_gboolean (operation_result, TRUE);
+
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+}
+
+static void
+set_allowed_modes (MMIfaceModem *self,
+ MMModemMode modes,
+ MMModemMode preferred,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ gint value;
+ gchar *command;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ set_allowed_modes);
+
+ /*
+ * The core has checked the following:
+ * - that 'modes' are a subset of the allowed modes
+ * - that 'preferred' is one mode, and a subset of 'modes'
+ */
+ if (modes == MM_MODEM_MODE_2G)
+ value = 0;
+ else if (modes == MM_MODEM_MODE_3G)
+ value = 1;
+ else if (modes == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G) &&
+ preferred == MM_MODEM_MODE_2G)
+ value = 2;
+ else if (modes == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G) &&
+ preferred == MM_MODEM_MODE_3G)
+ value = 3;
+ else if (modes == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G) &&
+ preferred == MM_MODEM_MODE_NONE)
+ value = 5;
+ else {
+ g_simple_async_result_set_error (result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_INVALID_ARGS,
+ "Couldn't set allowed modes, "
+ "unsupported combination of allowed (%d) and "
+ "preferred (%d)",
+ modes, preferred);
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+ return;
+ }
+
+ command = g_strdup_printf ("%%IPSYS=%d", value);
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ command,
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)set_allowed_modes_ready,
+ result);
+ g_free (command);
+}
+
+MMBroadbandModemSamsung *
+mm_broadband_modem_samsung_new (const gchar *device,
+ const gchar *driver,
+ const gchar *plugin,
+ guint16 vendor_id,
+ guint16 product_id)
+{
+ return g_object_new (MM_TYPE_BROADBAND_MODEM_SAMSUNG,
+ MM_BASE_MODEM_DEVICE, device,
+ MM_BASE_MODEM_DRIVER, driver,
+ MM_BASE_MODEM_PLUGIN, plugin,
+ MM_BASE_MODEM_VENDOR_ID, vendor_id,
+ MM_BASE_MODEM_PRODUCT_ID, product_id,
+ NULL);
+}
+
+static MMBearer *
+modem_create_bearer_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ MMBearer *bearer;
+
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return NULL;
+
+ bearer = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+
+ return g_object_ref (bearer);
+}
+
+static void
+broadband_bearer_new_ready (GObject *source,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ MMBearer *bearer = NULL;
+ GError *error = NULL;
+
+ bearer = mm_broadband_bearer_samsung_new_finish (res, &error);
+ if (!bearer)
+ g_simple_async_result_take_error (simple, error);
+ else
+ g_simple_async_result_set_op_res_gpointer (simple,
+ bearer,
+ (GDestroyNotify)g_object_unref);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+modem_create_bearer (MMIfaceModem *self,
+ MMBearerProperties *properties,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ /* Set a new ref to the bearer object as result */
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_create_bearer);
+
+ mm_broadband_bearer_samsung_new (MM_BROADBAND_MODEM_SAMSUNG (self),
+ properties,
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)broadband_bearer_new_ready,
+ result);
+}
+
+static MMUnlockRetries *
+load_unlock_retries_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return NULL;
+ return (MMUnlockRetries *) g_object_ref (g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+static void
+load_unlock_retries_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ const gchar *response;
+ GError *error = NULL;
+ int pin1, puk1, pin2, puk2;
+
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ mm_dbg ("Couldn't query unlock retries: '%s'", error->message);
+ g_simple_async_result_take_error (operation_result, error);
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+ return;
+ }
+
+ response = mm_strip_tag (response, "%PINNUM:");
+ if (sscanf (response, " %d, %d, %d, %d", &pin1, &puk1, &pin2, &puk2) == 4) {
+ MMUnlockRetries *retries;
+ retries = mm_unlock_retries_new ();
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PIN, pin1);
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PUK, puk1);
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PIN2, pin2);
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PUK2, puk2);
+ g_simple_async_result_set_op_res_gpointer (operation_result,
+ retries,
+ (GDestroyNotify)g_object_unref);
+ } else {
+ g_simple_async_result_set_error (operation_result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Invalid unlock retries response: '%s'",
+ response);
+ }
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+}
+
+static void
+load_unlock_retries (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "%PINNUM?",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)load_unlock_retries_ready,
+ g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_unlock_retries));
+}
+
+/*****************************************************************************/
+/* Setup/Cleanup unsolicited events (3GPP interface) */
+
+static void
+nwstate_changed (MMAtSerialPort *port,
+ GMatchInfo *info,
+ MMBroadbandModemSamsung *self)
+{
+ int rssi = -1;
+ MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+ gchar *str;
+
+ /*
+ * %NWSTATE: <rssi>,<mccmnc>,<tech>,<connection state>,<regulation>
+ *
+ * <connection state> shows the actual access technology in-use when a
+ * PS connection is active.
+ */
+ str = g_match_info_fetch (info, 1);
+ if (str) {
+ rssi = atoi (str);
+ rssi = CLAMP (rssi, 0, 5) * 100 / 5;
+ g_free (str);
+ }
+
+ str = g_match_info_fetch (info, 4);
+ if (!str || (strcmp (str, "-") == 0)) {
+ g_free (str);
+ str = g_match_info_fetch (info, 3);
+ }
+ if (str) {
+ act = nwstate_to_act (str);
+ g_free (str);
+ }
+
+ self->priv->last_act = act;
+ mm_iface_modem_update_access_technologies (MM_IFACE_MODEM (self),
+ act,
+ MM_MODEM_ACCESS_TECHNOLOGY_ANY);
+ mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self),
+ rssi);
+}
+
+static void
+set_unsolicited_events_handlers (MMBroadbandModemSamsung *self,
+ gboolean enable)
+{
+ MMAtSerialPort *ports[2];
+ guint i;
+
+ ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
+ ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
+
+ /* Enable unsolicited events in given port */
+ for (i = 0; i < 2; i++) {
+ if (!ports[i])
+ continue;
+
+ /* Access technology related */
+ mm_at_serial_port_add_unsolicited_msg_handler (
+ ports[i],
+ self->priv->nwstate_regex,
+ enable ? (MMAtSerialUnsolicitedMsgFn)nwstate_changed : NULL,
+ enable ? self : NULL,
+ NULL);
+ }
+}
+
+static gboolean
+modem_3gpp_unsolicited_events_finish (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+parent_setup_unsolicited_events_ready (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ if (!iface_modem_3gpp_parent->setup_unsolicited_events_finish (self, res, &error))
+ g_simple_async_result_take_error (simple, error);
+ else {
+ /* Our own setup now */
+ set_unsolicited_events_handlers (MM_BROADBAND_MODEM_SAMSUNG (self), TRUE);
+ g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res), TRUE);
+ }
+
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+setup_unsolicited_events (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ /* Chain up parent's setup */
+ iface_modem_3gpp_parent->setup_unsolicited_events (
+ self,
+ (GAsyncReadyCallback)parent_setup_unsolicited_events_ready,
+ g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ setup_unsolicited_events));
+}
+
+static void
+parent_cleanup_unsolicited_events_ready (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ if (!iface_modem_3gpp_parent->cleanup_unsolicited_events_finish (self, res, &error))
+ g_simple_async_result_take_error (simple, error);
+ else
+ g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res), TRUE);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+cleanup_unsolicited_events (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ /* Our own cleanup first */
+ set_unsolicited_events_handlers (MM_BROADBAND_MODEM_SAMSUNG (self), FALSE);
+
+ /* And now chain up parent's cleanup */
+ iface_modem_3gpp_parent->cleanup_unsolicited_events (
+ self,
+ (GAsyncReadyCallback)parent_cleanup_unsolicited_events_ready,
+ g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ cleanup_unsolicited_events));
+}
+
+/*****************************************************************************/
+/* Enabling unsolicited events (3GPP interface) */
+
+static void
+own_enable_unsolicited_events_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_at_sequence_full_finish (self, res, NULL, &error))
+ g_simple_async_result_take_error (simple, error);
+ else
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+parent_enable_unsolicited_events_ready (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ if (!iface_modem_3gpp_parent->enable_unsolicited_events_finish (self, res, &error)) {
+ g_simple_async_result_take_error (simple, error);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+ }
+
+ /* Our own enable now */
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "%NWSTATE=1",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)own_enable_unsolicited_events_ready,
+ simple);
+}
+
+static void
+enable_unsolicited_events (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ /* Chain up parent's enable */
+ iface_modem_3gpp_parent->enable_unsolicited_events (
+ self,
+ (GAsyncReadyCallback)parent_enable_unsolicited_events_ready,
+ g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ enable_unsolicited_events));
+}
+
+/*****************************************************************************/
+/* Disabling unsolicited events (3GPP interface) */
+
+static void
+parent_disable_unsolicited_events_ready (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ if (!iface_modem_3gpp_parent->disable_unsolicited_events_finish (self, res, &error))
+ g_simple_async_result_take_error (simple, error);
+ else
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+own_disable_unsolicited_events_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_at_command_finish (self, res, &error)) {
+ g_simple_async_result_take_error (simple, error);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+ return;
+ }
+
+ /* Next, chain up parent's disable */
+ iface_modem_3gpp_parent->disable_unsolicited_events (
+ MM_IFACE_MODEM_3GPP (self),
+ (GAsyncReadyCallback)parent_disable_unsolicited_events_ready,
+ simple);
+}
+
+static void
+disable_unsolicited_events (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ /* Our own disable first */
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "%NWSTATE=0",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)own_disable_unsolicited_events_ready,
+ g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ disable_unsolicited_events));
+}
+
+/*****************************************************************************/
+/* Setup ports (Broadband modem class) */
+
+static void
+setup_ports (MMBroadbandModem *self)
+{
+ /* Call parent's setup ports first always */
+ MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_samsung_parent_class)->setup_ports (self);
+
+ /* Now reset the unsolicited messages we'll handle when enabled */
+ set_unsolicited_events_handlers (MM_BROADBAND_MODEM_SAMSUNG (self), FALSE);
+}
+
+/*****************************************************************************/
+
+static void
+finalize (GObject *object)
+{
+ MMBroadbandModemSamsung *self = MM_BROADBAND_MODEM_SAMSUNG (object);
+
+ g_regex_unref (self->priv->nwstate_regex);
+
+ G_OBJECT_CLASS (mm_broadband_modem_samsung_parent_class)->finalize (object);
+}
+
+static void
+mm_broadband_modem_samsung_init (MMBroadbandModemSamsung *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
+ MM_TYPE_BROADBAND_MODEM_SAMSUNG,
+ MMBroadbandModemSamsungPrivate);
+
+ self->priv->nwstate_regex = g_regex_new(
+ "%NWSTATE:\\s*(-?\\d+),(\\d+),([^,]*),([^,]*),(\\d+)",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+}
+
+static void
+iface_modem_3gpp_init (MMIfaceModem3gpp *iface)
+{
+ iface_modem_3gpp_parent = g_type_interface_peek_parent (iface);
+
+ iface->setup_unsolicited_events = setup_unsolicited_events;
+ iface->setup_unsolicited_events_finish = modem_3gpp_unsolicited_events_finish;
+ iface->cleanup_unsolicited_events = cleanup_unsolicited_events;
+ iface->cleanup_unsolicited_events_finish = modem_3gpp_unsolicited_events_finish;
+ iface->enable_unsolicited_events = enable_unsolicited_events;
+ iface->enable_unsolicited_events_finish = modem_3gpp_unsolicited_events_finish;
+ iface->disable_unsolicited_events = disable_unsolicited_events;
+ iface->disable_unsolicited_events_finish = modem_3gpp_unsolicited_events_finish;
+}
+
+static void
+iface_modem_init (MMIfaceModem *iface)
+{
+ iface->create_bearer = modem_create_bearer;
+ iface->create_bearer_finish = modem_create_bearer_finish;
+ iface->load_supported_bands = load_supported_bands;
+ iface->load_supported_bands_finish = load_supported_bands_finish;
+ iface->load_current_bands = load_current_bands;
+ iface->load_current_bands_finish = load_current_bands_finish;
+ iface->set_bands = set_bands;
+ iface->set_bands_finish = set_bands_finish;
+ iface->load_supported_modes = load_supported_modes;
+ iface->load_supported_modes_finish = load_supported_modes_finish;
+ iface->load_allowed_modes = load_allowed_modes;
+ iface->load_allowed_modes_finish = load_allowed_modes_finish;
+ iface->set_allowed_modes = set_allowed_modes;
+ iface->set_allowed_modes_finish = set_allowed_modes_finish;
+ iface->load_access_technologies = load_access_technologies;
+ iface->load_access_technologies_finish = load_access_technologies_finish;
+ iface->load_unlock_retries = load_unlock_retries;
+ iface->load_unlock_retries_finish = load_unlock_retries_finish;
+}
+
+static void
+mm_broadband_modem_samsung_class_init (MMBroadbandModemSamsungClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ MMBroadbandModemClass *broadband_modem_class = MM_BROADBAND_MODEM_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (MMBroadbandModemSamsungPrivate));
+
+ object_class->finalize = finalize;
+ broadband_modem_class->setup_ports = setup_ports;
+}
diff --git a/plugins/samsung/mm-broadband-modem-samsung.h b/plugins/samsung/mm-broadband-modem-samsung.h
new file mode 100644
index 0000000..6e21603
--- /dev/null
+++ b/plugins/samsung/mm-broadband-modem-samsung.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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:
+ *
+ * Copyright (C) 2012 Google Inc.
+ * Author: Nathan Williams <njw@google.com>
+ */
+
+#ifndef MM_BROADBAND_MODEM_SAMSUNG_H
+#define MM_BROADBAND_MODEM_SAMSUNG_H
+
+#include "mm-broadband-modem.h"
+
+#define MM_TYPE_BROADBAND_MODEM_SAMSUNG (mm_broadband_modem_samsung_get_type ())
+#define MM_BROADBAND_MODEM_SAMSUNG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_SAMSUNG, MMBroadbandModemSamsung))
+#define MM_BROADBAND_MODEM_SAMSUNG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_SAMSUNG_AIRLINK, MMBroadbandModemSamsungClass))
+#define MM_IS_BROADBAND_MODEM_SAMSUNG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_SAMSUNG_AIRLINK))
+#define MM_IS_BROADBAND_MODEM_SAMSUNG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_SAMSUNG_AIRLINK))
+#define MM_BROADBAND_MODEM_SAMSUNG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_SAMSUNG_AIRLINK, MMBroadbandModemSamsungClass))
+
+typedef struct _MMBroadbandModemSamsung MMBroadbandModemSamsung;
+typedef struct _MMBroadbandModemSamsungClass MMBroadbandModemSamsungClass;
+typedef struct _MMBroadbandModemSamsungPrivate MMBroadbandModemSamsungPrivate;
+
+struct _MMBroadbandModemSamsung {
+ MMBroadbandModem parent;
+ MMBroadbandModemSamsungPrivate *priv;
+};
+
+struct _MMBroadbandModemSamsungClass{
+ MMBroadbandModemClass parent;
+};
+
+GType mm_broadband_modem_samsung_get_type (void);
+
+MMBroadbandModemSamsung *mm_broadband_modem_samsung_new (const gchar *device,
+ const gchar *driver,
+ const gchar *plugin,
+ guint16 vendor_id,
+ guint16 product_id);
+
+#endif /* MM_BROADBAND_MODEM_SAMSUNG_H */
diff --git a/plugins/samsung/mm-plugin-samsung.c b/plugins/samsung/mm-plugin-samsung.c
new file mode 100644
index 0000000..ea19835
--- /dev/null
+++ b/plugins/samsung/mm-plugin-samsung.c
@@ -0,0 +1,115 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/*
+ * 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) 2012 Google Inc.
+ * Author: Nathan Williams <njw@google.com>
+ */
+
+#include <string.h>
+#include <gmodule.h>
+
+#include "mm-plugin-samsung.h"
+#include "mm-private-boxed-types.h"
+#include "mm-broadband-modem-samsung.h"
+#include "mm-log.h"
+
+G_DEFINE_TYPE (MMPluginSamsung, mm_plugin_samsung, MM_TYPE_PLUGIN_BASE)
+
+int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
+int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
+
+static MMBaseModem *
+grab_port (MMPluginBase *base,
+ MMBaseModem *existing,
+ MMPortProbe *probe,
+ GError **error)
+{
+ MMBaseModem *modem = NULL;
+ const gchar *name, *subsys, *driver;
+ guint16 vendor = 0, product = 0;
+
+ mm_dbg(" existing %p", existing);
+ /* The Samsung plugin uses AT and net ports */
+ if (!mm_port_probe_is_at (probe) &&
+ !g_str_equal (mm_port_probe_get_port_subsys (probe), "net")) {
+ g_set_error (error, 0, 0, "Ignoring non-AT/net port");
+ return NULL;
+ }
+
+ subsys = mm_port_probe_get_port_subsys (probe);
+ name = mm_port_probe_get_port_name (probe);
+ driver = mm_port_probe_get_port_driver (probe);
+ mm_dbg("subsys %s name %s driver %s", subsys, name, driver);
+
+ /* Try to get Product IDs from udev. */
+ mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product);
+ mm_dbg("vendor 0x%04x product 0x%04x", vendor, product);
+
+ /* If this is the first port being grabbed, create a new modem object */
+ if (!existing)
+ modem = MM_BASE_MODEM (mm_broadband_modem_samsung_new (mm_port_probe_get_port_physdev (probe),
+ driver,
+ mm_plugin_get_name (MM_PLUGIN (base)),
+ vendor,
+ product));
+
+ if (!mm_base_modem_grab_port (existing ? existing : modem,
+ subsys,
+ name,
+ mm_port_probe_get_port_type (probe),
+ MM_AT_PORT_FLAG_NONE,
+ error)) {
+ mm_dbg("mm_base_modem_grab_port failed; releasing");
+ if (modem)
+ g_object_unref (modem);
+ return NULL;
+ }
+
+ return existing ? existing : modem;
+}
+
+/*****************************************************************************/
+
+G_MODULE_EXPORT MMPlugin *
+mm_plugin_create (void)
+{
+ static const gchar *subsystems[] = { "tty", "net", NULL };
+ static const mm_uint16_pair products[] = { { 0x04e8, 0x6872},
+ { 0x04e8, 0x6906},
+ {0, 0} };
+ return MM_PLUGIN (
+ g_object_new (MM_TYPE_PLUGIN_SAMSUNG,
+ MM_PLUGIN_BASE_NAME, "Samsung",
+ MM_PLUGIN_BASE_ALLOWED_SUBSYSTEMS, subsystems,
+ MM_PLUGIN_BASE_ALLOWED_PRODUCT_IDS, products,
+ MM_PLUGIN_BASE_ALLOWED_AT, TRUE,
+ NULL));
+}
+
+static void
+mm_plugin_samsung_init (MMPluginSamsung *self)
+{
+}
+
+static void
+mm_plugin_samsung_class_init (MMPluginSamsungClass *klass)
+{
+ MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass);
+
+ pb_class->grab_port = grab_port;
+}
diff --git a/plugins/samsung/mm-plugin-samsung.h b/plugins/samsung/mm-plugin-samsung.h
new file mode 100644
index 0000000..99876c3
--- /dev/null
+++ b/plugins/samsung/mm-plugin-samsung.h
@@ -0,0 +1,47 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/*
+ * 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) 2012 Google Inc.
+ * Author: Nathan Williams <njw@google.com>
+ */
+
+#ifndef MM_PLUGIN_SAMSUNG_H
+#define MM_PLUGIN_SAMSUNG_H
+
+#include "mm-plugin-base.h"
+
+#define MM_TYPE_PLUGIN_SAMSUNG (mm_plugin_samsung_get_type ())
+#define MM_PLUGIN_SAMSUNG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_SAMSUNG, MMPluginSamsung))
+#define MM_PLUGIN_SAMSUNG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_SAMSUNG, MMPluginSamsungClass))
+#define MM_IS_PLUGIN_SAMSUNG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_SAMSUNG))
+#define MM_IS_PLUGIN_SAMSUNG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_SAMSUNG))
+#define MM_PLUGIN_SAMSUNG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_SAMSUNG, MMPluginSamsungClass))
+
+typedef struct {
+ MMPluginBase parent;
+} MMPluginSamsung;
+
+typedef struct {
+ MMPluginBaseClass parent;
+} MMPluginSamsungClass;
+
+GType mm_plugin_samsung_get_type (void);
+
+G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
+
+#endif /* MM_PLUGIN_SAMSUNG_H */