184b580c4SWaldemar Kornewald/*
2abdb7d1aSWaldemar Kornewald * Copyright 2003-2005, Haiku Inc.
384b580c4SWaldemar Kornewald * Distributed under the terms of the MIT License.
484b580c4SWaldemar Kornewald */
592a8026eSWaldemar Kornewald
692a8026eSWaldemar Kornewald#ifndef _K_PPP_LAYER__H
792a8026eSWaldemar Kornewald#define _K_PPP_LAYER__H
892a8026eSWaldemar Kornewald
992a8026eSWaldemar Kornewald#include <KPPPDefs.h>
1092a8026eSWaldemar Kornewald
11e3724c38Smshlyn#include <net_buffer.h>
1292a8026eSWaldemar Kornewald
13f9ad2df8SWaldemar Kornewaldclass KPPPLayer {
1492a8026eSWaldemar Kornewald	protected:
1513013331SWaldemar Kornewald		//!	KPPPLayer must be subclassed
16f9ad2df8SWaldemar Kornewald		KPPPLayer(const char *name, ppp_level level, uint32 overhead);
1792a8026eSWaldemar Kornewald
1892a8026eSWaldemar Kornewald	public:
19f9ad2df8SWaldemar Kornewald		virtual ~KPPPLayer();
2092a8026eSWaldemar Kornewald
2192a8026eSWaldemar Kornewald		virtual status_t InitCheck() const;
2292a8026eSWaldemar Kornewald
2313013331SWaldemar Kornewald		//!	Layer name.
2492a8026eSWaldemar Kornewald		const char *Name() const
2592a8026eSWaldemar Kornewald			{ return fName; }
2613013331SWaldemar Kornewald		/*!	\brief Level of this layer (level is defined in enum: \c ppp_level).
2713013331SWaldemar Kornewald
2813013331SWaldemar Kornewald			This should be \c PPP_PROTOCOL_LEVEL if this layer is not an encapsulator.
2913013331SWaldemar Kornewald		*/
3092a8026eSWaldemar Kornewald		ppp_level Level() const
3192a8026eSWaldemar Kornewald			{ return fLevel; }
3213013331SWaldemar Kornewald		//!	Length of header that will be prepended to outgoing packets.
334e0ad752SWaldemar Kornewald		uint32 Overhead() const
344e0ad752SWaldemar Kornewald			{ return fOverhead; }
3592a8026eSWaldemar Kornewald
3613013331SWaldemar Kornewald		//!	Sets the next layer. This will be the target of \c SendToNext().
37f9ad2df8SWaldemar Kornewald		void SetNext(KPPPLayer *next)
3892a8026eSWaldemar Kornewald			{ fNext = next; }
3913013331SWaldemar Kornewald		//!	Next layer in chain.
40f9ad2df8SWaldemar Kornewald		KPPPLayer *Next() const
4192a8026eSWaldemar Kornewald			{ return fNext; }
4292a8026eSWaldemar Kornewald
4313013331SWaldemar Kornewald		//!	Brings this layer up.
4492a8026eSWaldemar Kornewald		virtual bool Up() = 0;
4513013331SWaldemar Kornewald		//!	Brings this layer down.
4692a8026eSWaldemar Kornewald		virtual bool Down() = 0;
4792a8026eSWaldemar Kornewald
4813013331SWaldemar Kornewald		//!	Returns whether this layer is allowed to send packets.
4992a8026eSWaldemar Kornewald		virtual bool IsAllowedToSend() const = 0;
5092a8026eSWaldemar Kornewald
5113013331SWaldemar Kornewald		//!	Send a packet with the given protocol number.
52e3724c38Smshlyn		virtual status_t Send(net_buffer *packet, uint16 protocolNumber) = 0;
5313013331SWaldemar Kornewald		//!	Receive a packet with the given protocol number.
54e3724c38Smshlyn		virtual status_t Receive(net_buffer *packet, uint16 protocolNumber) = 0;
5592a8026eSWaldemar Kornewald
56e3724c38Smshlyn		status_t SendToNext(net_buffer *packet, uint16 protocolNumber) const;
5792a8026eSWaldemar Kornewald			// send the packet to the next layer
5892a8026eSWaldemar Kornewald
5992a8026eSWaldemar Kornewald		virtual void Pulse();
6092a8026eSWaldemar Kornewald
6192a8026eSWaldemar Kornewald	protected:
62f9ad2df8SWaldemar Kornewald		void SetName(const char *name);
6313013331SWaldemar Kornewald
6413013331SWaldemar Kornewald	protected:
6592a8026eSWaldemar Kornewald		status_t fInitStatus;
664e0ad752SWaldemar Kornewald		uint32 fOverhead;
6792a8026eSWaldemar Kornewald
6892a8026eSWaldemar Kornewald	private:
6992a8026eSWaldemar Kornewald		char *fName;
7092a8026eSWaldemar Kornewald		ppp_level fLevel;
7192a8026eSWaldemar Kornewald
72f9ad2df8SWaldemar Kornewald		KPPPLayer *fNext;
7392a8026eSWaldemar Kornewald};
7492a8026eSWaldemar Kornewald
7592a8026eSWaldemar Kornewald
7692a8026eSWaldemar Kornewald#endif