summaryrefslogtreecommitdiffstats
path: root/MobileL3_v13.4.0_CNL113832_LATEST/src/SS_EncDec.cc
blob: ee4867ab949ce81af66b6d8a5ad78190b6791f60 (plain)
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Copyright Test Competence Center (TCC) ETH 2016                           //
//                                                                           //
// The copyright to the computer  program(s) herein  is the property of TCC. //
// The program(s) may be used and/or copied only with the written permission //
// of TCC or in accordance with  the terms and conditions  stipulated in the //
// agreement/contract under which the program(s) has been supplied.          //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
//
//  File:               SS_PDU_Defs.asn
//  Rev:                R1B
//  Prodnr:             CNL 113 832
//  Contact:            http://ttcn.ericsson.se
//  Reference:          3GPP TS 24.008 v13.4.0

#include "SS_PDU_Defs.hh"
#include "SS_Types.hh"

namespace SS__Types
{
using namespace SS__PDU__Defs;
TTCN_Module SS__EncDec("SS_EncDec", __DATE__, __TIME__);

//Type definitions to transfer data between coding functions
struct SS_Invoke_for_dec
{
  INTEGER               invokeId;
  OPTIONAL<INTEGER>     linkedId;
  Remote__Operations__Information__Objects::Code opcode;
  OPTIONAL<OCTETSTRING> stream;
};

struct SS_ReturnResult_for_dec
{
  INTEGER               invokeId;
  OPTIONAL<Remote__Operations__Information__Objects::Code> opcode;
  OPTIONAL<OCTETSTRING> stream;
};

struct SS_ReturnError_for_dec
{
  INTEGER               invokeId;
  Remote__Operations__Information__Objects::Code errorCode;
  OPTIONAL<OCTETSTRING> stream;
};

struct SS_Reject_for_dec
{
  OPTIONAL<INTEGER>     invokeId;
  Remote__Operations__Generic__ROS__PDUs::ProblemType problem;
};


//////////////////////////////////
// Encoding function for SS__Invoke
//////////////////////////////////
OCTETSTRING enc_SS_Invoke(const SS__Invoke& pdu)
{
  TTCN_Buffer buf;

  OCTETSTRING ret_val;
  pdu.encode(SS__Invoke_descr_, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);
  buf.get_string(ret_val);
  ret_val[0] = int2oct(161,1);

  return ret_val;
}
//////////////////////////////////
// Encoding function for SS__ReturnResult
//////////////////////////////////
OCTETSTRING enc_SS_ReturnResult(const SS__ReturnResult& pdu)
{
  TTCN_Buffer buf;

  OCTETSTRING ret_val;
  pdu.encode(SS__ReturnResult_descr_, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);
  buf.get_string(ret_val);
  ret_val[0] = int2oct(162,1);

  return ret_val;
}
//////////////////////////////////
// Encoding function for SS__ReturnError
//////////////////////////////////
OCTETSTRING enc_SS_ReturnError(const SS__ReturnError& pdu)
{
  TTCN_Buffer buf;

  OCTETSTRING ret_val;
  pdu.encode(SS__ReturnError_descr_, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);
  buf.get_string(ret_val);
  ret_val[0] = int2oct(163,1);

  return ret_val;
}
//////////////////////////////////
// Encoding function for SS__Reject
//////////////////////////////////
OCTETSTRING enc_SS_Reject(const SS__Reject& pdu)
{
  TTCN_Buffer buf;

  OCTETSTRING ret_val;
  pdu.encode(SS__Reject_descr_, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);
  buf.get_string(ret_val);
  ret_val[0] = int2oct(164,1);

  return ret_val;
}

//////////////////////////////////
// Decoding function for SS__Invoke
//////////////////////////////////
int dec_SS_Invoke(const SS_Invoke_for_dec& params, SS__Invoke& pdu)
{  
  SS__Invoke__help help_pdu;
  
  if(params.stream.ispresent())
  {
    help_pdu.invokeId().present__() = params.invokeId;
    if(params.linkedId.ispresent())
      help_pdu.linkedId()().present__().present__() = params.linkedId;
    else
      help_pdu.linkedId() = OMIT_VALUE;

    help_pdu.opcode() = params.opcode;

    OCTETSTRING oct_stream = params.stream;
    help_pdu.argument() = oct_stream;
    TTCN_Buffer buf;
    help_pdu.encode(SS__Invoke__help_descr_, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);  
    
	  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_IGNORE);
	  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
	  TTCN_EncDec::clear_error();
    
    pdu.decode(SS__Invoke_descr_, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL);
    
    TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
    
    if(TTCN_EncDec::get_last_error_type() != 0) return 1;
  }
  else
  {
    pdu.invokeId().present__() = params.invokeId;

    if(params.linkedId.ispresent())
      pdu.linkedId()().present__().present__() = params.linkedId;
    else
      pdu.linkedId() = OMIT_VALUE;

    pdu.opcode() = params.opcode;

    pdu.argument() = OMIT_VALUE;
  }

