Mostly fixes and smaller API changes.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5119 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,20 +20,20 @@ PPPConfigurePacket::PPPConfigurePacket(uint8 code)
|
|||||||
PPPConfigurePacket::PPPConfigurePacket(struct mbuf *packet)
|
PPPConfigurePacket::PPPConfigurePacket(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
// decode packet
|
// decode packet
|
||||||
ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*);
|
ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*);
|
||||||
|
|
||||||
if(!SetCode(data->code))
|
if(!SetCode(header->code))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(data->length < 4)
|
if(header->length < 4)
|
||||||
return;
|
return;
|
||||||
// there are no items (or one corrupted item)
|
// there are no items (or one corrupted item)
|
||||||
|
|
||||||
int32 position = 0;
|
int32 position = 0;
|
||||||
ppp_configure_item *item;
|
ppp_configure_item *item;
|
||||||
|
|
||||||
while(position <= data->length - 4) {
|
while(position <= header->length - 4) {
|
||||||
item = (ppp_configure_item*) (data->data + position);
|
item = (ppp_configure_item*) (header->data + position);
|
||||||
position += item->length;
|
position += item->length;
|
||||||
|
|
||||||
AddItem(item);
|
AddItem(item);
|
||||||
@@ -130,9 +130,9 @@ PPPConfigurePacket::ToMbuf(uint32 reserve = 0)
|
|||||||
struct mbuf *packet = m_gethdr(MT_DATA);
|
struct mbuf *packet = m_gethdr(MT_DATA);
|
||||||
packet->m_data += reserve;
|
packet->m_data += reserve;
|
||||||
|
|
||||||
ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*);
|
ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*);
|
||||||
|
|
||||||
data->code = Code();
|
header->code = Code();
|
||||||
|
|
||||||
uint8 length = 0;
|
uint8 length = 0;
|
||||||
ppp_configure_item *item;
|
ppp_configure_item *item;
|
||||||
@@ -140,17 +140,18 @@ PPPConfigurePacket::ToMbuf(uint32 reserve = 0)
|
|||||||
for(int32 index = 0; index < CountItems(); index++) {
|
for(int32 index = 0; index < CountItems(); index++) {
|
||||||
item = ItemAt(index);
|
item = ItemAt(index);
|
||||||
|
|
||||||
|
// make sure we have enough space left
|
||||||
if(0xFF - length < item->length) {
|
if(0xFF - length < item->length) {
|
||||||
m_freem(packet);
|
m_freem(packet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(data->data + length, item, item->length);
|
memcpy(header->data + length, item, item->length);
|
||||||
length += item->length;
|
length += item->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->length = length + 2;
|
header->length = length + 2;
|
||||||
packet->m_len = data->length;
|
packet->m_len = header->length;
|
||||||
|
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ PPPDevice::PPPDevice(const char *name, PPPInterface& interface,
|
|||||||
fMTU(1500),
|
fMTU(1500),
|
||||||
fInterface(interface),
|
fInterface(interface),
|
||||||
fSettings(settings),
|
fSettings(settings),
|
||||||
fIsUp(false)
|
fConnectionPhase(PPP_DOWN_PHASE)
|
||||||
{
|
{
|
||||||
fInitStatus = interface.SetDevice(this) && fInitStatus == B_OK ? B_OK : B_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PPPDevice::~PPPDevice()
|
PPPDevice::~PPPDevice()
|
||||||
{
|
{
|
||||||
|
if(Interface().Device() == this)
|
||||||
Interface().SetDevice(NULL);
|
Interface().SetDevice(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,15 +85,19 @@ PPPDevice::Pulse()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PPPDevice::UpStarted() const
|
PPPDevice::UpStarted()
|
||||||
{
|
{
|
||||||
|
fConnectionPhase = PPP_ESTABLISHMENT_PHASE;
|
||||||
|
|
||||||
return Interface().StateMachine().TLSNotify();
|
return Interface().StateMachine().TLSNotify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PPPDevice::DownStarted() const
|
PPPDevice::DownStarted()
|
||||||
{
|
{
|
||||||
|
fConnectionPhase = PPP_TERMINATION_PHASE;
|
||||||
|
|
||||||
return Interface().StateMachine().TLFNotify();
|
return Interface().StateMachine().TLFNotify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +105,7 @@ PPPDevice::DownStarted() const
|
|||||||
void
|
void
|
||||||
PPPDevice::UpFailedEvent()
|
PPPDevice::UpFailedEvent()
|
||||||
{
|
{
|
||||||
fIsUp = false;
|
fConnectionPhase = PPP_DOWN_PHASE;
|
||||||
|
|
||||||
Interface().StateMachine().UpFailedEvent();
|
Interface().StateMachine().UpFailedEvent();
|
||||||
}
|
}
|
||||||
@@ -110,7 +114,7 @@ PPPDevice::UpFailedEvent()
|
|||||||
void
|
void
|
||||||
PPPDevice::UpEvent()
|
PPPDevice::UpEvent()
|
||||||
{
|
{
|
||||||
fIsUp = true;
|
fConnectionPhase = PPP_ESTABLISHED_PHASE;
|
||||||
|
|
||||||
Interface().StateMachine().UpEvent();
|
Interface().StateMachine().UpEvent();
|
||||||
}
|
}
|
||||||
@@ -119,7 +123,7 @@ PPPDevice::UpEvent()
|
|||||||
void
|
void
|
||||||
PPPDevice::DownEvent()
|
PPPDevice::DownEvent()
|
||||||
{
|
{
|
||||||
fIsUp = false;
|
fConnectionPhase = PPP_DOWN_PHASE;
|
||||||
|
|
||||||
Interface().StateMachine().DownEvent();
|
Interface().StateMachine().DownEvent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
#ifdef _KERNEL_MODE
|
||||||
#define spawn_thread spawn_kernel_thread
|
#define spawn_thread spawn_kernel_thread
|
||||||
|
#define printf dprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -59,48 +60,58 @@ status_t redial_thread(void *data);
|
|||||||
status_t interface_deleter_thread(void *data);
|
status_t interface_deleter_thread(void *data);
|
||||||
|
|
||||||
|
|
||||||
PPPInterface::PPPInterface(uint32 ID, driver_settings *settings,
|
PPPInterface::PPPInterface(uint32 ID, const driver_settings *settings,
|
||||||
PPPInterface *parent = NULL)
|
PPPInterface *parent = NULL)
|
||||||
: PPPLayer("PPPInterface", PPP_INTERFACE_LEVEL),
|
: PPPLayer("PPPInterface", PPP_INTERFACE_LEVEL),
|
||||||
fID(ID),
|
fID(ID),
|
||||||
fSettings(dup_driver_settings(settings)),
|
fSettings(dup_driver_settings(settings)),
|
||||||
fStateMachine(*this),
|
|
||||||
fLCP(*this),
|
|
||||||
fReportManager(StateMachine().Locker()),
|
|
||||||
fIfnet(NULL),
|
fIfnet(NULL),
|
||||||
fUpThread(-1),
|
fUpThread(-1),
|
||||||
fRedialThread(-1),
|
fRedialThread(-1),
|
||||||
fDialRetry(0),
|
fDialRetry(0),
|
||||||
fDialRetriesLimit(0),
|
fDialRetriesLimit(0),
|
||||||
|
fManager(NULL),
|
||||||
fIdleSince(0),
|
fIdleSince(0),
|
||||||
fMRU(1500),
|
fMRU(1500),
|
||||||
fInterfaceMTU(1500),
|
fInterfaceMTU(1498),
|
||||||
fHeaderLength(2),
|
fHeaderLength(2),
|
||||||
|
fParent(NULL),
|
||||||
|
fIsMultilink(false),
|
||||||
fAutoRedial(false),
|
fAutoRedial(false),
|
||||||
fDialOnDemand(false),
|
fDialOnDemand(false),
|
||||||
|
fMode(PPP_CLIENT_MODE),
|
||||||
fLocalPFCState(PPP_PFC_DISABLED),
|
fLocalPFCState(PPP_PFC_DISABLED),
|
||||||
fPeerPFCState(PPP_PFC_DISABLED),
|
fPeerPFCState(PPP_PFC_DISABLED),
|
||||||
fPFCOptions(0),
|
fPFCOptions(0),
|
||||||
fDevice(NULL),
|
fDevice(NULL),
|
||||||
fFirstProtocol(NULL),
|
fFirstProtocol(NULL),
|
||||||
fLock(StateMachine().Locker()),
|
fStateMachine(*this),
|
||||||
|
fLCP(*this),
|
||||||
|
fReportManager(StateMachine().fLock),
|
||||||
|
fLock(StateMachine().fLock),
|
||||||
fDeleteCounter(0)
|
fDeleteCounter(0)
|
||||||
{
|
{
|
||||||
// add internal modules
|
// add internal modules
|
||||||
|
// LCP
|
||||||
|
if(!AddProtocol(&LCP())) {
|
||||||
|
fInitStatus = B_ERROR;
|
||||||
|
return;
|
||||||
|
}
|
||||||
// MRU
|
// MRU
|
||||||
_PPPMRUHandler *mruHandler =
|
_PPPMRUHandler *mruHandler =
|
||||||
new _PPPMRUHandler(*this);
|
new _PPPMRUHandler(*this);
|
||||||
if(mruHandler->InitCheck() != B_OK)
|
if(!LCP().AddOptionHandler(mruHandler) || mruHandler->InitCheck() != B_OK)
|
||||||
delete mruHandler;
|
delete mruHandler;
|
||||||
// authentication
|
// authentication
|
||||||
_PPPAuthenticationHandler *authenticationHandler =
|
_PPPAuthenticationHandler *authenticationHandler =
|
||||||
new _PPPAuthenticationHandler(*this);
|
new _PPPAuthenticationHandler(*this);
|
||||||
if(authenticationHandler->InitCheck() != B_OK)
|
if(!LCP().AddOptionHandler(authenticationHandler)
|
||||||
|
|| authenticationHandler->InitCheck() != B_OK)
|
||||||
delete authenticationHandler;
|
delete authenticationHandler;
|
||||||
// PFC
|
// PFC
|
||||||
_PPPPFCHandler *pfcHandler =
|
_PPPPFCHandler *pfcHandler =
|
||||||
new _PPPPFCHandler(fLocalPFCState, fPeerPFCState, *this);
|
new _PPPPFCHandler(fLocalPFCState, fPeerPFCState, *this);
|
||||||
if(pfcHandler->InitCheck() != B_OK)
|
if(!LCP().AddOptionHandler(pfcHandler) || pfcHandler->InitCheck() != B_OK)
|
||||||
delete pfcHandler;
|
delete pfcHandler;
|
||||||
|
|
||||||
// set up dial delays
|
// set up dial delays
|
||||||
@@ -110,20 +121,18 @@ PPPInterface::PPPInterface(uint32 ID, driver_settings *settings,
|
|||||||
// 1s delay between lost connection and redial
|
// 1s delay between lost connection and redial
|
||||||
|
|
||||||
if(get_module(PPP_INTERFACE_MODULE_NAME, (module_info**) &fManager) != B_OK)
|
if(get_module(PPP_INTERFACE_MODULE_NAME, (module_info**) &fManager) != B_OK)
|
||||||
fManager = NULL;
|
printf("PPPInterface: Manager module not found!\n");
|
||||||
|
|
||||||
// are we a multilink subinterface?
|
// are we a multilink subinterface?
|
||||||
if(parent && parent->IsMultilink()) {
|
if(parent && parent->IsMultilink()) {
|
||||||
fParent = parent;
|
fParent = parent;
|
||||||
fParent->AddChild(this);
|
fParent->AddChild(this);
|
||||||
fIsMultilink = true;
|
fIsMultilink = true;
|
||||||
} else {
|
|
||||||
fParent = NULL;
|
|
||||||
fIsMultilink = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterInterface();
|
||||||
|
|
||||||
if(!fSettings) {
|
if(!fSettings) {
|
||||||
fMode = PPP_CLIENT_MODE;
|
|
||||||
fInitStatus = B_ERROR;
|
fInitStatus = B_ERROR;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -142,7 +151,7 @@ PPPInterface::PPPInterface(uint32 ID, driver_settings *settings,
|
|||||||
|
|
||||||
// get mode settings
|
// get mode settings
|
||||||
value = get_settings_value(PPP_MODE_KEY, fSettings);
|
value = get_settings_value(PPP_MODE_KEY, fSettings);
|
||||||
if(!strcasecmp(value, PPP_SERVER_MODE_VALUE))
|
if(value && !strcasecmp(value, PPP_SERVER_MODE_VALUE))
|
||||||
fMode = PPP_SERVER_MODE;
|
fMode = PPP_SERVER_MODE;
|
||||||
else
|
else
|
||||||
fMode = PPP_CLIENT_MODE;
|
fMode = PPP_CLIENT_MODE;
|
||||||
@@ -164,17 +173,21 @@ PPPInterface::PPPInterface(uint32 ID, driver_settings *settings,
|
|||||||
// auto redial is disabled by default
|
// auto redial is disabled by default
|
||||||
|
|
||||||
// load all protocols and the device
|
// load all protocols and the device
|
||||||
if(LoadModules(fSettings, 0, fSettings->parameter_count) && fInitStatus == B_OK)
|
if(!LoadModules(fSettings, 0, fSettings->parameter_count)) {
|
||||||
fInitStatus = B_OK;
|
printf("PPPInterface: Error loading modules!\n");
|
||||||
else
|
|
||||||
fInitStatus = B_ERROR;
|
fInitStatus = B_ERROR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PPPInterface::~PPPInterface()
|
PPPInterface::~PPPInterface()
|
||||||
{
|
{
|
||||||
++fDeleteCounter;
|
++fDeleteCounter;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: Destructor\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
// make sure we are not accessible by any thread before we continue
|
// make sure we are not accessible by any thread before we continue
|
||||||
UnregisterInterface();
|
UnregisterInterface();
|
||||||
|
|
||||||
@@ -204,11 +217,12 @@ PPPInterface::~PPPInterface()
|
|||||||
|
|
||||||
delete Device();
|
delete Device();
|
||||||
|
|
||||||
while(CountProtocols())
|
while(FirstProtocol()) {
|
||||||
delete ProtocolAt(0);
|
if(FirstProtocol() == &LCP())
|
||||||
|
fFirstProtocol = fFirstProtocol->NextProtocol();
|
||||||
while(FirstProtocol())
|
else
|
||||||
delete FirstProtocol();
|
delete FirstProtocol();
|
||||||
|
}
|
||||||
|
|
||||||
for(int32 index = 0; index < fModules.CountItems(); index++) {
|
for(int32 index = 0; index < fModules.CountItems(); index++) {
|
||||||
put_module(fModules.ItemAt(index));
|
put_module(fModules.ItemAt(index));
|
||||||
@@ -249,6 +263,10 @@ PPPInterface::Delete()
|
|||||||
status_t
|
status_t
|
||||||
PPPInterface::InitCheck() const
|
PPPInterface::InitCheck() const
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: InitCheck(): 0x%lX\n", fInitStatus);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(fInitStatus != B_OK)
|
if(fInitStatus != B_OK)
|
||||||
return fInitStatus;
|
return fInitStatus;
|
||||||
|
|
||||||
@@ -269,7 +287,11 @@ PPPInterface::InitCheck() const
|
|||||||
bool
|
bool
|
||||||
PPPInterface::SetMRU(uint32 MRU)
|
PPPInterface::SetMRU(uint32 MRU)
|
||||||
{
|
{
|
||||||
if(MRU > Device()->MTU() - 2)
|
#if DEBUG
|
||||||
|
printf("PPPInterface: SetMRU(%ld)\n", MRU);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(Device() && MRU > Device()->MTU() - 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
@@ -293,6 +315,10 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
|
|||||||
ppp_interface_info *info = (ppp_interface_info*) data;
|
ppp_interface_info *info = (ppp_interface_info*) data;
|
||||||
memset(info, 0, sizeof(ppp_interface_info_t));
|
memset(info, 0, sizeof(ppp_interface_info_t));
|
||||||
info->settings = Settings();
|
info->settings = Settings();
|
||||||
|
if(Ifnet())
|
||||||
|
info->if_unit = Ifnet()->if_unit;
|
||||||
|
else
|
||||||
|
info->if_unit = -1;
|
||||||
info->mode = Mode();
|
info->mode = Mode();
|
||||||
info->state = State();
|
info->state = State();
|
||||||
info->phase = Phase();
|
info->phase = Phase();
|
||||||
@@ -343,7 +369,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
|
|||||||
SetAutoRedial(*((uint32*)data));
|
SetAutoRedial(*((uint32*)data));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPPC_ENABLE_INTERFACE_REPORTS: {
|
case PPPC_ENABLE_REPORTS: {
|
||||||
if(length < sizeof(ppp_report_request) || !data)
|
if(length < sizeof(ppp_report_request) || !data)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -352,7 +378,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
|
|||||||
request->flags);
|
request->flags);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case PPPC_DISABLE_INTERFACE_REPORTS: {
|
case PPPC_DISABLE_REPORTS: {
|
||||||
if(length < sizeof(ppp_report_request) || !data)
|
if(length < sizeof(ppp_report_request) || !data)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -432,7 +458,11 @@ PPPInterface::Control(uint32 op, void *data, size_t length)
|
|||||||
bool
|
bool
|
||||||
PPPInterface::SetDevice(PPPDevice *device)
|
PPPInterface::SetDevice(PPPDevice *device)
|
||||||
{
|
{
|
||||||
if(!device)
|
#if DEBUG
|
||||||
|
printf("PPPInterface: SetDevice()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(device && &device->Interface() != this)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(IsMultilink() && !Parent())
|
if(IsMultilink() && !Parent())
|
||||||
@@ -451,6 +481,7 @@ PPPInterface::SetDevice(PPPDevice *device)
|
|||||||
fDevice = device;
|
fDevice = device;
|
||||||
SetNext(device);
|
SetNext(device);
|
||||||
|
|
||||||
|
if(fDevice)
|
||||||
fMRU = fDevice->MTU() - 2;
|
fMRU = fDevice->MTU() - 2;
|
||||||
|
|
||||||
CalculateInterfaceMTU();
|
CalculateInterfaceMTU();
|
||||||
@@ -466,7 +497,12 @@ PPPInterface::AddProtocol(PPPProtocol *protocol)
|
|||||||
// Find instert position after the last protocol
|
// Find instert position after the last protocol
|
||||||
// with the same level.
|
// with the same level.
|
||||||
|
|
||||||
if(!protocol || protocol->Level() == PPP_INTERFACE_LEVEL)
|
#if DEBUG
|
||||||
|
printf("PPPInterface: AddProtocol()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(!protocol || &protocol->Interface() != this
|
||||||
|
|| protocol->Level() == PPP_INTERFACE_LEVEL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
@@ -495,7 +531,7 @@ PPPInterface::AddProtocol(PPPProtocol *protocol)
|
|||||||
protocol->SetNextProtocol(NULL);
|
protocol->SetNextProtocol(NULL);
|
||||||
// this also sets next to NULL
|
// this also sets next to NULL
|
||||||
protocol->SetNext(this);
|
protocol->SetNext(this);
|
||||||
// we need to set us as the next layer
|
// we need to set us as the next layer for the last protocol
|
||||||
} else {
|
} else {
|
||||||
protocol->SetNextProtocol(current);
|
protocol->SetNextProtocol(current);
|
||||||
|
|
||||||
@@ -518,6 +554,10 @@ PPPInterface::AddProtocol(PPPProtocol *protocol)
|
|||||||
bool
|
bool
|
||||||
PPPInterface::RemoveProtocol(PPPProtocol *protocol)
|
PPPInterface::RemoveProtocol(PPPProtocol *protocol)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: RemoveProtocol()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
if(Phase() != PPP_DOWN_PHASE)
|
if(Phase() != PPP_DOWN_PHASE)
|
||||||
@@ -559,10 +599,15 @@ int32
|
|||||||
PPPInterface::CountProtocols() const
|
PPPInterface::CountProtocols() const
|
||||||
{
|
{
|
||||||
PPPProtocol *protocol = FirstProtocol();
|
PPPProtocol *protocol = FirstProtocol();
|
||||||
|
|
||||||
int32 count = 0;
|
int32 count = 0;
|
||||||
for(; protocol; protocol = protocol->NextProtocol())
|
for(; protocol; protocol = protocol->NextProtocol())
|
||||||
++count;
|
++count;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: CountProtocols(): %ld\n", count);
|
||||||
|
#endif
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,19 +615,27 @@ PPPInterface::CountProtocols() const
|
|||||||
PPPProtocol*
|
PPPProtocol*
|
||||||
PPPInterface::ProtocolAt(int32 index) const
|
PPPInterface::ProtocolAt(int32 index) const
|
||||||
{
|
{
|
||||||
PPPProtocol *protocol = FirstProtocol();
|
#if DEBUG
|
||||||
int32 currentIndex = 0;
|
printf("PPPInterface: ProtocolAt(%ld)\n", index);
|
||||||
for(; protocol; protocol = protocol->NextProtocol(), ++currentIndex)
|
#endif
|
||||||
if(currentIndex == index)
|
|
||||||
return protocol;
|
|
||||||
|
|
||||||
return NULL;
|
PPPProtocol *protocol = FirstProtocol();
|
||||||
|
|
||||||
|
int32 currentIndex = 0;
|
||||||
|
for(; protocol && currentIndex != index; protocol = protocol->NextProtocol())
|
||||||
|
++currentIndex;
|
||||||
|
|
||||||
|
return protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PPPProtocol*
|
PPPProtocol*
|
||||||
PPPInterface::ProtocolFor(uint16 protocolNumber, PPPProtocol *start = NULL) const
|
PPPInterface::ProtocolFor(uint16 protocolNumber, PPPProtocol *start = NULL) const
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: ProtocolFor(0x%X)\n", protocolNumber);
|
||||||
|
#endif
|
||||||
|
|
||||||
PPPProtocol *current = start ? start : FirstProtocol();
|
PPPProtocol *current = start ? start : FirstProtocol();
|
||||||
|
|
||||||
for(; current; current = current->NextProtocol()) {
|
for(; current; current = current->NextProtocol()) {
|
||||||
@@ -599,6 +652,10 @@ PPPInterface::ProtocolFor(uint16 protocolNumber, PPPProtocol *start = NULL) cons
|
|||||||
bool
|
bool
|
||||||
PPPInterface::AddChild(PPPInterface *child)
|
PPPInterface::AddChild(PPPInterface *child)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: AddChild()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!child)
|
if(!child)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -616,6 +673,10 @@ PPPInterface::AddChild(PPPInterface *child)
|
|||||||
bool
|
bool
|
||||||
PPPInterface::RemoveChild(PPPInterface *child)
|
PPPInterface::RemoveChild(PPPInterface *child)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: RemoveChild()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
if(!fChildren.RemoveItem(child))
|
if(!fChildren.RemoveItem(child))
|
||||||
@@ -634,6 +695,10 @@ PPPInterface::RemoveChild(PPPInterface *child)
|
|||||||
PPPInterface*
|
PPPInterface*
|
||||||
PPPInterface::ChildAt(int32 index) const
|
PPPInterface::ChildAt(int32 index) const
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: ChildAt(%ld)\n", index);
|
||||||
|
#endif
|
||||||
|
|
||||||
PPPInterface *child = fChildren.ItemAt(index);
|
PPPInterface *child = fChildren.ItemAt(index);
|
||||||
|
|
||||||
if(child == fChildren.GetDefaultItem())
|
if(child == fChildren.GetDefaultItem())
|
||||||
@@ -646,6 +711,10 @@ PPPInterface::ChildAt(int32 index) const
|
|||||||
void
|
void
|
||||||
PPPInterface::SetAutoRedial(bool autoRedial = true)
|
PPPInterface::SetAutoRedial(bool autoRedial = true)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: SetAutoRedial(%s)\n", autoRedial ? "true" : "false");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(Mode() == PPP_CLIENT_MODE)
|
if(Mode() == PPP_CLIENT_MODE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -661,14 +730,29 @@ PPPInterface::SetDialOnDemand(bool dialOnDemand = true)
|
|||||||
// All protocols must check if DialOnDemand was enabled/disabled after this
|
// All protocols must check if DialOnDemand was enabled/disabled after this
|
||||||
// interface went down. This is the only situation where a change is relevant.
|
// interface went down. This is the only situation where a change is relevant.
|
||||||
|
|
||||||
// Only clients support DialOnDemand. Maybe no change needed.
|
#if DEBUG
|
||||||
if(Mode() != PPP_CLIENT_MODE || DoesDialOnDemand() == dialOnDemand)
|
printf("PPPInterface: SetDialOnDemand(%s)\n", dialOnDemand ? "true" : "false");
|
||||||
|
printf("PPPInterface::SetDialOnDemand(): %s\n", fDialOnDemand ? "true" : "false");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Only clients support DialOnDemand.
|
||||||
|
if(Mode() != PPP_CLIENT_MODE) {
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface::SetDialOnDemand(): Wrong mode!\n");
|
||||||
|
#endif
|
||||||
|
fDialOnDemand = false;
|
||||||
|
return;
|
||||||
|
} else if(DoesDialOnDemand() == dialOnDemand)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
fDialOnDemand = dialOnDemand;
|
fDialOnDemand = dialOnDemand;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface::SetDialOnDemand() done: %s\n", fDialOnDemand?"true":"false");
|
||||||
|
#endif
|
||||||
|
|
||||||
// Do not allow changes when we are disconnected (only main interfaces).
|
// Do not allow changes when we are disconnected (only main interfaces).
|
||||||
// This would make no sense because
|
// This would make no sense because
|
||||||
// - enabling: this cannot happen because hidden interfaces are deleted if they
|
// - enabling: this cannot happen because hidden interfaces are deleted if they
|
||||||
@@ -682,17 +766,13 @@ PPPInterface::SetDialOnDemand(bool dialOnDemand = true)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we need to register/unregister
|
// check if we need to set/unset flags
|
||||||
if(dialOnDemand) {
|
if(dialOnDemand) {
|
||||||
RegisterInterface();
|
|
||||||
if(Ifnet())
|
if(Ifnet())
|
||||||
Ifnet()->if_flags |= IFF_RUNNING;
|
Ifnet()->if_flags |= IFF_UP;
|
||||||
} else if(!dialOnDemand && Phase() < PPP_ESTABLISHED_PHASE) {
|
} else if(!dialOnDemand && Phase() < PPP_ESTABLISHED_PHASE) {
|
||||||
UnregisterInterface();
|
if(Ifnet())
|
||||||
|
Ifnet()->if_flags &= ~IFF_UP;
|
||||||
// if we are already down we must delete us
|
|
||||||
if(State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE)
|
|
||||||
Delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,6 +780,10 @@ PPPInterface::SetDialOnDemand(bool dialOnDemand = true)
|
|||||||
bool
|
bool
|
||||||
PPPInterface::SetPFCOptions(uint8 pfcOptions)
|
PPPInterface::SetPFCOptions(uint8 pfcOptions)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: SetPFCOptions(0x%X)\n", pfcOptions);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(PFCOptions() & PPP_FREEZE_PFC_OPTIONS)
|
if(PFCOptions() & PPP_FREEZE_PFC_OPTIONS)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -711,6 +795,10 @@ PPPInterface::SetPFCOptions(uint8 pfcOptions)
|
|||||||
bool
|
bool
|
||||||
PPPInterface::Up()
|
PPPInterface::Up()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: Up()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(InitCheck() != B_OK || Phase() == PPP_TERMINATION_PHASE)
|
if(InitCheck() != B_OK || Phase() == PPP_TERMINATION_PHASE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -763,6 +851,11 @@ PPPInterface::Up()
|
|||||||
if(receive_data(&sender, &report, sizeof(report)) != PPP_REPORT_CODE)
|
if(receive_data(&sender, &report, sizeof(report)) != PPP_REPORT_CODE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface::Up(): Report: Type = %ld Code = %ld\n", report.type,
|
||||||
|
report.code);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(IsUp()) {
|
if(IsUp()) {
|
||||||
if(me == fUpThread) {
|
if(me == fUpThread) {
|
||||||
fDialRetry = 0;
|
fDialRetry = 0;
|
||||||
@@ -894,6 +987,10 @@ PPPInterface::Up()
|
|||||||
bool
|
bool
|
||||||
PPPInterface::Down()
|
PPPInterface::Down()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: Down()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(InitCheck() != B_OK)
|
if(InitCheck() != B_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -951,6 +1048,10 @@ PPPInterface::IsUp() const
|
|||||||
bool
|
bool
|
||||||
PPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
|
PPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: LoadModules()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(Phase() != PPP_DOWN_PHASE)
|
if(Phase() != PPP_DOWN_PHASE)
|
||||||
return false;
|
return false;
|
||||||
// a running connection may not change
|
// a running connection may not change
|
||||||
@@ -966,11 +1067,10 @@ PPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
|
|||||||
if(!strcasecmp(settings->parameters[index].name, PPP_MULTILINK_KEY)
|
if(!strcasecmp(settings->parameters[index].name, PPP_MULTILINK_KEY)
|
||||||
&& settings->parameters[index].value_count > 0) {
|
&& settings->parameters[index].value_count > 0) {
|
||||||
if(!LoadModule(settings->parameters[index].values[0],
|
if(!LoadModule(settings->parameters[index].values[0],
|
||||||
settings->parameters[index].parameters, PPP_MULTILINK_KEY_TYPE))
|
&settings->parameters[index], PPP_MULTILINK_KEY_TYPE))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// are we a multilink main interface?
|
// are we a multilink main interface?
|
||||||
@@ -1000,7 +1100,7 @@ PPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
|
|||||||
for(int32 value_id = 0; value_id < settings->parameters[index].value_count;
|
for(int32 value_id = 0; value_id < settings->parameters[index].value_count;
|
||||||
value_id++)
|
value_id++)
|
||||||
if(!LoadModule(settings->parameters[index].values[value_id],
|
if(!LoadModule(settings->parameters[index].values[value_id],
|
||||||
settings->parameters[index].parameters, type))
|
&settings->parameters[index], type))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1012,6 +1112,10 @@ bool
|
|||||||
PPPInterface::LoadModule(const char *name, driver_parameter *parameter,
|
PPPInterface::LoadModule(const char *name, driver_parameter *parameter,
|
||||||
ppp_module_key_type type)
|
ppp_module_key_type type)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: LoadModule(%s)\n", name ? name : "XXX: NO NAME");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(Phase() != PPP_DOWN_PHASE)
|
if(Phase() != PPP_DOWN_PHASE)
|
||||||
return false;
|
return false;
|
||||||
// a running connection may not change
|
// a running connection may not change
|
||||||
@@ -1045,6 +1149,10 @@ PPPInterface::IsAllowedToSend() const
|
|||||||
status_t
|
status_t
|
||||||
PPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
|
PPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: Send(0x%X)\n", protocolNumber);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!packet)
|
if(!packet)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -1129,6 +1237,10 @@ PPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
|
|||||||
status_t
|
status_t
|
||||||
PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
|
PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: Receive(0x%X)\n", protocolNumber);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!packet)
|
if(!packet)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -1178,6 +1290,10 @@ PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
|
|||||||
status_t
|
status_t
|
||||||
PPPInterface::ReceiveFromDevice(struct mbuf *packet)
|
PPPInterface::ReceiveFromDevice(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: ReceiveFromDevice()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!packet)
|
if(!packet)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -1225,6 +1341,10 @@ PPPInterface::Pulse()
|
|||||||
bool
|
bool
|
||||||
PPPInterface::RegisterInterface()
|
PPPInterface::RegisterInterface()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: RegisterInterface()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(fIfnet)
|
if(fIfnet)
|
||||||
return true;
|
return true;
|
||||||
// we are already registered
|
// we are already registered
|
||||||
@@ -1247,6 +1367,10 @@ PPPInterface::RegisterInterface()
|
|||||||
if(!fIfnet)
|
if(!fIfnet)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if(DoesDialOnDemand())
|
||||||
|
fIfnet->if_flags |= IFF_UP;
|
||||||
|
|
||||||
|
CalculateInterfaceMTU();
|
||||||
CalculateBaudRate();
|
CalculateBaudRate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1256,6 +1380,10 @@ PPPInterface::RegisterInterface()
|
|||||||
bool
|
bool
|
||||||
PPPInterface::UnregisterInterface()
|
PPPInterface::UnregisterInterface()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: UnregisterInterface()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!fIfnet)
|
if(!fIfnet)
|
||||||
return true;
|
return true;
|
||||||
// we are already unregistered
|
// we are already unregistered
|
||||||
@@ -1270,6 +1398,7 @@ PPPInterface::UnregisterInterface()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
fManager->UnregisterInterface(ID());
|
fManager->UnregisterInterface(ID());
|
||||||
|
// this will delete fIfnet, so do not access it anymore!
|
||||||
fIfnet = NULL;
|
fIfnet = NULL;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1280,8 +1409,9 @@ PPPInterface::UnregisterInterface()
|
|||||||
status_t
|
status_t
|
||||||
PPPInterface::StackControl(uint32 op, void *data)
|
PPPInterface::StackControl(uint32 op, void *data)
|
||||||
{
|
{
|
||||||
// TODO:
|
#if DEBUG
|
||||||
// implement when writing ppp interface module
|
printf("PPPInterface: StackControl(0x%lX)\n", op);
|
||||||
|
#endif
|
||||||
|
|
||||||
switch(op) {
|
switch(op) {
|
||||||
default:
|
default:
|
||||||
@@ -1322,6 +1452,10 @@ class CallStackControl {
|
|||||||
status_t
|
status_t
|
||||||
PPPInterface::StackControlEachHandler(uint32 op, void *data)
|
PPPInterface::StackControlEachHandler(uint32 op, void *data)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: StackControlEachHandler(0x%lX)\n", op);
|
||||||
|
#endif
|
||||||
|
|
||||||
status_t result = B_BAD_VALUE, tmp;
|
status_t result = B_BAD_VALUE, tmp;
|
||||||
|
|
||||||
PPPProtocol *protocol = FirstProtocol();
|
PPPProtocol *protocol = FirstProtocol();
|
||||||
@@ -1345,7 +1479,12 @@ PPPInterface::StackControlEachHandler(uint32 op, void *data)
|
|||||||
void
|
void
|
||||||
PPPInterface::CalculateInterfaceMTU()
|
PPPInterface::CalculateInterfaceMTU()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: CalculateInterfaceMTU()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
fInterfaceMTU = fMRU;
|
fInterfaceMTU = fMRU;
|
||||||
|
fHeaderLength = 2;
|
||||||
|
|
||||||
// sum all headers (the protocol field is not counted)
|
// sum all headers (the protocol field is not counted)
|
||||||
PPPProtocol *protocol = FirstProtocol();
|
PPPProtocol *protocol = FirstProtocol();
|
||||||
@@ -1369,6 +1508,10 @@ PPPInterface::CalculateInterfaceMTU()
|
|||||||
void
|
void
|
||||||
PPPInterface::CalculateBaudRate()
|
PPPInterface::CalculateBaudRate()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: CalculateBaudRate()\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!Ifnet())
|
if(!Ifnet())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1387,6 +1530,10 @@ PPPInterface::CalculateBaudRate()
|
|||||||
void
|
void
|
||||||
PPPInterface::Redial(uint32 delay)
|
PPPInterface::Redial(uint32 delay)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
printf("PPPInterface: Redial(%ld)\n", delay);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(fRedialThread != -1)
|
if(fRedialThread != -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -32,16 +32,18 @@ PPPLCP::~PPPLCP()
|
|||||||
{
|
{
|
||||||
while(CountOptionHandlers())
|
while(CountOptionHandlers())
|
||||||
delete OptionHandlerAt(0);
|
delete OptionHandlerAt(0);
|
||||||
|
while(CountLCPExtensions())
|
||||||
|
delete LCPExtensionAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PPPLCP::AddOptionHandler(PPPOptionHandler *optionHandler)
|
PPPLCP::AddOptionHandler(PPPOptionHandler *optionHandler)
|
||||||
{
|
{
|
||||||
if(!optionHandler)
|
if(!optionHandler || &optionHandler->Interface() != &Interface())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LockerHelper locker(StateMachine().Locker());
|
LockerHelper locker(StateMachine().fLock);
|
||||||
|
|
||||||
if(Interface().Phase() != PPP_DOWN_PHASE || OptionHandlerFor(optionHandler->Type()))
|
if(Interface().Phase() != PPP_DOWN_PHASE || OptionHandlerFor(optionHandler->Type()))
|
||||||
return false;
|
return false;
|
||||||
@@ -55,7 +57,7 @@ PPPLCP::AddOptionHandler(PPPOptionHandler *optionHandler)
|
|||||||
bool
|
bool
|
||||||
PPPLCP::RemoveOptionHandler(PPPOptionHandler *optionHandler)
|
PPPLCP::RemoveOptionHandler(PPPOptionHandler *optionHandler)
|
||||||
{
|
{
|
||||||
LockerHelper locker(StateMachine().Locker());
|
LockerHelper locker(StateMachine().fLock);
|
||||||
|
|
||||||
if(Interface().Phase() != PPP_DOWN_PHASE)
|
if(Interface().Phase() != PPP_DOWN_PHASE)
|
||||||
return false;
|
return false;
|
||||||
@@ -106,10 +108,10 @@ PPPLCP::OptionHandlerFor(uint8 type, int32 *start = NULL) const
|
|||||||
bool
|
bool
|
||||||
PPPLCP::AddLCPExtension(PPPLCPExtension *lcpExtension)
|
PPPLCP::AddLCPExtension(PPPLCPExtension *lcpExtension)
|
||||||
{
|
{
|
||||||
if(!lcpExtension)
|
if(!lcpExtension || &lcpExtension->Interface() != &Interface())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LockerHelper locker(StateMachine().Locker());
|
LockerHelper locker(StateMachine().fLock);
|
||||||
|
|
||||||
if(Interface().Phase() != PPP_DOWN_PHASE)
|
if(Interface().Phase() != PPP_DOWN_PHASE)
|
||||||
return false;
|
return false;
|
||||||
@@ -122,7 +124,7 @@ PPPLCP::AddLCPExtension(PPPLCPExtension *lcpExtension)
|
|||||||
bool
|
bool
|
||||||
PPPLCP::RemoveLCPExtension(PPPLCPExtension *lcpExtension)
|
PPPLCP::RemoveLCPExtension(PPPLCPExtension *lcpExtension)
|
||||||
{
|
{
|
||||||
LockerHelper locker(StateMachine().Locker());
|
LockerHelper locker(StateMachine().fLock);
|
||||||
|
|
||||||
if(Interface().Phase() != PPP_DOWN_PHASE)
|
if(Interface().Phase() != PPP_DOWN_PHASE)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ PPPLCPExtension::PPPLCPExtension(const char *name, uint8 code, PPPInterface& int
|
|||||||
fName = strdup(name);
|
fName = strdup(name);
|
||||||
else
|
else
|
||||||
fName = strdup("Unknown");
|
fName = strdup("Unknown");
|
||||||
|
|
||||||
fInitStatus = interface.LCP().AddLCPExtension(this) ? B_OK : B_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,14 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <core_funcs.h>
|
#include <core_funcs.h>
|
||||||
|
|
||||||
|
#ifdef _KERNEL_MODE
|
||||||
#include <kernel_cpp.h>
|
#include <kernel_cpp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
PPPLayer::PPPLayer(const char *name, ppp_level level)
|
PPPLayer::PPPLayer(const char *name, ppp_level level)
|
||||||
: fInitStatus(B_OK),
|
: fInitStatus(B_OK),
|
||||||
|
fLevel(level),
|
||||||
fNext(NULL)
|
fNext(NULL)
|
||||||
{
|
{
|
||||||
if(name)
|
if(name)
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ PPPOptionHandler::PPPOptionHandler(const char *name, uint8 type,
|
|||||||
fName = strdup(name);
|
fName = strdup(name);
|
||||||
else
|
else
|
||||||
fName = strdup("Unknown");
|
fName = strdup("Unknown");
|
||||||
|
|
||||||
fInitStatus = interface.LCP().AddOptionHandler(this) ? B_OK : B_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ PPPProtocol::PPPProtocol(const char *name, ppp_phase activationPhase,
|
|||||||
else
|
else
|
||||||
fSide = PPP_PEER_SIDE;
|
fSide = PPP_PEER_SIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
fInitStatus = interface.AddProtocol(this) && fInitStatus == B_OK ? B_OK : B_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -118,11 +118,17 @@ PPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 len
|
|||||||
continue;
|
continue;
|
||||||
} else if(result == B_OK) {
|
} else if(result == B_OK) {
|
||||||
if(request->flags & PPP_WAIT_FOR_REPLY) {
|
if(request->flags & PPP_WAIT_FOR_REPLY) {
|
||||||
|
thread_info info;
|
||||||
|
|
||||||
if(request->flags & PPP_NO_REPLY_TIMEOUT) {
|
if(request->flags & PPP_NO_REPLY_TIMEOUT) {
|
||||||
sender = -1;
|
sender = -1;
|
||||||
while(sender != request->thread)
|
result = B_ERROR;
|
||||||
code = receive_data(&sender, NULL, 0);
|
// always check if the thread still exists
|
||||||
result = B_OK;
|
while(sender != request->thread
|
||||||
|
&& get_thread_info(request->thread, &info)
|
||||||
|
!= B_BAD_THREAD_ID)
|
||||||
|
result = receive_data_with_timeout(&sender, &code, NULL, 0,
|
||||||
|
PPP_REPORT_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
sender = -1;
|
sender = -1;
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ PPPStateMachine::NewState(ppp_state next)
|
|||||||
void
|
void
|
||||||
PPPStateMachine::NewPhase(ppp_phase next)
|
PPPStateMachine::NewPhase(ppp_phase next)
|
||||||
{
|
{
|
||||||
// the ifnet's running flag is set here and in PPPInterface::SetDialOnDemand()
|
|
||||||
|
|
||||||
// there is nothing after established phase and nothing before down phase
|
// there is nothing after established phase and nothing before down phase
|
||||||
if(next > PPP_ESTABLISHED_PHASE)
|
if(next > PPP_ESTABLISHED_PHASE)
|
||||||
next = PPP_ESTABLISHED_PHASE;
|
next = PPP_ESTABLISHED_PHASE;
|
||||||
@@ -86,10 +84,16 @@ PPPStateMachine::NewPhase(ppp_phase next)
|
|||||||
// Report a down event to parent if we are not usable anymore.
|
// Report a down event to parent if we are not usable anymore.
|
||||||
// The report threads get their notification later.
|
// The report threads get their notification later.
|
||||||
if(Phase() == PPP_ESTABLISHED_PHASE && next != Phase()) {
|
if(Phase() == PPP_ESTABLISHED_PHASE && next != Phase()) {
|
||||||
// there is no need to unset the running flag because we unregister, anyway
|
|
||||||
if(!Interface().DoesDialOnDemand())
|
if(!Interface().DoesDialOnDemand())
|
||||||
Interface().UnregisterInterface();
|
Interface().UnregisterInterface();
|
||||||
|
|
||||||
|
if(Interface().Ifnet()) {
|
||||||
|
Interface().Ifnet()->if_flags &= ~IFF_RUNNING;
|
||||||
|
|
||||||
|
if(!Interface().DoesDialOnDemand())
|
||||||
|
Interface().Ifnet()->if_flags &= ~IFF_UP;
|
||||||
|
}
|
||||||
|
|
||||||
if(Interface().Parent())
|
if(Interface().Parent())
|
||||||
Interface().Parent()->StateMachine().DownEvent(Interface());
|
Interface().Parent()->StateMachine().DownEvent(Interface());
|
||||||
}
|
}
|
||||||
@@ -97,8 +101,8 @@ PPPStateMachine::NewPhase(ppp_phase next)
|
|||||||
fPhase = next;
|
fPhase = next;
|
||||||
|
|
||||||
if(Phase() == PPP_ESTABLISHED_PHASE) {
|
if(Phase() == PPP_ESTABLISHED_PHASE) {
|
||||||
if(Interface().Ifnet() && !Interface().DoesDialOnDemand())
|
if(Interface().Ifnet())
|
||||||
Interface().Ifnet()->if_flags |= IFF_RUNNING;
|
Interface().Ifnet()->if_flags |= IFF_UP | IFF_RUNNING;
|
||||||
|
|
||||||
Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_UP_SUCCESSFUL, NULL, 0);
|
Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_UP_SUCCESSFUL, NULL, 0);
|
||||||
}
|
}
|
||||||
@@ -419,6 +423,11 @@ PPPStateMachine::UpFailedEvent()
|
|||||||
|
|
||||||
if(Interface().Parent())
|
if(Interface().Parent())
|
||||||
Interface().Parent()->StateMachine().UpFailedEvent(Interface());
|
Interface().Parent()->StateMachine().UpFailedEvent(Interface());
|
||||||
|
|
||||||
|
NewPhase(PPP_DOWN_PHASE);
|
||||||
|
// tell DownEvent() that we do not need to redial
|
||||||
|
|
||||||
|
DownEvent();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -525,6 +534,7 @@ PPPStateMachine::DownEvent()
|
|||||||
IllegalEvent(PPP_DOWN_EVENT);
|
IllegalEvent(PPP_DOWN_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ppp_phase oldPhase = Phase();
|
||||||
NewPhase(PPP_DOWN_PHASE);
|
NewPhase(PPP_DOWN_PHASE);
|
||||||
|
|
||||||
DownProtocols();
|
DownProtocols();
|
||||||
@@ -536,6 +546,7 @@ PPPStateMachine::DownEvent()
|
|||||||
if(State() == PPP_STARTING_STATE) {
|
if(State() == PPP_STARTING_STATE) {
|
||||||
bool needsRedial = false;
|
bool needsRedial = false;
|
||||||
|
|
||||||
|
// we do not try to redial if authentication failed
|
||||||
if(fLocalAuthenticationStatus == PPP_AUTHENTICATION_FAILED
|
if(fLocalAuthenticationStatus == PPP_AUTHENTICATION_FAILED
|
||||||
|| fLocalAuthenticationStatus == PPP_AUTHENTICATING)
|
|| fLocalAuthenticationStatus == PPP_AUTHENTICATING)
|
||||||
Interface().Report(PPP_CONNECTION_REPORT,
|
Interface().Report(PPP_CONNECTION_REPORT,
|
||||||
@@ -550,6 +561,8 @@ PPPStateMachine::DownEvent()
|
|||||||
if(Interface().fUpThread == -1)
|
if(Interface().fUpThread == -1)
|
||||||
needsRedial = true;
|
needsRedial = true;
|
||||||
|
|
||||||
|
// test if UpFailedEvent() was not called
|
||||||
|
if(oldPhase != PPP_DOWN_PHASE)
|
||||||
Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_CONNECTION_LOST,
|
Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_CONNECTION_LOST,
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
}
|
}
|
||||||
@@ -587,8 +600,10 @@ PPPStateMachine::OpenEvent()
|
|||||||
if(Interface().Mode() == PPP_SERVER_MODE) {
|
if(Interface().Mode() == PPP_SERVER_MODE) {
|
||||||
NewPhase(PPP_ESTABLISHMENT_PHASE);
|
NewPhase(PPP_ESTABLISHMENT_PHASE);
|
||||||
|
|
||||||
if(Interface().Device())
|
if(Interface().Device() && !Interface().Device()->Up()) {
|
||||||
Interface().Device()->Listen();
|
Interface().Device()->UpFailedEvent();
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
NewState(PPP_STARTING_STATE);
|
NewState(PPP_STARTING_STATE);
|
||||||
|
|
||||||
@@ -1452,8 +1467,8 @@ PPPStateMachine::ThisLayerDown()
|
|||||||
void
|
void
|
||||||
PPPStateMachine::ThisLayerStarted()
|
PPPStateMachine::ThisLayerStarted()
|
||||||
{
|
{
|
||||||
if(Interface().Device())
|
if(Interface().Device() && !Interface().Device()->Up())
|
||||||
Interface().Device()->Up();
|
Interface().Device()->UpFailedEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ struct mbuf;
|
|||||||
typedef struct ppp_configure_item {
|
typedef struct ppp_configure_item {
|
||||||
uint8 type;
|
uint8 type;
|
||||||
uint8 length;
|
uint8 length;
|
||||||
int8 data[0];
|
uint8 data[0];
|
||||||
// the data follows this structure
|
// the data follows this structure
|
||||||
} ppp_configure_item;
|
} ppp_configure_item;
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
#include <PPPDefs.h>
|
#include <PPPDefs.h>
|
||||||
|
|
||||||
|
|
||||||
typedef uint32 interface_id;
|
|
||||||
|
|
||||||
// various constants
|
// various constants
|
||||||
#define PPP_PULSE_RATE 500000
|
#define PPP_PULSE_RATE 500000
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
|
|
||||||
class PPPDevice : public PPPLayer {
|
class PPPDevice : public PPPLayer {
|
||||||
|
friend class PPPStateMachine;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// PPPDevice must be subclassed
|
// PPPDevice must be subclassed
|
||||||
PPPDevice(const char *name, PPPInterface& interface,
|
PPPDevice(const char *name, PPPInterface& interface,
|
||||||
@@ -35,12 +37,18 @@ class PPPDevice : public PPPLayer {
|
|||||||
uint32 MTU() const
|
uint32 MTU() const
|
||||||
{ return fMTU; }
|
{ return fMTU; }
|
||||||
|
|
||||||
// these calls must not block
|
|
||||||
virtual bool Up() = 0;
|
virtual bool Up() = 0;
|
||||||
|
// In server mode you should listen for incoming connections.
|
||||||
|
// On error: either call UpFailedEvent() or return false.
|
||||||
virtual bool Down() = 0;
|
virtual bool Down() = 0;
|
||||||
virtual bool Listen() = 0;
|
|
||||||
bool IsUp() const
|
bool IsUp() const
|
||||||
{ return fIsUp; }
|
{ return fConnectionPhase == PPP_ESTABLISHED_PHASE; }
|
||||||
|
bool IsDown() const
|
||||||
|
{ return fConnectionPhase == PPP_DOWN_PHASE; }
|
||||||
|
bool IsGoingUp() const
|
||||||
|
{ return fConnectionPhase == PPP_ESTABLISHMENT_PHASE; }
|
||||||
|
bool IsGoingDown() const
|
||||||
|
{ return fConnectionPhase == PPP_TERMINATION_PHASE; }
|
||||||
|
|
||||||
// The biggest of the two tranfer rates will be set in ifnet.
|
// The biggest of the two tranfer rates will be set in ifnet.
|
||||||
// These methods should return default values when disconnected.
|
// These methods should return default values when disconnected.
|
||||||
@@ -68,8 +76,8 @@ class PPPDevice : public PPPLayer {
|
|||||||
// Report that we are going up/down
|
// Report that we are going up/down
|
||||||
// (from now on, the Up() process can be aborted).
|
// (from now on, the Up() process can be aborted).
|
||||||
// Abort if false is returned!
|
// Abort if false is returned!
|
||||||
bool UpStarted() const;
|
bool UpStarted();
|
||||||
bool DownStarted() const;
|
bool DownStarted();
|
||||||
|
|
||||||
// report up/down events
|
// report up/down events
|
||||||
void UpFailedEvent();
|
void UpFailedEvent();
|
||||||
@@ -85,7 +93,7 @@ class PPPDevice : public PPPLayer {
|
|||||||
PPPInterface& fInterface;
|
PPPInterface& fInterface;
|
||||||
driver_parameter *fSettings;
|
driver_parameter *fSettings;
|
||||||
|
|
||||||
bool fIsUp;
|
ppp_phase fConnectionPhase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class PPPInterface : public PPPLayer {
|
|||||||
PPPInterface& operator= (const PPPInterface& copy);
|
PPPInterface& operator= (const PPPInterface& copy);
|
||||||
|
|
||||||
// only PPPManager may construct us!
|
// only PPPManager may construct us!
|
||||||
PPPInterface(interface_id ID, driver_settings *settings,
|
PPPInterface(interface_id ID, const driver_settings *settings,
|
||||||
PPPInterface *parent = NULL);
|
PPPInterface *parent = NULL);
|
||||||
~PPPInterface();
|
~PPPInterface();
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ class PPPInterface : public PPPLayer {
|
|||||||
PPPReportManager& ReportManager()
|
PPPReportManager& ReportManager()
|
||||||
{ return fReportManager; }
|
{ return fReportManager; }
|
||||||
bool Report(ppp_report_type type, int32 code, void *data, int32 length)
|
bool Report(ppp_report_type type, int32 code, void *data, int32 length)
|
||||||
{ return fReportManager.Report(type, code, data, length); }
|
{ return ReportManager().Report(type, code, data, length); }
|
||||||
// returns false if reply was bad (or an error occured)
|
// returns false if reply was bad (or an error occured)
|
||||||
|
|
||||||
bool LoadModules(driver_settings *settings,
|
bool LoadModules(driver_settings *settings,
|
||||||
@@ -168,9 +168,7 @@ class PPPInterface : public PPPLayer {
|
|||||||
virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber);
|
virtual status_t Receive(struct mbuf *packet, uint16 protocolNumber);
|
||||||
|
|
||||||
status_t ReceiveFromDevice(struct mbuf *packet);
|
status_t ReceiveFromDevice(struct mbuf *packet);
|
||||||
// This is called by the receive-thread.
|
// This must not block PPPDevice::Send()!
|
||||||
// Only call this if it does not block Send() or
|
|
||||||
// SendToDevice()!
|
|
||||||
|
|
||||||
void Pulse();
|
void Pulse();
|
||||||
// this manages all timeouts, etc.
|
// this manages all timeouts, etc.
|
||||||
@@ -199,9 +197,6 @@ class PPPInterface : public PPPLayer {
|
|||||||
interface_id fID;
|
interface_id fID;
|
||||||
// the manager assigns an ID to every interface
|
// the manager assigns an ID to every interface
|
||||||
driver_settings *fSettings;
|
driver_settings *fSettings;
|
||||||
PPPStateMachine fStateMachine;
|
|
||||||
PPPLCP fLCP;
|
|
||||||
PPPReportManager fReportManager;
|
|
||||||
struct ifnet *fIfnet;
|
struct ifnet *fIfnet;
|
||||||
|
|
||||||
thread_id fUpThread;
|
thread_id fUpThread;
|
||||||
@@ -229,6 +224,9 @@ class PPPInterface : public PPPLayer {
|
|||||||
PPPProtocol *fFirstProtocol;
|
PPPProtocol *fFirstProtocol;
|
||||||
List<char*> fModules;
|
List<char*> fModules;
|
||||||
|
|
||||||
|
PPPStateMachine fStateMachine;
|
||||||
|
PPPLCP fLCP;
|
||||||
|
PPPReportManager fReportManager;
|
||||||
BLocker& fLock;
|
BLocker& fLock;
|
||||||
int32 fDeleteCounter;
|
int32 fDeleteCounter;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#define _K_PPP_MANAGER__H
|
#define _K_PPP_MANAGER__H
|
||||||
|
|
||||||
#include "net_module.h"
|
#include "net_module.h"
|
||||||
|
#include <PPPControl.h>
|
||||||
|
#include <PPPReportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
#define PPP_INTERFACE_MODULE_NAME "network/interfaces/ppp"
|
#define PPP_INTERFACE_MODULE_NAME "network/interfaces/ppp"
|
||||||
@@ -16,18 +18,12 @@
|
|||||||
#define PPP_UNDEFINED_INTERFACE_ID 0
|
#define PPP_UNDEFINED_INTERFACE_ID 0
|
||||||
// create_interface() returns this value on failure
|
// create_interface() returns this value on failure
|
||||||
|
|
||||||
// this allows you to ask for specific interface_ids
|
|
||||||
enum ppp_interface_filter {
|
|
||||||
PPP_ALL_INTERFACES,
|
|
||||||
PPP_REGISTERED_INTERFACES,
|
|
||||||
PPP_UNREGISTERED_INTERFACES
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct ppp_interface_module_info {
|
typedef struct ppp_interface_module_info {
|
||||||
kernel_net_module_info knminfo;
|
kernel_net_module_info knminfo;
|
||||||
|
|
||||||
interface_id (*CreateInterface)(const driver_settings *settings,
|
interface_id (*CreateInterface)(const driver_settings *settings,
|
||||||
interface_id parent);
|
interface_id parentID = PPP_UNDEFINED_INTERFACE_ID);
|
||||||
// you should always create interfaces using this function
|
// you should always create interfaces using this function
|
||||||
void (*DeleteInterface)(interface_id ID);
|
void (*DeleteInterface)(interface_id ID);
|
||||||
// this marks the interface for deletion
|
// this marks the interface for deletion
|
||||||
@@ -37,12 +33,18 @@ typedef struct ppp_interface_module_info {
|
|||||||
ifnet *(*RegisterInterface)(interface_id ID);
|
ifnet *(*RegisterInterface)(interface_id ID);
|
||||||
bool (*UnregisterInterface)(interface_id ID);
|
bool (*UnregisterInterface)(interface_id ID);
|
||||||
|
|
||||||
status_t (*Control)(interface_id ID, uint32 op, void *data, size_t length);
|
status_t (*ControlInterface)(interface_id ID, uint32 op, void *data,
|
||||||
|
size_t length);
|
||||||
|
|
||||||
int32 (*GetInterfaces)(interface_id *interfaces, int32 count,
|
int32 (*GetInterfaces)(interface_id *interfaces, int32 count,
|
||||||
ppp_interface_filter filter = PPP_REGISTERED_INTERFACES);
|
ppp_interface_filter filter = PPP_REGISTERED_INTERFACES);
|
||||||
// make sure interfaces has enough space for count items
|
// make sure interfaces has enough space for count items
|
||||||
int32 (*CountInterfaces)();
|
int32 (*CountInterfaces)(ppp_interface_filter filter = PPP_REGISTERED_INTERFACES);
|
||||||
|
|
||||||
|
void (*EnableReports)(ppp_report_type type, thread_id thread,
|
||||||
|
int32 flags = PPP_NO_FLAGS);
|
||||||
|
void (*DisableReports)(ppp_report_type type, thread_id thread);
|
||||||
|
bool (*DoesReport)(ppp_report_type type, thread_id thread);
|
||||||
} ppp_interface_module_info;
|
} ppp_interface_module_info;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class PPPInterface;
|
|||||||
typedef struct ppp_module_info {
|
typedef struct ppp_module_info {
|
||||||
module_info minfo;
|
module_info minfo;
|
||||||
status_t (*control)(uint32 op, void *data, size_t length);
|
status_t (*control)(uint32 op, void *data, size_t length);
|
||||||
status_t (*add_to)(PPPInterface& mainInterface, PPPInterface *subInterface,
|
bool (*add_to)(PPPInterface& mainInterface, PPPInterface *subInterface,
|
||||||
driver_parameter *settings, ppp_module_key_type type);
|
driver_parameter *settings, ppp_module_key_type type);
|
||||||
// multilink: handlers that must run on a real device
|
// multilink: handlers that must run on a real device
|
||||||
// should be added to subInterface (may be NULL)
|
// should be added to subInterface (may be NULL)
|
||||||
|
|||||||
@@ -108,7 +108,6 @@ class PPPProtocol : public PPPLayer {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ppp_phase fActivationPhase;
|
ppp_phase fActivationPhase;
|
||||||
ppp_level fLevel;
|
|
||||||
uint16 fProtocolNumber;
|
uint16 fProtocolNumber;
|
||||||
int32 fAddressFamily;
|
int32 fAddressFamily;
|
||||||
PPPInterface& fInterface;
|
PPPInterface& fInterface;
|
||||||
|
|||||||
@@ -91,9 +91,6 @@ class PPPStateMachine {
|
|||||||
void DownEvent();
|
void DownEvent();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BLocker& Locker()
|
|
||||||
{ return fLock; }
|
|
||||||
|
|
||||||
// private StateMachine methods
|
// private StateMachine methods
|
||||||
void NewState(ppp_state next);
|
void NewState(ppp_state next);
|
||||||
void NewPhase(ppp_phase next);
|
void NewPhase(ppp_phase next);
|
||||||
|
|||||||
@@ -28,7 +28,10 @@
|
|||||||
#ifndef LIST_H
|
#ifndef LIST_H
|
||||||
#define LIST_H
|
#define LIST_H
|
||||||
|
|
||||||
|
#ifdef _KERNEL_MODE
|
||||||
#include <kernel_cpp.h>
|
#include <kernel_cpp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#define _PPP_CONTROL__H
|
#define _PPP_CONTROL__H
|
||||||
|
|
||||||
#include <Drivers.h>
|
#include <Drivers.h>
|
||||||
|
#include <driver_settings.h>
|
||||||
#include <PPPDefs.h>
|
#include <PPPDefs.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +30,17 @@
|
|||||||
|
|
||||||
|
|
||||||
enum ppp_control_ops {
|
enum ppp_control_ops {
|
||||||
|
// -----------------------------------------------------
|
||||||
|
// PPPManager
|
||||||
|
PPPC_CREATE_INTERFACE = PPP_OPS_START,
|
||||||
|
PPPC_DELETE_INTERFACE,
|
||||||
|
PPPC_BRING_INTERFACE_UP,
|
||||||
|
PPPC_BRING_INTERFACE_DOWN,
|
||||||
|
PPPC_CONTROL_INTERFACE,
|
||||||
|
PPPC_GET_INTERFACES,
|
||||||
|
PPPC_COUNT_INTERFACES,
|
||||||
|
// -----------------------------------------------------
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// PPPInterface
|
// PPPInterface
|
||||||
PPPC_GET_INTERFACE_INFO = PPP_INTERFACE_OPS_START,
|
PPPC_GET_INTERFACE_INFO = PPP_INTERFACE_OPS_START,
|
||||||
@@ -36,11 +48,6 @@ enum ppp_control_ops {
|
|||||||
PPPC_SET_DIAL_ON_DEMAND,
|
PPPC_SET_DIAL_ON_DEMAND,
|
||||||
PPPC_SET_AUTO_REDIAL,
|
PPPC_SET_AUTO_REDIAL,
|
||||||
|
|
||||||
// these control ops use the ppp_report_request structure
|
|
||||||
PPPC_ENABLE_INTERFACE_REPORTS,
|
|
||||||
PPPC_DISABLE_INTERFACE_REPORTS,
|
|
||||||
// flags are not used for this control op
|
|
||||||
|
|
||||||
// handler access
|
// handler access
|
||||||
PPPC_CONTROL_DEVICE,
|
PPPC_CONTROL_DEVICE,
|
||||||
PPPC_CONTROL_PROTOCOL,
|
PPPC_CONTROL_PROTOCOL,
|
||||||
@@ -64,15 +71,35 @@ enum ppp_control_ops {
|
|||||||
PPPC_ENABLE,
|
PPPC_ENABLE,
|
||||||
PPPC_GET_SIMPLE_HANDLER_INFO,
|
PPPC_GET_SIMPLE_HANDLER_INFO,
|
||||||
// PPPOptionHandler and PPPLCPExtension
|
// PPPOptionHandler and PPPLCPExtension
|
||||||
|
|
||||||
|
// these two control ops use the ppp_report_request structure
|
||||||
|
PPPC_ENABLE_REPORTS,
|
||||||
|
PPPC_DISABLE_REPORTS,
|
||||||
|
// flags are not used for this control op
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
|
||||||
PPP_CONTROL_OPS_END = B_DEVICE_OP_CODES_END + 0xFFFF
|
PPP_CONTROL_OPS_END = B_DEVICE_OP_CODES_END + 0xFFFF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct ppp_interface_settings_info {
|
||||||
|
const driver_settings *settings;
|
||||||
|
interface_id interface;
|
||||||
|
// only when creating: this is the id of the created interface
|
||||||
|
} ppp_interface_settings_info;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct ppp_get_interfaces_info {
|
||||||
|
interface_id *interfaces;
|
||||||
|
int32 count;
|
||||||
|
ppp_interface_filter filter;
|
||||||
|
int32 resultCount;
|
||||||
|
} ppp_get_interfaces_info;
|
||||||
|
|
||||||
|
|
||||||
typedef struct ppp_control_info {
|
typedef struct ppp_control_info {
|
||||||
uint32 index;
|
uint32 index;
|
||||||
// index of interface/protocol/etc.
|
// index/id of interface/protocol/etc.
|
||||||
uint32 op;
|
uint32 op;
|
||||||
// the Control()/ioctl() opcode
|
// the Control()/ioctl() opcode
|
||||||
void *data;
|
void *data;
|
||||||
@@ -91,6 +118,9 @@ typedef struct ppp_control_info {
|
|||||||
typedef struct ppp_interface_info {
|
typedef struct ppp_interface_info {
|
||||||
const driver_settings *settings;
|
const driver_settings *settings;
|
||||||
|
|
||||||
|
int32 if_unit;
|
||||||
|
// negative if not registered
|
||||||
|
|
||||||
ppp_mode mode;
|
ppp_mode mode;
|
||||||
ppp_state state;
|
ppp_state state;
|
||||||
ppp_phase phase;
|
ppp_phase phase;
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef uint32 interface_id;
|
||||||
|
|
||||||
|
|
||||||
// settings keys
|
// settings keys
|
||||||
#define PPP_DISONNECT_AFTER_IDLE_SINCE_KEY "DisonnectAfterIdleSince"
|
#define PPP_DISONNECT_AFTER_IDLE_SINCE_KEY "DisonnectAfterIdleSince"
|
||||||
#define PPP_MODE_KEY "Mode"
|
#define PPP_MODE_KEY "Mode"
|
||||||
@@ -35,6 +38,14 @@
|
|||||||
|
|
||||||
#define PPP_ERROR_BASE B_ERRORS_END + 1
|
#define PPP_ERROR_BASE B_ERRORS_END + 1
|
||||||
|
|
||||||
|
|
||||||
|
// this is used when talking to the interface manager
|
||||||
|
enum ppp_interface_filter {
|
||||||
|
PPP_ALL_INTERFACES,
|
||||||
|
PPP_REGISTERED_INTERFACES,
|
||||||
|
PPP_UNREGISTERED_INTERFACES
|
||||||
|
};
|
||||||
|
|
||||||
// return values for Send()/Receive() methods in addition to B_ERROR and B_OK
|
// return values for Send()/Receive() methods in addition to B_ERROR and B_OK
|
||||||
// PPP_UNHANDLED is also used by PPPOptionHandler
|
// PPP_UNHANDLED is also used by PPPOptionHandler
|
||||||
enum {
|
enum {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#ifndef _PPP_REPORT_DEFS__H
|
#ifndef _PPP_REPORT_DEFS__H
|
||||||
#define _PPP_REPORT_DEFS__H
|
#define _PPP_REPORT_DEFS__H
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
|
|
||||||
#define PPP_REPORT_TIMEOUT 10
|
#define PPP_REPORT_TIMEOUT 10
|
||||||
|
|
||||||
@@ -28,13 +30,21 @@ enum ppp_report_flags {
|
|||||||
enum ppp_report_type {
|
enum ppp_report_type {
|
||||||
PPP_ALL_REPORTS = -1,
|
PPP_ALL_REPORTS = -1,
|
||||||
// used only when disabling reports
|
// used only when disabling reports
|
||||||
|
PPP_MANAGER_REPORT = 1,
|
||||||
PPP_DESTRUCTION_REPORT = 16,
|
PPP_DESTRUCTION_REPORT = 16,
|
||||||
// the interface is being destroyed (no code is needed)
|
// the interface is being destroyed (no code is needed)
|
||||||
// this report is sent even if it was not requested
|
// this report is sent even if it was not requested
|
||||||
PPP_CONNECTION_REPORT = 17
|
PPP_CONNECTION_REPORT = 17
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// report codes (type-specific)
|
// report codes (type-specific)
|
||||||
|
enum ppp_manager_report_codes {
|
||||||
|
// the interface id is added to the following reports
|
||||||
|
PPP_REPORT_INTERFACE_CREATED = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
enum ppp_connection_report_codes {
|
enum ppp_connection_report_codes {
|
||||||
PPP_REPORT_GOING_UP = 0,
|
PPP_REPORT_GOING_UP = 0,
|
||||||
PPP_REPORT_UP_SUCCESSFUL = 1,
|
PPP_REPORT_UP_SUCCESSFUL = 1,
|
||||||
|
|||||||
@@ -27,10 +27,15 @@ dup_driver_settings(const driver_settings *dup)
|
|||||||
driver_settings *ret = (driver_settings*) malloc(sizeof(driver_settings));
|
driver_settings *ret = (driver_settings*) malloc(sizeof(driver_settings));
|
||||||
|
|
||||||
ret->parameter_count = dup->parameter_count;
|
ret->parameter_count = dup->parameter_count;
|
||||||
ret->parameters = (driver_parameter*) malloc(ret->parameter_count * sizeof(driver_parameter));
|
|
||||||
|
|
||||||
for(int32 i=0; i < ret->parameter_count; i++)
|
if(ret->parameter_count > 0)
|
||||||
copy_parameter(&dup->parameters[i], &ret->parameters[i]);
|
ret->parameters =
|
||||||
|
(driver_parameter*) malloc(ret->parameter_count * sizeof(driver_parameter));
|
||||||
|
else
|
||||||
|
ret->parameters = NULL;
|
||||||
|
|
||||||
|
for(int32 index = 0; index < ret->parameter_count; index++)
|
||||||
|
copy_parameter(&dup->parameters[index], &ret->parameters[index]);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -43,48 +48,111 @@ copy_parameter(const driver_parameter *from, driver_parameter *to)
|
|||||||
to->name = strdup(from->name);
|
to->name = strdup(from->name);
|
||||||
to->value_count = from->value_count;
|
to->value_count = from->value_count;
|
||||||
|
|
||||||
|
if(to->value_count > 0)
|
||||||
to->values = (char**) malloc(to->value_count * sizeof(char*));
|
to->values = (char**) malloc(to->value_count * sizeof(char*));
|
||||||
|
else
|
||||||
|
to->values = NULL;
|
||||||
|
|
||||||
for(int32 i=0; i < to->value_count; i++)
|
for(int32 index = 0; index < to->value_count; index++)
|
||||||
to->values[i] = strdup(from->values[i]);
|
to->values[index] = strdup(from->values[index]);
|
||||||
|
|
||||||
to->parameter_count = from->parameter_count;
|
to->parameter_count = from->parameter_count;
|
||||||
|
|
||||||
to->parameters = (driver_parameter*) malloc(to->parameter_count * sizeof(driver_parameter));
|
if(to->parameter_count > 0)
|
||||||
|
to->parameters =
|
||||||
|
(driver_parameter*) malloc(to->parameter_count * sizeof(driver_parameter));
|
||||||
|
else
|
||||||
|
to->parameters = NULL;
|
||||||
|
|
||||||
for(int32 i=0; i < to->parameter_count; i++)
|
for(int32 index = 0; index < to->parameter_count; index++)
|
||||||
copy_parameter(&from->parameters[i], &to->parameters[i]);
|
copy_parameter(&from->parameters[index], &to->parameters[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
free_driver_settings(driver_settings *settings)
|
free_driver_settings(driver_settings *settings)
|
||||||
{
|
{
|
||||||
for(int32 i=0; i < settings->parameter_count; i++)
|
if(!settings)
|
||||||
free_driver_parameter(&settings->parameters[i]);
|
return;
|
||||||
|
|
||||||
|
for(int32 index = 0; index < settings->parameter_count; index++)
|
||||||
|
free_driver_parameter(&settings->parameters[index]);
|
||||||
|
|
||||||
free(settings->parameters);
|
free(settings->parameters);
|
||||||
free(settings);
|
free(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
void
|
void
|
||||||
free_driver_parameter(driver_parameter *p)
|
free_driver_parameter(driver_parameter *p)
|
||||||
{
|
{
|
||||||
free(p->name);
|
free(p->name);
|
||||||
|
|
||||||
for(int32 i=0; i < p->value_count; i++)
|
for(int32 index = 0; index < p->value_count; index++)
|
||||||
free(p->values[i]);
|
free(p->values[index]);
|
||||||
|
|
||||||
free(p->values);
|
free(p->values);
|
||||||
|
|
||||||
for(int32 i=0; i < p->parameter_count; i++)
|
for(int32 index = 0; index < p->parameter_count; index++)
|
||||||
free_driver_parameter(&p->parameters[i]);
|
free_driver_parameter(&p->parameters[index]);
|
||||||
|
|
||||||
free(p->parameters);
|
free(p->parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs)
|
||||||
|
{
|
||||||
|
if(!lhs && !rhs)
|
||||||
|
return true;
|
||||||
|
else if(!lhs || !rhs)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
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]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs)
|
||||||
|
{
|
||||||
|
if(!lhs && !rhs)
|
||||||
|
return true;
|
||||||
|
else if(!lhs || !rhs)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(lhs->name && rhs->name) {
|
||||||
|
if(strcmp(lhs->name, rhs->name))
|
||||||
|
return false;
|
||||||
|
} else if(lhs->name != rhs->name)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
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]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int32 index = 0; index < lhs->parameter_count; index++) {
|
||||||
|
if(!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ppp_side
|
ppp_side
|
||||||
get_side_string_value(const char *sideString, ppp_side unknownValue)
|
get_side_string_value(const char *sideString, ppp_side unknownValue)
|
||||||
{
|
{
|
||||||
@@ -139,10 +207,11 @@ get_settings_value(const char *name, const driver_settings *settings)
|
|||||||
if(!name || !settings)
|
if(!name || !settings)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for(int32 i=0; i < settings->parameter_count; i++)
|
for(int32 index = 0; index < settings->parameter_count; index++)
|
||||||
if(!strcasecmp(settings->parameters[i].name, name)
|
if(!strcasecmp(settings->parameters[index].name, name)
|
||||||
&& settings->parameters[i].value_count > 0)
|
&& settings->parameters[index].value_count > 0
|
||||||
return settings->parameters[i].values[0];
|
&& settings->parameters[index].values)
|
||||||
|
return settings->parameters[index].values[0];
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,16 @@
|
|||||||
#ifndef _SETTINGS_TOOLS__H
|
#ifndef _SETTINGS_TOOLS__H
|
||||||
#define _SETTINGS_TOOLS__H
|
#define _SETTINGS_TOOLS__H
|
||||||
|
|
||||||
// remove this as soon as we get the extended driver_settings API
|
#include <driver_settings.h>
|
||||||
|
|
||||||
struct driver_settings;
|
|
||||||
struct driver_parameter;
|
|
||||||
|
|
||||||
|
// TODO: remove this as soon as we get the extended driver_settings API
|
||||||
|
|
||||||
driver_settings *dup_driver_settings(const driver_settings *settings);
|
driver_settings *dup_driver_settings(const driver_settings *settings);
|
||||||
void free_driver_settings(driver_settings *settings);
|
void free_driver_settings(driver_settings *settings);
|
||||||
|
|
||||||
|
bool equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs);
|
||||||
|
bool equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs);
|
||||||
|
|
||||||
ppp_side get_side_string_value(const char *sideString, ppp_side unknownValue);
|
ppp_side get_side_string_value(const char *sideString, ppp_side unknownValue);
|
||||||
bool get_boolean_value(const char *string, bool unknownValue);
|
bool get_boolean_value(const char *string, bool unknownValue);
|
||||||
@@ -27,7 +28,8 @@ inline
|
|||||||
const char*
|
const char*
|
||||||
get_parameter_value(const char *name, const driver_parameter *parameters)
|
get_parameter_value(const char *name, const driver_parameter *parameters)
|
||||||
{
|
{
|
||||||
return get_settings_value(name, (driver_settings*) ¶meters->parameter_count);
|
return get_settings_value(name,
|
||||||
|
parameters ? (driver_settings*) ¶meters->parameter_count : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user