xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPOptionHandler.h (revision 9eb55bc1d104b8fda80898f8b25c94d8000c8255)
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_OPTION_HANDLER__H
9 #define _K_PPP_OPTION_HANDLER__H
10 
11 #include <KPPPDefs.h>
12 
13 #ifndef _K_PPP_INTERFACE__H
14 #include <KPPPInterface.h>
15 #endif
16 
17 class KPPPConfigurePacket;
18 
19 
20 class KPPPOptionHandler {
21 	protected:
22 		// KPPPOptionHandler must be subclassed
23 		KPPPOptionHandler(const char *name, uint8 type, KPPPInterface& interface,
24 			driver_parameter *settings);
25 
26 	public:
27 		virtual ~KPPPOptionHandler();
28 
29 		virtual status_t InitCheck() const;
30 
31 		const char *Name() const
32 			{ return fName; }
33 
34 		uint8 Type() const
35 			{ return fType; }
36 
37 		KPPPInterface& Interface() const
38 			{ return fInterface; }
39 		driver_parameter *Settings() const
40 			{ return fSettings; }
41 
42 		void SetEnabled(bool enabled = true)
43 			{ fEnabled = enabled; }
44 		bool IsEnabled() const
45 			{ return fEnabled; }
46 
47 		virtual status_t Control(uint32 op, void *data, size_t length);
48 		virtual status_t StackControl(uint32 op, void *data);
49 			// called by netstack (forwarded by KPPPInterface)
50 
51 		// we want to send a configure request or we received a reply
52 		virtual status_t AddToRequest(KPPPConfigurePacket& request) = 0;
53 		virtual status_t ParseNak(const KPPPConfigurePacket& nak) = 0;
54 			// create next request based on these and previous values
55 		virtual status_t ParseReject(const KPPPConfigurePacket& reject) = 0;
56 			// create next request based on these and previous values
57 		virtual status_t ParseAck(const KPPPConfigurePacket& ack) = 0;
58 			// this is called for all handlers
59 
60 		// peer sent configure request
61 		virtual status_t ParseRequest(const KPPPConfigurePacket& request,
62 			int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) = 0;
63 			// index may be behind the last item which means additional values can be
64 			// appended
65 		virtual status_t SendingAck(const KPPPConfigurePacket& ack) = 0;
66 			// notification that we ack these values
67 
68 		virtual void Reset() = 0;
69 			// e.g.: remove list of rejected values
70 
71 	protected:
72 		status_t fInitStatus;
73 
74 	private:
75 		char *fName;
76 		uint8 fType;
77 		KPPPInterface& fInterface;
78 		driver_parameter *fSettings;
79 
80 		bool fEnabled;
81 };
82 
83 
84 #endif
85