Added libkernelppp.a to the build (although it does not build yet, I need help to fix the problem).
Fixed all warnings and errors (except from the one mentioned above). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4437 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
SubDir OBOS_TOP src tests kits net ppp ;
|
||||||
|
|
||||||
|
SubInclude OBOS_TOP src tests kits net ppp src ;
|
||||||
@@ -28,7 +28,7 @@ class PPPConfigurePacket {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
PPPConfigurePacket(uint8 code);
|
PPPConfigurePacket(uint8 code);
|
||||||
PPPConfigurePacket(mbuf *packet);
|
PPPConfigurePacket(struct mbuf *packet);
|
||||||
~PPPConfigurePacket();
|
~PPPConfigurePacket();
|
||||||
|
|
||||||
bool SetCode(uint8 code);
|
bool SetCode(uint8 code);
|
||||||
@@ -46,7 +46,7 @@ class PPPConfigurePacket {
|
|||||||
{ return fItems.CountItems(); }
|
{ return fItems.CountItems(); }
|
||||||
ppp_configure_item *ItemAt(int32 index) const;
|
ppp_configure_item *ItemAt(int32 index) const;
|
||||||
|
|
||||||
mbuf *ToMbuf(uint32 reserve = 0);
|
struct mbuf *ToMbuf(uint32 reserve = 0);
|
||||||
// the user is responsible for freeing the mbuf
|
// the user is responsible for freeing the mbuf
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -118,12 +118,6 @@ enum PPP_MODE {
|
|||||||
PPP_SERVER_MODE
|
PPP_SERVER_MODE
|
||||||
};
|
};
|
||||||
|
|
||||||
// report types
|
|
||||||
enum PPP_REPORT {
|
|
||||||
PPP_CONNECTION_REPORT = 0x01,
|
|
||||||
PPP_ERROR_REPORT = 0x02,
|
|
||||||
};
|
|
||||||
|
|
||||||
// authentication status
|
// authentication status
|
||||||
enum PPP_AUTHENTICATION_STATUS {
|
enum PPP_AUTHENTICATION_STATUS {
|
||||||
PPP_AUTHENTICATION_FAILED = -1,
|
PPP_AUTHENTICATION_FAILED = -1,
|
||||||
|
|||||||
@@ -8,7 +8,13 @@
|
|||||||
#ifndef _K_PPP_DEVICE__H
|
#ifndef _K_PPP_DEVICE__H
|
||||||
#define _K_PPP_DEVICE__H
|
#define _K_PPP_DEVICE__H
|
||||||
|
|
||||||
#include "KPPPInterface.h"
|
#include <driver_settings.h>
|
||||||
|
|
||||||
|
#include <KPPPDefs.h>
|
||||||
|
|
||||||
|
#ifndef _K_PPP_INTERFACE__H
|
||||||
|
#include <KPPPInterface.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class PPPDevice {
|
class PPPDevice {
|
||||||
@@ -27,12 +33,12 @@ class PPPDevice {
|
|||||||
|
|
||||||
PPPInterface *Interface() const
|
PPPInterface *Interface() const
|
||||||
{ return fInterface; }
|
{ return fInterface; }
|
||||||
driver_parameter *Settings()
|
driver_parameter *Settings() const
|
||||||
{ return fSettings; }
|
{ return fSettings; }
|
||||||
|
|
||||||
virtual status_t Control(uint32 op, void *data, size_t length);
|
virtual status_t Control(uint32 op, void *data, size_t length);
|
||||||
|
|
||||||
virtual bool SetMTU(uint32 mtu) = 0;
|
virtual bool SetMTU(uint32 MTU);
|
||||||
uint32 MTU() const
|
uint32 MTU() const
|
||||||
{ return fMTU; }
|
{ return fMTU; }
|
||||||
virtual uint32 PreferredMTU() const = 0;
|
virtual uint32 PreferredMTU() const = 0;
|
||||||
@@ -52,10 +58,10 @@ class PPPDevice {
|
|||||||
virtual uint32 CountOutputBytes() const = 0;
|
virtual uint32 CountOutputBytes() const = 0;
|
||||||
// how many bytes are waiting to be sent?
|
// how many bytes are waiting to be sent?
|
||||||
|
|
||||||
virtual status_t Send(mbuf *packet) = 0;
|
virtual status_t Send(struct mbuf *packet) = 0;
|
||||||
// This should enqueue the packet and return immediately.
|
// This should enqueue the packet and return immediately.
|
||||||
// The device is responsible for freeing the packet.
|
// The device is responsible for freeing the packet.
|
||||||
status_t PassToInterface(mbuf *packet);
|
status_t PassToInterface(struct mbuf *packet);
|
||||||
// This will pass the packet to the interface's queue.
|
// This will pass the packet to the interface's queue.
|
||||||
// Do not call Interface::ReceiveFromDevice directly
|
// Do not call Interface::ReceiveFromDevice directly
|
||||||
// if this can block a Send()!
|
// if this can block a Send()!
|
||||||
@@ -70,9 +76,9 @@ class PPPDevice {
|
|||||||
bool DownStarted() const;
|
bool DownStarted() const;
|
||||||
|
|
||||||
// report up/down events
|
// report up/down events
|
||||||
void UpFailedEvent() const;
|
void UpFailedEvent();
|
||||||
void UpEvent() const;
|
void UpEvent();
|
||||||
void DownEvent() const;
|
void DownEvent();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool fIsUp;
|
bool fIsUp;
|
||||||
|
|||||||
@@ -8,13 +8,22 @@
|
|||||||
#ifndef _K_PPP_ENCAPSULATOR__H
|
#ifndef _K_PPP_ENCAPSULATOR__H
|
||||||
#define _K_PPP_ENCAPSULATOR__H
|
#define _K_PPP_ENCAPSULATOR__H
|
||||||
|
|
||||||
#include "KPPPInterface.h"
|
#include <driver_settings.h>
|
||||||
|
|
||||||
|
#include <KPPPDefs.h>
|
||||||
|
|
||||||
|
class PPPInterface;
|
||||||
|
|
||||||
|
#ifndef _K_PPP_INTERFACE__H
|
||||||
|
#include <KPPPInterface.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class PPPEncapsulator {
|
class PPPEncapsulator {
|
||||||
public:
|
public:
|
||||||
PPPEncapsulator(const char *name, PPP_ENCAPSULATION_LEVEL level,
|
PPPEncapsulator(const char *name, PPP_PHASE phase,
|
||||||
uint16 protocol, int32 addressFamily, uint32 overhead,
|
PPP_ENCAPSULATION_LEVEL level, uint16 protocol,
|
||||||
|
int32 addressFamily, uint32 overhead,
|
||||||
PPPInterface *interface, driver_parameter *settings,
|
PPPInterface *interface, driver_parameter *settings,
|
||||||
int32 flags = PPP_NO_FLAGS);
|
int32 flags = PPP_NO_FLAGS);
|
||||||
virtual ~PPPEncapsulator();
|
virtual ~PPPEncapsulator();
|
||||||
@@ -24,6 +33,9 @@ class PPPEncapsulator {
|
|||||||
const char *Name() const
|
const char *Name() const
|
||||||
{ return fName; }
|
{ return fName; }
|
||||||
|
|
||||||
|
PPP_PHASE Phase() const
|
||||||
|
{ return fPhase; }
|
||||||
|
|
||||||
PPP_ENCAPSULATION_LEVEL Level() const
|
PPP_ENCAPSULATION_LEVEL Level() const
|
||||||
{ return fLevel; }
|
{ return fLevel; }
|
||||||
uint32 Overhead() const
|
uint32 Overhead() const
|
||||||
@@ -31,7 +43,7 @@ class PPPEncapsulator {
|
|||||||
|
|
||||||
PPPInterface *Interface() const
|
PPPInterface *Interface() const
|
||||||
{ return fInterface; }
|
{ return fInterface; }
|
||||||
driver_parameter *Settings()
|
driver_parameter *Settings() const
|
||||||
{ return fSettings; }
|
{ return fSettings; }
|
||||||
|
|
||||||
uint16 Protocol() const
|
uint16 Protocol() const
|
||||||
@@ -62,17 +74,17 @@ class PPPEncapsulator {
|
|||||||
virtual bool Down() = 0;
|
virtual bool Down() = 0;
|
||||||
bool IsUp() const
|
bool IsUp() const
|
||||||
{ return fConnectionStatus == PPP_ESTABLISHED_PHASE; }
|
{ return fConnectionStatus == PPP_ESTABLISHED_PHASE; }
|
||||||
bool IsDown const
|
bool IsDown() const
|
||||||
{ return fConectionStatus == PPP_DOWN_PHASE; }
|
{ return fConnectionStatus == PPP_DOWN_PHASE; }
|
||||||
bool IsGoingUp() const
|
bool IsGoingUp() const
|
||||||
{ return fConnectionStatus == PPP_ESTABLISHMENT_PHASE; }
|
{ return fConnectionStatus == PPP_ESTABLISHMENT_PHASE; }
|
||||||
bool IsGoingDown() const
|
bool IsGoingDown() const
|
||||||
{ return fConnectionStatus == PPP_TERMINATION_PHASE; }
|
{ return fConnectionStatus == PPP_TERMINATION_PHASE; }
|
||||||
|
|
||||||
virtual status_t Send(mbuf *packet, uint16 protocol) = 0;
|
virtual status_t Send(struct mbuf *packet, uint16 protocol) = 0;
|
||||||
virtual status_t Receive(mbuf *packet, uint16 protocol) = 0;
|
virtual status_t Receive(struct mbuf *packet, uint16 protocol) = 0;
|
||||||
|
|
||||||
status_t SendToNext(mbuf *packet, uint16 protocol) const;
|
status_t SendToNext(struct mbuf *packet, uint16 protocol) const;
|
||||||
// this will send your packet to the next (up) encapsulator
|
// this will send your packet to the next (up) encapsulator
|
||||||
// if there is no next encapsulator (==NULL), it will
|
// if there is no next encapsulator (==NULL), it will
|
||||||
// call the interface's SendToDevice function
|
// call the interface's SendToDevice function
|
||||||
@@ -93,6 +105,7 @@ class PPPEncapsulator {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
char *fName;
|
char *fName;
|
||||||
|
PPP_PHASE fPhase;
|
||||||
PPP_ENCAPSULATION_LEVEL fLevel;
|
PPP_ENCAPSULATION_LEVEL fLevel;
|
||||||
uint16 fProtocol;
|
uint16 fProtocol;
|
||||||
int32 fAddressFamily;
|
int32 fAddressFamily;
|
||||||
@@ -105,7 +118,7 @@ class PPPEncapsulator {
|
|||||||
bool fEnabled;
|
bool fEnabled;
|
||||||
bool fUpRequested;
|
bool fUpRequested;
|
||||||
PPP_PHASE fConnectionStatus;
|
PPP_PHASE fConnectionStatus;
|
||||||
}:
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,20 +10,29 @@
|
|||||||
|
|
||||||
#include <driver_settings.h>
|
#include <driver_settings.h>
|
||||||
|
|
||||||
#include "KPPPDefs.h"
|
#include <KPPPDefs.h>
|
||||||
|
|
||||||
#include "KPPPStateMachine.h"
|
#ifndef _K_PPP_LCP__H
|
||||||
#include "KPPPLCP.h"
|
#include <KPPPLCP.h>
|
||||||
#include "KPPPReportManager.h"
|
#endif
|
||||||
|
|
||||||
#include "List.h"
|
#include <KPPPReportManager.h>
|
||||||
#include "LockerHelper.h"
|
|
||||||
|
#ifndef _K_PPP_STATE_MACHINE__H
|
||||||
|
#include <KPPPStateMachine.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <List.h>
|
||||||
|
#include <LockerHelper.h>
|
||||||
|
|
||||||
class PPPDevice;
|
class PPPDevice;
|
||||||
class PPPProtocol;
|
class PPPProtocol;
|
||||||
class PPPEncapsulator;
|
class PPPEncapsulator;
|
||||||
class PPPOptionHandler;
|
class PPPOptionHandler;
|
||||||
|
|
||||||
|
struct ppp_manager_info;
|
||||||
|
struct ppp_module_info;
|
||||||
|
|
||||||
|
|
||||||
class PPPInterface {
|
class PPPInterface {
|
||||||
friend class PPPStateMachine;
|
friend class PPPStateMachine;
|
||||||
@@ -45,12 +54,12 @@ class PPPInterface {
|
|||||||
interface_id ID() const
|
interface_id ID() const
|
||||||
{ return fID; }
|
{ return fID; }
|
||||||
|
|
||||||
driver_settings* Settings()
|
driver_settings* Settings() const
|
||||||
{ return fSettings; }
|
{ return fSettings; }
|
||||||
|
|
||||||
PPPStateMachine& StateMachine() const
|
PPPStateMachine& StateMachine()
|
||||||
{ return fStateMachine; }
|
{ return fStateMachine; }
|
||||||
PPPLCP& LCP() const
|
PPPLCP& LCP()
|
||||||
{ return fLCP; }
|
{ return fLCP; }
|
||||||
|
|
||||||
struct ifnet *Ifnet() const
|
struct ifnet *Ifnet() const
|
||||||
@@ -75,6 +84,8 @@ class PPPInterface {
|
|||||||
status_t Control(uint32 op, void *data, size_t length);
|
status_t Control(uint32 op, void *data, size_t length);
|
||||||
|
|
||||||
bool SetDevice(PPPDevice *device);
|
bool SetDevice(PPPDevice *device);
|
||||||
|
PPPDevice *Device() const
|
||||||
|
{ return fDevice; }
|
||||||
|
|
||||||
bool AddProtocol(PPPProtocol *protocol);
|
bool AddProtocol(PPPProtocol *protocol);
|
||||||
bool RemoveProtocol(PPPProtocol *protocol);
|
bool RemoveProtocol(PPPProtocol *protocol);
|
||||||
@@ -82,7 +93,7 @@ class PPPInterface {
|
|||||||
{ return fProtocols.CountItems(); }
|
{ return fProtocols.CountItems(); }
|
||||||
PPPProtocol *ProtocolAt(int32 index) const;
|
PPPProtocol *ProtocolAt(int32 index) const;
|
||||||
PPPProtocol *ProtocolFor(uint16 protocol, int32 start = 0) const;
|
PPPProtocol *ProtocolFor(uint16 protocol, int32 start = 0) const;
|
||||||
int32 IndexOfProtocol(const PPPProtocol *protocol) const
|
int32 IndexOfProtocol(PPPProtocol *protocol) const
|
||||||
{ return fProtocols.IndexOf(protocol); }
|
{ return fProtocols.IndexOf(protocol); }
|
||||||
|
|
||||||
bool AddEncapsulator(PPPEncapsulator *encapsulator);
|
bool AddEncapsulator(PPPEncapsulator *encapsulator);
|
||||||
@@ -90,13 +101,14 @@ class PPPInterface {
|
|||||||
PPPEncapsulator *FirstEncapsulator() const
|
PPPEncapsulator *FirstEncapsulator() const
|
||||||
{ return fFirstEncapsulator; }
|
{ return fFirstEncapsulator; }
|
||||||
PPPEncapsulator *EncapsulatorFor(uint16 protocol,
|
PPPEncapsulator *EncapsulatorFor(uint16 protocol,
|
||||||
PPPEncapsulator start = NULL) const;
|
PPPEncapsulator *start = NULL) const;
|
||||||
|
|
||||||
// multilink methods
|
// multilink methods
|
||||||
void AddChild(PPPInterface *child);
|
bool AddChild(PPPInterface *child);
|
||||||
void RemoveChild(PPPInterface *child);
|
bool RemoveChild(PPPInterface *child);
|
||||||
int32 CountChildren() const
|
int32 CountChildren() const
|
||||||
{ return fChildren.CountItems(); }
|
{ return fChildren.CountItems(); }
|
||||||
|
PPPInterface *ChildAt(int32 index) const;
|
||||||
PPPInterface *Parent() const
|
PPPInterface *Parent() const
|
||||||
{ return fParent; }
|
{ return fParent; }
|
||||||
bool IsMultilink() const
|
bool IsMultilink() const
|
||||||
@@ -114,30 +126,31 @@ class PPPInterface {
|
|||||||
{ return fMode; }
|
{ return fMode; }
|
||||||
// client or server mode?
|
// client or server mode?
|
||||||
PPP_STATE State() const
|
PPP_STATE State() const
|
||||||
{ return StateMachine().State(); }
|
{ return fStateMachine.State(); }
|
||||||
PPP_PHASE Phase() const
|
PPP_PHASE Phase() const
|
||||||
{ return StateMachine().Phase(); }
|
{ return fStateMachine.Phase(); }
|
||||||
|
|
||||||
bool Up();
|
bool Up();
|
||||||
// in server mode Up() listens for an incoming connection
|
// in server mode Up() listens for an incoming connection
|
||||||
bool Down();
|
bool Down();
|
||||||
bool IsUp() const;
|
bool IsUp() const;
|
||||||
|
|
||||||
PPPReportManager& ReportManager() const
|
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)
|
||||||
{ fReportManager.Report(type, code, data, length); }
|
{ return fReportManager.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(const driver_settings *settings,
|
bool LoadModules(driver_settings *settings,
|
||||||
int32 start, int32 count);
|
int32 start, int32 count);
|
||||||
bool LoadModule(const char *name, const driver_parameter *parameter);
|
bool LoadModule(const char *name, driver_parameter *parameter,
|
||||||
|
int32 type);
|
||||||
|
|
||||||
status_t Send(mbuf *packet, uint16 protocol);
|
status_t Send(struct mbuf *packet, uint16 protocol);
|
||||||
status_t Receive(mbuf *packet, uint16 protocol);
|
status_t Receive(struct mbuf *packet, uint16 protocol);
|
||||||
|
|
||||||
status_t SendToDevice(mbuf *packet, uint16 protocol);
|
status_t SendToDevice(struct mbuf *packet, uint16 protocol);
|
||||||
status_t ReceiveFromDevice(mbuf *packet);
|
status_t ReceiveFromDevice(struct mbuf *packet);
|
||||||
// This is called by the receive-thread.
|
// This is called by the receive-thread.
|
||||||
// Only call this if it does not block Send() or
|
// Only call this if it does not block Send() or
|
||||||
// SendToDevice()!
|
// SendToDevice()!
|
||||||
@@ -193,7 +206,7 @@ class PPPInterface {
|
|||||||
PPPDevice *fDevice;
|
PPPDevice *fDevice;
|
||||||
PPPEncapsulator *fFirstEncapsulator;
|
PPPEncapsulator *fFirstEncapsulator;
|
||||||
List<PPPProtocol*> fProtocols;
|
List<PPPProtocol*> fProtocols;
|
||||||
List<ppp_module_info*> fModules;
|
List<char*> fModules;
|
||||||
|
|
||||||
BLocker& fLock;
|
BLocker& fLock;
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,30 @@
|
|||||||
#ifndef _K_PPP_LCP__H
|
#ifndef _K_PPP_LCP__H
|
||||||
#define _K_PPP_LCP__H
|
#define _K_PPP_LCP__H
|
||||||
|
|
||||||
#include "KPPPProtocol.h"
|
#include <List.h>
|
||||||
|
|
||||||
|
#ifndef _K_PPP_PROTOCOL__H
|
||||||
|
#include <KPPPProtocol.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _K_PPP_INTERFACE__H
|
||||||
|
#include <KPPPInterface.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _K_PPP_STATE_MACHINE__H
|
||||||
|
#include <KPPPStateMachine.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class PPPEncapsulator;
|
||||||
|
class PPPOptionHandler;
|
||||||
|
|
||||||
|
|
||||||
typedef struct lcp_packet {
|
typedef struct ppp_lcp_packet {
|
||||||
uint8 code;
|
uint8 code;
|
||||||
uint8 id;
|
uint8 id;
|
||||||
uint16 length;
|
uint16 length;
|
||||||
int8 data[0];
|
int8 data[0];
|
||||||
} lcp_packet;
|
} ppp_lcp_packet;
|
||||||
|
|
||||||
|
|
||||||
class PPPLCP : public PPPProtocol {
|
class PPPLCP : public PPPProtocol {
|
||||||
@@ -25,7 +40,7 @@ class PPPLCP : public PPPProtocol {
|
|||||||
private:
|
private:
|
||||||
// may only be constructed/destructed by PPPInterface
|
// may only be constructed/destructed by PPPInterface
|
||||||
PPPLCP(PPPInterface& interface);
|
PPPLCP(PPPInterface& interface);
|
||||||
~PPPLCP();
|
virtual ~PPPLCP();
|
||||||
|
|
||||||
// copies are not allowed!
|
// copies are not allowed!
|
||||||
PPPLCP(const PPPLCP& copy);
|
PPPLCP(const PPPLCP& copy);
|
||||||
@@ -33,7 +48,7 @@ class PPPLCP : public PPPProtocol {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
PPPStateMachine& StateMachine() const
|
PPPStateMachine& StateMachine() const
|
||||||
{ return Interface()->StateMachine(); }
|
{ return fStateMachine; }
|
||||||
|
|
||||||
bool AddOptionHandler(PPPOptionHandler *handler);
|
bool AddOptionHandler(PPPOptionHandler *handler);
|
||||||
bool RemoveOptionHandler(PPPOptionHandler *handler);
|
bool RemoveOptionHandler(PPPOptionHandler *handler);
|
||||||
@@ -54,12 +69,14 @@ class PPPLCP : public PPPProtocol {
|
|||||||
virtual bool Up();
|
virtual bool Up();
|
||||||
virtual bool Down();
|
virtual bool Down();
|
||||||
|
|
||||||
virtual status_t Send(mbuf *packet);
|
virtual status_t Send(struct mbuf *packet);
|
||||||
virtual status_t Receive(mbuf *packet, uint16 protocol);
|
virtual status_t Receive(struct mbuf *packet, uint16 protocol);
|
||||||
|
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PPPStateMachine& fStateMachine;
|
||||||
|
|
||||||
List<PPPOptionHandler*> fOptionHandlers;
|
List<PPPOptionHandler*> fOptionHandlers;
|
||||||
|
|
||||||
PPPEncapsulator *fTarget;
|
PPPEncapsulator *fTarget;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef _K_PPP_MANAGER__H
|
#ifndef _K_PPP_MANAGER__H
|
||||||
#define _K_PPP_MANAGER__H
|
#define _K_PPP_MANAGER__H
|
||||||
|
|
||||||
#include <net_module.h>
|
#include "net_module.h"
|
||||||
|
|
||||||
|
|
||||||
#define PPP_MANAGER_MODULE_NAME "network/interfaces/ppp"
|
#define PPP_MANAGER_MODULE_NAME "network/interfaces/ppp"
|
||||||
@@ -23,8 +23,9 @@ enum PPP_INTERFACE_FILTER {
|
|||||||
typedef struct ppp_manager_info {
|
typedef struct ppp_manager_info {
|
||||||
kernel_net_module_info knminfo;
|
kernel_net_module_info knminfo;
|
||||||
|
|
||||||
uint32 (*create_interface)(driver_settings *settings, interface_id parent);
|
interface_id (*create_interface)(const driver_settings *settings,
|
||||||
// you should always create interfaces using this function
|
interface_id parent);
|
||||||
|
// you should always create interfaces using this function
|
||||||
void (*delete_interface)(interface_id ID);
|
void (*delete_interface)(interface_id ID);
|
||||||
// this marks the interface for deletion
|
// this marks the interface for deletion
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,15 @@
|
|||||||
#ifndef _K_PPP_OPTION_HANDLER__H
|
#ifndef _K_PPP_OPTION_HANDLER__H
|
||||||
#define _K_PPP_OPTION_HANDLER__H
|
#define _K_PPP_OPTION_HANDLER__H
|
||||||
|
|
||||||
#include "KPPPConfigurePacket.h"
|
#include <driver_settings.h>
|
||||||
#include "KPPPInterface.h"
|
|
||||||
|
#include <KPPPDefs.h>
|
||||||
|
|
||||||
|
#ifndef _K_PPP_INTERFACE__H
|
||||||
|
#include <KPPPInterface.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class PPPConfigurePacket;
|
||||||
|
|
||||||
|
|
||||||
class PPPOptionHandler {
|
class PPPOptionHandler {
|
||||||
@@ -29,7 +36,7 @@ class PPPOptionHandler {
|
|||||||
|
|
||||||
PPPInterface *Interface() const
|
PPPInterface *Interface() const
|
||||||
{ return fInterface; }
|
{ return fInterface; }
|
||||||
driver_parameter *Settings()
|
driver_parameter *Settings() const
|
||||||
{ return fSettings; }
|
{ return fSettings; }
|
||||||
|
|
||||||
virtual void Reset() = 0;
|
virtual void Reset() = 0;
|
||||||
@@ -53,9 +60,9 @@ class PPPOptionHandler {
|
|||||||
// notification that we ack these values
|
// notification that we ack these values
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *fName;
|
char *fName;
|
||||||
PPPInterface *fInterface;
|
PPPInterface *fInterface;
|
||||||
driver_parameters *fSettings;
|
driver_parameter *fSettings;
|
||||||
|
|
||||||
bool fEnabled;
|
bool fEnabled;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,11 @@
|
|||||||
#ifndef _K_PPP_PROTOCOL__H
|
#ifndef _K_PPP_PROTOCOL__H
|
||||||
#define _K_PPP_PROTOCOL__H
|
#define _K_PPP_PROTOCOL__H
|
||||||
|
|
||||||
#include "KPPPInterface.h"
|
#include <driver_settings.h>
|
||||||
|
|
||||||
|
#include <KPPPDefs.h>
|
||||||
|
|
||||||
|
class PPPInterface;
|
||||||
|
|
||||||
|
|
||||||
class PPPProtocol {
|
class PPPProtocol {
|
||||||
@@ -26,7 +30,9 @@ class PPPProtocol {
|
|||||||
PPP_PHASE Phase() const
|
PPP_PHASE Phase() const
|
||||||
{ return fPhase; }
|
{ return fPhase; }
|
||||||
|
|
||||||
driver_parameter *Settings()
|
PPPInterface *Interface() const
|
||||||
|
{ return fInterface; }
|
||||||
|
driver_parameter *Settings() const
|
||||||
{ return fSettings; }
|
{ return fSettings; }
|
||||||
|
|
||||||
uint16 Protocol() const
|
uint16 Protocol() const
|
||||||
@@ -52,15 +58,15 @@ class PPPProtocol {
|
|||||||
virtual bool Down() = 0;
|
virtual bool Down() = 0;
|
||||||
bool IsUp() const
|
bool IsUp() const
|
||||||
{ return fConnectionStatus == PPP_ESTABLISHED_PHASE; }
|
{ return fConnectionStatus == PPP_ESTABLISHED_PHASE; }
|
||||||
bool IsDown const
|
bool IsDown() const
|
||||||
{ return fConectionStatus == PPP_DOWN_PHASE; }
|
{ return fConnectionStatus == PPP_DOWN_PHASE; }
|
||||||
bool IsGoingUp() const
|
bool IsGoingUp() const
|
||||||
{ return fConnectionStatus == PPP_ESTABLISHMENT_PHASE; }
|
{ return fConnectionStatus == PPP_ESTABLISHMENT_PHASE; }
|
||||||
bool IsGoingDown() const
|
bool IsGoingDown() const
|
||||||
{ return fConnectionStatus == PPP_TERMINATION_PHASE; }
|
{ return fConnectionStatus == PPP_TERMINATION_PHASE; }
|
||||||
|
|
||||||
virtual status_t Send(mbuf *packet) = 0;
|
virtual status_t Send(struct mbuf *packet) = 0;
|
||||||
virtual status_t Receive(mbuf *packet, uint16 protocol) = 0;
|
virtual status_t Receive(struct mbuf *packet, uint16 protocol) = 0;
|
||||||
|
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
|
|
||||||
@@ -74,12 +80,12 @@ class PPPProtocol {
|
|||||||
// report up/down events
|
// report up/down events
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *name;
|
char *fName;
|
||||||
PPP_PHASE fPhase;
|
PPP_PHASE fPhase;
|
||||||
uint16 fProtocol;
|
uint16 fProtocol;
|
||||||
int32 fAddressFamily;
|
int32 fAddressFamily;
|
||||||
PPPInterface fInterface;
|
PPPInterface *fInterface;
|
||||||
driver_parameter fSettings;
|
driver_parameter *fSettings;
|
||||||
int32 fFlags;
|
int32 fFlags;
|
||||||
|
|
||||||
bool fEnabled;
|
bool fEnabled;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#ifndef _K_PPP_REPORT_DEFS__H
|
#ifndef _K_PPP_REPORT_DEFS__H
|
||||||
#define _K_PPP_REPORT_DEFS__H
|
#define _K_PPP_REPORT_DEFS__H
|
||||||
|
|
||||||
|
|
||||||
#define PPP_REPORT_DATA_LIMIT 128
|
#define PPP_REPORT_DATA_LIMIT 128
|
||||||
// how much optional data can be added to the report
|
// how much optional data can be added to the report
|
||||||
#define PPP_REPORT_CODE '_3PR'
|
#define PPP_REPORT_CODE '_3PR'
|
||||||
@@ -47,7 +48,7 @@ enum PPP_CONNECTION_REPORT_CODES {
|
|||||||
typedef struct ppp_report_packet {
|
typedef struct ppp_report_packet {
|
||||||
int32 type;
|
int32 type;
|
||||||
int32 code;
|
int32 code;
|
||||||
uint8 len;
|
uint8 length;
|
||||||
char data[PPP_REPORT_DATA_LIMIT];
|
char data[PPP_REPORT_DATA_LIMIT];
|
||||||
} ppp_report_packet;
|
} ppp_report_packet;
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ typedef struct ppp_report_packet {
|
|||||||
#define PPP_REPORT_TIMEOUT 10
|
#define PPP_REPORT_TIMEOUT 10
|
||||||
|
|
||||||
typedef struct ppp_report_request {
|
typedef struct ppp_report_request {
|
||||||
port_id port;
|
thread_id thread;
|
||||||
int32 type;
|
int32 type;
|
||||||
int32 flags;
|
int32 flags;
|
||||||
} ppp_report_request;
|
} ppp_report_request;
|
||||||
|
|||||||
@@ -8,17 +8,19 @@
|
|||||||
#ifndef _K_PPP_REPORT_MANAGER__H
|
#ifndef _K_PPP_REPORT_MANAGER__H
|
||||||
#define _K_PPP_REPORT_MANAGER__H
|
#define _K_PPP_REPORT_MANAGER__H
|
||||||
|
|
||||||
#include "KPPPReportDefs.h"
|
#include <OS.h>
|
||||||
|
|
||||||
#include "List.h"
|
#include <KPPPReportDefs.h>
|
||||||
#include "LockerHelper.h"
|
|
||||||
|
#include <List.h>
|
||||||
|
|
||||||
|
|
||||||
#define PPP_REPLY(sender, value) send_data_with_timeout((sender), (value), NULL, 0, B_REPORT_TIMEOUT)
|
#define PPP_REPLY(sender, value) send_data_with_timeout((sender), (value), NULL, 0, PPP_REPORT_TIMEOUT)
|
||||||
|
|
||||||
class PPPReportManager {
|
class PPPReportManager {
|
||||||
public:
|
public:
|
||||||
PPPReportManager(BLocker& lock);
|
PPPReportManager(BLocker& lock);
|
||||||
|
~PPPReportManager();
|
||||||
|
|
||||||
void EnableReports(PPP_REPORT_TYPE type, thread_id thread,
|
void EnableReports(PPP_REPORT_TYPE type, thread_id thread,
|
||||||
int32 flags = PPP_NO_REPORT_FLAGS);
|
int32 flags = PPP_NO_REPORT_FLAGS);
|
||||||
@@ -29,7 +31,7 @@ class PPPReportManager {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BLocker& fLock;
|
BLocker& fLock;
|
||||||
List<ppp_report_request> fReportRequests;
|
List<ppp_report_request*> fReportRequests;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,17 @@
|
|||||||
#ifndef _K_PPP_STATE_MACHINE__H
|
#ifndef _K_PPP_STATE_MACHINE__H
|
||||||
#define _K_PPP_STATE_MACHINE__H
|
#define _K_PPP_STATE_MACHINE__H
|
||||||
|
|
||||||
#include "KPPPLCP.h"
|
#include <KPPPDefs.h>
|
||||||
|
|
||||||
#include "Locker.h"
|
class PPPEncapsulator;
|
||||||
|
class PPPInterface;
|
||||||
|
class PPPProtocol;
|
||||||
|
|
||||||
|
#ifndef _K_PPP_INTERFACE__H
|
||||||
|
#include <KPPPInterface.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Locker.h>
|
||||||
|
|
||||||
|
|
||||||
class PPPStateMachine {
|
class PPPStateMachine {
|
||||||
@@ -30,7 +38,7 @@ class PPPStateMachine {
|
|||||||
PPPInterface *Interface() const
|
PPPInterface *Interface() const
|
||||||
{ return fInterface; }
|
{ return fInterface; }
|
||||||
PPPLCP& LCP() const
|
PPPLCP& LCP() const
|
||||||
{ return Interface()->LCP(); }
|
{ return fLCP; }
|
||||||
|
|
||||||
PPP_STATE State() const
|
PPP_STATE State() const
|
||||||
{ return fState; }
|
{ return fState; }
|
||||||
@@ -44,16 +52,16 @@ class PPPStateMachine {
|
|||||||
void AuthenticationRequested();
|
void AuthenticationRequested();
|
||||||
void AuthenticationAccepted(const char *name);
|
void AuthenticationAccepted(const char *name);
|
||||||
void AuthenticationDenied(const char *name);
|
void AuthenticationDenied(const char *name);
|
||||||
const char *AuthenticationName() const;
|
const char *AuthenticationName() const
|
||||||
// returns NULL if not authenticated
|
{ return fAuthenticationName; }
|
||||||
PPP_AUTHENTICATION_STATUS AuthenticationStatus() const
|
PPP_AUTHENTICATION_STATUS AuthenticationStatus() const
|
||||||
{ return fAuthenticationStatus; }
|
{ return fAuthenticationStatus; }
|
||||||
|
|
||||||
void PeerAuthenticationRequested();
|
void PeerAuthenticationRequested();
|
||||||
void PeerAuthenticationAccepted(const char *name);
|
void PeerAuthenticationAccepted(const char *name);
|
||||||
void PeerAuthenticationDenied(const char *name);
|
void PeerAuthenticationDenied(const char *name);
|
||||||
const char *PeerAuthenticationName() const;
|
const char *PeerAuthenticationName() const
|
||||||
// returns NULL if not authenticated
|
{ return fPeerAuthenticationName; }
|
||||||
PPP_AUTHENTICATION_STATUS PeerAuthenticationStatus() const
|
PPP_AUTHENTICATION_STATUS PeerAuthenticationStatus() const
|
||||||
{ return fPeerAuthenticationStatus; }
|
{ return fPeerAuthenticationStatus; }
|
||||||
|
|
||||||
@@ -92,21 +100,21 @@ class PPPStateMachine {
|
|||||||
void CloseEvent();
|
void CloseEvent();
|
||||||
void TOGoodEvent();
|
void TOGoodEvent();
|
||||||
void TOBadEvent();
|
void TOBadEvent();
|
||||||
void RCRGoodEvent(mbuf *packet);
|
void RCRGoodEvent(struct mbuf *packet);
|
||||||
void RCRBadEvent(mbuf *nak, mbuf *reject);
|
void RCRBadEvent(struct mbuf *nak, struct mbuf *reject);
|
||||||
void RCAEvent(mbuf *packet);
|
void RCAEvent(struct mbuf *packet);
|
||||||
void RCNEvent(mbuf *packet);
|
void RCNEvent(struct mbuf *packet);
|
||||||
void RTREvent(mbuf *packet);
|
void RTREvent(struct mbuf *packet);
|
||||||
void RTAEvent(mbuf *packet);
|
void RTAEvent(struct mbuf *packet);
|
||||||
void RUCEvent(mbuf *packet, uint16 protocol, uint8 type = PPP_PROTOCOL_REJECT);
|
void RUCEvent(struct mbuf *packet, uint16 protocol, uint8 type = PPP_PROTOCOL_REJECT);
|
||||||
void RXJGoodEvent(mbuf *packet);
|
void RXJGoodEvent(struct mbuf *packet);
|
||||||
void RXJBadEvent(mbuf *packet);
|
void RXJBadEvent(struct mbuf *packet);
|
||||||
void RXREvent(mbuf *packet);
|
void RXREvent(struct mbuf *packet);
|
||||||
|
|
||||||
// general events (for Good/Bad events)
|
// general events (for Good/Bad events)
|
||||||
void TimerEvent();
|
void TimerEvent();
|
||||||
void RCREvent(mbuf *packet);
|
void RCREvent(struct mbuf *packet);
|
||||||
void RXJEvent(mbuf *packet);
|
void RXJEvent(struct mbuf *packet);
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
void IllegalEvent(PPP_EVENT event);
|
void IllegalEvent(PPP_EVENT event);
|
||||||
@@ -117,12 +125,12 @@ class PPPStateMachine {
|
|||||||
void InitializeRestartCount();
|
void InitializeRestartCount();
|
||||||
void ZeroRestartCount();
|
void ZeroRestartCount();
|
||||||
void SendConfigureRequest();
|
void SendConfigureRequest();
|
||||||
void SendConfigureAck(mbuf *packet);
|
void SendConfigureAck(struct mbuf *packet);
|
||||||
void SendConfigureNak(mbuf *packet);
|
void SendConfigureNak(struct mbuf *packet);
|
||||||
void SendTerminateRequest();
|
void SendTerminateRequest();
|
||||||
void SendTerminateAck(mbuf *request);
|
void SendTerminateAck(struct mbuf *request);
|
||||||
void SendCodeReject(mbuf *packet, uint16 protocol, uint8 type);
|
void SendCodeReject(struct mbuf *packet, uint16 protocol, uint8 type);
|
||||||
void SendEchoReply(mbuf *request);
|
void SendEchoReply(struct mbuf *request);
|
||||||
|
|
||||||
void BringHandlersUp();
|
void BringHandlersUp();
|
||||||
uint32 BringPhaseUp();
|
uint32 BringPhaseUp();
|
||||||
@@ -133,6 +141,7 @@ class PPPStateMachine {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PPPInterface *fInterface;
|
PPPInterface *fInterface;
|
||||||
|
PPPLCP& fLCP;
|
||||||
|
|
||||||
PPP_PHASE fPhase;
|
PPP_PHASE fPhase;
|
||||||
PPP_STATE fState;
|
PPP_STATE fState;
|
||||||
@@ -141,7 +150,7 @@ class PPPStateMachine {
|
|||||||
|
|
||||||
PPP_AUTHENTICATION_STATUS fAuthenticationStatus,
|
PPP_AUTHENTICATION_STATUS fAuthenticationStatus,
|
||||||
fPeerAuthenticationStatus;
|
fPeerAuthenticationStatus;
|
||||||
int32 fAuthenticatorIndex, fPeerAuthenticatorIndex;
|
char *fAuthenticationName, *fPeerAuthenticationName;
|
||||||
|
|
||||||
BLocker fLock;
|
BLocker fLock;
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#ifndef _LOCKER_HELPER__H
|
#ifndef _LOCKER_HELPER__H
|
||||||
#define _LOCKER_HELPER__H
|
#define _LOCKER_HELPER__H
|
||||||
|
|
||||||
#include "Locker.h"
|
#include <Locker.h>
|
||||||
|
|
||||||
|
|
||||||
class LockerHelper {
|
class LockerHelper {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
SubDir OBOS_TOP src tests kits net ppp src ;
|
||||||
|
|
||||||
|
LOCATE_SOURCE += [ FDirName $(OBOS_TOP) src add-ons kernel file_systems bfs ] ;
|
||||||
|
SubDirHdrs [ FDirName $(OBOS_TOP) src add-ons kernel file_systems bfs ] ;
|
||||||
|
|
||||||
|
UsePrivateHeaders net ;
|
||||||
|
UseHeaders [ FDirName $(OBOS_TOP) src tests kits net ppp headers ] ;
|
||||||
|
|
||||||
|
R5KernelStaticLibrary kernelppp :
|
||||||
|
KPPPConfigurePacket.cpp
|
||||||
|
KPPPDevice.cpp
|
||||||
|
KPPPEncapsulator.cpp
|
||||||
|
KPPPInterface.cpp
|
||||||
|
KPPPLCP.cpp
|
||||||
|
KPPPOptionHandler.cpp
|
||||||
|
KPPPProtocol.cpp
|
||||||
|
KPPPReportManager.cpp
|
||||||
|
KPPPStateMachine.cpp
|
||||||
|
KPPPUtils.cpp
|
||||||
|
Locker.cpp
|
||||||
|
settings_tools.cpp
|
||||||
|
cpp.cpp
|
||||||
|
;
|
||||||
@@ -5,7 +5,8 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPConfigurePacket.h"
|
#include <KPPPConfigurePacket.h>
|
||||||
|
#include <KPPPInterface.h>
|
||||||
|
|
||||||
|
|
||||||
PPPConfigurePacket::PPPConfigurePacket(uint8 code)
|
PPPConfigurePacket::PPPConfigurePacket(uint8 code)
|
||||||
@@ -14,10 +15,10 @@ PPPConfigurePacket::PPPConfigurePacket(uint8 code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PPPConfigurePacket::PPPConfigurePacket(mbuf *packet)
|
PPPConfigurePacket::PPPConfigurePacket(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
// decode packet
|
// decode packet
|
||||||
lcp_packet *data = mtod(packet, lcp_packet*);
|
ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*);
|
||||||
|
|
||||||
if(!SetCode(data->code))
|
if(!SetCode(data->code))
|
||||||
return;
|
return;
|
||||||
@@ -30,7 +31,7 @@ PPPConfigurePacket::PPPConfigurePacket(mbuf *packet)
|
|||||||
ppp_configure_item *item;
|
ppp_configure_item *item;
|
||||||
|
|
||||||
while(position <= data->length - 4) {
|
while(position <= data->length - 4) {
|
||||||
item = data->data + position;
|
item = (ppp_configure_item*) (data->data + position);
|
||||||
position += item->length;
|
position += item->length;
|
||||||
|
|
||||||
AddItem(item);
|
AddItem(item);
|
||||||
@@ -64,7 +65,7 @@ PPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index = -1)
|
|||||||
if(item->length < 2)
|
if(item->length < 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ppp_configure_item *add = malloc(item->length);
|
ppp_configure_item *add = (ppp_configure_item*) malloc(item->length);
|
||||||
memcpy(add, item, item->length);
|
memcpy(add, item, item->length);
|
||||||
|
|
||||||
bool status;
|
bool status;
|
||||||
@@ -106,13 +107,13 @@ PPPConfigurePacket::ItemAt(int32 index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mbuf*
|
struct mbuf*
|
||||||
PPPConfigurePacket::ToMbuf(uint32 reserve = 0)
|
PPPConfigurePacket::ToMbuf(uint32 reserve = 0)
|
||||||
{
|
{
|
||||||
mbuf *packet = m_gethdr(MT_DATA);
|
struct mbuf *packet = m_gethdr(MT_DATA);
|
||||||
packet->m_data += reserve;
|
packet->m_data += reserve;
|
||||||
|
|
||||||
lcp_packet *data = mtod(packet, lcp_packet*);
|
ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*);
|
||||||
|
|
||||||
data->code = Code();
|
data->code = Code();
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPDevice.h"
|
#include <KPPPDevice.h>
|
||||||
|
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <mbuf.h>
|
||||||
|
|
||||||
|
|
||||||
PPPDevice::PPPDevice(const char *name, uint32 overhead, PPPInterface *interface,
|
PPPDevice::PPPDevice(const char *name, uint32 overhead, PPPInterface *interface,
|
||||||
@@ -15,7 +18,7 @@ PPPDevice::PPPDevice(const char *name, uint32 overhead, PPPInterface *interface,
|
|||||||
{
|
{
|
||||||
fName = name ? strdup(name) : NULL;
|
fName = name ? strdup(name) : NULL;
|
||||||
|
|
||||||
SetMTU(PreferredMTU());
|
SetMTU(1500);
|
||||||
|
|
||||||
if(interface)
|
if(interface)
|
||||||
interface->SetDevice(this);
|
interface->SetDevice(this);
|
||||||
@@ -59,13 +62,25 @@ PPPDevice::Control(uint32 op, void *data, size_t length)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PPPDevice::SetMTU(uint32 MTU)
|
||||||
|
{
|
||||||
|
fMTU = MTU;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PPPDevice::PassToInterface(mbuf *packet)
|
PPPDevice::PassToInterface(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
if(!Interface() || !Interface()->InQueue())
|
if(!Interface() || !Interface()->InQueue())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
IFQ_ENQUEUE(Interface()->InQueue(), packet);
|
IFQ_ENQUEUE(Interface()->InQueue(), packet);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,15 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPEncapsulator.h"
|
#include <KPPPEncapsulator.h>
|
||||||
|
|
||||||
|
|
||||||
PPPEncapsulator::PPPEncapsulator(const char *name, PPP_ENCAPSULATION_LEVEL level,
|
PPPEncapsulator::PPPEncapsulator(const char *name, PPP_PHASE phase,
|
||||||
uint16 protocol, int32 addressFamily, uint32 overhead,
|
PPP_ENCAPSULATION_LEVEL level, uint16 protocol,
|
||||||
|
int32 addressFamily, uint32 overhead,
|
||||||
PPPInterface *interface, driver_parameter *settings,
|
PPPInterface *interface, driver_parameter *settings,
|
||||||
int32 flags = PPP_NO_FLAGS)
|
int32 flags = PPP_NO_FLAGS)
|
||||||
: fOverhead(overhead), fLevel(level), fProtocol(protocol),
|
: fOverhead(overhead), fPhase(phase), fLevel(level), fProtocol(protocol),
|
||||||
fAddressFamily(addressFamily), fInterface(interface),
|
fAddressFamily(addressFamily), fInterface(interface),
|
||||||
fSettings(settings), fFlags(flags), fEnabled(true),
|
fSettings(settings), fFlags(flags), fEnabled(true),
|
||||||
fUpRequested(true), fConnectionStatus(PPP_DOWN_PHASE)
|
fUpRequested(true), fConnectionStatus(PPP_DOWN_PHASE)
|
||||||
@@ -52,7 +53,7 @@ PPPEncapsulator::SetEnabled(bool enabled = true)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(!enabled) {
|
if(!enabled) {
|
||||||
if(IsUp() || IsGoingUp()))
|
if(IsUp() || IsGoingUp())
|
||||||
Down();
|
Down();
|
||||||
} else if(!IsUp() && !IsGoingUp() && IsUpRequested() && Interface()->IsUp())
|
} else if(!IsUp() && !IsGoingUp() && IsUpRequested() && Interface()->IsUp())
|
||||||
Up();
|
Up();
|
||||||
@@ -80,7 +81,7 @@ PPPEncapsulator::Control(uint32 op, void *data, size_t length)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PPPEncapsulator::SendToNext(mbuf *packet, uint16 protocol) const
|
PPPEncapsulator::SendToNext(struct mbuf *packet, uint16 protocol) const
|
||||||
{
|
{
|
||||||
if(Next())
|
if(Next())
|
||||||
return Next()->Send(packet, protocol);
|
return Next()->Send(packet, protocol);
|
||||||
|
|||||||
@@ -5,26 +5,33 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPInterface.h"
|
// Stdio.h must be included before PPPModule.h/PPPManager.h because
|
||||||
|
// dprintf is defined twice with different return values, once with
|
||||||
|
// void (KernelExport.h) and once with int (stdio.h).
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <new.h>
|
||||||
|
|
||||||
|
// now our headers...
|
||||||
|
#include <KPPPInterface.h>
|
||||||
|
|
||||||
// our other classes
|
// our other classes
|
||||||
#include "KPPPModule.h"
|
#include <KPPPDevice.h>
|
||||||
#include "KPPPManager.h"
|
#include <KPPPEncapsulator.h>
|
||||||
|
#include <KPPPModule.h>
|
||||||
|
#include <KPPPManager.h>
|
||||||
|
|
||||||
// general helper classes not only belonging to us
|
// general helper classes not only belonging to us
|
||||||
#include "LockerHelper.h"
|
#include <LockerHelper.h>
|
||||||
|
|
||||||
// tools only for us :)
|
// tools only for us :)
|
||||||
#include "KPPPUtils.h"
|
#include "KPPPUtils.h"
|
||||||
#include "settings_tools.h"
|
#include "settings_tools.h"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <new.h>
|
|
||||||
|
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// - implement timers with support for settings next time instead of receiving timer
|
// - implement timers with support for settings next time instead of receiving timer
|
||||||
// events
|
// events periodically
|
||||||
|
|
||||||
|
|
||||||
// needed for redial:
|
// needed for redial:
|
||||||
@@ -42,7 +49,7 @@ status_t in_queue_thread(void *data);
|
|||||||
PPPInterface::PPPInterface(uint32 ID, driver_settings *settings,
|
PPPInterface::PPPInterface(uint32 ID, driver_settings *settings,
|
||||||
PPPInterface *parent = NULL)
|
PPPInterface *parent = NULL)
|
||||||
: fID(ID), fSettings(dup_driver_settings(settings)),
|
: fID(ID), fSettings(dup_driver_settings(settings)),
|
||||||
fStateMachine(*this), fLCP(*this), ReportManager()(StateMachine().Locker()),
|
fStateMachine(*this), fLCP(*this), fReportManager(StateMachine().Locker()),
|
||||||
fIfnet(NULL), fUpThread(-1), fRedialThread(-1), fDialRetry(0),
|
fIfnet(NULL), fUpThread(-1), fRedialThread(-1), fDialRetry(0),
|
||||||
fDialRetriesLimit(0), fIdleSince(0), fLinkMTU(1500), fDevice(NULL),
|
fDialRetriesLimit(0), fIdleSince(0), fLinkMTU(1500), fDevice(NULL),
|
||||||
fFirstEncapsulator(NULL), fLock(StateMachine().Locker())
|
fFirstEncapsulator(NULL), fLock(StateMachine().Locker())
|
||||||
@@ -144,10 +151,14 @@ PPPInterface::~PPPInterface()
|
|||||||
while(FirstEncapsulator())
|
while(FirstEncapsulator())
|
||||||
delete FirstEncapsulator();
|
delete FirstEncapsulator();
|
||||||
|
|
||||||
for(int32 index = 0; index < fModules.CountItems(); index++)
|
for(int32 index = 0; index < fModules.CountItems(); index++) {
|
||||||
put_module((module_info**) &fModules.ItemAt(index));
|
put_module(fModules.ItemAt(index));
|
||||||
|
free(fModules.ItemAt(index));
|
||||||
|
}
|
||||||
|
|
||||||
put_module((module_info**) &fManager);
|
put_module(PPP_MANAGER_MODULE_NAME);
|
||||||
|
|
||||||
|
free_driver_settings(fSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -231,6 +242,8 @@ PPPInterface::SetDevice(PPPDevice *device)
|
|||||||
|
|
||||||
CalculateMRU();
|
CalculateMRU();
|
||||||
CalculateBaudRate();
|
CalculateBaudRate();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -250,6 +263,8 @@ PPPInterface::AddProtocol(PPPProtocol *protocol)
|
|||||||
|
|
||||||
if(IsUp() || Phase() >= protocol->Phase())
|
if(IsUp() || Phase() >= protocol->Phase())
|
||||||
protocol->Up();
|
protocol->Up();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -357,7 +372,7 @@ PPPInterface::RemoveEncapsulator(PPPEncapsulator *encapsulator)
|
|||||||
return false;
|
return false;
|
||||||
// a running connection may not change
|
// a running connection may not change
|
||||||
|
|
||||||
PPPEncapsulator *current = fFirstEncapsulator, previous = NULL;
|
PPPEncapsulator *current = fFirstEncapsulator, *previous = NULL;
|
||||||
|
|
||||||
while(current) {
|
while(current) {
|
||||||
if(current == encapsulator) {
|
if(current == encapsulator) {
|
||||||
@@ -386,7 +401,7 @@ PPPInterface::RemoveEncapsulator(PPPEncapsulator *encapsulator)
|
|||||||
|
|
||||||
PPPEncapsulator*
|
PPPEncapsulator*
|
||||||
PPPInterface::EncapsulatorFor(uint16 protocol,
|
PPPInterface::EncapsulatorFor(uint16 protocol,
|
||||||
PPPEncapsulator start = NULL) const
|
PPPEncapsulator *start = NULL) const
|
||||||
{
|
{
|
||||||
PPPEncapsulator *current = start ? start : fFirstEncapsulator;
|
PPPEncapsulator *current = start ? start : fFirstEncapsulator;
|
||||||
|
|
||||||
@@ -433,11 +448,23 @@ PPPInterface::RemoveChild(PPPInterface *child)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PPPInterface*
|
||||||
|
PPPInterface::ChildAt(int32 index) const
|
||||||
|
{
|
||||||
|
PPPInterface *child = fChildren.ItemAt(index);
|
||||||
|
|
||||||
|
if(child == fChildren.GetDefaultItem())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PPPInterface::SetAutoRedial(bool autoredial = true)
|
PPPInterface::SetAutoRedial(bool autoredial = true)
|
||||||
{
|
{
|
||||||
if(Mode() == PPP_CLIENT_MODE)
|
if(Mode() == PPP_CLIENT_MODE)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
@@ -449,7 +476,7 @@ void
|
|||||||
PPPInterface::SetDialOnDemand(bool dialondemand = true)
|
PPPInterface::SetDialOnDemand(bool dialondemand = true)
|
||||||
{
|
{
|
||||||
if(Mode() != PPP_CLIENT_MODE)
|
if(Mode() != PPP_CLIENT_MODE)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
@@ -517,7 +544,6 @@ PPPInterface::Up()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(report.type == PPP_DESTRUCTION_REPORT) {
|
if(report.type == PPP_DESTRUCTION_REPORT) {
|
||||||
if(me == fUpThread) {
|
if(me == fUpThread) {
|
||||||
fDialRetry = 0;
|
fDialRetry = 0;
|
||||||
@@ -676,13 +702,12 @@ PPPInterface::IsUp() const
|
|||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
return StateMachine().Phase() == PPP_ESTABLISHED_PHASE;
|
return Phase() == PPP_ESTABLISHED_PHASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PPPInterface::LoadModules(const driver_settings *settings,
|
PPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count)
|
||||||
int32 start, int32 count)
|
|
||||||
{
|
{
|
||||||
if(Phase() != PPP_DOWN_PHASE)
|
if(Phase() != PPP_DOWN_PHASE)
|
||||||
return false;
|
return false;
|
||||||
@@ -698,8 +723,8 @@ PPPInterface::LoadModules(const driver_settings *settings,
|
|||||||
i < settings->parameter_count && i < start + count; i++) {
|
i < settings->parameter_count && i < start + count; i++) {
|
||||||
if(!strcasecmp(settings->parameters[i].name, PPP_MULTILINK_KEY)
|
if(!strcasecmp(settings->parameters[i].name, PPP_MULTILINK_KEY)
|
||||||
&& settings->parameters[i].value_count > 0) {
|
&& settings->parameters[i].value_count > 0) {
|
||||||
if(!LoadModule(settings->parameters[i].value[0],
|
if(!LoadModule(settings->parameters[i].values[0],
|
||||||
parameters[i].parameters, PPP_MULTILINK_TYPE))
|
settings->parameters[i].parameters, PPP_MULTILINK_TYPE))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -734,7 +759,7 @@ PPPInterface::LoadModules(const driver_settings *settings,
|
|||||||
if(type >= 0)
|
if(type >= 0)
|
||||||
for(int32 value_id = 0; value_id < settings->parameters[i].value_count;
|
for(int32 value_id = 0; value_id < settings->parameters[i].value_count;
|
||||||
value_id++)
|
value_id++)
|
||||||
if(!LoadModule(settings->parameters[i].value[value_id],
|
if(!LoadModule(settings->parameters[i].values[value_id],
|
||||||
settings->parameters[i].parameters, type))
|
settings->parameters[i].parameters, type))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -744,7 +769,7 @@ PPPInterface::LoadModules(const driver_settings *settings,
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PPPInterface::LoadModule(const char *name, const driver_parameter *parameter,
|
PPPInterface::LoadModule(const char *name, driver_parameter *parameter,
|
||||||
int32 type)
|
int32 type)
|
||||||
{
|
{
|
||||||
if(Phase() != PPP_DOWN_PHASE)
|
if(Phase() != PPP_DOWN_PHASE)
|
||||||
@@ -754,7 +779,7 @@ PPPInterface::LoadModule(const char *name, const driver_parameter *parameter,
|
|||||||
if(!name || strlen(name) > B_FILE_NAME_LENGTH)
|
if(!name || strlen(name) > B_FILE_NAME_LENGTH)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char module_name[B_PATH_NAME_LENGTH];
|
char *module_name = (char*) malloc(B_PATH_NAME_LENGTH);
|
||||||
|
|
||||||
sprintf(module_name, "%s/%s", PPP_MODULES_PATH, name);
|
sprintf(module_name, "%s/%s", PPP_MODULES_PATH, name);
|
||||||
|
|
||||||
@@ -762,17 +787,16 @@ PPPInterface::LoadModule(const char *name, const driver_parameter *parameter,
|
|||||||
if(get_module(module_name, (module_info**) &module) != B_OK)
|
if(get_module(module_name, (module_info**) &module) != B_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!module->add_to(Parent()?Parent():this, this, parameter, type))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// add the module to the list of loaded modules
|
// add the module to the list of loaded modules
|
||||||
// for putting them on our destruction
|
// for putting them on our destruction
|
||||||
return fModules.AddItem(module);
|
fModules.AddItem(module_name);
|
||||||
|
|
||||||
|
return module->add_to(Parent()?Parent():this, this, parameter, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PPPInterface::Send(mbuf *packet, uint16 protocol)
|
PPPInterface::Send(struct mbuf *packet, uint16 protocol)
|
||||||
{
|
{
|
||||||
if(!packet)
|
if(!packet)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -815,14 +839,14 @@ PPPInterface::Send(mbuf *packet, uint16 protocol)
|
|||||||
return SendToDevice(packet, protocol);
|
return SendToDevice(packet, protocol);
|
||||||
|
|
||||||
if(!fFirstEncapsulator->IsEnabled())
|
if(!fFirstEncapsulator->IsEnabled())
|
||||||
return fFirstEncapsulator->SendToNext();
|
return fFirstEncapsulator->SendToNext(packet, protocol);
|
||||||
|
|
||||||
return fFirstEncapsulator->Send(packet, protocol);
|
return fFirstEncapsulator->Send(packet, protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PPPInterface::Receive(mbuf *packet, uint16 protocol)
|
PPPInterface::Receive(struct mbuf *packet, uint16 protocol)
|
||||||
{
|
{
|
||||||
if(!packet)
|
if(!packet)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -877,20 +901,20 @@ PPPInterface::Receive(mbuf *packet, uint16 protocol)
|
|||||||
|
|
||||||
// maybe the parent interface can handle it
|
// maybe the parent interface can handle it
|
||||||
if(Parent())
|
if(Parent())
|
||||||
return Parent->Receive(packet, protocol);
|
return Parent()->Receive(packet, protocol);
|
||||||
|
|
||||||
if(result == PPP_UNHANDLED)
|
if(result == PPP_UNHANDLED) {
|
||||||
m_freem(packet);
|
m_freem(packet);
|
||||||
return PPP_DISCARDED;
|
return PPP_DISCARDED;
|
||||||
else {
|
} else {
|
||||||
StateMachine()->RUCEvent(packet, protocol);
|
StateMachine().RUCEvent(packet, protocol);
|
||||||
return PPP_REJECTED;
|
return PPP_REJECTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PPPInterface::SendToDevice(mbuf *packet, uint16 protocol)
|
PPPInterface::SendToDevice(struct mbuf *packet, uint16 protocol)
|
||||||
{
|
{
|
||||||
if(!packet)
|
if(!packet)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -930,7 +954,7 @@ PPPInterface::SendToDevice(mbuf *packet, uint16 protocol)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// encode in ppp frame
|
// encode in ppp frame
|
||||||
M_PREPEND(packet, sizeof(uint16));
|
M_PREPEND(packet, 2);
|
||||||
|
|
||||||
if(packet == NULL)
|
if(packet == NULL)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -945,7 +969,7 @@ PPPInterface::SendToDevice(mbuf *packet, uint16 protocol)
|
|||||||
// pass to device/children
|
// pass to device/children
|
||||||
if(!IsMultilink() || Parent()) {
|
if(!IsMultilink() || Parent()) {
|
||||||
// check if packet is too big for device
|
// check if packet is too big for device
|
||||||
if((packet->m_flags & M_PKTHDR && packet->m_pkthdr.len > LinkMTU())
|
if((packet->m_flags & M_PKTHDR && (uint32) packet->m_pkthdr.len > LinkMTU())
|
||||||
|| packet->m_len > LinkMTU()) {
|
|| packet->m_len > LinkMTU()) {
|
||||||
m_freem(packet);
|
m_freem(packet);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -961,7 +985,7 @@ PPPInterface::SendToDevice(mbuf *packet, uint16 protocol)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PPPInterface::ReceiveFromDevice(mbuf *packet)
|
PPPInterface::ReceiveFromDevice(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
if(!packet)
|
if(!packet)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -984,7 +1008,7 @@ PPPInterface::ReceiveFromDevice(mbuf *packet)
|
|||||||
if(packet->m_flags & M_PKTHDR)
|
if(packet->m_flags & M_PKTHDR)
|
||||||
packet->m_pkthdr.rcvif = Ifnet();
|
packet->m_pkthdr.rcvif = Ifnet();
|
||||||
|
|
||||||
return Receive(packet, protocol);
|
return Receive(packet, *protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1068,7 +1092,7 @@ PPPInterface::CalculateMRU()
|
|||||||
// sum all headers
|
// sum all headers
|
||||||
fHeaderLength = sizeof(uint16);
|
fHeaderLength = sizeof(uint16);
|
||||||
|
|
||||||
PPPEncapsulator encapsulator = fFirstEncapsulator;
|
PPPEncapsulator *encapsulator = fFirstEncapsulator;
|
||||||
for(; encapsulator; encapsulator = encapsulator->Next())
|
for(; encapsulator; encapsulator = encapsulator->Next())
|
||||||
fHeaderLength += encapsulator->Overhead();
|
fHeaderLength += encapsulator->Overhead();
|
||||||
|
|
||||||
@@ -1091,7 +1115,7 @@ PPPInterface::CalculateBaudRate()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(Device())
|
if(Device())
|
||||||
fIfnet->if_baudrate = max(Device()->InputTransferRate(),
|
fIfnet->if_baudrate = max_c(Device()->InputTransferRate(),
|
||||||
Device()->OutputTransferRate());
|
Device()->OutputTransferRate());
|
||||||
else {
|
else {
|
||||||
fIfnet->if_baudrate = 0;
|
fIfnet->if_baudrate = 0;
|
||||||
@@ -1110,8 +1134,8 @@ PPPInterface::Redial()
|
|||||||
|
|
||||||
// start a new thread that calls our Up() method
|
// start a new thread that calls our Up() method
|
||||||
redial_info *info = new redial_info;
|
redial_info *info = new redial_info;
|
||||||
info.interface = this;
|
info->interface = this;
|
||||||
info.thread = &fRedialThread;
|
info->thread = &fRedialThread;
|
||||||
|
|
||||||
fRedialThread = spawn_kernel_thread(redial_func, "PPPInterface: redial_thread",
|
fRedialThread = spawn_kernel_thread(redial_func, "PPPInterface: redial_thread",
|
||||||
B_NORMAL_PRIORITY, info);
|
B_NORMAL_PRIORITY, info);
|
||||||
@@ -1129,6 +1153,8 @@ redial_func(void *data)
|
|||||||
*info->thread = -1;
|
*info->thread = -1;
|
||||||
|
|
||||||
delete info;
|
delete info;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1137,7 +1163,7 @@ in_queue_thread(void *data)
|
|||||||
{
|
{
|
||||||
PPPInterface *interface = (PPPInterface*) data;
|
PPPInterface *interface = (PPPInterface*) data;
|
||||||
struct ifq *queue = interface->InQueue();
|
struct ifq *queue = interface->InQueue();
|
||||||
mbuf *packet;
|
struct mbuf *packet;
|
||||||
status_t error;
|
status_t error;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|||||||
@@ -5,7 +5,16 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPLCP.h"
|
#include <KPPPInterface.h>
|
||||||
|
#include <KPPPDevice.h>
|
||||||
|
#include <KPPPEncapsulator.h>
|
||||||
|
#include <KPPPOptionHandler.h>
|
||||||
|
|
||||||
|
#include <LockerHelper.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <mbuf.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
|
||||||
#define PPP_PROTOCOL_OVERHEAD 2
|
#define PPP_PROTOCOL_OVERHEAD 2
|
||||||
@@ -17,7 +26,7 @@
|
|||||||
PPPLCP::PPPLCP(PPPInterface& interface)
|
PPPLCP::PPPLCP(PPPInterface& interface)
|
||||||
: PPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL,
|
: PPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL,
|
||||||
AF_UNSPEC, &interface, NULL, PPP_ALWAYS_ALLOWED),
|
AF_UNSPEC, &interface, NULL, PPP_ALWAYS_ALLOWED),
|
||||||
fTarget(NULL)
|
fStateMachine(interface.StateMachine()), fTarget(NULL)
|
||||||
{
|
{
|
||||||
SetUpRequested(false);
|
SetUpRequested(false);
|
||||||
// the state machine does everything for us
|
// the state machine does everything for us
|
||||||
@@ -35,7 +44,7 @@ bool
|
|||||||
PPPLCP::AddOptionHandler(PPPOptionHandler *handler)
|
PPPLCP::AddOptionHandler(PPPOptionHandler *handler)
|
||||||
{
|
{
|
||||||
if(!handler)
|
if(!handler)
|
||||||
return false
|
return false;
|
||||||
|
|
||||||
LockerHelper locker(StateMachine().Locker());
|
LockerHelper locker(StateMachine().Locker());
|
||||||
|
|
||||||
@@ -43,7 +52,7 @@ PPPLCP::AddOptionHandler(PPPOptionHandler *handler)
|
|||||||
return false;
|
return false;
|
||||||
// a running connection may not change
|
// a running connection may not change
|
||||||
|
|
||||||
fOptionHandlers.AddItem(handler);
|
return fOptionHandlers.AddItem(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +74,7 @@ PPPLCP::OptionHandlerAt(int32 index) const
|
|||||||
{
|
{
|
||||||
PPPOptionHandler *handler = fOptionHandlers.ItemAt(index);
|
PPPOptionHandler *handler = fOptionHandlers.ItemAt(index);
|
||||||
|
|
||||||
if(handler == fOptionHandlers.DefaultItem())
|
if(handler == fOptionHandlers.GetDefaultItem())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
@@ -74,7 +83,7 @@ PPPLCP::OptionHandlerAt(int32 index) const
|
|||||||
uint32
|
uint32
|
||||||
PPPLCP::AdditionalOverhead() const
|
PPPLCP::AdditionalOverhead() const
|
||||||
{
|
{
|
||||||
uint32 overhead += PPP_PROTOCOL_OVERHEAD;
|
uint32 overhead = PPP_PROTOCOL_OVERHEAD;
|
||||||
|
|
||||||
if(Target())
|
if(Target())
|
||||||
overhead += Target()->Overhead();
|
overhead += Target()->Overhead();
|
||||||
@@ -88,17 +97,19 @@ PPPLCP::AdditionalOverhead() const
|
|||||||
bool
|
bool
|
||||||
PPPLCP::Up()
|
PPPLCP::Up()
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PPPLCP::Down()
|
PPPLCP::Down()
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PPPLCP::Send(mbuf *packet)
|
PPPLCP::Send(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
if(!Interface())
|
if(!Interface())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -108,12 +119,12 @@ PPPLCP::Send(mbuf *packet)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PPPLCP::Receive(mbuf *packet, uint16 protocol)
|
PPPLCP::Receive(struct mbuf *packet, uint16 protocol)
|
||||||
{
|
{
|
||||||
if(protocol != PPP_LCP_PROTOCOL)
|
if(protocol != PPP_LCP_PROTOCOL)
|
||||||
return PPP_UNHANDLED;
|
return PPP_UNHANDLED;
|
||||||
|
|
||||||
lcp_packet *data = mtod(packet, lcp_packet*);
|
ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*);
|
||||||
|
|
||||||
if(ntohs(data->length) < 4)
|
if(ntohs(data->length) < 4)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPOptionHandler.h"
|
#include <KPPPOptionHandler.h>
|
||||||
|
|
||||||
|
|
||||||
PPPOptionHandler::PPPOptionHandler(const char *name, PPPInterface *interface,
|
PPPOptionHandler::PPPOptionHandler(const char *name, PPPInterface *interface,
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPProtocol.h"
|
#include <KPPPInterface.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
PPPProtocol::PPPProtocol(const char *name, PPP_PHASE phase, uint16 protocol,
|
PPPProtocol::PPPProtocol(const char *name, PPP_PHASE phase, uint16 protocol,
|
||||||
@@ -50,7 +52,7 @@ PPPProtocol::SetEnabled(bool enabled = true)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(!enabled) {
|
if(!enabled) {
|
||||||
if(IsUp() || IsGoingUp()))
|
if(IsUp() || IsGoingUp())
|
||||||
Down();
|
Down();
|
||||||
} else if(!IsUp() && !IsGoingUp() && IsUpRequested() && Interface()->IsUp())
|
} else if(!IsUp() && !IsGoingUp() && IsUpRequested() && Interface()->IsUp())
|
||||||
Up();
|
Up();
|
||||||
|
|||||||
@@ -5,7 +5,12 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPReportManager.h"
|
#include <KPPPReportManager.h>
|
||||||
|
#include <LockerHelper.h>
|
||||||
|
|
||||||
|
#include "KPPPUtils.h"
|
||||||
|
|
||||||
|
#include <new.h>
|
||||||
|
|
||||||
|
|
||||||
PPPReportManager::PPPReportManager(BLocker& lock)
|
PPPReportManager::PPPReportManager(BLocker& lock)
|
||||||
@@ -14,16 +19,23 @@ PPPReportManager::PPPReportManager(BLocker& lock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PPPReportManager::~PPPReportManager()
|
||||||
|
{
|
||||||
|
for(int32 index = 0; index < fReportRequests.CountItems(); index++)
|
||||||
|
delete fReportRequests.ItemAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PPPReportManager::EnableReports(PPP_REPORT_TYPE type, thread_id thread,
|
PPPReportManager::EnableReports(PPP_REPORT_TYPE type, thread_id thread,
|
||||||
int32 flags = PPP_NO_REPORT_FLAGS)
|
int32 flags = PPP_NO_REPORT_FLAGS)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
ppp_report_request request;
|
ppp_report_request *request = new ppp_report_request;
|
||||||
request.type = type;
|
request->type = type;
|
||||||
request.thread = thread;
|
request->thread = thread;
|
||||||
request.flags = flags;
|
request->flags = flags;
|
||||||
|
|
||||||
fReportRequests.AddItem(request);
|
fReportRequests.AddItem(request);
|
||||||
}
|
}
|
||||||
@@ -34,14 +46,16 @@ PPPReportManager::DisableReports(PPP_REPORT_TYPE type, thread_id thread)
|
|||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
|
ppp_report_request *request;
|
||||||
|
|
||||||
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
|
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
|
||||||
ppp_report_request& request = fReportRequests.ItemAt(i);
|
request = fReportRequests.ItemAt(i);
|
||||||
|
|
||||||
if(request.thread != thread)
|
if(request->thread != thread)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(report.type == type)
|
if(request->type == type)
|
||||||
fReportRequest.RemoveItem(request);
|
fReportRequests.RemoveItem(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,10 +65,12 @@ PPPReportManager::DoesReport(PPP_REPORT_TYPE type, thread_id thread)
|
|||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
|
ppp_report_request *request;
|
||||||
|
|
||||||
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
|
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
|
||||||
ppp_report_request& request = fReportRequests.ItemAt(i);
|
request = fReportRequests.ItemAt(i);
|
||||||
|
|
||||||
if(request.thread == thread && request.type == type)
|
if(request->thread == thread && request->type == type)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,20 +92,22 @@ PPPReportManager::Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 len
|
|||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
int32 code, query, result;
|
status_t result;
|
||||||
thread_id sender;
|
thread_id sender;
|
||||||
bool acceptable = true;
|
bool acceptable = true;
|
||||||
|
|
||||||
report_packet report;
|
ppp_report_packet report;
|
||||||
report.type = type;
|
report.type = type;
|
||||||
report.code = code;
|
report.code = code;
|
||||||
report.length = length;
|
report.length = length;
|
||||||
memcpy(report.data, data, length);
|
memcpy(report.data, data, length);
|
||||||
|
|
||||||
|
ppp_report_request *request;
|
||||||
|
|
||||||
for(int32 index = 0; index < fReportRequests.CountItems(); index++) {
|
for(int32 index = 0; index < fReportRequests.CountItems(); index++) {
|
||||||
ppp_report_request& request = fReportRequests.ItemAt(index);
|
request = fReportRequests.ItemAt(index);
|
||||||
|
|
||||||
result = send_data_with_timeout(request.thread, PPP_REPORT_CODE, &report,
|
result = send_data_with_timeout(request->thread, PPP_REPORT_CODE, &report,
|
||||||
sizeof(report), PPP_REPORT_TIMEOUT);
|
sizeof(report), PPP_REPORT_TIMEOUT);
|
||||||
|
|
||||||
if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) {
|
if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) {
|
||||||
@@ -97,16 +115,16 @@ PPPReportManager::Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 len
|
|||||||
--index;
|
--index;
|
||||||
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) {
|
||||||
if(request.flags & PPP_NO_REPLY_TIMEOUT) {
|
if(request->flags & PPP_NO_REPLY_TIMEOUT) {
|
||||||
sender = -1;
|
sender = -1;
|
||||||
while(sender != request.thread)
|
while(sender != request->thread)
|
||||||
code = receive_data(&sender, NULL, 0);
|
code = receive_data(&sender, NULL, 0);
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
} else {
|
} else {
|
||||||
sender = -1;
|
sender = -1;
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
while(sender != request.thread && result == B_OK)
|
while(sender != request->thread && result == B_OK)
|
||||||
result = receive_data_with_timeout(&sender, &code, NULL, 0,
|
result = receive_data_with_timeout(&sender, &code, NULL, 0,
|
||||||
PPP_REPORT_TIMEOUT);
|
PPP_REPORT_TIMEOUT);
|
||||||
}
|
}
|
||||||
@@ -116,7 +134,7 @@ PPPReportManager::Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 len
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(request.flags & PPP_REMOVE_AFTER_REPORT) {
|
if(request->flags & PPP_REMOVE_AFTER_REPORT) {
|
||||||
fReportRequests.RemoveItem(request);
|
fReportRequests.RemoveItem(request);
|
||||||
--index;
|
--index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,28 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPStateMachine.h"
|
#include <OS.h>
|
||||||
|
|
||||||
|
#include <KPPPInterface.h>
|
||||||
|
#include <KPPPConfigurePacket.h>
|
||||||
|
#include <KPPPDevice.h>
|
||||||
|
#include <KPPPEncapsulator.h>
|
||||||
|
#include <KPPPOptionHandler.h>
|
||||||
|
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <mbuf.h>
|
||||||
|
|
||||||
|
|
||||||
#define PPP_STATE_MACHINE_TIMEOUT 3000000
|
#define PPP_STATE_MACHINE_TIMEOUT 3000000
|
||||||
|
|
||||||
|
|
||||||
PPPStateMachine::PPPStateMachine(PPPInterface& interface)
|
PPPStateMachine::PPPStateMachine(PPPInterface& interface)
|
||||||
: fInterface(&interface), fPhase(PPP_DOWN_PHASE),
|
: fInterface(&interface), fLCP(interface.LCP()), fPhase(PPP_DOWN_PHASE),
|
||||||
fState(PPP_INITIAL_STATE), fID(system_time() & 0xFF),
|
fState(PPP_INITIAL_STATE), fID(system_time() & 0xFF),
|
||||||
fAuthenticationStatus(PPP_NOT_AUTHENTICATED),
|
fAuthenticationStatus(PPP_NOT_AUTHENTICATED),
|
||||||
fPeerAuthenticationStatus(PPP_NOT_AUTHENTICATED),
|
fPeerAuthenticationStatus(PPP_NOT_AUTHENTICATED),
|
||||||
fAuthenticationName(NULL), fPeerAuthenticationName(NULL),
|
fAuthenticationName(NULL), fPeerAuthenticationName(NULL),
|
||||||
fMaxTerminate(2), fMaxConfigure(10), fMaxNak(5),
|
fMaxRequest(10), fMaxTerminate(2), fMaxNak(5),
|
||||||
fRequestID(0), fTerminateID(0), fNextTimeout(0)
|
fRequestID(0), fTerminateID(0), fNextTimeout(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -100,7 +109,8 @@ PPPStateMachine::AuthenticationAccepted(const char *name)
|
|||||||
free(fAuthenticationName);
|
free(fAuthenticationName);
|
||||||
fAuthenticationName = strdup(name);
|
fAuthenticationName = strdup(name);
|
||||||
|
|
||||||
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_AUTHENTICATION_SUCCESSFUL, 0);
|
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_AUTHENTICATION_SUCCESSFUL,
|
||||||
|
NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -115,15 +125,6 @@ PPPStateMachine::AuthenticationDenied(const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
PPPStateMachine::AuthenticationName() const
|
|
||||||
{
|
|
||||||
LockerHelper locker(fLock);
|
|
||||||
|
|
||||||
return fAuthenticationName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PPPStateMachine::PeerAuthenticationRequested()
|
PPPStateMachine::PeerAuthenticationRequested()
|
||||||
{
|
{
|
||||||
@@ -145,7 +146,7 @@ PPPStateMachine::PeerAuthenticationAccepted(const char *name)
|
|||||||
fPeerAuthenticationName = strdup(name);
|
fPeerAuthenticationName = strdup(name);
|
||||||
|
|
||||||
Interface()->Report(PPP_CONNECTION_REPORT,
|
Interface()->Report(PPP_CONNECTION_REPORT,
|
||||||
PPP_REPORT_PEER_AUTHENTICATION_SUCCESSFUL, 0);
|
PPP_REPORT_PEER_AUTHENTICATION_SUCCESSFUL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -157,15 +158,8 @@ PPPStateMachine::PeerAuthenticationDenied(const char *name)
|
|||||||
fPeerAuthenticationStatus = PPP_AUTHENTICATION_FAILED;
|
fPeerAuthenticationStatus = PPP_AUTHENTICATION_FAILED;
|
||||||
free(fPeerAuthenticationName);
|
free(fPeerAuthenticationName);
|
||||||
fPeerAuthenticationName = strdup(name);
|
fPeerAuthenticationName = strdup(name);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
PPPStateMachine::PeerAuthenticationName() const
|
|
||||||
{
|
|
||||||
LockerHelper locker(fLock);
|
|
||||||
|
|
||||||
return fPeerAuthenticationName;
|
CloseEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -387,7 +381,7 @@ PPPStateMachine::UpEvent()
|
|||||||
|
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
if(!Interface()->Device() || !Interface()->Device->IsUp())
|
if(!Interface()->Device() || !Interface()->Device()->IsUp())
|
||||||
return;
|
return;
|
||||||
// it is not our device that went up...
|
// it is not our device that went up...
|
||||||
|
|
||||||
@@ -395,7 +389,7 @@ PPPStateMachine::UpEvent()
|
|||||||
|
|
||||||
switch(State()) {
|
switch(State()) {
|
||||||
case PPP_INITIAL_STATE:
|
case PPP_INITIAL_STATE:
|
||||||
if(Mode() != PPP_SERVER_MODE
|
if(Interface()->Mode() != PPP_SERVER_MODE
|
||||||
|| Phase() != PPP_ESTABLISHMENT_PHASE) {
|
|| Phase() != PPP_ESTABLISHMENT_PHASE) {
|
||||||
// we are a client or we do not listen for an incoming
|
// we are a client or we do not listen for an incoming
|
||||||
// connection, so this is an illegal event
|
// connection, so this is an illegal event
|
||||||
@@ -444,7 +438,7 @@ PPPStateMachine::DownEvent()
|
|||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
if(Interface()->Device() && Interface()->Device->IsUp())
|
if(Interface()->Device() && Interface()->Device()->IsUp())
|
||||||
return;
|
return;
|
||||||
// it is not our device that went up...
|
// it is not our device that went up...
|
||||||
|
|
||||||
@@ -489,7 +483,7 @@ PPPStateMachine::DownEvent()
|
|||||||
if(State() == PPP_STARTING_STATE) {
|
if(State() == PPP_STARTING_STATE) {
|
||||||
bool needsRedial = false;
|
bool needsRedial = false;
|
||||||
|
|
||||||
if(fAuthentiactionStatus == PPP_AUTHENTICATION_FAILED
|
if(fAuthenticationStatus == PPP_AUTHENTICATION_FAILED
|
||||||
|| fAuthenticationStatus == PPP_AUTHENTICATING
|
|| fAuthenticationStatus == PPP_AUTHENTICATING
|
||||||
|| fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED
|
|| fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED
|
||||||
|| fPeerAuthenticationStatus == PPP_AUTHENTICATING)
|
|| fPeerAuthenticationStatus == PPP_AUTHENTICATING)
|
||||||
@@ -569,6 +563,10 @@ PPPStateMachine::OpenEvent()
|
|||||||
|
|
||||||
case PPP_CLOSING_STATE:
|
case PPP_CLOSING_STATE:
|
||||||
NewState(PPP_STOPPING_STATE);
|
NewState(PPP_STOPPING_STATE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,6 +626,9 @@ PPPStateMachine::CloseEvent()
|
|||||||
case PPP_STOPPED_STATE:
|
case PPP_STOPPED_STATE:
|
||||||
NewState(PPP_STOPPED_STATE);
|
NewState(PPP_STOPPED_STATE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,7 +693,7 @@ PPPStateMachine::TOBadEvent()
|
|||||||
|
|
||||||
// receive configure request (acceptable request)
|
// receive configure request (acceptable request)
|
||||||
void
|
void
|
||||||
PPPStateMachine::RCRGoodEvent(mbuf *packet)
|
PPPStateMachine::RCRGoodEvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
@@ -704,7 +705,7 @@ PPPStateMachine::RCRGoodEvent(mbuf *packet)
|
|||||||
|
|
||||||
case PPP_CLOSED_STATE:
|
case PPP_CLOSED_STATE:
|
||||||
locker.UnlockNow();
|
locker.UnlockNow();
|
||||||
SendTerminateAck();
|
SendTerminateAck(packet);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPP_STOPPED_STATE:
|
case PPP_STOPPED_STATE:
|
||||||
@@ -737,13 +738,16 @@ PPPStateMachine::RCRGoodEvent(mbuf *packet)
|
|||||||
SendConfigureRequest();
|
SendConfigureRequest();
|
||||||
SendConfigureAck(packet);
|
SendConfigureAck(packet);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// receive configure request (unacceptable request)
|
// receive configure request (unacceptable request)
|
||||||
void
|
void
|
||||||
PPPStateMachine::RCRBadEvent(mbuf *nak, mbuf *reject)
|
PPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
@@ -755,7 +759,7 @@ PPPStateMachine::RCRBadEvent(mbuf *nak, mbuf *reject)
|
|||||||
|
|
||||||
case PPP_CLOSED_STATE:
|
case PPP_CLOSED_STATE:
|
||||||
locker.UnlockNow();
|
locker.UnlockNow();
|
||||||
SendTerminateAck();
|
SendTerminateAck(NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPP_STOPPED_STATE:
|
case PPP_STOPPED_STATE:
|
||||||
@@ -779,22 +783,25 @@ PPPStateMachine::RCRBadEvent(mbuf *nak, mbuf *reject)
|
|||||||
case PPP_REQ_SENT_STATE:
|
case PPP_REQ_SENT_STATE:
|
||||||
case PPP_ACK_RCVD_STATE:
|
case PPP_ACK_RCVD_STATE:
|
||||||
locker.UnlockNow();
|
locker.UnlockNow();
|
||||||
if(!nak && ntohs(mtod(nak, lcp_packet*)->length) > 3)
|
if(nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3)
|
||||||
SendConfigureNak(nak);
|
SendConfigureNak(nak);
|
||||||
else if(!reject && ntohs(mtod(reject, lcp_packet*)->length) > 3)
|
else if(reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3)
|
||||||
SendConfigureNak(reject);
|
SendConfigureNak(reject);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// receive configure ack
|
// receive configure ack
|
||||||
void
|
void
|
||||||
PPPStateMachine::RCAEvent(mbuf *packet)
|
PPPStateMachine::RCAEvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
if(fRequestID != mtod(packet, lcp_packet*)->id) {
|
if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) {
|
||||||
// this packet is not a reply to our request
|
// this packet is not a reply to our request
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
@@ -807,7 +814,7 @@ PPPStateMachine::RCAEvent(mbuf *packet)
|
|||||||
|
|
||||||
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) {
|
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) {
|
||||||
handler = LCP().OptionHandlerAt(index);
|
handler = LCP().OptionHandlerAt(index);
|
||||||
handler->ParseAck(ack);
|
handler->ParseAck(&ack);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(State()) {
|
switch(State()) {
|
||||||
@@ -819,7 +826,7 @@ PPPStateMachine::RCAEvent(mbuf *packet)
|
|||||||
case PPP_CLOSED_STATE:
|
case PPP_CLOSED_STATE:
|
||||||
case PPP_STOPPED_STATE:
|
case PPP_STOPPED_STATE:
|
||||||
locker.UnlockNow();
|
locker.UnlockNow();
|
||||||
SendTerminateAck();
|
SendTerminateAck(NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPP_REQ_SENT_STATE:
|
case PPP_REQ_SENT_STATE:
|
||||||
@@ -848,17 +855,20 @@ PPPStateMachine::RCAEvent(mbuf *packet)
|
|||||||
ThisLayerDown();
|
ThisLayerDown();
|
||||||
SendConfigureRequest();
|
SendConfigureRequest();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// receive configure nak/reject
|
// receive configure nak/reject
|
||||||
void
|
void
|
||||||
PPPStateMachine::RCNEvent(mbuf *packet)
|
PPPStateMachine::RCNEvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
if(fRequestID != mtod(packet, lcp_packet*)->id) {
|
if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) {
|
||||||
// this packet is not a reply to our request
|
// this packet is not a reply to our request
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
@@ -873,9 +883,9 @@ PPPStateMachine::RCNEvent(mbuf *packet)
|
|||||||
handler = LCP().OptionHandlerAt(index);
|
handler = LCP().OptionHandlerAt(index);
|
||||||
|
|
||||||
if(nak_reject.Code() == PPP_CONFIGURE_NAK)
|
if(nak_reject.Code() == PPP_CONFIGURE_NAK)
|
||||||
handler->ParseNak(nak_reject);
|
handler->ParseNak(&nak_reject);
|
||||||
else if(nak_reject.Code() == PPP_CONFIGURE_REJECT)
|
else if(nak_reject.Code() == PPP_CONFIGURE_REJECT)
|
||||||
handler->ParseReject(nak_reject);
|
handler->ParseReject(&nak_reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(State()) {
|
switch(State()) {
|
||||||
@@ -887,7 +897,7 @@ PPPStateMachine::RCNEvent(mbuf *packet)
|
|||||||
case PPP_CLOSED_STATE:
|
case PPP_CLOSED_STATE:
|
||||||
case PPP_STOPPED_STATE:
|
case PPP_STOPPED_STATE:
|
||||||
locker.UnlockNow();
|
locker.UnlockNow();
|
||||||
SendTermintateAck(packet);
|
SendTerminateAck(packet);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPP_REQ_SENT_STATE:
|
case PPP_REQ_SENT_STATE:
|
||||||
@@ -909,18 +919,21 @@ PPPStateMachine::RCNEvent(mbuf *packet)
|
|||||||
ThisLayerDown();
|
ThisLayerDown();
|
||||||
SendConfigureRequest();
|
SendConfigureRequest();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// receive terminate request
|
// receive terminate request
|
||||||
void
|
void
|
||||||
PPPStateMachine::RTREvent(mbuf *packet)
|
PPPStateMachine::RTREvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
// we should not use the same ID as the peer
|
// we should not use the same ID as the peer
|
||||||
if(fID == mtod(packet, lcp_packet*)->id)
|
if(fID == mtod(packet, ppp_lcp_packet*)->id)
|
||||||
fID -= 128;
|
fID -= 128;
|
||||||
|
|
||||||
fAuthenticationStatus = PPP_NOT_AUTHENTICATED;
|
fAuthenticationStatus = PPP_NOT_AUTHENTICATED;
|
||||||
@@ -962,11 +975,11 @@ PPPStateMachine::RTREvent(mbuf *packet)
|
|||||||
|
|
||||||
// receive terminate ack
|
// receive terminate ack
|
||||||
void
|
void
|
||||||
PPPStateMachine::RTAEvent(mbuf *packet)
|
PPPStateMachine::RTAEvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
if(fTerminateID != mtod(packet, lcp_packet*)->id) {
|
if(fTerminateID != mtod(packet, ppp_lcp_packet*)->id) {
|
||||||
// this packet is not a reply to our request
|
// this packet is not a reply to our request
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
@@ -986,14 +999,14 @@ PPPStateMachine::RTAEvent(mbuf *packet)
|
|||||||
ThisLayerFinished();
|
ThisLayerFinished();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPP_CLOSING_STATE:
|
case PPP_STOPPING_STATE:
|
||||||
NewState(PPP_STOPPED_STATE);
|
NewState(PPP_STOPPED_STATE);
|
||||||
locker.UnlockNow();
|
locker.UnlockNow();
|
||||||
ThisLayerFinished();
|
ThisLayerFinished();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPP_ACK_RCVD_STATE:
|
case PPP_ACK_RCVD_STATE:
|
||||||
NewState(REQ_SENT_STATE);
|
NewState(PPP_REQ_SENT_STATE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPP_OPENED_STATE:
|
case PPP_OPENED_STATE:
|
||||||
@@ -1002,13 +1015,16 @@ PPPStateMachine::RTAEvent(mbuf *packet)
|
|||||||
ThisLayerDown();
|
ThisLayerDown();
|
||||||
SendConfigureRequest();
|
SendConfigureRequest();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// receive unknown code
|
// receive unknown code
|
||||||
void
|
void
|
||||||
PPPStateMachine::RUCEvent(mbuf *packet, uint16 protocol, uint8 type = PPP_PROTOCOL_REJECT)
|
PPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocol, uint8 type = PPP_PROTOCOL_REJECT)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
@@ -1027,7 +1043,7 @@ PPPStateMachine::RUCEvent(mbuf *packet, uint16 protocol, uint8 type = PPP_PROTOC
|
|||||||
|
|
||||||
// receive code/protocol reject (acceptable such as IPX reject)
|
// receive code/protocol reject (acceptable such as IPX reject)
|
||||||
void
|
void
|
||||||
PPPStateMachine::RXJGoodEvent(mbuf *packet)
|
PPPStateMachine::RXJGoodEvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
@@ -1040,20 +1056,23 @@ PPPStateMachine::RXJGoodEvent(mbuf *packet)
|
|||||||
case PPP_ACK_RCVD_STATE:
|
case PPP_ACK_RCVD_STATE:
|
||||||
NewState(PPP_REQ_SENT_STATE);
|
NewState(PPP_REQ_SENT_STATE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// receive code/protocol reject (catastrophic such as LCP reject)
|
// receive code/protocol reject (catastrophic such as LCP reject)
|
||||||
void
|
void
|
||||||
PPPStateMachine::RXJBadEvent(mbuf *packet)
|
PPPStateMachine::RXJBadEvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
LockerHelper locker(fLock);
|
LockerHelper locker(fLock);
|
||||||
|
|
||||||
switch(State()) {
|
switch(State()) {
|
||||||
case PPP_INITIAL_STATE:
|
case PPP_INITIAL_STATE:
|
||||||
case PPP_STARTING_STATE:
|
case PPP_STARTING_STATE:
|
||||||
IllegalEvent(PPP_RJX_BAD_EVENT);
|
IllegalEvent(PPP_RXJ_BAD_EVENT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPP_CLOSING_STATE:
|
case PPP_CLOSING_STATE:
|
||||||
@@ -1088,9 +1107,9 @@ PPPStateMachine::RXJBadEvent(mbuf *packet)
|
|||||||
|
|
||||||
// receive echo request/reply, discard request
|
// receive echo request/reply, discard request
|
||||||
void
|
void
|
||||||
PPPStateMachine::RXREvent(mbuf *packet)
|
PPPStateMachine::RXREvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
lcp_packet *echo = mtod(mbuf, lcp_packet*);
|
ppp_lcp_packet *echo = mtod(packet, ppp_lcp_packet*);
|
||||||
|
|
||||||
switch(State()) {
|
switch(State()) {
|
||||||
case PPP_INITIAL_STATE:
|
case PPP_INITIAL_STATE:
|
||||||
@@ -1102,6 +1121,9 @@ PPPStateMachine::RXREvent(mbuf *packet)
|
|||||||
if(echo->code == PPP_ECHO_REQUEST)
|
if(echo->code == PPP_ECHO_REQUEST)
|
||||||
SendEchoReply(packet);
|
SendEchoReply(packet);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1118,7 +1140,7 @@ PPPStateMachine::TimerEvent()
|
|||||||
|
|
||||||
switch(State()) {
|
switch(State()) {
|
||||||
case PPP_CLOSING_STATE:
|
case PPP_CLOSING_STATE:
|
||||||
case PPP_STOPPTING_STATE:
|
case PPP_STOPPING_STATE:
|
||||||
if(fTerminateCounter <= 0)
|
if(fTerminateCounter <= 0)
|
||||||
TOBadEvent();
|
TOBadEvent();
|
||||||
else
|
else
|
||||||
@@ -1128,11 +1150,14 @@ PPPStateMachine::TimerEvent()
|
|||||||
case PPP_REQ_SENT_STATE:
|
case PPP_REQ_SENT_STATE:
|
||||||
case PPP_ACK_RCVD_STATE:
|
case PPP_ACK_RCVD_STATE:
|
||||||
case PPP_ACK_SENT_STATE:
|
case PPP_ACK_SENT_STATE:
|
||||||
if(fConfigureCounter <= 0)
|
if(fRequestCounter <= 0)
|
||||||
TOBadEvent();
|
TOBadEvent();
|
||||||
else
|
else
|
||||||
TOGoodEvent();
|
TOGoodEvent();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1142,14 +1167,14 @@ PPPStateMachine::TimerEvent()
|
|||||||
// Here we get a configure-request packet from LCP and aks all OptionHandlers
|
// Here we get a configure-request packet from LCP and aks all OptionHandlers
|
||||||
// if its values are acceptable. From here we call our Good/Bad counterparts.
|
// if its values are acceptable. From here we call our Good/Bad counterparts.
|
||||||
void
|
void
|
||||||
PPPStateMachine::RCREvent(mbuf *packet)
|
PPPStateMachine::RCREvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
PPPConfigurePacket request(packet), nak(PPP_CONFIGURE_NAK),
|
PPPConfigurePacket request(packet), nak(PPP_CONFIGURE_NAK),
|
||||||
reject(PPP_CONFIGURE_REJECT);
|
reject(PPP_CONFIGURE_REJECT);
|
||||||
PPPOptionHandler *handler;
|
PPPOptionHandler *handler;
|
||||||
|
|
||||||
// we should not use the same id as the peer
|
// we should not use the same id as the peer
|
||||||
if(fID == mtod(packet, lcp_packet*)->id)
|
if(fID == mtod(packet, ppp_lcp_packet*)->id)
|
||||||
fID -= 128;
|
fID -= 128;
|
||||||
|
|
||||||
nak.SetID(request.ID());
|
nak.SetID(request.ID());
|
||||||
@@ -1169,14 +1194,14 @@ PPPStateMachine::RCREvent(mbuf *packet)
|
|||||||
index++) {
|
index++) {
|
||||||
handler = LCP().OptionHandlerAt(index);
|
handler = LCP().OptionHandlerAt(index);
|
||||||
error = handler->ParseRequest(&request, item, &nak, &reject);
|
error = handler->ParseRequest(&request, item, &nak, &reject);
|
||||||
if(error == PPP_UNHANLED)
|
if(error == PPP_UNHANDLED)
|
||||||
continue;
|
continue;
|
||||||
else if(error == B_ERROR) {
|
else if(error == B_ERROR) {
|
||||||
// the request contains a value that has been sent more than
|
// the request contains a value that has been sent more than
|
||||||
// once or the value is corrupted
|
// once or the value is corrupted
|
||||||
CloseEvent();
|
CloseEvent();
|
||||||
return;
|
return;
|
||||||
} else if(error = B_OK)
|
} else if(error == B_OK)
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1188,7 +1213,7 @@ PPPStateMachine::RCREvent(mbuf *packet)
|
|||||||
|
|
||||||
if(nak.CountItems() > 0)
|
if(nak.CountItems() > 0)
|
||||||
RCRBadEvent(nak.ToMbuf(LCP().AdditionalOverhead()), NULL);
|
RCRBadEvent(nak.ToMbuf(LCP().AdditionalOverhead()), NULL);
|
||||||
else if(reject.CountItmes() > 0)
|
else if(reject.CountItems() > 0)
|
||||||
RCRBadEvent(NULL, reject.ToMbuf(LCP().AdditionalOverhead()));
|
RCRBadEvent(NULL, reject.ToMbuf(LCP().AdditionalOverhead()));
|
||||||
else
|
else
|
||||||
RCRGoodEvent(packet);
|
RCRGoodEvent(packet);
|
||||||
@@ -1199,9 +1224,9 @@ PPPStateMachine::RCREvent(mbuf *packet)
|
|||||||
// LCP received a code/protocol-reject packet and we look if it is acceptable.
|
// LCP received a code/protocol-reject packet and we look if it is acceptable.
|
||||||
// From here we call our Good/Bad counterparts.
|
// From here we call our Good/Bad counterparts.
|
||||||
void
|
void
|
||||||
PPPStateMachine::RXJEvent(mbuf *packet)
|
PPPStateMachine::RXJEvent(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
lcp_packet *reject mtod(packet, lcp_packet*);
|
ppp_lcp_packet *reject mtod(packet, ppp_lcp_packet*);
|
||||||
|
|
||||||
if(reject->code == PPP_CODE_REJECT) {
|
if(reject->code == PPP_CODE_REJECT) {
|
||||||
// we only have basic codes, so there must be something wrong
|
// we only have basic codes, so there must be something wrong
|
||||||
@@ -1304,7 +1329,7 @@ PPPStateMachine::ThisLayerFinished()
|
|||||||
void
|
void
|
||||||
PPPStateMachine::InitializeRestartCount()
|
PPPStateMachine::InitializeRestartCount()
|
||||||
{
|
{
|
||||||
fConfigureCounter = fMaxConfigure;
|
fRequestCounter = fMaxRequest;
|
||||||
fTerminateCounter = fMaxTerminate;
|
fTerminateCounter = fMaxTerminate;
|
||||||
fNakCounter = fMaxNak;
|
fNakCounter = fMaxNak;
|
||||||
|
|
||||||
@@ -1316,7 +1341,7 @@ PPPStateMachine::InitializeRestartCount()
|
|||||||
void
|
void
|
||||||
PPPStateMachine::ZeroRestartCount()
|
PPPStateMachine::ZeroRestartCount()
|
||||||
{
|
{
|
||||||
fConfigureCounter = 0;
|
fRequestCounter = 0;
|
||||||
fTerminateCounter = 0;
|
fTerminateCounter = 0;
|
||||||
fNakCounter = 0;
|
fNakCounter = 0;
|
||||||
|
|
||||||
@@ -1328,11 +1353,11 @@ PPPStateMachine::ZeroRestartCount()
|
|||||||
void
|
void
|
||||||
PPPStateMachine::SendConfigureRequest()
|
PPPStateMachine::SendConfigureRequest()
|
||||||
{
|
{
|
||||||
--fConfigureCounter;
|
--fRequestCounter;
|
||||||
|
|
||||||
PPPConfigurePacket request(PPP_CONFIGURE_REQUEST);
|
PPPConfigurePacket request(PPP_CONFIGURE_REQUEST);
|
||||||
request.SetID(NextID());
|
request.SetID(NextID());
|
||||||
fConfigureID = request.ID();
|
fRequestID = request.ID();
|
||||||
|
|
||||||
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) {
|
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) {
|
||||||
// add all items
|
// add all items
|
||||||
@@ -1347,12 +1372,12 @@ PPPStateMachine::SendConfigureRequest()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PPPStateMachine::SendConfigureAck(mbuf *packet)
|
PPPStateMachine::SendConfigureAck(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
mtod(packet, lcp_packet*)->code = PPP_CONFIGURE_ACK;
|
mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK;
|
||||||
PPPConfigurePacket ack(packet);
|
PPPConfigurePacket ack(packet);
|
||||||
|
|
||||||
for(int32 index = 0; index < LCP().CountOptionHandlers; index++)
|
for(int32 index = 0; index < LCP().CountOptionHandlers(); index++)
|
||||||
LCP().OptionHandlerAt(index)->SendingAck(&ack);
|
LCP().OptionHandlerAt(index)->SendingAck(&ack);
|
||||||
|
|
||||||
LCP().Send(packet);
|
LCP().Send(packet);
|
||||||
@@ -1360,9 +1385,9 @@ PPPStateMachine::SendConfigureAck(mbuf *packet)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PPPStateMachine::SendConfigureNak(mbuf *packet)
|
PPPStateMachine::SendConfigureNak(struct mbuf *packet)
|
||||||
{
|
{
|
||||||
lcp_packet *nak = mtod(packet, lcp_packet*);
|
ppp_lcp_packet *nak = mtod(packet, ppp_lcp_packet*);
|
||||||
if(nak->code == PPP_CONFIGURE_NAK) {
|
if(nak->code == PPP_CONFIGURE_NAK) {
|
||||||
if(fNakCounter == 0) {
|
if(fNakCounter == 0) {
|
||||||
// We sent enough naks. Let's try a reject.
|
// We sent enough naks. Let's try a reject.
|
||||||
@@ -1378,7 +1403,7 @@ PPPStateMachine::SendConfigureNak(mbuf *packet)
|
|||||||
void
|
void
|
||||||
PPPStateMachine::SendTerminateRequest()
|
PPPStateMachine::SendTerminateRequest()
|
||||||
{
|
{
|
||||||
mbuf *m = m_gethdr(MT_DATA);
|
struct mbuf *m = m_gethdr(MT_DATA);
|
||||||
if(!m)
|
if(!m)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1389,7 +1414,7 @@ PPPStateMachine::SendTerminateRequest()
|
|||||||
// reserve some space for other protocols
|
// reserve some space for other protocols
|
||||||
m->m_data += LCP().AdditionalOverhead();
|
m->m_data += LCP().AdditionalOverhead();
|
||||||
|
|
||||||
lcp_packet *request = mtod(m, lcp_packet*);
|
ppp_lcp_packet *request = mtod(m, ppp_lcp_packet*);
|
||||||
request->code = PPP_TERMINATE_REQUEST;
|
request->code = PPP_TERMINATE_REQUEST;
|
||||||
request->id = fTerminateID = NextID();
|
request->id = fTerminateID = NextID();
|
||||||
request->length = htons(4);
|
request->length = htons(4);
|
||||||
@@ -1399,18 +1424,34 @@ PPPStateMachine::SendTerminateRequest()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PPPStateMachine::SendTerminateAck(mbuf *request)
|
PPPStateMachine::SendTerminateAck(struct mbuf *request)
|
||||||
{
|
{
|
||||||
lcp_packet *ack = mtod(request, lcp_packet*);
|
struct mbuf *reply = request;
|
||||||
reply->code = PPP_TERMINATE_ACK;
|
|
||||||
// the request becomes an ack
|
|
||||||
|
|
||||||
LCP().Send(request);
|
ppp_lcp_packet *ack;
|
||||||
|
|
||||||
|
if(!reply) {
|
||||||
|
reply = m_gethdr(MT_DATA);
|
||||||
|
if(!reply)
|
||||||
|
return;
|
||||||
|
|
||||||
|
reply->m_data += LCP().AdditionalOverhead();
|
||||||
|
reply->m_len = 4;
|
||||||
|
|
||||||
|
ack = mtod(reply, ppp_lcp_packet*);
|
||||||
|
ack->id = NextID();
|
||||||
|
ack->length = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
ack = mtod(reply, ppp_lcp_packet*);
|
||||||
|
ack->code = PPP_TERMINATE_ACK;
|
||||||
|
|
||||||
|
LCP().Send(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PPPStateMachine::SendCodeReject(mbuf *packet, uint16 protocol, uint8 type)
|
PPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocol, uint8 type)
|
||||||
{
|
{
|
||||||
int32 length;
|
int32 length;
|
||||||
// additional space needed for this reject
|
// additional space needed for this reject
|
||||||
@@ -1422,7 +1463,7 @@ PPPStateMachine::SendCodeReject(mbuf *packet, uint16 protocol, uint8 type)
|
|||||||
int32 adjust = 0;
|
int32 adjust = 0;
|
||||||
// adjust packet size by this value if packet is too big
|
// adjust packet size by this value if packet is too big
|
||||||
if(packet->m_flags & M_PKTHDR) {
|
if(packet->m_flags & M_PKTHDR) {
|
||||||
if(packet->m_pkthdr.len > Interface()->LinkMTU())
|
if((uint32) packet->m_pkthdr.len > Interface()->LinkMTU())
|
||||||
adjust = Interface()->LinkMTU() - packet->m_pkthdr.len;
|
adjust = Interface()->LinkMTU() - packet->m_pkthdr.len;
|
||||||
} else if(packet->m_len > Interface()->LinkMTU())
|
} else if(packet->m_len > Interface()->LinkMTU())
|
||||||
adjust = Interface()->LinkMTU() - packet->m_len;
|
adjust = Interface()->LinkMTU() - packet->m_len;
|
||||||
@@ -1430,7 +1471,7 @@ PPPStateMachine::SendCodeReject(mbuf *packet, uint16 protocol, uint8 type)
|
|||||||
if(adjust != 0)
|
if(adjust != 0)
|
||||||
m_adj(packet, adjust);
|
m_adj(packet, adjust);
|
||||||
|
|
||||||
lcp_packet *reject = mtod(packet, lcp_packet*);
|
ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*);
|
||||||
reject->code = type;
|
reject->code = type;
|
||||||
reject->id = NextID();
|
reject->id = NextID();
|
||||||
if(packet->m_flags & M_PKTHDR)
|
if(packet->m_flags & M_PKTHDR)
|
||||||
@@ -1440,16 +1481,16 @@ PPPStateMachine::SendCodeReject(mbuf *packet, uint16 protocol, uint8 type)
|
|||||||
|
|
||||||
protocol = htons(protocol);
|
protocol = htons(protocol);
|
||||||
if(type == PPP_PROTOCOL_REJECT)
|
if(type == PPP_PROTOCOL_REJECT)
|
||||||
memcpy(&data->data, &protocol, sizeof(protocol));
|
memcpy(&reject->data, &protocol, sizeof(protocol));
|
||||||
|
|
||||||
LCP().Send(packet);
|
LCP().Send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PPPStateMachine::SendEchoReply(mbuf *request)
|
PPPStateMachine::SendEchoReply(struct mbuf *request)
|
||||||
{
|
{
|
||||||
lcp_packet *reply = mtod(request, lcp_packet*);
|
ppp_lcp_packet *reply = mtod(request, ppp_lcp_packet*);
|
||||||
reply->code = PPP_ECHO_REPLY;
|
reply->code = PPP_ECHO_REPLY;
|
||||||
// the request becomes a reply
|
// the request becomes a reply
|
||||||
|
|
||||||
@@ -1478,7 +1519,7 @@ PPPStateMachine::BringHandlersUp()
|
|||||||
|
|
||||||
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_UP_SUCCESSFUL, NULL, 0);
|
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_UP_SUCCESSFUL, NULL, 0);
|
||||||
} else
|
} else
|
||||||
NewPhase(Phase() + 1);
|
NewPhase((PPP_PHASE) (Phase() + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1539,7 +1580,7 @@ PPPStateMachine::DownEncapsulators()
|
|||||||
for(; encapsulator_handler;
|
for(; encapsulator_handler;
|
||||||
encapsulator_handler = encapsulator_handler->Next())
|
encapsulator_handler = encapsulator_handler->Next())
|
||||||
if(encapsulator_handler->IsEnabled())
|
if(encapsulator_handler->IsEnabled())
|
||||||
encapsualtor_handler->Down();
|
encapsulator_handler->Down();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "KPPPUtils.h"
|
|
||||||
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
|
#include "KPPPUtils.h"
|
||||||
|
|
||||||
|
|
||||||
// These are very simple send/receive_data functions with a timeout
|
// These are very simple send/receive_data functions with a timeout
|
||||||
// and there is a race condition beween has_data() and send/receive_data().
|
// and there is a race condition beween has_data() and send/receive_data().
|
||||||
@@ -17,9 +17,7 @@ status_t
|
|||||||
send_data_with_timeout(thread_id thread, int32 code, void *buffer,
|
send_data_with_timeout(thread_id thread, int32 code, void *buffer,
|
||||||
size_t buffer_size, uint32 timeout)
|
size_t buffer_size, uint32 timeout)
|
||||||
{
|
{
|
||||||
int32 tries;
|
for(uint32 tries = 0; tries < timeout; tries++) {
|
||||||
|
|
||||||
for(tries = 0; tries < timeout; tries++) {
|
|
||||||
if(has_data(thread))
|
if(has_data(thread))
|
||||||
snooze(1000);
|
snooze(1000);
|
||||||
}
|
}
|
||||||
@@ -35,9 +33,7 @@ status_t
|
|||||||
receive_data_with_timeout(thread_id *sender, int32 *code, void *buffer,
|
receive_data_with_timeout(thread_id *sender, int32 *code, void *buffer,
|
||||||
size_t buffer_size, uint32 timeout)
|
size_t buffer_size, uint32 timeout)
|
||||||
{
|
{
|
||||||
int32 tries;
|
for(uint32 tries = 0; tries < timeout; tries++) {
|
||||||
|
|
||||||
for(tries = 0; tries < timeout; tries++) {
|
|
||||||
if(!has_data(find_thread(NULL))) {
|
if(!has_data(find_thread(NULL))) {
|
||||||
snooze(1000);
|
snooze(1000);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -5,10 +5,12 @@
|
|||||||
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003 Waldemar Kornewald, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <driver_settings.h>
|
||||||
|
|
||||||
#include "settings_tools.h"
|
#include "settings_tools.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <driver_settings.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
|
|
||||||
static void copy_parameter(const driver_parameter *from, driver_parameter *to);
|
static void copy_parameter(const driver_parameter *from, driver_parameter *to);
|
||||||
@@ -17,7 +19,7 @@ static void free_driver_parameter(driver_parameter *p);
|
|||||||
|
|
||||||
driver_settings *dup_driver_settings(const driver_settings *dup)
|
driver_settings *dup_driver_settings(const driver_settings *dup)
|
||||||
{
|
{
|
||||||
if(!settings)
|
if(!dup)
|
||||||
return NULL; // we got a NULL pointer, so return nothing
|
return NULL; // we got a NULL pointer, so return nothing
|
||||||
|
|
||||||
driver_settings *ret = (driver_settings*) malloc(sizeof(driver_settings));
|
driver_settings *ret = (driver_settings*) malloc(sizeof(driver_settings));
|
||||||
@@ -37,7 +39,7 @@ static void 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;
|
||||||
|
|
||||||
to->values = (char**) malloc(values * sizeof(char*));
|
to->values = (char**) malloc(to->value_count * sizeof(char*));
|
||||||
|
|
||||||
for(int32 i=0; i < to->value_count; i++)
|
for(int32 i=0; i < to->value_count; i++)
|
||||||
to->values[i] = strdup(from->values[i]);
|
to->values[i] = strdup(from->values[i]);
|
||||||
@@ -77,38 +79,25 @@ void free_driver_parameter(driver_parameter *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void add_settings(const driver_settings *from, driver_settings *to)
|
bool get_string_value(const char *string, bool unknownValue)
|
||||||
{
|
|
||||||
if(!from || !to)
|
|
||||||
return;
|
|
||||||
|
|
||||||
to->parameters = realloc(to->parameters,
|
|
||||||
(to->parameter_count + from->parameter_count) * sizeof(driver_parameter));
|
|
||||||
|
|
||||||
for(int32 i=0; i < from->parameter_count; i++)
|
|
||||||
copy_parameters(&from->parameters[i], &to->parameters[to->parameter_count++]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool get_boolean_value(const char *string, bool unknownValue)
|
|
||||||
{
|
{
|
||||||
if(!string)
|
if(!string)
|
||||||
return unknownValue;
|
return unknownValue;
|
||||||
|
|
||||||
if (!strcmp(boolean, "1")
|
if (!strcmp(string, "1")
|
||||||
|| !strcasecmp(boolean, "true")
|
|| !strcasecmp(string, "true")
|
||||||
|| !strcasecmp(boolean, "yes")
|
|| !strcasecmp(string, "yes")
|
||||||
|| !strcasecmp(boolean, "on")
|
|| !strcasecmp(string, "on")
|
||||||
|| !strcasecmp(boolean, "enable")
|
|| !strcasecmp(string, "enable")
|
||||||
|| !strcasecmp(boolean, "enabled"))
|
|| !strcasecmp(string, "enabled"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!strcmp(boolean, "0")
|
if (!strcmp(string, "0")
|
||||||
|| !strcasecmp(boolean, "false")
|
|| !strcasecmp(string, "false")
|
||||||
|| !strcasecmp(boolean, "no")
|
|| !strcasecmp(string, "no")
|
||||||
|| !strcasecmp(boolean, "off")
|
|| !strcasecmp(string, "off")
|
||||||
|| !strcasecmp(boolean, "disable")
|
|| !strcasecmp(string, "disable")
|
||||||
|| !strcasecmp(boolean, "disabled"))
|
|| !strcasecmp(string, "disabled"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// no correct value has been found => return default value
|
// no correct value has been found => return default value
|
||||||
|
|||||||
@@ -17,19 +17,10 @@ struct driver_parameter;
|
|||||||
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);
|
||||||
|
|
||||||
void add_settings(const driver_settings *from, driver_settings *to);
|
|
||||||
void add_settings(const driver_settings *from, driver_parameter *to)
|
|
||||||
{ add_settings(from, (driver_settings*) &to->parameter_count); }
|
|
||||||
void add_parameter(const driver_parameter *from, driver_settings *to)
|
|
||||||
{ add_settings((driver_settings*) &from->parameter_count, to); }
|
|
||||||
void add_parameter(const driver_parameter *from, driver_parameter *to)
|
|
||||||
{ add_settings((driver_settings*) &from->parameter_count,
|
|
||||||
(driver_settings*) &to->parameter_count); }
|
|
||||||
|
|
||||||
bool get_boolean_value(const char *string, bool unknownValue);
|
bool get_boolean_value(const char *string, bool unknownValue);
|
||||||
const char *get_settings_value(const char *name, const driver_settings *settings);
|
const char *get_settings_value(const char *name, const driver_settings *settings);
|
||||||
const char *get_parameter_value(const char *name, const driver_parameter *parameters)
|
const char *get_parameter_value(const char *name, const driver_parameter *parameters)
|
||||||
{ get_settings_value(name, (driver_settings*) ¶meter->parameter_count); }
|
{ return get_settings_value(name, (driver_settings*) ¶meters->parameter_count); }
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user