1 //---------------------------------------------------------------------- 2 // This software is part of the OpenBeOS distribution and is covered 3 // by the OpenBeOS license. 4 // 5 // Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de 6 //--------------------------------------------------------------------- 7 8 #include <KPPPDevice.h> 9 10 #include <net/if.h> 11 #include <core_funcs.h> 12 13 #include <PPPControl.h> 14 15 16 PPPDevice::PPPDevice(const char *name, PPPInterface& interface, 17 driver_parameter *settings) 18 : PPPLayer(name, PPP_DEVICE_LEVEL), 19 fMTU(1500), 20 fInterface(interface), 21 fSettings(settings), 22 fIsUp(false) 23 { 24 fInitStatus = interface.SetDevice(this) && fInitStatus == B_OK ? B_OK : B_ERROR; 25 } 26 27 28 PPPDevice::~PPPDevice() 29 { 30 Interface().SetDevice(NULL); 31 } 32 33 34 status_t 35 PPPDevice::Control(uint32 op, void *data, size_t length) 36 { 37 switch(op) { 38 case PPPC_GET_DEVICE_INFO: { 39 if(length < sizeof(ppp_device_info_t) || !data) 40 return B_NO_MEMORY; 41 42 ppp_device_info *info = (ppp_device_info*) data; 43 memset(info, 0, sizeof(ppp_device_info_t)); 44 strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); 45 info->settings = Settings(); 46 info->MTU = MTU(); 47 info->inputTransferRate = InputTransferRate(); 48 info->outputTransferRate = OutputTransferRate(); 49 info->outputBytesCount = CountOutputBytes(); 50 info->isUp = IsUp(); 51 } break; 52 53 default: 54 return B_BAD_VALUE; 55 } 56 57 return B_OK; 58 } 59 60 61 bool 62 PPPDevice::IsAllowedToSend() const 63 { 64 return true; 65 // our connection status will be reported in Send() 66 } 67 68 69 status_t 70 PPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber) 71 { 72 // let the interface handle the packet 73 if(protocolNumber == 0) 74 return Interface().ReceiveFromDevice(packet); 75 else 76 return Interface().Receive(packet, protocolNumber); 77 } 78 79 80 void 81 PPPDevice::Pulse() 82 { 83 // do nothing by default 84 } 85 86 87 bool 88 PPPDevice::UpStarted() const 89 { 90 return Interface().StateMachine().TLSNotify(); 91 } 92 93 94 bool 95 PPPDevice::DownStarted() const 96 { 97 return Interface().StateMachine().TLFNotify(); 98 } 99 100 101 void 102 PPPDevice::UpFailedEvent() 103 { 104 fIsUp = false; 105 106 Interface().StateMachine().UpFailedEvent(); 107 } 108 109 110 void 111 PPPDevice::UpEvent() 112 { 113 fIsUp = true; 114 115 Interface().StateMachine().UpEvent(); 116 } 117 118 119 void 120 PPPDevice::DownEvent() 121 { 122 fIsUp = false; 123 124 Interface().StateMachine().DownEvent(); 125 } 126