1 //---------------------------------------------------------------------- 2 // This software is part of the OpenBeOS distribution and is covered 3 // by the OpenBeOS license. 4 // 5 // Copyright (c) 2003 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 <KPPPProtocol.h> 14 #include <Locker.h> 15 16 #include <arpa/inet.h> 17 18 19 #define IPCP_PROTOCOL 0x8021 20 #define IP_PROTOCOL 0x0021 21 22 23 typedef struct ip_item { 24 uint8 type; 25 uint8 length; 26 in_addr_t address; 27 } ip_item; 28 29 30 enum ipcp_configure_item_codes { 31 IPCP_ADDRESSES = 1, 32 IPCP_COMPRESSION_PROTOCOL = 2, 33 IPCP_ADDRESS = 3, 34 IPCP_PRIMARY_DNS = 129, 35 IPCP_SECONDARY_DNS = 131 36 }; 37 38 39 typedef struct ipcp_requests { 40 // let peer suggest value if ours equals 0.0.0.0 41 in_addr_t address; 42 in_addr_t netmask; 43 // if equal 0.0.0.0 it will be chosen automatically 44 in_addr_t primaryDNS; 45 in_addr_t secondaryDNS; 46 } ipcp_requests; 47 48 49 // the values that were negotiated 50 typedef struct ipcp_configuration { 51 in_addr_t address; 52 in_addr_t primaryDNS; 53 in_addr_t secondaryDNS; 54 } ipcp_configuration; 55 56 57 extern struct protosw *proto[]; 58 // defined in ipcp.cpp 59 60 61 class IPCP : public PPPProtocol { 62 public: 63 IPCP(PPPInterface& interface, driver_parameter *settings); 64 virtual ~IPCP(); 65 66 ppp_state State() const 67 { return fState; } 68 69 virtual bool Up(); 70 virtual bool Down(); 71 72 virtual status_t Send(struct mbuf *packet, 73 uint16 protocolNumber = IPCP_PROTOCOL); 74 virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber); 75 status_t ReceiveIPPacket(struct mbuf *packet, uint16 protocolNumber); 76 virtual void Pulse(); 77 78 private: 79 bool ParseSideRequests(driver_parameter *requests, ppp_side side); 80 void UpdateAddresses(); 81 82 // for state machine 83 void NewState(ppp_state next); 84 uint8 NextID(); 85 // return the next id for IPCP packets 86 87 // events 88 void TOGoodEvent(); 89 void TOBadEvent(); 90 void RCREvent(struct mbuf *packet); 91 void RCRGoodEvent(struct mbuf *packet); 92 void RCRBadEvent(struct mbuf *nak, struct mbuf *reject); 93 void RCAEvent(struct mbuf *packet); 94 void RCNEvent(struct mbuf *packet); 95 void RTREvent(struct mbuf *packet); 96 void RTAEvent(struct mbuf *packet); 97 void RUCEvent(struct mbuf *packet); 98 void RXJBadEvent(struct mbuf *packet); 99 100 // actions 101 void IllegalEvent(ppp_event event); 102 void ReportUpFailedEvent(); 103 void ReportUpEvent(); 104 void ReportDownEvent(); 105 void InitializeRestartCount(); 106 void ZeroRestartCount(); 107 bool SendConfigureRequest(); 108 bool SendConfigureAck(struct mbuf *packet); 109 bool SendConfigureNak(struct mbuf *packet); 110 bool SendTerminateRequest(); 111 bool SendTerminateAck(struct mbuf *request = NULL); 112 bool SendCodeReject(struct mbuf *packet); 113 114 private: 115 ipcp_configuration fLocalConfiguration, fPeerConfiguration; 116 ipcp_requests fLocalRequests, fPeerRequests; 117 118 // used for local requests 119 bool fRequestPrimaryDNS, fRequestSecondaryDNS; 120 121 // for state machine 122 ppp_state fState; 123 vint32 fID; 124 125 // counters and timers 126 int32 fMaxRequest, fMaxTerminate, fMaxNak; 127 int32 fRequestCounter, fTerminateCounter, fNakCounter; 128 uint8 fRequestID, fTerminateID; 129 // the ID we used for the last configure/terminate request 130 bigtime_t fNextTimeout; 131 132 BLocker fLock; 133 }; 134 135 136 #endif 137