9 static const u8_t broadcast[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
11 static const u8_t magic_cookie[] = { 0x63, 0x82, 0x53, 0x63 };
13 static u8_t dhcp_offer[] = {
14 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d,
15 0x00, 0x0F, 0xEE, 0x30, 0xAB, 0x22,
17 0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8,
18 0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00,
23 0xAA, 0xAA, 0xAA, 0xAA,
26 0x00, 0x00, 0x00, 0x00,
27 0xc3, 0xaa, 0xbd, 0xc8,
28 0xc3, 0xaa, 0xbd, 0xab,
29 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00,
46 0x63, 0x82, 0x53, 0x63,
48 0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab,
49 0x33, 0x04, 0x00, 0x00, 0x00, 0x78,
50 0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab,
51 0x01, 0x04, 0xff, 0xff, 0xff, 0x00,
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 static u8_t dhcp_ack[] = {
58 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d,
59 0x00, 0x0f, 0xEE, 0x30, 0xAB, 0x22,
61 0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8,
62 0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00,
66 0xAA, 0xAA, 0xAA, 0xAA,
69 0x00, 0x00, 0x00, 0x00,
70 0xc3, 0xaa, 0xbd, 0xc8,
71 0xc3, 0xaa, 0xbd, 0xab,
72 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00,
89 0x63, 0x82, 0x53, 0x63,
91 0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab,
92 0x33, 0x04, 0x00, 0x00, 0x00, 0x78,
93 0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab,
94 0x01, 0x04, 0xff, 0xff, 0xff, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101 static const u8_t arpreply[] = {
102 0x00, 0x23, 0xC1, 0xDE, 0xD0, 0x0D,
103 0x00, 0x32, 0x44, 0x20, 0x01, 0x02,
110 0x00, 0x32, 0x44, 0x20, 0x01, 0x02,
111 0xc3, 0xaa, 0xbd, 0xc8,
112 0x00, 0x23, 0xC1, 0xDE, 0xD0, 0x0D,
113 0x00, 0x00, 0x00, 0x00,
124 static int debug = 0;
125 static void setdebug(
int a) {debug = a;}
128 static void tick_lwip(
void)
134 if (tick % 600 == 0) {
139 static void send_pkt(
struct netif *
netif,
const u8_t *data,
size_t len)
148 printf(
"RX data (len %d)", p->
tot_len);
149 for (i = 0; i <
len; i++) {
150 printf(
" %02X", data[i]);
155 fail_unless(p !=
NULL);
156 for(q = p; q !=
NULL; q = q->
next) {
160 netif->
input(p, netif);
163 static err_t lwip_tx_func(
struct netif *netif,
struct pbuf *p);
165 static err_t testif_init(
struct netif *netif)
167 netif->
name[0] =
'c';
168 netif->
name[1] =
'h';
169 netif->output = etharp_output;
185 static void dhcp_setup(
void)
190 static void dhcp_teardown(
void)
198 fail_if((pos + len) > p->
tot_len);
199 while (pos > p->
len && p->
next) {
204 fail_unless(pos + len <= p->len);
207 fail_if(memcmp(&data[pos],
mem, len),
"data at pos %d, len %d in packet %d did not match", pos, len, txpacket);
216 fail_if((startpos + len) > p->
tot_len);
217 while (startpos > p->
len && p->
next) {
222 fail_unless(startpos + len <= p->len);
226 for (i = startpos; i <= (p->
len -
len); i++) {
227 if (memcmp(&data[i],
mem, len) == 0) {
235 static err_t lwip_tx_func(
struct netif *netif,
struct pbuf *p)
243 printf(
"TX data (pkt %d, len %d, tick %d)", txpacket, p->
tot_len, tick);
246 for (i = 0; i < pp->
len; i++) {
262 const u8_t ipproto[] = { 0x08, 0x00 };
263 const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00};
264 const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
266 check_pkt(p, 0, broadcast, 6);
267 check_pkt(p, 6, netif->
hwaddr, 6);
269 check_pkt(p, 12, ipproto,
sizeof(ipproto));
271 check_pkt(p, 42, bootp_start,
sizeof(bootp_start));
273 check_pkt(p, 53, ipaddrs,
sizeof(ipaddrs));
275 check_pkt(p, 70, netif->
hwaddr, 6);
277 check_pkt(p, 278, magic_cookie,
sizeof(magic_cookie));
281 u8_t dhcp_discover_opt[] = { 0x35, 0x01, 0x01 };
282 check_pkt_fuzzy(p, 282, dhcp_discover_opt,
sizeof(dhcp_discover_opt));
283 }
else if (txpacket == 2) {
284 u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 };
285 u8_t requested_ipaddr[] = { 0x32, 0x04, 0xc3, 0xaa, 0xbd, 0xc8 };
287 check_pkt_fuzzy(p, 282, dhcp_request_opt,
sizeof(dhcp_request_opt));
288 check_pkt_fuzzy(p, 282, requested_ipaddr,
sizeof(requested_ipaddr));
296 const u8_t arpproto[] = { 0x08, 0x06 };
298 check_pkt(p, 0, broadcast, 6);
299 check_pkt(p, 6, netif->
hwaddr, 6);
301 check_pkt(p, 12, arpproto,
sizeof(arpproto));
309 const u8_t ipproto[] = { 0x08, 0x00 };
310 const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00};
311 const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
312 const u8_t dhcp_nak_opt[] = { 0x35, 0x01, 0x04 };
313 const u8_t requested_ipaddr[] = { 0x32, 0x04, 0xc3, 0xaa, 0xbd, 0xc8 };
315 fail_unless(txpacket == 4);
316 check_pkt(p, 0, broadcast, 6);
317 check_pkt(p, 6, netif->
hwaddr, 6);
319 check_pkt(p, 12, ipproto,
sizeof(ipproto));
321 check_pkt(p, 42, bootp_start,
sizeof(bootp_start));
323 check_pkt(p, 53, ipaddrs,
sizeof(ipaddrs));
325 check_pkt(p, 70, netif->
hwaddr, 6);
327 check_pkt(p, 278, magic_cookie,
sizeof(magic_cookie));
329 check_pkt_fuzzy(p, 282, dhcp_nak_opt,
sizeof(dhcp_nak_opt));
331 check_pkt_fuzzy(p, 282, requested_ipaddr,
sizeof(requested_ipaddr));
340 const u8_t ipproto[] = { 0x08, 0x00 };
341 const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00};
342 const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
344 check_pkt(p, 0, broadcast, 6);
345 check_pkt(p, 6, netif->
hwaddr, 6);
347 check_pkt(p, 12, ipproto,
sizeof(ipproto));
349 check_pkt(p, 42, bootp_start,
sizeof(bootp_start));
351 check_pkt(p, 53, ipaddrs,
sizeof(ipaddrs));
353 check_pkt(p, 70, netif->
hwaddr, 6);
355 check_pkt(p, 278, magic_cookie,
sizeof(magic_cookie));
359 u8_t dhcp_discover_opt[] = { 0x35, 0x01, 0x01 };
360 check_pkt_fuzzy(p, 282, dhcp_discover_opt,
sizeof(dhcp_discover_opt));
361 }
else if (txpacket == 2) {
362 u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 };
363 u8_t requested_ipaddr[] = { 0x32, 0x04, 0x4f, 0x8a, 0x33, 0x05 };
365 check_pkt_fuzzy(p, 282, dhcp_request_opt,
sizeof(dhcp_request_opt));
366 check_pkt_fuzzy(p, 282, requested_ipaddr,
sizeof(requested_ipaddr));
375 const u8_t arpproto[] = { 0x08, 0x06 };
377 check_pkt(p, 0, broadcast, 6);
378 check_pkt(p, 6, netif->
hwaddr, 6);
380 check_pkt(p, 12, arpproto,
sizeof(arpproto));
385 const u8_t fake_arp[6] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xab };
386 const u8_t ipproto[] = { 0x08, 0x00 };
387 const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00};
388 const u8_t ipaddrs[] = { 0x00, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
389 const u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 };
391 check_pkt(p, 0, fake_arp, 6);
392 check_pkt(p, 6, netif->
hwaddr, 6);
394 check_pkt(p, 12, ipproto,
sizeof(ipproto));
396 check_pkt(p, 42, bootp_start,
sizeof(bootp_start));
398 check_pkt(p, 53, ipaddrs,
sizeof(ipaddrs));
400 check_pkt(p, 70, netif->
hwaddr, 6);
402 check_pkt(p, 278, magic_cookie,
sizeof(magic_cookie));
405 check_pkt_fuzzy(p, 282, dhcp_request_opt,
sizeof(dhcp_request_opt));
434 IP4_ADDR(&addr, 0, 0, 0, 0);
435 IP4_ADDR(&netmask, 0, 0, 0, 0);
436 IP4_ADDR(&gw, 0, 0, 0, 0);
443 fail_unless(txpacket == 1);
445 memcpy(&dhcp_offer[46], &xid, 4);
446 send_pkt(&
net_test, dhcp_offer,
sizeof(dhcp_offer));
449 fail_if(memcmp(&addr, &
net_test.ip_addr,
sizeof(ip4_addr_t)));
450 fail_if(memcmp(&netmask, &
net_test.netmask,
sizeof(ip4_addr_t)));
451 fail_if(memcmp(&gw, &
net_test.gw,
sizeof(ip4_addr_t)));
453 fail_unless(txpacket == 1,
"TX %d packets, expected 1", txpacket);
455 memcpy(&dhcp_offer[46], &xid, 4);
456 send_pkt(&
net_test, dhcp_offer,
sizeof(dhcp_offer));
458 fail_unless(txpacket == 2,
"TX %d packets, expected 2", txpacket);
460 memcpy(&dhcp_ack[46], &xid, 4);
461 send_pkt(&
net_test, dhcp_ack,
sizeof(dhcp_ack));
463 fail_unless(txpacket == 2,
"TX %d packets, still expected 2", txpacket);
465 memcpy(&dhcp_ack[46], &xid, 4);
466 send_pkt(&
net_test, dhcp_ack,
sizeof(dhcp_ack));
468 for (i = 0; i < 20; i++) {
471 fail_unless(txpacket == 5,
"TX %d packets, expected 5", txpacket);
477 IP4_ADDR(&addr, 195, 170, 189, 200);
478 IP4_ADDR(&netmask, 255, 255, 255, 0);
479 IP4_ADDR(&gw, 195, 170, 189, 171);
480 fail_if(memcmp(&addr, &
net_test.ip_addr,
sizeof(ip4_addr_t)));
481 fail_if(memcmp(&netmask, &
net_test.netmask,
sizeof(ip4_addr_t)));
482 fail_if(memcmp(&gw, &
net_test.gw,
sizeof(ip4_addr_t)));
503 IP4_ADDR(&addr, 0, 0, 0, 0);
504 IP4_ADDR(&netmask, 0, 0, 0, 0);
505 IP4_ADDR(&gw, 0, 0, 0, 0);
512 fail_unless(txpacket == 1);
514 memcpy(&dhcp_offer[46], &xid, 4);
515 send_pkt(&
net_test, dhcp_offer,
sizeof(dhcp_offer));
518 fail_if(memcmp(&addr, &
net_test.ip_addr,
sizeof(ip4_addr_t)));
519 fail_if(memcmp(&netmask, &
net_test.netmask,
sizeof(ip4_addr_t)));
520 fail_if(memcmp(&gw, &
net_test.gw,
sizeof(ip4_addr_t)));
522 fail_unless(txpacket == 1);
524 memcpy(&dhcp_offer[46], &xid, 4);
525 send_pkt(&
net_test, dhcp_offer,
sizeof(dhcp_offer));
527 fail_unless(txpacket == 2);
529 memcpy(&dhcp_ack[46], &xid, 4);
530 send_pkt(&
net_test, dhcp_ack,
sizeof(dhcp_ack));
532 fail_unless(txpacket == 2);
534 memcpy(&dhcp_ack[46], &xid, 4);
535 send_pkt(&
net_test, dhcp_ack,
sizeof(dhcp_ack));
537 fail_unless(txpacket == 3);
542 send_pkt(&
net_test, arpreply,
sizeof(arpreply));
544 fail_unless(txpacket == 4);
557 u8_t relay_offer[] = {
558 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d,
559 0x00, 0x22, 0x93, 0x5a, 0xf7, 0x60,
560 0x08, 0x00, 0x45, 0x00,
561 0x01, 0x38, 0xfd, 0x53, 0x00, 0x00, 0x40, 0x11,
562 0x78, 0x46, 0x4f, 0x8a, 0x32, 0x02, 0x4f, 0x8a,
563 0x33, 0x05, 0x00, 0x43, 0x00, 0x44, 0x01, 0x24,
564 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x51, 0x35,
565 0xb6, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
566 0x00, 0x00, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00,
567 0x00, 0x00, 0x0a, 0xb5, 0x04, 0x01, 0x00, 0x23,
568 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00,
569 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
570 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
571 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
572 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
573 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
574 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
575 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
576 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
577 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
579 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
580 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
581 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
582 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
583 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
584 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
585 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
586 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
587 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
588 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
589 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
590 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
591 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
592 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
593 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82,
594 0x53, 0x63, 0x01, 0x04, 0xff, 0xff, 0xfe, 0x00,
595 0x03, 0x04, 0x4f, 0x8a, 0x32, 0x01, 0x06, 0x08,
596 0x4f, 0x8a, 0x00, 0xb4, 0x55, 0x08, 0x1f, 0xd1,
597 0x1c, 0x04, 0x4f, 0x8a, 0x33, 0xff, 0x33, 0x04,
598 0x00, 0x00, 0x54, 0x49, 0x35, 0x01, 0x02, 0x36,
599 0x04, 0x0a, 0xb5, 0x04, 0x01, 0xff
602 u8_t relay_ack1[] = {
603 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x22,
604 0x93, 0x5a, 0xf7, 0x60, 0x08, 0x00, 0x45, 0x00,
605 0x01, 0x38, 0xfd, 0x55, 0x00, 0x00, 0x40, 0x11,
606 0x78, 0x44, 0x4f, 0x8a, 0x32, 0x02, 0x4f, 0x8a,
607 0x33, 0x05, 0x00, 0x43, 0x00, 0x44, 0x01, 0x24,
608 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x51, 0x35,
609 0xb6, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
610 0x00, 0x00, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00,
611 0x00, 0x00, 0x0a, 0xb5, 0x04, 0x01, 0x00, 0x23,
612 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00,
613 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
614 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
615 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
616 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
617 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
618 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
619 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
620 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
621 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
622 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
623 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
624 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
625 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
626 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
627 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
628 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
629 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
630 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
631 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
632 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
633 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
634 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
635 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
636 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
637 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82,
638 0x53, 0x63, 0x01, 0x04, 0xff, 0xff, 0xfe, 0x00,
639 0x03, 0x04, 0x4f, 0x8a, 0x32, 0x01, 0x06, 0x08,
640 0x4f, 0x8a, 0x00, 0xb4, 0x55, 0x08, 0x1f, 0xd1,
641 0x1c, 0x04, 0x4f, 0x8a, 0x33, 0xff, 0x33, 0x04,
642 0x00, 0x00, 0x54, 0x49, 0x35, 0x01, 0x05, 0x36,
643 0x04, 0x0a, 0xb5, 0x04, 0x01, 0xff
646 u8_t relay_ack2[] = {
647 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d,
648 0x00, 0x22, 0x93, 0x5a, 0xf7, 0x60,
649 0x08, 0x00, 0x45, 0x00,
650 0x01, 0x38, 0xfa, 0x18, 0x00, 0x00, 0x40, 0x11,
651 0x7b, 0x81, 0x4f, 0x8a, 0x32, 0x02, 0x4f, 0x8a,
652 0x33, 0x05, 0x00, 0x43, 0x00, 0x44, 0x01, 0x24,
653 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x49, 0x8b,
654 0x6e, 0xab, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x8a,
655 0x33, 0x05, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00,
656 0x00, 0x00, 0x0a, 0xb5, 0x04, 0x01, 0x00, 0x23,
657 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00,
658 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
659 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
660 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
661 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
662 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
663 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
664 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
665 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
666 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
667 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
668 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
669 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
670 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
671 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
672 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
673 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
674 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
675 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
676 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
677 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
678 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
679 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
680 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
681 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
682 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82,
683 0x53, 0x63, 0x01, 0x04, 0xff, 0xff, 0xfe, 0x00,
684 0x03, 0x04, 0x4f, 0x8a, 0x32, 0x01, 0x06, 0x08,
685 0x4f, 0x8a, 0x00, 0xb4, 0x55, 0x08, 0x1f, 0xd1,
686 0x1c, 0x04, 0x4f, 0x8a, 0x33, 0xff, 0x33, 0x04,
687 0x00, 0x00, 0x54, 0x60, 0x35, 0x01, 0x05, 0x36,
688 0x04, 0x0a, 0xb5, 0x04, 0x01, 0xff };
690 const u8_t arp_resp[] = {
691 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d,
692 0x00, 0x22, 0x93, 0x5a, 0xf7, 0x60,
700 0x12, 0x34, 0x56, 0x78, 0x9a, 0xab,
701 0x4f, 0x8a, 0x32, 0x01,
703 0x00, 0x23, 0xc1, 0x00, 0x06, 0x50,
704 0x4f, 0x8a, 0x33, 0x05,
707 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
708 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
709 0x00, 0x00, 0x00, 0x00 };
721 IP4_ADDR(&addr, 0, 0, 0, 0);
722 IP4_ADDR(&netmask, 0, 0, 0, 0);
723 IP4_ADDR(&gw, 0, 0, 0, 0);
730 fail_unless(txpacket == 1);
733 fail_if(memcmp(&addr, &
net_test.ip_addr,
sizeof(ip4_addr_t)));
734 fail_if(memcmp(&netmask, &
net_test.netmask,
sizeof(ip4_addr_t)));
735 fail_if(memcmp(&gw, &
net_test.gw,
sizeof(ip4_addr_t)));
737 fail_unless(txpacket == 1);
739 memcpy(&relay_offer[46], &xid, 4);
740 send_pkt(&
net_test, relay_offer,
sizeof(relay_offer));
743 fail_unless(txpacket == 2,
"txpkt = %d, should be 2", txpacket);
745 memcpy(&relay_ack1[46], &xid, 4);
746 send_pkt(&
net_test, relay_ack1,
sizeof(relay_ack1));
748 for (i = 0; i < 25; i++) {
751 fail_unless(txpacket == 5,
"txpkt should be 5, is %d", txpacket);
757 IP4_ADDR(&addr, 79, 138, 51, 5);
758 IP4_ADDR(&netmask, 255, 255, 254, 0);
759 IP4_ADDR(&gw, 79, 138, 50, 1);
760 fail_if(memcmp(&addr, &
net_test.ip_addr,
sizeof(ip4_addr_t)));
761 fail_if(memcmp(&netmask, &
net_test.netmask,
sizeof(ip4_addr_t)));
762 fail_if(memcmp(&gw, &
net_test.gw,
sizeof(ip4_addr_t)));
764 fail_unless(txpacket == 5,
"txpacket = %d", txpacket);
766 for (i = 0; i < 108000 - 25; i++) {
771 fail_unless(txpacket == 6,
"txpacket = %d", txpacket);
775 send_pkt(&
net_test, arp_resp,
sizeof(arp_resp));
777 fail_unless(txpacket == 7,
"txpacket = %d", txpacket);
781 memcpy(&relay_ack2[46], &xid, 4);
782 send_pkt(&
net_test, relay_ack2,
sizeof(relay_ack2));
784 for (i = 0; i < 100000; i++) {
788 fail_unless(txpacket == 7,
"txpacket = %d", txpacket);
801 u8_t dhcp_nack_no_endmarker[] = {
802 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x54, 0x75,
803 0xd0, 0x26, 0xd0, 0x0d, 0x08, 0x00, 0x45, 0x00,
804 0x01, 0x15, 0x38, 0x86, 0x00, 0x00, 0xff, 0x11,
805 0xc0, 0xa8, 0xc0, 0xa8, 0x01, 0x01, 0xff, 0xff,
806 0xff, 0xff, 0x00, 0x43, 0x00, 0x44, 0x01, 0x01,
807 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x7a, 0xcb,
808 0xba, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
809 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
810 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
811 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00,
812 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
813 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
814 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
815 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
816 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
817 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
818 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
819 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
820 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
821 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
822 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
823 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
824 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
825 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
826 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
827 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
828 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
829 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
830 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
831 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
832 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
833 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
834 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
835 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
836 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82,
837 0x53, 0x63, 0x35, 0x01, 0x06, 0x36, 0x04, 0xc0,
838 0xa8, 0x01, 0x01, 0x31, 0xef, 0xad, 0x72, 0x31,
839 0x43, 0x4e, 0x44, 0x30, 0x32, 0x35, 0x30, 0x43,
840 0x52, 0x47, 0x44, 0x38, 0x35, 0x36, 0x3c, 0x08,
841 0x4d, 0x53, 0x46, 0x54, 0x20, 0x35, 0x2e, 0x30,
842 0x37, 0x0d, 0x01, 0x0f, 0x03, 0x06, 0x2c, 0x2e,
843 0x2f, 0x1f, 0x21, 0x79, 0xf9, 0x2b, 0xfc, 0xff,
844 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x71,
845 0xf3, 0x5b, 0xe2, 0x71, 0x2e, 0x01, 0x08, 0x03,
846 0x04, 0xc0, 0xa8, 0x01, 0x01, 0xff, 0xeb, 0x1e,
847 0x44, 0xec, 0xeb, 0x1e, 0x30, 0x37, 0x0c, 0x01,
848 0x0f, 0x03, 0x06, 0x2c, 0x2e, 0x2f, 0x1f, 0x21,
849 0x79, 0xf9, 0x2b, 0xff, 0x25, 0xc0, 0x09, 0xd6,
850 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
851 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
859 IP4_ADDR(&addr, 0, 0, 0, 0);
860 IP4_ADDR(&netmask, 0, 0, 0, 0);
861 IP4_ADDR(&gw, 0, 0, 0, 0);
868 fail_unless(txpacket == 1);
870 memcpy(&dhcp_offer[46], &xid, 4);
871 send_pkt(&
net_test, dhcp_offer,
sizeof(dhcp_offer));
874 fail_if(memcmp(&addr, &
net_test.ip_addr,
sizeof(ip4_addr_t)));
875 fail_if(memcmp(&netmask, &
net_test.netmask,
sizeof(ip4_addr_t)));
876 fail_if(memcmp(&gw, &
net_test.gw,
sizeof(ip4_addr_t)));
878 fail_unless(txpacket == 1);
880 memcpy(&dhcp_offer[46], &xid, 4);
881 send_pkt(&
net_test, dhcp_offer,
sizeof(dhcp_offer));
885 fail_unless(txpacket == 2);
887 memcpy(&dhcp_nack_no_endmarker[46], &xid, 4);
888 send_pkt(&
net_test, dhcp_nack_no_endmarker,
sizeof(dhcp_nack_no_endmarker));
906 TESTFUNC(test_dhcp_nak_no_endmarker)
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
void netif_set_up(struct netif *netif)
netif_linkoutput_fn linkoutput
END_TEST Suite * dhcp_suite(void)
#define NETIF_FLAG_ETHARP
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define NETIF_FLAG_BROADCAST
#define LWIP_ASSERT(message, assertion)
void netif_remove(struct netif *netif)
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
#define netif_is_up(netif)
#define LWIP_UNUSED_ARG(x)