vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / network / ppp / modem / modem.cpp
blob55466c852021d1eef62f5f98ecfd0cb6f72b2343
1 /*
2 * Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
4 */
7 #include <KernelExport.h>
8 #include <driver_settings.h>
10 #include <KPPPInterface.h>
11 #include <KPPPModule.h>
13 #include "ModemDevice.h"
16 #define MODEM_MODULE_NAME NETWORK_MODULES_ROOT "ppp/modem"
18 net_stack_module_info *gStackModule = NULL;
19 net_buffer_module_info *gBufferModule = NULL;
20 status_t std_ops(int32 op, ...);
23 static bool
24 add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
25 driver_parameter *settings, ppp_module_key_type type)
27 if (mainInterface.Mode() != PPP_CLIENT_MODE || type != PPP_DEVICE_KEY_TYPE)
28 return B_ERROR;
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);
40 TRACE("Modem: add_to(): %s\n",
41 success && device && device->InitCheck() == B_OK ? "OK" : "ERROR");
43 return success && device && device->InitCheck() == B_OK;
47 static ppp_module_info modem_module = {
49 MODEM_MODULE_NAME,
51 std_ops
53 NULL,
54 add_to
58 _EXPORT
59 status_t
60 std_ops(int32 op, ...)
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;
72 return B_OK;
74 case B_MODULE_UNINIT:
75 put_module(NET_BUFFER_MODULE_NAME);
76 put_module(NET_STACK_MODULE_NAME);
77 break;
79 default:
80 return B_ERROR;
83 return B_OK;
87 _EXPORT
88 module_info *modules[] = {
89 (module_info*) &modem_module,
90 NULL