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