TEST ONLY!
Revision 0:a3d41f923207, committed 2010-11-17
- Comitter:
- AjK
- Date:
- Wed Nov 17 19:39:33 2010 +0000
- Commit message:
- TEST ONLY!
Changed in this revision
diff -r 000000000000 -r a3d41f923207 LLDP.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LLDP.cpp Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,87 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + + +#include "mbed.h" +#include "LLDP.h" + +const char LLDPinfo1[] = "MBED"; +const char LLDPinfo2[] = "A rapid prototyping system for the LPC17xx embedded microcontroller"; +const char LLDPinfo3[] = "\x00\x80\x00\x80"; + +LLDP::LLDP() : Ethernet() +{ + int totalLength = 0; + address(macAddress); + + memset(buffer, 0xFF, sizeof(buffer)); + + // Default to 4:MACAddress + _chassis.setSubtype(4); + _chassis.setPayload(macAddress, 6); + + // Default to 4:MACAddress + _port.setSubtype(3); + _port.setPayload(macAddress, 6); + + //_mbed.setOUI(macAddress); + //_mbed.setSubtype(1); + //_mbed.setPayload((char *)LLDPinfo, strlen(LLDPinfo)); + _systemName.base.header.setType(5); + _systemName.setPayload((char *)LLDPinfo1, strlen(LLDPinfo1)); + + _systemDesc.base.header.setType(6); + _systemDesc.setPayload((char *)LLDPinfo2, strlen(LLDPinfo2)); + + _systemCap.base.header.setType(7); + _systemCap.setPayload((char *)LLDPinfo3, 4); + + totalLength += _chassis.copy(buffer + totalLength); + totalLength += _port.copy(buffer + totalLength); + totalLength += _ttl.copy(buffer + totalLength); + //totalLength += _mbed.copy(buffer + totalLength); + totalLength += _systemName.copy(buffer + totalLength); + totalLength += _systemDesc.copy(buffer + totalLength); + totalLength += _systemCap.copy(buffer + totalLength); + totalLength += _end.copy(buffer + totalLength); + buflen = totalLength; +} + +void +LLDP::broadcast(void) +{ + char e[6 + 6 + 2]; + + e[0] = 0x01; e[1] = 0x80; e[2] = 0xc2; e[3] = 0x00; e[4] = 0x00; e[5] = 0x0e; + e[6] = macAddress[0]; + e[7] = macAddress[1]; + e[8] = macAddress[2]; + e[9] = macAddress[3]; + e[10] = macAddress[4]; + e[11] = macAddress[5]; + e[12] = 0x88; + e[13] = 0xCC; + + write(e, 6 + 6 + 2); + write(buffer, buflen); + send(); +}
diff -r 000000000000 -r a3d41f923207 LLDP.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LLDP.h Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,63 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef LLPDP_H +#define LLPDP_H + +#ifndef MBED_H +#include "mbed.h" +#endif + +#include "tlv.h" +#include "tlv_chassis.h" +#include "tlv_port.h" +#include "tlv_ttl.h" +#include "tlv_basic.h" +#include "tlv_custom.h" + +class LLDP : public Ethernet +{ +public: + + LLDP(); + virtual ~LLDP() {} + + void broadcast(void); + + // Properties. + tlv_chassis _chassis; + tlv_port _port; + tlv_ttl _ttl; + tlv_custom _mbed; + tlv_basic _systemName; + tlv_basic _systemDesc; + tlv_basic _systemCap; + tlv_header _end; + + char macAddress[6]; + char buffer[0x600]; + int buflen; + + +}; + +#endif
diff -r 000000000000 -r a3d41f923207 example.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example.cpp Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,42 @@ +#ifdef COMPILE_LLDP_TEXT + +#include "mbed.h" +#include "LLDP.h" + +Serial pc(USBTX, USBRX); +DigitalOut myled(LED1); +LLDP lldp; + +int main() { + char test[256]; + int j, k; + + pc.baud(115200); + + pc.printf("Chassis type = %d\r\n", lldp._chassis.base.header.getType()); + pc.printf("Chassis len = %d\r\n", lldp._chassis.base.header.getLength()); + for (j = 0, k = lldp._chassis.copy(test); j < k; j++) pc.printf("%02X ", test[j]); + pc.printf("\r\n"); + + pc.printf("Port type = %d\r\n", lldp._port.base.header.getType()); + pc.printf("Port len = %d\r\n", lldp._port.base.header.getLength()); + for (j = 0, k = lldp._port.copy(test); j < k; j++) pc.printf("%02X ", test[j]); + pc.printf("\r\n"); + + + pc.printf("Size is %d\r\n", lldp.buflen); + for (int i = 0; i < lldp.buflen; i++) { + pc.printf("%02X ", lldp.buffer[i]); + } + pc.printf("\r\nDone.\r\n"); + + while(1) { + myled = 1; + wait(0.5); + myled = 0; + wait(0.5); + lldp.broadcast(); + } +} + +#endif
diff -r 000000000000 -r a3d41f923207 tlv.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv.cpp Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,32 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "tlv.h" + +int +tlv_header::copy(char *buf) +{ + buf[0] = typeLength >> 8 & 0xFF; + buf[1] = typeLength & 0xFF; + return 2; +} +
diff -r 000000000000 -r a3d41f923207 tlv.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv.h Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,52 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef TLV_H +#define TLV_H + +#ifndef MBED_H +#include "mbed.h" +#endif + +class tlv_header { +public: + uint16_t typeLength; + tlv_header() { typeLength = 0; } + int copy (char *s); + void setType(int type) { typeLength |= ((type & 0x7F) << 9); } + int getType(void) { return (typeLength >> 9) & 0x7F; } + void setLength(int len) { typeLength |= (len & 0x1FF); } + int getLength(void) { return typeLength & 0x1FF; } + //void setType(int type) { typeLength |= (type & 0x7F); } + //int getType(void) { return typeLength & 0x7F; } + //void setLength(int len) { typeLength |= ((len & 0x1FF) << 7); } + //int getLength(void) { return (typeLength >> 7) & 0x1FF; } +}; + +class tlv_payload { +public: + char *pointer; + int length; + tlv_payload() { length = 0; pointer = NULL; } +}; + +#endif
diff -r 000000000000 -r a3d41f923207 tlv_basic.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_basic.cpp Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,32 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "tlv_basic.h" + +int +tlv_basic::copy(char *buf) +{ + base.header.setLength(payload.length); + base.header.copy(buf); + memcpy(&buf[2], (char *)payload.pointer, payload.length); + return base.header.getLength() + 2; +}
diff -r 000000000000 -r a3d41f923207 tlv_basic.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_basic.h Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,42 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef TLV_BASIC_H +#define TLV_BASIC_H + +#include "tlv.h" + +class tlv_basic_base { +public: + tlv_header header; +}; + +class tlv_basic { +public: + tlv_basic_base base; + tlv_payload payload; + + void setPayload(char *s, int len) { payload.pointer = s; payload.length = len; } + int copy (char *s); +}; + +#endif
diff -r 000000000000 -r a3d41f923207 tlv_chassis.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_chassis.cpp Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,34 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "tlv_chassis.h" + + +int +tlv_chassis::copy(char *buf) +{ + base.header.setLength(sizeof(tlv_chassis_base) - 2 + payload.length - 1); + base.header.copy(buf); + buf[2] = (char)base.subtype; + memcpy(buf + sizeof(tlv_chassis_base) - 1, (char *)payload.pointer, payload.length); + return base.header.getLength() + 2; +}
diff -r 000000000000 -r a3d41f923207 tlv_chassis.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_chassis.h Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,45 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef TLV_CHASSIS_H +#define TLV_CHASSIS_H + +#include "tlv.h" + +class tlv_chassis_base { +public: + tlv_header header; + uint8_t subtype; + tlv_chassis_base () { header.setType(1); } +}; + +class tlv_chassis { +public: + tlv_chassis_base base; + tlv_payload payload; + + void setSubtype(int subtype) { base.subtype = (uint8_t)(subtype & 0xFF); } + void setPayload(char *s, int len) { payload.pointer = s; payload.length = len; } + int copy (char *); +}; + +#endif
diff -r 000000000000 -r a3d41f923207 tlv_custom.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_custom.cpp Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,36 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "tlv_custom.h" + +int +tlv_custom::copy(char *buf) +{ + base.header.setLength(6 + payload.length); + base.header.copy(buf); + buf[2] = (char)base.oui[0]; + buf[3] = (char)base.oui[1]; + buf[4] = (char)base.oui[2]; + buf[5] = (char)base.subtype; + memcpy(&buf[6], (char *)payload.pointer, payload.length); + return base.header.getLength(); +}
diff -r 000000000000 -r a3d41f923207 tlv_custom.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_custom.h Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,47 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef TLV_CUSTOM_H +#define TLV_CUSTOM_H + +#include "tlv.h" + +class tlv_custom_base { +public: + tlv_header header; + uint8_t oui[3]; + uint8_t subtype; + tlv_custom_base () { header.setType(127); } +}; + +class tlv_custom { +public: + tlv_custom_base base; + tlv_payload payload; + + void setOUI(char *s) { base.oui[0] = s[0]; base.oui[1] = s[1]; base.oui[2] = s[2]; } + void setSubtype(int subtype) { base.subtype = (uint8_t)(subtype & 0xFF); } + void setPayload(char *s, int len) { payload.pointer = s; payload.length = len; } + int copy (char *); +}; + +#endif
diff -r 000000000000 -r a3d41f923207 tlv_port.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_port.cpp Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,33 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "tlv_port.h" + +int +tlv_port::copy(char *buf) +{ + base.header.setLength(sizeof(tlv_port_base) - 2 + payload.length - 1); + base.header.copy(buf); + buf[2] = (char)base.subtype; + memcpy(buf + sizeof(tlv_port_base) - 1, (char *)payload.pointer, payload.length); + return base.header.getLength() + 2; +}
diff -r 000000000000 -r a3d41f923207 tlv_port.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_port.h Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,45 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef TLV_PORT_H +#define TLV_PORT_H + +#include "tlv.h" + +class tlv_port_base { +public: + tlv_header header; + uint8_t subtype; + tlv_port_base() { header.setType(2); } +}; + +class tlv_port { +public: + tlv_port_base base; + tlv_payload payload; + + void setSubtype(int subtype) { base.subtype = (uint8_t)(subtype & 0xFF); } + void setPayload(char *s, int len) { payload.pointer = s; payload.length = len; } + int copy (char *s); +}; + +#endif
diff -r 000000000000 -r a3d41f923207 tlv_ttl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_ttl.cpp Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,32 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "tlv_ttl.h" + +int +tlv_ttl::copy(char *buf) +{ + header.copy(buf); + buf[2] = (char)((ttl >> 8) & 0xFF); + buf[3] = (char)(ttl & 0xFF); + return header.getLength() + 2; +}
diff -r 000000000000 -r a3d41f923207 tlv_ttl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlv_ttl.h Wed Nov 17 19:39:33 2010 +0000 @@ -0,0 +1,38 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef TLV_TTL_H +#define TLV_TTL_H + +#include "tlv.h" + +class tlv_ttl { +public: + tlv_header header; + uint16_t ttl; + tlv_ttl() { header.setType(3); header.setLength(2); ttl = 300; } + + void setTTL(int value) { ttl = (uint16_t)(value & 0xFFFF); } + int copy (char *s); +}; + +#endif