|
1 // Copyright (c) 2001-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 // Started by MWT, June 1997 |
|
15 // |
|
16 // |
|
17 |
|
18 #if !defined (__PINGENG_H__) |
|
19 #define __PINGENG_H__ |
|
20 |
|
21 #if !defined(__IN_SOCK_H__) |
|
22 #include <in_sock.h> |
|
23 #endif |
|
24 |
|
25 class MPingNotificationHandler |
|
26 { |
|
27 public: |
|
28 virtual void Pinging(const TNameRecord& aRecord, TInt aBytes) const=0; |
|
29 virtual void Sent() const=0; |
|
30 virtual void Reply(const TInetAddr& aFrom, TInt aBytes, TInt aSeq, TTimeIntervalMicroSeconds32 aTime) const=0; |
|
31 virtual void Icmp4Message(const TInetAddr& aFrom, TInt aType, TInt aCode, const TDesC8& aRestOfIt) const=0; |
|
32 virtual void Icmp6Message(const TInetAddr& aFrom, TInt aType, TInt aCode) const=0; |
|
33 virtual void Finished(const TNameRecord& aRecord, TInt aNrTransmitted, TInt aNrReceived, TInt aNrDuplicates, TInt aMin, TInt aMax, TInt aSum, TInt aError) =0; |
|
34 }; |
|
35 |
|
36 class TPingOptions |
|
37 { |
|
38 public: |
|
39 IMPORT_C TPingOptions(); |
|
40 public: |
|
41 TInt iNumberOfPings; |
|
42 TTimeIntervalMicroSeconds32 iInterval; |
|
43 TTimeIntervalMicroSeconds32 iWait; |
|
44 THostName iDestname; |
|
45 TInt iPingSize; |
|
46 TBool iResolveAddress; |
|
47 TInt iPreload; |
|
48 TInt iBacklog; |
|
49 TBool iPrompt; |
|
50 TInt iConnIap; |
|
51 TInt iConnSnap; |
|
52 }; |
|
53 |
|
54 class CPingEng; |
|
55 class TPingRecord |
|
56 { |
|
57 friend class CPingEng; |
|
58 |
|
59 public: |
|
60 TPingRecord(TUint aSeqNr); |
|
61 private: |
|
62 TTime iSendTime; |
|
63 TSglQueLink iLink; |
|
64 TInt iSeqNr; |
|
65 }; |
|
66 |
|
67 class CPingTimer; |
|
68 class CPingSender; |
|
69 class CPingReceiver; |
|
70 class HPingHeader; |
|
71 |
|
72 |
|
73 class CPingEng : public CBase |
|
74 { |
|
75 public: |
|
76 IMPORT_C static CPingEng* NewL(MPingNotificationHandler& aUi); |
|
77 IMPORT_C ~CPingEng(); |
|
78 |
|
79 IMPORT_C void SetPriorities(TInt aTimerPriority, TInt aSenderPriority, TInt aReceiverPriority); |
|
80 IMPORT_C void StartL(const TPingOptions& aOptions); |
|
81 IMPORT_C void Cancel(); |
|
82 IMPORT_C void CancelAndFinished(); |
|
83 |
|
84 void TimerComplete(); |
|
85 void SendCompleteL(); |
|
86 void SendDoCancel(); |
|
87 void RecvComplete(); |
|
88 void RecvDoCancel(); |
|
89 |
|
90 private: |
|
91 void ConstructL(); |
|
92 CPingEng(MPingNotificationHandler& aUi); |
|
93 |
|
94 void NextSend(); |
|
95 void DoError(TInt aError); |
|
96 void PurgeQue(); |
|
97 void EmptyPingRecordQue(); |
|
98 void DeletePingRecord(TPingRecord* aRecord); |
|
99 enum TState { EStopped, ELookingUp, ESending }; |
|
100 |
|
101 TState iState; |
|
102 MPingNotificationHandler& iUi; |
|
103 CPingTimer* iTimer; |
|
104 CPingSender* iSender; |
|
105 CPingReceiver* iReceiver; |
|
106 TPingOptions iOptions; |
|
107 RSocketServ iSocketServ; |
|
108 RSocket iSocket; |
|
109 RHostResolver iResolver; |
|
110 TNameEntry iNameEntry; |
|
111 TInetAddr iSrcAddr; |
|
112 |
|
113 TInt iNrTransmitted; |
|
114 TInt iNrReceived; |
|
115 TInt iNrDuplicates; |
|
116 TInt iMinTime; |
|
117 TInt iMaxTime; |
|
118 TInt iSumTime; |
|
119 |
|
120 TInt iSendFlags; |
|
121 |
|
122 TSglQue<TPingRecord> iQue; |
|
123 TInt iNoInQue; |
|
124 |
|
125 RConnection iConnect; |
|
126 HPingHeader* iRecvData; |
|
127 HPingHeader* iSendData; |
|
128 |
|
129 TInt iId; |
|
130 |
|
131 TBool iIsLoopback; |
|
132 }; |
|
133 |
|
134 enum TPingDefaultPriorites |
|
135 { |
|
136 EPingTimerPriority=10, |
|
137 EPingSenderPriority=20, |
|
138 EPingReceiverPriority=30, |
|
139 }; |
|
140 |
|
141 // ICMP Type and Code values |
|
142 const TUint KIPv4PingTypeEchoReply = 0; |
|
143 const TUint KIPv4PingCodeEcho = 0; |
|
144 const TUint KIPv4PingTypeEchoRequest = 8; |
|
145 const TUint KIPv4PingTypeUnreachable = 3; |
|
146 const TUint KIPv4PingCodeUnreachNet = 0; |
|
147 const TUint KIPv4PingCodeUnreachHost = 1; |
|
148 const TUint KIPv4PingCodeUnreachProtocol = 2; |
|
149 const TUint KIPv4PingCodeUnreachPort = 3; |
|
150 const TUint KIPv4PingCodeUnreachNeedFrag = 4; |
|
151 const TUint KIPv4PingCodeUnreachSrcRouteFail = 5; |
|
152 const TUint KIPv4PingCodeUnreachNetUnknown = 6; |
|
153 const TUint KIPv4PingCodeUnreachHostUnknown = 7; |
|
154 const TUint KIPv4PingCodeUnreachSrcHostIsolated = 8; |
|
155 const TUint KIPv4PingCodeUnreachNetProhibited = 9; |
|
156 const TUint KIPv4PingCodeUnreachHostProhibited = 10; |
|
157 const TUint KIPv4PingCodeUnreachNetTOS = 11; |
|
158 const TUint KIPv4PingCodeUnreachHostTOS = 12; |
|
159 const TUint KIPv4PingCodeUnreachProhibited = 13; |
|
160 const TUint KIPv4PingCodeUnreachPrecVolation = 14; |
|
161 const TUint KIPv4PingCodeUnreachPrecCutoff = 15; |
|
162 const TUint KIPv4PingTypeSourceQuench = 4; |
|
163 const TUint KIPv4PingTypeRedirect = 5; |
|
164 const TUint KIPv4PingCodeRedirectNet = 0; |
|
165 const TUint KIPv4PingCodeRedirectHost = 1; |
|
166 const TUint KIPv4PingCodeRedirectNetTOS = 2; |
|
167 const TUint KIPv4PingCodeRedirectHostTOS = 3; |
|
168 const TUint KIPv4PingTypeTimeExceeded = 11; |
|
169 const TUint KIPv4PingCodeExceedInTransit = 0; |
|
170 const TUint KIPv4PingCodeExceedInReasm = 1; |
|
171 const TUint KIPv4PingTypeBadParameter = 12; |
|
172 |
|
173 const TUint KIPv6PingTypeEchoReply = 129; |
|
174 const TUint KIPv6PingTypeEchoRequest = 128; |
|
175 const TUint KIPv6PingCodeEcho = 0; |
|
176 const TUint KIPv6PingTypeUnreachable = 1; |
|
177 const TUint KIPv6PingCodeNoRoute = 0; |
|
178 const TUint KIPv6PingCodeAdminProhibited = 1; |
|
179 const TUint KIPv6PingCodeAddressUnreachable = 3; |
|
180 const TUint KIPv6PingCodePortUnreachable = 4; |
|
181 const TUint KIPv6PingTypePacketTooBig = 2; |
|
182 const TUint KIPv6PingCodePacketTooBig = 0; |
|
183 const TUint KIPv6PingTypeTimeExeeded = 3; |
|
184 const TUint KIPv6PingCodeHLExeeded = 0; |
|
185 const TUint KIPv6PingCodeFragReassemblyExeeded = 1; |
|
186 const TUint KIPv6PingTypeParamProblem = 4; |
|
187 const TUint KIPv6PingCodeErroneousHeader = 0; |
|
188 const TUint KIPv6PingCodeNextHeaderUnrecognised = 1; |
|
189 const TUint KIPv6PingCodeIPv6OptionUnrecognised = 2; |
|
190 |
|
191 #endif |
|
192 |