1195972f6Sopenharmony_ci#include "test_dhcp.h" 2195972f6Sopenharmony_ci 3195972f6Sopenharmony_ci#include "lwip/netif.h" 4195972f6Sopenharmony_ci#include "lwip/dhcp.h" 5195972f6Sopenharmony_ci#include "lwip/prot/dhcp.h" 6195972f6Sopenharmony_ci#include "lwip/etharp.h" 7195972f6Sopenharmony_ci#include "netif/ethernet.h" 8195972f6Sopenharmony_ci 9195972f6Sopenharmony_cistatic struct netif net_test; 10195972f6Sopenharmony_ci 11195972f6Sopenharmony_cistatic const u8_t broadcast[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 12195972f6Sopenharmony_ci 13195972f6Sopenharmony_cistatic const u8_t magic_cookie[] = { 0x63, 0x82, 0x53, 0x63 }; 14195972f6Sopenharmony_ci 15195972f6Sopenharmony_cistatic u8_t dhcp_offer[] = { 16195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, /* To unit */ 17195972f6Sopenharmony_ci 0x00, 0x0F, 0xEE, 0x30, 0xAB, 0x22, /* From Remote host */ 18195972f6Sopenharmony_ci 0x08, 0x00, /* Protocol: IP */ 19195972f6Sopenharmony_ci 0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8, /* IP header */ 20195972f6Sopenharmony_ci 0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00, /* UDP header */ 21195972f6Sopenharmony_ci 22195972f6Sopenharmony_ci 0x02, /* Type == Boot reply */ 23195972f6Sopenharmony_ci 0x01, 0x06, /* Hw Ethernet, 6 bytes addrlen */ 24195972f6Sopenharmony_ci 0x00, /* 0 hops */ 25195972f6Sopenharmony_ci 0xAA, 0xAA, 0xAA, 0xAA, /* Transaction id, will be overwritten */ 26195972f6Sopenharmony_ci 0x00, 0x00, /* 0 seconds elapsed */ 27195972f6Sopenharmony_ci 0x00, 0x00, /* Flags (unicast) */ 28195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, /* Client ip */ 29195972f6Sopenharmony_ci 0xc3, 0xaa, 0xbd, 0xc8, /* Your IP */ 30195972f6Sopenharmony_ci 0xc3, 0xaa, 0xbd, 0xab, /* DHCP server ip */ 31195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, /* relay agent */ 32195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC addr + padding */ 33195972f6Sopenharmony_ci 34195972f6Sopenharmony_ci /* Empty server name and boot file name */ 35195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 37195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 47195972f6Sopenharmony_ci 48195972f6Sopenharmony_ci 0x63, 0x82, 0x53, 0x63, /* Magic cookie */ 49195972f6Sopenharmony_ci 0x35, 0x01, 0x02, /* Message type: Offer */ 50195972f6Sopenharmony_ci 0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Server identifier (IP) */ 51195972f6Sopenharmony_ci 0x33, 0x04, 0x00, 0x00, 0x00, 0x78, /* Lease time 2 minutes */ 52195972f6Sopenharmony_ci 0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Router IP */ 53195972f6Sopenharmony_ci 0x01, 0x04, 0xff, 0xff, 0xff, 0x00, /* Subnet mask */ 54195972f6Sopenharmony_ci 0xff, /* End option */ 55195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Padding */ 57195972f6Sopenharmony_ci}; 58195972f6Sopenharmony_ci 59195972f6Sopenharmony_cistatic u8_t dhcp_ack[] = { 60195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, /* To unit */ 61195972f6Sopenharmony_ci 0x00, 0x0f, 0xEE, 0x30, 0xAB, 0x22, /* From remote host */ 62195972f6Sopenharmony_ci 0x08, 0x00, /* Proto IP */ 63195972f6Sopenharmony_ci 0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8, /* IP header */ 64195972f6Sopenharmony_ci 0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00, /* UDP header */ 65195972f6Sopenharmony_ci 0x02, /* Bootp reply */ 66195972f6Sopenharmony_ci 0x01, 0x06, /* Hw type Eth, len 6 */ 67195972f6Sopenharmony_ci 0x00, /* 0 hops */ 68195972f6Sopenharmony_ci 0xAA, 0xAA, 0xAA, 0xAA, 69195972f6Sopenharmony_ci 0x00, 0x00, /* 0 seconds elapsed */ 70195972f6Sopenharmony_ci 0x00, 0x00, /* Flags (unicast) */ 71195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, /* Client IP */ 72195972f6Sopenharmony_ci 0xc3, 0xaa, 0xbd, 0xc8, /* Your IP */ 73195972f6Sopenharmony_ci 0xc3, 0xaa, 0xbd, 0xab, /* DHCP server IP */ 74195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, /* Relay agent */ 75195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Macaddr + padding */ 76195972f6Sopenharmony_ci 77195972f6Sopenharmony_ci /* Empty server name and boot file name */ 78195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 79195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 80195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 82195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 83195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 84195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 86195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 87195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 88195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 89195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 90195972f6Sopenharmony_ci 91195972f6Sopenharmony_ci 0x63, 0x82, 0x53, 0x63, /* Magic cookie */ 92195972f6Sopenharmony_ci 0x35, 0x01, 0x05, /* Dhcp message type ack */ 93195972f6Sopenharmony_ci 0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* DHCP server identifier */ 94195972f6Sopenharmony_ci 0x33, 0x04, 0x00, 0x00, 0x00, 0x78, /* Lease time 2 minutes */ 95195972f6Sopenharmony_ci 0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Router IP */ 96195972f6Sopenharmony_ci 0x01, 0x04, 0xff, 0xff, 0xff, 0x00, /* Netmask */ 97195972f6Sopenharmony_ci 0xff, /* End marker */ 98195972f6Sopenharmony_ci 99195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 100195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Padding */ 101195972f6Sopenharmony_ci}; 102195972f6Sopenharmony_ci 103195972f6Sopenharmony_cistatic const u8_t arpreply[] = { 104195972f6Sopenharmony_ci 0x00, 0x23, 0xC1, 0xDE, 0xD0, 0x0D, /* dst mac */ 105195972f6Sopenharmony_ci 0x00, 0x32, 0x44, 0x20, 0x01, 0x02, /* src mac */ 106195972f6Sopenharmony_ci 0x08, 0x06, /* proto arp */ 107195972f6Sopenharmony_ci 0x00, 0x01, /* hw eth */ 108195972f6Sopenharmony_ci 0x08, 0x00, /* proto ip */ 109195972f6Sopenharmony_ci 0x06, /* hw addr len 6 */ 110195972f6Sopenharmony_ci 0x04, /* proto addr len 4 */ 111195972f6Sopenharmony_ci 0x00, 0x02, /* arp reply */ 112195972f6Sopenharmony_ci 0x00, 0x32, 0x44, 0x20, 0x01, 0x02, /* sender mac */ 113195972f6Sopenharmony_ci 0xc3, 0xaa, 0xbd, 0xc8, /* sender ip */ 114195972f6Sopenharmony_ci 0x00, 0x23, 0xC1, 0xDE, 0xD0, 0x0D, /* target mac */ 115195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, /* target ip */ 116195972f6Sopenharmony_ci}; 117195972f6Sopenharmony_ci 118195972f6Sopenharmony_cistatic int txpacket; 119195972f6Sopenharmony_cistatic enum tcase { 120195972f6Sopenharmony_ci TEST_LWIP_DHCP, 121195972f6Sopenharmony_ci TEST_LWIP_DHCP_NAK, 122195972f6Sopenharmony_ci TEST_LWIP_DHCP_RELAY, 123195972f6Sopenharmony_ci TEST_LWIP_DHCP_NAK_NO_ENDMARKER, 124195972f6Sopenharmony_ci TEST_LWIP_DHCP_INVALID_OVERLOAD, 125195972f6Sopenharmony_ci TEST_NONE 126195972f6Sopenharmony_ci} tcase; 127195972f6Sopenharmony_ci 128195972f6Sopenharmony_cistatic int debug = 0; 129195972f6Sopenharmony_cistatic void setdebug(int a) {debug = a;} 130195972f6Sopenharmony_ci 131195972f6Sopenharmony_cistatic int tick = 0; 132195972f6Sopenharmony_cistatic void tick_lwip(void) 133195972f6Sopenharmony_ci{ 134195972f6Sopenharmony_ci tick++; 135195972f6Sopenharmony_ci if (tick % 5 == 0) { 136195972f6Sopenharmony_ci dhcp_fine_tmr(); 137195972f6Sopenharmony_ci } 138195972f6Sopenharmony_ci if (tick % 600 == 0) { 139195972f6Sopenharmony_ci dhcp_coarse_tmr(); 140195972f6Sopenharmony_ci } 141195972f6Sopenharmony_ci} 142195972f6Sopenharmony_ci 143195972f6Sopenharmony_cistatic void send_pkt(struct netif *netif, const u8_t *data, size_t len) 144195972f6Sopenharmony_ci{ 145195972f6Sopenharmony_ci struct pbuf *p, *q; 146195972f6Sopenharmony_ci LWIP_ASSERT("pkt too big", len <= 0xFFFF); 147195972f6Sopenharmony_ci p = pbuf_alloc(PBUF_RAW, (u16_t)len, PBUF_POOL); 148195972f6Sopenharmony_ci 149195972f6Sopenharmony_ci if (debug) { 150195972f6Sopenharmony_ci /* Dump data */ 151195972f6Sopenharmony_ci u32_t i; 152195972f6Sopenharmony_ci printf("RX data (len %d)", p->tot_len); 153195972f6Sopenharmony_ci for (i = 0; i < len; i++) { 154195972f6Sopenharmony_ci printf(" %02X", data[i]); 155195972f6Sopenharmony_ci } 156195972f6Sopenharmony_ci printf("\n"); 157195972f6Sopenharmony_ci } 158195972f6Sopenharmony_ci 159195972f6Sopenharmony_ci fail_unless(p != NULL); 160195972f6Sopenharmony_ci for(q = p; q != NULL; q = q->next) { 161195972f6Sopenharmony_ci memcpy(q->payload, data, q->len); 162195972f6Sopenharmony_ci data += q->len; 163195972f6Sopenharmony_ci } 164195972f6Sopenharmony_ci netif->input(p, netif); 165195972f6Sopenharmony_ci} 166195972f6Sopenharmony_ci 167195972f6Sopenharmony_cistatic err_t lwip_tx_func(struct netif *netif, struct pbuf *p); 168195972f6Sopenharmony_ci 169195972f6Sopenharmony_cistatic err_t testif_init(struct netif *netif) 170195972f6Sopenharmony_ci{ 171195972f6Sopenharmony_ci netif->name[0] = 'c'; 172195972f6Sopenharmony_ci netif->name[1] = 'h'; 173195972f6Sopenharmony_ci netif->output = etharp_output; 174195972f6Sopenharmony_ci netif->linkoutput = lwip_tx_func; 175195972f6Sopenharmony_ci netif->mtu = 1500; 176195972f6Sopenharmony_ci netif->hwaddr_len = 6; 177195972f6Sopenharmony_ci netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; 178195972f6Sopenharmony_ci 179195972f6Sopenharmony_ci netif->hwaddr[0] = 0x00; 180195972f6Sopenharmony_ci netif->hwaddr[1] = 0x23; 181195972f6Sopenharmony_ci netif->hwaddr[2] = 0xC1; 182195972f6Sopenharmony_ci netif->hwaddr[3] = 0xDE; 183195972f6Sopenharmony_ci netif->hwaddr[4] = 0xD0; 184195972f6Sopenharmony_ci netif->hwaddr[5] = 0x0D; 185195972f6Sopenharmony_ci 186195972f6Sopenharmony_ci return ERR_OK; 187195972f6Sopenharmony_ci} 188195972f6Sopenharmony_ci 189195972f6Sopenharmony_cistatic void dhcp_setup(void) 190195972f6Sopenharmony_ci{ 191195972f6Sopenharmony_ci txpacket = 0; 192195972f6Sopenharmony_ci lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT)); 193195972f6Sopenharmony_ci} 194195972f6Sopenharmony_ci 195195972f6Sopenharmony_cistatic void dhcp_teardown(void) 196195972f6Sopenharmony_ci{ 197195972f6Sopenharmony_ci lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT)); 198195972f6Sopenharmony_ci} 199195972f6Sopenharmony_ci 200195972f6Sopenharmony_cistatic void check_pkt(struct pbuf *p, u32_t pos, const u8_t *mem, u32_t len) 201195972f6Sopenharmony_ci{ 202195972f6Sopenharmony_ci u8_t *data; 203195972f6Sopenharmony_ci 204195972f6Sopenharmony_ci fail_if((pos + len) > p->tot_len); 205195972f6Sopenharmony_ci while (pos > p->len && p->next) { 206195972f6Sopenharmony_ci pos -= p->len; 207195972f6Sopenharmony_ci p = p->next; 208195972f6Sopenharmony_ci } 209195972f6Sopenharmony_ci fail_if(p == NULL); 210195972f6Sopenharmony_ci fail_unless(pos + len <= p->len); /* All data we seek within same pbuf */ 211195972f6Sopenharmony_ci 212195972f6Sopenharmony_ci data = (u8_t*)p->payload; 213195972f6Sopenharmony_ci fail_if(memcmp(&data[pos], mem, len), "data at pos %d, len %d in packet %d did not match", pos, len, txpacket); 214195972f6Sopenharmony_ci} 215195972f6Sopenharmony_ci 216195972f6Sopenharmony_cistatic void check_pkt_fuzzy(struct pbuf *p, u32_t startpos, const u8_t *mem, u32_t len) 217195972f6Sopenharmony_ci{ 218195972f6Sopenharmony_ci int found; 219195972f6Sopenharmony_ci u32_t i; 220195972f6Sopenharmony_ci u8_t *data; 221195972f6Sopenharmony_ci 222195972f6Sopenharmony_ci fail_if((startpos + len) > p->tot_len); 223195972f6Sopenharmony_ci while (startpos > p->len && p->next) { 224195972f6Sopenharmony_ci startpos -= p->len; 225195972f6Sopenharmony_ci p = p->next; 226195972f6Sopenharmony_ci } 227195972f6Sopenharmony_ci fail_if(p == NULL); 228195972f6Sopenharmony_ci fail_unless(startpos + len <= p->len); /* All data we seek within same pbuf */ 229195972f6Sopenharmony_ci 230195972f6Sopenharmony_ci found = 0; 231195972f6Sopenharmony_ci data = (u8_t*)p->payload; 232195972f6Sopenharmony_ci for (i = startpos; i <= (p->len - len); i++) { 233195972f6Sopenharmony_ci if (memcmp(&data[i], mem, len) == 0) { 234195972f6Sopenharmony_ci found = 1; 235195972f6Sopenharmony_ci break; 236195972f6Sopenharmony_ci } 237195972f6Sopenharmony_ci } 238195972f6Sopenharmony_ci fail_unless(found); 239195972f6Sopenharmony_ci} 240195972f6Sopenharmony_ci 241195972f6Sopenharmony_cistatic err_t lwip_tx_func(struct netif *netif, struct pbuf *p) 242195972f6Sopenharmony_ci{ 243195972f6Sopenharmony_ci fail_unless(netif == &net_test); 244195972f6Sopenharmony_ci txpacket++; 245195972f6Sopenharmony_ci 246195972f6Sopenharmony_ci if (debug) { 247195972f6Sopenharmony_ci struct pbuf *pp = p; 248195972f6Sopenharmony_ci /* Dump data */ 249195972f6Sopenharmony_ci printf("TX data (pkt %d, len %d, tick %d)", txpacket, p->tot_len, tick); 250195972f6Sopenharmony_ci do { 251195972f6Sopenharmony_ci int i; 252195972f6Sopenharmony_ci for (i = 0; i < pp->len; i++) { 253195972f6Sopenharmony_ci printf(" %02X", ((u8_t *) pp->payload)[i]); 254195972f6Sopenharmony_ci } 255195972f6Sopenharmony_ci if (pp->next) { 256195972f6Sopenharmony_ci pp = pp->next; 257195972f6Sopenharmony_ci } 258195972f6Sopenharmony_ci } while (pp->next); 259195972f6Sopenharmony_ci printf("\n"); 260195972f6Sopenharmony_ci } 261195972f6Sopenharmony_ci 262195972f6Sopenharmony_ci switch (tcase) { 263195972f6Sopenharmony_ci case TEST_LWIP_DHCP: 264195972f6Sopenharmony_ci switch (txpacket) { 265195972f6Sopenharmony_ci case 1: 266195972f6Sopenharmony_ci case 2: 267195972f6Sopenharmony_ci { 268195972f6Sopenharmony_ci const u8_t ipproto[] = { 0x08, 0x00 }; 269195972f6Sopenharmony_ci const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; /* bootp request, eth, hwaddr len 6, 0 hops */ 270195972f6Sopenharmony_ci const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 271195972f6Sopenharmony_ci 272195972f6Sopenharmony_ci check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */ 273195972f6Sopenharmony_ci check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */ 274195972f6Sopenharmony_ci 275195972f6Sopenharmony_ci check_pkt(p, 12, ipproto, sizeof(ipproto)); /* eth level proto: ip */ 276195972f6Sopenharmony_ci 277195972f6Sopenharmony_ci check_pkt(p, 42, bootp_start, sizeof(bootp_start)); 278195972f6Sopenharmony_ci 279195972f6Sopenharmony_ci check_pkt(p, 53, ipaddrs, sizeof(ipaddrs)); 280195972f6Sopenharmony_ci 281195972f6Sopenharmony_ci check_pkt(p, 70, netif->hwaddr, 6); /* mac addr inside bootp */ 282195972f6Sopenharmony_ci 283195972f6Sopenharmony_ci check_pkt(p, 278, magic_cookie, sizeof(magic_cookie)); 284195972f6Sopenharmony_ci 285195972f6Sopenharmony_ci /* Check dchp message type, can be at different positions */ 286195972f6Sopenharmony_ci if (txpacket == 1) { 287195972f6Sopenharmony_ci u8_t dhcp_discover_opt[] = { 0x35, 0x01, 0x01 }; 288195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, dhcp_discover_opt, sizeof(dhcp_discover_opt)); 289195972f6Sopenharmony_ci } else if (txpacket == 2) { 290195972f6Sopenharmony_ci u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 }; 291195972f6Sopenharmony_ci u8_t requested_ipaddr[] = { 0x32, 0x04, 0xc3, 0xaa, 0xbd, 0xc8 }; /* Ask for offered IP */ 292195972f6Sopenharmony_ci 293195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, dhcp_request_opt, sizeof(dhcp_request_opt)); 294195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, requested_ipaddr, sizeof(requested_ipaddr)); 295195972f6Sopenharmony_ci } 296195972f6Sopenharmony_ci break; 297195972f6Sopenharmony_ci } 298195972f6Sopenharmony_ci case 3: 299195972f6Sopenharmony_ci case 4: 300195972f6Sopenharmony_ci case 5: 301195972f6Sopenharmony_ci { 302195972f6Sopenharmony_ci const u8_t arpproto[] = { 0x08, 0x06 }; 303195972f6Sopenharmony_ci 304195972f6Sopenharmony_ci check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */ 305195972f6Sopenharmony_ci check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */ 306195972f6Sopenharmony_ci 307195972f6Sopenharmony_ci check_pkt(p, 12, arpproto, sizeof(arpproto)); /* eth level proto: ip */ 308195972f6Sopenharmony_ci break; 309195972f6Sopenharmony_ci } 310195972f6Sopenharmony_ci default: 311195972f6Sopenharmony_ci fail(); 312195972f6Sopenharmony_ci break; 313195972f6Sopenharmony_ci } 314195972f6Sopenharmony_ci break; 315195972f6Sopenharmony_ci 316195972f6Sopenharmony_ci case TEST_LWIP_DHCP_NAK: 317195972f6Sopenharmony_ci { 318195972f6Sopenharmony_ci const u8_t ipproto[] = { 0x08, 0x00 }; 319195972f6Sopenharmony_ci const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; /* bootp request, eth, hwaddr len 6, 0 hops */ 320195972f6Sopenharmony_ci const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 321195972f6Sopenharmony_ci const u8_t dhcp_nak_opt[] = { 0x35, 0x01, 0x04 }; 322195972f6Sopenharmony_ci const u8_t requested_ipaddr[] = { 0x32, 0x04, 0xc3, 0xaa, 0xbd, 0xc8 }; /* offered IP */ 323195972f6Sopenharmony_ci 324195972f6Sopenharmony_ci fail_unless(txpacket == 4); 325195972f6Sopenharmony_ci check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */ 326195972f6Sopenharmony_ci check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */ 327195972f6Sopenharmony_ci 328195972f6Sopenharmony_ci check_pkt(p, 12, ipproto, sizeof(ipproto)); /* eth level proto: ip */ 329195972f6Sopenharmony_ci 330195972f6Sopenharmony_ci check_pkt(p, 42, bootp_start, sizeof(bootp_start)); 331195972f6Sopenharmony_ci 332195972f6Sopenharmony_ci check_pkt(p, 53, ipaddrs, sizeof(ipaddrs)); 333195972f6Sopenharmony_ci 334195972f6Sopenharmony_ci check_pkt(p, 70, netif->hwaddr, 6); /* mac addr inside bootp */ 335195972f6Sopenharmony_ci 336195972f6Sopenharmony_ci check_pkt(p, 278, magic_cookie, sizeof(magic_cookie)); 337195972f6Sopenharmony_ci 338195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, dhcp_nak_opt, sizeof(dhcp_nak_opt)); /* NAK the ack */ 339195972f6Sopenharmony_ci 340195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, requested_ipaddr, sizeof(requested_ipaddr)); 341195972f6Sopenharmony_ci break; 342195972f6Sopenharmony_ci } 343195972f6Sopenharmony_ci 344195972f6Sopenharmony_ci case TEST_LWIP_DHCP_RELAY: 345195972f6Sopenharmony_ci switch (txpacket) { 346195972f6Sopenharmony_ci case 1: 347195972f6Sopenharmony_ci case 2: 348195972f6Sopenharmony_ci { 349195972f6Sopenharmony_ci const u8_t ipproto[] = { 0x08, 0x00 }; 350195972f6Sopenharmony_ci const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; /* bootp request, eth, hwaddr len 6, 0 hops */ 351195972f6Sopenharmony_ci const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 352195972f6Sopenharmony_ci 353195972f6Sopenharmony_ci check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */ 354195972f6Sopenharmony_ci check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */ 355195972f6Sopenharmony_ci 356195972f6Sopenharmony_ci check_pkt(p, 12, ipproto, sizeof(ipproto)); /* eth level proto: ip */ 357195972f6Sopenharmony_ci 358195972f6Sopenharmony_ci check_pkt(p, 42, bootp_start, sizeof(bootp_start)); 359195972f6Sopenharmony_ci 360195972f6Sopenharmony_ci check_pkt(p, 53, ipaddrs, sizeof(ipaddrs)); 361195972f6Sopenharmony_ci 362195972f6Sopenharmony_ci check_pkt(p, 70, netif->hwaddr, 6); /* mac addr inside bootp */ 363195972f6Sopenharmony_ci 364195972f6Sopenharmony_ci check_pkt(p, 278, magic_cookie, sizeof(magic_cookie)); 365195972f6Sopenharmony_ci 366195972f6Sopenharmony_ci /* Check dchp message type, can be at different positions */ 367195972f6Sopenharmony_ci if (txpacket == 1) { 368195972f6Sopenharmony_ci u8_t dhcp_discover_opt[] = { 0x35, 0x01, 0x01 }; 369195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, dhcp_discover_opt, sizeof(dhcp_discover_opt)); 370195972f6Sopenharmony_ci } else if (txpacket == 2) { 371195972f6Sopenharmony_ci u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 }; 372195972f6Sopenharmony_ci u8_t requested_ipaddr[] = { 0x32, 0x04, 0x4f, 0x8a, 0x33, 0x05 }; /* Ask for offered IP */ 373195972f6Sopenharmony_ci 374195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, dhcp_request_opt, sizeof(dhcp_request_opt)); 375195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, requested_ipaddr, sizeof(requested_ipaddr)); 376195972f6Sopenharmony_ci } 377195972f6Sopenharmony_ci break; 378195972f6Sopenharmony_ci } 379195972f6Sopenharmony_ci case 3: 380195972f6Sopenharmony_ci case 4: 381195972f6Sopenharmony_ci case 5: 382195972f6Sopenharmony_ci case 6: 383195972f6Sopenharmony_ci { 384195972f6Sopenharmony_ci const u8_t arpproto[] = { 0x08, 0x06 }; 385195972f6Sopenharmony_ci 386195972f6Sopenharmony_ci check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */ 387195972f6Sopenharmony_ci check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */ 388195972f6Sopenharmony_ci 389195972f6Sopenharmony_ci check_pkt(p, 12, arpproto, sizeof(arpproto)); /* eth level proto: ip */ 390195972f6Sopenharmony_ci break; 391195972f6Sopenharmony_ci } 392195972f6Sopenharmony_ci case 7: 393195972f6Sopenharmony_ci { 394195972f6Sopenharmony_ci const u8_t fake_arp[6] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xab }; 395195972f6Sopenharmony_ci const u8_t ipproto[] = { 0x08, 0x00 }; 396195972f6Sopenharmony_ci const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; /* bootp request, eth, hwaddr len 6, 0 hops */ 397195972f6Sopenharmony_ci const u8_t ipaddrs[] = { 0x00, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 398195972f6Sopenharmony_ci const u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 }; 399195972f6Sopenharmony_ci 400195972f6Sopenharmony_ci check_pkt(p, 0, fake_arp, 6); /* eth level dest: broadcast */ 401195972f6Sopenharmony_ci check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */ 402195972f6Sopenharmony_ci 403195972f6Sopenharmony_ci check_pkt(p, 12, ipproto, sizeof(ipproto)); /* eth level proto: ip */ 404195972f6Sopenharmony_ci 405195972f6Sopenharmony_ci check_pkt(p, 42, bootp_start, sizeof(bootp_start)); 406195972f6Sopenharmony_ci 407195972f6Sopenharmony_ci check_pkt(p, 53, ipaddrs, sizeof(ipaddrs)); 408195972f6Sopenharmony_ci 409195972f6Sopenharmony_ci check_pkt(p, 70, netif->hwaddr, 6); /* mac addr inside bootp */ 410195972f6Sopenharmony_ci 411195972f6Sopenharmony_ci check_pkt(p, 278, magic_cookie, sizeof(magic_cookie)); 412195972f6Sopenharmony_ci 413195972f6Sopenharmony_ci /* Check dchp message type, can be at different positions */ 414195972f6Sopenharmony_ci check_pkt_fuzzy(p, 282, dhcp_request_opt, sizeof(dhcp_request_opt)); 415195972f6Sopenharmony_ci break; 416195972f6Sopenharmony_ci } 417195972f6Sopenharmony_ci default: 418195972f6Sopenharmony_ci fail(); 419195972f6Sopenharmony_ci break; 420195972f6Sopenharmony_ci } 421195972f6Sopenharmony_ci break; 422195972f6Sopenharmony_ci 423195972f6Sopenharmony_ci default: 424195972f6Sopenharmony_ci break; 425195972f6Sopenharmony_ci } 426195972f6Sopenharmony_ci 427195972f6Sopenharmony_ci return ERR_OK; 428195972f6Sopenharmony_ci} 429195972f6Sopenharmony_ci 430195972f6Sopenharmony_ci/* 431195972f6Sopenharmony_ci * Test basic happy flow DHCP session. 432195972f6Sopenharmony_ci * Validate that xid is checked. 433195972f6Sopenharmony_ci */ 434195972f6Sopenharmony_ciSTART_TEST(test_dhcp) 435195972f6Sopenharmony_ci{ 436195972f6Sopenharmony_ci ip4_addr_t addr; 437195972f6Sopenharmony_ci ip4_addr_t netmask; 438195972f6Sopenharmony_ci ip4_addr_t gw; 439195972f6Sopenharmony_ci int i; 440195972f6Sopenharmony_ci u32_t xid; 441195972f6Sopenharmony_ci LWIP_UNUSED_ARG(_i); 442195972f6Sopenharmony_ci 443195972f6Sopenharmony_ci tcase = TEST_LWIP_DHCP; 444195972f6Sopenharmony_ci setdebug(0); 445195972f6Sopenharmony_ci 446195972f6Sopenharmony_ci IP4_ADDR(&addr, 0, 0, 0, 0); 447195972f6Sopenharmony_ci IP4_ADDR(&netmask, 0, 0, 0, 0); 448195972f6Sopenharmony_ci IP4_ADDR(&gw, 0, 0, 0, 0); 449195972f6Sopenharmony_ci 450195972f6Sopenharmony_ci netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); 451195972f6Sopenharmony_ci netif_set_link_up(&net_test); 452195972f6Sopenharmony_ci netif_set_up(&net_test); 453195972f6Sopenharmony_ci 454195972f6Sopenharmony_ci dhcp_start(&net_test); 455195972f6Sopenharmony_ci 456195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* DHCP discover sent */ 457195972f6Sopenharmony_ci xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ 458195972f6Sopenharmony_ci memcpy(&dhcp_offer[46], &xid, 4); 459195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); 460195972f6Sopenharmony_ci 461195972f6Sopenharmony_ci /* IP addresses should be zero */ 462195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 463195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 464195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 465195972f6Sopenharmony_ci 466195972f6Sopenharmony_ci fail_unless(txpacket == 1, "TX %d packets, expected 1", txpacket); /* Nothing more sent */ 467195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); 468195972f6Sopenharmony_ci memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ 469195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); 470195972f6Sopenharmony_ci 471195972f6Sopenharmony_ci fail_unless(txpacket == 2, "TX %d packets, expected 2", txpacket); /* DHCP request sent */ 472195972f6Sopenharmony_ci xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ 473195972f6Sopenharmony_ci memcpy(&dhcp_ack[46], &xid, 4); 474195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); 475195972f6Sopenharmony_ci 476195972f6Sopenharmony_ci fail_unless(txpacket == 2, "TX %d packets, still expected 2", txpacket); /* No more sent */ 477195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ 478195972f6Sopenharmony_ci memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */ 479195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); 480195972f6Sopenharmony_ci 481195972f6Sopenharmony_ci for (i = 0; i < 20; i++) { 482195972f6Sopenharmony_ci tick_lwip(); 483195972f6Sopenharmony_ci } 484195972f6Sopenharmony_ci fail_unless(txpacket == 5, "TX %d packets, expected 5", txpacket); /* ARP requests sent */ 485195972f6Sopenharmony_ci 486195972f6Sopenharmony_ci /* Interface up */ 487195972f6Sopenharmony_ci fail_unless(netif_is_up(&net_test)); 488195972f6Sopenharmony_ci 489195972f6Sopenharmony_ci /* Now it should have taken the IP */ 490195972f6Sopenharmony_ci IP4_ADDR(&addr, 195, 170, 189, 200); 491195972f6Sopenharmony_ci IP4_ADDR(&netmask, 255, 255, 255, 0); 492195972f6Sopenharmony_ci IP4_ADDR(&gw, 195, 170, 189, 171); 493195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 494195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 495195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 496195972f6Sopenharmony_ci 497195972f6Sopenharmony_ci tcase = TEST_NONE; 498195972f6Sopenharmony_ci dhcp_stop(&net_test); 499195972f6Sopenharmony_ci dhcp_cleanup(&net_test); 500195972f6Sopenharmony_ci netif_remove(&net_test); 501195972f6Sopenharmony_ci} 502195972f6Sopenharmony_ciEND_TEST 503195972f6Sopenharmony_ci 504195972f6Sopenharmony_ci/* 505195972f6Sopenharmony_ci * Test that IP address is not taken and NAK is sent if someone 506195972f6Sopenharmony_ci * replies to ARP requests for the offered address. 507195972f6Sopenharmony_ci */ 508195972f6Sopenharmony_ciSTART_TEST(test_dhcp_nak) 509195972f6Sopenharmony_ci{ 510195972f6Sopenharmony_ci ip4_addr_t addr; 511195972f6Sopenharmony_ci ip4_addr_t netmask; 512195972f6Sopenharmony_ci ip4_addr_t gw; 513195972f6Sopenharmony_ci u32_t xid; 514195972f6Sopenharmony_ci LWIP_UNUSED_ARG(_i); 515195972f6Sopenharmony_ci 516195972f6Sopenharmony_ci tcase = TEST_LWIP_DHCP; 517195972f6Sopenharmony_ci setdebug(0); 518195972f6Sopenharmony_ci 519195972f6Sopenharmony_ci IP4_ADDR(&addr, 0, 0, 0, 0); 520195972f6Sopenharmony_ci IP4_ADDR(&netmask, 0, 0, 0, 0); 521195972f6Sopenharmony_ci IP4_ADDR(&gw, 0, 0, 0, 0); 522195972f6Sopenharmony_ci 523195972f6Sopenharmony_ci netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); 524195972f6Sopenharmony_ci netif_set_link_up(&net_test); 525195972f6Sopenharmony_ci netif_set_up(&net_test); 526195972f6Sopenharmony_ci 527195972f6Sopenharmony_ci dhcp_start(&net_test); 528195972f6Sopenharmony_ci 529195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* DHCP discover sent */ 530195972f6Sopenharmony_ci xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ 531195972f6Sopenharmony_ci memcpy(&dhcp_offer[46], &xid, 4); 532195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); 533195972f6Sopenharmony_ci 534195972f6Sopenharmony_ci /* IP addresses should be zero */ 535195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 536195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 537195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 538195972f6Sopenharmony_ci 539195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* Nothing more sent */ 540195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); 541195972f6Sopenharmony_ci memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ 542195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); 543195972f6Sopenharmony_ci 544195972f6Sopenharmony_ci fail_unless(txpacket == 2); /* DHCP request sent */ 545195972f6Sopenharmony_ci xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ 546195972f6Sopenharmony_ci memcpy(&dhcp_ack[46], &xid, 4); 547195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); 548195972f6Sopenharmony_ci 549195972f6Sopenharmony_ci fail_unless(txpacket == 2); /* No more sent */ 550195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ 551195972f6Sopenharmony_ci memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */ 552195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); 553195972f6Sopenharmony_ci 554195972f6Sopenharmony_ci fail_unless(txpacket == 3); /* ARP request sent */ 555195972f6Sopenharmony_ci 556195972f6Sopenharmony_ci tcase = TEST_LWIP_DHCP_NAK; /* Switch testcase */ 557195972f6Sopenharmony_ci 558195972f6Sopenharmony_ci /* Send arp reply, mark offered IP as taken */ 559195972f6Sopenharmony_ci send_pkt(&net_test, arpreply, sizeof(arpreply)); 560195972f6Sopenharmony_ci 561195972f6Sopenharmony_ci fail_unless(txpacket == 4); /* DHCP nak sent */ 562195972f6Sopenharmony_ci 563195972f6Sopenharmony_ci tcase = TEST_NONE; 564195972f6Sopenharmony_ci dhcp_stop(&net_test); 565195972f6Sopenharmony_ci dhcp_cleanup(&net_test); 566195972f6Sopenharmony_ci netif_remove(&net_test); 567195972f6Sopenharmony_ci} 568195972f6Sopenharmony_ciEND_TEST 569195972f6Sopenharmony_ci 570195972f6Sopenharmony_ci/* 571195972f6Sopenharmony_ci * Test case based on captured data where 572195972f6Sopenharmony_ci * replies are sent from a different IP than the 573195972f6Sopenharmony_ci * one the client unicasted to. 574195972f6Sopenharmony_ci */ 575195972f6Sopenharmony_ciSTART_TEST(test_dhcp_relayed) 576195972f6Sopenharmony_ci{ 577195972f6Sopenharmony_ci u8_t relay_offer[] = { 578195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 579195972f6Sopenharmony_ci 0x00, 0x22, 0x93, 0x5a, 0xf7, 0x60, 580195972f6Sopenharmony_ci 0x08, 0x00, 0x45, 0x00, 581195972f6Sopenharmony_ci 0x01, 0x38, 0xfd, 0x53, 0x00, 0x00, 0x40, 0x11, 582195972f6Sopenharmony_ci 0x78, 0x46, 0x4f, 0x8a, 0x32, 0x02, 0x4f, 0x8a, 583195972f6Sopenharmony_ci 0x33, 0x05, 0x00, 0x43, 0x00, 0x44, 0x01, 0x24, 584195972f6Sopenharmony_ci 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x51, 0x35, 585195972f6Sopenharmony_ci 0xb6, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 586195972f6Sopenharmony_ci 0x00, 0x00, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00, 587195972f6Sopenharmony_ci 0x00, 0x00, 0x0a, 0xb5, 0x04, 0x01, 0x00, 0x23, 588195972f6Sopenharmony_ci 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 589195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 590195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 591195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 592195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 593195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 594195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 595195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 596195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 597195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 598195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 599195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 600195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 601195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 602195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 603195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 604195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 605195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 606195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 607195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 608195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 609195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 610195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 611195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 612195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 613195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 614195972f6Sopenharmony_ci 0x53, 0x63, 0x01, 0x04, 0xff, 0xff, 0xfe, 0x00, 615195972f6Sopenharmony_ci 0x03, 0x04, 0x4f, 0x8a, 0x32, 0x01, 0x06, 0x08, 616195972f6Sopenharmony_ci 0x4f, 0x8a, 0x00, 0xb4, 0x55, 0x08, 0x1f, 0xd1, 617195972f6Sopenharmony_ci 0x1c, 0x04, 0x4f, 0x8a, 0x33, 0xff, 0x33, 0x04, 618195972f6Sopenharmony_ci 0x00, 0x00, 0x54, 0x49, 0x35, 0x01, 0x02, 0x36, 619195972f6Sopenharmony_ci 0x04, 0x0a, 0xb5, 0x04, 0x01, 0xff 620195972f6Sopenharmony_ci }; 621195972f6Sopenharmony_ci 622195972f6Sopenharmony_ci u8_t relay_ack1[] = { 623195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x22, 624195972f6Sopenharmony_ci 0x93, 0x5a, 0xf7, 0x60, 0x08, 0x00, 0x45, 0x00, 625195972f6Sopenharmony_ci 0x01, 0x38, 0xfd, 0x55, 0x00, 0x00, 0x40, 0x11, 626195972f6Sopenharmony_ci 0x78, 0x44, 0x4f, 0x8a, 0x32, 0x02, 0x4f, 0x8a, 627195972f6Sopenharmony_ci 0x33, 0x05, 0x00, 0x43, 0x00, 0x44, 0x01, 0x24, 628195972f6Sopenharmony_ci 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x51, 0x35, 629195972f6Sopenharmony_ci 0xb6, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 630195972f6Sopenharmony_ci 0x00, 0x00, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00, 631195972f6Sopenharmony_ci 0x00, 0x00, 0x0a, 0xb5, 0x04, 0x01, 0x00, 0x23, 632195972f6Sopenharmony_ci 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 633195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 634195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 635195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 636195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 637195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 638195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 639195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 640195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 641195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 642195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 643195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 644195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 645195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 646195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 647195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 648195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 649195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 650195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 651195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 652195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 653195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 654195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 655195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 656195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 657195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 658195972f6Sopenharmony_ci 0x53, 0x63, 0x01, 0x04, 0xff, 0xff, 0xfe, 0x00, 659195972f6Sopenharmony_ci 0x03, 0x04, 0x4f, 0x8a, 0x32, 0x01, 0x06, 0x08, 660195972f6Sopenharmony_ci 0x4f, 0x8a, 0x00, 0xb4, 0x55, 0x08, 0x1f, 0xd1, 661195972f6Sopenharmony_ci 0x1c, 0x04, 0x4f, 0x8a, 0x33, 0xff, 0x33, 0x04, 662195972f6Sopenharmony_ci 0x00, 0x00, 0x54, 0x49, 0x35, 0x01, 0x05, 0x36, 663195972f6Sopenharmony_ci 0x04, 0x0a, 0xb5, 0x04, 0x01, 0xff 664195972f6Sopenharmony_ci }; 665195972f6Sopenharmony_ci 666195972f6Sopenharmony_ci u8_t relay_ack2[] = { 667195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 668195972f6Sopenharmony_ci 0x00, 0x22, 0x93, 0x5a, 0xf7, 0x60, 669195972f6Sopenharmony_ci 0x08, 0x00, 0x45, 0x00, 670195972f6Sopenharmony_ci 0x01, 0x38, 0xfa, 0x18, 0x00, 0x00, 0x40, 0x11, 671195972f6Sopenharmony_ci 0x7b, 0x81, 0x4f, 0x8a, 0x32, 0x02, 0x4f, 0x8a, 672195972f6Sopenharmony_ci 0x33, 0x05, 0x00, 0x43, 0x00, 0x44, 0x01, 0x24, 673195972f6Sopenharmony_ci 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x49, 0x8b, 674195972f6Sopenharmony_ci 0x6e, 0xab, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x8a, 675195972f6Sopenharmony_ci 0x33, 0x05, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00, 676195972f6Sopenharmony_ci 0x00, 0x00, 0x0a, 0xb5, 0x04, 0x01, 0x00, 0x23, 677195972f6Sopenharmony_ci 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 678195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 679195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 680195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 681195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 682195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 683195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 684195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 685195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 686195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 687195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 688195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 689195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 690195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 691195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 692195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 693195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 694195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 695195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 696195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 697195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 698195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 699195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 700195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 701195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 702195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 703195972f6Sopenharmony_ci 0x53, 0x63, 0x01, 0x04, 0xff, 0xff, 0xfe, 0x00, 704195972f6Sopenharmony_ci 0x03, 0x04, 0x4f, 0x8a, 0x32, 0x01, 0x06, 0x08, 705195972f6Sopenharmony_ci 0x4f, 0x8a, 0x00, 0xb4, 0x55, 0x08, 0x1f, 0xd1, 706195972f6Sopenharmony_ci 0x1c, 0x04, 0x4f, 0x8a, 0x33, 0xff, 0x33, 0x04, 707195972f6Sopenharmony_ci 0x00, 0x00, 0x54, 0x60, 0x35, 0x01, 0x05, 0x36, 708195972f6Sopenharmony_ci 0x04, 0x0a, 0xb5, 0x04, 0x01, 0xff }; 709195972f6Sopenharmony_ci 710195972f6Sopenharmony_ci const u8_t arp_resp[] = { 711195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, /* DEST */ 712195972f6Sopenharmony_ci 0x00, 0x22, 0x93, 0x5a, 0xf7, 0x60, /* SRC */ 713195972f6Sopenharmony_ci 0x08, 0x06, /* Type: ARP */ 714195972f6Sopenharmony_ci 0x00, 0x01, /* HW: Ethernet */ 715195972f6Sopenharmony_ci 0x08, 0x00, /* PROTO: IP */ 716195972f6Sopenharmony_ci 0x06, /* HW size */ 717195972f6Sopenharmony_ci 0x04, /* PROTO size */ 718195972f6Sopenharmony_ci 0x00, 0x02, /* OPCODE: Reply */ 719195972f6Sopenharmony_ci 720195972f6Sopenharmony_ci 0x12, 0x34, 0x56, 0x78, 0x9a, 0xab, /* Target MAC */ 721195972f6Sopenharmony_ci 0x4f, 0x8a, 0x32, 0x01, /* Target IP */ 722195972f6Sopenharmony_ci 723195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0x00, 0x06, 0x50, /* src mac */ 724195972f6Sopenharmony_ci 0x4f, 0x8a, 0x33, 0x05, /* src ip */ 725195972f6Sopenharmony_ci 726195972f6Sopenharmony_ci /* Padding follows.. */ 727195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 728195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 729195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00 }; 730195972f6Sopenharmony_ci 731195972f6Sopenharmony_ci ip4_addr_t addr; 732195972f6Sopenharmony_ci ip4_addr_t netmask; 733195972f6Sopenharmony_ci ip4_addr_t gw; 734195972f6Sopenharmony_ci int i; 735195972f6Sopenharmony_ci u32_t xid; 736195972f6Sopenharmony_ci LWIP_UNUSED_ARG(_i); 737195972f6Sopenharmony_ci 738195972f6Sopenharmony_ci tcase = TEST_LWIP_DHCP_RELAY; 739195972f6Sopenharmony_ci setdebug(0); 740195972f6Sopenharmony_ci 741195972f6Sopenharmony_ci IP4_ADDR(&addr, 0, 0, 0, 0); 742195972f6Sopenharmony_ci IP4_ADDR(&netmask, 0, 0, 0, 0); 743195972f6Sopenharmony_ci IP4_ADDR(&gw, 0, 0, 0, 0); 744195972f6Sopenharmony_ci 745195972f6Sopenharmony_ci netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); 746195972f6Sopenharmony_ci netif_set_link_up(&net_test); 747195972f6Sopenharmony_ci netif_set_up(&net_test); 748195972f6Sopenharmony_ci 749195972f6Sopenharmony_ci dhcp_start(&net_test); 750195972f6Sopenharmony_ci 751195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* DHCP discover sent */ 752195972f6Sopenharmony_ci 753195972f6Sopenharmony_ci /* IP addresses should be zero */ 754195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 755195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 756195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 757195972f6Sopenharmony_ci 758195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* Nothing more sent */ 759195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); 760195972f6Sopenharmony_ci memcpy(&relay_offer[46], &xid, 4); /* insert correct transaction id */ 761195972f6Sopenharmony_ci send_pkt(&net_test, relay_offer, sizeof(relay_offer)); 762195972f6Sopenharmony_ci 763195972f6Sopenharmony_ci /* request sent? */ 764195972f6Sopenharmony_ci fail_unless(txpacket == 2, "txpkt = %d, should be 2", txpacket); 765195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ 766195972f6Sopenharmony_ci memcpy(&relay_ack1[46], &xid, 4); /* insert transaction id */ 767195972f6Sopenharmony_ci send_pkt(&net_test, relay_ack1, sizeof(relay_ack1)); 768195972f6Sopenharmony_ci 769195972f6Sopenharmony_ci for (i = 0; i < 25; i++) { 770195972f6Sopenharmony_ci tick_lwip(); 771195972f6Sopenharmony_ci } 772195972f6Sopenharmony_ci fail_unless(txpacket == 5, "txpkt should be 5, is %d", txpacket); /* ARP requests sent */ 773195972f6Sopenharmony_ci 774195972f6Sopenharmony_ci /* Interface up */ 775195972f6Sopenharmony_ci fail_unless(netif_is_up(&net_test)); 776195972f6Sopenharmony_ci 777195972f6Sopenharmony_ci /* Now it should have taken the IP */ 778195972f6Sopenharmony_ci IP4_ADDR(&addr, 79, 138, 51, 5); 779195972f6Sopenharmony_ci IP4_ADDR(&netmask, 255, 255, 254, 0); 780195972f6Sopenharmony_ci IP4_ADDR(&gw, 79, 138, 50, 1); 781195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 782195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 783195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 784195972f6Sopenharmony_ci 785195972f6Sopenharmony_ci fail_unless(txpacket == 5, "txpacket = %d", txpacket); 786195972f6Sopenharmony_ci 787195972f6Sopenharmony_ci for (i = 0; i < 108000 - 25; i++) { 788195972f6Sopenharmony_ci tick_lwip(); 789195972f6Sopenharmony_ci } 790195972f6Sopenharmony_ci 791195972f6Sopenharmony_ci fail_unless(netif_is_up(&net_test)); 792195972f6Sopenharmony_ci fail_unless(txpacket == 6, "txpacket = %d", txpacket); 793195972f6Sopenharmony_ci 794195972f6Sopenharmony_ci /* We need to send arp response here.. */ 795195972f6Sopenharmony_ci 796195972f6Sopenharmony_ci send_pkt(&net_test, arp_resp, sizeof(arp_resp)); 797195972f6Sopenharmony_ci 798195972f6Sopenharmony_ci fail_unless(txpacket == 7, "txpacket = %d", txpacket); 799195972f6Sopenharmony_ci fail_unless(netif_is_up(&net_test)); 800195972f6Sopenharmony_ci 801195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ 802195972f6Sopenharmony_ci memcpy(&relay_ack2[46], &xid, 4); /* insert transaction id */ 803195972f6Sopenharmony_ci send_pkt(&net_test, relay_ack2, sizeof(relay_ack2)); 804195972f6Sopenharmony_ci 805195972f6Sopenharmony_ci for (i = 0; i < 100000; i++) { 806195972f6Sopenharmony_ci tick_lwip(); 807195972f6Sopenharmony_ci } 808195972f6Sopenharmony_ci 809195972f6Sopenharmony_ci fail_unless(txpacket == 7, "txpacket = %d", txpacket); 810195972f6Sopenharmony_ci 811195972f6Sopenharmony_ci tcase = TEST_NONE; 812195972f6Sopenharmony_ci dhcp_stop(&net_test); 813195972f6Sopenharmony_ci dhcp_cleanup(&net_test); 814195972f6Sopenharmony_ci netif_remove(&net_test); 815195972f6Sopenharmony_ci 816195972f6Sopenharmony_ci} 817195972f6Sopenharmony_ciEND_TEST 818195972f6Sopenharmony_ci 819195972f6Sopenharmony_ciSTART_TEST(test_dhcp_nak_no_endmarker) 820195972f6Sopenharmony_ci{ 821195972f6Sopenharmony_ci ip4_addr_t addr; 822195972f6Sopenharmony_ci ip4_addr_t netmask; 823195972f6Sopenharmony_ci ip4_addr_t gw; 824195972f6Sopenharmony_ci 825195972f6Sopenharmony_ci u8_t dhcp_nack_no_endmarker[] = { 826195972f6Sopenharmony_ci 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x54, 0x75, 827195972f6Sopenharmony_ci 0xd0, 0x26, 0xd0, 0x0d, 0x08, 0x00, 0x45, 0x00, 828195972f6Sopenharmony_ci 0x01, 0x15, 0x38, 0x86, 0x00, 0x00, 0xff, 0x11, 829195972f6Sopenharmony_ci 0xc0, 0xa8, 0xc0, 0xa8, 0x01, 0x01, 0xff, 0xff, 830195972f6Sopenharmony_ci 0xff, 0xff, 0x00, 0x43, 0x00, 0x44, 0x01, 0x01, 831195972f6Sopenharmony_ci 0x00, 0x00, 0x02, 0x01, 0x06, 0x00, 0x7a, 0xcb, 832195972f6Sopenharmony_ci 0xba, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 833195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 834195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 835195972f6Sopenharmony_ci 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 836195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 837195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 838195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 839195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 840195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 841195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 842195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 843195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 844195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 845195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 846195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 847195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 848195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 849195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 850195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 851195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 852195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 853195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 854195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 855195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 856195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 857195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 858195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 859195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 860195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 861195972f6Sopenharmony_ci 0x53, 0x63, 0x35, 0x01, 0x06, 0x36, 0x04, 0xc0, 862195972f6Sopenharmony_ci 0xa8, 0x01, 0x01, 0x31, 0xef, 0xad, 0x72, 0x31, 863195972f6Sopenharmony_ci 0x43, 0x4e, 0x44, 0x30, 0x32, 0x35, 0x30, 0x43, 864195972f6Sopenharmony_ci 0x52, 0x47, 0x44, 0x38, 0x35, 0x36, 0x3c, 0x08, 865195972f6Sopenharmony_ci 0x4d, 0x53, 0x46, 0x54, 0x20, 0x35, 0x2e, 0x30, 866195972f6Sopenharmony_ci 0x37, 0x0d, 0x01, 0x0f, 0x03, 0x06, 0x2c, 0x2e, 867195972f6Sopenharmony_ci 0x2f, 0x1f, 0x21, 0x79, 0xf9, 0x2b, 0xfc, 0xff, 868195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x71, 869195972f6Sopenharmony_ci 0xf3, 0x5b, 0xe2, 0x71, 0x2e, 0x01, 0x08, 0x03, 870195972f6Sopenharmony_ci 0x04, 0xc0, 0xa8, 0x01, 0x01, 0xff, 0xeb, 0x1e, 871195972f6Sopenharmony_ci 0x44, 0xec, 0xeb, 0x1e, 0x30, 0x37, 0x0c, 0x01, 872195972f6Sopenharmony_ci 0x0f, 0x03, 0x06, 0x2c, 0x2e, 0x2f, 0x1f, 0x21, 873195972f6Sopenharmony_ci 0x79, 0xf9, 0x2b, 0xff, 0x25, 0xc0, 0x09, 0xd6, 874195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 875195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 876195972f6Sopenharmony_ci }; 877195972f6Sopenharmony_ci u32_t xid; 878195972f6Sopenharmony_ci struct dhcp* dhcp; 879195972f6Sopenharmony_ci u8_t tries; 880195972f6Sopenharmony_ci u16_t request_timeout; 881195972f6Sopenharmony_ci LWIP_UNUSED_ARG(_i); 882195972f6Sopenharmony_ci 883195972f6Sopenharmony_ci tcase = TEST_LWIP_DHCP_NAK_NO_ENDMARKER; 884195972f6Sopenharmony_ci setdebug(0); 885195972f6Sopenharmony_ci 886195972f6Sopenharmony_ci IP4_ADDR(&addr, 0, 0, 0, 0); 887195972f6Sopenharmony_ci IP4_ADDR(&netmask, 0, 0, 0, 0); 888195972f6Sopenharmony_ci IP4_ADDR(&gw, 0, 0, 0, 0); 889195972f6Sopenharmony_ci 890195972f6Sopenharmony_ci netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); 891195972f6Sopenharmony_ci netif_set_link_up(&net_test); 892195972f6Sopenharmony_ci netif_set_up(&net_test); 893195972f6Sopenharmony_ci 894195972f6Sopenharmony_ci dhcp_start(&net_test); 895195972f6Sopenharmony_ci dhcp = netif_dhcp_data(&net_test); 896195972f6Sopenharmony_ci 897195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* DHCP discover sent */ 898195972f6Sopenharmony_ci xid = dhcp->xid; /* Write bad xid, not using htonl! */ 899195972f6Sopenharmony_ci memcpy(&dhcp_offer[46], &xid, 4); 900195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); 901195972f6Sopenharmony_ci 902195972f6Sopenharmony_ci /* IP addresses should be zero */ 903195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 904195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 905195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 906195972f6Sopenharmony_ci 907195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* Nothing more sent */ 908195972f6Sopenharmony_ci xid = htonl(dhcp->xid); 909195972f6Sopenharmony_ci memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ 910195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); 911195972f6Sopenharmony_ci 912195972f6Sopenharmony_ci fail_unless(dhcp->state == DHCP_STATE_REQUESTING); 913195972f6Sopenharmony_ci 914195972f6Sopenharmony_ci fail_unless(txpacket == 2); /* No more sent */ 915195972f6Sopenharmony_ci xid = htonl(dhcp->xid); /* xid updated */ 916195972f6Sopenharmony_ci memcpy(&dhcp_nack_no_endmarker[46], &xid, 4); /* insert transaction id */ 917195972f6Sopenharmony_ci tries = dhcp->tries; 918195972f6Sopenharmony_ci request_timeout = dhcp->request_timeout; 919195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_nack_no_endmarker, sizeof(dhcp_nack_no_endmarker)); 920195972f6Sopenharmony_ci 921195972f6Sopenharmony_ci /* NAK should be ignored */ 922195972f6Sopenharmony_ci fail_unless(dhcp->state == DHCP_STATE_REQUESTING); 923195972f6Sopenharmony_ci fail_unless(txpacket == 2); /* No more sent */ 924195972f6Sopenharmony_ci fail_unless(xid == htonl(dhcp->xid)); 925195972f6Sopenharmony_ci fail_unless(tries == dhcp->tries); 926195972f6Sopenharmony_ci fail_unless(request_timeout == dhcp->request_timeout); 927195972f6Sopenharmony_ci 928195972f6Sopenharmony_ci tcase = TEST_NONE; 929195972f6Sopenharmony_ci dhcp_stop(&net_test); 930195972f6Sopenharmony_ci dhcp_cleanup(&net_test); 931195972f6Sopenharmony_ci netif_remove(&net_test); 932195972f6Sopenharmony_ci} 933195972f6Sopenharmony_ciEND_TEST 934195972f6Sopenharmony_ci 935195972f6Sopenharmony_ciSTART_TEST(test_dhcp_invalid_overload) 936195972f6Sopenharmony_ci{ 937195972f6Sopenharmony_ci u8_t dhcp_offer_invalid_overload[] = { 938195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, /* To unit */ 939195972f6Sopenharmony_ci 0x00, 0x0F, 0xEE, 0x30, 0xAB, 0x22, /* From Remote host */ 940195972f6Sopenharmony_ci 0x08, 0x00, /* Protocol: IP */ 941195972f6Sopenharmony_ci 0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8, /* IP header */ 942195972f6Sopenharmony_ci 0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00, /* UDP header */ 943195972f6Sopenharmony_ci 944195972f6Sopenharmony_ci 0x02, /* Type == Boot reply */ 945195972f6Sopenharmony_ci 0x01, 0x06, /* Hw Ethernet, 6 bytes addrlen */ 946195972f6Sopenharmony_ci 0x00, /* 0 hops */ 947195972f6Sopenharmony_ci 0xAA, 0xAA, 0xAA, 0xAA, /* Transaction id, will be overwritten */ 948195972f6Sopenharmony_ci 0x00, 0x00, /* 0 seconds elapsed */ 949195972f6Sopenharmony_ci 0x00, 0x00, /* Flags (unicast) */ 950195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, /* Client ip */ 951195972f6Sopenharmony_ci 0xc3, 0xaa, 0xbd, 0xc8, /* Your IP */ 952195972f6Sopenharmony_ci 0xc3, 0xaa, 0xbd, 0xab, /* DHCP server ip */ 953195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, /* relay agent */ 954195972f6Sopenharmony_ci 0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC addr + padding */ 955195972f6Sopenharmony_ci 956195972f6Sopenharmony_ci /* Empty server name */ 957195972f6Sopenharmony_ci 0x34, 0x01, 0x02, 0xff, /* Overload: SNAME + END */ 958195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 959195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 960195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 961195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 962195972f6Sopenharmony_ci /* Empty boot file name */ 963195972f6Sopenharmony_ci 0x34, 0x01, 0x01, 0xff, /* Overload FILE + END */ 964195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 965195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 966195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 967195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 968195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 969195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 970195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 971195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 972195972f6Sopenharmony_ci 973195972f6Sopenharmony_ci 0x63, 0x82, 0x53, 0x63, /* Magic cookie */ 974195972f6Sopenharmony_ci 0x35, 0x01, 0x02, /* Message type: Offer */ 975195972f6Sopenharmony_ci 0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Server identifier (IP) */ 976195972f6Sopenharmony_ci 0x33, 0x04, 0x00, 0x00, 0x00, 0x78, /* Lease time 2 minutes */ 977195972f6Sopenharmony_ci 0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Router IP */ 978195972f6Sopenharmony_ci 0x01, 0x04, 0xff, 0xff, 0xff, 0x00, /* Subnet mask */ 979195972f6Sopenharmony_ci 0x34, 0x01, 0x03, /* Overload: FILE + SNAME */ 980195972f6Sopenharmony_ci 0xff, /* End option */ 981195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 982195972f6Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Padding */ 983195972f6Sopenharmony_ci }; 984195972f6Sopenharmony_ci ip4_addr_t addr; 985195972f6Sopenharmony_ci ip4_addr_t netmask; 986195972f6Sopenharmony_ci ip4_addr_t gw; 987195972f6Sopenharmony_ci u32_t xid; 988195972f6Sopenharmony_ci LWIP_UNUSED_ARG(_i); 989195972f6Sopenharmony_ci 990195972f6Sopenharmony_ci tcase = TEST_LWIP_DHCP_INVALID_OVERLOAD; 991195972f6Sopenharmony_ci setdebug(0); 992195972f6Sopenharmony_ci 993195972f6Sopenharmony_ci IP4_ADDR(&addr, 0, 0, 0, 0); 994195972f6Sopenharmony_ci IP4_ADDR(&netmask, 0, 0, 0, 0); 995195972f6Sopenharmony_ci IP4_ADDR(&gw, 0, 0, 0, 0); 996195972f6Sopenharmony_ci 997195972f6Sopenharmony_ci netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input); 998195972f6Sopenharmony_ci netif_set_link_up(&net_test); 999195972f6Sopenharmony_ci netif_set_up(&net_test); 1000195972f6Sopenharmony_ci 1001195972f6Sopenharmony_ci dhcp_start(&net_test); 1002195972f6Sopenharmony_ci 1003195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* DHCP discover sent */ 1004195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); 1005195972f6Sopenharmony_ci memcpy(&dhcp_offer_invalid_overload[46], &xid, 4); /* insert correct transaction id */ 1006195972f6Sopenharmony_ci dhcp_offer_invalid_overload[311] = 3; 1007195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer_invalid_overload, sizeof(dhcp_offer_invalid_overload)); 1008195972f6Sopenharmony_ci /* IP addresses should be zero */ 1009195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 1010195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 1011195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 1012195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* Nothing more sent */ 1013195972f6Sopenharmony_ci 1014195972f6Sopenharmony_ci dhcp_offer_invalid_overload[311] = 2; 1015195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer_invalid_overload, sizeof(dhcp_offer_invalid_overload)); 1016195972f6Sopenharmony_ci /* IP addresses should be zero */ 1017195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 1018195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 1019195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 1020195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* Nothing more sent */ 1021195972f6Sopenharmony_ci 1022195972f6Sopenharmony_ci dhcp_offer_invalid_overload[311] = 1; 1023195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer_invalid_overload, sizeof(dhcp_offer_invalid_overload)); 1024195972f6Sopenharmony_ci /* IP addresses should be zero */ 1025195972f6Sopenharmony_ci fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t))); 1026195972f6Sopenharmony_ci fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t))); 1027195972f6Sopenharmony_ci fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); 1028195972f6Sopenharmony_ci fail_unless(txpacket == 1); /* Nothing more sent */ 1029195972f6Sopenharmony_ci 1030195972f6Sopenharmony_ci dhcp_offer_invalid_overload[311] = 0; 1031195972f6Sopenharmony_ci send_pkt(&net_test, dhcp_offer_invalid_overload, sizeof(dhcp_offer)); 1032195972f6Sopenharmony_ci 1033195972f6Sopenharmony_ci fail_unless(netif_dhcp_data(&net_test)->state == DHCP_STATE_REQUESTING); 1034195972f6Sopenharmony_ci 1035195972f6Sopenharmony_ci fail_unless(txpacket == 2); /* No more sent */ 1036195972f6Sopenharmony_ci xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ 1037195972f6Sopenharmony_ci 1038195972f6Sopenharmony_ci tcase = TEST_NONE; 1039195972f6Sopenharmony_ci dhcp_stop(&net_test); 1040195972f6Sopenharmony_ci dhcp_cleanup(&net_test); 1041195972f6Sopenharmony_ci netif_remove(&net_test); 1042195972f6Sopenharmony_ci} 1043195972f6Sopenharmony_ciEND_TEST 1044195972f6Sopenharmony_ci 1045195972f6Sopenharmony_ci/** Create the suite including all tests for this module */ 1046195972f6Sopenharmony_ciSuite * 1047195972f6Sopenharmony_cidhcp_suite(void) 1048195972f6Sopenharmony_ci{ 1049195972f6Sopenharmony_ci testfunc tests[] = { 1050195972f6Sopenharmony_ci TESTFUNC(test_dhcp), 1051195972f6Sopenharmony_ci TESTFUNC(test_dhcp_nak), 1052195972f6Sopenharmony_ci TESTFUNC(test_dhcp_relayed), 1053195972f6Sopenharmony_ci TESTFUNC(test_dhcp_nak_no_endmarker), 1054195972f6Sopenharmony_ci TESTFUNC(test_dhcp_invalid_overload) 1055195972f6Sopenharmony_ci }; 1056195972f6Sopenharmony_ci return create_suite("DHCP", tests, sizeof(tests)/sizeof(testfunc), dhcp_setup, dhcp_teardown); 1057195972f6Sopenharmony_ci} 1058