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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
#include "mncc.h"
#include "MNCC_Types.hh"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
namespace MNCC__Types {
static void enc_bcap(struct gsm_mncc_bearer_cap *out, const MNCC__bearer__cap& in)
{
out->transfer = in.transfer();
out->mode = in.mode();
out->coding = in.coding();
out->radio = in.radio();
out->speech_ctm = in.speech__ctm();
for (int i = 0; i < in.speech__ver().lengthof(); i++)
out->speech_ver[i] = in.speech__ver()[i];
if (in.data().is_value()) {
MNCC__bearer__cap__data data = in.data();
out->data.rate_adaption = (gsm48_bcap_ra) (int) data.rate__adaptation();
out->data.sig_access = (gsm48_bcap_sig_access) (int) data.sig__access();
out->data.async = data.async();
out->data.nr_stop_bits = data.nr__stop__bits();
out->data.nr_data_bits = data.nr__data__bits();
out->data.user_rate = (gsm48_bcap_user_rate) (int) data.user__rate();
out->data.parity = (gsm48_bcap_parity) (int) data.parity();
out->data.interm_rate = (gsm48_bcap_interm_rate) (int) data.interm__rate();
out->data.transp = (gsm48_bcap_transp) (int) data.transp();
out->data.modem_type = (gsm48_bcap_modem_type) (int) data.modem__type();
}
}
static MNCC__bearer__cap dec_bcap(const struct gsm_mncc_bearer_cap *in)
{
MNCC__bearer__cap__data data;
MNCC__speech__vers vers;
data = MNCC__bearer__cap__data((GSM48__bcap__ra) in->data.rate_adaption,
(GSM48__bcap__sig__access) in->data.sig_access,
in->data.async,
in->data.nr_stop_bits,
in->data.nr_data_bits,
(GSM48__bcap__user__rate) in->data.user_rate,
(GSM48__bcap__parity) in->data.parity,
(GSM48__bcap__interm__rate) in->data.interm_rate,
(GSM48__bcap__transp) in->data.transp,
(GSM48__bcap__modem__type) in->data.modem_type);
for (unsigned int i = 0; i < ARRAY_SIZE(in->speech_ver); i++) {
vers[i] = in->speech_ver[i];
if (vers[i] == -1)
break;
}
return MNCC__bearer__cap(in->transfer, in->mode, in->coding, in->radio, in->speech_ctm,
vers, data);
}
static void enc_number(struct gsm_mncc_number *num, const MNCC__number& in)
{
num->type = in.number__type();
num->plan = in.plan();
num->present = in.presence();
num->screen = in.screen();
strncpy(num->number, in.number(), sizeof(num->number));
}
static MNCC__number dec_number(const struct gsm_mncc_number *num)
{
return MNCC__number(num->type, num->plan,num->present, num->screen, num->number);
}
OCTETSTRING enc__MNCC__PDU(const MNCC__PDU& in)
{
struct gsm_mncc mncc;
OCTETSTRING ret_val;
memset(&mncc, 0, sizeof(mncc));
mncc.msg_type = in.msg__type();
switch (in.u().get_selection()) {
case MNCC__MsgUnion::ALT_signal: {
const MNCC__PDU__Signal& in_sig = in.u().signal();
mncc.callref = in_sig.callref();
if (in_sig.bearer__cap().is_value()) {
enc_bcap(&mncc.bearer_cap, in_sig.bearer__cap());
mncc.fields |= MNCC_F_BEARER_CAP;
}
if (in_sig.called().is_value()) {
enc_number(&mncc.called, in_sig.called());
mncc.fields |= MNCC_F_CALLED;
}
if (in_sig.calling().is_value()) {
enc_number(&mncc.calling, in_sig.calling());
mncc.fields |= MNCC_F_CALLING;
}
if (in_sig.redirecting().is_value()) {
enc_number(&mncc.redirecting, in_sig.redirecting());
mncc.fields |= MNCC_F_REDIRECTING;
}
if (in_sig.connected().is_value()) {
enc_number(&mncc.connected, in_sig.connected());
mncc.fields |= MNCC_F_CONNECTED;
}
if (in_sig.cause().is_value()) {
const MNCC__cause &cause = in_sig.cause();
TTCN_Buffer ttcn_buffer(cause.diag());
mncc.cause.location = cause.location();
mncc.cause.coding = cause.coding();
mncc.cause.rec = cause.rec();
mncc.cause.rec_val = cause.rec__val();
mncc.cause.value = cause.val();
mncc.cause.diag_len = ttcn_buffer.get_len();
if (mncc.cause.diag_len > (int) sizeof(mncc.cause.diag)) {
TTCN_error("MNCC diagnostics length %u too long", mncc.cause.diag_len);
mncc.cause.diag_len = sizeof(mncc.cause.diag);
}
memcpy(mncc.cause.diag, ttcn_buffer.get_data(), ttcn_buffer.get_len());
mncc.fields |= MNCC_F_CAUSE;
}
if (in_sig.progress().is_value()) {
const MNCC__progress &progress = in_sig.progress();
mncc.progress.coding = progress.coding();
mncc.progress.location = progress.location();
mncc.progress.descr = progress.descr();
mncc.fields |= MNCC_F_PROGRESS;
}
if (in_sig.useruser().is_value()) {
const MNCC__useruser &useruser = in_sig.useruser();
mncc.useruser.proto = useruser.proto();
strncpy(mncc.useruser.info, useruser.info(), sizeof(mncc.useruser.info));
mncc.fields |= MNCC_F_USERUSER;
}
if (in_sig.facility().is_value()) {
const CHARSTRING &fac = in_sig.facility();
strncpy(mncc.facility.info, fac, sizeof(mncc.facility.info));
mncc.facility.len = strlen(mncc.facility.info);
mncc.fields |= MNCC_F_FACILITY;
}
if (in_sig.cccap().is_value()) {
const MNCC__cccap &cccap = in_sig.cccap();
mncc.cccap.dtmf = cccap.dtmf();
mncc.cccap.pcp = cccap.pcp();
mncc.fields |= MNCC_F_CCCAP;
}
if (in_sig.ssversion().is_value()) {
const CHARSTRING &ssv = in_sig.ssversion();
strncpy(mncc.ssversion.info, ssv, sizeof(mncc.ssversion.info));
mncc.ssversion.len = strlen(mncc.ssversion.info);
mncc.fields |= MNCC_F_SSVERSION;
}
mncc.clir.sup = in_sig.clir__sup();
mncc.clir.inv = in_sig.clir__inv();
if (in_sig.signal().is_value()) {
const INTEGER &sig = in_sig.signal();
mncc.signal = sig;
mncc.fields |= MNCC_F_SIGNAL;
}
if (in_sig.keypad().is_value()) {
const CHARSTRING &kpd = in_sig.keypad();
mncc.signal = (int) kpd[0].get_char();
mncc.fields |= MNCC_F_KEYPAD;
}
mncc.more = in_sig.more();
mncc.notify = in_sig.notify();
if (in_sig.emergency().is_value()) {
const INTEGER &emerg = in_sig.emergency();
mncc.emergency = emerg;
mncc.fields |= MNCC_F_EMERGENCY;
}
strncpy(mncc.imsi, in_sig.imsi(), sizeof(mncc.imsi));
mncc.lchan_type = in_sig.lchan__type();
mncc.lchan_mode = in_sig.lchan__mode();
ret_val = OCTETSTRING(sizeof(mncc), (uint8_t *)&mncc);
}
break;
case MNCC__MsgUnion::ALT_data:
struct gsm_data_frame data;
memset(&data, 0, sizeof(data));
data.msg_type = in.msg__type();
ret_val = OCTETSTRING(sizeof(data), (uint8_t *)&data);
ret_val = ret_val & in.u().data().data();
break;
case MNCC__MsgUnion::ALT_rtp:
struct gsm_mncc_rtp rtp;
memset(&rtp, 0, sizeof(rtp));
rtp.msg_type = in.msg__type();
rtp.callref = in.u().rtp().callref();
rtp.ip = in.u().rtp().ip();
rtp.port = in.u().rtp().rtp__port();
rtp.payload_type = in.u().rtp().payload__type();
rtp.payload_msg_type = in.u().rtp().payload__msg__type();
ret_val = OCTETSTRING(sizeof(rtp), (uint8_t *) &rtp);
break;
case MNCC__MsgUnion::ALT_hello:
struct gsm_mncc_hello hello;
memset(&hello, 0, sizeof(hello));
hello.msg_type = in.msg__type();
hello.version = in.u().hello().version();
hello.mncc_size = in.u().hello().mncc__size();
hello.data_frame_size = in.u().hello().data__frame__size();
hello.called_offset = in.u().hello().called__offset();
hello.signal_offset = in.u().hello().signal__offset();
hello.emergency_offset = in.u().hello().emergency__offset();
hello.lchan_type_offset = in.u().hello().lchan__type__offset();
ret_val = OCTETSTRING(sizeof(hello), (uint8_t *) &hello);
break;
}
return ret_val;
}
MNCC__PDU dec__MNCC__PDU(const OCTETSTRING& in)
{
TTCN_Buffer ttcn_buffer(in);
const struct gsm_mncc *in_mncc;
MNCC__PDU__Signal sign;
const struct gsm_mncc_hello *in_hello;
MNCC__PDU__Hello hello;
const struct gsm_data_frame *in_data;
MNCC__PDU__Data data;
const struct gsm_mncc_rtp *in_rtp;
MNCC__PDU__Rtp rtp;
MNCC__MsgUnion u;
in_mncc = (struct gsm_mncc *) ttcn_buffer.get_read_data();
sign.set_implicit_omit();
hello.set_implicit_omit();
data.set_implicit_omit();
rtp.set_implicit_omit();
switch (in_mncc->msg_type) {
case MNCC_SOCKET_HELLO:
in_hello = (const struct gsm_mncc_hello *) in_mncc;
hello = MNCC__PDU__Hello(in_hello->version,
in_hello->mncc_size,
in_hello->data_frame_size,
in_hello->called_offset,
in_hello->signal_offset,
in_hello->emergency_offset,
in_hello->lchan_type_offset);
u.hello() = hello;
break;
case GSM_TCHF_FRAME:
case GSM_TCHF_FRAME_EFR:
case GSM_TCHH_FRAME:
case GSM_TCH_FRAME_AMR:
case GSM_BAD_FRAME:
in_data = (const struct gsm_data_frame *) in_mncc;
u.data() = MNCC__PDU__Data(in_data->callref,
substr(in, offsetof(struct gsm_data_frame, data),
in.lengthof() - offsetof(struct gsm_data_frame, data)));
break;
case MNCC_RTP_CREATE:
case MNCC_RTP_CONNECT:
case MNCC_RTP_FREE:
in_rtp = (const struct gsm_mncc_rtp *) in_mncc;
rtp = MNCC__PDU__Rtp(in_rtp->callref, in_rtp->ip, in_rtp->port, in_rtp->payload_type,
in_rtp->payload_msg_type);
u.rtp() = rtp;
break;
default:
sign.callref() = in_mncc->callref;
if (in_mncc->fields & MNCC_F_BEARER_CAP) {
sign.bearer__cap() = dec_bcap(&in_mncc->bearer_cap);
}
if (in_mncc->fields & MNCC_F_CALLED)
sign.called() = dec_number(&in_mncc->called);
if (in_mncc->fields & MNCC_F_CALLING)
sign.calling() = dec_number(&in_mncc->calling);
if (in_mncc->fields & MNCC_F_REDIRECTING)
sign.redirecting() = dec_number(&in_mncc->redirecting);
if (in_mncc->fields & MNCC_F_CONNECTED)
sign.connected() = dec_number(&in_mncc->connected);
if (in_mncc->fields & MNCC_F_CAUSE) {
sign.cause() = MNCC__cause(in_mncc->cause.location,
in_mncc->cause.coding,
in_mncc->cause.rec,
in_mncc->cause.rec_val,
in_mncc->cause.value,
OCTETSTRING(in_mncc->cause.diag_len,
(const uint8_t *)in_mncc->cause.diag));
}
if (in_mncc->fields & MNCC_F_USERUSER) {
sign.useruser() = MNCC__useruser(in_mncc->useruser.proto,
CHARSTRING(in_mncc->useruser.info));
}
if (in_mncc->fields & MNCC_F_PROGRESS) {
sign.progress() = MNCC__progress(in_mncc->progress.coding,
in_mncc->progress.location,
in_mncc->progress.descr);
}
if (in_mncc->fields & MNCC_F_EMERGENCY)
sign.emergency() = in_mncc->emergency;
if (in_mncc->fields & MNCC_F_FACILITY)
sign.facility() = CHARSTRING(in_mncc->facility.info);
if (in_mncc->fields & MNCC_F_SSVERSION)
sign.ssversion() = CHARSTRING(in_mncc->ssversion.info);
if (in_mncc->fields & MNCC_F_CCCAP)
sign.cccap() = MNCC__cccap(in_mncc->cccap.dtmf, in_mncc->cccap.pcp);
if (in_mncc->fields & MNCC_F_KEYPAD) {
char kpd[2] = { (char) in_mncc->keypad, 0 };
sign.keypad() = CHARSTRING(kpd);
}
if (in_mncc->fields & MNCC_F_SIGNAL)
sign.signal() = in_mncc->signal;
sign.clir__sup() = in_mncc->clir.sup;
sign.clir__inv() = in_mncc->clir.inv;
sign.more() = in_mncc->more;
sign.notify() = in_mncc->notify;
sign.imsi() = CHARSTRING(in_mncc->imsi);
sign.lchan__type() = in_mncc->lchan_type;
sign.lchan__mode() = in_mncc->lchan_mode;
u.signal() = sign;
break;
}
return MNCC__PDU(in_mncc->msg_type, u);
}
}
|