<div dir="ltr">Sure thing. <div>I squashed the commits and attached the output from git format-patch.<br></div><div><div><br><div class="gmail_quote"><div dir="ltr">On Sat, May 27, 2017 at 10:21 AM Aleksander Morgado <<a href="mailto:aleksander@aleksander.es">aleksander@aleksander.es</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey Paul!<br>
<br>
On 26/05/17 04:39, Paul Bartell wrote:<br>
> The primary reason for this patch is that the current HL7588 MBIM firmware<br>
> implementation is quite broken and not supported by the manufacturer. This<br>
> requires the use of the somewhat less broken AT / NCM interface.<br>
><br>
> This implementation has been tested with a Sierra Wireless HL7588 (XMM<br>
> 7160) with firmware versions A2.10 and V3.6. It is based on an abandoned<br>
> branch from the ModemManager git repository.<br>
><br>
<br>
The branch wasn't abandoned!! it was waiting for someone to keep working on it, so thanks :)<br>
<br>
> There is a somewhat nasty hack in here to support the use of the A2.10<br>
> firmware on AT&T (see DIAL_3GPP_CONTEXT_STEP_DETACH and<br>
> set_reg_msg_handlers). If anyone has ideas on a better way to bypass the<br>
> automatic activation of PDP contexts when attaching to the network, I would<br>
> be happy to replace that part of this implementation. The HL75xx V3.6<br>
> firmware does not appear to have this limitation.<br>
><br>
> Further testing on other Intel/Infineon XMM based modems with AT/NCM USB<br>
> configurations would be a good idea (Telit LN93x and Sierra MC7345 come to<br>
> mind).<br>
><br>
<br>
Looks like your email application line wrapped the patch. Could you resend the patch in a way we can apply it with "git am"? i.e. either directly with "git send-email" or otherwise attached as a separate file obtained with "git format-patch".<br>
<br>
<br>
> diff --git a/plugins/Makefile.am b/plugins/Makefile.am<br>
> old mode 100644<br>
> new mode 100755<br>
> index 2a4ff2b..eef0490<br>
> --- a/plugins/Makefile.am<br>
> +++ b/plugins/Makefile.am<br>
> @@ -815,6 +815,21 @@ libmm_plugin_via_la_CPPFLAGS =<br>
> $(PLUGIN_COMMON_COMPILER_FLAGS)<br>
> libmm_plugin_via_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)<br>
><br>
> ################################################################################<br>
> +# plugin: Infineon<br>
> +################################################################################<br>
> +pkglib_LTLIBRARIES += <a href="http://libmm-plugin-infineon.la" rel="noreferrer" target="_blank">libmm-plugin-infineon.la</a><br>
> +libmm_plugin_infineon_la_SOURCES = \<br>
> + infineon/mm-plugin-infineon.c \<br>
> + infineon/mm-plugin-infineon.h \<br>
> + infineon/mm-broadband-modem-infineon.c \<br>
> + infineon/mm-broadband-modem-infineon.h \<br>
> + infineon/mm-broadband-bearer-infineon.c \<br>
> + infineon/mm-broadband-bearer-infineon.h \<br>
> + $(NULL)<br>
> +libmm_plugin_infineon_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)<br>
> +libmm_plugin_infineon_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)<br>
> +<br>
> +################################################################################<br>
> # plugin: telit<br>
> ################################################################################<br>
><br>
> diff --git a/plugins/infineon/mm-broadband-bearer-infineon.c<br>
> b/plugins/infineon/mm-broadband-bearer-infineon.c<br>
> new file mode 100755<br>
> index 0000000..9bc57bc<br>
> --- /dev/null<br>
> +++ b/plugins/infineon/mm-broadband-bearer-infineon.c<br>
> @@ -0,0 +1,1051 @@<br>
> +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-<br>
> */<br>
> +/*<br>
> + * This program is free software; you can redistribute it and/or modify<br>
> + * it under the terms of the GNU General Public License as published by<br>
> + * the Free Software Foundation; either version 2 of the License, or<br>
> + * (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
> + * GNU General Public License for more details:<br>
> + *<br>
> + * Copyright (C) 2013 Aleksander Morgado <<a href="mailto:aleksander@gnu.org" target="_blank">aleksander@gnu.org</a>><br>
> + * Copyright (C) 2017 Tempered Networks Inc.<br>
> + */<br>
> +<br>
> +#include <config.h><br>
> +<br>
> +#include <stdio.h><br>
> +#include <stdlib.h><br>
> +#include <unistd.h><br>
> +#include <string.h><br>
> +#include <ctype.h><br>
> +#include <arpa/inet.h><br>
> +<br>
> +#include <ModemManager.h><br>
> +#define _LIBMM_INSIDE_MM<br>
> +#include <libmm-glib.h><br>
> +<br>
> +#include "mm-base-modem-at.h"<br>
> +#include "mm-broadband-bearer-infineon.h"<br>
> +#include "mm-log.h"<br>
> +#include "mm-modem-helpers.h"<br>
> +<br>
> +G_DEFINE_TYPE (MMBroadbandBearerInfineon, mm_broadband_bearer_infineon,<br>
> MM_TYPE_BROADBAND_BEARER)<br>
> +<br>
> +/*****************************************************************************/<br>
> +/* WWAN interface mapping */<br>
> +<br>
> +/* Map CDC-NCM port index to USB interface number */<br>
> +static const guint usb_ncm_configs[] = { 0x06, 0x08, 0x0a, 0x0c };<br>
> +<br>
> +/* Map CDC-ACM port index to USB interface number */<br>
> +static const guint usb_acm_configs[] = { 0x00, 0xFF, 0x04 };<br>
> +<br>
> +static gint<br>
> +get_usb_ncm_config_index (MMPort *data,<br>
> + GError **error)<br>
> +{<br>
> + guint usb_iface_num;<br>
> + guint i;<br>
> +<br>
> + usb_iface_num = mm_kernel_device_get_property_as_int_hex<br>
> (mm_port_peek_kernel_device (data), "ID_USB_INTERFACE_NUM");<br>
> +<br>
> + for (i = 0; i < G_N_ELEMENTS (usb_ncm_configs); i++) {<br>
> + if (usb_ncm_configs[i] == usb_iface_num)<br>
> + return (gint) i;<br>
> + }<br>
> +<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "Unsupported WWAN interface: unexpected interface number:<br>
> 0x%02x", usb_iface_num);<br>
> + return -1;<br>
> +}<br>
> +<br>
> +static gint<br>
> +get_usb_acm_config_index (MMPortSerialAt *port,<br>
> + GError **error)<br>
> +{<br>
> + guint usb_iface_num;<br>
> + guint i;<br>
> +<br>
> + usb_iface_num = mm_kernel_device_get_property_as_int_hex<br>
> (mm_port_peek_kernel_device (&port->parent.parent), "ID_USB_INTERFACE_NUM");<br>
> + for (i = 0; i < G_N_ELEMENTS (usb_acm_configs); i++) {<br>
> + if (usb_acm_configs[i] == usb_iface_num)<br>
> + return (gint) i;<br>
> + }<br>
> +<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "Unsupported ACM interface: unexpected interface number:<br>
> 0x%02x", usb_iface_num);<br>
> + return -1;<br>
> +}<br>
> +<br>
> +/*****************************************************************************/<br>
> +/* 3GPP Dialing (sub-step of the 3GPP Connection sequence) */<br>
> +<br>
> +typedef enum {<br>
> + DIAL_3GPP_CONTEXT_STEP_CHECK_CGACT = 0,<br>
> + DIAL_3GPP_CONTEXT_STEP_DETACH,<br>
> + DIAL_3GPP_CONTEXT_STEP_SET_XGAUTH,<br>
> + DIAL_3GPP_CONTEXT_STEP_SET_XDNS,<br>
> + DIAL_3GPP_CONTEXT_STEP_SET_CGACT,<br>
> + DIAL_3GPP_CONTEXT_STEP_SET_DATA_CHAN,<br>
> + DIAL_3GPP_CONTEXT_STEP_START_DATA_CHAN,<br>
> + DIAL_3GPP_CONTEXT_STEP_LAST<br>
> +} Dial3gppContextStep;<br>
> +<br>
> +typedef struct {<br>
> + MMBroadbandBearerInfineon *self;<br>
> + MMBaseModem *modem;<br>
> + MMPortSerialAt *primary;<br>
> + MMPortSerialAt *secondary;<br>
> + guint cid;<br>
> + MMBearerIpFamily ip_family;<br>
> + MMPort *data;<br>
> + gint usb_interface_config_index;<br>
> + gint usb_acm_config_index;<br>
> + GPtrArray * creg_regexes;<br>
> + Dial3gppContextStep step;<br>
> +} Dial3gppContext;<br>
> +<br>
> +<br>
> +<br>
> +static void<br>
> +dial_3gpp_context_free (Dial3gppContext *ctx)<br>
> +{<br>
> + g_object_unref (ctx->self);<br>
> + g_object_unref (ctx->modem);<br>
> + g_object_unref (ctx->primary);<br>
> + g_object_unref (ctx->secondary);<br>
> + g_object_unref (ctx->data);<br>
> + g_slice_free (Dial3gppContext, ctx);<br>
> +}<br>
> +<br>
> +/* Forward Function declarations */<br>
> +static void dial_3gpp_context_step (GTask *task);<br>
> +<br>
> +static MMPort *<br>
> +dial_3gpp_finish (MMBroadbandBearer *self,<br>
> + GAsyncResult *res,<br>
> + GError **error)<br>
> +{<br>
> + return MM_PORT (g_task_propagate_pointer (G_TASK (res), error));<br>
> +}<br>
> +<br>
> +static void<br>
> +dial_3gpp_cgact_check_ready (MMBaseModem *modem,<br>
> + GAsyncResult *res,<br>
> + GTask *task)<br>
> +{<br>
> + const gchar *response;<br>
> + Dial3gppContext *ctx;<br>
> + GError *error = NULL;<br>
> + GList *cgact_list = NULL;<br>
> + GList *l = NULL;<br>
> + MM3gppPdpContextActive *pdp_ctx_active = NULL;<br>
> +<br>
> + ctx = (Dial3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + response = mm_base_modem_at_command_finish (modem, res, &error);<br>
> + if (!response) {<br>
> + g_task_return_error (task, error);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> +<br>
> + /* Parse response */<br>
> + cgact_list = mm_3gpp_parse_cgact_read_response (response, &error);<br>
> + g_assert(cgact_list != NULL);<br>
> +<br>
> + if (!cgact_list) {<br>
> + g_task_return_error (task, error);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> +<br>
> + /* Iterate over list and check for active context with same CID */<br>
> + for (l = cgact_list; l != NULL; l = l ->next) {<br>
> + pdp_ctx_active = l->data;<br>
> + if (pdp_ctx_active->cid == ctx->cid) {<br>
> + break;<br>
> + }<br>
> + else<br>
> + pdp_ctx_active = NULL;<br>
> + }<br>
> + g_assert(pdp_ctx_active != NULL);<br>
> + /* If context is already active. Detach from network before attempting<br>
> to connect<br>
> + in order to work around a Sierra HL7588 firmware bug */<br>
> + if (pdp_ctx_active != NULL && pdp_ctx_active->active){<br>
> + mm_dbg("Selected CID is currently active.");<br>
> + ctx->step++;<br>
> + }<br>
> + /* Otherwise, skip to auth step */<br>
> + else<br>
> + ctx->step = DIAL_3GPP_CONTEXT_STEP_SET_XGAUTH;<br>
> +<br>
> + mm_3gpp_pdp_context_active_list_free (cgact_list);<br>
> + dial_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +typedef enum {<br>
> + BEARER_INFINEON_AUTH_NONE = 0,<br>
> + BEARER_INFINEON_AUTH_PAP = 1,<br>
> + BEARER_INFINEON_AUTH_CHAP = 2<br>
> +} BearerInfineonAuthType;<br>
> +<br>
> +/* Generate XGAUTH string */<br>
> +static gchar *<br>
> +build_auth_string (Dial3gppContext *ctx)<br>
> +{<br>
> + gchar *command;<br>
> + const gchar *user;<br>
> + const gchar *password;<br>
> + MMBearerAllowedAuth auth_type;<br>
> +<br>
> + user = mm_bearer_properties_get_user (mm_base_bearer_peek_config<br>
> (MM_BASE_BEARER (ctx->self)));<br>
> + password = mm_bearer_properties_get_password<br>
> (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)));<br>
> + auth_type = mm_bearer_properties_get_allowed_auth<br>
> (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)));<br>
> +<br>
> + /* Both user and password are required; otherwise firmware returns an<br>
> error */<br>
> + if (user || password) {<br>
> + gchar *encoded_user;<br>
> + gchar *encoded_password;<br>
> + BearerInfineonAuthType auth_type_inf = BEARER_INFINEON_AUTH_NONE;<br>
> +<br>
> + /* Prefer CHAP over PAP */<br>
> + if (auth_type & MM_BEARER_ALLOWED_AUTH_CHAP)<br>
> + auth_type_inf = BEARER_INFINEON_AUTH_CHAP;<br>
> + else if (auth_type & MM_BEARER_ALLOWED_AUTH_PAP)<br>
> + auth_type_inf = BEARER_INFINEON_AUTH_PAP;<br>
> + else if (auth_type == MM_BEARER_ALLOWED_AUTH_UNKNOWN)<br>
> + auth_type_inf = BEARER_INFINEON_AUTH_CHAP;<br>
> + else if (auth_type == MM_BEARER_ALLOWED_AUTH_NONE)<br>
> + auth_type_inf = BEARER_INFINEON_AUTH_NONE;<br>
> +<br>
> + encoded_user =<br>
> mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM<br>
> (ctx->modem),<br>
> +<br>
> g_strdup (user));<br>
> + encoded_password =<br>
> mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM<br>
> (ctx->modem),<br>
> +<br>
> g_strdup (password));<br>
> +<br>
> + command = g_strdup_printf ("+XGAUTH=%u,%u,\"%s\",\"%s\"",<br>
> + ctx->cid,<br>
> + auth_type_inf,<br>
> + encoded_user ? encoded_user : "",<br>
> + encoded_password ? encoded_password :<br>
> "");<br>
> + g_free (encoded_user);<br>
> + g_free (encoded_password);<br>
> + } else {<br>
> + command = g_strdup_printf ("+XGAUTH=%u,0,\"\",\"\"", ctx->cid);<br>
> + }<br>
> + return command;<br>
> +}<br>
> +<br>
> +/* Generic AT command result ready callback */<br>
> +static void<br>
> +dial_3gpp_res_ready (MMBaseModem *modem,<br>
> + GAsyncResult *res,<br>
> + GTask *task)<br>
> +{<br>
> + Dial3gppContext *ctx;<br>
> + GError *error = NULL;<br>
> +<br>
> + ctx = (Dial3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + if (!mm_base_modem_at_command_finish (modem, res, &error)) {<br>
> +<br>
> + /* Disregard NO CARRIER message from modem when detaching from<br>
> network */<br>
> + if(ctx->step == DIAL_3GPP_CONTEXT_STEP_DETACH &&<br>
> + g_error_matches (error,<br>
> + MM_CONNECTION_ERROR,<br>
> + MM_CONNECTION_ERROR_NO_CARRIER))<br>
> + {<br>
> + g_error_free (error);<br>
> + } else {<br>
> + g_task_return_error (task, error);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> + }<br>
> +<br>
> + /* Go to next step */<br>
> + ctx->step++;<br>
> + dial_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +static void set_reg_msg_handlers (Dial3gppContext *ctx, gboolean enable)<br>
> +{<br>
> + guint i;<br>
> +<br>
> + if (!ctx->creg_regexes)<br>
> + {<br>
> + ctx->creg_regexes = mm_3gpp_creg_regex_get(FALSE);<br>
> + }<br>
> + for (i = 0; i < ctx->creg_regexes->len; i++)<br>
> + {<br>
> + mm_port_serial_at_enable_unsolicited_msg_handler (ctx->primary,<br>
> (GRegex *)ctx->creg_regexes->pdata[i], enable);<br>
> + mm_port_serial_at_enable_unsolicited_msg_handler (ctx->secondary,<br>
> (GRegex *)ctx->creg_regexes->pdata[i], enable);<br>
> + }<br>
> + if (enable)<br>
> + mm_dbg("Enabling unsolicited registration message handlers.");<br>
> + else<br>
> + mm_dbg("Disabling unsolicited registration message handlers.");<br>
> +}<br>
> +<br>
> +static void<br>
> +dial_3gpp_context_step (GTask *task)<br>
> +{<br>
> + Dial3gppContext *ctx;<br>
> +<br>
> + ctx = (Dial3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + mm_dbg("Dial3goo Step : %d", ctx->step);<br>
> +<br>
> + /* Check for cancellation */<br>
> + if (g_task_return_error_if_cancelled (task)) {<br>
> + set_reg_msg_handlers(ctx, TRUE);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> +<br>
> + switch (ctx->step) {<br>
> + case DIAL_3GPP_CONTEXT_STEP_CHECK_CGACT: {<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + "+CGACT?",<br>
> + 3,<br>
> + FALSE,<br>
> +<br>
> (GAsyncReadyCallback)dial_3gpp_cgact_check_ready,<br>
> + task);<br>
> + return;<br>
> + }<br>
> +<br>
> + case DIAL_3GPP_CONTEXT_STEP_DETACH: {<br>
> + /* Detach from network if context is already activated to bypass a<br>
> firmware bug in sierra HL75xx modules */<br>
> +<br>
> + /* Disable registration message handlers so our connect attempt<br>
> doesn't get cancelled */<br>
> + set_reg_msg_handlers(ctx, FALSE);<br>
> +<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + "+CGATT=0",<br>
> + 30,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)<br>
> dial_3gpp_res_ready,<br>
> + task);<br>
> + return;<br>
> + }<br>
> + case DIAL_3GPP_CONTEXT_STEP_SET_XGAUTH: {<br>
> + gchar *command = build_auth_string (ctx);<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + command,<br>
> + 3,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)dial_3gpp_res_ready,<br>
> + task);<br>
> + g_free (command);<br>
> + return;<br>
> + }<br>
> + case DIAL_3GPP_CONTEXT_STEP_SET_XDNS: {<br>
> + gchar *command = NULL;<br>
> +<br>
> + /* Select IP family with XDNS command */<br>
> + switch (mm_bearer_properties_get_ip_type<br>
> (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)))) {<br>
> + case MM_BEARER_IP_FAMILY_IPV4:<br>
> + command = g_strdup_printf ("+XDNS=%u,1", ctx->cid);<br>
> + break;<br>
> + case MM_BEARER_IP_FAMILY_IPV6:<br>
> + command = g_strdup_printf ("+XDNS=%u,2", ctx->cid);<br>
> + break;<br>
> + case MM_BEARER_IP_FAMILY_IPV4V6: /* Default to IPV4V6 dynamic DNS<br>
> request */<br>
> + default:<br>
> + command = g_strdup_printf ("+XDNS=%u,3", ctx->cid);<br>
> + break;<br>
> + }<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + command,<br>
> + 3,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)dial_3gpp_res_ready,<br>
> + task);<br>
> + g_free (command);<br>
> + return;<br>
> +<br>
> + }<br>
> + case DIAL_3GPP_CONTEXT_STEP_SET_CGACT: {<br>
> + gchar *command;<br>
> + command = g_strdup_printf ("+CGACT=1,%u", ctx->cid);<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + command,<br>
> + 30,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)dial_3gpp_res_ready,<br>
> + task);<br>
> + g_free (command);<br>
> + return;<br>
> +<br>
> + }<br>
> + case DIAL_3GPP_CONTEXT_STEP_SET_DATA_CHAN: {<br>
> + gchar *command;<br>
> + /* Setup data channel mapping */<br>
> + /* See Intel XMM7160 AT Functional Spec for more info on this<br>
> command */<br>
> + command = g_strdup_printf<br>
> ("+XDATACHANNEL=1,1,\"/USBCDC/%u\",\"/USBHS/NCM/%u\",2,%u",<br>
> + ctx->usb_acm_config_index,<br>
> ctx->usb_interface_config_index, ctx->cid);<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + command,<br>
> + 3,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)dial_3gpp_res_ready,<br>
> + task);<br>
> + g_free (command);<br>
> + return;<br>
> + }<br>
> + case DIAL_3GPP_CONTEXT_STEP_START_DATA_CHAN: {<br>
> + gchar *command;<br>
> + command = g_strdup_printf ("+CGDATA=\"M-RAW_IP\",%u", ctx->cid);<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + command,<br>
> + 10,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)dial_3gpp_res_ready,<br>
> + task);<br>
> + g_free (command);<br>
> + return;<br>
> + }<br>
> + case DIAL_3GPP_CONTEXT_STEP_LAST: {<br>
> + /* Restore message handlers */<br>
> + set_reg_msg_handlers(ctx, TRUE);<br>
> +<br>
> + g_task_return_pointer (task, g_object_ref (ctx->data),<br>
> g_object_unref);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> + }<br>
> +<br>
> +}<br>
> +<br>
> +static void<br>
> +dial_3gpp (MMBroadbandBearer *self,<br>
> + MMBaseModem *modem,<br>
> + MMPortSerialAt *primary,<br>
> + guint cid,<br>
> + GCancellable *cancellable,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data)<br>
> +{<br>
> + GTask *task;<br>
> + Dial3gppContext *ctx;<br>
> + GError *error = NULL;<br>
> +<br>
> + g_assert (primary != NULL);<br>
> +<br>
> + /* Setup task */<br>
> + task = g_task_new (self, cancellable, callback, user_data);<br>
> + ctx = g_slice_new0 (Dial3gppContext);<br>
> + g_task_set_task_data (task, ctx, (GDestroyNotify)<br>
> dial_3gpp_context_free);<br>
> +<br>
> + /* Setup Context */<br>
> + ctx->self = g_object_ref (self);<br>
> + ctx->modem = g_object_ref (modem);<br>
> + ctx->primary = g_object_ref (primary);<br>
> + ctx->cid = cid;<br>
> + ctx->step = DIAL_3GPP_CONTEXT_STEP_CHECK_CGACT;<br>
> + ctx->creg_regexes = NULL;<br>
> +<br>
> + /* Get a net port for the connection */<br>
> + ctx->data = mm_base_modem_peek_best_data_port (MM_BASE_MODEM (modem),<br>
> MM_PORT_TYPE_NET);<br>
> + if (!ctx->data) {<br>
> + g_task_return_new_error (task, MM_CORE_ERROR,<br>
> MM_CORE_ERROR_NOT_FOUND,<br>
> + "No valid data port found to<br>
> launch connection");<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> + g_object_ref (ctx->data);<br>
> +<br>
> + ctx->secondary = mm_base_modem_get_port_secondary (MM_BASE_MODEM<br>
> (modem));<br>
> +<br>
> + /* Validate the USB configuration */<br>
> + ctx->usb_interface_config_index = get_usb_ncm_config_index(ctx->data,<br>
> &error);<br>
> + ctx->usb_acm_config_index = get_usb_acm_config_index(ctx->primary,<br>
> &error);<br>
> + if (ctx->usb_interface_config_index < 0 || ctx->usb_acm_config_index <<br>
> 0)<br>
> + {<br>
> + g_task_return_error (task, error);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> +<br>
> + /* Run! */<br>
> + dial_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +/*****************************************************************************/<br>
> +/* 3GPP IP config retrieval (sub-step of the 3GPP Connection sequence) */<br>
> +<br>
> +typedef enum {<br>
> + GET_IP_CONFIG_3GPP_CONTEXT_STEP_CGPADDR,<br>
> + GET_IP_CONFIG_3GPP_CONTEXT_STEP_XDNS,<br>
> + GET_IP_CONFIG_3GPP_CONTEXT_STEP_LAST<br>
> +} GetIPConfig3gppContextStep;<br>
> +<br>
> +typedef struct {<br>
> + MMBroadbandBearerInfineon *self;<br>
> + MMBaseModem *modem;<br>
> + MMPortSerialAt *primary;<br>
> + guint cid;<br>
> + MMBearerIpFamily ip_family;<br>
> + MMPort *data;<br>
> + GetIPConfig3gppContextStep step;<br>
> + MMBearerIpConfig *ipv4_config;<br>
> + MMBearerIpConfig *ipv6_config;<br>
> +} GetIPConfig3gppContext;<br>
> +<br>
> +static void<br>
> +get_ip_config_3gpp_context_free (GetIPConfig3gppContext *ctx)<br>
> +{<br>
> + g_object_unref (ctx->modem);<br>
> + g_object_unref (ctx->primary);<br>
> + g_object_unref (ctx->data);<br>
> + if (ctx->ipv4_config)<br>
> + g_object_unref (ctx->ipv4_config);<br>
> + if (ctx->ipv6_config)<br>
> + g_object_unref (ctx->ipv6_config);<br>
> +}<br>
> +<br>
> +/* forward declaration */<br>
> +static void get_ip_config_3gpp_context_step (GTask *task);<br>
> +<br>
> +static gboolean<br>
> +get_ip_config_3gpp_finish (MMBroadbandBearer *self,<br>
> + GAsyncResult *res,<br>
> + MMBearerIpConfig **ipv4_config,<br>
> + MMBearerIpConfig **ipv6_config,<br>
> + GError **error)<br>
> +{<br>
> + MMBearerConnectResult *configs;<br>
> + MMBearerIpConfig *ipv4;<br>
> + MMBearerIpConfig *ipv6;<br>
> +<br>
> + configs = g_task_propagate_pointer (G_TASK (res), error);<br>
> + if (!configs)<br>
> + return FALSE;<br>
> +<br>
> + g_assert(configs != NULL);<br>
> +<br>
> + /* IPv4 config */<br>
> + ipv4 = mm_bearer_connect_result_peek_ipv4_config (configs);<br>
> + if (ipv4)<br>
> + *ipv4_config = g_object_ref (ipv4);<br>
> +<br>
> + /* IPv6 config */<br>
> + ipv6 = mm_bearer_connect_result_peek_ipv6_config (configs);<br>
> +<br>
> + if (ipv6)<br>
> + *ipv6_config = g_object_ref (ipv6);<br>
> +<br>
> + mm_bearer_connect_result_unref (configs);<br>
> + return TRUE;<br>
> +}<br>
> +<br>
> +static void<br>
> +ip_info_ready (MMBaseModem *modem,<br>
> + GAsyncResult *res,<br>
> + GTask *task)<br>
> +{<br>
> + const gchar *response;<br>
> + GError *error = NULL;<br>
> + guint cid;<br>
> + gchar *ipv4addr = NULL;<br>
> + gchar *ipv6addr = NULL;<br>
> + GetIPConfig3gppContext *ctx;<br>
> +<br>
> + ctx = (GetIPConfig3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + response = mm_base_modem_at_command_finish (modem, res, &error);<br>
> + if (!response) {<br>
> + g_task_return_error (task, error);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> +<br>
> + /* Parse response */<br>
> + if (!mm_3gpp_parse_cgpaddr_write_response (response, &cid, &ipv4addr,<br>
> &ipv6addr)) {<br>
> + g_task_return_new_error (task,<br>
> + MM_CORE_ERROR,<br>
> + MM_CORE_ERROR_FAILED,<br>
> + "Error parsing +CGPADDR response: '%s'",<br>
> + response);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> +<br>
> + g_warn_if_fail (cid == ctx->cid);<br>
> + /* Create IPv4 config */<br>
> + if (ipv4addr)<br>
> + {<br>
> + ctx->ipv4_config = mm_bearer_ip_config_new ();<br>
> + mm_bearer_ip_config_set_method (ctx->ipv4_config,<br>
> MM_BEARER_IP_METHOD_STATIC);<br>
> + mm_bearer_ip_config_set_address (ctx->ipv4_config, ipv4addr);<br>
> + mm_bearer_ip_config_set_prefix (ctx->ipv4_config, 0);<br>
> + g_free (ipv4addr);<br>
> + }<br>
> + /* IPv6 config */<br>
> + if (ipv6addr)<br>
> + {<br>
> + ctx->ipv6_config = mm_bearer_ip_config_new ();<br>
> + mm_bearer_ip_config_set_method (ctx->ipv6_config,<br>
> MM_BEARER_IP_METHOD_STATIC);<br>
> + mm_bearer_ip_config_set_address (ctx->ipv6_config, ipv6addr);<br>
> + mm_bearer_ip_config_set_prefix (ctx->ipv6_config, 0);<br>
> + g_free (ipv6addr);<br>
> + }<br>
> +<br>
> + ctx->step++;<br>
> + get_ip_config_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +static GList<br>
> +*deduplicate_string_list (GList *list)<br>
> +{<br>
> + GList *a, *b, *dup, *ret_list;<br>
> + ret_list = list;<br>
> + a = list;<br>
> + for (a = ret_list; a != NULL; a = a->next) {<br>
> + b = a->next;<br>
> + while (NULL != b) {<br>
> +<br>
> + if(0 == g_strcmp0 (a->data, b->data)) {<br>
> + dup = b;<br>
> + b = b->next;<br>
> + g_free (dup->data);<br>
> + ret_list = g_list_remove (ret_list, dup->data);<br>
> + } else {<br>
> + b = b->next;<br>
> + }<br>
> + }<br>
> + }<br>
> + return ret_list;<br>
> +}<br>
> +<br>
> +static gboolean<br>
> +parse_xdns_query_response (const gchar *reply,<br>
> + guint cid,<br>
> + guint max_dns_servers,<br>
> + gchar **dns_v4,<br>
> + gchar **dns_v6)<br>
> +{<br>
> + GRegex *r;<br>
> + GMatchInfo *match_info;<br>
> + guint this_cid = 0;<br>
> + guint num_v4 = 0;<br>
> + guint num_v6 = 0;<br>
> + GList *dns_list, *a;<br>
> + gchar *dns1, *dns2;<br>
> +<br>
> + dns1 = NULL;<br>
> + dns2 = NULL;<br>
> + dns_list = NULL;<br>
> + a = NULL;<br>
> +<br>
> + r = g_regex_new<br>
> ("\\+XDNS:\\s*(\\d+)\\s*,\\s*\"(.*)\"\\s*,\\s*\"(.*)\"",<br>
> + G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_MULTILINE |<br>
> G_REGEX_MATCH_NEWLINE_ANY,<br>
> + 0, NULL);<br>
> + g_assert (r != NULL);<br>
> +<br>
> + g_regex_match (r, reply, 0, &match_info);<br>
> + while (g_match_info_matches (match_info)) {<br>
> + if (mm_get_uint_from_match_info (match_info, 1, &this_cid) &&<br>
> + (this_cid == cid) &&<br>
> + (dns1 = mm_get_string_unquoted_from_match_info (match_info,<br>
> 2)) != NULL &&<br>
> + (dns2 = mm_get_string_unquoted_from_match_info (match_info,<br>
> 3)) != NULL)<br>
> + {<br>
> + dns_list = g_list_prepend(dns_list, dns1);<br>
> + dns_list = g_list_prepend(dns_list, dns2);<br>
> + }<br>
> + g_match_info_next (match_info, NULL);<br>
> + }<br>
> + g_match_info_free (match_info);<br>
> + g_regex_unref (r);<br>
> +<br>
> + dns_list = deduplicate_string_list(dns_list);<br>
> +<br>
> + for (a = dns_list; a != NULL; a = a->next) {<br>
> + /* Check if IPv6 address */<br>
> + if (g_strrstr (a->data, ":")) {<br>
> + if (num_v6 < max_dns_servers) {<br>
> + dns_v6[num_v6] = a->data;<br>
> + num_v6++;<br>
> + }<br>
> + else {<br>
> + g_free (a->data);<br>
> + }<br>
> + /* Process "empty" IPv4 address */<br>
> + } else if (0 == g_strcmp0("0.0.0.0", a->data)) {<br>
> + g_free (a->data);<br>
> + }<br>
> + /* Process IPv4 address */<br>
> + else if (num_v4 < max_dns_servers) {<br>
> + dns_v4[num_v4] = a->data;<br>
> + num_v4++;<br>
> + }<br>
> + else {<br>
> + g_free (a->data);<br>
> + }<br>
> + }<br>
> +<br>
> + g_list_free(dns_list);<br>
> + return num_v4 > 0 || num_v6 > 0;<br>
> +}<br>
> +<br>
> +static void<br>
> +dns_info_ready (MMBaseModem *modem,<br>
> + GAsyncResult *res,<br>
> + GTask *task)<br>
> +{<br>
> + static const gint MAX_DNS_SERVERS = 2;<br>
> + const gchar *response;<br>
> + GError *error = NULL;<br>
> + gchar *dns_v4[MAX_DNS_SERVERS + 1];<br>
> + gchar *dns_v6[MAX_DNS_SERVERS + 1];<br>
> + GetIPConfig3gppContext *ctx;<br>
> +<br>
> + memset(dns_v4, 0, sizeof( gchar *) * MAX_DNS_SERVERS + 1);<br>
> + memset(dns_v6, 0, sizeof( gchar *) * MAX_DNS_SERVERS + 1);<br>
> +<br>
> + ctx = (GetIPConfig3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + response = mm_base_modem_at_command_finish (modem, res, &error);<br>
> + if (!response) {<br>
> + g_task_return_error (task, error);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> +<br>
> + /* Parse XDNS results and return two vectors containing IPV4 and IPV6<br>
> addresses */<br>
> + if (!parse_xdns_query_response (response, ctx->cid, MAX_DNS_SERVERS,<br>
> dns_v4, dns_v6)) {<br>
> + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "Error parsing +XDNS response: '%s'",<br>
> + response);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> + if (ctx->ipv4_config)<br>
> + mm_bearer_ip_config_set_dns (ctx->ipv4_config, (const gchar<br>
> **)dns_v4);<br>
> +<br>
> + if (ctx->ipv6_config)<br>
> + mm_bearer_ip_config_set_dns (ctx->ipv6_config, (const gchar<br>
> **)dns_v6);<br>
> +<br>
> + ctx->step++;<br>
> + get_ip_config_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +static void<br>
> +get_ip_config_3gpp_context_step (GTask *task)<br>
> +{<br>
> + GetIPConfig3gppContext *ctx;<br>
> +<br>
> + ctx = (GetIPConfig3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + mm_dbg("GetIPConfig Step : %d", ctx->step);<br>
> +<br>
> + switch (ctx->step) {<br>
> + case GET_IP_CONFIG_3GPP_CONTEXT_STEP_CGPADDR: {<br>
> + gchar *command = g_strdup_printf ("+CGPADDR=%u", ctx->cid);<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + command,<br>
> + 3,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)ip_info_ready,<br>
> + task);<br>
> + g_free (command);<br>
> + return;<br>
> + }<br>
> + case GET_IP_CONFIG_3GPP_CONTEXT_STEP_XDNS: {<br>
> + /* query DNS addresses */<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + "+XDNS?",<br>
> + 3,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)dns_info_ready,<br>
> + task);<br>
> + return;<br>
> + }<br>
> + case GET_IP_CONFIG_3GPP_CONTEXT_STEP_LAST: {<br>
> +<br>
> + g_task_return_pointer (task,<br>
> + mm_bearer_connect_result_new (ctx->data,<br>
> ctx->ipv4_config, ctx->ipv6_config),<br>
> + (GDestroyNotify)<br>
> mm_bearer_connect_result_unref);<br>
> +<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +static void<br>
> +get_ip_config_3gpp (MMBroadbandBearer *self,<br>
> + MMBroadbandModem *modem,<br>
> + MMPortSerialAt *primary,<br>
> + MMPortSerialAt *secondary,<br>
> + MMPort *data,<br>
> + guint cid,<br>
> + MMBearerIpFamily ip_family,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data)<br>
> +{<br>
> + GTask *task;<br>
> + GetIPConfig3gppContext *ctx;<br>
> +<br>
> + g_assert (primary != NULL);<br>
> + g_assert (data != NULL);<br>
> + g_assert (modem != NULL);<br>
> +<br>
> + /* Setup task and create disconnect context */<br>
> + task = g_task_new (self, NULL, callback, user_data);<br>
> + ctx = g_slice_new0 (GetIPConfig3gppContext);<br>
> + g_task_set_task_data (task, ctx, (GDestroyNotify)<br>
> get_ip_config_3gpp_context_free);<br>
> +<br>
> + /* Setup context */<br>
> + ctx->self = g_object_ref (self);<br>
> + ctx->modem = g_object_ref (modem);<br>
> + ctx->primary = g_object_ref (primary);<br>
> + ctx->cid = cid;<br>
> + ctx->ip_family = ip_family;<br>
> + ctx->data = g_object_ref (data);<br>
> + ctx->step = GET_IP_CONFIG_3GPP_CONTEXT_STEP_CGPADDR;<br>
> + ctx->ipv4_config = NULL;<br>
> + ctx->ipv6_config = NULL;<br>
> +<br>
> + /* Start */<br>
> + get_ip_config_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +<br>
> +/*****************************************************************************/<br>
> +/* Disconnect 3GPP */<br>
> +<br>
> +typedef enum {<br>
> + DISCONNECT_3GPP_CONTEXT_STEP_CGACT,<br>
> + DISCONNECT_3GPP_CONTEXT_STEP_DYN_DNS,<br>
> + DISCONNECT_3GPP_CONTEXT_STEP_LAST<br>
> +} Disconnect3gppContextStep;<br>
> +<br>
> +typedef struct {<br>
> + MMBroadbandBearerInfineon *self;<br>
> + MMBaseModem *modem;<br>
> + MMPortSerialAt *primary;<br>
> + MMPort *data;<br>
> + guint cid;<br>
> + Disconnect3gppContextStep step;<br>
> +} Disconnect3gppContext;<br>
> +<br>
> +static void<br>
> +disconnect_3gpp_context_free (Disconnect3gppContext *ctx)<br>
> +{<br>
> + g_object_unref (ctx->self);<br>
> + g_object_unref (ctx->modem);<br>
> + g_object_unref (ctx->primary);<br>
> + g_object_unref (ctx->data);<br>
> + g_slice_free (Disconnect3gppContext, ctx);<br>
> +}<br>
> +<br>
> +static gboolean<br>
> +disconnect_3gpp_finish (MMBroadbandBearer *self,<br>
> + GAsyncResult *res,<br>
> + GError **error)<br>
> +{<br>
> + return g_task_propagate_boolean (G_TASK (res), error);<br>
> +}<br>
> +<br>
> +/* forward declaration */<br>
> +static void<br>
> +disconnect_3gpp_context_step (GTask *task);<br>
> +<br>
> +static void<br>
> +cgact_disconnect_ready (MMBaseModem *modem,<br>
> + GAsyncResult *res,<br>
> + GTask *task)<br>
> +{<br>
> + Disconnect3gppContext *ctx;<br>
> + GError *error = NULL;<br>
> +<br>
> + mm_base_modem_at_command_finish (modem, res, &error);<br>
> +<br>
> + if (error) {<br>
> + if(!g_error_matches (error,<br>
> + MM_CONNECTION_ERROR,<br>
> + MM_CONNECTION_ERROR_NO_CARRIER))<br>
> + {<br>
> + mm_dbg ("PDP context deactivation failed (not fatal): %s",<br>
> error->message);<br>
> + }<br>
> + g_error_free (error);<br>
> + }<br>
> +<br>
> + ctx = (Disconnect3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + /* Go on to next step */<br>
> + ctx->step++;<br>
> + disconnect_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +static void<br>
> +xdns_disconnect_ready (MMBaseModem *modem,<br>
> + GAsyncResult *res,<br>
> + GTask *task)<br>
> +{<br>
> + Disconnect3gppContext *ctx;<br>
> + GError *error = NULL;<br>
> +<br>
> + mm_base_modem_at_command_finish (modem, res, &error);<br>
> +<br>
> + if (error) {<br>
> + mm_dbg ("Dynamic DNS disable request failed: %s", error->message);<br>
> + g_error_free (error);<br>
> + }<br>
> +<br>
> + ctx = (Disconnect3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + /* Go on to next step */<br>
> + ctx->step++;<br>
> + disconnect_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +static void<br>
> +disconnect_3gpp_context_step (GTask *task)<br>
> +{<br>
> + Disconnect3gppContext *ctx;<br>
> +<br>
> + ctx = (Disconnect3gppContext *) g_task_get_task_data (task);<br>
> +<br>
> + mm_dbg("Disconnect3gpp Step : %d", ctx->step);<br>
> +<br>
> + switch (ctx->step) {<br>
> + case DISCONNECT_3GPP_CONTEXT_STEP_CGACT: {<br>
> + gchar *command;<br>
> +<br>
> + command = g_strdup_printf ("+CGACT=0,%u",<br>
> + ctx->cid );<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + command,<br>
> + 30,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)<br>
> cgact_disconnect_ready,<br>
> + task);<br>
> + g_free (command);<br>
> + return;<br>
> + }<br>
> +<br>
> + case DISCONNECT_3GPP_CONTEXT_STEP_DYN_DNS: {<br>
> + gchar *command;<br>
> +<br>
> + command = g_strdup_printf ("+XDNS=%u,0",<br>
> + ctx->cid);<br>
> + mm_base_modem_at_command (ctx->modem,<br>
> + command,<br>
> + 10,<br>
> + FALSE,<br>
> + (GAsyncReadyCallback)<br>
> xdns_disconnect_ready,<br>
> + task);<br>
> + g_free (command);<br>
> + return;<br>
> + }<br>
> +<br>
> + case DISCONNECT_3GPP_CONTEXT_STEP_LAST:{<br>
> + g_task_return_boolean (task, TRUE);<br>
> + g_object_unref (task);<br>
> + return;<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +static void<br>
> +disconnect_3gpp (MMBroadbandBearer *self,<br>
> + MMBroadbandModem *modem,<br>
> + MMPortSerialAt *primary,<br>
> + MMPortSerialAt *secondary,<br>
> + MMPort *data,<br>
> + guint cid,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data)<br>
> +{<br>
> + GTask *task;<br>
> + Disconnect3gppContext *ctx;<br>
> +<br>
> + g_assert (primary != NULL);<br>
> + g_assert (data != NULL);<br>
> + g_assert (modem != NULL);<br>
> +<br>
> + /* Setup task and create disconnect context */<br>
> + task = g_task_new (self, NULL, callback, user_data);<br>
> + ctx = g_slice_new0 (Disconnect3gppContext);<br>
> + g_task_set_task_data (task, ctx, (GDestroyNotify)<br>
> disconnect_3gpp_context_free);<br>
> +<br>
> + /* Setup context */<br>
> + ctx->self = g_object_ref (self);<br>
> + ctx->modem = g_object_ref (modem);<br>
> + ctx->primary = g_object_ref (primary);<br>
> + ctx->data = g_object_ref (data);<br>
> + ctx->cid = cid;<br>
> + ctx->step = DISCONNECT_3GPP_CONTEXT_STEP_CGACT;<br>
> +<br>
> + /* Start */<br>
> + disconnect_3gpp_context_step (task);<br>
> +}<br>
> +<br>
> +/*****************************************************************************/<br>
> +<br>
> +MMBaseBearer *<br>
> +mm_broadband_bearer_infineon_new_finish (GAsyncResult *res,<br>
> + GError **error)<br>
> +{<br>
> + GObject *bearer;<br>
> + GObject *source;<br>
> +<br>
> + source = g_async_result_get_source_object (res);<br>
> + bearer = g_async_initable_new_finish (G_ASYNC_INITABLE (source), res,<br>
> error);<br>
> + g_object_unref (source);<br>
> +<br>
> + if (!bearer)<br>
> + return NULL;<br>
> +<br>
> + /* Only export valid bearers */<br>
> + mm_base_bearer_export (MM_BASE_BEARER (bearer));<br>
> +<br>
> + return MM_BASE_BEARER (bearer);<br>
> +}<br>
> +<br>
> +void<br>
> +mm_broadband_bearer_infineon_new (MMBroadbandModemInfineon *modem,<br>
> + MMBearerProperties *config,<br>
> + GCancellable *cancellable,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data)<br>
> +{<br>
> + g_async_initable_new_async (<br>
> + MM_TYPE_BROADBAND_BEARER_INFINEON,<br>
> + G_PRIORITY_DEFAULT,<br>
> + cancellable,<br>
> + callback,<br>
> + user_data,<br>
> + MM_BASE_BEARER_MODEM, modem,<br>
> + MM_BASE_BEARER_CONFIG, config,<br>
> + NULL);<br>
> +}<br>
> +<br>
> +static void<br>
> +mm_broadband_bearer_infineon_init (MMBroadbandBearerInfineon *self)<br>
> +{<br>
> +<br>
> + return;<br>
> +}<br>
> +<br>
> +static void<br>
> +mm_broadband_bearer_infineon_class_init (MMBroadbandBearerInfineonClass<br>
> *klass)<br>
> +{<br>
> + MMBroadbandBearerClass *broadband_bearer_class =<br>
> MM_BROADBAND_BEARER_CLASS (klass);<br>
> +<br>
> + broadband_bearer_class->dial_3gpp = dial_3gpp;<br>
> + broadband_bearer_class->dial_3gpp_finish = dial_3gpp_finish;<br>
> +<br>
> + broadband_bearer_class->get_ip_config_3gpp = get_ip_config_3gpp;<br>
> + broadband_bearer_class->get_ip_config_3gpp_finish =<br>
> get_ip_config_3gpp_finish;<br>
> +<br>
> +<br>
> + broadband_bearer_class->disconnect_3gpp = disconnect_3gpp;<br>
> + broadband_bearer_class->disconnect_3gpp_finish =<br>
> disconnect_3gpp_finish;<br>
> +}<br>
> diff --git a/plugins/infineon/mm-broadband-bearer-infineon.h<br>
> b/plugins/infineon/mm-broadband-bearer-infineon.h<br>
> new file mode 100644<br>
> index 0000000..cfc6910<br>
> --- /dev/null<br>
> +++ b/plugins/infineon/mm-broadband-bearer-infineon.h<br>
> @@ -0,0 +1,59 @@<br>
> +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-<br>
> */<br>
> +/*<br>
> + * This program is free software; you can redistribute it and/or modify<br>
> + * it under the terms of the GNU General Public License as published by<br>
> + * the Free Software Foundation; either version 2 of the License, or<br>
> + * (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
> + * GNU General Public License for more details:<br>
> + *<br>
> + * Copyright (C) 2013 Aleksander Morgado <<a href="mailto:aleksander@gnu.org" target="_blank">aleksander@gnu.org</a>><br>
> + */<br>
> +<br>
> +#ifndef MM_BROADBAND_BEARER_INFINEON_H<br>
> +#define MM_BROADBAND_BEARER_INFINEON_H<br>
> +<br>
> +#include <glib.h><br>
> +#include <glib-object.h><br>
> +<br>
> +#define _LIBMM_INSIDE_MM<br>
> +#include <libmm-glib.h><br>
> +<br>
> +#include "mm-broadband-bearer.h"<br>
> +#include "mm-broadband-modem-infineon.h"<br>
> +<br>
> +#define MM_TYPE_BROADBAND_BEARER_INFINEON<br>
> (mm_broadband_bearer_infineon_get_type ())<br>
> +#define MM_BROADBAND_BEARER_INFINEON(obj)<br>
> (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_BEARER_INFINEON,<br>
> MMBroadbandBearerInfineon))<br>
> +#define MM_BROADBAND_BEARER_INFINEON_CLASS(klass)<br>
> (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_BEARER_INFINEON,<br>
> MMBroadbandBearerInfineonClass))<br>
> +#define MM_IS_BROADBAND_BEARER_INFINEON(obj)<br>
> (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_BEARER_INFINEON))<br>
> +#define MM_IS_BROADBAND_BEARER_INFINEON_CLASS(klass)<br>
> (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_BEARER_INFINEON))<br>
> +#define MM_BROADBAND_BEARER_INFINEON_GET_CLASS(obj)<br>
> (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_BEARER_INFINEON,<br>
> MMBroadbandBearerInfineonClass))<br>
> +<br>
> +typedef struct _MMBroadbandBearerInfineon MMBroadbandBearerInfineon;<br>
> +typedef struct _MMBroadbandBearerInfineonClass<br>
> MMBroadbandBearerInfineonClass;<br>
> +typedef struct _MMBroadbandBearerInfineonPrivate<br>
> MMBroadbandBearerInfineonPrivate;<br>
> +<br>
> +struct _MMBroadbandBearerInfineon {<br>
> + MMBroadbandBearer parent;<br>
> + MMBroadbandBearerInfineonPrivate *priv;<br>
> +};<br>
> +<br>
> +struct _MMBroadbandBearerInfineonClass {<br>
> + MMBroadbandBearerClass parent;<br>
> +};<br>
> +<br>
> +GType mm_broadband_bearer_infineon_get_type (void);<br>
> +<br>
> +/* Default 3GPP bearer creation implementation */<br>
> +void mm_broadband_bearer_infineon_new (MMBroadbandModemInfineon *modem,<br>
> + MMBearerProperties *config,<br>
> + GCancellable *cancellable,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data);<br>
> +MMBaseBearer *mm_broadband_bearer_infineon_new_finish (GAsyncResult *res,<br>
> + GError **error);<br>
> +<br>
> +#endif /* MM_BROADBAND_BEARER_INFINEON_H */<br>
> diff --git a/plugins/infineon/mm-broadband-modem-infineon.c<br>
> b/plugins/infineon/mm-broadband-modem-infineon.c<br>
> new file mode 100755<br>
> index 0000000..f20804f<br>
> --- /dev/null<br>
> +++ b/plugins/infineon/mm-broadband-modem-infineon.c<br>
> @@ -0,0 +1,216 @@<br>
> +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-<br>
> */<br>
> +/*<br>
> + * This program is free software; you can redistribute it and/or modify<br>
> + * it under the terms of the GNU General Public License as published by<br>
> + * the Free Software Foundation; either version 2 of the License, or<br>
> + * (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
> + * GNU General Public License for more details:<br>
> + *<br>
> + * Copyright (C) 2013 Aleksander Morgado <<a href="mailto:aleksander@gnu.org" target="_blank">aleksander@gnu.org</a>><br>
> + * Copyright (C) 2017 Tempered Networks Inc.<br>
> + */<br>
> +<br>
> +#include <config.h><br>
> +<br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +#include <string.h><br>
> +#include <unistd.h><br>
> +#include <ctype.h><br>
> +<br>
> +#include "ModemManager.h"<br>
> +#include "mm-base-modem-at.h"<br>
> +#include "mm-serial-parsers.h"<br>
> +#include "mm-log.h"<br>
> +#include "mm-errors-types.h"<br>
> +#include "mm-iface-modem.h"<br>
> +#include "mm-iface-modem-3gpp.h"<br>
> +#include "mm-broadband-bearer-infineon.h"<br>
> +#include "mm-broadband-modem-infineon.h"<br>
> +<br>
> +static void iface_modem_init (MMIfaceModem *iface);<br>
> +<br>
> +<br>
> +G_DEFINE_TYPE_EXTENDED (MMBroadbandModemInfineon,<br>
> mm_broadband_modem_infineon, MM_TYPE_BROADBAND_MODEM, 0,<br>
> + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM,<br>
> iface_modem_init))<br>
> +<br>
> +/*****************************************************************************/<br>
> +/* Create Bearer (Modem interface) */<br>
> +<br>
> +static MMBaseBearer *<br>
> +modem_create_bearer_finish (MMIfaceModem *self,<br>
> + GAsyncResult *res,<br>
> + GError **error)<br>
> +{<br>
> + MMBaseBearer *bearer;<br>
> +<br>
> + bearer = g_simple_async_result_get_op_res_gpointer<br>
> (G_SIMPLE_ASYNC_RESULT (res));<br>
> + mm_dbg ("New Infineon bearer created at DBus path '%s'",<br>
> mm_base_bearer_get_path (bearer));<br>
> +<br>
> + return g_object_ref (bearer);<br>
> +}<br>
> +<br>
> +static void<br>
> +broadband_bearer_infineon_new_ready (GObject *source,<br>
> + GAsyncResult *res,<br>
> + GSimpleAsyncResult *simple)<br>
> +{<br>
> + MMBaseBearer *bearer = NULL;<br>
> + GError *error = NULL;<br>
> +<br>
> + bearer = mm_broadband_bearer_infineon_new_finish (res, &error);<br>
> + if (!bearer)<br>
> + g_simple_async_result_take_error (simple, error);<br>
> + else<br>
> + g_simple_async_result_set_op_res_gpointer (simple,<br>
> + bearer,<br>
> +<br>
> (GDestroyNotify)g_object_unref);<br>
> + g_simple_async_result_complete (simple);<br>
> + g_object_unref (simple);<br>
> +}<br>
> +<br>
> +static void<br>
> +modem_create_bearer (MMIfaceModem *self,<br>
> + MMBearerProperties *properties,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data)<br>
> +{<br>
> + GSimpleAsyncResult *result;<br>
> +<br>
> + result = g_simple_async_result_new (G_OBJECT (self),<br>
> + callback,<br>
> + user_data,<br>
> + modem_create_bearer);<br>
> +<br>
> + mm_broadband_bearer_infineon_new (MM_BROADBAND_MODEM_INFINEON (self),<br>
> + properties,<br>
> + NULL, /* cancellable */<br>
> +<br>
> (GAsyncReadyCallback)broadband_bearer_infineon_new_ready,<br>
> + result);<br>
> +}<br>
> +<br>
> +/*****************************************************************************/<br>
> +/* Reset (Modem interface) */<br>
> +<br>
> +static gboolean<br>
> +modem_reset_finish (MMIfaceModem *self,<br>
> + GAsyncResult *res,<br>
> + GError **error)<br>
> +{<br>
> + return !!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res,<br>
> error);<br>
> +}<br>
> +<br>
> +static void<br>
> +modem_reset (MMIfaceModem *self,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data)<br>
> +{<br>
> + mm_base_modem_at_command (MM_BASE_MODEM (self),<br>
> + "AT+CFUN=1,1",<br>
> + 3,<br>
> + FALSE,<br>
> + callback,<br>
> + user_data);<br>
> +}<br>
> +<br>
> +/*****************************************************************************/<br>
> +/* MODEM POWER DOWN */<br>
> +<br>
> +static gboolean<br>
> +modem_power_down_finish (MMIfaceModem *self,<br>
> + GAsyncResult *res,<br>
> + GError **error)<br>
> +{<br>
> + return !!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res,<br>
> error);<br>
> +}<br>
> +<br>
> +static void<br>
> +modem_power_down (MMIfaceModem *self,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data)<br>
> +{<br>
> + /* Use AT+CFUN=4 for power down. It will stop the RF (IMSI detach), and<br>
> + * keeps access to the SIM */<br>
> + mm_base_modem_at_command (MM_BASE_MODEM (self),<br>
> + "+CFUN=4",<br>
> + /* The modem usually completes +CFUN=4<br>
> within 1-2 seconds,<br>
> + * but sometimes takes a ridiculously long<br>
> time (~30-35 seconds).<br>
> + * It's better to have a long timeout here<br>
> than to have the<br>
> + * modem not responding to subsequent AT<br>
> commands until +CFUN=4<br>
> + * completes. */<br>
> + 40,<br>
> + FALSE,<br>
> + callback,<br>
> + user_data);<br>
> +}<br>
> +<br>
> +<br>
> +/*****************************************************************************/<br>
> +/* Modem power up (Modem interface) */<br>
> +<br>
> +static gboolean<br>
> +modem_power_up_finish (MMIfaceModem *self,<br>
> + GAsyncResult *res,<br>
> + GError **error)<br>
> +{<br>
> + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT<br>
> (res), error);<br>
> +}<br>
> +<br>
> +static void<br>
> +modem_power_up (MMIfaceModem *self,<br>
> + GAsyncReadyCallback callback,<br>
> + gpointer user_data)<br>
> +{<br>
> + mm_base_modem_at_command (MM_BASE_MODEM (self),<br>
> + "+CFUN=1",<br>
> + 10,<br>
> + FALSE,<br>
> + callback,<br>
> + user_data);<br>
> +}<br>
> +<br>
> +/*****************************************************************************/<br>
> +<br>
> +MMBroadbandModemInfineon *<br>
> +mm_broadband_modem_infineon_new (const gchar *device,<br>
> + const gchar **drivers,<br>
> + const gchar *plugin,<br>
> + guint16 vendor_id,<br>
> + guint16 product_id)<br>
> +{<br>
> + return g_object_new (MM_TYPE_BROADBAND_MODEM_INFINEON,<br>
> + MM_BASE_MODEM_DEVICE, device,<br>
> + MM_BASE_MODEM_DRIVERS, drivers,<br>
> + MM_BASE_MODEM_PLUGIN, plugin,<br>
> + MM_BASE_MODEM_VENDOR_ID, vendor_id,<br>
> + MM_BASE_MODEM_PRODUCT_ID, product_id,<br>
> + NULL);<br>
> +}<br>
> +<br>
> +static void<br>
> +mm_broadband_modem_infineon_init (MMBroadbandModemInfineon *self)<br>
> +{<br>
> +}<br>
> +<br>
> +static void<br>
> +iface_modem_init (MMIfaceModem *iface)<br>
> +{<br>
> + iface->create_bearer = modem_create_bearer;<br>
> + iface->create_bearer_finish = modem_create_bearer_finish;<br>
> + iface->reset = modem_reset;<br>
> + iface->reset_finish = modem_reset_finish;<br>
> + iface->modem_power_down = modem_power_down;<br>
> + iface->modem_power_down_finish = modem_power_down_finish;<br>
> + iface->modem_power_up = modem_power_up;<br>
> + iface->modem_power_up_finish = modem_power_up_finish;<br>
> +<br>
> +}<br>
> +<br>
> +static void<br>
> +mm_broadband_modem_infineon_class_init (MMBroadbandModemInfineonClass<br>
> *klass)<br>
> +{<br>
> +}<br>
> diff --git a/plugins/infineon/mm-broadband-modem-infineon.h<br>
> b/plugins/infineon/mm-broadband-modem-infineon.h<br>
> new file mode 100644<br>
> index 0000000..1b4ee5a<br>
> --- /dev/null<br>
> +++ b/plugins/infineon/mm-broadband-modem-infineon.h<br>
> @@ -0,0 +1,47 @@<br>
> +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-<br>
> */<br>
> +/*<br>
> + * This program is free software; you can redistribute it and/or modify<br>
> + * it under the terms of the GNU General Public License as published by<br>
> + * the Free Software Foundation; either version 2 of the License, or<br>
> + * (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
> + * GNU General Public License for more details:<br>
> + *<br>
> + * Copyright (C) 2013 Aleksander Morgado <<a href="mailto:aleksander@gnu.org" target="_blank">aleksander@gnu.org</a>><br>
> + */<br>
> +<br>
> +#ifndef MM_BROADBAND_MODEM_INFINEON_H<br>
> +#define MM_BROADBAND_MODEM_INFINEON_H<br>
> +<br>
> +#include "mm-broadband-modem.h"<br>
> +<br>
> +#define MM_TYPE_BROADBAND_MODEM_INFINEON<br>
> (mm_broadband_modem_infineon_get_type ())<br>
> +#define MM_BROADBAND_MODEM_INFINEON(obj)<br>
> (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_INFINEON,<br>
> MMBroadbandModemInfineon))<br>
> +#define MM_BROADBAND_MODEM_INFINEON_CLASS(klass)<br>
> (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_INFINEON,<br>
> MMBroadbandModemInfineonClass))<br>
> +#define MM_IS_BROADBAND_MODEM_INFINEON(obj)<br>
> (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_INFINEON))<br>
> +#define MM_IS_BROADBAND_MODEM_INFINEON_CLASS(klass)<br>
> (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_INFINEON))<br>
> +#define MM_BROADBAND_MODEM_INFINEON_GET_CLASS(obj)<br>
> (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_INFINEON,<br>
> MMBroadbandModemInfineonClass))<br>
> +<br>
> +typedef struct _MMBroadbandModemInfineon MMBroadbandModemInfineon;<br>
> +typedef struct _MMBroadbandModemInfineonClass<br>
> MMBroadbandModemInfineonClass;<br>
> +<br>
> +struct _MMBroadbandModemInfineon {<br>
> + MMBroadbandModem parent;<br>
> +};<br>
> +<br>
> +struct _MMBroadbandModemInfineonClass{<br>
> + MMBroadbandModemClass parent;<br>
> +};<br>
> +<br>
> +GType mm_broadband_modem_infineon_get_type (void);<br>
> +<br>
> +MMBroadbandModemInfineon *mm_broadband_modem_infineon_new (const gchar<br>
> *device,<br>
> + const gchar<br>
> **drivers,<br>
> + const gchar<br>
> *plugin,<br>
> + guint16<br>
> vendor_id,<br>
> + guint16<br>
> product_id);<br>
> +<br>
> +#endif /* MM_BROADBAND_MODEM_INFINEON_H */<br>
> diff --git a/plugins/infineon/mm-plugin-infineon.c<br>
> b/plugins/infineon/mm-plugin-infineon.c<br>
> new file mode 100755<br>
> index 0000000..11ab596<br>
> --- /dev/null<br>
> +++ b/plugins/infineon/mm-plugin-infineon.c<br>
> @@ -0,0 +1,88 @@<br>
> +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-<br>
> */<br>
> +<br>
> +/*<br>
> + * This program is free software; you can redistribute it and/or<br>
> + * modify it under the terms of the GNU General Public License as<br>
> + * published by the Free Software Foundation; either version 2 of the<br>
> + * License, or (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
> + * General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU General Public<br>
> + * License along with this program; if not, write to the<br>
> + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,<br>
> + * Boston, MA 02111-1307, USA.<br>
> + *<br>
> + * Copyright (C) 2013 Aleksander Morgado <<a href="mailto:aleksander@gnu.org" target="_blank">aleksander@gnu.org</a>><br>
> + * Copyright (C) 2017 Tempered Networks Inc.<br>
> + */<br>
> +<br>
> +#include <string.h><br>
> +#include <gmodule.h><br>
> +<br>
> +#define _LIBMM_INSIDE_MM<br>
> +#include <libmm-glib.h><br>
> +<br>
> +#include "mm-broadband-modem-infineon.h"<br>
> +#include "mm-plugin-infineon.h"<br>
> +#include "mm-log.h"<br>
> +<br>
> +G_DEFINE_TYPE (MMPluginInfineon, mm_plugin_infineon, MM_TYPE_PLUGIN)<br>
> +<br>
> +int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;<br>
> +int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;<br>
> +<br>
> +static MMBaseModem *<br>
> +create_modem (MMPlugin *self,<br>
> + const gchar *sysfs_path,<br>
> + const gchar **drivers,<br>
> + guint16 vendor,<br>
> + guint16 product,<br>
> + GList *probes,<br>
> + GError **error)<br>
> +{<br>
> + return MM_BASE_MODEM (mm_broadband_modem_infineon_new (sysfs_path,<br>
> + drivers,<br>
> +<br>
> mm_plugin_get_name (self),<br>
> + vendor,<br>
> + product));<br>
> +}<br>
> +<br>
> +/*****************************************************************************/<br>
> +<br>
> +G_MODULE_EXPORT MMPlugin *<br>
> +mm_plugin_create (void)<br>
> +{<br>
> + static const gchar *subsystems[] = { "tty", "net", "usb", NULL };<br>
> + static const guint16 vendor_ids[] = { 0x1519, 0 };<br>
> + // We only want to support the NCM based USB composition.<br>
> + static const guint16 product_ids_allow[] = { 0x0443, 0};<br>
> + // Otherwise fall back on the Generic plugin.<br>
> + static const guint16 product_ids_forbid[] = { 0x0020, 0};<br>
> +<br>
> + return MM_PLUGIN (<br>
> + g_object_new (MM_TYPE_PLUGIN_INFINEON,<br>
> + MM_PLUGIN_NAME, "Infineon",<br>
> + MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems,<br>
> + MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids,<br>
> + MM_PLUGIN_ALLOWED_PRODUCT_IDS, product_ids_allow,<br>
> + MM_PLUGIN_FORBIDDEN_PRODUCT_IDS, product_ids_forbid,<br>
> + MM_PLUGIN_ALLOWED_AT, TRUE,<br>
> + NULL));<br>
> +}<br>
> +<br>
> +static void<br>
> +mm_plugin_infineon_init (MMPluginInfineon *self)<br>
> +{<br>
> +}<br>
> +<br>
> +static void<br>
> +mm_plugin_infineon_class_init (MMPluginInfineonClass *klass)<br>
> +{<br>
> + MMPluginClass *plugi</blockquote></div></div></div></div>