xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //---------------------------------------------------------------------
7 
8 #include <KPPPOptionHandler.h>
9 
10 #include <PPPControl.h>
11 
12 
13 PPPOptionHandler::PPPOptionHandler(const char *name, uint8 type,
14 		PPPInterface& 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 PPPOptionHandler::~PPPOptionHandler()
29 {
30 	free(fName);
31 
32 	Interface().LCP().RemoveOptionHandler(this);
33 }
34 
35 
36 status_t
37 PPPOptionHandler::InitCheck() const
38 {
39 	return fInitStatus;
40 }
41 
42 
43 status_t
44 PPPOptionHandler::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->settings = Settings();
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 PPPOptionHandler::StackControl(uint32 op, void *data)
75 {
76 	switch(op) {
77 		default:
78 			return B_BAD_VALUE;
79 	}
80 
81 	return B_OK;
82 }
83