1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-20 21:01:25 +03:00

Fix issue on client side

This commit is contained in:
Mimmo La Fauci
2013-03-26 19:49:19 +01:00
parent c0a7131a8a
commit 7fa382099d
7 changed files with 15012 additions and 14988 deletions

File diff suppressed because it is too large Load Diff

View File

@ -591,7 +591,7 @@ int set_ip_config_cmd_cb(int numParam, char* buf, void* ctx) {
} }
/* Disable DHCP */ /* Disable DHCP */
ncfg->dhcp_enabled = 0; ncfg->dhcp_enabled = STATIC_IP_CONFIG;
}else }else
RETURN_ERR(WL_FAILURE) RETURN_ERR(WL_FAILURE)
@ -635,7 +635,7 @@ int set_dns_config_cmd_cb(int numParam, char* buf, void* ctx) {
} }
} }
/* Disable DHCP */ /* Disable DHCP */
ncfg->dhcp_enabled = 0; ncfg->dhcp_enabled = STATIC_IP_CONFIG;
}else }else
RETURN_ERR(WL_FAILURE) RETURN_ERR(WL_FAILURE)

View File

@ -565,14 +565,21 @@ static int atcp_start(struct ttcp* ttcp) {
atcp_init_pend_flags(ttcp); atcp_init_pend_flags(ttcp);
if (ttcp->mode == TTCP_MODE_TRANSMIT) { if (ttcp->mode == TTCP_MODE_TRANSMIT) {
setNewClientConn(ttcp, p, 0); int8_t id = insertNewClientConn(ttcp, p);
struct tcp_pcb * pcb = GET_FIRST_CLIENT_TCP(ttcp); ttcp->payload[id] = malloc(ttcp->buflen);
INFO_TCP("Alloc payload %d-%p\n", id, ttcp->payload[id]);
if (ttcp->payload[id] == NULL) {
WARN("TTCP [%p]: could not allocate payload\n", ttcp);
return -1;
}
struct tcp_pcb * pcb = p;
tcp_err(pcb, atcp_conn_cli_err_cb); tcp_err(pcb, atcp_conn_cli_err_cb);
tcp_recv(pcb, atcp_recv_cb); tcp_recv(pcb, atcp_recv_cb);
tcp_sent(pcb, tcp_data_sent); tcp_sent(pcb, tcp_data_sent);
tcp_poll(pcb, atcp_poll_conn, 4); tcp_poll(pcb, atcp_poll_conn, 4);
_connected = false; _connected = false;
INFO_TCP("[tpcb]-%p payload:%p\n", pcb, ttcp->payload[currConnId]); INFO_TCP("[tpcb]-%p payload:%p\n", pcb, ttcp->payload[id]);
DUMP_TCP_STATE(ttcp); DUMP_TCP_STATE(ttcp);
if (tcp_connect(pcb, &ttcp->addr, ttcp->port, tcp_connect_cb) if (tcp_connect(pcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
!= ERR_OK) { != ERR_OK) {

View File

@ -189,13 +189,13 @@ cmd_set_ip(int argc, char* argv[], void* ctx)
if (argc == 2 && if (argc == 2 &&
(strncmp(argv[1], "none", 4) == 0)) { (strncmp(argv[1], "none", 4) == 0)) {
ncfg->dhcp_enabled = 1; ncfg->dhcp_enabled = DYNAMIC_IP_CONFIG;
return CMD_DONE; return CMD_DONE;
} }
else if (argc != 4 ) { else if (argc != 4 ) {
printk("usage: ip <ip> <netmask> <gateway-ip>\n"); printk("usage: ipconfig <ip> <netmask> <gateway-ip>\n");
printk(" or : ip none (to enable DHCP)\n"); printk(" or : ipconfig none (to enable DHCP)\n");
return CMD_DONE; return CMD_DONE;
} }
@ -210,7 +210,7 @@ cmd_set_ip(int argc, char* argv[], void* ctx)
lwip_addr = str2ip(argv[3]); lwip_addr = str2ip(argv[3]);
netif_set_gw(nif, &lwip_addr); netif_set_gw(nif, &lwip_addr);
/* Disable DHCP */ /* Disable DHCP */
ncfg->dhcp_enabled = 0; ncfg->dhcp_enabled = STATIC_IP_CONFIG;
return CMD_DONE; return CMD_DONE;
} }
@ -458,7 +458,11 @@ cmd_status(int argc, char* argv[], void* ctx)
/* print ip address */ /* print ip address */
if (netif_is_up(netif_default)) if (netif_is_up(netif_default))
printk("ip addr: %s\n", ip2str(netif_default->ip_addr)); {
printk("ip addr: %s - ", ip2str(netif_default->ip_addr));
printk("netmask: %s - ", ip2str(netif_default->netmask));
printk("gateway: %s\n", ip2str(netif_default->gw));
}
else else
printk("ip interface is down\n"); printk("ip interface is down\n");
printk("dhcp : "); printk("dhcp : ");
@ -471,8 +475,8 @@ cmd_status(int argc, char* argv[], void* ctx)
struct ip_addr addr1 = dns_getserver(0); struct ip_addr addr1 = dns_getserver(0);
struct ip_addr addr2 = dns_getserver(1); struct ip_addr addr2 = dns_getserver(1);
printk("==> DNS1: %s\n", ip2str(addr1), addr1); printk("DNS: %s - ", ip2str(addr1));
printk("==> DNS2: %s\n", ip2str(addr2), addr2); printk("%s\n", ip2str(addr2));
showTTCPstatus(); showTTCPstatus();
return CMD_DONE; return CMD_DONE;

View File

@ -1,6 +1,10 @@
#ifndef _LWIP_SETUP_H #ifndef _LWIP_SETUP_H
#define _LWIP_SETUP_H #define _LWIP_SETUP_H
#define INIT_IP_CONFIG 0xff
#define STATIC_IP_CONFIG 0
#define DYNAMIC_IP_CONFIG 1
struct net_cfg { struct net_cfg {
struct netif *netif; /* lwip network interface */ struct netif *netif; /* lwip network interface */
uint8_t dhcp_enabled; uint8_t dhcp_enabled;

View File

@ -277,7 +277,6 @@ void initShell(void* ctx)
console_add_cmd("debug", cmd_debug, NULL); console_add_cmd("debug", cmd_debug, NULL);
console_add_cmd("dumpBuf", cmd_dumpBuf, NULL); console_add_cmd("dumpBuf", cmd_dumpBuf, NULL);
console_add_cmd("ipconfig", cmd_set_ip, ctx); console_add_cmd("ipconfig", cmd_set_ip, ctx);
#ifdef ADD_CMDS #ifdef ADD_CMDS
console_add_cmd("powersave", cmd_power, NULL); console_add_cmd("powersave", cmd_power, NULL);
console_add_cmd("psconf", cmd_psconf, NULL); console_add_cmd("psconf", cmd_psconf, NULL);
@ -314,12 +313,15 @@ wl_init_complete_cb(void* ctx)
struct ip_addr ipaddr, netmask, gw; struct ip_addr ipaddr, netmask, gw;
wl_err_t wl_status; wl_err_t wl_status;
IP4_ADDR(&gw, 0,0,0,0); if (hs->net_cfg.dhcp_enabled == INIT_IP_CONFIG)
IP4_ADDR(&ipaddr, 0,0,0,0); {
IP4_ADDR(&netmask, 0,0,0,0); IP4_ADDR(&gw, 0,0,0,0);
IP4_ADDR(&ipaddr, 0,0,0,0);
/* default is dhcp enabled */ IP4_ADDR(&netmask, 0,0,0,0);
hs->net_cfg.dhcp_enabled = 1;
/* default is dhcp enabled */
hs->net_cfg.dhcp_enabled = DYNAMIC_IP_CONFIG;
}
start_ip_stack(&hs->net_cfg, start_ip_stack(&hs->net_cfg,
ipaddr, ipaddr,
@ -358,6 +360,8 @@ void startup_init(void)
DEB_PIN_UP(2); DEB_PIN_UP(2);
} }
const char timestamp[] = __TIMESTAMP__;
/** /**
* *
*/ */
@ -390,7 +394,7 @@ main(void)
} }
#else #else
printk("Arduino Wifi Startup... [%s]\n", __TIMESTAMP__); printk("Arduino Wifi Startup... [%s]\n", timestamp);
size_t size_ctx_server = sizeof(struct ctx_server); size_t size_ctx_server = sizeof(struct ctx_server);
hs = calloc(1, size_ctx_server); hs = calloc(1, size_ctx_server);
@ -399,6 +403,7 @@ main(void)
size_t size_netif = sizeof(struct netif); size_t size_netif = sizeof(struct netif);
hs->net_cfg.netif = calloc(1, size_netif); hs->net_cfg.netif = calloc(1, size_netif);
ASSERT(hs->net_cfg.netif, "out of memory"); ASSERT(hs->net_cfg.netif, "out of memory");
hs->net_cfg.dhcp_enabled = INIT_IP_CONFIG;
INFO_INIT("hs:%p size:0x%x netif:%p size:0x%x\n", hs, size_ctx_server, INFO_INIT("hs:%p size:0x%x netif:%p size:0x%x\n", hs, size_ctx_server,
hs->net_cfg.netif, size_netif); hs->net_cfg.netif, size_netif);