1 /* 2 * Copyright 2003-2005, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _PPP_CONTROL__H 7 #define _PPP_CONTROL__H 8 9 #include <Drivers.h> 10 #include <driver_settings.h> 11 #include <PPPDefs.h> 12 13 14 // various constants 15 #define PPP_HANDLER_NAME_LENGTH_LIMIT 63 16 // if the name is longer than this value it will be truncated to fit the structure 17 18 // starting values and other values for control ops 19 #define PPP_RESERVE_OPS_COUNT 0xFFFF 20 #define PPP_OPS_START B_DEVICE_OP_CODES_END + 1 21 #define PPP_INTERFACE_OPS_START PPP_OPS_START + PPP_RESERVE_OPS_COUNT 22 #define PPP_DEVICE_OPS_START PPP_OPS_START + 2 * PPP_RESERVE_OPS_COUNT 23 #define PPP_PROTOCOL_OPS_START PPP_OPS_START + 3 * PPP_RESERVE_OPS_COUNT 24 #define PPP_OPTION_HANDLER_OPS_START PPP_OPS_START + 5 * PPP_RESERVE_OPS_COUNT 25 #define PPP_LCP_EXTENSION_OPS_START PPP_OPS_START + 6 * PPP_RESERVE_OPS_COUNT 26 #define PPP_COMMON_OPS_START PPP_OPS_START + 10 * PPP_RESERVE_OPS_COUNT 27 #define PPP_USER_OPS_START PPP_OPS_START + 32 * PPP_RESERVE_OPS_COUNT 28 29 30 //! These values should be used for ppp_control_info::op. 31 enum ppp_control_ops { 32 // ----------------------------------------------------- 33 // PPPManager (the PPP interface module) 34 PPPC_CONTROL_MODULE = PPP_OPS_START, 35 PPPC_CREATE_INTERFACE, 36 PPPC_CREATE_INTERFACE_WITH_NAME, 37 PPPC_DELETE_INTERFACE, 38 PPPC_BRING_INTERFACE_UP, 39 PPPC_BRING_INTERFACE_DOWN, 40 PPPC_CONTROL_INTERFACE, 41 PPPC_GET_INTERFACES, 42 PPPC_COUNT_INTERFACES, 43 PPPC_FIND_INTERFACE_WITH_SETTINGS, 44 // ----------------------------------------------------- 45 46 // ----------------------------------------------------- 47 // KPPPInterface 48 PPPC_GET_INTERFACE_INFO = PPP_INTERFACE_OPS_START, 49 PPPC_SET_USERNAME, 50 PPPC_SET_PASSWORD, 51 PPPC_SET_ASK_BEFORE_CONNECTING, 52 // ppp_up uses this in order to finalize a connection request 53 PPPC_SET_MRU, 54 PPPC_SET_CONNECT_ON_DEMAND, 55 PPPC_SET_AUTO_RECONNECT, 56 PPPC_HAS_INTERFACE_SETTINGS, 57 PPPC_GET_STATISTICS, 58 59 // handler access 60 PPPC_CONTROL_DEVICE = PPP_INTERFACE_OPS_START + 0xFF, 61 PPPC_CONTROL_PROTOCOL, 62 PPPC_CONTROL_OPTION_HANDLER, 63 PPPC_CONTROL_LCP_EXTENSION, 64 PPPC_CONTROL_CHILD, 65 // ----------------------------------------------------- 66 67 // ----------------------------------------------------- 68 // KPPPDevice 69 PPPC_GET_DEVICE_INFO = PPP_DEVICE_OPS_START, 70 // ----------------------------------------------------- 71 72 // ----------------------------------------------------- 73 // KPPPProtocol 74 PPPC_GET_PROTOCOL_INFO = PPP_PROTOCOL_OPS_START, 75 // ----------------------------------------------------- 76 77 // ----------------------------------------------------- 78 // Common/mixed ops 79 PPPC_ENABLE, 80 PPPC_GET_SIMPLE_HANDLER_INFO, 81 // KPPPOptionHandler and KPPPLCPExtension 82 83 // these two control ops use the ppp_report_request structure 84 PPPC_ENABLE_REPORTS, 85 PPPC_DISABLE_REPORTS, 86 // flags are not used for this control op 87 // ----------------------------------------------------- 88 89 PPP_CONTROL_OPS_END = B_DEVICE_OP_CODES_END + 0xFFFF 90 }; 91 92 93 //! Basic structure used for creating and searching PPP interfaces. 94 typedef struct ppp_interface_description_info { 95 //! Different values for describing an interface. 96 union { 97 const driver_settings *settings; 98 //!< Interface settings. 99 const char *name; 100 //!< Name of interface description file. 101 } u; 102 ppp_interface_id interface; 103 //!< The id of the found/created interface. 104 } ppp_interface_description_info; 105 106 107 //! Used to get all interface ids from the PPP interface manager. 108 typedef struct ppp_get_interfaces_info { 109 ppp_interface_id *interfaces; 110 //!< The interface ids will be written to this pointer's target. 111 int32 count; 112 //!< The \a interfaces field has enough space for \a count entries. 113 ppp_interface_filter filter; 114 //!< Only interfaces that match this filter will be returned 115 int32 resultCount; 116 //!< The number of entries that the \a interfaces field contains. 117 } ppp_get_interfaces_info; 118 119 120 //! With this structure you can refer to some handler/interface. 121 typedef struct ppp_control_info { 122 uint32 index; 123 //!< Index/id of interface/protocol/etc. 124 uint32 op; 125 //!< The Control()/ioctl() opcode. This can be any value from ppp_control_ops. 126 void *data; 127 //!< Additional data may be specified here. 128 size_t length; 129 //!< The length should always be set. 130 } ppp_control_info; 131 132 133 // ----------------------------------------------------------- 134 // structures for storing information about interface/handlers 135 // use the xxx_info_t structures when allocating memory (they 136 // reserve memory for future implementations) 137 // ----------------------------------------------------------- 138 #define _PPP_INFO_T_SIZE_ 256 139 140 //! Structure used by \c PPPC_GET_INTERFACE_INFO. 141 typedef struct ppp_interface_info { 142 char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 143 int32 if_unit; 144 // negative if not registered 145 146 ppp_mode mode; 147 ppp_state state; 148 ppp_phase phase; 149 ppp_authentication_status localAuthenticationStatus, peerAuthenticationStatus; 150 ppp_pfc_state localPFCState, peerPFCState; 151 uint8 pfcOptions; 152 153 uint32 protocolsCount, optionHandlersCount, LCPExtensionsCount, childrenCount; 154 uint32 MRU, interfaceMTU; 155 156 uint32 connectAttempt, connectRetriesLimit; 157 uint32 connectRetryDelay, reconnectDelay; 158 bigtime_t connectedSince; 159 // undefined if disconnected 160 uint32 idleSince, disconnectAfterIdleSince; 161 162 bool doesConnectOnDemand, doesAutoReconnect, askBeforeConnecting, hasDevice; 163 bool isMultilink, hasParent; 164 } ppp_interface_info; 165 /*! \brief You \e must use this encapsulator instead of \c ppp_interface_info! 166 167 This structure guarantees backwards compatibility. 168 */ 169 typedef struct ppp_interface_info_t { 170 ppp_interface_info info; 171 uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_interface_info)]; 172 } ppp_interface_info_t; 173 174 175 //! Structure used by \c PPPC_GET_STATISTICS. 176 typedef struct ppp_statistics { 177 int64 bytesReceived, packetsReceived; 178 int64 bytesSent, packetsSent; 179 180 // TODO: currently unused 181 int64 errorBytesReceived, errorPacketsReceived; 182 183 // TODO: add compression statistics? 184 int8 _reserved_[80]; 185 } ppp_statistics; 186 187 //! Structure used by \c PPPC_GET_DEVICE_INFO. 188 typedef struct ppp_device_info { 189 char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 190 191 uint32 MTU; 192 uint32 inputTransferRate, outputTransferRate, outputBytesCount; 193 bool isUp; 194 } ppp_device_info; 195 /*! \brief You \e must use this encapsulator instead of \c ppp_device_info! 196 197 This structure guarantees backwards compatibility. 198 */ 199 typedef struct ppp_device_info_t { 200 ppp_device_info info; 201 uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_device_info)]; 202 } ppp_device_info_t; 203 204 205 //! Structure used by \c PPPC_GET_PROTOCOL_INFO. 206 typedef struct ppp_protocol_info { 207 char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 208 char type[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 209 210 ppp_phase activationPhase; 211 int32 addressFamily, flags; 212 ppp_side side; 213 ppp_level level; 214 uint32 overhead; 215 216 ppp_phase connectionPhase; 217 // there are four possible states: 218 // PPP_ESTABLISHED_PHASE - IsUp() == true 219 // PPP_DOWN_PHASE - IsDown() == true 220 // PPP_ESTABLISHMENT_PHASE - IsGoingUp() == true 221 // PPP_TERMINATION_PHASE - IsGoingDown() == true 222 223 uint16 protocolNumber; 224 bool isEnabled; 225 bool isUpRequested; 226 } ppp_protocol_info; 227 /*! \brief You \e must use this encapsulator instead of \c ppp_protocol_info! 228 229 This structure guarantees backwards compatibility. 230 */ 231 typedef struct ppp_protocol_info_t { 232 ppp_protocol_info info; 233 uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_protocol_info)]; 234 } ppp_protocol_info_t; 235 236 237 //! Structure used by \c PPPC_GET_SIMPLE_HANDLER_INFO. 238 typedef struct ppp_simple_handler_info { 239 char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 240 241 bool isEnabled; 242 243 uint8 code; 244 // only KPPPLCPExtension 245 } ppp_simple_handler_info; 246 /*! \brief You \e must use this encapsulator instead of \c ppp_simple_handler_info! 247 248 This structure guarantees backwards compatibility. 249 */ 250 typedef struct ppp_simple_handler_info_t { 251 ppp_simple_handler_info info; 252 uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_simple_handler_info)]; 253 } ppp_simple_handler_info_t; 254 255 256 #endif 257