xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPDevice.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_DEVICE__H
9 #define _K_PPP_DEVICE__H
10 
11 #include <KPPPDefs.h>
12 #include <KPPPLayer.h>
13 
14 #ifndef _K_PPP_INTERFACE__H
15 #include <KPPPInterface.h>
16 #endif
17 
18 
19 class KPPPDevice : public KPPPLayer {
20 		friend class KPPPStateMachine;
21 
22 	protected:
23 		// KPPPDevice must be subclassed
24 		KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interface,
25 			driver_parameter *settings);
26 
27 	public:
28 		virtual ~KPPPDevice();
29 
30 		KPPPInterface& Interface() const
31 			{ return fInterface; }
32 		driver_parameter *Settings() const
33 			{ return fSettings; }
34 
35 		virtual status_t Control(uint32 op, void *data, size_t length);
36 
37 		uint32 MTU() const
38 			{ return fMTU; }
39 
40 		virtual bool Up() = 0;
41 			// In server mode you should listen for incoming connections.
42 			// On error: either call UpFailedEvent() or return false.
43 		virtual bool Down() = 0;
44 		bool IsUp() const
45 			{ return fConnectionPhase == PPP_ESTABLISHED_PHASE; }
46 		bool IsDown() const
47 			{ return fConnectionPhase == PPP_DOWN_PHASE; }
48 		bool IsGoingUp() const
49 			{ return fConnectionPhase == PPP_ESTABLISHMENT_PHASE; }
50 		bool IsGoingDown() const
51 			{ return fConnectionPhase == PPP_TERMINATION_PHASE; }
52 
53 		// The biggest of the two tranfer rates will be set in ifnet.
54 		// These methods should return default values when disconnected.
55 		virtual uint32 InputTransferRate() const = 0;
56 		virtual uint32 OutputTransferRate() const = 0;
57 
58 		virtual uint32 CountOutputBytes() const = 0;
59 			// how many bytes are waiting to be sent?
60 
61 		virtual bool IsAllowedToSend() const;
62 			// always returns true
63 
64 		virtual status_t Send(struct mbuf *packet, uint16 protocolNumber) = 0;
65 			// This should enqueue the packet and return immediately (never block).
66 			// The device is responsible for freeing the packet.
67 		virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber);
68 			// this method is never used
69 
70 		virtual void Pulse();
71 
72 	protected:
73 		void SetMTU(uint32 MTU)
74 			{ fMTU = MTU; }
75 
76 		// Report that we are going up/down
77 		// (from now on, the Up() process can be aborted).
78 		// Abort if false is returned!
79 		bool UpStarted();
80 		bool DownStarted();
81 
82 		// report up/down events
83 		void UpFailedEvent();
84 		void UpEvent();
85 		void DownEvent();
86 
87 	protected:
88 		uint32 fMTU;
89 			// always hold this value up-to-date!
90 
91 	private:
92 		char *fName;
93 		KPPPInterface& fInterface;
94 		driver_parameter *fSettings;
95 
96 		ppp_phase fConnectionPhase;
97 };
98 
99 
100 #endif
101