xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPOptionHandler.h (revision b55a57da7173b9af0432bd3e148d03f06161d036)
1 /*
2  * Copyright 2003-2005, Haiku Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef _K_PPP_OPTION_HANDLER__H
7 #define _K_PPP_OPTION_HANDLER__H
8 
9 #include <KPPPDefs.h>
10 
11 #ifndef _K_PPP_INTERFACE__H
12 #include <KPPPInterface.h>
13 #endif
14 
15 class KPPPConfigurePacket;
16 
17 
18 class KPPPOptionHandler {
19 	protected:
20 		// KPPPOptionHandler must be subclassed
21 		KPPPOptionHandler(const char *name, uint8 type, KPPPInterface& interface,
22 			driver_parameter *settings);
23 
24 	public:
25 		virtual ~KPPPOptionHandler();
26 
27 		virtual status_t InitCheck() const;
28 
29 		//!	Returns the name of this handler.
30 		const char *Name() const
31 			{ return fName; }
32 
33 		//!	Returns the LCP item type this object can handle.
34 		uint8 Type() const
35 			{ return fType; }
36 
37 		//!	Returns the owning interface.
38 		KPPPInterface& Interface() const
39 			{ return fInterface; }
40 		//!	Returns the handler's settings.
41 		driver_parameter *Settings() const
42 			{ return fSettings; }
43 
44 		//!	Enables or disables this handler.
45 		void SetEnabled(bool enabled = true)
46 			{ fEnabled = enabled; }
47 		//!	Returns if the handler is enabled.
48 		bool IsEnabled() const
49 			{ return fEnabled; }
50 
51 		virtual status_t Control(uint32 op, void *data, size_t length);
52 		virtual status_t StackControl(uint32 op, void *data);
53 			// called by netstack (forwarded by KPPPInterface)
54 
55 		// we want to send a configure request or we received a reply
56 		virtual status_t AddToRequest(KPPPConfigurePacket& request);
57 		virtual status_t ParseNak(const KPPPConfigurePacket& nak);
58 			// create next request based on these and previous values
59 		virtual status_t ParseReject(const KPPPConfigurePacket& reject);
60 			// create next request based on these and previous values
61 		virtual status_t ParseAck(const KPPPConfigurePacket& ack);
62 			// this is called for all handlers
63 
64 		virtual status_t ParseRequest(const KPPPConfigurePacket& request,
65 			int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject);
66 		virtual status_t SendingAck(const KPPPConfigurePacket& ack);
67 
68 		virtual void Reset();
69 
70 	protected:
71 		status_t fInitStatus;
72 
73 	private:
74 		char *fName;
75 		uint8 fType;
76 		KPPPInterface& fInterface;
77 		driver_parameter *fSettings;
78 
79 		bool fEnabled;
80 };
81 
82 
83 #endif
84