xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 //-----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //-----------------------------------------------------------------------
7 
8 #ifndef _K_PPP_LCP__H
9 #define _K_PPP_LCP__H
10 
11 #include <TemplateList.h>
12 
13 #ifndef _K_PPP_PROTOCOL__H
14 #include <KPPPProtocol.h>
15 #endif
16 
17 #ifndef _K_PPP_INTERFACE__H
18 #include <KPPPInterface.h>
19 #endif
20 
21 #ifndef _K_PPP_STATE_MACHINE__H
22 #include <KPPPStateMachine.h>
23 #endif
24 
25 class KPPPLCPExtension;
26 class KPPPOptionHandler;
27 
28 
29 typedef struct ppp_lcp_packet {
30 	uint8 code;
31 	uint8 id;
32 	uint16 length;
33 	uint8 data[0];
34 } ppp_lcp_packet;
35 
36 
37 class KPPPLCP : public KPPPProtocol {
38 		friend class KPPPInterface;
39 
40 	private:
41 		// may only be constructed/destructed by KPPPInterface
42 		KPPPLCP(KPPPInterface& interface);
43 		virtual ~KPPPLCP();
44 
45 		// copies are not allowed!
46 		KPPPLCP(const KPPPLCP& copy);
47 		KPPPLCP& operator= (const KPPPLCP& copy);
48 
49 	public:
50 		KPPPStateMachine& StateMachine() const
51 			{ return fStateMachine; }
52 
53 		bool AddOptionHandler(KPPPOptionHandler *handler);
54 		bool RemoveOptionHandler(KPPPOptionHandler *handler);
55 		int32 CountOptionHandlers() const
56 			{ return fOptionHandlers.CountItems(); }
57 		KPPPOptionHandler *OptionHandlerAt(int32 index) const;
58 		KPPPOptionHandler *OptionHandlerFor(uint8 type, int32 *start = NULL) const;
59 
60 		bool AddLCPExtension(KPPPLCPExtension *extension);
61 		bool RemoveLCPExtension(KPPPLCPExtension *extension);
62 		int32 CountLCPExtensions() const
63 			{ return fLCPExtensions.CountItems(); }
64 		KPPPLCPExtension *LCPExtensionAt(int32 index) const;
65 		KPPPLCPExtension *LCPExtensionFor(uint8 code, int32 *start = NULL) const;
66 
67 		void SetTarget(KPPPProtocol *target)
68 			{ fTarget = target; }
69 			// if target != NULL all packtes will be passed to the protocol
70 			// instead of the interface/device
71 		KPPPProtocol *Target() const
72 			{ return fTarget; }
73 
74 		uint32 AdditionalOverhead() const;
75 			// the overhead caused by the target, the device, and the interface
76 
77 		virtual void ProfileChanged();
78 
79 		virtual bool Up();
80 		virtual bool Down();
81 
82 		virtual status_t Send(struct mbuf *packet,
83 			uint16 protocolNumber = PPP_LCP_PROTOCOL);
84 		virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber);
85 
86 		virtual void Pulse();
87 
88 	private:
89 		KPPPStateMachine& fStateMachine;
90 
91 		TemplateList<KPPPOptionHandler*> fOptionHandlers;
92 		TemplateList<KPPPLCPExtension*> fLCPExtensions;
93 
94 		KPPPProtocol *fTarget;
95 };
96 
97 
98 #endif
99