* Copyright 2003-2006, Haiku Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _K_PPP_INTERFACE__H
#define _K_PPP_INTERFACE__H
#include <driver_settings.h>
#ifndef _K_PPP_DEFS__H
#include <KPPPDefs.h>
#endif
#ifndef _PPP_CONTROL__H
#include <PPPControl.h>
#endif
#ifndef _K_PPP_LCP__H
#include <KPPPLCP.h>
#endif
#ifndef _K_PPP_REPORT_MANAGER__H
#include <KPPPReportManager.h>
#endif
#ifndef _K_PPP_STATE_MACHINE__H
#include <KPPPStateMachine.h>
#endif
#include <TemplateList.h>
#include <net_buffer.h>
#include <net_device.h>
#include <lock.h>
#include <util/AutoLock.h>
class KPPPDevice;
class KPPPProtocol;
class KPPPOptionHandler;
struct ppp_interface_module_info;
struct ppp_module_info;
struct ppp_interface_entry;
class KPPPInterface : public KPPPLayer {
friend class PPPManager;
friend class KPPPStateMachine;
private:
KPPPInterface(const KPPPInterface& copy);
KPPPInterface& operator= (const KPPPInterface& copy);
public:
KPPPInterface(const char *name, ppp_interface_entry *entry,
ppp_interface_id ID, const driver_settings *settings,
KPPPInterface *parent = NULL);
~KPPPInterface();
public:
void Delete();
virtual status_t InitCheck() const;
ppp_interface_id ID() const
{ return fID; }
driver_settings* Settings() const
{ return fSettings; }
KPPPStateMachine& StateMachine()
{ return fStateMachine; }
KPPPLCP& LCP()
{ return fLCP; }
net_device *Ifnet() const
{ return fIfnet; }
const char *Username() const;
const char *Password() const;
uint32 ConnectRetryDelay() const
{ return fConnectRetryDelay; }
uint32 ReconnectDelay() const
{ return fReconnectDelay; }
bigtime_t ConnectedSince() const
{ return fConnectedSince; }
void UpdateIdleSince()
{ fUpdateIdleSince = true; }
uint32 IdleSince() const
{ return fIdleSince; }
uint32 DisconnectAfterIdleSince() const
{ return fDisconnectAfterIdleSince; }
bool SetMRU(uint32 MRU);
uint32 MRU() const
{ return fMRU; }
bool SetInterfaceMTU(uint32 interfaceMTU)
{ return SetMRU(interfaceMTU - fHeaderLength); }
uint32 InterfaceMTU() const
{ return fInterfaceMTU; }
uint32 PacketOverhead() const;
virtual status_t Control(uint32 op, void *data, size_t length);
bool SetDevice(KPPPDevice *device);
KPPPDevice *Device() const
{ return fDevice; }
bool AddProtocol(KPPPProtocol *protocol);
bool RemoveProtocol(KPPPProtocol *protocol);
int32 CountProtocols() const;
KPPPProtocol *ProtocolAt(int32 index) const;
KPPPProtocol *FirstProtocol() const
{ return fFirstProtocol; }
KPPPProtocol *ProtocolFor(uint16 protocolNumber,
KPPPProtocol *start = NULL) const;
bool AddChild(KPPPInterface *child);
bool RemoveChild(KPPPInterface *child);
int32 CountChildren() const
{ return fChildren.CountItems(); }
KPPPInterface *ChildAt(int32 index) const;
KPPPInterface *Parent() const
{ return fParent; }
bool IsMultilink() const
{ return fIsMultilink; }
void SetAutoReconnect(bool autoReconnect = true);
bool DoesAutoReconnect() const
{ return fAutoReconnect; }
void SetConnectOnDemand(bool connectOnDemand = true);
bool DoesConnectOnDemand() const
{ return fConnectOnDemand; }
void SetAskBeforeConnecting(bool ask);
bool DoesAskBeforeConnecting() const
{ return fAskBeforeConnecting; }
ppp_mode Mode() const
{ return fMode; }
ppp_state State() const
{ return fStateMachine.State(); }
ppp_phase Phase() const
{ return fStateMachine.Phase(); }
bool SetPFCOptions(uint8 pfcOptions);
uint8 PFCOptions() const
{ return fPFCOptions; }
Values defined in \c ppp_pfc_state. \n
The local PFC state says if we accepted a request from the peer
i.e.: we may use PFC in outgoing packets.
*/
ppp_pfc_state LocalPFCState() const
{ return fLocalPFCState; }
Values defined in \c ppp_pfc_state. \n
The peer PFC state says if the peer accepted a request us
i.e.: the peer might send PFC-compressed packets to us
*/
ppp_pfc_state PeerPFCState() const
{ return fPeerPFCState; }
bool UseLocalPFC() const
{ return LocalPFCState() == PPP_PFC_ACCEPTED; }
virtual bool Up();
virtual bool Down();
bool WaitForConnection();
bool IsUp() const
{ return Phase() == PPP_ESTABLISHED_PHASE; }
KPPPReportManager& ReportManager()
{ return fReportManager; }
bool Report(ppp_report_type type, int32 code, void *data, int32 length)
{ return ReportManager().Report(type, code, data, length); }
bool LoadModules(driver_settings *settings,
int32 start, int32 count);
bool LoadModule(const char *name, driver_parameter *parameter,
ppp_module_key_type type);
virtual bool IsAllowedToSend() const;
virtual status_t Send(net_buffer *packet, uint16 protocolNumber);
virtual status_t Receive(net_buffer *packet, uint16 protocolNumber);
status_t ReceiveFromDevice(net_buffer *packet);
void Pulse();
private:
bool RegisterInterface();
bool UnregisterInterface();
status_t StackControl(uint32 op, void *data);
status_t StackControlEachHandler(uint32 op, void *data);
void CalculateInterfaceMTU();
void CalculateBaudRate();
void Reconnect(uint32 delay);
void SetParent(KPPPInterface *parent)
{ fParent = parent; }
private:
ppp_interface_id fID;
driver_settings *fSettings;
net_device *fIfnet;
char *fUsername, *fPassword;
thread_id fReconnectThread;
uint32 fConnectAttempt, fConnectRetriesLimit;
uint32 fConnectRetryDelay, fReconnectDelay;
ppp_interface_module_info *fManager;
ppp_statistics fStatistics;
bigtime_t fConnectedSince;
uint32 fIdleSince, fDisconnectAfterIdleSince;
bool fUpdateIdleSince;
uint32 fMRU, fInterfaceMTU, fHeaderLength;
KPPPInterface *fParent;
TemplateList<KPPPInterface*> fChildren;
bool fIsMultilink;
bool fAutoReconnect, fConnectOnDemand, fAskBeforeConnecting;
ppp_mode fMode;
ppp_pfc_state fLocalPFCState, fPeerPFCState;
uint8 fPFCOptions;
KPPPDevice *fDevice;
KPPPProtocol *fFirstProtocol;
TemplateList<char*> fModules;
KPPPStateMachine fStateMachine;
KPPPLCP fLCP;
KPPPReportManager fReportManager;
mutex& fLock;
int32 fDeleteCounter;
};
#endif