-module(pbx_acse). -behaviour(gen_event). -include("ACSE-1.hrl"). -include("CSTA-application-context-information-csta3.hrl"). -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). init(_Args) -> pbx_conn:send(encode(associate)), {ok, undefined}. 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) -> {ok, State}. handle_call(association, State) -> {ok, State, State}; handle_call(_Request, State) -> {ok, ok, State}. handle_info(_Info, State) -> {ok, State}. terminate(_Reason, accepted) -> pbx_conn:send(encode(release)), ok; terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%% encode(associate) -> UIforCSTA = #'NewACSEUserInformationForCSTA'{ cSTAVersion = [versionFive]}, {ok, UI} = 'CSTA-application-context-information-csta3':encode( 'ACSEUserInformationForCSTA', {newDefinition, UIforCSTA}), Ext = #'EXTERNAL'{'direct-reference' = {1, 3, 12, 0, 285, 200}, encoding = {'single-ASN1-type', UI}}, AARQ = #'AARQ-apdu'{ 'protocol-version' = [version1], % required 'application-context-name' = {1, 3, 12, 0, 218}, 'user-information' = [Ext]}, 'ACSE-1':encode('ACSE-apdu', {aarq, AARQ}); encode(release) -> 'ACSE-1':encode('ACSE-apdu', {rlrq, #'RLRQ-apdu'{}}).