36#include <lwip/etharp.h>
40#define NETIFAPI_VAR_REF(name) API_VAR_REF(name)
41#define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name)
42#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
43#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
57 ip_addr_t old_netmask;
58 ip_addr_t old_gateway;
63 old_ipaddr = netif->ip_addr;
64 old_netmask = netif->netmask;
65 old_gateway = netif->gw;
67 if (netif_dhcp_data(netif)) {
68 (
void)dhcp_release(netif);
69 (
void)dhcp_stop(netif);
70 (
void)dhcp_cleanup(netif);
71 LWIP_DEBUGF(NETIF_DEBUG, (
"DHCP is close;set static IP\n"));
74 ip_addr_set_val(&netif->ip_addr, &old_ipaddr);
75 ip_addr_set_val(&netif->netmask, &old_netmask);
76 ip_addr_set_val(&netif->gw, &old_gateway);
77 (
void)netif_set_up(netif);
84 struct dhcp *dhcp = NULL;
86 LWIP_ERROR(
"netif != NULL", (netif != NULL),
return ERR_ARG);
88 dhcp = netif_dhcp_data(netif);
89 LWIP_ERROR(
"netif->dhcp != NULL", (dhcp != NULL),
return ERR_ARG);
91 if (dhcp->state == DHCP_STATE_BOUND) {
94 return ERR_INPROGRESS;
109 struct netifapi_msg *msg = (
struct netifapi_msg *)(
void *)m;
110 ret =
dhcps_start(msg->netif, msg->msg.dhcp_start_params.start_ip, msg->msg.dhcp_start_params.ip_num);
117 NETIFAPI_VAR_DECLARE(msg);
119 LWIP_ERROR(
"netifapi_dhcps_start : invalid arguments", (netif != NULL),
return ERR_VAL);
120 NETIFAPI_VAR_ALLOC(msg);
122 NETIFAPI_VAR_REF(msg).netif = netif;
123 NETIFAPI_VAR_REF(msg).msg.dhcp_start_params.start_ip = start_ip;
124 NETIFAPI_VAR_REF(msg).msg.dhcp_start_params.ip_num = ip_num;
128 NETIFAPI_VAR_FREE(msg);
134 LWIP_ERROR(
"netifapi_dhcps_stop : invalid arguments", (netif != NULL),
return ERR_VAL);
136 return netifapi_netif_common(netif,
dhcps_stop, NULL);
153 LWIP_ERROR(
"netif_ip6_addr_set : invalid arguments", (netif != NULL),
return);
154 LWIP_ERROR(
"netif_ip6_addr_set : invalid arguments", (addr6 != NULL),
return);
156 idx = netif_get_ip6_addr_match(netif, addr6);
161 netif_ip6_addr_set_state(netif, idx, IP6_ADDR_INVALID);
167 ip_addr_t *ipaddr = (ip_addr_t *)arguments;
169 if (IP_IS_V6(ipaddr)) {
182 struct netifapi_msg *msg = (
struct netifapi_msg *)(
void *)m;
193 NETIFAPI_VAR_DECLARE(msg);
194 NETIFAPI_VAR_ALLOC(msg);
196 NETIFAPI_VAR_REF(msg).netif = netif;
197 NETIFAPI_VAR_REF(msg).msg.add.ipaddr = (
void *)ipaddr;
201 NETIFAPI_VAR_FREE(msg);
207 struct netif *netif = NULL;
209 LWIP_ASSERT_CORE_LOCKED();
215 NETIF_FOREACH(netif) {
216 if (strcmp(
"lo", name) == 0 && (netif->name[0] ==
'l' && netif->name[1] ==
'o')) {
217 LWIP_DEBUGF(NETIF_DEBUG, (
"netif_find_by_name: found lo\n"));
221 if (strcmp(netif->full_name, name) == 0) {
222 LWIP_DEBUGF(NETIF_DEBUG, (
"netif_find_by_name: found %s\n", name));
227 LWIP_DEBUGF(NETIF_DEBUG, (
"netif_find_by_name: didn't find %s\n", name));
235 struct netifapi_msg *msg = (
struct netifapi_msg *)(
void *)m;
243 struct netif *netif = NULL;
244 NETIFAPI_VAR_DECLARE(msg);
245 NETIFAPI_VAR_ALLOC(msg);
247 NETIFAPI_VAR_REF(msg).netif = NULL;
248#if LWIP_MPU_COMPATIBLE
249 if (strncpy_s(NETIFAPI_VAR_REF(msg).msg.ifs.name, NETIF_NAMESIZE, name, NETIF_NAMESIZE - 1)) {
250 NETIFAPI_VAR_FREE(msg);
253 NETIFAPI_VAR_REF(msg).msg.ifs.name[NETIF_NAMESIZE - 1] =
'\0';
255 NETIFAPI_VAR_REF(msg).msg.ifs.name = (
char *)name;
261 NETIFAPI_VAR_FREE(msg);
265#define NETIF_MTU_MIN 1280
266#ifndef IP_FRAG_MIN_MTU
267#define IP_FRAG_MIN_MTU 68
277 LWIP_ERROR(
"netif_set_mtu: invalid arguments", (netif != NULL),
return ERR_VAL);
280 LWIP_ERROR(
"netif_set_mtu: invalid arguments", (netif_mtu >= NETIF_MTU_MIN) && (netif_mtu <= IP_FRAG_MAX_MTU),
283 LWIP_ERROR(
"netif_set_mtu: invalid arguments", (netif_mtu >= IP_FRAG_MIN_MTU) && (netif_mtu <= IP_FRAG_MAX_MTU),
287 netif->mtu = netif_mtu;
288#if LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES
289 netif->mtu6 = netif_mtu;
292 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, (
"netif: MTU of interface %s is changed to %d\n",
293 netif_get_name(netif), netif->mtu));
299 LWIP_ERROR(
"netif_set_hwaddr : invalid arguments", (netif != NULL),
return ERR_VAL);
301 LWIP_ERROR(
"netif_set_hwaddr : invalid arguments", (hw_addr != NULL),
return ERR_VAL);
303 LWIP_ERROR(
"netif_set_hwaddr: invalid arguments",
304 ((
unsigned int)hw_len == NETIF_MAX_HWADDR_LEN),
return ERR_VAL);
306 if (netif->drv_set_hwaddr == NULL) {
310 if (netif->drv_set_hwaddr(netif, (u8_t *)hw_addr, hw_len) != ERR_OK) {
314 if (memcpy_s(netif->hwaddr, NETIF_MAX_HWADDR_LEN, hw_addr, hw_len) != EOK) {
315 LWIP_DEBUGF(NETIF_DEBUG, (
"netif_set_hwaddr: memcpy_s error\n"));
319 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
320 (
"netif: HW address of interface %s set to %02X:%02X:%02X:%02X:%02X:%02X\n",
321 netif_get_name(netif),
322 netif->hwaddr[0], netif->hwaddr[1], netif->hwaddr[2],
323 netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]));
367#if LWIP_ENABLE_IP_CONFLICT_SIGNAL
407 const int ipv6_blocks = 8;
408 u16_t current_block_index = 0;
409 u16_t current_block_value = 0;
410 u16_t addr16[ipv6_blocks];
411 u16_t *a16 = (u16_t *)addr->addr;
412 int squash_pos = ipv6_blocks;
415 const char *ss = cp-1;
418 if (current_block_index >= ipv6_blocks) {
423 if (squash_pos != current_block_index) {
427 addr16[current_block_index++] = current_block_value;
430 }
else if (*s ==
':') {
432 if (s != cp || s[1] !=
':') {
436 addr16[current_block_index++] = current_block_value;
439 if (squash_pos != ipv6_blocks) {
442 squash_pos = current_block_index;
446 current_block_value = 0;
447 }
else if (lwip_isxdigit(*s) && (s - ss) < 5) {
448 current_block_value = (current_block_value << 4) +
449 ((u8_t)(*s) | (
'a' -
'A')) -
'0' - (
'a' -
'9' - 1) * (*s >=
'A');
451 }
else if (*s ==
'.' && current_block_index < ipv6_blocks - 1) {
453 int ret = ip4addr_aton(ss+1, &ip4);
457 ip4.addr = lwip_ntohl(ip4.addr);
458 addr16[current_block_index++] = (u16_t)(ip4.addr >> 16);
459 addr16[current_block_index++] = (u16_t)(ip4.addr);
467 if (squash_pos == ipv6_blocks && current_block_index != ipv6_blocks) {
470 if (squash_pos != ipv6_blocks && current_block_index == ipv6_blocks) {
474 for (i = 0; i < squash_pos; ++i) {
475 a16[i] = lwip_htons(addr16[i]);
477 for (; i < ipv6_blocks - current_block_index + squash_pos; ++i) {
480 for (; i < ipv6_blocks; ++i) {
481 a16[i] = lwip_htons(addr16[i - ipv6_blocks + current_block_index]);
void dhcps_stop(struct netif *netif)
err_t dhcps_start(struct netif *netif, const char *start_ip, u16_t ip_num)
static err_t netif_do_rmv_ip6_address(struct tcpip_api_call_data *m)
err_t etharp_delete_arp_entry(struct netif *netif, ip4_addr_t *ipaddr)
void netifapi_netif_rmv_ip6_address(struct netif *netif, ip_addr_t *ipaddr)
err_t lwip_dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
volatile int tcpip_init_finish
int ip6addr_aton(const char *cp, ip6_addr_t *addr)
static struct netif * netif_find_by_name(const char *name)
const char *const tcp_state_str[]
struct raw_pcb * raw_pcbs
sys_sem_t dup_addr_detect
struct netif * netifapi_netif_find_by_name(const char *name)
err_t netif_set_hwaddr(struct netif *netif, const unsigned char *hw_addr, int hw_len)
err_t netifapi_dhcps_stop(struct netif *netif)
err_t netif_dhcp_off(struct netif *netif)
err_t netif_do_rmv_ipv6_addr(struct netif *netif, void *arguments)
err_t etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags)
err_t netifapi_dhcps_start(struct netif *netif, char *start_ip, u16_t ip_num)
static void netif_ip6_addr_setinvalid(struct netif *netif, const ip6_addr_t *addr6)
u32_t is_ip_conflict_signal
sys_sem_t ip_conflict_detect
int lwip_sntp_start(int server_num, char **sntp_server, struct timeval *time)
static err_t netifapi_do_dhcps_start(struct tcpip_api_call_data *m)
static err_t netifapi_do_find_by_name(struct tcpip_api_call_data *m)
err_t netif_set_mtu(struct netif *netif, u16_t netif_mtu)
u32_t is_dup_detect_initialized
err_t dhcp_is_bound(struct netif *netif)
struct raw_pcb * pkt_raw_pcbs
static void tcp_unlock_accept(ip6_addr_t *ipaddr)
err_t lwip_dns_getserver(u8_t numdns, ip_addr_t *dnsserver)
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void