Andy K / LLDP
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LLDP.cpp Source File

LLDP.cpp

00001 /*
00002     Copyright (c) 2010 Andy Kirkham
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021 */
00022 
00023 
00024 #include "mbed.h"
00025 #include "LLDP.h"
00026 
00027 const char LLDPinfo1[] = "MBED";
00028 const char LLDPinfo2[] = "A rapid prototyping system for the LPC17xx embedded microcontroller";
00029 const char LLDPinfo3[] = "\x00\x80\x00\x80";
00030 
00031 LLDP::LLDP() : Ethernet() 
00032 {
00033     int totalLength = 0;
00034     address(macAddress);
00035     
00036     memset(buffer, 0xFF, sizeof(buffer));
00037     
00038     // Default to 4:MACAddress 
00039     _chassis.setSubtype(4);
00040     _chassis.setPayload(macAddress, 6);
00041     
00042     // Default to 4:MACAddress 
00043     _port.setSubtype(3);
00044     _port.setPayload(macAddress, 6);
00045     
00046     //_mbed.setOUI(macAddress);
00047     //_mbed.setSubtype(1);
00048     //_mbed.setPayload((char *)LLDPinfo, strlen(LLDPinfo));
00049     _systemName.base.header.setType(5);
00050     _systemName.setPayload((char *)LLDPinfo1, strlen(LLDPinfo1));
00051     
00052     _systemDesc.base.header.setType(6);
00053     _systemDesc.setPayload((char *)LLDPinfo2, strlen(LLDPinfo2));
00054     
00055     _systemCap.base.header.setType(7);
00056     _systemCap.setPayload((char *)LLDPinfo3, 4);
00057     
00058     totalLength += _chassis.copy(buffer + totalLength);
00059     totalLength += _port.copy(buffer + totalLength);
00060     totalLength += _ttl.copy(buffer + totalLength);
00061     //totalLength += _mbed.copy(buffer + totalLength);
00062     totalLength += _systemName.copy(buffer + totalLength);
00063     totalLength += _systemDesc.copy(buffer + totalLength);
00064     totalLength += _systemCap.copy(buffer + totalLength);
00065     totalLength += _end.copy(buffer + totalLength);
00066     buflen = totalLength;   
00067 }
00068 
00069 void
00070 LLDP::broadcast(void)
00071 {
00072     char e[6 + 6 + 2];
00073     
00074     e[0] = 0x01; e[1] = 0x80; e[2] = 0xc2; e[3] = 0x00; e[4] = 0x00; e[5] = 0x0e;
00075     e[6] = macAddress[0];
00076     e[7] = macAddress[1];
00077     e[8] = macAddress[2];
00078     e[9] = macAddress[3];
00079     e[10] = macAddress[4];
00080     e[11] = macAddress[5];
00081     e[12] = 0x88;
00082     e[13] = 0xCC;
00083     
00084     write(e, 6 + 6 + 2);
00085     write(buffer, buflen);
00086     send();    
00087 }