[PATCH 2/5] ms-fwid: add support for the Microsoft Firmware ID service

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


---
 data/Makefile.am                            |  3 +-
 data/mbim-service-ms-fwid.json              | 13 ++++++++
 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                | 11 ++++++
 src/libmbim-glib/test/test-cid.c            |  9 +++++
 src/libmbim-glib/test/test-message-parser.c | 52 +++++++++++++++++++++++++++++
 src/libmbim-glib/test/test-uuid.c           |  7 ++++
 12 files changed, 155 insertions(+), 10 deletions(-)
 create mode 100644 data/mbim-service-ms-fwid.json

diff --git a/data/Makefile.am b/data/Makefile.am
index 091c2e2..e214ee0 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -7,4 +7,5 @@ EXTRA_DIST = \
 	mbim-service-auth.json \
 	mbim-service-phonebook.json \
 	mbim-service-stk.json \
-	mbim-service-dss.json
+	mbim-service-dss.json \
+	mbim-service-ms-fwid.json
diff --git a/data/mbim-service-ms-fwid.json b/data/mbim-service-ms-fwid.json
new file mode 100644
index 0000000..bdcdd4c
--- /dev/null
+++ b/data/mbim-service-ms-fwid.json
@@ -0,0 +1,13 @@
+[
+  // *********************************************************************************
+  { "type" : "Service",
+    "name" : "MS FWID" },
+
+  // *********************************************************************************
+  { "name"     : "FirmwareId",
+    "service"  : "MS FWID",
+    "type"     : "Command",
+    "query"    : [],
+    "response" : [ { "name"   : "FirmwareId",
+                     "format" : "uuid" } ] }
+]
diff --git a/src/libmbim-glib/generated/Makefile.am b/src/libmbim-glib/generated/Makefile.am
index 9db1c3e..16c71af 100644
--- a/src/libmbim-glib/generated/Makefile.am
+++ b/src/libmbim-glib/generated/Makefile.am
@@ -9,7 +9,8 @@ GENERATED_H = \
 	mbim-auth.h \
 	mbim-phonebook.h \
 	mbim-stk.h \
-	mbim-dss.h
+	mbim-dss.h \
+	mbim-ms-fwid.h
 
 GENERATED_C = \
 	mbim-error-types.c \
@@ -21,7 +22,8 @@ GENERATED_C = \
 	mbim-auth.c \
 	mbim-phonebook.c \
 	mbim-stk.c \
-	mbim-dss.c
+	mbim-dss.c \
+	mbim-ms-fwid.c
 
 GENERATED_SECTIONS = \
 	mbim-basic-connect.sections \
@@ -30,7 +32,8 @@ GENERATED_SECTIONS = \
 	mbim-auth.sections \
 	mbim-phonebook.sections \
 	mbim-stk.sections \
-	mbim-dss.sections
+	mbim-dss.sections \
+	mbim-ms-fwid.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
@@ -134,6 +137,15 @@ mbim-dss.h mbim-dss.c mbim-dss.sections: $(top_srcdir)/data/mbim-service-dss.jso
 			--input $(top_srcdir)/data/mbim-service-dss.json \
 			--output mbim-dss
 
+# Microsoft Firmware ID service
+mbim-ms-fwid.h mbim-ms-fwid.c mbim-ms-fwid.sections: $(top_srcdir)/data/mbim-service-ms-fwid.json $(top_srcdir)/build-aux/mbim-codegen/*.py $(top_srcdir)/build-aux/mbim-codegen/mbim-codegen
+	$(AM_V_GEN)  \
+		rm -f mbim-ms-fwid.h && \
+		rm -f mbim-ms-fwid.c && \
+		$(top_srcdir)/build-aux/mbim-codegen/mbim-codegen \
+			--input $(top_srcdir)/data/mbim-service-ms-fwid.json \
+			--output mbim-ms-fwid
+
 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 05cd71c..a7f0962 100644
--- a/src/libmbim-glib/libmbim-glib.h
+++ b/src/libmbim-glib/libmbim-glib.h
@@ -45,5 +45,6 @@
 #include "mbim-phonebook.h"
 #include "mbim-stk.h"
 #include "mbim-dss.h"
+#include "mbim-ms-fwid.h"
 
 #endif /* _LIBMBIM_GLIB_H_ */
