|
|
@@ -50,8 +50,11 @@ try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00
|
|
|
#include "dnserver.h"
|
|
|
#include "lwip/init.h"
|
|
|
#include "lwip/timeouts.h"
|
|
|
+#include "lwip/ethip6.h"
|
|
|
#include "httpd.h"
|
|
|
|
|
|
+#define INIT_IP4(a,b,c,d) { PP_HTONL(LWIP_MAKEU32(a,b,c,d)) }
|
|
|
+
|
|
|
/* lwip context */
|
|
|
static struct netif netif_data;
|
|
|
|
|
|
@@ -64,24 +67,24 @@ static struct pbuf *received_frame;
|
|
|
const uint8_t tud_network_mac_address[6] = {0x02,0x02,0x84,0x6A,0x96,0x00};
|
|
|
|
|
|
/* network parameters of this MCU */
|
|
|
-static const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(192, 168, 7, 1);
|
|
|
-static const ip_addr_t netmask = IPADDR4_INIT_BYTES(255, 255, 255, 0);
|
|
|
-static const ip_addr_t gateway = IPADDR4_INIT_BYTES(0, 0, 0, 0);
|
|
|
+static const ip4_addr_t ipaddr = INIT_IP4(192, 168, 7, 1);
|
|
|
+static const ip4_addr_t netmask = INIT_IP4(255, 255, 255, 0);
|
|
|
+static const ip4_addr_t gateway = INIT_IP4(0, 0, 0, 0);
|
|
|
|
|
|
/* database IP addresses that can be offered to the host; this must be in RAM to store assigned MAC addresses */
|
|
|
static dhcp_entry_t entries[] =
|
|
|
{
|
|
|
/* mac ip address lease time */
|
|
|
- { {0}, IPADDR4_INIT_BYTES(192, 168, 7, 2), 24 * 60 * 60 },
|
|
|
- { {0}, IPADDR4_INIT_BYTES(192, 168, 7, 3), 24 * 60 * 60 },
|
|
|
- { {0}, IPADDR4_INIT_BYTES(192, 168, 7, 4), 24 * 60 * 60 },
|
|
|
+ { {0}, INIT_IP4(192, 168, 7, 2), 24 * 60 * 60 },
|
|
|
+ { {0}, INIT_IP4(192, 168, 7, 3), 24 * 60 * 60 },
|
|
|
+ { {0}, INIT_IP4(192, 168, 7, 4), 24 * 60 * 60 },
|
|
|
};
|
|
|
|
|
|
static const dhcp_config_t dhcp_config =
|
|
|
{
|
|
|
- .router = IPADDR4_INIT_BYTES(0, 0, 0, 0), /* router address (if any) */
|
|
|
+ .router = INIT_IP4(0, 0, 0, 0), /* router address (if any) */
|
|
|
.port = 67, /* listen port */
|
|
|
- .dns = IPADDR4_INIT_BYTES(192, 168, 7, 1), /* dns server (if any) */
|
|
|
+ .dns = INIT_IP4(192, 168, 7, 1), /* dns server (if any) */
|
|
|
"usb", /* dns suffix */
|
|
|
TU_ARRAY_SIZE(entries), /* num entry */
|
|
|
entries /* entries */
|
|
|
@@ -108,11 +111,18 @@ static err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static err_t output_fn(struct netif *netif, struct pbuf *p, const ip_addr_t *addr)
|
|
|
+static err_t ip4_output_fn(struct netif *netif, struct pbuf *p, const ip4_addr_t *addr)
|
|
|
{
|
|
|
return etharp_output(netif, p, addr);
|
|
|
}
|
|
|
|
|
|
+#if LWIP_IPV6
|
|
|
+static err_t ip6_output_fn(struct netif *netif, struct pbuf *p, const ip6_addr_t *addr)
|
|
|
+{
|
|
|
+ return ethip6_output(netif, p, addr);
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
static err_t netif_init_cb(struct netif *netif)
|
|
|
{
|
|
|
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
|
|
@@ -122,7 +132,10 @@ static err_t netif_init_cb(struct netif *netif)
|
|
|
netif->name[0] = 'E';
|
|
|
netif->name[1] = 'X';
|
|
|
netif->linkoutput = linkoutput_fn;
|
|
|
- netif->output = output_fn;
|
|
|
+ netif->output = ip4_output_fn;
|
|
|
+#if LWIP_IPV6
|
|
|
+ netif->output_ip6 = ip6_output_fn;
|
|
|
+#endif
|
|
|
return ERR_OK;
|
|
|
}
|
|
|
|
|
|
@@ -138,11 +151,14 @@ static void init_lwip(void)
|
|
|
netif->hwaddr[5] ^= 0x01;
|
|
|
|
|
|
netif = netif_add(netif, &ipaddr, &netmask, &gateway, NULL, netif_init_cb, ip_input);
|
|
|
+#if LWIP_IPV6
|
|
|
+ netif_create_ip6_linklocal_address(netif, 1);
|
|
|
+#endif
|
|
|
netif_set_default(netif);
|
|
|
}
|
|
|
|
|
|
/* handle any DNS requests from dns-server */
|
|
|
-bool dns_query_proc(const char *name, ip_addr_t *addr)
|
|
|
+bool dns_query_proc(const char *name, ip4_addr_t *addr)
|
|
|
{
|
|
|
if (0 == strcmp(name, "tiny.usb"))
|
|
|
{
|
|
|
@@ -218,7 +234,7 @@ int main(void)
|
|
|
init_lwip();
|
|
|
while (!netif_is_up(&netif_data));
|
|
|
while (dhserv_init(&dhcp_config) != ERR_OK);
|
|
|
- while (dnserv_init(&ipaddr, 53, dns_query_proc) != ERR_OK);
|
|
|
+ while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc) != ERR_OK);
|
|
|
httpd_init();
|
|
|
|
|
|
while (1)
|