0001
0002
0003
0004
0005
0006 #ifndef __QMI_HELPERS_H__
0007 #define __QMI_HELPERS_H__
0008
0009 #include <linux/completion.h>
0010 #include <linux/idr.h>
0011 #include <linux/list.h>
0012 #include <linux/qrtr.h>
0013 #include <linux/types.h>
0014 #include <linux/workqueue.h>
0015
0016 struct socket;
0017
0018
0019
0020
0021
0022
0023
0024
0025 struct qmi_header {
0026 u8 type;
0027 u16 txn_id;
0028 u16 msg_id;
0029 u16 msg_len;
0030 } __packed;
0031
0032 #define QMI_REQUEST 0
0033 #define QMI_RESPONSE 2
0034 #define QMI_INDICATION 4
0035
0036 #define QMI_COMMON_TLV_TYPE 0
0037
0038 enum qmi_elem_type {
0039 QMI_EOTI,
0040 QMI_OPT_FLAG,
0041 QMI_DATA_LEN,
0042 QMI_UNSIGNED_1_BYTE,
0043 QMI_UNSIGNED_2_BYTE,
0044 QMI_UNSIGNED_4_BYTE,
0045 QMI_UNSIGNED_8_BYTE,
0046 QMI_SIGNED_2_BYTE_ENUM,
0047 QMI_SIGNED_4_BYTE_ENUM,
0048 QMI_STRUCT,
0049 QMI_STRING,
0050 };
0051
0052 enum qmi_array_type {
0053 NO_ARRAY,
0054 STATIC_ARRAY,
0055 VAR_LEN_ARRAY,
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 struct qmi_elem_info {
0072 enum qmi_elem_type data_type;
0073 u32 elem_len;
0074 u32 elem_size;
0075 enum qmi_array_type array_type;
0076 u8 tlv_type;
0077 u32 offset;
0078 struct qmi_elem_info *ei_array;
0079 };
0080
0081 #define QMI_RESULT_SUCCESS_V01 0
0082 #define QMI_RESULT_FAILURE_V01 1
0083
0084 #define QMI_ERR_NONE_V01 0
0085 #define QMI_ERR_MALFORMED_MSG_V01 1
0086 #define QMI_ERR_NO_MEMORY_V01 2
0087 #define QMI_ERR_INTERNAL_V01 3
0088 #define QMI_ERR_CLIENT_IDS_EXHAUSTED_V01 5
0089 #define QMI_ERR_INVALID_ID_V01 41
0090 #define QMI_ERR_ENCODING_V01 58
0091 #define QMI_ERR_DISABLED_V01 69
0092 #define QMI_ERR_INCOMPATIBLE_STATE_V01 90
0093 #define QMI_ERR_NOT_SUPPORTED_V01 94
0094
0095
0096
0097
0098
0099
0100 struct qmi_response_type_v01 {
0101 u16 result;
0102 u16 error;
0103 };
0104
0105 extern struct qmi_elem_info qmi_response_type_v01_ei[];
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 struct qmi_service {
0118 unsigned int service;
0119 unsigned int version;
0120 unsigned int instance;
0121
0122 unsigned int node;
0123 unsigned int port;
0124
0125 void *priv;
0126 struct list_head list_node;
0127 };
0128
0129 struct qmi_handle;
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 struct qmi_ops {
0147 int (*new_server)(struct qmi_handle *qmi, struct qmi_service *svc);
0148 void (*del_server)(struct qmi_handle *qmi, struct qmi_service *svc);
0149 void (*net_reset)(struct qmi_handle *qmi);
0150 void (*msg_handler)(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
0151 const void *data, size_t count);
0152 void (*bye)(struct qmi_handle *qmi, unsigned int node);
0153 void (*del_client)(struct qmi_handle *qmi,
0154 unsigned int node, unsigned int port);
0155 };
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 struct qmi_txn {
0168 struct qmi_handle *qmi;
0169
0170 u16 id;
0171
0172 struct mutex lock;
0173 struct completion completion;
0174 int result;
0175
0176 struct qmi_elem_info *ei;
0177 void *dest;
0178 };
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 struct qmi_msg_handler {
0189 unsigned int type;
0190 unsigned int msg_id;
0191
0192 struct qmi_elem_info *ei;
0193
0194 size_t decoded_size;
0195 void (*fn)(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
0196 struct qmi_txn *txn, const void *decoded);
0197 };
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216 struct qmi_handle {
0217 struct socket *sock;
0218 struct mutex sock_lock;
0219
0220 struct sockaddr_qrtr sq;
0221
0222 struct work_struct work;
0223 struct workqueue_struct *wq;
0224
0225 void *recv_buf;
0226 size_t recv_buf_size;
0227
0228 struct list_head lookups;
0229 struct list_head lookup_results;
0230 struct list_head services;
0231
0232 struct qmi_ops ops;
0233
0234 struct idr txns;
0235 struct mutex txn_lock;
0236
0237 const struct qmi_msg_handler *handlers;
0238 };
0239
0240 int qmi_add_lookup(struct qmi_handle *qmi, unsigned int service,
0241 unsigned int version, unsigned int instance);
0242 int qmi_add_server(struct qmi_handle *qmi, unsigned int service,
0243 unsigned int version, unsigned int instance);
0244
0245 int qmi_handle_init(struct qmi_handle *qmi, size_t max_msg_len,
0246 const struct qmi_ops *ops,
0247 const struct qmi_msg_handler *handlers);
0248 void qmi_handle_release(struct qmi_handle *qmi);
0249
0250 ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
0251 struct qmi_txn *txn, int msg_id, size_t len,
0252 struct qmi_elem_info *ei, const void *c_struct);
0253 ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
0254 struct qmi_txn *txn, int msg_id, size_t len,
0255 struct qmi_elem_info *ei, const void *c_struct);
0256 ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
0257 int msg_id, size_t len, struct qmi_elem_info *ei,
0258 const void *c_struct);
0259
0260 void *qmi_encode_message(int type, unsigned int msg_id, size_t *len,
0261 unsigned int txn_id, struct qmi_elem_info *ei,
0262 const void *c_struct);
0263
0264 int qmi_decode_message(const void *buf, size_t len,
0265 struct qmi_elem_info *ei, void *c_struct);
0266
0267 int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn,
0268 struct qmi_elem_info *ei, void *c_struct);
0269 int qmi_txn_wait(struct qmi_txn *txn, unsigned long timeout);
0270 void qmi_txn_cancel(struct qmi_txn *txn);
0271
0272 #endif