diff --git a/src/libmbim-glib/mbim-cid.c b/src/libmbim-glib/mbim-cid.c
index de86c93..715eb66 100644
--- a/src/libmbim-glib/mbim-cid.c
+++ b/src/libmbim-glib/mbim-cid.c
@@ -113,6 +113,12 @@ static const CidConfig cid_dss_config [MBIM_CID_DSS_LAST] = {
     { TRUE,  FALSE, FALSE }, /* MBIM_CID_DSS_CONNECT */
 };
 
+/* Note: index of the array is CID-1 */
+#define MBIM_CID_MS_FWID_LAST MBIM_CID_MS_FWID_FIRMWAREID
+static const CidConfig cid_ms_fwid_config [MBIM_CID_MS_FWID_LAST] = {
+    { FALSE, TRUE,  FALSE }, /* MBIM_CID_MS_FWID_FIRMWAREID */
+};
+
 /**
  * mbim_cid_can_set:
  * @service: a #MbimService.
@@ -130,7 +136,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_DSS, FALSE);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, FALSE);
 
     switch (service) {
     case MBIM_SERVICE_BASIC_CONNECT:
@@ -147,6 +153,8 @@ mbim_cid_can_set (MbimService service,
         return cid_auth_config[cid - 1].set;
     case MBIM_SERVICE_DSS:
         return cid_dss_config[cid - 1].set;
+    case MBIM_SERVICE_MS_FWID:
+        return cid_ms_fwid_config[cid - 1].set;
     default:
         g_assert_not_reached ();
         return FALSE;
@@ -170,7 +178,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_DSS, FALSE);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, FALSE);
 
     switch (service) {
     case MBIM_SERVICE_BASIC_CONNECT:
@@ -187,6 +195,8 @@ mbim_cid_can_query (MbimService service,
         return cid_auth_config[cid - 1].query;
     case MBIM_SERVICE_DSS:
         return cid_dss_config[cid - 1].query;
+    case MBIM_SERVICE_MS_FWID:
+        return cid_ms_fwid_config[cid - 1].query;
     default:
         g_assert_not_reached ();
         return FALSE;
@@ -210,7 +220,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_DSS, FALSE);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, FALSE);
 
     switch (service) {
     case MBIM_SERVICE_BASIC_CONNECT:
@@ -227,6 +237,8 @@ mbim_cid_can_notify (MbimService service,
         return cid_auth_config[cid - 1].notify;
     case MBIM_SERVICE_DSS:
         return cid_dss_config[cid - 1].notify;
+    case MBIM_SERVICE_MS_FWID:
+        return cid_ms_fwid_config[cid - 1].notify;
     default:
         g_assert_not_reached ();
         return FALSE;
@@ -251,7 +263,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_DSS, NULL);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, NULL);
 
     switch (service) {
     case MBIM_SERVICE_BASIC_CONNECT:
@@ -268,6 +280,8 @@ mbim_cid_get_printable (MbimService service,
         return mbim_cid_auth_get_string (cid);
     case MBIM_SERVICE_DSS:
         return mbim_cid_dss_get_string (cid);
+    case MBIM_SERVICE_MS_FWID:
+        return mbim_cid_ms_fwid_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 031baa0..a360d55 100644
--- a/src/libmbim-glib/mbim-cid.h
+++ b/src/libmbim-glib/mbim-cid.h
@@ -183,6 +183,18 @@ typedef enum {
     MBIM_CID_DSS_CONNECT = 1
 } MbimCidDss;
 
+/**
+ * MbimCidMsFwid:
+ * @MBIM_CID_MS_FWID_UNKNOWN: Unknown command.
+ * @MBIM_CID_MS_FWID_FIRMWAREID: Firmware ID.
+ *
+ * MBIM commands in the %MBIM_SERVICE_MS_FWID service.
+ */
+typedef enum {
+    MBIM_CID_MS_FWID_UNKNOWN    = 0,
+    MBIM_CID_MS_FWID_FIRMWAREID = 1
+} MbimCidMsFwid;
+
 /* 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 deb2c52..f2f8c64 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_DSS, FALSE);
+    g_return_val_if_fail (service <= MBIM_SERVICE_MS_FWID, 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 f25cf2f..a993ec2 100644
--- a/src/libmbim-glib/mbim-uuid.c
+++ b/src/libmbim-glib/mbim-uuid.c
@@ -143,6 +143,14 @@ static const MbimUuid uuid_dss = {
     .e = { 0x6e, 0x0d, 0x58, 0x3c, 0x4d, 0x0e }
 };
 
+static const MbimUuid uuid_ms_fwid = {
+    .a = { 0xe9, 0xf7, 0xde, 0xa2 },
+    .b = { 0xfe, 0xaf },
+    .c = { 0x40, 0x09 },
+    .d = { 0x93, 0xce },
+    .e = { 0x90, 0xa3, 0x69, 0x41, 0x03, 0xb6 }
+};
+
 /**
  * mbim_uuid_from_service:
  * @service: a #MbimService.
@@ -154,7 +162,7 @@ static const MbimUuid uuid_dss = {
 const MbimUuid *
 mbim_uuid_from_service (MbimService service)
 {
-    g_return_val_if_fail (service >= MBIM_SERVICE_INVALID && service <= MBIM_SERVICE_DSS,
+    g_return_val_if_fail (service >= MBIM_SERVICE_INVALID && service <= MBIM_SERVICE_MS_FWID,
                           &uuid_invalid);
 
     switch (service) {
@@ -174,6 +182,8 @@ mbim_uuid_from_service (MbimService service)
         return &uuid_auth;
     case MBIM_SERVICE_DSS:
         return &uuid_dss;
+    case MBIM_SERVICE_MS_FWID:
+        return &uuid_ms_fwid;
     default:
         g_assert_not_reached ();
     }
@@ -211,6 +221,9 @@ mbim_uuid_to_service (const MbimUuid *uuid)
     if (mbim_uuid_cmp (uuid, &uuid_dss))
         return MBIM_SERVICE_DSS;
 
+    if (mbim_uuid_cmp (uuid, &uuid_ms_fwid))
+        return MBIM_SERVICE_MS_FWID;
+
     return MBIM_SERVICE_INVALID;
 }
 
diff --git a/src/libmbim-glib/mbim-uuid.h b/src/libmbim-glib/mbim-uuid.h
index 0676861..04bb371 100644
--- a/src/libmbim-glib/mbim-uuid.h
+++ b/src/libmbim-glib/mbim-uuid.h
@@ -66,6 +66,7 @@ gchar    *mbim_uuid_get_printable (const MbimUuid *uuid);
  * @MBIM_SERVICE_STK: SIM toolkit service.
  * @MBIM_SERVICE_AUTH: Authentication service.
  * @MBIM_SERVICE_DSS: Device Service Stream service.
+ * @MBIM_SERVICE_MS_FWID: Microsoft Firmware ID service.
  *
  * Enumeration of the generic MBIM services.
  */
