summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin.Li <snowmanli88@gmail.com>2013-09-16 02:44:06 -0400
committerDan Williams <dcbw@redhat.com>2013-09-16 11:53:58 -0500
commitc22eca999bac9ccb9307970a059da39cdd100122 (patch)
tree15afabaa328ea460f2e9624ce641572a89dbe676
parent5d8efff2910d448a0df220d8e38efc72875aa730 (diff)
downloadModemManager-c22eca999bac9ccb9307970a059da39cdd100122.tar.gz
mtk: add plugin for various MediaTek devices
Signed-off-by: Quentin.Li <snowmanli88@gmail.com>
-rw-r--r--plugins/Makefile.am13
-rw-r--r--plugins/mtk/77-mm-mtk-port-types.rules35
-rw-r--r--plugins/mtk/mm-broadband-modem-mtk.c1036
-rw-r--r--plugins/mtk/mm-broadband-modem-mtk.h51
-rw-r--r--plugins/mtk/mm-plugin-mtk.c118
-rw-r--r--plugins/mtk/mm-plugin-mtk.h42
6 files changed, 1294 insertions, 1 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 9bfa11e7c..3e4ed726c 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -77,7 +77,8 @@ pkglib_LTLIBRARIES = \
libmm-plugin-sierra.la \
libmm-plugin-mbm.la \
libmm-plugin-via.la \
- libmm-plugin-telit.la
+ libmm-plugin-telit.la \
+ libmm-plugin-mtk.la
# Generic
libmm_plugin_generic_la_SOURCES = \
@@ -373,6 +374,16 @@ libmm_plugin_telit_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)
libmm_plugin_telit_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
udevrules_DATA += telit/77-mm-telit-port-types.rules
+# MTK
+libmm_plugin_mtk_la_SOURCES = \
+ mtk/mm-plugin-mtk.c \
+ mtk/mm-plugin-mtk.h \
+ mtk/mm-broadband-modem-mtk.h \
+ mtk/mm-broadband-modem-mtk.c
+libmm_plugin_mtk_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)
+libmm_plugin_mtk_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
+udevrules_DATA += mtk/77-mm-mtk-port-types.rules
+
# Additional files to include in the distribution
EXTRA_DIST += \
diff --git a/plugins/mtk/77-mm-mtk-port-types.rules b/plugins/mtk/77-mm-mtk-port-types.rules
new file mode 100644
index 000000000..37c1e4916
--- /dev/null
+++ b/plugins/mtk/77-mm-mtk-port-types.rules
@@ -0,0 +1,35 @@
+# do not edit this file, it will be overwritten on update
+
+ACTION!="add|change", GOTO="mm_mtk_port_types_end"
+
+SUBSYSTEMS=="usb", ATTRS{idVendor}=="0e8d", GOTO="mm_mtk_port_types_vendorcheck"
+GOTO="mm_mtk_port_types_end"
+
+LABEL="mm_mtk_port_types_vendorcheck"
+
+ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInterfaceNumber}"
+
+# Modem port flag setting
+# ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="02", ATTRS{bInterfaceProtocol}=="01", ENV{ID_MM_MTK_MODEM_PORT}="1"
+
+ATTRS{idProduct}=="00a1", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_MTK_MODEM_PORT}="1"
+ATTRS{idProduct}=="00a1", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_MTK_AT_PORT}="1"
+ATTRS{idProduct}=="00a1", ENV{ID_MM_MTK_TAGGED}="1"
+
+ATTRS{idProduct}=="00a2", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_MTK_MODEM_PORT}="1"
+ATTRS{idProduct}=="00a2", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_MTK_AT_PORT}="1"
+ATTRS{idProduct}=="00a2", ENV{ID_MM_MTK_TAGGED}="1"
+
+ATTRS{idProduct}=="00a4", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_MTK_MODEM_PORT}="1"
+ATTRS{idProduct}=="00a4", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_MTK_AT_PORT}="1"
+ATTRS{idProduct}=="00a4", ENV{ID_MM_MTK_TAGGED}="1"
+
+ATTRS{idProduct}=="00a5", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_MTK_MODEM_PORT}="1"
+ATTRS{idProduct}=="00a5", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_MTK_AT_PORT}="1"
+ATTRS{idProduct}=="00a5", ENV{ID_MM_MTK_TAGGED}="1"
+
+ATTRS{idProduct}=="00a7", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_MTK_MODEM_PORT}="1"
+ATTRS{idProduct}=="00a7", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_MTK_AT_PORT}="1"
+ATTRS{idProduct}=="00a7", ENV{ID_MM_MTK_TAGGED}="1"
+
+LABEL="mm_mtk_port_types_end"
diff --git a/plugins/mtk/mm-broadband-modem-mtk.c b/plugins/mtk/mm-broadband-modem-mtk.c
new file mode 100644
index 000000000..9732ae2f4
--- /dev/null
+++ b/plugins/mtk/mm-broadband-modem-mtk.c
@@ -0,0 +1,1036 @@
+/* -*- 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) 2008 - 2009 Novell, Inc.
+ * Copyright (C) 2009 - 2012 Red Hat, Inc.
+ * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "ModemManager.h"
+#include "mm-log.h"
+#include "mm-errors-types.h"
+#include "mm-modem-helpers.h"
+#include "mm-base-modem-at.h"
+#include "mm-iface-modem.h"
+#include "mm-iface-modem-3gpp.h"
+#include "mm-broadband-modem-mtk.h"
+
+static void iface_modem_init (MMIfaceModem *iface);
+static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface);
+
+static MMIfaceModem *iface_modem_parent;
+static MMIfaceModem3gpp *iface_modem_3gpp_parent;
+
+G_DEFINE_TYPE_EXTENDED (MMBroadbandModemMtk, mm_broadband_modem_mtk, 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 _MMBroadbandModemMtkPrivate {
+ /* Signal quality regex */
+ GRegex *ecsqg_regex;
+ GRegex *ecsqu_regex;
+ GRegex *ecsqeg_regex;
+ GRegex *ecsqeu_regex;
+ GRegex *ecsqel_regex;
+};
+
+/*****************************************************************************/
+/* Unlock retries (Modem interface) */
+
+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;
+ GMatchInfo *match_info = NULL;
+ GError *match_error = NULL;
+ GRegex *r = NULL;
+ gint pin1, puk1, pin2, puk2;
+ MMUnlockRetries *retries;
+
+ 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;
+ }
+
+ r = g_regex_new (
+ "\\+EPINC:\\s*([0-9]+),\\s*([0-9]+),\\s*([0-9]+),\\s*([0-9]+)",
+ 0,
+ 0,
+ NULL);
+
+ g_assert (r != NULL);
+
+ if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)){
+ if (match_error) {
+ g_propagate_error (&error, match_error);
+ } else {
+ g_set_error (&error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to match EPINC response: %s", response);
+ }
+ g_simple_async_result_take_error (operation_result, error);
+ } else if (!mm_get_int_from_match_info (match_info, 1, &pin1) ||
+ !mm_get_int_from_match_info (match_info, 2, &pin2) ||
+ !mm_get_int_from_match_info (match_info, 3, &puk1) ||
+ !mm_get_int_from_match_info (match_info, 4, &puk2)) {
+ g_set_error (&error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to parse the EPINC response: '%s'",
+ response);
+
+ g_simple_async_result_take_error (operation_result, error);
+ } else {
+ 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_PIN2, pin2);
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PUK, puk1);
+ 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);
+ }
+
+ if (match_info)
+ g_match_info_free (match_info);
+ g_regex_unref (r);
+
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+ return;
+}
+
+static void
+load_unlock_retries (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "+EPINC?",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)load_unlock_retries_ready,
+ g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_unlock_retries));
+}
+
+/*****************************************************************************/
+static gboolean
+modem_after_sim_unlock_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return TRUE;
+}
+
+static gboolean
+after_sim_unlock_wait_cb (GSimpleAsyncResult *result)
+{
+ g_simple_async_result_complete (result);
+ g_object_unref (result);
+ return FALSE;
+}
+
+static void
+modem_after_sim_unlock (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_after_sim_unlock);
+
+ /* For device, 3 second is OK for SIM get ready */
+ g_timeout_add_seconds (3, (GSourceFunc)after_sim_unlock_wait_cb, result);
+}
+
+/*****************************************************************************/
+/* Load supported modes (Modem interface) */
+
+static void
+get_supported_modes_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+
+{
+ const gchar *response;
+ GError *error = NULL;
+ GMatchInfo *match_info = NULL;
+ MMModemModeCombination mode;
+ GArray *combinations;
+ GRegex *r;
+ GError *match_error = NULL;
+ gint device_type;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ mm_dbg ("Fail to get response %s", response);
+ g_simple_async_result_take_error (simple, error);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+ return;
+ }
+
+ r = g_regex_new ("\\+EGMR:\\s*\"MT([0-9]+)",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ g_assert (r != NULL);
+
+ if(!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)) {
+ if (match_error) {
+ g_propagate_error (&error, match_error);
+ } else {
+ g_set_error (&error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to match EGMR response: %s", response);
+ }
+
+ g_regex_unref (r);
+ return;
+ }
+
+ if (!mm_get_int_from_match_info (match_info, 1, &device_type)) {
+ g_set_error (&error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to parse the allowed mode response: '%s'",
+ response);
+
+ g_regex_unref (r);
+ if (match_info)
+ g_match_info_free (match_info);
+ return;
+ }
+
+ /* Build list of combinations */
+ combinations = g_array_sized_new (FALSE,
+ FALSE,
+ sizeof (MMModemModeCombination),
+ 8);
+
+ /* 2G only */
+ mode.allowed = MM_MODEM_MODE_2G;
+ mode.preferred = MM_MODEM_MODE_NONE;
+ g_array_append_val (combinations, mode);
+ /* 3G only */
+ mode.allowed = MM_MODEM_MODE_3G;
+ mode.preferred = MM_MODEM_MODE_NONE;
+ g_array_append_val (combinations, mode);
+ /* 2G and 3G, no prefer*/
+ mode.allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G;
+ mode.preferred = MM_MODEM_MODE_NONE;
+ g_array_append_val (combinations, mode);
+ /* 2G and 3G, 3G prefer*/
+ mode.allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G;
+ mode.preferred = MM_MODEM_MODE_3G;
+ g_array_append_val (combinations, mode);
+
+ if (device_type == 6290) {
+ /* 4G only */
+ mode.allowed = MM_MODEM_MODE_4G;
+ mode.preferred = MM_MODEM_MODE_NONE;
+ g_array_append_val (combinations, mode);
+ /* 2G and 4G, no prefer */
+ mode.allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_4G;
+ mode.preferred = MM_MODEM_MODE_NONE;
+ g_array_append_val (combinations, mode);
+ /* 3G and 4G, no prefer */
+ mode.allowed = MM_MODEM_MODE_3G | MM_MODEM_MODE_4G;
+ mode.preferred = MM_MODEM_MODE_NONE;
+ g_array_append_val (combinations, mode);
+ /* 2G, 3G and 4G, no prefer */
+ mode.allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G;
+ mode.preferred = MM_MODEM_MODE_NONE;
+ g_array_append_val (combinations, mode);
+ }
+
+ /*********************************************************************
+ * No need to filter out any unsupported modes for MTK device. For
+ * +GCAP, +WS64 not support completely, generic filter will filter
+ * out 4G modes.
+ */
+ g_simple_async_result_set_op_res_gpointer (simple,
+ combinations,
+ (GDestroyNotify)g_array_unref);
+
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+
+ g_regex_unref (r);
+ if (match_info)
+ g_match_info_free (match_info);
+ return;
+}
+
+static void
+load_supported_modes (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "+EGMR=0,0",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)get_supported_modes_ready,
+ g_simple_async_result_new (
+ G_OBJECT (self),
+ callback,
+ user_data,
+ load_supported_modes));
+}
+
+static GArray *
+load_supported_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return NULL;
+
+ return g_array_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+/*****************************************************************************/
+/* Load initial allowed/preferred modes (Modem interface) */
+
+static gboolean
+load_current_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ MMModemMode *allowed,
+ MMModemMode *preferred,
+ GError **error)
+{
+ const gchar *response;
+ GMatchInfo *match_info = NULL;
+ GRegex *r;
+ gint erat_mode = -1;
+ gint erat_pref = -1;
+ GError *match_error = NULL;
+ gboolean result = FALSE;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
+ if (!response)
+ return result;
+
+ r = g_regex_new (
+ "\\+ERAT:\\s*[0-9]+,\\s*[0-9]+,\\s*([0-9]+),\\s*([0-9]+)",
+ 0,
+ 0,
+ error);
+ g_assert (r != NULL);
+
+ if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)) {
+ if (match_error)
+ g_propagate_error (error, match_error);
+ else {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Couldn't parse +ERAT response: '%s'",
+ response);
+
+ }
+ goto done;
+ }
+
+ if (!mm_get_int_from_match_info (match_info, 1, &erat_mode) ||
+ !mm_get_int_from_match_info (match_info, 2, &erat_pref)) {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to parse the ERAT response: m=%d p=%d",
+ erat_mode, erat_pref);
+ goto done;
+ }
+
+ /* Correctly parsed! */
+ result = TRUE;
+
+ switch (erat_mode) {
+ case 0:
+ *allowed = MM_MODEM_MODE_2G;
+ break;
+ case 1:
+ *allowed = MM_MODEM_MODE_3G;
+ break;
+ case 2:
+ *allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G;
+ break;
+ case 3:
+ *allowed = MM_MODEM_MODE_4G;
+ break;
+ case 4:
+ *allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_4G;
+ break;
+ case 5:
+ *allowed = MM_MODEM_MODE_3G | MM_MODEM_MODE_4G;
+ break;
+ case 6:
+ *allowed = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G;
+ break;
+ default:
+ result = FALSE;
+ mm_dbg ("Not supported allowed mode %d", erat_mode);
+ goto done;
+ }
+
+ switch (erat_pref) {
+ case 0:
+ *preferred = MM_MODEM_MODE_NONE;
+ break;
+ case 1:
+ *preferred = MM_MODEM_MODE_2G;
+ break;
+ case 2:
+ *preferred = MM_MODEM_MODE_3G;
+ break;
+ case 3:
+ *preferred = MM_MODEM_MODE_4G;
+ break;
+ default:
+ result = FALSE;
+ mm_dbg ("Not supported preferred mode %d", erat_pref);
+ goto done;
+ }
+
+done:
+ if (r)
+ g_regex_unref (r);
+ if (match_info)
+ g_match_info_free (match_info);
+
+ return result;
+}
+
+static void
+load_current_modes (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ mm_base_modem_at_command (MM_BASE_MODEM (self),
+ "+ERAT?",
+ 3,
+ FALSE,
+ callback,
+ user_data);
+}
+
+/*****************************************************************************/
+/* Set allowed modes (Modem interface) */
+
+static gboolean
+set_current_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+allowed_mode_update_ready (MMBroadbandModemMtk *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ GError *error = NULL;
+
+ mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+
+ if (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_current_modes (MMIfaceModem *self,
+ MMModemMode allowed,
+ MMModemMode preferred,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ gchar *command;
+ gint erat_mode = -1;
+ gint erat_pref = -1;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ set_current_modes);
+
+ if (allowed == MM_MODEM_MODE_2G) {
+ erat_mode = 0;
+ erat_pref = 0;
+ } else if (allowed == MM_MODEM_MODE_3G) {
+ erat_mode = 1;
+ erat_pref = 0;
+ } else if (allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G)) {
+ erat_mode = 2;
+ if (preferred == MM_MODEM_MODE_3G)
+ erat_pref = 2;
+ else if (preferred == MM_MODEM_MODE_NONE)
+ erat_pref = 0;
+ /* 2G prefer not supported */
+ } else if (allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G) &&
+ preferred == MM_MODEM_MODE_NONE) {
+ erat_mode = 6;
+ erat_pref = 0;
+ } else if ((allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_4G)) &&
+ preferred == MM_MODEM_MODE_NONE) {
+ erat_mode = 4;
+ erat_pref = 0;
+ } else if ((allowed == (MM_MODEM_MODE_3G | MM_MODEM_MODE_4G)) &&
+ preferred == MM_MODEM_MODE_NONE) {
+ erat_mode = 5;
+ erat_pref = 0;
+ } else if (allowed == MM_MODEM_MODE_4G) {
+ erat_mode = 3;
+ erat_pref = 0;
+ }
+
+ if (erat_mode < 0 || erat_pref < 0) {
+ gchar *allowed_str;
+ gchar *preferred_str;
+
+ allowed_str = mm_modem_mode_build_string_from_mask (allowed);
+ preferred_str = mm_modem_mode_build_string_from_mask (preferred);
+ g_simple_async_result_set_error (result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Requested mode (allowed: '%s', preferred: '%s') not "
+ "supported by the modem.",
+ allowed_str,
+ preferred_str);
+ g_free (allowed_str);
+ g_free (preferred_str);
+
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+ return;
+ }
+
+ command = g_strdup_printf ("AT+ERAT=%d,%d", erat_mode, erat_pref);
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ command,
+ 30,
+ FALSE,
+ (GAsyncReadyCallback)allowed_mode_update_ready,
+ result);
+ g_free (command);
+}
+
+/*****************************************************************************/
+/* Setup/Cleanup unsolicited events (3GPP interface) */
+
+static void
+mtk_80_signal_changed (MMAtSerialPort *port,
+ GMatchInfo *match_info,
+ MMBroadbandModemMtk *self)
+{
+ guint quality = 0;
+
+ if (!mm_get_uint_from_match_info (match_info, 1, &quality))
+ return;
+
+ if (quality == 99)
+ quality = 0;
+ else
+ quality = CLAMP(quality, 0, 31) * 100 / 31;
+
+ mm_dbg ("6280 signal quality URC received: quality = %u", quality);
+ mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), (guint)quality);
+}
+
+static void
+mtk_90_2g_signal_changed (MMAtSerialPort *port,
+ GMatchInfo *match_info,
+ MMBroadbandModemMtk *self)
+{
+ guint quality = 0;
+
+ if (!mm_get_uint_from_match_info (match_info, 1, &quality))
+ return;
+
+ if (quality == 99)
+ quality = 0;
+ else
+ quality = CLAMP (quality, 0, 63) * 100 / 63;
+
+ mm_dbg ("2G signal quality URC received: quality = %u", quality);
+ mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), (guint)quality);
+}
+
+static void
+mtk_90_3g_signal_changed (MMAtSerialPort *port,
+ GMatchInfo *match_info,
+ MMBroadbandModemMtk *self)
+{
+ guint quality = 0;
+
+ if (!mm_get_uint_from_match_info (match_info, 1, &quality))
+ return;
+
+ quality = CLAMP (quality, 0, 96) * 100 / 96;
+
+ mm_dbg ("3G signal quality URC received: quality = %u", quality);
+ mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), (guint)quality);
+}
+
+static void
+mtk_90_4g_signal_changed (MMAtSerialPort *port,
+ GMatchInfo *match_info,
+ MMBroadbandModemMtk *self)
+{
+ guint quality = 0;
+
+ if (!mm_get_uint_from_match_info (match_info, 1, &quality))
+ return;
+
+ quality = CLAMP (quality, 0, 97) * 100 / 97;
+
+ mm_dbg ("4G signal quality URC received: quality = %u", quality);
+ mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), (guint)quality);
+}
+
+static void
+set_unsolicited_events_handlers (MMBroadbandModemMtk *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/disable unsolicited events in given port */
+ for (i = 0; i < 2; i++){
+ if(!ports[i])
+ continue;
+
+ mm_at_serial_port_add_unsolicited_msg_handler (
+ ports[i],
+ self->priv->ecsqg_regex,
+ enable ? (MMAtSerialUnsolicitedMsgFn)mtk_80_signal_changed : NULL,
+ enable ? self : NULL,
+ NULL);
+
+ mm_at_serial_port_add_unsolicited_msg_handler (
+ ports[i],
+ self->priv->ecsqu_regex,
+ enable ? (MMAtSerialUnsolicitedMsgFn)mtk_80_signal_changed : NULL,
+ enable ? self : NULL,
+ NULL);
+
+ mm_at_serial_port_add_unsolicited_msg_handler (
+ ports[i],
+ self->priv->ecsqeg_regex,
+ enable ? (MMAtSerialUnsolicitedMsgFn)mtk_90_2g_signal_changed:NULL,
+ enable ? self : NULL,
+ NULL);
+
+ mm_at_serial_port_add_unsolicited_msg_handler (
+ ports[i],
+ self->priv->ecsqeu_regex,
+ enable ? (MMAtSerialUnsolicitedMsgFn)mtk_90_3g_signal_changed:NULL,
+ enable ? self : NULL,
+ NULL);
+
+ mm_at_serial_port_add_unsolicited_msg_handler (
+ ports[i],
+ self->priv->ecsqel_regex,
+ enable ? (MMAtSerialUnsolicitedMsgFn)mtk_90_4g_signal_changed:NULL,
+ enable ? self : NULL,
+ NULL);
+ }
+}
+
+static gboolean
+modem_3gpp_setup_cleanup_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_MTK (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
+modem_3gpp_setup_unsolicited_events (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_3gpp_setup_unsolicited_events);
+
+ /* Chain up parent's setup */
+ iface_modem_3gpp_parent->setup_unsolicited_events (
+ self,
+ (GAsyncReadyCallback)parent_setup_unsolicited_events_ready,
+ result);
+}
+
+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
+modem_3gpp_cleanup_unsolicited_events (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_3gpp_cleanup_unsolicited_events);
+
+ /* Our own cleanup first */
+ set_unsolicited_events_handlers (MM_BROADBAND_MODEM_MTK (self), FALSE);
+
+ /* And now chain up parent's cleanup */
+ iface_modem_3gpp_parent->cleanup_unsolicited_events (
+ self,
+ (GAsyncReadyCallback)parent_cleanup_unsolicited_events_ready,
+ result);
+}
+
+static const MMBaseModemAtCommand unsolicited_enable_sequence[] = {
+ /* enable signal URC */
+ {"+ECSQ=2", 5, FALSE, NULL},
+ {NULL}
+};
+
+static const MMBaseModemAtCommand unsolicited_disable_sequence[] = {
+ /* disable signal URC */
+ {"+ECSQ=0", 5, FALSE, NULL},
+ {NULL}
+};
+
+static void
+own_enable_unsolicited_events_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ GError *error = NULL;
+
+ mm_base_modem_at_sequence_full_finish (self, res, NULL, &error);
+ if (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_sequence_full (
+ MM_BASE_MODEM (self),
+ mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)),
+ unsolicited_enable_sequence,
+ NULL,NULL,NULL,
+ (GAsyncReadyCallback)own_enable_unsolicited_events_ready,
+ simple);
+}
+
+static void
+modem_3gpp_enable_unsolicited_events (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_3gpp_enable_unsolicited_events);
+
+ /* Chain up parent's enable */
+ iface_modem_3gpp_parent->enable_unsolicited_events (
+ self,
+ (GAsyncReadyCallback)parent_enable_unsolicited_events_ready,
+ result);
+}
+
+static gboolean
+modem_3gpp_enable_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_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;
+
+ mm_base_modem_at_sequence_full_finish (self, res, NULL, &error);
+ if (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
+modem_3gpp_disable_unsolicited_events (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_3gpp_disable_unsolicited_events);
+
+ /* Our own disable first */
+ mm_base_modem_at_sequence_full (
+ MM_BASE_MODEM (self),
+ mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)),
+ unsolicited_disable_sequence,
+ NULL, NULL, NULL,
+ (GAsyncReadyCallback)own_disable_unsolicited_events_ready,
+ result);
+}
+
+static gboolean
+modem_3gpp_disable_unsolicited_events_finish (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+/*****************************************************************************/
+/* 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_mtk_parent_class)->setup_ports (self);
+
+ /* Now reset the unsolicited messages we'll handle when enabled */
+ set_unsolicited_events_handlers (MM_BROADBAND_MODEM_MTK (self), FALSE);
+}
+
+/*****************************************************************************/
+MMBroadbandModemMtk *
+mm_broadband_modem_mtk_new (const gchar *device,
+ const gchar **drivers,
+ const gchar *plugin,
+ guint16 vendor_id,
+ guint16 product_id)
+{
+ return g_object_new (MM_TYPE_BROADBAND_MODEM_MTK,
+ MM_BASE_MODEM_DEVICE, device,
+ MM_BASE_MODEM_DRIVERS, drivers,
+ MM_BASE_MODEM_PLUGIN, plugin,
+ MM_BASE_MODEM_VENDOR_ID, vendor_id,
+ MM_BASE_MODEM_PRODUCT_ID, product_id,
+ NULL);
+}
+
+static void
+mm_broadband_modem_mtk_init (MMBroadbandModemMtk *self)
+{
+ /* Initialize private data */
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
+ MM_TYPE_BROADBAND_MODEM_MTK,
+ MMBroadbandModemMtkPrivate);
+ self->priv->ecsqg_regex = g_regex_new (
+ "\\r\\n\\+ECSQ:\\s*([0-9]*),\\s*[0-9]*,\\s*-[0-9]*\\r\\n",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ self->priv->ecsqu_regex = g_regex_new (
+ "\\r\\n\\+ECSQ:\\s*([0-9]*),\\s*[0-9]*,\\s*-[0-9]*,\\s*-[0-9]*,\\s*-[0-9]*\\r\\n",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ self->priv->ecsqeg_regex = g_regex_new (
+ "\\r\\n\\+ECSQ:\\s*([0-9]*),\\s*[0-9]*,\\s*-[0-9]*,\\s*1,\\s*1,\\s*1,\\s*1,\\s*[0-9]*\\r\\n",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ self->priv->ecsqeu_regex = g_regex_new (
+ "\\r\\n\\+ECSQ:\\s*([0-9]*),\\s*[0-9]*,\\s*1,\\s*-[0-9]*,\\s*-[0-9]*,\\s*1,\\s*1,\\s*[0-9]*\\r\\n",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ self->priv->ecsqel_regex = g_regex_new (
+ "\\r\\n\\+ECSQ:\\s*[0-9]*,\\s*([0-9]*),\\s*1,\\s*1,\\s*1,\\s*-[0-9]*,\\s*-[0-9]*,\\s*[0-9]*\\r\\n",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+}
+
+static void
+finalize (GObject *object)
+{
+ MMBroadbandModemMtk *self = MM_BROADBAND_MODEM_MTK (object);
+
+ g_regex_unref (self->priv->ecsqg_regex);
+ g_regex_unref (self->priv->ecsqu_regex);
+ g_regex_unref (self->priv->ecsqeg_regex);
+ g_regex_unref (self->priv->ecsqeu_regex);
+ g_regex_unref (self->priv->ecsqel_regex);
+
+ G_OBJECT_CLASS (mm_broadband_modem_mtk_parent_class)->finalize (object);
+}
+
+static void
+iface_modem_init (MMIfaceModem *iface)
+{
+ iface_modem_parent = g_type_interface_peek_parent (iface);
+
+ iface->modem_after_sim_unlock = modem_after_sim_unlock;
+ iface->modem_after_sim_unlock_finish = modem_after_sim_unlock_finish;
+ iface->load_supported_modes = load_supported_modes;
+ iface->load_supported_modes_finish = load_supported_modes_finish;
+ iface->load_current_modes = load_current_modes;
+ iface->load_current_modes_finish = load_current_modes_finish;
+ iface->set_current_modes = set_current_modes;
+ iface->set_current_modes_finish = set_current_modes_finish;
+ iface->load_unlock_retries = load_unlock_retries;
+ iface->load_unlock_retries_finish = load_unlock_retries_finish;
+}
+
+static void
+iface_modem_3gpp_init (MMIfaceModem3gpp *iface)
+{
+ iface_modem_3gpp_parent = g_type_interface_peek_parent (iface);
+
+ iface->setup_unsolicited_events = modem_3gpp_setup_unsolicited_events;
+ iface->setup_unsolicited_events_finish = modem_3gpp_setup_cleanup_unsolicited_events_finish;
+ iface->cleanup_unsolicited_events = modem_3gpp_cleanup_unsolicited_events;
+ iface->cleanup_unsolicited_events_finish = modem_3gpp_setup_cleanup_unsolicited_events_finish;
+ iface->enable_unsolicited_events = modem_3gpp_enable_unsolicited_events;
+ iface->enable_unsolicited_events_finish = modem_3gpp_enable_unsolicited_events_finish;
+ iface->disable_unsolicited_events = modem_3gpp_disable_unsolicited_events;
+ iface->disable_unsolicited_events_finish = modem_3gpp_disable_unsolicited_events_finish;
+}
+
+static void
+mm_broadband_modem_mtk_class_init (MMBroadbandModemMtkClass *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 (MMBroadbandModemMtkPrivate));
+
+ object_class->finalize = finalize;
+ broadband_modem_class->setup_ports = setup_ports;
+}
+
diff --git a/plugins/mtk/mm-broadband-modem-mtk.h b/plugins/mtk/mm-broadband-modem-mtk.h
new file mode 100644
index 000000000..bbe72cc27
--- /dev/null
+++ b/plugins/mtk/mm-broadband-modem-mtk.h
@@ -0,0 +1,51 @@
+/* -*- 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) 2008 - 2009 Novell, Inc.
+ * Copyright (C) 2009 - 2011 Red Hat, Inc.
+ * Copyright (C) 2011 Google Inc.
+ */
+
+#ifndef MM_BROADBAND_MODEM_MTK_H
+#define MM_BROADBAND_MODEM_MTK_H
+
+#include "mm-broadband-modem.h"
+
+#define MM_TYPE_BROADBAND_MODEM_MTK (mm_broadband_modem_mtk_get_type ())
+#define MM_BROADBAND_MODEM_MTK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_MTK, MMBroadbandModemMtk))
+#define MM_BROADBAND_MODEM_MTK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_MTK, MMBroadbandModemMtkClass))
+#define MM_IS_BROADBAND_MODEM_MTK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_MTK))
+#define MM_IS_BROADBAND_MODEM_MTK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_MTK))
+#define MM_BROADBAND_MODEM_MTK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_MTK, MMBroadbandModemMtkClass))
+
+typedef struct _MMBroadbandModemMtk MMBroadbandModemMtk;
+typedef struct _MMBroadbandModemMtkClass MMBroadbandModemMtkClass;
+typedef struct _MMBroadbandModemMtkPrivate MMBroadbandModemMtkPrivate;
+
+struct _MMBroadbandModemMtk {
+ MMBroadbandModem parent;
+ MMBroadbandModemMtkPrivate *priv;
+};
+
+struct _MMBroadbandModemMtkClass {
+ MMBroadbandModemClass parent;
+};
+
+GType mm_broadband_modem_mtk_get_type (void);
+
+MMBroadbandModemMtk *mm_broadband_modem_mtk_new (const gchar *device,
+ const gchar **drivers,
+ const gchar *plugin,
+ guint16 vendor_id,
+ guint16 product_id);
+
+#endif /* MM_BROADBAND_MODEM_MTK_H */
diff --git a/plugins/mtk/mm-plugin-mtk.c b/plugins/mtk/mm-plugin-mtk.c
new file mode 100644
index 000000000..ff5e1e454
--- /dev/null
+++ b/plugins/mtk/mm-plugin-mtk.c
@@ -0,0 +1,118 @@
+/* -*- 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) 2008 - 2009 Novell, Inc.
+ * Copyright (C) 2009 - 2012 Red Hat, Inc.
+ * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include <string.h>
+#include <gmodule.h>
+
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-log.h"
+#include "mm-plugin-mtk.h"
+#include "mm-broadband-modem-mtk.h"
+
+G_DEFINE_TYPE (MMPluginMtk, mm_plugin_mtk, MM_TYPE_PLUGIN)
+
+int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
+int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
+
+/*****************************************************************************/
+
+/* MTK done */
+static MMBaseModem *
+create_modem (MMPlugin *self,
+ const gchar *sysfs_path,
+ const gchar **drivers,
+ guint16 vendor,
+ guint16 product,
+ GList *probes,
+ GError **error)
+{
+ return MM_BASE_MODEM (mm_broadband_modem_mtk_new (sysfs_path,
+ drivers,
+ mm_plugin_get_name (self),
+ vendor,
+ product));
+}
+
+/* MTK done */
+static gboolean
+grab_port (MMPlugin *self,
+ MMBaseModem *modem,
+ MMPortProbe *probe,
+ GError **error)
+{
+ GUdevDevice *port;
+ MMAtPortFlag pflags = MM_AT_PORT_FLAG_NONE;
+
+ port = mm_port_probe_peek_port (probe);
+
+ if (mm_port_probe_is_at (probe)) {
+ /* Get port type from udev */
+ if (g_udev_device_get_property_as_boolean (port, "ID_MM_MTK_AT_PORT")) {
+ mm_dbg ("MTK: AT port '%s/%s' flagged as secondary",
+ mm_port_probe_get_port_subsys (probe),
+ mm_port_probe_get_port_name (probe));
+ pflags = MM_AT_PORT_FLAG_SECONDARY;
+ } else if (g_udev_device_get_property_as_boolean (port, "ID_MM_MTK_MODEM_PORT")) {
+ mm_dbg ("MTK: Modem port '%s/%s' flagged as primary",
+ mm_port_probe_get_port_subsys (probe),
+ mm_port_probe_get_port_name (probe));
+ pflags = MM_AT_PORT_FLAG_PRIMARY;
+ }
+ }
+
+ return mm_base_modem_grab_port (modem,
+ mm_port_probe_get_port_subsys (probe),
+ mm_port_probe_get_port_name (probe),
+ mm_port_probe_get_port_type(probe),
+ pflags,
+ error);
+}
+
+/*****************************************************************************/
+
+G_MODULE_EXPORT MMPlugin *
+mm_plugin_create (void)
+{
+ static const gchar *subsystems[] = { "tty", NULL };
+ static const gchar *udev_tags[]={
+ "ID_MM_MTK_TAGGED",
+ NULL};
+
+ return MM_PLUGIN (
+ g_object_new (MM_TYPE_PLUGIN_MTK,
+ MM_PLUGIN_NAME, "MTK",
+ MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems,
+ MM_PLUGIN_ALLOWED_UDEV_TAGS, udev_tags,
+ MM_PLUGIN_ALLOWED_AT, TRUE,
+ NULL));
+}
+
+static void
+mm_plugin_mtk_init (MMPluginMtk *self)
+{
+}
+
+static void
+mm_plugin_mtk_class_init (MMPluginMtkClass *klass)
+{
+ MMPluginClass *plugin_class = MM_PLUGIN_CLASS (klass);
+
+ plugin_class->create_modem = create_modem;
+ plugin_class->grab_port = grab_port;
+}
diff --git a/plugins/mtk/mm-plugin-mtk.h b/plugins/mtk/mm-plugin-mtk.h
new file mode 100644
index 000000000..cc7b0d191
--- /dev/null
+++ b/plugins/mtk/mm-plugin-mtk.h
@@ -0,0 +1,42 @@
+/* -*- 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) 2008 - 2009 Novell, Inc.
+ * Copyright (C) 2009 - 2012 Red Hat, Inc.
+ * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#ifndef MM_PLUGIN_MTK_H
+#define MM_PLUGIN_MTK_H
+
+#include "mm-plugin.h"
+
+#define MM_TYPE_PLUGIN_MTK (mm_plugin_mtk_get_type ())
+#define MM_PLUGIN_MTK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_MTK, MMPluginMtk))
+#define MM_PLUGIN_MTK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_MTK, MMPluginMtkClass))
+#define MM_IS_PLUGIN_MTK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_MTK))
+#define MM_IS_PLUGIN_MTK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_MTK))
+#define MM_PLUGIN_MTK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_MTK, MMPluginMtkClass))
+
+typedef struct {
+ MMPlugin parent;
+} MMPluginMtk;
+
+typedef struct {
+ MMPluginClass parent;
+} MMPluginMtkClass;
+
+GType mm_plugin_mtk_get_type (void);
+
+G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
+
+#endif /* MM_PLUGIN_MTK_H */