[PATCH 3/5] ms-hostshutdown: add support for the Microsoft Host Shutdown service

Ben Chan benchan at chromium.org
Tue Feb 25 12:48:16 PST 2014


---
 data/Makefile.am                             |   3 +-
 data/mbim-service-ms-hostshutdown.json       |  11 ++
 src/libmbim-glib/generated/Makefile.am       |  18 ++-
 src/libmbim-glib/libmbim-glib.h              |   1 +
 src/libmbim-glib/mbim-cid.c                  |  22 +++-
 src/libmbim-glib/mbim-cid.h                  |  12 ++
 src/libmbim-glib/mbim-message.c              |   2 +-
 src/libmbim-glib/mbim-uuid.c                 |  15 ++-
 src/libmbim-glib/mbim-uuid.h                 |  29 +++--
 src/libmbim-glib/test/test-cid.c             |  25 +++--
 src/libmbim-glib/test/test-message-builder.c |  51 +++++++++
 src/libmbim-glib/test/test-uuid.c            |  25 +++--
 src/mbimcli/mbimcli-ms-hostshutdown.c        | 158 +++++++++++++++++++++++++++
 13 files changed, 337 insertions(+), 35 deletions(-)
 create mode 100644 data/mbim-service-ms-hostshutdown.json
 create mode 100644 src/mbimcli/mbimcli-ms-hostshutdown.c

diff --git a/data/Makefile.am b/data/Makefile.am
index e214ee0..a212966 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -8,4 +8,5 @@ EXTRA_DIST = \
 	mbim-service-phonebook.json \
 	mbim-service-stk.json \
 	mbim-service-dss.json \
-	mbim-service-ms-fwid.json
+	mbim-service-ms-fwid.json \
+	mbim-service-ms-hostshutdown.json
diff --git a/data/mbim-service-ms-hostshutdown.json b/data/mbim-service-ms-hostshutdown.json
new file mode 100644
index 0000000..5d5d64a
--- /dev/null
+++ b/data/mbim-service-ms-hostshutdown.json
@@ -0,0 +1,11 @@
+[
+  // *********************************************************************************
+  { "type" : "Service",
+    "name" : "MS HostShutdown" },
+
+  // *********************************************************************************
+  { "name"     : "HostShutdown",
+    "service"  : "MS HostShutdown",
+    "type"     : "Command",
+    "set"      : [] }
+]
diff --git a/src/libmbim-glib/generated/Makefile.am b/src/libmbim-glib/generated/Makefile.am
index 16c71af..6e6a340 100644
--- a/src/libmbim-glib/generated/Makefile.am
+++ b/src/libmbim-glib/generated/Makefile.am
@@ -10,7 +10,8 @@ GENERATED_H = \
 	mbim-phonebook.h \
 	mbim-stk.h \
 	mbim-dss.h \
-	mbim-ms-fwid.h
+	mbim-ms-fwid.h \
+	mbim-ms-hostshutdown.h
 
 GENERATED_C = \
 	mbim-error-types.c \
@@ -23,7 +24,8 @@ GENERATED_C = \
 	mbim-phonebook.c \
 	mbim-stk.c \
 	mbim-dss.c \
-	mbim-ms-fwid.c
+	mbim-ms-fwid.c \
+	mbim-ms-hostshutdown.c
 
 GENERATED_SECTIONS = \
 	mbim-basic-connect.sections \
@@ -33,7 +35,8 @@ GENERATED_SECTIONS = \
 	mbim-phonebook.sections \
 	mbim-stk.sections \
 	mbim-dss.sections \
-	mbim-ms-fwid.sections
+	mbim-ms-fwid.sections \
+	mbim-ms-hostshutdown.sections
 
 # Error types
 mbim-error-types.h: $(top_srcdir)/src/libmbim-glib/mbim-errors.h $(top_srcdir)/build-aux/templates/mbim-error-types-template.h
@@ -146,6 +149,15 @@ mbim-ms-fwid.h mbim-ms-fwid.c mbim-ms-fwid.sections: $(top_srcdir)/data/mbim-ser
 			--input $(top_srcdir)/data/mbim-service-ms-fwid.json \
 			--output mbim-ms-fwid
 
