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 "_KPPPPFCHandler.h" 9 10 #include <KPPPConfigurePacket.h> 11 12 #define PFC_TYPE 0x7 13 14 15 _PPPPFCHandler::_PPPPFCHandler(ppp_pfc_state& localPFCState, 16 ppp_pfc_state& peerPFCState, PPPInterface& interface) 17 : PPPOptionHandler("PFC Handler", PFC_TYPE, interface, NULL), 18 fLocalPFCState(localPFCState), 19 fPeerPFCState(peerPFCState) 20 { 21 } 22 23 24 status_t 25 _PPPPFCHandler::AddToRequest(PPPConfigurePacket& request) 26 { 27 // is PFC not requested or was it rejected? 28 if(fLocalPFCState & PPP_PFC_REJECTED 29 || (Interface().PFCOptions() & PPP_REQUEST_PFC) == 0) 30 return B_OK; 31 32 // add PFC request 33 ppp_configure_item item; 34 item.type = PFC_TYPE; 35 item.length = 2; 36 return request.AddItem(&item) ? B_OK : B_ERROR; 37 } 38 39 40 status_t 41 _PPPPFCHandler::ParseNak(const PPPConfigurePacket& nak) 42 { 43 // naks do not contain PFC items 44 if(nak.ItemWithType(PFC_TYPE)) 45 return B_ERROR; 46 47 return B_OK; 48 } 49 50 51 status_t 52 _PPPPFCHandler::ParseReject(const PPPConfigurePacket& reject) 53 { 54 if(reject.ItemWithType(PFC_TYPE)) { 55 fLocalPFCState = PPP_PFC_REJECTED; 56 57 if(Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST) 58 return B_ERROR; 59 } 60 61 return B_OK; 62 } 63 64 65 status_t 66 _PPPPFCHandler::ParseAck(const PPPConfigurePacket& ack) 67 { 68 if(ack.ItemWithType(PFC_TYPE)) 69 fLocalPFCState = PPP_PFC_ACCEPTED; 70 else { 71 fLocalPFCState = PPP_PFC_DISABLED; 72 73 if(Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST) 74 return B_ERROR; 75 } 76 77 return B_OK; 78 } 79 80 81 status_t 82 _PPPPFCHandler::ParseRequest(const PPPConfigurePacket& request, 83 int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject) 84 { 85 if(!request.ItemWithType(PFC_TYPE)) 86 return B_OK; 87 88 if((Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) { 89 ppp_configure_item item; 90 item.type = PFC_TYPE; 91 item.length = 2; 92 return reject.AddItem(&item) ? B_OK : B_ERROR; 93 } 94 95 return B_OK; 96 } 97 98 99 status_t 100 _PPPPFCHandler::SendingAck(const PPPConfigurePacket& ack) 101 { 102 ppp_configure_item *item = ack.ItemWithType(PFC_TYPE); 103 104 if(item && (Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) 105 return B_ERROR; 106 107 if(item) 108 fPeerPFCState = PPP_PFC_ACCEPTED; 109 else 110 fPeerPFCState = PPP_PFC_DISABLED; 111 112 return B_OK; 113 } 114 115 116 void 117 _PPPPFCHandler::Reset() 118 { 119 fLocalPFCState = fPeerPFCState = PPP_PFC_DISABLED; 120 } 121