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