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 <NetBufferUtilities.h> 10#include <net_buffer.h> 11#include <net_stack.h> 12 13#include <KPPPDefs.h> 14#include <KPPPInterface.h> 15#include <KPPPModule.h> 16 17#include "Protocol.h" 18 19#define IPCP_MODULE_NAME NETWORK_MODULES_ROOT "/ppp/ipcp" 20 21status_t std_ops(int32 op, ...); 22 23net_stack_module_info *gStackModule = NULL; 24net_buffer_module_info *gBufferModule = NULL; 25 26 27// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 28// TODO: Remove isascii() (needed for inet_aton()) when our kernel is finished! 29// isascii() is not defined in the R5 kernel, thus we must define it here: 30extern "C" 31int 32isascii(char c) 33{ 34 return ((c & (~0x7f)) == 0); // If c is a 7 bit value. 35} 36// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 37 38 39static 40bool 41add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface, 42 driver_parameter *settings, ppp_module_key_type type) 43{ 44 if (type != PPP_PROTOCOL_KEY_TYPE) 45 return B_ERROR; 46 47 IPCP *ipcp; 48 bool success; 49 if (subInterface) { 50 ipcp = new IPCP(*subInterface, settings); 51 success = subInterface->AddProtocol(ipcp); 52 } else { 53 ipcp = new IPCP(mainInterface, settings); 54 success = mainInterface.AddProtocol(ipcp); 55 } 56 57 TRACE("IPCP: add_to(): %s\n", 58 success && ipcp && ipcp->InitCheck() == B_OK ? "OK" : "ERROR"); 59 60 return success && ipcp && ipcp->InitCheck() == B_OK; 61} 62 63 64static ppp_module_info ipcp_module = { 65 { 66 IPCP_MODULE_NAME, 67 0, 68 std_ops 69 }, 70 NULL, 71 add_to 72}; 73 74 75_EXPORT 76status_t 77std_ops(int32 op, ...) 78{ 79 switch (op) { 80 case B_MODULE_INIT: 81 if (get_module(NET_STACK_MODULE_NAME, 82 (module_info**) &gStackModule) != B_OK) 83 return B_ERROR; 84 if (get_module(NET_BUFFER_MODULE_NAME, 85 (module_info **)&gBufferModule) != B_OK) { 86 put_module(NET_STACK_MODULE_NAME); 87 return B_ERROR; 88 } 89 return B_OK; 90 break; 91 92 case B_MODULE_UNINIT: 93 put_module(NET_BUFFER_MODULE_NAME); 94 put_module(NET_STACK_MODULE_NAME); 95 break; 96 97 default: 98 return B_ERROR; 99 } 100 101 return B_OK; 102} 103 104 105_EXPORT 106module_info *modules[] = { 107 (module_info*) &ipcp_module, 108 NULL 109}; 110