-module(pbx_acse). -behaviour(gen_event). -include("ACSE-1.hrl"). -include("CSTA-application-context-information-csta3.hrl"). -export([start_link/0, add_handler/2]). -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). -export([encode/1, decode/1]). encode(userinformation) -> 'CSTA-application-context-information-csta3':encode( 'ACSEUserInformationForCSTA', {newDefinition, #'NewACSEUserInformationForCSTA'{cSTAVersion = [versionFive]}}); encode(associate) -> {ok, UI} = encode(userinformation), AARQ = {aarq, #'AARQ-apdu'{ 'protocol-version' = [version1], % required 'application-context-name' = {1, 3, 12, 0, 218}, 'user-information' = [#'EXTERNAL'{ 'direct-reference' = {1, 3, 12, 0, 285, 200}, encoding = {'single-ASN1-type', UI}}]}}, encode(AARQ); encode(release) -> RLRQ = {rlrq, #'RLRQ-apdu'{}}, encode(RLRQ); encode(Data) -> 'ACSE-1':encode('ACSE-apdu', Data). decode({aare, #'AARE-apdu'{result = accepted}}) -> ok; decode({aare, #'AARE-apdu'{}}) -> error; decode({rlre, _}) -> ok; decode({abrt, _}) -> error; decode({asn1_ExtAlt, Data}) -> pbx_rose:decode(Data); decode(<>) -> {ok, Pdu} = 'ACSE-1':decode('ACSE-apdu', Data), decode(Pdu). %%% start_link() -> gen_event:start_link({local, ?MODULE}). add_handler(Handler, Args) -> gen_event:add_handler(?MODULE, Handler, Args). init(_Args) -> {ok, []}. handle_event({aare, #'AARE-apdu'{result = Result}}, _State) -> io:format("AARE ~p~n", [Result]), {ok, Result}; % accepted or rejected handle_event({rlre, _}, _State) -> io:format("RLRE~n"), {ok, released}; handle_event({abrt, _}, _State) -> io:format("ABRT~n"), {ok, aborted}; handle_event(_Event, State) -> io:format("ELSE~n"), {ok, State}. handle_call(association, State) -> {ok, State, State}; handle_call(_Request, State) -> {ok, ok, State}. handle_info(_Info, State) -> {ok, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}.