|
|
@ -3,6 +3,7 @@ |
|
|
|
#include "cmd.h" |
|
|
|
#include "cmd.h" |
|
|
|
#include <socket.h> |
|
|
|
#include <socket.h> |
|
|
|
#include <ip_addr.h> |
|
|
|
#include <ip_addr.h> |
|
|
|
|
|
|
|
#include <strings.h> |
|
|
|
|
|
|
|
|
|
|
|
#if 1 |
|
|
|
#if 1 |
|
|
|
#define DBG_UPNP(format, ...) os_printf(format, ## __VA_ARGS__) |
|
|
|
#define DBG_UPNP(format, ...) os_printf(format, ## __VA_ARGS__) |
|
|
@ -26,7 +27,6 @@ static enum upnp_state_t upnp_state; |
|
|
|
|
|
|
|
|
|
|
|
static const char *upnp_ssdp_multicast = "239.255.255.250"; |
|
|
|
static const char *upnp_ssdp_multicast = "239.255.255.250"; |
|
|
|
static short upnp_server_port = 1900; |
|
|
|
static short upnp_server_port = 1900; |
|
|
|
static short upnp_local_port = -1; |
|
|
|
|
|
|
|
static const char *ssdp_message = "M-SEARCH * HTTP/1.1\r\n" |
|
|
|
static const char *ssdp_message = "M-SEARCH * HTTP/1.1\r\n" |
|
|
|
"HOST: 239.255.255.250:1900\r\n" |
|
|
|
"HOST: 239.255.255.250:1900\r\n" |
|
|
|
"ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n" |
|
|
|
"ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n" |
|
|
@ -48,8 +48,10 @@ typedef struct { |
|
|
|
uint16_t data_sent; |
|
|
|
uint16_t data_sent; |
|
|
|
} UPnPClient; |
|
|
|
} UPnPClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static UPnPClient *the_client; |
|
|
|
|
|
|
|
|
|
|
|
// Functions
|
|
|
|
// Functions
|
|
|
|
static void upnp_query_igd(); |
|
|
|
static void upnp_query_igd(struct espconn *); |
|
|
|
static void ssdp_sent_cb(void *arg); |
|
|
|
static void ssdp_sent_cb(void *arg); |
|
|
|
static void ssdp_recv_cb(void *arg, char *pusrdata, unsigned short length); |
|
|
|
static void ssdp_recv_cb(void *arg, char *pusrdata, unsigned short length); |
|
|
|
static void upnp_tcp_sent_cb(void *arg); |
|
|
|
static void upnp_tcp_sent_cb(void *arg); |
|
|
@ -61,7 +63,8 @@ static void upnp_tcp_recv(void *arg, char *pdata, unsigned short len); |
|
|
|
|
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
ssdp_recv_cb(void *arg, char *pusrdata, unsigned short length) { |
|
|
|
ssdp_recv_cb(void *arg, char *pusrdata, unsigned short length) { |
|
|
|
// struct espconn *con = (struct espconn *)arg;
|
|
|
|
struct espconn *con = (struct espconn *)arg; |
|
|
|
|
|
|
|
UPnPClient *client = con->reverse; |
|
|
|
|
|
|
|
|
|
|
|
os_printf("ssdp_recv_cb : %d bytes\n", length); |
|
|
|
os_printf("ssdp_recv_cb : %d bytes\n", length); |
|
|
|
|
|
|
|
|
|
|
@ -80,15 +83,16 @@ ssdp_recv_cb(void *arg, char *pusrdata, unsigned short length) { |
|
|
|
|
|
|
|
|
|
|
|
// FIXME this should be dynamically allocated
|
|
|
|
// FIXME this should be dynamically allocated
|
|
|
|
os_strncpy(location, pusrdata+j, len); |
|
|
|
os_strncpy(location, pusrdata+j, len); |
|
|
|
DBG_UPNP("len %d message %s\n", len, pusrdata+j); |
|
|
|
|
|
|
|
|
|
|
|
os_printf("ssdp_recv_cb : %s\n", pusrdata+i+2); |
|
|
|
|
|
|
|
|
|
|
|
// Trigger next query
|
|
|
|
// Trigger next query
|
|
|
|
upnp_query_igd(); |
|
|
|
upnp_query_igd(con); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
os_printf("UPnP FSM issue\n"); |
|
|
|
os_printf("UPnP FSM issue, upnp_state = %d\n", (int)upnp_state); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -96,20 +100,28 @@ ssdp_recv_cb(void *arg, char *pusrdata, unsigned short length) { |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
ssdp_sent_cb(void *arg) { |
|
|
|
ssdp_sent_cb(void *arg) { |
|
|
|
struct espconn *con = (struct espconn *)arg; |
|
|
|
struct espconn *con = (struct espconn *)arg; |
|
|
|
os_printf("ssdp_sent_cb\n"); |
|
|
|
os_printf("ssdp_sent_cb, count %d\n", counter); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
if (upnp_state == upnp_multicasted && counter < counter_max) { |
|
|
|
if (upnp_state == upnp_multicasted && counter < counter_max) { |
|
|
|
counter++; |
|
|
|
counter++; |
|
|
|
espconn_sent(con, (uint8_t*)ssdp_message, ssdp_len); |
|
|
|
espconn_sent(con, (uint8_t*)ssdp_message, ssdp_len); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
os_printf("Disabled ssdp_sent_cb\n"); |
|
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR upnp_query_igd(char *query) { |
|
|
|
// BTW, use http/1.0 to avoid responses with transfer-encoding: chunked
|
|
|
|
struct espconn *con = (struct espconn *)os_zalloc(sizeof(struct espconn)); |
|
|
|
const char *tmpl = "GET %s HTTP/1.0\r\n" |
|
|
|
|
|
|
|
"Host: %s\r\n" |
|
|
|
|
|
|
|
"Connection: close\r\n" |
|
|
|
|
|
|
|
"User-Agent: esp-link\r\n\r\n"; |
|
|
|
|
|
|
|
|
|
|
|
UPnPClient *client = (UPnPClient *)os_zalloc(sizeof(UPnPClient)); |
|
|
|
static void ICACHE_FLASH_ATTR upnp_query_igd(struct espconn *con) { |
|
|
|
client->con = con; |
|
|
|
UPnPClient *client = con->reverse; |
|
|
|
con->reverse = client; |
|
|
|
|
|
|
|
|
|
|
|
os_printf("upnp_query_igd\n"); |
|
|
|
|
|
|
|
|
|
|
|
con->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp)); |
|
|
|
con->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp)); |
|
|
|
upnp_state = upnp_found_igd; |
|
|
|
upnp_state = upnp_found_igd; |
|
|
@ -126,13 +138,21 @@ static void ICACHE_FLASH_ATTR upnp_query_igd(char *query) { |
|
|
|
else |
|
|
|
else |
|
|
|
con->proto.tcp->remote_port = 80; |
|
|
|
con->proto.tcp->remote_port = 80; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_printf("upnp_query_igd : location {%s} port %d\n", location, con->proto.tcp->remote_port); |
|
|
|
|
|
|
|
// #if 0
|
|
|
|
// Continue doing so : now the path
|
|
|
|
// Continue doing so : now the path
|
|
|
|
for (i=7; location[i] && location[i] != '/'; i++) ; |
|
|
|
char *path; |
|
|
|
|
|
|
|
for (; location[i] && location[i] != '/'; i++) ; |
|
|
|
if (location[i] == '/') { |
|
|
|
if (location[i] == '/') { |
|
|
|
client->path = location + i; |
|
|
|
path = location + i; |
|
|
|
q = i; |
|
|
|
q = i; |
|
|
|
} else |
|
|
|
} else |
|
|
|
client->path = ""; // FIX ME not sure what to do if no path
|
|
|
|
path = ""; // FIX ME not sure what to do if no path
|
|
|
|
|
|
|
|
os_printf("path {%s}\n", path); |
|
|
|
|
|
|
|
// os_printf("client ptr %08x\n", client);
|
|
|
|
|
|
|
|
client->path = path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #if 0
|
|
|
|
// Now the smallest of p and q points to end of IP address
|
|
|
|
// Now the smallest of p and q points to end of IP address
|
|
|
|
if (p != 0) { |
|
|
|
if (p != 0) { |
|
|
|
location[p] = 0; |
|
|
|
location[p] = 0; |
|
|
@ -141,11 +161,18 @@ static void ICACHE_FLASH_ATTR upnp_query_igd(char *query) { |
|
|
|
} else { // take the whole string
|
|
|
|
} else { // take the whole string
|
|
|
|
} |
|
|
|
} |
|
|
|
char *host = location + 7; |
|
|
|
char *host = location + 7; |
|
|
|
|
|
|
|
// #if 0
|
|
|
|
con->type = ESPCONN_TCP; |
|
|
|
con->type = ESPCONN_TCP; |
|
|
|
con->state = ESPCONN_NONE; |
|
|
|
con->state = ESPCONN_NONE; |
|
|
|
con->proto.tcp->local_port = espconn_port(); |
|
|
|
con->proto.tcp->local_port = espconn_port(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* strcpy(location, "http://192.168.1.1:8000/o8ee3npj36j/IGD/upnp/IGD.xml"); |
|
|
|
|
|
|
|
* char *query = (char *)os_malloc(strlen(tmpl) + location_size); |
|
|
|
|
|
|
|
* os_sprintf(query, tmpl, "/o8ee3npj36j/IGD/upnp/IGD.xml", "http://192.168.1.1:8000"); |
|
|
|
|
|
|
|
* upnp_query_igd(query); |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
client->data = query; |
|
|
|
client->data = query; |
|
|
|
client->data_len = strlen(query); |
|
|
|
client->data_len = strlen(query); |
|
|
|
|
|
|
|
|
|
|
@ -155,18 +182,20 @@ static void ICACHE_FLASH_ATTR upnp_query_igd(char *query) { |
|
|
|
|
|
|
|
|
|
|
|
if (UTILS_StrToIP(host, &con->proto.tcp->remote_ip)) { |
|
|
|
if (UTILS_StrToIP(host, &con->proto.tcp->remote_ip)) { |
|
|
|
DBG_UPNP("UPnP: Connect to ip %s:%d\n", host, con->proto.tcp->remote_port); |
|
|
|
DBG_UPNP("UPnP: Connect to ip %s:%d\n", host, con->proto.tcp->remote_port); |
|
|
|
|
|
|
|
client->ip = *(ip_addr_t *)&con->proto.tcp->remote_ip[0]; |
|
|
|
espconn_connect(con); |
|
|
|
espconn_connect(con); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
DBG_UPNP("UPnP: Connect to host %s:%d\n", host, con->proto.tcp->remote_port); |
|
|
|
DBG_UPNP("UPnP: Connect to host %s:%d\n", host, con->proto.tcp->remote_port); |
|
|
|
espconn_gethostbyname(con, host, (ip_addr_t *)&con->proto.tcp->remote_ip[0], upnp_dns_found); |
|
|
|
espconn_gethostbyname(con, host, (ip_addr_t *)&con->proto.tcp->remote_ip[0], upnp_dns_found); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// #endif
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
upnp_tcp_sent_cb(void *arg) { |
|
|
|
upnp_tcp_sent_cb(void *arg) { |
|
|
|
// struct espconn *pCon = (struct espconn *)arg;
|
|
|
|
// struct espconn *pCon = (struct espconn *)arg;
|
|
|
|
|
|
|
|
|
|
|
|
DBG_UPNP("UPNP: tcp_sent\n"); |
|
|
|
os_printf("upnp_tcp_sent_cb (disabled)\n"); |
|
|
|
#if 0 |
|
|
|
#if 0 |
|
|
|
if (client->data_sent != client->data_len) { |
|
|
|
if (client->data_sent != client->data_len) { |
|
|
|
// we only sent part of the buffer, send the rest
|
|
|
|
// we only sent part of the buffer, send the rest
|
|
|
@ -183,6 +212,7 @@ upnp_tcp_sent_cb(void *arg) { |
|
|
|
|
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
upnp_tcp_discon_cb(void *arg) { |
|
|
|
upnp_tcp_discon_cb(void *arg) { |
|
|
|
|
|
|
|
os_printf("upnp_tcp_discon_cb (empty)\n"); |
|
|
|
// struct espconn *pespconn = (struct espconn *)arg;
|
|
|
|
// struct espconn *pespconn = (struct espconn *)arg;
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
#if 0 |
|
|
@ -194,6 +224,7 @@ upnp_tcp_discon_cb(void *arg) { |
|
|
|
|
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
upnp_tcp_recon_cb(void *arg, sint8 errType) { |
|
|
|
upnp_tcp_recon_cb(void *arg, sint8 errType) { |
|
|
|
|
|
|
|
os_printf("upnp_tcp_recon_cb (empty)\n"); |
|
|
|
// struct espconn *pCon = (struct espconn *)arg;
|
|
|
|
// struct espconn *pCon = (struct espconn *)arg;
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
#if 0 |
|
|
@ -207,9 +238,10 @@ upnp_tcp_recon_cb(void *arg, sint8 errType) { |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
upnp_tcp_connect_cb(void *arg) { |
|
|
|
upnp_tcp_connect_cb(void *arg) { |
|
|
|
struct espconn *con = (struct espconn *)arg; |
|
|
|
struct espconn *con = (struct espconn *)arg; |
|
|
|
UPnPClient* client = (UPnPClient *)con->reverse; |
|
|
|
UPnPClient *client = (UPnPClient *)con->reverse; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_printf("upnp_tcp_connect_cb\n"); |
|
|
|
|
|
|
|
|
|
|
|
DBG_UPNP("UPnP : connected\n"); |
|
|
|
|
|
|
|
espconn_regist_disconcb(con, upnp_tcp_discon_cb); |
|
|
|
espconn_regist_disconcb(con, upnp_tcp_discon_cb); |
|
|
|
espconn_regist_recvcb(con, upnp_tcp_recv); |
|
|
|
espconn_regist_recvcb(con, upnp_tcp_recv); |
|
|
|
espconn_regist_sentcb(con, upnp_tcp_sent_cb); |
|
|
|
espconn_regist_sentcb(con, upnp_tcp_sent_cb); |
|
|
@ -225,7 +257,7 @@ upnp_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) { |
|
|
|
struct espconn *con = (struct espconn *)arg; |
|
|
|
struct espconn *con = (struct espconn *)arg; |
|
|
|
UPnPClient* client = (UPnPClient *)con->reverse; |
|
|
|
UPnPClient* client = (UPnPClient *)con->reverse; |
|
|
|
|
|
|
|
|
|
|
|
if(ipaddr == NULL) { |
|
|
|
if (ipaddr == NULL) { |
|
|
|
os_printf("REST DNS: Got no ip, try to reconnect\n"); |
|
|
|
os_printf("REST DNS: Got no ip, try to reconnect\n"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -234,7 +266,7 @@ upnp_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) { |
|
|
|
*((uint8 *) &ipaddr->addr + 1), |
|
|
|
*((uint8 *) &ipaddr->addr + 1), |
|
|
|
*((uint8 *) &ipaddr->addr + 2), |
|
|
|
*((uint8 *) &ipaddr->addr + 2), |
|
|
|
*((uint8 *) &ipaddr->addr + 3)); |
|
|
|
*((uint8 *) &ipaddr->addr + 3)); |
|
|
|
if(client->ip.addr == 0 && ipaddr->addr != 0) { |
|
|
|
if (client && client->ip.addr == 0 && ipaddr->addr != 0) { |
|
|
|
os_memcpy(client->con->proto.tcp->remote_ip, &ipaddr->addr, 4); |
|
|
|
os_memcpy(client->con->proto.tcp->remote_ip, &ipaddr->addr, 4); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef CLIENT_SSL_ENABLE |
|
|
|
#ifdef CLIENT_SSL_ENABLE |
|
|
@ -259,7 +291,7 @@ upnp_tcp_recv(void *arg, char *pdata, unsigned short len) { |
|
|
|
|
|
|
|
|
|
|
|
int inservice = 0, get_this = -1; |
|
|
|
int inservice = 0, get_this = -1; |
|
|
|
|
|
|
|
|
|
|
|
// os_printf("UPnP TCP Recv len %d\n", len);
|
|
|
|
os_printf("upnp_tcp_recv len %d\n", len); |
|
|
|
|
|
|
|
|
|
|
|
switch (upnp_state) { |
|
|
|
switch (upnp_state) { |
|
|
|
case upnp_found_igd: |
|
|
|
case upnp_found_igd: |
|
|
@ -296,6 +328,7 @@ upnp_tcp_recv(void *arg, char *pdata, unsigned short len) { |
|
|
|
os_printf("UPnP <removing port> TCP Recv len %d, %s\n", len, pdata); |
|
|
|
os_printf("UPnP <removing port> TCP Recv len %d, %s\n", len, pdata); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
|
|
|
|
os_printf("upnp_state (not treated) %d\n", (int)upnp_state); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -309,13 +342,28 @@ upnp_tcp_recv(void *arg, char *pdata, unsigned short len) { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void ICACHE_FLASH_ATTR |
|
|
|
void ICACHE_FLASH_ATTR |
|
|
|
cmdUPnPScan(CmdPacket *cmd) { |
|
|
|
cmdUPnPScan(CmdPacket *cmd) { |
|
|
|
upnp_state = upnp_none; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_printf("cmdUPnPScan()\n"); |
|
|
|
os_printf("cmdUPnPScan()\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (upnp_state == upnp_ready) { |
|
|
|
|
|
|
|
// Return the IP address of the gateway, this indicates success.
|
|
|
|
|
|
|
|
if (the_client == 0) |
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, 0, 0); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, (uint32_t)the_client->ip.addr, 0); |
|
|
|
|
|
|
|
cmdResponseEnd(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upnp_state = upnp_none; |
|
|
|
|
|
|
|
|
|
|
|
struct espconn *con = (struct espconn *)os_zalloc(sizeof(struct espconn)); |
|
|
|
struct espconn *con = (struct espconn *)os_zalloc(sizeof(struct espconn)); |
|
|
|
if (con == NULL) { |
|
|
|
if (con == NULL) { |
|
|
|
DBG_UPNP("SOCKET : Setup failed to alloc memory for client_pCon\n"); |
|
|
|
DBG_UPNP("SOCKET : Setup failed to alloc memory for client_pCon\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return 0, this means failure
|
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, 0, 0); |
|
|
|
|
|
|
|
cmdResponseEnd(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
counter = 0; |
|
|
|
counter = 0; |
|
|
@ -324,14 +372,23 @@ cmdUPnPScan(CmdPacket *cmd) { |
|
|
|
con->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp)); |
|
|
|
con->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp)); |
|
|
|
if (con->proto.udp == NULL) { |
|
|
|
if (con->proto.udp == NULL) { |
|
|
|
DBG_UPNP("SOCKET : Setup failed to alloc memory for client->pCon->proto.udp\n"); |
|
|
|
DBG_UPNP("SOCKET : Setup failed to alloc memory for client->pCon->proto.udp\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return 0, this means failure
|
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, 0, 0); |
|
|
|
|
|
|
|
cmdResponseEnd(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPnPClient *client = (UPnPClient *)os_zalloc(sizeof(UPnPClient)); |
|
|
|
|
|
|
|
client->con = con; |
|
|
|
|
|
|
|
con->reverse = client; |
|
|
|
|
|
|
|
the_client = client; |
|
|
|
|
|
|
|
|
|
|
|
con->state = ESPCONN_NONE; |
|
|
|
con->state = ESPCONN_NONE; |
|
|
|
|
|
|
|
|
|
|
|
con->proto.udp->remote_port = upnp_server_port; |
|
|
|
con->proto.udp->remote_port = upnp_server_port; |
|
|
|
con->proto.udp->local_port = espconn_port(); |
|
|
|
con->proto.udp->local_port = espconn_port(); |
|
|
|
con->reverse = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
espconn_regist_sentcb(con, ssdp_sent_cb); |
|
|
|
espconn_regist_sentcb(con, ssdp_sent_cb); |
|
|
|
espconn_regist_recvcb(con, ssdp_recv_cb); |
|
|
|
espconn_regist_recvcb(con, ssdp_recv_cb); |
|
|
@ -342,13 +399,46 @@ cmdUPnPScan(CmdPacket *cmd) { |
|
|
|
espconn_create(con); |
|
|
|
espconn_create(con); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
DBG_UPNP("SOCKET : failed to copy remote_ip to &con->proto.udp->remote_ip\n"); |
|
|
|
DBG_UPNP("SOCKET : failed to copy remote_ip to &con->proto.udp->remote_ip\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return 0, this means failure
|
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, 0, 0); |
|
|
|
|
|
|
|
cmdResponseEnd(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
// Return 0, this means failure
|
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, 0, 0); // Danny
|
|
|
|
|
|
|
|
cmdResponseEnd(); // Danny
|
|
|
|
|
|
|
|
return; // Danny
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_printf("Determining strlen(ssdp_message)\n"); |
|
|
|
ssdp_len = strlen(ssdp_message); |
|
|
|
ssdp_len = strlen(ssdp_message); |
|
|
|
|
|
|
|
os_printf("strlen(ssdp_message) = %d\n", ssdp_len); |
|
|
|
espconn_sent(con, (uint8_t*)ssdp_message, ssdp_len); |
|
|
|
espconn_sent(con, (uint8_t*)ssdp_message, ssdp_len); |
|
|
|
DBG_UPNP("SOCKET : sending %d bytes\n", ssdp_len); |
|
|
|
os_printf("espconn_sent() done\n"); |
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
// Return 0, this means failure
|
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, 0, 0); // Danny
|
|
|
|
|
|
|
|
cmdResponseEnd(); // Danny
|
|
|
|
|
|
|
|
return; // Danny
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
// DBG_UPNP("SOCKET : sending %d bytes\n", ssdp_len);
|
|
|
|
upnp_state = upnp_multicasted; |
|
|
|
upnp_state = upnp_multicasted; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
// Return 0, this means failure
|
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, 0, 0); // Danny
|
|
|
|
|
|
|
|
cmdResponseEnd(); // Danny
|
|
|
|
|
|
|
|
return; // Danny
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
// Not ready yet --> indicate failure
|
|
|
|
|
|
|
|
cmdResponseStart(CMD_RESP_V, 0, 0); |
|
|
|
|
|
|
|
cmdResponseEnd(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_printf("Return at end of cmdUPnPScan(), upnp_state = upnp_multicasted\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// BTW, use http/1.0 to avoid responses with transfer-encoding: chunked
|
|
|
|
// BTW, use http/1.0 to avoid responses with transfer-encoding: chunked
|
|
|
@ -359,12 +449,19 @@ const char *tmpl = "GET %s HTTP/1.0\r\n" |
|
|
|
|
|
|
|
|
|
|
|
void ICACHE_FLASH_ATTR |
|
|
|
void ICACHE_FLASH_ATTR |
|
|
|
cmdUPnPAddPort(CmdPacket *cmd) { |
|
|
|
cmdUPnPAddPort(CmdPacket *cmd) { |
|
|
|
|
|
|
|
#if 0 |
|
|
|
strcpy(location, "http://192.168.1.1:8000/o8ee3npj36j/IGD/upnp/IGD.xml"); |
|
|
|
strcpy(location, "http://192.168.1.1:8000/o8ee3npj36j/IGD/upnp/IGD.xml"); |
|
|
|
char *query = (char *)os_malloc(strlen(tmpl) + location_size); |
|
|
|
char *query = (char *)os_malloc(strlen(tmpl) + location_size); |
|
|
|
os_sprintf(query, tmpl, "/o8ee3npj36j/IGD/upnp/IGD.xml", "http://192.168.1.1:8000"); |
|
|
|
os_sprintf(query, tmpl, "/o8ee3npj36j/IGD/upnp/IGD.xml", "http://192.168.1.1:8000"); |
|
|
|
upnp_query_igd(query); |
|
|
|
upnp_query_igd(query); |
|
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ICACHE_FLASH_ATTR |
|
|
|
void ICACHE_FLASH_ATTR |
|
|
|
cmdUPnPRemovePort(CmdPacket *cmd) { |
|
|
|
cmdUPnPRemovePort(CmdPacket *cmd) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ICACHE_FLASH_ATTR |
|
|
|
|
|
|
|
cmdUPnPBegin(CmdPacket *cmd) { |
|
|
|
|
|
|
|
upnp_state = upnp_none; |
|
|
|
|
|
|
|
} |
|
|
|