* Copyright 2003-2004, Haiku Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _K_PPP_DEVICE__H
#define _K_PPP_DEVICE__H
#include <KPPPDefs.h>
#include <KPPPLayer.h>
#include <net_buffer.h>
#ifndef _K_PPP_INTERFACE__H
#include <KPPPInterface.h>
#endif
class KPPPDevice : public KPPPLayer {
friend class KPPPStateMachine;
protected:
KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interface,
driver_parameter *settings);
public:
virtual ~KPPPDevice();
KPPPInterface& Interface() const
{ return fInterface; }
driver_parameter *Settings() const
{ return fSettings; }
virtual status_t Control(uint32 op, void *data, size_t length);
uint32 MTU() const
{ return fMTU; }
ATTENTION: This method must not block! \n
Call UpStarted() to check if you are allowed to go down. After UpStarted()
is called the connection attempt may be aborted by calling Down(). \n
In server mode you should listen for incoming connections.
On error: \e Either call \c UpFailedEvent() and return \c true \e or
return \c false only. \e Never call \c UpFailedEvent() and return
\c false at the same time!
\sa UpStarted()
\sa UpFailedEvent()
*/
virtual bool Up() = 0;
Call DownStarted() to check if you are allowed to go down. \n
The return value of this method is currently ignored.
\sa DownStarted()
*/
virtual bool Down() = 0;
bool IsUp() const
{ return fConnectionPhase == PPP_ESTABLISHED_PHASE; }
bool IsDown() const
{ return fConnectionPhase == PPP_DOWN_PHASE; }
bool IsGoingUp() const
{ return fConnectionPhase == PPP_ESTABLISHMENT_PHASE; }
bool IsGoingDown() const
{ return fConnectionPhase == PPP_TERMINATION_PHASE; }
The biggest of the two tranfer rates will be set in ifnet. \n
Should return default value when disconnected.
*/
virtual uint32 InputTransferRate() const = 0;
The biggest of the two tranfer rates will be set in ifnet. \n
Should return default value when disconnected.
*/
virtual uint32 OutputTransferRate() const = 0;
virtual uint32 CountOutputBytes() const = 0;
virtual bool IsAllowedToSend() const;
This should enqueue the packet and return immediately (never block).
The device is responsible for freeing the packet by calling \c m_freem().
*/
virtual status_t Send(net_buffer *packet, uint16 protocolNumber) = 0;
virtual status_t Receive(net_buffer *packet, uint16 protocolNumber);
protected:
void SetMTU(uint32 MTU)
{ fMTU = MTU; }
bool UpStarted();
bool DownStarted();
void UpFailedEvent();
void UpEvent();
void DownEvent();
protected:
uint32 fMTU;
private:
char *fName;
KPPPInterface& fInterface;
driver_parameter *fSettings;
ppp_phase fConnectionPhase;
};
#endif