1 /* 2 * Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net> 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 bool Up(); 58 virtual bool Down(); 59 60 virtual status_t Send(struct mbuf *packet, uint16 protocolNumber); 61 virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber); 62 virtual void Pulse(); 63 64 private: 65 // for state machine 66 void NewState(pap_state next); 67 uint8 NextID(); 68 // return the next id for PAP packets 69 70 // events 71 void TOGoodEvent(); 72 void TOBadEvent(); 73 void RREvent(struct mbuf *packet); 74 void RAEvent(struct mbuf *packet); 75 void RNEvent(struct mbuf *packet); 76 77 // actions 78 void ReportUpFailedEvent(); 79 void ReportUpEvent(); 80 void ReportDownEvent(); 81 void InitializeRestartCount(); 82 bool SendRequest(); 83 bool SendAck(struct mbuf *packet); 84 bool SendNak(struct mbuf *packet); 85 86 private: 87 // for state machine 88 pap_state fState; 89 vint32 fID; 90 91 // counters and timers 92 int32 fMaxRequest; 93 int32 fRequestCounter; 94 uint8 fRequestID; 95 // the ID we used for the last configure/terminate request 96 bigtime_t fNextTimeout; 97 98 BLocker fLock; 99 }; 100 101 102 #endif 103