  return 0;
}

//////////////////////////////////
// Decoding function for SS__ReturnResult
//////////////////////////////////
int dec_SS_ReturnResult(const SS_ReturnResult_for_dec& params, SS__ReturnResult& pdu)
{  
  SS__ReturnResult__help help_pdu;


  if(params.opcode.ispresent() && params.stream.ispresent())
  {
    help_pdu.invokeId().present__() = params.invokeId;
    help_pdu.result()().opcode() = params.opcode;
    OCTETSTRING oct_stream = params.stream;
    help_pdu.result()().result() = oct_stream;
    TTCN_Buffer buf;
    help_pdu.encode(SS__ReturnResult__help_descr_, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);  
    
	  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_IGNORE);
	  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
	  TTCN_EncDec::clear_error();
	  
	  pdu.decode(SS__ReturnResult_descr_, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL);

    TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
    
    if(TTCN_EncDec::get_last_error_type() != 0) return 1;
  }
  else
  {
    pdu.invokeId().present__() = params.invokeId;
    pdu.result() = OMIT_VALUE;
  }

  return 0;
}

//////////////////////////////////
// Decoding function for SS__ReturnError
//////////////////////////////////
int dec_SS_ReturnError(const SS_ReturnError_for_dec& params, SS__ReturnError& pdu)
{
  
  SS__ReturnError__help help_pdu;

  if(params.stream.ispresent())
  {
    help_pdu.invokeId().present__() = params.invokeId;
    help_pdu.errcode() = params.errorCode;
    OCTETSTRING oct_stream = params.stream;
    help_pdu.parameter()() = oct_stream;

    TTCN_Buffer buf;

    help_pdu.encode(SS__ReturnError__help_descr_, buf, TTCN_EncDec::CT_BER, BER_ENCODE_DER);  

	  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_IGNORE);
	  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
	  TTCN_EncDec::clear_error();
	  
    pdu.decode(SS__ReturnError_descr_, buf, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL);

    TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
    
    if(TTCN_EncDec::get_last_error_type() != 0) return 1;
  }
  else
  {
    pdu.invokeId().present__() = params.invokeId;
    pdu.errcode() = params.errorCode;
    pdu.parameter() = OMIT_VALUE;
  }

  return 0;
}

//////////////////////////////////
// Decoding function for SS__Reject
//////////////////////////////////
int dec_SS_Reject(const SS_Reject_for_dec& params, SS__Reject& pdu)
{
  if(params.invokeId.ispresent())
    pdu.invokeId().present__() = params.invokeId;
  else
    pdu.invokeId().absent() = ASN_NULL_VALUE;

  pdu.problem() = params.problem;
  
  return 0;
}

////////////////////////////////////////////////////////////////////
// Decoding function for internal SS_TCAP_ComponentPortion
////////////////////////////////////////////////////////////////////
int dec__SS__TCAP__ComponentPortion(const OCTETSTRING& stream, SS__TCAP__ComponentPortion& pdu)
{
  if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC))
  {
    TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);
    TTCN_Logger::log_event_str("dec_SS_TCAP_ComponentPortion(): Stream before decoding: ");
    stream.log();
    TTCN_Logger::end_event();
  }

	TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_IGNORE);
	TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);
	TTCN_EncDec::clear_error();

  TTCN_Buffer ttcn_buffer(stream);
  SS__TCAP__Component    ret_sub_val;
  int i = 0;

  if(!ttcn_buffer.contains_complete_TLV()) {
    if (TTCN_Logger::log_this_event(TTCN_Logger::TTCN_WARNING))
    {
      TTCN_Logger::begin_event(TTCN_Logger::TTCN_WARNING);
      TTCN_Logger::log_event_str("dec_SS_TCAP_ComponentPortion(): there is no complete TLV in the incoming stream!");
      TTCN_Logger::end_event();
    }
    return 1;
  }

  while(ttcn_buffer.contains_complete_TLV())
  {
    ret_sub_val.decode(SS__TCAP__Component_descr_, ttcn_buffer, TTCN_EncDec::CT_BER, BER_ACCEPT_ALL);
    pdu[i] = ret_sub_val;
    i++;
    ttcn_buffer.cut();
  }

	TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);

  if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC))
  {
    TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);
    TTCN_Logger::log_event_str("dec_SS_TCAP_ComponentPortion(): Decoded @SS_Types.SS_TCAP_ComponentPortion: ");
    pdu.log();
    TTCN_Logger::end_event();
  }

	return TTCN_EncDec::get_last_error_type() == TTCN_EncDec::ET_NONE ? 0 : 1;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////
