xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //---------------------------------------------------------------------
7 
8 #ifndef _K_PPP_LCP__H
9 #define _K_PPP_LCP__H
10 
11 #include <List.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 PPPLCPExtension;
26 class PPPOptionHandler;
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 PPPLCP : public PPPProtocol {
38 		friend class PPPInterface;
39 
40 	private:
41 		// may only be constructed/destructed by PPPInterface
42 		PPPLCP(PPPInterface& interface);
43 		virtual ~PPPLCP();
44 
45 		// copies are not allowed!
46 		PPPLCP(const PPPLCP& copy);
47 		PPPLCP& operator= (const PPPLCP& copy);
48 
49 	public:
50 		PPPStateMachine& StateMachine() const
51 			{ return fStateMachine; }
52 
53 		bool AddOptionHandler(PPPOptionHandler *handler);
54 		bool RemoveOptionHandler(PPPOptionHandler *handler);
55 		int32 CountOptionHandlers() const
56 			{ return fOptionHandlers.CountItems(); }
57 		PPPOptionHandler *OptionHandlerAt(int32 index) const;
58 		PPPOptionHandler *OptionHandlerFor(uint8 type, int32 *start = NULL) const;
59 
60 		bool AddLCPExtension(PPPLCPExtension *extension);
61 		bool RemoveLCPExtension(PPPLCPExtension *extension);
62 		int32 CountLCPExtensions() const
63 			{ return fLCPExtensions.CountItems(); }
64 		PPPLCPExtension *LCPExtensionAt(int32 index) const;
65 		PPPLCPExtension *LCPExtensionFor(uint8 code, int32 *start = NULL) const;
66 
67 		void SetTarget(PPPProtocol *target)
68 			{ fTarget = target; }
69 			// if target != NULL all packtes will be passed to the protocol
70 			// instead of the interface/device
71 		PPPProtocol *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 bool Up();
78 		virtual bool Down();
79 
80 		virtual status_t Send(struct mbuf *packet,
81 			uint16 protocolNumber = PPP_LCP_PROTOCOL);
82 		virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber);
83 
84 		virtual void Pulse();
85 
86 	private:
87 		PPPStateMachine& fStateMachine;
88 
89 		List<PPPOptionHandler*> fOptionHandlers;
90 		List<PPPLCPExtension*> fLCPExtensions;
91 
92 		PPPProtocol *fTarget;
93 };
94 
95 
96 #endif
97