static void curc_ready (MMAtSerialPort *port, GString *response, GError *error, HuaweiCustomInitContext *ctx) { if (error) { /* Retry if we get a timeout error */ if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) { huawei_custom_init_step (ctx); return; } mm_dbg ("(Huawei) couldn't turn off unsolicited messages in" "secondary ports: '%s'", error->message); } mm_dbg ("(Huawei) unsolicited messages in secondary ports turned off"); ctx->curc_done = TRUE; huawei_custom_init_step (ctx); }
static void curc_ready (MMPortSerialAt *port, GAsyncResult *res, HuaweiCustomInitContext *ctx) { const gchar *response; GError *error = NULL; response = mm_port_serial_at_command_finish (port, res, &error); if (error) { /* Retry if we get a timeout error */ if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) goto out; mm_dbg ("(Huawei) couldn't turn off unsolicited messages in secondary ports: '%s'", error->message); } mm_dbg ("(Huawei) unsolicited messages in secondary ports turned off"); ctx->curc_done = TRUE; out: if (error) g_error_free (error); huawei_custom_init_step (ctx); }
static void getportmode_ready (MMAtSerialPort *port, GString *response, GError *error, HuaweiCustomInitContext *ctx) { if (error) { mm_dbg ("(Huawei) couldn't get port mode: '%s'", error->message); /* If any error occurred that was not ERROR or COMMAND NOT SUPPORT then * retry the command. */ if (!g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN)) { /* Retry */ huawei_custom_init_step (ctx); return; } /* Port mode not supported */ } else { MMDevice *device; mm_dbg ("(Huawei) port mode layout retrieved"); /* Results are cached in the parent device object */ device = mm_port_probe_peek_device (ctx->probe); cache_port_mode (device, response->str, "PCUI:", TAG_HUAWEI_PCUI_PORT); cache_port_mode (device, response->str, "MDM:", TAG_HUAWEI_MODEM_PORT); cache_port_mode (device, response->str, "NDIS:", TAG_HUAWEI_NDIS_PORT); cache_port_mode (device, response->str, "DIAG:", TAG_HUAWEI_DIAG_PORT); g_object_set_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED, GUINT_TO_POINTER (TRUE)); /* Mark port as being AT already */ mm_port_probe_set_result_at (ctx->probe, TRUE); } ctx->getportmode_done = TRUE; huawei_custom_init_step (ctx); }
static void getportmode_ready (MMPortSerialAt *port, GAsyncResult *res, HuaweiCustomInitContext *ctx) { const gchar *response; GError *error = NULL; response = mm_port_serial_at_command_finish (port, res, &error); if (error) { mm_dbg ("(Huawei) couldn't get port mode: '%s'", error->message); /* If any error occurred that was not ERROR or COMMAND NOT SUPPORT then * retry the command. */ if (!g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN)) goto out; /* Port mode not supported */ } else { MMDevice *device; mm_dbg ("(Huawei) port mode layout retrieved"); /* Results are cached in the parent device object */ device = mm_port_probe_peek_device (ctx->probe); cache_port_mode (device, response, "PCUI:", TAG_HUAWEI_PCUI_PORT); cache_port_mode (device, response, "MDM:", TAG_HUAWEI_MODEM_PORT); cache_port_mode (device, response, "NDIS:", TAG_HUAWEI_NDIS_PORT); cache_port_mode (device, response, "DIAG:", TAG_HUAWEI_DIAG_PORT); /* GETPORTMODE response format in newer devices... (e.g. E3372) */ cache_port_mode (device, response, "pcui:", TAG_HUAWEI_PCUI_PORT); cache_port_mode (device, response, "modem:", TAG_HUAWEI_MODEM_PORT); g_object_set_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED, GUINT_TO_POINTER (TRUE)); /* Mark port as being AT already */ mm_port_probe_set_result_at (ctx->probe, TRUE); } ctx->getportmode_done = TRUE; out: if (error) g_error_free (error); huawei_custom_init_step (ctx); }
static void huawei_custom_init (MMPortProbe *probe, MMAtSerialPort *port, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { MMDevice *device; FirstInterfaceContext *fi_ctx; HuaweiCustomInitContext *ctx; device = mm_port_probe_peek_device (probe); /* The primary port (called the "modem" port in the Windows drivers) is * always USB interface 0, and we need to detect that interface first for * two reasons: (1) to disable unsolicited messages on other ports that * may fill up the buffer and crash the device, and (2) to attempt to get * the port layout for hints about what the secondary port is (called the * "pcui" port in Windows). Thus we probe USB interface 0 first and defer * probing other interfaces until we've got if0, at which point we allow * the other ports to be probed too. */ fi_ctx = g_object_get_data (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT); if (!fi_ctx) { /* This is the first time we ask for the context. Set it up. */ fi_ctx = g_slice_new0 (FirstInterfaceContext); g_object_set_data_full (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT, fi_ctx, (GDestroyNotify)first_interface_context_free); /* The timeout is controlled in the data set in 'device', and therefore * it should be safe to assume that the timeout will not get fired after * having disposed 'device' */ fi_ctx->timeout_id = g_timeout_add_seconds (MAX_WAIT_TIME, (GSourceFunc)first_interface_missing_timeout_cb, device); /* By default, we'll ask the Huawei plugin to start probing usbif 0 */ fi_ctx->first_usbif = 0; /* Custom init of the Huawei plugin is to be run only in the first * interface. We'll control here whether we did run it already or not. */ fi_ctx->custom_init_run = FALSE; } ctx = g_slice_new (HuaweiCustomInitContext); ctx->result = g_simple_async_result_new (G_OBJECT (probe), callback, user_data, huawei_custom_init); ctx->probe = g_object_ref (probe); ctx->port = g_object_ref (port); ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; ctx->curc_done = FALSE; ctx->curc_retries = 3; ctx->getportmode_done = FALSE; ctx->getportmode_retries = 3; /* Custom init only to be run in the first interface */ if (g_udev_device_get_property_as_int (mm_port_probe_peek_port (probe), "ID_USB_INTERFACE_NUM") != fi_ctx->first_usbif) { if (fi_ctx->custom_init_run) /* If custom init was run already, we can consider this as successfully run */ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); else /* Otherwise, we'll need to defer the probing a bit more */ g_simple_async_result_set_error (ctx->result, MM_CORE_ERROR, MM_CORE_ERROR_RETRY, "Defer needed"); huawei_custom_init_context_complete_and_free (ctx); return; } /* We can run custom init in the first interface! clear the timeout as it is no longer needed */ g_source_remove (fi_ctx->timeout_id); fi_ctx->timeout_id = 0; huawei_custom_init_step (ctx); }