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