summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandrew-elder <aelder@audioscience.com>2016-04-01 16:51:04 -0400
committerandrew-elder <aelder@audioscience.com>2016-04-01 16:51:04 -0400
commit780683fb8a789ad56c8eacfb66bcccf921cf298a (patch)
tree650199bf470c2ffb0de5783891d48d4884520253
parent94740d02475cbe52e9faa666985b7b7980e50547 (diff)
parentf7cdaa841a8cb013a794ad95d61e3abe5a939916 (diff)
downloadOpen-AVB-feature-gptp-next.tar.gz
Merge pull request #367 from davidcemin/task-gptpv3feature-gptp-next
64 bit words network/host order conversion
-rw-r--r--daemons/gptp/common/ptp_message.cpp4
-rw-r--r--daemons/gptp/linux/src/platform.cpp8
-rw-r--r--daemons/gptp/linux/src/platform.hpp14
-rw-r--r--daemons/gptp/windows/daemon_cl/platform.cpp10
-rw-r--r--daemons/gptp/windows/daemon_cl/platform.hpp14
5 files changed, 48 insertions, 2 deletions
diff --git a/daemons/gptp/common/ptp_message.cpp b/daemons/gptp/common/ptp_message.cpp
index 691abc3c..ef8eb728 100644
--- a/daemons/gptp/common/ptp_message.cpp
+++ b/daemons/gptp/common/ptp_message.cpp
@@ -489,7 +489,7 @@ PTPMessageCommon *buildPTPMessage
memcpy(&(msg->correctionField),
buf + PTP_COMMON_HDR_CORRECTION(PTP_COMMON_HDR_OFFSET),
sizeof(msg->correctionField));
- msg->correctionField = byte_swap64(msg->correctionField); // Assume LE machine
+ msg->correctionField = PLAT_ntohll(msg->correctionField);
msg->sourcePortIdentity = sourcePortIdentity;
msg->sequenceId = sequenceId;
memcpy(&(msg->control),
@@ -523,7 +523,7 @@ void PTPMessageCommon::buildCommonHeader(uint8_t * buf)
* So I am not sure why we are adding 0x10 to it
*/
tspec_msg_t = messageType | 0x10;
- long long correctionField_BE = byte_swap64(correctionField); // Assume LE machine
+ long long correctionField_BE = PLAT_htonll(correctionField);
uint16_t messageLength_NO = PLAT_htons(messageLength);
memcpy(buf + PTP_COMMON_HDR_TRANSSPEC_MSGTYPE(PTP_COMMON_HDR_OFFSET),
diff --git a/daemons/gptp/linux/src/platform.cpp b/daemons/gptp/linux/src/platform.cpp
index 7a5bb71d..8ad587b9 100644
--- a/daemons/gptp/linux/src/platform.cpp
+++ b/daemons/gptp/linux/src/platform.cpp
@@ -46,3 +46,11 @@ uint16_t PLAT_ntohs( uint16_t s ) {
uint32_t PLAT_ntohl( uint32_t l ) {
return ntohl( l );
}
+uint64_t PLAT_htonll(uint64_t x)
+{
+ return ( (htonl(1) == 1) ? x : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32) );
+}
+uint64_t PLAT_ntohll(uint64_t x)
+{
+ return( (ntohl(1) == 1) ? x : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32) );
+}
diff --git a/daemons/gptp/linux/src/platform.hpp b/daemons/gptp/linux/src/platform.hpp
index c7977b5b..26d4cada 100644
--- a/daemons/gptp/linux/src/platform.hpp
+++ b/daemons/gptp/linux/src/platform.hpp
@@ -73,4 +73,18 @@ uint16_t PLAT_ntohs( uint16_t s );
*/
uint32_t PLAT_ntohl( uint32_t l );
+/**
+ * @brief Converts a 64-bit word from host to network order
+ * @param x Value to be converted
+ * @return Converted value
+ */
+uint64_t PLAT_htonll(uint64_t x);
+
+/**
+ * @brief Converts a 64 bit word from network to host order
+ * @param x Value to be converted
+ * @return Converted value
+ */
+uint64_t PLAT_ntohll(uint64_t x);
+
#endif
diff --git a/daemons/gptp/windows/daemon_cl/platform.cpp b/daemons/gptp/windows/daemon_cl/platform.cpp
index 12f9aa56..a6ec4d50 100644
--- a/daemons/gptp/windows/daemon_cl/platform.cpp
+++ b/daemons/gptp/windows/daemon_cl/platform.cpp
@@ -53,3 +53,13 @@ uint16_t PLAT_ntohs( uint16_t s ) {
uint32_t PLAT_ntohl( uint32_t l ) {
return ntohl( l );
}
+
+uint64_t PLAT_htonll(uint64_t x)
+{
+ return ( (htonl(1) == 1) ? x : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32) );
+}
+
+uint64_t PLAT_ntohll(uint64_t x)
+{
+ return( (ntohl(1) == 1) ? x : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32) );
+}
diff --git a/daemons/gptp/windows/daemon_cl/platform.hpp b/daemons/gptp/windows/daemon_cl/platform.hpp
index 7e81d5a4..ef14e19f 100644
--- a/daemons/gptp/windows/daemon_cl/platform.hpp
+++ b/daemons/gptp/windows/daemon_cl/platform.hpp
@@ -79,4 +79,18 @@ uint16_t PLAT_ntohs( uint16_t s );
*/
uint32_t PLAT_ntohl( uint32_t l );
+/**
+ * @brief Converts a 64-bit word from host to network order
+ * @param x Value to be converted
+ * @return Converted value
+ */
+uint64_t PLAT_htonll(uint64_t x);
+
+/**
+ * @brief Converts a 64 bit word from network to host order
+ * @param x Value to be converted
+ * @return Converted value
+ */
+uint64_t PLAT_ntohll(uint64_t x);
+
#endif