Commit 3a16a930 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: avoid bit fields on our types

The __BYTE_ORDER == __LITTLE_ENDIAN was failing on lm32, I don't know
why. So dumping on the spec was wrong: "VERSION: unsupported (0)"

The above symbols are defined by glibc, and I didn't even get
undefined macro errors. So the commit kill bit fields, and I mask at
run time instead.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 7559ded4
/* copied from /usr/include/netinet/ip.h */
#if __BYTE_ORDER == __LITTLE_ENDIAN
#elif __BYTE_ORDER == __BIG_ENDIAN
# error "big endian not supported, yet"
#else
# error "Please fix <bits/endian.h>"
#endif
/*
* I used to have bit fields, but endianness detection failed. Let's be
* honest: bit fields must die. I use masks at run time instead
*/
/* Common Message header (table 18, page 124) -- was "MsgHeader */
struct ptp_header {
/* 0 */
unsigned int messageType:4;
unsigned int transportSpecific:4;
uint8_t type_and_transport_specific; /* LSB = type */
/* 1 */
unsigned int versionPTP:4;
unsigned int reserved1:4;
uint8_t versionPTP_and_reserved; /* LSB = version */
/* 2 */
uint16_t messageLength;
/* 4 */
......
......@@ -156,13 +156,15 @@ static void dump_payload(char *prefix, void *pl, int len)
struct ptp_header *h = pl;
void *msg_specific = (void *)(h + 1);
int donelen = 34; /* packet length before tlv */
int version = h->versionPTP_and_reserved & 0xf;
int messageType = h->type_and_transport_specific & 0xf;
if (h->versionPTP != 2) {
printf("%sVERSION: unsupported (%i)\n", prefix, h->versionPTP);
if (version != 2) {
printf("%sVERSION: unsupported (%i)\n", prefix, version);
return;
}
printf("%sVERSION: %i (type %i, len %i, domain %i)\n", prefix,
h->versionPTP, h->messageType,
version, messageType,
ntohs(h->messageLength), h->domainNumber);
printf("%sFLAGS: 0x%04x (correction 0x%08lu)\n", prefix, h->flagField,
(unsigned long)h->correctionField);
......@@ -170,7 +172,7 @@ static void dump_payload(char *prefix, void *pl, int len)
printf("%sREST: seq %i, ctrl %i, log-interval %i\n", prefix,
ntohs(h->sequenceId), h->controlField, h->logMessageInterval);
#define CASE(t, x) case PPM_ ##x: printf("%sMESSAGE: (" #t ") " #x "\n", prefix)
switch(h->messageType) {
switch(messageType) {
CASE(E, SYNC);
dump_msg_sync_etc(prefix, "MSG-SYNC: ", msg_specific);
donelen = 44;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment