modules: readme files regenerated - uac ... [skip ci]
[sip-router] / src / modules / sipcapture / hep.h
1 /*
2  * hep related structure
3  *
4  * Copyright (C) 2011-14 Alexandr Dubovikov <alexandr.dubovikov@gmail.com>
5  *
6  * This file is part of Kamailio, a free SIP server.
7  *
8  * Kamailio is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * Kamailio is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifndef _hep_h
25 #define _hep_h
26
27 #include "../../core/endianness.h"
28 #include "../../core/events.h"
29
30 #ifdef __IS_BIG_ENDIAN
31 #define to_le(x) bswap32(x)
32 #else
33 #define to_le(x) (x)
34 #endif
35
36 #ifdef __OS_solaris
37 typedef uint8_t u_int8_t;
38 typedef uint16_t u_int16_t;
39 typedef uint32_t u_int32_t;
40 #define IPPROTO_IPIP IPPROTO_ENCAP /* Solaris IPIP protocol has name ENCAP */
41 #endif
42
43 extern int hep_capture_on;
44 extern int hep_offset;
45 extern char *authkey;
46 extern char *correlation_id;
47
48 /* int hep_msg_received(char * buf, unsigned int len, struct receive_info * ri);*/
49 int hep_msg_received(sr_event_param_t *evp);
50
51 /* new method for events */
52 int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t *msg);
53 int hepv2_message_parse(char *buf, unsigned int len, sip_msg_t *msg);
54 int hepv3_get_chunk(struct sip_msg *msg, char *buf, unsigned int len,
55                 int req_chunk, pv_param_t *param, pv_value_t *res);
56
57
58 struct hep_hdr
59 {
60         u_int8_t hp_v;          /* version */
61         u_int8_t hp_l;          /* length */
62         u_int8_t hp_f;          /* family */
63         u_int8_t hp_p;          /* protocol */
64         u_int16_t hp_sport; /* source port */
65         u_int16_t hp_dport; /* destination port */
66 };
67
68 struct hep_iphdr
69 {
70         struct in_addr hp_src;
71         struct in_addr hp_dst; /* source and dest address */
72 };
73
74 struct hep_timehdr
75 {
76         u_int32_t tv_sec;  /* seconds */
77         u_int32_t tv_usec; /* useconds */
78         u_int16_t captid;  /* Capture ID node */
79 };
80
81 struct hep_timeinfo
82 {
83         u_int32_t tv_sec;  /* seconds */
84         u_int32_t tv_usec; /* useconds */
85         u_int32_t captid;  /* Capture ID node */
86 };
87
88 struct hep_ip6hdr
89 {
90         struct in6_addr hp6_src; /* source address */
91         struct in6_addr hp6_dst; /* destination address */
92 };
93
94 /* HEPv3 types */
95
96 struct hep_chunk
97 {
98         u_int16_t vendor_id;
99         u_int16_t type_id;
100         u_int16_t length;
101 } __attribute__((packed));
102
103 typedef struct hep_chunk hep_chunk_t;
104
105 struct hep_chunk_uint8
106 {
107         hep_chunk_t chunk;
108         u_int8_t data;
109 } __attribute__((packed));
110
111 typedef struct hep_chunk_uint8 hep_chunk_uint8_t;
112
113 struct hep_chunk_uint16
114 {
115         hep_chunk_t chunk;
116         u_int16_t data;
117 } __attribute__((packed));
118
119 typedef struct hep_chunk_uint16 hep_chunk_uint16_t;
120
121 struct hep_chunk_uint32
122 {
123         hep_chunk_t chunk;
124         u_int32_t data;
125 } __attribute__((packed));
126
127 typedef struct hep_chunk_uint32 hep_chunk_uint32_t;
128
129 struct hep_chunk_str
130 {
131         hep_chunk_t chunk;
132         char *data;
133 } __attribute__((packed));
134
135 typedef struct hep_chunk_str hep_chunk_str_t;
136
137 struct hep_chunk_ip4
138 {
139         hep_chunk_t chunk;
140         struct in_addr data;
141 } __attribute__((packed));
142
143 typedef struct hep_chunk_ip4 hep_chunk_ip4_t;
144
145 struct hep_chunk_ip6
146 {
147         hep_chunk_t chunk;
148         struct in6_addr data;
149 } __attribute__((packed));
150
151 typedef struct hep_chunk_ip6 hep_chunk_ip6_t;
152
153 struct hep_chunk_payload
154 {
155         hep_chunk_t chunk;
156         char *data;
157 } __attribute__((packed));
158
159 typedef struct hep_chunk_payload hep_chunk_payload_t;
160
161
162 struct hep_ctrl
163 {
164         char id[4];
165         u_int16_t length;
166 } __attribute__((packed));
167
168 typedef struct hep_ctrl hep_ctrl_t;
169
170
171 /* Structure of HEP */
172
173 struct hep_generic_recv
174 {
175         hep_ctrl_t *header;
176         hep_chunk_uint8_t *ip_family;
177         hep_chunk_uint8_t *ip_proto;
178         hep_chunk_uint16_t *src_port;
179         hep_chunk_uint16_t *dst_port;
180         hep_chunk_uint32_t *time_sec;
181         hep_chunk_uint32_t *time_usec;
182         hep_chunk_ip4_t *hep_src_ip4;
183         hep_chunk_ip4_t *hep_dst_ip4;
184         hep_chunk_ip6_t *hep_src_ip6;
185         hep_chunk_ip6_t *hep_dst_ip6;
186         hep_chunk_uint8_t *proto_t;
187         hep_chunk_uint32_t *capt_id;
188         hep_chunk_uint16_t *keep_tm;
189         hep_chunk_str_t *auth_key;
190         hep_chunk_str_t *correlation_id;
191         hep_chunk_t *payload_chunk;
192 } __attribute__((packed));
193
194 typedef struct hep_generic_recv hep_generic_recv_t;
195
196 #define HEP3_PACK_INIT(buf)         \
197         union                           \
198         {                               \
199                 hep_chunk_uint8_t chunk8;   \
200                 hep_chunk_uint16_t chunk16; \
201                 hep_chunk_uint32_t chunk32; \
202                 hep_chunk_t chunkpl;        \
203                 uint16_t len;               \
204         } _tmpu;                        \
205         char *_tmp_p = (buf);           \
206         memcpy(_tmp_p, "HEP3", 4);      \
207         _tmp_p += 4 + 2 /* skip length */;
208
209 #define HEP3_PACK_FINALIZE(buf, lenp)                                          \
210         do {                                                                       \
211                 _tmpu.len = htons(_tmp_p - (char *)(buf));                             \
212                 memcpy((void *)(&(((hep_ctrl_t *)(buf))->length)), (void *)&_tmpu.len, \
213                                 2);                                                            \
214                 *lenp = _tmp_p - (char *)(buf);                                        \
215         } while(0)
216
217 #define _HEP3_PACK_CHUNK_GENERIC(type, tmpvar, vid, tid, val) \
218         do {                                                      \
219                 (tmpvar).chunk.vendor_id = htons(vid);                \
220                 (tmpvar).chunk.type_id = htons(tid);                  \
221                 (tmpvar).chunk.length = htons(sizeof(type));          \
222                 (tmpvar).data = (val);                                \
223                 memcpy(_tmp_p, (void *)&(tmpvar), sizeof(type));      \
224                 _tmp_p += sizeof(type);                               \
225         } while(0)
226
227 #define HEP3_PACK_CHUNK_UINT8(vid, tid, val) \
228         _HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint8_t, _tmpu.chunk8, vid, tid, val)
229 #define HEP3_PACK_CHUNK_UINT16(vid, tid, val) \
230         _HEP3_PACK_CHUNK_GENERIC(                 \
231                         hep_chunk_uint16_t, _tmpu.chunk16, vid, tid, htons(val))
232 #define HEP3_PACK_CHUNK_UINT16_NBO(vid, tid, val) \
233         _HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint16_t, _tmpu.chunk16, vid, tid, (val))
234 #define HEP3_PACK_CHUNK_UINT32(vid, tid, val) \
235         _HEP3_PACK_CHUNK_GENERIC(                 \
236                         hep_chunk_uint32_t, _tmpu.chunk32, vid, tid, htonl(val))
237 #define HEP3_PACK_CHUNK_UINT32_NBO(vid, tid, val) \
238         _HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint32_t, _tmpu.chunk32, vid, tid, (val))
239
240 #define HEP3_PACK_CHUNK_DATA(vid, tid, val, len)                     \
241         do {                                                             \
242                 _tmpu.chunkpl.vendor_id = htons(vid);                        \
243                 _tmpu.chunkpl.type_id = htons(tid);                          \
244                 _tmpu.chunkpl.length = htons(sizeof(hep_chunk_t) + (len));   \
245                 memcpy(_tmp_p, (void *)&_tmpu.chunkpl, sizeof(hep_chunk_t)); \
246                 _tmp_p += sizeof(hep_chunk_t);                               \
247                 memcpy(_tmp_p, (void *)(val), len);                          \
248                 _tmp_p += len;                                               \
249         } while(0)
250
251 #define HEP3_PACK_CHUNK_IP6(vid, tid, paddr) \
252         HEP3_PACK_CHUNK_DATA(vid, tid, paddr, sizeof(struct in6_addr))
253
254 #endif