add command_id to verbose output
[project/umbim.git] / mbim-dev.c
index e5d90f9f270ad1f7f856a80b76b293632bf2e538..d986cbe775b00468faabff21f32f4b3a59f27e96 100644 (file)
@@ -1,3 +1,17 @@
+/*
+ * umbim
+ * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
+ *
+ * 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.
+ */
+
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -62,7 +76,7 @@ mbim_recv(struct uloop_fd *u, unsigned int events)
 {
        ssize_t cnt = read(u->fd, mbim_buffer, MBIM_BUFFER_SIZE);
        struct mbim_message_header *hdr = (struct mbim_message_header *) mbim_buffer;
-       struct command_message *msg = (struct command_message *) mbim_buffer;
+       struct command_done_message *msg = (struct command_done_message *) (hdr + 1);
        int i;
 
        if (cnt < 0)
@@ -91,7 +105,14 @@ mbim_recv(struct uloop_fd *u, unsigned int events)
                        mbim_send_close_msg();
                break;
        case MBIM_MESSAGE_TYPE_COMMAND_DONE:
-               return_code = current_handler->response(msg->buffer, le32toh(msg->buffer_length));
+               if (verbose) {
+                       printf("  command_id: %04X\n", le32toh(msg->command_id));
+                       printf("  status_code: %04X\n", le32toh(msg->status_code));
+               }
+               if (msg->status_code && !msg->buffer_length)
+                       return_code = -le32toh(msg->status_code);
+               else
+                       return_code = current_handler->response(msg->buffer, le32toh(msg->buffer_length));
                if (return_code < 0)
                        no_close = 0;
                mbim_send_close_msg();