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 if(Name()) 45 strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); 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 KPPPDevice::IsAllowedToSend() const 63 { 64 return true; 65 // our connection status will be reported in Send() 66 } 67 68 69 status_t 70 KPPPDevice::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 KPPPDevice::Pulse() 82 { 83 // do nothing by default 84 } 85 86 87 bool 88 KPPPDevice::UpStarted() 89 { 90 fConnectionPhase = PPP_ESTABLISHMENT_PHASE; 91 92 return Interface().StateMachine().TLSNotify(); 93 } 94 95 96 bool 97 KPPPDevice::DownStarted() 98 { 99 fConnectionPhase = PPP_TERMINATION_PHASE; 100 101 return Interface().StateMachine().TLFNotify(); 102 } 103 104 105 void 106 KPPPDevice::UpFailedEvent() 107 { 108 fConnectionPhase = PPP_DOWN_PHASE; 109 110 Interface().StateMachine().UpFailedEvent(); 111 } 112 113 114 void 115 KPPPDevice::UpEvent() 116 { 117 fConnectionPhase = PPP_ESTABLISHED_PHASE; 118 119 Interface().StateMachine().UpEvent(); 120 } 121 122 123 void 124 KPPPDevice::DownEvent() 125 { 126 fConnectionPhase = PPP_DOWN_PHASE; 127 128 Interface().StateMachine().DownEvent(); 129 } 130