Style cleanup, patch by Vasilis Kaoutsis - thanks!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20430 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-03-27 00:14:30 +00:00
parent a71744ba3a
commit fc1cf1a3d2
21 changed files with 872 additions and 853 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2004, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -33,21 +33,21 @@ KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)
ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*); ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*);
SetID(header->id); SetID(header->id);
if(!SetCode(header->code)) if (!SetCode(header->code))
return; return;
uint16 length = ntohs(header->length); uint16 length = ntohs(header->length);
if(length < 6 || length > packet->m_len) if (length < 6 || length > packet->m_len)
return; return;
// there are no items (or one corrupted item) // there are no items (or one corrupted item)
int32 position = 0; int32 position = 0;
ppp_configure_item *item; ppp_configure_item *item;
while(position < length - 4) { while (position < length - 4) {
item = (ppp_configure_item*) (header->data + position); item = (ppp_configure_item*) (header->data + position);
if(item->length < 2) if (item->length < 2)
return; return;
// found a corrupted item // found a corrupted item
@@ -60,7 +60,7 @@ KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)
//! Frees all items. //! Frees all items.
KPPPConfigurePacket::~KPPPConfigurePacket() KPPPConfigurePacket::~KPPPConfigurePacket()
{ {
for(int32 index = 0; index < CountItems(); index++) for (int32 index = 0; index < CountItems(); index++)
free(ItemAt(index)); free(ItemAt(index));
} }
@@ -70,7 +70,7 @@ bool
KPPPConfigurePacket::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)
return false; return false;
fCode = code; fCode = code;
@@ -94,18 +94,18 @@ KPPPConfigurePacket::SetCode(uint8 code)
bool bool
KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index) KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index)
{ {
if(!item || item->length < 2) if (!item || item->length < 2)
return false; return false;
ppp_configure_item *add = (ppp_configure_item*) malloc(item->length); ppp_configure_item *add = (ppp_configure_item*) malloc(item->length);
memcpy(add, item, item->length); memcpy(add, item, item->length);
bool status; bool status;
if(index < 0) if (index < 0)
status = fItems.AddItem(add); status = fItems.AddItem(add);
else else
status = fItems.AddItem(add, index); status = fItems.AddItem(add, index);
if(!status) { if (!status) {
free(add); free(add);
return false; return false;
} }
@@ -118,7 +118,7 @@ KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index)
bool bool
KPPPConfigurePacket::RemoveItem(ppp_configure_item *item) KPPPConfigurePacket::RemoveItem(ppp_configure_item *item)
{ {
if(!fItems.HasItem(item)) if (!fItems.HasItem(item))
return false; return false;
fItems.RemoveItem(item); fItems.RemoveItem(item);
@@ -134,7 +134,7 @@ KPPPConfigurePacket::ItemAt(int32 index) const
{ {
ppp_configure_item *item = fItems.ItemAt(index); ppp_configure_item *item = fItems.ItemAt(index);
if(item == fItems.GetDefaultItem()) if (item == fItems.GetDefaultItem())
return NULL; return NULL;
return item; return item;
@@ -147,9 +147,9 @@ KPPPConfigurePacket::ItemWithType(uint8 type) const
{ {
ppp_configure_item *item; ppp_configure_item *item;
for(int32 index = 0; index < CountItems(); index++) { for (int32 index = 0; index < CountItems(); index++) {
item = ItemAt(index); item = ItemAt(index);
if(item && item->type == type) if (item && item->type == type)
return item; return item;
} }
@@ -180,11 +180,11 @@ KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve)
uint16 length = 0; uint16 length = 0;
ppp_configure_item *item; ppp_configure_item *item;
for(int32 index = 0; index < CountItems(); index++) { for (int32 index = 0; index < CountItems(); index++) {
item = ItemAt(index); item = ItemAt(index);
// make sure we have enough space left // make sure we have enough space left
if(MRU - length < item->length) { if (MRU - length < item->length) {
m_freem(packet); m_freem(packet);
return NULL; return NULL;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2004, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -40,7 +40,7 @@ KPPPDevice::KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interfa
//! Destructor. Removes device from interface. //! Destructor. Removes device from interface.
KPPPDevice::~KPPPDevice() KPPPDevice::~KPPPDevice()
{ {
if(Interface().Device() == this) if (Interface().Device() == this)
Interface().SetDevice(NULL); Interface().SetDevice(NULL);
} }
@@ -52,21 +52,21 @@ KPPPDevice::~KPPPDevice()
status_t status_t
KPPPDevice::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:
if(length < sizeof(ppp_device_info_t) || !data) if (length < sizeof(ppp_device_info_t) || !data)
return B_NO_MEMORY; return B_NO_MEMORY;
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));
if(Name()) if (Name())
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->MTU = MTU(); info->MTU = MTU();
info->inputTransferRate = InputTransferRate(); info->inputTransferRate = InputTransferRate();
info->outputTransferRate = OutputTransferRate(); info->outputTransferRate = OutputTransferRate();
info->outputBytesCount = CountOutputBytes(); info->outputBytesCount = CountOutputBytes();
info->isUp = IsUp(); info->isUp = IsUp();
} break; break;
default: default:
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -90,7 +90,7 @@ status_t
KPPPDevice::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)
return Interface().ReceiveFromDevice(packet); return Interface().ReceiveFromDevice(packet);
else else
return Interface().Receive(packet, protocolNumber); return Interface().Receive(packet, protocolNumber);
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2006, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -26,7 +26,8 @@
//! Creates a new LCP protocol for the given interface. //! Creates a new LCP protocol for the given interface.
KPPPLCP::KPPPLCP(KPPPInterface& interface) KPPPLCP::KPPPLCP(KPPPInterface& interface)
: KPPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL, :
KPPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL,
PPP_PROTOCOL_LEVEL, AF_UNSPEC, 0, interface, NULL, PPP_ALWAYS_ALLOWED), PPP_PROTOCOL_LEVEL, AF_UNSPEC, 0, interface, NULL, PPP_ALWAYS_ALLOWED),
fStateMachine(interface.StateMachine()), fStateMachine(interface.StateMachine()),
fTarget(NULL) fTarget(NULL)
@@ -39,9 +40,9 @@ KPPPLCP::KPPPLCP(KPPPInterface& interface)
//! Deletes all added option handlers and LCP extensions. //! Deletes all added option handlers and LCP extensions.
KPPPLCP::~KPPPLCP() KPPPLCP::~KPPPLCP()
{ {
while(CountOptionHandlers()) while (CountOptionHandlers())
delete OptionHandlerAt(0); delete OptionHandlerAt(0);
while(CountLCPExtensions()) while (CountLCPExtensions())
delete LCPExtensionAt(0); delete LCPExtensionAt(0);
} }
@@ -54,10 +55,10 @@ KPPPLCP::~KPPPLCP()
bool bool
KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler) KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler)
{ {
if(!optionHandler || &optionHandler->Interface() != &Interface()) if (!optionHandler || &optionHandler->Interface() != &Interface())
return false; return false;
if(Interface().Phase() != PPP_DOWN_PHASE if (Interface().Phase() != PPP_DOWN_PHASE
|| OptionHandlerFor(optionHandler->Type())) || OptionHandlerFor(optionHandler->Type()))
return false; return false;
// a running connection may not change and there may only be // a running connection may not change and there may only be
@@ -74,7 +75,7 @@ KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler)
bool bool
KPPPLCP::RemoveOptionHandler(KPPPOptionHandler *optionHandler) KPPPLCP::RemoveOptionHandler(KPPPOptionHandler *optionHandler)
{ {
if(Interface().Phase() != PPP_DOWN_PHASE) if (Interface().Phase() != PPP_DOWN_PHASE)
return false; return false;
// a running connection may not change // a running connection may not change
@@ -88,7 +89,7 @@ KPPPLCP::OptionHandlerAt(int32 index) const
{ {
KPPPOptionHandler *optionHandler = fOptionHandlers.ItemAt(index); KPPPOptionHandler *optionHandler = fOptionHandlers.ItemAt(index);
if(optionHandler == fOptionHandlers.GetDefaultItem()) if (optionHandler == fOptionHandlers.GetDefaultItem())
return NULL; return NULL;
return optionHandler; return optionHandler;
@@ -105,14 +106,14 @@ KPPPLCP::OptionHandlerFor(uint8 type, int32 *start) const
int32 index = start ? *start : 0; int32 index = start ? *start : 0;
if(index < 0) if (index < 0)
return NULL; return NULL;
KPPPOptionHandler *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) {
if(start) if (start)
*start = index; *start = index;
return current; return current;
} }
@@ -129,10 +130,10 @@ KPPPLCP::OptionHandlerFor(uint8 type, int32 *start) const
bool bool
KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension) KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension)
{ {
if(!lcpExtension || &lcpExtension->Interface() != &Interface()) if (!lcpExtension || &lcpExtension->Interface() != &Interface())
return false; return false;
if(Interface().Phase() != PPP_DOWN_PHASE) if (Interface().Phase() != PPP_DOWN_PHASE)
return false; return false;
// a running connection may not change // a running connection may not change
@@ -147,7 +148,7 @@ KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension)
bool bool
KPPPLCP::RemoveLCPExtension(KPPPLCPExtension *lcpExtension) KPPPLCP::RemoveLCPExtension(KPPPLCPExtension *lcpExtension)
{ {
if(Interface().Phase() != PPP_DOWN_PHASE) if (Interface().Phase() != PPP_DOWN_PHASE)
return false; return false;
// a running connection may not change // a running connection may not change
@@ -161,7 +162,7 @@ KPPPLCP::LCPExtensionAt(int32 index) const
{ {
KPPPLCPExtension *lcpExtension = fLCPExtensions.ItemAt(index); KPPPLCPExtension *lcpExtension = fLCPExtensions.ItemAt(index);
if(lcpExtension == fLCPExtensions.GetDefaultItem()) if (lcpExtension == fLCPExtensions.GetDefaultItem())
return NULL; return NULL;
return lcpExtension; return lcpExtension;
@@ -178,14 +179,14 @@ KPPPLCP::LCPExtensionFor(uint8 code, int32 *start) const
int32 index = start ? *start : 0; int32 index = start ? *start : 0;
if(index < 0) if (index < 0)
return NULL; return NULL;
KPPPLCPExtension *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) {
if(start) if (start)
*start = index; *start = index;
return current; return current;
} }
@@ -201,10 +202,10 @@ KPPPLCP::AdditionalOverhead() const
{ {
uint32 overhead = Interface().Overhead(); uint32 overhead = Interface().Overhead();
if(Target()) if (Target())
overhead += Target()->Overhead(); overhead += Target()->Overhead();
if(Interface().Device()) if (Interface().Device())
overhead += Interface().Device()->Overhead(); overhead += Interface().Device()->Overhead();
return overhead; return overhead;
@@ -231,7 +232,7 @@ KPPPLCP::Down()
status_t status_t
KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber) KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber)
{ {
if(Target()) if (Target())
return Target()->Send(packet, PPP_LCP_PROTOCOL); return Target()->Send(packet, PPP_LCP_PROTOCOL);
else else
return Interface().Send(packet, PPP_LCP_PROTOCOL); return Interface().Send(packet, PPP_LCP_PROTOCOL);
@@ -242,10 +243,10 @@ KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber)
status_t status_t
KPPPLCP::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) {
ERROR("KPPPLCP::Receive(): wrong protocol number!\n"); ERROR("KPPPLCP::Receive(): wrong protocol number!\n");
return PPP_UNHANDLED; return PPP_UNHANDLED;
} }
@@ -254,25 +255,25 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
// remove padding // remove padding
int32 length = packet->m_len; int32 length = packet->m_len;
if(packet->m_flags & M_PKTHDR) if (packet->m_flags & M_PKTHDR)
length = packet->m_pkthdr.len; length = packet->m_pkthdr.len;
length -= ntohs(data->length); length -= ntohs(data->length);
if(length) if (length)
m_adj(packet, -length); m_adj(packet, -length);
struct mbuf *copy = m_gethdr(MT_DATA); struct mbuf *copy = m_gethdr(MT_DATA);
if(copy) { if (copy) {
copy->m_data += AdditionalOverhead(); copy->m_data += AdditionalOverhead();
copy->m_pkthdr.len = copy->m_len = packet->m_len; copy->m_pkthdr.len = copy->m_len = packet->m_len;
memcpy(copy->m_data, packet->m_data, copy->m_len); memcpy(copy->m_data, packet->m_data, copy->m_len);
} }
if(ntohs(data->length) < 4) if (ntohs(data->length) < 4)
return B_ERROR; return B_ERROR;
bool handled = true; bool handled = true;
switch(data->code) { switch (data->code) {
case PPP_CONFIGURE_REQUEST: case PPP_CONFIGURE_REQUEST:
StateMachine().RCREvent(packet); StateMachine().RCREvent(packet);
break; break;
@@ -315,7 +316,7 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
packet = copy; packet = copy;
if(!packet) if (!packet)
return handled ? B_OK : B_ERROR; return handled ? B_OK : B_ERROR;
status_t result = B_OK; status_t result = B_OK;
@@ -324,22 +325,22 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
// 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;
KPPPLCPExtension *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;
result = lcpExtension->Receive(packet, data->code); result = lcpExtension->Receive(packet, data->code);
// check return value and return it on error // check return value and return it on error
if(result == B_OK) if (result == B_OK)
handled = true; handled = true;
else if(result != PPP_UNHANDLED) { else if (result != PPP_UNHANDLED) {
m_freem(packet); m_freem(packet);
return result; return result;
} }
} }
if(!handled) { if (!handled) {
StateMachine().RUCEvent(packet, PPP_LCP_PROTOCOL, PPP_CODE_REJECT); StateMachine().RUCEvent(packet, PPP_LCP_PROTOCOL, PPP_CODE_REJECT);
return PPP_REJECTED; return PPP_REJECTED;
} }
@@ -356,6 +357,6 @@ KPPPLCP::Pulse()
{ {
StateMachine().TimerEvent(); StateMachine().TimerEvent();
for(int32 index = 0; index < CountLCPExtensions(); index++) for (int32 index = 0; index < CountLCPExtensions(); index++)
LCPExtensionAt(index)->Pulse(); LCPExtensionAt(index)->Pulse();
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -10,7 +10,6 @@
*/ */
#include <KPPPLCPExtension.h> #include <KPPPLCPExtension.h>
#include <PPPControl.h> #include <PPPControl.h>
@@ -31,7 +30,7 @@ KPPPLCPExtension::KPPPLCPExtension(const char *name, uint8 code,
fCode(code), fCode(code),
fEnabled(true) fEnabled(true)
{ {
if(name) if (name)
fName = strdup(name); fName = strdup(name);
else else
fName = NULL; fName = NULL;
@@ -59,20 +58,22 @@ KPPPLCPExtension::InitCheck() const
status_t status_t
KPPPLCPExtension::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:
if(length < sizeof(ppp_simple_handler_info_t) || !data) {
if (length < sizeof(ppp_simple_handler_info_t) || !data)
return B_ERROR; return B_ERROR;
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));
if(Name()) if (Name())
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->isEnabled = IsEnabled(); info->isEnabled = IsEnabled();
} break; break;
}
case PPPC_ENABLE: case PPPC_ENABLE:
if(length < sizeof(uint32) || !data) if (length < sizeof(uint32) || !data)
return B_ERROR; return B_ERROR;
SetEnabled(*((uint32*)data)); SetEnabled(*((uint32*)data));
@@ -90,7 +91,7 @@ KPPPLCPExtension::Control(uint32 op, void *data, size_t length)
status_t status_t
KPPPLCPExtension::StackControl(uint32 op, void *data) KPPPLCPExtension::StackControl(uint32 op, void *data)
{ {
switch(op) { switch (op) {
default: default:
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -58,13 +58,13 @@ KPPPLayer::InitCheck() const
status_t status_t
KPPPLayer::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;
// Find the next possible handler for this packet. // Find the next possible handler for this packet.
// Normal protocols (Level() >= PPP_PROTOCOL_LEVEL) do not encapsulate anything. // Normal protocols (Level() >= PPP_PROTOCOL_LEVEL) do not encapsulate anything.
if(Next()) { if (Next()) {
if(Next()->IsAllowedToSend() && Next()->Level() < PPP_PROTOCOL_LEVEL) if (Next()->IsAllowedToSend() && Next()->Level() < PPP_PROTOCOL_LEVEL)
return Next()->Send(packet, protocolNumber); return Next()->Send(packet, protocolNumber);
else else
return Next()->SendToNext(packet, protocolNumber); return Next()->SendToNext(packet, protocolNumber);
@@ -93,7 +93,7 @@ KPPPLayer::SetName(const char *name)
{ {
free(fName); free(fName);
if(name) if (name)
fName = strdup(name); fName = strdup(name);
else else
fName = NULL; fName = NULL;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -25,13 +25,14 @@
*/ */
KPPPOptionHandler::KPPPOptionHandler(const char *name, uint8 type, KPPPOptionHandler::KPPPOptionHandler(const char *name, uint8 type,
KPPPInterface& interface, driver_parameter *settings) KPPPInterface& interface, driver_parameter *settings)
: fInitStatus(B_OK), :
fInitStatus(B_OK),
fType(type), fType(type),
fInterface(interface), fInterface(interface),
fSettings(settings), fSettings(settings),
fEnabled(true) fEnabled(true)
{ {
if(name) if (name)
fName = strdup(name); fName = strdup(name);
else else
fName = NULL; fName = NULL;
@@ -59,20 +60,22 @@ KPPPOptionHandler::InitCheck() const
status_t status_t
KPPPOptionHandler::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:
if(length < sizeof(ppp_simple_handler_info_t) || !data) {
if (length < sizeof(ppp_simple_handler_info_t) || !data)
return B_ERROR; return B_ERROR;
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));
if(Name()) if (Name())
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->isEnabled = IsEnabled(); info->isEnabled = IsEnabled();
} break; break;
}
case PPPC_ENABLE: case PPPC_ENABLE:
if(length < sizeof(uint32) || !data) if (length < sizeof(uint32) || !data)
return B_ERROR; return B_ERROR;
SetEnabled(*((uint32*)data)); SetEnabled(*((uint32*)data));
@@ -90,7 +93,7 @@ KPPPOptionHandler::Control(uint32 op, void *data, size_t length)
status_t status_t
KPPPOptionHandler::StackControl(uint32 op, void *data) KPPPOptionHandler::StackControl(uint32 op, void *data)
{ {
switch(op) { switch (op) {
default: default:
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2004, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -43,7 +43,8 @@ KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase,
uint32 overhead, KPPPInterface& interface, uint32 overhead, KPPPInterface& interface,
driver_parameter *settings, int32 flags, driver_parameter *settings, int32 flags,
const char *type, KPPPOptionHandler *optionHandler) const char *type, KPPPOptionHandler *optionHandler)
: KPPPLayer(name, level, overhead), :
KPPPLayer(name, level, overhead),
fActivationPhase(activationPhase), fActivationPhase(activationPhase),
fProtocolNumber(protocolNumber), fProtocolNumber(protocolNumber),
fAddressFamily(addressFamily), fAddressFamily(addressFamily),
@@ -56,16 +57,16 @@ KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase,
fUpRequested(true), fUpRequested(true),
fConnectionPhase(PPP_DOWN_PHASE) fConnectionPhase(PPP_DOWN_PHASE)
{ {
if(type) if (type)
fType = strdup(type); fType = strdup(type);
else else
fType = NULL; fType = NULL;
const char *sideString = get_parameter_value("side", settings); const char *sideString = get_parameter_value("side", settings);
if(sideString) if (sideString)
fSide = get_side_string_value(sideString, PPP_LOCAL_SIDE); fSide = get_side_string_value(sideString, PPP_LOCAL_SIDE);
else { else {
if(interface.Mode() == PPP_CLIENT_MODE) if (interface.Mode() == PPP_CLIENT_MODE)
fSide = PPP_LOCAL_SIDE; fSide = PPP_LOCAL_SIDE;
else else
fSide = PPP_PEER_SIDE; fSide = PPP_PEER_SIDE;
@@ -77,7 +78,6 @@ KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase,
KPPPProtocol::~KPPPProtocol() KPPPProtocol::~KPPPProtocol()
{ {
Interface().RemoveProtocol(this); Interface().RemoveProtocol(this);
free(fType); free(fType);
} }
@@ -100,16 +100,17 @@ KPPPProtocol::Uninit()
status_t status_t
KPPPProtocol::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:
if(length < sizeof(ppp_protocol_info_t) || !data) {
if (length < sizeof(ppp_protocol_info_t) || !data)
return B_ERROR; return B_ERROR;
ppp_protocol_info *info = (ppp_protocol_info*) data; ppp_protocol_info *info = (ppp_protocol_info*) data;
memset(info, 0, sizeof(ppp_protocol_info_t)); memset(info, 0, sizeof(ppp_protocol_info_t));
if(Name()) if (Name())
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
if(Type()) if (Type())
strncpy(info->type, Type(), PPP_HANDLER_NAME_LENGTH_LIMIT); strncpy(info->type, Type(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->activationPhase = ActivationPhase(); info->activationPhase = ActivationPhase();
info->addressFamily = AddressFamily(); info->addressFamily = AddressFamily();
@@ -121,10 +122,11 @@ KPPPProtocol::Control(uint32 op, void *data, size_t length)
info->protocolNumber = ProtocolNumber(); info->protocolNumber = ProtocolNumber();
info->isEnabled = IsEnabled(); info->isEnabled = IsEnabled();
info->isUpRequested = IsUpRequested(); info->isUpRequested = IsUpRequested();
} break; break;
}
case PPPC_ENABLE: case PPPC_ENABLE:
if(length < sizeof(uint32) || !data) if (length < sizeof(uint32) || !data)
return B_ERROR; return B_ERROR;
SetEnabled(*((uint32*)data)); SetEnabled(*((uint32*)data));
@@ -142,7 +144,7 @@ KPPPProtocol::Control(uint32 op, void *data, size_t length)
status_t status_t
KPPPProtocol::StackControl(uint32 op, void *data) KPPPProtocol::StackControl(uint32 op, void *data)
{ {
switch(op) { switch (op) {
default: default:
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -160,10 +162,10 @@ KPPPProtocol::SetEnabled(bool enabled)
{ {
fEnabled = enabled; fEnabled = enabled;
if(!enabled) { if (!enabled) {
if(IsUp() || IsGoingUp()) if (IsUp() || IsGoingUp())
Down(); Down();
} else if(!IsUp() && !IsGoingUp() && IsUpRequested() && Interface().IsUp()) } else if (!IsUp() && !IsGoingUp() && IsUpRequested() && Interface().IsUp())
Up(); Up();
} }
@@ -207,7 +209,6 @@ void
KPPPProtocol::UpFailedEvent() KPPPProtocol::UpFailedEvent()
{ {
fConnectionPhase = PPP_DOWN_PHASE; fConnectionPhase = PPP_DOWN_PHASE;
Interface().StateMachine().UpFailedEvent(this); Interface().StateMachine().UpFailedEvent(this);
} }
@@ -220,7 +221,6 @@ void
KPPPProtocol::UpEvent() KPPPProtocol::UpEvent()
{ {
fConnectionPhase = PPP_ESTABLISHED_PHASE; fConnectionPhase = PPP_ESTABLISHED_PHASE;
Interface().StateMachine().UpEvent(this); Interface().StateMachine().UpEvent(this);
} }
@@ -233,6 +233,5 @@ void
KPPPProtocol::DownEvent() KPPPProtocol::DownEvent()
{ {
fConnectionPhase = PPP_DOWN_PHASE; fConnectionPhase = PPP_DOWN_PHASE;
Interface().StateMachine().DownEvent(this); Interface().StateMachine().DownEvent(this);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -42,7 +42,7 @@ KPPPReportManager::KPPPReportManager(BLocker& lock)
//! Deletes all report requests. //! Deletes all report requests.
KPPPReportManager::~KPPPReportManager() 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);
} }
@@ -57,10 +57,10 @@ KPPPReportManager::~KPPPReportManager()
bool bool
KPPPReportManager::SendReport(thread_id thread, const ppp_report_packet *report) KPPPReportManager::SendReport(thread_id thread, const ppp_report_packet *report)
{ {
if(!report) if (!report)
return false; return false;
if(thread == find_thread(NULL)) { if (thread == find_thread(NULL)) {
report_sender_info *info = new report_sender_info; report_sender_info *info = new report_sender_info;
info->thread = thread; info->thread = thread;
memcpy(&info->report, report, sizeof(ppp_report_packet)); memcpy(&info->report, report, sizeof(ppp_report_packet));
@@ -85,7 +85,7 @@ void
KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread, KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread,
int32 flags) int32 flags)
{ {
if(thread < 0 || type == PPP_ALL_REPORTS) if (thread < 0 || type == PPP_ALL_REPORTS)
return; return;
LockerHelper locker(fLock); LockerHelper locker(fLock);
@@ -103,25 +103,25 @@ KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread,
void void
KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread) KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread)
{ {
if(thread < 0) if (thread < 0)
return; return;
LockerHelper locker(fLock); LockerHelper locker(fLock);
ppp_report_request *request; ppp_report_request *request;
for(int32 i = 0; i < fReportRequests.CountItems(); i++) { for (int32 i = 0; i < fReportRequests.CountItems(); i++) {
request = fReportRequests.ItemAt(i); request = fReportRequests.ItemAt(i);
if(request->thread != thread) if (request->thread != thread)
continue; continue;
if(request->type == type || type == PPP_ALL_REPORTS) if (request->type == type || type == PPP_ALL_REPORTS)
fReportRequests.RemoveItem(request); fReportRequests.RemoveItem(request);
} }
// empty message queue // empty message queue
while(has_data(thread)) { while (has_data(thread)) {
thread_id sender; thread_id sender;
receive_data(&sender, NULL, 0); receive_data(&sender, NULL, 0);
} }
@@ -132,17 +132,17 @@ KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread)
bool bool
KPPPReportManager::DoesReport(ppp_report_type type, thread_id thread) KPPPReportManager::DoesReport(ppp_report_type type, thread_id thread)
{ {
if(thread < 0) if (thread < 0)
return false; return false;
LockerHelper locker(fLock); LockerHelper locker(fLock);
ppp_report_request *request; ppp_report_request *request;
for(int32 i = 0; i < fReportRequests.CountItems(); i++) { for (int32 i = 0; i < fReportRequests.CountItems(); i++) {
request = fReportRequests.ItemAt(i); request = fReportRequests.ItemAt(i);
if(request->thread == thread && request->type == type) if (request->thread == thread && request->type == type)
return true; return true;
} }
@@ -168,13 +168,13 @@ KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le
TRACE("KPPPReportManager: Report(type=%d code=%ld length=%ld) to %ld receivers\n", TRACE("KPPPReportManager: Report(type=%d code=%ld length=%ld) to %ld receivers\n",
type, code, length, fReportRequests.CountItems()); type, code, length, fReportRequests.CountItems());
if(length > PPP_REPORT_DATA_LIMIT) if (length > PPP_REPORT_DATA_LIMIT)
return false; return false;
if(fReportRequests.CountItems() == 0) if (fReportRequests.CountItems() == 0)
return true; return true;
if(!data) if (!data)
length = 0; length = 0;
LockerHelper locker(fLock); LockerHelper locker(fLock);
@@ -190,22 +190,22 @@ KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le
ppp_report_request *request; ppp_report_request *request;
for(int32 index = 0; index < fReportRequests.CountItems(); index++) { for (int32 index = 0; index < fReportRequests.CountItems(); index++) {
request = fReportRequests.ItemAt(index); request = fReportRequests.ItemAt(index);
// do not send to yourself // do not send to yourself
if(request->thread == me) if (request->thread == me)
continue; continue;
result = send_data_with_timeout(request->thread, PPP_REPORT_CODE, &report, result = send_data_with_timeout(request->thread, PPP_REPORT_CODE, &report,
sizeof(report), PPP_REPORT_TIMEOUT); sizeof(report), PPP_REPORT_TIMEOUT);
#if DEBUG #if DEBUG
if(result == B_TIMED_OUT) if (result == B_TIMED_OUT)
TRACE("KPPPReportManager::Report(): timed out sending\n"); TRACE("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
|| request->flags & PPP_REMOVE_AFTER_REPORT) { || request->flags & PPP_REMOVE_AFTER_REPORT) {
fReportRequests.RemoveItem(request); fReportRequests.RemoveItem(request);
--index; --index;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2006, Waldemar Kornewald <[email protected]> * Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -81,10 +81,10 @@ KPPPStateMachine::NewState(ppp_state next)
TRACE("KPPPSM: NewState(%d) state=%d\n", next, State()); TRACE("KPPPSM: NewState(%d) state=%d\n", next, State());
// maybe we do not need the timer anymore // maybe we do not need the timer anymore
if(next < PPP_CLOSING_STATE || next == PPP_OPENED_STATE) if (next < PPP_CLOSING_STATE || next == PPP_OPENED_STATE)
fNextTimeout = 0; fNextTimeout = 0;
if(State() == PPP_OPENED_STATE && next != State()) if (State() == PPP_OPENED_STATE && next != State())
ResetLCPHandlers(); ResetLCPHandlers();
fState = next; fState = next;
@@ -100,34 +100,34 @@ void
KPPPStateMachine::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)
TRACE("KPPPSM: NewPhase(%d) phase=%d\n", next, Phase()); TRACE("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
if(next > PPP_ESTABLISHED_PHASE) if (next > PPP_ESTABLISHED_PHASE)
next = PPP_ESTABLISHED_PHASE; next = PPP_ESTABLISHED_PHASE;
else if(next < PPP_DOWN_PHASE) else if (next < PPP_DOWN_PHASE)
next = PPP_DOWN_PHASE; next = PPP_DOWN_PHASE;
// Report a down event to parent if we are not usable anymore. // Report a down event to parent if we are not usable anymore.
// The report threads get their notification later. // The report threads get their notification later.
if(Phase() == PPP_ESTABLISHED_PHASE && next != Phase()) { if (Phase() == PPP_ESTABLISHED_PHASE && next != Phase()) {
if(Interface().Ifnet()) { if (Interface().Ifnet()) {
Interface().Ifnet()->if_flags &= ~IFF_RUNNING; Interface().Ifnet()->if_flags &= ~IFF_RUNNING;
Interface().Ifnet()->if_flags &= ~IFF_UP; Interface().Ifnet()->if_flags &= ~IFF_UP;
} }
if(Interface().Parent()) if (Interface().Parent())
Interface().Parent()->StateMachine().DownEvent(Interface()); Interface().Parent()->StateMachine().DownEvent(Interface());
} }
fPhase = next; fPhase = next;
if(Phase() == PPP_ESTABLISHED_PHASE) { if (Phase() == PPP_ESTABLISHED_PHASE) {
Interface().fConnectedSince = system_time(); Interface().fConnectedSince = system_time();
if(Interface().Ifnet()) if (Interface().Ifnet())
Interface().Ifnet()->if_flags |= IFF_UP | IFF_RUNNING; Interface().Ifnet()->if_flags |= IFF_UP | IFF_RUNNING;
Interface().fConnectAttempt = 0; Interface().fConnectAttempt = 0;
@@ -149,7 +149,7 @@ KPPPStateMachine::Reconfigure()
{ {
TRACE("KPPPSM: Reconfigure() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: Reconfigure() state=%d phase=%d\n", State(), Phase());
if(State() < PPP_REQ_SENT_STATE) if (State() < PPP_REQ_SENT_STATE)
return false; return false;
NewState(PPP_REQ_SENT_STATE); NewState(PPP_REQ_SENT_STATE);
@@ -169,11 +169,11 @@ KPPPStateMachine::SendEchoRequest()
{ {
TRACE("KPPPSM: SendEchoRequest() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: SendEchoRequest() state=%d phase=%d\n", State(), Phase());
if(State() != PPP_OPENED_STATE) if (State() != PPP_OPENED_STATE)
return false; return false;
struct mbuf *packet = m_gethdr(MT_DATA); struct mbuf *packet = m_gethdr(MT_DATA);
if(!packet) if (!packet)
return false; return false;
packet->m_data += LCP().AdditionalOverhead(); packet->m_data += LCP().AdditionalOverhead();
@@ -197,11 +197,11 @@ KPPPStateMachine::SendDiscardRequest()
{ {
TRACE("KPPPSM: SendDiscardRequest() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: SendDiscardRequest() state=%d phase=%d\n", State(), Phase());
if(State() != PPP_OPENED_STATE) if (State() != PPP_OPENED_STATE)
return false; return false;
struct mbuf *packet = m_gethdr(MT_DATA); struct mbuf *packet = m_gethdr(MT_DATA);
if(!packet) if (!packet)
return false; return false;
packet->m_data += LCP().AdditionalOverhead(); packet->m_data += LCP().AdditionalOverhead();
@@ -255,7 +255,7 @@ KPPPStateMachine::LocalAuthenticationAccepted(const char *name)
fLocalAuthenticationStatus = PPP_AUTHENTICATION_SUCCESSFUL; fLocalAuthenticationStatus = PPP_AUTHENTICATION_SUCCESSFUL;
free(fLocalAuthenticationName); free(fLocalAuthenticationName);
if(name) if (name)
fLocalAuthenticationName = strdup(name); fLocalAuthenticationName = strdup(name);
else else
fLocalAuthenticationName = NULL; fLocalAuthenticationName = NULL;
@@ -275,7 +275,7 @@ KPPPStateMachine::LocalAuthenticationDenied(const char *name)
fLocalAuthenticationStatus = PPP_AUTHENTICATION_FAILED; fLocalAuthenticationStatus = PPP_AUTHENTICATION_FAILED;
free(fLocalAuthenticationName); free(fLocalAuthenticationName);
if(name) if (name)
fLocalAuthenticationName = strdup(name); fLocalAuthenticationName = strdup(name);
else else
fLocalAuthenticationName = NULL; fLocalAuthenticationName = NULL;
@@ -316,7 +316,7 @@ KPPPStateMachine::PeerAuthenticationAccepted(const char *name)
fPeerAuthenticationStatus = PPP_AUTHENTICATION_SUCCESSFUL; fPeerAuthenticationStatus = PPP_AUTHENTICATION_SUCCESSFUL;
free(fPeerAuthenticationName); free(fPeerAuthenticationName);
if(name) if (name)
fPeerAuthenticationName = strdup(name); fPeerAuthenticationName = strdup(name);
else else
fPeerAuthenticationName = NULL; fPeerAuthenticationName = NULL;
@@ -336,7 +336,7 @@ KPPPStateMachine::PeerAuthenticationDenied(const char *name)
fPeerAuthenticationStatus = PPP_AUTHENTICATION_FAILED; fPeerAuthenticationStatus = PPP_AUTHENTICATION_FAILED;
free(fPeerAuthenticationName); free(fPeerAuthenticationName);
if(name) if (name)
fPeerAuthenticationName = strdup(name); fPeerAuthenticationName = strdup(name);
else else
fPeerAuthenticationName = NULL; fPeerAuthenticationName = NULL;
@@ -364,18 +364,18 @@ KPPPStateMachine::UpEvent(KPPPInterface& interface)
{ {
TRACE("KPPPSM: UpEvent(interface) state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: UpEvent(interface) state=%d phase=%d\n", State(), Phase());
if(Phase() <= PPP_TERMINATION_PHASE) { if (Phase() <= PPP_TERMINATION_PHASE) {
interface.StateMachine().CloseEvent(); interface.StateMachine().CloseEvent();
return; return;
} }
Interface().CalculateBaudRate(); Interface().CalculateBaudRate();
if(Phase() == PPP_ESTABLISHMENT_PHASE) { if (Phase() == PPP_ESTABLISHMENT_PHASE) {
// this is the first interface that went up // this is the first interface that went up
Interface().SetMRU(interface.MRU()); Interface().SetMRU(interface.MRU());
ThisLayerUp(); ThisLayerUp();
} else if(Interface().MRU() > interface.MRU()) } else if (Interface().MRU() > interface.MRU())
Interface().SetMRU(interface.MRU()); Interface().SetMRU(interface.MRU());
// MRU should always be the smallest value of all children // MRU should always be the smallest value of all children
@@ -395,29 +395,29 @@ KPPPStateMachine::DownEvent(KPPPInterface& interface)
Interface().CalculateBaudRate(); Interface().CalculateBaudRate();
// 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;
KPPPInterface *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);
if(child && child->IsUp()) { if (child && child->IsUp()) {
// set MRU to the smallest value of all children // set MRU to the smallest value of all children
if(MRU == 0) if (MRU == 0)
MRU = child->MRU(); MRU = child->MRU();
else if(MRU > child->MRU()) else if (MRU > child->MRU())
MRU = child->MRU(); MRU = child->MRU();
++count; ++count;
} }
} }
if(MRU == 0) if (MRU == 0)
Interface().SetMRU(1500); Interface().SetMRU(1500);
else else
Interface().SetMRU(MRU); Interface().SetMRU(MRU);
if(count == 0) if (count == 0)
DownEvent(); DownEvent();
} }
} }
@@ -433,13 +433,13 @@ KPPPStateMachine::UpFailedEvent(KPPPProtocol *protocol)
{ {
TRACE("KPPPSM: UpFailedEvent(protocol) state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: UpFailedEvent(protocol) state=%d phase=%d\n", State(), Phase());
if((protocol->Flags() & PPP_NOT_IMPORTANT) == 0) { if ((protocol->Flags() & PPP_NOT_IMPORTANT) == 0) {
if(Interface().Mode() == PPP_CLIENT_MODE) { if (Interface().Mode() == PPP_CLIENT_MODE) {
// pretend we lost connection // pretend we lost connection
if(Interface().IsMultilink() && !Interface().Parent()) if (Interface().IsMultilink() && !Interface().Parent())
for(int32 index = 0; index < Interface().CountChildren(); index++) for (int32 index = 0; index < Interface().CountChildren(); index++)
Interface().ChildAt(index)->StateMachine().CloseEvent(); Interface().ChildAt(index)->StateMachine().CloseEvent();
else if(Interface().Device()) else if (Interface().Device())
Interface().Device()->Down(); Interface().Device()->Down();
else else
CloseEvent(); CloseEvent();
@@ -460,7 +460,7 @@ KPPPStateMachine::UpEvent(KPPPProtocol *protocol)
{ {
TRACE("KPPPSM: UpEvent(protocol) state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: UpEvent(protocol) state=%d phase=%d\n", State(), Phase());
if(Phase() >= PPP_ESTABLISHMENT_PHASE) if (Phase() >= PPP_ESTABLISHMENT_PHASE)
BringProtocolsUp(); BringProtocolsUp();
} }
@@ -490,8 +490,8 @@ KPPPStateMachine::TLSNotify()
{ {
TRACE("KPPPSM: TLSNotify() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: TLSNotify() state=%d phase=%d\n", State(), Phase());
if(State() == PPP_STARTING_STATE) { if (State() == PPP_STARTING_STATE) {
if(Phase() == PPP_DOWN_PHASE) if (Phase() == PPP_DOWN_PHASE)
NewPhase(PPP_ESTABLISHMENT_PHASE); NewPhase(PPP_ESTABLISHMENT_PHASE);
// this says that the device is going up // this says that the device is going up
return true; return true;
@@ -527,12 +527,12 @@ KPPPStateMachine::UpFailedEvent()
{ {
TRACE("KPPPSM: UpFailedEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: UpFailedEvent() state=%d phase=%d\n", State(), Phase());
switch(State()) { switch (State()) {
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
fLastConnectionReportCode = PPP_REPORT_DEVICE_UP_FAILED; fLastConnectionReportCode = PPP_REPORT_DEVICE_UP_FAILED;
Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_DEVICE_UP_FAILED, Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_DEVICE_UP_FAILED,
&fInterface.fID, sizeof(ppp_interface_id)); &fInterface.fID, sizeof(ppp_interface_id));
if(Interface().Parent()) if (Interface().Parent())
Interface().Parent()->StateMachine().UpFailedEvent(Interface()); Interface().Parent()->StateMachine().UpFailedEvent(Interface());
NewPhase(PPP_DOWN_PHASE); NewPhase(PPP_DOWN_PHASE);
@@ -555,15 +555,15 @@ KPPPStateMachine::UpEvent()
// This call is public, thus, it might not only be called by the device. // This call is public, thus, it might not only be called by the device.
// We must recognize these attempts to fool us and handle them correctly. // We must recognize these attempts to fool us and handle them correctly.
if(!Interface().Device() || !Interface().Device()->IsUp()) if (!Interface().Device() || !Interface().Device()->IsUp())
return; return;
// it is not our device that went up... // it is not our device that went up...
Interface().CalculateBaudRate(); Interface().CalculateBaudRate();
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
if(Interface().Mode() != PPP_SERVER_MODE if (Interface().Mode() != PPP_SERVER_MODE
|| Phase() != PPP_ESTABLISHMENT_PHASE) { || Phase() != PPP_ESTABLISHMENT_PHASE) {
// we are a client or we do not listen for an incoming // we are a client or we do not listen for an incoming
// connection, so this is an illegal event // connection, so this is an illegal event
@@ -582,7 +582,7 @@ KPPPStateMachine::UpEvent()
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
// we must have called TLS() which sets establishment phase // we must have called TLS() which sets establishment phase
if(Phase() != PPP_ESTABLISHMENT_PHASE) { if (Phase() != PPP_ESTABLISHMENT_PHASE) {
// there must be a BUG in the device add-on or someone is trying to // there must be a BUG in the device add-on or someone is trying to
// fool us (UpEvent() is public) as we did not request the device // fool us (UpEvent() is public) as we did not request the device
// to go up // to go up
@@ -613,7 +613,7 @@ KPPPStateMachine::DownEvent()
{ {
TRACE("KPPPSM: DownEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: DownEvent() state=%d phase=%d\n", State(), Phase());
if(Interface().Device() && Interface().Device()->IsUp()) if (Interface().Device() && Interface().Device()->IsUp())
return; return;
// it is not our device that went down... // it is not our device that went down...
@@ -622,7 +622,7 @@ KPPPStateMachine::DownEvent()
// reset IdleSince // reset IdleSince
Interface().fIdleSince = 0; Interface().fIdleSince = 0;
switch(State()) { switch (State()) {
// XXX: this does not belong to the standard, but may happen in our // XXX: this does not belong to the standard, but may happen in our
// implementation // implementation
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
@@ -657,11 +657,11 @@ KPPPStateMachine::DownEvent()
DownProtocols(); DownProtocols();
// maybe we need to reconnect // maybe we need to reconnect
if(State() == PPP_STARTING_STATE) { if (State() == PPP_STARTING_STATE) {
bool deleteInterface = false, retry = false; bool deleteInterface = false, retry = false;
// we do not try to reconnect if authentication failed // we do not try to reconnect if authentication failed
if(fLocalAuthenticationStatus == PPP_AUTHENTICATION_FAILED if (fLocalAuthenticationStatus == PPP_AUTHENTICATION_FAILED
|| fLocalAuthenticationStatus == PPP_AUTHENTICATING || fLocalAuthenticationStatus == PPP_AUTHENTICATING
|| fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED || fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED
|| fPeerAuthenticationStatus == PPP_AUTHENTICATING) { || fPeerAuthenticationStatus == PPP_AUTHENTICATING) {
@@ -671,10 +671,10 @@ KPPPStateMachine::DownEvent()
sizeof(ppp_interface_id)); sizeof(ppp_interface_id));
deleteInterface = true; deleteInterface = true;
} else { } else {
if(Interface().fConnectAttempt > (Interface().fConnectRetriesLimit + 1)) if (Interface().fConnectAttempt > (Interface().fConnectRetriesLimit + 1))
deleteInterface = true; deleteInterface = true;
if(oldPhase == PPP_DOWN_PHASE) { if (oldPhase == PPP_DOWN_PHASE) {
// failed to bring device up (UpFailedEvent() was called) // failed to bring device up (UpFailedEvent() was called)
retry = true; retry = true;
// this may have been overridden by "deleteInterface = true" // this may have been overridden by "deleteInterface = true"
@@ -686,12 +686,12 @@ KPPPStateMachine::DownEvent()
} }
} }
if(Interface().Parent()) if (Interface().Parent())
Interface().Parent()->StateMachine().UpFailedEvent(Interface()); Interface().Parent()->StateMachine().UpFailedEvent(Interface());
NewState(PPP_INITIAL_STATE); NewState(PPP_INITIAL_STATE);
if(!deleteInterface && (retry || Interface().DoesAutoReconnect())) if (!deleteInterface && (retry || Interface().DoesAutoReconnect()))
Interface().Reconnect(Interface().ReconnectDelay()); Interface().Reconnect(Interface().ReconnectDelay());
else else
Interface().Delete(); Interface().Delete();
@@ -714,33 +714,33 @@ KPPPStateMachine::OpenEvent()
TRACE("KPPPSM: OpenEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: OpenEvent() state=%d phase=%d\n", State(), Phase());
// reset all handlers // reset all handlers
if(Phase() != PPP_ESTABLISHED_PHASE) { if (Phase() != PPP_ESTABLISHED_PHASE) {
DownProtocols(); DownProtocols();
ResetLCPHandlers(); ResetLCPHandlers();
} }
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
fLastConnectionReportCode = PPP_REPORT_GOING_UP; fLastConnectionReportCode = PPP_REPORT_GOING_UP;
Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_GOING_UP, Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_GOING_UP,
&fInterface.fID, sizeof(ppp_interface_id)); &fInterface.fID, sizeof(ppp_interface_id));
if(Interface().Mode() == PPP_SERVER_MODE) { if (Interface().Mode() == PPP_SERVER_MODE) {
NewPhase(PPP_ESTABLISHMENT_PHASE); NewPhase(PPP_ESTABLISHMENT_PHASE);
if(Interface().Device() && !Interface().Device()->Up()) { if (Interface().Device() && !Interface().Device()->Up()) {
Interface().Device()->UpFailedEvent(); Interface().Device()->UpFailedEvent();
return; return;
} }
} else } else
NewState(PPP_STARTING_STATE); NewState(PPP_STARTING_STATE);
if(Interface().fAskBeforeConnecting == false) if (Interface().fAskBeforeConnecting == false)
ContinueOpenEvent(); ContinueOpenEvent();
break; break;
case PPP_CLOSED_STATE: case PPP_CLOSED_STATE:
if(Phase() == PPP_DOWN_PHASE) { if (Phase() == PPP_DOWN_PHASE) {
// the device is already going down // the device is already going down
return; return;
} }
@@ -766,10 +766,10 @@ KPPPStateMachine::ContinueOpenEvent()
{ {
TRACE("KPPPSM: ContinueOpenEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: ContinueOpenEvent() state=%d phase=%d\n", State(), Phase());
if(Interface().IsMultilink() && !Interface().Parent()) { if (Interface().IsMultilink() && !Interface().Parent()) {
NewPhase(PPP_ESTABLISHMENT_PHASE); NewPhase(PPP_ESTABLISHMENT_PHASE);
for(int32 index = 0; index < Interface().CountChildren(); index++) for (int32 index = 0; index < Interface().CountChildren(); index++)
if(Interface().ChildAt(index)->Mode() == Interface().Mode()) if (Interface().ChildAt(index)->Mode() == Interface().Mode())
Interface().ChildAt(index)->StateMachine().OpenEvent(); Interface().ChildAt(index)->StateMachine().OpenEvent();
} else } else
ThisLayerStarted(); ThisLayerStarted();
@@ -781,21 +781,21 @@ KPPPStateMachine::CloseEvent()
{ {
TRACE("KPPPSM: CloseEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: CloseEvent() state=%d phase=%d\n", State(), Phase());
if(Interface().IsMultilink() && !Interface().Parent()) { if (Interface().IsMultilink() && !Interface().Parent()) {
NewState(PPP_INITIAL_STATE); NewState(PPP_INITIAL_STATE);
if(Phase() != PPP_DOWN_PHASE) if (Phase() != PPP_DOWN_PHASE)
NewPhase(PPP_TERMINATION_PHASE); NewPhase(PPP_TERMINATION_PHASE);
ThisLayerDown(); ThisLayerDown();
for(int32 index = 0; index < Interface().CountChildren(); index++) for (int32 index = 0; index < Interface().CountChildren(); index++)
Interface().ChildAt(index)->StateMachine().CloseEvent(); Interface().ChildAt(index)->StateMachine().CloseEvent();
return; return;
} }
switch(State()) { switch (State()) {
case PPP_OPENED_STATE: case PPP_OPENED_STATE:
case PPP_REQ_SENT_STATE: case PPP_REQ_SENT_STATE:
case PPP_ACK_RCVD_STATE: case PPP_ACK_RCVD_STATE:
@@ -804,7 +804,7 @@ KPPPStateMachine::CloseEvent()
NewPhase(PPP_TERMINATION_PHASE); NewPhase(PPP_TERMINATION_PHASE);
// indicates to handlers that we are terminating // indicates to handlers that we are terminating
InitializeRestartCount(); InitializeRestartCount();
if(State() == PPP_OPENED_STATE) if (State() == PPP_OPENED_STATE)
ThisLayerDown(); ThisLayerDown();
SendTerminateRequest(); SendTerminateRequest();
break; break;
@@ -814,7 +814,7 @@ KPPPStateMachine::CloseEvent()
// TLSNotify() will know that we were faster because we // TLSNotify() will know that we were faster because we
// are in PPP_INITIAL_STATE now // are in PPP_INITIAL_STATE now
if(Phase() == PPP_ESTABLISHMENT_PHASE) { if (Phase() == PPP_ESTABLISHMENT_PHASE) {
// the device is already up // the device is already up
NewPhase(PPP_DOWN_PHASE); NewPhase(PPP_DOWN_PHASE);
// this says the following DownEvent() was not caused by // this says the following DownEvent() was not caused by
@@ -843,7 +843,7 @@ KPPPStateMachine::TOGoodEvent()
{ {
TRACE("KPPPSM: TOGoodEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: TOGoodEvent() state=%d phase=%d\n", State(), Phase());
switch(State()) { switch (State()) {
case PPP_CLOSING_STATE: case PPP_CLOSING_STATE:
case PPP_STOPPING_STATE: case PPP_STOPPING_STATE:
SendTerminateRequest(); SendTerminateRequest();
@@ -869,7 +869,7 @@ KPPPStateMachine::TOBadEvent()
{ {
TRACE("KPPPSM: TOBadEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: TOBadEvent() state=%d phase=%d\n", State(), Phase());
switch(State()) { switch (State()) {
case PPP_CLOSING_STATE: case PPP_CLOSING_STATE:
NewState(PPP_CLOSED_STATE); NewState(PPP_CLOSED_STATE);
NewPhase(PPP_TERMINATION_PHASE); NewPhase(PPP_TERMINATION_PHASE);
@@ -897,7 +897,7 @@ KPPPStateMachine::RCRGoodEvent(struct mbuf *packet)
{ {
TRACE("KPPPSM: RCRGoodEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: RCRGoodEvent() state=%d phase=%d\n", State(), Phase());
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RCR_GOOD_EVENT); IllegalEvent(PPP_RCR_GOOD_EVENT);
@@ -949,7 +949,7 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject)
{ {
TRACE("KPPPSM: RCRBadEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: RCRBadEvent() state=%d phase=%d\n", State(), Phase());
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RCR_BAD_EVENT); IllegalEvent(PPP_RCR_BAD_EVENT);
@@ -972,15 +972,15 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject)
SendConfigureRequest(); SendConfigureRequest();
case PPP_ACK_SENT_STATE: case PPP_ACK_SENT_STATE:
if(State() == PPP_ACK_SENT_STATE) if (State() == PPP_ACK_SENT_STATE)
NewState(PPP_REQ_SENT_STATE); NewState(PPP_REQ_SENT_STATE);
// OPENED_STATE might have set this already // OPENED_STATE might have set this already
case PPP_REQ_SENT_STATE: case PPP_REQ_SENT_STATE:
case PPP_ACK_RCVD_STATE: case PPP_ACK_RCVD_STATE:
if(nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3) if (nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3)
SendConfigureNak(nak); SendConfigureNak(nak);
else if(reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3) else if (reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3)
SendConfigureNak(reject); SendConfigureNak(reject);
return; return;
// prevents the nak/reject from being m_freem()'d // prevents the nak/reject from being m_freem()'d
@@ -989,9 +989,9 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject)
; ;
} }
if(nak) if (nak)
m_freem(nak); m_freem(nak);
if(reject) if (reject)
m_freem(reject); m_freem(reject);
} }
@@ -1002,7 +1002,7 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet)
{ {
TRACE("KPPPSM: RCAEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: RCAEvent() state=%d phase=%d\n", State(), Phase());
if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { if (fRequestID != mtod(packet, ppp_lcp_packet*)->id) {
// this packet is not a reply to our request // this packet is not a reply to our request
// TODO: // TODO:
@@ -1014,16 +1014,16 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet)
// let the option handlers parse this ack // let the option handlers parse this ack
KPPPConfigurePacket ack(packet); KPPPConfigurePacket ack(packet);
KPPPOptionHandler *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) {
m_freem(packet); m_freem(packet);
CloseEvent(); CloseEvent();
return; return;
} }
} }
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RCA_EVENT); IllegalEvent(PPP_RCA_EVENT);
@@ -1072,7 +1072,7 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet)
{ {
TRACE("KPPPSM: RCNEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: RCNEvent() state=%d phase=%d\n", State(), Phase());
if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { if (fRequestID != mtod(packet, ppp_lcp_packet*)->id) {
// this packet is not a reply to our request // this packet is not a reply to our request
// TODO: // TODO:
@@ -1084,17 +1084,17 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet)
// let the option handlers parse this nak/reject // let the option handlers parse this nak/reject
KPPPConfigurePacket nak_reject(packet); KPPPConfigurePacket nak_reject(packet);
KPPPOptionHandler *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(nak_reject.Code() == PPP_CONFIGURE_NAK) { if (nak_reject.Code() == PPP_CONFIGURE_NAK) {
if(optionHandler->ParseNak(nak_reject) != B_OK) { if (optionHandler->ParseNak(nak_reject) != B_OK) {
m_freem(packet); m_freem(packet);
CloseEvent(); CloseEvent();
return; return;
} }
} else if(nak_reject.Code() == PPP_CONFIGURE_REJECT) { } else if (nak_reject.Code() == PPP_CONFIGURE_REJECT) {
if(optionHandler->ParseReject(nak_reject) != B_OK) { if (optionHandler->ParseReject(nak_reject) != B_OK) {
m_freem(packet); m_freem(packet);
CloseEvent(); CloseEvent();
return; return;
@@ -1102,7 +1102,7 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet)
} }
} }
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RCN_EVENT); IllegalEvent(PPP_RCN_EVENT);
@@ -1118,7 +1118,7 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet)
InitializeRestartCount(); InitializeRestartCount();
case PPP_ACK_RCVD_STATE: case PPP_ACK_RCVD_STATE:
if(State() == PPP_ACK_RCVD_STATE) if (State() == PPP_ACK_RCVD_STATE)
NewState(PPP_REQ_SENT_STATE); NewState(PPP_REQ_SENT_STATE);
SendConfigureRequest(); SendConfigureRequest();
break; break;
@@ -1146,13 +1146,13 @@ KPPPStateMachine::RTREvent(struct mbuf *packet)
TRACE("KPPPSM: RTREvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: RTREvent() state=%d phase=%d\n", State(), Phase());
// 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)
fID -= 128; fID -= 128;
fLocalAuthenticationStatus = PPP_NOT_AUTHENTICATED; fLocalAuthenticationStatus = PPP_NOT_AUTHENTICATED;
fPeerAuthenticationStatus = PPP_NOT_AUTHENTICATED; fPeerAuthenticationStatus = PPP_NOT_AUTHENTICATED;
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RTR_EVENT); IllegalEvent(PPP_RTR_EVENT);
@@ -1190,7 +1190,7 @@ KPPPStateMachine::RTAEvent(struct mbuf *packet)
{ {
TRACE("KPPPSM: RTAEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: RTAEvent() state=%d phase=%d\n", State(), Phase());
if(fTerminateID != mtod(packet, ppp_lcp_packet*)->id) { if (fTerminateID != mtod(packet, ppp_lcp_packet*)->id) {
// this packet is not a reply to our request // this packet is not a reply to our request
// TODO: // TODO:
@@ -1199,7 +1199,7 @@ KPPPStateMachine::RTAEvent(struct mbuf *packet)
return; return;
} }
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RTA_EVENT); IllegalEvent(PPP_RTA_EVENT);
@@ -1242,7 +1242,7 @@ KPPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber,
{ {
TRACE("KPPPSM: RUCEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: RUCEvent() state=%d phase=%d\n", State(), Phase());
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RUC_EVENT); IllegalEvent(PPP_RUC_EVENT);
@@ -1264,7 +1264,7 @@ KPPPStateMachine::RXJGoodEvent(struct mbuf *packet)
// This method does not m_freem(packet) because the acceptable rejects are // This method does not m_freem(packet) because the acceptable rejects are
// also passed to the parent. RXJEvent() will m_freem(packet) when needed. // also passed to the parent. RXJEvent() will m_freem(packet) when needed.
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RXJ_GOOD_EVENT); IllegalEvent(PPP_RXJ_GOOD_EVENT);
@@ -1286,7 +1286,7 @@ KPPPStateMachine::RXJBadEvent(struct mbuf *packet)
{ {
TRACE("KPPPSM: RXJBadEvent() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: RXJBadEvent() state=%d phase=%d\n", State(), Phase());
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RXJ_BAD_EVENT); IllegalEvent(PPP_RXJ_BAD_EVENT);
@@ -1333,19 +1333,19 @@ KPPPStateMachine::RXREvent(struct mbuf *packet)
ppp_lcp_packet *echo = mtod(packet, ppp_lcp_packet*); ppp_lcp_packet *echo = mtod(packet, ppp_lcp_packet*);
if(echo->code == PPP_ECHO_REPLY && echo->id != fEchoID) { if (echo->code == PPP_ECHO_REPLY && echo->id != fEchoID) {
// TODO: // TODO:
// log that we got a reply, but no request was sent // log that we got a reply, but no request was sent
} }
switch(State()) { switch (State()) {
case PPP_INITIAL_STATE: case PPP_INITIAL_STATE:
case PPP_STARTING_STATE: case PPP_STARTING_STATE:
IllegalEvent(PPP_RXR_EVENT); IllegalEvent(PPP_RXR_EVENT);
break; break;
case PPP_OPENED_STATE: case PPP_OPENED_STATE:
if(echo->code == PPP_ECHO_REQUEST) if (echo->code == PPP_ECHO_REQUEST)
SendEchoReply(packet); SendEchoReply(packet);
return; return;
// this prevents the packet from being freed // this prevents the packet from being freed
@@ -1363,19 +1363,19 @@ void
KPPPStateMachine::TimerEvent() KPPPStateMachine::TimerEvent()
{ {
#if DEBUG #if DEBUG
if(fNextTimeout != 0) if (fNextTimeout != 0)
TRACE("KPPPSM: TimerEvent()\n"); TRACE("KPPPSM: TimerEvent()\n");
#endif #endif
if(fNextTimeout == 0 || fNextTimeout > system_time()) if (fNextTimeout == 0 || fNextTimeout > system_time())
return; return;
fNextTimeout = 0; fNextTimeout = 0;
switch(State()) { switch (State()) {
case PPP_CLOSING_STATE: case PPP_CLOSING_STATE:
case PPP_STOPPING_STATE: case PPP_STOPPING_STATE:
if(fTerminateCounter <= 0) if (fTerminateCounter <= 0)
TOBadEvent(); TOBadEvent();
else else
TOGoodEvent(); TOGoodEvent();
@@ -1384,7 +1384,7 @@ KPPPStateMachine::TimerEvent()
case PPP_REQ_SENT_STATE: case PPP_REQ_SENT_STATE:
case PPP_ACK_RCVD_STATE: case PPP_ACK_RCVD_STATE:
case PPP_ACK_SENT_STATE: case PPP_ACK_SENT_STATE:
if(fRequestCounter <= 0) if (fRequestCounter <= 0)
TOBadEvent(); TOBadEvent();
else else
TOGoodEvent(); TOGoodEvent();
@@ -1409,7 +1409,7 @@ KPPPStateMachine::RCREvent(struct mbuf *packet)
KPPPConfigurePacket 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)
fID -= 128; fID -= 128;
nak.SetID(request.ID()); nak.SetID(request.ID());
@@ -1419,10 +1419,10 @@ KPPPStateMachine::RCREvent(struct mbuf *packet)
status_t result; status_t result;
// the return value of ParseRequest() // the return value of ParseRequest()
KPPPOptionHandler *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()) {
ERROR("KPPPSM::RCREvent():unknown type:%d\n", request.ItemAt(index)->type); ERROR("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));
@@ -1433,11 +1433,11 @@ KPPPStateMachine::RCREvent(struct mbuf *packet)
optionHandler->Name() ? optionHandler->Name() : "Unknown"); optionHandler->Name() ? optionHandler->Name() : "Unknown");
result = optionHandler->ParseRequest(request, index, nak, reject); result = optionHandler->ParseRequest(request, index, nak, reject);
if(result == PPP_UNHANDLED) { if (result == PPP_UNHANDLED) {
// 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;
} 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
ERROR("KPPPSM::RCREvent(): OptionHandler returned parse error!\n"); ERROR("KPPPSM::RCREvent(): OptionHandler returned parse error!\n");
@@ -1449,14 +1449,14 @@ KPPPStateMachine::RCREvent(struct mbuf *packet)
// Additional values may be appended. // Additional values may be appended.
// If we sent too many naks we should not append additional values. // If we sent too many naks we should not append additional values.
if(fNakCounter > 0) { if (fNakCounter > 0) {
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 && optionHandler->IsEnabled()) { if (optionHandler && optionHandler->IsEnabled()) {
result = optionHandler->ParseRequest(request, request.CountItems(), result = optionHandler->ParseRequest(request, request.CountItems(),
nak, reject); nak, reject);
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
ERROR("KPPPSM::RCREvent():OptionHandler returned append error!\n"); ERROR("KPPPSM::RCREvent():OptionHandler returned append error!\n");
@@ -1468,10 +1468,10 @@ KPPPStateMachine::RCREvent(struct mbuf *packet)
} }
} }
if(reject.CountItems() > 0) { if (reject.CountItems() > 0) {
RCRBadEvent(NULL, reject.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead())); RCRBadEvent(NULL, reject.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead()));
m_freem(packet); m_freem(packet);
} else if(nak.CountItems() > 0) { } else if (nak.CountItems() > 0) {
RCRBadEvent(nak.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead()), NULL); RCRBadEvent(nak.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead()), NULL);
m_freem(packet); m_freem(packet);
} else } else
@@ -1489,12 +1489,12 @@ KPPPStateMachine::RXJEvent(struct mbuf *packet)
ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*); ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*);
if(reject->code == PPP_CODE_REJECT) { if (reject->code == PPP_CODE_REJECT) {
uint8 rejectedCode = reject->data[0]; uint8 rejectedCode = reject->data[0];
// test if the rejected code belongs to the minimum LCP requirements // test if the rejected code belongs to the minimum LCP requirements
if(rejectedCode >= PPP_MIN_LCP_CODE && rejectedCode <= PPP_MAX_LCP_CODE) { if (rejectedCode >= PPP_MIN_LCP_CODE && rejectedCode <= PPP_MAX_LCP_CODE) {
if(Interface().IsMultilink() && !Interface().Parent()) { if (Interface().IsMultilink() && !Interface().Parent()) {
// Main interfaces do not have states between STARTING and OPENED. // Main interfaces do not have states between STARTING and OPENED.
// An RXJBadEvent() would enter one of those states which is bad. // An RXJBadEvent() would enter one of those states which is bad.
m_freem(packet); m_freem(packet);
@@ -1507,20 +1507,20 @@ KPPPStateMachine::RXJEvent(struct mbuf *packet)
// find the LCP extension and disable it // find the LCP extension and disable it
KPPPLCPExtension *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);
if(lcpExtension->Code() == rejectedCode) if (lcpExtension->Code() == rejectedCode)
lcpExtension->SetEnabled(false); lcpExtension->SetEnabled(false);
} }
m_freem(packet); m_freem(packet);
} else if(reject->code == PPP_PROTOCOL_REJECT) { } else if (reject->code == PPP_PROTOCOL_REJECT) {
// disable all handlers for rejected protocol type // disable all handlers for rejected protocol type
uint16 rejected = *((uint16*) reject->data); uint16 rejected = *((uint16*) reject->data);
// rejected protocol number // rejected protocol number
if(rejected == PPP_LCP_PROTOCOL) { if (rejected == PPP_LCP_PROTOCOL) {
// LCP must not be rejected! // LCP must not be rejected!
RXJBadEvent(packet); RXJBadEvent(packet);
return; return;
@@ -1528,8 +1528,8 @@ KPPPStateMachine::RXJEvent(struct mbuf *packet)
// disable protocols with the rejected protocol number // disable protocols with the rejected protocol number
KPPPProtocol *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);
// disable protocol // disable protocol
} }
@@ -1538,7 +1538,7 @@ KPPPStateMachine::RXJEvent(struct mbuf *packet)
// this event handler does not m_freem(packet)!!! // this event handler does not m_freem(packet)!!!
// notify parent, too // notify parent, too
if(Interface().Parent()) if (Interface().Parent())
Interface().Parent()->StateMachine().RXJEvent(packet); Interface().Parent()->StateMachine().RXJEvent(packet);
else else
m_freem(packet); m_freem(packet);
@@ -1566,7 +1566,7 @@ KPPPStateMachine::ThisLayerUp()
// We stop when we reach established phase. // We stop when we reach established phase.
// Do not forget to check if we are going down. // Do not forget to check if we are going down.
if(Phase() != PPP_ESTABLISHMENT_PHASE) if (Phase() != PPP_ESTABLISHMENT_PHASE)
return; return;
NewPhase(PPP_AUTHENTICATION_PHASE); NewPhase(PPP_AUTHENTICATION_PHASE);
@@ -1590,7 +1590,7 @@ KPPPStateMachine::ThisLayerStarted()
{ {
TRACE("KPPPSM: ThisLayerStarted() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: ThisLayerStarted() state=%d phase=%d\n", State(), Phase());
if(Interface().Device() && !Interface().Device()->Up()) if (Interface().Device() && !Interface().Device()->Up())
Interface().Device()->UpFailedEvent(); Interface().Device()->UpFailedEvent();
} }
@@ -1600,7 +1600,7 @@ KPPPStateMachine::ThisLayerFinished()
{ {
TRACE("KPPPSM: ThisLayerFinished() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: ThisLayerFinished() state=%d phase=%d\n", State(), Phase());
if(Interface().Device()) if (Interface().Device())
Interface().Device()->Down(); Interface().Device()->Down();
} }
@@ -1635,9 +1635,9 @@ KPPPStateMachine::SendConfigureRequest()
request.SetID(NextID()); request.SetID(NextID());
fRequestID = request.ID(); fRequestID = request.ID();
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) {
// add all items // add all items
if(LCP().OptionHandlerAt(index)->AddToRequest(request) != B_OK) { if (LCP().OptionHandlerAt(index)->AddToRequest(request) != B_OK) {
CloseEvent(); CloseEvent();
return false; return false;
} }
@@ -1653,15 +1653,15 @@ KPPPStateMachine::SendConfigureAck(struct mbuf *packet)
{ {
TRACE("KPPPSM: SendConfigureAck() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: SendConfigureAck() state=%d phase=%d\n", State(), Phase());
if(!packet) if (!packet)
return false; return false;
mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK; mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK;
KPPPConfigurePacket 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++) {
if(LCP().OptionHandlerAt(index)->SendingAck(ack) != B_OK) { if (LCP().OptionHandlerAt(index)->SendingAck(ack) != B_OK) {
m_freem(packet); m_freem(packet);
CloseEvent(); CloseEvent();
return false; return false;
@@ -1677,12 +1677,12 @@ KPPPStateMachine::SendConfigureNak(struct mbuf *packet)
{ {
TRACE("KPPPSM: SendConfigureNak() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: SendConfigureNak() state=%d phase=%d\n", State(), Phase());
if(!packet) if (!packet)
return false; return false;
ppp_lcp_packet *nak = mtod(packet, ppp_lcp_packet*); ppp_lcp_packet *nak = mtod(packet, ppp_lcp_packet*);
if(nak->code == PPP_CONFIGURE_NAK) { if (nak->code == PPP_CONFIGURE_NAK) {
if(fNakCounter == 0) { if (fNakCounter == 0) {
// We sent enough naks. Let's try a reject. // We sent enough naks. Let's try a reject.
nak->code = PPP_CONFIGURE_REJECT; nak->code = PPP_CONFIGURE_REJECT;
} else } else
@@ -1702,7 +1702,7 @@ KPPPStateMachine::SendTerminateRequest()
fNextTimeout = system_time() + kPPPStateMachineTimeout; fNextTimeout = system_time() + kPPPStateMachineTimeout;
struct mbuf *packet = m_gethdr(MT_DATA); struct mbuf *packet = m_gethdr(MT_DATA);
if(!packet) if (!packet)
return false; return false;
packet->m_pkthdr.len = packet->m_len = 4; packet->m_pkthdr.len = packet->m_len = 4;
@@ -1728,9 +1728,9 @@ KPPPStateMachine::SendTerminateAck(struct mbuf *request)
ppp_lcp_packet *ack; ppp_lcp_packet *ack;
if(!reply) { if (!reply) {
reply = m_gethdr(MT_DATA); reply = m_gethdr(MT_DATA);
if(!reply) if (!reply)
return false; return false;
reply->m_data += LCP().AdditionalOverhead(); reply->m_data += LCP().AdditionalOverhead();
@@ -1754,12 +1754,12 @@ KPPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uin
TRACE("KPPPSM: SendCodeReject(protocolNumber=%X;code=%d) state=%d phase=%d\n", TRACE("KPPPSM: SendCodeReject(protocolNumber=%X;code=%d) state=%d phase=%d\n",
protocolNumber, code, State(), Phase()); protocolNumber, code, State(), Phase());
if(!packet) if (!packet)
return false; return false;
int32 length; int32 length;
// additional space needed for this reject // additional space needed for this reject
if(code == PPP_PROTOCOL_REJECT) if (code == PPP_PROTOCOL_REJECT)
length = 6; length = 6;
else else
length = 4; length = 4;
@@ -1769,24 +1769,24 @@ KPPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uin
// adjust packet if too big // adjust packet if too big
int32 adjust = Interface().MRU(); int32 adjust = Interface().MRU();
if(packet->m_flags & M_PKTHDR) { if (packet->m_flags & M_PKTHDR) {
adjust -= packet->m_pkthdr.len; adjust -= packet->m_pkthdr.len;
} else } else
adjust -= packet->m_len; adjust -= packet->m_len;
if(adjust < 0) if (adjust < 0)
m_adj(packet, adjust); m_adj(packet, adjust);
ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*); ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*);
reject->code = code; reject->code = code;
reject->id = NextID(); reject->id = NextID();
if(packet->m_flags & M_PKTHDR) if (packet->m_flags & M_PKTHDR)
reject->length = htons(packet->m_pkthdr.len); reject->length = htons(packet->m_pkthdr.len);
else else
reject->length = htons(packet->m_len); reject->length = htons(packet->m_len);
protocolNumber = htons(protocolNumber); protocolNumber = htons(protocolNumber);
if(code == PPP_PROTOCOL_REJECT) if (code == PPP_PROTOCOL_REJECT)
memcpy(&reject->data, &protocolNumber, sizeof(protocolNumber)); memcpy(&reject->data, &protocolNumber, sizeof(protocolNumber));
return LCP().Send(packet) == B_OK; return LCP().Send(packet) == B_OK;
@@ -1798,14 +1798,14 @@ KPPPStateMachine::SendEchoReply(struct mbuf *request)
{ {
TRACE("KPPPSM: SendEchoReply() state=%d phase=%d\n", State(), Phase()); TRACE("KPPPSM: SendEchoReply() state=%d phase=%d\n", State(), Phase());
if(!request) if (!request)
return false; return false;
ppp_lcp_packet *reply = mtod(request, ppp_lcp_packet*); ppp_lcp_packet *reply = mtod(request, ppp_lcp_packet*);
reply->code = PPP_ECHO_REPLY; reply->code = PPP_ECHO_REPLY;
// the request becomes a reply // the request becomes a reply
if(request->m_flags & M_PKTHDR) if (request->m_flags & M_PKTHDR)
request->m_pkthdr.len = 8; request->m_pkthdr.len = 8;
request->m_len = 8; request->m_len = 8;
@@ -1820,15 +1820,15 @@ void
KPPPStateMachine::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) {
if(BringPhaseUp() > 0) if (BringPhaseUp() > 0)
break; break;
if(Phase() < PPP_AUTHENTICATION_PHASE) if (Phase() < PPP_AUTHENTICATION_PHASE)
return; return;
// phase was changed by another event // phase was changed by another event
else if(Phase() == PPP_ESTABLISHED_PHASE) { else if (Phase() == PPP_ESTABLISHED_PHASE) {
if(Interface().Parent()) if (Interface().Parent())
Interface().Parent()->StateMachine().UpEvent(Interface()); Interface().Parent()->StateMachine().UpEvent(Interface());
break; break;
} else } else
@@ -1845,17 +1845,17 @@ KPPPStateMachine::BringPhaseUp()
// The client specifies which protocols he wants to go up. // The client specifies which protocols he wants to go up.
// check for phase change // check for phase change
if(Phase() < PPP_AUTHENTICATION_PHASE) if (Phase() < PPP_AUTHENTICATION_PHASE)
return 0; return 0;
uint32 count = 0; uint32 count = 0;
KPPPProtocol *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)
++count; ++count;
else if(protocol->IsDown() && protocol->IsUpRequested()) { else if (protocol->IsDown() && protocol->IsUpRequested()) {
if(Interface().Mode() == PPP_CLIENT_MODE) if (Interface().Mode() == PPP_CLIENT_MODE)
++count; ++count;
protocol->Up(); protocol->Up();
@@ -1864,7 +1864,7 @@ KPPPStateMachine::BringPhaseUp()
} }
// We only wait until authentication is complete. // We only wait until authentication is complete.
if(Interface().Mode() == PPP_SERVER_MODE if (Interface().Mode() == PPP_SERVER_MODE
&& (LocalAuthenticationStatus() == PPP_AUTHENTICATING && (LocalAuthenticationStatus() == PPP_AUTHENTICATING
|| PeerAuthenticationStatus() == PPP_AUTHENTICATING)) || PeerAuthenticationStatus() == PPP_AUTHENTICATING))
++count; ++count;
@@ -1878,8 +1878,8 @@ KPPPStateMachine::DownProtocols()
{ {
KPPPProtocol *protocol = Interface().FirstProtocol(); KPPPProtocol *protocol = Interface().FirstProtocol();
for(; protocol; protocol = protocol->NextProtocol()) for (; protocol; protocol = protocol->NextProtocol())
if(protocol->IsEnabled()) if (protocol->IsEnabled())
protocol->Down(); protocol->Down();
} }
@@ -1887,9 +1887,9 @@ KPPPStateMachine::DownProtocols()
void void
KPPPStateMachine::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();
for(int32 index = 0; index < LCP().CountLCPExtensions(); index++) for (int32 index = 0; index < LCP().CountLCPExtensions(); index++)
LCP().LCPExtensionAt(index)->Reset(); LCP().LCPExtensionAt(index)->Reset();
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -13,11 +13,11 @@
bool bool
IsProtocolAllowed(const KPPPProtocol& protocol) IsProtocolAllowed(const KPPPProtocol& protocol)
{ {
if(protocol.ProtocolNumber() == PPP_LCP_PROTOCOL) if (protocol.ProtocolNumber() == PPP_LCP_PROTOCOL)
return true; return true;
else if(protocol.Interface().State() != PPP_OPENED_STATE) else if (protocol.Interface().State() != PPP_OPENED_STATE)
return false; return false;
else if(protocol.Interface().Phase() > PPP_AUTHENTICATION_PHASE else if (protocol.Interface().Phase() > PPP_AUTHENTICATION_PHASE
|| (protocol.Interface().Phase() >= PPP_ESTABLISHMENT_PHASE || (protocol.Interface().Phase() >= PPP_ESTABLISHMENT_PHASE
&& protocol.Flags() & PPP_ALWAYS_ALLOWED)) && protocol.Flags() & PPP_ALWAYS_ALLOWED))
return true; return true;
@@ -30,14 +30,14 @@ status_t
send_data_with_timeout(thread_id thread, int32 code, void *buffer, send_data_with_timeout(thread_id thread, int32 code, void *buffer,
size_t buffer_size, uint32 timeout) size_t buffer_size, uint32 timeout)
{ {
for(uint32 tries = 0; tries < timeout; tries += 5) { for (uint32 tries = 0; tries < timeout; tries += 5) {
if(has_data(thread)) if (has_data(thread))
snooze(5000); snooze(5000);
else else
break; break;
} }
if(!has_data(thread)) if (!has_data(thread))
return send_data(thread, code, buffer, buffer_size); return send_data(thread, code, buffer, buffer_size);
else else
return B_TIMED_OUT; return B_TIMED_OUT;
@@ -49,14 +49,14 @@ receive_data_with_timeout(thread_id *sender, int32 *code, void *buffer,
size_t buffer_size, uint32 timeout) size_t buffer_size, uint32 timeout)
{ {
thread_id me = find_thread(NULL); thread_id me = find_thread(NULL);
for(uint32 tries = 0; tries < timeout; tries += 5) { for (uint32 tries = 0; tries < timeout; tries += 5) {
if(!has_data(me)) if (!has_data(me))
snooze(5000); snooze(5000);
else else
break; break;
} }
if(has_data(find_thread(NULL))) { if (has_data(find_thread(NULL))) {
*code = receive_data(sender, buffer, buffer_size); *code = receive_data(sender, buffer, buffer_size);
return B_OK; return B_OK;
} else } else
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -39,8 +39,8 @@ _KPPPAuthenticationHandler::NextAuthenticator(const KPPPProtocol *start,
// find the next authenticator for side, beginning at start // find the next authenticator for side, beginning at start
KPPPProtocol *current = start ? start->NextProtocol() : Interface().FirstProtocol(); KPPPProtocol *current = start ? start->NextProtocol() : Interface().FirstProtocol();
for(; current; current = current->NextProtocol()) { for (; current; current = current->NextProtocol()) {
if(current->Type() && !strcasecmp(current->Type(), kAuthenticatorTypeString) if (current->Type() && !strcasecmp(current->Type(), kAuthenticatorTypeString)
&& current->OptionHandler() && current->Side() == side) && current->OptionHandler() && current->Side() == side)
return current; return current;
} }
@@ -56,14 +56,14 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
// add an authentication request if needed. This request is added // add an authentication request if needed. This request is added
// by the authenticator's OptionHandler. // by the authenticator's OptionHandler.
if(fPeerAuthenticator) if (fPeerAuthenticator)
fPeerAuthenticator->SetEnabled(false); fPeerAuthenticator->SetEnabled(false);
if(fSuggestedPeerAuthenticator) if (fSuggestedPeerAuthenticator)
fSuggestedPeerAuthenticator->SetEnabled(false); fSuggestedPeerAuthenticator->SetEnabled(false);
KPPPProtocol *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
// protocol is supplied to us or the suggested protocol is not supported. // protocol is supplied to us or the suggested protocol is not supported.
// We can use this chance to increase fPeerIndex to the next authenticator. // We can use this chance to increase fPeerIndex to the next authenticator.
@@ -73,7 +73,7 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
fPeerAuthenticatorRejected = false; fPeerAuthenticatorRejected = false;
} else { } else {
if(!fPeerAuthenticator) { if (!fPeerAuthenticator) {
// there is no authenticator selected, so find one for us // there is no authenticator selected, so find one for us
authenticator = NextAuthenticator(fPeerAuthenticator, PPP_PEER_SIDE); authenticator = NextAuthenticator(fPeerAuthenticator, PPP_PEER_SIDE);
} else } else
@@ -81,8 +81,8 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
} }
// check if all authenticators were rejected or if no authentication needed // check if all authenticators were rejected or if no authentication needed
if(!authenticator) { if (!authenticator) {
if(fPeerAuthenticator) if (fPeerAuthenticator)
return B_ERROR; return B_ERROR;
// all authenticators were denied // all authenticators were denied
else else
@@ -90,7 +90,7 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
// no peer authentication needed // no peer authentication needed
} }
if(!authenticator || !authenticator->OptionHandler()) if (!authenticator || !authenticator->OptionHandler())
return B_ERROR; return B_ERROR;
fPeerAuthenticator = authenticator; fPeerAuthenticator = authenticator;
@@ -113,17 +113,17 @@ _KPPPAuthenticationHandler::ParseNak(const KPPPConfigurePacket& nak)
authentication_item *item = authentication_item *item =
(authentication_item*) nak.ItemWithType(kAuthenticationType); (authentication_item*) nak.ItemWithType(kAuthenticationType);
if(!item) if (!item)
return B_OK; return B_OK;
// the request was not rejected // the request was not rejected
if(item->length < 4) if (item->length < 4)
return B_ERROR; return B_ERROR;
if(fSuggestedPeerAuthenticator) { if (fSuggestedPeerAuthenticator) {
fSuggestedPeerAuthenticator->SetEnabled(false); fSuggestedPeerAuthenticator->SetEnabled(false);
// if no alternative protocol is supplied we will choose a new one in // if no alternative protocol is supplied we will choose a new one in
// AddToRequest() // AddToRequest()
if(ntohs(item->protocolNumber) == if (ntohs(item->protocolNumber) ==
fSuggestedPeerAuthenticator->ProtocolNumber()) { fSuggestedPeerAuthenticator->ProtocolNumber()) {
fSuggestedPeerAuthenticator = NULL; fSuggestedPeerAuthenticator = NULL;
return B_OK; return B_OK;
@@ -132,7 +132,7 @@ _KPPPAuthenticationHandler::ParseNak(const KPPPConfigurePacket& nak)
fPeerAuthenticatorRejected = true; fPeerAuthenticatorRejected = true;
KPPPProtocol *authenticator = Interface().ProtocolFor(ntohs(item->protocolNumber)); KPPPProtocol *authenticator = Interface().ProtocolFor(ntohs(item->protocolNumber));
if(authenticator && authenticator->Type() if (authenticator && authenticator->Type()
&& !strcasecmp(authenticator->Type(), kAuthenticatorTypeString) && !strcasecmp(authenticator->Type(), kAuthenticatorTypeString)
&& authenticator->OptionHandler()) && authenticator->OptionHandler())
fSuggestedPeerAuthenticator = authenticator; fSuggestedPeerAuthenticator = authenticator;
@@ -147,7 +147,7 @@ status_t
_KPPPAuthenticationHandler::ParseReject(const KPPPConfigurePacket& reject) _KPPPAuthenticationHandler::ParseReject(const KPPPConfigurePacket& reject)
{ {
// an authentication request must not be rejected! // an authentication request must not be rejected!
if(reject.ItemWithType(kAuthenticationType)) if (reject.ItemWithType(kAuthenticationType))
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;
@@ -160,14 +160,14 @@ _KPPPAuthenticationHandler::ParseAck(const KPPPConfigurePacket& ack)
authentication_item *item = authentication_item *item =
(authentication_item*) ack.ItemWithType(kAuthenticationType); (authentication_item*) ack.ItemWithType(kAuthenticationType);
if(!item) { if (!item) {
if(fPeerAuthenticator) if (fPeerAuthenticator)
return B_ERROR; return B_ERROR;
// the ack does not contain our request // the ack does not contain our request
else else
return B_OK; return B_OK;
// no authentication needed // no authentication needed
} else if(!fPeerAuthenticator } else if (!fPeerAuthenticator
|| ntohs(item->protocolNumber) != fPeerAuthenticator->ProtocolNumber()) || ntohs(item->protocolNumber) != fPeerAuthenticator->ProtocolNumber())
return B_ERROR; return B_ERROR;
// this item was never requested // this item was never requested
@@ -181,11 +181,11 @@ status_t
_KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request, _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{ {
if(fLocalAuthenticator) if (fLocalAuthenticator)
fLocalAuthenticator->SetEnabled(false); fLocalAuthenticator->SetEnabled(false);
authentication_item *item = (authentication_item*) request.ItemAt(index); authentication_item *item = (authentication_item*) request.ItemAt(index);
if(!item) if (!item)
return B_OK; return B_OK;
// no authentication requested by peer (index > request.CountItems()) // no authentication requested by peer (index > request.CountItems())
@@ -193,7 +193,7 @@ _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request,
// try to find the requested protocol // try to find the requested protocol
fLocalAuthenticator = Interface().ProtocolFor(ntohs(item->protocolNumber)); fLocalAuthenticator = Interface().ProtocolFor(ntohs(item->protocolNumber));
if(fLocalAuthenticator && fLocalAuthenticator->Type() if (fLocalAuthenticator && fLocalAuthenticator->Type()
&& !strcasecmp(fLocalAuthenticator->Type(), kAuthenticatorTypeString) && !strcasecmp(fLocalAuthenticator->Type(), kAuthenticatorTypeString)
&& fLocalAuthenticator->OptionHandler()) && fLocalAuthenticator->OptionHandler())
return fLocalAuthenticator->OptionHandler()->ParseRequest(request, index, return fLocalAuthenticator->OptionHandler()->ParseRequest(request, index,
@@ -203,8 +203,8 @@ _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request,
KPPPProtocol *nextAuthenticator = KPPPProtocol *nextAuthenticator =
NextAuthenticator(fSuggestedLocalAuthenticator, PPP_LOCAL_SIDE); NextAuthenticator(fSuggestedLocalAuthenticator, PPP_LOCAL_SIDE);
if(!nextAuthenticator) { if (!nextAuthenticator) {
if(!fSuggestedLocalAuthenticator) { if (!fSuggestedLocalAuthenticator) {
// reject the complete authentication option // reject the complete authentication option
reject.AddItem((ppp_configure_item*) item); reject.AddItem((ppp_configure_item*) item);
return B_OK; return B_OK;
@@ -234,17 +234,17 @@ _KPPPAuthenticationHandler::SendingAck(const KPPPConfigurePacket& ack)
authentication_item *item = authentication_item *item =
(authentication_item*) ack.ItemWithType(kAuthenticationType); (authentication_item*) ack.ItemWithType(kAuthenticationType);
if(!item) if (!item)
return B_OK; return B_OK;
// no authentication needed // no authentication needed
fSuggestedLocalAuthenticator = NULL; fSuggestedLocalAuthenticator = NULL;
if(!fLocalAuthenticator) if (!fLocalAuthenticator)
return B_ERROR; return B_ERROR;
// no authenticator selected (our suggestions must be requested, too) // no authenticator selected (our suggestions must be requested, too)
if(!fLocalAuthenticator) if (!fLocalAuthenticator)
return B_ERROR; return B_ERROR;
fLocalAuthenticator->SetEnabled(true); fLocalAuthenticator->SetEnabled(true);
@@ -256,15 +256,15 @@ _KPPPAuthenticationHandler::SendingAck(const KPPPConfigurePacket& ack)
void void
_KPPPAuthenticationHandler::Reset() _KPPPAuthenticationHandler::Reset()
{ {
if(fLocalAuthenticator) { if (fLocalAuthenticator) {
fLocalAuthenticator->SetEnabled(false); fLocalAuthenticator->SetEnabled(false);
fLocalAuthenticator->OptionHandler()->Reset(); fLocalAuthenticator->OptionHandler()->Reset();
} }
if(fPeerAuthenticator) { if (fPeerAuthenticator) {
fPeerAuthenticator->SetEnabled(false); fPeerAuthenticator->SetEnabled(false);
fPeerAuthenticator->OptionHandler()->Reset(); fPeerAuthenticator->OptionHandler()->Reset();
} }
if(fSuggestedPeerAuthenticator) { if (fSuggestedPeerAuthenticator) {
fSuggestedPeerAuthenticator->SetEnabled(false); fSuggestedPeerAuthenticator->SetEnabled(false);
fSuggestedPeerAuthenticator->OptionHandler()->Reset(); fSuggestedPeerAuthenticator->OptionHandler()->Reset();
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -32,7 +32,7 @@ _KPPPMRUHandler::_KPPPMRUHandler(KPPPInterface& interface)
status_t status_t
_KPPPMRUHandler::AddToRequest(KPPPConfigurePacket& request) _KPPPMRUHandler::AddToRequest(KPPPConfigurePacket& request)
{ {
if(!Interface().Device() || Interface().MRU() == 1500) if (!Interface().Device() || Interface().MRU() == 1500)
return B_OK; return B_OK;
// add MRU request // add MRU request
@@ -48,11 +48,11 @@ status_t
_KPPPMRUHandler::ParseNak(const KPPPConfigurePacket& nak) _KPPPMRUHandler::ParseNak(const KPPPConfigurePacket& nak)
{ {
mru_item *item = (mru_item*) nak.ItemWithType(kMRUType); mru_item *item = (mru_item*) nak.ItemWithType(kMRUType);
if(!item || item->length != 4) if (!item || item->length != 4)
return B_OK; return B_OK;
uint16 MRU = ntohs(item->MRU); uint16 MRU = ntohs(item->MRU);
if(MRU < fLocalMRU) if (MRU < fLocalMRU)
fLocalMRU = MRU; fLocalMRU = MRU;
return B_OK; return B_OK;
@@ -62,7 +62,7 @@ _KPPPMRUHandler::ParseNak(const KPPPConfigurePacket& nak)
status_t status_t
_KPPPMRUHandler::ParseReject(const KPPPConfigurePacket& reject) _KPPPMRUHandler::ParseReject(const KPPPConfigurePacket& reject)
{ {
if(reject.ItemWithType(kMRUType)) if (reject.ItemWithType(kMRUType))
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;
@@ -75,10 +75,10 @@ _KPPPMRUHandler::ParseAck(const KPPPConfigurePacket& ack)
uint16 MRU = 1500; uint16 MRU = 1500;
mru_item *item = (mru_item*) ack.ItemWithType(kMRUType); mru_item *item = (mru_item*) ack.ItemWithType(kMRUType);
if(item) if (item)
MRU = ntohs(item->MRU); MRU = ntohs(item->MRU);
if(MRU < Interface().MRU()) if (MRU < Interface().MRU())
fLocalMRU = MRU; fLocalMRU = MRU;
return B_OK; return B_OK;
@@ -89,7 +89,7 @@ status_t
_KPPPMRUHandler::ParseRequest(const KPPPConfigurePacket& request, _KPPPMRUHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{ {
if(index == reject.CountItems()) if (index == reject.CountItems())
return B_OK; return B_OK;
return ParseRequestedItem((mru_item*) request.ItemAt(index), Interface()); return ParseRequestedItem((mru_item*) request.ItemAt(index), Interface());
@@ -111,15 +111,15 @@ ParseRequestedItem(mru_item *item, KPPPInterface& interface)
{ {
uint16 MRU = 1500; uint16 MRU = 1500;
if(item) { if (item) {
if(item->length != 4) if (item->length != 4)
return B_ERROR; return B_ERROR;
// the request has a corrupted item // the request has a corrupted item
MRU = ntohs(item->MRU); MRU = ntohs(item->MRU);
} }
if(MRU < interface.MRU()) if (MRU < interface.MRU())
interface.SetMRU(MRU); interface.SetMRU(MRU);
return B_OK; return B_OK;
@@ -129,7 +129,7 @@ ParseRequestedItem(mru_item *item, KPPPInterface& interface)
void void
_KPPPMRUHandler::Reset() _KPPPMRUHandler::Reset()
{ {
if(Interface().Device()) { if (Interface().Device()) {
fLocalMRU = Interface().Device()->MTU() - 2; fLocalMRU = Interface().Device()->MTU() - 2;
Interface().SetMRU(fLocalMRU); Interface().SetMRU(fLocalMRU);
} else { } else {
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -24,7 +24,7 @@ status_t
_KPPPPFCHandler::AddToRequest(KPPPConfigurePacket& 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
|| (Interface().PFCOptions() & PPP_REQUEST_PFC) == 0) || (Interface().PFCOptions() & PPP_REQUEST_PFC) == 0)
return B_OK; return B_OK;
@@ -40,7 +40,7 @@ status_t
_KPPPPFCHandler::ParseNak(const KPPPConfigurePacket& nak) _KPPPPFCHandler::ParseNak(const KPPPConfigurePacket& nak)
{ {
// naks do not contain PFC items // naks do not contain PFC items
if(nak.ItemWithType(kPFCType)) if (nak.ItemWithType(kPFCType))
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;
@@ -50,10 +50,10 @@ _KPPPPFCHandler::ParseNak(const KPPPConfigurePacket& nak)
status_t status_t
_KPPPPFCHandler::ParseReject(const KPPPConfigurePacket& reject) _KPPPPFCHandler::ParseReject(const KPPPConfigurePacket& reject)
{ {
if(reject.ItemWithType(kPFCType)) { if (reject.ItemWithType(kPFCType)) {
fLocalPFCState = PPP_PFC_REJECTED; fLocalPFCState = PPP_PFC_REJECTED;
if(Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST) if (Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST)
return B_ERROR; return B_ERROR;
} }
@@ -64,12 +64,12 @@ _KPPPPFCHandler::ParseReject(const KPPPConfigurePacket& reject)
status_t status_t
_KPPPPFCHandler::ParseAck(const KPPPConfigurePacket& ack) _KPPPPFCHandler::ParseAck(const KPPPConfigurePacket& ack)
{ {
if(ack.ItemWithType(kPFCType)) if (ack.ItemWithType(kPFCType))
fLocalPFCState = PPP_PFC_ACCEPTED; fLocalPFCState = PPP_PFC_ACCEPTED;
else { else {
fLocalPFCState = PPP_PFC_DISABLED; fLocalPFCState = PPP_PFC_DISABLED;
if(Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST) if (Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST)
return B_ERROR; return B_ERROR;
} }
@@ -81,10 +81,10 @@ status_t
_KPPPPFCHandler::ParseRequest(const KPPPConfigurePacket& request, _KPPPPFCHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{ {
if(!request.ItemWithType(kPFCType)) if (!request.ItemWithType(kPFCType))
return B_OK; return B_OK;
if((Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) { if ((Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) {
ppp_configure_item item; ppp_configure_item item;
item.type = kPFCType; item.type = kPFCType;
item.length = 2; item.length = 2;
@@ -100,10 +100,10 @@ _KPPPPFCHandler::SendingAck(const KPPPConfigurePacket& ack)
{ {
ppp_configure_item *item = ack.ItemWithType(kPFCType); ppp_configure_item *item = ack.ItemWithType(kPFCType);
if(item && (Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) if (item && (Interface().PFCOptions() & PPP_ALLOW_PFC) == 0)
return B_ERROR; return B_ERROR;
if(item) if (item)
fPeerPFCState = PPP_PFC_ACCEPTED; fPeerPFCState = PPP_PFC_ACCEPTED;
else else
fPeerPFCState = PPP_PFC_DISABLED; fPeerPFCState = PPP_PFC_DISABLED;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -26,21 +26,21 @@ static const char *sSkipInterfaceParameters[] = {
driver_settings* driver_settings*
dup_driver_settings(const driver_settings *dup) dup_driver_settings(const driver_settings *dup)
{ {
if(!dup) if (!dup)
return NULL; // we got a NULL pointer, so return nothing return NULL; // we got a NULL pointer, so return nothing
driver_settings *ret = new_driver_settings(); driver_settings *ret = new_driver_settings();
ret->parameter_count = dup->parameter_count; ret->parameter_count = dup->parameter_count;
if(ret->parameter_count > 0) { if (ret->parameter_count > 0) {
ret->parameters = (driver_parameter*) ret->parameters = (driver_parameter*)
malloc(ret->parameter_count * sizeof(driver_parameter)); malloc(ret->parameter_count * sizeof(driver_parameter));
memset(ret->parameters, 0, ret->parameter_count * sizeof(driver_parameter)); memset(ret->parameters, 0, ret->parameter_count * sizeof(driver_parameter));
} else } else
ret->parameters = NULL; ret->parameters = NULL;
for(int32 index = 0; index < ret->parameter_count; index++) for (int32 index = 0; index < ret->parameter_count; index++)
copy_driver_parameter(&dup->parameters[index], &ret->parameters[index]); copy_driver_parameter(&dup->parameters[index], &ret->parameters[index]);
return ret; return ret;
@@ -50,10 +50,10 @@ dup_driver_settings(const driver_settings *dup)
void void
free_driver_settings(driver_settings *settings) free_driver_settings(driver_settings *settings)
{ {
if(!settings) if (!settings)
return; return;
for(int32 index = 0; index < settings->parameter_count; index++) for (int32 index = 0; index < settings->parameter_count; index++)
free_driver_parameter_fields(&settings->parameters[index]); free_driver_parameter_fields(&settings->parameters[index]);
free(settings->parameters); free(settings->parameters);
@@ -74,12 +74,12 @@ free_driver_parameter_fields(driver_parameter *parameter)
{ {
free(parameter->name); free(parameter->name);
for(int32 index = 0; index < parameter->value_count; index++) for (int32 index = 0; index < parameter->value_count; index++)
free(parameter->values[index]); free(parameter->values[index]);
free(parameter->values); free(parameter->values);
for(int32 index = 0; index < parameter->parameter_count; index++) for (int32 index = 0; index < parameter->parameter_count; index++)
free_driver_parameter_fields(&parameter->parameters[index]); free_driver_parameter_fields(&parameter->parameters[index]);
free(parameter->parameters); free(parameter->parameters);
@@ -111,35 +111,35 @@ new_driver_parameter(const char *name)
bool bool
copy_driver_parameter(const driver_parameter *from, driver_parameter *to) copy_driver_parameter(const driver_parameter *from, driver_parameter *to)
{ {
if(!from || !to) if (!from || !to)
return false; return false;
free_driver_parameter_fields(to); free_driver_parameter_fields(to);
if(from->name) if (from->name)
to->name = strdup(from->name); to->name = strdup(from->name);
else else
to->name = NULL; to->name = NULL;
to->value_count = from->value_count; to->value_count = from->value_count;
if(from->value_count > 0) if (from->value_count > 0)
to->values = (char**) malloc(from->value_count * sizeof(char*)); to->values = (char**) malloc(from->value_count * sizeof(char*));
else else
to->values = NULL; to->values = NULL;
for(int32 index = 0; index < to->value_count; index++) for (int32 index = 0; index < to->value_count; index++)
to->values[index] = strdup(from->values[index]); to->values[index] = strdup(from->values[index]);
to->parameter_count = from->parameter_count; to->parameter_count = from->parameter_count;
if(to->parameter_count > 0) { if (to->parameter_count > 0) {
to->parameters = to->parameters =
(driver_parameter*) malloc(to->parameter_count * sizeof(driver_parameter)); (driver_parameter*) malloc(to->parameter_count * sizeof(driver_parameter));
memset(to->parameters, 0, to->parameter_count * sizeof(driver_parameter)); memset(to->parameters, 0, to->parameter_count * sizeof(driver_parameter));
} else } else
to->parameters = NULL; to->parameters = NULL;
for(int32 index = 0; index < to->parameter_count; index++) for (int32 index = 0; index < to->parameter_count; index++)
copy_driver_parameter(&from->parameters[index], &to->parameters[index]); copy_driver_parameter(&from->parameters[index], &to->parameters[index]);
return true; return true;
@@ -149,12 +149,12 @@ copy_driver_parameter(const driver_parameter *from, driver_parameter *to)
bool bool
set_driver_parameter_name(const char *name, driver_parameter *parameter) set_driver_parameter_name(const char *name, driver_parameter *parameter)
{ {
if(!parameter) if (!parameter)
return false; return false;
free(parameter->name); free(parameter->name);
if(name) if (name)
parameter->name = strdup(name); parameter->name = strdup(name);
else else
parameter->name = NULL; parameter->name = NULL;
@@ -166,7 +166,7 @@ set_driver_parameter_name(const char *name, driver_parameter *parameter)
bool bool
add_driver_parameter_value(const char *value, driver_parameter *to) add_driver_parameter_value(const char *value, driver_parameter *to)
{ {
if(!value || !to) if (!value || !to)
return false; return false;
int32 oldCount = to->value_count; int32 oldCount = to->value_count;
@@ -174,7 +174,7 @@ add_driver_parameter_value(const char *value, driver_parameter *to)
to->values = (char**) malloc((oldCount + 1) * sizeof(char*)); to->values = (char**) malloc((oldCount + 1) * sizeof(char*));
if(!to->values) { if (!to->values) {
to->values = old; to->values = old;
return false; return false;
} }
@@ -190,7 +190,7 @@ add_driver_parameter_value(const char *value, driver_parameter *to)
bool bool
add_driver_parameter(driver_parameter *add, driver_settings *to) add_driver_parameter(driver_parameter *add, driver_settings *to)
{ {
if(!add || !to) if (!add || !to)
return false; return false;
int32 oldCount = to->parameter_count; int32 oldCount = to->parameter_count;
@@ -199,7 +199,7 @@ add_driver_parameter(driver_parameter *add, driver_settings *to)
to->parameters = to->parameters =
(driver_parameter*) malloc((oldCount + 1) * sizeof(driver_parameter)); (driver_parameter*) malloc((oldCount + 1) * sizeof(driver_parameter));
if(!to->parameters) { if (!to->parameters) {
to->parameters = old; to->parameters = old;
return false; return false;
} }
@@ -215,16 +215,16 @@ add_driver_parameter(driver_parameter *add, driver_settings *to)
bool bool
equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs) equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs)
{ {
if(!lhs && !rhs) if (!lhs && !rhs)
return true; return true;
else if(!lhs || !rhs) else if (!lhs || !rhs)
return false; return false;
if(lhs->parameter_count != rhs->parameter_count) if (lhs->parameter_count != rhs->parameter_count)
return false; return false;
for(int32 index = 0; index < lhs->parameter_count; index++) { for (int32 index = 0; index < lhs->parameter_count; index++) {
if(!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index])) if (!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index]))
return false; return false;
} }
@@ -235,28 +235,28 @@ equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs)
bool bool
equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs) equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs)
{ {
if(!lhs && !rhs) if (!lhs && !rhs)
return true; return true;
else if(!lhs || !rhs) else if (!lhs || !rhs)
return false; return false;
if(lhs->name && rhs->name) { if (lhs->name && rhs->name) {
if(strcmp(lhs->name, rhs->name)) if (strcmp(lhs->name, rhs->name))
return false; return false;
} else if(lhs->name != rhs->name) } else if (lhs->name != rhs->name)
return false; return false;
if(lhs->value_count != rhs->value_count if (lhs->value_count != rhs->value_count
|| lhs->parameter_count != rhs->parameter_count) || lhs->parameter_count != rhs->parameter_count)
return false; return false;
for(int32 index = 0; index < lhs->value_count; index++) { for (int32 index = 0; index < lhs->value_count; index++) {
if(strcmp(lhs->values[index], rhs->values[index])) if (strcmp(lhs->values[index], rhs->values[index]))
return false; return false;
} }
for(int32 index = 0; index < lhs->parameter_count; index++) { for (int32 index = 0; index < lhs->parameter_count; index++) {
if(!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index])) if (!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index]))
return false; return false;
} }
@@ -267,11 +267,11 @@ equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs
bool bool
skip_interface_parameter(const driver_parameter *parameter) skip_interface_parameter(const driver_parameter *parameter)
{ {
if(!parameter || !parameter->name) if (!parameter || !parameter->name)
return false; return false;
for(int32 index = 0; sSkipInterfaceParameters[index]; index++) for (int32 index = 0; sSkipInterfaceParameters[index]; index++)
if(!strcasecmp(parameter->name, sSkipInterfaceParameters[index])) if (!strcasecmp(parameter->name, sSkipInterfaceParameters[index]))
return true; return true;
return false; return false;
@@ -281,30 +281,30 @@ skip_interface_parameter(const driver_parameter *parameter)
bool bool
equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs) equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs)
{ {
if(!lhs && !rhs) if (!lhs && !rhs)
return true; return true;
else if(!lhs || !rhs) else if (!lhs || !rhs)
return false; return false;
int32 lhsIndex = 0, rhsIndex = 0; int32 lhsIndex = 0, rhsIndex = 0;
for(; lhsIndex < lhs->parameter_count; lhsIndex++) { for (; lhsIndex < lhs->parameter_count; lhsIndex++) {
if(skip_interface_parameter(&lhs->parameters[lhsIndex])) if (skip_interface_parameter(&lhs->parameters[lhsIndex]))
continue; continue;
for(; rhsIndex < rhs->parameter_count; rhsIndex++) for (; rhsIndex < rhs->parameter_count; rhsIndex++)
if(!skip_interface_parameter(&rhs->parameters[rhsIndex])) if (!skip_interface_parameter(&rhs->parameters[rhsIndex]))
break; break;
if(rhsIndex >= rhs->parameter_count) if (rhsIndex >= rhs->parameter_count)
return false; return false;
if(!equal_driver_parameters(&lhs->parameters[lhsIndex], if (!equal_driver_parameters(&lhs->parameters[lhsIndex],
&rhs->parameters[rhsIndex])) &rhs->parameters[rhsIndex]))
return false; return false;
} }
for(; rhsIndex < rhs->parameter_count; rhsIndex++) for (; rhsIndex < rhs->parameter_count; rhsIndex++)
if(!skip_interface_parameter(&rhs->parameters[rhsIndex])) if (!skip_interface_parameter(&rhs->parameters[rhsIndex]))
return false; return false;
return true; return true;
@@ -314,17 +314,17 @@ equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs)
ppp_side ppp_side
get_side_string_value(const char *sideString, ppp_side unknownValue) get_side_string_value(const char *sideString, ppp_side unknownValue)
{ {
if(!sideString) if (!sideString)
return unknownValue; return unknownValue;
if(!strcasecmp(sideString, "local")) if (!strcasecmp(sideString, "local"))
return PPP_LOCAL_SIDE; return PPP_LOCAL_SIDE;
if(!strcasecmp(sideString, "peer")) if (!strcasecmp(sideString, "peer"))
return PPP_PEER_SIDE; return PPP_PEER_SIDE;
if(!strcasecmp(sideString, "none") if (!strcasecmp(sideString, "none")
|| !strcasecmp(sideString, "no")) || !strcasecmp(sideString, "no"))
return PPP_NO_SIDE; return PPP_NO_SIDE;
if(!strcasecmp(sideString, "both")) if (!strcasecmp(sideString, "both"))
return PPP_BOTH_SIDES; return PPP_BOTH_SIDES;
// no correct value has been found => return default value // no correct value has been found => return default value
@@ -335,7 +335,7 @@ get_side_string_value(const char *sideString, ppp_side unknownValue)
bool bool
get_boolean_value(const char *string, bool unknownValue) get_boolean_value(const char *string, bool unknownValue)
{ {
if(!string) if (!string)
return unknownValue; return unknownValue;
if (!strcmp(string, "1") if (!strcmp(string, "1")
@@ -362,11 +362,11 @@ get_boolean_value(const char *string, bool unknownValue)
const driver_parameter* const driver_parameter*
get_parameter_with_name(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))
return &settings->parameters[index]; return &settings->parameters[index];
return NULL; return NULL;
@@ -378,7 +378,7 @@ get_settings_value(const char *name, const driver_settings *settings)
{ {
const driver_parameter *parameter = get_parameter_with_name(name, settings); const driver_parameter *parameter = get_parameter_with_name(name, settings);
if(parameter && parameter->value_count > 0 && parameter->values) if (parameter && parameter->value_count > 0 && parameter->values)
return parameter->values[0]; return parameter->values[0];
return NULL; return NULL;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2004-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -24,10 +24,10 @@ FindMessageParameter(const char *name, const BMessage& message, BMessage *save,
// XXX: this should be removed when we can replace BMessage with something better // XXX: this should be removed when we can replace BMessage with something better
BString string; BString string;
int32 index = startIndex ? *startIndex : 0; int32 index = startIndex ? *startIndex : 0;
for(; message.FindMessage(MDSU_PARAMETERS, index, save) == B_OK; index++) { for (; message.FindMessage(MDSU_PARAMETERS, index, save) == B_OK; index++) {
if(save->FindString(MDSU_NAME, &string) == B_OK if (save->FindString(MDSU_NAME, &string) == B_OK
&& string.ICompare(name) == 0) { && string.ICompare(name) == 0) {
if(startIndex) if (startIndex)
*startIndex = index; *startIndex = index;
return true; return true;
} }
@@ -42,9 +42,9 @@ bool
AddValues(const BMessage& message, driver_parameter *parameter) AddValues(const BMessage& message, driver_parameter *parameter)
{ {
const char *value; const char *value;
for(int32 index = 0; message.FindString(MDSU_VALUES, index, &value) == B_OK; for (int32 index = 0; message.FindString(MDSU_VALUES, index, &value) == B_OK;
index++) index++)
if(!add_driver_parameter_value(value, parameter)) if (!add_driver_parameter_value(value, parameter))
return false; return false;
return true; return true;
@@ -55,7 +55,7 @@ inline
bool bool
AddParameters(const BMessage& message, driver_parameter *to) AddParameters(const BMessage& message, driver_parameter *to)
{ {
if(!to) if (!to)
return false; return false;
return AddParameters(message, return AddParameters(message,
@@ -70,11 +70,11 @@ AddParameters(const BMessage& message, driver_settings *to)
const char *name; const char *name;
BMessage current; BMessage current;
driver_parameter *parameter; driver_parameter *parameter;
for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, for (int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index,
&current) == B_OK; index++) { &current) == B_OK; index++) {
name = current.FindString(MDSU_NAME); name = current.FindString(MDSU_NAME);
parameter = new_driver_parameter(name); parameter = new_driver_parameter(name);
if(!AddValues(current, parameter)) if (!AddValues(current, parameter))
return false; return false;
AddParameters(current, parameter); AddParameters(current, parameter);
@@ -90,7 +90,7 @@ MessageToDriverSettings(const BMessage& message)
{ {
driver_settings *settings = new_driver_settings(); driver_settings *settings = new_driver_settings();
if(!AddParameters(message, settings)) { if (!AddParameters(message, settings)) {
free_driver_settings(settings); free_driver_settings(settings);
return NULL; return NULL;
} }
@@ -103,19 +103,19 @@ static
bool bool
AddParameter(const driver_parameter *parameter, BMessage *message) AddParameter(const driver_parameter *parameter, BMessage *message)
{ {
if(!parameter || !message) if (!parameter || !message)
return false; return false;
if(parameter->name) if (parameter->name)
message->AddString(MDSU_NAME, parameter->name); message->AddString(MDSU_NAME, parameter->name);
else else
return false; return false;
for(int32 index = 0; index < parameter->value_count; index++) for (int32 index = 0; index < parameter->value_count; index++)
if(parameter->values[index]) if (parameter->values[index])
message->AddString(MDSU_VALUES, parameter->values[index]); message->AddString(MDSU_VALUES, parameter->values[index]);
for(int32 index = 0; index < parameter->parameter_count; index++) { for (int32 index = 0; index < parameter->parameter_count; index++) {
BMessage parameterMessage; BMessage parameterMessage;
AddParameter(&parameter->parameters[index], &parameterMessage); AddParameter(&parameter->parameters[index], &parameterMessage);
message->AddMessage(MDSU_PARAMETERS, &parameterMessage); message->AddMessage(MDSU_PARAMETERS, &parameterMessage);
@@ -128,19 +128,19 @@ AddParameter(const driver_parameter *parameter, BMessage *message)
bool bool
ReadMessageDriverSettings(const char *name, BMessage *message) ReadMessageDriverSettings(const char *name, BMessage *message)
{ {
if(!name || !message) if (!name || !message)
return false; return false;
void *handle = load_driver_settings(name); void *handle = load_driver_settings(name);
if(!handle) if (!handle)
return false; return false;
const driver_settings *settings = get_driver_settings(handle); const driver_settings *settings = get_driver_settings(handle);
if(!settings) { if (!settings) {
unload_driver_settings(handle); unload_driver_settings(handle);
return false; return false;
} }
for(int32 index = 0; index < settings->parameter_count; index++) { for (int32 index = 0; index < settings->parameter_count; index++) {
BMessage parameter; BMessage parameter;
AddParameter(&settings->parameters[index], &parameter); AddParameter(&settings->parameters[index], &parameter);
message->AddMessage(MDSU_PARAMETERS, &parameter); message->AddMessage(MDSU_PARAMETERS, &parameter);
@@ -168,30 +168,30 @@ bool
WriteParameter(BFile& file, const BMessage& parameter, int32 level) WriteParameter(BFile& file, const BMessage& parameter, int32 level)
{ {
const char *name; const char *name;
if(parameter.FindString(MDSU_NAME, &name) != B_OK || !name) if (parameter.FindString(MDSU_NAME, &name) != B_OK || !name)
return false; return false;
BString line, word(name); BString line, word(name);
EscapeWord(word); EscapeWord(word);
bool needsEscaping = word.FindFirst(' ') >= 0; bool needsEscaping = word.FindFirst(' ') >= 0;
line.SetTo('\t', level); line.SetTo('\t', level);
if(needsEscaping) if (needsEscaping)
line << '\"'; line << '\"';
line << word; line << word;
if(needsEscaping) if (needsEscaping)
line << '\"'; line << '\"';
for(int32 index = 0; parameter.FindString(MDSU_VALUES, index, &name) == B_OK; for (int32 index = 0; parameter.FindString(MDSU_VALUES, index, &name) == B_OK;
index++) index++)
if(name) { if (name) {
line << ' '; line << ' ';
word = name; word = name;
EscapeWord(word); EscapeWord(word);
needsEscaping = word.FindFirst(' ') >= 0; needsEscaping = word.FindFirst(' ') >= 0;
if(needsEscaping) if (needsEscaping)
line << '\"'; line << '\"';
line << word; line << word;
if(needsEscaping) if (needsEscaping)
line << '\"'; line << '\"';
} }
@@ -199,15 +199,15 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level)
int32 parameterCount; int32 parameterCount;
parameter.GetInfo(MDSU_PARAMETERS, &type, &parameterCount); parameter.GetInfo(MDSU_PARAMETERS, &type, &parameterCount);
if(parameterCount > 0) if (parameterCount > 0)
line << " {"; line << " {";
line << '\n'; line << '\n';
file.Write(line.String(), line.Length()); file.Write(line.String(), line.Length());
if(parameterCount > 0) { if (parameterCount > 0) {
BMessage subParameter; BMessage subParameter;
for(int32 index = 0; parameter.FindMessage(MDSU_PARAMETERS, index, for (int32 index = 0; parameter.FindMessage(MDSU_PARAMETERS, index,
&subParameter) == B_OK; index++) &subParameter) == B_OK; index++)
WriteParameter(file, subParameter, level + 1); WriteParameter(file, subParameter, level + 1);
@@ -223,16 +223,16 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level)
bool bool
WriteMessageDriverSettings(BFile& file, const BMessage& message) WriteMessageDriverSettings(BFile& file, const BMessage& message)
{ {
if(file.InitCheck() != B_OK || !file.IsWritable()) if (file.InitCheck() != B_OK || !file.IsWritable())
return false; return false;
file.SetSize(0); file.SetSize(0);
file.Seek(0, SEEK_SET); file.Seek(0, SEEK_SET);
BMessage parameter; BMessage parameter;
for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, &parameter) == B_OK; for (int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, &parameter) == B_OK;
index++) { index++) {
if(index > 0) if (index > 0)
file.Write("\n", 1); file.Write("\n", 1);
WriteParameter(file, parameter, 0); WriteParameter(file, parameter, 0);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -45,7 +45,7 @@ PPPInterface::PPPInterface(const PPPInterface& copy)
//! Destructor. //! Destructor.
PPPInterface::~PPPInterface() PPPInterface::~PPPInterface()
{ {
if(fFD >= 0) if (fFD >= 0)
close(fFD); close(fFD);
} }
@@ -62,9 +62,9 @@ PPPInterface::~PPPInterface()
status_t status_t
PPPInterface::InitCheck() const PPPInterface::InitCheck() const
{ {
if(fFD < 0) if (fFD < 0)
return B_ERROR; return B_ERROR;
if(fID == PPP_UNDEFINED_INTERFACE_ID) if (fID == PPP_UNDEFINED_INTERFACE_ID)
return B_BAD_INDEX; return B_BAD_INDEX;
return B_OK; return B_OK;
@@ -87,11 +87,11 @@ PPPInterface::InitCheck() const
status_t status_t
PPPInterface::SetTo(ppp_interface_id ID) PPPInterface::SetTo(ppp_interface_id ID)
{ {
if(fFD < 0) if (fFD < 0)
return B_ERROR; return B_ERROR;
ppp_interface_info_t info; ppp_interface_info_t info;
if(GetInterfaceInfo(&info)) { if (GetInterfaceInfo(&info)) {
fName = info.info.name; fName = info.info.name;
fID = ID; fID = ID;
} else { } else {
@@ -119,7 +119,7 @@ PPPInterface::SetTo(ppp_interface_id ID)
status_t status_t
PPPInterface::Control(uint32 op, void *data, size_t length) const PPPInterface::Control(uint32 op, void *data, size_t length) const
{ {
if(InitCheck() != B_OK) if (InitCheck() != B_OK)
return InitCheck(); return InitCheck();
ppp_control_info control; ppp_control_info control;
@@ -143,7 +143,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length) const
bool bool
PPPInterface::SetUsername(const char *username) const PPPInterface::SetUsername(const char *username) const
{ {
if(InitCheck() != B_OK || !username) if (InitCheck() != B_OK || !username)
return false; return false;
return Control(PPPC_SET_USERNAME, const_cast<char*>(username), strlen(username)) return Control(PPPC_SET_USERNAME, const_cast<char*>(username), strlen(username))
@@ -155,7 +155,7 @@ PPPInterface::SetUsername(const char *username) const
bool bool
PPPInterface::SetPassword(const char *password) const PPPInterface::SetPassword(const char *password) const
{ {
if(InitCheck() != B_OK || !password) if (InitCheck() != B_OK || !password)
return false; return false;
return Control(PPPC_SET_PASSWORD, const_cast<char*>(password), strlen(password)) return Control(PPPC_SET_PASSWORD, const_cast<char*>(password), strlen(password))
@@ -167,7 +167,7 @@ PPPInterface::SetPassword(const char *password) const
bool bool
PPPInterface::SetAskBeforeConnecting(bool askBeforeConnecting) const PPPInterface::SetAskBeforeConnecting(bool askBeforeConnecting) const
{ {
if(InitCheck() != B_OK) if (InitCheck() != B_OK)
return false; return false;
uint32 value = askBeforeConnecting ? 1 : 0; uint32 value = askBeforeConnecting ? 1 : 0;
@@ -188,9 +188,9 @@ PPPInterface::SetAskBeforeConnecting(bool askBeforeConnecting) const
status_t status_t
PPPInterface::GetSettingsEntry(BEntry *entry) const PPPInterface::GetSettingsEntry(BEntry *entry) const
{ {
if(InitCheck() != B_OK) if (InitCheck() != B_OK)
return InitCheck(); return InitCheck();
else if(!entry || strlen(Name()) == 0) else if (!entry || strlen(Name()) == 0)
return B_BAD_VALUE; return B_BAD_VALUE;
BDirectory directory(PTP_INTERFACE_SETTINGS_PATH); BDirectory directory(PTP_INTERFACE_SETTINGS_PATH);
@@ -205,7 +205,7 @@ PPPInterface::GetSettingsEntry(BEntry *entry) const
bool bool
PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const
{ {
if(InitCheck() != B_OK || !info) if (InitCheck() != B_OK || !info)
return false; return false;
return Control(PPPC_GET_INTERFACE_INFO, &info, sizeof(ppp_interface_info_t)) return Control(PPPC_GET_INTERFACE_INFO, &info, sizeof(ppp_interface_info_t))
@@ -222,7 +222,7 @@ PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const
bool bool
PPPInterface::GetStatistics(ppp_statistics *statistics) const PPPInterface::GetStatistics(ppp_statistics *statistics) const
{ {
if(!statistics) if (!statistics)
return false; return false;
return Control(PPPC_GET_STATISTICS, statistics, sizeof(ppp_statistics)) == B_OK; return Control(PPPC_GET_STATISTICS, statistics, sizeof(ppp_statistics)) == B_OK;
@@ -233,10 +233,10 @@ PPPInterface::GetStatistics(ppp_statistics *statistics) const
bool bool
PPPInterface::HasSettings(const driver_settings *settings) const PPPInterface::HasSettings(const driver_settings *settings) const
{ {
if(InitCheck() != B_OK || !settings) if (InitCheck() != B_OK || !settings)
return false; return false;
if(Control(PPPC_HAS_INTERFACE_SETTINGS, const_cast<driver_settings*>(settings), if (Control(PPPC_HAS_INTERFACE_SETTINGS, const_cast<driver_settings*>(settings),
sizeof(driver_settings)) == B_OK) sizeof(driver_settings)) == B_OK)
return true; return true;
@@ -248,7 +248,7 @@ PPPInterface::HasSettings(const driver_settings *settings) const
bool bool
PPPInterface::Up() const PPPInterface::Up() const
{ {
if(InitCheck() != B_OK) if (InitCheck() != B_OK)
return false; return false;
int32 id = ID(); int32 id = ID();
@@ -266,7 +266,7 @@ PPPInterface::Up() const
bool bool
PPPInterface::Down() const PPPInterface::Down() const
{ {
if(InitCheck() != B_OK) if (InitCheck() != B_OK)
return false; return false;
int32 id = ID(); int32 id = ID();
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -40,22 +40,22 @@ report_thread(void *data)
thread_id sender; thread_id sender;
BMessage message; BMessage message;
while(true) { while (true) {
code = receive_data(&sender, &report, sizeof(report)); code = receive_data(&sender, &report, sizeof(report));
if(code == kCodeQuitReportThread) if (code == kCodeQuitReportThread)
break; break;
else if(code != PPP_REPORT_CODE) else if (code != PPP_REPORT_CODE)
continue; continue;
BMessenger messenger(listener->Target()); BMessenger messenger(listener->Target());
if(messenger.IsValid()) { if (messenger.IsValid()) {
message.MakeEmpty(); message.MakeEmpty();
message.what = PPP_REPORT_MESSAGE; message.what = PPP_REPORT_MESSAGE;
message.AddInt32("type", report.type); message.AddInt32("type", report.type);
message.AddInt32("code", report.code); message.AddInt32("code", report.code);
if(report.length >= sizeof(ppp_interface_id) if (report.length >= sizeof(ppp_interface_id)
&& ((report.type == PPP_MANAGER_REPORT && ((report.type == PPP_MANAGER_REPORT
&& report.code == PPP_REPORT_INTERFACE_CREATED) && report.code == PPP_REPORT_INTERFACE_CREATED)
|| report.type >= PPP_INTERFACE_REPORT_TYPE_MIN)) { || report.type >= PPP_INTERFACE_REPORT_TYPE_MIN)) {
@@ -121,7 +121,7 @@ PPPInterfaceListener::~PPPInterfaceListener()
status_t status_t
PPPInterfaceListener::InitCheck() const PPPInterfaceListener::InitCheck() const
{ {
if(fReportThread < 0) if (fReportThread < 0)
return B_ERROR; return B_ERROR;
return Manager().InitCheck(); return Manager().InitCheck();
@@ -147,20 +147,20 @@ PPPInterfaceListener::SetTarget(BHandler *target)
bool bool
PPPInterfaceListener::WatchInterface(ppp_interface_id ID) PPPInterfaceListener::WatchInterface(ppp_interface_id ID)
{ {
if(ID == fInterface) if (ID == fInterface)
return true; return true;
StopWatchingInterface(); StopWatchingInterface();
if(ID == PPP_UNDEFINED_INTERFACE_ID) if (ID == PPP_UNDEFINED_INTERFACE_ID)
return true; return true;
// enable reports // enable reports
PPPInterface interface(ID); PPPInterface interface(ID);
if(interface.InitCheck() != B_OK) if (interface.InitCheck() != B_OK)
return false; return false;
if(!interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, PPP_NO_FLAGS)) if (!interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, PPP_NO_FLAGS))
return false; return false;
fIsWatching = true; fIsWatching = true;
@@ -185,7 +185,7 @@ PPPInterfaceListener::WatchManager()
void void
PPPInterfaceListener::StopWatchingInterface() PPPInterfaceListener::StopWatchingInterface()
{ {
if(!fIsWatching) if (!fIsWatching)
return; return;
PPPInterface interface(fInterface); PPPInterface interface(fInterface);
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -36,7 +36,7 @@ PPPManager::PPPManager()
//! Destructor. //! Destructor.
PPPManager::~PPPManager() PPPManager::~PPPManager()
{ {
if(fFD >= 0) if (fFD >= 0)
close(fFD); close(fFD);
} }
@@ -47,26 +47,26 @@ PPPManager::SetDefaultInterface(const BString name)
{ {
// load current settings and replace value of "default" with <name> // load current settings and replace value of "default" with <name>
BMessage settings; BMessage settings;
if(!ReadMessageDriverSettings("ptpnet.settings", &settings)) if (!ReadMessageDriverSettings("ptpnet.settings", &settings))
settings.MakeEmpty(); settings.MakeEmpty();
BMessage parameter; BMessage parameter;
int32 index = 0; int32 index = 0;
if(FindMessageParameter("default", settings, &parameter, &index)) if (FindMessageParameter("default", settings, &parameter, &index))
settings.RemoveData(MDSU_PARAMETERS, index); settings.RemoveData(MDSU_PARAMETERS, index);
parameter.MakeEmpty(); parameter.MakeEmpty();
if(name != "") { if (name != "") {
parameter.AddString(MDSU_NAME, "default"); parameter.AddString(MDSU_NAME, "default");
parameter.AddString(MDSU_VALUES, name); parameter.AddString(MDSU_VALUES, name);
settings.AddMessage(MDSU_PARAMETERS, &parameter); settings.AddMessage(MDSU_PARAMETERS, &parameter);
} }
BFile file(PTP_SETTINGS_PATH, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); BFile file(PTP_SETTINGS_PATH, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if(file.InitCheck() != B_OK) if (file.InitCheck() != B_OK)
return false; return false;
if(WriteMessageDriverSettings(file, settings)) if (WriteMessageDriverSettings(file, settings))
return true; return true;
else else
return false; return false;
@@ -88,12 +88,12 @@ PPPManager::DefaultInterface()
bool bool
PPPManager::GetSettingsDirectory(BDirectory *settingsDirectory) PPPManager::GetSettingsDirectory(BDirectory *settingsDirectory)
{ {
if(settingsDirectory) { if (settingsDirectory) {
BDirectory settings(PTP_INTERFACE_SETTINGS_PATH); BDirectory settings(PTP_INTERFACE_SETTINGS_PATH);
if(settings.InitCheck() != B_OK) { if (settings.InitCheck() != B_OK) {
create_directory(PTP_INTERFACE_SETTINGS_PATH, 0750); create_directory(PTP_INTERFACE_SETTINGS_PATH, 0750);
settings.SetTo(PTP_INTERFACE_SETTINGS_PATH); settings.SetTo(PTP_INTERFACE_SETTINGS_PATH);
if(settings.InitCheck() != B_OK) if (settings.InitCheck() != B_OK)
return false; return false;
} }
@@ -108,7 +108,7 @@ PPPManager::GetSettingsDirectory(BDirectory *settingsDirectory)
status_t status_t
PPPManager::InitCheck() const PPPManager::InitCheck() const
{ {
if(fFD < 0) if (fFD < 0)
return B_ERROR; return B_ERROR;
else else
return B_OK; return B_OK;
@@ -129,7 +129,7 @@ PPPManager::InitCheck() const
status_t status_t
PPPManager::Control(uint32 op, void *data, size_t length) const PPPManager::Control(uint32 op, void *data, size_t length) const
{ {
if(InitCheck() != B_OK) if (InitCheck() != B_OK)
return B_ERROR; return B_ERROR;
control_net_module_args args; control_net_module_args args;
@@ -165,7 +165,7 @@ status_t
PPPManager::ControlModule(const char *name, uint32 op, void *data, PPPManager::ControlModule(const char *name, uint32 op, void *data,
size_t length) const size_t length) const
{ {
if(!name) if (!name)
return B_ERROR; return B_ERROR;
control_net_module_args args; control_net_module_args args;
@@ -189,7 +189,7 @@ PPPManager::CreateInterface(const driver_settings *settings) const
ppp_interface_description_info info; ppp_interface_description_info info;
info.u.settings = settings; info.u.settings = settings;
if(Control(PPPC_CREATE_INTERFACE, &info, sizeof(info)) != B_OK) if (Control(PPPC_CREATE_INTERFACE, &info, sizeof(info)) != B_OK)
return PPP_UNDEFINED_INTERFACE_ID; return PPP_UNDEFINED_INTERFACE_ID;
else else
return info.interface; return info.interface;
@@ -210,7 +210,7 @@ PPPManager::CreateInterfaceWithName(const char *name) const
ppp_interface_description_info info; ppp_interface_description_info info;
info.u.name = name; info.u.name = name;
if(Control(PPPC_CREATE_INTERFACE_WITH_NAME, &info, sizeof(info)) != B_OK) if (Control(PPPC_CREATE_INTERFACE_WITH_NAME, &info, sizeof(info)) != B_OK)
return PPP_UNDEFINED_INTERFACE_ID; return PPP_UNDEFINED_INTERFACE_ID;
else else
return info.interface; return info.interface;
@@ -221,7 +221,7 @@ PPPManager::CreateInterfaceWithName(const char *name) const
bool bool
PPPManager::DeleteInterface(ppp_interface_id ID) const PPPManager::DeleteInterface(ppp_interface_id ID) const
{ {
if(Control(PPPC_DELETE_INTERFACE, &ID, sizeof(ID)) != B_OK) if (Control(PPPC_DELETE_INTERFACE, &ID, sizeof(ID)) != B_OK)
return false; return false;
else else
return true; return true;
@@ -251,21 +251,21 @@ PPPManager::Interfaces(int32 *count,
ppp_interface_id *interfaces; ppp_interface_id *interfaces;
// loop until we get all interfaces // loop until we get all interfaces
while(true) { while (true) {
requestCount = *count = CountInterfaces(filter); requestCount = *count = CountInterfaces(filter);
if(*count == -1) if (*count == -1)
return NULL; return NULL;
requestCount += 10; requestCount += 10;
// request some more interfaces in case some are added in the mean time // request some more interfaces in case some are added in the mean time
interfaces = new ppp_interface_id[requestCount]; interfaces = new ppp_interface_id[requestCount];
*count = GetInterfaces(interfaces, requestCount, filter); *count = GetInterfaces(interfaces, requestCount, filter);
if(*count == -1) { if (*count == -1) {
delete interfaces; delete interfaces;
return NULL; return NULL;
} }
if(*count < requestCount) if (*count < requestCount)
break; break;
delete interfaces; delete interfaces;
@@ -285,7 +285,7 @@ PPPManager::GetInterfaces(ppp_interface_id *interfaces, int32 count,
info.count = count; info.count = count;
info.filter = filter; info.filter = filter;
if(Control(PPPC_GET_INTERFACES, &info, sizeof(info)) != B_OK) if (Control(PPPC_GET_INTERFACES, &info, sizeof(info)) != B_OK)
return -1; return -1;
else else
return info.resultCount; return info.resultCount;
@@ -313,16 +313,16 @@ PPPManager::InterfaceWithUnit(int32 if_unit) const
int32 count; int32 count;
ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES); ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES);
if(!interfaces) if (!interfaces)
return PPP_UNDEFINED_INTERFACE_ID; return PPP_UNDEFINED_INTERFACE_ID;
ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID; ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID;
PPPInterface interface; PPPInterface interface;
ppp_interface_info_t info; ppp_interface_info_t info;
for(int32 index = 0; index < count; index++) { for (int32 index = 0; index < count; index++) {
interface.SetTo(interfaces[index]); interface.SetTo(interfaces[index]);
if(interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info) if (interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info)
&& info.info.if_unit == if_unit) { && info.info.if_unit == if_unit) {
id = interface.ID(); id = interface.ID();
break; break;
@@ -339,22 +339,22 @@ PPPManager::InterfaceWithUnit(int32 if_unit) const
ppp_interface_id ppp_interface_id
PPPManager::InterfaceWithName(const char *name) const PPPManager::InterfaceWithName(const char *name) const
{ {
if(!name) if (!name)
return PPP_UNDEFINED_INTERFACE_ID; return PPP_UNDEFINED_INTERFACE_ID;
int32 count; int32 count;
ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES); ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES);
if(!interfaces) if (!interfaces)
return PPP_UNDEFINED_INTERFACE_ID; return PPP_UNDEFINED_INTERFACE_ID;
ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID; ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID;
PPPInterface interface; PPPInterface interface;
ppp_interface_info_t info; ppp_interface_info_t info;
for(int32 index = 0; index < count; index++) { for (int32 index = 0; index < count; index++) {
interface.SetTo(interfaces[index]); interface.SetTo(interfaces[index]);
if(interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info) if (interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info)
&& strlen(info.info.name) > 0 && !strcasecmp(info.info.name, name)) { && strlen(info.info.name) > 0 && !strcasecmp(info.info.name, name)) {
id = interface.ID(); id = interface.ID();
break; break;
@@ -363,11 +363,11 @@ PPPManager::InterfaceWithName(const char *name) const
delete interfaces; delete interfaces;
if(id != PPP_UNDEFINED_INTERFACE_ID) if (id != PPP_UNDEFINED_INTERFACE_ID)
return id; return id;
else if(!strncmp(name, "ppp", 3) && strlen(name) > 3 && isdigit(name[3])) else if (!strncmp(name, "ppp", 3) && strlen(name) > 3 && isdigit(name[3]))
return InterfaceWithUnit(atoi(name + 3)); return InterfaceWithUnit(atoi(name + 3));
else if(isdigit(name[0])) else if (isdigit(name[0]))
return atoi(name); return atoi(name);
else else
return PPP_UNDEFINED_INTERFACE_ID; return PPP_UNDEFINED_INTERFACE_ID;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -16,7 +16,7 @@ get_stack_driver_path()
// user-defined stack driver path? // user-defined stack driver path?
path = getenv("NET_STACK_DRIVER_PATH"); path = getenv("NET_STACK_DRIVER_PATH");
if(path) if (path)
return path; return path;
// use the default stack driver path // use the default stack driver path
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net> * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */