suppress error callbacks if requested
[project/uqmi.git] / uqmi.h
1 #ifndef __UQMI_H
2 #define __UQMI_H
3
4 #include <libubox/uloop.h>
5 #include <libubox/ustream.h>
6 #include "qmi-message.h"
7
8 #ifdef DEBUG_PACKET
9 void dump_packet(const char *prefix, void *ptr, int len);
10 #else
11 static inline void dump_packet(const char *prefix, void *ptr, int len)
12 {
13 }
14 #endif
15
16 #define __qmi_services \
17 __qmi_service(QMI_SERVICE_WDS), \
18 __qmi_service(QMI_SERVICE_DMS), \
19 __qmi_service(QMI_SERVICE_NAS), \
20 __qmi_service(QMI_SERVICE_QOS), \
21 __qmi_service(QMI_SERVICE_WMS), \
22 __qmi_service(QMI_SERVICE_PDS), \
23 __qmi_service(QMI_SERVICE_AUTH), \
24 __qmi_service(QMI_SERVICE_AT), \
25 __qmi_service(QMI_SERVICE_VOICE), \
26 __qmi_service(QMI_SERVICE_CAT2), \
27 __qmi_service(QMI_SERVICE_UIM), \
28 __qmi_service(QMI_SERVICE_PBM), \
29 __qmi_service(QMI_SERVICE_LOC), \
30 __qmi_service(QMI_SERVICE_SAR), \
31 __qmi_service(QMI_SERVICE_RMTFS), \
32 __qmi_service(QMI_SERVICE_CAT), \
33 __qmi_service(QMI_SERVICE_RMS), \
34 __qmi_service(QMI_SERVICE_OMA)
35
36 #define __qmi_service(_n) __##_n
37 enum {
38 __qmi_services,
39 __QMI_SERVICE_LAST
40 };
41 #undef __qmi_service
42
43 struct qmi_dev;
44 struct qmi_request;
45 struct qmi_msg;
46
47 typedef void (*request_cb)(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg);
48
49 struct qmi_dev {
50 struct ustream_fd sf;
51
52 struct list_head req;
53
54 struct {
55 bool connected;
56 uint8_t client_id;
57 uint16_t tid;
58 } service_data[__QMI_SERVICE_LAST];
59
60 uint32_t service_connected;
61 uint32_t service_keep_cid;
62
63 uint8_t ctl_tid;
64 };
65
66 struct qmi_request {
67 struct list_head list;
68
69 request_cb cb;
70
71 bool *complete;
72 bool pending;
73 bool no_error_cb;
74 uint8_t service;
75 uint16_t tid;
76 int ret;
77 };
78
79 int qmi_device_open(struct qmi_dev *qmi, const char *path);
80 void qmi_device_close(struct qmi_dev *qmi);
81
82 int qmi_request_start(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, request_cb cb);
83 void qmi_request_cancel(struct qmi_dev *qmi, struct qmi_request *req);
84 int qmi_request_wait(struct qmi_dev *qmi, struct qmi_request *req);
85
86 static inline bool qmi_request_pending(struct qmi_request *req)
87 {
88 return req->pending;
89 }
90
91 int qmi_service_connect(struct qmi_dev *qmi, QmiService svc, int client_id);
92 int qmi_service_get_client_id(struct qmi_dev *qmi, QmiService svc);
93 QmiService qmi_service_get_by_name(const char *str);
94
95 #endif