summaryrefslogtreecommitdiff
path: root/mbim.c
diff options
context:
space:
mode:
Diffstat (limited to 'mbim.c')
-rw-r--r--mbim.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/mbim.c b/mbim.c
new file mode 100644
index 0000000..861554c
--- /dev/null
+++ b/mbim.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 Bjørn Mork <bjorn@mork.no>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include <endian.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <stdio.h>
+
+#include "mbim.h"
+
+static const uint8_t qmiuuid[16] = { 0xd1, 0xa3, 0x0b, 0xc2, 0xf9, 0x7a, 0x6e, 0x43,
+ 0xbf, 0x65, 0xc7, 0xe2, 0x4f, 0xb0, 0xf0, 0xd3 };
+
+bool is_mbim_qmi(struct mbim_command_message *msg)
+{
+ return msg->header.type == htole32(MBIM_MESSAGE_TYPE_COMMAND_DONE) &&
+ msg->command_id == htole32(MBIM_CID_QMI_MSG) &&
+ !msg->command_type && /* actually 'status' here */
+ !memcmp(msg->service_id, qmiuuid, 16);
+ }
+
+void mbim_qmi_cmd(struct mbim_command_message *msg, int len, uint16_t tid)
+{
+ msg->header.type = htole32(MBIM_MESSAGE_TYPE_COMMAND);
+ msg->header.length = sizeof(*msg) + len;
+ msg->header.transaction_id = htole32(tid);
+ msg->fragment_header.total = 1;
+ msg->fragment_header.current = 0;
+ memcpy(msg->service_id, qmiuuid, 16);
+ msg->command_id = htole32(MBIM_CID_QMI_MSG);
+ msg->command_type = htole32(MBIM_MESSAGE_COMMAND_TYPE_SET);
+ msg->buffer_length = len;
+}