uqmi.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_H
  22. #define __UQMI_H
  23. #include <stdbool.h>
  24. #include <libubox/uloop.h>
  25. #include <libubox/ustream.h>
  26. #include "qmi-message.h"
  27. #ifdef DEBUG_PACKET
  28. void dump_packet(const char *prefix, void *ptr, int len);
  29. #else
  30. static inline void dump_packet(const char *prefix, void *ptr, int len)
  31. {
  32. }
  33. #endif
  34. #define __qmi_services \
  35. __qmi_service(QMI_SERVICE_WDS), \
  36. __qmi_service(QMI_SERVICE_DMS), \
  37. __qmi_service(QMI_SERVICE_NAS), \
  38. __qmi_service(QMI_SERVICE_QOS), \
  39. __qmi_service(QMI_SERVICE_WMS), \
  40. __qmi_service(QMI_SERVICE_PDS), \
  41. __qmi_service(QMI_SERVICE_AUTH), \
  42. __qmi_service(QMI_SERVICE_AT), \
  43. __qmi_service(QMI_SERVICE_VOICE), \
  44. __qmi_service(QMI_SERVICE_CAT2), \
  45. __qmi_service(QMI_SERVICE_UIM), \
  46. __qmi_service(QMI_SERVICE_PBM), \
  47. __qmi_service(QMI_SERVICE_LOC), \
  48. __qmi_service(QMI_SERVICE_SAR), \
  49. __qmi_service(QMI_SERVICE_RMTFS), \
  50. __qmi_service(QMI_SERVICE_CAT), \
  51. __qmi_service(QMI_SERVICE_RMS), \
  52. __qmi_service(QMI_SERVICE_OMA), \
  53. __qmi_service(QMI_SERVICE_WDA)
  54. #define __qmi_service(_n) __##_n
  55. enum {
  56. __qmi_services,
  57. __QMI_SERVICE_LAST
  58. };
  59. #undef __qmi_service
  60. struct qmi_dev;
  61. struct qmi_request;
  62. struct qmi_msg;
  63. typedef void (*request_cb)(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg);
  64. struct qmi_dev {
  65. struct ustream_fd sf;
  66. struct list_head req;
  67. struct {
  68. bool connected;
  69. uint8_t client_id;
  70. uint16_t tid;
  71. } service_data[__QMI_SERVICE_LAST];
  72. uint32_t service_connected;
  73. uint32_t service_keep_cid;
  74. uint32_t service_release_cid;
  75. uint8_t ctl_tid;
  76. void *buf;
  77. bool is_mbim;
  78. };
  79. struct qmi_request {
  80. struct list_head list;
  81. request_cb cb;
  82. bool *complete;
  83. bool pending;
  84. bool no_error_cb;
  85. uint8_t service;
  86. uint16_t tid;
  87. int ret;
  88. };
  89. extern bool cancel_all_requests;
  90. int qmi_device_open(struct qmi_dev *qmi, const char *path);
  91. void qmi_device_close(struct qmi_dev *qmi);
  92. int qmi_request_start(struct qmi_dev *qmi, struct qmi_request *req, request_cb cb);
  93. void qmi_request_cancel(struct qmi_dev *qmi, struct qmi_request *req);
  94. int qmi_request_wait(struct qmi_dev *qmi, struct qmi_request *req);
  95. static inline bool qmi_request_pending(struct qmi_request *req)
  96. {
  97. return req->pending;
  98. }
  99. int qmi_service_connect(struct qmi_dev *qmi, QmiService svc, int client_id);
  100. int qmi_service_get_client_id(struct qmi_dev *qmi, QmiService svc);
  101. int qmi_service_release_client_id(struct qmi_dev *qmi, QmiService svc);
  102. QmiService qmi_service_get_by_name(const char *str);
  103. const char *qmi_get_error_str(int code);
  104. #endif