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