[PATCH] broadband-modem-mbim: implement network scan
Ben Chan
benchan at chromium.org
Wed Dec 4 11:07:42 PST 2013
---
src/mm-broadband-modem-mbim.c | 81 ++++++++++++++++++++++++++++++++++++++++---
src/mm-modem-helpers-mbim.c | 48 +++++++++++++++++++++++++
src/mm-modem-helpers-mbim.h | 4 +++
3 files changed, 129 insertions(+), 4 deletions(-)
diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c
index 9ab36a9..b4d3ff1 100644
--- a/src/mm-broadband-modem-mbim.c
+++ b/src/mm-broadband-modem-mbim.c
@@ -2301,6 +2301,81 @@ modem_3gpp_register_in_network (MMIfaceModem3gpp *self,
}
/*****************************************************************************/
+/* Scan networks (3GPP interface) */
+
+static GList *
+modem_3gpp_scan_networks_finish (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return NULL;
+
+ return g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+}
+
+static void
+visible_providers_query_ready (MbimDevice *device,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ MbimMessage *response;
+ GError *error = NULL;
+ MbimProvider **providers;
+ guint n_providers;
+
+ response = mbim_device_command_finish (device, res, &error);
+ if (response &&
+ mbim_message_command_done_get_result (response, &error) &&
+ mbim_message_visible_providers_response_parse (
+ response,
+ &n_providers,
+ &providers,
+ &error)) {
+ GList *info_list;
+
+ info_list = mm_3gpp_network_info_list_from_mbim_providers ((const MbimProvider *const *)providers,
+ n_providers);
+ g_simple_async_result_set_op_res_gpointer (simple, info_list, NULL);
+ mbim_provider_array_free (providers);
+ } else
+ g_simple_async_result_take_error (simple, error);
+
+ if (response)
+ mbim_message_unref (response);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+modem_3gpp_scan_networks (MMIfaceModem3gpp *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ MbimDevice *device;
+ MbimMessage *message;
+
+ if (!peek_device (self, &device, callback, user_data))
+ return;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_3gpp_scan_networks);
+
+ mm_dbg ("scanning networks...");
+ message = mbim_message_visible_providers_query_new (MBIM_VISIBLE_PROVIDERS_ACTION_FULL_SCAN, NULL);
+ mbim_device_command (device,
+ message,
+ 120,
+ NULL,
+ (GAsyncReadyCallback)visible_providers_query_ready,
+ result);
+ mbim_message_unref (message);
+}
+
+/*****************************************************************************/
/* Check support (Messaging interface) */
static gboolean
@@ -2698,10 +2773,8 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface)
iface->run_registration_checks_finish = modem_3gpp_run_registration_checks_finish;
iface->register_in_network = modem_3gpp_register_in_network;
iface->register_in_network_finish = modem_3gpp_register_in_network_finish;
-
- /* TODO: use MBIM_CID_VISIBLE_PROVIDERS */
- iface->scan_networks = NULL;
- iface->scan_networks_finish = NULL;
+ iface->scan_networks = modem_3gpp_scan_networks;
+ iface->scan_networks_finish = modem_3gpp_scan_networks_finish;
}
static void
diff --git a/src/mm-modem-helpers-mbim.c b/src/mm-modem-helpers-mbim.c
index d58ed59..8060ace 100644
--- a/src/mm-modem-helpers-mbim.c
+++ b/src/mm-modem-helpers-mbim.c
@@ -14,6 +14,7 @@
*/
#include "mm-modem-helpers-mbim.h"
+#include "mm-modem-helpers.h"
#include "mm-enums-types.h"
#include "mm-errors-types.h"
#include "mm-log.h"
@@ -127,6 +128,53 @@ mm_modem_access_technology_from_mbim_data_class (MbimDataClass data_class)
/*****************************************************************************/
+MMModem3gppNetworkAvailability
+mm_modem_3gpp_network_availability_from_mbim_provider_state (MbimProviderState state)
+{
+ switch (state) {
+ case MBIM_PROVIDER_STATE_HOME:
+ case MBIM_PROVIDER_STATE_PREFERRED:
+ case MBIM_PROVIDER_STATE_VISIBLE:
+ case MBIM_PROVIDER_STATE_PREFERRED_MULTICARRIER:
+ return MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE;
+ case MBIM_PROVIDER_STATE_REGISTERED:
+ return MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT;
+ case MBIM_PROVIDER_STATE_FORBIDDEN:
+ return MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN;
+ case MBIM_PROVIDER_STATE_UNKNOWN:
+ default:
+ return MM_MODEM_3GPP_NETWORK_AVAILABILITY_UNKNOWN;
+ }
+}
+
+/*****************************************************************************/
+
+GList *
+mm_3gpp_network_info_list_from_mbim_providers (const MbimProvider *const *providers, guint n_providers)
+{
+ GList *info_list = NULL;
+ guint i;
+
+ g_return_val_if_fail (providers != NULL, NULL);
+
+ for (i = 0; i < n_providers; i++) {
+ MM3gppNetworkInfo *info;
+
+ info = g_new0 (MM3gppNetworkInfo, 1);
+ info->status = mm_modem_3gpp_network_availability_from_mbim_provider_state (providers[i]->provider_state);
+ info->operator_long = g_strdup (providers[i]->provider_name);
+ info->operator_short = g_strdup (providers[i]->provider_name);
+ info->operator_code = g_strdup (providers[i]->provider_id);
+ info->access_tech = mm_modem_access_technology_from_mbim_data_class (providers[i]->cellular_class);
+
+ info_list = g_list_append (info_list, info);
+ }
+
+ return info_list;
+}
+
+/*****************************************************************************/
+
GError *
mm_mobile_equipment_error_from_mbim_nw_error (MbimNwError nw_error)
{
diff --git a/src/mm-modem-helpers-mbim.h b/src/mm-modem-helpers-mbim.h
index 28d8f7e..67b6b57 100644
--- a/src/mm-modem-helpers-mbim.h
+++ b/src/mm-modem-helpers-mbim.h
@@ -30,6 +30,10 @@ MMModem3gppRegistrationState mm_modem_3gpp_registration_state_from_mbim_register
MMModemAccessTechnology mm_modem_access_technology_from_mbim_data_class (MbimDataClass data_class);
+MMModem3gppNetworkAvailability mm_modem_3gpp_network_availability_from_mbim_provider_state (MbimProviderState state);
+
+GList *mm_3gpp_network_info_list_from_mbim_providers (const MbimProvider *const *providers, guint n_providers);
+
GError *mm_mobile_equipment_error_from_mbim_nw_error (MbimNwError nw_error);
/*****************************************************************************/
--
1.8.5.1
More information about the ModemManager-devel
mailing list