forked from calebccff/qmic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqmic.h
147 lines (115 loc) · 2.56 KB
/
qmic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef __QMIC_H__
#define __QMIC_H__
#include <err.h>
#include <stdbool.h>
#include "list.h"
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
#define STRUCT_NEST_MAX 32
enum symbol_type {
TYPE_U8,
TYPE_U16,
TYPE_U32,
TYPE_U64,
TYPE_I8,
TYPE_I16,
TYPE_I32,
TYPE_I64,
TYPE_CHAR,
TYPE_STRING,
TYPE_STRUCT,
TYPE_ENUM,
};
enum message_type {
MESSAGE_REQUEST = 0,
MESSAGE_RESPONSE = 2,
MESSAGE_INDICATION = 4,
};
extern const char *sz_simple_types[];
struct qmi_package {
const char *name;
unsigned short service_id;
};
extern struct qmi_package qmi_package;
struct qmi_const {
const char *name;
long long value;
struct list_head node;
};
struct qmi_message_member {
const char *name;
int type;
struct qmi_struct *qmi_struct;
int id;
bool required;
unsigned array_size;
bool array_fixed;
/* Number of bytes used to encode array length.
* only valid for variable arrays.
*/
int array_len_type;
struct list_head node;
};
struct qmi_message {
enum message_type type;
const char *name;
unsigned msg_id;
struct list_head node;
struct list_head members;
};
struct qmi_struct;
struct qmi_struct_member {
const char *name;
int type;
/* Valid only if type is TYPE_STRUCT */
struct qmi_struct *qmi_struct;
bool is_ptr;
bool is_struct_ref;
/* Number of bytes used to encode array length.
* only valid if is_ptr is true
*/
int array_len_type;
unsigned array_size;
bool array_fixed;
struct list_head node;
};
struct qmi_struct {
char *name;
/*
* Valid if this struct is defined
* as a member of another struct
*/
struct qmi_struct_member *member;
struct list_head node;
struct list_head members;
};
struct qmi_enum {
char *name;
struct list_head node;
struct list_head members;
};
extern struct list_head qmi_consts;
extern struct list_head qmi_messages;
extern struct list_head qmi_structs;
extern struct list_head qmi_enums;
extern FILE *sourcefile;
void qmi_parse(void);
void emit_source_includes(FILE *fp, const char *package);
void guard_header(FILE *fp, const char *package);
void guard_footer(FILE *fp);
void qmi_const_header(FILE *fp);
void qmi_enum_header(FILE *fp);
void accessor_emit_c(FILE *fp, const char *package);
void accessor_emit_h(FILE *fp, const char *package);
void kernel_emit_c(FILE *fp);
void kernel_emit_h(FILE *fp);
/* Allocate and zero a block of memory; and exit if it fails */
#define memalloc(size) ({ \
void *__p = malloc(size); \
\
if (!__p) \
errx(1, "malloc() failed in %s(), line %d\n", \
__func__, __LINE__); \
memset(__p, 0, size); \
__p; \
})
#endif