Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
LLDP.cpp@0:a3d41f923207, 2010-11-17 (annotated)
- Committer:
- AjK
- Date:
- Wed Nov 17 19:39:33 2010 +0000
- Revision:
- 0:a3d41f923207
TEST ONLY!
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| AjK | 0:a3d41f923207 | 1 | /* | 
| AjK | 0:a3d41f923207 | 2 | Copyright (c) 2010 Andy Kirkham | 
| AjK | 0:a3d41f923207 | 3 | |
| AjK | 0:a3d41f923207 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy | 
| AjK | 0:a3d41f923207 | 5 | of this software and associated documentation files (the "Software"), to deal | 
| AjK | 0:a3d41f923207 | 6 | in the Software without restriction, including without limitation the rights | 
| AjK | 0:a3d41f923207 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
| AjK | 0:a3d41f923207 | 8 | copies of the Software, and to permit persons to whom the Software is | 
| AjK | 0:a3d41f923207 | 9 | furnished to do so, subject to the following conditions: | 
| AjK | 0:a3d41f923207 | 10 | |
| AjK | 0:a3d41f923207 | 11 | The above copyright notice and this permission notice shall be included in | 
| AjK | 0:a3d41f923207 | 12 | all copies or substantial portions of the Software. | 
| AjK | 0:a3d41f923207 | 13 | |
| AjK | 0:a3d41f923207 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
| AjK | 0:a3d41f923207 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
| AjK | 0:a3d41f923207 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
| AjK | 0:a3d41f923207 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
| AjK | 0:a3d41f923207 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| AjK | 0:a3d41f923207 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
| AjK | 0:a3d41f923207 | 20 | THE SOFTWARE. | 
| AjK | 0:a3d41f923207 | 21 | */ | 
| AjK | 0:a3d41f923207 | 22 | |
| AjK | 0:a3d41f923207 | 23 | |
| AjK | 0:a3d41f923207 | 24 | #include "mbed.h" | 
| AjK | 0:a3d41f923207 | 25 | #include "LLDP.h" | 
| AjK | 0:a3d41f923207 | 26 | |
| AjK | 0:a3d41f923207 | 27 | const char LLDPinfo1[] = "MBED"; | 
| AjK | 0:a3d41f923207 | 28 | const char LLDPinfo2[] = "A rapid prototyping system for the LPC17xx embedded microcontroller"; | 
| AjK | 0:a3d41f923207 | 29 | const char LLDPinfo3[] = "\x00\x80\x00\x80"; | 
| AjK | 0:a3d41f923207 | 30 | |
| AjK | 0:a3d41f923207 | 31 | LLDP::LLDP() : Ethernet() | 
| AjK | 0:a3d41f923207 | 32 | { | 
| AjK | 0:a3d41f923207 | 33 | int totalLength = 0; | 
| AjK | 0:a3d41f923207 | 34 | address(macAddress); | 
| AjK | 0:a3d41f923207 | 35 | |
| AjK | 0:a3d41f923207 | 36 | memset(buffer, 0xFF, sizeof(buffer)); | 
| AjK | 0:a3d41f923207 | 37 | |
| AjK | 0:a3d41f923207 | 38 | // Default to 4:MACAddress | 
| AjK | 0:a3d41f923207 | 39 | _chassis.setSubtype(4); | 
| AjK | 0:a3d41f923207 | 40 | _chassis.setPayload(macAddress, 6); | 
| AjK | 0:a3d41f923207 | 41 | |
| AjK | 0:a3d41f923207 | 42 | // Default to 4:MACAddress | 
| AjK | 0:a3d41f923207 | 43 | _port.setSubtype(3); | 
| AjK | 0:a3d41f923207 | 44 | _port.setPayload(macAddress, 6); | 
| AjK | 0:a3d41f923207 | 45 | |
| AjK | 0:a3d41f923207 | 46 | //_mbed.setOUI(macAddress); | 
| AjK | 0:a3d41f923207 | 47 | //_mbed.setSubtype(1); | 
| AjK | 0:a3d41f923207 | 48 | //_mbed.setPayload((char *)LLDPinfo, strlen(LLDPinfo)); | 
| AjK | 0:a3d41f923207 | 49 | _systemName.base.header.setType(5); | 
| AjK | 0:a3d41f923207 | 50 | _systemName.setPayload((char *)LLDPinfo1, strlen(LLDPinfo1)); | 
| AjK | 0:a3d41f923207 | 51 | |
| AjK | 0:a3d41f923207 | 52 | _systemDesc.base.header.setType(6); | 
| AjK | 0:a3d41f923207 | 53 | _systemDesc.setPayload((char *)LLDPinfo2, strlen(LLDPinfo2)); | 
| AjK | 0:a3d41f923207 | 54 | |
| AjK | 0:a3d41f923207 | 55 | _systemCap.base.header.setType(7); | 
| AjK | 0:a3d41f923207 | 56 | _systemCap.setPayload((char *)LLDPinfo3, 4); | 
| AjK | 0:a3d41f923207 | 57 | |
| AjK | 0:a3d41f923207 | 58 | totalLength += _chassis.copy(buffer + totalLength); | 
| AjK | 0:a3d41f923207 | 59 | totalLength += _port.copy(buffer + totalLength); | 
| AjK | 0:a3d41f923207 | 60 | totalLength += _ttl.copy(buffer + totalLength); | 
| AjK | 0:a3d41f923207 | 61 | //totalLength += _mbed.copy(buffer + totalLength); | 
| AjK | 0:a3d41f923207 | 62 | totalLength += _systemName.copy(buffer + totalLength); | 
| AjK | 0:a3d41f923207 | 63 | totalLength += _systemDesc.copy(buffer + totalLength); | 
| AjK | 0:a3d41f923207 | 64 | totalLength += _systemCap.copy(buffer + totalLength); | 
| AjK | 0:a3d41f923207 | 65 | totalLength += _end.copy(buffer + totalLength); | 
| AjK | 0:a3d41f923207 | 66 | buflen = totalLength; | 
| AjK | 0:a3d41f923207 | 67 | } | 
| AjK | 0:a3d41f923207 | 68 | |
| AjK | 0:a3d41f923207 | 69 | void | 
| AjK | 0:a3d41f923207 | 70 | LLDP::broadcast(void) | 
| AjK | 0:a3d41f923207 | 71 | { | 
| AjK | 0:a3d41f923207 | 72 | char e[6 + 6 + 2]; | 
| AjK | 0:a3d41f923207 | 73 | |
| AjK | 0:a3d41f923207 | 74 | e[0] = 0x01; e[1] = 0x80; e[2] = 0xc2; e[3] = 0x00; e[4] = 0x00; e[5] = 0x0e; | 
| AjK | 0:a3d41f923207 | 75 | e[6] = macAddress[0]; | 
| AjK | 0:a3d41f923207 | 76 | e[7] = macAddress[1]; | 
| AjK | 0:a3d41f923207 | 77 | e[8] = macAddress[2]; | 
| AjK | 0:a3d41f923207 | 78 | e[9] = macAddress[3]; | 
| AjK | 0:a3d41f923207 | 79 | e[10] = macAddress[4]; | 
| AjK | 0:a3d41f923207 | 80 | e[11] = macAddress[5]; | 
| AjK | 0:a3d41f923207 | 81 | e[12] = 0x88; | 
| AjK | 0:a3d41f923207 | 82 | e[13] = 0xCC; | 
| AjK | 0:a3d41f923207 | 83 | |
| AjK | 0:a3d41f923207 | 84 | write(e, 6 + 6 + 2); | 
| AjK | 0:a3d41f923207 | 85 | write(buffer, buflen); | 
| AjK | 0:a3d41f923207 | 86 | send(); | 
| AjK | 0:a3d41f923207 | 87 | } |