* Copyright 2003-2004, Haiku Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _K_PPP_STATE_MACHINE__H
#define _K_PPP_STATE_MACHINE__H
#include <KPPPDefs.h>
class KPPPProtocol;
#ifndef _K_PPP_INTERFACE__H
#include <KPPPInterface.h>
#endif
#include <lock.h>
#include <util/AutoLock.h>
class PPPManager;
class KPPPInterface;
class KPPPLCP;
class KPPPStateMachine {
friend class PPPManager;
friend class KPPPInterface;
friend class KPPPLCP;
private:
KPPPStateMachine(KPPPInterface& interface);
~KPPPStateMachine();
KPPPStateMachine(const KPPPStateMachine& copy);
KPPPStateMachine& operator= (const KPPPStateMachine& copy);
public:
KPPPInterface& Interface() const
{ return fInterface; }
KPPPLCP& LCP() const
{ return fLCP; }
ppp_state State() const
{ return fState; }
ppp_phase Phase() const
{ return fPhase; }
uint8 NextID();
void SetMagicNumber(uint32 magicNumber)
{ fMagicNumber = magicNumber; }
uint32 MagicNumber() const
{ return fMagicNumber; }
bool Reconfigure();
bool SendEchoRequest();
bool SendDiscardRequest();
void LocalAuthenticationRequested();
void LocalAuthenticationAccepted(const char *name);
void LocalAuthenticationDenied(const char *name);
const char *LocalAuthenticationName() const
{ return fLocalAuthenticationName; }
ppp_authentication_status LocalAuthenticationStatus() const
{ return fLocalAuthenticationStatus; }
void PeerAuthenticationRequested();
void PeerAuthenticationAccepted(const char *name);
void PeerAuthenticationDenied(const char *name);
const char *PeerAuthenticationName() const
{ return fPeerAuthenticationName; }
ppp_authentication_status PeerAuthenticationStatus() const
{ return fPeerAuthenticationStatus; }
void UpFailedEvent(KPPPInterface& interface);
void UpEvent(KPPPInterface& interface);
void DownEvent(KPPPInterface& interface);
void UpFailedEvent(KPPPProtocol *protocol);
void UpEvent(KPPPProtocol *protocol);
void DownEvent(KPPPProtocol *protocol);
bool TLSNotify();
bool TLFNotify();
void UpFailedEvent();
void UpEvent();
void DownEvent();
private:
void NewState(ppp_state next);
void NewPhase(ppp_phase next);
void OpenEvent();
void ContinueOpenEvent();
void CloseEvent();
void TOGoodEvent();
void TOBadEvent();
void RCRGoodEvent(net_buffer *packet);
void RCRBadEvent(net_buffer *nak, net_buffer *reject);
void RCAEvent(net_buffer *packet);
void RCNEvent(net_buffer *packet);
void RTREvent(net_buffer *packet);
void RTAEvent(net_buffer *packet);
void RUCEvent(net_buffer *packet, uint16 protocolNumber,
uint8 code = PPP_PROTOCOL_REJECT);
void RXJGoodEvent(net_buffer *packet);
void RXJBadEvent(net_buffer *packet);
void RXREvent(net_buffer *packet);
void TimerEvent();
void RCREvent(net_buffer *packet);
void RXJEvent(net_buffer *packet);
void IllegalEvent(ppp_event event);
void ThisLayerUp();
void ThisLayerDown();
void ThisLayerStarted();
void ThisLayerFinished();
void InitializeRestartCount();
void ZeroRestartCount();
bool SendConfigureRequest();
bool SendConfigureAck(net_buffer *packet);
bool SendConfigureNak(net_buffer *packet);
bool SendTerminateRequest();
bool SendTerminateAck(net_buffer *request = NULL);
bool SendCodeReject(net_buffer *packet, uint16 protocolNumber, uint8 code);
bool SendEchoReply(net_buffer *request);
void BringProtocolsUp();
uint32 BringPhaseUp();
void DownProtocols();
void ResetLCPHandlers();
private:
KPPPInterface& fInterface;
KPPPLCP& fLCP;
ppp_state fState;
ppp_phase fPhase;
int32 fID;
uint32 fMagicNumber;
int32 fLastConnectionReportCode;
ppp_authentication_status fLocalAuthenticationStatus,
fPeerAuthenticationStatus;
char *fLocalAuthenticationName, *fPeerAuthenticationName;
int32 fMaxRequest, fMaxTerminate, fMaxNak;
int32 fRequestCounter, fTerminateCounter, fNakCounter;
uint8 fRequestID, fTerminateID, fEchoID;
bigtime_t fNextTimeout;
mutex fLock;
};
#endif