1/*
2 * Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <KernelExport.h>
8#include <driver_settings.h>
9
10#include <KPPPInterface.h>
11#include <KPPPModule.h>
12
13#include "ModemDevice.h"
14
15
16#define MODEM_MODULE_NAME		NETWORK_MODULES_ROOT "ppp/modem"
17
18net_stack_module_info *gStackModule = NULL;
19net_buffer_module_info *gBufferModule = NULL;
20status_t std_ops(int32 op, ...);
21
22
23static bool
24add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
25	driver_parameter *settings, ppp_module_key_type type)
26{
27	if (mainInterface.Mode() != PPP_CLIENT_MODE || type != PPP_DEVICE_KEY_TYPE)
28		return B_ERROR;
29
30	ModemDevice *device;
31	bool success;
32	if (subInterface) {
33		device = new ModemDevice(*subInterface, settings);
34		success = subInterface->SetDevice(device);
35	} else {
36		device = new ModemDevice(mainInterface, settings);
37		success = mainInterface.SetDevice(device);
38	}
39
40	TRACE("Modem: add_to(): %s\n",
41		success && device && device->InitCheck() == B_OK ? "OK" : "ERROR");
42
43	return success && device && device->InitCheck() == B_OK;
44}
45
46
47static ppp_module_info modem_module = {
48	{
49		MODEM_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,
65					(module_info**)&gStackModule) != B_OK)
66				return B_ERROR;
67			if (get_module(NET_BUFFER_MODULE_NAME,
68					(module_info **)&gBufferModule) != B_OK) {
69				put_module(NET_STACK_MODULE_NAME);
70				return B_ERROR;
71			}
72		return B_OK;
73
74		case B_MODULE_UNINIT:
75			put_module(NET_BUFFER_MODULE_NAME);
76			put_module(NET_STACK_MODULE_NAME);
77		break;
78
79		default:
80			return B_ERROR;
81	}
82
83	return B_OK;
84}
85
86
87_EXPORT
88module_info *modules[] = {
89	(module_info*) &modem_module,
90	NULL
91};
92