Add hooks for converting TLV values to and from host byte order.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-07-29 07:24:59 +02:00
parent 7d32a4bce7
commit 4e173932d2
4 changed files with 68 additions and 1 deletions

View File

@ -24,7 +24,7 @@ CFLAGS = -Wall $(INC) $(DEBUG) $(EXTRA_CFLAGS)
LDLIBS = -lm -lrt $(EXTRA_LDFLAGS)
PRG = ptp4l phc2sys hwstamp_ctl
OBJ = bmc.o clock.o config.o fsm.o ptp4l.o mave.o msg.o phc.o pi.o port.o \
print.o raw.o servo.o sk.o tmtab.o transport.o udp.o udp6.o util.o
print.o raw.o servo.o sk.o tlv.o tmtab.o transport.o udp.o udp6.o util.o
OBJECTS = $(OBJ) phc2sys.o hwstamp_ctl.o
SRC = $(OBJECTS:.o=.c)

3
msg.c
View File

@ -25,6 +25,7 @@
#include "msg.h"
#include "print.h"
#include "tlv.h"
#define VERSION_MASK 0x0f
#define VERSION 0x02
@ -164,6 +165,7 @@ static int suffix_post_recv(uint8_t *ptr, int len)
}
len -= tlv->length;
ptr += tlv->length;
tlv_post_recv(tlv);
}
return cnt;
}
@ -178,6 +180,7 @@ static void suffix_pre_send(uint8_t *ptr, int cnt)
for (i = 0; i < cnt; i++) {
tlv = (struct TLV *) ptr;
tlv_pre_send(tlv);
ptr += sizeof(struct TLV) + tlv->length;
tlv->type = htons(tlv->type);
tlv->length = htons(tlv->length);

27
tlv.c 100644
View File

@ -0,0 +1,27 @@
/**
* @file tlv.c
* @note Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "tlv.h"
void tlv_post_recv(struct TLV *tlv)
{
}
void tlv_pre_send(struct TLV *tlv)
{
}

37
tlv.h 100644
View File

@ -0,0 +1,37 @@
/**
* @file tlv.h
* @brief Implements helper routines for processing Type Length Value fields.
* @note Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef HAVE_TLV_H
#define HAVE_TLV_H
#include "ddt.h"
/**
* Converts recognized value sub-fields into host byte order.
* @param tlv Pointer to a Type Length Value field.
*/
void tlv_post_recv(struct TLV *tlv);
/**
* Converts recognized value sub-fields into network byte order.
* @param tlv Pointer to a Type Length Value field.
*/
void tlv_pre_send(struct TLV *tlv);
#endif