Added *many* Doxygen comments. More will follow. Documentation is no fun at all, really.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7617 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f5be30013c
commit
13013331d0
@ -5,12 +5,22 @@
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*! \class KPPPConfigurePacket
|
||||
\brief Helper class for LCP configure packets.
|
||||
|
||||
This class allows iterating over configure items and adding/removing items.
|
||||
*/
|
||||
|
||||
#include <KPPPConfigurePacket.h>
|
||||
#include <KPPPInterface.h>
|
||||
|
||||
#include <core_funcs.h>
|
||||
|
||||
|
||||
/*! \brief Constructor.
|
||||
|
||||
\param code The code value (e.g.: PPP_CONFIGURE_REQUEST) of this packet.
|
||||
*/
|
||||
KPPPConfigurePacket::KPPPConfigurePacket(uint8 code)
|
||||
: fCode(code),
|
||||
fID(0)
|
||||
@ -18,6 +28,7 @@ KPPPConfigurePacket::KPPPConfigurePacket(uint8 code)
|
||||
}
|
||||
|
||||
|
||||
//! Decodes a packet and adds its items to this object.
|
||||
KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)
|
||||
{
|
||||
// decode packet
|
||||
@ -48,6 +59,7 @@ KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)
|
||||
}
|
||||
|
||||
|
||||
//! Frees all items.
|
||||
KPPPConfigurePacket::~KPPPConfigurePacket()
|
||||
{
|
||||
for(int32 index = 0; index < CountItems(); index++)
|
||||
@ -55,6 +67,7 @@ KPPPConfigurePacket::~KPPPConfigurePacket()
|
||||
}
|
||||
|
||||
|
||||
//! Sets the packet's code value (e.g.: PPP_CONFIGURE_REQUEST).
|
||||
bool
|
||||
KPPPConfigurePacket::SetCode(uint8 code)
|
||||
{
|
||||
@ -68,6 +81,18 @@ KPPPConfigurePacket::SetCode(uint8 code)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Adds a new configure item to this packet.
|
||||
|
||||
Make sure all values are correct because the item will be copied. If the item's
|
||||
length field is incorrect you will get bad results.
|
||||
|
||||
\param item The item.
|
||||
\param index Item's index. Adds after the last item if not specified or negative.
|
||||
|
||||
\return \c true if successful, \c false otherwise.
|
||||
|
||||
\sa ppp_configure_item
|
||||
*/
|
||||
bool
|
||||
KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index = -1)
|
||||
{
|
||||
@ -91,6 +116,7 @@ KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index = -1)
|
||||
}
|
||||
|
||||
|
||||
//! Removes an item. The item \e must belong to this packet.
|
||||
bool
|
||||
KPPPConfigurePacket::RemoveItem(ppp_configure_item *item)
|
||||
{
|
||||
@ -104,6 +130,7 @@ KPPPConfigurePacket::RemoveItem(ppp_configure_item *item)
|
||||
}
|
||||
|
||||
|
||||
//! Returns the item at \a index or \c NULL.
|
||||
ppp_configure_item*
|
||||
KPPPConfigurePacket::ItemAt(int32 index) const
|
||||
{
|
||||
@ -116,6 +143,7 @@ KPPPConfigurePacket::ItemAt(int32 index) const
|
||||
}
|
||||
|
||||
|
||||
//! Returns the item of a special \a type or \c NULL.
|
||||
ppp_configure_item*
|
||||
KPPPConfigurePacket::ItemWithType(uint8 type) const
|
||||
{
|
||||
@ -131,6 +159,15 @@ KPPPConfigurePacket::ItemWithType(uint8 type) const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Converts this packet into an mbuf structure.
|
||||
|
||||
ATTENTION: You are responsible for freeing this packet by calling \c m_freem()!
|
||||
|
||||
\param MRU The interface's maximum receive unit (MRU).
|
||||
\param reserve Number of bytes to reserve at the beginning of the packet.
|
||||
|
||||
\return The mbuf structure or \c NULL on error (e.g.: too big for given MRU).
|
||||
*/
|
||||
struct mbuf*
|
||||
KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve = 0)
|
||||
{
|
||||
|
@ -5,6 +5,14 @@
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*! \class KPPPDevice
|
||||
\brief Represents a device at the lowest level of the communcation stack.
|
||||
|
||||
A device may be, for example: Modem, PPPoE, PPTP.\n
|
||||
It encapsulates the packet and sends it over a line to the other end.
|
||||
The device is the first layer that receives a packet.
|
||||
*/
|
||||
|
||||
#include <KPPPDevice.h>
|
||||
|
||||
#include <net/if.h>
|
||||
@ -13,6 +21,13 @@
|
||||
#include <PPPControl.h>
|
||||
|
||||
|
||||
/*! \brief Initializes the device.
|
||||
|
||||
\param name The device's type name (e.g.: PPPoE).
|
||||
\param overhead Length of the header that is prepended to each packet.
|
||||
\param interface Owning interface.
|
||||
\param settings Device's settings.
|
||||
*/
|
||||
KPPPDevice::KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interface,
|
||||
driver_parameter *settings)
|
||||
: KPPPLayer(name, PPP_DEVICE_LEVEL, overhead),
|
||||
@ -24,6 +39,7 @@ KPPPDevice::KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interfa
|
||||
}
|
||||
|
||||
|
||||
//! Destructor. Removes device from interface.
|
||||
KPPPDevice::~KPPPDevice()
|
||||
{
|
||||
if(Interface().Device() == this)
|
||||
@ -31,6 +47,10 @@ KPPPDevice::~KPPPDevice()
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Allows private extensions.
|
||||
|
||||
If you override this method you must call the parent's method for unknown ops.
|
||||
*/
|
||||
status_t
|
||||
KPPPDevice::Control(uint32 op, void *data, size_t length)
|
||||
{
|
||||
@ -58,6 +78,7 @@ KPPPDevice::Control(uint32 op, void *data, size_t length)
|
||||
}
|
||||
|
||||
|
||||
//! Returns \c true (indicates to KPPPInterface we are always allowed to send).
|
||||
bool
|
||||
KPPPDevice::IsAllowedToSend() const
|
||||
{
|
||||
@ -66,6 +87,7 @@ KPPPDevice::IsAllowedToSend() const
|
||||
}
|
||||
|
||||
|
||||
//! This method is never used.
|
||||
status_t
|
||||
KPPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber)
|
||||
{
|
||||
@ -77,13 +99,15 @@ KPPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KPPPDevice::Pulse()
|
||||
{
|
||||
// do nothing by default
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Report that device is going up.
|
||||
|
||||
Called by Up().\n
|
||||
From now on, the connection attempt can may be aborted by calling Down().
|
||||
|
||||
\return
|
||||
- \c true: You are allowed to connect.
|
||||
- \c false: You should abort immediately. Down() will \e not be called!
|
||||
*/
|
||||
bool
|
||||
KPPPDevice::UpStarted()
|
||||
{
|
||||
@ -93,6 +117,14 @@ KPPPDevice::UpStarted()
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Report that device is going down.
|
||||
|
||||
Called by Down().
|
||||
|
||||
\return
|
||||
- \c true: You are allowed to disconnect.
|
||||
- \c false: You must not disconnect!
|
||||
*/
|
||||
bool
|
||||
KPPPDevice::DownStarted()
|
||||
{
|
||||
@ -102,6 +134,7 @@ KPPPDevice::DownStarted()
|
||||
}
|
||||
|
||||
|
||||
//! Reports that device failed going up. May only be called after Up() was called.
|
||||
void
|
||||
KPPPDevice::UpFailedEvent()
|
||||
{
|
||||
@ -111,6 +144,7 @@ KPPPDevice::UpFailedEvent()
|
||||
}
|
||||
|
||||
|
||||
//! Reports that device went up. May only be called after Up() was called.
|
||||
void
|
||||
KPPPDevice::UpEvent()
|
||||
{
|
||||
@ -120,6 +154,7 @@ KPPPDevice::UpEvent()
|
||||
}
|
||||
|
||||
|
||||
//! Reports that device went down. This may be called to indicate connection loss.
|
||||
void
|
||||
KPPPDevice::DownEvent()
|
||||
{
|
||||
|
@ -5,6 +5,21 @@
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*! \class KPPPInterface
|
||||
\brief The kernel representation of a PPP interface.
|
||||
|
||||
This class is never created by the programmer directly. Instead, the PPP manager
|
||||
kernel module should be used.\n
|
||||
KPPPInterface handles all interface-specific commands from userspace and it
|
||||
passes packets to their receiver or sends them to the device. Additionally,
|
||||
it contains the KPPPLCP object with represents the LCP protocol and the
|
||||
KPPPStateMachine object which represents the state machine.\n
|
||||
All PPP modules are loaded from here.\n
|
||||
Protocols and encapsulators should be added to this class. LCP-specific extensions
|
||||
belong to the KPPPLCP object.\n
|
||||
Multilink support is distributed between KPPPInterface and KPPPStateMachine.
|
||||
*/
|
||||
|
||||
// cstdio must be included before KPPPModule.h/KPPPManager.h because
|
||||
// ddprintf is defined twice with different return values, once with
|
||||
// void (KernelExport.h) and once with int (stdio.h).
|
||||
@ -57,6 +72,17 @@ status_t call_open_event_thread(void *data);
|
||||
status_t call_close_event_thread(void *data);
|
||||
|
||||
|
||||
/*! \brief Creates a new interface.
|
||||
|
||||
\param name Name of the PPP interface description file.
|
||||
\param entry The PPP manager passes an internal structure to the constructor.
|
||||
\param ID The interface's ID.
|
||||
\param settings (Optional): If no name is given you must pass the settings here.
|
||||
\param profile (Optional): Overriding profile for this interface.
|
||||
\param parent (Optional): Interface's parent (only used for multilink interfaces).
|
||||
|
||||
\sa KPPPProfile
|
||||
*/
|
||||
KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry,
|
||||
ppp_interface_id ID, const driver_settings *settings,
|
||||
const driver_settings *profile, KPPPInterface *parent = NULL)
|
||||
@ -205,6 +231,7 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry,
|
||||
}
|
||||
|
||||
|
||||
//! Destructor: Disconnects and marks interface for deletion.
|
||||
KPPPInterface::~KPPPInterface()
|
||||
{
|
||||
#if DEBUG
|
||||
@ -272,6 +299,7 @@ KPPPInterface::~KPPPInterface()
|
||||
}
|
||||
|
||||
|
||||
//! Marks interface for deletion.
|
||||
void
|
||||
KPPPInterface::Delete()
|
||||
{
|
||||
@ -294,6 +322,7 @@ KPPPInterface::Delete()
|
||||
}
|
||||
|
||||
|
||||
//! Returns if interface was initialized correctly.
|
||||
status_t
|
||||
KPPPInterface::InitCheck() const
|
||||
{
|
||||
@ -314,6 +343,7 @@ KPPPInterface::InitCheck() const
|
||||
}
|
||||
|
||||
|
||||
//! Sets interface MRU.
|
||||
bool
|
||||
KPPPInterface::SetMRU(uint32 MRU)
|
||||
{
|
||||
@ -334,6 +364,7 @@ KPPPInterface::SetMRU(uint32 MRU)
|
||||
}
|
||||
|
||||
|
||||
//! Returns number of bytes spent for protocol overhead. Includes device overhead.
|
||||
uint32
|
||||
KPPPInterface::PacketOverhead() const
|
||||
{
|
||||
@ -346,13 +377,28 @@ KPPPInterface::PacketOverhead() const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Allows accessing additional functions.
|
||||
|
||||
This is normally called by userland apps to get information about the interface.
|
||||
|
||||
\param op The op value (see ppp_control_ops enum).
|
||||
\param data (Optional): Additional data may be needed for this op.
|
||||
\param length Length of data.
|
||||
|
||||
\return
|
||||
- \c B_OK: \c Control() was successful.
|
||||
- \c B_ERROR: Either \a length is too small or data is NULL.
|
||||
- \c B_BAD_INDEX: Wrong index (e.g.: when accessing interface submodules).
|
||||
- \c B_BAD_VALUE: Unknown op.
|
||||
- Return value of submodule (when controlling one).
|
||||
*/
|
||||
status_t
|
||||
KPPPInterface::Control(uint32 op, void *data, size_t length)
|
||||
{
|
||||
switch(op) {
|
||||
case PPPC_GET_INTERFACE_INFO: {
|
||||
if(length < sizeof(ppp_interface_info_t) || !data)
|
||||
return B_NO_MEMORY;
|
||||
return B_ERROR;
|
||||
|
||||
ppp_interface_info *info = (ppp_interface_info*) data;
|
||||
memset(info, 0, sizeof(ppp_interface_info_t));
|
||||
@ -400,14 +446,14 @@ KPPPInterface::Control(uint32 op, void *data, size_t length)
|
||||
|
||||
case PPPC_SET_DIAL_ON_DEMAND:
|
||||
if(length < sizeof(uint32) || !data)
|
||||
return B_NO_MEMORY;
|
||||
return B_ERROR;
|
||||
|
||||
SetDialOnDemand(*((uint32*)data));
|
||||
break;
|
||||
|
||||
case PPPC_SET_AUTO_REDIAL:
|
||||
if(length < sizeof(uint32) || !data)
|
||||
return B_NO_MEMORY;
|
||||
return B_ERROR;
|
||||
|
||||
SetAutoRedial(*((uint32*)data));
|
||||
break;
|
||||
@ -518,6 +564,18 @@ KPPPInterface::Control(uint32 op, void *data, size_t length)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Sets a new device for this interface.
|
||||
|
||||
A device add-on should call this method to register itself. The best place to do
|
||||
this is in your module's \c add_to() function.
|
||||
|
||||
\param device The device object.
|
||||
|
||||
\return \c true if successful or \false otherwise.
|
||||
|
||||
\sa KPPPDevice
|
||||
\sa kppp_module_info
|
||||
*/
|
||||
bool
|
||||
KPPPInterface::SetDevice(KPPPDevice *device)
|
||||
{
|
||||
@ -554,6 +612,18 @@ KPPPInterface::SetDevice(KPPPDevice *device)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Adds a new protocol to this interface.
|
||||
|
||||
A protocol add-on should call this method to register itself. The best place to do
|
||||
this is in your module's \c add_to() function.
|
||||
|
||||
\param protocol The protocol object.
|
||||
|
||||
\return \c true if successful or \false otherwise.
|
||||
|
||||
\sa KPPPProtocol
|
||||
\sa kppp_module_info
|
||||
*/
|
||||
bool
|
||||
KPPPInterface::AddProtocol(KPPPProtocol *protocol)
|
||||
{
|
||||
@ -615,6 +685,17 @@ KPPPInterface::AddProtocol(KPPPProtocol *protocol)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Removes a protocol from this interface.
|
||||
|
||||
A protocol add-on should call this method to remove itself explicitly from the
|
||||
interface.\n
|
||||
Normally, this method is called in KPPPProtocol's destructor. Do not call it
|
||||
yourself unless you know what you do!
|
||||
|
||||
\param protocol The protocol object.
|
||||
|
||||
\return \c true if successful or \false otherwise.
|
||||
*/
|
||||
bool
|
||||
KPPPInterface::RemoveProtocol(KPPPProtocol *protocol)
|
||||
{
|
||||
@ -660,6 +741,7 @@ KPPPInterface::RemoveProtocol(KPPPProtocol *protocol)
|
||||
}
|
||||
|
||||
|
||||
//! Returns the number of protocol modules belonging to this interface.
|
||||
int32
|
||||
KPPPInterface::CountProtocols() const
|
||||
{
|
||||
@ -673,6 +755,7 @@ KPPPInterface::CountProtocols() const
|
||||
}
|
||||
|
||||
|
||||
//! Returns the protocol at the given \a index or \c NULL if it could not be found.
|
||||
KPPPProtocol*
|
||||
KPPPInterface::ProtocolAt(int32 index) const
|
||||
{
|
||||
@ -686,6 +769,13 @@ KPPPInterface::ProtocolAt(int32 index) const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Returns the protocol object responsible for a given protocol number.
|
||||
|
||||
\param protocolNumber The protocol number that the object should handle.
|
||||
\param start (Optional): Start with this protocol. Can be used for iteration.
|
||||
|
||||
\return Either the object that was found or \c NULL.
|
||||
*/
|
||||
KPPPProtocol*
|
||||
KPPPInterface::ProtocolFor(uint16 protocolNumber, KPPPProtocol *start = NULL) const
|
||||
{
|
||||
@ -707,6 +797,7 @@ KPPPInterface::ProtocolFor(uint16 protocolNumber, KPPPProtocol *start = NULL) co
|
||||
}
|
||||
|
||||
|
||||
//! Adds a new child interface (used for multilink interfaces).
|
||||
bool
|
||||
KPPPInterface::AddChild(KPPPInterface *child)
|
||||
{
|
||||
@ -729,6 +820,7 @@ KPPPInterface::AddChild(KPPPInterface *child)
|
||||
}
|
||||
|
||||
|
||||
//! Removes a new child from this interface (used for multilink interfaces).
|
||||
bool
|
||||
KPPPInterface::RemoveChild(KPPPInterface *child)
|
||||
{
|
||||
@ -752,6 +844,7 @@ KPPPInterface::RemoveChild(KPPPInterface *child)
|
||||
}
|
||||
|
||||
|
||||
//! Returns the child interface at the given \a index (used for multilink interfaces).
|
||||
KPPPInterface*
|
||||
KPPPInterface::ChildAt(int32 index) const
|
||||
{
|
||||
@ -768,6 +861,7 @@ KPPPInterface::ChildAt(int32 index) const
|
||||
}
|
||||
|
||||
|
||||
//! Enables or disables the auto-redial feture.
|
||||
void
|
||||
KPPPInterface::SetAutoRedial(bool autoRedial = true)
|
||||
{
|
||||
@ -784,6 +878,7 @@ KPPPInterface::SetAutoRedial(bool autoRedial = true)
|
||||
}
|
||||
|
||||
|
||||
//! Enables or disables the dial-on-demand feature.
|
||||
void
|
||||
KPPPInterface::SetDialOnDemand(bool dialOnDemand = true)
|
||||
{
|
||||
@ -832,6 +927,7 @@ KPPPInterface::SetDialOnDemand(bool dialOnDemand = true)
|
||||
}
|
||||
|
||||
|
||||
//! Sets Protocol-Field-Compression options.
|
||||
bool
|
||||
KPPPInterface::SetPFCOptions(uint8 pfcOptions)
|
||||
{
|
||||
@ -847,6 +943,13 @@ KPPPInterface::SetPFCOptions(uint8 pfcOptions)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Brings this interface up.
|
||||
|
||||
\c Down() overrides all \c Up() requests.\n
|
||||
This blocks until the connection process is finished.
|
||||
|
||||
\return \c true if successful or \c false otherwise.
|
||||
*/
|
||||
bool
|
||||
KPPPInterface::Up()
|
||||
{
|
||||
@ -1038,6 +1141,13 @@ KPPPInterface::Up()
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Brings this interface down.
|
||||
|
||||
\c Down() overrides all \c Up() requests.\n
|
||||
This blocks until diconnecting finished.
|
||||
|
||||
\return \c true if successful or \c false otherwise.
|
||||
*/
|
||||
bool
|
||||
KPPPInterface::Down()
|
||||
{
|
||||
@ -1099,6 +1209,7 @@ KPPPInterface::Down()
|
||||
}
|
||||
|
||||
|
||||
//! Returns if the interface is connected.
|
||||
bool
|
||||
KPPPInterface::IsUp() const
|
||||
{
|
||||
@ -1108,6 +1219,14 @@ KPPPInterface::IsUp() const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Loads modules specified in the settings structure.
|
||||
|
||||
\param settings PPP interface description file format settings.
|
||||
\param start Index of driver_parameter to start with.
|
||||
\param count Number of driver_parameters to look at.
|
||||
|
||||
\return \c true if successful or \c false otherwise.
|
||||
*/
|
||||
bool
|
||||
KPPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
|
||||
{
|
||||
@ -1126,7 +1245,7 @@ KPPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
|
||||
|
||||
// multilink handling
|
||||
for(int32 index = start;
|
||||
index < settings->parameter_count && index < start + count; index++) {
|
||||
index < settings->parameter_count && index < (start + count); index++) {
|
||||
if(!strcasecmp(settings->parameters[index].name, PPP_MULTILINK_KEY)
|
||||
&& settings->parameters[index].value_count > 0) {
|
||||
if(!LoadModule(settings->parameters[index].values[0],
|
||||
@ -1171,6 +1290,14 @@ KPPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Loads a specific module.
|
||||
|
||||
\param name Name of the module.
|
||||
\param parameter Module settings.
|
||||
\param type Type of module.
|
||||
|
||||
\return \c true if successful or \c false otherwise.
|
||||
*/
|
||||
bool
|
||||
KPPPInterface::LoadModule(const char *name, driver_parameter *parameter,
|
||||
ppp_module_key_type type)
|
||||
@ -1204,6 +1331,7 @@ KPPPInterface::LoadModule(const char *name, driver_parameter *parameter,
|
||||
}
|
||||
|
||||
|
||||
//! Always returns true.
|
||||
bool
|
||||
KPPPInterface::IsAllowedToSend() const
|
||||
{
|
||||
@ -1211,6 +1339,19 @@ KPPPInterface::IsAllowedToSend() const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Sends a packet to the device.
|
||||
|
||||
This brings the interface up if dial-on-demand is enabled and we are not
|
||||
connected.\n
|
||||
PFC encoding is handled here.
|
||||
|
||||
\param packet The packet.
|
||||
\param protocolNumber The packet's protocol number.
|
||||
|
||||
\return
|
||||
- \c B_OK: Sending was successful.
|
||||
- \c B_ERROR: Some error occured.
|
||||
*/
|
||||
status_t
|
||||
KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
|
||||
{
|
||||
@ -1305,6 +1446,23 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Receives a packet.
|
||||
|
||||
Encapsulation protocols may use this method to pass encapsulated packets to the
|
||||
PPP interface. Packets will be handled as if they were raw packets that came
|
||||
directly from the device via \c ReceiveFromDevice().\n
|
||||
If no handler could be found in this interface the parent's \c Receive() method
|
||||
is called.
|
||||
|
||||
\param packet The packet.
|
||||
\param protocolNumber The packet's protocol number.
|
||||
|
||||
\return
|
||||
- \c B_OK: Receiving was successful.
|
||||
- \c B_ERROR: Some error occured.
|
||||
- \c PPP_REJECTED: No protocol handler could be found for this packet.
|
||||
- \c PPP_DISCARDED: The protocol handler(s) did not handle this packet.
|
||||
*/
|
||||
status_t
|
||||
KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
|
||||
{
|
||||
@ -1367,6 +1525,19 @@ KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Receives a base PPP packet from the device.
|
||||
|
||||
KPPPDevice should call this method when it receives a packet.\n
|
||||
PFC decoding is handled here.
|
||||
|
||||
\param packet The packet.
|
||||
|
||||
\return
|
||||
- \c B_OK: Receiving was successful.
|
||||
- \c B_ERROR: Some error occured.
|
||||
- \c PPP_REJECTED: No protocol handler could be found for this packet.
|
||||
- \c PPP_DISCARDED: The protocol handler(s) did not handle this packet.
|
||||
*/
|
||||
status_t
|
||||
KPPPInterface::ReceiveFromDevice(struct mbuf *packet)
|
||||
{
|
||||
@ -1395,6 +1566,7 @@ KPPPInterface::ReceiveFromDevice(struct mbuf *packet)
|
||||
}
|
||||
|
||||
|
||||
//! Manages Pulse() calls for all add-ons and hanldes idle-disconnection.
|
||||
void
|
||||
KPPPInterface::Pulse()
|
||||
{
|
||||
@ -1418,6 +1590,7 @@ KPPPInterface::Pulse()
|
||||
}
|
||||
|
||||
|
||||
//! Registers an ifnet structure for this interface.
|
||||
bool
|
||||
KPPPInterface::RegisterInterface()
|
||||
{
|
||||
@ -1453,6 +1626,7 @@ KPPPInterface::RegisterInterface()
|
||||
}
|
||||
|
||||
|
||||
//! Unregisters this interface's ifnet structure.
|
||||
bool
|
||||
KPPPInterface::UnregisterInterface()
|
||||
{
|
||||
@ -1481,7 +1655,7 @@ KPPPInterface::UnregisterInterface()
|
||||
}
|
||||
|
||||
|
||||
// called when profile changes
|
||||
//! Called when profile changes.
|
||||
void
|
||||
KPPPInterface::UpdateProfile()
|
||||
{
|
||||
@ -1491,7 +1665,7 @@ KPPPInterface::UpdateProfile()
|
||||
}
|
||||
|
||||
|
||||
// called by KPPPManager: manager routes stack ioctls to interface
|
||||
//! Called by KPPPManager: manager routes stack ioctls to the corresponding interface.
|
||||
status_t
|
||||
KPPPInterface::StackControl(uint32 op, void *data)
|
||||
{
|
||||
@ -1530,11 +1704,13 @@ class CallStackControl {
|
||||
status_t& fResult;
|
||||
};
|
||||
|
||||
// This calls Control() with the given parameters for each handler.
|
||||
// Return values:
|
||||
// B_OK: all handlers returned B_OK
|
||||
// B_BAD_VALUE: no handler was found
|
||||
// any other value: the error value that was returned by the last handler that failed
|
||||
/*! \brief This calls Control() with the given parameters for each add-on.
|
||||
|
||||
\return
|
||||
- \c B_OK: All handlers returned B_OK.
|
||||
- \c B_BAD_VALUE: No handler was found.
|
||||
- Any other value: Error code which was returned by the last failing handler.
|
||||
*/
|
||||
status_t
|
||||
KPPPInterface::StackControlEachHandler(uint32 op, void *data)
|
||||
{
|
||||
@ -1562,6 +1738,7 @@ KPPPInterface::StackControlEachHandler(uint32 op, void *data)
|
||||
}
|
||||
|
||||
|
||||
//! Recalculates the MTU from the MRU (includes encapsulation protocol overheads).
|
||||
void
|
||||
KPPPInterface::CalculateInterfaceMTU()
|
||||
{
|
||||
@ -1591,6 +1768,7 @@ KPPPInterface::CalculateInterfaceMTU()
|
||||
}
|
||||
|
||||
|
||||
//! Recalculates the baud rate.
|
||||
void
|
||||
KPPPInterface::CalculateBaudRate()
|
||||
{
|
||||
@ -1613,6 +1791,7 @@ KPPPInterface::CalculateBaudRate()
|
||||
}
|
||||
|
||||
|
||||
//! Redials. Waits a given delay (in miliseconds) before redialing.
|
||||
void
|
||||
KPPPInterface::Redial(uint32 delay)
|
||||
{
|
||||
|
@ -5,6 +5,17 @@
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*! \class KPPPLCP
|
||||
\brief The LCP protocol.
|
||||
|
||||
Every PPP interface \e must have an LCP protocol. It is used for establishing
|
||||
and terminating connections.\n
|
||||
When establishing a connecition the LCP protocol determines connection-specific
|
||||
settings like the packet MRU. These settings are handled by the KPPPOptionHandler
|
||||
class. Additional LCP codes like the PPP Multilink-Protocol uses them should
|
||||
be implemented through the KPPPLCPExtension class.\n
|
||||
*/
|
||||
|
||||
#include <KPPPInterface.h>
|
||||
#include <KPPPDevice.h>
|
||||
#include <KPPPLCPExtension.h>
|
||||
@ -17,6 +28,7 @@
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
//! Creates a new LCP protocol for the given interface.
|
||||
KPPPLCP::KPPPLCP(KPPPInterface& interface)
|
||||
: KPPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL,
|
||||
PPP_PROTOCOL_LEVEL, AF_UNSPEC, 0, interface, NULL, PPP_ALWAYS_ALLOWED),
|
||||
@ -28,6 +40,7 @@ KPPPLCP::KPPPLCP(KPPPInterface& interface)
|
||||
}
|
||||
|
||||
|
||||
//! Deletes all added option handlers and LCP extensions.
|
||||
KPPPLCP::~KPPPLCP()
|
||||
{
|
||||
while(CountOptionHandlers())
|
||||
@ -37,6 +50,7 @@ KPPPLCP::~KPPPLCP()
|
||||
}
|
||||
|
||||
|
||||
//! Adds a new option handler.
|
||||
bool
|
||||
KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler)
|
||||
{
|
||||
@ -54,6 +68,7 @@ KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler)
|
||||
}
|
||||
|
||||
|
||||
//! Removes an option handler, but does not delete it.
|
||||
bool
|
||||
KPPPLCP::RemoveOptionHandler(KPPPOptionHandler *optionHandler)
|
||||
{
|
||||
@ -67,6 +82,7 @@ KPPPLCP::RemoveOptionHandler(KPPPOptionHandler *optionHandler)
|
||||
}
|
||||
|
||||
|
||||
//! Returns the option handler at the given \a index.
|
||||
KPPPOptionHandler*
|
||||
KPPPLCP::OptionHandlerAt(int32 index) const
|
||||
{
|
||||
@ -79,6 +95,7 @@ KPPPLCP::OptionHandlerAt(int32 index) const
|
||||
}
|
||||
|
||||
|
||||
//! Returns the option handler that can handle options of a given \a type.
|
||||
KPPPOptionHandler*
|
||||
KPPPLCP::OptionHandlerFor(uint8 type, int32 *start = NULL) const
|
||||
{
|
||||
@ -105,6 +122,7 @@ KPPPLCP::OptionHandlerFor(uint8 type, int32 *start = NULL) const
|
||||
}
|
||||
|
||||
|
||||
//! Adds a new LCP extension.
|
||||
bool
|
||||
KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension)
|
||||
{
|
||||
@ -121,6 +139,7 @@ KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension)
|
||||
}
|
||||
|
||||
|
||||
//! Removes an LCP extension, but does not delete it.
|
||||
bool
|
||||
KPPPLCP::RemoveLCPExtension(KPPPLCPExtension *lcpExtension)
|
||||
{
|
||||
@ -134,6 +153,7 @@ KPPPLCP::RemoveLCPExtension(KPPPLCPExtension *lcpExtension)
|
||||
}
|
||||
|
||||
|
||||
//! Returns the LCP extension at the given \a index.
|
||||
KPPPLCPExtension*
|
||||
KPPPLCP::LCPExtensionAt(int32 index) const
|
||||
{
|
||||
@ -146,6 +166,7 @@ KPPPLCP::LCPExtensionAt(int32 index) const
|
||||
}
|
||||
|
||||
|
||||
//! Returns the LCP extension that can handle LCP packets of a given \a code.
|
||||
KPPPLCPExtension*
|
||||
KPPPLCP::LCPExtensionFor(uint8 code, int32 *start = NULL) const
|
||||
{
|
||||
@ -172,6 +193,7 @@ KPPPLCP::LCPExtensionFor(uint8 code, int32 *start = NULL) const
|
||||
}
|
||||
|
||||
|
||||
//! Returns the interface, target, and device overhead.
|
||||
uint32
|
||||
KPPPLCP::AdditionalOverhead() const
|
||||
{
|
||||
@ -187,6 +209,7 @@ KPPPLCP::AdditionalOverhead() const
|
||||
}
|
||||
|
||||
|
||||
//! Calls \c ProfileChanged() for each option handler and LCP extension.
|
||||
void
|
||||
KPPPLCP::ProfileChanged()
|
||||
{
|
||||
@ -207,6 +230,7 @@ KPPPLCP::ProfileChanged()
|
||||
}
|
||||
|
||||
|
||||
//! Always returns \c true.
|
||||
bool
|
||||
KPPPLCP::Up()
|
||||
{
|
||||
@ -214,6 +238,7 @@ KPPPLCP::Up()
|
||||
}
|
||||
|
||||
|
||||
//! Always returns \c true.
|
||||
bool
|
||||
KPPPLCP::Down()
|
||||
{
|
||||
@ -221,6 +246,7 @@ KPPPLCP::Down()
|
||||
}
|
||||
|
||||
|
||||
//! Sends a packet to the target (if there is one) or to the interface.
|
||||
status_t
|
||||
KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber = PPP_LCP_PROTOCOL)
|
||||
{
|
||||
@ -231,6 +257,7 @@ KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber = PPP_LCP_PROTOCOL)
|
||||
}
|
||||
|
||||
|
||||
//! Decodes the LCP packet and passes it to the KPPPStateMachine or an LCP extension.
|
||||
status_t
|
||||
KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
|
||||
{
|
||||
@ -342,6 +369,7 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
|
||||
}
|
||||
|
||||
|
||||
//! Calls \c Pulse() for each LCP extension.
|
||||
void
|
||||
KPPPLCP::Pulse()
|
||||
{
|
||||
|
@ -5,6 +5,16 @@
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*! \class KPPPLayer
|
||||
\brief An abstract layer that can encapsulate/send and receive packets.
|
||||
|
||||
All packet handlers should derive from this class. It does not define a protocol
|
||||
number like KPPPProtocol does. It only has a header overhead and an encapsulation
|
||||
level that is used to determine the order at which the packets get encapsulated
|
||||
by the layers. If this layer does not encapsulate PPP packets you should use
|
||||
PPP_PROTOCOL_LEVEL.
|
||||
*/
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <kernel_cpp.h>
|
||||
#endif
|
||||
@ -16,6 +26,10 @@
|
||||
#include <core_funcs.h>
|
||||
|
||||
|
||||
/*! \brief Creates a new layer.
|
||||
|
||||
If an error appears in the constructor you should set \c fInitStatus.
|
||||
*/
|
||||
KPPPLayer::KPPPLayer(const char *name, ppp_level level, uint32 overhead)
|
||||
: fInitStatus(B_OK),
|
||||
fOverhead(overhead),
|
||||
@ -27,12 +41,14 @@ KPPPLayer::KPPPLayer(const char *name, ppp_level level, uint32 overhead)
|
||||
}
|
||||
|
||||
|
||||
//! Only frees the name.
|
||||
KPPPLayer::~KPPPLayer()
|
||||
{
|
||||
free(fName);
|
||||
}
|
||||
|
||||
|
||||
//! Returns \c fInitStatus. May be overridden to return status-dependend errors.
|
||||
status_t
|
||||
KPPPLayer::InitCheck() const
|
||||
{
|
||||
@ -40,6 +56,12 @@ KPPPLayer::InitCheck() const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Notification hook when the interface profile changes dynamically.
|
||||
|
||||
You should override this method to update your profile settings if this layer
|
||||
has such settings at all. This is mostly used by authenticators and possibly
|
||||
protocols.
|
||||
*/
|
||||
void
|
||||
KPPPLayer::ProfileChanged()
|
||||
{
|
||||
@ -47,6 +69,7 @@ KPPPLayer::ProfileChanged()
|
||||
}
|
||||
|
||||
|
||||
//! Sends a packet to the next layer in the chain.
|
||||
status_t
|
||||
KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
|
||||
{
|
||||
@ -68,6 +91,10 @@ KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief You may override this for periodic tasks.
|
||||
|
||||
This method gets called every \c PPP_PULSE_RATE microseconds.
|
||||
*/
|
||||
void
|
||||
KPPPLayer::Pulse()
|
||||
{
|
||||
@ -75,6 +102,7 @@ KPPPLayer::Pulse()
|
||||
}
|
||||
|
||||
|
||||
//! Allows changing the name of this layer.
|
||||
void
|
||||
KPPPLayer::SetName(const char *name)
|
||||
{
|
||||
|
@ -12,11 +12,14 @@
|
||||
|
||||
struct mbuf;
|
||||
|
||||
//! An abstract configure item.
|
||||
typedef struct ppp_configure_item {
|
||||
uint8 type;
|
||||
//!< Item's type.
|
||||
uint8 length;
|
||||
//!< Item length (including appended data, if any).
|
||||
uint8 data[0];
|
||||
// the data follows this structure
|
||||
//!< Additional data may be appended to this structure.
|
||||
} ppp_configure_item;
|
||||
|
||||
|
||||
@ -32,16 +35,20 @@ class KPPPConfigurePacket {
|
||||
~KPPPConfigurePacket();
|
||||
|
||||
bool SetCode(uint8 code);
|
||||
//! Returns this packet's code value.
|
||||
uint8 Code() const
|
||||
{ return fCode; }
|
||||
|
||||
//! Sets the packet's (unique) ID. Use KPPPLCP::NextID() to get a unique ID.
|
||||
void SetID(uint8 id)
|
||||
{ fID = id; }
|
||||
//! Returns this packet's ID.
|
||||
uint8 ID() const
|
||||
{ return fID; }
|
||||
|
||||
bool AddItem(const ppp_configure_item *item, int32 index = -1);
|
||||
bool RemoveItem(ppp_configure_item *item);
|
||||
//! Returns number of items in this packet.
|
||||
int32 CountItems() const
|
||||
{ return fItems.CountItems(); }
|
||||
ppp_configure_item *ItemAt(int32 index) const;
|
||||
|
@ -18,9 +18,10 @@ extern struct core_module_info *core;
|
||||
|
||||
// various constants
|
||||
#define PPP_PULSE_RATE 500000
|
||||
//!< Rate at which Pulse() is called (in microseconds).
|
||||
|
||||
|
||||
// module key types (used when loading a module)
|
||||
//! Module key types used when loading a module.
|
||||
enum ppp_module_key_type {
|
||||
PPP_UNDEFINED_KEY_TYPE = -1,
|
||||
PPP_LOAD_MODULE_KEY_TYPE = 0,
|
||||
@ -30,7 +31,7 @@ enum ppp_module_key_type {
|
||||
PPP_MULTILINK_KEY_TYPE
|
||||
};
|
||||
|
||||
// PPP events as defined in RFC 1661 (with one exception: PPP_UP_FAILED_EVENT)
|
||||
//! PPP events as defined in RFC 1661 (with one exception: PPP_UP_FAILED_EVENT).
|
||||
enum ppp_event {
|
||||
PPP_UP_FAILED_EVENT,
|
||||
PPP_UP_EVENT,
|
||||
@ -51,8 +52,7 @@ enum ppp_event {
|
||||
PPP_RXR_EVENT
|
||||
};
|
||||
|
||||
// LCP protocol codes as defined in RFC 1661
|
||||
// ToDo: add LCP extensions
|
||||
//! LCP protocol codes as defined in RFC 1661.
|
||||
enum ppp_lcp_code {
|
||||
PPP_CONFIGURE_REQUEST = 1,
|
||||
PPP_CONFIGURE_ACK = 2,
|
||||
@ -65,6 +65,8 @@ enum ppp_lcp_code {
|
||||
PPP_ECHO_REQUEST = 9,
|
||||
PPP_ECHO_REPLY = 10,
|
||||
PPP_DISCARD_REQUEST = 11
|
||||
|
||||
// ToDo: add LCP extensions
|
||||
};
|
||||
|
||||
#define PPP_MIN_LCP_CODE PPP_CONFIGURE_REQUEST
|
||||
|
@ -27,55 +27,85 @@ class KPPPDevice : public KPPPLayer {
|
||||
public:
|
||||
virtual ~KPPPDevice();
|
||||
|
||||
//! Returns the interface that owns this device.
|
||||
KPPPInterface& Interface() const
|
||||
{ return fInterface; }
|
||||
//! Returns the device's settings.
|
||||
driver_parameter *Settings() const
|
||||
{ return fSettings; }
|
||||
|
||||
virtual status_t Control(uint32 op, void *data, size_t length);
|
||||
|
||||
//! Returns the device's MTU.
|
||||
uint32 MTU() const
|
||||
{ return fMTU; }
|
||||
|
||||
/*! \brief This brings the device up.
|
||||
|
||||
ATTENTION: This method must not block!\n
|
||||
Call UpStarted() to check if you are allowed to go down. After UpStarted()
|
||||
is called the connection attempt may be aborted by calling Down().\n
|
||||
In server mode you should listen for incoming connections.
|
||||
On error: \e Either call \c UpFailedEvent() and return \c true \e or
|
||||
return \c false only. \e Never call \c UpFailedEvent() and return
|
||||
\c false at the same time!
|
||||
|
||||
\sa UpStarted()
|
||||
\sa UpFailedEvent()
|
||||
*/
|
||||
virtual bool Up() = 0;
|
||||
// In server mode you should listen for incoming connections.
|
||||
// On error: either call UpFailedEvent() or return false.
|
||||
/*! \brief Bring the interface down.
|
||||
|
||||
Call DownStarted() to check if you are allowed to go down.\n
|
||||
The return value of this method is currently ignored.
|
||||
|
||||
\sa DownStarted()
|
||||
*/
|
||||
virtual bool Down() = 0;
|
||||
//! Is the connection established?
|
||||
bool IsUp() const
|
||||
{ return fConnectionPhase == PPP_ESTABLISHED_PHASE; }
|
||||
//! Is the interface disconnected and ready to connect?
|
||||
bool IsDown() const
|
||||
{ return fConnectionPhase == PPP_DOWN_PHASE; }
|
||||
//! Is the interface connecting at the moment?
|
||||
bool IsGoingUp() const
|
||||
{ return fConnectionPhase == PPP_ESTABLISHMENT_PHASE; }
|
||||
//! Is the interface disconnecting at the moment?
|
||||
bool IsGoingDown() const
|
||||
{ return fConnectionPhase == PPP_TERMINATION_PHASE; }
|
||||
|
||||
// The biggest of the two tranfer rates will be set in ifnet.
|
||||
// These methods should return default values when disconnected.
|
||||
/*! \brief Input speed in bytes per second.
|
||||
|
||||
The biggest of the two tranfer rates will be set in ifnet.\n
|
||||
Should return default value when disconnected.
|
||||
*/
|
||||
virtual uint32 InputTransferRate() const = 0;
|
||||
/*! \brief Output speed in bytes per second.
|
||||
|
||||
The biggest of the two tranfer rates will be set in ifnet.\n
|
||||
Should return default value when disconnected.
|
||||
*/
|
||||
virtual uint32 OutputTransferRate() const = 0;
|
||||
|
||||
//! Number of bytes waiting to be sent (i.e.: waiting in output queue).
|
||||
virtual uint32 CountOutputBytes() const = 0;
|
||||
// how many bytes are waiting to be sent?
|
||||
|
||||
virtual bool IsAllowedToSend() const;
|
||||
// always returns true
|
||||
|
||||
/*! \brief Sends a packet.
|
||||
|
||||
This should enqueue the packet and return immediately (never block).
|
||||
The device is responsible for freeing the packet by calling \c m_freem().
|
||||
*/
|
||||
virtual status_t Send(struct mbuf *packet, uint16 protocolNumber) = 0;
|
||||
// This should enqueue the packet and return immediately (never block).
|
||||
// The device is responsible for freeing the packet.
|
||||
virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber);
|
||||
// this method is never used
|
||||
|
||||
virtual void Pulse();
|
||||
|
||||
protected:
|
||||
//! Use this to set the device's maximum transfer unit (in bytes).
|
||||
void SetMTU(uint32 MTU)
|
||||
{ fMTU = MTU; }
|
||||
|
||||
// Report that we are going up/down
|
||||
// (from now on, the Up() process can be aborted).
|
||||
// Abort if false is returned!
|
||||
bool UpStarted();
|
||||
bool DownStarted();
|
||||
|
||||
|
@ -47,7 +47,7 @@ class KPPPInterface : public KPPPLayer {
|
||||
friend class KPPPInterfaceAccess;
|
||||
|
||||
private:
|
||||
// copies are not allowed!
|
||||
//! Copies are not allowed.
|
||||
KPPPInterface(const KPPPInterface& copy);
|
||||
KPPPInterface& operator= (const KPPPInterface& copy);
|
||||
|
||||
@ -62,51 +62,62 @@ class KPPPInterface : public KPPPLayer {
|
||||
|
||||
virtual status_t InitCheck() const;
|
||||
|
||||
//! Returns this interface's unique identifier.
|
||||
ppp_interface_id ID() const
|
||||
{ return fID; }
|
||||
|
||||
//! Returns interface's settings.
|
||||
driver_settings* Settings() const
|
||||
{ return fSettings; }
|
||||
|
||||
//! Returns the KPPPStateMachine of this interface.
|
||||
KPPPStateMachine& StateMachine()
|
||||
{ return fStateMachine; }
|
||||
//! Returns the KPPPLCP protocol of this interface.
|
||||
KPPPLCP& LCP()
|
||||
{ return fLCP; }
|
||||
//! Returns interface's profile object.
|
||||
KPPPProfile& Profile()
|
||||
{ return fProfile; }
|
||||
|
||||
//! Returns the interfac's ifnet structure that is exported to the netstack.
|
||||
struct ifnet *Ifnet() const
|
||||
{ return fIfnet; }
|
||||
|
||||
// delays
|
||||
//! Delay in miliseconds between a dial retry.
|
||||
uint32 DialRetryDelay() const
|
||||
{ return fDialRetryDelay; }
|
||||
//! Delay in miliseconds to wait until redialing.
|
||||
uint32 RedialDelay() const
|
||||
{ return fRedialDelay; }
|
||||
|
||||
// idle handling
|
||||
//! Used for reporting that a packet was send/received (updates idle time).
|
||||
void UpdateIdleSince()
|
||||
{ fUpdateIdleSince = true; }
|
||||
//! Returns the time in seconds when the last packet was received.
|
||||
uint32 IdleSince() const
|
||||
{ return fIdleSince; }
|
||||
//! If no packets were received this number of seconds we will disconnect.
|
||||
uint32 DisconnectAfterIdleSince() const
|
||||
{ return fDisconnectAfterIdleSince; }
|
||||
|
||||
bool SetMRU(uint32 MRU);
|
||||
//! This is the smallest MRU that we and the peer have.
|
||||
uint32 MRU() const
|
||||
{ return fMRU; }
|
||||
// this is the smallest MRU that we and the peer have
|
||||
//! Sets interface's maximum transfer unit (will set ifnet value accordingly).
|
||||
bool SetInterfaceMTU(uint32 interfaceMTU)
|
||||
{ return SetMRU(interfaceMTU - fHeaderLength); }
|
||||
//! This is the MRU including protocol overhead.
|
||||
uint32 InterfaceMTU() const
|
||||
{ return fInterfaceMTU; }
|
||||
// this is the MRU including protocol overhead
|
||||
//! Includes the length of all device and encapsulator headers.
|
||||
uint32 PacketOverhead() const;
|
||||
// including device and encapsulator headers
|
||||
|
||||
virtual status_t Control(uint32 op, void *data, size_t length);
|
||||
|
||||
bool SetDevice(KPPPDevice *device);
|
||||
//! Returns interface's transport device.
|
||||
KPPPDevice *Device() const
|
||||
{ return fDevice; }
|
||||
|
||||
@ -114,6 +125,7 @@ class KPPPInterface : public KPPPLayer {
|
||||
bool RemoveProtocol(KPPPProtocol *protocol);
|
||||
int32 CountProtocols() const;
|
||||
KPPPProtocol *ProtocolAt(int32 index) const;
|
||||
//! Returns first protocol in chain.
|
||||
KPPPProtocol *FirstProtocol() const
|
||||
{ return fFirstProtocol; }
|
||||
KPPPProtocol *ProtocolFor(uint16 protocolNumber,
|
||||
@ -122,42 +134,59 @@ class KPPPInterface : public KPPPLayer {
|
||||
// multilink methods
|
||||
bool AddChild(KPPPInterface *child);
|
||||
bool RemoveChild(KPPPInterface *child);
|
||||
//! Returns the number of child interfaces that this interface has.
|
||||
int32 CountChildren() const
|
||||
{ return fChildren.CountItems(); }
|
||||
KPPPInterface *ChildAt(int32 index) const;
|
||||
//! Returns this interface's parent.
|
||||
KPPPInterface *Parent() const
|
||||
{ return fParent; }
|
||||
//! Returns whether we are a multilink-interface.
|
||||
bool IsMultilink() const
|
||||
{ return fIsMultilink; }
|
||||
|
||||
void SetAutoRedial(bool autoRedial = true);
|
||||
//! Returns whether this interface redials automatically.
|
||||
bool DoesAutoRedial() const
|
||||
{ return fAutoRedial; }
|
||||
|
||||
void SetDialOnDemand(bool dialOnDemand = true);
|
||||
//! Returns whether dial-on-demand (auto-dial) is enabled.
|
||||
bool DoesDialOnDemand() const
|
||||
{ return fDialOnDemand; }
|
||||
|
||||
//! Clients are in \c PPP_CLIENT_MODE and servers are in \c PPP_SERVER_MODE.
|
||||
ppp_mode Mode() const
|
||||
{ return fMode; }
|
||||
// client or server mode?
|
||||
//! Current state of the state machine (see enum: \c ppp_state).
|
||||
ppp_state State() const
|
||||
{ return fStateMachine.State(); }
|
||||
//! Current phase of the state machine (see enum: \c ppp_phase).
|
||||
ppp_phase Phase() const
|
||||
{ return fStateMachine.Phase(); }
|
||||
|
||||
// Protocol-Field-Compression
|
||||
bool SetPFCOptions(uint8 pfcOptions);
|
||||
//! PFC option flags as defined in enum: \c ppp_pfc_options.
|
||||
uint8 PFCOptions() const
|
||||
{ return fPFCOptions; }
|
||||
/*! \brief Local PFC state
|
||||
|
||||
Values defined in \c ppp_pfc_state.\n
|
||||
The local PFC state says if we accepted a request from the peer
|
||||
i.e.: we may use PFC in outgoing packets.
|
||||
*/
|
||||
ppp_pfc_state LocalPFCState() const
|
||||
{ return fLocalPFCState; }
|
||||
// the local PFC state says if we accepted a request from the peer
|
||||
// i.e.: we may use PFC in outgoing packets
|
||||
/*! \brief Peer PFC state
|
||||
|
||||
Values defined in \c ppp_pfc_state.\n
|
||||
The peer PFC state says if the peer accepted a request us
|
||||
i.e.: the peer might send PFC-compressed packets to us
|
||||
*/
|
||||
ppp_pfc_state PeerPFCState() const
|
||||
{ return fPeerPFCState; }
|
||||
// the peer PFC state says if the peer accepted a request us
|
||||
// i.e.: the peer might send PFC-compressed packets to us
|
||||
//! Shortcut for check if local state is \c PPP_PFC_ACCEPTED.
|
||||
bool UseLocalPFC() const
|
||||
{ return LocalPFCState() == PPP_PFC_ACCEPTED; }
|
||||
|
||||
@ -166,8 +195,10 @@ class KPPPInterface : public KPPPLayer {
|
||||
virtual bool Down();
|
||||
bool IsUp() const;
|
||||
|
||||
//! Returns interface's report manager.
|
||||
KPPPReportManager& ReportManager()
|
||||
{ return fReportManager; }
|
||||
//! Shortcut to KPPPReportManager::Report() of this interface's report manager.
|
||||
bool Report(ppp_report_type type, int32 code, void *data, int32 length)
|
||||
{ return ReportManager().Report(type, code, data, length); }
|
||||
// returns false if reply was bad (or an error occured)
|
||||
@ -215,6 +246,7 @@ class KPPPInterface : public KPPPLayer {
|
||||
void Redial(uint32 delay);
|
||||
|
||||
// multilink methods
|
||||
//! Set the parent of this interface.
|
||||
void SetParent(KPPPInterface *parent)
|
||||
{ fParent = parent; }
|
||||
|
||||
|
@ -26,6 +26,7 @@ class KPPPLCPExtension;
|
||||
class KPPPOptionHandler;
|
||||
|
||||
|
||||
//! LCP packet header structure.
|
||||
typedef struct ppp_lcp_packet {
|
||||
uint8 code;
|
||||
uint8 id;
|
||||
@ -47,11 +48,13 @@ class KPPPLCP : public KPPPProtocol {
|
||||
KPPPLCP& operator= (const KPPPLCP& copy);
|
||||
|
||||
public:
|
||||
//! Returns the KPPPStateMachine of the interface that owns this protocol.
|
||||
KPPPStateMachine& StateMachine() const
|
||||
{ return fStateMachine; }
|
||||
|
||||
bool AddOptionHandler(KPPPOptionHandler *handler);
|
||||
bool RemoveOptionHandler(KPPPOptionHandler *handler);
|
||||
//! Returns number of registered KPPPOptionHandler objects.
|
||||
int32 CountOptionHandlers() const
|
||||
{ return fOptionHandlers.CountItems(); }
|
||||
KPPPOptionHandler *OptionHandlerAt(int32 index) const;
|
||||
@ -59,15 +62,22 @@ class KPPPLCP : public KPPPProtocol {
|
||||
|
||||
bool AddLCPExtension(KPPPLCPExtension *extension);
|
||||
bool RemoveLCPExtension(KPPPLCPExtension *extension);
|
||||
//! Returns number of registered KPPPLCPExtension objects.
|
||||
int32 CountLCPExtensions() const
|
||||
{ return fLCPExtensions.CountItems(); }
|
||||
KPPPLCPExtension *LCPExtensionAt(int32 index) const;
|
||||
KPPPLCPExtension *LCPExtensionFor(uint8 code, int32 *start = NULL) const;
|
||||
|
||||
/*! \brief Sets the target protocol handler for outgoing LCP packets.
|
||||
|
||||
This may be used for filtering or routing LCP packets. Multilink
|
||||
protocols might need this method.\n
|
||||
If \a target != \c NULL all packets will be passed to the given protocol
|
||||
instead of the interface/device.
|
||||
*/
|
||||
void SetTarget(KPPPProtocol *target)
|
||||
{ fTarget = target; }
|
||||
// if target != NULL all packtes will be passed to the protocol
|
||||
// instead of the interface/device
|
||||
//! Returns the LCP packet handler or \c NULL.
|
||||
KPPPProtocol *Target() const
|
||||
{ return fTarget; }
|
||||
|
||||
|
@ -26,19 +26,25 @@ class KPPPLCPExtension {
|
||||
|
||||
virtual status_t InitCheck() const;
|
||||
|
||||
//! Returns the name of this LCP extension.
|
||||
const char *Name() const
|
||||
{ return fName; }
|
||||
|
||||
//! Returns the owning interface.
|
||||
KPPPInterface& Interface() const
|
||||
{ return fInterface; }
|
||||
//! Returns the LCP extension's settings.
|
||||
driver_parameter *Settings() const
|
||||
{ return fSettings; }
|
||||
|
||||
//! Enables or disables this handler.
|
||||
void SetEnabled(bool enabled = true)
|
||||
{ fEnabled = enabled; }
|
||||
//! Returns if the handler is enabled.
|
||||
bool IsEnabled() const
|
||||
{ return fEnabled; }
|
||||
|
||||
//! Returns the LCP packet code this extension can handle.
|
||||
uint8 Code() const
|
||||
{ return fCode; }
|
||||
|
||||
@ -48,6 +54,7 @@ class KPPPLCPExtension {
|
||||
|
||||
virtual void ProfileChanged();
|
||||
|
||||
//! Must be overridden. Called when an LCP packet with your code is received.
|
||||
virtual status_t Receive(struct mbuf *packet, uint8 code) = 0;
|
||||
|
||||
virtual void Reset();
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
class KPPPLayer {
|
||||
protected:
|
||||
// KPPPLayer must be subclassed
|
||||
//! KPPPLayer must be subclassed
|
||||
KPPPLayer(const char *name, ppp_level level, uint32 overhead);
|
||||
|
||||
public:
|
||||
@ -21,27 +21,39 @@ class KPPPLayer {
|
||||
|
||||
virtual status_t InitCheck() const;
|
||||
|
||||
//! Layer name.
|
||||
const char *Name() const
|
||||
{ return fName; }
|
||||
/*! \brief Level of this layer (level is defined in enum: \c ppp_level).
|
||||
|
||||
This should be \c PPP_PROTOCOL_LEVEL if this layer is not an encapsulator.
|
||||
*/
|
||||
ppp_level Level() const
|
||||
{ return fLevel; }
|
||||
// should be PPP_PROTOCOL_LEVEL if not encapsulator
|
||||
//! Length of header that will be prepended to outgoing packets.
|
||||
uint32 Overhead() const
|
||||
{ return fOverhead; }
|
||||
|
||||
//! Sets the next layer. This will be the target of \c SendToNext().
|
||||
void SetNext(KPPPLayer *next)
|
||||
{ fNext = next; }
|
||||
//! Next layer in chain.
|
||||
KPPPLayer *Next() const
|
||||
{ return fNext; }
|
||||
|
||||
virtual void ProfileChanged();
|
||||
|
||||
//! Brings this layer up.
|
||||
virtual bool Up() = 0;
|
||||
//! Brings this layer down.
|
||||
virtual bool Down() = 0;
|
||||
|
||||
//! Returns whether this layer is allowed to send packets.
|
||||
virtual bool IsAllowedToSend() const = 0;
|
||||
|
||||
//! Send a packet with the given protocol number.
|
||||
virtual status_t Send(struct mbuf *packet, uint16 protocolNumber) = 0;
|
||||
//! Receive a packet with the given protocol number.
|
||||
virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber) = 0;
|
||||
|
||||
status_t SendToNext(struct mbuf *packet, uint16 protocolNumber) const;
|
||||
@ -51,7 +63,8 @@ class KPPPLayer {
|
||||
|
||||
protected:
|
||||
void SetName(const char *name);
|
||||
|
||||
|
||||
protected:
|
||||
status_t fInitStatus;
|
||||
uint32 fOverhead;
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#define PPP_USER_OPS_START PPP_OPS_START + 32 * PPP_RESERVE_OPS_COUNT
|
||||
|
||||
|
||||
//! These values should be used for ppp_control_info::op.
|
||||
//! These values should be used for ppp_control_info::op.
|
||||
enum ppp_control_ops {
|
||||
// -----------------------------------------------------
|
||||
// PPPManager (the PPP interface module)
|
||||
|
@ -57,7 +57,7 @@ enum ppp_interface_filter {
|
||||
|
||||
// return values for Send()/Receive() methods in addition to B_ERROR and B_OK
|
||||
// PPP_UNHANDLED is also used by KPPPOptionHandler
|
||||
enum {
|
||||
enum ppp_return_values {
|
||||
// B_ERROR means that the packet is corrupted
|
||||
// B_OK means the packet was handled correctly
|
||||
|
||||
@ -76,23 +76,26 @@ enum {
|
||||
// could not send a packet because device is not connected
|
||||
};
|
||||
|
||||
// PFC options
|
||||
enum {
|
||||
//! PFC options. Should be set by KPPPDevice.
|
||||
enum ppp_pfc_options {
|
||||
PPP_REQUEST_PFC = 0x01,
|
||||
// try to request PFC (does not fail if not successful)
|
||||
//!< Try requesting PFC (does not fail if not successful).
|
||||
PPP_ALLOW_PFC = 0x02,
|
||||
// allow PFC if other side requests it
|
||||
//!< Allow PFC if other side requests it.
|
||||
PPP_FORCE_PFC_REQUEST = 0x04,
|
||||
// if PFC request fails the connection attempt will terminate
|
||||
//!< If PFC request fails the connection attempt will terminate.
|
||||
PPP_FREEZE_PFC_OPTIONS = 0x80
|
||||
// the options cannot be changed if this flag is set (mainly used by KPPPDevice)
|
||||
//!< Options cannot be changed if this flag is set (mainly used by KPPPDevice).
|
||||
};
|
||||
|
||||
//! PFC state constants.
|
||||
enum ppp_pfc_state {
|
||||
PPP_PFC_DISABLED,
|
||||
//!< PFC is disabled.
|
||||
PPP_PFC_ACCEPTED,
|
||||
//!< PFC was accepted by other side.
|
||||
PPP_PFC_REJECTED
|
||||
// not used for peer state
|
||||
//!< PFC was rejected by other side. Not used for peer state.
|
||||
};
|
||||
|
||||
// protocol flags
|
||||
|
Loading…
x
Reference in New Issue
Block a user