xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp (revision 9eb55bc1d104b8fda80898f8b25c94d8000c8255)
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 = strdup("Unknown");
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 			strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
54 			info->isEnabled = IsEnabled();
55 		} break;
56 
57 		case PPPC_ENABLE:
58 			if(length < sizeof(uint32) || !data)
59 				return B_ERROR;
60 
61 			SetEnabled(*((uint32*)data));
62 		break;
63 
64 		default:
65 			return B_BAD_VALUE;
66 	}
67 
68 	return B_OK;
69 }
70 
71 
72 status_t
73 KPPPOptionHandler::StackControl(uint32 op, void *data)
74 {
75 	switch(op) {
76 		default:
77 			return B_BAD_VALUE;
78 	}
79 
80 	return B_OK;
81 }
82