1/*
2 * Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
4 */
5
6#include <KernelExport.h>
7#include <driver_settings.h>
8
9#include <net_buffer.h>
10#include <net_stack.h>
11
12#include <KPPPInterface.h>
13#include <KPPPModule.h>
14
15#include "Protocol.h"
16
17#define PAP_MODULE_NAME		NETWORK_MODULES_ROOT "/ppp/pap"
18
19net_stack_module_info *gStackModule = NULL;
20net_buffer_module_info *gBufferModule = NULL;
21status_t std_ops(int32 op, ...);
22
23static bool
24add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
25	driver_parameter *settings, ppp_module_key_type type)
26{
27	if (type != PPP_AUTHENTICATOR_KEY_TYPE)
28		return B_ERROR;
29
30	PAP *pap;
31	bool success;
32	if (subInterface) {
33		pap = new PAP(*subInterface, settings);
34		success = subInterface->AddProtocol(pap);
35	} else {
36		pap = new PAP(mainInterface, settings);
37		success = mainInterface.AddProtocol(pap);
38	}
39
40	TRACE("PAP: add_to(): %s\n",
41		success && pap && pap->InitCheck() == B_OK ? "OK" : "ERROR");
42
43	return success && pap && pap->InitCheck() == B_OK;
44}
45
46
47static ppp_module_info pap_module = {
48	{
49		PAP_MODULE_NAME,
50		0,
51		std_ops
52	},
53	NULL,
54	add_to
55};
56
57
58_EXPORT
59status_t
60std_ops(int32 op, ...)
61{
62	switch (op) {
63		case B_MODULE_INIT:
64			if (get_module(NET_STACK_MODULE_NAME, (module_info**) &gStackModule) != B_OK)
65				return B_ERROR;
66			if (get_module(NET_BUFFER_MODULE_NAME,
67				(module_info **)&gBufferModule) != B_OK) {
68				put_module(NET_STACK_MODULE_NAME);
69				return B_ERROR;
70			}
71		return B_OK;
72
73		case B_MODULE_UNINIT:
74			put_module(NET_BUFFER_MODULE_NAME);
75			put_module(NET_STACK_MODULE_NAME);
76		break;
77
78		default:
79			return B_ERROR;
80	}
81
82	return B_OK;
83}
84
85
86_EXPORT
87module_info *modules[] = {
88	(module_info*) &pap_module,
89	NULL
90};
91