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