// Main encoding function for SS_FacilityInformation. This is called from TTCN-3
//////////////////////////////////////////////////////////////////////////////////////////////////////
OCTETSTRING enc__SS__FacilityInformation(const SS__FacilityInformation& pdu)
{
  if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC))
  {
    TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);
    TTCN_Logger::log_event_str("enc_SS_FacilityInformation(): SS_FacilityInformation before encoding: ");
    pdu.log();
    TTCN_Logger::end_event();
  }
  SS__TCAP__ComponentPortion temp_val;
  OCTETSTRING ret_val(0,NULL);

  for (int i = 0; i < pdu.size_of(); i++)
  {
    if (pdu[i].get_selection() == SS__Component::ALT_invoke)
    {
       ret_val = ret_val + enc_SS_Invoke(pdu[i].invoke());
    }
    else if (pdu[i].get_selection() == SS__Component::ALT_returnResult)
    {
       ret_val = ret_val + enc_SS_ReturnResult(pdu[i].returnResult());
    }
    else if (pdu[i].get_selection() == SS__Component::ALT_returnError)
    {
       ret_val = ret_val + enc_SS_ReturnError(pdu[i].returnError());
    }
    else if (pdu[i].get_selection() == SS__Component::ALT_reject)
    {
       ret_val = ret_val + enc_SS_Reject(pdu[i].reject());
    }
  }
  if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC))
  {
    TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);
    TTCN_Logger::log_event_str("enc_SS_FacilityInformation(): stream after encoding: ");
    ret_val.log();
    TTCN_Logger::end_event();
  }
  return ret_val;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Main decoding function for SS_FacilityInformation. This is called from TTCN-3
//////////////////////////////////////////////////////////////////////////////////////////////////////
INTEGER dec__SS__FacilityInformation__backtrack(const OCTETSTRING& stream, SS__FacilityInformation& pdu)
{
  if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC))
  {
    TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);
    TTCN_Logger::log_event_str("dec_SS_FacilityInformation__backtrack(): Stream before decoding: ");
    stream.log();
    TTCN_Logger::end_event();
  }
  
  SS__TCAP__ComponentPortion temp_val;
  int decode = dec__SS__TCAP__ComponentPortion(stream, temp_val);
  
  if(decode == 0) {

    for (int i = 0; i < temp_val.size_of() && decode == 0; i++)
    {
      if (temp_val[i].get_selection() == SS__TCAP__Component::ALT_invoke)
      {
        SS_Invoke_for_dec par_val;
        par_val.invokeId = temp_val[i].invoke().invokeID();
        par_val.linkedId = temp_val[i].invoke().linkedID();
        par_val.opcode   =   temp_val[i].invoke().operationCode();
        par_val.stream   =   temp_val[i].invoke().parameter();
        decode = dec_SS_Invoke(par_val, pdu[i].invoke());
      }
      else if (temp_val[i].get_selection() == SS__TCAP__Component::ALT_returnResult)
      {
        SS_ReturnResult_for_dec par_val;
        par_val.invokeId = temp_val[i].returnResult().invokeID();

        if(temp_val[i].returnResult().result().ispresent())
        {
          SS__TCAP__ReturnResult__Result temp_res = temp_val[i].returnResult().result();
          par_val.opcode = temp_res.operationCode();
          par_val.stream = temp_res.parameter();
        }
        else
        {
          par_val.opcode = OMIT_VALUE;
          par_val.stream = OMIT_VALUE;
        }
        decode = dec_SS_ReturnResult(par_val, pdu[i].returnResult());
      }
      else if (temp_val[i].get_selection() == SS__TCAP__Component::ALT_returnError)
      {
        SS_ReturnError_for_dec par_val;
        par_val.invokeId = temp_val[i].returnError().invokeID();
        par_val.errorCode = temp_val[i].returnError().errorCode();
        par_val.stream  =   temp_val[i].returnError().parameter();

        decode = dec_SS_ReturnError(par_val, pdu[i].returnError());
      }
      else if (temp_val[i].get_selection() == SS__TCAP__Component::ALT_reject)
      {
        SS_Reject_for_dec par_val;
        if( temp_val[i].reject().invokeID().get_selection() == SS__TCAP__Reject_invokeID::ALT_derivable)
          par_val.invokeId = temp_val[i].reject().invokeID().derivable();
        else
          par_val.invokeId = OMIT_VALUE;
        par_val.problem = temp_val[i].reject().problem();

        decode = dec_SS_Reject(par_val, pdu[i].reject());
      }
    }
  }

  if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC))
  {
    TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);
    TTCN_Logger::log_event_str("dec_SS_FacilityInformation__backtrack(): Decoded @SS_Types.SS_FacilityInformation: ");
    pdu.log();
    TTCN_Logger::end_event();
  }

  return decode;
}

SS__FacilityInformation dec__SS__FacilityInformation(const OCTETSTRING& stream)
{
  SS__FacilityInformation ret;
  dec__SS__FacilityInformation__backtrack(stream, ret);
  return ret;
}

}//namespace