static void reg_nwsnap_6800_cb (MMQcdmSerialPort *port, GByteArray *response, GError *error, gpointer user_data) { MMCallbackInfo *info = user_data; QcdmResult *result; GByteArray *nwsnap; if (error) goto done; /* Parse the response */ result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const char *) response->data, response->len, NULL); if (!result) { /* Try for MSM6500 */ nwsnap = g_byte_array_sized_new (25); nwsnap->len = qcdm_cmd_nw_subsys_modem_snapshot_cdma_new ((char *) nwsnap->data, 25, QCDM_NW_CHIPSET_6500); g_assert (nwsnap->len); mm_qcdm_serial_port_queue_command (port, nwsnap, 3, reg_nwsnap_6500_cb, info); return; } parse_modem_snapshot (info, result); qcdm_result_unref (result); done: mm_callback_info_schedule (info); }
static void reg_eri_6500_cb (MMPortSerialQcdm *port, GAsyncResult *res, DetailedRegistrationStateContext *ctx) { GError *error = NULL; GByteArray *response; response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { /* Just ignore the error and complete with the input info */ mm_dbg ("Couldn't run QCDM MSM6500 ERI: '%s'", error->message); g_error_free (error); } else { QcdmResult *result; result = qcdm_cmd_nw_subsys_eri_result ((const gchar *) response->data, response->len, NULL); g_byte_array_unref (response); if (result) { parse_modem_eri (ctx, result); qcdm_result_unref (result); } } /* NOTE: always complete NOT in idle here */ g_simple_async_result_set_op_res_gpointer (ctx->result, &ctx->state, NULL); detailed_registration_state_context_complete_and_free (ctx); }
static void nw_snapshot_old_cb (MMPortSerialQcdm *port, GAsyncResult *res, SnapshotContext *ctx) { QcdmResult *result; guint8 hdr_revision = QCDM_HDR_REV_UNKNOWN; GError *error = NULL; GByteArray *response; response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { /* Just ignore the error and complete with the input info */ mm_dbg ("Couldn't run QCDM Novatel Modem MSM6500 snapshot: '%s'", error->message); g_error_free (error); snapshot_context_complete_and_free (ctx, QCDM_HDR_REV_UNKNOWN); return; } /* Parse the response */ result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const gchar *) response->data, response->len, NULL); g_byte_array_unref (response); if (result) { qcdm_result_get_u8 (result, QCDM_CMD_NW_SUBSYS_MODEM_SNAPSHOT_CDMA_ITEM_HDR_REV, &hdr_revision); qcdm_result_unref (result); } else mm_dbg ("Failed to get QCDM Novatel Modem MSM6500 snapshot."); snapshot_context_complete_and_free (ctx, hdr_revision); }
void test_result_string (void *f, void *data) { const char *str = "foobarblahblahblah"; const char *tmp = NULL; QCDMResult *result; result = qcdm_result_new (); qcdm_result_add_string (result, TEST_TAG, str); qcdm_result_get_string (result, TEST_TAG, &tmp); g_assert (tmp); g_assert (strcmp (tmp, str) == 0); qcdm_result_unref (result); }
static void reg_nwsnap_6500_cb (MMQcdmSerialPort *port, GByteArray *response, GError *error, gpointer user_data) { MMCallbackInfo *info = user_data; QcdmResult *result; if (!error) { result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const char *) response->data, response->len, NULL); if (result) { parse_modem_snapshot (info, result); qcdm_result_unref (result); } } mm_callback_info_schedule (info); }
static void reg_eri_6800_cb (MMPortSerialQcdm *port, GAsyncResult *res, DetailedRegistrationStateContext *ctx) { GError *error = NULL; GByteArray *response; response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { /* Just ignore the error and complete with the input info */ mm_dbg ("Couldn't run QCDM MSM6800 ERI: '%s'", error->message); g_error_free (error); } else { QcdmResult *result; /* Parse the response */ result = qcdm_cmd_nw_subsys_eri_result ((const gchar *) response->data, response->len, NULL); g_byte_array_unref (response); if (result) { parse_modem_eri (ctx, result); qcdm_result_unref (result); } else { GByteArray *nweri; /* Try for MSM6500 */ nweri = g_byte_array_sized_new (25); nweri->len = qcdm_cmd_nw_subsys_eri_new ((char *) nweri->data, 25, QCDM_NW_CHIPSET_6500); g_assert (nweri->len); mm_port_serial_qcdm_command (port, nweri, 3, NULL, (GAsyncReadyCallback)reg_eri_6500_cb, ctx); g_byte_array_unref (nweri); return; } } /* NOTE: always complete NOT in idle here */ g_simple_async_result_set_op_res_gpointer (ctx->result, &ctx->state, NULL); detailed_registration_state_context_complete_and_free (ctx); }
static void nw_snapshot_new_cb (MMPortSerialQcdm *port, GAsyncResult *res, SnapshotContext *ctx) { QcdmResult *result; GByteArray *nwsnap; guint8 hdr_revision = QCDM_HDR_REV_UNKNOWN; GError *error = NULL; GByteArray *response; response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { mm_dbg ("Couldn't run QCDM Novatel Modem MSM6800 snapshot: '%s'", error->message); g_error_free (error); snapshot_context_complete_and_free (ctx, QCDM_HDR_REV_UNKNOWN); return; } /* Parse the response */ result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const gchar *) response->data, response->len, NULL); g_byte_array_unref (response); if (result) { qcdm_result_get_u8 (result, QCDM_CMD_NW_SUBSYS_MODEM_SNAPSHOT_CDMA_ITEM_HDR_REV, &hdr_revision); qcdm_result_unref (result); snapshot_context_complete_and_free (ctx, hdr_revision); return; } mm_dbg ("Failed to get QCDM Novatel Modem MSM6800 snapshot."); /* Try for MSM6500 */ nwsnap = g_byte_array_sized_new (25); nwsnap->len = qcdm_cmd_nw_subsys_modem_snapshot_cdma_new ((char *) nwsnap->data, 25, QCDM_NW_CHIPSET_6500); g_assert (nwsnap->len); mm_port_serial_qcdm_command (port, nwsnap, 3, NULL, (GAsyncReadyCallback)nw_snapshot_old_cb, ctx); g_byte_array_unref (nwsnap); }
static void serial_probe_qcdm_parse_response (MMQcdmSerialPort *port, GByteArray *response, GError *error, MMPortProbe *self) { QcdmResult *result; gint err = QCDM_SUCCESS; gboolean is_qcdm = FALSE; /* Just the initial poke; ignore it */ if (!self) return; /* If already cancelled, do nothing else */ if (port_probe_run_is_cancelled (self)) return; if (!error) { /* Parse the response */ result = qcdm_cmd_version_info_result ((const gchar *) response->data, response->len, &err); if (!result) { mm_warn ("(%s) failed to parse QCDM version info command result: %d", self->priv->name, err); } else { /* yay, probably a QCDM port */ is_qcdm = TRUE; qcdm_result_unref (result); } } /* Set probing result */ mm_port_probe_set_result_qcdm (self, is_qcdm); /* Reschedule probing */ serial_probe_schedule (self); }
static void qcdm_verinfo_cb (MMQcdmSerialPort *port, GByteArray *response, GError *error, gpointer user_data) { MMPluginBaseSupportsTask *task; MMPluginBaseSupportsTaskPrivate *priv; QCDMResult *result; GError *dm_error = NULL; /* Just the initial poke; ignore it */ if (!user_data) return; task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data); priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task); if (error) { /* Probably not a QCDM port */ goto done; } /* Parse the response */ result = qcdm_cmd_version_info_result ((const char *) response->data, response->len, &dm_error); if (!result) { g_warning ("(%s) failed to parse QCDM version info command result: (%d) %s.", g_udev_device_get_name (priv->port), dm_error ? dm_error->code : -1, dm_error && dm_error->message ? dm_error->message : "(unknown)"); g_clear_error (&dm_error); goto done; } /* yay, probably a QCDM port */ qcdm_result_unref (result); priv->probed_caps |= MM_PLUGIN_BASE_PORT_CAP_QCDM; done: probe_complete (task); }
static int qcdm_set_mode (int fd, u_int8_t mode) { int err; char buf[512]; size_t len; QcdmResult *result; size_t reply_len; len = qcdm_cmd_control_new (buf, sizeof (buf), mode); assert (len); /* Send the command */ if (!qcdm_send (fd, buf, len)) { fprintf (stderr, "E: failed to send QCDM Control command\n"); goto error; } reply_len = qcdm_wait_reply (fd, buf, sizeof (buf)); if (!reply_len) { fprintf (stderr, "E: failed to receive Control command reply\n"); goto error; } /* Parse the response into a result structure */ err = QCDM_SUCCESS; result = qcdm_cmd_control_result (buf, reply_len, &err); if (!result) { fprintf (stderr, "E: failed to parse Control command reply: %d\n", err); goto error; } qcdm_result_unref (result); return 0; error: return -1; }
static void serial_probe_qcdm_parse_response (MMQcdmSerialPort *port, GByteArray *response, GError *error, MMPortProbe *self) { QcdmResult *result; gint err = QCDM_SUCCESS; gboolean is_qcdm = FALSE; gboolean retry = FALSE; PortProbeRunTask *task = self->priv->task; /* If already cancelled, do nothing else */ if (port_probe_run_is_cancelled (self)) return; if (!error) { /* Parse the response */ result = qcdm_cmd_version_info_result ((const gchar *) response->data, response->len, &err); if (!result) { mm_warn ("(%s/%s) failed to parse QCDM version info command result: %d", g_udev_device_get_subsystem (self->priv->port), g_udev_device_get_name (self->priv->port), err); retry = TRUE; } else { /* yay, probably a QCDM port */ is_qcdm = TRUE; qcdm_result_unref (result); } } else { if (!g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) mm_dbg ("QCDM probe error: (%d) %s", error->code, error->message); retry = TRUE; } if (retry) { GByteArray *cmd2; cmd2 = g_object_steal_data (G_OBJECT (self), "cmd2"); if (cmd2) { /* second try */ mm_qcdm_serial_port_queue_command (MM_QCDM_SERIAL_PORT (task->serial), cmd2, 3, NULL, (MMQcdmSerialResponseFn)serial_probe_qcdm_parse_response, self); return; } /* no more retries left */ } /* Set probing result */ mm_port_probe_set_result_qcdm (self, is_qcdm); /* Reschedule probing */ serial_probe_schedule (self); }