Processing MACRAW large response

Using the info i was able to gleen from here - MACRAW Application Note? - #3 by suhwan
I’ve been able to implement a MACRAW driver that passes the data to the FreeRTOS TCP stack and i thought i had it all working. My plan was just to use the driver to pass one packet at a time to the FreeRTOS stack. Here is the code i use to try and receive only 1 packet at a time. It works for DHCP and dns and all my testing was looking good. But upon making my first TCP connection [to an mqtt server] it returns a “data_len” [see code] of around 20000 to 65000. How can i be receiving a packet that large if my MTU is 1526?
If it is reporting the full length instead of the packet length I’m emotionally destroyed. I can’t possibly allocate 20kb of ram. And i’ve no idea how to retrieve keeping alignment with the frames so the FreeRTOS stack is happy.

Please Help

//the point here is to get the the ptr to the start of the ethernet packet and return the packet length.
//must try to keep buffers in alignment. :frowning:
uint16_t macraw_prep(uint8_t sn, uint16_t tot_len)
{
uint16_t data_len = 0;
uint16_t ptr = 0;
uint32_t addrsel = 0;

ptr = getSn_RX_RD(sn);
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
data_len = WIZCHIP_READ(addrsel);
ptr++;
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
data_len = ((data_len<<8) + WIZCHIP_READ(addrsel)) - 2;
ptr++;

if(data_len > 1536)
{
 //recommand : close and open - something went wrong to get here
	setSn_CR(sn,Sn_CR_CLOSE);
	setSn_MR(sn, (Sn_MR_MACRAW | (0 & 0xF0)));
	setSn_CR(sn,Sn_CR_OPEN);
	return 0;
}

if(data_len > getSn_RX_RSR(sn))
{
 //not a full packet in buffer
 return 0;
}

setSn_RX_RD(sn,ptr);

setSn_CR(sn,Sn_CR_RECV); // this should make the new pointer stick.

return data_len;
}

something is just funny about this whole thing.
len1 = getSn_RX_RSR(sn); is returning 64506, how is that possible if i’ve only got 16k of buffer for socket 0? funny how it works with dhcp and dns until i try connecting to this server. I can also confirm that if i shut the server down the large reply problem is exactly the same.

Ahhhhhhh! Mark as solved. Sorry if anyone looked into this. My code wasn’t thread safe. Got to remember with freertos that other crap is going on out of sight and out of mind.