Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 1 | % MAP masquerading application |
| 2 | |
| 3 | % (C) 2010-2011 by Harald Welte <laforge@gnumonks.org> |
| 4 | % (C) 2010-2011 by On-Waves |
| 5 | % |
| 6 | % All Rights Reserved |
| 7 | % |
| 8 | % This program is free software; you can redistribute it and/or modify |
| 9 | % it under the terms of the GNU General Public License as published by |
| 10 | % the Free Software Foundation; either version 2 of the License, or |
| 11 | % (at your option) any later version. |
| 12 | % |
| 13 | % This program is distributed in the hope that it will be useful, |
| 14 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | % GNU General Public License for more details. |
| 17 | % |
| 18 | % You should have received a copy of the GNU General Public License along |
| 19 | % with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | % 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | |
| 22 | |
| 23 | -module(map_masq). |
| 24 | -author('Harald Welte <laforge@gnumonks.org>'). |
| 25 | %-compile(export_all). |
| 26 | |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 27 | -export([mangle_map/2, config_update/0]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 28 | |
| 29 | -include_lib("osmo_map/include/map.hrl"). |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 30 | -include_lib("osmo_ss7/include/isup.hrl"). |
| 31 | |
| 32 | % Use the MAP address translation table to alter an ISDN-Address-String |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 33 | patch_map_isdn_addr(_From, asn1_NOVALUE, _Type) -> |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 34 | asn1_NOVALUE; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 35 | patch_map_isdn_addr(From, AddrIn, Type) when is_binary(AddrIn) -> |
| 36 | patch_map_isdn_addr(From, binary_to_list(AddrIn), Type); |
| 37 | patch_map_isdn_addr(From, AddrIn, Type) when is_list(AddrIn) -> |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 38 | % obtain some configuration data |
| 39 | {ok, Tbl} = application:get_env(map_rewrite_table), |
| 40 | {ok, IntPfx} = application:get_env(intern_pfx), |
| 41 | % Decode the list of octets into an party_number |
| 42 | AddrInDec = map_codec:parse_addr_string(AddrIn), |
| 43 | % First we always internationalize the address |
Harald Welte | 6a33c1e | 2011-02-10 21:40:40 +0100 | [diff] [blame] | 44 | AddrInIntl = mgw_nat:isup_party_internationalize(AddrInDec, IntPfx), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 45 | % And then patch/replace the address digits |
| 46 | DigitsIn = AddrInIntl#party_number.phone_number, |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 47 | DigitsOut = patch_map_isdn_digits(From, DigitsIn, Type, Tbl), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 48 | AddrOutIntl = AddrInIntl#party_number{phone_number = DigitsOut}, |
| 49 | if AddrOutIntl == AddrInDec -> |
| 50 | ok; |
| 51 | true -> |
| 52 | io:format("Translating MAP-ISDN-Addess ~p ~p -> ~p~n", |
| 53 | [Type, AddrInDec, AddrOutIntl]) |
| 54 | end, |
Harald Welte | 62aa7c6 | 2011-02-10 22:52:01 +0100 | [diff] [blame] | 55 | map_codec:encode_addr_string(AddrOutIntl). |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 56 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 57 | patch_map_isdn_digits(_From, AddrIn, _Type, []) -> |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 58 | AddrIn; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 59 | patch_map_isdn_digits(From, AddrIn, TypeIn, [Head|Tail]) -> |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 60 | case Head of |
| 61 | {TypeIn, _,_, MscSide, StpSide} -> |
| 62 | if AddrIn == MscSide -> |
| 63 | StpSide; |
| 64 | AddrIn == StpSide -> |
| 65 | MscSide; |
| 66 | true -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 67 | patch_map_isdn_digits(From, AddrIn, TypeIn, Tail) |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 68 | end; |
| 69 | _ -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 70 | patch_map_isdn_digits(From, AddrIn, TypeIn, Tail) |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 71 | end. |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 72 | |
| 73 | mangle_msisdn(from_stp, _Opcode, AddrIn) -> |
| 74 | {ok, IntPfx} = application:get_env(intern_pfx), |
Harald Welte | 6a33c1e | 2011-02-10 21:40:40 +0100 | [diff] [blame] | 75 | mgw_nat:isup_party_internationalize(AddrIn, IntPfx). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 76 | |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 77 | % Someobdy inquires on Routing Info for a MS (from HLR) |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 78 | patch(From = from_stp, #'SendRoutingInfoArg'{msisdn = Msisdn,'gmsc-OrGsmSCF-Address'=GmscAddr} = P) -> |
Harald Welte | e78474e | 2011-02-10 21:04:52 +0100 | [diff] [blame] | 79 | % First Translate the MSISDN into international |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 80 | AddrInDec = map_codec:parse_addr_string(Msisdn), |
| 81 | io:format("MSISDN IN = ~p~n", [AddrInDec]), |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 82 | AddrOutDec = mangle_msisdn(From, 22, AddrInDec), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 83 | io:format("MSISDN OUT = ~p~n", [AddrOutDec]), |
| 84 | AddrOutBin = map_codec:encode_addr_string(AddrOutDec), |
Harald Welte | e78474e | 2011-02-10 21:04:52 +0100 | [diff] [blame] | 85 | % Second, try to masquerade the G-MSC |
| 86 | GmscInDec = map_codec:parse_addr_string(GmscAddr), |
| 87 | case sccp_masq:lookup_masq_addr(orig, GmscInDec#party_number.phone_number) of |
| 88 | undef -> |
| 89 | GmscOut = GmscAddr; |
| 90 | GmscOutDigits -> |
| 91 | GmscOutDec = GmscInDec#party_number{phone_number = GmscOutDigits}, |
| 92 | GmscOut = map_codec:encode_addr_string(GmscOutDec) |
| 93 | end, |
| 94 | P#'SendRoutingInfoArg'{msisdn = AddrOutBin, 'gmsc-OrGsmSCF-Address' = GmscOut}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 95 | |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 96 | % HLR responds with Routing Info for a MS |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 97 | patch(From, #'SendRoutingInfoRes'{extendedRoutingInfo = ExtRoutInfo, |
Holger Hans Peter Freyther | 016e306 | 2011-02-21 22:04:38 +0100 | [diff] [blame] | 98 | subscriberInfo = SubscriberInfo, |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 99 | 'vmsc-Address' = VmscAddress} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 100 | VmscAddrOut = patch_map_isdn_addr(From, VmscAddress, msc), |
| 101 | P#'SendRoutingInfoRes'{extendedRoutingInfo = patch(From, ExtRoutInfo), |
| 102 | 'subscriberInfo' = patch(From, SubscriberInfo), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 103 | 'vmsc-Address' = VmscAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 104 | patch(From, #'CamelRoutingInfo'{gmscCamelSubscriptionInfo = GmscCamelSI} = P) -> |
| 105 | P#'CamelRoutingInfo'{gmscCamelSubscriptionInfo = patch(From, GmscCamelSI)}; |
| 106 | patch(From, {camelRoutingInfo, CRI}) -> |
| 107 | {camelRoutingInfo, patch(From, CRI)}; |
| 108 | patch(From, {routingInfo, RI}) -> |
| 109 | {routingInfo, patch(From, RI)}; |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 110 | |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 111 | % HLR responds to inquiring MSC indicating the current serving MSC number |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 112 | patch(From, #'RoutingInfoForSM-Res'{locationInfoWithLMSI = LocInf} = P) -> |
| 113 | P#'RoutingInfoForSM-Res'{locationInfoWithLMSI = patch(From, LocInf)}; |
| 114 | patch(From, #'LocationInfoWithLMSI'{'networkNode-Number' = NetNodeNr} = P) -> |
| 115 | NetNodeNrOut = patch_map_isdn_addr(From, NetNodeNr, msc), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 116 | P#'LocationInfoWithLMSI'{'networkNode-Number' = NetNodeNrOut}; |
| 117 | |
Harald Welte | df81bdd | 2011-02-10 17:21:26 +0100 | [diff] [blame] | 118 | % patch the roaming number as it is sent from HLR to G-MSC (SRI Resp) |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 119 | patch(_From, {roamingNumber, RoamNumTBCD}) -> |
Harald Welte | df81bdd | 2011-02-10 17:21:26 +0100 | [diff] [blame] | 120 | RoamNumIn = map_codec:parse_addr_string(RoamNumTBCD), |
| 121 | io:format("Roaming Number IN = ~p~n", [RoamNumIn]), |
| 122 | {ok, MsrnPfxStp} = application:get_env(msrn_pfx_stp), |
| 123 | {ok, MsrnPfxMsc} = application:get_env(msrn_pfx_msc), |
Harald Welte | 6a33c1e | 2011-02-10 21:40:40 +0100 | [diff] [blame] | 124 | RoamNumOut = mgw_nat:isup_party_replace_prefix(RoamNumIn, MsrnPfxMsc, MsrnPfxStp), |
Harald Welte | df81bdd | 2011-02-10 17:21:26 +0100 | [diff] [blame] | 125 | io:format("Roaming Number OUT = ~p~n", [RoamNumOut]), |
| 126 | RoamNumOutTBCD = map_codec:encode_addr_string(RoamNumOut), |
| 127 | {roamingNumber, RoamNumOutTBCD}; |
| 128 | |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 129 | |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 130 | % patch a UpdateGprsLocationArg and replace SGSN number and SGSN address |
| 131 | % !!! TESTING ONLY !!! |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 132 | patch(From, #'UpdateGprsLocationArg'{'sgsn-Number' = SgsnNum, |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 133 | 'sgsn-Address' = SgsnAddr} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 134 | SgsnNumOut = patch_map_isdn_addr(From, SgsnNum, sgsn), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 135 | P#'UpdateGprsLocationArg'{'sgsn-Number'= SgsnNumOut, |
| 136 | 'sgsn-Address' = SgsnAddr}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 137 | |
| 138 | % Some other SGSN is sendingu us a GPRS location update. In the response, |
| 139 | % we indicate teh HLR number, which we need to masquerade |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 140 | patch(From, #'UpdateGprsLocationRes'{'hlr-Number' = HlrNum} = P) -> |
| 141 | HlrNumOut = patch_map_isdn_addr(From, HlrNum, hlr), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 142 | P#'UpdateGprsLocationRes'{'hlr-Number' = HlrNumOut}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 143 | |
| 144 | % Some other MSC/VLR is sendingu us a GSM location update. In the response, |
| 145 | % we indicate teh HLR number, which we need to masquerade |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 146 | patch(From, #'UpdateLocationRes'{'hlr-Number' = HlrNum} = P) -> |
| 147 | HlrNumOut = patch_map_isdn_addr(From, HlrNum, hlr), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 148 | P#'UpdateLocationRes'{'hlr-Number' = HlrNumOut}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 149 | |
| 150 | % HLR responds to VLR's MAP_RESTORE_REQ (i.e. it has lost information) |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 151 | patch(From, #'RestoreDataRes'{'hlr-Number' = HlrNum} = P) -> |
| 152 | HlrNumOut = patch_map_isdn_addr(From, HlrNum, hlr), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 153 | P#'RestoreDataRes'{'hlr-Number' = HlrNumOut}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 154 | |
| 155 | % HLR sends subscriber data to VLR/SGSN, including CAMEL info |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 156 | patch(From, #'InsertSubscriberDataArg'{'vlrCamelSubscriptionInfo'=VlrCamel, |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 157 | 'sgsn-CAMEL-SubscriptionInfo'=SgsnCamel} = Arg) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 158 | Arg#'InsertSubscriberDataArg'{'vlrCamelSubscriptionInfo'=patch(From, VlrCamel), |
| 159 | 'sgsn-CAMEL-SubscriptionInfo'=patch(From, SgsnCamel)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 160 | |
| 161 | % HLR sends subscriber data to gsmSCF |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 162 | patch(From, #'AnyTimeSubscriptionInterrogationRes'{'camel-SubscriptionInfo'=Csi} = P) -> |
| 163 | P#'AnyTimeSubscriptionInterrogationRes'{'camel-SubscriptionInfo'=patch(From, Csi)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 164 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 165 | patch(From, asn1_NOVALUE) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 166 | asn1_NOVALUE; |
| 167 | |
| 168 | % CAMEL related parsing |
| 169 | |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 170 | % this is part of the SRI Response (HLR->GMSC) |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 171 | patch(From, #'GmscCamelSubscriptionInfo'{'o-CSI'=Ocsi, 't-CSI'=Tcsi, |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 172 | 'd-csi'=Dcsi} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 173 | P#'GmscCamelSubscriptionInfo'{'o-CSI'=patch(From, Ocsi), |
| 174 | 't-CSI'=patch(From, Tcsi), |
| 175 | 'd-csi'=patch(From, Dcsi)}; |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 176 | |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 177 | % this is part of the InsertSubscriberData HLR -> VLR |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 178 | patch(From, #'VlrCamelSubscriptionInfo'{'o-CSI'=Ocsi, 'mo-sms-CSI'=MoSmsCsi, |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 179 | 'mt-sms-CSI'=MtSmsCsi, 'ss-CSI'=SsCsi} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 180 | P#'VlrCamelSubscriptionInfo'{'o-CSI'=patch(From, Ocsi), |
| 181 | 'mo-sms-CSI'=patch(From, MoSmsCsi), |
| 182 | 'mt-sms-CSI'=patch(From, MtSmsCsi), |
| 183 | 'ss-CSI'=patch(From, SsCsi)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 184 | |
| 185 | % this is part of the InsertSubscriberData HLR -> SGSN |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 186 | patch(From, #'SGSN-CAMEL-SubscriptionInfo'{'gprs-CSI'=GprsCsi, |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 187 | 'mo-sms-CSI'=MoSmsCsi, |
| 188 | 'mt-sms-CSI'=MtSmsCsi} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 189 | P#'SGSN-CAMEL-SubscriptionInfo'{'gprs-CSI'=patch(From, GprsCsi), |
| 190 | 'mo-sms-CSI'=patch(From, MoSmsCsi), |
| 191 | 'mt-sms-CSI'=patch(From, MtSmsCsi)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 192 | |
| 193 | % this is part of the Anytime Subscription Interrogation Result HLR->gsmSCF |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 194 | patch(From, #'CAMEL-SubscriptionInfo'{'o-CSI'=Ocsi, |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 195 | 'd-CSI'=Dcsi, |
| 196 | 't-CSI'=Tcsi, |
| 197 | 'vt-CSI'=Vtcsi, |
| 198 | %'tif-CSI'=Tifcsi, |
| 199 | 'gprs-CSI'=GprsCsi, |
| 200 | 'mo-sms-CSI'=MoSmsCsi, |
| 201 | 'ss-CSI'=SsCsi, |
| 202 | 'm-CSI'=Mcsi, |
| 203 | 'mt-sms-CSI'=MtSmsCsi, |
| 204 | 'mg-csi'=MgCsi, |
| 205 | 'o-IM-CSI'=OimCsi, |
| 206 | 'd-IM-CSI'=DimCsi, |
| 207 | 'vt-IM-CSI'=VtImCsi} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 208 | P#'CAMEL-SubscriptionInfo'{'o-CSI'=patch(From, Ocsi), |
| 209 | 'd-CSI'=patch(From, Dcsi), |
| 210 | 't-CSI'=patch(From, Tcsi), |
| 211 | 'vt-CSI'=patch(From, Vtcsi), |
| 212 | 'gprs-CSI'=patch(From, GprsCsi), |
| 213 | 'mo-sms-CSI'=patch(From, MoSmsCsi), |
| 214 | 'ss-CSI'=patch(From, SsCsi), |
| 215 | 'm-CSI'=patch(From, Mcsi), |
| 216 | 'mt-sms-CSI'=patch(From, MtSmsCsi), |
| 217 | 'mg-csi'=patch(From, MgCsi), |
| 218 | 'o-IM-CSI'=patch(From, OimCsi), |
| 219 | 'd-IM-CSI'=patch(From, DimCsi), |
| 220 | 'vt-IM-CSI'=patch(From, VtImCsi)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 221 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 222 | patch(From, #'T-CSI'{'t-BcsmCamelTDPDataList'=TdpList} = P) -> |
| 223 | P#'T-CSI'{'t-BcsmCamelTDPDataList'=patch_tBcsmCamelTDPDataList(From, TdpList)}; |
| 224 | patch(From, #'M-CSI'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 225 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 226 | P#'M-CSI'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 227 | patch(From, #'MG-CSI'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 228 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 229 | P#'MG-CSI'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 230 | patch(From, #'O-CSI'{'o-BcsmCamelTDPDataList'=TdpList} = P) -> |
| 231 | P#'O-CSI'{'o-BcsmCamelTDPDataList'=patch_oBcsmCamelTDPDataList(From, TdpList)}; |
| 232 | patch(From, #'D-CSI'{'dp-AnalysedInfoCriteriaList'=List} = P) -> |
| 233 | P#'D-CSI'{'dp-AnalysedInfoCriteriaList'=patch_AnInfoCritList(From, List)}; |
| 234 | patch(From, #'SMS-CSI'{'sms-CAMEL-TDP-DataList'=TdpList} = P) -> |
| 235 | P#'SMS-CSI'{'sms-CAMEL-TDP-DataList'=patch_SmsCamelTDPDataList(From, TdpList)}; |
| 236 | patch(From, #'SS-CSI'{'ss-CamelData'=Sscd} = P) -> |
| 237 | P#'SS-CSI'{'ss-CamelData'=patch(From, Sscd)}; |
| 238 | patch(From, #'GPRS-CSI'{'gprs-CamelTDPDataList'=TdpList} = P) -> |
| 239 | P#'GPRS-CSI'{'gprs-CamelTDPDataList'=patch_GprsCamelTDPDataList(From, TdpList)}; |
| 240 | patch(From, #'SS-CamelData'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 241 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 242 | P#'SS-CamelData'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 243 | patch(From, #'O-BcsmCamelTDPData'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 244 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 245 | P#'O-BcsmCamelTDPData'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 246 | patch(From, #'T-BcsmCamelTDPData'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 247 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Holger Hans Peter Freyther | 60e0fb2 | 2011-02-21 21:02:08 +0100 | [diff] [blame] | 248 | P#'T-BcsmCamelTDPData'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 249 | patch(From, #'SMS-CAMEL-TDP-Data'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 250 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 251 | P#'SMS-CAMEL-TDP-Data'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 252 | patch(From, #'GPRS-CamelTDPData'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 253 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 254 | P#'GPRS-CamelTDPData'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 255 | patch(From, #'DP-AnalysedInfoCriterium'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 256 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 257 | P#'DP-AnalysedInfoCriterium'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 258 | patch(From, #'SubscriberInfo'{'locationInformation'=LocInformation} = P) -> |
| 259 | P#'SubscriberInfo'{'locationInformation'=patch(From, LocInformation)}; |
| 260 | patch(From, #'LocationInformation'{'vlr-number'=VlrNumber} = P) -> |
| 261 | VlrNumberOut = patch_map_isdn_addr(From, VlrNumber, vlr), |
Holger Hans Peter Freyther | 016e306 | 2011-02-21 22:04:38 +0100 | [diff] [blame] | 262 | P#'LocationInformation'{'vlr-number'=VlrNumberOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 263 | patch(From, #'MO-ForwardSM-Arg'{'sm-RP-DA'=SC} = P) -> |
| 264 | NewSC = patch_scaddr(From, SC), |
Holger Hans Peter Freyther | e86edbd | 2011-02-22 23:24:55 +0100 | [diff] [blame] | 265 | P#'MO-ForwardSM-Arg'{'sm-RP-DA'=NewSC}; |
Holger Hans Peter Freyther | 016e306 | 2011-02-21 22:04:38 +0100 | [diff] [blame] | 266 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 267 | patch(_From, Default) -> |
Harald Welte | c752362 | 2011-02-10 14:42:31 +0100 | [diff] [blame] | 268 | Default. |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 269 | |
Holger Hans Peter Freyther | e86edbd | 2011-02-22 23:24:55 +0100 | [diff] [blame] | 270 | %rewrite the serviceCentreAddressDA |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 271 | patch_scaddr(From, {serviceCentreAddressDA,Ar}) -> |
| 272 | NewAddr = patch_map_isdn_addr(From, Ar, smsCDA), |
Holger Hans Peter Freyther | e86edbd | 2011-02-22 23:24:55 +0100 | [diff] [blame] | 273 | {serviceCentreAddressDA,NewAddr}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 274 | patch_scaddr(From, Default) -> |
Holger Hans Peter Freyther | e86edbd | 2011-02-22 23:24:55 +0100 | [diff] [blame] | 275 | Default. |
| 276 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 277 | patch_oBcsmCamelTDPDataList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 278 | % we reverse the origianl list, as the tail recursive _acc function |
| 279 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 280 | patch_oBcsmCamelTDPDataList_acc(From, lists:reverse(List), []). |
| 281 | patch_oBcsmCamelTDPDataList_acc(From, [], NewList) -> NewList; |
| 282 | patch_oBcsmCamelTDPDataList_acc(From, [TdpData|Tail], NewList) -> |
| 283 | NewTdpData = patch(From, TdpData#'O-BcsmCamelTDPData'{}), |
| 284 | patch_oBcsmCamelTDPDataList_acc(From, Tail, [NewTdpData|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 285 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 286 | patch_tBcsmCamelTDPDataList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 287 | % we reverse the origianl list, as the tail recursive _acc function |
| 288 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 289 | patch_tBcsmCamelTDPDataList_acc(From, lists:reverse(List), []). |
| 290 | patch_tBcsmCamelTDPDataList_acc(From, [], NewList) -> NewList; |
| 291 | patch_tBcsmCamelTDPDataList_acc(From, [TdpData|Tail], NewList) -> |
| 292 | NewTdpData = patch(From, TdpData#'T-BcsmCamelTDPData'{}), |
| 293 | patch_tBcsmCamelTDPDataList_acc(From, Tail, [NewTdpData|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 294 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 295 | patch_AnInfoCritList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 296 | % we reverse the origianl list, as the tail recursive _acc function |
| 297 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 298 | patch_AnInfoCritList_acc(From, lists:reverse(List), []). |
| 299 | patch_AnInfoCritList_acc(From, [], NewList) -> NewList; |
| 300 | patch_AnInfoCritList_acc(From, [Crit|Tail], NewList) -> |
| 301 | NewCrit = patch(From, Crit#'DP-AnalysedInfoCriterium'{}), |
| 302 | patch_AnInfoCritList_acc(From, Tail, [NewCrit|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 303 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 304 | patch_GprsCamelTDPDataList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 305 | % we reverse the origianl list, as the tail recursive _acc function |
| 306 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 307 | patch_GprsCamelTDPDataList_acc(From, lists:reverse(List), []). |
| 308 | patch_GprsCamelTDPDataList_acc(_From, [], NewList) -> NewList; |
| 309 | patch_GprsCamelTDPDataList_acc(From, [TdpData|Tail], NewList) -> |
| 310 | NewTdpData = patch(From, TdpData#'GPRS-CamelTDPData'{}), |
| 311 | patch_GprsCamelTDPDataList_acc(From, Tail, [NewTdpData|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 312 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 313 | patch_SmsCamelTDPDataList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 314 | % we reverse the origianl list, as the tail recursive _acc function |
| 315 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 316 | patch_SmsCamelTDPDataList_acc(From, lists:reverse(List), []). |
| 317 | patch_SmsCamelTDPDataList_acc(From, [], NewList) -> NewList; |
| 318 | patch_SmsCamelTDPDataList_acc(From, [TdpData|Tail], NewList) -> |
| 319 | NewTdpData = patch(From, TdpData#'SMS-CAMEL-TDP-Data'{}), |
| 320 | patch_GprsCamelTDPDataList_acc(From, Tail, [NewTdpData|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 321 | |
| 322 | |
| 323 | |
| 324 | % process the Argument of a particular MAP invocation |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 325 | process_component_arg(From, OpCode, Arg) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 326 | case Arg of |
| 327 | asn1_NOVALUE -> Arg; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame^] | 328 | _ -> patch(From,Arg) |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 329 | end. |
| 330 | |
| 331 | % recurse over all components |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 332 | handle_tcap_components(_From, asn1_NOVALUE) -> |
Harald Welte | 17f6474 | 2011-02-10 18:29:59 +0100 | [diff] [blame] | 333 | asn1_NOVALUE; |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 334 | handle_tcap_components(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 335 | % we reverse the origianl list, as the tail recursive _acc function |
| 336 | % will invert the order of components again |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 337 | handle_tcap_components_acc(From, lists:reverse(List), []). |
| 338 | handle_tcap_components_acc(_From, [], NewComponents) -> NewComponents; |
| 339 | handle_tcap_components_acc(From, [Component|Tail], NewComponents) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 340 | case Component of |
| 341 | {basicROS, {Primitive, Body}} -> |
| 342 | io:format("handle component ~p primitive ~n", [Component]), |
| 343 | case Body of |
| 344 | % BEGIN |
| 345 | #'MapSpecificPDUs_begin_components_SEQOF_basicROS_invoke'{opcode={local, OpCode}, |
| 346 | argument=Arg} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 347 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 348 | NewBody = Body#'MapSpecificPDUs_begin_components_SEQOF_basicROS_invoke'{argument=NewArg}; |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 349 | #'MapSpecificPDUs_begin_components_SEQOF_basicROS_returnResult'{result=#'MapSpecificPDUs_begin_components_SEQOF_basicROS_returnResult_result'{opcode={local, OpCode}, result=Arg} = R} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 350 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 351 | NewBody = Body#'MapSpecificPDUs_begin_components_SEQOF_basicROS_returnResult'{result=R#'MapSpecificPDUs_begin_components_SEQOF_basicROS_returnResult_result'{result=NewArg}}; |
| 352 | #'MapSpecificPDUs_begin_components_SEQOF_returnResultNotLast'{result=#'MapSpecificPDUs_begin_components_SEQOF_returnResultNotLast_result'{opcode={local, OpCode}, result=Arg} = R} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 353 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 354 | NewBody = Body#'MapSpecificPDUs_begin_components_SEQOF_returnResultNotLast'{result=R#'MapSpecificPDUs_begin_components_SEQOF_returnResultNotLast_result'{result=NewArg}}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 355 | % END |
| 356 | #'MapSpecificPDUs_end_components_SEQOF_basicROS_invoke'{opcode={local, OpCode}, |
| 357 | argument=Arg} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 358 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 359 | NewBody = Body#'MapSpecificPDUs_end_components_SEQOF_basicROS_invoke'{argument=NewArg}; |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 360 | #'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult'{result=#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult_result'{opcode={local, OpCode}, result=Arg} = R} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 361 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 362 | NewBody = Body#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult'{result=R#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult_result'{result=NewArg}}; |
| 363 | #'MapSpecificPDUs_end_components_SEQOF_returnResultNotLast'{result=#'MapSpecificPDUs_end_components_SEQOF_returnResultNotLast_result'{opcode={local, OpCode}, result=Arg} = R} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 364 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 365 | NewBody = Body#'MapSpecificPDUs_end_components_SEQOF_returnResultNotLast'{result=R#'MapSpecificPDUs_end_components_SEQOF_returnResultNotLast_result'{result=NewArg}}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 366 | % CONTINUE |
| 367 | #'MapSpecificPDUs_continue_components_SEQOF_basicROS_invoke'{opcode={local, OpCode}, |
| 368 | argument=Arg} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 369 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 370 | NewBody = Body#'MapSpecificPDUs_continue_components_SEQOF_basicROS_invoke'{argument=NewArg}; |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 371 | #'MapSpecificPDUs_continue_components_SEQOF_basicROS_returnResult'{result=#'MapSpecificPDUs_continue_components_SEQOF_basicROS_returnResult_result'{opcode={local, OpCode}, result=Arg} = R} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 372 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 373 | NewBody = Body#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult'{result=R#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult_result'{result=NewArg}}; |
| 374 | #'MapSpecificPDUs_continue_components_SEQOF_returnResultNotLast'{result=#'MapSpecificPDUs_continue_components_SEQOF_returnResultNotLast_result'{opcode={local, OpCode}, result=Arg} = R} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 375 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 376 | NewBody = Body#'MapSpecificPDUs_continue_components_SEQOF_returnResultNotLast'{result=R#'MapSpecificPDUs_continue_components_SEQOF_returnResultNotLast_result'{result=NewArg}}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 377 | _ -> |
| 378 | NewBody = Body |
| 379 | end, |
| 380 | %NewBody = setelement(5, Body, NewArg) |
| 381 | NewComponent = {basicROS, {Primitive, NewBody}}; |
| 382 | _ -> |
| 383 | NewComponent = Component |
| 384 | end, |
| 385 | io:format("=> modified component ~p~n", [NewComponent]), |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 386 | handle_tcap_components_acc(From, Tail, [NewComponent|NewComponents]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 387 | |
| 388 | |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 389 | % Erlang asn1rt has this strange property that all incoming EXTERNAL types are |
| 390 | % converted from the 1990 version into the 1994 version. The latter does not |
| 391 | % preserve the encoding (octet string, single ASN1 type, ...). During encoding, |
| 392 | % it then uses the OCTTET-STRING encoding, which is different from the MAP |
| 393 | % customary single-ASN1-type format. |
Harald Welte | c506fe5 | 2011-02-10 13:09:44 +0100 | [diff] [blame] | 394 | asn1_EXTERNAL1994_fixup({'EXTERNAL', DirRef, IndRef, Data}) when is_list(Data);is_binary(Data) -> |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 395 | % our trick is as follows: we simply convert back to 1990 format, and explicitly |
| 396 | % set the single-ASN1-type encoding. asn1rt:s 'enc_EXTERNAL'() will detect this |
| 397 | #'EXTERNAL'{'direct-reference' = DirRef, 'indirect-reference' = IndRef, |
| 398 | 'encoding' = {'single-ASN1-type', Data}}; |
| 399 | asn1_EXTERNAL1994_fixup(Foo) -> |
| 400 | Foo. |
| 401 | |
| 402 | |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 403 | handle_tcap_dialogue(_From, Foo = {'EXTERNAL', DirRef, IndRef, Data}) -> |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 404 | asn1_EXTERNAL1994_fixup(Foo); |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 405 | handle_tcap_dialogue(_From, Foo) -> |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 406 | Foo. |
| 407 | |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 408 | |
| 409 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 410 | % Actual mangling of the decoded MAP messages |
| 411 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 412 | mangle_map(From, {Type, TcapMsgDec}) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 413 | case {Type, TcapMsgDec} of |
| 414 | {'unidirectional', #'MapSpecificPDUs_unidirectional'{dialoguePortion=Dialg, |
| 415 | components=Components}} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 416 | NewDialg = handle_tcap_dialogue(From, Dialg), |
| 417 | NewComponents = handle_tcap_components(From, Components), |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 418 | NewTcapMsgDec = TcapMsgDec#'MapSpecificPDUs_unidirectional'{dialoguePortion=NewDialg, components=NewComponents}; |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 419 | {'begin', #'MapSpecificPDUs_begin'{dialoguePortion=Dialg, components=Components}} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 420 | NewDialg = handle_tcap_dialogue(From, Dialg), |
| 421 | NewComponents = handle_tcap_components(From, Components), |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 422 | NewTcapMsgDec = TcapMsgDec#'MapSpecificPDUs_begin'{dialoguePortion=NewDialg, components=NewComponents}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 423 | {'continue', #'MapSpecificPDUs_continue'{dialoguePortion=Dialg, components=Components}} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 424 | NewDialg = handle_tcap_dialogue(From, Dialg), |
| 425 | NewComponents = handle_tcap_components(From, Components), |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 426 | NewTcapMsgDec = TcapMsgDec#'MapSpecificPDUs_continue'{dialoguePortion=NewDialg, components=NewComponents}; |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 427 | {'end', #'MapSpecificPDUs_end'{dialoguePortion=Dialg, components=Components}} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 428 | NewDialg = handle_tcap_dialogue(From, Dialg), |
| 429 | NewComponents = handle_tcap_components(From, Components), |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 430 | NewTcapMsgDec = TcapMsgDec#'MapSpecificPDUs_end'{dialoguePortion=NewDialg, components=NewComponents}; |
| 431 | %{_, #'Abort'{reason=Reason} -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 432 | _ -> |
| 433 | NewTcapMsgDec = TcapMsgDec |
| 434 | end, |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 435 | io:format("new TcapMsgDec (Type=~p) ~p~n", [Type, NewTcapMsgDec]), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 436 | {Type, NewTcapMsgDec}. |
| 437 | |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 438 | |
| 439 | % Configuration file has changed, re-generate internal data structures |
| 440 | config_update() -> |
| 441 | % (re-)generate the MAP Address rewrite table |
Harald Welte | 6009f6e | 2011-02-10 21:41:50 +0100 | [diff] [blame] | 442 | {ok, MapRewriteTbl} = application:get_env(mgw_nat, map_rewrite_table), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 443 | MapRewriteTblOut = generate_rewrite_table(MapRewriteTbl), |
Harald Welte | 6009f6e | 2011-02-10 21:41:50 +0100 | [diff] [blame] | 444 | application:set_env(mgw_nat, map_rewrite_table, MapRewriteTblOut), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 445 | %{ok, MsrnPfxStp} = application:get_env(msrn_pfx_stp), |
| 446 | %{ok, MsrnPfxMsc} = application:get_env(msrn_pfx_msc), |
| 447 | %{ok, IntPfx} = application:get_env(intern_pfx), |
| 448 | ok. |
| 449 | |
| 450 | % Generate the full MAP address rewrite table |
| 451 | generate_rewrite_table(List) when is_list(List) -> |
| 452 | generate_rewrite_table(List, []). |
| 453 | generate_rewrite_table([], OutList) -> |
| 454 | io:format("(Re)generated MAP ISDN-Address rewrite table: ~p~n", [OutList]), |
| 455 | OutList; |
| 456 | generate_rewrite_table([Head|Tail], OutList) -> |
| 457 | NewItem = generate_rewrite_entry(Head), |
| 458 | generate_rewrite_table(Tail, [NewItem|OutList]). |
| 459 | |
| 460 | % Generate a MAP Address rewrite table entry |
| 461 | generate_rewrite_entry({Name, MscSideInt, StpSideInt}) -> |
| 462 | MscSideList = osmo_util:int2digit_list(MscSideInt), |
| 463 | StpSideList = osmo_util:int2digit_list(StpSideInt), |
| 464 | {Name, MscSideInt, StpSideInt, MscSideList, StpSideList}. |