adds CLOCK_DESCRIPTION struct

Modifies existing structs changing Octet *foo -> Octet foo[0] and
marks them PACKED so the message buffer can be cast to the structs.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
master
Geoff Salmon 2013-02-24 18:56:36 -05:00 committed by Richard Cochran
parent f4e8f5be3f
commit e919971905
4 changed files with 49 additions and 21 deletions

13
ddt.h
View File

@ -51,8 +51,13 @@ struct PortIdentity {
struct PortAddress { struct PortAddress {
Enumeration16 networkProtocol; Enumeration16 networkProtocol;
UInteger16 addressLength; UInteger16 addressLength;
Octet *address; Octet address[0];
}; } PACKED;
struct PhysicalAddress {
UInteger16 length;
Octet address[0];
} PACKED;
struct ClockQuality { struct ClockQuality {
UInteger8 clockClass; UInteger8 clockClass;
@ -68,8 +73,8 @@ struct TLV {
struct PTPText { struct PTPText {
UInteger8 length; UInteger8 length;
Octet *text; Octet text[0];
}; } PACKED;
/* A static_ptp_text is like a PTPText but includes space to store the /* A static_ptp_text is like a PTPText but includes space to store the
* text inside the struct. The text array must always be * text inside the struct. The text array must always be

26
tlv.h
View File

@ -21,6 +21,7 @@
#define HAVE_TLV_H #define HAVE_TLV_H
#include "ddt.h" #include "ddt.h"
#include "ds.h"
/* TLV types */ /* TLV types */
#define TLV_MANAGEMENT 0x0001 #define TLV_MANAGEMENT 0x0001
@ -176,10 +177,31 @@ struct time_status_np {
struct ClockIdentity gmIdentity; struct ClockIdentity gmIdentity;
} PACKED; } PACKED;
enum clock_type {
CLOCK_TYPE_ORDINARY = 0x80,
CLOCK_TYPE_BOUNDARY = 0x40,
CLOCK_TYPE_P2P = 0x20,
CLOCK_TYPE_E2E = 0x10,
CLOCK_TYPE_MANAGEMENT = 0x08,
};
#define PROFILE_ID_LEN 6
struct mgmt_clock_description {
UInteger16 *clockType;
struct PTPText *physicalLayerProtocol;
struct PhysicalAddress *physicalAddress;
struct PortAddress *protocolAddress;
Octet *manufacturerIdentity;
struct PTPText *productDescription;
struct PTPText *revisionData;
struct PTPText *userDescription;
Octet *profileIdentity;
};
struct tlv_extra { struct tlv_extra {
union { union {
/* Empty for now, but will contain structs for the struct mgmt_clock_description cd;
* TLVs that use the tlv_extra support. */
}; };
}; };

17
util.c
View File

@ -119,7 +119,7 @@ int static_ptp_text_copy(struct static_ptp_text *dst, const struct PTPText *src)
void ptp_text_copy(struct PTPText *dst, const struct static_ptp_text *src) void ptp_text_copy(struct PTPText *dst, const struct static_ptp_text *src)
{ {
dst->length = src->length; dst->length = src->length;
dst->text = (Octet *)src->text; memcpy(dst->text, src->text, src->length);
} }
int ptp_text_set(struct PTPText *dst, const char *src) int ptp_text_set(struct PTPText *dst, const char *src)
@ -130,21 +130,22 @@ int ptp_text_set(struct PTPText *dst, const char *src)
if (len > MAX_PTP_OCTETS) if (len > MAX_PTP_OCTETS)
return -1; return -1;
dst->length = len; dst->length = len;
dst->text = (Octet *)src; memcpy(dst->text, src, len);
} else { } else {
dst->length = 0; dst->length = 0;
dst->text = NULL;
} }
return 0; return 0;
} }
int static_ptp_text_set(struct static_ptp_text *dst, const char *src) int static_ptp_text_set(struct static_ptp_text *dst, const char *src)
{ {
struct PTPText t; int len = strlen(src);
size_t len = strlen(src);
if (len > MAX_PTP_OCTETS) if (len > MAX_PTP_OCTETS)
return -1; return -1;
t.length = len; if (dst->max_symbols > 0 && strlen_utf8((Octet *) src) > dst->max_symbols)
t.text = (Octet *)src; return -1;
return static_ptp_text_copy(dst, &t); dst->length = len;
memcpy(dst->text, src, len);
dst->text[len] = '\0';
return 0;
} }

14
util.h
View File

@ -58,7 +58,7 @@ int generate_clock_identity(struct ClockIdentity *ci, char *name);
/** /**
* Copies a PTPText to a static_ptp_text. This copies the text into * Copies a PTPText to a static_ptp_text. This copies the text into
* the static_ptp_text.o * the static_ptp_text.
* @param dst The static_ptp_text to copy to * @param dst The static_ptp_text to copy to
* @param src The PTPText to copy from * @param src The PTPText to copy from
* @return Zero on success, -1 if text in src is too long or not valid * @return Zero on success, -1 if text in src is too long or not valid
@ -67,18 +67,18 @@ int generate_clock_identity(struct ClockIdentity *ci, char *name);
int static_ptp_text_copy(struct static_ptp_text *dst, const struct PTPText *src); int static_ptp_text_copy(struct static_ptp_text *dst, const struct PTPText *src);
/** /**
* Copies a static_ptp_text to a PTPText. This makes the PTPText point * Copies a static_ptp_text to a PTPText. Caller must ensure it's
* to the memory inside the static_ptp_text. * valid to write to the memory after the PTPText struct. The trailing
* \0 is not copied.
* @param dst The PTPText to copy to * @param dst The PTPText to copy to
* @param src The static_ptp_text to copy from * @param src The static_ptp_text to copy from
*/ */
void ptp_text_copy(struct PTPText *dst, const struct static_ptp_text *src); void ptp_text_copy(struct PTPText *dst, const struct static_ptp_text *src);
/** /**
* Sets a PTPText from a null-terminated char*. After returning, the * Sets a PTPText from a null-terminated char*. Caller must ensure it's
* PTPText field points to the same memory as str, so str should not * valid to write to the memory after the PTPText struct. The trailing
* be modified and should remain valid as long as the PTPText can be * \0 is not copied.
* used.
* @param dst The PTPText to copy to * @param dst The PTPText to copy to
* @param src The text to copy from * @param src The text to copy from
* @return Zero on success, -1 if src is too long * @return Zero on success, -1 if src is too long