xref: /haiku/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
1 /*
2  * Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef DISCOVERY_PACKET__H
7 #define DISCOVERY_PACKET__H
8 
9 #include "PPPoE.h"
10 
11 #include <TemplateList.h>
12 
13 
14 enum PPPoE_TAG_TYPE {
15 	END_OF_LIST = 0x0000,
16 	SERVICE_NAME = 0x0101,
17 	AC_NAME = 0x0102,
18 	HOST_UNIQ = 0x0103,
19 	AC_COOKIE = 0x0104,
20 	VENDOR_SPECIFIC = 0x0105,
21 	RELAY_SESSION_ID = 0x0110,
22 	SERVICE_NAME_ERROR = 0x0201,
23 	AC_SYSTEM_ERROR = 0x0202,
24 	GENERIC_ERROR = 0x0203
25 };
26 
27 enum PPPoE_CODE {
28 	PADI = 0x09,
29 	PADO = 0x07,
30 	PADR = 0x19,
31 	PADS = 0x65,
32 	PADT = 0xA7
33 };
34 
35 
36 typedef struct pppoe_tag {
37 	uint16 type;
38 	uint16 length;
39 	uint8 data[0];
40 };
41 
42 
43 class DiscoveryPacket {
44 	public:
45 		DiscoveryPacket(uint8 code, uint16 sessionID = 0x0000);
46 		DiscoveryPacket(struct mbuf *packet, uint32 start = 0);
47 		~DiscoveryPacket();
48 
49 		status_t InitCheck() const
50 			{ return fInitStatus; }
51 
52 		void SetCode(uint8 code)
53 			{ fCode = code; }
54 		uint8 Code() const
55 			{ return fCode; }
56 
57 		void SetSessionID(uint16 sessionID)
58 			{ fSessionID = sessionID; }
59 		uint16 SessionID() const
60 			{ return fSessionID; }
61 
62 		bool AddTag(uint16 type, const void *data, uint16 length, int32 index = -1);
63 		bool RemoveTag(pppoe_tag *tag);
64 		int32 CountTags() const
65 			{ return fTags.CountItems(); }
66 		pppoe_tag *TagAt(int32 index) const;
67 		pppoe_tag *TagWithType(uint16 type) const;
68 
69 		struct mbuf *ToMbuf(uint32 MTU, uint32 reserve = ETHER_HDR_LEN);
70 			// the user is responsible for freeing the mbuf
71 
72 	private:
73 		uint8 fCode;
74 		uint16 fSessionID;
75 		TemplateList<pppoe_tag*> fTags;
76 		status_t fInitStatus;
77 };
78 
79 
80 #endif
81