qmi-message.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * uqmi -- tiny QMI support implementation
  3. *
  4. * Copyright (C) 2014-2015 Felix Fietkau <nbd@openwrt.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301 USA.
  20. */
  21. #ifndef __UQMI_MESSAGE_H
  22. #define __UQMI_MESSAGE_H
  23. #include <libubox/utils.h>
  24. #include <stdbool.h>
  25. #include "qmi-struct.h"
  26. #include "qmi-enums.h"
  27. #include "qmi-enums-private.h"
  28. #include "qmi-message-ctl.h"
  29. #include "qmi-enums-dms.h"
  30. #include "qmi-flags64-dms.h"
  31. #include "qmi-message-dms.h"
  32. #include "qmi-enums-nas.h"
  33. #include "qmi-flags64-nas.h"
  34. #include "qmi-message-nas.h"
  35. #include "qmi-enums-pds.h"
  36. #include "qmi-message-pds.h"
  37. #include "qmi-enums-wds.h"
  38. #include "qmi-message-wds.h"
  39. #include "qmi-enums-wms.h"
  40. #include "qmi-message-wms.h"
  41. #include "qmi-enums-wda.h"
  42. #include "qmi-message-wda.h"
  43. #include "qmi-enums-uim.h"
  44. #include "qmi-message-uim.h"
  45. #define qmi_set(_data, _field, _val) \
  46. do { \
  47. (_data)->set._field = 1; \
  48. (_data)->data._field = _val; \
  49. } while (0)
  50. #define qmi_set_ptr(_data, _field, _val) \
  51. do { \
  52. (_data)->data._field = _val; \
  53. } while (0)
  54. #define qmi_set_static_array(_data, _field, _val) \
  55. do { \
  56. (_data)->data._field##_n = ARRAY_SIZE(_val); \
  57. (_data)->data._field = _val; \
  58. } while (0);
  59. #define qmi_set_array(_data, _field, _val, _n) \
  60. do { \
  61. (_data)->data.n_##_field = _n; \
  62. (_data)->data._field = _val; \
  63. } while (0);
  64. #define QMI_INIT(_field, _val) \
  65. .set._field = 1, \
  66. .data._field = (_val)
  67. #define QMI_INIT_SEQUENCE(_field, ...) \
  68. .set._field = 1, \
  69. .data._field = { __VA_ARGS__ }
  70. #define QMI_INIT_PTR(_field, _val) \
  71. .data._field = (_val)
  72. #define QMI_INIT_STATIC_ARRAY(_field, _val) \
  73. .data._field##_n = ARRAY_SIZE(_val), \
  74. .data._field = (_val)
  75. #define QMI_INIT_ARRAY(_field, _val, _n) \
  76. .data._field##_n = (_n), \
  77. .data._field = (_val)
  78. enum {
  79. QMI_ERROR_NO_DATA = -1,
  80. QMI_ERROR_INVALID_DATA = -2,
  81. QMI_ERROR_CANCELLED = -3,
  82. };
  83. #define QMI_BUFFER_LEN 2048
  84. void __qmi_alloc_reset(void);
  85. void *__qmi_alloc_static(unsigned int len);
  86. char *__qmi_copy_string(void *data, unsigned int len);
  87. uint8_t *__qmi_get_buf(unsigned int *ofs);
  88. static inline int tlv_data_len(struct tlv *tlv)
  89. {
  90. return le16_to_cpu(tlv->len);
  91. }
  92. struct tlv *tlv_get_next(void **buf, unsigned int *buflen);
  93. void tlv_new(struct qmi_msg *qm, uint8_t type, uint16_t len, void *data);
  94. void qmi_init_request_message(struct qmi_msg *qm, QmiService service);
  95. int qmi_complete_request_message(struct qmi_msg *qm);
  96. int qmi_check_message_status(void *buf, unsigned int len);
  97. void *qmi_msg_get_tlv_buf(struct qmi_msg *qm, int *len);
  98. #endif