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 <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 } _PACKED 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 *gProto[]; 58 // defined in ipcp.cpp 59 60 61 class IPCP : public KPPPProtocol { 62 public: 63 IPCP(KPPPInterface& interface, driver_parameter *settings); 64 virtual ~IPCP(); 65 66 ppp_state State() const 67 { return fState; } 68 69 virtual status_t StackControl(uint32 op, void *data); 70 71 virtual bool Up(); 72 virtual bool Down(); 73 74 virtual status_t Send(struct mbuf *packet, 75 uint16 protocolNumber = IPCP_PROTOCOL); 76 virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber); 77 status_t ReceiveIPPacket(struct mbuf *packet, uint16 protocolNumber); 78 virtual void Pulse(); 79 80 private: 81 bool ParseSideRequests(const driver_parameter *requests, ppp_side side); 82 void UpdateAddresses(); 83 void RemoveRoutes(); 84 85 // for state machine 86 void NewState(ppp_state next); 87 uint8 NextID(); 88 // return the next id for IPCP packets 89 90 // events 91 void TOGoodEvent(); 92 void TOBadEvent(); 93 void RCREvent(struct mbuf *packet); 94 void RCRGoodEvent(struct mbuf *packet); 95 void RCRBadEvent(struct mbuf *nak, struct mbuf *reject); 96 void RCAEvent(struct mbuf *packet); 97 void RCNEvent(struct mbuf *packet); 98 void RTREvent(struct mbuf *packet); 99 void RTAEvent(struct mbuf *packet); 100 void RUCEvent(struct mbuf *packet); 101 void RXJBadEvent(struct mbuf *packet); 102 103 // actions 104 void IllegalEvent(ppp_event event); 105 void ReportUpFailedEvent(); 106 void ReportUpEvent(); 107 void ReportDownEvent(); 108 void InitializeRestartCount(); 109 void ZeroRestartCount(); 110 bool SendConfigureRequest(); 111 bool SendConfigureAck(struct mbuf *packet); 112 bool SendConfigureNak(struct mbuf *packet); 113 bool SendTerminateRequest(); 114 bool SendTerminateAck(struct mbuf *request = NULL); 115 bool SendCodeReject(struct mbuf *packet); 116 117 private: 118 ipcp_configuration fLocalConfiguration, fPeerConfiguration; 119 ipcp_requests fLocalRequests, fPeerRequests; 120 121 // default route 122 struct sockaddr_in fGateway; 123 rtentry *fDefaultRoute; 124 125 // used for local requests 126 bool fRequestPrimaryDNS, fRequestSecondaryDNS; 127 128 // for state machine 129 ppp_state fState; 130 vint32 fID; 131 132 // counters and timers 133 int32 fMaxRequest, fMaxTerminate, fMaxNak; 134 int32 fRequestCounter, fTerminateCounter, fNakCounter; 135 uint8 fRequestID, fTerminateID; 136 // the ID we used for the last configure/terminate request 137 bigtime_t fNextTimeout; 138 139 BLocker fLock; 140 }; 141 142 143 #endif 144