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