umbim: add home provider query support
authorIngo Feinerer <feinerer@logic.at>
Sun, 4 Aug 2019 11:02:16 +0000 (13:02 +0200)
committerJohn Crispin <john@phrozen.org>
Wed, 11 Sep 2019 07:23:21 +0000 (09:23 +0200)
This adds support to query the home provider, mainly for debugging and
information purposes.

Signed-off-by: Ingo Feinerer <feinerer@logic.at>
Reviewed-by: Bjørn Mork <bjorn@mork.no>
cli.c

diff --git a/cli.c b/cli.c
index 19f36f4f63c42a0338228b73b606007e00eccca6..3a845d463d843040e19325de2098831ca47fb014 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -95,6 +95,32 @@ mbim_pin_state_response(void *buffer, size_t len)
        return 0;
 }
 
+static int
+mbim_home_provider_response(void *buffer, size_t len)
+{
+       struct mbim_basic_connect_home_provider_r *state = (struct mbim_basic_connect_home_provider_r *) buffer;
+       struct mbimprovider *provider;
+       char *provider_id, *provider_name;
+
+       if (len < sizeof(struct mbim_basic_connect_home_provider_r)) {
+               fprintf(stderr, "message not long enough\n");
+               return -1;
+       }
+
+       provider = &state->provider;
+       provider_id = mbim_get_string(&provider->providerid, buffer);
+       provider_name = mbim_get_string(&provider->providername, buffer);
+
+       printf("  provider_id: %s\n", provider_id);
+       printf("  provider_name: %s\n", provider_name);
+       printf("  cellularclass: %04X - %s\n", le32toh(provider->cellularclass),
+               mbim_enum_string(mbim_cellular_class_values, le32toh(provider->cellularclass)));
+       printf("  rssi: %04X\n", le32toh(provider->rssi));
+       printf("  errorrate: %04X\n", le32toh(provider->errorrate));
+
+       return 0;
+}
+
 static int
 mbim_registration_response(void *buffer, size_t len)
 {
@@ -294,6 +320,14 @@ mbim_pin_state_request(void)
        return mbim_send_command_msg();
 }
 
+static int
+mbim_home_provider_request(void)
+{
+       mbim_setup_command_msg(basic_connect, MBIM_MESSAGE_COMMAND_TYPE_QUERY, MBIM_CID_BASIC_CONNECT_HOME_PROVIDER, 0);
+
+       return mbim_send_command_msg();
+}
+
 static int
 mbim_registration_request(void)
 {
@@ -478,6 +512,7 @@ static struct mbim_handler handlers[] = {
        { "caps", 0, mbim_device_caps_request, mbim_device_caps_response },
        { "pinstate", 0, mbim_pin_state_request, mbim_pin_state_response },
        { "unlock", 1, mbim_pin_unlock_request, mbim_pin_state_response },
+       { "home", 0, mbim_home_provider_request, mbim_home_provider_response },
        { "registration", 0, mbim_registration_request, mbim_registration_response },
        { "subscriber", 0, mbim_subscriber_request, mbim_subscriber_response },
        { "attach", 0, mbim_attach_request, mbim_attach_response },
@@ -491,7 +526,7 @@ static struct mbim_handler handlers[] = {
 static int
 usage(void)
 {
-       fprintf(stderr, "Usage: umbim <caps|pinstate|unlock|registration|subscriber|attach|detach|connect|disconnect|config|radio> [options]\n"
+       fprintf(stderr, "Usage: umbim <caps|pinstate|unlock|home|registration|subscriber|attach|detach|connect|disconnect|config|radio> [options]\n"
                "Options:\n"
 #ifdef LIBQMI_MBIM_PROXY
                "    -p                 use mbim-proxy\n"