1 /* 2 * Copyright 2003-2005, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _K_PPP_LAYER__H 7 #define _K_PPP_LAYER__H 8 9 #include <KPPPDefs.h> 10 11 #include <net_buffer.h> 12 13 class KPPPLayer { 14 protected: 15 //! KPPPLayer must be subclassed 16 KPPPLayer(const char *name, ppp_level level, uint32 overhead); 17 18 public: 19 virtual ~KPPPLayer(); 20 21 virtual status_t InitCheck() const; 22 23 //! Layer name. 24 const char *Name() const 25 { return fName; } 26 /*! \brief Level of this layer (level is defined in enum: \c ppp_level). 27 28 This should be \c PPP_PROTOCOL_LEVEL if this layer is not an encapsulator. 29 */ 30 ppp_level Level() const 31 { return fLevel; } 32 //! Length of header that will be prepended to outgoing packets. 33 uint32 Overhead() const 34 { return fOverhead; } 35 36 //! Sets the next layer. This will be the target of \c SendToNext(). 37 void SetNext(KPPPLayer *next) 38 { fNext = next; } 39 //! Next layer in chain. 40 KPPPLayer *Next() const 41 { return fNext; } 42 43 //! Brings this layer up. 44 virtual bool Up() = 0; 45 //! Brings this layer down. 46 virtual bool Down() = 0; 47 48 //! Returns whether this layer is allowed to send packets. 49 virtual bool IsAllowedToSend() const = 0; 50 51 //! Send a packet with the given protocol number. 52 virtual status_t Send(net_buffer *packet, uint16 protocolNumber) = 0; 53 //! Receive a packet with the given protocol number. 54 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber) = 0; 55 56 status_t SendToNext(net_buffer *packet, uint16 protocolNumber) const; 57 // send the packet to the next layer 58 59 virtual void Pulse(); 60 61 protected: 62 void SetName(const char *name); 63 64 protected: 65 status_t fInitStatus; 66 uint32 fOverhead; 67 68 private: 69 char *fName; 70 ppp_level fLevel; 71 72 KPPPLayer *fNext; 73 }; 74 75 76 #endif 77