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 | 22a2b03 | 2011-02-25 17:04:57 +0100 | [diff] [blame] | 96 | % Someobdy inquires on Routing Info for a MS (from our HLR -> STP) |
| 97 | patch(from_msc, #'SendRoutingInfoArg'{'gmsc-OrGsmSCF-Address'=GmscAddr} = P) -> |
| 98 | % try to translate the G-MSC |
| 99 | GmscInDec = map_codec:parse_addr_string(GmscAddr), |
| 100 | case sccp_masq:lookup_masq_addr(rev, GmscInDec#party_number.phone_number) of |
| 101 | undef -> |
| 102 | GmscOut = GmscAddr; |
| 103 | GmscOutDigits -> |
| 104 | GmscOutDec = GmscInDec#party_number{phone_number = GmscOutDigits}, |
| 105 | GmscOut = map_codec:encode_addr_string(GmscOutDec) |
| 106 | end, |
| 107 | P#'SendRoutingInfoArg'{'gmsc-OrGsmSCF-Address' = GmscOut}; |
| 108 | |
| 109 | |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 110 | % HLR responds with Routing Info for a MS |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 111 | patch(From, #'SendRoutingInfoRes'{extendedRoutingInfo = ExtRoutInfo, |
Holger Hans Peter Freyther | 016e306 | 2011-02-21 22:04:38 +0100 | [diff] [blame] | 112 | subscriberInfo = SubscriberInfo, |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 113 | 'vmsc-Address' = VmscAddress} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 114 | VmscAddrOut = patch_map_isdn_addr(From, VmscAddress, msc), |
| 115 | P#'SendRoutingInfoRes'{extendedRoutingInfo = patch(From, ExtRoutInfo), |
| 116 | 'subscriberInfo' = patch(From, SubscriberInfo), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 117 | 'vmsc-Address' = VmscAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 118 | patch(From, #'CamelRoutingInfo'{gmscCamelSubscriptionInfo = GmscCamelSI} = P) -> |
| 119 | P#'CamelRoutingInfo'{gmscCamelSubscriptionInfo = patch(From, GmscCamelSI)}; |
| 120 | patch(From, {camelRoutingInfo, CRI}) -> |
| 121 | {camelRoutingInfo, patch(From, CRI)}; |
| 122 | patch(From, {routingInfo, RI}) -> |
| 123 | {routingInfo, patch(From, RI)}; |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 124 | |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 125 | % HLR responds to inquiring MSC indicating the current serving MSC number |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 126 | patch(From, #'RoutingInfoForSM-Res'{locationInfoWithLMSI = LocInf} = P) -> |
| 127 | P#'RoutingInfoForSM-Res'{locationInfoWithLMSI = patch(From, LocInf)}; |
| 128 | patch(From, #'LocationInfoWithLMSI'{'networkNode-Number' = NetNodeNr} = P) -> |
| 129 | NetNodeNrOut = patch_map_isdn_addr(From, NetNodeNr, msc), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 130 | P#'LocationInfoWithLMSI'{'networkNode-Number' = NetNodeNrOut}; |
| 131 | |
Harald Welte | df81bdd | 2011-02-10 17:21:26 +0100 | [diff] [blame] | 132 | % 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] | 133 | patch(_From, {roamingNumber, RoamNumTBCD}) -> |
Harald Welte | df81bdd | 2011-02-10 17:21:26 +0100 | [diff] [blame] | 134 | RoamNumIn = map_codec:parse_addr_string(RoamNumTBCD), |
| 135 | io:format("Roaming Number IN = ~p~n", [RoamNumIn]), |
| 136 | {ok, MsrnPfxStp} = application:get_env(msrn_pfx_stp), |
| 137 | {ok, MsrnPfxMsc} = application:get_env(msrn_pfx_msc), |
Harald Welte | 6a33c1e | 2011-02-10 21:40:40 +0100 | [diff] [blame] | 138 | RoamNumOut = mgw_nat:isup_party_replace_prefix(RoamNumIn, MsrnPfxMsc, MsrnPfxStp), |
Harald Welte | df81bdd | 2011-02-10 17:21:26 +0100 | [diff] [blame] | 139 | io:format("Roaming Number OUT = ~p~n", [RoamNumOut]), |
| 140 | RoamNumOutTBCD = map_codec:encode_addr_string(RoamNumOut), |
| 141 | {roamingNumber, RoamNumOutTBCD}; |
| 142 | |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 143 | |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 144 | % patch a UpdateGprsLocationArg and replace SGSN number and SGSN address |
| 145 | % !!! TESTING ONLY !!! |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 146 | patch(From, #'UpdateGprsLocationArg'{'sgsn-Number' = SgsnNum, |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 147 | 'sgsn-Address' = SgsnAddr} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 148 | SgsnNumOut = patch_map_isdn_addr(From, SgsnNum, sgsn), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 149 | P#'UpdateGprsLocationArg'{'sgsn-Number'= SgsnNumOut, |
| 150 | 'sgsn-Address' = SgsnAddr}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 151 | |
| 152 | % Some other SGSN is sendingu us a GPRS location update. In the response, |
| 153 | % we indicate teh HLR number, which we need to masquerade |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 154 | patch(From, #'UpdateGprsLocationRes'{'hlr-Number' = HlrNum} = P) -> |
| 155 | HlrNumOut = patch_map_isdn_addr(From, HlrNum, hlr), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 156 | P#'UpdateGprsLocationRes'{'hlr-Number' = HlrNumOut}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 157 | |
| 158 | % Some other MSC/VLR is sendingu us a GSM location update. In the response, |
| 159 | % we indicate teh HLR number, which we need to masquerade |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 160 | patch(From, #'UpdateLocationRes'{'hlr-Number' = HlrNum} = P) -> |
| 161 | HlrNumOut = patch_map_isdn_addr(From, HlrNum, hlr), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 162 | P#'UpdateLocationRes'{'hlr-Number' = HlrNumOut}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 163 | |
| 164 | % 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] | 165 | patch(From, #'RestoreDataRes'{'hlr-Number' = HlrNum} = P) -> |
| 166 | HlrNumOut = patch_map_isdn_addr(From, HlrNum, hlr), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 167 | P#'RestoreDataRes'{'hlr-Number' = HlrNumOut}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 168 | |
| 169 | % HLR sends subscriber data to VLR/SGSN, including CAMEL info |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 170 | patch(From, #'InsertSubscriberDataArg'{'vlrCamelSubscriptionInfo'=VlrCamel, |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 171 | 'sgsn-CAMEL-SubscriptionInfo'=SgsnCamel} = Arg) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 172 | Arg#'InsertSubscriberDataArg'{'vlrCamelSubscriptionInfo'=patch(From, VlrCamel), |
| 173 | 'sgsn-CAMEL-SubscriptionInfo'=patch(From, SgsnCamel)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 174 | |
| 175 | % HLR sends subscriber data to gsmSCF |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 176 | patch(From, #'AnyTimeSubscriptionInterrogationRes'{'camel-SubscriptionInfo'=Csi} = P) -> |
| 177 | P#'AnyTimeSubscriptionInterrogationRes'{'camel-SubscriptionInfo'=patch(From, Csi)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 178 | |
Harald Welte | e77cb26 | 2011-02-25 17:06:30 +0100 | [diff] [blame] | 179 | patch(_From, asn1_NOVALUE) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 180 | asn1_NOVALUE; |
| 181 | |
| 182 | % CAMEL related parsing |
| 183 | |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 184 | % this is part of the SRI Response (HLR->GMSC) |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 185 | patch(From, #'GmscCamelSubscriptionInfo'{'o-CSI'=Ocsi, 't-CSI'=Tcsi, |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 186 | 'd-csi'=Dcsi} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 187 | P#'GmscCamelSubscriptionInfo'{'o-CSI'=patch(From, Ocsi), |
| 188 | 't-CSI'=patch(From, Tcsi), |
| 189 | 'd-csi'=patch(From, Dcsi)}; |
Harald Welte | 449a317 | 2011-02-10 15:06:27 +0100 | [diff] [blame] | 190 | |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 191 | % this is part of the InsertSubscriberData HLR -> VLR |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 192 | patch(From, #'VlrCamelSubscriptionInfo'{'o-CSI'=Ocsi, 'mo-sms-CSI'=MoSmsCsi, |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 193 | 'mt-sms-CSI'=MtSmsCsi, 'ss-CSI'=SsCsi} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 194 | P#'VlrCamelSubscriptionInfo'{'o-CSI'=patch(From, Ocsi), |
| 195 | 'mo-sms-CSI'=patch(From, MoSmsCsi), |
| 196 | 'mt-sms-CSI'=patch(From, MtSmsCsi), |
| 197 | 'ss-CSI'=patch(From, SsCsi)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 198 | |
| 199 | % this is part of the InsertSubscriberData HLR -> SGSN |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 200 | patch(From, #'SGSN-CAMEL-SubscriptionInfo'{'gprs-CSI'=GprsCsi, |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 201 | 'mo-sms-CSI'=MoSmsCsi, |
| 202 | 'mt-sms-CSI'=MtSmsCsi} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 203 | P#'SGSN-CAMEL-SubscriptionInfo'{'gprs-CSI'=patch(From, GprsCsi), |
| 204 | 'mo-sms-CSI'=patch(From, MoSmsCsi), |
| 205 | 'mt-sms-CSI'=patch(From, MtSmsCsi)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 206 | |
| 207 | % this is part of the Anytime Subscription Interrogation Result HLR->gsmSCF |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 208 | patch(From, #'CAMEL-SubscriptionInfo'{'o-CSI'=Ocsi, |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 209 | 'd-CSI'=Dcsi, |
| 210 | 't-CSI'=Tcsi, |
| 211 | 'vt-CSI'=Vtcsi, |
| 212 | %'tif-CSI'=Tifcsi, |
| 213 | 'gprs-CSI'=GprsCsi, |
| 214 | 'mo-sms-CSI'=MoSmsCsi, |
| 215 | 'ss-CSI'=SsCsi, |
| 216 | 'm-CSI'=Mcsi, |
| 217 | 'mt-sms-CSI'=MtSmsCsi, |
| 218 | 'mg-csi'=MgCsi, |
| 219 | 'o-IM-CSI'=OimCsi, |
| 220 | 'd-IM-CSI'=DimCsi, |
| 221 | 'vt-IM-CSI'=VtImCsi} = P) -> |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 222 | P#'CAMEL-SubscriptionInfo'{'o-CSI'=patch(From, Ocsi), |
| 223 | 'd-CSI'=patch(From, Dcsi), |
| 224 | 't-CSI'=patch(From, Tcsi), |
| 225 | 'vt-CSI'=patch(From, Vtcsi), |
| 226 | 'gprs-CSI'=patch(From, GprsCsi), |
| 227 | 'mo-sms-CSI'=patch(From, MoSmsCsi), |
| 228 | 'ss-CSI'=patch(From, SsCsi), |
| 229 | 'm-CSI'=patch(From, Mcsi), |
| 230 | 'mt-sms-CSI'=patch(From, MtSmsCsi), |
| 231 | 'mg-csi'=patch(From, MgCsi), |
| 232 | 'o-IM-CSI'=patch(From, OimCsi), |
| 233 | 'd-IM-CSI'=patch(From, DimCsi), |
| 234 | 'vt-IM-CSI'=patch(From, VtImCsi)}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 235 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 236 | patch(From, #'T-CSI'{'t-BcsmCamelTDPDataList'=TdpList} = P) -> |
| 237 | P#'T-CSI'{'t-BcsmCamelTDPDataList'=patch_tBcsmCamelTDPDataList(From, TdpList)}; |
| 238 | patch(From, #'M-CSI'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 239 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 240 | P#'M-CSI'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 241 | patch(From, #'MG-CSI'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 242 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 243 | P#'MG-CSI'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 244 | patch(From, #'O-CSI'{'o-BcsmCamelTDPDataList'=TdpList} = P) -> |
| 245 | P#'O-CSI'{'o-BcsmCamelTDPDataList'=patch_oBcsmCamelTDPDataList(From, TdpList)}; |
| 246 | patch(From, #'D-CSI'{'dp-AnalysedInfoCriteriaList'=List} = P) -> |
| 247 | P#'D-CSI'{'dp-AnalysedInfoCriteriaList'=patch_AnInfoCritList(From, List)}; |
| 248 | patch(From, #'SMS-CSI'{'sms-CAMEL-TDP-DataList'=TdpList} = P) -> |
| 249 | P#'SMS-CSI'{'sms-CAMEL-TDP-DataList'=patch_SmsCamelTDPDataList(From, TdpList)}; |
| 250 | patch(From, #'SS-CSI'{'ss-CamelData'=Sscd} = P) -> |
| 251 | P#'SS-CSI'{'ss-CamelData'=patch(From, Sscd)}; |
| 252 | patch(From, #'GPRS-CSI'{'gprs-CamelTDPDataList'=TdpList} = P) -> |
| 253 | P#'GPRS-CSI'{'gprs-CamelTDPDataList'=patch_GprsCamelTDPDataList(From, TdpList)}; |
| 254 | patch(From, #'SS-CamelData'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 255 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 256 | P#'SS-CamelData'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 257 | patch(From, #'O-BcsmCamelTDPData'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 258 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 259 | P#'O-BcsmCamelTDPData'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 260 | patch(From, #'T-BcsmCamelTDPData'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 261 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Holger Hans Peter Freyther | 60e0fb2 | 2011-02-21 21:02:08 +0100 | [diff] [blame] | 262 | P#'T-BcsmCamelTDPData'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 263 | patch(From, #'SMS-CAMEL-TDP-Data'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 264 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 265 | P#'SMS-CAMEL-TDP-Data'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 266 | patch(From, #'GPRS-CamelTDPData'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 267 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 268 | P#'GPRS-CamelTDPData'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 269 | patch(From, #'DP-AnalysedInfoCriterium'{'gsmSCF-Address'=GsmScfAddr} = P) -> |
| 270 | GsmScfAddrOut = patch_map_isdn_addr(From, GsmScfAddr, scf), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 271 | P#'DP-AnalysedInfoCriterium'{'gsmSCF-Address'=GsmScfAddrOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 272 | patch(From, #'SubscriberInfo'{'locationInformation'=LocInformation} = P) -> |
| 273 | P#'SubscriberInfo'{'locationInformation'=patch(From, LocInformation)}; |
| 274 | patch(From, #'LocationInformation'{'vlr-number'=VlrNumber} = P) -> |
| 275 | VlrNumberOut = patch_map_isdn_addr(From, VlrNumber, vlr), |
Holger Hans Peter Freyther | 016e306 | 2011-02-21 22:04:38 +0100 | [diff] [blame] | 276 | P#'LocationInformation'{'vlr-number'=VlrNumberOut}; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 277 | patch(From, #'MO-ForwardSM-Arg'{'sm-RP-DA'=SC} = P) -> |
| 278 | NewSC = patch_scaddr(From, SC), |
Holger Hans Peter Freyther | e86edbd | 2011-02-22 23:24:55 +0100 | [diff] [blame] | 279 | P#'MO-ForwardSM-Arg'{'sm-RP-DA'=NewSC}; |
Holger Hans Peter Freyther | 016e306 | 2011-02-21 22:04:38 +0100 | [diff] [blame] | 280 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 281 | patch(_From, Default) -> |
Harald Welte | c752362 | 2011-02-10 14:42:31 +0100 | [diff] [blame] | 282 | Default. |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 283 | |
Holger Hans Peter Freyther | e86edbd | 2011-02-22 23:24:55 +0100 | [diff] [blame] | 284 | %rewrite the serviceCentreAddressDA |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 285 | patch_scaddr(From, {serviceCentreAddressDA,Ar}) -> |
| 286 | NewAddr = patch_map_isdn_addr(From, Ar, smsCDA), |
Holger Hans Peter Freyther | e86edbd | 2011-02-22 23:24:55 +0100 | [diff] [blame] | 287 | {serviceCentreAddressDA,NewAddr}; |
Harald Welte | e77cb26 | 2011-02-25 17:06:30 +0100 | [diff] [blame] | 288 | patch_scaddr(_From, Default) -> |
Holger Hans Peter Freyther | e86edbd | 2011-02-22 23:24:55 +0100 | [diff] [blame] | 289 | Default. |
| 290 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 291 | patch_oBcsmCamelTDPDataList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 292 | % we reverse the origianl list, as the tail recursive _acc function |
| 293 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 294 | patch_oBcsmCamelTDPDataList_acc(From, lists:reverse(List), []). |
Harald Welte | e77cb26 | 2011-02-25 17:06:30 +0100 | [diff] [blame] | 295 | patch_oBcsmCamelTDPDataList_acc(_From, [], NewList) -> NewList; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 296 | patch_oBcsmCamelTDPDataList_acc(From, [TdpData|Tail], NewList) -> |
| 297 | NewTdpData = patch(From, TdpData#'O-BcsmCamelTDPData'{}), |
| 298 | patch_oBcsmCamelTDPDataList_acc(From, Tail, [NewTdpData|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 299 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 300 | patch_tBcsmCamelTDPDataList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 301 | % we reverse the origianl list, as the tail recursive _acc function |
| 302 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 303 | patch_tBcsmCamelTDPDataList_acc(From, lists:reverse(List), []). |
Harald Welte | e77cb26 | 2011-02-25 17:06:30 +0100 | [diff] [blame] | 304 | patch_tBcsmCamelTDPDataList_acc(_From, [], NewList) -> NewList; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 305 | patch_tBcsmCamelTDPDataList_acc(From, [TdpData|Tail], NewList) -> |
| 306 | NewTdpData = patch(From, TdpData#'T-BcsmCamelTDPData'{}), |
| 307 | patch_tBcsmCamelTDPDataList_acc(From, Tail, [NewTdpData|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 308 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 309 | patch_AnInfoCritList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 310 | % we reverse the origianl list, as the tail recursive _acc function |
| 311 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 312 | patch_AnInfoCritList_acc(From, lists:reverse(List), []). |
Harald Welte | e77cb26 | 2011-02-25 17:06:30 +0100 | [diff] [blame] | 313 | patch_AnInfoCritList_acc(_From, [], NewList) -> NewList; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 314 | patch_AnInfoCritList_acc(From, [Crit|Tail], NewList) -> |
| 315 | NewCrit = patch(From, Crit#'DP-AnalysedInfoCriterium'{}), |
| 316 | patch_AnInfoCritList_acc(From, Tail, [NewCrit|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 317 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 318 | patch_GprsCamelTDPDataList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 319 | % we reverse the origianl list, as the tail recursive _acc function |
| 320 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 321 | patch_GprsCamelTDPDataList_acc(From, lists:reverse(List), []). |
| 322 | patch_GprsCamelTDPDataList_acc(_From, [], NewList) -> NewList; |
| 323 | patch_GprsCamelTDPDataList_acc(From, [TdpData|Tail], NewList) -> |
| 324 | NewTdpData = patch(From, TdpData#'GPRS-CamelTDPData'{}), |
| 325 | patch_GprsCamelTDPDataList_acc(From, Tail, [NewTdpData|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 326 | |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 327 | patch_SmsCamelTDPDataList(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 328 | % we reverse the origianl list, as the tail recursive _acc function |
| 329 | % will invert the order of components again |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 330 | patch_SmsCamelTDPDataList_acc(From, lists:reverse(List), []). |
Harald Welte | e77cb26 | 2011-02-25 17:06:30 +0100 | [diff] [blame] | 331 | patch_SmsCamelTDPDataList_acc(_From, [], NewList) -> NewList; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 332 | patch_SmsCamelTDPDataList_acc(From, [TdpData|Tail], NewList) -> |
| 333 | NewTdpData = patch(From, TdpData#'SMS-CAMEL-TDP-Data'{}), |
| 334 | patch_GprsCamelTDPDataList_acc(From, Tail, [NewTdpData|NewList]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 335 | |
| 336 | |
| 337 | |
| 338 | % process the Argument of a particular MAP invocation |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 339 | process_component_arg(From, OpCode, Arg) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 340 | case Arg of |
| 341 | asn1_NOVALUE -> Arg; |
Harald Welte | 29e589f | 2011-02-25 15:17:57 +0100 | [diff] [blame] | 342 | _ -> patch(From,Arg) |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 343 | end. |
| 344 | |
| 345 | % recurse over all components |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 346 | handle_tcap_components(_From, asn1_NOVALUE) -> |
Harald Welte | 17f6474 | 2011-02-10 18:29:59 +0100 | [diff] [blame] | 347 | asn1_NOVALUE; |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 348 | handle_tcap_components(From, List) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 349 | % we reverse the origianl list, as the tail recursive _acc function |
| 350 | % will invert the order of components again |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 351 | handle_tcap_components_acc(From, lists:reverse(List), []). |
| 352 | handle_tcap_components_acc(_From, [], NewComponents) -> NewComponents; |
| 353 | handle_tcap_components_acc(From, [Component|Tail], NewComponents) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 354 | case Component of |
| 355 | {basicROS, {Primitive, Body}} -> |
| 356 | io:format("handle component ~p primitive ~n", [Component]), |
| 357 | case Body of |
| 358 | % BEGIN |
| 359 | #'MapSpecificPDUs_begin_components_SEQOF_basicROS_invoke'{opcode={local, OpCode}, |
| 360 | argument=Arg} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 361 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 362 | NewBody = Body#'MapSpecificPDUs_begin_components_SEQOF_basicROS_invoke'{argument=NewArg}; |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 363 | #'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] | 364 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 365 | NewBody = Body#'MapSpecificPDUs_begin_components_SEQOF_basicROS_returnResult'{result=R#'MapSpecificPDUs_begin_components_SEQOF_basicROS_returnResult_result'{result=NewArg}}; |
| 366 | #'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] | 367 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 368 | 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] | 369 | % END |
| 370 | #'MapSpecificPDUs_end_components_SEQOF_basicROS_invoke'{opcode={local, OpCode}, |
| 371 | argument=Arg} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 372 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 373 | NewBody = Body#'MapSpecificPDUs_end_components_SEQOF_basicROS_invoke'{argument=NewArg}; |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 374 | #'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] | 375 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 376 | NewBody = Body#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult'{result=R#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult_result'{result=NewArg}}; |
| 377 | #'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] | 378 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 379 | 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] | 380 | % CONTINUE |
| 381 | #'MapSpecificPDUs_continue_components_SEQOF_basicROS_invoke'{opcode={local, OpCode}, |
| 382 | argument=Arg} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 383 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 384 | NewBody = Body#'MapSpecificPDUs_continue_components_SEQOF_basicROS_invoke'{argument=NewArg}; |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 385 | #'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] | 386 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 387 | NewBody = Body#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult'{result=R#'MapSpecificPDUs_end_components_SEQOF_basicROS_returnResult_result'{result=NewArg}}; |
| 388 | #'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] | 389 | NewArg = process_component_arg(From, OpCode, Arg), |
Harald Welte | ea19314 | 2011-02-10 15:40:36 +0100 | [diff] [blame] | 390 | 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] | 391 | _ -> |
| 392 | NewBody = Body |
| 393 | end, |
| 394 | %NewBody = setelement(5, Body, NewArg) |
| 395 | NewComponent = {basicROS, {Primitive, NewBody}}; |
| 396 | _ -> |
| 397 | NewComponent = Component |
| 398 | end, |
| 399 | io:format("=> modified component ~p~n", [NewComponent]), |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 400 | handle_tcap_components_acc(From, Tail, [NewComponent|NewComponents]). |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 401 | |
| 402 | |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 403 | % Erlang asn1rt has this strange property that all incoming EXTERNAL types are |
| 404 | % converted from the 1990 version into the 1994 version. The latter does not |
| 405 | % preserve the encoding (octet string, single ASN1 type, ...). During encoding, |
| 406 | % it then uses the OCTTET-STRING encoding, which is different from the MAP |
| 407 | % customary single-ASN1-type format. |
Harald Welte | c506fe5 | 2011-02-10 13:09:44 +0100 | [diff] [blame] | 408 | 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] | 409 | % our trick is as follows: we simply convert back to 1990 format, and explicitly |
| 410 | % set the single-ASN1-type encoding. asn1rt:s 'enc_EXTERNAL'() will detect this |
| 411 | #'EXTERNAL'{'direct-reference' = DirRef, 'indirect-reference' = IndRef, |
| 412 | 'encoding' = {'single-ASN1-type', Data}}; |
| 413 | asn1_EXTERNAL1994_fixup(Foo) -> |
| 414 | Foo. |
| 415 | |
| 416 | |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 417 | handle_tcap_dialogue(_From, Foo = {'EXTERNAL', DirRef, IndRef, Data}) -> |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 418 | asn1_EXTERNAL1994_fixup(Foo); |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 419 | handle_tcap_dialogue(_From, Foo) -> |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 420 | Foo. |
| 421 | |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 422 | |
| 423 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 424 | % Actual mangling of the decoded MAP messages |
| 425 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 426 | mangle_map(From, {Type, TcapMsgDec}) -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 427 | case {Type, TcapMsgDec} of |
| 428 | {'unidirectional', #'MapSpecificPDUs_unidirectional'{dialoguePortion=Dialg, |
| 429 | components=Components}} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 430 | NewDialg = handle_tcap_dialogue(From, Dialg), |
| 431 | NewComponents = handle_tcap_components(From, Components), |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 432 | NewTcapMsgDec = TcapMsgDec#'MapSpecificPDUs_unidirectional'{dialoguePortion=NewDialg, components=NewComponents}; |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 433 | {'begin', #'MapSpecificPDUs_begin'{dialoguePortion=Dialg, components=Components}} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 434 | NewDialg = handle_tcap_dialogue(From, Dialg), |
| 435 | NewComponents = handle_tcap_components(From, Components), |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 436 | NewTcapMsgDec = TcapMsgDec#'MapSpecificPDUs_begin'{dialoguePortion=NewDialg, components=NewComponents}; |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 437 | {'continue', #'MapSpecificPDUs_continue'{dialoguePortion=Dialg, components=Components}} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 438 | NewDialg = handle_tcap_dialogue(From, Dialg), |
| 439 | NewComponents = handle_tcap_components(From, Components), |
Harald Welte | 9bc2e4a | 2011-02-10 12:40:31 +0100 | [diff] [blame] | 440 | NewTcapMsgDec = TcapMsgDec#'MapSpecificPDUs_continue'{dialoguePortion=NewDialg, components=NewComponents}; |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 441 | {'end', #'MapSpecificPDUs_end'{dialoguePortion=Dialg, components=Components}} -> |
Harald Welte | 2cc831f | 2011-02-10 18:36:02 +0100 | [diff] [blame] | 442 | NewDialg = handle_tcap_dialogue(From, Dialg), |
| 443 | NewComponents = handle_tcap_components(From, Components), |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 444 | NewTcapMsgDec = TcapMsgDec#'MapSpecificPDUs_end'{dialoguePortion=NewDialg, components=NewComponents}; |
| 445 | %{_, #'Abort'{reason=Reason} -> |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 446 | _ -> |
| 447 | NewTcapMsgDec = TcapMsgDec |
| 448 | end, |
Harald Welte | 29c5f40 | 2011-02-10 13:24:49 +0100 | [diff] [blame] | 449 | io:format("new TcapMsgDec (Type=~p) ~p~n", [Type, NewTcapMsgDec]), |
Harald Welte | a68d96e | 2011-02-10 09:49:46 +0100 | [diff] [blame] | 450 | {Type, NewTcapMsgDec}. |
| 451 | |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 452 | |
| 453 | % Configuration file has changed, re-generate internal data structures |
| 454 | config_update() -> |
| 455 | % (re-)generate the MAP Address rewrite table |
Harald Welte | 6009f6e | 2011-02-10 21:41:50 +0100 | [diff] [blame] | 456 | {ok, MapRewriteTbl} = application:get_env(mgw_nat, map_rewrite_table), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 457 | MapRewriteTblOut = generate_rewrite_table(MapRewriteTbl), |
Harald Welte | 6009f6e | 2011-02-10 21:41:50 +0100 | [diff] [blame] | 458 | application:set_env(mgw_nat, map_rewrite_table, MapRewriteTblOut), |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 459 | %{ok, MsrnPfxStp} = application:get_env(msrn_pfx_stp), |
| 460 | %{ok, MsrnPfxMsc} = application:get_env(msrn_pfx_msc), |
| 461 | %{ok, IntPfx} = application:get_env(intern_pfx), |
| 462 | ok. |
| 463 | |
| 464 | % Generate the full MAP address rewrite table |
| 465 | generate_rewrite_table(List) when is_list(List) -> |
| 466 | generate_rewrite_table(List, []). |
| 467 | generate_rewrite_table([], OutList) -> |
| 468 | io:format("(Re)generated MAP ISDN-Address rewrite table: ~p~n", [OutList]), |
| 469 | OutList; |
| 470 | generate_rewrite_table([Head|Tail], OutList) -> |
| 471 | NewItem = generate_rewrite_entry(Head), |
| 472 | generate_rewrite_table(Tail, [NewItem|OutList]). |
| 473 | |
Harald Welte | d1410ae | 2011-02-25 21:33:34 +0100 | [diff] [blame] | 474 | % If a rewrite table entry is already fully-qualified, return it unmodified |
| 475 | generate_rewrite_entry({Name, MscInt, StpInt, Msc, Stp}) -> |
| 476 | {Name, MscInt, StpInt, Msc, Stp}; |
Harald Welte | f962964 | 2011-02-10 20:44:46 +0100 | [diff] [blame] | 477 | % Generate a MAP Address rewrite table entry |
| 478 | generate_rewrite_entry({Name, MscSideInt, StpSideInt}) -> |
| 479 | MscSideList = osmo_util:int2digit_list(MscSideInt), |
| 480 | StpSideList = osmo_util:int2digit_list(StpSideInt), |
| 481 | {Name, MscSideInt, StpSideInt, MscSideList, StpSideList}. |