Initial commit of very skeletal ppp interface module.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5030 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b80f17599b
commit
d6a3da1874
@ -1 +1,20 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network interfaces ppp ;
|
||||
|
||||
# for kernel_cpp.cpp/h and BLocker
|
||||
SEARCH_SOURCE += [ FDirName $(OBOS_TOP) src kernel core util ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(OBOS_TOP) src kernel core disk_device_manager ] ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
UsePrivateHeaders [ FDirName kernel ] ;
|
||||
UsePrivateHeaders [ FDirName kernel util ] ;
|
||||
UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkernelppp headers ] ;
|
||||
|
||||
|
||||
R5KernelAddon ppp : kernel network interfaces :
|
||||
kernel_cpp.cpp
|
||||
|
||||
ppp.cpp
|
||||
PPPManager.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs ppp : libkernelppp.a ;
|
||||
|
139
src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp
Normal file
139
src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
// Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
#include "PPPManager.h"
|
||||
|
||||
#include <kernel_cpp.h>
|
||||
#include <LockerHelper.h>
|
||||
|
||||
|
||||
PPPManager::PPPManager()
|
||||
: fReportManager(fLock),
|
||||
fNextID(1)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PPPManager::~PPPManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
interface_id
|
||||
PPPManager::CreateInterface(const driver_settings *settings, interface_id parentID)
|
||||
{
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
interface_entry *parentEntry = EntryFor(parentID);
|
||||
if(parentID != PPP_UNDEFINED_INTERFACE_ID && !parentEntry)
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
|
||||
interface_id id = NextID();
|
||||
interface_entry *entry = new interface_entry;
|
||||
entry->accessing = 0;
|
||||
entry->deleting = false;
|
||||
entry->interface = new PPPInterface(id, settings,
|
||||
parentEntry ? parentEntry->interface : NULL);
|
||||
|
||||
if(entry->interface->InitCheck() != B_OK) {
|
||||
delete entry->interface;
|
||||
delete entry;
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
}
|
||||
|
||||
fEntries.AddItem(entry);
|
||||
locker.UnlockNow();
|
||||
|
||||
if(!entry->interface->DoesDialOnDemand())
|
||||
entry->interface->Up();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPManager::DeleteInterface(interface_id ID)
|
||||
{
|
||||
// This only marks the interface for deletion.
|
||||
// Our deleter_thread does the real work.
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
interface_entry *entry = EntryFor(ID);
|
||||
if(entry)
|
||||
entry->deleting = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPManager::RemoveInterface(interface_id ID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
ifnet*
|
||||
PPPManager::RegisterInterface(interface_id ID)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPManager::UnregisterInterface(interface_id ID)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PPPManager::Control(uint32 op, void *data, size_t length)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PPPManager::ControlInterface(interface_id ID, uint32 op, void *data, size_t length)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
PPPManager::GetInterfaces(interface_id *interfaces, int32 count,
|
||||
ppp_interface_filter filter = PPP_REGISTERED_INTERFACES)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
PPPManager::CountInterfaces(ppp_interface_filter filter = PPP_REGISTERED_INTERFACES)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
interface_entry*
|
||||
PPPManager::EntryFor(interface_id ID, int32 *start = NULL) const
|
||||
{
|
||||
if(ID == PPP_UNDEFINED_INTERFACE_ID)
|
||||
return NULL;
|
||||
|
||||
interface_entry *entry;
|
||||
|
||||
for(int32 index = start ? *start : 0; index < fEntries.CountItems(); index++) {
|
||||
entry = fEntries.ItemAt(index);
|
||||
if(entry && entry->interface->ID() == ID) {
|
||||
if(start)
|
||||
*start = index;
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
62
src/add-ons/kernel/network/interfaces/ppp/PPPManager.h
Normal file
62
src/add-ons/kernel/network/interfaces/ppp/PPPManager.h
Normal file
@ -0,0 +1,62 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
// Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
#ifndef _PPP_MANAGER__H
|
||||
#define _PPP_MANAGER__H
|
||||
|
||||
#include <KPPPInterface.h>
|
||||
#include <KPPPManager.h>
|
||||
|
||||
|
||||
typedef struct interface_entry {
|
||||
PPPInterface *interface;
|
||||
vint32 accessing;
|
||||
bool deleting;
|
||||
} interface_entry;
|
||||
|
||||
|
||||
class PPPManager {
|
||||
public:
|
||||
PPPManager();
|
||||
~PPPManager();
|
||||
|
||||
interface_id CreateInterface(const driver_settings *settings,
|
||||
interface_id parentID);
|
||||
void DeleteInterface(interface_id ID);
|
||||
void RemoveInterface(interface_id ID);
|
||||
|
||||
ifnet *RegisterInterface(interface_id ID);
|
||||
bool UnregisterInterface(interface_id ID);
|
||||
|
||||
status_t Control(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,
|
||||
ppp_interface_filter filter = PPP_REGISTERED_INTERFACES);
|
||||
int32 CountInterfaces(ppp_interface_filter filter = PPP_REGISTERED_INTERFACES);
|
||||
|
||||
PPPReportManager& ReportManager()
|
||||
{ return fReportManager; }
|
||||
bool Report(ppp_report_type type, int32 code, void *data, int32 length)
|
||||
{ return ReportManager().Report(type, code, data, length); }
|
||||
// returns false if reply was bad (or an error occured)
|
||||
|
||||
interface_entry *EntryFor(interface_id ID, int32 *start = NULL) const;
|
||||
|
||||
interface_id NextID()
|
||||
{ return (interface_id) atomic_add((vint32*) &fNextID, 1); }
|
||||
|
||||
private:
|
||||
BLocker fLock;
|
||||
PPPReportManager fReportManager;
|
||||
List<interface_entry*> fEntries;
|
||||
interface_id fNextID;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
226
src/add-ons/kernel/network/interfaces/ppp/ppp.cpp
Normal file
226
src/add-ons/kernel/network/interfaces/ppp/ppp.cpp
Normal file
@ -0,0 +1,226 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
// Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
#include <core_funcs.h>
|
||||
#include <KernelExport.h>
|
||||
#include <driver_settings.h>
|
||||
|
||||
#include <kernel_cpp.h>
|
||||
|
||||
#include <KPPPDefs.h>
|
||||
#include "PPPManager.h"
|
||||
|
||||
|
||||
status_t std_ops(int32 op, ...);
|
||||
|
||||
struct core_module_info *core = NULL;
|
||||
static PPPManager *manager = NULL;
|
||||
|
||||
|
||||
static
|
||||
int
|
||||
ppp_start(void *cpp)
|
||||
{
|
||||
if(cpp)
|
||||
core = (core_module_info*) cpp;
|
||||
|
||||
manager = new PPPManager;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
int
|
||||
ppp_stop()
|
||||
{
|
||||
delete manager;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
// PPPManager wrappers
|
||||
static
|
||||
status_t
|
||||
ppp_control(uint32 op, void *data, size_t length)
|
||||
{
|
||||
if(manager)
|
||||
return manager->Control(op, data, length);
|
||||
else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
interface_id
|
||||
CreateInterface(const driver_settings *settings, interface_id parent)
|
||||
{
|
||||
if(manager)
|
||||
return manager->CreateInterface(settings, parent);
|
||||
else
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
DeleteInterface(interface_id ID)
|
||||
{
|
||||
if(manager)
|
||||
manager->DeleteInterface(ID);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
RemoveInterface(interface_id ID)
|
||||
{
|
||||
if(manager)
|
||||
manager->RemoveInterface(ID);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
ifnet*
|
||||
RegisterInterface(interface_id ID)
|
||||
{
|
||||
if(manager)
|
||||
return manager->RegisterInterface(ID);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
bool
|
||||
UnregisterInterface(interface_id ID)
|
||||
{
|
||||
if(manager)
|
||||
return manager->UnregisterInterface(ID);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
status_t
|
||||
ControlInterface(interface_id ID, uint32 op, void *data, size_t length)
|
||||
{
|
||||
if(manager)
|
||||
return manager->ControlInterface(ID, op, data, length);
|
||||
else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
int32
|
||||
GetInterfaces(interface_id *interfaces, int32 count,
|
||||
ppp_interface_filter filter = PPP_REGISTERED_INTERFACES)
|
||||
{
|
||||
if(manager)
|
||||
return manager->GetInterfaces(interfaces, count, filter);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
int32
|
||||
CountInterfaces(ppp_interface_filter filter = PPP_REGISTERED_INTERFACES)
|
||||
{
|
||||
if(manager)
|
||||
return manager->CountInterfaces(filter);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
EnableReports(ppp_report_type type, thread_id thread, int32 flags = PPP_NO_FLAGS)
|
||||
{
|
||||
if(manager)
|
||||
manager->ReportManager().EnableReports(type, thread, flags);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
DisableReports(ppp_report_type type, thread_id thread)
|
||||
{
|
||||
if(manager)
|
||||
manager->ReportManager().DisableReports(type, thread);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
bool
|
||||
DoesReport(ppp_report_type type, thread_id thread)
|
||||
{
|
||||
if(manager)
|
||||
return manager->ReportManager().DoesReport(type, thread);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
struct ppp_interface_module_info ppp_interface_module = {
|
||||
{
|
||||
{
|
||||
PPP_INTERFACE_MODULE_NAME,
|
||||
0,
|
||||
std_ops
|
||||
},
|
||||
ppp_start,
|
||||
ppp_stop,
|
||||
ppp_control
|
||||
},
|
||||
CreateInterface,
|
||||
DeleteInterface,
|
||||
RemoveInterface,
|
||||
RegisterInterface,
|
||||
UnregisterInterface,
|
||||
ControlInterface,
|
||||
GetInterfaces,
|
||||
CountInterfaces,
|
||||
EnableReports,
|
||||
DisableReports,
|
||||
DoesReport
|
||||
};
|
||||
|
||||
|
||||
_EXPORT
|
||||
status_t
|
||||
std_ops(int32 op, ...)
|
||||
{
|
||||
switch(op) {
|
||||
case B_MODULE_INIT:
|
||||
get_module(NET_CORE_MODULE_NAME, (module_info**)&core);
|
||||
|
||||
if(!core)
|
||||
return B_ERROR;
|
||||
return B_OK;
|
||||
|
||||
case B_MODULE_UNINIT:
|
||||
put_module(NET_CORE_MODULE_NAME);
|
||||
break;
|
||||
|
||||
default:
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
_EXPORT
|
||||
module_info *modules[] = {
|
||||
(module_info*) &ppp_interface_module,
|
||||
NULL
|
||||
};
|
Loading…
Reference in New Issue
Block a user