1/*
2 * Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
4 */
5
6/*!	\class KPPPLCPExtension
7	\brief LCP protocol extension
8
9	This class can be used to extend the supported LCP protocol codes.
10*/
11
12#include <KPPPLCPExtension.h>
13#include <PPPControl.h>
14
15
16/*!	\brief Constructor.
17
18	If an error occurs in the constructor you should set \c fInitStatus.
19
20	\param name Name of the extension.
21	\param code LCP code that this extension can handle.
22	\param interface Owning interface.
23	\param settings Settings for this extension.
24*/
25KPPPLCPExtension::KPPPLCPExtension(const char *name, uint8 code,
26		KPPPInterface& interface, driver_parameter *settings)
27	: fInitStatus(B_OK),
28	fInterface(interface),
29	fSettings(settings),
30	fCode(code),
31	fEnabled(true)
32{
33	if (name)
34		fName = strdup(name);
35	else
36		fName = NULL;
37}
38
39
40//!	Destructor. Frees the name and unregisters extension from LCP protocol.
41KPPPLCPExtension::~KPPPLCPExtension()
42{
43	Interface().LCP().RemoveLCPExtension(this);
44
45	free(fName);
46}
47
48
49//!	Returns \c fInitStatus. May be overridden to return status-dependend errors.
50status_t
51KPPPLCPExtension::InitCheck() const
52{
53	return fInitStatus;
54}
55
56
57//!	Allows controlling this extension from userlevel.
58status_t
59KPPPLCPExtension::Control(uint32 op, void *data, size_t length)
60{
61	switch (op) {
62		case PPPC_GET_SIMPLE_HANDLER_INFO:
63		{
64			if (length < sizeof(ppp_simple_handler_info_t) || !data)
65				return B_ERROR;
66
67			ppp_simple_handler_info *info = (ppp_simple_handler_info*) data;
68			memset(info, 0, sizeof(ppp_simple_handler_info_t));
69			if (Name())
70				strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
71			info->isEnabled = IsEnabled();
72			break;
73		}
74
75		case PPPC_ENABLE:
76			if (length < sizeof(uint32) || !data)
77				return B_ERROR;
78
79			SetEnabled(*((uint32*)data));
80			break;
81
82		default:
83			return B_BAD_VALUE;
84	}
85
86	return B_OK;
87}
88
89
90//!	Stack ioctl handler.
91status_t
92KPPPLCPExtension::StackControl(uint32 op, void *data)
93{
94	switch (op) {
95		default:
96			return B_BAD_VALUE;
97	}
98
99	return B_OK;
100}
101
102
103/*!	\brief Reset internal connection state.
104
105	This method is called when: connecting, reconfiguring, or disconnecting.
106*/
107void
108KPPPLCPExtension::Reset()
109{
110	// do nothing by default
111}
112
113
114/*!	\brief You may override this for periodic tasks.
115
116	This method gets called every \c PPP_PULSE_RATE microseconds.
117*/
118void
119KPPPLCPExtension::Pulse()
120{
121	// do nothing by default
122}
123