tcpiputils/tun/inc/tun.h
branchRCL_3
changeset 63 425d8f4f7fa5
equal deleted inserted replaced
58:8d540f55e491 63:425d8f4f7fa5
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file 
       
    18  @internalComponent
       
    19  */
       
    20 
       
    21 #ifndef __TUN_H__
       
    22 #define __TUN_H__
       
    23 
       
    24 #include <posthook.h>
       
    25 #include <nifif.h>
       
    26 #include "tunfamily.h"
       
    27 #include "tun.pan"
       
    28 
       
    29 const TUint KProtocolTUN    = 145; // number that is unassigned by IANA
       
    30 const TUint KTunTos         = 192; // 0xC0; uses the UNUSED 7,8 MSB of Differentiated Services  
       
    31 
       
    32 class CProtocolTun;
       
    33 class CTunFlowInfo;
       
    34 class CNifIfBase;
       
    35 
       
    36 class CSapTun : public CServProviderBase
       
    37 /** 
       
    38  *  Class Derived from CServProviderBase. 
       
    39  *  Inherit virtual functions from CServProviderBase.This Class is socket support for this 
       
    40  *  Hook (protocol).Protocol or Hook could be manipulated by the Socket using socket options.
       
    41  *  This class will be used to take downlink information from the private client.The SAP will 
       
    42  *  called for all the Socket opened by the socket. SAP is 1 to 1 with Socket.
       
    43  *  we are maintaining a singleton pattern for this SAP
       
    44  **/
       
    45     {
       
    46 
       
    47 public:
       
    48     friend class CProtocolTun;
       
    49 
       
    50 protected:
       
    51     CSapTun();
       
    52     ~CSapTun();
       
    53     
       
    54 public:
       
    55     //static CSapTun* GetInstanceL();
       
    56     void Ioctl(TUint /*level*/,TUint /* name*/,TDes8* /* anOption*/);
       
    57     void Start();
       
    58     void Shutdown(TCloseType option);
       
    59     void LocalName(TSockAddr& anAddr) const; 
       
    60     TInt SetLocalName(TSockAddr& anAddr); 
       
    61     void RemName(TSockAddr& anAddr) const;
       
    62     TInt SetRemName(TSockAddr& anAddr);
       
    63     TInt GetOption(TUint /*level*/,TUint /*name*/,TDes8& /*anOption*/)const;    
       
    64     void CancelIoctl(TUint /*aLevel*/,TUint /*aName*/);
       
    65     TInt SetOption(TUint aLevel,TUint aName,const TDesC8& anOption); 
       
    66     void ActiveOpen();
       
    67     void ActiveOpen(const TDesC8& /*aConnectionData*/);
       
    68     TInt PassiveOpen(TUint /*aQueSize*/);
       
    69     TInt PassiveOpen(TUint /*aQueSize*/,const TDesC8& /*aConnectionData*/);
       
    70     void Shutdown(TCloseType /*option*/,const TDesC8& /*aDisconnectionData*/);
       
    71     void AutoBind();
       
    72     TInt SecurityCheck(MProvdSecurityChecker* aChecker);
       
    73 
       
    74 private:
       
    75     //static CSapTun* iInstance;
       
    76     CProtocolTun* iProtocol;
       
    77     CTunFlowInfo* iFlowInfo;
       
    78     };  //End Class CProtocolSap
       
    79 
       
    80 //CSapTun* CSapTun::iInstance = NULL;
       
    81 
       
    82 class CProtocolTun : public CProtocolPosthook
       
    83     {
       
    84     friend class CSapTun;
       
    85 public:  // Constructors and destructor
       
    86 
       
    87     /**
       
    88      * Constructor.
       
    89      */
       
    90 
       
    91     CProtocolTun ();
       
    92 
       
    93     /* 
       
    94      * Two Phase Construction
       
    95      */
       
    96     static CProtocolTun* NewL();
       
    97 
       
    98     /**
       
    99      * Destructor.
       
   100      */
       
   101     virtual ~CProtocolTun ();
       
   102 
       
   103 public: // Functions from base classes
       
   104 
       
   105     /**
       
   106      * From CProtocolBase  
       
   107      * Used as second phase of Two Phase construction
       
   108      * @param aTag Name
       
   109      * @return void
       
   110      */
       
   111     void ConstructL ();
       
   112 
       
   113     /**
       
   114      * From CProtocolBase  
       
   115      * @since 
       
   116      * @param aDesc Descriptor to be filled by this method.
       
   117      * @return void
       
   118      */
       
   119     virtual void Identify (TServerProtocolDesc * aDesc) const;
       
   120 
       
   121     /**
       
   122      * Static method that can be invoked from the Protocol Family 
       
   123      * @since 
       
   124      * @param aDesc Descriptor to be filled by this method.
       
   125      * @return void
       
   126      */
       
   127     static void Identify (TServerProtocolDesc & aDesc);
       
   128 
       
   129     /**
       
   130      * From CProtocolPostHook Handles attach to the stack
       
   131      * @since
       
   132      * @return void
       
   133      */
       
   134     void NetworkAttachedL();
       
   135 
       
   136     /**
       
   137      * From CProtocolPostHook Handles detach from the stack
       
   138      * @since
       
   139      * @return void
       
   140      */
       
   141     void NetworkDetached();
       
   142 
       
   143     /**
       
   144      * From MIp6Hook Handles received packets. 
       
   145      * @since 
       
   146      * @param aPacket Packet received.
       
   147      * @param aInfo Info structure.
       
   148      * @return void
       
   149      */       
       
   150     virtual TInt ApplyL (RMBufHookPacket & /* aPacket */ ,RMBufRecvInfo & /* aInfo */ );
       
   151 
       
   152     /**
       
   153      * From MIp6Hook Handles outbound opening. 
       
   154      * @since 
       
   155      * @param aHead Flow-specific precomputed data.
       
   156      * @param aFlow Flow.
       
   157      * @return void
       
   158      */       
       
   159     virtual MFlowHook *OpenL (TPacketHead & aHead, CFlowContext * aFlow);
       
   160 
       
   161     /**
       
   162      * NewSAPL function to create a CSapTun instance
       
   163      * and use for setting up the LocalAddress Information
       
   164      * @param aProtocol ignored in our case.
       
   165      * @return instance of the CServProviderBase instance CSapFullTunnel
       
   166      */
       
   167     CServProviderBase* NewSAPL(TUint aProtocol);
       
   168 
       
   169     /**
       
   170      *  Cancels the Sap creation
       
   171      *  @param the Sap instance that has to be removed 
       
   172      */ 
       
   173   //  void CancelSap(CSapTun *aSap);
       
   174 
       
   175     /**
       
   176      *  Sets the NifBase instances to be used for Control functionality
       
   177      *  @param the NifBase instance that will be retained.
       
   178      */
       
   179     void SetCNifBase(CNifIfBase* aNifBase)
       
   180         {
       
   181         iNifBase = aNifBase;
       
   182         }
       
   183     
       
   184     void SetAppPortNum(TUint aPort)
       
   185         {
       
   186         iAppPortNum = aPort;
       
   187         iPortSet = ETrue;
       
   188         }
       
   189     
       
   190     TBool IsPortSet()
       
   191         {
       
   192         return iPortSet;
       
   193         }
       
   194 
       
   195 
       
   196 private:
       
   197     TUint iAppPortNum;  // Tunnel port configured.
       
   198     TBool iPortSet;     //Bool to check whether the port is set/not.
       
   199     RPointerArray<CSapTun> iSapList;  // List of SAP instances created.
       
   200     CNifIfBase* iNifBase;    // CNifBase* instance
       
   201     CTunFlowInfo* iFlowinfo;   // instance of the Flow Hook
       
   202     CSapTun* iSapInstance; // instance of sap
       
   203 
       
   204     };
       
   205 
       
   206 /**
       
   207  *  TUN Driver flow hook
       
   208  *  Outbound Flow hook and performs actions on the packets
       
   209  *  destined for the Virtual Tunnel Nif.
       
   210  */
       
   211 class CTunFlowInfo : public CBase, public MFlowHook
       
   212     {
       
   213     friend class CProtocolTun;
       
   214     friend class CSapTun;
       
   215 
       
   216 public: // Constructors & destructors
       
   217 
       
   218     /**
       
   219      * Constructor.
       
   220      */
       
   221 
       
   222     CTunFlowInfo();
       
   223 
       
   224     /**
       
   225      * Copy Constructor.
       
   226      */
       
   227 
       
   228     CTunFlowInfo(CTunFlowInfo* aInstance )
       
   229     :iAppPortNum(aInstance -> iAppPortNum)
       
   230         {}
       
   231 
       
   232     /**
       
   233      * Destructor.
       
   234      */
       
   235 
       
   236     ~CTunFlowInfo();
       
   237 
       
   238 
       
   239 public: // Functions from base classes
       
   240 
       
   241     /**
       
   242      * From MFlowHook Open and Close implements reference counting system.
       
   243      * @since
       
   244      * @param
       
   245      * @return void
       
   246      */
       
   247     void Open ();
       
   248 
       
   249     /**
       
   250      * From MFlowHook Informs stack if the hook is ready. Can update address
       
   251      * information.
       
   252      * @since
       
   253      * @param aHead Address information of the flow.
       
   254      * @return TInt 0 => ready, >0 => pending, <0 => error.
       
   255      */
       
   256     TInt ReadyL (TPacketHead & aHead);
       
   257 
       
   258     /**
       
   259      * Called by IP when processing outbound packet.
       
   260      * @since
       
   261      * @param aPacket Complete packet
       
   262      * @param aInfo Information block associated with the packet
       
   263      * @return TInt 0 => processed, <0 => discarded, >0 => restart processing
       
   264      */
       
   265     TInt ApplyL (RMBufSendPacket & aPacket, RMBufSendInfo & aInfo);
       
   266 
       
   267     /**
       
   268      * From MFlowHook Open and Close implements reference counting system.
       
   269      * @since
       
   270      * @param
       
   271      * @return void
       
   272      */
       
   273     void Close ();
       
   274     
       
   275     void SetAppPortNum(TUint aPort)
       
   276         {
       
   277         iAppPortNum = aPort;
       
   278         }
       
   279     
       
   280 private:    // Data
       
   281 
       
   282     TInt iRef; // Reference count
       
   283     TUint iAppPortNum; // Tunnel port configured.
       
   284 
       
   285     };
       
   286 
       
   287 
       
   288 #endif //__TUN_H__