summaryrefslogtreecommitdiff
path: root/src/pbx_acse.erl
blob: 84a3bb378826888d972ecff87b54d4a248afa162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-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]).
-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(<<Data/binary>>) ->
	{ok, Pdu} = 'ACSE-1':decode('ACSE-apdu', Data),
	decode(Pdu).

%%%

init(_Args) ->
	{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, _State) ->
	ok.

code_change(_OldVsn, State, _Extra) ->
	{ok, State}.