1
2
3
4
5
6#ifndef __QMI_HELPERS_H__
7#define __QMI_HELPERS_H__
8
9#include <linux/completion.h>
10#include <linux/idr.h>
11#include <linux/list.h>
12#include <linux/qrtr.h>
13#include <linux/types.h>
14#include <linux/workqueue.h>
15
16struct socket;
17
18
19
20
21
22
23
24
25struct qmi_header {
26 u8 type;
27 u16 txn_id;
28 u16 msg_id;
29 u16 msg_len;
30} __packed;
31
32#define QMI_REQUEST 0
33#define QMI_RESPONSE 2
34#define QMI_INDICATION 4
35
36#define QMI_COMMON_TLV_TYPE 0
37
38enum qmi_elem_type {
39 QMI_EOTI,
40 QMI_OPT_FLAG,
41 QMI_DATA_LEN,
42 QMI_UNSIGNED_1_BYTE,
43 QMI_UNSIGNED_2_BYTE,
44 QMI_UNSIGNED_4_BYTE,
45 QMI_UNSIGNED_8_BYTE,
46 QMI_SIGNED_2_BYTE_ENUM,
47 QMI_SIGNED_4_BYTE_ENUM,
48 QMI_STRUCT,
49 QMI_STRING,
50};
51
52enum qmi_array_type {
53 NO_ARRAY,
54 STATIC_ARRAY,
55 VAR_LEN_ARRAY,
56};
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71struct qmi_elem_info {
72 enum qmi_elem_type data_type;
73 u32 elem_len;
74 u32 elem_size;
75 enum qmi_array_type array_type;
76 u8 tlv_type;
77 u32 offset;
78 struct qmi_elem_info *ei_array;
79};
80
81#define QMI_RESULT_SUCCESS_V01 0
82#define QMI_RESULT_FAILURE_V01 1
83
84#define QMI_ERR_NONE_V01 0
85#define QMI_ERR_MALFORMED_MSG_V01 1
86#define QMI_ERR_NO_MEMORY_V01 2
87#define QMI_ERR_INTERNAL_V01 3
88#define QMI_ERR_CLIENT_IDS_EXHAUSTED_V01 5
89#define QMI_ERR_INVALID_ID_V01 41
90#define QMI_ERR_ENCODING_V01 58
91#define QMI_ERR_INCOMPATIBLE_STATE_V01 90
92#define QMI_ERR_NOT_SUPPORTED_V01 94
93
94
95
96
97
98
99struct qmi_response_type_v01 {
100 u16 result;
101 u16 error;
102};
103
104extern struct qmi_elem_info qmi_response_type_v01_ei[];
105
106
107
108
109
110
111
112
113
114
115
116struct qmi_service {
117 unsigned int service;
118 unsigned int version;
119 unsigned int instance;
120
121 unsigned int node;
122 unsigned int port;
123
124 void *priv;
125 struct list_head list_node;
126};
127
128struct qmi_handle;
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145struct qmi_ops {
146 int (*new_server)(struct qmi_handle *qmi, struct qmi_service *svc);
147 void (*del_server)(struct qmi_handle *qmi, struct qmi_service *svc);
148 void (*net_reset)(struct qmi_handle *qmi);
149 void (*msg_handler)(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
150 const void *data, size_t count);
151 void (*bye)(struct qmi_handle *qmi, unsigned int node);
152 void (*del_client)(struct qmi_handle *qmi,
153 unsigned int node, unsigned int port);
154};
155
156
157
158
159
160
161
162
163
164
165
166struct qmi_txn {
167 struct qmi_handle *qmi;
168
169 u16 id;
170
171 struct mutex lock;
172 struct completion completion;
173 int result;
174
175 struct qmi_elem_info *ei;
176 void *dest;
177};
178
179
180
181
182
183
184
185
186
187struct qmi_msg_handler {
188 unsigned int type;
189 unsigned int msg_id;
190
191 struct qmi_elem_info *ei;
192
193 size_t decoded_size;
194 void (*fn)(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
195 struct qmi_txn *txn, const void *decoded);
196};
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215struct qmi_handle {
216 struct socket *sock;
217 struct mutex sock_lock;
218
219 struct sockaddr_qrtr sq;
220
221 struct work_struct work;
222 struct workqueue_struct *wq;
223
224 void *recv_buf;
225 size_t recv_buf_size;
226
227 struct list_head lookups;
228 struct list_head lookup_results;
229 struct list_head services;
230
231 struct qmi_ops ops;
232
233 struct idr txns;
234 struct mutex txn_lock;
235
236 const struct qmi_msg_handler *handlers;
237};
238
239int qmi_add_lookup(struct qmi_handle *qmi, unsigned int service,
240 unsigned int version, unsigned int instance);
241int qmi_add_server(struct qmi_handle *qmi, unsigned int service,
242 unsigned int version, unsigned int instance);
243
244int qmi_handle_init(struct qmi_handle *qmi, size_t max_msg_len,
245 const struct qmi_ops *ops,
246 const struct qmi_msg_handler *handlers);
247void qmi_handle_release(struct qmi_handle *qmi);
248
249ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
250 struct qmi_txn *txn, int msg_id, size_t len,
251 struct qmi_elem_info *ei, const void *c_struct);
252ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
253 struct qmi_txn *txn, int msg_id, size_t len,
254 struct qmi_elem_info *ei, const void *c_struct);
255ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
256 int msg_id, size_t len, struct qmi_elem_info *ei,
257 const void *c_struct);
258
259void *qmi_encode_message(int type, unsigned int msg_id, size_t *len,
260 unsigned int txn_id, struct qmi_elem_info *ei,
261 const void *c_struct);
262
263int qmi_decode_message(const void *buf, size_t len,
264 struct qmi_elem_info *ei, void *c_struct);
265
266int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn,
267 struct qmi_elem_info *ei, void *c_struct);
268int qmi_txn_wait(struct qmi_txn *txn, unsigned long timeout);
269void qmi_txn_cancel(struct qmi_txn *txn);
270
271#endif
272