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