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