update(demo): include dnserver & dhserver config for rndis & ecm
Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
@@ -5,6 +5,12 @@
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_cdc_ecm.h"
|
||||
#include "dhserver.h"
|
||||
#include "dnserver.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
#ifndef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
#error "Please enable CONFIG_USBDEV_CDC_ECM_USING_LWIP for this demo"
|
||||
@@ -203,7 +209,7 @@ const uint8_t mac[6] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
|
||||
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
|
||||
#define IP_ADDR0 (uint8_t)192
|
||||
#define IP_ADDR1 (uint8_t)168
|
||||
#define IP_ADDR2 (uint8_t)123
|
||||
#define IP_ADDR2 (uint8_t)7
|
||||
#define IP_ADDR3 (uint8_t)100
|
||||
|
||||
/*NETMASK*/
|
||||
@@ -215,18 +221,40 @@ const uint8_t mac[6] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
|
||||
/*Gateway Address*/
|
||||
#define GW_ADDR0 (uint8_t)192
|
||||
#define GW_ADDR1 (uint8_t)168
|
||||
#define GW_ADDR2 (uint8_t)123
|
||||
#define GW_ADDR2 (uint8_t)7
|
||||
#define GW_ADDR3 (uint8_t)1
|
||||
|
||||
#include "netif/etharp.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
|
||||
const ip_addr_t netmask = IPADDR4_INIT_BYTES(NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
const ip_addr_t gateway = IPADDR4_INIT_BYTES(GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
|
||||
#define NUM_DHCP_ENTRY 3
|
||||
|
||||
static dhcp_entry_t entries[NUM_DHCP_ENTRY] = {
|
||||
/* mac ip address subnet mask lease time */
|
||||
{ { 0 }, { 192, 168, 7, 2 }, { 255, 255, 255, 0 }, 24 * 60 * 60 },
|
||||
{ { 0 }, { 192, 168, 7, 3 }, { 255, 255, 255, 0 }, 24 * 60 * 60 },
|
||||
{ { 0 }, { 192, 168, 7, 4 }, { 255, 255, 255, 0 }, 24 * 60 * 60 }
|
||||
};
|
||||
|
||||
static dhcp_config_t dhcp_config = {
|
||||
{ 192, 168, 7, 1 }, /* server address */
|
||||
67, /* port */
|
||||
{ 192, 168, 7, 1 }, /* dns server */
|
||||
"cherry", /* dns suffix */
|
||||
NUM_DHCP_ENTRY, /* num entry */
|
||||
entries /* entries */
|
||||
};
|
||||
|
||||
static bool dns_query_proc(const char *name, ip_addr_t *addr)
|
||||
{
|
||||
if (strcmp(name, "rndis.cherry") == 0 || strcmp(name, "www.rndis.cherry") == 0) {
|
||||
addr->addr = *(uint32_t *)ipaddr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct netif cdc_ecm_netif; //network interface
|
||||
|
||||
/* Network interface name */
|
||||
@@ -292,7 +320,7 @@ void cdc_ecm_lwip_init(void)
|
||||
|
||||
while (dhserv_init(&dhcp_config)) {}
|
||||
|
||||
while (dnserv_init(&ipaddr, PORT_DNS, dns_query_proc)) {}
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {}
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_data_recv_done(uint32_t len)
|
||||
|
||||
Reference in New Issue
Block a user