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 #define IF_NAMESIZE 32 15 // copied from if.h 16 17 struct control_net_module_args { 18 char ifr_name[IF_NAMESIZE]; 19 const char* name; 20 uint32 op; 21 void* data; 22 size_t length; 23 // union { 24 // struct sockaddr ifr_addr; 25 // struct sockaddr ifr_dstaddr; 26 // struct sockaddr ifr_broadaddr; 27 // struct sockaddr ifr_mask; 28 // struct ifreq_stats ifr_stats; 29 // struct route_entry ifr_route; 30 // int ifr_flags; 31 // int ifr_index; 32 // int ifr_metric; 33 // int ifr_mtu; 34 // int ifr_media; 35 // int ifr_type; 36 // int ifr_reqcap; 37 // int ifr_count; 38 // uint8_t* ifr_data; 39 // }; 40 }; 41 // copied from libppp 42 43 44 enum { 45 // Paranoia mode: be far away of B_DEVICE_OP_CODES_END opcodes!!! 46 // You never know what another device driver ioctl() will do 47 // if think our NET_STACK_* is in fact his DO_RISKY_BUSINESS opcode, or whatever... 48 NET_IOCTL_BASE = 0xbe230000, 49 NET_STACK_IOCTL_BASE = NET_IOCTL_BASE + 0x200 50 }; 51 52 enum { 53 NET_STACK_SOCKET = NET_STACK_IOCTL_BASE, // socket_args * 54 NET_STACK_BIND, // sockaddr_args * 55 NET_STACK_RECVFROM, // struct msghdr * 56 NET_STACK_RECV, // transfer_args * 57 NET_STACK_SENDTO, // struct msghdr * 58 NET_STACK_SEND, // transfer_args * 59 NET_STACK_LISTEN, // int_args * (value = backlog) 60 NET_STACK_ACCEPT, // sockaddr_args * 61 NET_STACK_CONNECT, // sockaddr_args * 62 NET_STACK_SHUTDOWN, // int_args * (value = how) 63 NET_STACK_GETSOCKOPT, // sockopt_args * 64 NET_STACK_SETSOCKOPT, // sockopt_args * 65 NET_STACK_GETSOCKNAME, // sockaddr_args * 66 NET_STACK_GETPEERNAME, // sockaddr_args * 67 68 NET_STACK_SYSCTL, // sysctl_args * 69 NET_STACK_SELECT, // select_args * 70 NET_STACK_DESELECT, // select_args * 71 72 NET_STACK_GET_COOKIE, // void ** 73 74 NET_STACK_STOP, 75 76 NET_STACK_NOTIFY_SOCKET_EVENT, // notify_socket_event_args * (userland stack only) 77 78 NET_STACK_CONTROL_NET_MODULE, 79 80 NET_STACK_IOCTL_MAX 81 }; 82 83 84 // various constants 85 #define PPP_HANDLER_NAME_LENGTH_LIMIT 63 86 // if the name is longer than this value it will be truncated to fit the structure 87 88 // starting values and other values for control ops 89 #define PPP_RESERVE_OPS_COUNT 0xFFFF 90 #define PPP_OPS_START B_DEVICE_OP_CODES_END + 1 91 #define PPP_INTERFACE_OPS_START PPP_OPS_START + PPP_RESERVE_OPS_COUNT 92 #define PPP_DEVICE_OPS_START PPP_OPS_START + 2 * PPP_RESERVE_OPS_COUNT 93 #define PPP_PROTOCOL_OPS_START PPP_OPS_START + 3 * PPP_RESERVE_OPS_COUNT 94 #define PPP_OPTION_HANDLER_OPS_START PPP_OPS_START + 5 * PPP_RESERVE_OPS_COUNT 95 #define PPP_LCP_EXTENSION_OPS_START PPP_OPS_START + 6 * PPP_RESERVE_OPS_COUNT 96 #define PPP_COMMON_OPS_START PPP_OPS_START + 10 * PPP_RESERVE_OPS_COUNT 97 #define PPP_USER_OPS_START PPP_OPS_START + 32 * PPP_RESERVE_OPS_COUNT 98 99 100 //! These values should be used for ppp_control_info::op. 101 enum ppp_control_ops { 102 // ----------------------------------------------------- 103 // PPPManager (the PPP interface module) 104 PPPC_CONTROL_MODULE = PPP_OPS_START, 105 PPPC_CREATE_INTERFACE, 106 PPPC_CREATE_INTERFACE_WITH_NAME, 107 PPPC_DELETE_INTERFACE, 108 PPPC_BRING_INTERFACE_UP, 109 PPPC_BRING_INTERFACE_DOWN, 110 PPPC_CONTROL_INTERFACE, 111 PPPC_GET_INTERFACES, 112 PPPC_COUNT_INTERFACES, 113 PPPC_FIND_INTERFACE_WITH_SETTINGS, 114 // ----------------------------------------------------- 115 116 // ----------------------------------------------------- 117 // KPPPInterface 118 PPPC_GET_INTERFACE_INFO = PPP_INTERFACE_OPS_START, 119 PPPC_SET_USERNAME, 120 PPPC_SET_PASSWORD, 121 PPPC_SET_ASK_BEFORE_CONNECTING, 122 // ppp_up uses this in order to finalize a connection request 123 PPPC_SET_MRU, 124 PPPC_SET_CONNECT_ON_DEMAND, 125 PPPC_SET_AUTO_RECONNECT, 126 PPPC_HAS_INTERFACE_SETTINGS, 127 PPPC_GET_STATISTICS, 128 129 // handler access 130 PPPC_CONTROL_DEVICE = PPP_INTERFACE_OPS_START + 0xFF, 131 PPPC_CONTROL_PROTOCOL, 132 PPPC_CONTROL_OPTION_HANDLER, 133 PPPC_CONTROL_LCP_EXTENSION, 134 PPPC_CONTROL_CHILD, 135 // ----------------------------------------------------- 136 137 // ----------------------------------------------------- 138 // KPPPDevice 139 PPPC_GET_DEVICE_INFO = PPP_DEVICE_OPS_START, 140 // ----------------------------------------------------- 141 142 // ----------------------------------------------------- 143 // KPPPProtocol 144 PPPC_GET_PROTOCOL_INFO = PPP_PROTOCOL_OPS_START, 145 // ----------------------------------------------------- 146 147 // ----------------------------------------------------- 148 // Common/mixed ops 149 PPPC_ENABLE, 150 PPPC_GET_SIMPLE_HANDLER_INFO, 151 // KPPPOptionHandler and KPPPLCPExtension 152 153 // these two control ops use the ppp_report_request structure 154 PPPC_ENABLE_REPORTS, 155 PPPC_DISABLE_REPORTS, 156 // flags are not used for this control op 157 // ----------------------------------------------------- 158 159 PPP_CONTROL_OPS_END = B_DEVICE_OP_CODES_END + 0xFFFF 160 }; 161 162 163 //! Basic structure used for creating and searching PPP interfaces. 164 typedef struct ppp_interface_description_info { 165 //! Different values for describing an interface. 166 union { 167 const driver_settings *settings; 168 //!< Interface settings. 169 const char *name; 170 //!< Name of interface description file. 171 } u; 172 ppp_interface_id interface; 173 //!< The id of the found/created interface. 174 } ppp_interface_description_info; 175 176 177 //! Used to get all interface ids from the PPP interface manager. 178 typedef struct ppp_get_interfaces_info { 179 ppp_interface_id *interfaces; 180 //!< The interface ids will be written to this pointer's target. 181 int32 count; 182 //!< The \a interfaces field has enough space for \a count entries. 183 ppp_interface_filter filter; 184 //!< Only interfaces that match this filter will be returned 185 int32 resultCount; 186 //!< The number of entries that the \a interfaces field contains. 187 } ppp_get_interfaces_info; 188 189 190 //! With this structure you can refer to some handler/interface. 191 typedef struct ppp_control_info { 192 uint32 index; 193 //!< Index/id of interface/protocol/etc. 194 uint32 op; 195 //!< The Control()/ioctl() opcode. This can be any value from ppp_control_ops. 196 void *data; 197 //!< Additional data may be specified here. 198 size_t length; 199 //!< The length should always be set. 200 } ppp_control_info; 201 202 203 // ----------------------------------------------------------- 204 // structures for storing information about interface/handlers 205 // use the xxx_info_t structures when allocating memory (they 206 // reserve memory for future implementations) 207 // ----------------------------------------------------------- 208 #define _PPP_INFO_T_SIZE_ 256 209 210 //! Structure used by \c PPPC_GET_INTERFACE_INFO. 211 typedef struct ppp_interface_info { 212 char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 213 int32 if_unit; 214 // negative if not registered 215 216 ppp_mode mode; 217 ppp_state state; 218 ppp_phase phase; 219 ppp_authentication_status localAuthenticationStatus, peerAuthenticationStatus; 220 ppp_pfc_state localPFCState, peerPFCState; 221 uint8 pfcOptions; 222 223 uint32 protocolsCount, optionHandlersCount, LCPExtensionsCount, childrenCount; 224 uint32 MRU, interfaceMTU; 225 226 uint32 connectAttempt, connectRetriesLimit; 227 uint32 connectRetryDelay, reconnectDelay; 228 bigtime_t connectedSince; 229 // undefined if disconnected 230 uint32 idleSince, disconnectAfterIdleSince; 231 232 bool doesConnectOnDemand, doesAutoReconnect, askBeforeConnecting, hasDevice; 233 bool isMultilink, hasParent; 234 } ppp_interface_info; 235 /*! \brief You \e must use this encapsulator instead of \c ppp_interface_info! 236 237 This structure guarantees backwards compatibility. 238 */ 239 typedef struct ppp_interface_info_t { 240 ppp_interface_info info; 241 uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_interface_info)]; 242 } ppp_interface_info_t; 243 244 245 //! Structure used by \c PPPC_GET_STATISTICS. 246 typedef struct ppp_statistics { 247 int64 bytesReceived, packetsReceived; 248 int64 bytesSent, packetsSent; 249 250 // TODO: currently unused 251 int64 errorBytesReceived, errorPacketsReceived; 252 253 // TODO: add compression statistics? 254 int8 _reserved_[80]; 255 } ppp_statistics; 256 257 //! Structure used by \c PPPC_GET_DEVICE_INFO. 258 typedef struct ppp_device_info { 259 char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 260 261 uint32 MTU; 262 uint32 inputTransferRate, outputTransferRate, outputBytesCount; 263 bool isUp; 264 } ppp_device_info; 265 /*! \brief You \e must use this encapsulator instead of \c ppp_device_info! 266 267 This structure guarantees backwards compatibility. 268 */ 269 typedef struct ppp_device_info_t { 270 ppp_device_info info; 271 uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_device_info)]; 272 } ppp_device_info_t; 273 274 275 //! Structure used by \c PPPC_GET_PROTOCOL_INFO. 276 typedef struct ppp_protocol_info { 277 char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 278 char type[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 279 280 ppp_phase activationPhase; 281 int32 addressFamily, flags; 282 ppp_side side; 283 ppp_level level; 284 uint32 overhead; 285 286 ppp_phase connectionPhase; 287 // there are four possible states: 288 // PPP_ESTABLISHED_PHASE - IsUp() == true 289 // PPP_DOWN_PHASE - IsDown() == true 290 // PPP_ESTABLISHMENT_PHASE - IsGoingUp() == true 291 // PPP_TERMINATION_PHASE - IsGoingDown() == true 292 293 uint16 protocolNumber; 294 bool isEnabled; 295 bool isUpRequested; 296 } ppp_protocol_info; 297 /*! \brief You \e must use this encapsulator instead of \c ppp_protocol_info! 298 299 This structure guarantees backwards compatibility. 300 */ 301 typedef struct ppp_protocol_info_t { 302 ppp_protocol_info info; 303 uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_protocol_info)]; 304 } ppp_protocol_info_t; 305 306 307 //! Structure used by \c PPPC_GET_SIMPLE_HANDLER_INFO. 308 typedef struct ppp_simple_handler_info { 309 char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; 310 311 bool isEnabled; 312 313 uint8 code; 314 // only KPPPLCPExtension 315 } ppp_simple_handler_info; 316 /*! \brief You \e must use this encapsulator instead of \c ppp_simple_handler_info! 317 318 This structure guarantees backwards compatibility. 319 */ 320 typedef struct ppp_simple_handler_info_t { 321 ppp_simple_handler_info info; 322 uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_simple_handler_info)]; 323 } ppp_simple_handler_info_t; 324 325 326 #endif 327