+# Microsoft Host Shutdown service
+mbim-ms-hostshutdown.h mbim-ms-hostshutdown.c mbim-ms-hostshutdown.sections: $(top_srcdir)/data/mbim-service-ms-hostshutdown.json $(top_srcdir)/build-aux/mbim-codegen/*.py $(top_srcdir)/build-aux/mbim-codegen/mbim-codegen
+	$(AM_V_GEN)  \
+		rm -f mbim-ms-hostshutdown.h && \
+		rm -f mbim-ms-hostshutdown.c && \
+		$(top_srcdir)/build-aux/mbim-codegen/mbim-codegen \
+			--input $(top_srcdir)/data/mbim-service-ms-hostshutdown.json \
+			--output mbim-ms-hostshutdown
+
 BUILT_SOURCES = $(GENERATED_H) $(GENERATED_C)
 
 nodist_libmbim_glib_generated_la_SOURCES = \
diff --git a/src/libmbim-glib/libmbim-glib.h b/src/libmbim-glib/libmbim-glib.h
index a7f0962..f863c9d 100644
--- a/src/libmbim-glib/libmbim-glib.h
+++ b/src/libmbim-glib/libmbim-glib.h
@@ -46,5 +46,6 @@
 #include "mbim-stk.h"
 #include "mbim-dss.h"
 #include "mbim-ms-fwid.h"
+#include "mbim-ms-hostshutdown.h"
 
 #endif /* _LIBMBIM_GLIB_H_ */
diff --git a/src/libmbim-glib/mbim-cid.c b/src/libmbim-glib/mbim-cid.c
index 715eb66..50099a2 100644
--- a/src/libmbim-glib/mbim-cid.c
+++ b/src/libmbim-glib/mbim-cid.c
@@ -119,6 +119,12 @@ static const CidConfig cid_ms_fwid_config [MBIM_CID_MS_FWID_LAST] = {
     { FALSE, TRUE,  FALSE }, /* MBIM_CID_MS_FWID_FIRMWAREID */
 };
 
+/* Note: index of the array is CID-1 */
+#define MBIM_CID_MS_HOSTSHUTDOWN_LAST MBIM_CID_MS_HOSTSHUTDOWN_HOSTSHUTDOWN
+static const CidConfig cid_ms_hostshutdown_config [MBIM_CID_MS_HOSTSHUTDOWN_LAST] = {
+    { TRUE,  FALSE, FALSE }, /* MBIM_CID_MS_HOSTSHUTDOWN_HOSTSHUTDOWN */
+};
+
 /**
  * mbim_cid_can_set:
  * @service: a #MbimService.
@@ -136,7 +142,7 @@ mbim_cid_can_set (MbimService service,
     g_return_val_if_fail (cid > 0, FALSE);
     /* Known service required */
     g_return_val_if_fail (service > MBIM_SERVICE_INVALID, FALSE);
