How to detect unplugged LAN cable ?

Hello there…
i am having problem with detecting unplugged LAN cable.
i read that i must turn on the keep alive timer, so if the remote client/server doesnt reply when keep alive timer send 1 byte data, W5500 will generate timeout interrupt, and then i can close the socket.

And then i found something weird. I did 3 type of testing. the result is:

TESTING 1

  1. set socket 0 to TCP server
  2. socket 0 OPEN
  3. set keep alive timer to 1 (5 secs)
  4. socket 0 LISTEN
  5. remote TCP Client connecting to W5500
  6. connected, socket status become 0x17
  7. TCP client send some data, received normally by W5500
  8. and then i unplugged the LAN cable
  9. after some time, socket TIMEOUT occurs (as expected)
  10. socket 0 closed, back to point 2

TESTING 2

  1. set socket 0 to TCP server
  2. socket 0 OPEN
  3. set keep alive timer to 1 (5 secs)
  4. socket 0 LISTEN
  5. remote TCP Client connecting to W5500
  6. connected, socket status become 0x17
  7. W5500 send some data, received normally by remote TCP client
  8. and then i unplugged the LAN cable
  9. after some time, socket TIMEOUT occurs (as expected)
  10. socket 0 closed, back to point 2

TESTING 3

  1. set socket 0 to TCP server
  2. socket 0 OPEN
  3. set keep alive timer to 1 (5 secs)
  4. socket 0 LISTEN
  5. remote TCP Client connecting to W5500
  6. connected, socket status become 0x17
  7. do nothing
  8. and then i unplugged the LAN cable
  9. i waited, but no timeout at all.

i am confused about TESTING 3. do i have to send/receive data first, so the timeout will occur? or there is another way to detect unplugged cable?

Hi.
I determine a link link this:

  • linked: (getPHYCFGR() & PHYCFGR_LNK_ON)
  • unlinked: !(getPHYCFGR() & PHYCFGR_LNK_ON)

Hello Yaumen,
thank you for your advice. I implemented it, and it worked OK.