%% Generated by the Erlang ASN.1 BER-compiler version, utilizing bit-syntax:1.4.4.2 %% Purpose: encoder and decoder to the types in mod TCAPMessages -module('TCAPMessages'). -include("TCAPMessages.hrl"). -define('RT_BER',asn1rt_ber_bin). -export([encoding_rule/0]). -export([ 'enc_Abort'/2, 'enc_DialoguePortion'/2, 'enc_OrigTransactionID'/2, 'enc_DestTransactionID'/2, 'enc_P-AbortCause'/2, 'enc_TCInvokeIdSet'/2, 'enc_EXTERNAL'/2 ]). -export([ 'dec_Abort'/2, 'dec_DialoguePortion'/2, 'dec_OrigTransactionID'/2, 'dec_DestTransactionID'/2, 'dec_P-AbortCause'/2, 'dec_TCInvokeIdSet'/2, 'dec_EXTERNAL'/2 ]). -export([ 'dec_Abort'/3, 'dec_DialoguePortion'/3, 'dec_OrigTransactionID'/3, 'dec_DestTransactionID'/3, 'dec_P-AbortCause'/3, 'dec_TCInvokeIdSet'/3, 'dec_EXTERNAL'/3 ]). -export([info/0]). -export([encode/2,decode/2,encode_disp/2,decode_disp/2]). encoding_rule() -> ber_bin. encode(Type,Data) -> case catch encode_disp(Type,Data) of {'EXIT',{error,Reason}} -> {error,Reason}; {'EXIT',Reason} -> {error,{asn1,Reason}}; {Bytes,_Len} -> {ok,Bytes}; Bytes -> {ok,Bytes} end. decode(Type,Data) -> case catch decode_disp(Type,Data) of {'EXIT',{error,Reason}} -> {error,Reason}; {'EXIT',Reason} -> {error,{asn1,Reason}}; {X,_Rest} -> {ok,X}; {X,_Rest,_Len} -> {ok,X} end. encode_disp('Abort',Data) -> 'enc_Abort'(Data,[]); encode_disp('DialoguePortion',Data) -> 'enc_DialoguePortion'(Data,[]); encode_disp('OrigTransactionID',Data) -> 'enc_OrigTransactionID'(Data,[]); encode_disp('DestTransactionID',Data) -> 'enc_DestTransactionID'(Data,[]); encode_disp('P-AbortCause',Data) -> 'enc_P-AbortCause'(Data,[]); encode_disp('TCInvokeIdSet',Data) -> 'enc_TCInvokeIdSet'(Data,[]); encode_disp('EXTERNAL',Data) -> 'enc_EXTERNAL'(Data,[]); encode_disp(Type,_Data) -> exit({error,{asn1,{undefined_type,Type}}}). decode_disp('Abort',Data) -> 'dec_Abort'(Data,mandatory); decode_disp('DialoguePortion',Data) -> 'dec_DialoguePortion'(Data,mandatory); decode_disp('OrigTransactionID',Data) -> 'dec_OrigTransactionID'(Data,mandatory); decode_disp('DestTransactionID',Data) -> 'dec_DestTransactionID'(Data,mandatory); decode_disp('P-AbortCause',Data) -> 'dec_P-AbortCause'(Data,mandatory); decode_disp('TCInvokeIdSet',Data) -> 'dec_TCInvokeIdSet'(Data,mandatory); decode_disp('EXTERNAL',Data) -> 'dec_EXTERNAL'(Data,mandatory); decode_disp(Type,_Data) -> exit({error,{asn1,{undefined_type,Type}}}). info() -> [{vsn,'1.4.4.2'}, {module,'TCAPMessages'}, {options,[ber_bin]}]. %%================================ %% Abort %%================================ 'enc_Abort'(Val, TagIn) -> %%------------------------------------------------- %% attribute number 1 with type OCTET STRING %%------------------------------------------------- {EncBytes1,EncLen1} = ?RT_BER:encode_octet_string([], ?RT_BER:cindex(2,Val,dtid), [{tag,64,9,'IMPLICIT',32}]), %%------------------------------------------------- %% attribute number 2 with type CHOICE OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case ?RT_BER:cindex(3,Val,reason) of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Abort_reason'(?RT_BER:cindex(3,Val,reason), []) end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, ?RT_BER:encode_tags(TagIn ++ [{tag,0,16,'IMPLICIT',32}], BytesSoFar, LenSoFar). %%================================ %% Abort_reason %%================================ 'enc_Abort_reason'({'Abort_reason',Val}, TagIn) -> 'enc_Abort_reason'(Val, TagIn); 'enc_Abort_reason'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of 'p-abortCause' -> ?RT_BER:encode_integer([], element(2,Val), [{unrecognizedMessageType,0},{unrecognizedTransactionID,1},{badlyFormattedTransactionPortion,2},{incorrectTransactionPortion,3},{resourceLimitation,4}], [{tag,64,10,'IMPLICIT',32}]); 'u-abortCause' -> 'enc_DialoguePortion'(element(2,Val), []); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, ?RT_BER:encode_tags(TagIn ++[], EncBytes, EncLen). 'dec_Abort_reason'(Bytes, OptOrMand, TagIn) -> {{_,Len},Bytes1, RbExp} = ?RT_BER:check_tags(TagIn++[], Bytes, OptOrMand), IndefEndBytes = fun(indefinite,<<0,0,R/binary>>)-> R; (_,B)-> B end, IndefEndRb = fun(indefinite,<<0,0,_R/binary>>)-> 2; (_,_)-> 0 end, case Bytes1 of %% 'p-abortCause' <<1:2,_:1,10:5,_/binary>> -> {Dec, Rest, RbCho} = ?RT_BER:decode_integer(Bytes1,{0,127},[{unrecognizedMessageType,0},{unrecognizedTransactionID,1},{badlyFormattedTransactionPortion,2},{incorrectTransactionPortion,3},{resourceLimitation,4}],[{tag,64,10,'IMPLICIT',32}], mandatory), {{'p-abortCause', Dec}, IndefEndBytes(Len,Rest), RbExp + RbCho + IndefEndRb(Len,Rest)}; %% 'u-abortCause' <<1:2,_:1,11:5,_/binary>> -> {Dec, Rest, RbCho} = 'dec_DialoguePortion'(Bytes1, mandatory, []), {{'u-abortCause', Dec}, IndefEndBytes(Len,Rest), RbExp + RbCho + IndefEndRb(Len,Rest)}; Else -> case OptOrMand of mandatory ->exit({error,{asn1,{invalid_choice_tag,Else}}}); _ ->exit({error,{asn1,{no_optional_tag,Else}}}) end end. 'dec_Abort'(Bytes, OptOrMand) -> 'dec_Abort'(Bytes, OptOrMand, []). 'dec_Abort'(Bytes, OptOrMand, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- {{_,Len},Bytes1,Rb1} = ?RT_BER:check_tags(TagIn ++ [{tag,0,16,'IMPLICIT',32}], Bytes, OptOrMand), {Bytes2,RemBytes} = ?RT_BER:split_list(Bytes1,Len), %%------------------------------------------------- %% attribute number 1 with type OCTET STRING %%------------------------------------------------- {Term1,Bytes3,Rb2} = ?RT_BER:decode_octet_string(Bytes2,{1,4},[{tag,64,9,'IMPLICIT',32}], no_length, mandatory), %%------------------------------------------------- %% attribute number 2 with type CHOICE OPTIONAL %%------------------------------------------------- {Term2,Bytes4,Rb3} = case (catch 'dec_Abort_reason'(Bytes3, opt_or_default, [])) of {'EXIT',{error,{asn1,{no_optional_tag,_}}}} -> { asn1_NOVALUE, Bytes3, 0 }; Casetmp1-> Casetmp1 end, {Bytes5,Rb4} = ?RT_BER:restbytes2(RemBytes, Bytes4,noext), {{'Abort', Term1, Term2}, Bytes5, Rb1+Rb2+Rb3+Rb4}. %%================================ %% DialoguePortion %%================================ 'enc_DialoguePortion'({'DialoguePortion',Val}, TagIn) -> 'enc_DialoguePortion'(Val, TagIn); 'enc_DialoguePortion'(Val, TagIn) -> 'enc_EXTERNAL'(Val, TagIn ++ [{tag,64,11,'EXPLICIT',32}]). 'dec_DialoguePortion'(Bytes, OptOrMand) -> 'dec_DialoguePortion'(Bytes, OptOrMand, []). 'dec_DialoguePortion'(Bytes, OptOrMand, TagIn) -> 'dec_EXTERNAL'(Bytes, OptOrMand, TagIn++[{tag,64,11,'EXPLICIT',32}]). %%================================ %% OrigTransactionID %%================================ 'enc_OrigTransactionID'({'OrigTransactionID',Val}, TagIn) -> 'enc_OrigTransactionID'(Val, TagIn); 'enc_OrigTransactionID'(Val, TagIn) -> ?RT_BER:encode_octet_string([], Val, TagIn ++ [{tag,64,8,'IMPLICIT',32}]). 'dec_OrigTransactionID'(Bytes, OptOrMand) -> 'dec_OrigTransactionID'(Bytes, OptOrMand, []). 'dec_OrigTransactionID'(Bytes, OptOrMand, TagIn) -> ?RT_BER:decode_octet_string(Bytes,{1,4},TagIn++[{tag,64,8,'IMPLICIT',32}], no_length, OptOrMand). %%================================ %% DestTransactionID %%================================ 'enc_DestTransactionID'({'DestTransactionID',Val}, TagIn) -> 'enc_DestTransactionID'(Val, TagIn); 'enc_DestTransactionID'(Val, TagIn) -> ?RT_BER:encode_octet_string([], Val, TagIn ++ [{tag,64,9,'IMPLICIT',32}]). 'dec_DestTransactionID'(Bytes, OptOrMand) -> 'dec_DestTransactionID'(Bytes, OptOrMand, []). 'dec_DestTransactionID'(Bytes, OptOrMand, TagIn) -> ?RT_BER:decode_octet_string(Bytes,{1,4},TagIn++[{tag,64,9,'IMPLICIT',32}], no_length, OptOrMand). %%================================ %% P-AbortCause %%================================ 'enc_P-AbortCause'({'P-AbortCause',Val}, TagIn) -> 'enc_P-AbortCause'(Val, TagIn); 'enc_P-AbortCause'(Val, TagIn) -> ?RT_BER:encode_integer([], Val, [{unrecognizedMessageType,0},{unrecognizedTransactionID,1},{badlyFormattedTransactionPortion,2},{incorrectTransactionPortion,3},{resourceLimitation,4}], TagIn ++ [{tag,64,10,'IMPLICIT',32}]). 'dec_P-AbortCause'(Bytes, OptOrMand) -> 'dec_P-AbortCause'(Bytes, OptOrMand, []). 'dec_P-AbortCause'(Bytes, OptOrMand, TagIn) -> ?RT_BER:decode_integer(Bytes,{0,127},[{unrecognizedMessageType,0},{unrecognizedTransactionID,1},{badlyFormattedTransactionPortion,2},{incorrectTransactionPortion,3},{resourceLimitation,4}],TagIn++[{tag,64,10,'IMPLICIT',32}], OptOrMand). %%================================ %% TCInvokeIdSet %%================================ 'enc_TCInvokeIdSet'({'TCInvokeIdSet',Val}, TagIn) -> 'enc_TCInvokeIdSet'(Val, TagIn); 'enc_TCInvokeIdSet'(Val, TagIn) -> 'Remote-Operations-Generic-ROS-PDUs':'enc_InvokeId'(Val, TagIn ++ []). 'dec_TCInvokeIdSet'(Bytes, OptOrMand) -> 'dec_TCInvokeIdSet'(Bytes, OptOrMand, []). 'dec_TCInvokeIdSet'(Bytes, OptOrMand, TagIn) -> 'Remote-Operations-Generic-ROS-PDUs':'dec_InvokeId'(Bytes, OptOrMand, TagIn++[]). %%================================ %% EXTERNAL %%================================ 'enc_EXTERNAL'(Val, TagIn) -> NewVal = asn1rt_check:transform_to_EXTERNAL1990(Val), %%------------------------------------------------- %% attribute number 1 with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {EncBytes1,EncLen1} = case ?RT_BER:cindex(2,NewVal,'direct-reference') of asn1_NOVALUE -> {<<>>,0}; _ -> ?RT_BER:encode_object_identifier(?RT_BER:cindex(2,NewVal,'direct-reference'), []) end, %%------------------------------------------------- %% attribute number 2 with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case ?RT_BER:cindex(3,NewVal,'indirect-reference') of asn1_NOVALUE -> {<<>>,0}; _ -> ?RT_BER:encode_integer([], ?RT_BER:cindex(3,NewVal,'indirect-reference'), []) end, %%------------------------------------------------- %% attribute number 3 with type ObjectDescriptor OPTIONAL %%------------------------------------------------- {EncBytes3,EncLen3} = case ?RT_BER:cindex(4,NewVal,'data-value-descriptor') of asn1_NOVALUE -> {<<>>,0}; _ -> ?RT_BER:encode_restricted_string([], ?RT_BER:cindex(4,NewVal,'data-value-descriptor'), 7, []) end, %%------------------------------------------------- %% attribute number 4 with type CHOICE %%------------------------------------------------- {EncBytes4,EncLen4} = 'enc_EXTERNAL_encoding'(?RT_BER:cindex(5,NewVal,encoding), []), BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4, ?RT_BER:encode_tags(TagIn ++ [{tag,0,8,'IMPLICIT',32},{tag,0,16,'IMPLICIT',32}], BytesSoFar, LenSoFar). %%================================ %% EXTERNAL_encoding %%================================ 'enc_EXTERNAL_encoding'({'EXTERNAL_encoding',Val}, TagIn) -> 'enc_EXTERNAL_encoding'(Val, TagIn); 'enc_EXTERNAL_encoding'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of 'single-ASN1-type' -> ?RT_BER:encode_open_type(element(2,Val), [{tag,128,0,'EXPLICIT',32}]); 'octet-aligned' -> ?RT_BER:encode_octet_string([], element(2,Val), [{tag,128,1,'IMPLICIT',0}]); arbitrary -> ?RT_BER:encode_bit_string([], element(2,Val), [], [{tag,128,2,'IMPLICIT',0}]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, ?RT_BER:encode_tags(TagIn ++[], EncBytes, EncLen). 'dec_EXTERNAL_encoding'(Bytes, OptOrMand, TagIn) -> {{_,Len},Bytes1, RbExp} = ?RT_BER:check_tags(TagIn++[], Bytes, OptOrMand), IndefEndBytes = fun(indefinite,<<0,0,R/binary>>)-> R; (_,B)-> B end, IndefEndRb = fun(indefinite,<<0,0,_R/binary>>)-> 2; (_,_)-> 0 end, case Bytes1 of %% 'single-ASN1-type' <<2:2,_:1,0:5,_/binary>> -> {Dec, Rest, RbCho} = ?RT_BER:decode_open_type(ber_bin,Bytes1,[{tag,128,0,'EXPLICIT',32}]), {{'single-ASN1-type', Dec}, IndefEndBytes(Len,Rest), RbExp + RbCho + IndefEndRb(Len,Rest)}; %% 'octet-aligned' <<2:2,_:1,1:5,_/binary>> -> {Dec, Rest, RbCho} = ?RT_BER:decode_octet_string(Bytes1,[],[{tag,128,1,'IMPLICIT',0}], no_length, mandatory), {{'octet-aligned', Dec}, IndefEndBytes(Len,Rest), RbExp + RbCho + IndefEndRb(Len,Rest)}; %% 'arbitrary' <<2:2,_:1,2:5,_/binary>> -> {Dec, Rest, RbCho} = ?RT_BER:decode_bit_string(Bytes1,[],[],[{tag,128,2,'IMPLICIT',0}], no_length, mandatory), {{arbitrary, Dec}, IndefEndBytes(Len,Rest), RbExp + RbCho + IndefEndRb(Len,Rest)}; Else -> case OptOrMand of mandatory ->exit({error,{asn1,{invalid_choice_tag,Else}}}); _ ->exit({error,{asn1,{no_optional_tag,Else}}}) end end. 'dec_EXTERNAL'(Bytes, OptOrMand) -> 'dec_EXTERNAL'(Bytes, OptOrMand, []). 'dec_EXTERNAL'(Bytes, OptOrMand, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- {{_,Len},Bytes1,Rb1} = ?RT_BER:check_tags(TagIn ++ [{tag,0,8,'IMPLICIT',32},{tag,0,16,'IMPLICIT',32}], Bytes, OptOrMand), {Bytes2,RemBytes} = ?RT_BER:split_list(Bytes1,Len), %%------------------------------------------------- %% attribute number 1 with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {Term1,Bytes3,Rb2} = case Bytes2 of <<0:2,_:1,6:5,_/binary>> -> ?RT_BER:decode_object_identifier(Bytes2,[], mandatory); _ -> { asn1_NOVALUE, Bytes2, 0 } end, %%------------------------------------------------- %% attribute number 2 with type INTEGER OPTIONAL %%------------------------------------------------- {Term2,Bytes4,Rb3} = case Bytes3 of <<0:2,_:1,2:5,_/binary>> -> ?RT_BER:decode_integer(Bytes3,[],[], mandatory); _ -> { asn1_NOVALUE, Bytes3, 0 } end, %%------------------------------------------------- %% attribute number 3 with type ObjectDescriptor OPTIONAL %%------------------------------------------------- {Term3,Bytes5,Rb4} = case Bytes4 of <<0:2,_:1,7:5,_/binary>> -> ?RT_BER:decode_restricted_string(Bytes4,[],7,[], no_length, mandatory); _ -> { asn1_NOVALUE, Bytes4, 0 } end, %%------------------------------------------------- %% attribute number 4 with type CHOICE %%------------------------------------------------- {Term4,Bytes6,Rb5} = 'dec_EXTERNAL_encoding'(Bytes5, mandatory, []), {Bytes7,Rb6} = ?RT_BER:restbytes2(RemBytes, Bytes6,noext), OldFormat={'EXTERNAL', Term1, Term2, Term3, Term4}, ASN11994Format = asn1rt_check:transform_to_EXTERNAL1994(OldFormat), {ASN11994Format,Bytes7, Rb1+Rb2+Rb3+Rb4+Rb5+Rb6}.