xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPProtocol.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_PROTOCOL__H
9 #define _K_PPP_PROTOCOL__H
10 
11 #include <KPPPDefs.h>
12 #include <KPPPLayer.h>
13 
14 class KPPPInterface;
15 class KPPPOptionHandler;
16 
17 
18 class KPPPProtocol : public KPPPLayer {
19 	protected:
20 		// KPPPProtocol must be subclassed
21 		KPPPProtocol(const char *name, ppp_phase activationPhase,
22 			uint16 protocolNumber, ppp_level level, int32 addressFamily,
23 			uint32 overhead, KPPPInterface& interface,
24 			driver_parameter *settings, int32 flags = PPP_NO_FLAGS,
25 			const char *type = NULL, KPPPOptionHandler *optionHandler = NULL);
26 
27 	public:
28 		virtual ~KPPPProtocol();
29 
30 		virtual void Uninit();
31 
32 		KPPPInterface& Interface() const
33 			{ return fInterface; }
34 		driver_parameter *Settings() const
35 			{ return fSettings; }
36 
37 		ppp_phase ActivationPhase() const
38 			{ return fActivationPhase; }
39 
40 		uint16 ProtocolNumber() const
41 			{ return fProtocolNumber; }
42 		int32 AddressFamily() const
43 			{ return fAddressFamily; }
44 				// negative values and values > 0xFF are ignored
45 		int32 Flags() const
46 			{ return fFlags; }
47 		ppp_side Side() const
48 			{ return fSide; }
49 				// which side this protocol works for
50 
51 		const char *Type() const
52 			{ return fType; }
53 		KPPPOptionHandler *OptionHandler() const
54 			{ return fOptionHandler; }
55 
56 		void SetNextProtocol(KPPPProtocol *protocol)
57 			{ fNextProtocol = protocol; SetNext(protocol); }
58 		KPPPProtocol *NextProtocol() const
59 			{ return fNextProtocol; }
60 
61 		void SetEnabled(bool enabled = true);
62 		bool IsEnabled() const
63 			{ return fEnabled; }
64 
65 		bool IsUpRequested() const
66 			{ return fUpRequested; }
67 
68 		virtual status_t Control(uint32 op, void *data, size_t length);
69 		virtual status_t StackControl(uint32 op, void *data);
70 			// called by netstack (forwarded by KPPPInterface)
71 
72 		virtual bool Up() = 0;
73 		virtual bool Down() = 0;
74 			// if DialOnDemand is supported check for DialOnDemand settings change
75 		bool IsUp() const
76 			{ return fConnectionPhase == PPP_ESTABLISHED_PHASE; }
77 		bool IsDown() const
78 			{ return fConnectionPhase == PPP_DOWN_PHASE; }
79 		bool IsGoingUp() const
80 			{ return fConnectionPhase == PPP_ESTABLISHMENT_PHASE; }
81 		bool IsGoingDown() const
82 			{ return fConnectionPhase == PPP_TERMINATION_PHASE; }
83 
84 		virtual bool IsAllowedToSend() const;
85 
86 		virtual status_t Send(struct mbuf *packet, uint16 protocolNumber) = 0;
87 		virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber) = 0;
88 
89 	protected:
90 		void SetUpRequested(bool requested = true)
91 			{ fUpRequested = requested; }
92 
93 		// Report that we are going up/down
94 		// (from now on, the Up() process can be aborted).
95 		void UpStarted();
96 		void DownStarted();
97 
98 		// report up/down events
99 		void UpFailedEvent();
100 		void UpEvent();
101 		void DownEvent();
102 
103 	protected:
104 		ppp_side fSide;
105 
106 	private:
107 		ppp_phase fActivationPhase;
108 		uint16 fProtocolNumber;
109 		int32 fAddressFamily;
110 		KPPPInterface& fInterface;
111 		driver_parameter *fSettings;
112 		int32 fFlags;
113 		char *fType;
114 		KPPPOptionHandler *fOptionHandler;
115 
116 		KPPPProtocol *fNextProtocol;
117 		bool fEnabled;
118 		bool fUpRequested;
119 		ppp_phase fConnectionPhase;
120 };
121 
122 
123 #endif
124