-    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, FALSE);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_HOSTSHUTDOWN, FALSE);
 
     switch (service) {
     case MBIM_SERVICE_BASIC_CONNECT:
@@ -155,6 +161,8 @@ mbim_cid_can_set (MbimService service,
         return cid_dss_config[cid - 1].set;
     case MBIM_SERVICE_MS_FWID:
         return cid_ms_fwid_config[cid - 1].set;
+    case MBIM_SERVICE_MS_HOSTSHUTDOWN:
+        return cid_ms_hostshutdown_config[cid - 1].set;
     default:
         g_assert_not_reached ();
         return FALSE;
@@ -178,7 +186,7 @@ mbim_cid_can_query (MbimService service,
     g_return_val_if_fail (cid > 0, FALSE);
     /* Known service required */
     g_return_val_if_fail (service > MBIM_SERVICE_INVALID, FALSE);
-    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, FALSE);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_HOSTSHUTDOWN, FALSE);
 
     switch (service) {
     case MBIM_SERVICE_BASIC_CONNECT:
@@ -197,6 +205,8 @@ mbim_cid_can_query (MbimService service,
         return cid_dss_config[cid - 1].query;
     case MBIM_SERVICE_MS_FWID:
         return cid_ms_fwid_config[cid - 1].query;
+    case MBIM_SERVICE_MS_HOSTSHUTDOWN:
+        return cid_ms_hostshutdown_config[cid - 1].query;
     default:
         g_assert_not_reached ();
         return FALSE;
@@ -220,7 +230,7 @@ mbim_cid_can_notify (MbimService service,
     g_return_val_if_fail (cid > 0, FALSE);
     /* Known service required */
     g_return_val_if_fail (service > MBIM_SERVICE_INVALID, FALSE);
-    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, FALSE);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_HOSTSHUTDOWN, FALSE);
 
     switch (service) {
     case MBIM_SERVICE_BASIC_CONNECT:
@@ -239,6 +249,8 @@ mbim_cid_can_notify (MbimService service,
         return cid_dss_config[cid - 1].notify;
     case MBIM_SERVICE_MS_FWID:
         return cid_ms_fwid_config[cid - 1].notify;
+    case MBIM_SERVICE_MS_HOSTSHUTDOWN:
+        return cid_ms_hostshutdown_config[cid - 1].notify;
     default:
         g_assert_not_reached ();
         return FALSE;
@@ -263,7 +275,7 @@ mbim_cid_get_printable (MbimService service,
     g_return_val_if_fail (cid > 0, NULL);
     /* Known service required */
     g_return_val_if_fail (service > MBIM_SERVICE_INVALID, NULL);
-    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, NULL);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_HOSTSHUTDOWN, NULL);
 
     switch (service) {
     case MBIM_SERVICE_BASIC_CONNECT:
@@ -282,6 +294,8 @@ mbim_cid_get_printable (MbimService service,
         return mbim_cid_dss_get_string (cid);
     case MBIM_SERVICE_MS_FWID:
         return mbim_cid_ms_fwid_get_string (cid);
+    case MBIM_SERVICE_MS_HOSTSHUTDOWN:
+        return mbim_cid_ms_hostshutdown_get_string (cid);
     default:
         g_assert_not_reached ();
         return FALSE;
diff --git a/src/libmbim-glib/mbim-cid.h b/src/libmbim-glib/mbim-cid.h
index a360d55..dbdaf25 100644
--- a/src/libmbim-glib/mbim-cid.h
+++ b/src/libmbim-glib/mbim-cid.h
@@ -195,6 +195,18 @@ typedef enum {
     MBIM_CID_MS_FWID_FIRMWAREID = 1
 } MbimCidMsFwid;
 
+/**
+ * MbimCidMsHostshutdown:
+ * @MBIM_CID_MS_HOSTSHUTDOWN_UNKNOWN: Unknown command.
+ * @MBIM_CID_MS_HOSTSHUTDOWN_HOSTSHUTDOWN: Indicate that the host is shutting down.
+ *
+ * MBIM commands in the %MBIM_SERVICE_MS_HOSTSHUTDOWN service.
+ */
+typedef enum {
+    MBIM_CID_MS_HOSTSHUTDOWN_UNKNOWN      = 0,
+    MBIM_CID_MS_HOSTSHUTDOWN_HOSTSHUTDOWN = 1
+} MbimCidMsHostshutdown;
+
 /* Command helpers */
 
 gboolean     mbim_cid_can_set       (MbimService service,
diff --git a/src/libmbim-glib/mbim-message.c b/src/libmbim-glib/mbim-message.c
index f2f8c64..1923c56 100644
--- a/src/libmbim-glib/mbim-message.c
+++ b/src/libmbim-glib/mbim-message.c
@@ -1738,7 +1738,7 @@ mbim_message_command_new (guint32                transaction_id,
 
     /* Known service required */
     g_return_val_if_fail (service > MBIM_SERVICE_INVALID, FALSE);
-    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, FALSE);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_HOSTSHUTDOWN, FALSE);
     service_id = mbim_uuid_from_service (service);
 
     self = _mbim_message_allocate (MBIM_MESSAGE_TYPE_COMMAND,
diff --git a/src/libmbim-glib/mbim-uuid.c b/src/libmbim-glib/mbim-uuid.c
index a993ec2..06b53e0 100644
--- a/src/libmbim-glib/mbim-uuid.c
+++ b/src/libmbim-glib/mbim-uuid.c
@@ -151,6 +151,14 @@ static const MbimUuid uuid_ms_fwid = {
     .e = { 0x90, 0xa3, 0x69, 0x41, 0x03, 0xb6 }
 };
 
+static const MbimUuid uuid_ms_hostshutdown = {
+    .a = { 0x88, 0x3b, 0x7c, 0x26 },
+    .b = { 0x98, 0x5f },
+    .c = { 0x43, 0xfa },
+    .d = { 0x98, 0x04 },
+    .e = { 0x27, 0xd7, 0xfb, 0x80, 0x95, 0x9c }
+};
+
 /**
  * mbim_uuid_from_service:
  * @service: a #MbimService.
@@ -162,7 +170,7 @@ static const MbimUuid uuid_ms_fwid = {
 const MbimUuid *
 mbim_uuid_from_service (MbimService service)
 {
-    g_return_val_if_fail (service >= MBIM_SERVICE_INVALID && service <= MBIM_SERVICE_MS_FWID,
+    g_return_val_if_fail (service >= MBIM_SERVICE_INVALID && service <= MBIM_SERVICE_MS_HOSTSHUTDOWN,
                           &uuid_invalid);
 
     switch (service) {
@@ -184,6 +192,8 @@ mbim_uuid_from_service (MbimService service)
         return &uuid_dss;
     case MBIM_SERVICE_MS_FWID:
         return &uuid_ms_fwid;
+    case MBIM_SERVICE_MS_HOSTSHUTDOWN:
+        return &uuid_ms_hostshutdown;
     default:
         g_assert_not_reached ();
     }
@@ -224,6 +234,9 @@ mbim_uuid_to_service (const MbimUuid *uuid)
     if (mbim_uuid_cmp (uuid, &uuid_ms_fwid))
         return MBIM_SERVICE_MS_FWID;
 
+    if (mbim_uuid_cmp (uuid, &uuid_ms_hostshutdown))
+        return MBIM_SERVICE_MS_HOSTSHUTDOWN;
+
     return MBIM_SERVICE_INVALID;
 }
 
diff --git a/src/libmbim-glib/mbim-uuid.h b/src/libmbim-glib/mbim-uuid.h
index 04bb371..d568878 100644
--- a/src/libmbim-glib/mbim-uuid.h
+++ b/src/libmbim-glib/mbim-uuid.h
@@ -67,19 +67,21 @@ gchar    *mbim_uuid_get_printable (const MbimUuid *uuid);
  * @MBIM_SERVICE_AUTH: Authentication service.
  * @MBIM_SERVICE_DSS: Device Service Stream service.
  * @MBIM_SERVICE_MS_FWID: Microsoft Firmware ID service.
+ * @MBIM_SERVICE_MS_HOSTSHUTDOWN: Microsoft Host Shutdown service.
  *
  * Enumeration of the generic MBIM services.
  */
 typedef enum {
-    MBIM_SERVICE_INVALID       = 0,
-    MBIM_SERVICE_BASIC_CONNECT = 1,
-    MBIM_SERVICE_SMS           = 2,
-    MBIM_SERVICE_USSD          = 3,
-    MBIM_SERVICE_PHONEBOOK     = 4,
-    MBIM_SERVICE_STK           = 5,
-    MBIM_SERVICE_AUTH          = 6,
-    MBIM_SERVICE_DSS           = 7,
-    MBIM_SERVICE_MS_FWID       = 8,
+    MBIM_SERVICE_INVALID         = 0,
+    MBIM_SERVICE_BASIC_CONNECT   = 1,
+    MBIM_SERVICE_SMS             = 2,
+    MBIM_SERVICE_USSD            = 3,
+    MBIM_SERVICE_PHONEBOOK       = 4,
+    MBIM_SERVICE_STK             = 5,
+    MBIM_SERVICE_AUTH            = 6,
+    MBIM_SERVICE_DSS             = 7,
+    MBIM_SERVICE_MS_FWID         = 8,
+    MBIM_SERVICE_MS_HOSTSHUTDOWN = 9,
 } MbimService;
 
 /**
@@ -163,6 +165,15 @@ typedef enum {
  */
 #define MBIM_UUID_MS_FWID mbim_uuid_from_service (MBIM_SERVICE_MS_FWID)
 
+/**
+ * MBIM_UUID_MS_HOSTSHUTDOWN:
+ *
+ * Get the UUID of the %MBIM_SERVICE_MS_HOSTSHUTDOWN service.
+ *
+ * Returns: (transfer none): a #MbimUuid.
+ */
+#define MBIM_UUID_MS_HOSTSHUTDOWN mbim_uuid_from_service (MBIM_SERVICE_MS_HOSTSHUTDOWN)
+
 /* To/From service */
 const MbimUuid *mbim_uuid_from_service  (MbimService     service);
 MbimService     mbim_uuid_to_service    (const MbimUuid *uuid);
diff --git a/src/libmbim-glib/test/test-cid.c b/src/libmbim-glib/test/test-cid.c
index 2c9c0d2..8bee01f 100644
--- a/src/libmbim-glib/test/test-cid.c
+++ b/src/libmbim-glib/test/test-cid.c
@@ -113,18 +113,27 @@ test_cid_ms_fwid (void)
                  FALSE, TRUE, FALSE);
 }
 
+static void
+test_cid_ms_hostshutdown (void)
+{
+    test_common (MBIM_SERVICE_MS_HOSTSHUTDOWN,
+                 MBIM_CID_MS_HOSTSHUTDOWN_HOSTSHUTDOWN,
+                 TRUE, FALSE, FALSE);
+}
+
 int main (int argc, char **argv)
 {
     g_test_init (&argc, &argv, NULL);
 
-    g_test_add_func ("/libmbim-glib/cid/basic-connect", test_cid_basic_connect);
-    g_test_add_func ("/libmbim-glib/cid/sms",           test_cid_sms);
-    g_test_add_func ("/libmbim-glib/cid/ussd",          test_cid_ussd);
-    g_test_add_func ("/libmbim-glib/cid/phonebook",     test_cid_phonebook);
-    g_test_add_func ("/libmbim-glib/cid/stk",           test_cid_stk);
-    g_test_add_func ("/libmbim-glib/cid/auth",          test_cid_auth);
-    g_test_add_func ("/libmbim-glib/cid/dss",           test_cid_dss);
-    g_test_add_func ("/libmbim-glib/cid/ms-fwid",       test_cid_ms_fwid);
+    g_test_add_func ("/libmbim-glib/cid/basic-connect",   test_cid_basic_connect);
+    g_test_add_func ("/libmbim-glib/cid/sms",             test_cid_sms);
+    g_test_add_func ("/libmbim-glib/cid/ussd",            test_cid_ussd);
+    g_test_add_func ("/libmbim-glib/cid/phonebook",       test_cid_phonebook);
+    g_test_add_func ("/libmbim-glib/cid/stk",             test_cid_stk);
+    g_test_add_func ("/libmbim-glib/cid/auth",            test_cid_auth);
+    g_test_add_func ("/libmbim-glib/cid/dss",             test_cid_dss);
+    g_test_add_func ("/libmbim-glib/cid/ms-fwid",         test_cid_ms_fwid);
+    g_test_add_func ("/libmbim-glib/cid/ms-hostshutdown", test_cid_ms_hostshutdown);
 
     return g_test_run ();
 }
diff --git a/src/libmbim-glib/test/test-message-builder.c b/src/libmbim-glib/test/test-message-builder.c
index 239a8bf..780aa0a 100644
--- a/src/libmbim-glib/test/test-message-builder.c
+++ b/src/libmbim-glib/test/test-message-builder.c
@@ -26,6 +26,7 @@
 #include "mbim-auth.h"
 #include "mbim-stk.h"
 #include "mbim-dss.h"
+#include "mbim-ms-hostshutdown.h"
 
 #if defined ENABLE_TEST_MESSAGE_TRACES
 static void
@@ -1296,6 +1297,55 @@ test_message_builder_basic_connect_multicarrier_providers_set (void)
     mbim_provider_array_free (providers);
 }
 
+static void
+test_message_builder_ms_hostshutdown_hostshutdown_set (void)
+{
+    GError *error = NULL;
+    MbimMessage *message;
+    const guint8 expected_message [] = {
+        /* header */
+        0x03, 0x00, 0x00, 0x00, /* type */
+        0x30, 0x00, 0x00, 0x00, /* length */
+        0x01, 0x00, 0x00, 0x00, /* transaction id */
+        /* fragment header */
+        0x01, 0x00, 0x00, 0x00, /* total */
+        0x00, 0x00, 0x00, 0x00, /* current */
+        /* command_message */
+        0x88, 0x3B, 0x7C, 0x26, /* service id */
+        0x98, 0x5F, 0x43, 0xFA,
+        0x98, 0x04, 0x27, 0xD7,
+        0xFB, 0x80, 0x95, 0x9C,
+        0x01, 0x00, 0x00, 0x00, /* command id */
+        0x01, 0x00, 0x00, 0x00, /* command_type */
+        0x00, 0x00, 0x00, 0x00, /* buffer_length */
+        /* information buffer */
+    };
+
+    /* MS Host Shutdown set message */
+    message = mbim_message_ms_hostshutdown_hostshutdown_set_new (&error);
+    g_assert_no_error (error);
+    g_assert (message != NULL);
+    mbim_message_set_transaction_id (message, 1);
+
+    test_message_trace ((const guint8 *)((GByteArray *)message)->data,
+                        ((GByteArray *)message)->len,
+                        expected_message,
+                        sizeof (expected_message));
+
+    g_assert_cmpuint (mbim_message_get_transaction_id (message), ==, 1);
+    g_assert_cmpuint (mbim_message_get_message_type   (message), ==, MBIM_MESSAGE_TYPE_COMMAND);
+    g_assert_cmpuint (mbim_message_get_message_length (message), ==, sizeof (expected_message));
+
+    g_assert_cmpuint (mbim_message_command_get_service      (message), ==, MBIM_SERVICE_MS_HOSTSHUTDOWN);
+    g_assert_cmpuint (mbim_message_command_get_cid          (message), ==, MBIM_CID_MS_HOSTSHUTDOWN_HOSTSHUTDOWN);
+    g_assert_cmpuint (mbim_message_command_get_command_type (message), ==, MBIM_MESSAGE_COMMAND_TYPE_SET);
+
+    g_assert_cmpuint (((GByteArray *)message)->len, ==, sizeof (expected_message));
+    g_assert (memcmp (((GByteArray *)message)->data, expected_message, sizeof (expected_message)) == 0);
+
+    mbim_message_unref (message);
+}
+
 int main (int argc, char **argv)
 {
     g_test_init (&argc, &argv, NULL);
@@ -1316,6 +1366,7 @@ int main (int argc, char **argv)
     g_test_add_func ("/libmbim-glib/message/builder/basic-connect/ip-packet-filters/set/two", test_message_builder_basic_connect_ip_packet_filters_set_two);
     g_test_add_func ("/libmbim-glib/message/builder/dss/connect/set", test_message_builder_dss_connect_set);
     g_test_add_func ("/libmbim-glib/message/builder/basic-connect/multicarrier-providers/set", test_message_builder_basic_connect_multicarrier_providers_set);
+    g_test_add_func ("/libmbim-glib/message/builder/ms-hostshutdown/hostshutdown/set", test_message_builder_ms_hostshutdown_hostshutdown_set);
 
     return g_test_run ();
 }
diff --git a/src/libmbim-glib/test/test-uuid.c b/src/libmbim-glib/test/test-uuid.c
index 758d204..a20698f 100644
--- a/src/libmbim-glib/test/test-uuid.c
+++ b/src/libmbim-glib/test/test-uuid.c
@@ -83,18 +83,27 @@ test_uuid_ms_fwid (void)
     compare_uuid_strings (MBIM_UUID_MS_FWID,
                           "e9f7dea2-feaf-4009-93ce-90a3694103b6");
 }
+
+static void
+test_uuid_ms_hostshutdown (void)
+{
+    compare_uuid_strings (MBIM_UUID_MS_HOSTSHUTDOWN,
+                          "883b7c26-985f-43fa-9804-27d7fb80959c");
+}
+
 int main (int argc, char **argv)
 {
     g_test_init (&argc, &argv, NULL);
 
-    g_test_add_func ("/libmbim-glib/uuid/basic-connect", test_uuid_basic_connect);
-    g_test_add_func ("/libmbim-glib/uuid/sms",           test_uuid_sms);
-    g_test_add_func ("/libmbim-glib/uuid/ussd",          test_uuid_ussd);
-    g_test_add_func ("/libmbim-glib/uuid/phonebook",     test_uuid_phonebook);
-    g_test_add_func ("/libmbim-glib/uuid/stk",           test_uuid_stk);
-    g_test_add_func ("/libmbim-glib/uuid/auth",          test_uuid_auth);
-    g_test_add_func ("/libmbim-glib/uuid/dss",           test_uuid_dss);
-    g_test_add_func ("/libmbim-glib/uuid/ms-fwid",       test_uuid_ms_fwid);
+    g_test_add_func ("/libmbim-glib/uuid/basic-connect",   test_uuid_basic_connect);
+    g_test_add_func ("/libmbim-glib/uuid/sms",             test_uuid_sms);
+    g_test_add_func ("/libmbim-glib/uuid/ussd",            test_uuid_ussd);
+    g_test_add_func ("/libmbim-glib/uuid/phonebook",       test_uuid_phonebook);
+    g_test_add_func ("/libmbim-glib/uuid/stk",             test_uuid_stk);
+    g_test_add_func ("/libmbim-glib/uuid/auth",            test_uuid_auth);
+    g_test_add_func ("/libmbim-glib/uuid/dss",             test_uuid_dss);
+    g_test_add_func ("/libmbim-glib/uuid/ms-fwid",         test_uuid_ms_fwid);
+    g_test_add_func ("/libmbim-glib/uuid/ms-hostshutdown", test_uuid_ms_hostshutdown);
 
     return g_test_run ();
 }
diff --git a/src/mbimcli/mbimcli-ms-hostshutdown.c b/src/mbimcli/mbimcli-ms-hostshutdown.c
new file mode 100644
index 0000000..9d0c023
--- /dev/null
+++ b/src/mbimcli/mbimcli-ms-hostshutdown.c
@@ -0,0 +1,158 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mbimcli -- Command line interface to control MBIM devices
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2014 Google, Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <libmbim-glib.h>
+
+#include "mbimcli.h"
+
+/* Context */
+typedef struct {
+    MbimDevice *device;
+    GCancellable *cancellable;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean ms_hostshutdown_flag;
+
+static GOptionEntry entries[] = {
+    { "ms-hostshutdown", 0, 0, G_OPTION_ARG_NONE, &ms_hostshutdown_flag,
+      "Notify that host is shutting down",
+      NULL
+    },
+    { NULL }
+};
+
+GOptionGroup *
+mbimcli_ms_hostshutdown_get_option_group (void)
+{
+   GOptionGroup *group;
+
+   group = g_option_group_new ("ms-hostshutdown",
+                               "Microsoft Host Shutdown options",
+                               "Show Microsoft Host Shutdown Service options",
+                               NULL,
+                               NULL);
+   g_option_group_add_entries (group, entries);
+
+   return group;
+}
+
+gboolean
+mbimcli_ms_hostshutdown_options_enabled (void)
+{
+    static guint n_actions = 0;
+    static gboolean checked = FALSE;
+
+    if (checked)
+        return !!n_actions;
+
+    n_actions = ms_hostshutdown_flag;
+
+    if (n_actions > 1) {
+        g_printerr ("error: too many Microsoft Host Shutdown actions requested\n");
+        exit (EXIT_FAILURE);
+    }
+
+    checked = TRUE;
+    return !!n_actions;
+}
+
+static void
+context_free (Context *context)
+{
+    if (!context)
+        return;
+
+    if (context->cancellable)
+        g_object_unref (context->cancellable);
+    if (context->device)
+        g_object_unref (context->device);
+    g_slice_free (Context, context);
+}
+
+static void
+shutdown (gboolean operation_status)
+{
+    /* Cleanup context and finish async operation */
+    context_free (ctx);
+    mbimcli_async_operation_done (operation_status);
+}
+
+static void
+ms_hostshutdown_ready (MbimDevice   *device,
+                       GAsyncResult *res)
+{
+    MbimMessage *response;
+    GError *error = NULL;
+
+    response = mbim_device_command_finish (device, res, &error);
+    if (!response) {
+        g_printerr ("error: operation failed: %s\n", error->message);
+        g_error_free (error);
+        shutdown (FALSE);
+        return;
+    }
+
+    g_print ("[%s] Successfully notified that host is shutting down\n\n",
+             mbim_device_get_path_display (device));
+
+    mbim_message_unref (response);
+    shutdown (TRUE);
+}
+
+void
+mbimcli_ms_hostshutdown_run (MbimDevice   *device,
+                             GCancellable *cancellable)
+{
+    /* Initialize context */
+    ctx = g_slice_new (Context);
+    ctx->device = g_object_ref (device);
+    if (cancellable)
+        ctx->cancellable = g_object_ref (cancellable);
+
+    /* Request to notify that host is shutting down */
+    if (ms_hostshutdown_flag) {
+        MbimMessage *request;
+
+        g_debug ("Asynchronously notifying host is shutting down...");
+        request = (mbim_message_ms_hostshutdown_hostshutdown_set_new (NULL));
+        mbim_device_command (ctx->device,
+                             request,
+                             10,
+                             ctx->cancellable,
+                             (GAsyncReadyCallback)ms_hostshutdown_ready,
+                             NULL);
+        mbim_message_unref (request);
+        return;
+    }
+
+    g_warn_if_reached ();
+}
-- 
1.9.0.rc1.175.g0b1dcb5



More information about the libmbim-devel mailing list