networkingtestandutils/ipanalyzer/inc/engine.h
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2004-2009 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 // engine.h - protocol analyzer engine header
       
    15 // The monitoring of IPv6 header includes some recursivity when 
       
    16 // calling to monitor the next packet but it shouldn't be a problem
       
    17 // However, in case of problrems it could easily turn into a loop
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @internalComponent
       
    24 */
       
    25 
       
    26 #ifndef __ENGINE_H
       
    27 #define __ENGINE_H
       
    28 
       
    29 #include <es_sock.h>
       
    30 #include <in_sock.h>
       
    31 
       
    32 #if EPOC_SDK >= 0x07010000
       
    33 // here would go the includes that you would
       
    34 // need for opening a link or links
       
    35 #elif EPOC_SDK >= 0x06010000
       
    36 #include <agentclient.h>
       
    37 #include <connectprog.h>
       
    38 #else
       
    39 #include <netdial.h>
       
    40 #endif
       
    41 
       
    42 #define SECOND 1000000
       
    43 
       
    44 #define MIN_FACTOR 0.05
       
    45 #define MAX_FACTOR 1
       
    46 #define STEP	0.05
       
    47 #define MINI_STEP	0.01
       
    48 
       
    49 #define	KProtocolInetEsp	50	//Protocols numbers. Not defined in any system include
       
    50 #define	KProtocolInetAh    51
       
    51 
       
    52 #define IPV4_ADDR_SIZE	16	//IPV4 size in char
       
    53 #define IPV6_ADDR_SIZE	40	//IPV6 size in char
       
    54 
       
    55 //Protocols no defined in .h's
       
    56 #define KIPv6HopByHopHdr	0
       
    57 #define KIPv6RoutingHdr	43
       
    58 #define KIPv6FragmentHdr	44
       
    59 #define	KIPv6ESPHdr	50
       
    60 #define	KIPv6AuthenticationHdr	51
       
    61 #define KIPv6DestOptHdr	60
       
    62 #define KIPv6NoNextHdr	59
       
    63 
       
    64 //ICMP codes not defined in .h's
       
    65 #define KInet6ICMP_HopLimitExceeded		0
       
    66 #define KInet6ICMP_FragReassExceeded	1
       
    67 
       
    68 #define KInet6ICMP_NoRoute				0
       
    69 #define KInet6ICMP_AdminProhibition		1
       
    70 #define KInet6ICMP_NotNeighbour			2
       
    71 #define KInet6ICMP_AddrUnreach			3
       
    72 #define KInet6ICMP_PortUnreach			4
       
    73 
       
    74 #define KInet6ICMP_ErrHdrField			0
       
    75 #define KInet6ICMP_NextHdrUnknown		1
       
    76 #define KInet6ICMP_OptionUnkown			2
       
    77 
       
    78 #define MAX_READ_DATA	512	
       
    79 
       
    80 
       
    81 struct TPreferences
       
    82 {
       
    83 	TBool iDumpIPv4;	//To dump dropped IPv4 packets
       
    84 	TBool iDumpIPv6;	//To dump dropped IPv6 packets
       
    85 	TBool iDumpIPSEC;	//To dump dropped ipsec packet
       
    86 	TInt iProtocol;	//icmp, ip, tcp, udp
       
    87 	TUint iPort;	//To be used with tcp or udp
       
    88 	TBool iViewIPHdr;
       
    89 	TInt iNumBlades;
       
    90 };
       
    91 
       
    92 #if 0
       
    93 struct SMonIPv4Info 
       
    94 {
       
    95 	TBool iIPVersion;
       
    96 	TBool iIPHdrLen;
       
    97 	TBool iIPTOS;
       
    98 	TBool iIPTotalLen;
       
    99 	TBool iIPId;
       
   100 	TBool iIPFlags;
       
   101 	TBool iIPOffset;
       
   102 	TBool iIPTTL;
       
   103 	TBool iIPProtocol;
       
   104 	TBool iIPChksum;
       
   105 	TBool iIPSrcAddr;
       
   106 	TBool iIPDstAddr;
       
   107 
       
   108 	TBool iICMPType;
       
   109 	TBool iICMPCode;
       
   110 	TBool iICMPChksum;
       
   111 
       
   112 	TBool iTCPSrcPort;
       
   113 	TBool iTCPDstPort;
       
   114 	TBool iTCPSeq;
       
   115 	TBool iTCPAckNum;
       
   116 	TBool iTCPHdrLen;
       
   117 	TBool iTCPFlags;
       
   118 	TBool iTCPHdrWinSize;
       
   119 	TBool iTCPChksum;
       
   120 	TBool iTCPHdrUrgPtr;
       
   121 
       
   122 	TBool iUDPSrcPort;
       
   123 	TBool iUDPDstPort;
       
   124 	TBool iUDPLen;
       
   125 	TBool iUDPChksum;
       
   126 
       
   127 	TBool iAHProtocol;
       
   128 	TBool iAHHdrLen;
       
   129 	TBool iAHSPI;
       
   130 	TBool iAHSeq;
       
   131 
       
   132 	TBool iESPSPI;
       
   133 	TBool iESPSeq;
       
   134 
       
   135 };
       
   136 #else
       
   137 #	define	SMonIPv4Info SMonIpInfo
       
   138 #	define	SMonIPv6Info SMonIpInfo
       
   139 #endif
       
   140 struct SMonIpInfo 
       
   141 {
       
   142 
       
   143 	TBool iIPVersion;
       
   144 	union
       
   145 		{
       
   146 		TBool iIPTraffic;	// IPv6
       
   147 		TBool iIPTOS;		// IPv4
       
   148 		};
       
   149 	TBool iIPFlowLabel;
       
   150 	union
       
   151 		{
       
   152 		TBool iIPTotalLen;	// IPv4
       
   153 		TBool iIPPayloadLen;// IPv6
       
   154 		};
       
   155 	union
       
   156 		{
       
   157 		TBool iIPNextHdr;	// IPv6
       
   158 		TBool iIPProtocol;	// IPv4
       
   159 		};
       
   160 	union
       
   161 		{
       
   162 		TBool iIPHopLimit;	// IPv6
       
   163 		TBool iIPTTL;		// IPv4
       
   164 		};
       
   165 
       
   166 	TBool iIPSrcAddr;
       
   167 	TBool iIPDstAddr;
       
   168 
       
   169 	TBool iIPHdrLen;	// IPv4
       
   170 	TBool iIPId;		// IPv4
       
   171 	TBool iIPFlags;		// IPv4
       
   172 	TBool iIPOffset;	// IPv4
       
   173 	TBool iIPChksum;	// IPv4
       
   174 
       
   175 	TBool iICMPType;
       
   176 	TBool iICMPCode;
       
   177 	TBool iICMPChksum;
       
   178 	TBool iICMPParameter;	//Particular Info depending on ICMP Code and Type
       
   179 
       
   180 	TBool iTCPSrcPort;
       
   181 	TBool iTCPDstPort;
       
   182 	TBool iTCPSeq;
       
   183 	TBool iTCPAckNum;
       
   184 	TBool iTCPHdrLen;
       
   185 	TBool iTCPFlags;
       
   186 	TBool iTCPHdrWinSize;
       
   187 	TBool iTCPChksum;
       
   188 	TBool iTCPHdrUrgPtr;
       
   189 	TBool iTCPOptions;
       
   190 
       
   191 	TBool iUDPSrcPort;
       
   192 	TBool iUDPDstPort;
       
   193 	TBool iUDPLen;
       
   194 	TBool iUDPChksum;
       
   195 
       
   196 	TBool iHOPNextHdr;
       
   197 	TBool iHOPHdrExtLen;
       
   198 	TBool iHOPOptionType;
       
   199 	TBool iHOPOptionLen;
       
   200 
       
   201 	TBool iDSTNextHdr;
       
   202 	TBool iDSTHdrExtLen;
       
   203 	TBool iDSTHomeAddr;
       
   204 	TBool iDSTBindingUpdate;
       
   205 	TBool iDSTBindingRequest;
       
   206 	TBool iDSTBindingAck;
       
   207 	TBool iDSTPad;
       
   208 	TBool iDSTUnknown;
       
   209 
       
   210 	TBool iRTNextHdr;
       
   211 	TBool iRTHdrExtLen;
       
   212 	TBool iRTRoutingType;
       
   213 	TBool iRTSegLeft;
       
   214 	TBool iRTSLBitMap;
       
   215 	TBool iRTAddresses;
       
   216 
       
   217 	TBool iFRAGNextHdr;
       
   218 	TBool iFRAGFragOffset;
       
   219 	TBool iFRAGMFlag;
       
   220 	TBool iFRAGId;
       
   221 
       
   222 	TBool iAHProtocol;
       
   223 	TBool iAHHdrLen;
       
   224 	TBool iAHSPI;
       
   225 	TBool iAHSeq;
       
   226 
       
   227 	TBool iESPSPI;
       
   228 	TBool iESPSeq;
       
   229 
       
   230 };
       
   231 
       
   232 
       
   233 struct SMonStatInfo 
       
   234 {
       
   235 	TUint iTotalPackets;
       
   236 	TUint iIPv4Packets;
       
   237 	TUint iIPv6Packets;
       
   238 	TUint iTCPPackets;
       
   239 	TUint iUDPPackets;
       
   240 	TUint iICMPPackets;
       
   241 	TUint iExtPackets;
       
   242 };
       
   243 
       
   244 class CRotorAppView;
       
   245 class CRotorReceiver;
       
   246 class CRotorIPv6Receiver;
       
   247 class CRotorDumper;
       
   248 class CRotorBraker;
       
   249 
       
   250 class CRotorEngine : public CTimer
       
   251 {
       
   252 public:
       
   253 	//constructor
       
   254 	CRotorEngine(CRotorAppView *aAppView);
       
   255 
       
   256 	//destructor
       
   257 	~CRotorEngine();
       
   258 	
       
   259 	//second phase constructor
       
   260 	void ConstructL(const TPreferences& aPref);
       
   261 	void GetPreferences(TPreferences &aPref) const;
       
   262 	static void DefaultPreferences(TPreferences &aPref);
       
   263 	CRotorReceiver *StartReceiver(const TDesC &aName);
       
   264 	void FirstRun();
       
   265 	void StartL();
       
   266 	void Stop();
       
   267 	void IncreaseSpeed();
       
   268 	void DecreaseSpeedL();
       
   269 	void PacketReceived();
       
   270 
       
   271 	inline SMonIPv4Info *MonIPv4Info()
       
   272 		{return &iMonIPv4Info;}
       
   273 	inline SMonIPv6Info *MonIPv6Info()
       
   274 		{return &iMonIPv6Info;}
       
   275 	inline RSocketServ &SocketServ()
       
   276 	{return iSockServ;}
       
   277 
       
   278 protected:
       
   279 	//void UpdateRotor();
       
   280 	void UpdateSpeedL();
       
   281 
       
   282 	//Issues next RunL execution
       
   283 	void IssueRequest();
       
   284 
       
   285 	// will send all the packets
       
   286 	void RunL();
       
   287 
       
   288 	//Cancel Packet Sending
       
   289 	void DoCancel();
       
   290 
       
   291 private:
       
   292 	void SetNetworkUp() const;
       
   293 
       
   294 public:
       
   295 	// General option. Public to make it easier to access from the dialog
       
   296 	TPreferences iPref;
       
   297 
       
   298 	TBool iProbeActive;	// IP Probe Hook availabe
       
   299 	TBool iIPv4Active;	//IPv4 packets dump available
       
   300 	TBool iIPv6Active;	//IPv6 packets dump available
       
   301 	TBool iIPSECActive;	//IPSEC packets dump available
       
   302 	SMonStatInfo iStatInfo;	
       
   303 	TBool iShowPackets;	//Tells the engine to avoid using the console
       
   304 	CRotorAppView *iAppView;
       
   305 
       
   306 private:
       
   307 	RSocketServ iSockServ;
       
   308 	CRotorReceiver *iReceiver;		//AO listening IPv4
       
   309 	CRotorReceiver *iIPv6Receiver;	//AO listening IPv6
       
   310 	CRotorReceiver *iDumper;		//AO listening IPSEC socket
       
   311 	CRotorBraker *iBraker;			//AO that brakes the rotor
       
   312 	TReal iFactor;
       
   313 	TBool iPacketReceived;
       
   314 	//TUint iRecvPackets;
       
   315 	TReal iPartialPackets;
       
   316 	TTime iInitTime;
       
   317 	SMonIPv4Info iMonIPv4Info;
       
   318 	SMonIPv6Info iMonIPv6Info;
       
   319 	
       
   320 	//TBool iRunning;
       
   321 
       
   322 #if EPOC_SDK >= 0x07010000
       
   323 	// Here would go the member variable you would use
       
   324 	// to open a link or links
       
   325 #elif EPOC_SDK >= 0x06010000
       
   326 	RGenericAgent xnetdial;	// Use GenConn for R6.1+
       
   327 #else
       
   328 	RNetDial xnetdial;	// To set the net UP
       
   329 #endif
       
   330 };
       
   331 
       
   332 
       
   333 
       
   334 class CRotorListener : public CActive
       
   335 {
       
   336 public:
       
   337 	//constructor
       
   338 	CRotorListener(CRotorAppView *aAppView, CRotorEngine *aEngine);
       
   339 
       
   340 	//destructor
       
   341 	~CRotorListener();
       
   342 	
       
   343 	//second phase constructor
       
   344 	void ConstructL();
       
   345 	void FirstRun();
       
   346 	void Start();
       
   347 	
       
   348 
       
   349 protected:
       
   350 	//void UpdateRotor();
       
   351 
       
   352 	//Issues next RunL execution
       
   353 	void IssueRequest();
       
   354 
       
   355 
       
   356 	// will send all the packets
       
   357 	//void RunL();
       
   358 
       
   359 	void Stop() const;
       
   360 
       
   361 	//Cancel Packet Sending
       
   362 	void DoCancel();
       
   363 
       
   364 	TBool Filter(const TDesC8 &aPacket) const;
       
   365 
       
   366 	void ViewData(const TUint8 *aData,TUint aSize);
       
   367 
       
   368 	void MonitorIpPacket(const TDesC8 &aPacket);
       
   369 
       
   370 	TUint MonitorIPv4(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   371 	TUint MonitorIPv6(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   372 	TUint MonitorICMPv4(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   373 	TUint MonitorICMPv6(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   374 	TUint ICMPv4Specific(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   375 	TUint ICMPv6Specific(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);	
       
   376 	TUint MonitorTCP(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   377 	TUint MonitorUDP(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   378 	TUint MonitorESP(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   379 	TUint MonitorAH(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   380 	TUint MonitorHopByHopHeader(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   381 	TUint MonitorDestOptHeader(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   382 	TUint MonitorRoutingHeader(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   383 	TUint MonitorFragmentHeader(const TDesC8 &aPacket, const SMonIpInfo &aMonitor, TUint &aNext);
       
   384 	
       
   385 	//aPacket contains the full packet
       
   386 	const TUint8 *FindTransportProtocol(const TDesC8& aPacket) const;
       
   387 	void ErrorL(const TDesC& string,TInt error);
       
   388 
       
   389 protected:
       
   390 	CRotorAppView *const iAppView;
       
   391 	CRotorEngine *const iEngine;
       
   392 	//RSocketServ iSockServ;
       
   393 	RSocket iSocket;
       
   394 	HBufC8* iReceivedData;
       
   395 	TPtr8 iBuf;
       
   396 	TInt iErrPackets;
       
   397 	TRequestStatus iWriteStatus;
       
   398 };
       
   399 
       
   400 
       
   401 //
       
   402 //	CRotorReceiver: Receives IPv4 packets to move the rotor
       
   403 //
       
   404 
       
   405 
       
   406 class CRotorReceiver : public CRotorListener
       
   407 {
       
   408 friend class CRotorDumper; //To let this class use the monitoring functions
       
   409 public:
       
   410 	//constructor
       
   411 	CRotorReceiver(CRotorAppView *aAppView, CRotorEngine *aEngine);
       
   412 	
       
   413 	//second phase constructor
       
   414 	void ConstructL(TUint aProtocol, const TDesC &aName);
       
   415 
       
   416 protected:
       
   417 	void RunL();
       
   418 private:
       
   419 	TInt iSwapIpHeader;
       
   420 };
       
   421 
       
   422 class CRotorBraker : public CTimer
       
   423 {
       
   424 public:
       
   425 	//constructor
       
   426 	CRotorBraker(CRotorEngine *aEngine);
       
   427 
       
   428 	//destructor
       
   429 	~CRotorBraker();
       
   430 
       
   431 	//second phase constructor
       
   432 	void ConstructL();
       
   433 	
       
   434 	void Start();
       
   435 	void ReIssueRequest();
       
   436 
       
   437 protected:
       
   438 	
       
   439 	//Issues next RunL execution
       
   440 	void IssueRequest();
       
   441 
       
   442 	void FirstRun();
       
   443 
       
   444 	// will send all the packets
       
   445 	void RunL();
       
   446 
       
   447 	void Stop() const;
       
   448 
       
   449 	//Cancel Packet Sending
       
   450 	void DoCancel();
       
   451 
       
   452 private:
       
   453 	CRotorEngine *iEngine;
       
   454 };
       
   455 
       
   456 #endif