Harald Welte | 2619013 | 2011-04-16 14:12:10 +0200 | [diff] [blame] | 1 | -module(m3ua_example). |
| 2 | |
| 3 | -include("osmo_util.hrl"). |
| 4 | -include("m3ua.hrl"). |
| 5 | -include("sccp.hrl"). |
| 6 | |
| 7 | -export([init/0]). |
| 8 | |
| 9 | -record(loop_dat, { |
| 10 | scrc_pid, |
| 11 | m3ua_pid |
| 12 | }). |
| 13 | |
| 14 | init() -> |
| 15 | % start the M3UA link to the SG |
| 16 | Opts = [{user_pid, self()}, {sctp_remote_ip, {192,168,104,2}}, {sctp_remote_port, 2905}, |
| 17 | {sctp_local_port, 60180}, {user_fun, fun m3ua_tx_to_user/2}, {user_args, self()}], |
| 18 | {ok, M3uaPid} = m3ua_core:start_link(Opts), |
| 19 | % instantiate SCCP routing instance |
| 20 | {ok, ScrcPid} = sccp_scrc:start_link([{mtp_tx_action, {callback_fn, fun scrc_tx_to_mtp/2, M3uaPid}}]), |
| 21 | loop(#loop_dat{m3ua_pid = M3uaPid, scrc_pid = ScrcPid}). |
| 22 | |
| 23 | loop(L) -> |
| 24 | io:format("Example: Entering main loop~n"), |
| 25 | receive |
| 26 | {m3ua_prim, Prim} -> |
| 27 | io:format("Example: Rx M3UA Prim ~p~n", [Prim]), |
| 28 | rx_m3ua_prim(Prim, L); |
| 29 | Stop -> |
| 30 | io:format("Example: Received ~p~n", [Stop]), |
| 31 | exit(stop_received) |
| 32 | end, |
| 33 | loop(L). |
| 34 | |
| 35 | |
| 36 | scrc_tx_to_mtp(Prim, Args) -> |
| 37 | M3uaPid = Args, |
| 38 | gen_fsm:send_event(M3uaPid, Prim). |
| 39 | |
| 40 | m3ua_tx_to_user(Prim, Args) -> |
| 41 | UserPid = Args, |
| 42 | UserPid ! {m3ua_prim, Prim}. |
| 43 | |
| 44 | |
| 45 | rx_m3ua_prim(#primitive{subsystem = 'M', gen_name = 'SCTP_ESTABLISH', spec_name = confirm}, L) -> |
| 46 | gen_fsm:send_event(L#loop_dat.m3ua_pid, osmo_util:make_prim('M','ASP_UP',request)); |
| 47 | |
| 48 | rx_m3ua_prim(#primitive{subsystem = 'M', gen_name = 'ASP_UP', spec_name = confirm}, L) -> |
| 49 | gen_fsm:send_event(L#loop_dat.m3ua_pid, osmo_util:make_prim('M','ASP_ACTIVE',request)); |
| 50 | |
| 51 | rx_m3ua_prim(#primitive{subsystem = 'M', gen_name = 'ASP_ACTIVE', spec_name = confirm}, L) -> |
| 52 | io:format("Example: M3UA now active and ready~n"), |
| 53 | tx_sccp_udt(L#loop_dat.scrc_pid); |
| 54 | |
| 55 | rx_m3ua_prim(P, _L) -> |
| 56 | io:format("Example: Ignoring M3UA prim ~p~n", [P]), |
| 57 | ok. |
| 58 | |
| 59 | |
| 60 | tx_sccp_udt(ScrcPid) -> |
| 61 | CallingP = #sccp_addr{ssn = ?SCCP_SSN_MSC, point_code = osmo_util:pointcode2int(itu, {1,2,2})}, |
| 62 | CalledP = #sccp_addr{ssn = ?SCCP_SSN_HLR, point_code = osmo_util:pointcode2int(itu, {1,1,1})}, |
| 63 | Data = <<1,2,3,4>>, |
| 64 | Opts = [{protocol_class, 0}, {called_party_addr, CalledP}, |
| 65 | {calling_party_addr, CallingP}, {user_data, Data}], |
| 66 | io:format("Example: Sending N-UNITDATA.req to SCRC~n"), |
| 67 | gen_fsm:send_event(ScrcPid, osmo_util:make_prim('N','UNITDATA',request,Opts)). |
| 68 | |