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