From a987b1b7453955e8edd3e2d12e5bde46b7085bc6 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Tue, 24 Jul 2012 03:31:15 +0000 Subject: [PATCH] handling TLVs in received response messages. --- src/management.c | 9 +- tools/ptpmanager/handleIncomingMsg.c | 251 +++++++++++++++++++++++++-- tools/ptpmanager/packOutgoingMsg.c | 2 +- tools/ptpmanager/ptpmanager.h | 117 +++++++++++++ 4 files changed, 364 insertions(+), 15 deletions(-) diff --git a/src/management.c b/src/management.c index 9f6aaf4d..b1f3f939 100644 --- a/src/management.c +++ b/src/management.c @@ -265,7 +265,7 @@ void handleMMUserDescription(MsgManagement* incoming, MsgManagement* outgoing, P userDescriptionLength); /* add null-terminator to make use of C string function strlen later */ ptpClock->user_description[userDescriptionLength] = '\0'; - printf("==> %d , %s, %s,\n",(int)data->userDescription.lengthField, data->userDescription.textField, ptpClock->user_description); + printf("lengthField: %d , TextField: %s,\n",(int)data->userDescription.lengthField, ptpClock->user_description); } else { WARNING("management user description exceeds specification length \n"); } @@ -283,6 +283,7 @@ void handleMMUserDescription(MsgManagement* incoming, MsgManagement* outgoing, P memcpy(data->userDescription.textField, ptpClock->user_description, data->userDescription.lengthField); + printf("lengthField: %d , TextField: %s,\n",(int)data->userDescription.lengthField, data->userDescription.textField); break; default: printf(" unknown actionType \n"); @@ -1056,7 +1057,7 @@ void handleMMClockAccuracy(MsgManagement* incoming, MsgManagement* outgoing, Ptp data = (MMClockAccuracy*)incoming->tlv->dataField; /* SET actions */ ptpClock->clockQuality.clockAccuracy = data->clockAccuracy; - printf("Clock Accuracy = %x\n",ptpClock->clockQuality.clockAccuracy); + printf("Clock Accuracy = %hhu\n",ptpClock->clockQuality.clockAccuracy); /* intentionally fall through to GET case */ case GET: printf(" GET action\n"); @@ -1065,6 +1066,8 @@ void handleMMClockAccuracy(MsgManagement* incoming, MsgManagement* outgoing, Ptp data = (MMClockAccuracy*)outgoing->tlv->dataField; /* GET actions */ data->clockAccuracy = ptpClock->clockQuality.clockAccuracy; + printf("Clock Accuracy = %hhu\n",ptpClock->clockQuality.clockAccuracy); + printf("Clock Accuracy = %x\n",ptpClock->clockQuality.clockAccuracy); data->reserved = 0x0; break; case RESPONSE: @@ -1117,6 +1120,7 @@ void handleMMUtcProperties(MsgManagement* incoming, MsgManagement* outgoing, Ptp Octet li59 = SET_FIELD(ptpClock->leap59, LI59); Octet li61 = SET_FIELD(ptpClock->leap61, LI61); data->utcv_li59_li61 = utcv | li59 | li61; + printf("bool byte = %hhu\n",data->utcv_li59_li61); data->reserved = 0x0; break; case RESPONSE: @@ -1163,6 +1167,7 @@ void handleMMTraceabilityProperties(MsgManagement* incoming, MsgManagement* outg Octet ftra = SET_FIELD(ptpClock->frequencyTraceable, FTRA); Octet ttra = SET_FIELD(ptpClock->timeTraceable, TTRA); data->ftra_ttra = ftra | ttra; + printf("bool byte = %hhu\n",data->ftra_ttra); data->reserved = 0x0; break; case RESPONSE: diff --git a/tools/ptpmanager/handleIncomingMsg.c b/tools/ptpmanager/handleIncomingMsg.c index b22404b2..7bd89680 100644 --- a/tools/ptpmanager/handleIncomingMsg.c +++ b/tools/ptpmanager/handleIncomingMsg.c @@ -48,6 +48,195 @@ unpackManagementHeader(Octet *inmessage, MsgManagement *manage) manage->tlv->managementId = flip16(*(UInteger16 *) (inmessage + 52)); } + +void +handleUserDescription(MsgManagement *manage) +{ + char tempBuf[100]; + MMUserDescription *data = (MMUserDescription *)(inmessage + 54); + data->userDescription.textField = (Octet*)(inmessage + 55); + memcpy(tempBuf,data->userDescription.textField,data->userDescription.lengthField); + tempBuf[data->userDescription.lengthField] = '\0'; + printf("Lengthfield: %hhu\n",data->userDescription.lengthField); + printf("Name_of_device;Physical_location = %s\n",tempBuf); +} + +void +handlePriority1(MsgManagement *manage) +{ + MMPriority1* data = (MMPriority1 *)(inmessage + 54); + printf("Priority1 = %hhu\n",data->priority1); +} + +void +handlePriority2(MsgManagement *manage) +{ + MMPriority2* data = (MMPriority2 *)(inmessage + 54); + printf("Priority1 = %hhu\n",data->priority2); +} + +void +handleDomain(MsgManagement *manage) +{ + MMDomain* data = (MMDomain*)(inmessage + 54); + printf("Domain = %hhu\n",data->domainNumber); +} + +void +handleSlaveOnly(MsgManagement *manage) +{ + MMSlaveOnly* data = (MMSlaveOnly*)(inmessage + 54); + if ((data->so && 01) == 0) + printf("SlaveOnly = False\n"); + else + printf("SlaveOnly = True\n"); +} + +void +handleLogAnnounceInterval(MsgManagement *manage) +{ + MMLogAnnounceInterval* data = (MMLogAnnounceInterval*)(inmessage + 54); + printf("LogAnnounceInterval = %hhd\n",data->logAnnounceInterval); +} + +void +handleAnnounceReceiptTimeout(MsgManagement *manage) +{ + MMAnnounceReceiptTimeout* data = (MMAnnounceReceiptTimeout*)(inmessage + 54); + printf("AnnounceReceiptTimeout = %hhu\n",data->announceReceiptTimeout); +} + +void +handleLogSyncInterval(MsgManagement *manage) +{ + MMLogSyncInterval* data = (MMLogSyncInterval*)(inmessage + 54); + printf("LogSyncInterval = %hhd\n",data->logSyncInterval); +} + +void +handleVersionNumber(MsgManagement *manage) +{ + MMVersionNumber* data = (MMVersionNumber*)(inmessage + 54); + printf("VersionNumber = %hhu\n",data->versionNumber); +} + +void +handleClockAccuracy(MsgManagement *manage) +{ + MMClockAccuracy* data = (MMClockAccuracy*)(inmessage + 54); + printf("ClockAccuracy = %hhu\n",data->clockAccuracy); + switch(data->clockAccuracy){ + case 32: + printf("The time is accurate to within 25 ns\n"); + break; + case 33: + printf("The time is accurate to within 100 ns\n"); + break; + case 34: + printf("The time is accurate to within 250 ns\n"); + break; + case 35: + printf("The time is accurate to within 1 microsec\n"); + break; + case 36: + printf("The time is accurate to within 2.5 microsec\n"); + break; + case 37: + printf("The time is accurate to within 10 microsec\n"); + break; + case 38: + printf("The time is accurate to within 25 microsec\n"); + break; + case 39: + printf("The time is accurate to within 100 microsec\n"); + break; + case 40: + printf("The time is accurate to within 250 microsec\n"); + break; + case 41: + printf("The time is accurate to within 1 millisec\n"); + break; + case 42: + printf("The time is accurate to within 2.5 millisec\n"); + break; + case 43: + printf("The time is accurate to within 10 millisec\n"); + break; + case 44: + printf("The time is accurate to within 25 millisec\n"); + break; + case 45: + printf("The time is accurate to within 100 millisec\n"); + break; + case 46: + printf("The time is accurate to within 250 millisec\n"); + break; + case 47: + printf("The time is accurate to within 1 sec\n"); + break; + case 48: + printf("The time is accurate to within 10 sec\n"); + break; + case 49: + printf("The time is accurate to > 10 sec\n"); + break; + default: + printf("Unknown accuracy\n"); + } +} + +void +handleUtcProperties(MsgManagement *manage) +{ + MMUtcProperties* data = (MMUtcProperties*)(inmessage + 54); + printf("currentUtcOffset = %hd\n",data->currentUtcOffset); + if ((data->utcv_li59_li61 & 0x04) == 0) + printf("UTCV = False, "); + else + printf("UTCV = True, "); + + if ((data->utcv_li59_li61 & 0x02) == 0) + printf("L1-59 = False, "); + else + printf("L1-59 = True, "); + + if ((data->utcv_li59_li61 & 0x01) == 0) + printf("L1-61 = False\n"); + else + printf("L1-61 = True\n"); +} + +void +handleTraceabilityProperties(MsgManagement *manage) +{ + MMTraceabilityProperties* data = (MMTraceabilityProperties*)(inmessage + 54); + if ((data->ftra_ttra & 0x20) == 0) + printf("FTRA = False, "); + else + printf("FTRA = True, "); + + if ((data->ftra_ttra & 0x10) == 0) + printf("TTRA = False\n"); + else + printf("TTRA = True\n"); + +} + +void +handleDelayMechanism(MsgManagement *manage) +{ + MMDelayMechanism* data = (MMDelayMechanism*)(inmessage + 54); + printf("DelayMechanism = %hhu\n",data->delayMechanism); +} + +void +handleLogMinRequirement(MsgManagement *manage) +{ + MMLogMinPdelayReqInterval* data = (MMLogMinPdelayReqInterval*)(inmessage + 54); + printf("LogMinPdelayReqInterval = %hhu\n",data->logMinPdelayReqInterval); +} + + /*Function to handle management response and display the required fields*/ void handleManagementResponse(Octet *inmessage, MsgManagement *manage) @@ -55,32 +244,70 @@ handleManagementResponse(Octet *inmessage, MsgManagement *manage) printf("Received a RESPONSE management message.\n"); switch(manage->tlv->managementId){ case MM_NULL_MANAGEMENT: - case MM_CLOCK_DESCRIPTION: + //nothing to handle + break; + case MM_USER_DESCRIPTION: - case MM_SAVE_IN_NON_VOLATILE_STORAGE: - case MM_RESET_NON_VOLATILE_STORAGE: - case MM_INITIALIZE: - case MM_DEFAULT_DATA_SET: - case MM_CURRENT_DATA_SET: - case MM_PARENT_DATA_SET: - case MM_TIME_PROPERTIES_DATA_SET: - case MM_PORT_DATA_SET: + handleUserDescription(manage); + break; case MM_PRIORITY1: + handlePriority1(manage); + break; case MM_PRIORITY2: + handlePriority2(manage); + break; case MM_DOMAIN: + handleDomain(manage); + break; case MM_SLAVE_ONLY: + handleSlaveOnly(manage); + break; case MM_LOG_ANNOUNCE_INTERVAL: + handleLogAnnounceInterval(manage); + break; case MM_ANNOUNCE_RECEIPT_TIMEOUT: + handleAnnounceReceiptTimeout(manage); + break; case MM_LOG_SYNC_INTERVAL: + handleLogSyncInterval(manage); + break; case MM_VERSION_NUMBER: - case MM_ENABLE_PORT: - case MM_DISABLE_PORT: - case MM_TIME: + handleVersionNumber(manage); + break; case MM_CLOCK_ACCURACY: + handleClockAccuracy(manage); + break; case MM_UTC_PROPERTIES: + handleUtcProperties(manage); + break; case MM_TRACEABILITY_PROPERTIES: + handleTraceabilityProperties(manage); + break; case MM_DELAY_MECHANISM: + handleDelayMechanism(manage); + break; case MM_LOG_MIN_PDELAY_REQ_INTERVAL: + handleLogMinRequirement(manage); + break; + + case MM_CLOCK_DESCRIPTION: + case MM_DEFAULT_DATA_SET: + case MM_CURRENT_DATA_SET: + case MM_PARENT_DATA_SET: + case MM_TIME_PROPERTIES_DATA_SET: + case MM_PORT_DATA_SET: + printf("Yet to handle the response\n"); + break; + + case MM_SAVE_IN_NON_VOLATILE_STORAGE: + case MM_RESET_NON_VOLATILE_STORAGE: + case MM_INITIALIZE: + case MM_ENABLE_PORT: + case MM_DISABLE_PORT: + printf("But Ack was expected\n"); + break; + + case MM_TIME: case MM_FAULT_LOG: case MM_FAULT_LOG_RESET: case MM_TIMESCALE_PROPERTIES: diff --git a/tools/ptpmanager/packOutgoingMsg.c b/tools/ptpmanager/packOutgoingMsg.c index 79b47b91..8421c7d6 100644 --- a/tools/ptpmanager/packOutgoingMsg.c +++ b/tools/ptpmanager/packOutgoingMsg.c @@ -584,7 +584,7 @@ packMMClockAccuracy(Octet *buf) break; case SET: *(UInteger8 *) (buf + 46) = *(UInteger8 *) (buf + 46) | SET; - printf(">clock accuracy number (20-31) see table 6?"); + printf(">clock accuracy number (32-49) see table 6?"); scanf("%hhu",(UInteger8 *)(manage->tlv) + TLV_LENGTH); *(UInteger16 *) (buf + 2) = flip16(MANAGEMENT_LENGTH+TLV_LENGTH + 2); manage->tlv->lengthField = flip16(0x0004); diff --git a/tools/ptpmanager/ptpmanager.h b/tools/ptpmanager/ptpmanager.h index 1611db2a..904143da 100644 --- a/tools/ptpmanager/ptpmanager.h +++ b/tools/ptpmanager/ptpmanager.h @@ -99,6 +99,123 @@ typedef struct { PTPText userDescription; } MMUserDescription; +/** + * \brief Management TLV Priority1 fields (Table 51 of the spec) + */ +/* Management TLV Priority1 Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/priority1.def" +} MMPriority1; + +/** + * \brief Management TLV Priority2 fields (Table 52 of the spec) + */ +/* Management TLV Priority2 Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/priority2.def" +} MMPriority2; + +/** + * \brief Management TLV Domain fields (Table 53 of the spec) + */ +/* Management TLV Domain Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/domain.def" +} MMDomain; + +/** + * \brief Management TLV Slave Only fields (Table 54 of the spec) + */ +/* Management TLV Slave Only Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/slaveOnly.def" +} MMSlaveOnly; + +/** + * \brief Management TLV Log Announce Interval fields (Table 62 of the spec) + */ +/* Management TLV Log Announce Interval Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/logAnnounceInterval.def" +} MMLogAnnounceInterval; + +/** + * \brief Management TLV Announce Receipt Timeout fields (Table 63 of the spec) + */ +/* Management TLV Announce Receipt Timeout Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/announceReceiptTimeout.def" +} MMAnnounceReceiptTimeout; + +/** + * \brief Management TLV Log Sync Interval fields (Table 64 of the spec) + */ +/* Management TLV Log Sync Interval Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/logSyncInterval.def" +} MMLogSyncInterval; + +/** + * \brief Management TLV Version Number fields (Table 67 of the spec) + */ +/* Management TLV Version Number Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/versionNumber.def" +} MMVersionNumber; + +/** + * \brief Management TLV Clock Accuracy fields (Table 49 of the spec) + */ +/* Management TLV Clock Accuracy Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/clockAccuracy.def" +} MMClockAccuracy; + +/** + * \brief Management TLV UTC Properties fields (Table 58 of the spec) + */ +/* Management TLV UTC Properties Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/utcProperties.def" +} MMUtcProperties; + +/** + * \brief Management TLV Traceability Properties fields (Table 59 of the spec) + */ +/* Management TLV Traceability Properties Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/traceabilityProperties.def" +} MMTraceabilityProperties; + +/** + * \brief Management TLV Delay Mechanism fields (Table 65 of the spec) + */ +/* Management TLV Delay Mechanism Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/delayMechanism.def" +} MMDelayMechanism; + +/** + * \brief Management TLV Log Min Pdelay Req Interval fields (Table 66 of the spec) + */ +/* Management TLV Log Min Pdelay Req Interval Message */ +typedef struct { + #define OPERATE( name, size, type ) type name; + #include "../../src/def/managementTLV/logMinPdelayReqInterval.def" +} MMLogMinPdelayReqInterval; + /** * \brief Management message fields (Table 37 of the spec) */