Link-local 地址:设备根据 MAC 地址自动生成 Link-local 地址(FE80::/10 前缀),并通过 DAD(重复地址检测)确认该地址在链路上唯一。
Global 地址:通过路由器公告(RA)进行无状态地址自动配置(SLAAC),或通过 DHCPv6 向服务器申请。
SLAAC 无状态地址自动配置
SLAAC(Stateless Address Autoconfiguration)是 IPv6 中通过路由器公告(RA)自动配置地址的机制。路由器周期性发送 RA 报文,包含网络前缀、网关、DNS 等信息。设备根据 RA 中的前缀和自身的接口标识符组合生成 Global 地址。本例程通过 W6300 的 MACRAW 模式捕获 RA 报文并解析,完成地址自动配置。
硬件连接与拓扑
请注意:
测试需要路由器支持并开启 IPv6,且发送 RA 公告。PC 和开发板需在同一网段。PC 端作为 TCP 客户端/服务器与开发板通信。
打开 WIZ UartTool V1.0,连接 DEBUG USB 对应 COM 口(115200 / 8N1)。烧录例程运行后,首先进行 PHY 链路检测,然后执行 DAD 检测和 RA 解析,完成 IPv6 地址自动配置后启动 TCP 服务器和客户端。预期串口输出如下:
MH2457 W6300 QSPI example start
W6300 IPv6 TCP Client / Server example
PHY no link
PHY no link
PHY link
The current Mbtis speed : 100Mbps
The current Duplex Mode : Full-Duplex
Duplicate_Address_Detection
Wait RQIR.....
Timeout !!! DAD SUCCESSED
flags = 0x80
Address_Auto_Configuration Start
RA capture mode : W6300 MACRAW
Sn_SR : 42
RA
type : 86
code : 0
RA_flag : c0
Router_lifetime : 1800 s
Reachable_time : 0 ms
Retrans_time : 0 ms
Option Type : 1, length : 8
Option Type : 5, length : 8
Option Type : 3, length : 32
Prefix Length : 64
Prefix Information Flag : c0
valid lifetime : 238095
preferred lifetime : 151695
Accepted first autonomous /64 PIO
Option Type : 25, length : 24
DNS lifetime : 1800
Option Type : 7, length : 8
MO normalized result : 3
RA requests Stateful DHCPv6
Mac address : 00:08:dc:12:34:56
your Link Local IP is fe80:0000:0000:0000:0208:dcff:fe12:3456
your Global IP is 240e:033d:945a:a301:0208:dcff:fe12:3456
your Gateway IP is fe80:0000:0000:0000:0000:0000:0000:0002
your DNSv6 is 240e:033d:945a:a301:0000:0000:0000:0001
Stateful DHCPv6 succeeded
Link-local address: FE80:0000:0000:0000:0208:DCFF:FE12:3456
Global address: 240E:033D:945A:A301:0000:0000:0000:05EC
IPv6 gateway: FE80:0000:0000:0000:0000:0000:0000:0002
IPv6 DNS: 240E:033D:945A:A301:0000:0000:0000:0001
IPv6 auto configuration complete; starting application loop
1:TCP server loopback start
1:Socket opened[19]
1:Listen, TCP server loopback, port [5000] as IPv6 mode
排查步骤:1) 确认路由器支持并开启 IPv6,且发送 RA 公告;2) 确认 PC 和 W6300 在同一网段;3) 检查串口是否打印 DAD SUCCESSED 和 RA 解析信息;4) 若 RA 未收到,检查路由器 IPv6 配置;5) 程序在自动配置失败时不会启动应用循环,可根据串口提示定位问题。