|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #ifndef __PPPDEF_H__ |
|
22 #define __PPPDEF_H__ |
|
23 |
|
24 #include <nifutl.h> |
|
25 #include <nifmbuf.h> |
|
26 #include <networking/pppsock.h> |
|
27 |
|
28 #if !defined INLINE |
|
29 #if defined( _DEBUG ) |
|
30 #define INLINE |
|
31 #else |
|
32 #define INLINE inline |
|
33 #endif |
|
34 #endif |
|
35 |
|
36 class CPppLcp; |
|
37 class CNifFactory; |
|
38 class RPppOptionList; |
|
39 |
|
40 // |
|
41 // PPP Interface to Link protocols - accepts frames from Lcp's demux |
|
42 // |
|
43 |
|
44 class MPppRecvr |
|
45 { |
|
46 public: |
|
47 MPppRecvr(CPppLcp* aPppLcp, TPppPhase aPhase, TUint aPppId=KPppIdUnknown); |
|
48 // The following constructor and Init function is a provisional fix, |
|
49 // since according to Symbian Coding Standard M classes (mixins) are |
|
50 // not supposed to have state - data members - and should contain no |
|
51 // costructors or destructors. MPppRecvr is not in fact a valid |
|
52 // "mixin class", because it does not fulfill these requirements. |
|
53 void Init(CPppLcp* aPppLcp, TPppPhase aPhase, TUint aPppId=KPppIdUnknown); |
|
54 virtual ~MPppRecvr(); |
|
55 // |
|
56 inline TInt SendFrame(RMBufChain& aPacket); |
|
57 inline void SetId(TUint aPppId); |
|
58 inline void SetPhase(TPppPhase aPhase); |
|
59 void Register(TUint aPpdId=KPppIdAsIs); |
|
60 void Reregister(TUint aPpdId, TPppPhase aPhase); |
|
61 void Deregister(); |
|
62 void Deque(); |
|
63 |
|
64 |
|
65 /** |
|
66 Delivers a data link frame to this receiver for processing. |
|
67 @param aPacket [in] A reference to the RMBufChain object containing |
|
68 the data link frame. |
|
69 @return EFalse |
|
70 */ |
|
71 virtual TBool RecvFrame(RMBufChain& aPacket)=0; |
|
72 |
|
73 /** |
|
74 Notifies that a CRC error has been detected in the data link frame |
|
75 that has been received. |
|
76 */ |
|
77 virtual void FrameError()=0; |
|
78 |
|
79 /** |
|
80 Deactivates this receiver object, preventing any processing of the |
|
81 data link frames being received. |
|
82 */ |
|
83 virtual void KillProtocol()=0; |
|
84 |
|
85 IMPORT_C virtual void FlowOn(); |
|
86 |
|
87 /** |
|
88 Notifies this receiver that the lower layer is up, i.e. that the |
|
89 PPP link is now in a phase when this receiver is active and that |
|
90 this receiver should get ready for processing the data frames being |
|
91 received, as the data frames being received will be delivered to |
|
92 it. |
|
93 */ |
|
94 virtual void LowerLayerUp(); |
|
95 |
|
96 /** |
|
97 Notifies this receiver that the lower layer is down, i.e. that the |
|
98 PPP link is now in a phase when this receiver is inactive and the |
|
99 data frames being received will not be delivered to it. |
|
100 @param aStatus [in] A status code that may indicate a special |
|
101 reason for which this receiver was deactivated. |
|
102 */ |
|
103 virtual void LowerLayerDown(TInt aStatus); |
|
104 protected: |
|
105 CNifFactory* FindPppFactoryL(const TDesC& aFilename, TUid aUid2, CObjectCon& aCon); |
|
106 MPppRecvr(); |
|
107 // virtual void PhaseChanged(TPppPhase aOldPhase, TPppPhase aNewPhase, TInt aReason)=0; |
|
108 protected: |
|
109 TUint iPppId; |
|
110 TPppPhase iActivePhase; |
|
111 CPppLcp* iPppLcp; |
|
112 TInt iPppAbortCode; |
|
113 private: |
|
114 friend class CPppLcp; |
|
115 TDblQueLink iPppRecvrListLink; |
|
116 }; |
|
117 |
|
118 class RPppOption; |
|
119 class TPppFcs32; |
|
120 class MPppOptionHandler; |
|
121 |
|
122 // |
|
123 // PPP Options |
|
124 // |
|
125 |
|
126 class RPppOptionList : public RMBufPktQ |
|
127 { |
|
128 public: |
|
129 void SetL(RMBufChain& aList, TInt aLength=0); |
|
130 TInt CopyL(RMBufChain& aPacket, TInt aHdrLen=0) const; |
|
131 TInt RemoveOption(RPppOption& aOption); |
|
132 TInt ReplaceOption(RPppOption& aOption); |
|
133 TInt RemoveOptions(RPppOptionList& aRejectList); |
|
134 TInt ReplaceOptions(RPppOptionList& aReplaceList); |
|
135 void CreatePacketL(RMBufPacket& aPacket, TUint aPppId, TUint8 aType, TUint8 aId, TBool aCreateEmptyPacket = EFalse); |
|
136 void CreateAndAddL(TUint8 aType); |
|
137 void CreateAndAddL(TUint8 aType, TUint8 aValue); |
|
138 void CreateAndAddL(TUint8 aType, TUint16 aValue); |
|
139 void CreateAndAddL(TUint8 aType, TUint32 aValue); |
|
140 void CreateAndAddL(TUint8 aType, const TUint8* aBuf, TInt aLen ); // CSW |
|
141 void CreateAndAddL(TUint8 aType, TPtrC8& aValue); |
|
142 void Crc32(TPppFcs32& aFcs, TBool aInitFcs=ETrue); |
|
143 TBool EqualTo(RPppOptionList& aList); |
|
144 TBool IsSubsetOf(RPppOptionList& aList); |
|
145 }; |
|
146 |
|
147 class MPppOptionsExtender |
|
148 { |
|
149 public: |
|
150 MPppOptionsExtender(); |
|
151 void ExtOptRegister(MPppOptionHandler* aHandler); |
|
152 void ExtOptDeregister(MPppOptionHandler* aHandler); |
|
153 void ExtOptNegotiationStarted(); |
|
154 void ExtOptNegotiationAborted(); |
|
155 void ExtOptNegotiationComplete(); |
|
156 void ExtOptFillinConfigRequestL(RPppOptionList& aRequestList); |
|
157 void ExtOptCheckConfigRequest(RPppOption& aOption, RPppOptionList &aAckList, RPppOptionList &aNakList, RPppOptionList &aRejList); |
|
158 void ExtOptApplyConfigRequest(RPppOption& aOption); |
|
159 void ExtOptRecvConfigAck(RPppOption& aOption); |
|
160 void ExtOptRecvConfigNak(RPppOption& aOption, RPppOptionList& aReqList); |
|
161 void ExtOptRecvConfigReject(RPppOption& aOption, RPppOptionList& aReqList); |
|
162 MPppOptionHandler* ExtOptLookup(TUint8 aOptId); |
|
163 private: |
|
164 TDblQue<MPppOptionHandler> iExtOptHandlerList; |
|
165 }; |
|
166 |
|
167 // |
|
168 // PPP Finite State Machine |
|
169 // |
|
170 |
|
171 enum TPppFsmState |
|
172 { |
|
173 EPppFsmInitial, EPppFsmStarting, |
|
174 EPppFsmClosed, EPppFsmStopped, |
|
175 EPppFsmClosing, EPppFsmStopping, |
|
176 EPppFsmReqSent, EPppFsmAckRecvd, |
|
177 EPppFsmAckSent, EPppFsmOpened |
|
178 }; |
|
179 |
|
180 class MPppFsm : public MPppRecvr, public MTimer |
|
181 { |
|
182 public: |
|
183 MPppFsm(CPppLcp* aPppLcp, TPppPhase aPhase, TUint aPppId); |
|
184 virtual ~MPppFsm(); |
|
185 void FsmConstructL(); |
|
186 // Open the state machine |
|
187 TInt FsmOpen(); |
|
188 // Close the state machine |
|
189 void FsmClose(TInt aReason); |
|
190 // Abort, similar to close, but enters stopped/closed states |
|
191 void FsmAbort(TInt aReason); |
|
192 // Enquire if this layer is in the Opened state |
|
193 TBool FsmIsThisLayerOpen(); |
|
194 TUint8 FsmNewId(); |
|
195 void FsmRejectPacket(RMBufChain& aPacket, TUint aReason=KPppLcpCodeReject, TUint aPppId=KPppIdAsIs); |
|
196 void TerminateLink(); |
|
197 inline void ChangeTimers(TBool aLengthen); |
|
198 inline void ConnectionPersist(TBool aPersist); |
|
199 |
|
200 |
|
201 protected: |
|
202 // Open the layer below |
|
203 virtual TInt FsmLayerStarted()=0; |
|
204 // Close the layer below |
|
205 virtual void FsmLayerFinished(TInt aReason=KErrNone)=0; |
|
206 // Signal up event to next layer above |
|
207 virtual void FsmLayerUp()=0; |
|
208 // Signal down event to next layer above |
|
209 virtual void FsmLayerDown(TInt aReason=KErrNone)=0; |
|
210 // Fillin Config Request to be sent |
|
211 virtual void FsmFillinConfigRequestL(RPppOptionList& aRequestList)=0; |
|
212 // Check options in a recvd config request |
|
213 virtual void FsmCheckConfigRequest(RPppOptionList& aRequestList, RPppOptionList& aAckList, RPppOptionList& aNakList, RPppOptionList& aRejList)=0; |
|
214 // Apply options in a recvd config request - no-one has complained |
|
215 virtual void FsmApplyConfigRequest(RPppOptionList& aRequestList)=0; |
|
216 // Recvd a Config Ack |
|
217 virtual void FsmRecvConfigAck(RPppOptionList& aReplyList)=0; |
|
218 // Recvd a Config Nak - The associated original request is in aReqList |
|
219 virtual void FsmRecvConfigNak(RPppOptionList& aReplyList, RPppOptionList& aReqList)=0; |
|
220 // Recvd a Config Reject - The associated original request is in aReqList |
|
221 virtual void FsmRecvConfigReject(RPppOptionList& aReplyList, RPppOptionList& aReqList)=0; |
|
222 // Recvd an unrecognised opcode - has a default implementation |
|
223 virtual void FsmTerminationPhaseComplete()=0; |
|
224 virtual TBool FsmRecvUnknownCode(TUint8 aCode, TUint8 aId, TInt aLength, RMBufChain& aPacket); |
|
225 IMPORT_C virtual void KillProtocol(); |
|
226 virtual TBool FsmAckOptionsValid(RPppOptionList& aList, RPppOptionList& aRequestList); |
|
227 virtual TBool FsmRejectOptionsValid(RPppOptionList& aList, RPppOptionList& aRequestList); |
|
228 virtual TBool FsmConfigRequestOptionsValid(RPppOptionList& aList); |
|
229 |
|
230 //PG Moved to protected so it can be called by CPppCcp::KillProtocol |
|
231 void SetState(TPppFsmState aState); |
|
232 |
|
233 //SL Added to return current state for CPppLcp::LinkRecv |
|
234 inline TPppFsmState FsmState() const; |
|
235 |
|
236 TUint8* NewPacket(RMBufPacket& aPkt, TUint aLength); |
|
237 |
|
238 protected: |
|
239 /** |
|
240 Is RFC compliant termination phase for Administrative close enabled? */ |
|
241 TBool iTerminateRequestEnabled; |
|
242 |
|
243 /** |
|
244 Is RFC compliant termination phase for incoming TerminateRequest enabled? */ |
|
245 TBool iTerminateAckEnabled; |
|
246 |
|
247 /** Why PPP is shutting down */ |
|
248 TInt iFsmTerminationCauseError; |
|
249 |
|
250 private: |
|
251 // MPppRecvr upcalls handled by FSM |
|
252 IMPORT_C virtual TBool RecvFrame(RMBufChain& aPacket); |
|
253 IMPORT_C virtual void FrameError(); |
|
254 IMPORT_C virtual void LowerLayerUp(); |
|
255 IMPORT_C virtual void LowerLayerDown(TInt aStatus=KErrNone); |
|
256 // MTimer upcall |
|
257 IMPORT_C virtual void TimerComplete(TInt aStatus); |
|
258 // Internal functions |
|
259 void InitRestartCountForConfig(); |
|
260 void InitRestartCountForTerminate(); |
|
261 void ZeroRestartCount(); |
|
262 void SendConfigRequest(); |
|
263 void SendInitialConfigRequest(); |
|
264 void SendConfigRequestAfterNak(RPppOptionList& aOptList); |
|
265 void SendConfigRequestAfterReject(RPppOptionList& aOptList); |
|
266 void SendConfigReply(RPppOptionList& aOptList, TUint8 aType, TUint8 aId); |
|
267 void SendInitialTerminateRequest(); |
|
268 void SendTerminateRequest(); |
|
269 void SendTerminateAck(TUint8 aId); |
|
270 void ProcessConfig(TUint8 aCode, TUint8 aId, TInt aLength, RMBufChain& aPacket); |
|
271 TBool ProcessEmptyConfigReq(); |
|
272 void ProcessReject(TUint8 aCode, TUint8 aId, TInt aLength, RMBufChain& aPacket); |
|
273 void ProcessTerminate(TUint8 aCode, TUint8 aId, TInt aLength, RMBufChain& aPacket); |
|
274 void ThisLayerUp(); |
|
275 void ThisLayerDown(); |
|
276 void ThisLayerStarted(); |
|
277 void ThisLayerFinished(); |
|
278 TInt InitialiseConfigRequest(); |
|
279 |
|
280 void ReadIniFileL(); |
|
281 inline TBool MaxFailureExceeded() const; |
|
282 inline void DecrementMaxFailure(); |
|
283 inline void InitMaxFailure(); |
|
284 |
|
285 public: |
|
286 const TText* __iFsmName; |
|
287 private: |
|
288 TUint8 iCurrentId; |
|
289 TUint iTerminateId; |
|
290 TUint iRequestId; |
|
291 RPppOptionList iRequestList; |
|
292 // RFC 1661 4.6 |
|
293 TInt iMaxRestartConfig; |
|
294 TInt iRestartCount; |
|
295 |
|
296 TPppFsmState iState; |
|
297 |
|
298 // RFC 1661 4.6 |
|
299 TInt iWaitTimeConfig; |
|
300 TInt iWaitTime; |
|
301 TInt iConsecCfgReq; |
|
302 TUint32 iLastCfgReqFcs; |
|
303 |
|
304 // RFC 1661 4.6 |
|
305 TInt iMaxFailureConfig; |
|
306 TInt iMaxFailureCount; |
|
307 |
|
308 // |
|
309 // Termination phase support. |
|
310 // CDMA2000 requires RFC compliant behavior for terminating the PPP link. |
|
311 // |
|
312 |
|
313 /** |
|
314 Maximum TerminateRequest transmissions. */ |
|
315 TInt iMaxTerminateRequest; |
|
316 |
|
317 /** |
|
318 TerminateRequest retransmission timeout */ |
|
319 TInt iTerminateRequestTimeout; |
|
320 |
|
321 /** |
|
322 Terminate Ack timeout period*/ |
|
323 TInt iTerminateAckTimeout; |
|
324 |
|
325 |
|
326 TBool iLengthenTimers:1; |
|
327 TBool iPersist:1; |
|
328 /** If MPppFsm is to be terminated.*/ |
|
329 TBool iFsmTermination:1; |
|
330 /** The physical layer may block on its own retries when trying to send an initial config packet |
|
331 which then blocks the LCP from shutting down until attempts to send a disconnect packet have timed |
|
332 out. To allow for a quick shutdown in such cases where there is no evidence that the link layer |
|
333 is working the EPppFsmStarting state also sets this flag. This is driven by INC85191. |
|
334 */ |
|
335 TBool iNoEvidenceOfPeer:1; |
|
336 |
|
337 /** |
|
338 Whether restart timer period doubles or not */ |
|
339 TBool iWaitTimeNoIncrease:1; |
|
340 }; |
|
341 |
|
342 |
|
343 inline void MPppFsm::ChangeTimers(TBool aLengthen) |
|
344 { |
|
345 iLengthenTimers=aLengthen; |
|
346 } |
|
347 |
|
348 inline void MPppFsm::ConnectionPersist(TBool aPersist) |
|
349 { |
|
350 iPersist=aPersist; |
|
351 } |
|
352 |
|
353 inline TPppFsmState MPppFsm::FsmState() const |
|
354 { |
|
355 return iState; |
|
356 } |
|
357 |
|
358 inline TBool MPppFsm::MaxFailureExceeded() const |
|
359 { |
|
360 return iMaxFailureCount == 0; |
|
361 } |
|
362 |
|
363 inline void MPppFsm::DecrementMaxFailure() |
|
364 { |
|
365 iMaxFailureCount--; |
|
366 } |
|
367 |
|
368 inline void MPppFsm::InitMaxFailure() |
|
369 { |
|
370 iMaxFailureCount = iMaxFailureConfig; |
|
371 } |
|
372 |
|
373 // |
|
374 // [lcp] |
|
375 // PPPEnableMaxFailure = 0:disabled/1:enabled |
|
376 // PPPMaxFailureCount = 5 default |
|
377 _LIT(LCPSECTIONNAME,"lcp"); |
|
378 _LIT(PPPMAXFAILUREENTRYNAME_ENABLE,"PPPEnableMaxFailure"); |
|
379 _LIT(PPPMAXFAILUREENTRYNAME_COUNT,"PPPMaxFailureCount"); |
|
380 const TInt KPppMaxFailureDefault = 5; |
|
381 |
|
382 // [lcp] |
|
383 // PPPEnableMaxRestart = 0:disabled/1:enabled |
|
384 // PPPMaxRestartCount = 20 default |
|
385 _LIT(PPPMAXRESTARTENTRYNAME_ENABLE,"PPPEnableMaxRestart"); |
|
386 _LIT(PPPMAXRESTARTENTRYNAME_COUNT,"PPPMaxRestartCount"); |
|
387 |
|
388 // [lcp] |
|
389 // PPPEnableRestartTimer = 0:disabled/1:enabled |
|
390 // PPPRestartPeriod= 3000 default 3 Seconds |
|
391 _LIT(PPPRESTARTTIMERENTRYNAME_ENABLE,"PPPEnableRestartTimer"); |
|
392 _LIT(PPPRESTARTTIMERENTRYNAME_PERIOD,"PPPRestartPeriod"); |
|
393 _LIT(PPP_RESTARTTIMER_ENTRYNAME_MODE,"PPPRestartTimerMode"); |
|
394 |
|
395 |
|
396 // |
|
397 // Termination sequence support |
|
398 // Doesn't follow the macro naming convention deliberately |
|
399 // |
|
400 |
|
401 //[lcp] |
|
402 // PPPEnableMaxTerminateRestart = 0:disabled/1:enabled |
|
403 _LIT(TERMINATE_REQUEST_ENABLE, "PPPEnableTerminateRequest"); |
|
404 |
|
405 // PPPEnableMaxTerminateRestart = 0:disabled/1:enabled |
|
406 // PPPMaxTerminateRequestCount: Max TerminateRequests to be sent |
|
407 _LIT(MAX_TERMINATE_REQUEST_ENABLE, "PPPEnableMaxTerminateRequest"); |
|
408 _LIT(MAX_TERMINATE_REQUEST_COUNT, "PPPMaxTerminateRequestCount"); |
|
409 |
|
410 |
|
411 // [lcp] |
|
412 // PPPEnableTerminateRestartTimer 0:disabled/1:enabled |
|
413 // PPPTerminateRestartPeriod time to TerminateRequest retransmission |
|
414 _LIT(TERMINATE_REQUEST_TIMER_ENABLE, "PPPEnableTerminateRequestTimer"); |
|
415 _LIT(TERMINATE_REQUEST_TIMER_PERIOD, "PPPTerminateRequestPeriod"); |
|
416 |
|
417 // [lcp] |
|
418 // PPPEnableTerminateAck = 0: disabled / 1: enabled |
|
419 _LIT(TERMINATE_ACK_ENABLE, "PPPEnableTerminateAck"); |
|
420 |
|
421 // PPPEnableTerminateAckTimer = 0: disabled / 1: enabled |
|
422 // PPPTerminateAckPeriod the time to wait after sending TerminateAck |
|
423 _LIT(TERMINATE_ACK_TIMER_ENABLE, "PPPEnableTerminateAckTimer"); |
|
424 _LIT(TERMINATE_ACK_TIMER_PERIOD, "PPPTerminateAckPeriod"); |
|
425 |
|
426 #endif |