xref: /haiku/src/add-ons/kernel/network/ppp/modem/ModemDevice.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 MODEM_DEVICE__H
9 #define MODEM_DEVICE__H
10 
11 #include "Modem.h"
12 
13 #include <KPPPDevice.h>
14 
15 
16 enum modem_state {
17 	INITIAL,
18 		// the same as IsDown() == true
19 	TERMINATING,
20 	DIALING,
21 	OPENED
22 		// the same as IsUp() == true
23 };
24 
25 
26 class ACFCHandler;
27 
28 class ModemDevice : public KPPPDevice {
29 	public:
30 		ModemDevice(KPPPInterface& interface, driver_parameter *settings);
31 		virtual ~ModemDevice();
32 
33 		const char *PortName() const
34 			{ return fPortName; }
35 		int32 Handle() const
36 			{ return fHandle; }
37 				// returns file handle for modem driver
38 
39 		const char *InitString() const
40 			{ return fInitString; }
41 		const char *DialString() const
42 			{ return fDialString; }
43 
44 		virtual status_t InitCheck() const;
45 
46 		virtual bool Up();
47 		virtual bool Down();
48 
49 		void SetSpeed(uint32 bps);
50 		virtual uint32 InputTransferRate() const;
51 		virtual uint32 OutputTransferRate() const;
52 			// this is around 60% of the input transfer rate
53 
54 		virtual uint32 CountOutputBytes() const;
55 
56 		void OpenModem();
57 		void CloseModem();
58 
59 		// notifications:
60 		void FinishedDialing();
61 		void FailedDialing();
62 		void ConnectionLost();
63 
64 		virtual status_t Send(struct mbuf *packet, uint16 protocolNumber = 0);
65 		status_t DataReceived(uint8 *buffer, uint32 length);
66 			// this will put the data into an mbuf and call Receive()
67 		virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber = 0);
68 
69 	private:
70 		const char *fPortName, *fInitString, *fDialString;
71 		int32 fHandle;
72 			// file handle for modem driver
73 
74 		thread_id fWorkerThread;
75 
76 		uint32 fInputTransferRate, fOutputTransferRate;
77 		uint32 fOutputBytes;
78 
79 		modem_state fState;
80 
81 		ACFCHandler *fACFC;
82 
83 		BLocker fLock;
84 };
85 
86 
87 #endif
88