Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 1 | % ITU-T Q.71x SCCP Message coding / decoding |
| 2 | |
| 3 | % (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | % |
| 5 | % All Rights Reserved |
| 6 | % |
| 7 | % This program is free software; you can redistribute it and/or modify |
| 8 | % it under the terms of the GNU Affero General Public License as |
| 9 | % published by the Free Software Foundation; either version 3 of the |
| 10 | % License, or (at your option) any later version. |
| 11 | % |
| 12 | % This program is distributed in the hope that it will be useful, |
| 13 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | % GNU General Public License for more details. |
| 16 | % |
| 17 | % You should have received a copy of the GNU Affero General Public License |
| 18 | % along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | -module(sccp_codec). |
| 21 | -author('Harald Welte <laforge@gnumonks.org>'). |
| 22 | -include("sccp.hrl"). |
| 23 | |
Harald Welte | 9abbbad | 2011-04-21 12:19:41 +0200 | [diff] [blame] | 24 | -export([parse_sccp_msg/1, encode_sccp_msg/1, encode_sccp_msgt/2, |
| 25 | is_connectionless/1]). |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 26 | |
Harald Welte | 9baab6d | 2011-12-08 00:46:00 +0100 | [diff] [blame] | 27 | -export([gen_gt_helper/1, gen_addr_helper/2, gen_addr_helper/3]). |
| 28 | |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 29 | -compile(export_all). |
| 30 | |
Harald Welte | 2edaf55 | 2011-04-02 16:46:16 +0200 | [diff] [blame] | 31 | -compile({parse_transform, exprecs}). |
Harald Welte | 0f2f596 | 2011-04-04 15:59:49 +0200 | [diff] [blame] | 32 | -export_records([global_title, sccp_addr, sccp_msg]). |
Harald Welte | 2edaf55 | 2011-04-02 16:46:16 +0200 | [diff] [blame] | 33 | |
Harald Welte | d9c318f | 2011-12-10 22:17:11 +0100 | [diff] [blame] | 34 | binarify(In) when is_binary(In) -> |
| 35 | In; |
| 36 | binarify(In) when is_list(In) -> |
| 37 | list_to_binary(In). |
| 38 | |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 39 | parse_point_code(BinPC, PCind) when is_binary(BinPC) -> |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 40 | case PCind of |
| 41 | 1 -> |
Harald Welte | 9c3b1bb | 2011-10-12 17:00:34 +0200 | [diff] [blame] | 42 | <<PointCode:16/little, Remain/binary>> = BinPC; |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 43 | _ -> |
| 44 | Remain = BinPC, |
Harald Welte | b5936ba | 2011-12-08 00:58:51 +0100 | [diff] [blame] | 45 | PointCode = undefined |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 46 | end, |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 47 | {Remain, PointCode}. |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 48 | |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 49 | parse_ssn(BinSSN, SSNind) -> |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 50 | case SSNind of |
| 51 | 1 -> |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 52 | <<SSN:8, Remain/binary>> = BinSSN; |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 53 | _ -> |
| 54 | Remain = BinSSN, |
Harald Welte | b5936ba | 2011-12-08 00:58:51 +0100 | [diff] [blame] | 55 | SSN = undefined |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 56 | end, |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 57 | {Remain, SSN}. |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 58 | |
| 59 | enc_is_odd(Enc) -> |
| 60 | case Enc of |
| 61 | 1 -> 1; |
| 62 | _ -> 0 |
| 63 | end. |
| 64 | |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 65 | parse_gt(BinGT, GTind) -> |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 66 | case GTind of |
| 67 | ?SCCP_GTI_NO_GT -> |
Harald Welte | b5936ba | 2011-12-08 00:58:51 +0100 | [diff] [blame] | 68 | undefined; |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 69 | ?SCCP_GTI_NAT_ONLY -> |
| 70 | % Figure 7/Q.713 |
| 71 | <<Odd:1, Nature:7, Digits/binary>> = BinGT, |
| 72 | PhoneNum = isup_codec:parse_isup_party(Digits, Odd), |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 73 | #global_title{gti = GTind, |
| 74 | nature_of_addr_ind = Nature, |
| 75 | phone_number = PhoneNum}; |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 76 | ?SCCP_GTI_TT_ONLY -> |
| 77 | % Figure 9/Q.913 |
| 78 | <<TransType:8, Digits/binary>> = BinGT, |
| 79 | % Used in national interfaces only, we cannot parse Digits |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 80 | #global_title{gti = GTind, |
| 81 | trans_type = TransType, |
| 82 | phone_number = Digits}; |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 83 | ?SCCP_GTI_TT_NP_ENC -> |
| 84 | % Figure 10/Q.713 |
| 85 | <<TransType:8, NumPlan:4, Enc:4, Digits/binary>> = BinGT, |
| 86 | PhoneNum = isup_codec:parse_isup_party(Digits, enc_is_odd(Enc)), |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 87 | #global_title{gti = GTind, |
| 88 | trans_type = TransType, encoding = Enc, |
| 89 | numbering_plan = NumPlan, |
| 90 | phone_number = PhoneNum}; |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 91 | ?SCCP_GTI_TT_NP_ENC_NAT -> |
| 92 | % Figure 11/Q.713 |
| 93 | <<TransType:8, NumPlan:4, Enc:4, 0:1, Nature:7, Digits/binary>> = BinGT, |
| 94 | PhoneNum = isup_codec:parse_isup_party(Digits, enc_is_odd(Enc)), |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 95 | #global_title{gti = GTind, |
| 96 | trans_type = TransType, encoding = Enc, |
| 97 | numbering_plan = NumPlan, |
| 98 | nature_of_addr_ind = Nature, |
| 99 | phone_number = PhoneNum}; |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 100 | _ -> |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 101 | BinGT |
| 102 | end. |
Harald Welte | ba6fdbb | 2011-01-23 22:04:39 +0100 | [diff] [blame] | 103 | |
| 104 | % parse SCCP Address |
| 105 | parse_sccp_addr(BinAddr) when is_binary(BinAddr) -> |
| 106 | <<ResNatUse:1, RoutInd:1, GTind:4, SSNind:1, PCind:1, Remain/binary>> = BinAddr, |
Harald Welte | 2b4b267 | 2011-02-03 12:50:41 +0100 | [diff] [blame] | 107 | {RemainPC, OptPC} = parse_point_code(Remain, PCind), |
| 108 | {RemainSSN, OptSSN} = parse_ssn(RemainPC, SSNind), |
| 109 | OptGT = parse_gt(RemainSSN, GTind), |
| 110 | #sccp_addr{res_nat_use = ResNatUse, route_on_ssn = RoutInd, |
| 111 | point_code = OptPC, ssn = OptSSN, global_title = OptGT}. |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 112 | |
| 113 | % parse SCCP Optional Part |
| 114 | parse_sccp_opt(OptType, OptLen, Content) -> |
| 115 | {OptType, {OptLen, Content}}. |
| 116 | |
| 117 | parse_sccp_opts(<<>>, OptList) -> |
| 118 | % empty list |
| 119 | OptList; |
| 120 | parse_sccp_opts(<<0>>, OptList) -> |
| 121 | % end of options |
| 122 | OptList; |
| 123 | parse_sccp_opts(OptBin, OptList) -> |
| 124 | <<OptType, OptLen, Content:OptLen/binary, Remain/binary>> = OptBin, |
| 125 | NewOpt = parse_sccp_opt(OptType, OptLen, Content), |
| 126 | parse_sccp_opts(Remain, [NewOpt|OptList]). |
| 127 | |
| 128 | % Parse incoming SCCP message, one function for every message type |
| 129 | parse_sccp_msgt(?SCCP_MSGT_CR, DataBin) -> |
| 130 | % first get the fixed part |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 131 | <<_:8, SrcLocalRef:24/big, PCOpt:4, ProtoClass:4, RemainVar/binary >> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 132 | % variable length fixed part |
| 133 | <<PtrVar:8, PtrOpt:8, _/binary>> = RemainVar, |
| 134 | CalledPartyLen = binary:at(RemainVar, PtrVar), |
| 135 | CalledParty = binary:part(RemainVar, PtrVar+1, CalledPartyLen), |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 136 | CalledPartyDec = parse_sccp_addr(CalledParty), |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 137 | % optional part |
| 138 | OptBin = binary:part(RemainVar, 1 + PtrOpt, byte_size(RemainVar)-(1+PtrOpt)), |
| 139 | OptList = parse_sccp_opts(OptBin, []), |
| 140 | %OptList = [], |
| 141 | % build parsed list of message |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 142 | [{src_local_ref, SrcLocalRef},{protocol_class, {ProtoClass, PCOpt}}, |
| 143 | {called_party_addr, CalledPartyDec} | OptList]; |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 144 | parse_sccp_msgt(?SCCP_MSGT_CC, DataBin) -> |
| 145 | % first get the fixed part |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 146 | <<_:8, DstLocalRef:24/big, SrcLocalRef:24/big, PCOpt:4, ProtoClass:4, Remain/binary >> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 147 | % optional part |
| 148 | OptList = parse_sccp_opts(Remain, []), |
| 149 | % build parsed list of message |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 150 | [{dst_local_ref, DstLocalRef},{src_local_ref, SrcLocalRef}, |
| 151 | {protocol_class, {ProtoClass, PCOpt}} | OptList]; |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 152 | parse_sccp_msgt(?SCCP_MSGT_CREF, DataBin) -> |
| 153 | % first get the fixed part |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 154 | <<_:8, DstLocalRef:24/big, RefusalCause:8, Remain/binary >> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 155 | % optional part |
| 156 | OptList = parse_sccp_opts(Remain, []), |
| 157 | % build parsed list of message |
| 158 | [{dst_local_ref, DstLocalRef},{refusal_cause, RefusalCause}|OptList]; |
| 159 | parse_sccp_msgt(?SCCP_MSGT_RLSD, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 160 | <<_:8, DstLocalRef:24/big, SrcLocalRef:24/big, ReleaseCause:8, Remain/binary >> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 161 | % optional part |
| 162 | OptList = parse_sccp_opts(Remain, []), |
| 163 | % build parsed list of message |
| 164 | [{dst_local_ref, DstLocalRef},{src_local_ref, SrcLocalRef},{release_cause, ReleaseCause}|OptList]; |
| 165 | parse_sccp_msgt(?SCCP_MSGT_RLC, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 166 | <<_:8, DstLocalRef:24/big, SrcLocalRef:24/big>> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 167 | % build parsed list of message |
| 168 | [{dst_local_ref, DstLocalRef},{src_local_ref, SrcLocalRef}]; |
| 169 | parse_sccp_msgt(?SCCP_MSGT_DT1, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 170 | <<_:8, DstLocalRef:24/big, SegmReass:8, DataPtr:8, Remain/binary >> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 171 | DataLen = binary:at(Remain, DataPtr-1), |
| 172 | UserData = binary:part(Remain, DataPtr-1+1, DataLen), |
| 173 | % build parsed list of message |
| 174 | [{dst_local_ref, DstLocalRef},{segm_reass, SegmReass},{user_data, UserData}]; |
| 175 | parse_sccp_msgt(?SCCP_MSGT_DT2, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 176 | <<_:8, DstLocalRef:24/big, SeqSegm:16, DataPtr:8, Remain/binary >> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 177 | DataLen = binary:at(Remain, DataPtr-1), |
| 178 | UserData = binary:part(Remain, DataPtr-1+1, DataLen), |
| 179 | % build parsed list of message |
| 180 | [{dst_local_ref, DstLocalRef},{seq_segm, SeqSegm},{user_data, UserData}]; |
| 181 | parse_sccp_msgt(?SCCP_MSGT_AK, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 182 | <<_:8, DstLocalRef:24/big, RxSeqnr:8, Credit:8>> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 183 | [{dst_local_ref, DstLocalRef},{rx_seq_nr, RxSeqnr},{credit, Credit}]; |
| 184 | parse_sccp_msgt(?SCCP_MSGT_UDT, DataBin) -> |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 185 | <<_:8, PCOpt:4, ProtoClass:4, CalledPartyPtr:8, CallingPartyPtr:8, DataPtr:8, Remain/binary >> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 186 | % variable part |
| 187 | CalledPartyLen = binary:at(Remain, CalledPartyPtr-3), |
| 188 | CalledParty = binary:part(Remain, CalledPartyPtr-3+1, CalledPartyLen), |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 189 | CalledPartyDec = parse_sccp_addr(CalledParty), |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 190 | CallingPartyLen = binary:at(Remain, CallingPartyPtr-2), |
| 191 | CallingParty = binary:part(Remain, CallingPartyPtr-2+1, CallingPartyLen), |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 192 | CallingPartyDec = parse_sccp_addr(CallingParty), |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 193 | DataLen = binary:at(Remain, DataPtr-1), |
| 194 | UserData = binary:part(Remain, DataPtr-1+1, DataLen), |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 195 | [{protocol_class, {ProtoClass, PCOpt}},{called_party_addr, CalledPartyDec}, |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 196 | {calling_party_addr, CallingPartyDec},{user_data, UserData}]; |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 197 | parse_sccp_msgt(?SCCP_MSGT_UDTS, DataBin) -> |
Harald Welte | 030f109 | 2011-03-11 19:08:07 +0100 | [diff] [blame] | 198 | <<_:8, ReturnCause:8, CalledPartyPtr:8, CallingPartyPtr:8, DataPtr:8, Remain/binary >> = DataBin, |
| 199 | % variable part |
| 200 | CalledPartyLen = binary:at(Remain, CalledPartyPtr-3), |
| 201 | CalledParty = binary:part(Remain, CalledPartyPtr-3+1, CalledPartyLen), |
| 202 | CalledPartyDec = parse_sccp_addr(CalledParty), |
| 203 | CallingPartyLen = binary:at(Remain, CallingPartyPtr-2), |
| 204 | CallingParty = binary:part(Remain, CallingPartyPtr-2+1, CallingPartyLen), |
| 205 | CallingPartyDec = parse_sccp_addr(CallingParty), |
| 206 | DataLen = binary:at(Remain, DataPtr-1), |
| 207 | UserData = binary:part(Remain, DataPtr-1+1, DataLen), |
| 208 | [{return_cause, ReturnCause},{called_party_addr, CalledPartyDec}, |
| 209 | {calling_party_addr, CallingPartyDec},{user_data, UserData}]; |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 210 | parse_sccp_msgt(?SCCP_MSGT_ED, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 211 | <<_:8, DstLocalRef:24/big, DataPtr:8, Remain/binary>> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 212 | DataLen = binary:at(Remain, DataPtr-1), |
| 213 | UserData = binary:part(Remain, DataPtr-1+1, DataLen), |
| 214 | [{dst_local_ref, DstLocalRef}, {user_data, UserData}]; |
| 215 | parse_sccp_msgt(?SCCP_MSGT_EA, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 216 | <<_:8, DstLocalRef:24/big>> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 217 | [{dst_local_ref, DstLocalRef}]; |
| 218 | parse_sccp_msgt(?SCCP_MSGT_RSR, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 219 | <<_:8, DstLocalRef:24/big, SrcLocalRef:24/big, ResetCause:8>> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 220 | [{dst_local_ref, DstLocalRef},{src_local_ref, SrcLocalRef},{reset_cause, ResetCause}]; |
| 221 | parse_sccp_msgt(?SCCP_MSGT_RSC, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 222 | <<_:8, DstLocalRef:24/big, SrcLocalRef:24/big>> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 223 | [{dst_local_ref, DstLocalRef},{src_local_ref, SrcLocalRef}]; |
| 224 | parse_sccp_msgt(?SCCP_MSGT_ERR, DataBin) -> |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 225 | <<_:8, DstLocalRef:24/big, ErrCause:8>> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 226 | [{dst_local_ref, DstLocalRef},{error_cause, ErrCause}]; |
| 227 | parse_sccp_msgt(?SCCP_MSGT_IT, DataBin) -> |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 228 | <<_:8, DstLocalRef:24/big, SrcLocalRef:24/big, PCOpt: 4, ProtoClass:4, SegmSeq:16, Credit:8>> = DataBin, |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 229 | [{dst_local_ref, DstLocalRef},{src_local_ref, SrcLocalRef}, |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 230 | {protocol_class, {ProtoClass, PCOpt}},{seq_segm, SegmSeq},{credit, Credit}]. |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 231 | % FIXME: XUDT/XUDTS, LUDT/LUDTS |
| 232 | |
| 233 | % process one incoming SCCP message |
| 234 | parse_sccp_msg(DataBin) -> |
| 235 | MsgType = binary:first(DataBin), |
| 236 | Parsed = parse_sccp_msgt(MsgType, DataBin), |
| 237 | {ok, #sccp_msg{msg_type = MsgType, parameters = Parsed}}. |
| 238 | |
| 239 | % Encoding Part |
| 240 | |
Harald Welte | 0e1709c | 2011-02-06 22:17:53 +0100 | [diff] [blame] | 241 | gt_enc_by_odd(Odd) -> |
| 242 | if Odd == 1 -> |
| 243 | 1; |
| 244 | true -> |
| 245 | 2 |
| 246 | end. |
| 247 | |
Harald Welte | 5a1cf3c | 2011-04-14 21:55:13 +0200 | [diff] [blame] | 248 | encode_gt(undefined) -> |
| 249 | {?SCCP_GTI_NO_GT, <<>>}; |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 250 | encode_gt(#global_title{gti = GTind, phone_number = PhoneNum, |
| 251 | nature_of_addr_ind = Nature, |
Harald Welte | 0e1709c | 2011-02-06 22:17:53 +0100 | [diff] [blame] | 252 | trans_type = TransType, encoding = _EncOrig, |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 253 | numbering_plan = NumPlan}) -> |
| 254 | case GTind of |
| 255 | ?SCCP_GTI_NO_GT -> |
| 256 | {GTind, <<>>}; |
| 257 | ?SCCP_GTI_NAT_ONLY -> |
| 258 | % Figure 7/Q.713 |
| 259 | {PhoneBin, OddEven} = isup_codec:encode_isup_party(PhoneNum), |
| 260 | {GTind, <<OddEven:1, Nature:7, PhoneBin/binary>>}; |
| 261 | ?SCCP_GTI_TT_ONLY -> |
| 262 | % Figure 9/Q.913 |
| 263 | % Used in national interfaces only, we cannot parse Digits |
| 264 | {GTind, <<TransType:8, PhoneNum/binary>>}; |
| 265 | ?SCCP_GTI_TT_NP_ENC -> |
| 266 | % Figure 10/Q.713 |
Harald Welte | 0e1709c | 2011-02-06 22:17:53 +0100 | [diff] [blame] | 267 | {PhoneBin, OddEven} = isup_codec:encode_isup_party(PhoneNum), |
| 268 | Enc = gt_enc_by_odd(OddEven), |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 269 | {GTind, <<TransType:8, NumPlan:4, Enc:4, PhoneBin/binary>>}; |
| 270 | ?SCCP_GTI_TT_NP_ENC_NAT -> |
| 271 | % Figure 11/Q.713 |
Harald Welte | 0e1709c | 2011-02-06 22:17:53 +0100 | [diff] [blame] | 272 | {PhoneBin, OddEven} = isup_codec:encode_isup_party(PhoneNum), |
| 273 | Enc = gt_enc_by_odd(OddEven), |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 274 | {GTind, <<TransType:8, NumPlan:4, Enc:4, 0:1, Nature:7, PhoneBin/binary>>} |
| 275 | end. |
| 276 | |
Harald Welte | 683ed23 | 2011-12-08 00:56:54 +0100 | [diff] [blame] | 277 | encode_pc(PointCode) when is_integer(PointCode) -> |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 278 | case PointCode of |
Harald Welte | b5936ba | 2011-12-08 00:58:51 +0100 | [diff] [blame] | 279 | undefined -> |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 280 | {0, <<>>}; |
| 281 | _ -> |
Harald Welte | 9c3b1bb | 2011-10-12 17:00:34 +0200 | [diff] [blame] | 282 | {1, <<PointCode:16/little>>} |
Harald Welte | 683ed23 | 2011-12-08 00:56:54 +0100 | [diff] [blame] | 283 | end; |
| 284 | encode_pc(PcRec) -> |
| 285 | PcInt = osmo_util:pointcode2int(PcRec), |
| 286 | encode_pc(PcInt). |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 287 | |
| 288 | encode_ssn(SSN) -> |
| 289 | case SSN of |
Harald Welte | b5936ba | 2011-12-08 00:58:51 +0100 | [diff] [blame] | 290 | undefined -> |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 291 | {0, <<>>}; |
| 292 | _ -> |
| 293 | {1, <<SSN:8>>} |
| 294 | end. |
| 295 | |
Harald Welte | 5a1cf3c | 2011-04-14 21:55:13 +0200 | [diff] [blame] | 296 | undef_or_true(Foo) -> |
| 297 | case Foo of |
| 298 | undefined -> 0; |
| 299 | 0 -> 0; |
| 300 | _ -> 1 |
| 301 | end. |
| 302 | |
| 303 | |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 304 | encode_sccp_addr(#sccp_addr{res_nat_use = ResNatUse, |
| 305 | route_on_ssn = RoutInd, |
| 306 | point_code = PointCode, |
| 307 | ssn = SSN, |
| 308 | global_title = GT}) -> |
| 309 | |
| 310 | {GTind, GTbin} = encode_gt(GT), |
| 311 | {SSNind, SSNbin} = encode_ssn(SSN), |
| 312 | {PCind, PCbin} = encode_pc(PointCode), |
Harald Welte | 5a1cf3c | 2011-04-14 21:55:13 +0200 | [diff] [blame] | 313 | ResNatOut = undef_or_true(ResNatUse), |
| 314 | RoutIndOut = undef_or_true(RoutInd), |
| 315 | <<ResNatOut:1, RoutIndOut:1, GTind:4, SSNind:1, PCind:1, PCbin/binary, SSNbin/binary, GTbin/binary>>. |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 316 | |
| 317 | |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 318 | encode_sccp_opt({OptNum, {DataBinLen, DataBin}}) when is_integer(OptNum) -> |
| 319 | DataBinLen8 = DataBinLen*8, |
| 320 | <<OptNum:8, DataBinLen:8, DataBin:DataBinLen8>>; |
| 321 | encode_sccp_opt({OptAtom,_}) when is_atom(OptAtom) -> |
| 322 | <<>>. |
| 323 | |
| 324 | encode_sccp_opts([], OptEnc) -> |
| 325 | % end of options + convert to binary |
| 326 | list_to_binary([OptEnc, ?SCCP_PNC_END_OF_OPTIONAL]); |
| 327 | encode_sccp_opts([CurOpt|OptPropList], OptEnc) -> |
| 328 | CurOptEnc = encode_sccp_opt(CurOpt), |
| 329 | encode_sccp_opts(OptPropList, list_to_binary([OptEnc,CurOptEnc])). |
| 330 | |
| 331 | |
| 332 | |
| 333 | encode_sccp_msgt(?SCCP_MSGT_CR, Params) -> |
| 334 | SrcLocalRef = proplists:get_value(src_local_ref, Params), |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 335 | {ProtoClass, PCOpt} = proplists:get_value(protocol_class, Params), |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 336 | OptBin = encode_sccp_opts(Params, []), |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 337 | <<?SCCP_MSGT_CR:8, SrcLocalRef:24/big, PCOpt:4, ProtoClass:4, OptBin/binary>>; |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 338 | encode_sccp_msgt(?SCCP_MSGT_CC, Params) -> |
| 339 | SrcLocalRef = proplists:get_value(src_local_ref, Params), |
| 340 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 341 | {ProtoClass, PCOpt} = proplists:get_value(protocol_class, Params), |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 342 | OptBin = encode_sccp_opts(Params, []), |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 343 | <<?SCCP_MSGT_CC:8, DstLocalRef:24/big, SrcLocalRef:24/big, PCOpt:4, ProtoClass:4, OptBin/binary>>; |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 344 | encode_sccp_msgt(?SCCP_MSGT_CREF, Params) -> |
| 345 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 346 | RefusalCause = proplists:get_value(refusal_cause, Params), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 347 | OptBin = encode_sccp_opts(Params, []), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 348 | <<?SCCP_MSGT_CREF:8, DstLocalRef:24/big, RefusalCause:8, OptBin/binary>>; |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 349 | encode_sccp_msgt(?SCCP_MSGT_RLSD, Params) -> |
| 350 | SrcLocalRef = proplists:get_value(src_local_ref, Params), |
| 351 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 352 | ReleaseCause = proplists:get_value(release_cause, Params), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 353 | OptBin = encode_sccp_opts(Params, []), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 354 | <<?SCCP_MSGT_RLSD:8, DstLocalRef:24/big, SrcLocalRef:24/big, ReleaseCause:8, OptBin/binary>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 355 | encode_sccp_msgt(?SCCP_MSGT_RLC, Params) -> |
| 356 | SrcLocalRef = proplists:get_value(src_local_ref, Params), |
| 357 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 358 | <<?SCCP_MSGT_RLC:8, DstLocalRef:24/big, SrcLocalRef:24/big>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 359 | encode_sccp_msgt(?SCCP_MSGT_DT1, Params) -> |
| 360 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 361 | SegmReass = proplists:get_value(segm_reass, Params), |
Harald Welte | d9c318f | 2011-12-10 22:17:11 +0100 | [diff] [blame] | 362 | UserData = binarify(proplists:get_value(user_data, Params)), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 363 | UserDataLen = byte_size(UserData), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 364 | <<?SCCP_MSGT_DT1:8, DstLocalRef:24/big, SegmReass:8, 1:8, UserDataLen:8, UserData/binary>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 365 | encode_sccp_msgt(?SCCP_MSGT_DT2, Params) -> |
| 366 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 367 | SeqSegm = proplists:get_value(seq_segm, Params), |
Harald Welte | d9c318f | 2011-12-10 22:17:11 +0100 | [diff] [blame] | 368 | UserData = binarify(proplists:get_value(user_data, Params)), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 369 | UserDataLen = byte_size(UserData), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 370 | <<?SCCP_MSGT_DT2:8, DstLocalRef:24/big, SeqSegm:16, 1:8, UserDataLen:8, UserData/binary>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 371 | encode_sccp_msgt(?SCCP_MSGT_AK, Params) -> |
| 372 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 373 | RxSeqnr = proplists:get_value(rx_seqnr, Params), |
| 374 | Credit = proplists:get_value(credit, Params), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 375 | <<?SCCP_MSGT_AK:8, DstLocalRef:24/big, RxSeqnr:8, Credit:8>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 376 | encode_sccp_msgt(?SCCP_MSGT_UDT, Params) -> |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 377 | {ProtoClass, PCOpt} = proplists:get_value(protocol_class, Params), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 378 | CalledParty = proplists:get_value(called_party_addr, Params), |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 379 | CalledPartyEnc = encode_sccp_addr(CalledParty), |
| 380 | CalledPartyLen = byte_size(CalledPartyEnc), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 381 | CallingParty = proplists:get_value(calling_party_addr, Params), |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 382 | CallingPartyEnc = encode_sccp_addr(CallingParty), |
| 383 | CallingPartyLen = byte_size(CallingPartyEnc), |
Harald Welte | d9c318f | 2011-12-10 22:17:11 +0100 | [diff] [blame] | 384 | UserData = binarify(proplists:get_value(user_data, Params)), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 385 | UserDataLen = byte_size(UserData), |
| 386 | % variable part |
| 387 | CalledPartyPtr = 3, |
| 388 | CallingPartyPtr = 2 + (1 + CalledPartyLen), |
| 389 | DataPtr = 1 + (1 + CalledPartyLen) + (1 + CallingPartyLen), |
Harald Welte | 234c956 | 2011-02-03 13:51:12 +0100 | [diff] [blame] | 390 | Remain = <<CalledPartyLen:8, CalledPartyEnc/binary, |
| 391 | CallingPartyLen:8, CallingPartyEnc/binary, |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 392 | UserDataLen:8, UserData/binary>>, |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 393 | <<?SCCP_MSGT_UDT:8, PCOpt:4, ProtoClass:4, CalledPartyPtr:8, CallingPartyPtr:8, DataPtr:8, Remain/binary>>; |
Harald Welte | 030f109 | 2011-03-11 19:08:07 +0100 | [diff] [blame] | 394 | encode_sccp_msgt(?SCCP_MSGT_UDTS, Params) -> |
| 395 | ReturnCause = proplists:get_value(return_cause, Params), |
| 396 | CalledParty = proplists:get_value(called_party_addr, Params), |
| 397 | CalledPartyEnc = encode_sccp_addr(CalledParty), |
| 398 | CalledPartyLen = byte_size(CalledPartyEnc), |
| 399 | CallingParty = proplists:get_value(calling_party_addr, Params), |
| 400 | CallingPartyEnc = encode_sccp_addr(CallingParty), |
| 401 | CallingPartyLen = byte_size(CallingPartyEnc), |
Harald Welte | d9c318f | 2011-12-10 22:17:11 +0100 | [diff] [blame] | 402 | UserData = binarify(proplists:get_value(user_data, Params)), |
Harald Welte | 030f109 | 2011-03-11 19:08:07 +0100 | [diff] [blame] | 403 | UserDataLen = byte_size(UserData), |
| 404 | % variable part |
| 405 | CalledPartyPtr = 3, |
| 406 | CallingPartyPtr = 2 + (1 + CalledPartyLen), |
| 407 | DataPtr = 1 + (1 + CalledPartyLen) + (1 + CallingPartyLen), |
| 408 | Remain = <<CalledPartyLen:8, CalledPartyEnc/binary, |
| 409 | CallingPartyLen:8, CallingPartyEnc/binary, |
| 410 | UserDataLen:8, UserData/binary>>, |
| 411 | <<?SCCP_MSGT_UDTS:8, ReturnCause:8, CalledPartyPtr:8, CallingPartyPtr:8, DataPtr:8, Remain/binary>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 412 | encode_sccp_msgt(?SCCP_MSGT_ED, Params) -> |
| 413 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
Harald Welte | d9c318f | 2011-12-10 22:17:11 +0100 | [diff] [blame] | 414 | UserData = binarify(proplists:get_value(user_data, Params)), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 415 | UserDataLen = byte_size(UserData), |
| 416 | DataPtr = 1, |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 417 | <<?SCCP_MSGT_ED:8, DstLocalRef:24/big, DataPtr:8, UserDataLen:8, UserData/binary>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 418 | encode_sccp_msgt(?SCCP_MSGT_EA, Params) -> |
| 419 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 420 | <<?SCCP_MSGT_EA:8, DstLocalRef:24/big>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 421 | encode_sccp_msgt(?SCCP_MSGT_RSR, Params) -> |
| 422 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 423 | SrcLocalRef = proplists:get_value(src_local_ref, Params), |
| 424 | ResetCause = proplists:get_value(reset_cause, Params), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 425 | <<?SCCP_MSGT_RSR:8, DstLocalRef:24/big, SrcLocalRef:24/big, ResetCause:8>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 426 | encode_sccp_msgt(?SCCP_MSGT_RSC, Params) -> |
| 427 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 428 | SrcLocalRef = proplists:get_value(src_local_ref, Params), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 429 | <<?SCCP_MSGT_RSC:8, DstLocalRef:24/big, SrcLocalRef:24/big>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 430 | encode_sccp_msgt(?SCCP_MSGT_ERR, Params) -> |
| 431 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 432 | ErrCause = proplists:get_value(error_cause, Params), |
Harald Welte | 56ee7a6 | 2010-12-20 13:34:32 +0100 | [diff] [blame] | 433 | <<?SCCP_MSGT_ERR:8, DstLocalRef:24/big, ErrCause:8>>; |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 434 | encode_sccp_msgt(?SCCP_MSGT_IT, Params) -> |
| 435 | DstLocalRef = proplists:get_value(dst_local_ref, Params), |
| 436 | SrcLocalRef = proplists:get_value(src_local_ref, Params), |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 437 | {ProtoClass, PCOpt} = proplists:get_value(protocol_class, Params), |
Harald Welte | 09b4399 | 2010-12-20 12:21:03 +0100 | [diff] [blame] | 438 | SegmSeq = proplists:get_value(seq_segm, Params), |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 439 | Credit = proplists:get_value(credit, Params), |
Harald Welte | 1156577 | 2011-04-15 10:37:57 +0200 | [diff] [blame] | 440 | <<?SCCP_MSGT_IT:8, DstLocalRef:24/big, SrcLocalRef:24/big, PCOpt:4, ProtoClass:4, SegmSeq:16, Credit:8>>. |
Harald Welte | c0696b0 | 2010-12-20 00:09:37 +0100 | [diff] [blame] | 441 | % FIXME: XUDT/XUDTS, LUDT/LUDTS |
| 442 | |
Harald Welte | 033cef0 | 2010-12-19 22:47:14 +0100 | [diff] [blame] | 443 | |
| 444 | % encode one sccp message data structure into the on-wire format |
| 445 | encode_sccp_msg(#sccp_msg{msg_type = MsgType, parameters = Params}) -> |
| 446 | encode_sccp_msgt(MsgType, Params). |
Harald Welte | 9abbbad | 2011-04-21 12:19:41 +0200 | [diff] [blame] | 447 | |
| 448 | % is the supplied message type a connectionless message? |
| 449 | is_connectionless(#sccp_msg{msg_type = MsgType}) -> |
| 450 | is_connectionless(MsgType); |
| 451 | is_connectionless(MsgType) -> |
| 452 | case MsgType of |
| 453 | ?SCCP_MSGT_UDT -> true; |
| 454 | ?SCCP_MSGT_UDTS -> true; |
| 455 | ?SCCP_MSGT_XUDT -> true; |
| 456 | ?SCCP_MSGT_XUDTS -> true; |
| 457 | ?SCCP_MSGT_LUDT -> true; |
| 458 | ?SCCP_MSGT_LUDTS -> true; |
| 459 | _ -> false |
| 460 | end. |
Harald Welte | 9baab6d | 2011-12-08 00:46:00 +0100 | [diff] [blame] | 461 | |
| 462 | |
| 463 | gen_gt_helper(Number) when is_list(Number) -> |
| 464 | #global_title{gti=?SCCP_GTI_NAT_ONLY, |
| 465 | nature_of_addr_ind=?SCCP_NAI_INTERNATIONAL, |
| 466 | phone_number = Number}. |
| 467 | |
| 468 | gen_addr_helper(Gt, Pc, Ssn) when is_record(Gt, global_title) -> |
| 469 | #sccp_addr{point_code=Pc, ssn=Ssn, global_title=Gt}; |
| 470 | gen_addr_helper(Number, Pc, Ssn) when is_list(Number) -> |
| 471 | Gt = gen_gt_helper(Number), |
| 472 | gen_addr_helper(Gt, Pc, Ssn). |
| 473 | |
| 474 | |
| 475 | gen_addr_helper(Gt, Pc) when is_record(Gt, global_title) -> |
| 476 | #sccp_addr{point_code=Pc, global_title=Gt}; |
| 477 | gen_addr_helper(Number, Pc) when is_list(Number) -> |
| 478 | Gt = gen_gt_helper(Number), |
| 479 | gen_addr_helper(Gt, Pc). |