xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 //-----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //-----------------------------------------------------------------------
7 
8 #include <KPPPOptionHandler.h>
9 
10 #include <PPPControl.h>
11 
12 
13 KPPPOptionHandler::KPPPOptionHandler(const char *name, uint8 type,
14 		KPPPInterface& interface, driver_parameter *settings)
15 	: fInitStatus(B_OK),
16 	fType(type),
17 	fInterface(interface),
18 	fSettings(settings),
19 	fEnabled(true)
20 {
21 	if(name)
22 		fName = strdup(name);
23 	else
24 		fName = NULL;
25 }
26 
27 
28 KPPPOptionHandler::~KPPPOptionHandler()
29 {
30 	free(fName);
31 
32 	Interface().LCP().RemoveOptionHandler(this);
33 }
34 
35 
36 status_t
37 KPPPOptionHandler::InitCheck() const
38 {
39 	return fInitStatus;
40 }
41 
42 
43 status_t
44 KPPPOptionHandler::Control(uint32 op, void *data, size_t length)
45 {
46 	switch(op) {
47 		case PPPC_GET_SIMPLE_HANDLER_INFO: {
48 			if(length < sizeof(ppp_simple_handler_info_t) || !data)
49 				return B_ERROR;
50 
51 			ppp_simple_handler_info *info = (ppp_simple_handler_info*) data;
52 			memset(info, 0, sizeof(ppp_simple_handler_info_t));
53 			if(Name())
54 				strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
55 			info->isEnabled = IsEnabled();
56 		} break;
57 
58 		case PPPC_ENABLE:
59 			if(length < sizeof(uint32) || !data)
60 				return B_ERROR;
61 
62 			SetEnabled(*((uint32*)data));
63 		break;
64 
65 		default:
66 			return B_BAD_VALUE;
67 	}
68 
69 	return B_OK;
70 }
71 
72 
73 status_t
74 KPPPOptionHandler::StackControl(uint32 op, void *data)
75 {
76 	switch(op) {
77 		default:
78 			return B_BAD_VALUE;
79 	}
80 
81 	return B_OK;
82 }
83 
84 
85 void
86 KPPPOptionHandler::ProfileChanged()
87 {
88 	// do nothing by default
89 }
90