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#include <net_buffer.h>
24#include <NetBufferUtilities.h>
25
26class KPPPLCPExtension;
27class KPPPOptionHandler;
28
29
30//!	LCP packet header structure.
31typedef struct ppp_lcp_packet {
32	uint8 code;
33	uint8 id;
34	uint16 length;
35	uint8 data[0];
36} ppp_lcp_packet;
37
38
39class KPPPLCP : public KPPPProtocol {
40		friend class KPPPInterface;
41
42	private:
43		// may only be constructed/destructed by KPPPInterface
44		KPPPLCP(KPPPInterface& interface);
45		virtual ~KPPPLCP();
46
47		// copies are not allowed!
48		KPPPLCP(const KPPPLCP& copy);
49		KPPPLCP& operator= (const KPPPLCP& copy);
50
51	public:
52		//!	Returns the KPPPStateMachine of the interface that owns this protocol.
53		KPPPStateMachine& StateMachine() const
54			{ return fStateMachine; }
55
56		bool AddOptionHandler(KPPPOptionHandler *handler);
57		bool RemoveOptionHandler(KPPPOptionHandler *handler);
58		//!	Returns number of registered KPPPOptionHandler objects.
59		int32 CountOptionHandlers() const
60			{ return fOptionHandlers.CountItems(); }
61		KPPPOptionHandler *OptionHandlerAt(int32 index) const;
62		KPPPOptionHandler *OptionHandlerFor(uint8 type, int32 *start = NULL) const;
63
64		bool AddLCPExtension(KPPPLCPExtension *extension);
65		bool RemoveLCPExtension(KPPPLCPExtension *extension);
66		//!	Returns number of registered KPPPLCPExtension objects.
67		int32 CountLCPExtensions() const
68			{ return fLCPExtensions.CountItems(); }
69		KPPPLCPExtension *LCPExtensionAt(int32 index) const;
70		KPPPLCPExtension *LCPExtensionFor(uint8 code, int32 *start = NULL) const;
71
72		/*!	\brief Sets the target protocol handler for outgoing LCP packets.
73
74			This may be used for filtering or routing LCP packets. Multilink
75			protocols might need this method. \n
76			If \a target != \c NULL all packets will be passed to the given protocol
77			instead of the interface/device.
78		*/
79		void SetTarget(KPPPProtocol *target)
80			{ fTarget = target; }
81		//!	Returns the LCP packet handler or \c NULL.
82		KPPPProtocol *Target() const
83			{ return fTarget; }
84
85		virtual bool Up();
86		virtual bool Down();
87
88		virtual status_t Send(net_buffer *packet,
89			uint16 protocolNumber = PPP_LCP_PROTOCOL);
90		virtual status_t Receive(net_buffer *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