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