summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2017-09-19 21:18:26 -0500
committerDenis Kenzior <denkenz@gmail.com>2017-10-05 11:08:38 -0500
commit2d4093ae279f8eb3bec23d0fdf726d5363b43a4e (patch)
treeb3aa70f86e5e61ea5b6694530eb83547949588f1
parent1bfa2749cd1f0c361a33c48770dea581b254d22b (diff)
downloadofono-2d4093ae279f8eb3bec23d0fdf726d5363b43a4e.tar.gz
mbim: Add MBIM descriptor utilities
Used to find MBIM Functional and MBIM Extended Functional descriptors
-rw-r--r--Makefile.am4
-rw-r--r--drivers/mbimmodem/mbim-desc.c80
-rw-r--r--drivers/mbimmodem/mbim-desc.h49
3 files changed, 132 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 2b48724c..07b8ee02 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -608,7 +608,9 @@ builtin_libadd += @ELL_LIBS@
if MBIMMODEM
mbim_sources = drivers/mbimmodem/mbim.h \
- drivers/mbimmodem/mbim.c
+ drivers/mbimmodem/mbim.c \
+ drivers/mbimmodem/mbim-desc.h \
+ drivers/mbimmodem/mbim-desc.c
builtin_modules += mbimmodem
builtin_sources += $(mbim_sources) \
diff --git a/drivers/mbimmodem/mbim-desc.c b/drivers/mbimmodem/mbim-desc.c
new file mode 100644
index 00000000..7e4bcba2
--- /dev/null
+++ b/drivers/mbimmodem/mbim-desc.c
@@ -0,0 +1,80 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stddef.h>
+
+#include "mbim-desc.h"
+
+/*
+ * Attempts to find MBIM specific descriptors.
+ *
+ * Returns true if the MBIM Function descriptor was found, false otherwise.
+ */
+bool mbim_find_descriptors(const uint8_t *data, size_t data_len,
+ const struct mbim_desc **out_desc,
+ const struct mbim_extended_desc **out_ext_desc)
+{
+ bool r = false;
+
+ while (data_len > 3) {
+ uint8_t len = data[0];
+
+ if (data[1] != 0x24)
+ goto next;
+
+ /* MBIM v1.0, Table 4-3 */
+ switch (data[2]) {
+ case 0x1b:
+ if (!out_desc)
+ break;
+
+ if (len != sizeof(struct mbim_desc) || data_len < len)
+ break;
+
+ *out_desc = (const struct mbim_desc *) data;
+ r = true;
+ break;
+ case 0x1c:
+ if (!out_ext_desc)
+ break;
+
+ if (len != sizeof(struct mbim_extended_desc) ||
+ data_len < len)
+ break;
+
+ *out_ext_desc =
+ (const struct mbim_extended_desc *) data;
+ break;
+ }
+
+next:
+ data_len -= len;
+ data += len;
+ }
+
+ return r;
+}
diff --git a/drivers/mbimmodem/mbim-desc.h b/drivers/mbimmodem/mbim-desc.h
new file mode 100644
index 00000000..4a7d9260
--- /dev/null
+++ b/drivers/mbimmodem/mbim-desc.h
@@ -0,0 +1,49 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <linux/types.h>
+
+/* MBIM v1.0, Section 6.4: MBIM Functional Descriptor */
+struct mbim_desc {
+ uint8_t bFunctionLength;
+ uint8_t bDescriptorType;
+ uint8_t bDescriptorSubtype;
+ __le16 bcdMBIMVersion;
+ __le16 wMaxControlMessage;
+ uint8_t bNumberFilters;
+ uint8_t bMaxFilterSize;
+ __le16 wMaxSegmentSize;
+ uint8_t bmNetworkCapabilities;
+} __attribute__ ((packed));
+
+/* MBIM v1.0, Section 6.5: MBIM Extended Functional Descriptor */
+struct mbim_extended_desc {
+ uint8_t bFunctionLength;
+ uint8_t bDescriptorType;
+ uint8_t bDescriptorSubtype;
+ __le16 bcdMBIMExtendedVersion;
+ uint8_t bMaxOutstandingCommandMessages;
+ __le16 wMTU;
+} __attribute__ ((packed));
+
+bool mbim_find_descriptors(const uint8_t *data, size_t data_len,
+ const struct mbim_desc **out_desc,
+ const struct mbim_extended_desc **out_ext_desc);