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