xref: /haiku/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h (revision bab64f65bb775dc23060e276f1f1c4498ab7af6c)
184b580c4SWaldemar Kornewald /*
2abdb7d1aSWaldemar Kornewald  * Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
384b580c4SWaldemar Kornewald  * Distributed under the terms of the MIT License.
484b580c4SWaldemar Kornewald  */
55a4503c3SWaldemar Kornewald 
65a4503c3SWaldemar Kornewald #ifndef DISCOVERY_PACKET__H
75a4503c3SWaldemar Kornewald #define DISCOVERY_PACKET__H
85a4503c3SWaldemar Kornewald 
95a4503c3SWaldemar Kornewald #include "PPPoE.h"
105a4503c3SWaldemar Kornewald 
1149c2f687SWaldemar Kornewald #include <TemplateList.h>
125a4503c3SWaldemar Kornewald 
13*e3724c38Smshlyn #define ETHER_HDR_LEN 14
145a4503c3SWaldemar Kornewald 
155a4503c3SWaldemar Kornewald enum PPPoE_TAG_TYPE {
165a4503c3SWaldemar Kornewald 	END_OF_LIST = 0x0000,
175a4503c3SWaldemar Kornewald 	SERVICE_NAME = 0x0101,
185a4503c3SWaldemar Kornewald 	AC_NAME = 0x0102,
195a4503c3SWaldemar Kornewald 	HOST_UNIQ = 0x0103,
205a4503c3SWaldemar Kornewald 	AC_COOKIE = 0x0104,
215a4503c3SWaldemar Kornewald 	VENDOR_SPECIFIC = 0x0105,
225a4503c3SWaldemar Kornewald 	RELAY_SESSION_ID = 0x0110,
235a4503c3SWaldemar Kornewald 	SERVICE_NAME_ERROR = 0x0201,
245a4503c3SWaldemar Kornewald 	AC_SYSTEM_ERROR = 0x0202,
255a4503c3SWaldemar Kornewald 	GENERIC_ERROR = 0x0203
265a4503c3SWaldemar Kornewald };
275a4503c3SWaldemar Kornewald 
285a4503c3SWaldemar Kornewald enum PPPoE_CODE {
295a4503c3SWaldemar Kornewald 	PADI = 0x09,
305a4503c3SWaldemar Kornewald 	PADO = 0x07,
315a4503c3SWaldemar Kornewald 	PADR = 0x19,
325a4503c3SWaldemar Kornewald 	PADS = 0x65,
335a4503c3SWaldemar Kornewald 	PADT = 0xA7
345a4503c3SWaldemar Kornewald };
355a4503c3SWaldemar Kornewald 
365a4503c3SWaldemar Kornewald 
375a4503c3SWaldemar Kornewald typedef struct pppoe_tag {
385a4503c3SWaldemar Kornewald 	uint16 type;
395a4503c3SWaldemar Kornewald 	uint16 length;
405a4503c3SWaldemar Kornewald 	uint8 data[0];
41*e3724c38Smshlyn } pppoe_tag;
425a4503c3SWaldemar Kornewald 
435a4503c3SWaldemar Kornewald 
445a4503c3SWaldemar Kornewald class DiscoveryPacket {
455a4503c3SWaldemar Kornewald 	public:
465a4503c3SWaldemar Kornewald 		DiscoveryPacket(uint8 code, uint16 sessionID = 0x0000);
47*e3724c38Smshlyn 		DiscoveryPacket(net_buffer *packet, uint32 start = 0);
485a4503c3SWaldemar Kornewald 		~DiscoveryPacket();
495a4503c3SWaldemar Kornewald 
InitCheck()504e0ad752SWaldemar Kornewald 		status_t InitCheck() const
514e0ad752SWaldemar Kornewald 			{ return fInitStatus; }
524e0ad752SWaldemar Kornewald 
SetCode(uint8 code)535a4503c3SWaldemar Kornewald 		void SetCode(uint8 code)
545a4503c3SWaldemar Kornewald 			{ fCode = code; }
Code()555a4503c3SWaldemar Kornewald 		uint8 Code() const
565a4503c3SWaldemar Kornewald 			{ return fCode; }
575a4503c3SWaldemar Kornewald 
SetSessionID(uint16 sessionID)585a4503c3SWaldemar Kornewald 		void SetSessionID(uint16 sessionID)
595a4503c3SWaldemar Kornewald 			{ fSessionID = sessionID; }
SessionID()605a4503c3SWaldemar Kornewald 		uint16 SessionID() const
615a4503c3SWaldemar Kornewald 			{ return fSessionID; }
625a4503c3SWaldemar Kornewald 
635a483e4dSWaldemar Kornewald 		bool AddTag(uint16 type, const void *data, uint16 length, int32 index = -1);
645a4503c3SWaldemar Kornewald 		bool RemoveTag(pppoe_tag *tag);
CountTags()655a4503c3SWaldemar Kornewald 		int32 CountTags() const
665a4503c3SWaldemar Kornewald 			{ return fTags.CountItems(); }
675a4503c3SWaldemar Kornewald 		pppoe_tag *TagAt(int32 index) const;
685a4503c3SWaldemar Kornewald 		pppoe_tag *TagWithType(uint16 type) const;
695a4503c3SWaldemar Kornewald 
70*e3724c38Smshlyn 		net_buffer *ToNetBuffer(uint32 MTU);
71*e3724c38Smshlyn 			// the user is responsible for freeing the net_buffer
725a4503c3SWaldemar Kornewald 
735a4503c3SWaldemar Kornewald 	private:
745a4503c3SWaldemar Kornewald 		uint8 fCode;
755a4503c3SWaldemar Kornewald 		uint16 fSessionID;
7649c2f687SWaldemar Kornewald 		TemplateList<pppoe_tag*> fTags;
774e0ad752SWaldemar Kornewald 		status_t fInitStatus;
785a4503c3SWaldemar Kornewald };
795a4503c3SWaldemar Kornewald 
805a4503c3SWaldemar Kornewald 
815a4503c3SWaldemar Kornewald #endif
82