Trouble sending ICMP (but can receive ok and send UDP & TCP)

Hi,

I am using a W5500 with a Silicon Labs EM357 (ARM based).

I’ve setup socket 0 as MACRAW and can receive all kinds of traffic on this socket (ICMP, UDP, IPv6), which is good.
I’ve setup socket 4 as TCP Server and can receive TCP traffic on this and send TCP traffic (telnet), which is good.
I’ve setup socket 2 as UDP and can send UDP from this socket, which is good.

I cannot seem to send ICMP using the socket 0 which is setup for MACRAW. If I use the same code and change to using socket 2 (UDP) the packet goes out (but has an IP and UDP header and is not ICMP). Any ideas on what could make the packet not go out? The status on socket 0 is 0x42 = SOCK_MACRAW. I’ve included a dump of the socket registers and common registers, and the code used for init and send of the ICMP packet.

Any suggestions or help is greatly appreciated.

Thanks,
-Matt

------------ Common Register -------------
Mode (MR)…: 10
Gateway Addr (GAR)…: 0A 01 01 01
Subnet Mask (SUBR)…: FF FF FF 00
Src HW addr (SHWR)…: 70 B3 D5 55 90 88
Src IP addr (SIPR)…: 0A 01 01 C0
Int Level (INTLVL)…: 00 00
Interrupt(IR)…: 00
Int Mask (IMR)…: 80
Sock Int (SIR)…: 00
Sock Int Mask (SIMR): FF
Retry time (RTR)…: 07 D0
Retry count (RCR)…: 02
unreach IP (UIPR)…: 00 00 00 00
unreach Port (UPRTR): 00 00
Phy config (PHYCFGR): FF
chip version (VERR).: 04
------------ Socket Register 0: raw -------------
mode (SnMR)…: 04
command (SnCR)…: 00
interrupt (SnIR)…: 00
status (SnSR)…: 42
source port (SnPORTR).: 00 00
Dst HW addr (SnDHAR)…: FF FF FF FF FF FF
Dst IP addr (SnDIPR)…: 00 00 00 00
Dst Port (SnDPORT)…: 00 00
Max seg size (SnMSSR).: 05 B4
RX buff size (SnRXBUF): 02
TX buff size (SnTXBUF): 02
TX Free size (SnTXFSR): 08 00
TX Read ptr (SnTXRD)…: 00 4A
TX Write ptr (SnTXWR).: 00 4A
RX recv size (SnRXRSR): 00 00
RX read ptr (SnRXRD)…: 01 E2
RX write ptr (SnRXWD).: 01 E2
Int Mask (SnIMR)…: FF

My init code for socket 0:

// sc1SpiReadOrWrite6BytesOrLess(readOrWrite, socketId, addresToWriteTo, byteToWrite, values…)

// Mode = MACRAW = 0b0100 = 0000 0100 = 0x04
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0000, 1, 0x04, 0,0,0,0,0);
// command = OPEN = 1
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0001, 1, 0x01, 0,0,0,0,0);
// max segment size = 1460
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0012, 2, 0x05, 0xB4,0,0,0,0);
// IP TOS = 0b1000 = 0x08
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0015, 1, 0x08, 0,0,0,0,0);
// IP TTL = default for IP = 64
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0016, 1, 64, 0,0,0,0,0);
// RX Buffer = 2KB
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x001E, 1, 2, 0,0,0,0,0);
// TX Buffer = 2KB
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x001F, 1, 2, 0,0,0,0,0);

My “send a ping” code for socket 0:

// dest mac address
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0006, 6, 0x74, 0x86, 0x7A, 0x59, 0xA9, 0x47);
// dest IP address
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x000C, 4, ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3], 0,0);
// Socket 0 command register = OPEN = 1
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0001, 1, 0x01, 0,0,0,0,0);

// ---- Ethernet ----

// dest MAC
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 0, 6, 0x74, 0x86, 0x7A, 0x59, 0xA9, 0x47);
// source MAC
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 6, 6, 0x70, 0xB3, 0xD5, 0x55, 0x90, 0x99);
// ethertype
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 12, 2, 0x80, 0x00, 0,0,0,0);

// ---- IP ----

int16u ipId = 12;
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 14, 6, 0x45, 0x00, 0x00, 0x3C, HIGH_BYTE(ipId), LOW_BYTE(ipId));
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 20, 6, 0x00, 0x00, 0x40, 0x01, 0xdd, 0xdd);
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 26, 4, wiznetSrcIp[0], wiznetSrcIp[1], wiznetSrcIp[2], wiznetSrcIp[3], 0,0);
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 30, 4, ipAddr[0], ipAddr[1], ipAddr[3], ipAddr[4], 0,0);

// — ICMP ----
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 34, 6, 0x00, 0x00, 0xdd, 0xdd, HIGH_BYTE(icmpId), LOW_BYTE(icmpId));
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 40, 2, HIGH_BYTE(seqNum), LOW_BYTE(seqNum), 0,0,0,0);

// ICMP data
int8u i;
for (i=0; i<32; i++) {
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_TX, 42+i, 1, 60+i, 0,0,0,0,0);
}

// TX buffer size = 42 + 32 = 74
int16u txSize = 74;
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0024, 2, HIGH_BYTE(txSize), LOW_BYTE(txSize), 0,0,0,0);
// Socket 0 command register = SEND = 0x20
sc1SpiReadOrWrite6BytesOrLess(SPI_WRITE, BLOCK_SOCKET0_REGISTER, 0x0001, 1, 0x20, 0,0,0,0,0);

I didn’t figure out why I can’t send from a MACRAW socket but I did change to use a IPRAW socket and use ICMP and this allowed me to send and receive ICMP messages