1 /* 2 * Copyright 2003-2004, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _K_PPP_DEVICE__H 7 #define _K_PPP_DEVICE__H 8 9 #include <KPPPDefs.h> 10 #include <KPPPLayer.h> 11 12 #ifndef _K_PPP_INTERFACE__H 13 #include <KPPPInterface.h> 14 #endif 15 16 17 class KPPPDevice : public KPPPLayer { 18 friend class KPPPStateMachine; 19 20 protected: 21 // KPPPDevice must be subclassed 22 KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interface, 23 driver_parameter *settings); 24 25 public: 26 virtual ~KPPPDevice(); 27 28 //! Returns the interface that owns this device. 29 KPPPInterface& Interface() const 30 { return fInterface; } 31 //! Returns the device's settings. 32 driver_parameter *Settings() const 33 { return fSettings; } 34 35 virtual status_t Control(uint32 op, void *data, size_t length); 36 37 //! Returns the device's MTU. 38 uint32 MTU() const 39 { return fMTU; } 40 41 /*! \brief This brings the device up. 42 43 ATTENTION: This method must not block! \n 44 Call UpStarted() to check if you are allowed to go down. After UpStarted() 45 is called the connection attempt may be aborted by calling Down(). \n 46 In server mode you should listen for incoming connections. 47 On error: \e Either call \c UpFailedEvent() and return \c true \e or 48 return \c false only. \e Never call \c UpFailedEvent() and return 49 \c false at the same time! 50 51 \sa UpStarted() 52 \sa UpFailedEvent() 53 */ 54 virtual bool Up() = 0; 55 /*! \brief Bring the interface down. 56 57 Call DownStarted() to check if you are allowed to go down. \n 58 The return value of this method is currently ignored. 59 60 \sa DownStarted() 61 */ 62 virtual bool Down() = 0; 63 //! Is the connection established? 64 bool IsUp() const 65 { return fConnectionPhase == PPP_ESTABLISHED_PHASE; } 66 //! Is the interface disconnected and ready to connect? 67 bool IsDown() const 68 { return fConnectionPhase == PPP_DOWN_PHASE; } 69 //! Is the interface connecting at the moment? 70 bool IsGoingUp() const 71 { return fConnectionPhase == PPP_ESTABLISHMENT_PHASE; } 72 //! Is the interface disconnecting at the moment? 73 bool IsGoingDown() const 74 { return fConnectionPhase == PPP_TERMINATION_PHASE; } 75 76 /*! \brief Input speed in bytes per second. 77 78 The biggest of the two tranfer rates will be set in ifnet. \n 79 Should return default value when disconnected. 80 */ 81 virtual uint32 InputTransferRate() const = 0; 82 /*! \brief Output speed in bytes per second. 83 84 The biggest of the two tranfer rates will be set in ifnet. \n 85 Should return default value when disconnected. 86 */ 87 virtual uint32 OutputTransferRate() const = 0; 88 89 //! Number of bytes waiting to be sent (i.e.: waiting in output queue). 90 virtual uint32 CountOutputBytes() const = 0; 91 92 virtual bool IsAllowedToSend() const; 93 94 /*! \brief Sends a packet. 95 96 This should enqueue the packet and return immediately (never block). 97 The device is responsible for freeing the packet by calling \c m_freem(). 98 */ 99 virtual status_t Send(struct mbuf *packet, uint16 protocolNumber) = 0; 100 virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber); 101 102 protected: 103 //! Use this to set the device's maximum transfer unit (in bytes). 104 void SetMTU(uint32 MTU) 105 { fMTU = MTU; } 106 107 bool UpStarted(); 108 bool DownStarted(); 109 110 // report up/down events 111 void UpFailedEvent(); 112 void UpEvent(); 113 void DownEvent(); 114 115 protected: 116 uint32 fMTU; 117 // always hold this value up-to-date! 118 119 private: 120 char *fName; 121 KPPPInterface& fInterface; 122 driver_parameter *fSettings; 123 124 ppp_phase fConnectionPhase; 125 }; 126 127 128 #endif 129