wireshark DHCP抓包
网线插拔代码
第一次插上网线成功通信的串口打印详情
[boot] start...
[boot] jump to app...
[13:25:51.653]收←◆
[flash] ID:EF15
[sys] no init
[sys] read sys param
[sys] read sn param
[sys] read run param
[13:25:51.755]收←◆
[task] main start
[task] lan start
[task] dev start
[backup] ok
[LAN] gpio_for_w5500_config //W5500引脚和SPI配置
[LAN] lan_PowerOn //LAN网线上电
[13:26:02.991]收←◆
[LAN] set_w5500_mac addr //设置MAC地址
[LAN] socket_buf_init //初始化8个Socket的发送接收缓存大小
tx_size[0]: 2, Sn_TXMEM_SIZE = 2
rx_size[0]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[1]: 2, Sn_TXMEM_SIZE = 2
rx_size[1]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[2]: 2, Sn_TXMEM_SIZE = 2
rx_size[2]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[3]: 2, Sn_TXMEM_SIZE = 2
rx_size[3]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[4]: 2, Sn_TXMEM_SIZE = 2
rx_size[4]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
[13:26:03.216]收←◆
tx_size[5]: 2, Sn_TXMEM_SIZE = 2
rx_size[5]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[6]: 2, Sn_TXMEM_SIZE = 2
rx_size[6]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[7]: 2, Sn_TXMEM_SIZE = 2
rx_size[7]: 2, Sn_RXMEM_SIZE = 2
socket处于关闭状态
state : STATE_DHCP_READY //dhcp state = STATE_DHCP_READY 0
socket打开成功UDP socket
[switch] dhcp_state: 0 收包类型:0 //0 STATE_DHCP_READY 收包类型:0,暂未收到DHCP服务器返回的包
case STATE_DHCP_READY //dhcp state == STATE_DHCP_READY时执行
DHCP定时初始化,复位超时时间
sent DHCP_DISCOVER:548 bytes //发送 DISCOVER 包发送了548个字节
[13:26:03.596]收←◆
socket处于打开状态 //解析接收到的DHCP消息
DHCP_SIP:0.0.0.0
DHCP_RIP:0.0.0.0
svr_addr:192.168.1.1
DHCP MSG received
yiaddr : 192.168.1.171
p : 20008614 e : 2000866C len : 328
dhcpMessageType : 02
DHCP_SIP : 0.0.0.0
My dhcpServerIdentifier : 192.168.1.1
My DHCP server real IP address : 192.168.1.1
dhcpIPaddrLeaseTime : 43200
opt_len : 4
opt_len : 4
subnetMask : 255.255.255.0
opt_len : 4
routersOnSubnet : 192.168.1.1
opt_len : 18
opt_len : 14
解析收到的封包类型type = 2, MSG: //type == 2, DHCP_OFFER消息
[switch
[13:26:03.636]收←◆]
dhcp_state: 1 收包类型:2 // dhcp_state1 状态为 STATE_DHCP_DISCOVER已发送DISCOVER
case STATE_DHCP_READY //dhcp state == STATE_DHCP_DISCOVER时执行
DHCP定时初始化,复位超时时间
[13:26:03.666]收←◆
sent DHCP_REQUEST:548 bytes //发送 REQUEST 包
state : STATE_DHCP_REQUEST //// dhcp_state1 状态为STATE_DHCP_REQUEST已发送REQUEST
[13:26:04.027]收←◆
socket处于打开状态 //解析接收到的DHCP消息
DHCP_SIP:192.168.1.1
DHCP_RIP:192.168.1.1
svr_addr:192.168.1.1
DHCP MSG received
yiaddr : 192.168.1.171
p : 20008614 e : 2000866C len : 328
dhcpMessageType : 05
DHCP_SIP : 192.168.1.1
My dhcpServerIdentifier : 192.168.1.1
My DHCP server real IP address : 192.168.1.1
dhcpIPaddrLeaseTime : 43200
opt_len : 4
opt_len : 4
subnetMask : 255.255.255.0
opt_len : 4
routersOnSubnet : 192.168.1.1
opt_len : 18
opt_len : 14
解析收到的封包类型type = 5, MSG: //type == 5, DHCP_ACK消息
[13:26:04.096]收←◆
[switch] dhcp_state: 2 收包类型:5
case STATE_DHCP_READY
DHCP定时初始化,复位超时时间 //检查DHCP服务器分配的地址是否冲突
<Check the IP Conflict 192.168.1.171: No Conflict> //不冲突
state : STATE_DHCP_LEASED
IP from DHCP //显示分配到的地址
W5500 IP地址 : 192.168.1.171
W5500 子网掩码 : 255.255.255.0
W5500 网关 : 192.168.1.1
已从DHCP服务器成功获得IP地址
MSG_LAN_IP
lan_connect_ip 0 //SOCK_LAN == 0 ,SOCK_CLOSED
初始化 //TCPsocket
[13:26:06.853]收←◆
MSG_LAN_IP
lan_connect_ip 13 //SOCK_LAN == 13 , SOCK_INIT
连接 //socket连接服务器成功
使用DNS服务器获取服务器地址
[13:26:09.892]收←◆
Get [dl22.gps218.com]'s IP address [121.201.107.22] from 192.168.1.1
[13:26:10.930]收←◆
服务器IP:121.201.107.22 //DNS获取服务器IP
服务器端口:9883
SOCK_LAN连接 connect ok.
[13:26:11.991]收←◆
MSG_LAN_IP
lan_connect_ip 17 //SOCK_LAN == 17,SOCK_ESTABLISHED 成功连接
SOCK_ESTABLISHED
Platfoem_DevLink
PROID: netdevice,AUIF: neT21201%m*n@871!50,DEVID:42203281200000080
[13:26:12.170]收←◆
Tips: while(w5500_buf) len:4
Tips: 出来 w5500_buf
[LAN] Platfoem_DevLinkw5500_buf:
Tips: 连接成功
Subscribe Topic: downmsg/42201000004012223
[13:26:12.329]收←◆
Tips: while(w5500_buf) len:5
订阅确认 QoS等级1
MSG_LAN_LOGIN
Publish Topic: upmsg/1000/3, Msg: 42201000004012223
[13:26:12.529]收←◆
Tips: while(w5500_buf) len:63
MSG_LAN_RECV_SOCKET
Tips: MQTT Publish Send OK
topic: downmsg/42201000004012223
payload: 42201000004012223
[lan] ip1 rcv:34323230313030303030343031323232330201
[lan ip1] 终端登陆成功
第二次拔下网线后在插上的日志打印
网线断开
[13:41:36.618]收←◆
MSG_LAN_LOGIN
Publish Topic: upmsg/1000/3, Msg: 42201000004012223
CH: 0 Unexpected1 length 0
[13:41:46.658]收←◆
MSG_LAN_LOGIN
Publish Topic: upmsg/1000/3, Msg: 42201000004012223
CH: 0 Unexpected1 length 0
[13:41:51.661]收←◆
网线连接
[LAN] gpio_for_w5500_config
[LAN] lan_PowerOn
[13:41:52.922]收←◆
[LAN] set_w5500_mac addr
[LAN] socket_buf_init
tx_size[0]: 2, Sn_TXMEM_SIZE = 2
rx_size[0]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[1]: 2, Sn_TXMEM_SIZE = 2
rx_size[1]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[2]: 2, Sn_TXMEM_SIZE = 2
rx_size[2]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[3]: 2, Sn_TXMEM_SIZE = 2
rx_size[3]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[4]: 2, Sn_TXMEM_SIZE = 2
rx_size[4]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
[13:41:53.172]收←◆
tx_size[5]: 2, Sn_TXMEM_SIZE = 2
rx_size[5]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[6]: 2, Sn_TXMEM_SIZE = 2
rx_size[6]: 2, Sn_RXMEM_SIZE = 2
[LAN] socket_buf_init
tx_size[7]: 2, Sn_TXMEM_SIZE = 2
rx_size[7]: 2, Sn_RXMEM_SIZE = 2
mac=02:0a:0d:0e:0d:06
init_dhcp_client:4
socket处于关闭状态
state : STATE_DHCP_READY
socket打开成功UDP socket
[switch] dhcp_state: 0 收包类型:0
case STATE_DHCP_READY
DHCP定时初始化,复位超时时间
sent DHCP_DISCOVER:548 bytes
[13:41:53.322]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:41:53.462]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:41:53.602]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:41:53.742]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:41:53.882]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:41:54.023]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:41:54.163]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:41:54.303]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:41:54.443]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:42:26.053]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
[13:42:28.593]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
<<timeout>> state : STATE_DHCP_DISCOVER
sent DHCP_DISCOVER:548 bytes
[13:42:28.753]收←◆
socket处于打开状态
[switch] dhcp_state: 1 收包类型:0
case STATE_DHCP_READY
DHCP定时初始化,复位超时时间
[13:42:28.823]收←◆
sent DHCP_DISCOVER:548 bytes
timeout : state : STATE_DHCP_DISCOVER
DHCP_timeout, set dhcp_state = STATE_DHCP_READY
DHCP 终端发送Discover包给DHCP服务器 —— 成功通信和失败通信的抓包文件对比
疑问
是第二次W5500重新设置错了吗还是第一次通信成功没有释放IP地址导致服务器中保存着之前的地址也问过官网客服暂时未解决该问题。
官网客服回答謝謝你的資料. 因為每一個客戶都會用不同的方法去連我們的W5500 芯片去溝通, 所以我們只可以建議一些方向給客戶. 看了你的資料後, 我們覺得是你DHCP服務器方面好像有點問題.我們建議先看看是不是服務器的問題. 如果你覺得真的不是你的DHCP服務器問題, 我覺得你可以參考我們的DHCP代碼做對比和測試看那裡出了問題吧.
官方DHCP代码https://www.w5500.com/code/W5500EVB/DHCP.html