From 4e173932d22c950ab23590e2ca0685c775d2f7f6 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 29 Jul 2012 07:24:59 +0200 Subject: [PATCH] Add hooks for converting TLV values to and from host byte order. Signed-off-by: Richard Cochran --- makefile | 2 +- msg.c | 3 +++ tlv.c | 27 +++++++++++++++++++++++++++ tlv.h | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tlv.c create mode 100644 tlv.h diff --git a/makefile b/makefile index 78d2059..bd99e97 100644 --- a/makefile +++ b/makefile @@ -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) diff --git a/msg.c b/msg.c index 8558ccd..0082a90 100644 --- a/msg.c +++ b/msg.c @@ -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); diff --git a/tlv.c b/tlv.c new file mode 100644 index 0000000..7a94eee --- /dev/null +++ b/tlv.c @@ -0,0 +1,27 @@ +/** + * @file tlv.c + * @note Copyright (C) 2012 Richard Cochran + * + * 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) +{ +} diff --git a/tlv.h b/tlv.h new file mode 100644 index 0000000..613938e --- /dev/null +++ b/tlv.h @@ -0,0 +1,37 @@ +/** + * @file tlv.h + * @brief Implements helper routines for processing Type Length Value fields. + * @note Copyright (C) 2012 Richard Cochran + * + * 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