Skip to content

Commit

Permalink
Convert the management TLV to and from host byte order.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Aug 1, 2012
1 parent 7f18da0 commit b654f6c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,58 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <arpa/inet.h>

#include "tlv.h"

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)
{
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 changes: 7 additions & 0 deletions tlv.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ enum management_action {
#define DELAY_MECHANISM 0x6000
#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.
* @param tlv Pointer to a Type Length Value field.
Expand Down

0 comments on commit b654f6c

Please sign in to comment.