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