Splitted implementation into kernel space (K-prefix) and user space headers. The former will become private headers while the latter will be moved into the headers/os/ hierarchie (where exactly is uncertain at the moment).

Added some control/ioctl ops.
Moved KPPPUtils.h to headers.
Limited the name length of each handler to a maximum of 255 characters (not including the zero-byte).
Removed PPP_ACTION from (K)PPPDefs.h.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4502 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald
2003-09-04 19:40:36 +00:00
parent f1e077f831
commit d3b140a64c
17 changed files with 334 additions and 200 deletions
+1 -132
View File
@@ -8,7 +8,7 @@
#ifndef _K_PPP_DEFS__H
#define _K_PPP_DEFS__H
#include <Errors.h>
#include <PPPDefs.h>
typedef uint32 interface_id;
@@ -16,52 +16,6 @@ typedef uint32 interface_id;
// various constants
#define PPP_PULSE_RATE 500000
// settings keys
#define PPP_DISONNECT_AFTER_IDLE_SINCE_KEY "DisonnectAfterIdleSince"
#define PPP_MODE_KEY "Mode"
#define PPP_DIAL_ON_DEMAND_KEY "DialOnDemand"
#define PPP_AUTO_REDIAL_KEY "AutoRedial"
#define PPP_LOAD_MODULE_KEY "LoadModule"
#define PPP_PROTOCOL_KEY "Protocol"
#define PPP_DEVICE_KEY "Device"
#define PPP_AUTHENTICATOR_KEY "Authenticator"
#define PPP_PEER_AUTHENTICATOR_KEY "Peer-Authenticator"
#define PPP_MULTILINK_KEY "Multilink-Protocol"
// settings values
#define PPP_CLIENT_MODE_VALUE "Client"
#define PPP_SERVER_MODE_VALUE "Server"
// path defines
#define PPP_MODULES_PATH "network/ppp-modules"
// built-in protocols
#define PPP_LCP_PROTOCOL 0xC021
#define PPP_ERROR_BASE B_ERRORS_END
// return values for Send()/Receive() methods in addition to B_ERROR and B_OK
// PPP_UNHANDLED is also used by PPPOptionHandler
enum {
// B_ERROR means that the packet is corrupted
// B_OK means the packet was handled correctly
// return values for PPPProtocol and PPPEncapsulator (and PPPOptionHandler)
PPP_UNHANDLED = PPP_ERROR_BASE,
// The packet does not belong to this handler.
// Do not delete the packet when you return this!
// For PPPOptionHandler: the item is unrecognized
// return values of PPPInterface::Receive()
PPP_DISCARDED,
// packet was silently discarded
PPP_REJECTED,
// a protocol-reject
PPP_NO_CONNECTION
// could not send a packet because device is not connected
};
// module key types (used when loading a module)
enum {
@@ -73,91 +27,6 @@ enum {
PPP_MULTILINK_TYPE
};
// protocol and encapsulator flags
enum {
PPP_NO_FLAGS = 0x00,
PPP_ALWAYS_ALLOWED = 0x01,
// protocol may send/receive in PPP_ESTABLISHMENT_PHASE
PPP_NEEDS_DOWN = 0x02,
// protocol needs a Down() in addition to a Reset() to
// terminate the connection properly (losing the connection
// still results in a Reset() only)
PPP_NOT_IMPORTANT = 0x03
// if this protocol fails to go up we do not disconnect
};
// phase when the protocol is brought up
enum PPP_PHASE {
// the following may be used by protocols
PPP_AUTHENTICATION_PHASE = 15,
PPP_NCP_PHASE = 20,
PPP_ESTABLISHED_PHASE = 25,
// only use PPP_ESTABLISHED_PHASE if
// you want to activate this protocol after
// the normal protocols like IP (i.e., IPCP)
// the following must not be used by protocols!
PPP_DOWN_PHASE = 0,
PPP_TERMINATION_PHASE = 1,
// this is the selected phase when we are GOING down
PPP_ESTABLISHMENT_PHASE = 2
// in this phase some protocols (with PPP_ALWAYS_ALLOWED
// flag set) may be used
};
// this defines the order in which the packets get encapsulated
enum PPP_ENCAPSULATION_LEVEL {
PPP_MULTILINK_LEVEL = 0,
PPP_ENCRYPTION_LEVEL = 5,
PPP_COMPRESSION_LEVEL = 10
};
// we can be a ppp client or a ppp server interface
enum PPP_MODE {
PPP_CLIENT_MODE = 0,
PPP_SERVER_MODE
};
// authentication status
enum PPP_AUTHENTICATION_STATUS {
PPP_AUTHENTICATION_FAILED = -1,
PPP_NOT_AUTHENTICATED = 0,
PPP_AUTHENTICATION_SUCCESSFUL = 1,
PPP_AUTHENTICATING = 0xFF
};
// PPP states as defined in RFC 1661
enum PPP_STATE {
PPP_INITIAL_STATE,
PPP_STARTING_STATE,
PPP_CLOSED_STATE,
PPP_STOPPED_STATE,
PPP_CLOSING_STATE,
PPP_STOPPING_STATE,
PPP_REQ_SENT_STATE,
PPP_ACK_RCVD_STATE,
PPP_ACK_SENT_STATE,
PPP_OPENED_STATE
};
// PPP actions as defined in RFC 1661
enum PPP_ACTION {
PPP_ILLEGAL_EVENT_ACTION,
PPP_THIS_LAYER_UP_ACTION,
PPP_THIS_LAYER_DOWN_ACTION,
PPP_THIS_LAYER_STARTED_ACTION,
PPP_THIS_LAYER_FINISHED_ACTION,
PPP_INIT_RESTART_COUNT_ACTION,
PPP_ZERO_RESTART_COUNT_ACTION,
PPP_SEND_CONF_REQ_ACTION,
PPP_SEND_CONF_ACK_ACTION,
PPP_SEND_CONF_NAK_ACTION,
PPP_SEND_TERM_REQ_ACTION,
PPP_SEND_TERM_ACK_ACTION,
PPP_SEND_CODE_REJ_ACTION,
PPP_SEND_ECHO_REPLY_ACTION
};
// PPP events as defined in RFC 1661 (with one exception: PPP_UP_FAILED_EVENT)
enum PPP_EVENT {
PPP_UP_FAILED_EVENT,
+1 -1
View File
@@ -84,7 +84,7 @@ class PPPDevice {
bool fIsUp;
private:
char *fName;
char fName[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
uint32 fOverhead;
PPPInterface *fInterface;
driver_parameter *fSettings;
@@ -104,7 +104,7 @@ class PPPEncapsulator {
uint32 fOverhead;
private:
char *fName;
char fName[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
PPP_PHASE fPhase;
PPP_ENCAPSULATION_LEVEL fLevel;
uint16 fProtocol;
@@ -60,7 +60,7 @@ class PPPOptionHandler {
// notification that we ack these values
private:
char *fName;
char fName[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
PPPInterface *fInterface;
driver_parameter *fSettings;
@@ -80,7 +80,7 @@ class PPPProtocol {
// report up/down events
private:
char *fName;
char fName[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
PPP_PHASE fPhase;
uint16 fProtocol;
int32 fAddressFamily;
@@ -8,56 +8,8 @@
#ifndef _K_PPP_REPORT_DEFS__H
#define _K_PPP_REPORT_DEFS__H
#include <PPPReportDefs.h>
#define PPP_REPORT_DATA_LIMIT 128
// how much optional data can be added to the report
#define PPP_REPORT_CODE '_3PR'
// the code field of read_port
// report flags
enum PPP_REPORT_FLAGS {
PPP_NO_REPORT_FLAGS = 0,
PPP_WAIT_FOR_REPLY = 0x1,
PPP_REMOVE_AFTER_REPORT = 0x2,
PPP_NO_REPLY_TIMEOUT = 0x4
};
// report types
enum PPP_REPORT_TYPE {
PPP_DESTRUCTION_REPORT = 0,
// the interface is being destroyed (no code is needed)
PPP_CONNECTION_REPORT = 1,
PPP_AUTHENTICATION_REPORT = 2
};
// report codes (type-specific)
enum PPP_CONNECTION_REPORT_CODES {
PPP_REPORT_GOING_UP = 0,
PPP_REPORT_UP_SUCCESSFUL = 1,
PPP_REPORT_DOWN_SUCCESSFUL = 2,
PPP_REPORT_UP_ABORTED = 3,
PPP_REPORT_DEVICE_UP_FAILED = 4,
PPP_REPORT_AUTHENTICATION_SUCCESSFUL = 5,
PPP_REPORT_PEER_AUTHENTICATION_SUCCESSFUL = 6,
PPP_REPORT_AUTHENTICATION_FAILED = 7,
PPP_REPORT_CONNECTION_LOST = 8
};
typedef struct ppp_report_packet {
int32 type;
int32 code;
uint8 length;
char data[PPP_REPORT_DATA_LIMIT];
} ppp_report_packet;
//***********
// private
//***********
#define PPP_REPORT_TIMEOUT 10
typedef struct ppp_report_request {
thread_id thread;
+116
View File
@@ -0,0 +1,116 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
//---------------------------------------------------------------------
#ifndef _PPP_CONTROL__H
#define _PPP_CONTROL__H
#include <Drivers.h>
#include <PPPDefs.h>
// starting values and other values for control ops
#define PPP_RESERVE_OPS_COUNT 0xFFFF
#define PPP_OPS_START B_DEVICE_OP_CODES_END + 1
#define PPP_DEVICE_OPS_START PPP_OPS_START + 2 * PPP_RESERVE_OPS_COUNT
#define PPP_PROTOCOL_OPS_START PPP_OPS_START + 3 * PPP_RESERVE_OPS_COUNT
#define PPP_ENCAPSULATOR_OPS_START PPP_OPS_START + 4 * PPP_RESERVE_OPS_COUNT
#define PPP_OPTION_HANDLER_OPS_START PPP_OPS_START + 5 * PPP_RESERVE_OPS_COUNT
#define PPP_LCP_EXTENSION_OPS_START PPP_OPS_START + 6 * PPP_RESERVE_OPS_COUNT
#define PPP_COMMON_PROTO_ENCAPS_OPS_START PPP_OPS_START + 10 * PPP_RESERVE_OPS_COUNT
#define PPP_USER_OPS_START PPP_OPS_START + 32 * PPP_RESERVE_OPS_COUNT
enum PPP_CONTROL_OPS {
// -----------------------------------------------------
// PPPInterface
PPPC_GET_STATUS = PPP_OPS_START,
PPPC_GET_MRU,
PPPC_SET_MRU,
PPPC_GET_LINK_MTU,
PPPC_SET_LINK_MTU,
PPPC_GET_DIAL_ON_DEMAND,
PPPC_SET_DIAL_ON_DEMAND,
PPPC_GET_AUTO_REDIAL,
PPPC_SET_AUTO_REDIAL,
PPPC_GET_PROTOCOLS_COUNT,
PPPC_GET_ENCAPSULATORS_COUNT,
PPPC_GET_OPTION_HANDLERS_COUNT,
PPPC_GET_LCP_EXTENSIONS_COUNT,
PPPC_GET_CHILDREN_COUNT,
PPPC_CONTROL_PROTOCOL,
PPPC_CONTROL_ENCAPSULATOR,
PPPC_CONTROL_OPTION_HANDLER,
PPPC_CONTROL_LCP_EXTENSION,
PPPC_CONTROL_CHILD,
// -----------------------------------------------------
// -----------------------------------------------------
// PPPDevice
PPPC_GET_MTU = PPP_DEVICE_OPS_START,
PPPC_SET_MTU,
PPPC_GET_PREFERRED_MTU,
// -----------------------------------------------------
// -----------------------------------------------------
// PPPProtocol
// -----------------------------------------------------
// -----------------------------------------------------
// PPPEncapsulator
// -----------------------------------------------------
// -----------------------------------------------------
// PPPOptionHandler
// -----------------------------------------------------
// -----------------------------------------------------
// PPPLCPExtension
// -----------------------------------------------------
// -----------------------------------------------------
// PPPProtocol and PPPEncapsulator
PPPC_GET_NAME,
PPPC_GET_ENABLED = PPP_COMMON_PROTO_ENCAPS_OPS_START,
PPPC_SET_ENABLED,
// -----------------------------------------------------
PPP_CONTROL_OPS_END = B_DEVICE_OP_CODES_END + 0xFFFF
};
typedef struct ppp_control_structure {
uint32 index;
// index of interface/protocol/encapsulator/etc.
uint32 op;
// the Control()/ioctl() opcode
union {
void *data;
ppp_control_struct *subcontrol;
} pointer;
// either a pointer to the data or a pointer to a control structure for
// accessing protocols/encapsulators/etc.
size_t length;
// not always needed
} ppp_control_structure;
typedef struct ppp_status_structure {
PPP_MODE mode;
PPP_STATE state;
PPP_PHASE phase;
PPP_AUTHENTICATION_STATUS authenticationStatus, peerAuthenticationStatus;
bigtime_t idle_since;
uint8 _reserved_[64 - (sizeof(PPP_MODE) + sizeof(PPP_STATE) + sizeof(PPP_PHASE)
+ 2 * sizeof(PPP_AUTHENTICATION_STATUS) + sizeof(bigtime_t))];
} ppp_status_structure;
#endif
+132
View File
@@ -0,0 +1,132 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
//---------------------------------------------------------------------
#ifndef _PPP_DEFS__H
#define _PPP_DEFS__H
#include <Errors.h>
// various constants
#define PPP_HANDLER_NAME_LENGTH_LIMIT 255
// if the name is longer than this value it will be truncated
// settings keys
#define PPP_DISONNECT_AFTER_IDLE_SINCE_KEY "DisonnectAfterIdleSince"
#define PPP_MODE_KEY "Mode"
#define PPP_DIAL_ON_DEMAND_KEY "DialOnDemand"
#define PPP_AUTO_REDIAL_KEY "AutoRedial"
#define PPP_LOAD_MODULE_KEY "LoadModule"
#define PPP_PROTOCOL_KEY "Protocol"
#define PPP_DEVICE_KEY "Device"
#define PPP_AUTHENTICATOR_KEY "Authenticator"
#define PPP_PEER_AUTHENTICATOR_KEY "Peer-Authenticator"
#define PPP_MULTILINK_KEY "Multilink-Protocol"
// settings values
#define PPP_CLIENT_MODE_VALUE "Client"
#define PPP_SERVER_MODE_VALUE "Server"
// path defines
#define PPP_MODULES_PATH "network/ppp-modules"
// built-in protocols
#define PPP_LCP_PROTOCOL 0xC021
#define PPP_ERROR_BASE B_ERRORS_END + 1
// return values for Send()/Receive() methods in addition to B_ERROR and B_OK
// PPP_UNHANDLED is also used by PPPOptionHandler
enum {
// B_ERROR means that the packet is corrupted
// B_OK means the packet was handled correctly
// return values for PPPProtocol and PPPEncapsulator (and PPPOptionHandler)
PPP_UNHANDLED = PPP_ERROR_BASE,
// The packet does not belong to this handler.
// Do not delete the packet when you return this!
// For PPPOptionHandler: the item is unrecognized
// return values of PPPInterface::Receive()
PPP_DISCARDED,
// packet was silently discarded
PPP_REJECTED,
// a protocol-reject
PPP_NO_CONNECTION
// could not send a packet because device is not connected
};
// protocol and encapsulator flags
enum {
PPP_NO_FLAGS = 0x00,
PPP_ALWAYS_ALLOWED = 0x01,
// protocol may send/receive in PPP_ESTABLISHMENT_PHASE
PPP_NEEDS_DOWN = 0x02,
// protocol needs a Down() in addition to a Reset() to
// terminate the connection properly (losing the connection
// still results in a Reset() only)
PPP_NOT_IMPORTANT = 0x03
// if this protocol fails to go up we do not disconnect
};
// phase when the protocol is brought up
enum PPP_PHASE {
// the following may be used by protocols
PPP_AUTHENTICATION_PHASE = 15,
PPP_NCP_PHASE = 20,
PPP_ESTABLISHED_PHASE = 25,
// only use PPP_ESTABLISHED_PHASE if
// you want to activate this protocol after
// the normal protocols like IP (i.e., IPCP)
// the following must not be used by protocols!
PPP_DOWN_PHASE = 0,
PPP_TERMINATION_PHASE = 1,
// this is the selected phase when we are GOING down
PPP_ESTABLISHMENT_PHASE = 2
// in this phase some protocols (with PPP_ALWAYS_ALLOWED
// flag set) may be used
};
// this defines the order in which the packets get encapsulated
enum PPP_ENCAPSULATION_LEVEL {
PPP_MULTILINK_LEVEL = 0,
PPP_ENCRYPTION_LEVEL = 5,
PPP_COMPRESSION_LEVEL = 10
};
// we can be a ppp client or a ppp server interface
enum PPP_MODE {
PPP_CLIENT_MODE = 0,
PPP_SERVER_MODE
};
// authentication status
enum PPP_AUTHENTICATION_STATUS {
PPP_AUTHENTICATION_FAILED = -1,
PPP_NOT_AUTHENTICATED = 0,
PPP_AUTHENTICATION_SUCCESSFUL = 1,
PPP_AUTHENTICATING = 0xFF
};
// PPP states as defined in RFC 1661
enum PPP_STATE {
PPP_INITIAL_STATE,
PPP_STARTING_STATE,
PPP_CLOSED_STATE,
PPP_STOPPED_STATE,
PPP_CLOSING_STATE,
PPP_STOPPING_STATE,
PPP_REQ_SENT_STATE,
PPP_ACK_RCVD_STATE,
PPP_ACK_SENT_STATE,
PPP_OPENED_STATE
};
#endif
@@ -0,0 +1,57 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
//---------------------------------------------------------------------
#ifndef _PPP_REPORT_DEFS__H
#define _PPP_REPORT_DEFS__H
#define PPP_REPORT_TIMEOUT 10
#define PPP_REPORT_DATA_LIMIT 128
// how much optional data can be added to the report
#define PPP_REPORT_CODE '_3PR'
// the code of receive_data() must have this value
// report flags
enum PPP_REPORT_FLAGS {
PPP_NO_REPORT_FLAGS = 0,
PPP_WAIT_FOR_REPLY = 0x1,
PPP_REMOVE_AFTER_REPORT = 0x2,
PPP_NO_REPLY_TIMEOUT = 0x4
};
// report types
enum PPP_REPORT_TYPE {
PPP_DESTRUCTION_REPORT = 0,
// the interface is being destroyed (no code is needed)
PPP_CONNECTION_REPORT = 1,
PPP_AUTHENTICATION_REPORT = 2
};
// report codes (type-specific)
enum PPP_CONNECTION_REPORT_CODES {
PPP_REPORT_GOING_UP = 0,
PPP_REPORT_UP_SUCCESSFUL = 1,
PPP_REPORT_DOWN_SUCCESSFUL = 2,
PPP_REPORT_UP_ABORTED = 3,
PPP_REPORT_DEVICE_UP_FAILED = 4,
PPP_REPORT_AUTHENTICATION_SUCCESSFUL = 5,
PPP_REPORT_PEER_AUTHENTICATION_SUCCESSFUL = 6,
PPP_REPORT_AUTHENTICATION_FAILED = 7,
PPP_REPORT_CONNECTION_LOST = 8
};
typedef struct ppp_report_packet {
int32 type;
int32 code;
uint8 length;
char data[PPP_REPORT_DATA_LIMIT];
} ppp_report_packet;
#endif
+5 -3
View File
@@ -16,7 +16,11 @@ PPPDevice::PPPDevice(const char *name, uint32 overhead, PPPInterface *interface,
: fOverhead(overhead), fInterface(interface),
fSettings(settings)
{
fName = name ? strdup(name) : NULL;
if(name) {
strncpy(fName, name, PPP_HANDLER_NAME_LENGTH_LIMIT);
fName[PPP_HANDLER_NAME_LENGTH_LIMIT] = 0;
} else
strcpy(fName, "");
SetMTU(1500);
@@ -27,8 +31,6 @@ PPPDevice::PPPDevice(const char *name, uint32 overhead, PPPInterface *interface,
PPPDevice::~PPPDevice()
{
free(fName);
if(Interface())
Interface()->SetDevice(NULL);
}
@@ -18,7 +18,11 @@ PPPEncapsulator::PPPEncapsulator(const char *name, PPP_PHASE phase,
fSettings(settings), fFlags(flags), fEnabled(true),
fUpRequested(true), fConnectionStatus(PPP_DOWN_PHASE)
{
fName = name ? strdup(name) : NULL;
if(name) {
strncpy(fName, name, PPP_HANDLER_NAME_LENGTH_LIMIT);
fName[PPP_HANDLER_NAME_LENGTH_LIMIT] = 0;
} else
strcpy(fName, "");
if(interface)
interface->AddEncapsulator(this);
@@ -27,8 +31,6 @@ PPPEncapsulator::PPPEncapsulator(const char *name, PPP_PHASE phase,
PPPEncapsulator::~PPPEncapsulator()
{
free(fName);
if(Interface())
Interface()->RemoveEncapsulator(this);
}
+1 -1
View File
@@ -20,12 +20,12 @@
#include <KPPPEncapsulator.h>
#include <KPPPModule.h>
#include <KPPPManager.h>
#include <KPPPUtils.h>
// general helper classes not only belonging to us
#include <LockerHelper.h>
// tools only for us :)
#include "KPPPUtils.h"
#include "settings_tools.h"
@@ -12,7 +12,11 @@ PPPOptionHandler::PPPOptionHandler(const char *name, PPPInterface *interface,
driver_parameter *settings)
: fInterface(interface), fSettings(settings)
{
fName = name ? strdup(name) : NULL;
if(name) {
strncpy(fName, name, PPP_HANDLER_NAME_LENGTH_LIMIT);
fName[PPP_HANDLER_NAME_LENGTH_LIMIT] = 0;
} else
strcpy(fName, "");
if(interface)
interface->LCP().AddOptionHandler(this);
@@ -21,8 +25,6 @@ PPPOptionHandler::PPPOptionHandler(const char *name, PPPInterface *interface,
PPPOptionHandler::~PPPOptionHandler()
{
free(fName);
if(Interface())
Interface()->LCP().RemoveOptionHandler(this);
}
+5 -3
View File
@@ -17,7 +17,11 @@ PPPProtocol::PPPProtocol(const char *name, PPP_PHASE phase, uint16 protocol,
fInterface(interface), fSettings(settings), fFlags(flags),
fEnabled(true), fUpRequested(true), fConnectionStatus(PPP_DOWN_PHASE)
{
fName = name ? strdup(name) : NULL;
if(name) {
strncpy(fName, name, PPP_HANDLER_NAME_LENGTH_LIMIT);
fName[PPP_HANDLER_NAME_LENGTH_LIMIT] = 0;
} else
strcpy(fName, "");
if(interface)
interface->AddProtocol(this);
@@ -26,8 +30,6 @@ PPPProtocol::PPPProtocol(const char *name, PPP_PHASE phase, uint16 protocol,
PPPProtocol::~PPPProtocol()
{
free(fName);
if(Interface())
Interface()->RemoveProtocol(this);
}
@@ -8,7 +8,7 @@
#include <KPPPReportManager.h>
#include <LockerHelper.h>
#include "KPPPUtils.h"
#include <KPPPUtils.h>
#include <new.h>
+1 -1
View File
@@ -7,7 +7,7 @@
#include <OS.h>
#include "KPPPUtils.h"
#include <KPPPUtils.h>
// These are very simple send/receive_data functions with a timeout