xref: /haiku/src/add-ons/kernel/network/ppp/pap/Protocol.h (revision aff60bb217827097c13d643275fdf1f1c66e7f17)
1 /*
2  * Copyright 2003-2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef PROTOCOL__H
7 #define PROTOCOL__H
8 
9 #include <driver_settings.h>
10 
11 #include <KPPPOptionHandler.h>
12 #include <KPPPProtocol.h>
13 #include <Locker.h>
14 
15 #include <arpa/inet.h>
16 
17 
18 #define PAP_PROTOCOL	0xC023
19 
20 
21 enum pap_state {
22 	INITIAL,
23 	REQ_SENT,
24 	WAITING_FOR_REQ,
25 	ACCEPTED
26 };
27 
28 
29 class PAP;
30 
31 class PAPHandler : public KPPPOptionHandler {
32 	public:
33 		PAPHandler(PAP& owner, KPPPInterface& interface);
34 
35 		PAP& Owner() const
36 			{ return fOwner; }
37 
38 		virtual status_t AddToRequest(KPPPConfigurePacket& request);
39 		virtual status_t ParseRequest(const KPPPConfigurePacket& request,
40 			int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject);
41 
42 	private:
43 		PAP& fOwner;
44 };
45 
46 
47 class PAP : public KPPPProtocol {
48 	public:
49 		PAP(KPPPInterface& interface, driver_parameter *settings);
50 		virtual ~PAP();
51 
52 		virtual status_t InitCheck() const;
53 
54 		pap_state State() const
55 			{ return fState; }
56 
57 		virtual void ProfileChanged();
58 
59 		virtual bool Up();
60 		virtual bool Down();
61 
62 		virtual status_t Send(struct mbuf *packet, uint16 protocolNumber);
63 		virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber);
64 		virtual void Pulse();
65 
66 	private:
67 		bool ParseSettings(const driver_parameter *settings);
68 
69 		// for state machine
70 		void NewState(pap_state next);
71 		uint8 NextID();
72 			// return the next id for PAP packets
73 
74 		// events
75 		void TOGoodEvent();
76 		void TOBadEvent();
77 		void RREvent(struct mbuf *packet);
78 		void RAEvent(struct mbuf *packet);
79 		void RNEvent(struct mbuf *packet);
80 
81 		// actions
82 		void ReportUpFailedEvent();
83 		void ReportUpEvent();
84 		void ReportDownEvent();
85 		void InitializeRestartCount();
86 		bool SendRequest();
87 		bool SendAck(struct mbuf *packet);
88 		bool SendNak(struct mbuf *packet);
89 
90 	private:
91 		char fUser[256], fPassword[256];
92 
93 		// for state machine
94 		pap_state fState;
95 		vint32 fID;
96 
97 		// counters and timers
98 		int32 fMaxRequest;
99 		int32 fRequestCounter;
100 		uint8 fRequestID;
101 			// the ID we used for the last configure/terminate request
102 		bigtime_t fNextTimeout;
103 
104 		BLocker fLock;
105 };
106 
107 
108 #endif
109