1 /* 2 * Copyright 2003-2006, 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 Owner()35 PAP& Owner() const 36 { return fOwner; } 37 38 virtual status_t AddToRequest(KPPPConfigurePacket& request); 39 virtual status_t SendingAck(const KPPPConfigurePacket&); 40 virtual status_t ParseRequest(const KPPPConfigurePacket& request, 41 int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject); 42 43 private: 44 PAP& fOwner; 45 }; 46 47 48 class PAP : public KPPPProtocol { 49 public: 50 PAP(KPPPInterface& interface, driver_parameter *settings); 51 virtual ~PAP(); 52 53 virtual status_t InitCheck() const; 54 State()55 pap_state State() const 56 { return fState; } 57 58 virtual bool Up(); 59 virtual bool Down(); 60 61 virtual status_t Send(net_buffer *packet, uint16 protocolNumber); 62 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber); 63 virtual void Pulse(); 64 65 private: 66 // for state machine 67 void NewState(pap_state next); 68 uint8 NextID(); 69 // return the next id for PAP packets 70 71 // events 72 void TOGoodEvent(); 73 void TOBadEvent(); 74 void RREvent(net_buffer *packet); 75 void RAEvent(net_buffer *packet); 76 void RNEvent(net_buffer *packet); 77 78 // actions 79 void ReportUpFailedEvent(); 80 void ReportUpEvent(); 81 void ReportDownEvent(); 82 void InitializeRestartCount(); 83 bool SendRequest(); 84 bool SendAck(net_buffer *packet); 85 bool SendNak(net_buffer *packet); 86 87 private: 88 // for state machine 89 pap_state fState; 90 int32 fID; 91 92 // counters and timers 93 int32 fMaxRequest; 94 int32 fRequestCounter; 95 uint8 fRequestID; 96 // the ID we used for the last configure/terminate request 97 bigtime_t fNextTimeout; 98 }; 99 100 101 #endif 102