1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2004-2016. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20
21%%
22%%----------------------------------------------------------------------
23%% Purpose: Handle meta data about packages
24%%----------------------------------------------------------------------
25
26-module(megaco_binary_name_resolver_prev3a).
27
28-include_lib("megaco/src/engine/megaco_message_internal.hrl").
29-include_lib("megaco/src/app/megaco_internal.hrl").
30
31
32-define(LOWER(Char),
33	if
34	    Char >= $A, Char =< $Z ->
35		Char - ($A - $a);
36	    true ->
37		Char
38	end).
39
40-export([packages/0,
41	 capabilities/0,
42	 capabilities/1,
43         decode_name/3,
44	 encode_name/3
45        ]).
46
47encode_name(Config, term_id, TermId) ->
48    case megaco:encode_binary_term_id(Config, TermId) of
49	{ok, TermId2} ->
50	    TermId2;
51	{error, _Reason} ->
52	    exit({bad_term_id, TermId})
53    end;
54encode_name(_Config, Scope, Item) ->
55    ?d("encode_name(~p) -> entry with"
56       "~n   Item: ~p", [Scope, Item]),
57    encode(Scope, Item).
58
59decode_name(Config, term_id, TermId) ->
60    case megaco:decode_binary_term_id(Config, TermId) of
61	{ok, TermId2} ->
62	    TermId2;
63	{error, _Reason} ->
64	    exit({bad_term_id, TermId})
65    end;
66decode_name(_Config, Scope, Item) ->
67    ?d("decode_name(~p) -> entry with"
68       "~n   Item: ~p", [Scope, Item]),
69    decode(Scope, Item).
70
71
72
73%%----------------------------------------------------------------------
74%% 12.1.1	Package
75%%
76%% Overall description of the package, specifying:
77%%
78%% 	Package Name: only descriptive
79%%
80%% 	PackageID: is an identifier
81%%
82%% 	Description: is a description of the package
83%%
84%% 	Version:
85%%
86%%            A new version of a package can only add additional Properties,
87%%            Events, Signals, Statistics and new possible values for an
88%%            existing parameter described in the original package. No
89%%            deletions or modifications shall be allowed. A version is an
90%%            integer in the range from 1 to 99.
91%%
92%% 	Designed to be extended only (Optional): Yes
93%%
94%%            This indicates that the package has been expressly designed to
95%%            be extended by others, not to be directly referenced. For
96%%            example, the package may not have any function on its own or be
97%%            nonsensical on its own. The MG SHOULD NOT publish this PackageID
98%%            when reporting packages.
99%%
100%% 	Extends: existing package Descriptor
101%%
102%%            A package may extend an existing package. The version of the
103%%            original package must be specified. When a package extends
104%%            another package it shall only add additional Properties, Events,
105%%            Signals, Statistics and new possible values for an existing
106%%            parameter described in the original package. An extended package
107%%            shall not redefine or overload an identifier defined in the
108%%            original package and packages it may have extended (multiple
109%%            levels of extension). Hence, if package B version 1 extends
110%%            package A version 1, version 2 of B will not be able to extend
111%%            the A version 2 if A version 2 defines a name already in B
112%%            version 1. If the package does not extend another package, it
113%%            shall specify "none".
114%%
115%%
116%% 12.1.2	Properties
117%%
118%% Properties defined by the package, specifying:
119%%
120%% 	Property Name: only descriptive
121%%
122%% 	PropertyID: is an identifier
123%%
124%% 	Description: is a description of the function of the property
125%%
126%% 	Type: One of:
127%%
128%%            Boolean
129%%
130%%            String: UTF-8 string
131%%
132%%            Octet String: A number of octets. See Annex A and B.3 for
133%%                          encoding
134%%
135%%            Integer: 4 byte signed integer
136%%
137%%            Double: 8 byte signed integer
138%%
139%%            Character: unicode UTF-8 encoding of a single letter.
140%%                       Could be more than one octet.
141%%
142%%            Enumeration: one of a list of possible unique values (see 12.3)
143%%
144%%            Sub-list: a list of several values from a list.
145%%                      The type of sub-list SHALL also be specified.
146%%                      The type shall be chosen from the types specified in
147%%                      this section (with the exception of sub-list). For
148%%                      example, Type: sub-list of enumeration. The encoding
149%%                      of sub-lists is specified in Annexes A and B.3.
150%%
151%% 	Possible values:
152%%
153%%            A package MUST specify either a specific set of values or a
154%%            description of how values are determined. A package MUST also
155%%            specify a default value or the default behaviour when the value
156%%            is omitted from its descriptor. For example, a package may
157%%            specify that procedures related to the property are suspended
158%%            when its value is omitted.
159%%
160%% 	Default:
161%%
162%%            A default value (but not procedures) may be specified as
163%%            provisionable.
164%%
165%% 	Defined in:
166%%
167%%            Which H.248.1 descriptor the property is defined in.
168%%            LocalControl is for stream-dependent properties.
169%%            TerminationState is for stream-independent properties.
170%%            ContextAttribute is for properties that affect the context as
171%%            a whole, i.e., mixing properties. These are expected to be the
172%%            most common cases, but it is possible for properties to be
173%%            defined in other descriptors. Context properties MUST be defined
174%%            in the ContextAttribute descriptor.
175%%
176%% 	Characteristics: Read/Write or both, and (optionally), global:
177%%
178%%            Indicates whether a property is read-only, or read-write, and
179%%            if it is global. If Global is omitted, the property is not
180%%            global. If a property is declared as global, the value of the
181%%            property is shared by all Terminations realizing the package.
182%%            If a context property is declared as global, the property is
183%%            shared by all contexts realizing the package.
184%%
185%%
186%% 12.1.3	Events
187%%
188%% Events defined by the package, specifying:
189%%
190%% 	Event name: only descriptive
191%%
192%% 	EventID: is an identifier
193%%
194%% 	Description: a description of the function of the event
195%%
196%% 	EventsDescriptor Parameters:
197%%
198%%            Parameters used by the MGC to configure the event, and found in
199%%            the EventsDescriptor. See 12.2. If there are no parameters for
200%%            the Events Descriptor, then "none" shall be specified.
201%%
202%% 	ObservedEventsDescriptor Parameters:
203%%
204%%            Parameters returned to the MGC in Notify requests and in replies
205%%            to command requests from the MGC that audit
206%%            ObservedEventsDescriptor, and found in the
207%%            ObservedEventsDescriptor. See 12.2. If there are no parameters
208%%            for the ObservedEvents Descriptor, then 'none' shall be specified.
209%%
210%%
211%% 12.1.4	Signals
212%%
213%% Signals defined by the package, specifying:
214%%
215%% 	Signal Name: only descriptive
216%%
217%% 	SignalID: is an identifier. SignalID is used in a SignalsDescriptor
218%%
219%% 	Description: a description of the function of the signal
220%%
221%% 	SignalType: one of:
222%%
223%%            OO (On/Off)
224%%
225%%            TO (TimeOut)
226%%
227%%            BR (Brief)
228%%
229%% 	   NOTE - SignalType may be defined such that it is dependent on
230%%            the value of one or more parameters. The package MUST specify a
231%%            default signal type. If the default type is TO, the package MUST
232%%            specify a default duration which may be provisioned. A default
233%%            duration is meaningless for BR.
234%%
235%% 	Duration: in hundredths of seconds
236%%
237%% 	Additional Parameters: see 12.2
238%%
239%%
240%% 12.1.5	Statistics
241%%
242%% Statistics defined by the package, specifying:
243%%
244%% 	Statistic name: only descriptive
245%%
246%% 	StatisticID: is an identifier
247%%
248%% 	StatisticID is used in a StatisticsDescriptor
249%%
250%% 	Description: a description of the statistic
251%%
252%% 	Type: One of:
253%%
254%% 	   Boolean
255%%
256%%            String: UTF-8 string
257%%
258%%            Octet String: A number of octets.
259%%                          See Annex A and Annex B.3 for encoding
260%%
261%%            Integer: 4 byte signed integer
262%%
263%%            Double: 8 byte signed integer
264%%
265%%            Character: Unicode UTF-8 encoding of a single letter.
266%%                       Could be more than one octet.
267%%
268%%            Enumeration: One of a list of possible unique values (See 12.3)
269%%
270%%            Sub-list: A list of several values from a list.
271%%                      The type of sub-list SHALL also be specified.
272%%                      The type shall be chosen from the types specified in
273%%                      this section (with the exception of sub-list).
274%%                      For example, Type: sub-list of enumeration.
275%%                      The encoding of sub-lists is specified in Annexes A
276%%                      and B.3.
277%%
278%% 	Possible Values:
279%%
280%%            A package must indicate the unit of measure, e.g. milliseconds,
281%%            packets, either here or along with the type above, as well as
282%%            indicating any restriction on the range.
283%%
284%% 	Level: Specify if the statistic can be kept at the Termination
285%%                level, Stream level or Either.
286%%
287%%
288%% 12.1.6	Error Codes
289%%
290%% If the package does not define any error codes, this section may be omitted.
291%% Otherwise, it describes error codes defined by the package, specifying:
292%%
293%% 	Error Code #: The error code number.
294%%
295%% 	Name: Name of the error
296%%
297%% 	Definition: A description of the error code.
298%%
299%% 	Error Text in the Error Descriptor:
300%%
301%%            A description of what text to return in the Error Descriptor.
302%%
303%% 	Comment: Any further comments on the use of the error code.
304%%
305%%
306%% 12.1.7	Procedures
307%%
308%% Additional guidance on the use of the package.
309%%
310%%
311%% 12.2	Guidelines to defining parameters to events and signals
312%%
313%%         Parameter Name: only descriptive
314%%
315%%         ParameterID: is an identifier. The textual ParameterID of
316%%         parameters to Events and Signals shall not start with "EPA" and
317%%         "SPA", respectively. The textual ParameterID shall also not be
318%%         "ST", "Stream", "SY", "SignalType", "DR", "Duration", "NC",
319%%         "NotifyCompletion", "KA", "KeepActive", "EB", "Embed", "DM",
320%%         "DigitMap", "DI", "Direction", "RQ" or "RequestID".
321%%
322%%         Description: a description of the function of the parameter.
323%%
324%%         Type: One of:
325%%
326%%            Boolean
327%%
328%%            String: UTF-8 octet string
329%%
330%%            Octet String: A number of octets. See Annex A and B.3 for
331%%                          encoding
332%%
333%%            Integer: 4-octet signed integer
334%%
335%%            Double: 8-octet signed integer
336%%
337%%            Character: Unicode UTF-8 encoding of a single letter. Could be
338%%                       more than one octet.
339%%
340%%            Enumeration: one of a list of possible unique values (see 12.3)
341%%
342%%            Sub-list: a list of several values from a list (not supported
343%%                      for statistics). The type of sub-list SHALL also be
344%%                      specified The type shall be chosen from the types
345%%                      specified in this section (with the exception of
346%%                      sub-list). For example, Type: sub-list of enumeration.
347%%                      The encoding of sub-lists is specified in Annex A
348%%                      and B.3.
349%%
350%%            Optional: Yes/No
351%%
352%%               Describes if the parameter may be omitted from the signal or
353%%               event.
354%%
355%%            Possible values:
356%%
357%%               A package MUST specify either a specific set of values or a
358%%               description of how values are determined. A package MUST
359%%               also specify a default value or the default behavior when the
360%%               value is omitted from its descriptor. For example, a package
361%%               may specify that procedures related to the parameter are
362%%               suspended when its value is omitted.
363%%
364%%            Default:
365%%
366%%               A default value (but not procedures) may be specified as
367%%               provisionable.
368%%
369%%
370%% 12.3	Lists
371%%
372%% Possible values for parameters include enumerations. Enumerations may be
373%% defined in a list. It is recommended that the list be IANA registered so
374%% that packages that extend the list can be defined without concern for
375%% conflicting names.
376%%
377%%
378%% 12.4	Identifiers
379%%
380%% Identifiers in text encoding shall be strings of up to 64 characters,
381%% containing no spaces, starting with an alphabetic character and consisting
382%% of alphanumeric characters and/or digits, and possibly including the
383%% special character underscore ("_").
384%%
385%% Identifiers in binary encoding are 2 octets long.
386%%
387%% Both text and binary values shall be specified for each identifier,
388%% including identifiers used as values in enumerated types.
389%%
390%%
391%% 12.5	Package registration
392%%
393%% A package can be registered with IANA for interoperability reasons. See
394%% clause 14 for IANA considerations.
395%%
396%%----------------------------------------------------------------------
397
398capabilities() ->
399    [{P, capabilities(P)} || P <- packages()].
400
401%% -record(property, {name, type, values, defined_in, characteristics}).
402
403%%----------------------------------------------------------------------
404%% List all known packages
405%% 'native' and 'all' are not real packages
406%%----------------------------------------------------------------------
407
408packages() ->
409    [
410     "g",        % Generic
411     "root",	 % Base Root Package
412     "tonegen",	 % Tone Generator Package
413     "tonedet",	 % Tone Detection Package
414     "dg",	 % Basic DTMF Generator Package
415     "dd",	 % DTMF detection Package
416     "cg",	 % Call Progress Tones Generator Package
417     "cd",	 % Call Progress Tones Detection Package
418     "al",	 % Analog Line Supervision Package
419     "ct",	 % Basic Continuity Package
420     "nt",	 % Network Package
421     "rtp",	 % RTP Package
422     "swb",	 % SwitchBoard Package
423     "tdmc",     % TDM Circuit Package
424     ""          % Native pseudo package
425    ].
426
427%%----------------------------------------------------------------------
428%% List all matching capabilities
429%%----------------------------------------------------------------------
430
431capabilities(Package) ->
432    case Package of
433        "g"       -> capabilities_g();
434        "root"    -> capabilities_root();
435        "tonegen" -> capabilities_tonegen();
436        "tonedet" -> capabilities_tonedet();
437        "dg"      -> capabilities_dg();
438        "dd"      -> capabilities_dd();
439        "cg"      -> capabilities_cg();
440        "cd"      -> capabilities_cd();
441        "al"      -> capabilities_al();
442        "ct"      -> capabilities_ct();
443        "nt"      -> capabilities_nt();
444        "rtp"     -> capabilities_rtp();
445	"swb"     -> capabilities_swb();
446        "tdmc"    -> capabilities_tdmc();
447        ""        -> capabilities_native()
448    end.
449
450%%----------------------------------------------------------------------
451%% Decode package name to internal form
452%% Scope  ::= property | event | signal | statistics
453%%----------------------------------------------------------------------
454
455decode(mid, Package) ->
456    decode_mid(Package);
457decode(package, Package) ->
458    decode_package(Package);
459decode(profile, Package) ->
460    decode_profile(Package);
461decode(dialplan, Dialplan) ->
462    decode_dialplan(Dialplan);
463decode(Scope, [A, B | Item]) when is_atom(Scope) ->
464    ?d("decode(~p) -> entry with"
465       "~n   A:    ~p"
466       "~n   B:    ~p"
467       "~n   Item: ~p", [Scope, A, B, Item]),
468    case decode_package([A, B]) of
469	"" ->
470 	    ?d("decode -> \"no\" package",[]),
471	    decode_item(Scope, [A, B], Item);
472	Package ->
473 	    ?d("decode -> Package: ~p", [Package]),
474	    Package ++ "/" ++ decode_item(Scope, [A, B], Item)
475    end;
476decode({Scope, [A, B | Item]}, SubItem) when is_atom(Scope) ->
477    ?d("decode(~p) -> entry with"
478       "~n   A:       ~p"
479       "~n   B:       ~p"
480       "~n   Item:    ~p"
481       "~n   SubItem: ~p", [Scope, A, B, Item, SubItem]),
482    decode_item({Scope, Item}, [A, B], SubItem).
483
484decode_item(Scope, [A, B], Item) ->
485    ?d("decode_item -> entry",[]),
486    case A of
487        16#00 ->
488            case B of
489                16#01 -> decode_g(Scope, Item);
490                16#02 -> decode_root(Scope, Item);
491                16#03 -> decode_tonegen(Scope, Item);
492                16#04 -> decode_tonedet(Scope, Item);
493                16#05 -> decode_dg(Scope, Item);
494                16#06 -> decode_dd(Scope, Item);
495                16#07 -> decode_cg(Scope, Item);
496                16#08 -> decode_cd(Scope, Item);
497                16#09 -> decode_al(Scope, Item);
498                16#0a -> decode_ct(Scope, Item);
499                16#0b -> decode_nt(Scope, Item);
500                16#0c -> decode_rtp(Scope, Item);
501                16#0d -> decode_tdmc(Scope, Item);
502                16#00 -> decode_native(Scope, Item)
503            end;
504        16#fe ->
505            case B of
506                %% Proprietary extension
507                16#fe -> decode_swb(Scope, Item)
508            end;
509        16#ff ->
510            case B of
511                16#ff when Item =:= [16#ff, 16#ff] -> "*"
512            end
513    end.
514
515decode_package(Package) ->
516    ?d("decode_package -> entry with"
517       "~n   Package: ~p", [Package]),
518    [A, B] = Package,
519    case A of
520        16#00 ->
521            case B of
522                16#01 -> "g";
523                16#02 -> "root";
524                16#03 -> "tonegen";
525                16#04 -> "tonedet";
526                16#05 -> "dg";
527                16#06 -> "dd";
528                16#07 -> "cg";
529                16#08 -> "cd";
530                16#09 -> "al";
531                16#0a -> "ct";
532                16#0b -> "nt";
533                16#0c -> "rtp";
534                16#0d -> "tdmc";
535                16#00 -> ""
536            end;
537        16#fe ->
538            case B of
539                16#fe ->  "swb"
540            end;
541        16#ff ->
542            case B of
543                16#ff -> "*"
544            end
545    end.
546
547decode_profile([A, B]) ->
548    case A of
549        16#00 ->
550            case B of
551                16#fe -> "resgw";
552		_     -> "profile" ++ [A + $0, B + $0]
553            end;
554	_ ->
555	    "profile" ++ [A + $0, B + $0]
556    end.
557
558decode_dialplan([A, B]) ->
559    "dialplan" ++ [A + $0, B + $0].
560
561decode_mid(Mid) ->
562    case Mid of
563	{domainName, DN} ->
564	    Lower = to_lower(DN#'DomainName'.name),
565	    {domainName, DN#'DomainName'{name = Lower}};
566	{deviceName, PathName} ->
567	    Lower = to_lower(PathName),
568	    {deviceName, Lower};
569	Other ->
570	    Other
571    end.
572
573to_lower(Chars) ->
574    [?LOWER(Char) || Char <- Chars].
575
576%%----------------------------------------------------------------------
577%% Encode package name from internal form
578%% Scope  ::= property | event | signal | statistics
579%%----------------------------------------------------------------------
580
581encode(mid, Package) ->
582    encode_mid(Package);
583encode(package, Package) ->
584    encode_package(Package);
585encode(profile, Profile) ->
586    encode_profile(Profile);
587encode(dialplan, Dialplan) ->
588    encode_dialplan(Dialplan);
589encode(Scope, PackageItem) when is_atom(Scope) ->
590    ?d("encode(~p) -> entry with"
591       "~n   PackageItem: ~p", [Scope, PackageItem]),
592    case string:tokens(PackageItem, [$/]) of
593	[Package, Item] ->
594	    ?d("encode -> "
595	       "~n   Package: ~p"
596	       "~n   Item:    ~p", [Package, Item]),
597	    encode_package(Package) ++ encode_item(Scope, Package, Item);
598	[Item] ->
599	    ?d("encode -> Item: ~p", [Item]),
600	    [16#00, 16#00 | encode_native(Scope, Item)]
601    end;
602encode({Scope, PackageItem}, SubItem) when is_atom(Scope) ->
603    ?d("encode(~p) -> entry with"
604       "~n   PackageItem: ~p"
605       "~n   SubItem:     ~p", [Scope, PackageItem, SubItem]),
606    case string:tokens(PackageItem, [$/]) of
607	[Package, Item] ->
608	    ?d("encode -> "
609	       "~n   Package: ~p"
610	       "~n   Item:    ~p", [Package, Item]),
611	    encode_item({Scope, Item}, Package, SubItem);
612	[_Item] ->
613	    ?d("encode -> _Item: ~p", [_Item]),
614	    encode_native(Scope, SubItem)
615    end.
616
617encode_item(_Scope, _Package, "*") ->
618    [16#ff, 16#ff];
619encode_item(Scope, Package, Item) ->
620    ?d("encode_item(~s) -> entry", [Package]),
621    case Package of
622        "g"       -> encode_g(Scope, Item);
623        "root"    -> encode_root(Scope, Item);
624        "tonegen" -> encode_tonegen(Scope, Item);
625        "tonedet" -> encode_tonedet(Scope, Item);
626        "dg"      -> encode_dg(Scope, Item);
627        "dd"      -> encode_dd(Scope, Item);
628        "cg"      -> encode_cg(Scope, Item);
629        "cd"      -> encode_cd(Scope, Item);
630        "al"      -> encode_al(Scope, Item);
631        "ct"      -> encode_ct(Scope, Item);
632        "nt"      -> encode_nt(Scope, Item);
633        "rtp"     -> encode_rtp(Scope, Item);
634        "tdmc"    -> encode_tdmc(Scope, Item);
635        "swb"     -> encode_swb(Scope, Item)
636    end.
637
638encode_package(Package) ->
639    case Package of
640        "g"       -> [16#00, 16#01];
641        "root"    -> [16#00, 16#02];
642        "tonegen" -> [16#00, 16#03];
643        "tonedet" -> [16#00, 16#04];
644        "dg"      -> [16#00, 16#05];
645        "dd"      -> [16#00, 16#06];
646        "cg"      -> [16#00, 16#07];
647        "cd"      -> [16#00, 16#08];
648        "al"      -> [16#00, 16#09];
649        "ct"      -> [16#00, 16#0a];
650        "nt"      -> [16#00, 16#0b];
651        "rtp"     -> [16#00, 16#0c];
652        "tdmc"    -> [16#00, 16#0d];
653        ""        -> [16#00, 16#00];
654	"*"       -> [16#ff, 16#ff];
655        "swb"     -> [16#fe, 16#fe]
656    end.
657
658encode_profile(Profile) ->
659    case Profile of
660        "resgw" ->
661	    [16#00, 16#fe];
662	[$p, $r, $o, $f, $i, $l, $e | Name] ->
663	    case Name of
664		[A, B] -> [A - $0, B - $0];
665		[B]    -> [0, B - $0];
666		[]     -> [0, 0]
667	    end
668    end.
669
670encode_dialplan(Dialplan) ->
671    case Dialplan of
672	[$d, $i, $a, $l, $p, $l, $a, $n | Name] ->
673	    case Name of
674		[A, B] -> [A - $0, B - $0];
675		[B]    -> [0, B - $0];
676		[]     -> [0, 0]
677	    end
678    end.
679
680encode_mid(Mid) ->
681    Mid.
682
683
684%%----------------------------------------------------------------------
685%% Name:    g - Generic
686%% Version: 1
687%% Extends: None
688%% Purpose: Generic package for commonly encountered items
689%%----------------------------------------------------------------------
690
691capabilities_g() ->
692    [
693     {event, "cause"},
694     {event, "sc"}
695    ].
696
697encode_g(event, Item) ->
698    case Item of
699	"cause"  -> [16#00, 16#01];
700	"sc"     -> [16#00, 16#02]
701    end;
702
703encode_g({event_parameter, Item}, SubItem) ->
704    case Item of
705	"cause"  ->
706	    case SubItem of
707		"Generalcause" -> [16#00, 16#01];
708		"Failurecause" -> [16#00, 16#02]
709	    end;
710	"sc" ->
711	    case SubItem of
712		"SigID" -> [16#00, 16#01];
713		"Meth"  -> [16#00, 16#02];
714		"SLID"  -> [16#00, 16#03];
715		"RID"   -> [16#00, 16#04]
716	    end
717    end.
718
719decode_g(event, Item) ->
720    case Item of
721	[16#00, 16#01] -> "cause";
722	[16#00, 16#02] -> "sc"
723    end;
724
725decode_g({event_parameter, Item}, SubItem) ->
726    case Item of
727        [16#00, 16#01] -> % Event: cause
728            case SubItem of
729                [16#00, 16#01] -> "Generalcause";
730		[16#00, 16#02] -> "Failurecause"
731            end;
732
733        [16#00, 16#02] -> % Event: sc
734            case SubItem of
735                [16#00, 16#01] -> "SigID";
736                [16#00, 16#02] -> "Meth";
737		[16#00, 16#03] -> "SLID";
738		[16#00, 16#04] -> "RID"
739            end
740    end.
741
742
743%%----------------------------------------------------------------------
744%% Name:    root - Base Root Package
745%% Version: 2
746%% Extends: None
747%% Purpose: This package defines Gateway wide properties.
748%%----------------------------------------------------------------------
749
750capabilities_root() ->
751    [
752     {property, "maxNumberOfContexts"},
753     {property, "maxTerminationsPerContext"},
754     {property, "normalMGExecutionTime"},
755     {property, "normalMGCExecutionTime"},
756     {property, "MGProvisionalResponseTimerValue"},
757     {property, "MGCProvisionalResponseTimerValue"},
758     {property, "MGCOriginatedPendingLimit"},
759     {property, "MGOriginatedPendingLimit"}
760    ].
761
762encode_root(Scope, Item) ->
763    case Scope of
764        property ->
765            case Item of
766                "maxNumberOfContexts"              -> [16#00, 16#01];
767                "maxTerminationsPerContext"        -> [16#00, 16#02];
768                "normalMGExecutionTime"            -> [16#00, 16#03];
769                "normalMGCExecutionTime"           -> [16#00, 16#04];
770                "MGProvisionalResponseTimerValue"  -> [16#00, 16#05];
771                "MGCProvisionalResponseTimerValue" -> [16#00, 16#06];
772                "MGCOriginatedPendingLimit"        -> [16#00, 16#07];
773                "MGOriginatedPendingLimit"         -> [16#00, 16#08]
774            end
775    end.
776
777decode_root(Scope, Item) ->
778    case Scope of
779        property ->
780            case Item of
781                [16#00, 16#01] -> "maxNumberOfContexts";
782                [16#00, 16#02] -> "maxTerminationsPerContext";
783                [16#00, 16#03] -> "normalMGExecutionTime";
784                [16#00, 16#04] -> "normalMGCExecutionTime";
785                [16#00, 16#05] -> "MGProvisionalResponseTimerValue";
786		[16#00, 16#06] -> "MGCProvisionalResponseTimerValue";
787		[16#00, 16#07] -> "MGCOriginatedPendingLimit";
788		[16#00, 16#08] -> "MGOriginatedPendingLimit"
789            end
790    end.
791
792
793%%----------------------------------------------------------------------
794%% Name:    tonegen - Tone Generator Package
795%% Version: 2
796%% Extends: None
797%% Purpose: This package defines signals to generate audio tones.
798%%          This package does not specify parameter values. It is
799%%          intended to be extendable. Generally, tones are defined
800%%          as an individual signal with a parameter, ind,
801%%          representing "interdigit" time delay, and a tone id to
802%%          be used with playtones.  A tone id should be kept
803%%          consistent with any tone generation for the same tone.
804%%          MGs are expected to be provisioned with the characteristics
805%%          of appropriate tones for the country in which the MG is located.
806%%----------------------------------------------------------------------
807
808capabilities_tonegen() ->
809    [
810     {signal, "pt"}
811    ].
812
813encode_tonegen(signal, Item) ->
814    case Item of
815	"pt" -> [16#00, 16#01]
816    end;
817
818encode_tonegen({signal_parameter, Item}, SubItem) ->
819    case Item of
820        "pt" ->
821            case SubItem of
822                "tl"  -> [16#00, 16#01];
823                "ind" -> [16#00, 16#02];
824                "btd" -> [16#00, 16#03]
825            end
826    end.
827
828decode_tonegen(signal, Item) ->
829    case Item of
830	[16#00, 16#01] -> "pt"
831    end;
832
833decode_tonegen({signal_parameter, Item}, SubItem) ->
834    case Item of
835        [16#00, 16#01] -> % Event: pt
836            case SubItem of
837                [16#00, 16#01] -> "tl";
838                [16#00, 16#02] -> "ind";
839                [16#00, 16#03] -> "btd"
840            end
841    end.
842
843
844%%----------------------------------------------------------------------
845%% Name:    tonedet - Tone Detection Package
846%% Version: 1
847%% Extends: None
848%% Purpose: This Package defines events for audio tone detection.
849%%          Tones are selected by name (tone id). MGs are expected
850%%          to be provisioned with the characteristics of appropriate
851%%          tones for the country in which the MG is located.
852%%
853%%          This package does not specify parameter values.
854%%          It is intended to be extendable.
855%%----------------------------------------------------------------------
856
857capabilities_tonedet() ->
858    [
859     {event, "std"},
860     {event, "etd"},
861     {event, "ltd"}
862    ].
863
864encode_tonedet(event, Item) ->
865    case Item of
866	"std" -> [16#00, 16#01];
867	"etd" -> [16#00, 16#02];
868	"ltd" -> [16#00, 16#03]
869    end;
870
871encode_tonedet({event_parameter, Item}, SubItem) ->
872    case Item of
873        "std" ->
874            case SubItem of
875                "tl"  -> [16#00, 16#01];
876                "tid" -> [16#00, 16#03]
877            end;
878        "etd" ->
879            case SubItem of
880                "tl"  -> [16#00, 16#01];
881                "tid" -> [16#00, 16#03];
882                "dur" -> [16#00, 16#02]
883            end;
884        "ltd" ->
885            case SubItem of
886                "tl"  -> [16#00, 16#01];
887                "dur" -> [16#00, 16#02];
888                "tid" -> [16#00, 16#03]
889            end
890    end.
891
892decode_tonedet(event, Item) ->
893    case Item of
894	[16#00, 16#01] -> "std";
895	[16#00, 16#02] -> "etd";
896	[16#00, 16#03] -> "ltd"
897    end;
898
899decode_tonedet({event_parameter, Item}, SubItem) ->
900    case Item of
901        [16#00, 16#01] -> % Event std
902            case SubItem of
903                [16#00, 16#01] -> "tl";
904                [16#00, 16#03] -> "tid"
905            end;
906        [16#00, 16#02] -> % Event etd
907            case SubItem of
908                [16#00, 16#01] -> "tl";
909                [16#00, 16#03] -> "tid";
910                [16#00, 16#02] -> "dur"
911            end;
912        [16#00, 16#03] -> % Event ltd
913            case SubItem of
914                [16#00, 16#01] -> "tl";
915                [16#00, 16#02] -> "dur";
916                [16#00, 16#03] -> "tid"
917            end
918    end.
919
920%%----------------------------------------------------------------------
921%% Name:    dg - Basic DTMF Generator Package
922%% Version: 1
923%% Extends: tonegen  version 1
924%% Purpose: This package defines the basic DTMF tones as signals and
925%%          extends the allowed values of parameter tl of playtone
926%%          in tonegen.
927%%----------------------------------------------------------------------
928
929capabilities_dg() ->
930    [
931     {signal, "d0"},
932     {signal, "d1"},
933     {signal, "d2"},
934     {signal, "d3"},
935     {signal, "d4"},
936     {signal, "d5"},
937     {signal, "d6"},
938     {signal, "d7"},
939     {signal, "d8"},
940     {signal, "d9"},
941     {signal, "ds"},
942     {signal, "do"},
943     {signal, "da"},
944     {signal, "db"},
945     {signal, "dc"},
946     {signal, "dd"}
947    ].
948
949encode_dg(signal, Item) ->
950    case Item of
951	"d0" -> [16#00, 16#10];
952	"d1" -> [16#00, 16#11];
953	"d2" -> [16#00, 16#12];
954	"d3" -> [16#00, 16#13];
955	"d4" -> [16#00, 16#14];
956	"d5" -> [16#00, 16#15];
957	"d6" -> [16#00, 16#16];
958	"d7" -> [16#00, 16#17];
959	"d8" -> [16#00, 16#18];
960	"d9" -> [16#00, 16#19];
961	"ds" -> [16#00, 16#20];
962	"do" -> [16#00, 16#21];
963	"da" -> [16#00, 16#1a];
964	"db" -> [16#00, 16#1b];
965	"dc" -> [16#00, 16#1c];
966	"dd" -> [16#00, 16#1d]
967    end;
968
969encode_dg({signal_parameter, Item}, SubItem) ->
970    case Item of
971	"d0" ->
972	    case SubItem of
973		"btd" -> [16#00, 16#01]
974	    end;
975	"d1" ->
976	    case SubItem of
977		"btd" -> [16#00, 16#01]
978	    end;
979	"d2" ->
980	    case SubItem of
981		"btd" -> [16#00, 16#01]
982	    end;
983	"d3" ->
984	    case SubItem of
985		"btd" -> [16#00, 16#01]
986	    end;
987	"d4" ->
988	    case SubItem of
989		"btd" -> [16#00, 16#01]
990	    end;
991	"d5" ->
992	    case SubItem of
993		"btd" -> [16#00, 16#01]
994	    end;
995	"d6" ->
996	    case SubItem of
997		"btd" -> [16#00, 16#01]
998	    end;
999	"d7" ->
1000	    case SubItem of
1001		"btd" -> [16#00, 16#01]
1002	    end;
1003	"d8" ->
1004	    case SubItem of
1005		"btd" -> [16#00, 16#01]
1006	    end;
1007	"d9" ->
1008	    case SubItem of
1009		"btd" -> [16#00, 16#01]
1010	    end;
1011	"ds" ->
1012	    case SubItem of
1013		"btd" -> [16#00, 16#01]
1014	    end;
1015	"do" ->
1016	    case SubItem of
1017		"btd" -> [16#00, 16#01]
1018	    end;
1019	"da" ->
1020	    case SubItem of
1021		"btd" -> [16#00, 16#01]
1022	    end;
1023	"db" ->
1024	    case SubItem of
1025		"btd" -> [16#00, 16#01]
1026	    end;
1027	"dc" ->
1028	    case SubItem of
1029		"btd" -> [16#00, 16#01]
1030	    end;
1031	"dd" ->
1032	    case SubItem of
1033		"btd" -> [16#00, 16#01]
1034	    end
1035    end.
1036
1037decode_dg(signal, Item) ->
1038    case Item of
1039	[16#00, 16#10] -> "d0";
1040	[16#00, 16#11] -> "d1";
1041	[16#00, 16#12] -> "d2";
1042	[16#00, 16#13] -> "d3";
1043	[16#00, 16#14] -> "d4";
1044	[16#00, 16#15] -> "d5";
1045	[16#00, 16#16] -> "d6";
1046	[16#00, 16#17] -> "d7";
1047	[16#00, 16#18] -> "d8";
1048	[16#00, 16#19] -> "d9";
1049	[16#00, 16#20] -> "ds";
1050	[16#00, 16#21] -> "do";
1051	[16#00, 16#1a] -> "da";
1052	[16#00, 16#1b] -> "db";
1053	[16#00, 16#1c] -> "dc";
1054	[16#00, 16#1d] -> "dd"
1055    end;
1056
1057decode_dg({signal_parameter, Item}, SubItem) ->
1058    case Item of
1059	[16#00, 16#10] ->
1060	    case SubItem of
1061		[16#00, 16#01] -> "btd"
1062	    end;
1063	[16#00, 16#11] ->
1064	    case SubItem of
1065		[16#00, 16#01] -> "btd"
1066	    end;
1067	[16#00, 16#12] ->
1068	    case SubItem of
1069		[16#00, 16#01] -> "btd"
1070	    end;
1071	[16#00, 16#13] ->
1072	    case SubItem of
1073		[16#00, 16#01] -> "btd"
1074	    end;
1075	[16#00, 16#14] ->
1076	    case SubItem of
1077		[16#00, 16#01] -> "btd"
1078	    end;
1079	[16#00, 16#15] ->
1080	    case SubItem of
1081		[16#00, 16#01] -> "btd"
1082	    end;
1083	[16#00, 16#16] ->
1084	    case SubItem of
1085		[16#00, 16#01] -> "btd"
1086	    end;
1087	[16#00, 16#17] ->
1088	    case SubItem of
1089		[16#00, 16#01] -> "btd"
1090	    end;
1091	[16#00, 16#18] ->
1092	    case SubItem of
1093		[16#00, 16#01] -> "btd"
1094	    end;
1095	[16#00, 16#19] ->
1096	    case SubItem of
1097		[16#00, 16#01] -> "btd"
1098	    end;
1099	[16#00, 16#20] ->
1100	    case SubItem of
1101		[16#00, 16#01] -> "btd"
1102	    end;
1103	[16#00, 16#21] ->
1104	    case SubItem of
1105		[16#00, 16#01] -> "btd"
1106	    end;
1107	[16#00, 16#1a] ->
1108	    case SubItem of
1109		[16#00, 16#01] -> "btd"
1110	    end;
1111	[16#00, 16#1b] ->
1112	    case SubItem of
1113		[16#00, 16#01] -> "btd"
1114	    end;
1115	[16#00, 16#1c] ->
1116	    case SubItem of
1117		[16#00, 16#01] -> "btd"
1118	    end;
1119	[16#00, 16#1d] ->
1120	    case SubItem of
1121		[16#00, 16#01] -> "btd"
1122	    end
1123    end.
1124
1125
1126%%----------------------------------------------------------------------
1127%% Name:    dd - DTMF detection Package
1128%% Version: 1
1129%% Extends: tonedet version 1
1130%% Purpose: This package defines the basic DTMF tones detection.
1131%%          Tones are selected by name (tone id). MGs are expected
1132%%          to be provisioned with the characteristics of appropriate
1133%%          tones for the country in which the MG is located.
1134%%
1135%%          This package does not specify parameter values.
1136%%          It is intended to be extendable.
1137%%
1138%% Additional tone id values are all tone ids described in package dg
1139%% (basic DTMF generator package).
1140%%
1141%% The following table maps DTMF events to digit map symbols as described
1142%% in section 7.1.14.
1143%%
1144%%                    _________________________________
1145%%                   | DTMF Event        | Symbol     |
1146%%                   | d0                |  "0"       |
1147%%                   | d1                |  "1"       |
1148%%                   | d2                |  "2"       |
1149%%                   | d3                |  "3"       |
1150%%                   | d4                |  "4"       |
1151%%                   | d5                |  "5"       |
1152%%                   | d6                |  "6"       |
1153%%                   | d7                |  "7"       |
1154%%                   | d8                |  "8"       |
1155%%                   | d9                |  "9"       |
1156%%                   | da                |  "A" or "a"|
1157%%                   | db                |  "B" or "b"|
1158%%                   | dc                |  "C" or "c"|
1159%%                   | dd                |  "D" or "d"|
1160%%                   | ds                |  "E" or "e"|
1161%%                   | do                |  "F" or "f"|
1162%%                   |___________________|____________|
1163%%
1164%%----------------------------------------------------------------------
1165
1166capabilities_dd() ->
1167    [
1168     {event, "ce"},
1169     {event, "d0"},
1170     {event, "d1"},
1171     {event, "d2"},
1172     {event, "d3"},
1173     {event, "d4"},
1174     {event, "d5"},
1175     {event, "d6"},
1176     {event, "d7"},
1177     {event, "d8"},
1178     {event, "d9"},
1179     {event, "ds"},
1180     {event, "do"},
1181     {event, "da"},
1182     {event, "db"},
1183     {event, "dc"},
1184     {event, "dd"}
1185    ].
1186
1187encode_dd(event, Item) ->
1188    case Item of
1189	"ce" -> [16#00, 16#04];
1190	"d0" -> [16#00, 16#10];
1191	"d1" -> [16#00, 16#11];
1192	"d2" -> [16#00, 16#12];
1193	"d3" -> [16#00, 16#13];
1194	"d4" -> [16#00, 16#14];
1195	"d5" -> [16#00, 16#15];
1196	"d6" -> [16#00, 16#16];
1197	"d7" -> [16#00, 16#17];
1198	"d8" -> [16#00, 16#18];
1199	"d9" -> [16#00, 16#19];
1200	"ds" -> [16#00, 16#20];
1201	"do" -> [16#00, 16#21];
1202	"da" -> [16#00, 16#1a];
1203	"db" -> [16#00, 16#1b];
1204	"dc" -> [16#00, 16#1c];
1205	"dd" -> [16#00, 16#1d]
1206    end;
1207
1208encode_dd({event_parameter, Item}, SubItem) ->
1209    case Item of
1210        "ce" ->
1211            case SubItem of
1212                "ds"   -> [16#00, 16#01];
1213		"Meth" -> [16#00, 16#03]
1214            end;
1215	"d0" ->
1216	    case SubItem of
1217		"btd" -> [16#00, 16#01]
1218	    end;
1219	"d1" ->
1220	    case SubItem of
1221		"btd" -> [16#00, 16#01]
1222	    end;
1223	"d2" ->
1224	    case SubItem of
1225		"btd" -> [16#00, 16#01]
1226	    end;
1227	"d3" ->
1228	    case SubItem of
1229		"btd" -> [16#00, 16#01]
1230	    end;
1231	"d4" ->
1232	    case SubItem of
1233		"btd" -> [16#00, 16#01]
1234	    end;
1235	"d5" ->
1236	    case SubItem of
1237		"btd" -> [16#00, 16#01]
1238	    end;
1239	"d6" ->
1240	    case SubItem of
1241		"btd" -> [16#00, 16#01]
1242	    end;
1243	"d7" ->
1244	    case SubItem of
1245		"btd" -> [16#00, 16#01]
1246	    end;
1247	"d8" ->
1248	    case SubItem of
1249		"btd" -> [16#00, 16#01]
1250	    end;
1251	"d9" ->
1252	    case SubItem of
1253		"btd" -> [16#00, 16#01]
1254	    end;
1255	"ds" ->
1256	    case SubItem of
1257		"btd" -> [16#00, 16#01]
1258	    end;
1259	"do" ->
1260	    case SubItem of
1261		"btd" -> [16#00, 16#01]
1262	    end;
1263	"da" ->
1264	    case SubItem of
1265		"btd" -> [16#00, 16#01]
1266	    end;
1267	"db" ->
1268	    case SubItem of
1269		"btd" -> [16#00, 16#01]
1270	    end;
1271	"dc" ->
1272	    case SubItem of
1273		"btd" -> [16#00, 16#01]
1274	    end;
1275	"dd" ->
1276	    case SubItem of
1277		"btd" -> [16#00, 16#01]
1278	    end
1279    end.
1280
1281decode_dd(event, Item) ->
1282    case Item of
1283	[16#00, 16#04] -> "ce";
1284	[16#00, 16#10] -> "d0";
1285	[16#00, 16#11] -> "d1";
1286	[16#00, 16#12] -> "d2";
1287	[16#00, 16#13] -> "d3";
1288	[16#00, 16#14] -> "d4";
1289	[16#00, 16#15] -> "d5";
1290	[16#00, 16#16] -> "d6";
1291	[16#00, 16#17] -> "d7";
1292	[16#00, 16#18] -> "d8";
1293	[16#00, 16#19] -> "d9";
1294	[16#00, 16#20] -> "ds";
1295	[16#00, 16#21] -> "do";
1296	[16#00, 16#1a] -> "da";
1297	[16#00, 16#1b] -> "db";
1298	[16#00, 16#1c] -> "dc";
1299	[16#00, 16#1d] -> "dd"
1300    end;
1301
1302decode_dd({event_parameter, Item}, SubItem) ->
1303    case Item of
1304	[16#00, 16#04] -> % Event ce
1305            case SubItem of
1306                [16#00, 16#01] -> "ds";
1307		[16#00, 16#03] -> "Meth"
1308            end;
1309	[16#00, 16#10] ->
1310	    case SubItem of
1311		[16#00, 16#01] -> "btd"
1312	    end;
1313	[16#00, 16#11] ->
1314	    case SubItem of
1315		[16#00, 16#01] -> "btd"
1316	    end;
1317	[16#00, 16#12] ->
1318	    case SubItem of
1319		[16#00, 16#01] -> "btd"
1320	    end;
1321	[16#00, 16#13] ->
1322	    case SubItem of
1323		[16#00, 16#01] -> "btd"
1324	    end;
1325	[16#00, 16#14] ->
1326	    case SubItem of
1327		[16#00, 16#01] -> "btd"
1328	    end;
1329	[16#00, 16#15] ->
1330	    case SubItem of
1331		[16#00, 16#01] -> "btd"
1332	    end;
1333	[16#00, 16#16] ->
1334	    case SubItem of
1335		[16#00, 16#01] -> "btd"
1336	    end;
1337	[16#00, 16#17] ->
1338	    case SubItem of
1339		[16#00, 16#01] -> "btd"
1340	    end;
1341	[16#00, 16#18] ->
1342	    case SubItem of
1343		[16#00, 16#01] -> "btd"
1344	    end;
1345	[16#00, 16#19] ->
1346	    case SubItem of
1347		[16#00, 16#01] -> "btd"
1348	    end;
1349	[16#00, 16#20] ->
1350	    case SubItem of
1351		[16#00, 16#01] -> "btd"
1352	    end;
1353	[16#00, 16#21] ->
1354	    case SubItem of
1355		[16#00, 16#01] -> "btd"
1356	    end;
1357	[16#00, 16#1a] ->
1358	    case SubItem of
1359		[16#00, 16#01] -> "btd"
1360	    end;
1361	[16#00, 16#1b] ->
1362	    case SubItem of
1363		[16#00, 16#01] -> "btd"
1364	    end;
1365	[16#00, 16#1c] ->
1366	    case SubItem of
1367		[16#00, 16#01] -> "btd"
1368	    end;
1369	[16#00, 16#1d] ->
1370	    case SubItem of
1371		[16#00, 16#01] -> "btd"
1372	    end
1373    end.
1374
1375%%----------------------------------------------------------------------
1376%% Name:    cg - Call Progress Tones Generator Package
1377%% Version: 1
1378%% Extends: tonegen version 1
1379%% Purpose: This package defines the basic call progress tones as signals
1380%%          and extends the allowed values of the tl parameter of
1381%%          playtone in tonegen.
1382%%----------------------------------------------------------------------
1383
1384capabilities_cg() ->
1385    [
1386     {signal, "dt"},
1387     {signal, "rt"},
1388     {signal, "bt"},
1389     {signal, "ct"},
1390     {signal, "sit"},
1391     {signal, "wt"},
1392     {signal, "prt"},
1393     {signal, "cw"},
1394     {signal, "cr"}
1395    ].
1396
1397
1398encode_cg(Scope, Item) ->
1399    case Scope of
1400        signal ->
1401            case Item of
1402                "dt"  -> [16#00, 16#30];
1403                "rt"  -> [16#00, 16#31];
1404                "bt"  -> [16#00, 16#32];
1405                "ct"  -> [16#00, 16#33];
1406                "sit" -> [16#00, 16#34];
1407                "wt"  -> [16#00, 16#35];
1408                "prt" -> [16#00, 16#36];
1409                "cw"  -> [16#00, 16#37];
1410                "cr"  -> [16#00, 16#38]
1411            end
1412    end.
1413
1414decode_cg(Scope, Item) ->
1415    case Scope of
1416        signal ->
1417            case Item of
1418                [16#00, 16#30] -> "dt";
1419                [16#00, 16#31] -> "rt";
1420                [16#00, 16#32] -> "bt";
1421                [16#00, 16#33] -> "ct";
1422                [16#00, 16#34] -> "sit";
1423                [16#00, 16#35] -> "wt";
1424                [16#00, 16#36] -> "prt";
1425                [16#00, 16#37] -> "cw";
1426                [16#00, 16#38] -> "cr"
1427            end
1428    end.
1429
1430%%----------------------------------------------------------------------
1431%% Name:    cd - Call Progress Tones Detection Package
1432%% Version: 1
1433%% Extends: tonedet version 1
1434%% Purpose: This package defines the basic call progress detection tones.
1435%%          This Package extends the possible values of tone id
1436%%          in the "start tone detected", "end tone detected" and
1437%%          "long tone detected" events.
1438%%       Additional values
1439%%             tone id values are defined for start tone detected,
1440%%                   end tone detected and long tone detected with
1441%%                   the same values as those in package cg (call
1442%%                   progress tones generation package).
1443%%
1444%% The required set of tone ids corresponds to Recommendation E.180/Q.35
1445%% [ITU-T Recommendation E.180/Q.35 (1998)].  See Recommendation E.180/Q.35
1446%% for definition of the meanings of these tones.
1447%%----------------------------------------------------------------------
1448
1449capabilities_cd() ->
1450    [
1451     {event, "dt"},
1452     {event, "rt"},
1453     {event, "bt"},
1454     {event, "ct"},
1455     {event, "sit"},
1456     {event, "wt"},
1457     {event, "prt"},
1458     {event, "cw"},
1459     {event, "cr"}
1460    ].
1461
1462
1463encode_cd(Scope, Item) ->
1464    case Scope of
1465        event ->
1466            case Item of
1467                "dt" -> [16#00, 16#30];
1468                "rt" -> [16#00, 16#31];
1469                "bt" -> [16#00, 16#32];
1470                "ct" -> [16#00, 16#33];
1471                "sit"-> [16#00, 16#34];
1472                "wt" -> [16#00, 16#35];
1473                "prt"-> [16#00, 16#36];
1474                "cw" -> [16#00, 16#37];
1475                "cr" -> [16#00, 16#38]
1476            end
1477    end.
1478
1479decode_cd(Scope, Item) ->
1480    case Scope of
1481        event ->
1482            case Item of
1483                [16#00, 16#30] -> "dt";
1484                [16#00, 16#31] -> "rt";
1485                [16#00, 16#32] -> "bt";
1486                [16#00, 16#33] -> "ct";
1487                [16#00, 16#34] -> "sit";
1488                [16#00, 16#35] -> "wt";
1489                [16#00, 16#36] -> "prt";
1490                [16#00, 16#37] -> "cw";
1491                [16#00, 16#38] -> "cr"
1492            end
1493    end.
1494
1495%%----------------------------------------------------------------------
1496%% Name:    al - Analog Line Supervision Package
1497%% Version: 1
1498%% Extends: None
1499%% Purpose: This package defines events and signals for an analog line.
1500%%----------------------------------------------------------------------
1501
1502capabilities_al() ->
1503    [
1504     {event,  "on"},
1505     {event,  "of"},
1506     {event,  "fl"},
1507     {signal, "ri"}
1508    ].
1509
1510encode_al(event, Item) ->
1511    ?d("encode_al(event) -> entry with"
1512       "~n   Item: ~p", [Item]),
1513    case Item of
1514	"on" -> [16#00, 16#04];
1515	"of" -> [16#00, 16#05];
1516	"fl" -> [16#00, 16#06]
1517    end;
1518
1519encode_al({event_parameter, Item}, SubItem) ->
1520    ?d("encode_al({event_parameter,~p}) -> entry with"
1521       "~n   SubItem: ~p", [Item, SubItem]),
1522    case Item of
1523	"on" ->
1524            case SubItem of
1525                "strict" -> [16#00, 16#01];
1526                "init"   -> [16#00, 16#02]
1527            end;
1528        "of" ->
1529            case SubItem of
1530                "strict" -> [16#00, 16#01];
1531                "init"   -> [16#00, 16#02]
1532            end;
1533        "fl" ->
1534            case SubItem of
1535                "mindur" -> [16#00, 16#04];
1536                "maxdur" -> [16#00, 16#05]
1537            end
1538    end;
1539
1540encode_al(signal, Item) ->
1541    ?d("encode_al(signal) -> entry with"
1542       "~n   Item: ~p", [Item]),
1543    case Item of
1544	"ri"    -> [16#00, 16#02]
1545    end;
1546
1547encode_al({signal_parameter, Item}, SubItem) ->
1548    ?d("encode_al({signal_parameter,~p}) -> entry with"
1549       "~n   SubItem: ~p", [Item, SubItem]),
1550    case Item of
1551        "ri" ->
1552            case SubItem of
1553                "cad"  -> [16#00, 16#06];
1554                "freq" -> [16#00, 16#07]
1555            end
1556    end.
1557
1558decode_al(event, SubItem) ->
1559    ?d("decode_al(event) -> entry with"
1560       "~n   SubItem: ~p", [SubItem]),
1561    case SubItem of
1562	[16#00, 16#04] -> "on";
1563	[16#00, 16#05] -> "of";
1564	[16#00, 16#06] -> "fl"
1565    end;
1566
1567decode_al({event_parameter, Item}, SubItem) ->
1568    ?d("decode_al({event_parameter,~p}) -> entry with"
1569       "~n   SubItem: ~p", [Item, SubItem]),
1570    case Item of
1571        [16#00,16#04] -> %% Event: on
1572            case SubItem of
1573		[16#00, 16#01] -> "strict";
1574                [16#00, 16#02] -> "init"
1575            end;
1576        [16#00,16#05] -> %% Event: of
1577            case SubItem of
1578		[16#00, 16#01] -> "strict";
1579                [16#00, 16#02] -> "init"
1580            end;
1581        [16#00,16#06] -> %% Event: fl
1582            case SubItem of
1583		[16#00, 16#04] -> "mindur";
1584                [16#00, 16#05] -> "maxdur"
1585            end
1586    end;
1587
1588decode_al(signal, SubItem) ->
1589    ?d("decode_al(signal) -> entry with"
1590       "~n   SubItem: ~p", [SubItem]),
1591    case SubItem of
1592	[16#00, 16#02] -> "ri"
1593    end;
1594
1595decode_al({signal_parameter, Item}, SubItem) ->
1596    ?d("decode_al({signal_parameter,~p}) -> entry with"
1597       "~n   SubItem: ~p", [Item, SubItem]),
1598    case Item of
1599        [16#00,16#02] -> %% Event: ri
1600            case SubItem of
1601		[16#00, 16#06] -> "cad";
1602                [16#00, 16#07] -> "freq"
1603            end
1604    end.
1605
1606
1607%%----------------------------------------------------------------------
1608%% Name:    ct - Basic Continuity Package
1609%% Version: 1
1610%% Extends: None
1611%% Purpose: This package defines events and signals for continuity test.
1612%%          The continuity test includes provision of either a loopback
1613%%          or transceiver functionality.
1614%%----------------------------------------------------------------------
1615
1616capabilities_ct() ->
1617    [
1618     {event,  "cmp"},
1619     {signal, "ct"},
1620     {signal, "rsp"}
1621    ].
1622
1623encode_ct(event, Item) ->
1624    case Item of
1625	"cmp" -> [16#00, 16#05]
1626    end;
1627encode_ct({event_parameter, Item}, SubItem) ->
1628    case Item of
1629        "cmp" ->
1630            case SubItem of
1631                "res" -> [16#00, 16#08]
1632            end
1633    end;
1634encode_ct(signal, Item) ->
1635    case Item of
1636	"ct"  -> [16#00, 16#03];
1637	"rsp" -> [16#00, 16#04]
1638    end.
1639
1640decode_ct(event, Item) ->
1641    case Item of
1642	[16#00, 16#05] -> "cmp"
1643    end;
1644decode_ct({event_parameter, Item}, SubItem) ->
1645    case Item of
1646        [16#00, 16#05] -> % Event cmp
1647            case SubItem of
1648                [16#00, 16#08] -> "res"
1649            end
1650    end;
1651decode_ct(signal, Item) ->
1652    case Item of
1653	[16#00, 16#03] -> "ct";
1654	[16#00, 16#04] -> "rsp"
1655    end.
1656
1657%%----------------------------------------------------------------------
1658%% Name:    nt - Network Package
1659%% Version: 1
1660%% Extends: None
1661%% Purpose: This package defines properties of network terminations
1662%%          independent of network type.
1663%%----------------------------------------------------------------------
1664
1665capabilities_nt() ->
1666    [
1667     {property,   "jit"},
1668     {event,      "netfail"},
1669     {event,      "qualert"},
1670     {statistics, "dur"},
1671     {statistics, "os"},
1672     {statistics, "or"}
1673    ].
1674
1675encode_nt(property, Item) ->
1676    case Item of
1677	"jit" -> [16#00, 16#07]
1678    end;
1679encode_nt(event, Item) ->
1680    case Item of
1681	"netfail" -> [16#00, 16#05];
1682	"qualert" -> [16#00, 16#06]
1683    end;
1684encode_nt({event_parameter, Item}, SubItem) ->
1685    case Item of
1686        "netfail" ->
1687            case SubItem of
1688                "cs" -> [16#00, 16#01]
1689            end;
1690        "qualert" ->
1691            case SubItem of
1692                "th"  -> [16#00, 16#01]
1693            end
1694    end;
1695encode_nt(statistics, Item) ->
1696    case Item of
1697	"dur" -> [16#00, 16#01];
1698	"os"  -> [16#00, 16#02];
1699	"or"  -> [16#00, 16#03]
1700    end.
1701
1702decode_nt(property, Item) ->
1703    case Item of
1704	[16#00, 16#07] -> "jit"
1705    end;
1706decode_nt(event, Item) ->
1707    case Item of
1708	[16#00, 16#05] -> "netfail";
1709	[16#00, 16#06] -> "qualert"
1710    end;
1711decode_nt({event_parameter, Item}, SubItem) ->
1712    case Item of
1713        [16#00, 16#05] -> % Event netfail
1714            case SubItem of
1715                [16#00, 16#01] -> "cs"
1716            end;
1717        [16#00, 16#06] -> % Event qualert
1718            case Item of
1719                [16#00, 16#01] -> "th"
1720            end
1721	end;
1722decode_nt(statistics, Item) ->
1723    case Item of
1724	[16#00, 16#01] -> "dur";
1725	[16#00, 16#02] -> "os";
1726	[16#00, 16#03] -> "or"
1727    end.
1728
1729%%----------------------------------------------------------------------
1730%% Name:    rtp - RTP Package
1731%% Version: 1
1732%% Extends: nt version 1
1733%% Purpose: This package is used to support packet based multimedia
1734%%          data transfer by means of the Real-time Transport Protocol
1735%%          (RTP) [RFC 1889].
1736%%----------------------------------------------------------------------
1737
1738capabilities_rtp() ->
1739    [
1740     {event,      "pltrans"},
1741     {statistics, "ps"},
1742     {statistics, "pr"},
1743     {statistics, "pl"},
1744     {statistics, "jit"},
1745     {statistics, "delay"}
1746    ].
1747
1748encode_rtp(event, Item) ->
1749    case Item of
1750	"pltrans" -> [16#00, 16#01]
1751    end;
1752encode_rtp({event_parameter, Item}, SubItem) ->
1753    case Item of
1754        "pltrans" ->
1755            case SubItem of
1756                "rtppltype" -> [16#00, 16#01]
1757            end
1758    end;
1759encode_rtp(statistics, Item) ->
1760    case Item of
1761	"ps"    -> [16#00, 16#04];
1762	"pr"    -> [16#00, 16#05];
1763	"pl"    -> [16#00, 16#06];
1764	"jit"   -> [16#00, 16#07];
1765	"delay" -> [16#00, 16#08]
1766    end.
1767
1768decode_rtp(event, Item) ->
1769    case Item of
1770	[16#00, 16#01] -> "pltrans"
1771    end;
1772decode_rtp({event_parameter, Item}, SubItem) ->
1773    case Item of
1774        [16#00, 16#01] -> % Event pltrans
1775            case SubItem of
1776                [16#00, 16#01] -> "rtppltype"
1777            end
1778    end;
1779decode_rtp(statistics, Item) ->
1780    case Item of
1781	[16#00, 16#04] -> "ps";
1782	[16#00, 16#05] -> "pr";
1783	[16#00, 16#06] -> "pl";
1784	[16#00, 16#07] -> "jit";
1785	[16#00, 16#08] -> "delay"
1786    end.
1787
1788
1789%%----------------------------------------------------------------------
1790%% Name:    tdmc - TDM Circuit Package
1791%% Version: 1
1792%% Extends: nt version 1
1793%% Purpose: This package is used to support TDM circuit terminations.
1794%%----------------------------------------------------------------------
1795
1796capabilities_tdmc() ->
1797    [
1798     {property, "ec"},
1799     {property, "gain"}
1800    ].
1801
1802encode_tdmc(Scope, Item) ->
1803    case Scope of
1804        property ->
1805            case Item of
1806                "ec"   -> [16#00, 16#08];
1807                "gain" -> [16#00, 16#0a]
1808            end
1809    end.
1810
1811decode_tdmc(Scope, Item) ->
1812    case Scope of
1813        property ->
1814            case Item of
1815                [16#00, 16#08] -> "ec";
1816                [16#00, 16#0a] -> "gain"
1817            end
1818    end.
1819
1820
1821%%----------------------------------------------------------------------
1822%% Name:    swb - SwitchBoard Package
1823%% Version: 1
1824%% Extends: none
1825%% Purpose: This package is used to support SwitchBoard specials
1826%%----------------------------------------------------------------------
1827
1828capabilities_swb() ->
1829    [
1830     {statistics, "fs"}, % Free slots
1831     {statistics, "as"}  % Allocated slots
1832    ].
1833
1834encode_swb(Scope, Item) ->
1835    case Scope of
1836        statistics ->
1837            case Item of
1838                "fs" -> [16#00, 16#00];
1839                "as" -> [16#00, 16#01]
1840            end
1841    end.
1842
1843decode_swb(Scope, Item) ->
1844    case Scope of
1845        statistics ->
1846            case Item of
1847                [16#00, 16#00] -> "fs";
1848                [16#00, 16#01] -> "as"
1849            end
1850    end.
1851
1852
1853%%----------------------------------------------------------------------
1854%% Name:  native -  Pseudo package
1855%% Version: 1
1856%% Extends: None
1857%% Purpose: Native tags for media stream properties
1858%%
1859%% Parameters for Local descriptors and Remote descriptors are
1860%% specified as tag-value pairs if binary encoding is used for the
1861%% protocol.  This annex contains the property names (PropertyID), the
1862%% tags (Property Tag), type of the property (Type) and the values
1863%% (Value).Values presented in the Value field when the field contains
1864%% references shall be regarded as "information". The reference
1865%% contains the normative values.  If a value field does not contain a
1866%% reference then the values in that field can be considered as
1867%% "normative".
1868%%
1869%% Tags are given as hexadecimal numbers in this annex. When setting
1870%% the value of a property, a MGC may underspecify the value according
1871%% to one of the mechanisms specified in section 7.1.1.
1872%%
1873%% For type "enumeration" the value is represented by the value in brack-
1874%% ets, e.g., Send(0), Receive(1).
1875%%----------------------------------------------------------------------
1876%%
1877%% C.6.  IP
1878%%
1879%%     ________________________________________________________________
1880%%    | PropertyID|  Tag       |  Type        |  Value                |
1881%%    | IPv4      |  6001      |  32 BITS     |  Ipv4Address          |
1882%%    | IPv6      |  6002      |  128 BITS    |  IPv6 Address         |
1883%%    | Port      |  6003      |  Unsigned Int|  Port                 |
1884%%    | Porttype  |  6004      |  Enumerated  |  TCP(0),UDP(1),SCTP(2)|
1885%%    |___________|____________|______________|_______________________|
1886%%
1887%%
1888%% C.11.  SDP Equivalents
1889%%
1890%%      ______________________________________________________________
1891%%     | PropertyID|  Tag |  Type  |  Value                          |
1892%%     | SDP_V     |  B001|  STRING|  Protocol Version               |
1893%%     | SDP_O     |  B002|  STRING|  Owner-creator and session ID   |
1894%%     | SDP_S     |  B003|  STRING|  Sesson name                    |
1895%%     | SDP_I     |  B004|  STRING|  Session identifier             |
1896%%     | SDP_U     |  B005|  STRING|  URI of descriptor              |
1897%%     | SDC_E     |  B006|  STRING|  email address                  |
1898%%     | SDP_P     |  B007|  STRING|  phone number                   |
1899%%     | SDP_C     |  B008|  STRING|  Connection information         |
1900%%     | SDP_B     |  B009|  STRING|  Bandwidth Information          |
1901%%     | SDP_Z     |  B00A|  STRING|  time zone adjustment           |
1902%%     | SDP_K     |  B00B|  STRING|  Encryption Key                 |
1903%%     | SDP_A     |  B00C|  STRING|  Zero or more session attributes|
1904%%     | SDP_T     |  B00D|  STRING|  Active Session Time            |
1905%%     | SDP_R     |  B00E|  STRING|  Zero or more repeat times      |
1906%%     | SDP_M     |  B00F|  STRING|  Media name and transport addr  |
1907%%     |           |      |        |  Reference: IETF RFC 2327       |
1908%%     |___________|______|________|_________________________________|
1909%%
1910%%----------------------------------------------------------------------
1911
1912capabilities_native() ->
1913    [
1914     %% C.6.  IP
1915     {property, "IPv4"},
1916     {property, "IPv6"},
1917     {property, "Port"},
1918     {property, "Porttype"},
1919
1920     %% C.11. SDP Equivalents
1921     {property, "v"},
1922     {property, "o"},
1923     {property, "s"},
1924     {property, "i"},
1925     {property, "u"},
1926     {property, "e"},
1927     {property, "p"},
1928     {property, "c"},
1929     {property, "b"},
1930     {property, "z"},
1931     {property, "k"},
1932     {property, "a"},
1933     {property, "t"},
1934     {property, "r"},
1935     {property, "m"}
1936    ].
1937
1938encode_native(Scope, Item) ->
1939    case Scope of
1940        property ->
1941	    case Item of
1942		%% IP
1943		"IPv4"     -> [16#60, 16#01];
1944		"IPv6"     -> [16#60, 16#02];
1945		"Port"     -> [16#60, 16#03];
1946		"Porttype" -> [16#60, 16#04];
1947
1948		%% SDP
1949		"v" -> [16#b0, 16#01];
1950		"o" -> [16#b0, 16#02];
1951		"s" -> [16#b0, 16#03];
1952		"i" -> [16#b0, 16#04];
1953		"u" -> [16#b0, 16#05];
1954		"e" -> [16#b0, 16#06];
1955		"p" -> [16#b0, 16#07];
1956		"c" -> [16#b0, 16#08];
1957		"b" -> [16#b0, 16#09];
1958		"z" -> [16#b0, 16#0a];
1959		"k" -> [16#b0, 16#0b];
1960		"a" -> [16#b0, 16#0c];
1961		"t" -> [16#b0, 16#0d];
1962		"r" -> [16#b0, 16#0e];
1963		"m" -> [16#b0, 16#0f]
1964	    end
1965    end.
1966
1967decode_native(Scope, [Type, Item]) ->
1968    case Scope of
1969        property ->
1970            case Type of
1971		16#60 ->
1972		    case Item of
1973			16#01 -> "IPv4";
1974			16#02 -> "IPv6";
1975			16#03 -> "Port";
1976			16#04 -> "Porttype"
1977		    end;
1978
1979                16#b0 ->
1980		    case Item of
1981			16#01 -> "v";
1982			16#02 -> "o";
1983			16#03 -> "s";
1984			16#04 -> "i";
1985			16#05 -> "u";
1986			16#06 -> "e";
1987			16#07 -> "p";
1988			16#08 -> "c";
1989			16#09 -> "b";
1990			16#0a -> "z";
1991			16#0b -> "k";
1992			16#0c -> "a";
1993			16#0d -> "t";
1994			16#0e -> "r";
1995			16#0f -> "m"
1996		    end
1997            end
1998    end.
1999
2000%% -------------------------------------------------------------------
2001
2002% error(Reason) ->
2003%     erlang:error(Reason).
2004
2005