1 /*
2  * h235caps.h
3  *
4  * H.235 Capability wrapper class.
5  *
6  * h323plus library
7  *
8  * Copyright (c) 2011 Spranto Australia Pty Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.1 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Alternatively, the contents of this file may be used under the terms
16  * of the General Public License (the  "GNU License"), in which case the
17  * provisions of GNU License are applicable instead of those
18  * above. If you wish to allow use of your version of this file only
19  * under the terms of the GNU License and not to allow others to use
20  * your version of this file under the MPL, indicate your decision by
21  * deleting the provisions above and replace them with the notice and
22  * other provisions required by the GNU License. If you do not delete
23  * the provisions above, a recipient may use your version of this file
24  * under either the MPL or the GNU License."
25  *
26  * Software distributed under the License is distributed on an "AS IS"
27  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
28  * the License for the specific language governing rights and limitations
29  * under the License.
30  *
31  *
32  * The Initial Developer of the Original Code is ISVO (Asia) Pte. Ltd.
33  *
34  *
35  * Contributor(s): ______________________________________.
36  *
37  * $Id $
38  *
39  *
40  */
41 
42 #include "h323caps.h"
43 
44 #ifdef H323_H235
45 
46 #pragma once
47 
48 class H245_EncryptionAuthenticationAndIntegrity;
49 class H235SecurityCapability  : public H323Capability
50 {
51   PCLASSINFO(H235SecurityCapability, H323Capability);
52 
53   public:
54 
55   /**@name Construction */
56 
57     /**Create the Security capability
58       */
59     H235SecurityCapability(H323Capabilities * capabilities, unsigned capabilityNo);
60     ~H235SecurityCapability();
61 
62   //@}
63 
64   /**@name Overrides from class PObject */
65   //@{
66     /**Create a copy of the object.
67       */
68     virtual PObject * Clone() const;
69   //@}
70 
71   /**@name Identification functions */
72   //@{
73     /**Get the main type of the capability.
74      */
75     virtual MainTypes GetMainType() const;
76 
77     /**Get the sub-type of the capability. This is a code dependent on the
78        main type of the capability.
79      */
80     virtual unsigned GetSubType()  const;
81 
82     /**Get the name of the media data format this class represents.
83      */
84     virtual PString GetFormatName() const;
85 
86     /**Validate that the capability is usable given the connection.
87        This checks agains the negotiated protocol version number and remote
88        application to determine if this capability should be used in TCS or
89        OLC pdus.
90 
91        The default behaviour returns TRUE.
92       */
93     virtual PBoolean IsUsable(
94       const H323Connection & connection) const;
95   //@}
96 
97   /**@name Operations */
98   //@{
99     /**Create the channel instance, allocating resources as required.
100        This creates a logical channel object appropriate for the parameters
101        provided. Not if param is NULL, sessionID must be provided, otherwise
102        this is taken from the fields in param.
103      */
104     virtual H323Channel * CreateChannel(
105       H323Connection & connection,    ///< Owner connection for channel
106       H323Channel::Directions dir,    ///< Direction of channel
107       unsigned sessionID,             ///< Session ID for RTP channel
108       const H245_H2250LogicalChannelParameters * param
109                                       ///< Parameters for channel
110     ) const;
111 
112     /**Create the codec instance, allocating resources as required.
113      */
114     virtual H323Codec * CreateCodec(
115       H323Codec::Direction direction  ///< Direction in which this instance runs
116     ) const;
117 
118     /**Get the default RTP session.
119        This function gets the default RTP session ID for the capability
120        type. For example audio capabilities return the value
121        RTP_Session::DefaultAudioSessionID etc.
122 
123        The default behaviour returns zero, indicating it is not an RTP
124        based capability.
125       */
126     unsigned GetDefaultSessionID() const;
127 
128   //@}
129 
130   /**@name Protocol manipulation */
131   //@{
132     /**This function is called whenever and outgoing TerminalCapabilitySet
133        PDU is being constructed for the control channel. It allows the
134        capability to set the PDU fields from information in members specific
135        to the class.
136 
137        The default behaviour is pure.
138      */
139     virtual PBoolean OnSendingPDU(
140       H245_Capability & pdu  ///< PDU to set information on
141     ) const;
142 
143     /**This function is called whenever and outgoing OpenLogicalChannel
144        PDU is being constructed for the control channel. It allows the
145        capability to set the PDU fields from information in members specific
146        to the class.
147 
148        The default behaviour is pure.
149      */
150     virtual PBoolean OnSendingPDU(
151       H245_DataType & pdu  ///< PDU to set information on
152     ) const;
153 
154     /**This function is called whenever and outgoing RequestMode
155        PDU is being constructed for the control channel. It allows the
156        capability to set the PDU fields from information in members specific
157        to the class.
158 
159        The default behaviour calls the OnSendingPDU() function with a more
160        specific PDU type.
161      */
162     virtual PBoolean OnSendingPDU(
163       H245_ModeElement & pdu  ///< PDU to set information on
164     ) const;
165 
166     /**This function is called whenever and incoming TerminalCapabilitySet
167        PDU is received on the control channel, and a new H323Capability
168        descendent was created. This completes reading fields from the PDU
169        into the classes members.
170 
171        If the function returns FALSE then the received PDU codec description
172        is not supported, so will be ignored. The default behaviour simply
173        returns TRUE.
174      */
175     virtual PBoolean OnReceivedPDU(
176       const H245_Capability & pdu  ///< PDU to get information from
177     );
178 
179     /**This function is called whenever and incoming OpenLogicalChannel
180        PDU has been used to construct the control channel. It allows the
181        capability to set from the PDU fields, information in members specific
182        to the class.
183 
184        The default behaviour is pure.
185      */
186     virtual PBoolean OnReceivedPDU(
187       const H245_DataType & pdu,  ///< PDU to get information from
188       PBoolean receiver               ///< Is receiver OLC
189     );
190 
191     /**This function is called whenever and incoming OpenLogicalChannel
192        PDU has been used to construct the control channel. It allows the
193        capability to set from the PDU fields, information in members specific
194        to the class.
195      */
196     PBoolean OnSendingPDU(
197        H245_EncryptionAuthenticationAndIntegrity & encAuth,  ///< Encryption Algorithms
198        H323Capability::CommandType type = e_TCS              ///< Message Type
199     ) const;
200 
201 
202     /**This function is called whenever and incoming OpenLogicalChannel
203        PDU has been used to construct the control channel. It allows the
204        capability to set from the PDU fields, information in members specific
205        to the class.
206      */
207     PBoolean OnReceivedPDU(
208        const H245_EncryptionAuthenticationAndIntegrity & encAuth,  ///< Encryption Algorithms
209        H323Capability::CommandType type = e_TCS                    ///< Message Type
210     ) const;
211 
212 
213     /**Set the Associated Capability Number
214       */
215     virtual void SetAssociatedCapability(unsigned capNumber);
216 
217     /**Merge the Algorithms
218       */
219     PBoolean MergeAlgorithms(
220         const PStringArray & remote   ///< List of remote algorithms
221     );
222 
223     /**Get the number of Algorithms in the list
224       */
225     PINDEX GetAlgorithmCount();
226 
227     /**Get the current Algorithms
228       */
229     PString GetAlgorithm();
230 
231   //@}
232 
233   protected:
234       H323Capabilities * m_capabilities;
235       unsigned m_capNumber;
236       PStringList m_capList;
237 };
238 
239 
240 ////////////////////////////////////////////////////////////////////////////////////////
241 /**This class describes the secure interface to a codec that has channels based on
242    the RTP protocol.
243 
244    An application may create a descendent off this class and override
245    functions as required for descibing the codec.
246  */
247 
248 enum H235ChType {
249     H235ChNew,          /// New Channel (Template)
250     H235ChClone,        /// Clone Channel (Primary)
251     H235Channel,        /// Connection Channel
252 };
253 
254 class H323SecureRealTimeCapability  : public H323Capability
255 {
256 public:
257 
258   PCLASSINFO(H323SecureRealTimeCapability, H323Capability);
259 
260   /**@name Constructor/Deconstructor */
261   //@{
262     /**Constructor
263       */
264          H323SecureRealTimeCapability(
265           H323Capability * childCapability,          ///< Child Capability
266           H323Capabilities * capabilities = NULL,    ///< Capabilities reference
267           unsigned secNo = 0,                        ///< Security Capability No
268           PBoolean active = false                    ///< Whether encryption Activated
269           );
270 
271       H323SecureRealTimeCapability(
272           RTP_QOS * _rtpqos,
273           H323Capability * childCapability
274           );
275 
276     /**Deconstructor
277       */
278       ~H323SecureRealTimeCapability();
279   //@}
280 
281   /**@name Operations */
282   //@{
283     /**Create the channel instance, allocating resources as required.
284      */
285     virtual H323Channel * CreateChannel(
286       H323Connection & connection,    /// Owner connection for channel
287       H323Channel::Directions dir,    /// Direction of channel
288       unsigned sessionID,             /// Session ID for RTP channel
289       const H245_H2250LogicalChannelParameters * param
290                                       /// Parameters for channel
291     ) const;
292 
293     /// Get unique capability number.
294     virtual unsigned GetCapabilityNumber() const;
295 
296     /// Set unique capability number.
297     virtual void SetCapabilityNumber(unsigned num);
298 
299     /// Attach QoS
300     void AttachQoS(RTP_QOS * _rtpqos);
301 
302     /// Set the Associated Capability
303     virtual void SetAssociatedCapability(unsigned  _secNo);
304 
305     /// Set the Capability List
306     virtual void SetCapabilityList(H323Capabilities * capabilities);
307 
308     /// Set the encryption active
309     virtual void SetEncryptionActive(PBoolean active);
310 
311     /// Is encryption active
312     virtual PBoolean IsEncryptionActive() const;
313 
314     /// Set Algorithm
315     virtual void SetEncryptionAlgorithm(const PString & alg);
316 
317     /// Get Algorithm
318     virtual const PString & GetEncryptionAlgorithm() const;
319 
320     /// Get the MediaFormat for this capability.
321     virtual const OpalMediaFormat & GetMediaFormat() const;
322 
323     virtual OpalMediaFormat & GetWritableMediaFormat();
324   //@}
325 
326 protected:
327     H323Capability * ChildCapability;    /// Child Capability
328     H235ChType chtype;                   /// Channel Type
329     PBoolean  m_active;                  /// Whether encryption is active
330     H323Capabilities * m_capabilities;   /// Capabilities list
331     unsigned  m_secNo;                   /// Security Capability
332     RTP_QOS * nrtpqos;                   /// RTP QOS
333     PString   m_algorithm;               /// Algorithm for encryption
334 
335 };
336 
337 
338 /////////////////////////////////////////////////////////////////////////////////////////
339 
340 /**This class describes the interface to a secure codec used to transfer data
341    via the logical channels opened and managed by the H323 control channel.
342 
343    An application may create a descendent off this class and override
344    functions as required for descibing a codec.
345  */
346 class H323SecureCapability : public H323SecureRealTimeCapability
347 {
348   PCLASSINFO(H323SecureCapability, H323SecureRealTimeCapability);
349 
350   public:
351   /**@name Construction */
352   //@{
353 
354     /**Create an encrypted audio based capability
355       */
356     H323SecureCapability(
357         H323Capability & childCapability,          ///< Child Capability
358         enum H235ChType Ch = H235ChNew,            ///< ChannelType
359         H323Capabilities * capabilities = NULL,    ///< Capabilities reference
360         unsigned secNo = 0,                        ///< Security Capability No
361         PBoolean active = false                    ///< Whether encryption is active or not
362     );
363 
364   //@}
365 
366   /**@name Overrides from class PObject */
367   //@{
368     /**Create a copy of the object.
369       */
370     virtual PObject * Clone() const;
371 
372     /**Compare
373       */
374     PObject::Comparison Compare(const PObject & obj) const;
375   //@}
376 
377   /**@name Identification functions */
378   //@{
379     /**Get the main type of the capability.
380        Always returns e_Audio.
381      */
382     virtual MainTypes GetMainType() const;
383 
384     /**Get the sub-type of the capability. This is a code dependent on the
385        main type of the capability.
386 
387        This returns one of the four possible combinations of mode and speed
388        using the enum values of the protocol ASN H245_AudioCapability class.
389      */
390     virtual unsigned GetSubType() const;
391 
392     /**Get Generic Identifier
393         Default returns PString::Empty
394      */
395     virtual PString GetIdentifier() const;
396 
397     /**Get the name of the media data format this class represents.
398      */
399     virtual PString GetFormatName() const;
400 
401    /**Create the Codec */
402     H323Codec * CreateCodec(H323Codec::Direction direction) const;
403   //@}
404 
405   /**@name Operations */
406   //@{
407     /**Get the default RTP session.
408        This function gets the default RTP session ID for the capability
409        type. For example audio capabilities return the value
410        RTP_Session::DefaultAudioSessionID etc.
411 
412        The default behaviour returns zero, indicating it is not an RTP
413        based capability.
414       */
415     virtual unsigned GetDefaultSessionID() const;
416   //@}
417 
418   /**@name Protocol manipulation */
419   //@{
420     /**This function is called whenever and outgoing TerminalCapabilitySet
421        PDU is being constructed for the control channel. It allows the
422        capability to set the PDU fields from information in members specific
423        to the class.
424 
425        The default behaviour calls the OnSendingPDU() function with a more
426        specific PDU type.
427      */
428     virtual PBoolean OnSendingPDU(
429       H245_Capability & pdu  /// PDU to set information on
430     ) const;
431 
432     /**This function is called whenever and outgoing OpenLogicalChannel
433        PDU is being constructed for the control channel. It allows the
434        capability to set the PDU fields from information in members specific
435        to the class.
436 
437        The default behaviour calls the OnSendingPDU() function with a more
438        specific PDU type.
439      */
440     virtual PBoolean OnSendingPDU(
441       H245_DataType & pdu  /// PDU to set information on
442     ) const;
443 
444     /**This function is called whenever and outgoing RequestMode
445        PDU is being constructed for the control channel. It allows the
446        capability to set the PDU fields from information in members specific
447        to the class.
448 
449        The default behaviour calls the OnSendingPDU() function with a more
450        specific PDU type.
451      */
452     virtual PBoolean OnSendingPDU(
453       H245_ModeElement & pdu  /// PDU to set information on
454     ) const;
455 
456     /**This function is called whenever and incoming TerminalCapabilitySet
457        PDU is received on the control channel, and a new H323Capability
458        descendent was created. This completes reading fields from the PDU
459        into the classes members.
460 
461        If the function returns FALSE then the received PDU codec description
462        is not supported, so will be ignored.
463 
464        The default behaviour calls the OnReceivedPDU() that takes a
465        H245_AudioCapability and clamps the txFramesInPacket.
466      */
467 
468     virtual PBoolean OnReceivedPDU(
469       const H245_Capability & pdu  /// PDU to get information from
470     );
471 
472     /**This function is called whenever and incoming OpenLogicalChannel
473        PDU has been used to construct the control channel. It allows the
474        capability to set from the PDU fields, information in members specific
475        to the class.
476 
477        The default behaviour calls the OnReceivedPDU() that takes a
478        H245_AudioCapability and clamps the txFramesInPacket or
479        rxFramesInPacket.
480      */
481     virtual PBoolean OnReceivedPDU(
482       const H245_DataType & pdu,  /// PDU to get information from
483       PBoolean receiver                  /// is receiver OLC
484     );
485 
486     /**Compare the sub capability.
487       */
488     virtual PBoolean IsMatch(
489       const PASN_Choice & subTypePDU  ///<  sub-type PDU of H323Capability
490     ) const;
491 
492     /**Compare the security part of the capability, if applicable.
493       */
494     virtual PBoolean IsSubMatch(
495       const PASN_Choice & subTypePDU  ///<  sub-type PDU of H323Capability
496     ) const;
497 
498     /**Get Child Capability
499       */
GetChildCapability()500     H323Capability * GetChildCapability() const { return ChildCapability; }
501 
502     /**Validate that the capability is usable given the connection.
503        This checks agains the negotiated protocol version number and remote
504        application to determine if this capability should be used in TCS or
505        OLC pdus.
506 
507        The default behaviour returns TRUE.
508       */
IsUsable(const H323Connection & connection)509     virtual PBoolean IsUsable(
510       const H323Connection & connection
511       ) const { return ChildCapability->IsUsable(connection); }
512   //@}
513 
514     /**Get the direction for this capability.
515       */
GetCapabilityDirection()516     CapabilityDirection GetCapabilityDirection() const
517         { return ChildCapability->GetCapabilityDirection(); }
518 
519     /**Set the direction for this capability.
520       */
SetCapabilityDirection(CapabilityDirection dir)521     void SetCapabilityDirection(
522       CapabilityDirection dir   /// New direction code
523     ) { ChildCapability->SetCapabilityDirection(dir); }
524 
525     /// Get the payload type for the capaibility
GetPayloadType()526     RTP_DataFrame::PayloadTypes GetPayloadType() const
527         { return ChildCapability->GetPayloadType(); }
528 
529   //@}
530 
531 };
532 
533 ////////////////////////////////////////////////////////////////////////////////////////
534 /**This class describes the interface to a secure extended codec used to transfer data
535    via the logical channels opened and managed by the H323 control channel.
536 
537    An application may create a descendent off this class and override
538    functions as required for descibing a codec.
539  */
540 
541 class H323SecureExtendedCapability  : public H323ExtendedVideoCapability
542 {
543 public:
544 
545   PCLASSINFO(H323SecureExtendedCapability, H323ExtendedVideoCapability);
546 
547   /**@name Constructor/Deconstructor */
548   //@{
549     /**Constructor
550       */
551          H323SecureExtendedCapability(
552           H323Capability * childCapability,          ///< Child Capability
553           enum H235ChType Ch = H235ChNew,            ///< ChannelType
554           H323Capabilities * capabilities = NULL,    ///< Capabilities reference
555           unsigned secNo = 0,                        ///< Security Capability No
556           PBoolean active = false                    ///< Whether encryption Activated
557           );
558 
559       H323SecureExtendedCapability(
560           RTP_QOS * _rtpqos,
561           H323Capability * childCapability
562           );
563 
564     /**Deconstructor
565       */
566       ~H323SecureExtendedCapability();
567   //@}
568 
569   /**@name Operations */
570   //@{
571     /**Create the channel instance, allocating resources as required.
572      */
573     virtual H323Channel * CreateChannel(
574       H323Connection & connection,    /// Owner connection for channel
575       H323Channel::Directions dir,    /// Direction of channel
576       unsigned sessionID,             /// Session ID for RTP channel
577       const H245_H2250LogicalChannelParameters * param
578                                       /// Parameters for channel
579     ) const;
580 
581     /// Get unique capability number.
582     virtual unsigned GetCapabilityNumber() const;
583 
584     /// Set unique capability number.
585     virtual void SetCapabilityNumber(unsigned num);
586 
587     /// Attach QoS
588     void AttachQoS(RTP_QOS * _rtpqos);
589 
590     /// Set the Associated Capability
591     virtual void SetAssociatedCapability(unsigned  _secNo);
592 
593     /// Set the Capability List
594     virtual void SetCapabilityList(H323Capabilities * capabilities);
595 
596     /// Set the encryption active
597     virtual void SetEncryptionActive(PBoolean active);
598 
599     /// Is encryption active
600     virtual PBoolean IsEncryptionActive() const;
601 
602     /// Set Algorithm
603     virtual void SetEncryptionAlgorithm(const PString & alg);
604 
605     /// Get Algorithm
606     virtual const PString & GetEncryptionAlgorithm() const;
607 
608     /// Get the MediaFormat for this capability.
609     virtual const OpalMediaFormat & GetMediaFormat() const;
610 
611     virtual OpalMediaFormat & GetWritableMediaFormat();
612   //@}
613 
614   /**@name Overrides from class PObject */
615   //@{
616     /**Create a copy of the object.
617       */
618     virtual PObject * Clone() const;
619 
620     /**Compare
621       */
622     PObject::Comparison Compare(const PObject & obj) const;
623   //@}
624 
625   /**@name Identification functions */
626   //@{
627     /**Get the main type of the capability.
628        Always returns e_Audio.
629      */
630     virtual MainTypes GetMainType() const;
631 
632     /**Get the sub-type of the capability. This is a code dependent on the
633        main type of the capability.
634 
635        This returns one of the four possible combinations of mode and speed
636        using the enum values of the protocol ASN H245_AudioCapability class.
637      */
638     virtual unsigned GetSubType() const;
639 
640     /**Get Generic Identifier
641         Default returns PString::Empty
642      */
643     virtual PString GetIdentifier() const;
644 
645     /**Get the name of the media data format this class represents.
646      */
647     virtual PString GetFormatName() const;
648 
649    /**Create the Codec */
650     H323Codec * CreateCodec(H323Codec::Direction direction) const;
651   //@}
652 
653   /**@name Operations */
654   //@{
655     /**Get the default RTP session.
656        This function gets the default RTP session ID for the capability
657        type. For example audio capabilities return the value
658        RTP_Session::DefaultAudioSessionID etc.
659 
660        The default behaviour returns zero, indicating it is not an RTP
661        based capability.
662       */
663     virtual unsigned GetDefaultSessionID() const;
664   //@}
665 
666   /**@name Protocol manipulation */
667   //@{
668     /**This function is called whenever and outgoing TerminalCapabilitySet
669        PDU is being constructed for the control channel. It allows the
670        capability to set the PDU fields from information in members specific
671        to the class.
672 
673        The default behaviour calls the OnSendingPDU() function with a more
674        specific PDU type.
675      */
676     virtual PBoolean OnSendingPDU(
677       H245_Capability & pdu  /// PDU to set information on
678     ) const;
679 
680     /**This function is called whenever and outgoing OpenLogicalChannel
681        PDU is being constructed for the control channel. It allows the
682        capability to set the PDU fields from information in members specific
683        to the class.
684 
685        The default behaviour calls the OnSendingPDU() function with a more
686        specific PDU type.
687      */
688     virtual PBoolean OnSendingPDU(
689       H245_DataType & pdu  /// PDU to set information on
690     ) const;
691 
692     /**This function is called whenever and outgoing RequestMode
693        PDU is being constructed for the control channel. It allows the
694        capability to set the PDU fields from information in members specific
695        to the class.
696 
697        The default behaviour calls the OnSendingPDU() function with a more
698        specific PDU type.
699      */
700     virtual PBoolean OnSendingPDU(
701       H245_ModeElement & pdu  /// PDU to set information on
702     ) const;
703 
704     /**This function is called whenever and incoming TerminalCapabilitySet
705        PDU is received on the control channel, and a new H323Capability
706        descendent was created. This completes reading fields from the PDU
707        into the classes members.
708 
709        If the function returns FALSE then the received PDU codec description
710        is not supported, so will be ignored.
711 
712        The default behaviour calls the OnReceivedPDU() that takes a
713        H245_AudioCapability and clamps the txFramesInPacket.
714      */
715 
716     virtual PBoolean OnReceivedPDU(
717       const H245_Capability & pdu  /// PDU to get information from
718     );
719 
720     /**This function is called whenever and incoming OpenLogicalChannel
721        PDU has been used to construct the control channel. It allows the
722        capability to set from the PDU fields, information in members specific
723        to the class.
724 
725        The default behaviour calls the OnReceivedPDU() that takes a
726        H245_AudioCapability and clamps the txFramesInPacket or
727        rxFramesInPacket.
728      */
729     virtual PBoolean OnReceivedPDU(
730       const H245_DataType & pdu,  /// PDU to get information from
731       PBoolean receiver                  /// is receiver OLC
732     );
733 
734     /**Compare the sub capability.
735       */
736     virtual PBoolean IsMatch(
737       const PASN_Choice & subTypePDU  ///<  sub-type PDU of H323Capability
738     ) const;
739 
740     /**Compare the security part of the capability, if applicable.
741       */
742     virtual PBoolean IsSubMatch(
743       const PASN_Choice & subTypePDU  ///<  sub-type PDU of H323Capability
744     ) const;
745 
746     /**Get Child Capability
747       */
GetChildCapability()748     H323Capability * GetChildCapability() const { return ChildCapability; }
749 
750     /**Validate that the capability is usable given the connection.
751        This checks agains the negotiated protocol version number and remote
752        application to determine if this capability should be used in TCS or
753        OLC pdus.
754 
755        The default behaviour returns TRUE.
756       */
IsUsable(const H323Connection & connection)757     virtual PBoolean IsUsable(
758       const H323Connection & connection
759       ) const { return ChildCapability->IsUsable(connection); }
760 
761     /**Get the capabilities
762       */
763     virtual const H323Capabilities & GetCapabilities() const;
764   //@}
765 
766     /**Get the direction for this capability.
767       */
GetCapabilityDirection()768     CapabilityDirection GetCapabilityDirection() const
769         { return ChildCapability->GetCapabilityDirection(); }
770 
771     /**Set the direction for this capability.
772       */
SetCapabilityDirection(CapabilityDirection dir)773     void SetCapabilityDirection(
774       CapabilityDirection dir   /// New direction code
775     ) { ChildCapability->SetCapabilityDirection(dir); }
776 
777     /// Get the payload type for the capaibility
GetPayloadType()778     RTP_DataFrame::PayloadTypes GetPayloadType() const
779         { return ChildCapability->GetPayloadType(); }
780 
781   //@}
782 
783 protected:
784     H323Capability * ChildCapability;    /// Child Capability
785     H235ChType chtype;                   /// Channel Type
786     PBoolean  m_active;                  /// Whether encryption is active
787     H323Capabilities * m_capabilities;   /// Capabilities list
788     unsigned  m_secNo;                   /// Security Capability
789     RTP_QOS * nrtpqos;                   /// RTP QOS
790     PString   m_algorithm;               /// Algorithm for encryption
791 };
792 
793 ////////////////////////////////////////////////////////////////////////////////////////
794 /**This class describes the secure interface to a data codec that has channels based on
795    the RTP protocol.
796 
797    An application may create a descendent off this class and override
798    functions as required for descibing the codec.
799  */
800 
801 class H323SecureDataCapability : public H323DataCapability
802 {
803   PCLASSINFO(H323SecureDataCapability, H323DataCapability);
804 
805 public:
806 
807     H323SecureDataCapability(H323Capability & childCapability,          ///< Child Capability
808                            enum H235ChType Ch = H235ChNew,               ///< ChannelType
809                            H323Capabilities * capabilities = NULL,    ///< Capabilities reference
810                            unsigned secNo = 0,                        ///< Security Capability No
811                            PBoolean active = false                    ///< Whether encryption is active or not
812                            );
813     ~H323SecureDataCapability();
814 
815     Comparison Compare(const PObject & obj) const;
816 
817     virtual PObject * Clone() const;
818 
819     virtual unsigned GetSubType() const;
820 
821     virtual PString GetFormatName() const;
822 
823     virtual H323Channel * CreateChannel(H323Connection & connection,
824                                       H323Channel::Directions dir,
825                                       unsigned sesionID,
826                                       const H245_H2250LogicalChannelParameters * param) const;
827 
828     virtual PBoolean IsMatch(const PASN_Choice & subTypePDU) const;
829     virtual PBoolean IsSubMatch(const PASN_Choice & subTypePDU) const;
830 
IsUsable(const H323Connection & connection)831     virtual PBoolean IsUsable(const H323Connection & connection) const { return ChildCapability->IsUsable(connection); }
832 
GetCapabilityDirection()833     CapabilityDirection GetCapabilityDirection() const  { return ChildCapability->GetCapabilityDirection(); }
834 
SetCapabilityDirection(CapabilityDirection dir)835     void SetCapabilityDirection(CapabilityDirection dir ) { ChildCapability->SetCapabilityDirection(dir); }
836 
GetPayloadType()837     RTP_DataFrame::PayloadTypes GetPayloadType() const { return ChildCapability->GetPayloadType(); }
838 
GetChildCapability()839     H323Capability * GetChildCapability() const { return ChildCapability; }
840 
841     virtual PBoolean OnSendingPDU(H245_Capability & pdu) const;
842     virtual PBoolean OnReceivedPDU(const H245_Capability & pdu);
843 
844     virtual PBoolean OnSendingPDU(H245_ModeElement & mode) const;
845 
846     virtual PBoolean OnSendingPDU(H245_DataType & dataType) const;
847     virtual PBoolean OnReceivedPDU(const H245_DataType & dataType,PBoolean receiver);
848 
849     virtual PBoolean OnSendingPDU(H245_DataMode & pdu) const;
850 
851 
852     virtual void SetEncryptionActive(PBoolean active);
853     virtual PBoolean IsEncryptionActive() const;
854 
855     virtual void SetEncryptionAlgorithm(const PString & alg);
856     virtual const PString & GetEncryptionAlgorithm() const;
857 
858     virtual void SetAssociatedCapability(unsigned _secNo);
859 
860 protected:
861     H323Capability * ChildCapability;    /// Child Capability
862     H235ChType chtype;                   /// Channel Type
863     PBoolean  m_active;                  /// Whether encryption is active
864     H323Capabilities * m_capabilities;   /// Capabilities list
865     unsigned  m_secNo;                   /// Security Capability
866     PString   m_algorithm;               /// Algorithm for encryption
867 
868 };
869 
870 //////////////////////////////////////////////////////////////////////////////////////////
871 
872 class H235_DiffieHellman;
873 class H235Capabilities : public H323Capabilities
874 {
875      PCLASSINFO(H235Capabilities, H323Capabilities);
876 
877 public:
878     H235Capabilities();
879 
880     H235Capabilities(
881       const H323Capabilities & original ///< Original capabilities to duplicate
882     );
883 
884     /**Construct a capability set from the H.245 PDU provided.
885       */
886     H235Capabilities(
887       const H323Connection & connection,             ///< Connection for capabilities
888       const H245_TerminalCapabilitySet & pdu         ///< PDU to convert to a capability set.
889     );
890 
891     void WrapCapability(PINDEX descriptorNum,        ///< The member of the capabilityDescriptor to add
892                         PINDEX simultaneous,         ///< The member of the SimultaneousCapabilitySet to add
893                         H323Capability & capability  ///< capability to wrap
894                        );
895 
896     void AddSecure(PINDEX descriptorNum,             ///< The member of the capabilityDescriptor to add
897                    PINDEX simultaneous,              ///< The member of the SimultaneousCapabilitySet to add
898                    H323Capability * capability       ///< capability to add
899                    );
900 
901     H323Capability * CopySecure(PINDEX descriptorNum,             ///< The member of the capabilityDescriptor to add
902                                 PINDEX simultaneous,              ///< The member of the SimultaneousCapabilitySet to add
903                                 const H323Capability & capability ///< capability to copy
904                                 );
905 
906     /**Add all matching capabilities to descriptor lists.
907        All capabilities that match the specified name are added as in the other
908        form of the SetCapability() function.
909       */
910     virtual PINDEX AddAllCapabilities(
911       PINDEX descriptorNum, ///< The member of the capabilityDescriptor to add
912       PINDEX simultaneous,  ///< The member of the SimultaneousCapabilitySet to add
913       const PString & name  ///< New capabilities name, if using "known" one.
914     );
915 
916     /**Add the DH KeyPair
917       */
918     void SetDHKeyPair(const PStringList & keyOIDs, H235_DiffieHellman * key, PBoolean isMaster);
919 
920     /**Get the DH KeyPair
921       */
922    void GetDHKeyPair(PStringList & keyOIDs, H235_DiffieHellman * & key, PBoolean & isMaster);
923 
924     /**Get the Algorithms
925          return false if no algorithms.
926       */
927     PBoolean GetAlgorithms(const PStringList & algorithms) const;
928 
GetDiffieHellMan()929     H235_DiffieHellman * GetDiffieHellMan() { return m_DHkey; }
930 
931     /**Filter codecs
932       */
933     static void SetH235Codecs(const PStringArray & servers);
934     PBoolean IsH235Codec(const PString & name);
935 
936 protected:
937     H235_DiffieHellman * m_DHkey;
938     PStringList          m_algorithms;
939     PBoolean             m_h245Master;
940 
941 };
942 
943 #endif  // H323_H235
944 
945 
946