TLVPackOS.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * void * TLVPackOS (void const * memory, size_t extent, uint8_t type, uint16_t length, void const * value);
  11. *
  12. * lldp.h
  13. *
  14. * write an IEEE 802.1AB organizationally specific TLV into memory
  15. * and return the address of the next free memory location; type
  16. * and length are converted to 7-bits and 9-bits respectively per
  17. * the standard;
  18. *
  19. * use macro TLV_HEAD to insert type and length into the header;
  20. * the type is 0x7F and OUI is 00:B0:52;
  21. *
  22. *--------------------------------------------------------------------*/
  23. #ifndef TLVPACKOS_SOURCE
  24. #define TLVPACKOS_SOURCE
  25. #include <stdio.h>
  26. #include <stdint.h>
  27. #include <string.h>
  28. #include "../tools/types.h"
  29. #include "../lldp/lldp.h"
  30. void * TLVPackOS (void const * memory, size_t extent, uint8_t type, uint16_t length, void const * value)
  31. {
  32. byte * offset = (byte *) (memory);
  33. struct tlv * tlv = (struct tlv *) (memory);
  34. if ((sizeof (* tlv) + 4 + length) <= extent)
  35. {
  36. tlv->head = TLV_HEAD (0x7F, length);
  37. tlv->data [0] = 0x00;
  38. tlv->data [1] = 0xB0;
  39. tlv->data [2] = 0x52;
  40. tlv->data [3] = type;
  41. memcpy (tlv->data + 4, value, length);
  42. offset += sizeof (* tlv) + 4 + length;
  43. }
  44. return ((void *) (offset));
  45. }
  46. #endif