mbim-msg.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * umbim
  3. * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation
  8. *
  9. * This program 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
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef _MBIM_MSG_H__
  15. #define _MBIM_MSG_H__
  16. #include <string.h>
  17. struct mbim_message_header {
  18. uint32_t type;
  19. uint32_t length;
  20. uint32_t transaction_id;
  21. } __attribute__((packed));
  22. struct mbim_open_message {
  23. struct mbim_message_header header;
  24. uint32_t max_control_transfer;
  25. } __attribute__((packed));
  26. struct mbim_open_done_message {
  27. struct mbim_message_header header;
  28. uint32_t status_code;
  29. } __attribute__((packed));
  30. struct mbim_close_done_message {
  31. uint32_t status_code;
  32. } __attribute__((packed));
  33. struct mbim_error_message {
  34. uint32_t error_status_code;
  35. } __attribute__((packed));
  36. struct mbim_fragment_header {
  37. uint32_t total;
  38. uint32_t current;
  39. } __attribute__((packed));
  40. struct fragment_message {
  41. struct mbim_fragment_header fragment_header;
  42. uint8_t buffer[];
  43. } __attribute__((packed));
  44. struct command_message {
  45. struct mbim_message_header header;
  46. struct mbim_fragment_header fragment_header;
  47. uint8_t service_id[16];
  48. uint32_t command_id;
  49. uint32_t command_type;
  50. uint32_t buffer_length;
  51. uint8_t buffer[];
  52. } __attribute__((packed));
  53. struct command_done_message {
  54. struct mbim_fragment_header fragment_header;
  55. uint8_t service_id[16];
  56. uint32_t command_id;
  57. uint32_t status_code;
  58. uint32_t buffer_length;
  59. uint8_t buffer[];
  60. } __attribute__((packed));
  61. struct indicate_status_message {
  62. struct mbim_fragment_header fragment_header;
  63. uint8_t service_id[16];
  64. uint32_t command_id;
  65. uint32_t buffer_length;
  66. uint8_t buffer[];
  67. } __attribute__((packed));
  68. typedef int (*_mbim_cmd_request)(void);
  69. typedef int (*_mbim_cmd_response)(void *buffer, size_t len);
  70. extern uint8_t basic_connect[16];
  71. extern int transaction_id;
  72. const char* mbim_enum_string(struct mbim_enum *e, uint32_t key);
  73. char* mbim_get_string(struct mbim_string *str, char *in);
  74. void mbim_setup_header(struct mbim_message_header *hdr, MbimMessageType type, int length);
  75. uint8_t* mbim_setup_command_msg(uint8_t *uuid, uint32_t type, uint32_t command_id, int len);
  76. int mbim_send_open_msg(void);
  77. int mbim_send_close_msg(void);
  78. int mbim_send_command_msg(void);
  79. int mbim_add_payload(uint8_t len);
  80. int mbim_encode_string(struct mbim_string *str, char *in);
  81. void mbim_get_ipv4(void *buffer, char *out, uint32_t offset);
  82. void mbim_get_ipv6(void *buffer, char *out, uint32_t offset);
  83. uint32_t mbim_get_int(void *buffer, uint32_t offset);
  84. #endif