Harald Welte | 5df8338 | 2011-03-08 15:17:32 +0100 | [diff] [blame] | 1 | % VFUK-ONW specific mgw_nat actor callback functions |
| 2 | |
| 3 | % (C) 2011 by Harald Welte <laforge@gnumonks.org> |
| 4 | % (C) 2011 OnWaves |
| 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 Affero General Public License as |
| 10 | % published by the Free Software Foundation; either version 3 of the |
| 11 | % License, or (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 Affero General Public License |
| 19 | % along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | |
| 21 | -module(mgw_nat_act_vfuk_onw). |
| 22 | -author("Harald Welte <laforge@gnumonks.org>"). |
| 23 | |
| 24 | -export([rewrite_actor/5]). |
Harald Welte | 93db48d | 2011-03-10 00:47:36 +0100 | [diff] [blame] | 25 | -export([camelph_twalk_cb/3]). |
| 26 | |
| 27 | -include_lib("osmo_map/include/map.hrl"). |
| 28 | -include_lib("osmo_ss7/include/sccp.hrl"). |
Harald Welte | 5df8338 | 2011-03-08 15:17:32 +0100 | [diff] [blame] | 29 | |
| 30 | % Rewrite at SCTP (root) level: |
| 31 | rewrite_actor(sctp, From, Path, 2, DataBin) -> |
| 32 | try mgw_nat:mangle_rx_data(From, Path, DataBin, fun rewrite_actor/5) of |
| 33 | Val -> |
| 34 | Val |
| 35 | catch error:Error -> |
| 36 | % some parser error, simply forward msg unmodified |
Harald Welte | eee3eac | 2011-03-12 10:34:33 +0100 | [diff] [blame] | 37 | error_logger:error_report([{error, Error}, |
| 38 | {stacktrace, erlang:get_stacktrace()}]), |
Harald Welte | 5df8338 | 2011-03-08 15:17:32 +0100 | [diff] [blame] | 39 | DataBin |
| 40 | end; |
| 41 | |
| 42 | % Rewrite at MAP level: call into map_masq module |
| 43 | rewrite_actor(map, From, Path, 0, MapDec) -> |
| 44 | mangle_map_camel_phase(From, Path, MapDec); |
| 45 | |
| 46 | % Default action: no rewrite |
| 47 | rewrite_actor(_Level, _From, _Path, _MsgType, Msg) -> |
| 48 | Msg. |
| 49 | |
| 50 | |
Harald Welte | eee3eac | 2011-03-12 10:34:33 +0100 | [diff] [blame] | 51 | mangle_map_camel_phase(from_stp, _Path, MapDec) -> |
Harald Welte | 93db48d | 2011-03-10 00:47:36 +0100 | [diff] [blame] | 52 | MapDec; |
| 53 | mangle_map_camel_phase(from_msc, Path, MapDec) -> |
| 54 | % Resolve the Global Title of the SCCP Called Addr |
Harald Welte | eea20e1 | 2011-03-31 09:40:44 +0200 | [diff] [blame^] | 55 | {value, #sccp_msg{parameters = SccpPars}} = lists:keysearch(sccp_msg, 1, Path), |
Harald Welte | 93db48d | 2011-03-10 00:47:36 +0100 | [diff] [blame] | 56 | CalledAddr = proplists:get_value(called_party_addr, SccpPars), |
| 57 | #global_title{phone_number = PhoneNum} = CalledAddr#sccp_addr.global_title, |
| 58 | PhoneNumInt = osmo_util:digit_list2int(PhoneNum), |
Harald Welte | eee3eac | 2011-03-12 10:34:33 +0100 | [diff] [blame] | 59 | {ok, CamelPatchTbl} = application:get_env(mgw_nat, camel_phase_patch_table), |
Harald Welte | eea20e1 | 2011-03-31 09:40:44 +0200 | [diff] [blame^] | 60 | case lists:keysearch(PhoneNumInt, 1, CamelPatchTbl) of |
Harald Welte | 93db48d | 2011-03-10 00:47:36 +0100 | [diff] [blame] | 61 | false -> |
| 62 | MapDec; |
Harald Welte | eea20e1 | 2011-03-31 09:40:44 +0200 | [diff] [blame^] | 63 | {value, { _Num, PhaseL }} -> |
| 64 | io:format("Rewriting Camel Phase List to ~p, GT ~p~n", [PhaseL, PhoneNumInt]), |
Harald Welte | 93db48d | 2011-03-10 00:47:36 +0100 | [diff] [blame] | 65 | osmo_util:tuple_walk(MapDec, fun camelph_twalk_cb/3, [PhaseL]) |
| 66 | end. |
| 67 | |
| 68 | % tuple tree walker callback function |
| 69 | camelph_twalk_cb(['begin','MapSpecificPDUs_begin',basicROS,invoke, |
| 70 | 'MapSpecificPDUs_begin_components_SEQOF_basicROS_invoke', |
| 71 | 'UpdateLocationArg'], VC = #'VLR-Capability'{}, [PhaseL|_Args]) -> |
| 72 | % Manipulate the VLR capabilities in UpdateLocationArg |
| 73 | VC#'VLR-Capability'{supportedCamelPhases = PhaseL}; |
| 74 | camelph_twalk_cb(_Path, Msg, _Args) -> |
| 75 | % Default case: simply return the unmodified tuple |
| 76 | Msg. |