1 //----------------------------------------------------------------------- 2 // This software is part of the OpenBeOS distribution and is covered 3 // by the OpenBeOS license. 4 // 5 // Copyright (c) 2003-2004 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 KPPPDevice::KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interface, 17 driver_parameter *settings) 18 : KPPPLayer(name, PPP_DEVICE_LEVEL, overhead), 19 fMTU(1500), 20 fInterface(interface), 21 fSettings(settings), 22 fConnectionPhase(PPP_DOWN_PHASE) 23 { 24 } 25 26 27 KPPPDevice::~KPPPDevice() 28 { 29 if(Interface().Device() == this) 30 Interface().SetDevice(NULL); 31 } 32 33 34 status_t 35 KPPPDevice::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->MTU = MTU(); 46 info->inputTransferRate = InputTransferRate(); 47 info->outputTransferRate = OutputTransferRate(); 48 info->outputBytesCount = CountOutputBytes(); 49 info->isUp = IsUp(); 50 } break; 51 52 default: 53 return B_BAD_VALUE; 54 } 55 56 return B_OK; 57 } 58 59 60 bool 61 KPPPDevice::IsAllowedToSend() const 62 { 63 return true; 64 // our connection status will be reported in Send() 65 } 66 67 68 status_t 69 KPPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber) 70 { 71 // let the interface handle the packet 72 if(protocolNumber == 0) 73 return Interface().ReceiveFromDevice(packet); 74 else 75 return Interface().Receive(packet, protocolNumber); 76 } 77 78 79 void 80 KPPPDevice::Pulse() 81 { 82 // do nothing by default 83 } 84 85 86 bool 87 KPPPDevice::UpStarted() 88 { 89 fConnectionPhase = PPP_ESTABLISHMENT_PHASE; 90 91 return Interface().StateMachine().TLSNotify(); 92 } 93 94 95 bool 96 KPPPDevice::DownStarted() 97 { 98 fConnectionPhase = PPP_TERMINATION_PHASE; 99 100 return Interface().StateMachine().TLFNotify(); 101 } 102 103 104 void 105 KPPPDevice::UpFailedEvent() 106 { 107 fConnectionPhase = PPP_DOWN_PHASE; 108 109 Interface().StateMachine().UpFailedEvent(); 110 } 111 112 113 void 114 KPPPDevice::UpEvent() 115 { 116 fConnectionPhase = PPP_ESTABLISHED_PHASE; 117 118 Interface().StateMachine().UpEvent(); 119 } 120 121 122 void 123 KPPPDevice::DownEvent() 124 { 125 fConnectionPhase = PPP_DOWN_PHASE; 126 127 Interface().StateMachine().DownEvent(); 128 } 129