blob: 1224bd4806c7ea95828b2f5240587d64c0d6d12f [file] [log] [blame]
Harald Welte5df83382011-03-08 15:17:32 +01001% 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
Harald Welte99e92c22011-04-06 17:22:30 +020024-export([rewrite_actor/5, reload_config/0]).
Harald Welte93db48d2011-03-10 00:47:36 +010025-export([camelph_twalk_cb/3]).
26
27-include_lib("osmo_map/include/map.hrl").
28-include_lib("osmo_ss7/include/sccp.hrl").
Harald Welte5df83382011-03-08 15:17:32 +010029
30% Rewrite at SCTP (root) level:
31rewrite_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 Welteeee3eac2011-03-12 10:34:33 +010037 error_logger:error_report([{error, Error},
Harald Welte92acea92011-04-14 17:50:09 +020038 {stacktrace, erlang:get_stacktrace()},
39 {from, From}, {path, Path},
40 {data_bin, DataBin}]),
Harald Welte5df83382011-03-08 15:17:32 +010041 DataBin
42 end;
43
44% Rewrite at MAP level: call into map_masq module
45rewrite_actor(map, From, Path, 0, MapDec) ->
46 mangle_map_camel_phase(From, Path, MapDec);
47
48% Default action: no rewrite
49rewrite_actor(_Level, _From, _Path, _MsgType, Msg) ->
50 Msg.
51
52
Harald Welteeee3eac2011-03-12 10:34:33 +010053mangle_map_camel_phase(from_stp, _Path, MapDec) ->
Harald Welte93db48d2011-03-10 00:47:36 +010054 MapDec;
55mangle_map_camel_phase(from_msc, Path, MapDec) ->
56 % Resolve the Global Title of the SCCP Called Addr
Harald Welteeea20e12011-03-31 09:40:44 +020057 {value, #sccp_msg{parameters = SccpPars}} = lists:keysearch(sccp_msg, 1, Path),
Harald Welte93db48d2011-03-10 00:47:36 +010058 CalledAddr = proplists:get_value(called_party_addr, SccpPars),
Harald Welte99e92c22011-04-06 17:22:30 +020059 {ok, IntTbl} = application:get_env(mgw_nat, int_camel_ph_tbl),
60 case osmo_ss7_gtt:global_title_match(IntTbl, CalledAddr) of
Harald Welte93db48d2011-03-10 00:47:36 +010061 false ->
62 MapDec;
Harald Welte99e92c22011-04-06 17:22:30 +020063 PhaseL ->
64 #global_title{phone_number = PhoneNum} = CalledAddr#sccp_addr.global_title,
65 PhoneNumInt = osmo_util:digit_list2int(PhoneNum),
Harald Welteeea20e12011-03-31 09:40:44 +020066 io:format("Rewriting Camel Phase List to ~p, GT ~p~n", [PhaseL, PhoneNumInt]),
Harald Welte93db48d2011-03-10 00:47:36 +010067 osmo_util:tuple_walk(MapDec, fun camelph_twalk_cb/3, [PhaseL])
68 end.
69
Harald Welte99e92c22011-04-06 17:22:30 +020070
Harald Welte93db48d2011-03-10 00:47:36 +010071% tuple tree walker callback function
72camelph_twalk_cb(['begin','MapSpecificPDUs_begin',basicROS,invoke,
73 'MapSpecificPDUs_begin_components_SEQOF_basicROS_invoke',
74 'UpdateLocationArg'], VC = #'VLR-Capability'{}, [PhaseL|_Args]) ->
75 % Manipulate the VLR capabilities in UpdateLocationArg
76 VC#'VLR-Capability'{supportedCamelPhases = PhaseL};
77camelph_twalk_cb(_Path, Msg, _Args) ->
78 % Default case: simply return the unmodified tuple
79 Msg.
Harald Welte99e92c22011-04-06 17:22:30 +020080
81
82gen_int_camelph_tbl(L) ->
83 gen_int_camelph_tbl(L, []).
84gen_int_camelph_tbl([], Out) ->
85 Out;
86gen_int_camelph_tbl([{GttPart, PhasePart}|Tail], Out) ->
87 GttMatch = osmo_ss7_gtt:'#new-gtt_match'(GttPart),
88 % Fixme: use ordered insert!
89 gen_int_camelph_tbl(Tail, Out ++ [{GttMatch, PhasePart}]).
90
91reload_config() ->
92 {ok, CamelPatchTblIn} = application:get_env(mgw_nat, camel_phase_patch_table),
93 io:format("VFUK-ONW actor: reloading config ~p~n", [CamelPatchTblIn]),
94 try gen_int_camelph_tbl(CamelPatchTblIn) of
95 TblOut ->
96 application:set_env(mgw_nat, int_camel_ph_tbl, TblOut)
97 catch error:Error ->
98 error_logger:error_report([{error, Error},
99 {stacktrace, erlang:get_stacktrace()}])
100 end.