# FreeRTOS+TCP HW Timestamping Option

**URL:** <https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458>\
**Category:** Libraries\
**Created:** [December 18, 2019, 10:12pm UTC](https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458 "2019-12-18T22:12:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nlapp](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/nlapp/32/86_2.png) [@nlapp](https://forums.freertos.org/u/nlapp)\
**Post date:** [December 18, 2019, 10:12pm UTC](https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458/1 "2019-12-18T22:12:31Z")

</div>

Hello,

I’m wondering if there is any way to provide / enable a HW timestamping option for FreeRTOS + TCP. The micro that I’m using provides a HW timestamp on exactly when the ethernet frame was processed by the ethernet MAC, and it would be ideal to be able to propagate this information up the stack to be consumed by PTP or the like somewhere down the line.

If this doesn’t exist, can you please guide me to information on working on a patch and possibly getting it added into the FreeRTOS mainline? Would be great to get this feature added (maybe behind a #define in FreeRTOSIPConfig.h)

Thanks!

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 18, 2019, 11:27pm UTC](https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458/2 "2019-12-18T23:27:08Z")

</div>

This sounds to be a very port specific thing and currently there is no way of attaching metadata to network packets. From memory it should be possible to add a new optional field into the network packet structure to store additional information - and as that data is coming from the MAC it would have to be filled in within the driver in your case. Then that additional information would follow the network packet as it flowed through the stack up to the application.

---

<div class="post-metadata">

**Author:** ![nlapp](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/nlapp/32/86_2.png) [@nlapp](https://forums.freertos.org/u/nlapp)\
**Post date:** [December 18, 2019, 11:29pm UTC](https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458/3 "2019-12-18T23:29:22Z")

</div>

Thanks for your reply. I’m getting a working example that sort of mimics normal sockets API with SO\_TIMESTAMP. Once I’ve got this working, what’s the procedure for getting changes back into mainline? Is this possible?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 19, 2019, 1:12am UTC](https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458/4 "2019-12-19T01:12:56Z")

</div>

Yes it is definitely possible - the master copy of the TCP code is currently here [https://github.com/aws/amazon-freertos/tree/master/libraries/freertos\_plus/standard/freertos\_plus\_tcp](https://github.com/aws/amazon-freertos/tree/master/libraries/freertos_plus/standard/freertos_plus_tcp) so you can open a pull request.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [December 19, 2019, 5:33am UTC](https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458/5 "2019-12-19T05:33:10Z")

</div>

The development of a general-purpose library is often guided by 2 contradicting desires: the wish to make it as complete as possible, and on the other hand, the wish to keep things simple. TCP Time-stamping has disappeared from the library in order to decrease its complexity.

But it is possibly not TCP time-stamping what you want to do?

Like Richard suggested, you could add a new field to `NetworkBufferDescriptor_t`:

```auto
typedef struct xNETWORK_BUFFER
{
	...
	#if( ipconfigUSE_MESSAGE_TIME_STAMP != 0 )
		uint32_t ulTimeStamp;
	#endif
} NetworkBufferDescriptor_t;

```

Just curiosity: does your application have to do with ( synchronising ) audio?

---

<div class="post-metadata">

**Author:** ![nlapp](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/nlapp/32/86_2.png) [@nlapp](https://forums.freertos.org/u/nlapp)\
**Post date:** [December 20, 2019, 12:12am UTC](https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458/6 "2019-12-20T00:12:32Z")

</div>

Thanks again for the quick response. I got this part working quite nicely actually, but now I’ve run into another issue that it looks that the network stack does not support IGMP or Multicast messaging.  
My goal was to add a PTP library to FreeRTOS+TCP to replace lwIP, but the lack of multicast support means this is pretty difficult.  
I did see this post: [https://www.freertos.org/FreeRTOS\_Support\_Forum\_Archive/November\_2018/freertos\_FreeRTOS\_TCP\_support\_for\_multicast\_and\_mdns\_6699520f32j.html](https://www.freertos.org/FreeRTOS_Support_Forum_Archive/November_2018/freertos_FreeRTOS_TCP_support_for_multicast_and_mdns_6699520f32j.html)  
which mentions what you need to do to support multicast, but I’d really rather not hack up the library so much if at all possible.

Any chance multicast / IGMP support will be arriving any time soon?

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [December 20, 2019, 4:10am UTC](https://forums.freertos.org/t/freertos-tcp-hw-timestamping-option/8458/7 "2019-12-20T04:10:04Z")

</div>

There have been many proposals to add multi-casting, and also mDNS, but a decision has not been taken yet.

Note that in principle you can use multi-casting **already** : create a UDP socket, bind it to the desired UDP port number and call `recvfrom()`.

Make sure that incoming multicast packets are not dropped by a filter.  
You can define `ipconfigETHERNET_DRIVER_FILTERS_PACKETS`, and make sure that all multicast packets are let through in your `NetworkInterface.c`.

Also the peripheral (the EMAC) must be programmed to accept IPv4 multicast packets ( 0x01, 0x00, 0x5E ).  
I am attaching 2 functions for IPv4 multi-cast addresses.

```auto
/* Return pdTRUE if the IPv4 address is a multicast address. */
BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress );

/* Set the MAC-address that belongs to a given IPv4 multi-cast address. */
void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress, MACAddress_t *pxMACAddress );

```

[multicast.c](https://forums.freertos.org/uploads/short-url/8NSSKqGbZyJd23q0mzeihFGxzAk.c) (2.4 KB)
