1 //---------------------------------------------------------------------- 2 // This software is part of the OpenBeOS distribution and is covered 3 // by the OpenBeOS license. 4 // 5 // Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de 6 //--------------------------------------------------------------------- 7 8 #ifndef _K_PPP_STATE_MACHINE__H 9 #define _K_PPP_STATE_MACHINE__H 10 11 #include <KPPPDefs.h> 12 13 class PPPProtocol; 14 15 #ifndef _K_PPP_INTERFACE__H 16 #include <KPPPInterface.h> 17 #endif 18 19 #include <Locker.h> 20 21 22 class PPPStateMachine { 23 friend class PPPInterface; 24 friend class PPPLCP; 25 26 private: 27 // may only be constructed/destructed by PPPInterface 28 PPPStateMachine(PPPInterface& interface); 29 ~PPPStateMachine(); 30 31 // copies are not allowed! 32 PPPStateMachine(const PPPStateMachine& copy); 33 PPPStateMachine& operator= (const PPPStateMachine& copy); 34 35 public: 36 PPPInterface& Interface() const 37 { return fInterface; } 38 PPPLCP& LCP() const 39 { return fLCP; } 40 41 ppp_state State() const 42 { return fState; } 43 ppp_phase Phase() const 44 { return fPhase; } 45 46 uint8 NextID(); 47 // return the next id for LCP packets 48 49 void SetMagicNumber(uint32 magicNumber) 50 { fMagicNumber = magicNumber; } 51 uint32 MagicNumber() const 52 { return fMagicNumber; } 53 54 // public actions 55 bool Reconfigure(); 56 bool SendEchoRequest(); 57 bool SendDiscardRequest(); 58 59 // public events 60 void LocalAuthenticationRequested(); 61 void LocalAuthenticationAccepted(const char *name); 62 void LocalAuthenticationDenied(const char *name); 63 const char *LocalAuthenticationName() const 64 { return fLocalAuthenticationName; } 65 ppp_authentication_status LocalAuthenticationStatus() const 66 { return fLocalAuthenticationStatus; } 67 68 void PeerAuthenticationRequested(); 69 void PeerAuthenticationAccepted(const char *name); 70 void PeerAuthenticationDenied(const char *name); 71 const char *PeerAuthenticationName() const 72 { return fPeerAuthenticationName; } 73 ppp_authentication_status PeerAuthenticationStatus() const 74 { return fPeerAuthenticationStatus; } 75 76 // sub-interface events 77 void UpFailedEvent(PPPInterface& interface); 78 void UpEvent(PPPInterface& interface); 79 void DownEvent(PPPInterface& interface); 80 81 // protocol events 82 void UpFailedEvent(PPPProtocol *protocol); 83 void UpEvent(PPPProtocol *protocol); 84 void DownEvent(PPPProtocol *protocol); 85 86 // device events 87 bool TLSNotify(); 88 bool TLFNotify(); 89 void UpFailedEvent(); 90 void UpEvent(); 91 void DownEvent(); 92 93 private: 94 // private StateMachine methods 95 void NewState(ppp_state next); 96 void NewPhase(ppp_phase next); 97 98 // private events 99 void OpenEvent(); 100 void CloseEvent(); 101 void TOGoodEvent(); 102 void TOBadEvent(); 103 void RCRGoodEvent(struct mbuf *packet); 104 void RCRBadEvent(struct mbuf *nak, struct mbuf *reject); 105 void RCAEvent(struct mbuf *packet); 106 void RCNEvent(struct mbuf *packet); 107 void RTREvent(struct mbuf *packet); 108 void RTAEvent(struct mbuf *packet); 109 void RUCEvent(struct mbuf *packet, uint16 protocolNumber, 110 uint8 code = PPP_PROTOCOL_REJECT); 111 void RXJGoodEvent(struct mbuf *packet); 112 void RXJBadEvent(struct mbuf *packet); 113 void RXREvent(struct mbuf *packet); 114 115 // general events (for Good/Bad events) 116 void TimerEvent(); 117 void RCREvent(struct mbuf *packet); 118 void RXJEvent(struct mbuf *packet); 119 120 // actions 121 void IllegalEvent(ppp_event event); 122 void ThisLayerUp(); 123 void ThisLayerDown(); 124 void ThisLayerStarted(); 125 void ThisLayerFinished(); 126 void InitializeRestartCount(); 127 void ZeroRestartCount(); 128 bool SendConfigureRequest(); 129 bool SendConfigureAck(struct mbuf *packet); 130 bool SendConfigureNak(struct mbuf *packet); 131 bool SendTerminateRequest(); 132 bool SendTerminateAck(struct mbuf *request = NULL); 133 bool SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uint8 code); 134 bool SendEchoReply(struct mbuf *request); 135 136 void BringProtocolsUp(); 137 uint32 BringPhaseUp(); 138 139 void DownProtocols(); 140 void ResetLCPHandlers(); 141 142 private: 143 PPPInterface& fInterface; 144 PPPLCP& fLCP; 145 146 ppp_phase fPhase; 147 ppp_state fState; 148 149 vint32 fID; 150 uint32 fMagicNumber; 151 152 ppp_authentication_status fLocalAuthenticationStatus, 153 fPeerAuthenticationStatus; 154 char *fLocalAuthenticationName, *fPeerAuthenticationName; 155 156 BLocker fLock; 157 158 // counters and timers 159 int32 fMaxRequest, fMaxTerminate, fMaxNak; 160 int32 fRequestCounter, fTerminateCounter, fNakCounter; 161 uint8 fRequestID, fTerminateID, fEchoID; 162 // the ID we used for the last configure/terminate/echo request 163 bigtime_t fNextTimeout; 164 }; 165 166 167 #endif 168