@@ -78,6 +79,7 @@ typedef enum {
     MBIM_SERVICE_STK           = 5,
     MBIM_SERVICE_AUTH          = 6,
     MBIM_SERVICE_DSS           = 7,
+    MBIM_SERVICE_MS_FWID       = 8,
 } MbimService;
 
 /**
@@ -152,6 +154,15 @@ typedef enum {
  */
 #define MBIM_UUID_DSS mbim_uuid_from_service (MBIM_SERVICE_DSS)
 
+/**
+ * MBIM_UUID_MS_FWID:
+ *
+ * Get the UUID of the %MBIM_SERVICE_MS_FWID service.
+ *
+ * Returns: (transfer none): a #MbimUuid.
+ */
+#define MBIM_UUID_MS_FWID mbim_uuid_from_service (MBIM_SERVICE_MS_FWID)
+
 /* 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 ffb6837..2c9c0d2 100644
--- a/src/libmbim-glib/test/test-cid.c
+++ b/src/libmbim-glib/test/test-cid.c
@@ -105,6 +105,14 @@ test_cid_dss (void)
                  TRUE, FALSE, FALSE);
 }
 
+static void
+test_cid_ms_fwid (void)
+{
+    test_common (MBIM_SERVICE_MS_FWID,
+                 MBIM_CID_MS_FWID_FIRMWAREID,
+                 FALSE, TRUE, FALSE);
+}
+
 int main (int argc, char **argv)
 {
     g_test_init (&argc, &argv, NULL);
@@ -116,6 +124,7 @@ int main (int argc, char **argv)
     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);
 
     return g_test_run ();
 }
diff --git a/src/libmbim-glib/test/test-message-parser.c b/src/libmbim-glib/test/test-message-parser.c
index 1f33805..6008622 100644
--- a/src/libmbim-glib/test/test-message-parser.c
+++ b/src/libmbim-glib/test/test-message-parser.c
@@ -21,6 +21,7 @@
 #include "mbim-ussd.h"
 #include "mbim-auth.h"
 #include "mbim-stk.h"
+#include "mbim-ms-fwid.h"
 #include "mbim-message.h"
 #include "mbim-cid.h"
 #include "mbim-utils.h"
@@ -1561,6 +1562,56 @@ test_message_parser_basic_connect_ip_packet_filters_two (void)
     mbim_message_unref (response);
 }
 
+static void
+test_message_parser_ms_fwid_firmwareid (void)
+{
+    const MbimUuid *firmware_id;
+    MbimMessage *response;
+    GError *error = NULL;
+    const guint8 buffer [] = {
+        /* header */
+        0x03, 0x00, 0x00, 0x80, /* type */
+        0x40, 0x00, 0x00, 0x00, /* length */
+        0x02, 0x00, 0x00, 0x00, /* transaction id */
+        /* fragment header */
+        0x01, 0x00, 0x00, 0x00, /* total */
+        0x00, 0x00, 0x00, 0x00, /* current */
+        /* command_done_message */
+        0xE9, 0xF7, 0xDE, 0xA2, /* service id */
+        0xFE, 0xAF, 0x40, 0x09,
+        0x93, 0xCE, 0x90, 0xA3,
+        0x69, 0x41, 0x03, 0xB6,
+        0x01, 0x00, 0x00, 0x00, /* command id */
+        0x00, 0x00, 0x00, 0x00, /* status code */
+        0x10, 0x00, 0x00, 0x00, /* buffer length */
+        /* information buffer */
+        0x00, 0x11, 0x22, 0x33, /* firmware id */
+        0x44, 0x55, 0x66, 0x77,
+        0x88, 0x99, 0xAA, 0xBB,
+        0xCC, 0xDD, 0xEE, 0xFF  };
+
+    const MbimUuid expected_firmware_id = {
+        .a = { 0x00, 0x11, 0x22, 0x33 },
+        .b = { 0x44, 0x55 },
+        .c = { 0x66, 0x77 },
+        .d = { 0x88, 0x99 },
+        .e = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }
+    };
+
+    response = mbim_message_new (buffer, sizeof (buffer));
+
+    g_assert (mbim_message_ms_fwid_firmwareid_response_parse (
+                  response,
+                  &firmware_id,
+                  &error));
+
+    g_assert_no_error (error);
+
+    g_assert (mbim_uuid_cmp (firmware_id, &expected_firmware_id));
+
+    mbim_message_unref (response);
+}
+
 int main (int argc, char **argv)
 {
     g_test_init (&argc, &argv, NULL);
@@ -1582,6 +1633,7 @@ int main (int argc, char **argv)
     g_test_add_func ("/libmbim-glib/message/parser/basic-connect/ip-packet-filters/none", test_message_parser_basic_connect_ip_packet_filters_none);
     g_test_add_func ("/libmbim-glib/message/parser/basic-connect/ip-packet-filters/one", test_message_parser_basic_connect_ip_packet_filters_one);
     g_test_add_func ("/libmbim-glib/message/parser/basic-connect/ip-packet-filters/two", test_message_parser_basic_connect_ip_packet_filters_two);
+    g_test_add_func ("/libmbim-glib/message/parser/ms-fwid/firmwareid", test_message_parser_ms_fwid_firmwareid);
 
     return g_test_run ();
 }
diff --git a/src/libmbim-glib/test/test-uuid.c b/src/libmbim-glib/test/test-uuid.c
index 010b0e9..758d204 100644
--- a/src/libmbim-glib/test/test-uuid.c
+++ b/src/libmbim-glib/test/test-uuid.c
@@ -77,6 +77,12 @@ test_uuid_dss (void)
                           "c08a26dd-7718-4382-8482-6e0d583c4d0e");
 }
 
+static void
+test_uuid_ms_fwid (void)
+{
+    compare_uuid_strings (MBIM_UUID_MS_FWID,
+                          "e9f7dea2-feaf-4009-93ce-90a3694103b6");
+}
 int main (int argc, char **argv)
 {
     g_test_init (&argc, &argv, NULL);
@@ -88,6 +94,7 @@ int main (int argc, char **argv)
     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);
 
     return g_test_run ();
 }
-- 
1.9.0.rc1.175.g0b1dcb5



More information about the libmbim-devel mailing list