1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2003-2016. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20%%
21-module('TCAPPackage_msg').
22
23-compile(export_all).
24
25-include("TCAPPackage.hrl").
26
27val('PackageType',unidirectional) ->
28    {unidirectional,val('UniTransactionPDU')};
29val('PackageType',abort) ->
30    {abort,val('Abort')};
31val('PackageType',Component) ->
32    {Component,val('TransactionPDU')};
33val('ComponentPDU',1) ->
34    {invokeLast,val('Invoke')};
35val('ComponentPDU',2) ->
36    {returnResultLast,val('ReturnResult')};
37val('ComponentPDU',3) ->
38    {returnError,val('ReturnError')}.
39
40
41
42val('UniTransactionPDU') ->
43    #'UniTransactionPDU'{identifier=val('TransactionID'),
44			 dialoguePortion=val('DialoguePortion'),
45			 componentPortion=val('ComponentSequence')};
46val('TransactionPDU') ->
47    #'TransactionPDU'{identifier=val('TransactionID'),
48		      dialoguePortion=val('DialoguePortion'),
49		      componentPortion=val('ComponentSequence')};
50val('TransactionID') ->
51    <<"OCTET STRING">>;
52val('DialoguePortion') ->
53    #'DialoguePortion'{version=val('ProtocolVersion'),
54		       applicationContext={integerApplicationId,12},
55		       userInformation=val('UserInformation'),
56		       securityContext={integerSecurityId,13},
57		       confidentiality=val('Confidentiality')};
58val('Confidentiality') ->
59    #'Confidentiality'{confidentialityId={integerConfidentialityId,14}};
60val('ProtocolVersion') ->
61    <<"K">>;
62val('UserInformation') ->
63    [val('EXTERNAL'),val('EXTERNAL')];
64val('EXTERNAL') ->
65    #'EXTERNAL'{'direct-reference'={0,1,2},
66		encoding={'single-ASN1-type',<<1,2,3,4>>}};
67val('ComponentSequence') ->
68    [val('ComponentPDU',1),val('ComponentPDU',2),val('ComponentPDU',3)];
69val('Invoke') ->
70    #'Invoke'{componentIDs = <<"AB">>,
71	      opcode={local,-2},
72	      parameter=running};
73val('ReturnResult') ->
74    #'ReturnResult'{componentID = <<"C">>,
75		    parameter=[1,2,3,4]};
76val('ReturnError') ->
77    #'ReturnError'{componentID = <<"D">>,
78		   errorCode={local,21},
79		   parameter=true};
80val('Abort') ->
81    #'Abort'{identifier=val('TransactionID'),
82	     dialoguePortion=val('DialoguePortion'),
83	     causeInformation={abortCause,unrecognizedPackageType}};
84val(Type) ->
85    io:format("Missing type: ~p~n",[Type]).
86
87
88check_result('PackageType',unidirectional,Res) ->
89    {unidirectional,
90     {'UniTransactionPDU',
91      <<"OCTET STRING">>,
92      {'DialoguePortion',<<"K">>,
93       {integerApplicationId,12},
94       [_,%{'EXTERNAL',{syntax,{0,1,2}},asn1_NOVALUE,OTVal},
95	_],%{'EXTERNAL',{syntax,{0,1,2}},asn1_NOVALUE,OTVal}],
96       {integerSecurityId,13},
97       {'Confidentiality',
98	{integerConfidentialityId,14}}},
99      [{invokeLast,
100	{_,<<"AB">>,{local,-2},running}},
101       {returnResultLast,{_,<<"C">>,_}},
102       {returnError,{_,<<"D">>,{local,21},true}}]}} = Res,
103    ok;
104%%    check_OT_val(OTVal);
105check_result('PackageType',abort,Res)->
106    {abort,{'Abort',<<"OCTET STRING">>,
107	    {'DialoguePortion',<<"K">>,
108	     {integerApplicationId,12},
109	     [_,%{'EXTERNAL',{syntax,{0,1,2}},asn1_NOVALUE,OTVal},
110	      _],%{'EXTERNAL',{syntax,{0,1,2}},asn1_NOVALUE,OTVal}],
111	     {integerSecurityId,13},
112	     {'Confidentiality',
113	      {integerConfidentialityId,14}}},
114	    {abortCause,unrecognizedPackageType}}} = Res,
115    ok;
116%%    check_OT_val(OTVal);
117check_result('PackageType',response,Res) ->
118    {response,{'TransactionPDU',<<"OCTET STRING">>,
119	       {'DialoguePortion',
120		<<"K">>,
121		{integerApplicationId,12},
122		[_,%{'EXTERNAL',{syntax,{0,1,2}},asn1_NOVALUE,OTVal},
123		 _],%{'EXTERNAL',{syntax,{0,1,2}},asn1_NOVALUE,OTVal}],
124		{integerSecurityId,13},
125		{'Confidentiality',
126		 {integerConfidentialityId,14}}},
127	       [{invokeLast,
128		 {_,<<"AB">>,{local,-2},running}},
129		{returnResultLast,
130		 {_,<<"C">>,_}},
131		{returnError,
132		 {_,<<"D">>,{local,21},true}}]}} = Res,
133    ok.
134%%    check_OT_val(OTVal).
135
136check_OT_val([160,4,1,2,3,4]) ->
137    ok;
138check_OT_val(<<160,4,1,2,3,4>>) ->
139    ok;
140check_OT_val(_) ->
141    error.
142
143