184b580c4SWaldemar Kornewald/*
284b580c4SWaldemar Kornewald * Copyright 2003-2004, Haiku Inc.
384b580c4SWaldemar Kornewald * Distributed under the terms of the MIT License.
484b580c4SWaldemar Kornewald */
5de2f76e1SWaldemar Kornewald
6de2f76e1SWaldemar Kornewald#ifndef _K_PPP_DEVICE__H
7de2f76e1SWaldemar Kornewald#define _K_PPP_DEVICE__H
8de2f76e1SWaldemar Kornewald
9de2f76e1SWaldemar Kornewald#include <KPPPDefs.h>
1092a8026eSWaldemar Kornewald#include <KPPPLayer.h>
11de2f76e1SWaldemar Kornewald
12e3724c38Smshlyn#include <net_buffer.h>
14de2f76e1SWaldemar Kornewald#ifndef _K_PPP_INTERFACE__H
15de2f76e1SWaldemar Kornewald#include <KPPPInterface.h>
16de2f76e1SWaldemar Kornewald#endif
17de2f76e1SWaldemar Kornewald
18de2f76e1SWaldemar Kornewald
19f9ad2df8SWaldemar Kornewaldclass KPPPDevice : public KPPPLayer {
20f9ad2df8SWaldemar Kornewald		friend class KPPPStateMachine;
21e7452421SWaldemar Kornewald
2292a8026eSWaldemar Kornewald	protected:
23f9ad2df8SWaldemar Kornewald		// KPPPDevice must be subclassed
24f9ad2df8SWaldemar Kornewald		KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interface,
25de2f76e1SWaldemar Kornewald			driver_parameter *settings);
2692a8026eSWaldemar Kornewald
2792a8026eSWaldemar Kornewald	public:
28f9ad2df8SWaldemar Kornewald		virtual ~KPPPDevice();
29de2f76e1SWaldemar Kornewald
3013013331SWaldemar Kornewald		//!	Returns the interface that owns this device.
31f9ad2df8SWaldemar Kornewald		KPPPInterface& Interface() const
32de2f76e1SWaldemar Kornewald			{ return fInterface; }
3313013331SWaldemar Kornewald		//!	Returns the device's settings.
34de2f76e1SWaldemar Kornewald		driver_parameter *Settings() const
35de2f76e1SWaldemar Kornewald			{ return fSettings; }
36de2f76e1SWaldemar Kornewald
37de2f76e1SWaldemar Kornewald		virtual status_t Control(uint32 op, void *data, size_t length);
38de2f76e1SWaldemar Kornewald
3913013331SWaldemar Kornewald		//!	Returns the device's MTU.
40de2f76e1SWaldemar Kornewald		uint32 MTU() const
41de2f76e1SWaldemar Kornewald			{ return fMTU; }
42de2f76e1SWaldemar Kornewald
4313013331SWaldemar Kornewald		/*!	\brief This brings the device up.
4413013331SWaldemar Kornewald
453f3689bbSWaldemar Kornewald			ATTENTION: This method must not block! \n
4613013331SWaldemar Kornewald			Call UpStarted() to check if you are allowed to go down. After UpStarted()
473f3689bbSWaldemar Kornewald			is called the connection attempt may be aborted by calling Down(). \n
4813013331SWaldemar Kornewald			In server mode you should listen for incoming connections.
4913013331SWaldemar Kornewald			On error: \e Either call \c UpFailedEvent() and return \c true \e or
5013013331SWaldemar Kornewald			return \c false only. \e Never call \c UpFailedEvent() and return
5113013331SWaldemar Kornewald			\c false at the same time!
5213013331SWaldemar Kornewald
5313013331SWaldemar Kornewald			\sa UpStarted()
5413013331SWaldemar Kornewald			\sa UpFailedEvent()
5513013331SWaldemar Kornewald		*/
5692a8026eSWaldemar Kornewald		virtual bool Up() = 0;
5713013331SWaldemar Kornewald		/*!	\brief Bring the interface down.
5813013331SWaldemar Kornewald
593f3689bbSWaldemar Kornewald			Call DownStarted() to check if you are allowed to go down. \n
6013013331SWaldemar Kornewald			The return value of this method is currently ignored.
6113013331SWaldemar Kornewald
6213013331SWaldemar Kornewald			\sa DownStarted()
6313013331SWaldemar Kornewald		*/
6492a8026eSWaldemar Kornewald		virtual bool Down() = 0;
6513013331SWaldemar Kornewald		//!	Is the connection established?
66de2f76e1SWaldemar Kornewald		bool IsUp() const
67e7452421SWaldemar Kornewald			{ return fConnectionPhase == PPP_ESTABLISHED_PHASE; }
6813013331SWaldemar Kornewald		//!	Is the interface disconnected and ready to connect?
69e7452421SWaldemar Kornewald		bool IsDown() const
70e7452421SWaldemar Kornewald			{ return fConnectionPhase == PPP_DOWN_PHASE; }
7113013331SWaldemar Kornewald		//!	Is the interface connecting at the moment?
72e7452421SWaldemar Kornewald		bool IsGoingUp() const
73e7452421SWaldemar Kornewald			{ return fConnectionPhase == PPP_ESTABLISHMENT_PHASE; }
7413013331SWaldemar Kornewald		//!	Is the interface disconnecting at the moment?
75e7452421SWaldemar Kornewald		bool IsGoingDown() const
76e7452421SWaldemar Kornewald			{ return fConnectionPhase == PPP_TERMINATION_PHASE; }
77de2f76e1SWaldemar Kornewald
7813013331SWaldemar Kornewald		/*!	\brief Input speed in bytes per second.
7913013331SWaldemar Kornewald
803f3689bbSWaldemar Kornewald			The biggest of the two tranfer rates will be set in ifnet. \n
8113013331SWaldemar Kornewald			Should return default value when disconnected.
8213013331SWaldemar Kornewald		*/
83de2f76e1SWaldemar Kornewald		virtual uint32 InputTransferRate() const = 0;
8413013331SWaldemar Kornewald		/*!	\brief Output speed in bytes per second.
8513013331SWaldemar Kornewald
863f3689bbSWaldemar Kornewald			The biggest of the two tranfer rates will be set in ifnet. \n
8713013331SWaldemar Kornewald			Should return default value when disconnected.
8813013331SWaldemar Kornewald		*/
89de2f76e1SWaldemar Kornewald		virtual uint32 OutputTransferRate() const = 0;
90de2f76e1SWaldemar Kornewald
9113013331SWaldemar Kornewald		//!	Number of bytes waiting to be sent (i.e.: waiting in output queue).
92de2f76e1SWaldemar Kornewald		virtual uint32 CountOutputBytes() const = 0;
93de2f76e1SWaldemar Kornewald
9492a8026eSWaldemar Kornewald		virtual bool IsAllowedToSend() const;
9592a8026eSWaldemar Kornewald
9613013331SWaldemar Kornewald		/*!	\brief Sends a packet.
9713013331SWaldemar Kornewald
9813013331SWaldemar Kornewald			This should enqueue the packet and return immediately (never block).
9913013331SWaldemar Kornewald			The device is responsible for freeing the packet by calling \c m_freem().
10013013331SWaldemar Kornewald		*/
101e3724c38Smshlyn		virtual status_t Send(net_buffer *packet, uint16 protocolNumber) = 0;
102e3724c38Smshlyn		virtual status_t Receive(net_buffer *packet, uint16 protocolNumber);
103de2f76e1SWaldemar Kornewald
104de2f76e1SWaldemar Kornewald	protected:
10513013331SWaldemar Kornewald		//!	Use this to set the device's maximum transfer unit (in bytes).
106de2f76e1SWaldemar Kornewald		void SetMTU(uint32 MTU)
107de2f76e1SWaldemar Kornewald			{ fMTU = MTU; }
108de2f76e1SWaldemar Kornewald
109e7452421SWaldemar Kornewald		bool UpStarted();
110e7452421SWaldemar Kornewald		bool DownStarted();
111de2f76e1SWaldemar Kornewald
112de2f76e1SWaldemar Kornewald		// report up/down events
113de2f76e1SWaldemar Kornewald		void UpFailedEvent();
114de2f76e1SWaldemar Kornewald		void UpEvent();
115de2f76e1SWaldemar Kornewald		void DownEvent();
116de2f76e1SWaldemar Kornewald
117de2f76e1SWaldemar Kornewald	protected:
118de2f76e1SWaldemar Kornewald		uint32 fMTU;
119de2f76e1SWaldemar Kornewald			// always hold this value up-to-date!
120de2f76e1SWaldemar Kornewald
121de2f76e1SWaldemar Kornewald	private:
122de2f76e1SWaldemar Kornewald		char *fName;
123f9ad2df8SWaldemar Kornewald		KPPPInterface& fInterface;
124de2f76e1SWaldemar Kornewald		driver_parameter *fSettings;
12592a8026eSWaldemar Kornewald
126e7452421SWaldemar Kornewald		ppp_phase fConnectionPhase;
127de2f76e1SWaldemar Kornewald};
128de2f76e1SWaldemar Kornewald
129de2f76e1SWaldemar Kornewald
130de2f76e1SWaldemar Kornewald#endif