1 /* 2 * Copyright 2003-2005, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _K_PPP_LCP__H 7 #define _K_PPP_LCP__H 8 9 #include <TemplateList.h> 10 11 #ifndef _K_PPP_PROTOCOL__H 12 #include <KPPPProtocol.h> 13 #endif 14 15 #ifndef _K_PPP_INTERFACE__H 16 #include <KPPPInterface.h> 17 #endif 18 19 #ifndef _K_PPP_STATE_MACHINE__H 20 #include <KPPPStateMachine.h> 21 #endif 22 23 class KPPPLCPExtension; 24 class KPPPOptionHandler; 25 26 27 //! LCP packet header structure. 28 typedef struct ppp_lcp_packet { 29 uint8 code; 30 uint8 id; 31 uint16 length; 32 uint8 data[0]; 33 } ppp_lcp_packet; 34 35 36 class KPPPLCP : public KPPPProtocol { 37 friend class KPPPInterface; 38 39 private: 40 // may only be constructed/destructed by KPPPInterface 41 KPPPLCP(KPPPInterface& interface); 42 virtual ~KPPPLCP(); 43 44 // copies are not allowed! 45 KPPPLCP(const KPPPLCP& copy); 46 KPPPLCP& operator= (const KPPPLCP& copy); 47 48 public: 49 //! Returns the KPPPStateMachine of the interface that owns this protocol. 50 KPPPStateMachine& StateMachine() const 51 { return fStateMachine; } 52 53 bool AddOptionHandler(KPPPOptionHandler *handler); 54 bool RemoveOptionHandler(KPPPOptionHandler *handler); 55 //! Returns number of registered KPPPOptionHandler objects. 56 int32 CountOptionHandlers() const 57 { return fOptionHandlers.CountItems(); } 58 KPPPOptionHandler *OptionHandlerAt(int32 index) const; 59 KPPPOptionHandler *OptionHandlerFor(uint8 type, int32 *start = NULL) const; 60 61 bool AddLCPExtension(KPPPLCPExtension *extension); 62 bool RemoveLCPExtension(KPPPLCPExtension *extension); 63 //! Returns number of registered KPPPLCPExtension objects. 64 int32 CountLCPExtensions() const 65 { return fLCPExtensions.CountItems(); } 66 KPPPLCPExtension *LCPExtensionAt(int32 index) const; 67 KPPPLCPExtension *LCPExtensionFor(uint8 code, int32 *start = NULL) const; 68 69 /*! \brief Sets the target protocol handler for outgoing LCP packets. 70 71 This may be used for filtering or routing LCP packets. Multilink 72 protocols might need this method. \n 73 If \a target != \c NULL all packets will be passed to the given protocol 74 instead of the interface/device. 75 */ 76 void SetTarget(KPPPProtocol *target) 77 { fTarget = target; } 78 //! Returns the LCP packet handler or \c NULL. 79 KPPPProtocol *Target() const 80 { return fTarget; } 81 82 uint32 AdditionalOverhead() const; 83 // the overhead caused by the target, the device, and the interface 84 85 virtual bool Up(); 86 virtual bool Down(); 87 88 virtual status_t Send(struct mbuf *packet, 89 uint16 protocolNumber = PPP_LCP_PROTOCOL); 90 virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber); 91 92 virtual void Pulse(); 93 94 private: 95 KPPPStateMachine& fStateMachine; 96 97 TemplateList<KPPPOptionHandler*> fOptionHandlers; 98 TemplateList<KPPPLCPExtension*> fLCPExtensions; 99 100 KPPPProtocol *fTarget; 101 }; 102 103 104 #endif 105