xref: /haiku/src/add-ons/kernel/network/ppp/pap/pap.cpp (revision db10640de90f7f9519ba2da9577b7c1af3c64f6b)
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 <KernelExport.h>
9 #include <driver_settings.h>
10 #include <core_funcs.h>
11 #include <net_module.h>
12 
13 #include <KPPPInterface.h>
14 #include <KPPPModule.h>
15 #include <LockerHelper.h>
16 
17 #include "Protocol.h"
18 
19 
20 #define PAP_MODULE_NAME		NETWORK_MODULES_ROOT "ppp/pap"
21 
22 struct core_module_info *core = NULL;
23 status_t std_ops(int32 op, ...);
24 
25 
26 static
27 bool
28 add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
29 	driver_parameter *settings, ppp_module_key_type type)
30 {
31 	if(type != PPP_AUTHENTICATOR_KEY_TYPE)
32 		return B_ERROR;
33 
34 	PAP *pap;
35 	bool success;
36 	if(subInterface) {
37 		pap = new PAP(*subInterface, settings);
38 		success = subInterface->AddProtocol(pap);
39 	} else {
40 		pap = new PAP(mainInterface, settings);
41 		success = mainInterface.AddProtocol(pap);
42 	}
43 
44 #if DEBUG
45 	dprintf("PAP: add_to(): %s\n",
46 		success && pap && pap->InitCheck() == B_OK ? "OK" : "ERROR");
47 #endif
48 
49 	return success && pap && pap->InitCheck() == B_OK;
50 }
51 
52 
53 static ppp_module_info pap_module = {
54 	{
55 		PAP_MODULE_NAME,
56 		0,
57 		std_ops
58 	},
59 	NULL,
60 	add_to
61 };
62 
63 
64 _EXPORT
65 status_t
66 std_ops(int32 op, ...)
67 {
68 	switch(op) {
69 		case B_MODULE_INIT:
70 			if(get_module(NET_CORE_MODULE_NAME, (module_info**) &core) != B_OK)
71 				return B_ERROR;
72 		return B_OK;
73 
74 		case B_MODULE_UNINIT:
75 			put_module(NET_CORE_MODULE_NAME);
76 		break;
77 
78 		default:
79 			return B_ERROR;
80 	}
81 
82 	return B_OK;
83 }
84 
85 
86 _EXPORT
87 module_info *modules[] = {
88 	(module_info*) &pap_module,
89 	NULL
90 };
91