Added profile and interface naming support.

Added 'K' prefix to all kernel classes to resolve naming issue with doxygen.
Began some small doxygen comments.
Minor changes.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6282 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald
2004-01-25 12:54:00 +00:00
parent d9ca398271
commit f9ad2df864
39 changed files with 974 additions and 617 deletions
@@ -16,6 +16,7 @@ R5KernelStaticLibrary kernelppp :
KPPPLCP.cpp KPPPLCP.cpp
KPPPLCPExtension.cpp KPPPLCPExtension.cpp
KPPPOptionHandler.cpp KPPPOptionHandler.cpp
KPPPProfile.cpp
KPPPProtocol.cpp KPPPProtocol.cpp
KPPPReportManager.cpp KPPPReportManager.cpp
KPPPStateMachine.cpp KPPPStateMachine.cpp
@@ -11,14 +11,14 @@
#include <core_funcs.h> #include <core_funcs.h>
PPPConfigurePacket::PPPConfigurePacket(uint8 code) KPPPConfigurePacket::KPPPConfigurePacket(uint8 code)
: fCode(code), : fCode(code),
fID(0) fID(0)
{ {
} }
PPPConfigurePacket::PPPConfigurePacket(struct mbuf *packet) KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)
{ {
// decode packet // decode packet
ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*); ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*);
@@ -48,7 +48,7 @@ PPPConfigurePacket::PPPConfigurePacket(struct mbuf *packet)
} }
PPPConfigurePacket::~PPPConfigurePacket() KPPPConfigurePacket::~KPPPConfigurePacket()
{ {
for(int32 index = 0; index < CountItems(); index++) for(int32 index = 0; index < CountItems(); index++)
free(ItemAt(index)); free(ItemAt(index));
@@ -56,7 +56,7 @@ PPPConfigurePacket::~PPPConfigurePacket()
bool bool
PPPConfigurePacket::SetCode(uint8 code) KPPPConfigurePacket::SetCode(uint8 code)
{ {
// only configure codes are allowed! // only configure codes are allowed!
if(code < PPP_CONFIGURE_REQUEST || code > PPP_CONFIGURE_REJECT) if(code < PPP_CONFIGURE_REQUEST || code > PPP_CONFIGURE_REJECT)
@@ -69,7 +69,7 @@ PPPConfigurePacket::SetCode(uint8 code)
bool bool
PPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index = -1) KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index = -1)
{ {
if(!item || item->length < 2) if(!item || item->length < 2)
return false; return false;
@@ -92,7 +92,7 @@ PPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index = -1)
bool bool
PPPConfigurePacket::RemoveItem(ppp_configure_item *item) KPPPConfigurePacket::RemoveItem(ppp_configure_item *item)
{ {
if(!fItems.HasItem(item)) if(!fItems.HasItem(item))
return false; return false;
@@ -105,7 +105,7 @@ PPPConfigurePacket::RemoveItem(ppp_configure_item *item)
ppp_configure_item* ppp_configure_item*
PPPConfigurePacket::ItemAt(int32 index) const KPPPConfigurePacket::ItemAt(int32 index) const
{ {
ppp_configure_item *item = fItems.ItemAt(index); ppp_configure_item *item = fItems.ItemAt(index);
@@ -117,7 +117,7 @@ PPPConfigurePacket::ItemAt(int32 index) const
ppp_configure_item* ppp_configure_item*
PPPConfigurePacket::ItemWithType(uint8 type) const KPPPConfigurePacket::ItemWithType(uint8 type) const
{ {
ppp_configure_item *item; ppp_configure_item *item;
@@ -132,7 +132,7 @@ PPPConfigurePacket::ItemWithType(uint8 type) const
struct mbuf* struct mbuf*
PPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve = 0) KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve = 0)
{ {
struct mbuf *packet = m_gethdr(MT_DATA); struct mbuf *packet = m_gethdr(MT_DATA);
packet->m_data += reserve; packet->m_data += reserve;
@@ -13,9 +13,9 @@
#include <PPPControl.h> #include <PPPControl.h>
PPPDevice::PPPDevice(const char *name, uint32 overhead, PPPInterface& interface, KPPPDevice::KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interface,
driver_parameter *settings) driver_parameter *settings)
: PPPLayer(name, PPP_DEVICE_LEVEL, overhead), : KPPPLayer(name, PPP_DEVICE_LEVEL, overhead),
fMTU(1500), fMTU(1500),
fInterface(interface), fInterface(interface),
fSettings(settings), fSettings(settings),
@@ -24,7 +24,7 @@ PPPDevice::PPPDevice(const char *name, uint32 overhead, PPPInterface& interface,
} }
PPPDevice::~PPPDevice() KPPPDevice::~KPPPDevice()
{ {
if(Interface().Device() == this) if(Interface().Device() == this)
Interface().SetDevice(NULL); Interface().SetDevice(NULL);
@@ -32,7 +32,7 @@ PPPDevice::~PPPDevice()
status_t status_t
PPPDevice::Control(uint32 op, void *data, size_t length) KPPPDevice::Control(uint32 op, void *data, size_t length)
{ {
switch(op) { switch(op) {
case PPPC_GET_DEVICE_INFO: { case PPPC_GET_DEVICE_INFO: {
@@ -42,7 +42,6 @@ PPPDevice::Control(uint32 op, void *data, size_t length)
ppp_device_info *info = (ppp_device_info*) data; ppp_device_info *info = (ppp_device_info*) data;
memset(info, 0, sizeof(ppp_device_info_t)); memset(info, 0, sizeof(ppp_device_info_t));
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->settings = Settings();
info->MTU = MTU(); info->MTU = MTU();
info->inputTransferRate = InputTransferRate(); info->inputTransferRate = InputTransferRate();
info->outputTransferRate = OutputTransferRate(); info->outputTransferRate = OutputTransferRate();
@@ -59,7 +58,7 @@ PPPDevice::Control(uint32 op, void *data, size_t length)
bool bool
PPPDevice::IsAllowedToSend() const KPPPDevice::IsAllowedToSend() const
{ {
return true; return true;
// our connection status will be reported in Send() // our connection status will be reported in Send()
@@ -67,7 +66,7 @@ PPPDevice::IsAllowedToSend() const
status_t status_t
PPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber) KPPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber)
{ {
// let the interface handle the packet // let the interface handle the packet
if(protocolNumber == 0) if(protocolNumber == 0)
@@ -78,14 +77,14 @@ PPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber)
void void
PPPDevice::Pulse() KPPPDevice::Pulse()
{ {
// do nothing by default // do nothing by default
} }
bool bool
PPPDevice::UpStarted() KPPPDevice::UpStarted()
{ {
fConnectionPhase = PPP_ESTABLISHMENT_PHASE; fConnectionPhase = PPP_ESTABLISHMENT_PHASE;
@@ -94,7 +93,7 @@ PPPDevice::UpStarted()
bool bool
PPPDevice::DownStarted() KPPPDevice::DownStarted()
{ {
fConnectionPhase = PPP_TERMINATION_PHASE; fConnectionPhase = PPP_TERMINATION_PHASE;
@@ -103,7 +102,7 @@ PPPDevice::DownStarted()
void void
PPPDevice::UpFailedEvent() KPPPDevice::UpFailedEvent()
{ {
fConnectionPhase = PPP_DOWN_PHASE; fConnectionPhase = PPP_DOWN_PHASE;
@@ -112,7 +111,7 @@ PPPDevice::UpFailedEvent()
void void
PPPDevice::UpEvent() KPPPDevice::UpEvent()
{ {
fConnectionPhase = PPP_ESTABLISHED_PHASE; fConnectionPhase = PPP_ESTABLISHED_PHASE;
@@ -121,7 +120,7 @@ PPPDevice::UpEvent()
void void
PPPDevice::DownEvent() KPPPDevice::DownEvent()
{ {
fConnectionPhase = PPP_DOWN_PHASE; fConnectionPhase = PPP_DOWN_PHASE;
@@ -5,7 +5,7 @@
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected] // Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// cstdio must be included before PPPModule.h/PPPManager.h because // cstdio must be included before KPPPModule.h/KPPPManager.h because
// ddprintf is defined twice with different return values, once with // ddprintf is defined twice with different return values, once with
// void (KernelExport.h) and once with int (stdio.h). // void (KernelExport.h) and once with int (stdio.h).
#include <cstdio> #include <cstdio>
@@ -39,11 +39,12 @@
// TODO: // TODO:
// - implement timers with support for settings next time instead of receiving timer // - implement timers with support for settings next time instead of receiving timer
// events periodically // events periodically
// - add missing settings support (DialRetryDelay, etc.)
// needed for redial: // needed for redial:
typedef struct redial_info { typedef struct redial_info {
PPPInterface *interface; KPPPInterface *interface;
thread_id *thread; thread_id *thread;
uint32 delay; uint32 delay;
} redial_info; } redial_info;
@@ -56,9 +57,10 @@ status_t call_open_event_thread(void *data);
status_t call_close_event_thread(void *data); status_t call_close_event_thread(void *data);
PPPInterface::PPPInterface(ppp_interface_entry *entry, uint32 ID, KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry,
const driver_settings *settings, PPPInterface *parent = NULL) ppp_interface_id ID, const driver_settings *settings,
: PPPLayer("PPPInterface", PPP_INTERFACE_LEVEL, 2), const driver_settings *profile, KPPPInterface *parent = NULL)
: KPPPLayer(name, PPP_INTERFACE_LEVEL, 2),
fID(ID), fID(ID),
fSettings(dup_driver_settings(settings)), fSettings(dup_driver_settings(settings)),
fIfnet(NULL), fIfnet(NULL),
@@ -85,12 +87,15 @@ PPPInterface::PPPInterface(ppp_interface_entry *entry, uint32 ID,
fFirstProtocol(NULL), fFirstProtocol(NULL),
fStateMachine(*this), fStateMachine(*this),
fLCP(*this), fLCP(*this),
fProfile(*this),
fReportManager(StateMachine().fLock), fReportManager(StateMachine().fLock),
fLock(StateMachine().fLock), fLock(StateMachine().fLock),
fDeleteCounter(0) fDeleteCounter(0)
{ {
entry->interface = this; entry->interface = this;
fProfile.LoadSettings(profile, fSettings);
// add internal modules // add internal modules
// LCP // LCP
if(!AddProtocol(&LCP())) { if(!AddProtocol(&LCP())) {
@@ -98,25 +103,25 @@ PPPInterface::PPPInterface(ppp_interface_entry *entry, uint32 ID,
return; return;
} }
// MRU // MRU
_PPPMRUHandler *mruHandler = _KPPPMRUHandler *mruHandler =
new _PPPMRUHandler(*this); new _KPPPMRUHandler(*this);
if(!LCP().AddOptionHandler(mruHandler) || mruHandler->InitCheck() != B_OK) { if(!LCP().AddOptionHandler(mruHandler) || mruHandler->InitCheck() != B_OK) {
dprintf("PPPInterface: Could not add MRU handler!\n"); dprintf("KPPPInterface: Could not add MRU handler!\n");
delete mruHandler; delete mruHandler;
} }
// authentication // authentication
_PPPAuthenticationHandler *authenticationHandler = _KPPPAuthenticationHandler *authenticationHandler =
new _PPPAuthenticationHandler(*this); new _KPPPAuthenticationHandler(*this);
if(!LCP().AddOptionHandler(authenticationHandler) if(!LCP().AddOptionHandler(authenticationHandler)
|| authenticationHandler->InitCheck() != B_OK) { || authenticationHandler->InitCheck() != B_OK) {
dprintf("PPPInterface: Could not add authentication handler!\n"); dprintf("KPPPInterface: Could not add authentication handler!\n");
delete authenticationHandler; delete authenticationHandler;
} }
// PFC // PFC
_PPPPFCHandler *pfcHandler = _KPPPPFCHandler *pfcHandler =
new _PPPPFCHandler(fLocalPFCState, fPeerPFCState, *this); new _KPPPPFCHandler(fLocalPFCState, fPeerPFCState, *this);
if(!LCP().AddOptionHandler(pfcHandler) || pfcHandler->InitCheck() != B_OK) { if(!LCP().AddOptionHandler(pfcHandler) || pfcHandler->InitCheck() != B_OK) {
dprintf("PPPInterface: Could not add PFC handler!\n"); dprintf("KPPPInterface: Could not add PFC handler!\n");
delete pfcHandler; delete pfcHandler;
} }
@@ -127,7 +132,7 @@ PPPInterface::PPPInterface(ppp_interface_entry *entry, uint32 ID,
// 1s delay between lost connection and redial // 1s delay between lost connection and redial
if(get_module(PPP_INTERFACE_MODULE_NAME, (module_info**) &fManager) != B_OK) if(get_module(PPP_INTERFACE_MODULE_NAME, (module_info**) &fManager) != B_OK)
dprintf("PPPInterface: Manager module not found!\n"); dprintf("KPPPInterface: Manager module not found!\n");
// are we a multilink subinterface? // are we a multilink subinterface?
if(parent && parent->IsMultilink()) { if(parent && parent->IsMultilink()) {
@@ -180,16 +185,16 @@ PPPInterface::PPPInterface(ppp_interface_entry *entry, uint32 ID,
// load all protocols and the device // load all protocols and the device
if(!LoadModules(fSettings, 0, fSettings->parameter_count)) { if(!LoadModules(fSettings, 0, fSettings->parameter_count)) {
dprintf("PPPInterface: Error loading modules!\n"); dprintf("KPPPInterface: Error loading modules!\n");
fInitStatus = B_ERROR; fInitStatus = B_ERROR;
} }
} }
PPPInterface::~PPPInterface() KPPPInterface::~KPPPInterface()
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: Destructor\n"); dprintf("KPPPInterface: Destructor\n");
#endif #endif
++fDeleteCounter; ++fDeleteCounter;
@@ -248,7 +253,7 @@ PPPInterface::~PPPInterface()
void void
PPPInterface::Delete() KPPPInterface::Delete()
{ {
if(atomic_add(&fDeleteCounter, 1) > 0) if(atomic_add(&fDeleteCounter, 1) > 0)
return; return;
@@ -263,14 +268,14 @@ PPPInterface::Delete()
// Spawn a thread that will delete us. // Spawn a thread that will delete us.
thread_id interfaceDeleterThread thread_id interfaceDeleterThread
= spawn_kernel_thread(interface_deleter_thread, = spawn_kernel_thread(interface_deleter_thread,
"PPPInterface: interface_deleter_thread", B_NORMAL_PRIORITY, this); "KPPPInterface: interface_deleter_thread", B_NORMAL_PRIORITY, this);
resume_thread(interfaceDeleterThread); resume_thread(interfaceDeleterThread);
} }
} }
status_t status_t
PPPInterface::InitCheck() const KPPPInterface::InitCheck() const
{ {
if(fInitStatus != B_OK) if(fInitStatus != B_OK)
return fInitStatus; return fInitStatus;
@@ -290,10 +295,10 @@ PPPInterface::InitCheck() const
bool bool
PPPInterface::SetMRU(uint32 MRU) KPPPInterface::SetMRU(uint32 MRU)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: SetMRU(%ld)\n", MRU); dprintf("KPPPInterface: SetMRU(%ld)\n", MRU);
#endif #endif
if(Device() && MRU > Device()->MTU() - 2) if(Device() && MRU > Device()->MTU() - 2)
@@ -310,7 +315,7 @@ PPPInterface::SetMRU(uint32 MRU)
uint32 uint32
PPPInterface::PacketOverhead() const KPPPInterface::PacketOverhead() const
{ {
uint32 overhead = fHeaderLength + 2; uint32 overhead = fHeaderLength + 2;
@@ -322,7 +327,7 @@ PPPInterface::PacketOverhead() const
status_t status_t
PPPInterface::Control(uint32 op, void *data, size_t length) KPPPInterface::Control(uint32 op, void *data, size_t length)
{ {
switch(op) { switch(op) {
case PPPC_GET_INTERFACE_INFO: { case PPPC_GET_INTERFACE_INFO: {
@@ -331,7 +336,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
ppp_interface_info *info = (ppp_interface_info*) data; ppp_interface_info *info = (ppp_interface_info*) data;
memset(info, 0, sizeof(ppp_interface_info_t)); memset(info, 0, sizeof(ppp_interface_info_t));
info->settings = Settings(); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
if(Ifnet()) if(Ifnet())
info->if_unit = Ifnet()->if_unit; info->if_unit = Ifnet()->if_unit;
else else
@@ -386,6 +391,16 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
SetAutoRedial(*((uint32*)data)); SetAutoRedial(*((uint32*)data));
break; break;
case PPPC_HAS_INTERFACE_SETTINGS:
if(length < sizeof(driver_settings) || !data)
return B_ERROR;
if(equal_interface_settings(Settings(), (driver_settings*) data))
return B_OK;
else
return B_ERROR;
break;
case PPPC_ENABLE_REPORTS: { case PPPC_ENABLE_REPORTS: {
if(length < sizeof(ppp_report_request) || !data) if(length < sizeof(ppp_report_request) || !data)
return B_ERROR; return B_ERROR;
@@ -419,7 +434,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
return B_ERROR; return B_ERROR;
ppp_control_info *control = (ppp_control_info*) data; ppp_control_info *control = (ppp_control_info*) data;
PPPProtocol *protocol = ProtocolAt(control->index); KPPPProtocol *protocol = ProtocolAt(control->index);
if(!protocol) if(!protocol)
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -431,7 +446,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
return B_ERROR; return B_ERROR;
ppp_control_info *control = (ppp_control_info*) data; ppp_control_info *control = (ppp_control_info*) data;
PPPOptionHandler *optionHandler = LCP().OptionHandlerAt(control->index); KPPPOptionHandler *optionHandler = LCP().OptionHandlerAt(control->index);
if(!optionHandler) if(!optionHandler)
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -444,7 +459,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
return B_ERROR; return B_ERROR;
ppp_control_info *control = (ppp_control_info*) data; ppp_control_info *control = (ppp_control_info*) data;
PPPLCPExtension *lcpExtension = LCP().LCPExtensionAt(control->index); KPPPLCPExtension *lcpExtension = LCP().LCPExtensionAt(control->index);
if(!lcpExtension) if(!lcpExtension)
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -457,7 +472,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
return B_ERROR; return B_ERROR;
ppp_control_info *control = (ppp_control_info*) data; ppp_control_info *control = (ppp_control_info*) data;
PPPInterface *child = ChildAt(control->index); KPPPInterface *child = ChildAt(control->index);
if(!child) if(!child)
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -473,10 +488,10 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
bool bool
PPPInterface::SetDevice(PPPDevice *device) KPPPInterface::SetDevice(KPPPDevice *device)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: SetDevice(%p)\n", device); dprintf("KPPPInterface: SetDevice(%p)\n", device);
#endif #endif
if(device && &device->Interface() != this) if(device && &device->Interface() != this)
@@ -509,13 +524,13 @@ PPPInterface::SetDevice(PPPDevice *device)
bool bool
PPPInterface::AddProtocol(PPPProtocol *protocol) KPPPInterface::AddProtocol(KPPPProtocol *protocol)
{ {
// Find instert position after the last protocol // Find instert position after the last protocol
// with the same level. // with the same level.
#if DEBUG #if DEBUG
dprintf("PPPInterface: AddProtocol(%X)\n", dprintf("KPPPInterface: AddProtocol(%X)\n",
protocol ? protocol->ProtocolNumber() : 0); protocol ? protocol->ProtocolNumber() : 0);
#endif #endif
@@ -529,7 +544,7 @@ PPPInterface::AddProtocol(PPPProtocol *protocol)
return false; return false;
// a running connection may not change // a running connection may not change
PPPProtocol *current = fFirstProtocol, *previous = NULL; KPPPProtocol *current = fFirstProtocol, *previous = NULL;
while(current) { while(current) {
if(current->Level() < protocol->Level()) if(current->Level() < protocol->Level())
@@ -570,10 +585,10 @@ PPPInterface::AddProtocol(PPPProtocol *protocol)
bool bool
PPPInterface::RemoveProtocol(PPPProtocol *protocol) KPPPInterface::RemoveProtocol(KPPPProtocol *protocol)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: RemoveProtocol(%X)\n", dprintf("KPPPInterface: RemoveProtocol(%X)\n",
protocol ? protocol->ProtocolNumber() : 0); protocol ? protocol->ProtocolNumber() : 0);
#endif #endif
@@ -583,7 +598,7 @@ PPPInterface::RemoveProtocol(PPPProtocol *protocol)
return false; return false;
// a running connection may not change // a running connection may not change
PPPProtocol *current = fFirstProtocol, *previous = NULL; KPPPProtocol *current = fFirstProtocol, *previous = NULL;
while(current) { while(current) {
if(current == protocol) { if(current == protocol) {
@@ -615,9 +630,9 @@ PPPInterface::RemoveProtocol(PPPProtocol *protocol)
int32 int32
PPPInterface::CountProtocols() const KPPPInterface::CountProtocols() const
{ {
PPPProtocol *protocol = FirstProtocol(); KPPPProtocol *protocol = FirstProtocol();
int32 count = 0; int32 count = 0;
for(; protocol; protocol = protocol->NextProtocol()) for(; protocol; protocol = protocol->NextProtocol())
@@ -627,10 +642,10 @@ PPPInterface::CountProtocols() const
} }
PPPProtocol* KPPPProtocol*
PPPInterface::ProtocolAt(int32 index) const KPPPInterface::ProtocolAt(int32 index) const
{ {
PPPProtocol *protocol = FirstProtocol(); KPPPProtocol *protocol = FirstProtocol();
int32 currentIndex = 0; int32 currentIndex = 0;
for(; protocol && currentIndex != index; protocol = protocol->NextProtocol()) for(; protocol && currentIndex != index; protocol = protocol->NextProtocol())
@@ -640,19 +655,19 @@ PPPInterface::ProtocolAt(int32 index) const
} }
PPPProtocol* KPPPProtocol*
PPPInterface::ProtocolFor(uint16 protocolNumber, PPPProtocol *start = NULL) const KPPPInterface::ProtocolFor(uint16 protocolNumber, KPPPProtocol *start = NULL) const
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: ProtocolFor(%X), p&=%X\n", protocolNumber, dprintf("KPPPInterface: ProtocolFor(%X), p&=%X\n", protocolNumber,
protocolNumber & 0x7FFF); protocolNumber & 0x7FFF);
#endif #endif
PPPProtocol *current = start ? start : FirstProtocol(); KPPPProtocol *current = start ? start : FirstProtocol();
for(; current; current = current->NextProtocol()) { for(; current; current = current->NextProtocol()) {
#if DEBUG #if DEBUG
dprintf("PPPInterface: ProtocolFor(): c=%X, c&=%X\n", current->ProtocolNumber(), dprintf("KPPPInterface: ProtocolFor(): c=%X, c&=%X\n", current->ProtocolNumber(),
current->ProtocolNumber() & 0x7FFF); current->ProtocolNumber() & 0x7FFF);
#endif #endif
@@ -668,10 +683,10 @@ PPPInterface::ProtocolFor(uint16 protocolNumber, PPPProtocol *start = NULL) cons
bool bool
PPPInterface::AddChild(PPPInterface *child) KPPPInterface::AddChild(KPPPInterface *child)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: AddChild(%lX)\n", dprintf("KPPPInterface: AddChild(%lX)\n",
child ? child->ID() : 0); child ? child->ID() : 0);
#endif #endif
@@ -690,10 +705,10 @@ PPPInterface::AddChild(PPPInterface *child)
bool bool
PPPInterface::RemoveChild(PPPInterface *child) KPPPInterface::RemoveChild(KPPPInterface *child)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: RemoveChild(%lX)\n", dprintf("KPPPInterface: RemoveChild(%lX)\n",
child ? child->ID() : 0); child ? child->ID() : 0);
#endif #endif
@@ -712,14 +727,14 @@ PPPInterface::RemoveChild(PPPInterface *child)
} }
PPPInterface* KPPPInterface*
PPPInterface::ChildAt(int32 index) const KPPPInterface::ChildAt(int32 index) const
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: ChildAt(%ld)\n", index); dprintf("KPPPInterface: ChildAt(%ld)\n", index);
#endif #endif
PPPInterface *child = fChildren.ItemAt(index); KPPPInterface *child = fChildren.ItemAt(index);
if(child == fChildren.GetDefaultItem()) if(child == fChildren.GetDefaultItem())
return NULL; return NULL;
@@ -729,10 +744,10 @@ PPPInterface::ChildAt(int32 index) const
void void
PPPInterface::SetAutoRedial(bool autoRedial = true) KPPPInterface::SetAutoRedial(bool autoRedial = true)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: SetAutoRedial(%s)\n", autoRedial ? "true" : "false"); dprintf("KPPPInterface: SetAutoRedial(%s)\n", autoRedial ? "true" : "false");
#endif #endif
if(Mode() != PPP_CLIENT_MODE) if(Mode() != PPP_CLIENT_MODE)
@@ -745,19 +760,19 @@ PPPInterface::SetAutoRedial(bool autoRedial = true)
void void
PPPInterface::SetDialOnDemand(bool dialOnDemand = true) KPPPInterface::SetDialOnDemand(bool dialOnDemand = true)
{ {
// All protocols must check if DialOnDemand was enabled/disabled after this // All protocols must check if DialOnDemand was enabled/disabled after this
// interface went down. This is the only situation where a change is relevant. // interface went down. This is the only situation where a change is relevant.
#if DEBUG #if DEBUG
dprintf("PPPInterface: SetDialOnDemand(%s)\n", dialOnDemand ? "true" : "false"); dprintf("KPPPInterface: SetDialOnDemand(%s)\n", dialOnDemand ? "true" : "false");
#endif #endif
// Only clients support DialOnDemand. // Only clients support DialOnDemand.
if(Mode() != PPP_CLIENT_MODE) { if(Mode() != PPP_CLIENT_MODE) {
#if DEBUG #if DEBUG
dprintf("PPPInterface::SetDialOnDemand(): Wrong mode!\n"); dprintf("KPPPInterface::SetDialOnDemand(): Wrong mode!\n");
#endif #endif
fDialOnDemand = false; fDialOnDemand = false;
return; return;
@@ -793,10 +808,10 @@ PPPInterface::SetDialOnDemand(bool dialOnDemand = true)
bool bool
PPPInterface::SetPFCOptions(uint8 pfcOptions) KPPPInterface::SetPFCOptions(uint8 pfcOptions)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: SetPFCOptions(0x%X)\n", pfcOptions); dprintf("KPPPInterface: SetPFCOptions(0x%X)\n", pfcOptions);
#endif #endif
if(PFCOptions() & PPP_FREEZE_PFC_OPTIONS) if(PFCOptions() & PPP_FREEZE_PFC_OPTIONS)
@@ -808,10 +823,10 @@ PPPInterface::SetPFCOptions(uint8 pfcOptions)
bool bool
PPPInterface::Up() KPPPInterface::Up()
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: Up()\n"); dprintf("KPPPInterface: Up()\n");
#endif #endif
if(InitCheck() != B_OK || Phase() == PPP_TERMINATION_PHASE) if(InitCheck() != B_OK || Phase() == PPP_TERMINATION_PHASE)
@@ -841,7 +856,7 @@ PPPInterface::Up()
wait_for_thread(fOpenEventThread, &tmp); wait_for_thread(fOpenEventThread, &tmp);
} }
fOpenEventThread = spawn_kernel_thread(call_open_event_thread, fOpenEventThread = spawn_kernel_thread(call_open_event_thread,
"PPPInterface: call_open_event_thread", B_NORMAL_PRIORITY, this); "KPPPInterface: call_open_event_thread", B_NORMAL_PRIORITY, this);
resume_thread(fOpenEventThread); resume_thread(fOpenEventThread);
} }
fLock.Unlock(); fLock.Unlock();
@@ -859,7 +874,7 @@ PPPInterface::Up()
continue; continue;
//#if DEBUG //#if DEBUG
// dprintf("PPPInterface::Up(): Report: Type = %ld Code = %ld\n", report.type, // dprintf("KPPPInterface::Up(): Report: Type = %ld Code = %ld\n", report.type,
// report.code); // report.code);
//#endif //#endif
@@ -945,7 +960,7 @@ PPPInterface::Up()
if(report.code == PPP_REPORT_DEVICE_UP_FAILED) { if(report.code == PPP_REPORT_DEVICE_UP_FAILED) {
if(fDialRetry >= fDialRetriesLimit) { if(fDialRetry >= fDialRetriesLimit) {
#if DEBUG #if DEBUG
dprintf("PPPInterface::Up(): DEVICE_UP_FAILED: >=maxretries!\n"); dprintf("KPPPInterface::Up(): DEVICE_UP_FAILED: >=maxretries!\n");
#endif #endif
fDialRetry = 0; fDialRetry = 0;
fUpThread = -1; fUpThread = -1;
@@ -958,12 +973,12 @@ PPPInterface::Up()
return false; return false;
} else { } else {
#if DEBUG #if DEBUG
dprintf("PPPInterface::Up(): DEVICE_UP_FAILED: <maxretries\n"); dprintf("KPPPInterface::Up(): DEVICE_UP_FAILED: <maxretries\n");
#endif #endif
++fDialRetry; ++fDialRetry;
PPP_REPLY(sender, B_OK); PPP_REPLY(sender, B_OK);
#if DEBUG #if DEBUG
dprintf("PPPInterface::Up(): DEVICE_UP_FAILED: replied\n"); dprintf("KPPPInterface::Up(): DEVICE_UP_FAILED: replied\n");
#endif #endif
Redial(DialRetryDelay()); Redial(DialRetryDelay());
continue; continue;
@@ -999,10 +1014,10 @@ PPPInterface::Up()
bool bool
PPPInterface::Down() KPPPInterface::Down()
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: Down()\n"); dprintf("KPPPInterface: Down()\n");
#endif #endif
if(InitCheck() != B_OK) if(InitCheck() != B_OK)
@@ -1028,7 +1043,7 @@ PPPInterface::Down()
} }
fCloseEventThread = spawn_kernel_thread(call_close_event_thread, fCloseEventThread = spawn_kernel_thread(call_close_event_thread,
"PPPInterface: call_close_event_thread", B_NORMAL_PRIORITY, this); "KPPPInterface: call_close_event_thread", B_NORMAL_PRIORITY, this);
resume_thread(fCloseEventThread); resume_thread(fCloseEventThread);
locker.UnlockNow(); locker.UnlockNow();
@@ -1058,7 +1073,7 @@ PPPInterface::Down()
bool bool
PPPInterface::IsUp() const KPPPInterface::IsUp() const
{ {
LockerHelper locker(fLock); LockerHelper locker(fLock);
@@ -1067,10 +1082,10 @@ PPPInterface::IsUp() const
bool bool
PPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count) KPPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: LoadModules()\n"); dprintf("KPPPInterface: LoadModules()\n");
#endif #endif
if(Phase() != PPP_DOWN_PHASE) if(Phase() != PPP_DOWN_PHASE)
@@ -1098,7 +1113,7 @@ PPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
if(IsMultilink() && !Parent()) { if(IsMultilink() && !Parent()) {
// main interfaces only load the multilink module // main interfaces only load the multilink module
// and create a child using their settings // and create a child using their settings
fManager->CreateInterface(settings, ID()); fManager->CreateInterface(settings, Profile().Settings(), ID());
return true; return true;
} }
@@ -1130,11 +1145,11 @@ PPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
bool bool
PPPInterface::LoadModule(const char *name, driver_parameter *parameter, KPPPInterface::LoadModule(const char *name, driver_parameter *parameter,
ppp_module_key_type type) ppp_module_key_type type)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: LoadModule(%s)\n", name ? name : "XXX: NO NAME"); dprintf("KPPPInterface: LoadModule(%s)\n", name ? name : "XXX: NO NAME");
#endif #endif
if(Phase() != PPP_DOWN_PHASE) if(Phase() != PPP_DOWN_PHASE)
@@ -1161,17 +1176,17 @@ PPPInterface::LoadModule(const char *name, driver_parameter *parameter,
bool bool
PPPInterface::IsAllowedToSend() const KPPPInterface::IsAllowedToSend() const
{ {
return true; return true;
} }
status_t status_t
PPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: Send(0x%X)\n", protocolNumber); dprintf("KPPPInterface: Send(0x%X)\n", protocolNumber);
#endif #endif
if(!packet) if(!packet)
@@ -1195,28 +1210,28 @@ PPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
} }
// find the protocol handler for the current protocol number // find the protocol handler for the current protocol number
PPPProtocol *protocol = ProtocolFor(protocolNumber); KPPPProtocol *protocol = ProtocolFor(protocolNumber);
while(protocol && !protocol->IsEnabled()) while(protocol && !protocol->IsEnabled())
protocol = protocol->NextProtocol() ? protocol = protocol->NextProtocol() ?
ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL; ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL;
#if DEBUG #if DEBUG
if(!protocol) if(!protocol)
dprintf("PPPInterface::Send(): no protocol found!\n"); dprintf("KPPPInterface::Send(): no protocol found!\n");
else if(!Device()->IsUp()) else if(!Device()->IsUp())
dprintf("PPPInterface::Send(): device is not up!\n"); dprintf("KPPPInterface::Send(): device is not up!\n");
else if(!protocol->IsEnabled()) else if(!protocol->IsEnabled())
dprintf("PPPInterface::Send(): protocol not enabled!\n"); dprintf("KPPPInterface::Send(): protocol not enabled!\n");
else if(!IsProtocolAllowed(*protocol)) else if(!IsProtocolAllowed(*protocol))
dprintf("PPPInterface::Send(): protocol not allowed to send!\n"); dprintf("KPPPInterface::Send(): protocol not allowed to send!\n");
else else
dprintf("PPPInterface::Send(): protocol allowed\n"); dprintf("KPPPInterface::Send(): protocol allowed\n");
#endif #endif
// make sure that protocol is allowed to send and everything is up // make sure that protocol is allowed to send and everything is up
if(!Device()->IsUp() || !protocol || !protocol->IsEnabled() if(!Device()->IsUp() || !protocol || !protocol->IsEnabled()
|| !IsProtocolAllowed(*protocol)) { || !IsProtocolAllowed(*protocol)) {
dprintf("PPPInterface::Send(): cannot send!\n"); dprintf("KPPPInterface::Send(): cannot send!\n");
m_freem(packet); m_freem(packet);
return B_ERROR; return B_ERROR;
} }
@@ -1262,10 +1277,10 @@ PPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
status_t status_t
PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber) KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: Receive(0x%X)\n", protocolNumber); dprintf("KPPPInterface: Receive(0x%X)\n", protocolNumber);
#endif #endif
if(!packet) if(!packet)
@@ -1288,12 +1303,12 @@ PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
// The handler does need not be up because if we are a server // The handler does need not be up because if we are a server
// the handler might be upped by this packet. // the handler might be upped by this packet.
// If authenticating we only allow authentication phase protocols. // If authenticating we only allow authentication phase protocols.
PPPProtocol *protocol = ProtocolFor(protocolNumber); KPPPProtocol *protocol = ProtocolFor(protocolNumber);
for(; protocol; for(; protocol;
protocol = protocol->NextProtocol() ? protocol = protocol->NextProtocol() ?
ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL) { ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL) {
#if DEBUG #if DEBUG
dprintf("PPPInterface::Receive(): trying protocol\n"); dprintf("KPPPInterface::Receive(): trying protocol\n");
#endif #endif
if(!protocol->IsEnabled() || !IsProtocolAllowed(*protocol)) if(!protocol->IsEnabled() || !IsProtocolAllowed(*protocol))
@@ -1308,7 +1323,7 @@ PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
} }
#if DEBUG #if DEBUG
dprintf("PPPInterface::Receive(): trying parent\n"); dprintf("KPPPInterface::Receive(): trying parent\n");
#endif #endif
// maybe the parent interface can handle the packet // maybe the parent interface can handle the packet
@@ -1326,10 +1341,10 @@ PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
status_t status_t
PPPInterface::ReceiveFromDevice(struct mbuf *packet) KPPPInterface::ReceiveFromDevice(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: ReceiveFromDevice()\n"); dprintf("KPPPInterface: ReceiveFromDevice()\n");
#endif #endif
if(!packet) if(!packet)
@@ -1354,12 +1369,12 @@ PPPInterface::ReceiveFromDevice(struct mbuf *packet)
void void
PPPInterface::Pulse() KPPPInterface::Pulse()
{ {
if(Device()) if(Device())
Device()->Pulse(); Device()->Pulse();
PPPProtocol *protocol = FirstProtocol(); KPPPProtocol *protocol = FirstProtocol();
for(; protocol; protocol = protocol->NextProtocol()) for(; protocol; protocol = protocol->NextProtocol())
protocol->Pulse(); protocol->Pulse();
@@ -1371,10 +1386,10 @@ PPPInterface::Pulse()
bool bool
PPPInterface::RegisterInterface() KPPPInterface::RegisterInterface()
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: RegisterInterface()\n"); dprintf("KPPPInterface: RegisterInterface()\n");
#endif #endif
if(fIfnet) if(fIfnet)
@@ -1406,10 +1421,10 @@ PPPInterface::RegisterInterface()
bool bool
PPPInterface::UnregisterInterface() KPPPInterface::UnregisterInterface()
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: UnregisterInterface()\n"); dprintf("KPPPInterface: UnregisterInterface()\n");
#endif #endif
if(!fIfnet) if(!fIfnet)
@@ -1433,12 +1448,12 @@ PPPInterface::UnregisterInterface()
} }
// called by PPPManager: manager routes stack ioctls to interface // called by KPPPManager: manager routes stack ioctls to interface
status_t status_t
PPPInterface::StackControl(uint32 op, void *data) KPPPInterface::StackControl(uint32 op, void *data)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: StackControl(0x%lX)\n", op); dprintf("KPPPInterface: StackControl(0x%lX)\n", op);
#endif #endif
switch(op) { switch(op) {
@@ -1478,15 +1493,15 @@ class CallStackControl {
// B_BAD_VALUE: no handler was found // B_BAD_VALUE: no handler was found
// any other value: the error value that was returned by the last handler that failed // any other value: the error value that was returned by the last handler that failed
status_t status_t
PPPInterface::StackControlEachHandler(uint32 op, void *data) KPPPInterface::StackControlEachHandler(uint32 op, void *data)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: StackControlEachHandler(0x%lX)\n", op); dprintf("KPPPInterface: StackControlEachHandler(0x%lX)\n", op);
#endif #endif
status_t result = B_BAD_VALUE, tmp; status_t result = B_BAD_VALUE, tmp;
PPPProtocol *protocol = FirstProtocol(); KPPPProtocol *protocol = FirstProtocol();
for(; protocol; protocol = protocol->NextProtocol()) { for(; protocol; protocol = protocol->NextProtocol()) {
tmp = protocol->StackControl(op, data); tmp = protocol->StackControl(op, data);
if(tmp == B_OK && result == B_BAD_VALUE) if(tmp == B_OK && result == B_BAD_VALUE)
@@ -1496,26 +1511,26 @@ PPPInterface::StackControlEachHandler(uint32 op, void *data)
} }
ForEachItem(LCP().fLCPExtensions, ForEachItem(LCP().fLCPExtensions,
CallStackControl<PPPLCPExtension>(op, data, result)); CallStackControl<KPPPLCPExtension>(op, data, result));
ForEachItem(LCP().fOptionHandlers, ForEachItem(LCP().fOptionHandlers,
CallStackControl<PPPOptionHandler>(op, data, result)); CallStackControl<KPPPOptionHandler>(op, data, result));
return result; return result;
} }
void void
PPPInterface::CalculateInterfaceMTU() KPPPInterface::CalculateInterfaceMTU()
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: CalculateInterfaceMTU()\n"); dprintf("KPPPInterface: CalculateInterfaceMTU()\n");
#endif #endif
fInterfaceMTU = fMRU; fInterfaceMTU = fMRU;
fHeaderLength = 2; fHeaderLength = 2;
// sum all headers (the protocol field is not counted) // sum all headers (the protocol field is not counted)
PPPProtocol *protocol = FirstProtocol(); KPPPProtocol *protocol = FirstProtocol();
for(; protocol; protocol = protocol->NextProtocol()) { for(; protocol; protocol = protocol->NextProtocol()) {
if(protocol->Level() < PPP_PROTOCOL_LEVEL) if(protocol->Level() < PPP_PROTOCOL_LEVEL)
fHeaderLength += protocol->Overhead(); fHeaderLength += protocol->Overhead();
@@ -1534,10 +1549,10 @@ PPPInterface::CalculateInterfaceMTU()
void void
PPPInterface::CalculateBaudRate() KPPPInterface::CalculateBaudRate()
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: CalculateBaudRate()\n"); dprintf("KPPPInterface: CalculateBaudRate()\n");
#endif #endif
if(!Ifnet()) if(!Ifnet())
@@ -1556,10 +1571,10 @@ PPPInterface::CalculateBaudRate()
void void
PPPInterface::Redial(uint32 delay) KPPPInterface::Redial(uint32 delay)
{ {
#if DEBUG #if DEBUG
dprintf("PPPInterface: Redial(%ld)\n", delay); dprintf("KPPPInterface: Redial(%ld)\n", delay);
#endif #endif
if(fRedialThread != -1) if(fRedialThread != -1)
@@ -1571,7 +1586,7 @@ PPPInterface::Redial(uint32 delay)
info.thread = &fRedialThread; info.thread = &fRedialThread;
info.delay = delay; info.delay = delay;
fRedialThread = spawn_kernel_thread(redial_thread, "PPPInterface: redial_thread", fRedialThread = spawn_kernel_thread(redial_thread, "KPPPInterface: redial_thread",
B_NORMAL_PRIORITY, NULL); B_NORMAL_PRIORITY, NULL);
resume_thread(fRedialThread); resume_thread(fRedialThread);
@@ -1608,13 +1623,13 @@ redial_thread(void *data)
// ---------------------------------- // ----------------------------------
// Function: interface_deleter_thread // Function: interface_deleter_thread
// ---------------------------------- // ----------------------------------
class PPPInterfaceAccess { class KPPPInterfaceAccess {
public: public:
PPPInterfaceAccess() {} KPPPInterfaceAccess() {}
void Delete(PPPInterface *interface) void Delete(KPPPInterface *interface)
{ delete interface; } { delete interface; }
void CallOpenEvent(PPPInterface *interface) void CallOpenEvent(KPPPInterface *interface)
{ {
while(interface->fLock.LockWithTimeout(100000) != B_NO_ERROR) while(interface->fLock.LockWithTimeout(100000) != B_NO_ERROR)
if(interface->fDeleteCounter > 0) if(interface->fDeleteCounter > 0)
@@ -1623,7 +1638,7 @@ class PPPInterfaceAccess {
interface->fOpenEventThread = -1; interface->fOpenEventThread = -1;
interface->fLock.Unlock(); interface->fLock.Unlock();
} }
void CallCloseEvent(PPPInterface *interface) void CallCloseEvent(KPPPInterface *interface)
{ {
while(interface->fLock.LockWithTimeout(100000) != B_NO_ERROR) while(interface->fLock.LockWithTimeout(100000) != B_NO_ERROR)
if(interface->fDeleteCounter > 0) if(interface->fDeleteCounter > 0)
@@ -1638,8 +1653,8 @@ class PPPInterfaceAccess {
status_t status_t
interface_deleter_thread(void *data) interface_deleter_thread(void *data)
{ {
PPPInterfaceAccess access; KPPPInterfaceAccess access;
access.Delete((PPPInterface*) data); access.Delete((KPPPInterface*) data);
return B_OK; return B_OK;
} }
@@ -1648,8 +1663,8 @@ interface_deleter_thread(void *data)
status_t status_t
call_open_event_thread(void *data) call_open_event_thread(void *data)
{ {
PPPInterfaceAccess access; KPPPInterfaceAccess access;
access.CallOpenEvent((PPPInterface*) data); access.CallOpenEvent((KPPPInterface*) data);
return B_OK; return B_OK;
} }
@@ -1658,8 +1673,8 @@ call_open_event_thread(void *data)
status_t status_t
call_close_event_thread(void *data) call_close_event_thread(void *data)
{ {
PPPInterfaceAccess access; KPPPInterfaceAccess access;
access.CallCloseEvent((PPPInterface*) data); access.CallCloseEvent((KPPPInterface*) data);
return B_OK; return B_OK;
} }
@@ -17,8 +17,8 @@
#include <sys/socket.h> #include <sys/socket.h>
PPPLCP::PPPLCP(PPPInterface& interface) KPPPLCP::KPPPLCP(KPPPInterface& interface)
: PPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL, PPP_PROTOCOL_LEVEL, : KPPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL, PPP_PROTOCOL_LEVEL,
AF_UNSPEC, 0, interface, NULL, PPP_ALWAYS_ALLOWED), AF_UNSPEC, 0, interface, NULL, PPP_ALWAYS_ALLOWED),
fStateMachine(interface.StateMachine()), fStateMachine(interface.StateMachine()),
fTarget(NULL) fTarget(NULL)
@@ -28,7 +28,7 @@ PPPLCP::PPPLCP(PPPInterface& interface)
} }
PPPLCP::~PPPLCP() KPPPLCP::~KPPPLCP()
{ {
while(CountOptionHandlers()) while(CountOptionHandlers())
delete OptionHandlerAt(0); delete OptionHandlerAt(0);
@@ -38,7 +38,7 @@ PPPLCP::~PPPLCP()
bool bool
PPPLCP::AddOptionHandler(PPPOptionHandler *optionHandler) KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler)
{ {
if(!optionHandler || &optionHandler->Interface() != &Interface()) if(!optionHandler || &optionHandler->Interface() != &Interface())
return false; return false;
@@ -55,7 +55,7 @@ PPPLCP::AddOptionHandler(PPPOptionHandler *optionHandler)
bool bool
PPPLCP::RemoveOptionHandler(PPPOptionHandler *optionHandler) KPPPLCP::RemoveOptionHandler(KPPPOptionHandler *optionHandler)
{ {
LockerHelper locker(StateMachine().fLock); LockerHelper locker(StateMachine().fLock);
@@ -67,10 +67,10 @@ PPPLCP::RemoveOptionHandler(PPPOptionHandler *optionHandler)
} }
PPPOptionHandler* KPPPOptionHandler*
PPPLCP::OptionHandlerAt(int32 index) const KPPPLCP::OptionHandlerAt(int32 index) const
{ {
PPPOptionHandler *optionHandler = fOptionHandlers.ItemAt(index); KPPPOptionHandler *optionHandler = fOptionHandlers.ItemAt(index);
if(optionHandler == fOptionHandlers.GetDefaultItem()) if(optionHandler == fOptionHandlers.GetDefaultItem())
return NULL; return NULL;
@@ -79,8 +79,8 @@ PPPLCP::OptionHandlerAt(int32 index) const
} }
PPPOptionHandler* KPPPOptionHandler*
PPPLCP::OptionHandlerFor(uint8 type, int32 *start = NULL) const KPPPLCP::OptionHandlerFor(uint8 type, int32 *start = NULL) const
{ {
// The iteration style in this method is strange C/C++. // The iteration style in this method is strange C/C++.
// Explanation: I use this style because it makes extending all XXXFor // Explanation: I use this style because it makes extending all XXXFor
@@ -91,7 +91,7 @@ PPPLCP::OptionHandlerFor(uint8 type, int32 *start = NULL) const
if(index < 0) if(index < 0)
return NULL; return NULL;
PPPOptionHandler *current = OptionHandlerAt(index); KPPPOptionHandler *current = OptionHandlerAt(index);
for(; current; current = OptionHandlerAt(++index)) { for(; current; current = OptionHandlerAt(++index)) {
if(current->Type() == type) { if(current->Type() == type) {
@@ -106,7 +106,7 @@ PPPLCP::OptionHandlerFor(uint8 type, int32 *start = NULL) const
bool bool
PPPLCP::AddLCPExtension(PPPLCPExtension *lcpExtension) KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension)
{ {
if(!lcpExtension || &lcpExtension->Interface() != &Interface()) if(!lcpExtension || &lcpExtension->Interface() != &Interface())
return false; return false;
@@ -122,7 +122,7 @@ PPPLCP::AddLCPExtension(PPPLCPExtension *lcpExtension)
bool bool
PPPLCP::RemoveLCPExtension(PPPLCPExtension *lcpExtension) KPPPLCP::RemoveLCPExtension(KPPPLCPExtension *lcpExtension)
{ {
LockerHelper locker(StateMachine().fLock); LockerHelper locker(StateMachine().fLock);
@@ -134,10 +134,10 @@ PPPLCP::RemoveLCPExtension(PPPLCPExtension *lcpExtension)
} }
PPPLCPExtension* KPPPLCPExtension*
PPPLCP::LCPExtensionAt(int32 index) const KPPPLCP::LCPExtensionAt(int32 index) const
{ {
PPPLCPExtension *lcpExtension = fLCPExtensions.ItemAt(index); KPPPLCPExtension *lcpExtension = fLCPExtensions.ItemAt(index);
if(lcpExtension == fLCPExtensions.GetDefaultItem()) if(lcpExtension == fLCPExtensions.GetDefaultItem())
return NULL; return NULL;
@@ -146,8 +146,8 @@ PPPLCP::LCPExtensionAt(int32 index) const
} }
PPPLCPExtension* KPPPLCPExtension*
PPPLCP::LCPExtensionFor(uint8 code, int32 *start = NULL) const KPPPLCP::LCPExtensionFor(uint8 code, int32 *start = NULL) const
{ {
// The iteration style in this method is strange C/C++. // The iteration style in this method is strange C/C++.
// Explanation: I use this style because it makes extending all XXXFor // Explanation: I use this style because it makes extending all XXXFor
@@ -158,7 +158,7 @@ PPPLCP::LCPExtensionFor(uint8 code, int32 *start = NULL) const
if(index < 0) if(index < 0)
return NULL; return NULL;
PPPLCPExtension *current = LCPExtensionAt(index); KPPPLCPExtension *current = LCPExtensionAt(index);
for(; current; current = LCPExtensionAt(++index)) { for(; current; current = LCPExtensionAt(++index)) {
if(current->Code() == code) { if(current->Code() == code) {
@@ -173,7 +173,7 @@ PPPLCP::LCPExtensionFor(uint8 code, int32 *start = NULL) const
uint32 uint32
PPPLCP::AdditionalOverhead() const KPPPLCP::AdditionalOverhead() const
{ {
uint32 overhead = Interface().Overhead(); uint32 overhead = Interface().Overhead();
@@ -188,21 +188,21 @@ PPPLCP::AdditionalOverhead() const
bool bool
PPPLCP::Up() KPPPLCP::Up()
{ {
return true; return true;
} }
bool bool
PPPLCP::Down() KPPPLCP::Down()
{ {
return true; return true;
} }
status_t status_t
PPPLCP::Send(struct mbuf *packet, uint16 protocolNumber = PPP_LCP_PROTOCOL) KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber = PPP_LCP_PROTOCOL)
{ {
if(Target()) if(Target())
return Target()->Send(packet, PPP_LCP_PROTOCOL); return Target()->Send(packet, PPP_LCP_PROTOCOL);
@@ -212,13 +212,13 @@ PPPLCP::Send(struct mbuf *packet, uint16 protocolNumber = PPP_LCP_PROTOCOL)
status_t status_t
PPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
{ {
if(!packet) if(!packet)
return B_ERROR; return B_ERROR;
if(protocolNumber != PPP_LCP_PROTOCOL) { if(protocolNumber != PPP_LCP_PROTOCOL) {
dprintf("PPPLCP::Receive(): wrong protocol number!\n"); dprintf("KPPPLCP::Receive(): wrong protocol number!\n");
return PPP_UNHANDLED; return PPP_UNHANDLED;
} }
@@ -295,7 +295,7 @@ PPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
// Try to find LCP extensions that can handle this code. // Try to find LCP extensions that can handle this code.
// We must duplicate the packet in order to ask all handlers. // We must duplicate the packet in order to ask all handlers.
int32 index = 0; int32 index = 0;
PPPLCPExtension *lcpExtension = LCPExtensionFor(data->code, &index); KPPPLCPExtension *lcpExtension = LCPExtensionFor(data->code, &index);
for(; lcpExtension; lcpExtension = LCPExtensionFor(data->code, &(++index))) { for(; lcpExtension; lcpExtension = LCPExtensionFor(data->code, &(++index))) {
if(!lcpExtension->IsEnabled()) if(!lcpExtension->IsEnabled())
continue; continue;
@@ -323,7 +323,7 @@ PPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
void void
PPPLCP::Pulse() KPPPLCP::Pulse()
{ {
StateMachine().TimerEvent(); StateMachine().TimerEvent();
@@ -10,7 +10,7 @@
#include <PPPControl.h> #include <PPPControl.h>
PPPLCPExtension::PPPLCPExtension(const char *name, uint8 code, PPPInterface& interface, KPPPLCPExtension::KPPPLCPExtension(const char *name, uint8 code, KPPPInterface& interface,
driver_parameter *settings) driver_parameter *settings)
: fInterface(interface), : fInterface(interface),
fSettings(settings), fSettings(settings),
@@ -24,7 +24,7 @@ PPPLCPExtension::PPPLCPExtension(const char *name, uint8 code, PPPInterface& int
} }
PPPLCPExtension::~PPPLCPExtension() KPPPLCPExtension::~KPPPLCPExtension()
{ {
free(fName); free(fName);
@@ -33,14 +33,14 @@ PPPLCPExtension::~PPPLCPExtension()
status_t status_t
PPPLCPExtension::InitCheck() const KPPPLCPExtension::InitCheck() const
{ {
return fInitStatus; return fInitStatus;
} }
status_t status_t
PPPLCPExtension::Control(uint32 op, void *data, size_t length) KPPPLCPExtension::Control(uint32 op, void *data, size_t length)
{ {
switch(op) { switch(op) {
case PPPC_GET_SIMPLE_HANDLER_INFO: { case PPPC_GET_SIMPLE_HANDLER_INFO: {
@@ -50,7 +50,6 @@ PPPLCPExtension::Control(uint32 op, void *data, size_t length)
ppp_simple_handler_info *info = (ppp_simple_handler_info*) data; ppp_simple_handler_info *info = (ppp_simple_handler_info*) data;
memset(info, 0, sizeof(ppp_simple_handler_info_t)); memset(info, 0, sizeof(ppp_simple_handler_info_t));
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->settings = Settings();
info->isEnabled = IsEnabled(); info->isEnabled = IsEnabled();
} break; } break;
@@ -70,7 +69,7 @@ PPPLCPExtension::Control(uint32 op, void *data, size_t length)
status_t status_t
PPPLCPExtension::StackControl(uint32 op, void *data) KPPPLCPExtension::StackControl(uint32 op, void *data)
{ {
switch(op) { switch(op) {
default: default:
@@ -82,14 +81,14 @@ PPPLCPExtension::StackControl(uint32 op, void *data)
void void
PPPLCPExtension::Reset() KPPPLCPExtension::Reset()
{ {
// do nothing by default // do nothing by default
} }
void void
PPPLCPExtension::Pulse() KPPPLCPExtension::Pulse()
{ {
// do nothing by default // do nothing by default
} }
@@ -16,34 +16,31 @@
#include <core_funcs.h> #include <core_funcs.h>
PPPLayer::PPPLayer(const char *name, ppp_level level, uint32 overhead) KPPPLayer::KPPPLayer(const char *name, ppp_level level, uint32 overhead)
: fInitStatus(B_OK), : fInitStatus(B_OK),
fOverhead(overhead), fOverhead(overhead),
fLevel(level), fLevel(level),
fNext(NULL) fNext(NULL)
{ {
if(name) SetName(name);
fName = strdup(name);
else
fName = strdup("Unknown");
} }
PPPLayer::~PPPLayer() KPPPLayer::~KPPPLayer()
{ {
free(fName); free(fName);
} }
status_t status_t
PPPLayer::InitCheck() const KPPPLayer::InitCheck() const
{ {
return fInitStatus; return fInitStatus;
} }
status_t status_t
PPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
{ {
if(!packet) if(!packet)
return B_ERROR; return B_ERROR;
@@ -56,7 +53,7 @@ PPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
else else
return Next()->SendToNext(packet, protocolNumber); return Next()->SendToNext(packet, protocolNumber);
} else { } else {
dprintf("PPPLayer: SendToNext() failed because there is no next handler!\n"); dprintf("KPPPLayer: SendToNext() failed because there is no next handler!\n");
m_freem(packet); m_freem(packet);
return B_ERROR; return B_ERROR;
} }
@@ -64,7 +61,19 @@ PPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
void void
PPPLayer::Pulse() KPPPLayer::Pulse()
{ {
// do nothing by default // do nothing by default
} }
void
KPPPLayer::SetName(const char *name)
{
free(fName);
if(name)
fName = strdup(name);
else
fName = strdup("Unknown");
}
@@ -10,8 +10,8 @@
#include <PPPControl.h> #include <PPPControl.h>
PPPOptionHandler::PPPOptionHandler(const char *name, uint8 type, KPPPOptionHandler::KPPPOptionHandler(const char *name, uint8 type,
PPPInterface& interface, driver_parameter *settings) KPPPInterface& interface, driver_parameter *settings)
: fInitStatus(B_OK), : fInitStatus(B_OK),
fType(type), fType(type),
fInterface(interface), fInterface(interface),
@@ -25,7 +25,7 @@ PPPOptionHandler::PPPOptionHandler(const char *name, uint8 type,
} }
PPPOptionHandler::~PPPOptionHandler() KPPPOptionHandler::~KPPPOptionHandler()
{ {
free(fName); free(fName);
@@ -34,14 +34,14 @@ PPPOptionHandler::~PPPOptionHandler()
status_t status_t
PPPOptionHandler::InitCheck() const KPPPOptionHandler::InitCheck() const
{ {
return fInitStatus; return fInitStatus;
} }
status_t status_t
PPPOptionHandler::Control(uint32 op, void *data, size_t length) KPPPOptionHandler::Control(uint32 op, void *data, size_t length)
{ {
switch(op) { switch(op) {
case PPPC_GET_SIMPLE_HANDLER_INFO: { case PPPC_GET_SIMPLE_HANDLER_INFO: {
@@ -51,7 +51,6 @@ PPPOptionHandler::Control(uint32 op, void *data, size_t length)
ppp_simple_handler_info *info = (ppp_simple_handler_info*) data; ppp_simple_handler_info *info = (ppp_simple_handler_info*) data;
memset(info, 0, sizeof(ppp_simple_handler_info_t)); memset(info, 0, sizeof(ppp_simple_handler_info_t));
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->settings = Settings();
info->isEnabled = IsEnabled(); info->isEnabled = IsEnabled();
} break; } break;
@@ -71,7 +70,7 @@ PPPOptionHandler::Control(uint32 op, void *data, size_t length)
status_t status_t
PPPOptionHandler::StackControl(uint32 op, void *data) KPPPOptionHandler::StackControl(uint32 op, void *data)
{ {
switch(op) { switch(op) {
default: default:
@@ -0,0 +1,134 @@
//-----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
//-----------------------------------------------------------------------
/*! \class KPPPProfile
\brief Manages profiles for KPPPInterface.
PPP modules should store their user-specific and private settings in profiles.
This allows one interface description to be used by multiple users although
they have different logins. Temporary profiles are used when you enter a password
in the connection prompt.
PPP servers may use \c Request() to communicate with the userland PPP add-ons.
These add-ons could, for instance, forward all requests to a central server or
database.
*/
#include <cstdio>
#include <KPPPInterface.h>
#include "settings_tools.h"
//! Initializes profile.
KPPPProfile::KPPPProfile(KPPPInterface& interface)
: fInterface(interface),
fSettings(NULL)
{
}
//! Frees profile settings.
KPPPProfile::~KPPPProfile()
{
if(fSettings != Interface().Settings())
free_driver_settings(fSettings);
}
/*! \brief Loads profile settings.
Search order for profiles:
- given profile
- profile mentioned in interface settings ("profile $type { name $name }")
- profile description file with name of this interface
- the interface's settings (to stay compatible with the simple in-settings
description format)
\param profile The dynamically created profile for this interface (if defined).
\param interfaceSettings The interface's settings.
*/
void
KPPPProfile::LoadSettings(const driver_settings *profile,
driver_settings *interfaceSettings)
{
// -----------------------------
// given profile
// -----------------------------
if(profile) {
fSettings = dup_driver_settings(profile);
return;
}
// -----------------------------
// profile in settings and
// profile with interface's name
// TODO: try /etc/ppp/profile if local profile could not be found
// -----------------------------
const char *name = NULL;
char path[B_PATH_NAME_LENGTH];
const driver_parameter *parameter = get_parameter_with_name("profile",
interfaceSettings);
// TODO: add support for "ppp_server" profile type
if(parameter && parameter->value_count > 0 && parameter->parameter_count > 0
&& !strcasecmp(parameter->values[0], "file"))
name = get_parameter_value("name", parameter);
else if(Interface().Name())
name = Interface().Name();
if(name) {
sprintf(path, "pppidf/profile/%s", name);
void *handle = load_driver_settings(path);
fSettings = dup_driver_settings(get_driver_settings(handle));
if(handle)
unload_driver_settings(handle);
if(fSettings)
return;
}
// -----------------------------
// interface's settings
// -----------------------------
fSettings = interfaceSettings;
}
/*! \brief Finds a parameter with name \a type that has a value of \a name.
This method is intended for modules.
\param type Module's type (e.g.: "authenticator").
\param name Module's name (e.g.: "pap").
\return
\c NULL: No parameter was found.
*/
const driver_parameter*
KPPPProfile::SettingsFor(const char *type, const char *name) const
{
if(!Settings() || !type)
return NULL;
const driver_parameter *parameter;
for(int32 index = 0; index < Settings()->parameter_count; index++) {
parameter = &Settings()->parameters[index];
if(!strcasecmp(parameter->name, type)) {
if(name) {
for(int32 valueIndex = 0; valueIndex < parameter->value_count;
valueIndex++)
if(!strcasecmp(parameter->values[index], name))
return parameter;
} else
return parameter;
}
}
return NULL;
}
@@ -13,12 +13,12 @@
#include <cstring> #include <cstring>
PPPProtocol::PPPProtocol(const char *name, ppp_phase activationPhase, KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase,
uint16 protocolNumber, ppp_level level, int32 addressFamily, uint16 protocolNumber, ppp_level level, int32 addressFamily,
uint32 overhead, PPPInterface& interface, uint32 overhead, KPPPInterface& interface,
driver_parameter *settings, int32 flags = PPP_NO_FLAGS, driver_parameter *settings, int32 flags = PPP_NO_FLAGS,
const char *type = NULL, PPPOptionHandler *optionHandler = NULL) const char *type = NULL, KPPPOptionHandler *optionHandler = NULL)
: PPPLayer(name, level, overhead), : KPPPLayer(name, level, overhead),
fActivationPhase(activationPhase), fActivationPhase(activationPhase),
fProtocolNumber(protocolNumber), fProtocolNumber(protocolNumber),
fAddressFamily(addressFamily), fAddressFamily(addressFamily),
@@ -48,7 +48,7 @@ PPPProtocol::PPPProtocol(const char *name, ppp_phase activationPhase,
} }
PPPProtocol::~PPPProtocol() KPPPProtocol::~KPPPProtocol()
{ {
Interface().RemoveProtocol(this); Interface().RemoveProtocol(this);
@@ -57,7 +57,7 @@ PPPProtocol::~PPPProtocol()
status_t status_t
PPPProtocol::Control(uint32 op, void *data, size_t length) KPPPProtocol::Control(uint32 op, void *data, size_t length)
{ {
switch(op) { switch(op) {
case PPPC_GET_PROTOCOL_INFO: { case PPPC_GET_PROTOCOL_INFO: {
@@ -68,7 +68,6 @@ PPPProtocol::Control(uint32 op, void *data, size_t length)
memset(info, 0, sizeof(ppp_protocol_info_t)); memset(info, 0, sizeof(ppp_protocol_info_t));
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
strncpy(info->type, Type(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->type, Type(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->settings = Settings();
info->activationPhase = ActivationPhase(); info->activationPhase = ActivationPhase();
info->addressFamily = AddressFamily(); info->addressFamily = AddressFamily();
info->flags = Flags(); info->flags = Flags();
@@ -97,7 +96,7 @@ PPPProtocol::Control(uint32 op, void *data, size_t length)
status_t status_t
PPPProtocol::StackControl(uint32 op, void *data) KPPPProtocol::StackControl(uint32 op, void *data)
{ {
switch(op) { switch(op) {
default: default:
@@ -109,7 +108,7 @@ PPPProtocol::StackControl(uint32 op, void *data)
void void
PPPProtocol::SetEnabled(bool enabled = true) KPPPProtocol::SetEnabled(bool enabled = true)
{ {
fEnabled = enabled; fEnabled = enabled;
@@ -122,28 +121,28 @@ PPPProtocol::SetEnabled(bool enabled = true)
bool bool
PPPProtocol::IsAllowedToSend() const KPPPProtocol::IsAllowedToSend() const
{ {
return IsEnabled() && IsUp() && IsProtocolAllowed(*this); return IsEnabled() && IsUp() && IsProtocolAllowed(*this);
} }
void void
PPPProtocol::UpStarted() KPPPProtocol::UpStarted()
{ {
fConnectionPhase = PPP_ESTABLISHMENT_PHASE; fConnectionPhase = PPP_ESTABLISHMENT_PHASE;
} }
void void
PPPProtocol::DownStarted() KPPPProtocol::DownStarted()
{ {
fConnectionPhase = PPP_TERMINATION_PHASE; fConnectionPhase = PPP_TERMINATION_PHASE;
} }
void void
PPPProtocol::UpFailedEvent() KPPPProtocol::UpFailedEvent()
{ {
fConnectionPhase = PPP_DOWN_PHASE; fConnectionPhase = PPP_DOWN_PHASE;
@@ -152,7 +151,7 @@ PPPProtocol::UpFailedEvent()
void void
PPPProtocol::UpEvent() KPPPProtocol::UpEvent()
{ {
fConnectionPhase = PPP_ESTABLISHED_PHASE; fConnectionPhase = PPP_ESTABLISHED_PHASE;
@@ -161,7 +160,7 @@ PPPProtocol::UpEvent()
void void
PPPProtocol::DownEvent() KPPPProtocol::DownEvent()
{ {
fConnectionPhase = PPP_DOWN_PHASE; fConnectionPhase = PPP_DOWN_PHASE;
@@ -11,13 +11,13 @@
#include <KPPPUtils.h> #include <KPPPUtils.h>
PPPReportManager::PPPReportManager(BLocker& lock) KPPPReportManager::KPPPReportManager(BLocker& lock)
: fLock(lock) : fLock(lock)
{ {
} }
PPPReportManager::~PPPReportManager() KPPPReportManager::~KPPPReportManager()
{ {
for(int32 index = 0; index < fReportRequests.CountItems(); index++) for(int32 index = 0; index < fReportRequests.CountItems(); index++)
delete fReportRequests.ItemAt(index); delete fReportRequests.ItemAt(index);
@@ -25,7 +25,7 @@ PPPReportManager::~PPPReportManager()
void void
PPPReportManager::EnableReports(ppp_report_type type, thread_id thread, KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread,
int32 flags = PPP_NO_FLAGS) int32 flags = PPP_NO_FLAGS)
{ {
LockerHelper locker(fLock); LockerHelper locker(fLock);
@@ -40,7 +40,7 @@ PPPReportManager::EnableReports(ppp_report_type type, thread_id thread,
void void
PPPReportManager::DisableReports(ppp_report_type type, thread_id thread) KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread)
{ {
LockerHelper locker(fLock); LockerHelper locker(fLock);
@@ -59,7 +59,7 @@ PPPReportManager::DisableReports(ppp_report_type type, thread_id thread)
bool bool
PPPReportManager::DoesReport(ppp_report_type type, thread_id thread) KPPPReportManager::DoesReport(ppp_report_type type, thread_id thread)
{ {
LockerHelper locker(fLock); LockerHelper locker(fLock);
@@ -77,10 +77,10 @@ PPPReportManager::DoesReport(ppp_report_type type, thread_id thread)
bool bool
PPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 length) KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 length)
{ {
#if DEBUG #if DEBUG
dprintf("PPPReportManager: Report(type=%d code=%ld length=%ld) to %ld receivers\n", dprintf("KPPPReportManager: Report(type=%d code=%ld length=%ld) to %ld receivers\n",
type, code, length, fReportRequests.CountItems()); type, code, length, fReportRequests.CountItems());
#endif #endif
@@ -119,7 +119,7 @@ PPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 len
#if DEBUG #if DEBUG
if(result == B_TIMED_OUT) if(result == B_TIMED_OUT)
dprintf("PPPReportManager::Report(): timed out sending\n"); dprintf("KPPPReportManager::Report(): timed out sending\n");
#endif #endif
if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) { if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) {
@@ -159,7 +159,7 @@ PPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 len
acceptable = false; acceptable = false;
#if DEBUG #if DEBUG
if(result == B_TIMED_OUT) if(result == B_TIMED_OUT)
dprintf("PPPReportManager::Report(): reply timed out\n"); dprintf("KPPPReportManager::Report(): reply timed out\n");
#endif #endif
} }
} }
@@ -171,7 +171,7 @@ PPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 len
} }
#if DEBUG #if DEBUG
dprintf("PPPReportManager::Report(): returning: %s\n", acceptable?"true":"false"); dprintf("KPPPReportManager::Report(): returning: %s\n", acceptable?"true":"false");
#endif #endif
return acceptable; return acceptable;
@@ -13,6 +13,8 @@
#include <KPPPLCPExtension.h> #include <KPPPLCPExtension.h>
#include <KPPPOptionHandler.h> #include <KPPPOptionHandler.h>
#include <LockerHelper.h>
#include <net/if.h> #include <net/if.h>
#include <core_funcs.h> #include <core_funcs.h>
@@ -21,7 +23,7 @@
// 3 seconds // 3 seconds
PPPStateMachine::PPPStateMachine(PPPInterface& interface) KPPPStateMachine::KPPPStateMachine(KPPPInterface& interface)
: fInterface(interface), : fInterface(interface),
fLCP(interface.LCP()), fLCP(interface.LCP()),
fState(PPP_INITIAL_STATE), fState(PPP_INITIAL_STATE),
@@ -43,7 +45,7 @@ PPPStateMachine::PPPStateMachine(PPPInterface& interface)
} }
PPPStateMachine::~PPPStateMachine() KPPPStateMachine::~KPPPStateMachine()
{ {
free(fLocalAuthenticationName); free(fLocalAuthenticationName);
free(fPeerAuthenticationName); free(fPeerAuthenticationName);
@@ -51,7 +53,7 @@ PPPStateMachine::~PPPStateMachine()
uint8 uint8
PPPStateMachine::NextID() KPPPStateMachine::NextID()
{ {
return (uint8) atomic_add(&fID, 1); return (uint8) atomic_add(&fID, 1);
} }
@@ -60,10 +62,10 @@ PPPStateMachine::NextID()
// remember: NewState() must always be called _after_ IllegalEvent() // remember: NewState() must always be called _after_ IllegalEvent()
// because IllegalEvent() also looks at the current state. // because IllegalEvent() also looks at the current state.
void void
PPPStateMachine::NewState(ppp_state next) KPPPStateMachine::NewState(ppp_state next)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: NewState(%d) state=%d\n", next, State()); dprintf("KPPPSM: NewState(%d) state=%d\n", next, State());
#endif #endif
// maybe we do not need the timer anymore // maybe we do not need the timer anymore
@@ -78,11 +80,11 @@ PPPStateMachine::NewState(ppp_state next)
void void
PPPStateMachine::NewPhase(ppp_phase next) KPPPStateMachine::NewPhase(ppp_phase next)
{ {
#if DEBUG #if DEBUG
if(next <= PPP_ESTABLISHMENT_PHASE || next == PPP_ESTABLISHED_PHASE) if(next <= PPP_ESTABLISHMENT_PHASE || next == PPP_ESTABLISHED_PHASE)
dprintf("PPPSM: NewPhase(%d) phase=%d\n", next, Phase()); dprintf("KPPPSM: NewPhase(%d) phase=%d\n", next, Phase());
#endif #endif
// there is nothing after established phase and nothing before down phase // there is nothing after established phase and nothing before down phase
@@ -119,10 +121,10 @@ PPPStateMachine::NewPhase(ppp_phase next)
// public actions // public actions
bool bool
PPPStateMachine::Reconfigure() KPPPStateMachine::Reconfigure()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: Reconfigure() state=%d phase=%d\n", dprintf("KPPPSM: Reconfigure() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -145,10 +147,10 @@ PPPStateMachine::Reconfigure()
bool bool
PPPStateMachine::SendEchoRequest() KPPPStateMachine::SendEchoRequest()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendEchoRequest() state=%d phase=%d\n", dprintf("KPPPSM: SendEchoRequest() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -175,10 +177,10 @@ PPPStateMachine::SendEchoRequest()
bool bool
PPPStateMachine::SendDiscardRequest() KPPPStateMachine::SendDiscardRequest()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendDiscardRequest() state=%d phase=%d\n", dprintf("KPPPSM: SendDiscardRequest() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -205,10 +207,10 @@ PPPStateMachine::SendDiscardRequest()
// authentication events // authentication events
void void
PPPStateMachine::LocalAuthenticationRequested() KPPPStateMachine::LocalAuthenticationRequested()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: LocalAuthenticationRequested() state=%d phase=%d\n", dprintf("KPPPSM: LocalAuthenticationRequested() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -221,10 +223,10 @@ PPPStateMachine::LocalAuthenticationRequested()
void void
PPPStateMachine::LocalAuthenticationAccepted(const char *name) KPPPStateMachine::LocalAuthenticationAccepted(const char *name)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: LocalAuthenticationAccepted() state=%d phase=%d\n", dprintf("KPPPSM: LocalAuthenticationAccepted() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -244,10 +246,10 @@ PPPStateMachine::LocalAuthenticationAccepted(const char *name)
void void
PPPStateMachine::LocalAuthenticationDenied(const char *name) KPPPStateMachine::LocalAuthenticationDenied(const char *name)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: LocalAuthenticationDenied() state=%d phase=%d\n", dprintf("KPPPSM: LocalAuthenticationDenied() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -263,10 +265,10 @@ PPPStateMachine::LocalAuthenticationDenied(const char *name)
void void
PPPStateMachine::PeerAuthenticationRequested() KPPPStateMachine::PeerAuthenticationRequested()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: PeerAuthenticationRequested() state=%d phase=%d\n", dprintf("KPPPSM: PeerAuthenticationRequested() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -279,10 +281,10 @@ PPPStateMachine::PeerAuthenticationRequested()
void void
PPPStateMachine::PeerAuthenticationAccepted(const char *name) KPPPStateMachine::PeerAuthenticationAccepted(const char *name)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: PeerAuthenticationAccepted() state=%d phase=%d\n", dprintf("KPPPSM: PeerAuthenticationAccepted() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -302,10 +304,10 @@ PPPStateMachine::PeerAuthenticationAccepted(const char *name)
void void
PPPStateMachine::PeerAuthenticationDenied(const char *name) KPPPStateMachine::PeerAuthenticationDenied(const char *name)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: PeerAuthenticationDenied() state=%d phase=%d\n", dprintf("KPPPSM: PeerAuthenticationDenied() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -323,10 +325,10 @@ PPPStateMachine::PeerAuthenticationDenied(const char *name)
void void
PPPStateMachine::UpFailedEvent(PPPInterface& interface) KPPPStateMachine::UpFailedEvent(KPPPInterface& interface)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: UpFailedEvent(interface) state=%d phase=%d\n", dprintf("KPPPSM: UpFailedEvent(interface) state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -336,10 +338,10 @@ PPPStateMachine::UpFailedEvent(PPPInterface& interface)
void void
PPPStateMachine::UpEvent(PPPInterface& interface) KPPPStateMachine::UpEvent(KPPPInterface& interface)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: UpEvent(interface) state=%d phase=%d\n", dprintf("KPPPSM: UpEvent(interface) state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -366,10 +368,10 @@ PPPStateMachine::UpEvent(PPPInterface& interface)
void void
PPPStateMachine::DownEvent(PPPInterface& interface) KPPPStateMachine::DownEvent(KPPPInterface& interface)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: DownEvent(interface) state=%d phase=%d\n", dprintf("KPPPSM: DownEvent(interface) state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -383,7 +385,7 @@ PPPStateMachine::DownEvent(PPPInterface& interface)
// when all children are down we should not be running // when all children are down we should not be running
if(Interface().IsMultilink() && !Interface().Parent()) { if(Interface().IsMultilink() && !Interface().Parent()) {
uint32 count = 0; uint32 count = 0;
PPPInterface *child; KPPPInterface *child;
for(int32 index = 0; index < Interface().CountChildren(); index++) { for(int32 index = 0; index < Interface().CountChildren(); index++) {
child = Interface().ChildAt(index); child = Interface().ChildAt(index);
@@ -412,10 +414,10 @@ PPPStateMachine::DownEvent(PPPInterface& interface)
void void
PPPStateMachine::UpFailedEvent(PPPProtocol *protocol) KPPPStateMachine::UpFailedEvent(KPPPProtocol *protocol)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: UpFailedEvent(protocol) state=%d phase=%d\n", dprintf("KPPPSM: UpFailedEvent(protocol) state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -437,10 +439,10 @@ PPPStateMachine::UpFailedEvent(PPPProtocol *protocol)
void void
PPPStateMachine::UpEvent(PPPProtocol *protocol) KPPPStateMachine::UpEvent(KPPPProtocol *protocol)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: UpEvent(protocol) state=%d phase=%d\n", dprintf("KPPPSM: UpEvent(protocol) state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -452,10 +454,10 @@ PPPStateMachine::UpEvent(PPPProtocol *protocol)
void void
PPPStateMachine::DownEvent(PPPProtocol *protocol) KPPPStateMachine::DownEvent(KPPPProtocol *protocol)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: DownEvent(protocol) state=%d phase=%d\n", dprintf("KPPPSM: DownEvent(protocol) state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
} }
@@ -467,10 +469,10 @@ PPPStateMachine::DownEvent(PPPProtocol *protocol)
// The return value says if we are waiting for an UpEvent(). If false is // The return value says if we are waiting for an UpEvent(). If false is
// returned the device should immediately abort its attempt to connect. // returned the device should immediately abort its attempt to connect.
bool bool
PPPStateMachine::TLSNotify() KPPPStateMachine::TLSNotify()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: TLSNotify() state=%d phase=%d\n", dprintf("KPPPSM: TLSNotify() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -492,10 +494,10 @@ PPPStateMachine::TLSNotify()
// If false is returned we want to stay connected, though we called // If false is returned we want to stay connected, though we called
// Device::Down(). // Device::Down().
bool bool
PPPStateMachine::TLFNotify() KPPPStateMachine::TLFNotify()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: TLFNotify() state=%d phase=%d\n", dprintf("KPPPSM: TLFNotify() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -509,10 +511,10 @@ PPPStateMachine::TLFNotify()
void void
PPPStateMachine::UpFailedEvent() KPPPStateMachine::UpFailedEvent()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: UpFailedEvent() state=%d phase=%d\n", dprintf("KPPPSM: UpFailedEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -537,10 +539,10 @@ PPPStateMachine::UpFailedEvent()
void void
PPPStateMachine::UpEvent() KPPPStateMachine::UpEvent()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: UpEvent() state=%d phase=%d\n", dprintf("KPPPSM: UpEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -602,10 +604,10 @@ PPPStateMachine::UpEvent()
void void
PPPStateMachine::DownEvent() KPPPStateMachine::DownEvent()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: DownEvent() state=%d phase=%d\n", dprintf("KPPPSM: DownEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -706,10 +708,10 @@ PPPStateMachine::DownEvent()
// private events // private events
void void
PPPStateMachine::OpenEvent() KPPPStateMachine::OpenEvent()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: OpenEvent() state=%d phase=%d\n", dprintf("KPPPSM: OpenEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -772,10 +774,10 @@ PPPStateMachine::OpenEvent()
void void
PPPStateMachine::CloseEvent() KPPPStateMachine::CloseEvent()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: CloseEvent() state=%d phase=%d\n", dprintf("KPPPSM: CloseEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -841,10 +843,10 @@ PPPStateMachine::CloseEvent()
// timeout (restart counters are > 0) // timeout (restart counters are > 0)
void void
PPPStateMachine::TOGoodEvent() KPPPStateMachine::TOGoodEvent()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: TOGoodEvent() state=%d phase=%d\n", dprintf("KPPPSM: TOGoodEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -874,10 +876,10 @@ PPPStateMachine::TOGoodEvent()
// timeout (restart counters are <= 0) // timeout (restart counters are <= 0)
void void
PPPStateMachine::TOBadEvent() KPPPStateMachine::TOBadEvent()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: TOBadEvent() state=%d phase=%d\n", dprintf("KPPPSM: TOBadEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -909,10 +911,10 @@ PPPStateMachine::TOBadEvent()
// receive configure request (acceptable request) // receive configure request (acceptable request)
void void
PPPStateMachine::RCRGoodEvent(struct mbuf *packet) KPPPStateMachine::RCRGoodEvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RCRGoodEvent() state=%d phase=%d\n", dprintf("KPPPSM: RCRGoodEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -970,10 +972,10 @@ PPPStateMachine::RCRGoodEvent(struct mbuf *packet)
// receive configure request (unacceptable request) // receive configure request (unacceptable request)
void void
PPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RCRBadEvent() state=%d phase=%d\n", dprintf("KPPPSM: RCRBadEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1031,10 +1033,10 @@ PPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject)
// receive configure ack // receive configure ack
void void
PPPStateMachine::RCAEvent(struct mbuf *packet) KPPPStateMachine::RCAEvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RCAEvent() state=%d phase=%d\n", dprintf("KPPPSM: RCAEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1050,8 +1052,8 @@ PPPStateMachine::RCAEvent(struct mbuf *packet)
} }
// let the option handlers parse this ack // let the option handlers parse this ack
PPPConfigurePacket ack(packet); KPPPConfigurePacket ack(packet);
PPPOptionHandler *optionHandler; KPPPOptionHandler *optionHandler;
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) {
optionHandler = LCP().OptionHandlerAt(index); optionHandler = LCP().OptionHandlerAt(index);
if(optionHandler->ParseAck(ack) != B_OK) { if(optionHandler->ParseAck(ack) != B_OK) {
@@ -1111,10 +1113,10 @@ PPPStateMachine::RCAEvent(struct mbuf *packet)
// receive configure nak/reject // receive configure nak/reject
void void
PPPStateMachine::RCNEvent(struct mbuf *packet) KPPPStateMachine::RCNEvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RCNEvent() state=%d phase=%d\n", dprintf("KPPPSM: RCNEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1130,8 +1132,8 @@ PPPStateMachine::RCNEvent(struct mbuf *packet)
} }
// let the option handlers parse this nak/reject // let the option handlers parse this nak/reject
PPPConfigurePacket nak_reject(packet); KPPPConfigurePacket nak_reject(packet);
PPPOptionHandler *optionHandler; KPPPOptionHandler *optionHandler;
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) {
optionHandler = LCP().OptionHandlerAt(index); optionHandler = LCP().OptionHandlerAt(index);
@@ -1194,10 +1196,10 @@ PPPStateMachine::RCNEvent(struct mbuf *packet)
// receive terminate request // receive terminate request
void void
PPPStateMachine::RTREvent(struct mbuf *packet) KPPPStateMachine::RTREvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RTREvent() state=%d phase=%d\n", dprintf("KPPPSM: RTREvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1247,10 +1249,10 @@ PPPStateMachine::RTREvent(struct mbuf *packet)
// receive terminate ack // receive terminate ack
void void
PPPStateMachine::RTAEvent(struct mbuf *packet) KPPPStateMachine::RTAEvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RTAEvent() state=%d phase=%d\n", dprintf("KPPPSM: RTAEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1306,11 +1308,11 @@ PPPStateMachine::RTAEvent(struct mbuf *packet)
// receive unknown code // receive unknown code
void void
PPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber, KPPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber,
uint8 code = PPP_PROTOCOL_REJECT) uint8 code = PPP_PROTOCOL_REJECT)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RUCEvent() state=%d phase=%d\n", dprintf("KPPPSM: RUCEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1332,10 +1334,10 @@ PPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber,
// receive code/protocol reject (acceptable such as IPX reject) // receive code/protocol reject (acceptable such as IPX reject)
void void
PPPStateMachine::RXJGoodEvent(struct mbuf *packet) KPPPStateMachine::RXJGoodEvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RXJGoodEvent() state=%d phase=%d\n", dprintf("KPPPSM: RXJGoodEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1361,10 +1363,10 @@ PPPStateMachine::RXJGoodEvent(struct mbuf *packet)
// receive code/protocol reject (catastrophic such as LCP reject) // receive code/protocol reject (catastrophic such as LCP reject)
void void
PPPStateMachine::RXJBadEvent(struct mbuf *packet) KPPPStateMachine::RXJBadEvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RXJBadEvent() state=%d phase=%d\n", dprintf("KPPPSM: RXJBadEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1414,10 +1416,10 @@ PPPStateMachine::RXJBadEvent(struct mbuf *packet)
// receive echo request/reply, discard request // receive echo request/reply, discard request
void void
PPPStateMachine::RXREvent(struct mbuf *packet) KPPPStateMachine::RXREvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RXREvent() state=%d phase=%d\n", dprintf("KPPPSM: RXREvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1450,11 +1452,11 @@ PPPStateMachine::RXREvent(struct mbuf *packet)
// general events (for Good/Bad events) // general events (for Good/Bad events)
void void
PPPStateMachine::TimerEvent() KPPPStateMachine::TimerEvent()
{ {
#if DEBUG #if DEBUG
if(fNextTimeout != 0) if(fNextTimeout != 0)
dprintf("PPPSM: TimerEvent()\n"); dprintf("KPPPSM: TimerEvent()\n");
#endif #endif
LockerHelper locker(fLock); LockerHelper locker(fLock);
@@ -1491,16 +1493,16 @@ PPPStateMachine::TimerEvent()
// Here we get a configure-request packet from LCP and aks all OptionHandlers // Here we get a configure-request packet from LCP and aks all OptionHandlers
// if its values are acceptable. From here we call our Good/Bad counterparts. // if its values are acceptable. From here we call our Good/Bad counterparts.
void void
PPPStateMachine::RCREvent(struct mbuf *packet) KPPPStateMachine::RCREvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RCREvent() state=%d phase=%d\n", dprintf("KPPPSM: RCREvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
PPPConfigurePacket request(packet); KPPPConfigurePacket request(packet);
PPPConfigurePacket nak(PPP_CONFIGURE_NAK); KPPPConfigurePacket nak(PPP_CONFIGURE_NAK);
PPPConfigurePacket reject(PPP_CONFIGURE_REJECT); KPPPConfigurePacket reject(PPP_CONFIGURE_REJECT);
// we should not use the same id as the peer // we should not use the same id as the peer
if(fID == mtod(packet, ppp_lcp_packet*)->id) if(fID == mtod(packet, ppp_lcp_packet*)->id)
@@ -1512,19 +1514,19 @@ PPPStateMachine::RCREvent(struct mbuf *packet)
// each handler should add unacceptable values for each item // each handler should add unacceptable values for each item
status_t result; status_t result;
// the return value of ParseRequest() // the return value of ParseRequest()
PPPOptionHandler *optionHandler; KPPPOptionHandler *optionHandler;
for(int32 index = 0; index < request.CountItems(); index++) { for(int32 index = 0; index < request.CountItems(); index++) {
optionHandler = LCP().OptionHandlerFor(request.ItemAt(index)->type); optionHandler = LCP().OptionHandlerFor(request.ItemAt(index)->type);
if(!optionHandler || !optionHandler->IsEnabled()) { if(!optionHandler || !optionHandler->IsEnabled()) {
dprintf("PPPSM::RCREvent(): unknown type:%d\n", request.ItemAt(index)->type); dprintf("KPPPSM::RCREvent(): unknown type:%d\n", request.ItemAt(index)->type);
// unhandled items should be added to the reject // unhandled items should be added to the reject
reject.AddItem(request.ItemAt(index)); reject.AddItem(request.ItemAt(index));
continue; continue;
} }
#if DEBUG #if DEBUG
dprintf("PPPSM::RCREvent(): OH=%s\n", optionHandler->Name()); dprintf("KPPPSM::RCREvent(): OH=%s\n", optionHandler->Name());
#endif #endif
result = optionHandler->ParseRequest(request, index, nak, reject); result = optionHandler->ParseRequest(request, index, nak, reject);
@@ -1535,7 +1537,7 @@ PPPStateMachine::RCREvent(struct mbuf *packet)
} else if(result != B_OK) { } else if(result != B_OK) {
// the request contains a value that has been sent more than // the request contains a value that has been sent more than
// once or the value is corrupted // once or the value is corrupted
dprintf("PPPSM::RCREvent(): OptionHandler returned parse error!\n"); dprintf("KPPPSM::RCREvent(): OptionHandler returned parse error!\n");
m_freem(packet); m_freem(packet);
CloseEvent(); CloseEvent();
return; return;
@@ -1554,7 +1556,7 @@ PPPStateMachine::RCREvent(struct mbuf *packet)
if(result != B_OK) { if(result != B_OK) {
// the request contains a value that has been sent more than // the request contains a value that has been sent more than
// once or the value is corrupted // once or the value is corrupted
dprintf("PPPSM::RCREvent(): OptionHandler returned append error!\n"); dprintf("KPPPSM::RCREvent(): OptionHandler returned append error!\n");
m_freem(packet); m_freem(packet);
CloseEvent(); CloseEvent();
return; return;
@@ -1578,10 +1580,10 @@ PPPStateMachine::RCREvent(struct mbuf *packet)
// LCP received a code/protocol-reject packet and we look if it is acceptable. // LCP received a code/protocol-reject packet and we look if it is acceptable.
// From here we call our Good/Bad counterparts. // From here we call our Good/Bad counterparts.
void void
PPPStateMachine::RXJEvent(struct mbuf *packet) KPPPStateMachine::RXJEvent(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: RXJEvent() state=%d phase=%d\n", dprintf("KPPPSM: RXJEvent() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1604,7 +1606,7 @@ PPPStateMachine::RXJEvent(struct mbuf *packet)
} }
// find the LCP extension and disable it // find the LCP extension and disable it
PPPLCPExtension *lcpExtension; KPPPLCPExtension *lcpExtension;
for(int32 index = 0; index < LCP().CountLCPExtensions(); index++) { for(int32 index = 0; index < LCP().CountLCPExtensions(); index++) {
lcpExtension = LCP().LCPExtensionAt(index); lcpExtension = LCP().LCPExtensionAt(index);
@@ -1625,7 +1627,7 @@ PPPStateMachine::RXJEvent(struct mbuf *packet)
} }
// disable protocols with the rejected protocol number // disable protocols with the rejected protocol number
PPPProtocol *protocol = Interface().FirstProtocol(); KPPPProtocol *protocol = Interface().FirstProtocol();
for(; protocol; protocol = protocol->NextProtocol()) { for(; protocol; protocol = protocol->NextProtocol()) {
if(protocol->ProtocolNumber() == rejected) if(protocol->ProtocolNumber() == rejected)
protocol->SetEnabled(false); protocol->SetEnabled(false);
@@ -1646,20 +1648,20 @@ PPPStateMachine::RXJEvent(struct mbuf *packet)
// actions (all private) // actions (all private)
void void
PPPStateMachine::IllegalEvent(ppp_event event) KPPPStateMachine::IllegalEvent(ppp_event event)
{ {
// TODO: // TODO:
// update error statistics // update error statistics
dprintf("PPPSM: IllegalEvent(event=%d) state=%d phase=%d\n", dprintf("KPPPSM: IllegalEvent(event=%d) state=%d phase=%d\n",
event, State(), Phase()); event, State(), Phase());
} }
void void
PPPStateMachine::ThisLayerUp() KPPPStateMachine::ThisLayerUp()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: ThisLayerUp() state=%d phase=%d\n", dprintf("KPPPSM: ThisLayerUp() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1681,23 +1683,23 @@ PPPStateMachine::ThisLayerUp()
void void
PPPStateMachine::ThisLayerDown() KPPPStateMachine::ThisLayerDown()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: ThisLayerDown() state=%d phase=%d\n", dprintf("KPPPSM: ThisLayerDown() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
// PPPProtocol::Down() should block if needed. // KPPPProtocol::Down() should block if needed.
DownProtocols(); DownProtocols();
} }
void void
PPPStateMachine::ThisLayerStarted() KPPPStateMachine::ThisLayerStarted()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: ThisLayerStarted() state=%d phase=%d\n", dprintf("KPPPSM: ThisLayerStarted() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1707,10 +1709,10 @@ PPPStateMachine::ThisLayerStarted()
void void
PPPStateMachine::ThisLayerFinished() KPPPStateMachine::ThisLayerFinished()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: ThisLayerFinished() state=%d phase=%d\n", dprintf("KPPPSM: ThisLayerFinished() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1720,7 +1722,7 @@ PPPStateMachine::ThisLayerFinished()
void void
PPPStateMachine::InitializeRestartCount() KPPPStateMachine::InitializeRestartCount()
{ {
fRequestCounter = fMaxRequest; fRequestCounter = fMaxRequest;
fTerminateCounter = fMaxTerminate; fTerminateCounter = fMaxTerminate;
@@ -1729,7 +1731,7 @@ PPPStateMachine::InitializeRestartCount()
void void
PPPStateMachine::ZeroRestartCount() KPPPStateMachine::ZeroRestartCount()
{ {
fRequestCounter = 0; fRequestCounter = 0;
fTerminateCounter = 0; fTerminateCounter = 0;
@@ -1738,10 +1740,10 @@ PPPStateMachine::ZeroRestartCount()
bool bool
PPPStateMachine::SendConfigureRequest() KPPPStateMachine::SendConfigureRequest()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendConfigureRequest() state=%d phase=%d\n", dprintf("KPPPSM: SendConfigureRequest() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1750,7 +1752,7 @@ PPPStateMachine::SendConfigureRequest()
fNextTimeout = system_time() + PPP_STATE_MACHINE_TIMEOUT; fNextTimeout = system_time() + PPP_STATE_MACHINE_TIMEOUT;
locker.UnlockNow(); locker.UnlockNow();
PPPConfigurePacket request(PPP_CONFIGURE_REQUEST); KPPPConfigurePacket request(PPP_CONFIGURE_REQUEST);
request.SetID(NextID()); request.SetID(NextID());
fRequestID = request.ID(); fRequestID = request.ID();
@@ -1768,10 +1770,10 @@ PPPStateMachine::SendConfigureRequest()
bool bool
PPPStateMachine::SendConfigureAck(struct mbuf *packet) KPPPStateMachine::SendConfigureAck(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendConfigureAck() state=%d phase=%d\n", dprintf("KPPPSM: SendConfigureAck() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1779,7 +1781,7 @@ PPPStateMachine::SendConfigureAck(struct mbuf *packet)
return false; return false;
mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK; mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK;
PPPConfigurePacket ack(packet); KPPPConfigurePacket ack(packet);
// notify all option handlers that we are sending an ack for each value // notify all option handlers that we are sending an ack for each value
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) {
@@ -1795,10 +1797,10 @@ PPPStateMachine::SendConfigureAck(struct mbuf *packet)
bool bool
PPPStateMachine::SendConfigureNak(struct mbuf *packet) KPPPStateMachine::SendConfigureNak(struct mbuf *packet)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendConfigureNak() state=%d phase=%d\n", dprintf("KPPPSM: SendConfigureNak() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1819,10 +1821,10 @@ PPPStateMachine::SendConfigureNak(struct mbuf *packet)
bool bool
PPPStateMachine::SendTerminateRequest() KPPPStateMachine::SendTerminateRequest()
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendTerminateRequest() state=%d phase=%d\n", dprintf("KPPPSM: SendTerminateRequest() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1850,10 +1852,10 @@ PPPStateMachine::SendTerminateRequest()
bool bool
PPPStateMachine::SendTerminateAck(struct mbuf *request = NULL) KPPPStateMachine::SendTerminateAck(struct mbuf *request = NULL)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendTerminateAck() state=%d phase=%d\n", dprintf("KPPPSM: SendTerminateAck() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1882,10 +1884,10 @@ PPPStateMachine::SendTerminateAck(struct mbuf *request = NULL)
bool bool
PPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uint8 code) KPPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uint8 code)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendCodeReject(protocolNumber=%X;code=%d) state=%d phase=%d\n", dprintf("KPPPSM: SendCodeReject(protocolNumber=%X;code=%d) state=%d phase=%d\n",
protocolNumber, code, State(), Phase()); protocolNumber, code, State(), Phase());
#endif #endif
@@ -1929,10 +1931,10 @@ PPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uint
bool bool
PPPStateMachine::SendEchoReply(struct mbuf *request) KPPPStateMachine::SendEchoReply(struct mbuf *request)
{ {
#if DEBUG #if DEBUG
dprintf("PPPSM: SendEchoReply() state=%d phase=%d\n", dprintf("KPPPSM: SendEchoReply() state=%d phase=%d\n",
State(), Phase()); State(), Phase());
#endif #endif
@@ -1955,7 +1957,7 @@ PPPStateMachine::SendEchoReply(struct mbuf *request)
// methods for bringing protocols up // methods for bringing protocols up
void void
PPPStateMachine::BringProtocolsUp() KPPPStateMachine::BringProtocolsUp()
{ {
// use a simple check for phase changes (e.g., caused by CloseEvent()) // use a simple check for phase changes (e.g., caused by CloseEvent())
while(Phase() <= PPP_ESTABLISHED_PHASE && Phase() >= PPP_AUTHENTICATION_PHASE) { while(Phase() <= PPP_ESTABLISHED_PHASE && Phase() >= PPP_AUTHENTICATION_PHASE) {
@@ -1979,7 +1981,7 @@ PPPStateMachine::BringProtocolsUp()
// this returns the number of handlers waiting to go up // this returns the number of handlers waiting to go up
uint32 uint32
PPPStateMachine::BringPhaseUp() KPPPStateMachine::BringPhaseUp()
{ {
// Servers do not need to bring all protocols up. // Servers do not need to bring all protocols up.
// The client specifies which protocols he wants to go up. // The client specifies which protocols he wants to go up.
@@ -1991,7 +1993,7 @@ PPPStateMachine::BringPhaseUp()
return 0; return 0;
uint32 count = 0; uint32 count = 0;
PPPProtocol *protocol = Interface().FirstProtocol(); KPPPProtocol *protocol = Interface().FirstProtocol();
for(; protocol; protocol = protocol->NextProtocol()) { for(; protocol; protocol = protocol->NextProtocol()) {
if(protocol->IsEnabled() && protocol->ActivationPhase() == Phase()) { if(protocol->IsEnabled() && protocol->ActivationPhase() == Phase()) {
if(protocol->IsGoingUp() && Interface().Mode() == PPP_CLIENT_MODE) if(protocol->IsGoingUp() && Interface().Mode() == PPP_CLIENT_MODE)
@@ -2016,9 +2018,9 @@ PPPStateMachine::BringPhaseUp()
void void
PPPStateMachine::DownProtocols() KPPPStateMachine::DownProtocols()
{ {
PPPProtocol *protocol = Interface().FirstProtocol(); KPPPProtocol *protocol = Interface().FirstProtocol();
for(; protocol; protocol = protocol->NextProtocol()) for(; protocol; protocol = protocol->NextProtocol())
if(protocol->IsEnabled()) if(protocol->IsEnabled())
@@ -2027,7 +2029,7 @@ PPPStateMachine::DownProtocols()
void void
PPPStateMachine::ResetLCPHandlers() KPPPStateMachine::ResetLCPHandlers()
{ {
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) for(int32 index = 0; index < LCP().CountOptionHandlers(); index++)
LCP().OptionHandlerAt(index)->Reset(); LCP().OptionHandlerAt(index)->Reset();
@@ -12,7 +12,7 @@
bool bool
IsProtocolAllowed(const PPPProtocol& protocol) IsProtocolAllowed(const KPPPProtocol& protocol)
{ {
if(protocol.ProtocolNumber() == PPP_LCP_PROTOCOL) if(protocol.ProtocolNumber() == PPP_LCP_PROTOCOL)
return true; return true;
@@ -1,2 +1,3 @@
- finish support for server mode - add missing settings support (DialRetryDelay, etc.)
- finish support for server mode (profiles, etc.)
- add callback support - add callback support
@@ -23,8 +23,8 @@ typedef struct authentication_item {
} authentication_item; } authentication_item;
_PPPAuthenticationHandler::_PPPAuthenticationHandler(PPPInterface& interface) _KPPPAuthenticationHandler::_KPPPAuthenticationHandler(KPPPInterface& interface)
: PPPOptionHandler("Authentication Handler", AUTHENTICATION_TYPE, interface, NULL), : KPPPOptionHandler("Authentication Handler", AUTHENTICATION_TYPE, interface, NULL),
fLocalAuthenticator(NULL), fLocalAuthenticator(NULL),
fPeerAuthenticator(NULL), fPeerAuthenticator(NULL),
fSuggestedLocalAuthenticator(NULL), fSuggestedLocalAuthenticator(NULL),
@@ -34,12 +34,12 @@ _PPPAuthenticationHandler::_PPPAuthenticationHandler(PPPInterface& interface)
} }
PPPProtocol* KPPPProtocol*
_PPPAuthenticationHandler::NextAuthenticator(const PPPProtocol *start, _KPPPAuthenticationHandler::NextAuthenticator(const KPPPProtocol *start,
ppp_side side) const ppp_side side) const
{ {
// find the next authenticator for side, beginning at start // find the next authenticator for side, beginning at start
PPPProtocol *current = start ? start->NextProtocol() : Interface().FirstProtocol(); KPPPProtocol *current = start ? start->NextProtocol() : Interface().FirstProtocol();
for(; current; current = current->NextProtocol()) { for(; current; current = current->NextProtocol()) {
if(!strcasecmp(current->Type(), AUTHENTICATOR_TYPE_STRING) if(!strcasecmp(current->Type(), AUTHENTICATOR_TYPE_STRING)
@@ -52,7 +52,7 @@ _PPPAuthenticationHandler::NextAuthenticator(const PPPProtocol *start,
status_t status_t
_PPPAuthenticationHandler::AddToRequest(PPPConfigurePacket& request) _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
{ {
// AddToRequest(): Check if peer must authenticate itself and // AddToRequest(): Check if peer must authenticate itself and
// add an authentication request if needed. This request is added // add an authentication request if needed. This request is added
@@ -63,7 +63,7 @@ _PPPAuthenticationHandler::AddToRequest(PPPConfigurePacket& request)
if(fSuggestedPeerAuthenticator) if(fSuggestedPeerAuthenticator)
fSuggestedPeerAuthenticator->SetEnabled(false); fSuggestedPeerAuthenticator->SetEnabled(false);
PPPProtocol *authenticator; KPPPProtocol *authenticator;
if(fPeerAuthenticatorRejected) { if(fPeerAuthenticatorRejected) {
if(!fSuggestedPeerAuthenticator) { if(!fSuggestedPeerAuthenticator) {
// This happens when the protocol is rejected, but no alternative // This happens when the protocol is rejected, but no alternative
@@ -100,7 +100,7 @@ _PPPAuthenticationHandler::AddToRequest(PPPConfigurePacket& request)
// no problem because the suggested authenticator will be accepted (hopefully) // no problem because the suggested authenticator will be accepted (hopefully)
#if DEBUG #if DEBUG
dprintf("PPPAuthHandler: AddToRequest(%X)\n", authenticator->ProtocolNumber()); dprintf("KPPPAuthHandler: AddToRequest(%X)\n", authenticator->ProtocolNumber());
#endif #endif
authenticator->SetEnabled(true); authenticator->SetEnabled(true);
@@ -110,7 +110,7 @@ _PPPAuthenticationHandler::AddToRequest(PPPConfigurePacket& request)
status_t status_t
_PPPAuthenticationHandler::ParseNak(const PPPConfigurePacket& nak) _KPPPAuthenticationHandler::ParseNak(const KPPPConfigurePacket& nak)
{ {
// The authenticator's OptionHandler is not notified. // The authenticator's OptionHandler is not notified.
@@ -135,7 +135,7 @@ _PPPAuthenticationHandler::ParseNak(const PPPConfigurePacket& nak)
} }
fPeerAuthenticatorRejected = true; fPeerAuthenticatorRejected = true;
PPPProtocol *authenticator = Interface().ProtocolFor(ntohs(item->protocolNumber)); KPPPProtocol *authenticator = Interface().ProtocolFor(ntohs(item->protocolNumber));
if(authenticator if(authenticator
&& !strcasecmp(authenticator->Type(), AUTHENTICATOR_TYPE_STRING) && !strcasecmp(authenticator->Type(), AUTHENTICATOR_TYPE_STRING)
&& authenticator->OptionHandler()) && authenticator->OptionHandler())
@@ -148,7 +148,7 @@ _PPPAuthenticationHandler::ParseNak(const PPPConfigurePacket& nak)
status_t status_t
_PPPAuthenticationHandler::ParseReject(const PPPConfigurePacket& reject) _KPPPAuthenticationHandler::ParseReject(const KPPPConfigurePacket& reject)
{ {
// an authentication request must not be rejected! // an authentication request must not be rejected!
if(reject.ItemWithType(AUTHENTICATION_TYPE)) if(reject.ItemWithType(AUTHENTICATION_TYPE))
@@ -159,7 +159,7 @@ _PPPAuthenticationHandler::ParseReject(const PPPConfigurePacket& reject)
status_t status_t
_PPPAuthenticationHandler::ParseAck(const PPPConfigurePacket& ack) _KPPPAuthenticationHandler::ParseAck(const KPPPConfigurePacket& ack)
{ {
authentication_item *item = authentication_item *item =
(authentication_item*) ack.ItemWithType(AUTHENTICATION_TYPE); (authentication_item*) ack.ItemWithType(AUTHENTICATION_TYPE);
@@ -182,8 +182,8 @@ _PPPAuthenticationHandler::ParseAck(const PPPConfigurePacket& ack)
status_t status_t
_PPPAuthenticationHandler::ParseRequest(const PPPConfigurePacket& request, _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject) int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{ {
if(fLocalAuthenticator) if(fLocalAuthenticator)
fLocalAuthenticator->SetEnabled(false); fLocalAuthenticator->SetEnabled(false);
@@ -194,7 +194,7 @@ _PPPAuthenticationHandler::ParseRequest(const PPPConfigurePacket& request,
// no authentication requested by peer (index > request.CountItems()) // no authentication requested by peer (index > request.CountItems())
#if DEBUG #if DEBUG
dprintf("PPPAuthHandler: ParseRequest(%X)\n", ntohs(item->protocolNumber)); dprintf("KPPPAuthHandler: ParseRequest(%X)\n", ntohs(item->protocolNumber));
#endif #endif
// try to find the requested protocol // try to find the requested protocol
@@ -206,7 +206,7 @@ _PPPAuthenticationHandler::ParseRequest(const PPPConfigurePacket& request,
nak, reject); nak, reject);
// suggest another authentication protocol // suggest another authentication protocol
PPPProtocol *nextAuthenticator = KPPPProtocol *nextAuthenticator =
NextAuthenticator(fSuggestedLocalAuthenticator, PPP_LOCAL_SIDE); NextAuthenticator(fSuggestedLocalAuthenticator, PPP_LOCAL_SIDE);
if(!nextAuthenticator) { if(!nextAuthenticator) {
@@ -233,7 +233,7 @@ _PPPAuthenticationHandler::ParseRequest(const PPPConfigurePacket& request,
status_t status_t
_PPPAuthenticationHandler::SendingAck(const PPPConfigurePacket& ack) _KPPPAuthenticationHandler::SendingAck(const KPPPConfigurePacket& ack)
{ {
// do not insist on authenticating our side of the link ;) // do not insist on authenticating our side of the link ;)
@@ -260,7 +260,7 @@ _PPPAuthenticationHandler::SendingAck(const PPPConfigurePacket& ack)
void void
_PPPAuthenticationHandler::Reset() _KPPPAuthenticationHandler::Reset()
{ {
if(fLocalAuthenticator) { if(fLocalAuthenticator) {
fLocalAuthenticator->SetEnabled(false); fLocalAuthenticator->SetEnabled(false);
@@ -11,25 +11,26 @@
#include <KPPPOptionHandler.h> #include <KPPPOptionHandler.h>
class _PPPAuthenticationHandler : public PPPOptionHandler { class _KPPPAuthenticationHandler : public KPPPOptionHandler {
public: public:
_PPPAuthenticationHandler(PPPInterface& interface); _KPPPAuthenticationHandler(KPPPInterface& interface);
PPPProtocol *NextAuthenticator(const PPPProtocol *start, ppp_side side) const; KPPPProtocol *NextAuthenticator(const KPPPProtocol *start,
ppp_side side) const;
virtual status_t AddToRequest(PPPConfigurePacket& request); virtual status_t AddToRequest(KPPPConfigurePacket& request);
virtual status_t ParseNak(const PPPConfigurePacket& nak); virtual status_t ParseNak(const KPPPConfigurePacket& nak);
virtual status_t ParseReject(const PPPConfigurePacket& reject); virtual status_t ParseReject(const KPPPConfigurePacket& reject);
virtual status_t ParseAck(const PPPConfigurePacket& ack); virtual status_t ParseAck(const KPPPConfigurePacket& ack);
virtual status_t ParseRequest(const PPPConfigurePacket& request, virtual status_t ParseRequest(const KPPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject); int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject);
virtual status_t SendingAck(const PPPConfigurePacket& ack); virtual status_t SendingAck(const KPPPConfigurePacket& ack);
virtual void Reset(); virtual void Reset();
private: private:
PPPProtocol *fLocalAuthenticator, *fPeerAuthenticator, KPPPProtocol *fLocalAuthenticator, *fPeerAuthenticator,
*fSuggestedLocalAuthenticator, *fSuggestedPeerAuthenticator; *fSuggestedLocalAuthenticator, *fSuggestedPeerAuthenticator;
bool fPeerAuthenticatorRejected; bool fPeerAuthenticatorRejected;
}; };
@@ -21,18 +21,18 @@ typedef struct mru_item {
uint16 MRU _PACKED; uint16 MRU _PACKED;
} mru_item; } mru_item;
status_t ParseRequestedItem(mru_item *item, PPPInterface& interface); status_t ParseRequestedItem(mru_item *item, KPPPInterface& interface);
_PPPMRUHandler::_PPPMRUHandler(PPPInterface& interface) _KPPPMRUHandler::_KPPPMRUHandler(KPPPInterface& interface)
: PPPOptionHandler("MRU Handler", MRU_TYPE, interface, NULL) : KPPPOptionHandler("MRU Handler", MRU_TYPE, interface, NULL)
{ {
Reset(); Reset();
} }
status_t status_t
_PPPMRUHandler::AddToRequest(PPPConfigurePacket& request) _KPPPMRUHandler::AddToRequest(KPPPConfigurePacket& request)
{ {
if(!Interface().Device() || Interface().MRU() == 1500) if(!Interface().Device() || Interface().MRU() == 1500)
return B_OK; return B_OK;
@@ -47,7 +47,7 @@ _PPPMRUHandler::AddToRequest(PPPConfigurePacket& request)
status_t status_t
_PPPMRUHandler::ParseNak(const PPPConfigurePacket& nak) _KPPPMRUHandler::ParseNak(const KPPPConfigurePacket& nak)
{ {
mru_item *item = (mru_item*) nak.ItemWithType(MRU_TYPE); mru_item *item = (mru_item*) nak.ItemWithType(MRU_TYPE);
if(!item || item->length != 4) if(!item || item->length != 4)
@@ -62,7 +62,7 @@ _PPPMRUHandler::ParseNak(const PPPConfigurePacket& nak)
status_t status_t
_PPPMRUHandler::ParseReject(const PPPConfigurePacket& reject) _KPPPMRUHandler::ParseReject(const KPPPConfigurePacket& reject)
{ {
if(reject.ItemWithType(MRU_TYPE)) if(reject.ItemWithType(MRU_TYPE))
return B_ERROR; return B_ERROR;
@@ -72,7 +72,7 @@ _PPPMRUHandler::ParseReject(const PPPConfigurePacket& reject)
status_t status_t
_PPPMRUHandler::ParseAck(const PPPConfigurePacket& ack) _KPPPMRUHandler::ParseAck(const KPPPConfigurePacket& ack)
{ {
uint16 MRU = 1500; uint16 MRU = 1500;
mru_item *item = (mru_item*) ack.ItemWithType(MRU_TYPE); mru_item *item = (mru_item*) ack.ItemWithType(MRU_TYPE);
@@ -88,8 +88,8 @@ _PPPMRUHandler::ParseAck(const PPPConfigurePacket& ack)
status_t status_t
_PPPMRUHandler::ParseRequest(const PPPConfigurePacket& request, _KPPPMRUHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject) int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{ {
if(index == reject.CountItems()) if(index == reject.CountItems())
return B_OK; return B_OK;
@@ -101,7 +101,7 @@ _PPPMRUHandler::ParseRequest(const PPPConfigurePacket& request,
status_t status_t
_PPPMRUHandler::SendingAck(const PPPConfigurePacket& ack) _KPPPMRUHandler::SendingAck(const KPPPConfigurePacket& ack)
{ {
return ParseRequestedItem((mru_item*) ack.ItemWithType(MRU_TYPE), Interface()); return ParseRequestedItem((mru_item*) ack.ItemWithType(MRU_TYPE), Interface());
} }
@@ -109,7 +109,7 @@ _PPPMRUHandler::SendingAck(const PPPConfigurePacket& ack)
// this function contains code shared by ParseRequest and SendingAck // this function contains code shared by ParseRequest and SendingAck
status_t status_t
ParseRequestedItem(mru_item *item, PPPInterface& interface) ParseRequestedItem(mru_item *item, KPPPInterface& interface)
{ {
uint16 MRU = 1500; uint16 MRU = 1500;
@@ -129,7 +129,7 @@ ParseRequestedItem(mru_item *item, PPPInterface& interface)
void void
_PPPMRUHandler::Reset() _KPPPMRUHandler::Reset()
{ {
if(Interface().Device()) { if(Interface().Device()) {
fLocalMRU = Interface().Device()->MTU() - 2; fLocalMRU = Interface().Device()->MTU() - 2;
@@ -11,18 +11,18 @@
#include <KPPPOptionHandler.h> #include <KPPPOptionHandler.h>
class _PPPMRUHandler : public PPPOptionHandler { class _KPPPMRUHandler : public KPPPOptionHandler {
public: public:
_PPPMRUHandler(PPPInterface& interface); _KPPPMRUHandler(KPPPInterface& interface);
virtual status_t AddToRequest(PPPConfigurePacket& request); virtual status_t AddToRequest(KPPPConfigurePacket& request);
virtual status_t ParseNak(const PPPConfigurePacket& nak); virtual status_t ParseNak(const KPPPConfigurePacket& nak);
virtual status_t ParseReject(const PPPConfigurePacket& reject); virtual status_t ParseReject(const KPPPConfigurePacket& reject);
virtual status_t ParseAck(const PPPConfigurePacket& ack); virtual status_t ParseAck(const KPPPConfigurePacket& ack);
virtual status_t ParseRequest(const PPPConfigurePacket& request, virtual status_t ParseRequest(const KPPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject); int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject);
virtual status_t SendingAck(const PPPConfigurePacket& ack); virtual status_t SendingAck(const KPPPConfigurePacket& ack);
virtual void Reset(); virtual void Reset();
@@ -13,9 +13,9 @@
#define PFC_TYPE 0x7 #define PFC_TYPE 0x7
_PPPPFCHandler::_PPPPFCHandler(ppp_pfc_state& localPFCState, _KPPPPFCHandler::_KPPPPFCHandler(ppp_pfc_state& localPFCState,
ppp_pfc_state& peerPFCState, PPPInterface& interface) ppp_pfc_state& peerPFCState, KPPPInterface& interface)
: PPPOptionHandler("PFC Handler", PFC_TYPE, interface, NULL), : KPPPOptionHandler("PFC Handler", PFC_TYPE, interface, NULL),
fLocalPFCState(localPFCState), fLocalPFCState(localPFCState),
fPeerPFCState(peerPFCState) fPeerPFCState(peerPFCState)
{ {
@@ -23,7 +23,7 @@ _PPPPFCHandler::_PPPPFCHandler(ppp_pfc_state& localPFCState,
status_t status_t
_PPPPFCHandler::AddToRequest(PPPConfigurePacket& request) _KPPPPFCHandler::AddToRequest(KPPPConfigurePacket& request)
{ {
// is PFC not requested or was it rejected? // is PFC not requested or was it rejected?
if(fLocalPFCState == PPP_PFC_REJECTED if(fLocalPFCState == PPP_PFC_REJECTED
@@ -39,7 +39,7 @@ _PPPPFCHandler::AddToRequest(PPPConfigurePacket& request)
status_t status_t
_PPPPFCHandler::ParseNak(const PPPConfigurePacket& nak) _KPPPPFCHandler::ParseNak(const KPPPConfigurePacket& nak)
{ {
// naks do not contain PFC items // naks do not contain PFC items
if(nak.ItemWithType(PFC_TYPE)) if(nak.ItemWithType(PFC_TYPE))
@@ -50,7 +50,7 @@ _PPPPFCHandler::ParseNak(const PPPConfigurePacket& nak)
status_t status_t
_PPPPFCHandler::ParseReject(const PPPConfigurePacket& reject) _KPPPPFCHandler::ParseReject(const KPPPConfigurePacket& reject)
{ {
if(reject.ItemWithType(PFC_TYPE)) { if(reject.ItemWithType(PFC_TYPE)) {
fLocalPFCState = PPP_PFC_REJECTED; fLocalPFCState = PPP_PFC_REJECTED;
@@ -64,7 +64,7 @@ _PPPPFCHandler::ParseReject(const PPPConfigurePacket& reject)
status_t status_t
_PPPPFCHandler::ParseAck(const PPPConfigurePacket& ack) _KPPPPFCHandler::ParseAck(const KPPPConfigurePacket& ack)
{ {
if(ack.ItemWithType(PFC_TYPE)) if(ack.ItemWithType(PFC_TYPE))
fLocalPFCState = PPP_PFC_ACCEPTED; fLocalPFCState = PPP_PFC_ACCEPTED;
@@ -80,8 +80,8 @@ _PPPPFCHandler::ParseAck(const PPPConfigurePacket& ack)
status_t status_t
_PPPPFCHandler::ParseRequest(const PPPConfigurePacket& request, _KPPPPFCHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject) int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{ {
if(!request.ItemWithType(PFC_TYPE)) if(!request.ItemWithType(PFC_TYPE))
return B_OK; return B_OK;
@@ -98,7 +98,7 @@ _PPPPFCHandler::ParseRequest(const PPPConfigurePacket& request,
status_t status_t
_PPPPFCHandler::SendingAck(const PPPConfigurePacket& ack) _KPPPPFCHandler::SendingAck(const KPPPConfigurePacket& ack)
{ {
ppp_configure_item *item = ack.ItemWithType(PFC_TYPE); ppp_configure_item *item = ack.ItemWithType(PFC_TYPE);
@@ -115,7 +115,7 @@ _PPPPFCHandler::SendingAck(const PPPConfigurePacket& ack)
void void
_PPPPFCHandler::Reset() _KPPPPFCHandler::Reset()
{ {
fLocalPFCState = fPeerPFCState = PPP_PFC_DISABLED; fLocalPFCState = fPeerPFCState = PPP_PFC_DISABLED;
} }
@@ -11,19 +11,19 @@
#include <KPPPOptionHandler.h> #include <KPPPOptionHandler.h>
class _PPPPFCHandler : public PPPOptionHandler { class _KPPPPFCHandler : public KPPPOptionHandler {
public: public:
_PPPPFCHandler(ppp_pfc_state& localPFCState, ppp_pfc_state& peerPFCState, _KPPPPFCHandler(ppp_pfc_state& localPFCState, ppp_pfc_state& peerPFCState,
PPPInterface& interface); KPPPInterface& interface);
virtual status_t AddToRequest(PPPConfigurePacket& request); virtual status_t AddToRequest(KPPPConfigurePacket& request);
virtual status_t ParseNak(const PPPConfigurePacket& nak); virtual status_t ParseNak(const KPPPConfigurePacket& nak);
virtual status_t ParseReject(const PPPConfigurePacket& reject); virtual status_t ParseReject(const KPPPConfigurePacket& reject);
virtual status_t ParseAck(const PPPConfigurePacket& ack); virtual status_t ParseAck(const KPPPConfigurePacket& ack);
virtual status_t ParseRequest(const PPPConfigurePacket& request, virtual status_t ParseRequest(const KPPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject); int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject);
virtual status_t SendingAck(const PPPConfigurePacket& ack); virtual status_t SendingAck(const KPPPConfigurePacket& ack);
virtual void Reset(); virtual void Reset();
@@ -12,7 +12,6 @@
struct mbuf; struct mbuf;
typedef struct ppp_configure_item { typedef struct ppp_configure_item {
uint8 type; uint8 type;
uint8 length; uint8 length;
@@ -21,16 +20,16 @@ typedef struct ppp_configure_item {
} ppp_configure_item; } ppp_configure_item;
class PPPConfigurePacket { class KPPPConfigurePacket {
private: private:
// copies are not allowed! // copies are not allowed!
PPPConfigurePacket(const PPPConfigurePacket& copy); KPPPConfigurePacket(const KPPPConfigurePacket& copy);
PPPConfigurePacket& operator= (const PPPConfigurePacket& copy); KPPPConfigurePacket& operator= (const KPPPConfigurePacket& copy);
public: public:
PPPConfigurePacket(uint8 code); KPPPConfigurePacket(uint8 code);
PPPConfigurePacket(struct mbuf *packet); KPPPConfigurePacket(struct mbuf *packet);
~PPPConfigurePacket(); ~KPPPConfigurePacket();
bool SetCode(uint8 code); bool SetCode(uint8 code);
uint8 Code() const uint8 Code() const
@@ -12,13 +12,14 @@
#include <PPPDefs.h> #include <PPPDefs.h>
extern struct core_module_info *core;
// needed by core quick-access function defines
// various constants // various constants
#define PPP_PULSE_RATE 500000 #define PPP_PULSE_RATE 500000
extern struct core_module_info *core;
// module key types (used when loading a module) // module key types (used when loading a module)
enum ppp_module_key_type { enum ppp_module_key_type {
PPP_UNDEFINED_KEY_TYPE = -1, PPP_UNDEFINED_KEY_TYPE = -1,
@@ -69,4 +70,5 @@ enum ppp_lcp_code {
#define PPP_MIN_LCP_CODE PPP_CONFIGURE_REQUEST #define PPP_MIN_LCP_CODE PPP_CONFIGURE_REQUEST
#define PPP_MAX_LCP_CODE PPP_DISCARD_REQUEST #define PPP_MAX_LCP_CODE PPP_DISCARD_REQUEST
#endif #endif
@@ -16,18 +16,18 @@
#endif #endif
class PPPDevice : public PPPLayer { class KPPPDevice : public KPPPLayer {
friend class PPPStateMachine; friend class KPPPStateMachine;
protected: protected:
// PPPDevice must be subclassed // KPPPDevice must be subclassed
PPPDevice(const char *name, uint32 overhead, PPPInterface& interface, KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interface,
driver_parameter *settings); driver_parameter *settings);
public: public:
virtual ~PPPDevice(); virtual ~KPPPDevice();
PPPInterface& Interface() const KPPPInterface& Interface() const
{ return fInterface; } { return fInterface; }
driver_parameter *Settings() const driver_parameter *Settings() const
{ return fSettings; } { return fSettings; }
@@ -90,7 +90,7 @@ class PPPDevice : public PPPLayer {
private: private:
char *fName; char *fName;
PPPInterface& fInterface; KPPPInterface& fInterface;
driver_parameter *fSettings; driver_parameter *fSettings;
ppp_phase fConnectionPhase; ppp_phase fConnectionPhase;
@@ -10,44 +10,52 @@
#include <driver_settings.h> #include <driver_settings.h>
#ifndef _K_PPP_DEFS__H
#include <KPPPDefs.h> #include <KPPPDefs.h>
#endif
#ifndef _K_PPP_LCP__H #ifndef _K_PPP_LCP__H
#include <KPPPLCP.h> #include <KPPPLCP.h>
#endif #endif
#ifndef _K_PPP_PROFILE__H
#include <KPPPProfile.h>
#endif
#ifndef _K_PPP_REPORT_MANAGER__H
#include <KPPPReportManager.h> #include <KPPPReportManager.h>
#endif
#ifndef _K_PPP_STATE_MACHINE__H #ifndef _K_PPP_STATE_MACHINE__H
#include <KPPPStateMachine.h> #include <KPPPStateMachine.h>
#endif #endif
#include <TemplateList.h> #include <TemplateList.h>
#include <LockerHelper.h>
class PPPDevice; class KPPPDevice;
class PPPProtocol; class KPPPProtocol;
class PPPOptionHandler; class KPPPOptionHandler;
struct ppp_interface_module_info; struct ppp_interface_module_info;
struct ppp_module_info; struct ppp_module_info;
struct ppp_interface_entry; struct ppp_interface_entry;
class PPPInterface : public PPPLayer { class KPPPInterface : public KPPPLayer {
friend class PPPStateMachine;
friend class PPPManager; friend class PPPManager;
friend class PPPInterfaceAccess; friend class KPPPStateMachine;
friend class KPPPInterfaceAccess;
private: private:
// copies are not allowed! // copies are not allowed!
PPPInterface(const PPPInterface& copy); KPPPInterface(const KPPPInterface& copy);
PPPInterface& operator= (const PPPInterface& copy); KPPPInterface& operator= (const KPPPInterface& copy);
// only PPPManager may construct us! // only PPPManager may construct us!
PPPInterface(ppp_interface_entry *entry, ppp_interface_id ID, KPPPInterface(const char *name, ppp_interface_entry *entry,
const driver_settings *settings, PPPInterface *parent = NULL); ppp_interface_id ID, const driver_settings *settings,
~PPPInterface(); const driver_settings *profile, KPPPInterface *parent = NULL);
~KPPPInterface();
public: public:
void Delete(); void Delete();
@@ -60,10 +68,12 @@ class PPPInterface : public PPPLayer {
driver_settings* Settings() const driver_settings* Settings() const
{ return fSettings; } { return fSettings; }
PPPStateMachine& StateMachine() KPPPStateMachine& StateMachine()
{ return fStateMachine; } { return fStateMachine; }
PPPLCP& LCP() KPPPLCP& LCP()
{ return fLCP; } { return fLCP; }
KPPPProfile& Profile()
{ return fProfile; }
struct ifnet *Ifnet() const struct ifnet *Ifnet() const
{ return fIfnet; } { return fIfnet; }
@@ -94,25 +104,26 @@ class PPPInterface : public PPPLayer {
virtual status_t Control(uint32 op, void *data, size_t length); virtual status_t Control(uint32 op, void *data, size_t length);
bool SetDevice(PPPDevice *device); bool SetDevice(KPPPDevice *device);
PPPDevice *Device() const KPPPDevice *Device() const
{ return fDevice; } { return fDevice; }
bool AddProtocol(PPPProtocol *protocol); bool AddProtocol(KPPPProtocol *protocol);
bool RemoveProtocol(PPPProtocol *protocol); bool RemoveProtocol(KPPPProtocol *protocol);
int32 CountProtocols() const; int32 CountProtocols() const;
PPPProtocol *ProtocolAt(int32 index) const; KPPPProtocol *ProtocolAt(int32 index) const;
PPPProtocol *FirstProtocol() const KPPPProtocol *FirstProtocol() const
{ return fFirstProtocol; } { return fFirstProtocol; }
PPPProtocol *ProtocolFor(uint16 protocolNumber, PPPProtocol *start = NULL) const; KPPPProtocol *ProtocolFor(uint16 protocolNumber,
KPPPProtocol *start = NULL) const;
// multilink methods // multilink methods
bool AddChild(PPPInterface *child); bool AddChild(KPPPInterface *child);
bool RemoveChild(PPPInterface *child); bool RemoveChild(KPPPInterface *child);
int32 CountChildren() const int32 CountChildren() const
{ return fChildren.CountItems(); } { return fChildren.CountItems(); }
PPPInterface *ChildAt(int32 index) const; KPPPInterface *ChildAt(int32 index) const;
PPPInterface *Parent() const KPPPInterface *Parent() const
{ return fParent; } { return fParent; }
bool IsMultilink() const bool IsMultilink() const
{ return fIsMultilink; } { return fIsMultilink; }
@@ -153,7 +164,7 @@ class PPPInterface : public PPPLayer {
virtual bool Down(); virtual bool Down();
bool IsUp() const; bool IsUp() const;
PPPReportManager& ReportManager() KPPPReportManager& ReportManager()
{ return fReportManager; } { return fReportManager; }
bool Report(ppp_report_type type, int32 code, void *data, int32 length) bool Report(ppp_report_type type, int32 code, void *data, int32 length)
{ return ReportManager().Report(type, code, data, length); } { return ReportManager().Report(type, code, data, length); }
@@ -172,7 +183,7 @@ class PPPInterface : public PPPLayer {
virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber); virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber);
status_t ReceiveFromDevice(struct mbuf *packet); status_t ReceiveFromDevice(struct mbuf *packet);
// This must not block PPPDevice::Send()! // This must not block KPPPDevice::Send()!
void Pulse(); void Pulse();
// this manages all timeouts, etc. // this manages all timeouts, etc.
@@ -183,6 +194,8 @@ class PPPInterface : public PPPLayer {
// saves the returned ifnet structure // saves the returned ifnet structure
bool UnregisterInterface(); bool UnregisterInterface();
void SetName(const char *name);
status_t StackControl(uint32 op, void *data); status_t StackControl(uint32 op, void *data);
// stack routes ioctls to interface // stack routes ioctls to interface
status_t StackControlEachHandler(uint32 op, void *data); status_t StackControlEachHandler(uint32 op, void *data);
@@ -200,7 +213,7 @@ class PPPInterface : public PPPLayer {
void Redial(uint32 delay); void Redial(uint32 delay);
// multilink methods // multilink methods
void SetParent(PPPInterface *parent) void SetParent(KPPPInterface *parent)
{ fParent = parent; } { fParent = parent; }
private: private:
@@ -220,8 +233,8 @@ class PPPInterface : public PPPLayer {
uint32 fIdleSince, fDisconnectAfterIdleSince; uint32 fIdleSince, fDisconnectAfterIdleSince;
uint32 fMRU, fInterfaceMTU, fHeaderLength; uint32 fMRU, fInterfaceMTU, fHeaderLength;
PPPInterface *fParent; KPPPInterface *fParent;
TemplateList<PPPInterface*> fChildren; TemplateList<KPPPInterface*> fChildren;
bool fIsMultilink; bool fIsMultilink;
bool fAutoRedial, fDialOnDemand; bool fAutoRedial, fDialOnDemand;
@@ -230,13 +243,14 @@ class PPPInterface : public PPPLayer {
ppp_pfc_state fLocalPFCState, fPeerPFCState; ppp_pfc_state fLocalPFCState, fPeerPFCState;
uint8 fPFCOptions; uint8 fPFCOptions;
PPPDevice *fDevice; KPPPDevice *fDevice;
PPPProtocol *fFirstProtocol; KPPPProtocol *fFirstProtocol;
TemplateList<char*> fModules; TemplateList<char*> fModules;
PPPStateMachine fStateMachine; KPPPStateMachine fStateMachine;
PPPLCP fLCP; KPPPLCP fLCP;
PPPReportManager fReportManager; KPPPProfile fProfile;
KPPPReportManager fReportManager;
BLocker& fLock; BLocker& fLock;
int32 fDeleteCounter; int32 fDeleteCounter;
}; };
@@ -22,8 +22,8 @@
#include <KPPPStateMachine.h> #include <KPPPStateMachine.h>
#endif #endif
class PPPLCPExtension; class KPPPLCPExtension;
class PPPOptionHandler; class KPPPOptionHandler;
typedef struct ppp_lcp_packet { typedef struct ppp_lcp_packet {
@@ -34,41 +34,41 @@ typedef struct ppp_lcp_packet {
} ppp_lcp_packet; } ppp_lcp_packet;
class PPPLCP : public PPPProtocol { class KPPPLCP : public KPPPProtocol {
friend class PPPInterface; friend class KPPPInterface;
private: private:
// may only be constructed/destructed by PPPInterface // may only be constructed/destructed by KPPPInterface
PPPLCP(PPPInterface& interface); KPPPLCP(KPPPInterface& interface);
virtual ~PPPLCP(); virtual ~KPPPLCP();
// copies are not allowed! // copies are not allowed!
PPPLCP(const PPPLCP& copy); KPPPLCP(const KPPPLCP& copy);
PPPLCP& operator= (const PPPLCP& copy); KPPPLCP& operator= (const KPPPLCP& copy);
public: public:
PPPStateMachine& StateMachine() const KPPPStateMachine& StateMachine() const
{ return fStateMachine; } { return fStateMachine; }
bool AddOptionHandler(PPPOptionHandler *handler); bool AddOptionHandler(KPPPOptionHandler *handler);
bool RemoveOptionHandler(PPPOptionHandler *handler); bool RemoveOptionHandler(KPPPOptionHandler *handler);
int32 CountOptionHandlers() const int32 CountOptionHandlers() const
{ return fOptionHandlers.CountItems(); } { return fOptionHandlers.CountItems(); }
PPPOptionHandler *OptionHandlerAt(int32 index) const; KPPPOptionHandler *OptionHandlerAt(int32 index) const;
PPPOptionHandler *OptionHandlerFor(uint8 type, int32 *start = NULL) const; KPPPOptionHandler *OptionHandlerFor(uint8 type, int32 *start = NULL) const;
bool AddLCPExtension(PPPLCPExtension *extension); bool AddLCPExtension(KPPPLCPExtension *extension);
bool RemoveLCPExtension(PPPLCPExtension *extension); bool RemoveLCPExtension(KPPPLCPExtension *extension);
int32 CountLCPExtensions() const int32 CountLCPExtensions() const
{ return fLCPExtensions.CountItems(); } { return fLCPExtensions.CountItems(); }
PPPLCPExtension *LCPExtensionAt(int32 index) const; KPPPLCPExtension *LCPExtensionAt(int32 index) const;
PPPLCPExtension *LCPExtensionFor(uint8 code, int32 *start = NULL) const; KPPPLCPExtension *LCPExtensionFor(uint8 code, int32 *start = NULL) const;
void SetTarget(PPPProtocol *target) void SetTarget(KPPPProtocol *target)
{ fTarget = target; } { fTarget = target; }
// if target != NULL all packtes will be passed to the protocol // if target != NULL all packtes will be passed to the protocol
// instead of the interface/device // instead of the interface/device
PPPProtocol *Target() const KPPPProtocol *Target() const
{ return fTarget; } { return fTarget; }
uint32 AdditionalOverhead() const; uint32 AdditionalOverhead() const;
@@ -84,12 +84,12 @@ class PPPLCP : public PPPProtocol {
virtual void Pulse(); virtual void Pulse();
private: private:
PPPStateMachine& fStateMachine; KPPPStateMachine& fStateMachine;
TemplateList<PPPOptionHandler*> fOptionHandlers; TemplateList<KPPPOptionHandler*> fOptionHandlers;
TemplateList<PPPLCPExtension*> fLCPExtensions; TemplateList<KPPPLCPExtension*> fLCPExtensions;
PPPProtocol *fTarget; KPPPProtocol *fTarget;
}; };
@@ -15,21 +15,21 @@
#endif #endif
class PPPLCPExtension { class KPPPLCPExtension {
protected: protected:
// PPPLCPExtension must be subclassed // KPPPLCPExtension must be subclassed
PPPLCPExtension(const char *name, uint8 code, PPPInterface& interface, KPPPLCPExtension(const char *name, uint8 code, KPPPInterface& interface,
driver_parameter *settings); driver_parameter *settings);
public: public:
virtual ~PPPLCPExtension(); virtual ~KPPPLCPExtension();
virtual status_t InitCheck() const; virtual status_t InitCheck() const;
const char *Name() const const char *Name() const
{ return fName; } { return fName; }
PPPInterface& Interface() const KPPPInterface& Interface() const
{ return fInterface; } { return fInterface; }
driver_parameter *Settings() const driver_parameter *Settings() const
{ return fSettings; } { return fSettings; }
@@ -44,7 +44,7 @@ class PPPLCPExtension {
virtual status_t Control(uint32 op, void *data, size_t length); virtual status_t Control(uint32 op, void *data, size_t length);
virtual status_t StackControl(uint32 op, void *data); virtual status_t StackControl(uint32 op, void *data);
// called by netstack (forwarded by PPPInterface) // called by netstack (forwarded by KPPPInterface)
virtual status_t Receive(struct mbuf *packet, uint8 code) = 0; virtual status_t Receive(struct mbuf *packet, uint8 code) = 0;
@@ -56,7 +56,7 @@ class PPPLCPExtension {
private: private:
char *fName; char *fName;
PPPInterface& fInterface; KPPPInterface& fInterface;
driver_parameter *fSettings; driver_parameter *fSettings;
uint8 fCode; uint8 fCode;
@@ -11,13 +11,13 @@
#include <KPPPDefs.h> #include <KPPPDefs.h>
class PPPLayer { class KPPPLayer {
protected: protected:
// PPPLayer must be subclassed // KPPPLayer must be subclassed
PPPLayer(const char *name, ppp_level level, uint32 overhead); KPPPLayer(const char *name, ppp_level level, uint32 overhead);
public: public:
virtual ~PPPLayer(); virtual ~KPPPLayer();
virtual status_t InitCheck() const; virtual status_t InitCheck() const;
@@ -29,9 +29,9 @@ class PPPLayer {
uint32 Overhead() const uint32 Overhead() const
{ return fOverhead; } { return fOverhead; }
void SetNext(PPPLayer *next) void SetNext(KPPPLayer *next)
{ fNext = next; } { fNext = next; }
PPPLayer *Next() const KPPPLayer *Next() const
{ return fNext; } { return fNext; }
virtual bool Up() = 0; virtual bool Up() = 0;
@@ -48,6 +48,8 @@ class PPPLayer {
virtual void Pulse(); virtual void Pulse();
protected: protected:
void SetName(const char *name);
status_t fInitStatus; status_t fInitStatus;
uint32 fOverhead; uint32 fOverhead;
@@ -55,7 +57,7 @@ class PPPLayer {
char *fName; char *fName;
ppp_level fLevel; ppp_level fLevel;
PPPLayer *fNext; KPPPLayer *fNext;
}; };
@@ -19,20 +19,30 @@
// create_interface() returns this value on failure // create_interface() returns this value on failure
class PPPInterface; class KPPPInterface;
typedef struct ppp_interface_entry { typedef struct ppp_interface_entry {
PPPInterface *interface; KPPPInterface *interface;
vint32 accessing; vint32 accessing;
bool deleting; bool deleting;
} ppp_interface_entry; } ppp_interface_entry;
/*! \brief Exported by the PPP interface manager kernel module.
You should always create interfaces using either of the CreateInterface()
functions. The manager keeps track of all running connections and automatically
deletes them when they are not needed anymore.
*/
typedef struct ppp_interface_module_info { typedef struct ppp_interface_module_info {
kernel_net_module_info knminfo; kernel_net_module_info knminfo;
//!< Exports needed network module functions.
ppp_interface_id (*CreateInterface)(const driver_settings *settings, ppp_interface_id (*CreateInterface)(const driver_settings *settings,
const driver_settings *profile = NULL,
ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID);
ppp_interface_id (*CreateInterfaceWithName)(const char *name,
const driver_settings *profile = NULL,
ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID); ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID);
// you should always create interfaces using this function
bool (*DeleteInterface)(ppp_interface_id ID); bool (*DeleteInterface)(ppp_interface_id ID);
// this marks the interface for deletion // this marks the interface for deletion
bool (*RemoveInterface)(ppp_interface_id ID); bool (*RemoveInterface)(ppp_interface_id ID);
@@ -10,18 +10,42 @@
#include <module.h> #include <module.h>
class PPPInterface; class KPPPInterface;
//! This structure is exported by PPP kernel modules.
typedef struct ppp_module_info { typedef struct ppp_module_info {
module_info minfo; module_info minfo;
//!< Default kernel module structure.
//! You may define this \e optional function if you want to export a private API.
status_t (*control)(uint32 op, void *data, size_t length); status_t (*control)(uint32 op, void *data, size_t length);
bool (*add_to)(PPPInterface& mainInterface, PPPInterface *subInterface,
/*! \brief Signals your module to add its handlers to the PPP interface.
This function \e must be exported.
Multilink-only: Handlers that must run on a bundle's child should be
added to \a subInterface while \a mainInterface handlers are used for the
bundle interfaces. For example, devices must be added to every child
individually because every \a subInterface establishes its own connection
while the IP Control Protocol is added to the \a mainInterface because
it is shared by all interfaces of the bundle.
\param mainInterface The multilink bundle or (if subInterface == NULL) the
actual interface object.
\param subInterface If defined, this is a child interface of a bundle.
\param settings The settings for your module.
\param type Specifies which key caused loading the module. This would be
\c PPP_AUTHENTICATOR_KEY_TYPE for "authenticator". You should check
if \a type is correct (e.g.: loading an authenticator with "device"
should fail).
\return
\c true: Modules could be added successfully.
*/
bool (*add_to)(KPPPInterface& mainInterface, KPPPInterface *subInterface,
driver_parameter *settings, ppp_module_key_type type); driver_parameter *settings, ppp_module_key_type type);
// multilink: handlers that must run on a real device
// should be added to subInterface (may be NULL)
// while mainInterface handlers are used for the
// bundle of interfaces
} ppp_module_info; } ppp_module_info;
@@ -14,17 +14,17 @@
#include <KPPPInterface.h> #include <KPPPInterface.h>
#endif #endif
class PPPConfigurePacket; class KPPPConfigurePacket;
class PPPOptionHandler { class KPPPOptionHandler {
protected: protected:
// PPPOptionHandler must be subclassed // KPPPOptionHandler must be subclassed
PPPOptionHandler(const char *name, uint8 type, PPPInterface& interface, KPPPOptionHandler(const char *name, uint8 type, KPPPInterface& interface,
driver_parameter *settings); driver_parameter *settings);
public: public:
virtual ~PPPOptionHandler(); virtual ~KPPPOptionHandler();
virtual status_t InitCheck() const; virtual status_t InitCheck() const;
@@ -34,7 +34,7 @@ class PPPOptionHandler {
uint8 Type() const uint8 Type() const
{ return fType; } { return fType; }
PPPInterface& Interface() const KPPPInterface& Interface() const
{ return fInterface; } { return fInterface; }
driver_parameter *Settings() const driver_parameter *Settings() const
{ return fSettings; } { return fSettings; }
@@ -46,23 +46,23 @@ class PPPOptionHandler {
virtual status_t Control(uint32 op, void *data, size_t length); virtual status_t Control(uint32 op, void *data, size_t length);
virtual status_t StackControl(uint32 op, void *data); virtual status_t StackControl(uint32 op, void *data);
// called by netstack (forwarded by PPPInterface) // called by netstack (forwarded by KPPPInterface)
// we want to send a configure request or we received a reply // we want to send a configure request or we received a reply
virtual status_t AddToRequest(PPPConfigurePacket& request) = 0; virtual status_t AddToRequest(KPPPConfigurePacket& request) = 0;
virtual status_t ParseNak(const PPPConfigurePacket& nak) = 0; virtual status_t ParseNak(const KPPPConfigurePacket& nak) = 0;
// create next request based on these and previous values // create next request based on these and previous values
virtual status_t ParseReject(const PPPConfigurePacket& reject) = 0; virtual status_t ParseReject(const KPPPConfigurePacket& reject) = 0;
// create next request based on these and previous values // create next request based on these and previous values
virtual status_t ParseAck(const PPPConfigurePacket& ack) = 0; virtual status_t ParseAck(const KPPPConfigurePacket& ack) = 0;
// this is called for all handlers // this is called for all handlers
// peer sent configure request // peer sent configure request
virtual status_t ParseRequest(const PPPConfigurePacket& request, virtual status_t ParseRequest(const KPPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject) = 0; int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) = 0;
// index may be behind the last item which means additional values can be // index may be behind the last item which means additional values can be
// appended // appended
virtual status_t SendingAck(const PPPConfigurePacket& ack) = 0; virtual status_t SendingAck(const KPPPConfigurePacket& ack) = 0;
// notification that we ack these values // notification that we ack these values
virtual void Reset() = 0; virtual void Reset() = 0;
@@ -74,7 +74,7 @@ class PPPOptionHandler {
private: private:
char *fName; char *fName;
uint8 fType; uint8 fType;
PPPInterface& fInterface; KPPPInterface& fInterface;
driver_parameter *fSettings; driver_parameter *fSettings;
bool fEnabled; bool fEnabled;
@@ -0,0 +1,43 @@
//-----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
//-----------------------------------------------------------------------
#ifndef _K_PPP_PROFILE__H
#define _K_PPP_PROFILE__H
#include <KPPPDefs.h>
class KPPPInterface;
class KPPPProfile {
friend class KPPPInterface;
private:
KPPPProfile(KPPPInterface& interface);
~KPPPProfile();
void LoadSettings(const driver_settings *profile,
driver_settings *interfaceSettings);
public:
//! Returns interface that owns this profile.
KPPPInterface& Interface() const
{ return fInterface; }
//! Returns the loaded profile settings.
const driver_settings *Settings() const
{ return fSettings; }
const driver_parameter *SettingsFor(const char *type, const char *name) const;
// name may be NULL
// size_t Request(void *out, size_t outSize, void *in, size_t inSize) const;
private:
KPPPInterface& fInterface;
driver_settings *fSettings;
};
#endif
@@ -11,23 +11,23 @@
#include <KPPPDefs.h> #include <KPPPDefs.h>
#include <KPPPLayer.h> #include <KPPPLayer.h>
class PPPInterface; class KPPPInterface;
class PPPOptionHandler; class KPPPOptionHandler;
class PPPProtocol : public PPPLayer { class KPPPProtocol : public KPPPLayer {
protected: protected:
// PPPProtocol must be subclassed // KPPPProtocol must be subclassed
PPPProtocol(const char *name, ppp_phase activationPhase, KPPPProtocol(const char *name, ppp_phase activationPhase,
uint16 protocolNumber, ppp_level level, int32 addressFamily, uint16 protocolNumber, ppp_level level, int32 addressFamily,
uint32 overhead, PPPInterface& interface, uint32 overhead, KPPPInterface& interface,
driver_parameter *settings, int32 flags = PPP_NO_FLAGS, driver_parameter *settings, int32 flags = PPP_NO_FLAGS,
const char *type = NULL, PPPOptionHandler *optionHandler = NULL); const char *type = NULL, KPPPOptionHandler *optionHandler = NULL);
public: public:
virtual ~PPPProtocol(); virtual ~KPPPProtocol();
PPPInterface& Interface() const KPPPInterface& Interface() const
{ return fInterface; } { return fInterface; }
driver_parameter *Settings() const driver_parameter *Settings() const
{ return fSettings; } { return fSettings; }
@@ -48,12 +48,12 @@ class PPPProtocol : public PPPLayer {
const char *Type() const const char *Type() const
{ return fType; } { return fType; }
PPPOptionHandler *OptionHandler() const KPPPOptionHandler *OptionHandler() const
{ return fOptionHandler; } { return fOptionHandler; }
void SetNextProtocol(PPPProtocol *protocol) void SetNextProtocol(KPPPProtocol *protocol)
{ fNextProtocol = protocol; SetNext(protocol); } { fNextProtocol = protocol; SetNext(protocol); }
PPPProtocol *NextProtocol() const KPPPProtocol *NextProtocol() const
{ return fNextProtocol; } { return fNextProtocol; }
void SetEnabled(bool enabled = true); void SetEnabled(bool enabled = true);
@@ -65,7 +65,7 @@ class PPPProtocol : public PPPLayer {
virtual status_t Control(uint32 op, void *data, size_t length); virtual status_t Control(uint32 op, void *data, size_t length);
virtual status_t StackControl(uint32 op, void *data); virtual status_t StackControl(uint32 op, void *data);
// called by netstack (forwarded by PPPInterface) // called by netstack (forwarded by KPPPInterface)
virtual bool Up() = 0; virtual bool Up() = 0;
virtual bool Down() = 0; virtual bool Down() = 0;
@@ -105,13 +105,13 @@ class PPPProtocol : public PPPLayer {
ppp_phase fActivationPhase; ppp_phase fActivationPhase;
uint16 fProtocolNumber; uint16 fProtocolNumber;
int32 fAddressFamily; int32 fAddressFamily;
PPPInterface& fInterface; KPPPInterface& fInterface;
driver_parameter *fSettings; driver_parameter *fSettings;
int32 fFlags; int32 fFlags;
char *fType; char *fType;
PPPOptionHandler *fOptionHandler; KPPPOptionHandler *fOptionHandler;
PPPProtocol *fNextProtocol; KPPPProtocol *fNextProtocol;
bool fEnabled; bool fEnabled;
bool fUpRequested; bool fUpRequested;
ppp_phase fConnectionPhase; ppp_phase fConnectionPhase;
@@ -16,12 +16,13 @@
#include <TemplateList.h> #include <TemplateList.h>
#define PPP_REPLY(sender, value) send_data_with_timeout((sender), (value), NULL, 0, PPP_REPORT_TIMEOUT) #define PPP_REPLY(sender, value) \
send_data_with_timeout((sender), (value), NULL, 0, PPP_REPORT_TIMEOUT)
class PPPReportManager { class KPPPReportManager {
public: public:
PPPReportManager(BLocker& lock); KPPPReportManager(BLocker& lock);
~PPPReportManager(); ~KPPPReportManager();
void EnableReports(ppp_report_type type, thread_id thread, void EnableReports(ppp_report_type type, thread_id thread,
int32 flags = PPP_NO_FLAGS); int32 flags = PPP_NO_FLAGS);
@@ -10,7 +10,7 @@
#include <KPPPDefs.h> #include <KPPPDefs.h>
class PPPProtocol; class KPPPProtocol;
#ifndef _K_PPP_INTERFACE__H #ifndef _K_PPP_INTERFACE__H
#include <KPPPInterface.h> #include <KPPPInterface.h>
@@ -19,24 +19,24 @@ class PPPProtocol;
#include <Locker.h> #include <Locker.h>
class PPPStateMachine { class KPPPStateMachine {
friend class PPPInterface;
friend class PPPLCP;
friend class PPPManager; friend class PPPManager;
friend class KPPPInterface;
friend class KPPPLCP;
private: private:
// may only be constructed/destructed by PPPInterface // may only be constructed/destructed by KPPPInterface
PPPStateMachine(PPPInterface& interface); KPPPStateMachine(KPPPInterface& interface);
~PPPStateMachine(); ~KPPPStateMachine();
// copies are not allowed! // copies are not allowed!
PPPStateMachine(const PPPStateMachine& copy); KPPPStateMachine(const KPPPStateMachine& copy);
PPPStateMachine& operator= (const PPPStateMachine& copy); KPPPStateMachine& operator= (const KPPPStateMachine& copy);
public: public:
PPPInterface& Interface() const KPPPInterface& Interface() const
{ return fInterface; } { return fInterface; }
PPPLCP& LCP() const KPPPLCP& LCP() const
{ return fLCP; } { return fLCP; }
ppp_state State() const ppp_state State() const
@@ -78,14 +78,14 @@ class PPPStateMachine {
{ return fPeerAuthenticationStatus; } { return fPeerAuthenticationStatus; }
// sub-interface events // sub-interface events
void UpFailedEvent(PPPInterface& interface); void UpFailedEvent(KPPPInterface& interface);
void UpEvent(PPPInterface& interface); void UpEvent(KPPPInterface& interface);
void DownEvent(PPPInterface& interface); void DownEvent(KPPPInterface& interface);
// protocol events // protocol events
void UpFailedEvent(PPPProtocol *protocol); void UpFailedEvent(KPPPProtocol *protocol);
void UpEvent(PPPProtocol *protocol); void UpEvent(KPPPProtocol *protocol);
void DownEvent(PPPProtocol *protocol); void DownEvent(KPPPProtocol *protocol);
// device events // device events
bool TLSNotify(); bool TLSNotify();
@@ -144,8 +144,8 @@ class PPPStateMachine {
void ResetLCPHandlers(); void ResetLCPHandlers();
private: private:
PPPInterface& fInterface; KPPPInterface& fInterface;
PPPLCP& fLCP; KPPPLCP& fLCP;
ppp_state fState; ppp_state fState;
ppp_phase fPhase; ppp_phase fPhase;
@@ -14,11 +14,11 @@
#include <OS.h> #include <OS.h>
class PPPProtocol; class KPPPProtocol;
// helper functions // helper functions
bool IsProtocolAllowed(const PPPProtocol& protocol); bool IsProtocolAllowed(const KPPPProtocol& protocol);
// the list template does not support iterating over each item :( // the list template does not support iterating over each item :(
// this template iterates over each item in an indexed list // this template iterates over each item in an indexed list
@@ -29,24 +29,28 @@
#define PPP_USER_OPS_START PPP_OPS_START + 32 * PPP_RESERVE_OPS_COUNT #define PPP_USER_OPS_START PPP_OPS_START + 32 * PPP_RESERVE_OPS_COUNT
//! These values should be used for ppp_control_info::op.
enum ppp_control_ops { enum ppp_control_ops {
// ----------------------------------------------------- // -----------------------------------------------------
// PPPManager // PPPManager (the PPP interface module)
PPPC_CREATE_INTERFACE = PPP_OPS_START, PPPC_CREATE_INTERFACE = PPP_OPS_START,
PPPC_CREATE_INTERFACE_WITH_NAME,
PPPC_DELETE_INTERFACE, PPPC_DELETE_INTERFACE,
PPPC_BRING_INTERFACE_UP, PPPC_BRING_INTERFACE_UP,
PPPC_BRING_INTERFACE_DOWN, PPPC_BRING_INTERFACE_DOWN,
PPPC_CONTROL_INTERFACE, PPPC_CONTROL_INTERFACE,
PPPC_GET_INTERFACES, PPPC_GET_INTERFACES,
PPPC_COUNT_INTERFACES, PPPC_COUNT_INTERFACES,
PPPC_FIND_INTERFACE_WITH_SETTINGS,
// ----------------------------------------------------- // -----------------------------------------------------
// ----------------------------------------------------- // -----------------------------------------------------
// PPPInterface // KPPPInterface
PPPC_GET_INTERFACE_INFO = PPP_INTERFACE_OPS_START, PPPC_GET_INTERFACE_INFO = PPP_INTERFACE_OPS_START,
PPPC_SET_MRU, PPPC_SET_MRU,
PPPC_SET_DIAL_ON_DEMAND, PPPC_SET_DIAL_ON_DEMAND,
PPPC_SET_AUTO_REDIAL, PPPC_SET_AUTO_REDIAL,
PPPC_HAS_INTERFACE_SETTINGS,
// handler access // handler access
PPPC_CONTROL_DEVICE, PPPC_CONTROL_DEVICE,
@@ -57,12 +61,12 @@ enum ppp_control_ops {
// ----------------------------------------------------- // -----------------------------------------------------
// ----------------------------------------------------- // -----------------------------------------------------
// PPPDevice // KPPPDevice
PPPC_GET_DEVICE_INFO = PPP_DEVICE_OPS_START, PPPC_GET_DEVICE_INFO = PPP_DEVICE_OPS_START,
// ----------------------------------------------------- // -----------------------------------------------------
// ----------------------------------------------------- // -----------------------------------------------------
// PPPProtocol // KPPPProtocol
PPPC_GET_PROTOCOL_INFO = PPP_PROTOCOL_OPS_START, PPPC_GET_PROTOCOL_INFO = PPP_PROTOCOL_OPS_START,
// ----------------------------------------------------- // -----------------------------------------------------
@@ -70,7 +74,7 @@ enum ppp_control_ops {
// Common/mixed ops // Common/mixed ops
PPPC_ENABLE, PPPC_ENABLE,
PPPC_GET_SIMPLE_HANDLER_INFO, PPPC_GET_SIMPLE_HANDLER_INFO,
// PPPOptionHandler and PPPLCPExtension // KPPPOptionHandler and KPPPLCPExtension
// these two control ops use the ppp_report_request structure // these two control ops use the ppp_report_request structure
PPPC_ENABLE_REPORTS, PPPC_ENABLE_REPORTS,
@@ -82,29 +86,45 @@ enum ppp_control_ops {
}; };
typedef struct ppp_interface_settings_info { //! Basic structure used for creating and searching PPP interfaces.
const driver_settings *settings; typedef struct ppp_interface_description_info {
union {
const driver_settings *settings;
//!< Interface settings.
const char *name;
//!< Name of interface description file.
} u;
//!< Different values for describing an interface.
const driver_settings *profile;
//!<
ppp_interface_id interface; ppp_interface_id interface;
// only when creating: this is the id of the created interface //!< the found/created interface
} ppp_interface_settings_info; } ppp_interface_description_info;
//! Used to get all interface ids from the PPP interface manager.
typedef struct ppp_get_interfaces_info { typedef struct ppp_get_interfaces_info {
ppp_interface_id *interfaces; ppp_interface_id *interfaces;
//!< The interface ids will be written to this pointer's target.
int32 count; int32 count;
//!< \a Interface has \a count entries.
ppp_interface_filter filter; ppp_interface_filter filter;
//!< Only interfaces that match this filter will be returned
int32 resultCount; int32 resultCount;
//!< The number of saved interfaces.
} ppp_get_interfaces_info; } ppp_get_interfaces_info;
//! With this structure you can refer to some handler/interface.
typedef struct ppp_control_info { typedef struct ppp_control_info {
uint32 index; uint32 index;
// index/id of interface/protocol/etc. //!< Index/id of interface/protocol/etc.
uint32 op; uint32 op;
// the Control()/ioctl() opcode //!< The Control()/ioctl() opcode. This can be any value from ppp_control_ops.
void *data; void *data;
//!< Additional data may be specified.
size_t length; size_t length;
// should always be set //!< The length should always be set.
} ppp_control_info; } ppp_control_info;
@@ -116,8 +136,7 @@ typedef struct ppp_control_info {
#define _PPP_INFO_T_SIZE_ 256 #define _PPP_INFO_T_SIZE_ 256
typedef struct ppp_interface_info { typedef struct ppp_interface_info {
const driver_settings *settings; char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
int32 if_unit; int32 if_unit;
// negative if not registered // negative if not registered
@@ -147,7 +166,6 @@ typedef struct ppp_interface_info_t {
typedef struct ppp_device_info { typedef struct ppp_device_info {
char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
const driver_parameter *settings;
uint32 MTU; uint32 MTU;
uint32 inputTransferRate, outputTransferRate, outputBytesCount; uint32 inputTransferRate, outputTransferRate, outputBytesCount;
bool isUp; bool isUp;
@@ -162,7 +180,6 @@ typedef struct ppp_protocol_info {
char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
char type[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; char type[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
const driver_parameter *settings;
ppp_phase activationPhase; ppp_phase activationPhase;
int32 addressFamily, flags; int32 addressFamily, flags;
ppp_side side; ppp_side side;
@@ -189,11 +206,10 @@ typedef struct ppp_protocol_info_t {
typedef struct ppp_simple_handler_info { typedef struct ppp_simple_handler_info {
char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1]; char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
const driver_parameter *settings;
bool isEnabled; bool isEnabled;
uint8 code; uint8 code;
// only PPPLCPExtension // only KPPPLCPExtension
} ppp_simple_handler_info; } ppp_simple_handler_info;
typedef struct ppp_simple_handler_info_t { typedef struct ppp_simple_handler_info_t {
ppp_simple_handler_info info; ppp_simple_handler_info info;
@@ -17,10 +17,15 @@ typedef uint32 ppp_interface_id;
// settings keys // settings keys
#define PPP_DIALING_NOTIFICATION_KEY "DialingNotification"
// userland ppp_server handles this key
#define PPP_DISONNECT_AFTER_IDLE_SINCE_KEY "DisonnectAfterIdleSince" #define PPP_DISONNECT_AFTER_IDLE_SINCE_KEY "DisonnectAfterIdleSince"
#define PPP_MODE_KEY "Mode" #define PPP_MODE_KEY "Mode"
#define PPP_DIAL_RETRIES_LIMIT_KEY "DialRetriesLimit"
#define PPP_DIAL_RETRY_DELAY_KEY "DialRetryDelay"
#define PPP_DIAL_ON_DEMAND_KEY "DialOnDemand" #define PPP_DIAL_ON_DEMAND_KEY "DialOnDemand"
#define PPP_AUTO_REDIAL_KEY "AutoRedial" #define PPP_AUTO_REDIAL_KEY "AutoRedial"
#define PPP_REDIAL_DELAY_KEY "RedialDelay"
#define PPP_LOAD_MODULE_KEY "LoadModule" #define PPP_LOAD_MODULE_KEY "LoadModule"
#define PPP_PROTOCOL_KEY "Protocol" #define PPP_PROTOCOL_KEY "Protocol"
#define PPP_DEVICE_KEY "Device" #define PPP_DEVICE_KEY "Device"
@@ -33,6 +38,8 @@ typedef uint32 ppp_interface_id;
// path defines // path defines
#define PPP_MODULES_PATH NETWORK_MODULES_ROOT "ppp" #define PPP_MODULES_PATH NETWORK_MODULES_ROOT "ppp"
#define PPP_INTERFACE_SETTINGS_PATH "/boot/home/config/settings/kernel/drivers/pppidf"
// should be: /etc/ppp
// built-in protocols // built-in protocols
#define PPP_LCP_PROTOCOL 0xC021 #define PPP_LCP_PROTOCOL 0xC021
@@ -49,17 +56,17 @@ enum ppp_interface_filter {
}; };
// return values for Send()/Receive() methods in addition to B_ERROR and B_OK // return values for Send()/Receive() methods in addition to B_ERROR and B_OK
// PPP_UNHANDLED is also used by PPPOptionHandler // PPP_UNHANDLED is also used by KPPPOptionHandler
enum { enum {
// B_ERROR means that the packet is corrupted // B_ERROR means that the packet is corrupted
// B_OK means the packet was handled correctly // B_OK means the packet was handled correctly
// return values for PPPProtocol // return values for KPPPProtocol
PPP_UNHANDLED = PPP_ERROR_BASE, PPP_UNHANDLED = PPP_ERROR_BASE,
// The packet does not belong to this protocol. // The packet does not belong to this protocol.
// Do not delete the packet when you return this! // Do not delete the packet when you return this!
// return values of PPPInterface::Receive() // return values of KPPPInterface::Receive()
PPP_DISCARDED, PPP_DISCARDED,
// packet was silently discarded // packet was silently discarded
PPP_REJECTED, PPP_REJECTED,
@@ -78,7 +85,7 @@ enum {
PPP_FORCE_PFC_REQUEST = 0x04, 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 PPP_FREEZE_PFC_OPTIONS = 0x80
// the options cannot be changed if this flag is set (mainly used by PPPDevice) // the options cannot be changed if this flag is set (mainly used by KPPPDevice)
}; };
enum ppp_pfc_state { enum ppp_pfc_state {
@@ -124,7 +131,7 @@ enum ppp_phase {
enum ppp_level { enum ppp_level {
PPP_DEVICE_LEVEL = 0, PPP_DEVICE_LEVEL = 0,
PPP_INTERFACE_LEVEL = 1, PPP_INTERFACE_LEVEL = 1,
// only used by PPPInterface // only used by KPPPInterface
PPP_MULTILINK_LEVEL = 2, PPP_MULTILINK_LEVEL = 2,
PPP_ENCRYPTION_LEVEL = 5, PPP_ENCRYPTION_LEVEL = 5,
PPP_COMPRESSION_LEVEL = 10, PPP_COMPRESSION_LEVEL = 10,
@@ -14,6 +14,17 @@
#include <malloc.h> #include <malloc.h>
static char *sSkipInterfaceParameters[] = {
PPP_DIALING_NOTIFICATION_KEY,
PPP_DISONNECT_AFTER_IDLE_SINCE_KEY,
PPP_DIAL_RETRIES_LIMIT_KEY,
PPP_DIAL_RETRY_DELAY_KEY,
PPP_DIAL_ON_DEMAND_KEY,
PPP_AUTO_REDIAL_KEY,
PPP_REDIAL_DELAY_KEY,
NULL
};
static void copy_parameter(const driver_parameter *from, driver_parameter *to); static void copy_parameter(const driver_parameter *from, driver_parameter *to);
static void free_driver_parameter(driver_parameter *parameter); static void free_driver_parameter(driver_parameter *parameter);
@@ -153,6 +164,53 @@ equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs
} }
bool
skip_interface_parameter(const driver_parameter *parameter)
{
if(!parameter || !parameter->name)
return false;
for(int32 index = 0; sSkipInterfaceParameters[index]; index++)
if(!strcasecmp(parameter->name, sSkipInterfaceParameters[index]))
return true;
return false;
}
bool
equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs)
{
if(!lhs && !rhs)
return true;
else if(!lhs || !rhs)
return false;
int32 lhsIndex = 0, rhsIndex = 0;
for(; lhsIndex < lhs->parameter_count; lhsIndex++) {
if(skip_interface_parameter(&lhs->parameters[lhsIndex]))
continue;
for(; rhsIndex < rhs->parameter_count; rhsIndex++)
if(!skip_interface_parameter(&rhs->parameters[rhsIndex]))
break;
if(rhsIndex >= rhs->parameter_count)
return false;
if(!equal_driver_parameters(&lhs->parameters[lhsIndex],
&rhs->parameters[rhsIndex]))
return false;
}
for(; rhsIndex < rhs->parameter_count; rhsIndex++)
if(!skip_interface_parameter(&rhs->parameters[rhsIndex]))
return false;
return true;
}
ppp_side ppp_side
get_side_string_value(const char *sideString, ppp_side unknownValue) get_side_string_value(const char *sideString, ppp_side unknownValue)
{ {
@@ -201,17 +259,27 @@ get_boolean_value(const char *string, bool unknownValue)
} }
const char* const driver_parameter*
get_settings_value(const char *name, const driver_settings *settings) get_parameter_with_name(const char *name, const driver_settings *settings)
{ {
if(!name || !settings) if(!name || !settings)
return NULL; return NULL;
for(int32 index = 0; index < settings->parameter_count; index++) for(int32 index = 0; index < settings->parameter_count; index++)
if(!strcasecmp(settings->parameters[index].name, name) if(!strcasecmp(settings->parameters[index].name, name))
&& settings->parameters[index].value_count > 0 return &settings->parameters[index];
&& settings->parameters[index].values)
return settings->parameters[index].values[0]; return NULL;
}
const char*
get_settings_value(const char *name, const driver_settings *settings)
{
const driver_parameter *parameter = get_parameter_with_name(name, settings);
if(parameter && parameter->value_count > 0 && parameter->values)
return parameter->values[0];
return NULL; return NULL;
} }
@@ -12,18 +12,30 @@
// TODO: remove this as soon as we get the extended driver_settings API // TODO: remove this as soon as we get the extended driver_settings API
driver_settings *dup_driver_settings(const driver_settings *settings); driver_settings *dup_driver_settings(const driver_settings *settings);
void free_driver_settings(driver_settings *settings); void free_driver_settings(driver_settings *settings);
bool equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs); bool equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs);
bool equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs); bool equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs);
bool equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs);
// this compares only the relevant parts of the interface settings
ppp_side get_side_string_value(const char *sideString, ppp_side unknownValue); ppp_side get_side_string_value(const char *sideString, ppp_side unknownValue);
bool get_boolean_value(const char *string, bool unknownValue); bool get_boolean_value(const char *string, bool unknownValue);
const driver_parameter *get_parameter_with_name(const char *name,
const driver_settings *settings);
const char *get_settings_value(const char *name, const driver_settings *settings); const char *get_settings_value(const char *name, const driver_settings *settings);
inline
const driver_parameter*
get_parameter_with_name(const char *name, const driver_parameter *parameters)
{
return get_parameter_with_name(name,
parameters ? (driver_settings*) &parameters->parameter_count : NULL);
}
inline inline
const char* const char*
get_parameter_value(const char *name, const driver_parameter *parameters) get_parameter_value(const char *name, const driver_parameter *parameters)