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