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