mbim.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (C) 2016 Bjørn Mork <bjorn@mork.no>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301 USA.
  18. */
  19. #include <stdbool.h>
  20. #include <stdint.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include "mbim.h"
  24. static const uint8_t qmiuuid[16] = { 0xd1, 0xa3, 0x0b, 0xc2, 0xf9, 0x7a, 0x6e, 0x43,
  25. 0xbf, 0x65, 0xc7, 0xe2, 0x4f, 0xb0, 0xf0, 0xd3 };
  26. bool is_mbim_qmi(struct mbim_command_message *msg)
  27. {
  28. return msg->header.type == cpu_to_le32(MBIM_MESSAGE_TYPE_COMMAND_DONE) &&
  29. msg->command_id == cpu_to_le32(MBIM_CID_QMI_MSG) &&
  30. !msg->command_type && /* actually 'status' here */
  31. !memcmp(msg->service_id, qmiuuid, 16);
  32. }
  33. void mbim_qmi_cmd(struct mbim_command_message *msg, int len, uint16_t tid)
  34. {
  35. msg->header.type = cpu_to_le32(MBIM_MESSAGE_TYPE_COMMAND);
  36. msg->header.length = cpu_to_le32(sizeof(*msg) + len);
  37. msg->header.transaction_id = cpu_to_le32(tid);
  38. msg->fragment_header.total = cpu_to_le32(1);
  39. msg->fragment_header.current = 0;
  40. memcpy(msg->service_id, qmiuuid, 16);
  41. msg->command_id = cpu_to_le32(MBIM_CID_QMI_MSG);
  42. msg->command_type = cpu_to_le32(MBIM_MESSAGE_COMMAND_TYPE_SET);
  43. msg->buffer_length = cpu_to_le32(len);
  44. }