Convert the management TLV to and from host byte order.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-07-29 08:49:09 +02:00
parent 7f18da0191
commit b654f6c35c
2 changed files with 53 additions and 0 deletions

46
tlv.c
View File

@ -16,12 +16,58 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <arpa/inet.h>
#include "tlv.h" #include "tlv.h"
void tlv_post_recv(struct TLV *tlv) void tlv_post_recv(struct TLV *tlv)
{ {
struct management_tlv *mgt;
switch (tlv->type) {
case TLV_MANAGEMENT:
mgt = (struct management_tlv *) tlv;
mgt->id = ntohs(mgt->id);
break;
case TLV_MANAGEMENT_ERROR_STATUS:
case TLV_ORGANIZATION_EXTENSION:
case TLV_REQUEST_UNICAST_TRANSMISSION:
case TLV_GRANT_UNICAST_TRANSMISSION:
case TLV_CANCEL_UNICAST_TRANSMISSION:
case TLV_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION:
case TLV_PATH_TRACE:
case TLV_ALTERNATE_TIME_OFFSET_INDICATOR:
case TLV_AUTHENTICATION:
case TLV_AUTHENTICATION_CHALLENGE:
case TLV_SECURITY_ASSOCIATION_UPDATE:
case TLV_CUM_FREQ_SCALE_FACTOR_OFFSET:
default:
break;
}
} }
void tlv_pre_send(struct TLV *tlv) void tlv_pre_send(struct TLV *tlv)
{ {
struct management_tlv *mgt;
switch (tlv->type) {
case TLV_MANAGEMENT:
mgt = (struct management_tlv *) tlv;
mgt->id = htons(mgt->id);
break;
case TLV_MANAGEMENT_ERROR_STATUS:
case TLV_ORGANIZATION_EXTENSION:
case TLV_REQUEST_UNICAST_TRANSMISSION:
case TLV_GRANT_UNICAST_TRANSMISSION:
case TLV_CANCEL_UNICAST_TRANSMISSION:
case TLV_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION:
case TLV_PATH_TRACE:
case TLV_ALTERNATE_TIME_OFFSET_INDICATOR:
case TLV_AUTHENTICATION:
case TLV_AUTHENTICATION_CHALLENGE:
case TLV_SECURITY_ASSOCIATION_UPDATE:
case TLV_CUM_FREQ_SCALE_FACTOR_OFFSET:
default:
break;
}
} }

7
tlv.h
View File

@ -96,6 +96,13 @@ enum management_action {
#define DELAY_MECHANISM 0x6000 #define DELAY_MECHANISM 0x6000
#define LOG_MIN_PDELAY_REQ_INTERVAL 0x6001 #define LOG_MIN_PDELAY_REQ_INTERVAL 0x6001
struct management_tlv {
Enumeration16 type;
UInteger16 length;
Enumeration16 id;
Octet data[0];
} PACKED;
/** /**
* Converts recognized value sub-fields into host byte order. * Converts recognized value sub-fields into host byte order.
* @param tlv Pointer to a Type Length Value field. * @param tlv Pointer to a Type Length Value field.