xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
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 */
25 KPPPLCPExtension::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.
41 KPPPLCPExtension::~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.
50 status_t
51 KPPPLCPExtension::InitCheck() const
52 {
53 	return fInitStatus;
54 }
55 
56 
57 //!	Allows controlling this extension from userlevel.
58 status_t
59 KPPPLCPExtension::Control(uint32 op, void *data, size_t length)
60 {
61 	dprintf("KPPPLCPExtension::Control\n");
62 	switch (op) {
63 		case PPPC_GET_SIMPLE_HANDLER_INFO:
64 		{
65 			if (length < sizeof(ppp_simple_handler_info_t) || !data)
66 				return B_ERROR;
67 
68 			ppp_simple_handler_info *info = (ppp_simple_handler_info*) data;
69 			memset(info, 0, sizeof(ppp_simple_handler_info_t));
70 			if (Name())
71 				strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
72 			info->isEnabled = IsEnabled();
73 			break;
74 		}
75 
76 		case PPPC_ENABLE:
77 			if (length < sizeof(uint32) || !data)
78 				return B_ERROR;
79 
80 			SetEnabled(*((uint32*)data));
81 			break;
82 
83 		default:
84 			return B_BAD_VALUE;
85 	}
86 
87 	return B_OK;
88 }
89 
90 
91 //!	Stack ioctl handler.
92 status_t
93 KPPPLCPExtension::StackControl(uint32 op, void *data)
94 {
95 	switch (op) {
96 		default:
97 			return B_BAD_VALUE;
98 	}
99 
100 	return B_OK;
101 }
102 
103 
104 /*!	\brief Reset internal connection state.
105 
106 	This method is called when: connecting, reconfiguring, or disconnecting.
107 */
108 void
109 KPPPLCPExtension::Reset()
110 {
111 	// do nothing by default
112 }
113 
114 
115 /*!	\brief You may override this for periodic tasks.
116 
117 	This method gets called every \c PPP_PULSE_RATE microseconds.
118 */
119 void
120 KPPPLCPExtension::Pulse()
121 {
122 	// do nothing by default
123 }
124