MeterLogger
Data Structures | Macros | Typedefs | Enumerations | Functions
espconn.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _esp_tcp
 
struct  _esp_udp
 
struct  _remot_info
 
struct  espconn
 
struct  espconn_packet
 
struct  mdns_info
 

Macros

#define ESPCONN_OK   0 /* No error, everything OK. */
 
#define ESPCONN_MEM   -1 /* Out of memory error. */
 
#define ESPCONN_TIMEOUT   -3 /* Timeout. */
 
#define ESPCONN_RTE   -4 /* Routing problem. */
 
#define ESPCONN_INPROGRESS   -5 /* Operation in progress */
 
#define ESPCONN_MAXNUM   -7 /* Total number exceeds the set maximum*/
 
#define ESPCONN_ABRT   -8 /* Connection aborted. */
 
#define ESPCONN_RST   -9 /* Connection reset. */
 
#define ESPCONN_CLSD   -10 /* Connection closed. */
 
#define ESPCONN_CONN   -11 /* Not connected. */
 
#define ESPCONN_ARG   -12 /* Illegal argument. */
 
#define ESPCONN_IF   -14 /* UDP send error */
 
#define ESPCONN_ISCONN   -15 /* Already connected. */
 
#define ESPCONN_HANDSHAKE   -28 /* ssl handshake failed */
 
#define ESPCONN_SSL_INVALID_DATA   -61 /* ssl application invalid */
 

Typedefs

typedef sint8 err_t
 
typedef void * espconn_handle
 
typedef void(* espconn_connect_callback) (void *arg)
 
typedef void(* espconn_reconnect_callback) (void *arg, sint8 err)
 
typedef struct _esp_tcp esp_tcp
 
typedef struct _esp_udp esp_udp
 
typedef struct _remot_info remot_info
 
typedef void(* espconn_recv_callback) (void *arg, char *pdata, unsigned short len)
 
typedef void(* espconn_sent_callback) (void *arg)
 
typedef void(* dns_found_callback) (const char *name, ip_addr_t *ipaddr, void *callback_arg)
 

Enumerations

enum  espconn_type {
  ESPCONN_INVALID = 0, ESPCONN_TCP = 0x10, ESPCONN_UDP = 0x20, ESPCONN_INVALID = 0,
  ESPCONN_TCP = 0x10, ESPCONN_UDP = 0x20
}
 
enum  espconn_state {
  ESPCONN_NONE, ESPCONN_WAIT, ESPCONN_LISTEN, ESPCONN_CONNECT,
  ESPCONN_WRITE, ESPCONN_READ, ESPCONN_CLOSE, ESPCONN_NONE,
  ESPCONN_WAIT, ESPCONN_LISTEN, ESPCONN_CONNECT, ESPCONN_WRITE,
  ESPCONN_READ, ESPCONN_CLOSE
}
 
enum  espconn_option {
  ESPCONN_START = 0x00, ESPCONN_REUSEADDR = 0x01, ESPCONN_NODELAY = 0x02, ESPCONN_COPY = 0x04,
  ESPCONN_KEEPALIVE = 0x08, ESPCONN_END, ESPCONN_START = 0x00, ESPCONN_REUSEADDR = 0x01,
  ESPCONN_NODELAY = 0x02, ESPCONN_COPY = 0x04, ESPCONN_KEEPALIVE = 0x08, ESPCONN_END
}
 
enum  espconn_level {
  ESPCONN_KEEPIDLE, ESPCONN_KEEPINTVL, ESPCONN_KEEPCNT, ESPCONN_KEEPIDLE,
  ESPCONN_KEEPINTVL, ESPCONN_KEEPCNT
}
 
enum  {
  ESPCONN_IDLE = 0, ESPCONN_CLIENT, ESPCONN_SERVER, ESPCONN_BOTH,
  ESPCONN_MAX
}
 

Functions

sint8 espconn_connect (struct espconn *espconn)
 
sint8 espconn_disconnect (struct espconn *espconn)
 
sint8 espconn_delete (struct espconn *espconn)
 
sint8 espconn_accept (struct espconn *espconn)
 
sint8 espconn_create (struct espconn *espconn)
 
uint8 espconn_tcp_get_max_con (void)
 
sint8 espconn_tcp_set_max_con (uint8 num)
 
sint8 espconn_tcp_get_max_con_allow (struct espconn *espconn)
 
sint8 espconn_tcp_set_max_con_allow (struct espconn *espconn, uint8 num)
 
sint8 espconn_regist_time (struct espconn *espconn, uint32 interval, uint8 type_flag)
 
sint8 espconn_get_connection_info (struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags)
 
sint8 espconn_get_packet_info (struct espconn *espconn, struct espconn_packet *infoarg)
 
sint8 espconn_regist_sentcb (struct espconn *espconn, espconn_sent_callback sent_cb)
 
sint8 espconn_regist_write_finish (struct espconn *espconn, espconn_connect_callback write_finish_fn)
 
sint8 espconn_send (struct espconn *espconn, uint8 *psent, uint16 length)
 
sint8 espconn_sent (struct espconn *espconn, uint8 *psent, uint16 length)
 
sint16 espconn_sendto (struct espconn *espconn, uint8 *psent, uint16 length)
 
sint8 espconn_regist_connectcb (struct espconn *espconn, espconn_connect_callback connect_cb)
 
sint8 espconn_regist_recvcb (struct espconn *espconn, espconn_recv_callback recv_cb)
 
sint8 espconn_regist_reconcb (struct espconn *espconn, espconn_reconnect_callback recon_cb)
 
sint8 espconn_regist_disconcb (struct espconn *espconn, espconn_connect_callback discon_cb)
 
uint32 espconn_port (void)
 
sint8 espconn_set_opt (struct espconn *espconn, uint8 opt)
 
sint8 espconn_clear_opt (struct espconn *espconn, uint8 opt)
 
sint8 espconn_set_keepalive (struct espconn *espconn, uint8 level, void *optarg)
 
sint8 espconn_get_keepalive (struct espconn *espconn, uint8 level, void *optarg)
 
err_t espconn_gethostbyname (struct espconn *pespconn, const char *hostname, ip_addr_t *addr, dns_found_callback found)
 
sint8 espconn_abort (struct espconn *espconn)
 
sint8 espconn_secure_connect (struct espconn *espconn)
 
sint8 espconn_secure_disconnect (struct espconn *espconn)
 
sint8 espconn_secure_send (struct espconn *espconn, uint8 *psent, uint16 length)
 
sint8 espconn_secure_sent (struct espconn *espconn, uint8 *psent, uint16 length)
 
bool espconn_secure_set_size (uint8 level, uint16 size)
 
sint16 espconn_secure_get_size (uint8 level)
 
bool espconn_secure_ca_enable (uint8 level, uint32 flash_sector)
 
bool espconn_secure_ca_disable (uint8 level)
 
bool espconn_secure_cert_req_enable (uint8 level, uint32 flash_sector)
 
bool espconn_secure_cert_req_disable (uint8 level)
 
bool espconn_secure_set_default_certificate (const uint8 *certificate, uint16 length)
 
bool espconn_secure_set_default_private_key (const uint8 *private_key, uint16 length)
 
sint8 espconn_secure_accept (struct espconn *espconn)
 
sint8 espconn_secure_delete (struct espconn *espconn)
 
sint8 espconn_igmp_join (ip_addr_t *host_ip, ip_addr_t *multicast_ip)
 
sint8 espconn_igmp_leave (ip_addr_t *host_ip, ip_addr_t *multicast_ip)
 
sint8 espconn_recv_hold (struct espconn *pespconn)
 
sint8 espconn_recv_unhold (struct espconn *pespconn)
 
void espconn_mdns_init (struct mdns_info *info)
 
void espconn_mdns_close (void)
 
void espconn_mdns_server_register (void)
 
void espconn_mdns_server_unregister (void)
 
char * espconn_mdns_get_servername (void)
 
void espconn_mdns_set_servername (const char *name)
 
void espconn_mdns_set_hostname (char *name)
 
char * espconn_mdns_get_hostname (void)
 
void espconn_mdns_disable (void)
 
void espconn_mdns_enable (void)
 
void espconn_dns_setserver (char numdns, ip_addr_t *dnsserver)
 

Macro Definition Documentation

◆ ESPCONN_ABRT

#define ESPCONN_ABRT   -8 /* Connection aborted. */

Definition at line 43 of file espconn.h.

◆ ESPCONN_ARG

#define ESPCONN_ARG   -12 /* Illegal argument. */

Definition at line 48 of file espconn.h.

◆ ESPCONN_CLSD

#define ESPCONN_CLSD   -10 /* Connection closed. */

Definition at line 45 of file espconn.h.

◆ ESPCONN_CONN

#define ESPCONN_CONN   -11 /* Not connected. */

Definition at line 46 of file espconn.h.

◆ ESPCONN_HANDSHAKE

#define ESPCONN_HANDSHAKE   -28 /* ssl handshake failed */

Definition at line 52 of file espconn.h.

◆ ESPCONN_IF

#define ESPCONN_IF   -14 /* UDP send error */

Definition at line 49 of file espconn.h.

◆ ESPCONN_INPROGRESS

#define ESPCONN_INPROGRESS   -5 /* Operation in progress */

Definition at line 40 of file espconn.h.

◆ ESPCONN_ISCONN

#define ESPCONN_ISCONN   -15 /* Already connected. */

Definition at line 50 of file espconn.h.

◆ ESPCONN_MAXNUM

#define ESPCONN_MAXNUM   -7 /* Total number exceeds the set maximum*/

Definition at line 41 of file espconn.h.

◆ ESPCONN_MEM

#define ESPCONN_MEM   -1 /* Out of memory error. */

Definition at line 37 of file espconn.h.

◆ ESPCONN_OK

#define ESPCONN_OK   0 /* No error, everything OK. */

Definition at line 36 of file espconn.h.

◆ ESPCONN_RST

#define ESPCONN_RST   -9 /* Connection reset. */

Definition at line 44 of file espconn.h.

◆ ESPCONN_RTE

#define ESPCONN_RTE   -4 /* Routing problem. */

Definition at line 39 of file espconn.h.

◆ ESPCONN_SSL_INVALID_DATA

#define ESPCONN_SSL_INVALID_DATA   -61 /* ssl application invalid */

Definition at line 53 of file espconn.h.

◆ ESPCONN_TIMEOUT

#define ESPCONN_TIMEOUT   -3 /* Timeout. */

Definition at line 38 of file espconn.h.

Typedef Documentation

◆ dns_found_callback

typedef void(* dns_found_callback) (const char *name, ip_addr_t *ipaddr, void *callback_arg)

Definition at line 437 of file espconn.h.

◆ err_t

typedef sint8 err_t

Definition at line 28 of file espconn.h.

◆ esp_tcp

typedef struct _esp_tcp esp_tcp

◆ esp_udp

typedef struct _esp_udp esp_udp

◆ espconn_connect_callback

typedef void(* espconn_connect_callback) (void *arg)

Definition at line 31 of file espconn.h.

◆ espconn_handle

typedef void* espconn_handle

Definition at line 30 of file espconn.h.

◆ espconn_reconnect_callback

typedef void(* espconn_reconnect_callback) (void *arg, sint8 err)

Definition at line 32 of file espconn.h.

◆ espconn_recv_callback

typedef void(* espconn_recv_callback) (void *arg, char *pdata, unsigned short len)

A callback prototype to inform about events for a espconn

Definition at line 100 of file espconn.h.

◆ espconn_sent_callback

typedef void(* espconn_sent_callback) (void *arg)

Definition at line 101 of file espconn.h.

◆ remot_info

typedef struct _remot_info remot_info

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ESPCONN_IDLE 
ESPCONN_CLIENT 
ESPCONN_SERVER 
ESPCONN_BOTH 
ESPCONN_MAX 

Definition at line 135 of file espconn.h.

◆ espconn_level

Enumerator
ESPCONN_KEEPIDLE 
ESPCONN_KEEPINTVL 
ESPCONN_KEEPCNT 
ESPCONN_KEEPIDLE 
ESPCONN_KEEPINTVL 
ESPCONN_KEEPCNT 

Definition at line 129 of file espconn.h.

◆ espconn_option

Enumerator
ESPCONN_START 
ESPCONN_REUSEADDR 
ESPCONN_NODELAY 
ESPCONN_COPY 
ESPCONN_KEEPALIVE 
ESPCONN_END 
ESPCONN_START 
ESPCONN_REUSEADDR 
ESPCONN_NODELAY 
ESPCONN_COPY 
ESPCONN_KEEPALIVE 
ESPCONN_END 

Definition at line 120 of file espconn.h.

120  {
121  ESPCONN_START = 0x00,
122  ESPCONN_REUSEADDR = 0x01,
123  ESPCONN_NODELAY = 0x02,
124  ESPCONN_COPY = 0x04,
125  ESPCONN_KEEPALIVE = 0x08,
127 };

◆ espconn_state

Current state of the espconn. Non-TCP espconn are always in state ESPCONN_NONE!

Enumerator
ESPCONN_NONE 
ESPCONN_WAIT 
ESPCONN_LISTEN 
ESPCONN_CONNECT 
ESPCONN_WRITE 
ESPCONN_READ 
ESPCONN_CLOSE 
ESPCONN_NONE 
ESPCONN_WAIT 
ESPCONN_LISTEN 
ESPCONN_CONNECT 
ESPCONN_WRITE 
ESPCONN_READ 
ESPCONN_CLOSE 

Definition at line 65 of file espconn.h.

◆ espconn_type

Protocol family and type of the espconn

Enumerator
ESPCONN_INVALID 
ESPCONN_TCP 
ESPCONN_UDP 
ESPCONN_INVALID 
ESPCONN_TCP 
ESPCONN_UDP 

Definition at line 56 of file espconn.h.

56  {
57  ESPCONN_INVALID = 0,
58  /* ESPCONN_TCP Group */
59  ESPCONN_TCP = 0x10,
60  /* ESPCONN_UDP Group */
61  ESPCONN_UDP = 0x20,
62 };

Function Documentation

◆ espconn_abort()

sint8 espconn_abort ( struct espconn espconn)

Definition at line 972 of file espconn.c.

References ESPCONN_ARG, ESPCONN_CLOSE, espconn_find_connection(), ESPCONN_INPROGRESS, ESPCONN_OK, ESPCONN_TCP, espconn_tcp_disconnect(), ICACHE_FLASH_ATTR, NULL, and espconn::state.

Referenced by mqtt_tcpclient_delete().

973 {
974  espconn_msg *pnode = NULL;
975  bool value = false;
976 
977  if (espconn == NULL) {
978  return ESPCONN_ARG;;
979  } else if (espconn ->type != ESPCONN_TCP)
980  return ESPCONN_ARG;
981 
982  /*Find the node depend on the espconn message*/
983  value = espconn_find_connection(espconn, &pnode);
984 
985  if (value){
986  /*protect for redisconnection*/
987  if (espconn->state == ESPCONN_CLOSE)
988  return ESPCONN_INPROGRESS;
989  espconn_tcp_disconnect(pnode,1); //1 force, 0 normal
990  return ESPCONN_OK;
991  } else
992  return ESPCONN_ARG;
993 }
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
void espconn_tcp_disconnect(espconn_msg *pdiscon, u8 type)
Definition: espconn_tcp.c:498
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_state state
Definition: espconn.h:103
#define ESPCONN_INPROGRESS
Definition: espconn.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ espconn_accept()

sint8 espconn_accept ( struct espconn espconn)

Definition at line 875 of file espconn.c.

References ESPCONN_ARG, ESPCONN_ISCONN, ESPCONN_OK, ESPCONN_TCP, espconn_tcp_server(), _esp_tcp::local_port, NULL, _espconn_msg::pespconn, plist, _espconn_msg::pnext, espconn::proto, espconn::tcp, and espconn::type.

876 {
877  sint8 value = ESPCONN_OK;
879 
880  if (espconn == NULL) {
881  return ESPCONN_ARG;
882  } else if (espconn ->type != ESPCONN_TCP)
883  return ESPCONN_ARG;
884 
885  /*check the active node information whether is the same as the entity or not*/
886  for (plist = plink_active; plist != NULL; plist = plist->pnext){
887  if (plist->pespconn && plist->pespconn->type == ESPCONN_TCP){
888  if (espconn->proto.tcp->local_port == plist->pespconn->proto.tcp->local_port){
889  return ESPCONN_ISCONN;
890  }
891  }
892  }
893  value = espconn_tcp_server(espconn);
894 
895  return value;
896 }
esp_tcp * tcp
Definition: espconn.h:105
struct _espconn_msg * pnext
Definition: espconn.h:175
#define NULL
Definition: def.h:47
int local_port
Definition: espconn.h:72
#define ESPCONN_ISCONN
Definition: espconn.h:34
sint8 espconn_tcp_server(struct espconn *espconn)
Definition: espconn_tcp.c:1281
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_msg * plink_active
Definition: espconn.c:32
union espconn::@1 proto
enum espconn_type type
Definition: espconn.h:101
signed char sint8
Definition: c_types.h:47
static list_node * plist
Definition: dhcpserver.c:34
struct espconn * pespconn
Definition: espconn.h:169
Here is the call graph for this function:

◆ espconn_clear_opt()

sint8 espconn_clear_opt ( struct espconn espconn,
uint8  opt 
)

Definition at line 1092 of file espconn.c.

References ESPCONN_ARG, espconn_delay_enabled, espconn_find_connection(), espconn_keepalive_disable, espconn_keepalive_enabled, ESPCONN_OK, _comon_pkt::espconn_opt, ESPCONN_TCP, NULL, _comon_pkt::pcb, _espconn_msg::pcommon, and espconn::type.

1093 {
1094  espconn_msg *pnode = NULL;
1095  struct tcp_pcb *tpcb;
1096  bool value = false;
1097 
1098  if (espconn == NULL) {
1099  return ESPCONN_ARG;;
1100  } else if (espconn->type != ESPCONN_TCP)
1101  return ESPCONN_ARG;
1102 
1103  /*Find the node depend on the espconn message*/
1104  value = espconn_find_connection(espconn, &pnode);
1105  if (value) {
1106  pnode->pcommon.espconn_opt &= ~opt;
1107  tpcb = pnode->pcommon.pcb;
1108  if (espconn_keepalive_enabled(pnode))
1110 
1111  if (espconn_delay_enabled(pnode))
1112  tcp_nagle_enable(tpcb);
1113 
1114  return ESPCONN_OK;
1115  } else
1116  return ESPCONN_ARG;
1117 }
#define espconn_keepalive_enabled(espconn)
Definition: espconn.h:201
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
#define ESPCONN_OK
Definition: espconn.h:20
#define espconn_delay_enabled(espconn)
Definition: espconn.h:196
comon_pkt pcommon
Definition: espconn.h:170
#define ESPCONN_ARG
Definition: espconn.h:32
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_type type
Definition: espconn.h:101
#define espconn_keepalive_disable(pcb)
Definition: espconn_tcp.h:14
enum espconn_option espconn_opt
Definition: espconn.h:165
Here is the call graph for this function:

◆ espconn_connect()

sint8 espconn_connect ( struct espconn espconn)

Definition at line 260 of file espconn.c.

References ip_addr::addr, AP_NETIF, ESPCONN_AP, ESPCONN_AP_STA, ESPCONN_ARG, espconn_get_acticve_num(), ESPCONN_ISCONN, ESPCONN_OK, espconn_printf, ESPCONN_RTE, ESPCONN_STA, ESPCONN_TCP, espconn_tcp_client(), espconn_tcp_get_max_con(), ICACHE_FLASH_ATTR, ip_info::ip, IP4_ADDR, _esp_tcp::local_port, NULL, _espconn_msg::pespconn, plist, _espconn_msg::pnext, espconn::proto, _esp_tcp::remote_ip, STA_NETIF, STATION_GOT_IP, STATION_IDLE, espconn::tcp, espconn::type, wifi_get_ip_info(), wifi_get_opmode(), and wifi_station_get_connect_status().

261 {
262  struct ip_addr ipaddr;
263  struct ip_info ipinfo;
264  uint8 connect_status = 0;
265  sint8 value = ESPCONN_OK;
267  remot_info *pinfo = NULL;
268 
269  if (espconn == NULL) {
270  return ESPCONN_ARG;
271  } else if (espconn ->type != ESPCONN_TCP)
272  return ESPCONN_ARG;
273 
274  /*Check the active node count whether is the limit or not*/
276  return ESPCONN_ISCONN;
277 
278  /*Check the IP address whether is zero or not in different mode*/
279  if (wifi_get_opmode() == ESPCONN_STA){
280  wifi_get_ip_info(STA_NETIF,&ipinfo);
281  if (ipinfo.ip.addr == 0){
282  return ESPCONN_RTE;
283  }
284  } else if(wifi_get_opmode() == ESPCONN_AP){
285  wifi_get_ip_info(AP_NETIF,&ipinfo);
286  if (ipinfo.ip.addr == 0){
287  return ESPCONN_RTE;
288  }
289  } else if(wifi_get_opmode() == ESPCONN_AP_STA){
290  IP4_ADDR(&ipaddr, espconn->proto.tcp->remote_ip[0],
291  espconn->proto.tcp->remote_ip[1],
292  espconn->proto.tcp->remote_ip[2],
293  espconn->proto.tcp->remote_ip[3]);
294  ipaddr.addr <<= 8;
295  wifi_get_ip_info(AP_NETIF,&ipinfo);
296  ipinfo.ip.addr <<= 8;
297  espconn_printf("softap_addr = %x, remote_addr = %x\n", ipinfo.ip.addr, ipaddr.addr);
298 
299  if (ipaddr.addr != ipinfo.ip.addr){
300  connect_status = wifi_station_get_connect_status();
301  if (connect_status == STATION_GOT_IP){
302  wifi_get_ip_info(STA_NETIF,&ipinfo);
303  if (ipinfo.ip.addr == 0)
304  return ESPCONN_RTE;
305  } else if (connect_status == STATION_IDLE){
306  return ESPCONN_RTE;
307  } else {
308  return connect_status;
309  }
310  }
311  }
312 
313  /*check the active node information whether is the same as the entity or not*/
314  for (plist = plink_active; plist != NULL; plist = plist->pnext){
315  if (plist->pespconn && plist->pespconn->type == ESPCONN_TCP){
316  if (espconn->proto.tcp->local_port == plist->pespconn->proto.tcp->local_port){
317  return ESPCONN_ISCONN;
318  }
319  }
320  }
321 
322  value = espconn_tcp_client(espconn);
323 
324  return value;
325 }
uint8 ICACHE_FLASH_ATTR espconn_tcp_get_max_con(void)
Definition: espconn.c:528
esp_tcp * tcp
Definition: espconn.h:105
struct _espconn_msg * pnext
Definition: espconn.h:175
#define ESPCONN_AP_STA
Definition: espconn.h:45
#define STA_NETIF
Definition: espconn.h:47
#define NULL
Definition: def.h:47
int local_port
Definition: espconn.h:72
#define ESPCONN_ISCONN
Definition: espconn.h:34
#define ESPCONN_OK
Definition: espconn.h:20
uint8 remote_ip[4]
Definition: espconn.h:74
bool wifi_get_ip_info(uint8 if_index, struct ip_info *info)
uint8 wifi_station_get_connect_status(void)
uint8 wifi_get_opmode(void)
#define ESPCONN_RTE
Definition: espconn.h:23
#define ESPCONN_ARG
Definition: espconn.h:32
unsigned char uint8
Definition: c_types.h:45
espconn_msg * plink_active
Definition: espconn.c:32
static uint8 ICACHE_FLASH_ATTR espconn_get_acticve_num(uint8 type)
Definition: espconn.c:239
#define espconn_printf(fmt, args...)
Definition: espconn.h:10
union espconn::@1 proto
#define AP_NETIF
Definition: espconn.h:48
enum espconn_type type
Definition: espconn.h:101
sint8 espconn_tcp_client(struct espconn *espconn)
Definition: espconn_tcp.c:878
signed char sint8
Definition: c_types.h:47
#define ESPCONN_AP
Definition: espconn.h:44
static list_node * plist
Definition: dhcpserver.c:34
struct espconn * pespconn
Definition: espconn.h:169
#define ESPCONN_STA
Definition: espconn.h:43
#define IP4_ADDR(ipaddr, a, b, c, d)
Definition: ip_addr.h:139
Here is the call graph for this function:

◆ espconn_create()

sint8 espconn_create ( struct espconn espconn)

Definition at line 334 of file espconn.c.

References ESPCONN_ARG, ESPCONN_ISCONN, ESPCONN_OK, ESPCONN_UDP, espconn_udp_server(), ICACHE_FLASH_ATTR, _esp_udp::local_port, NULL, _espconn_msg::pespconn, plist, _espconn_msg::pnext, espconn::proto, espconn::type, and espconn::udp.

335 {
336  sint8 value = ESPCONN_OK;
338 
339  if (espconn == NULL) {
340  return ESPCONN_ARG;
341  } else if (espconn ->type != ESPCONN_UDP){
342  return ESPCONN_ARG;
343  }
344 
345  /*check the active node information whether is the same as the entity or not*/
346  for (plist = plink_active; plist != NULL; plist = plist->pnext){
347  if (plist->pespconn && plist->pespconn->type == ESPCONN_UDP){
348  if (espconn->proto.udp->local_port == plist->pespconn->proto.udp->local_port){
349  return ESPCONN_ISCONN;
350  }
351  }
352  }
353 
354  value = espconn_udp_server(espconn);
355 
356  return value;
357 }
esp_udp * udp
Definition: espconn.h:106
int local_port
Definition: espconn.h:83
struct _espconn_msg * pnext
Definition: espconn.h:175
#define NULL
Definition: def.h:47
#define ESPCONN_ISCONN
Definition: espconn.h:34
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_msg * plink_active
Definition: espconn.c:32
union espconn::@1 proto
enum espconn_type type
Definition: espconn.h:101
sint8 espconn_udp_server(struct espconn *espconn)
Definition: espconn_udp.c:363
signed char sint8
Definition: c_types.h:47
static list_node * plist
Definition: dhcpserver.c:34
struct espconn * pespconn
Definition: espconn.h:169
Here is the call graph for this function:

◆ espconn_delete()

sint8 espconn_delete ( struct espconn espconn)

Definition at line 1217 of file espconn.c.

References ESPCONN_ARG, espconn_find_connection(), ESPCONN_OK, espconn_tcp_delete(), ESPCONN_UDP, espconn_udp_disconnect(), ICACHE_FLASH_ATTR, and NULL.

1218 {
1219  espconn_msg *pnode = NULL;
1220  bool value = false;
1221 
1222  if (espconn == NULL) {
1223  return ESPCONN_ARG;
1224  } else if (espconn ->type != ESPCONN_UDP)
1225  return espconn_tcp_delete(espconn);
1226 
1227  /*Find the node depend on the espconn message*/
1228  value = espconn_find_connection(espconn, &pnode);
1229 
1230  if (value){
1231  espconn_udp_disconnect(pnode);
1232  return ESPCONN_OK;
1233  } else
1234  return ESPCONN_ARG;
1235 }
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
void espconn_udp_disconnect(espconn_msg *pdiscon)
Definition: espconn_udp.c:338
#define ESPCONN_ARG
Definition: espconn.h:32
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
sint8 ICACHE_FLASH_ATTR espconn_tcp_delete(struct espconn *pdeletecon)
Definition: espconn_tcp.c:1335
Here is the call graph for this function:

◆ espconn_disconnect()

sint8 espconn_disconnect ( struct espconn espconn)

Definition at line 942 of file espconn.c.

References ESPCONN_ARG, ESPCONN_CLOSE, espconn_find_connection(), ESPCONN_INPROGRESS, ESPCONN_OK, ESPCONN_TCP, espconn_tcp_disconnect(), ICACHE_FLASH_ATTR, NULL, and espconn::state.

943 {
944  espconn_msg *pnode = NULL;
945  bool value = false;
946 
947  if (espconn == NULL) {
948  return ESPCONN_ARG;;
949  } else if (espconn ->type != ESPCONN_TCP)
950  return ESPCONN_ARG;
951 
952  /*Find the node depend on the espconn message*/
953  value = espconn_find_connection(espconn, &pnode);
954 
955  if (value){
956  /*protect for redisconnection*/
957  if (espconn->state == ESPCONN_CLOSE)
958  return ESPCONN_INPROGRESS;
959  espconn_tcp_disconnect(pnode,0); //1 force, 0 normal
960  return ESPCONN_OK;
961  } else
962  return ESPCONN_ARG;
963 }
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
void espconn_tcp_disconnect(espconn_msg *pdiscon, u8 type)
Definition: espconn_tcp.c:498
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_state state
Definition: espconn.h:103
#define ESPCONN_INPROGRESS
Definition: espconn.h:24
Here is the call graph for this function:

◆ espconn_dns_setserver()

void espconn_dns_setserver ( char  numdns,
ip_addr_t dnsserver 
)

◆ espconn_get_connection_info()

sint8 espconn_get_connection_info ( struct espconn pespconn,
remot_info **  pcon_info,
uint8  typeflags 
)

Definition at line 825 of file espconn.c.

References ESPCONN_ARG, ESPCONN_OK, ESPCONN_TCP, ESPCONN_UDP, ICACHE_FLASH_ATTR, espconn::link_cnt, NULL, os_memcpy, os_memset, _espconn_msg::pcommon, _espconn_msg::pespconn, plink_active, plist, _espconn_msg::pnext, premot, _espconn_msg::preverse, _remot_info::remote_ip, _comon_pkt::remote_ip, _remot_info::remote_port, _comon_pkt::remote_port, _remot_info::state, espconn::state, and espconn::type.

826 {
828 
829  if (pespconn == NULL)
830  return ESPCONN_ARG;
831 
832  os_memset(premot, 0, sizeof(premot));
833  pespconn->link_cnt = 0;
834  plist = plink_active;
835  switch (pespconn->type){
836  case ESPCONN_TCP:
837  while(plist != NULL){
838  if (plist->preverse == pespconn){
839  premot[pespconn->link_cnt].state = plist->pespconn->state;
840  premot[pespconn->link_cnt].remote_port = plist->pcommon.remote_port;
841  os_memcpy(premot[pespconn->link_cnt].remote_ip, plist->pcommon.remote_ip, 4);
842  pespconn->link_cnt ++;
843  }
844  plist = plist->pnext;
845  }
846 
847  break;
848  case ESPCONN_UDP:
849  while(plist != NULL){
850  if (plist->pespconn == pespconn){
851  premot[pespconn->link_cnt].state = plist->pespconn->state;
852  premot[pespconn->link_cnt].remote_port = plist->pcommon.remote_port;
853  os_memcpy(premot[pespconn->link_cnt].remote_ip, plist->pcommon.remote_ip, 4);
854  pespconn->link_cnt ++;
855  }
856  plist = plist->pnext;
857  }
858  break;
859  default:
860  break;
861  }
862  *pcon_info = premot;
863  if (pespconn->link_cnt == 0)
864  return ESPCONN_ARG;
865  return ESPCONN_OK;
866 }
int remote_port
Definition: espconn.h:151
struct _espconn_msg * pnext
Definition: espconn.h:175
#define NULL
Definition: def.h:47
uint8 link_cnt
Definition: espconn.h:111
#define ESPCONN_OK
Definition: espconn.h:20
enum espconn_state state
Definition: espconn.h:89
void * preverse
Definition: espconn.h:173
uint8 remote_ip[4]
Definition: espconn.h:91
#define os_memcpy
Definition: osapi.h:36
#define os_memset
Definition: osapi.h:38
comon_pkt pcommon
Definition: espconn.h:170
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_msg * plink_active
Definition: espconn.c:32
remot_info premot[linkMax]
Definition: espconn.c:34
uint8 remote_ip[4]
Definition: espconn.h:152
enum espconn_type type
Definition: espconn.h:101
enum espconn_state state
Definition: espconn.h:103
static list_node * plist
Definition: dhcpserver.c:34
struct espconn * pespconn
Definition: espconn.h:169
int remote_port
Definition: espconn.h:90

◆ espconn_get_keepalive()

sint8 espconn_get_keepalive ( struct espconn espconn,
uint8  level,
void *  optarg 
)

Definition at line 1173 of file espconn.c.

References ESPCONN_ARG, espconn_find_connection(), espconn_keepalive_disabled, ESPCONN_KEEPCNT, ESPCONN_KEEPIDLE, ESPCONN_KEEPINTVL, ESPCONN_OK, ESPCONN_TCP, ICACHE_FLASH_ATTR, NULL, _comon_pkt::pcb, _espconn_msg::pcommon, and espconn::type.

1174 {
1175  espconn_msg *pnode = NULL;
1176  bool value = false;
1177  sint8 ret = ESPCONN_OK;
1178 
1179  if (espconn == NULL || optarg == NULL) {
1180  return ESPCONN_ARG;;
1181  } else if (espconn->type != ESPCONN_TCP)
1182  return ESPCONN_ARG;
1183 
1184  /*Find the node depend on the espconn message*/
1185  value = espconn_find_connection(espconn, &pnode);
1186  if (value && espconn_keepalive_disabled(pnode)) {
1187  struct tcp_pcb *pcb = pnode->pcommon.pcb;
1188  switch (level) {
1189  case ESPCONN_KEEPIDLE:
1190  *(int*)optarg = (int)(pcb->keep_idle/1000);
1191  ret = ESPCONN_OK;
1192  break;
1193  case ESPCONN_KEEPINTVL:
1194  *(int*)optarg = (int)(pcb->keep_intvl/1000);
1195  ret = ESPCONN_OK;
1196  break;
1197  case ESPCONN_KEEPCNT:
1198  *(int*)optarg = (int)(pcb->keep_cnt);
1199  ret = ESPCONN_OK;
1200  break;
1201  default:
1202  ret = ESPCONN_ARG;
1203  break;
1204  }
1205  return ret;
1206  } else
1207  return ESPCONN_ARG;
1208 }
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
#define ESPCONN_OK
Definition: espconn.h:20
comon_pkt pcommon
Definition: espconn.h:170
#define ESPCONN_ARG
Definition: espconn.h:32
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_type type
Definition: espconn.h:101
signed char sint8
Definition: c_types.h:47
#define espconn_keepalive_disabled(espconn)
Definition: espconn.h:200
Here is the call graph for this function:

◆ espconn_get_packet_info()

sint8 espconn_get_packet_info ( struct espconn espconn,
struct espconn_packet infoarg 
)

Definition at line 1004 of file espconn.c.

References ESPCONN_ARG, ESPCONN_CLOSE, espconn_find_connection(), ESPCONN_NONE, ESPCONN_OK, ESPCONN_TCP, ICACHE_FLASH_ATTR, NULL, os_memcpy, _comon_pkt::packet_info, espconn_packet::packseq_nxt, espconn_packet::packseqno, _comon_pkt::pcb, _espconn_msg::pcommon, pktinfo, espconn_packet::snd_buf_size, espconn_packet::snd_queuelen, espconn::state, TCP_SND_QUEUELEN, espconn_packet::total_queuelen, and espconn::type.

1005 {
1006  espconn_msg *pnode = NULL;
1007  err_t err;
1008  bool value = false;
1009 
1010  if (espconn == NULL || infoarg == NULL) {
1011  return ESPCONN_ARG;;
1012  } else if (espconn->type != ESPCONN_TCP)
1013  return ESPCONN_ARG;
1014 
1015  /*Find the node depend on the espconn message*/
1016  value = espconn_find_connection(espconn, &pnode);
1017  if (value) {
1018  struct tcp_pcb *pcb = pnode->pcommon.pcb;
1019  if (pcb == NULL)
1020  return ESPCONN_ARG;
1021 
1022  pnode->pcommon.packet_info.packseq_nxt = pcb->rcv_nxt;
1023  pnode->pcommon.packet_info.packseqno = pcb->snd_nxt;
1024  pnode->pcommon.packet_info.snd_buf_size = pcb->snd_buf;
1026  pnode->pcommon.packet_info.snd_queuelen = pnode->pcommon.packet_info.total_queuelen - pcb->snd_queuelen;
1027  os_memcpy(infoarg,(void*)&pnode->pcommon.packet_info, sizeof(struct espconn_packet));
1028  return ESPCONN_OK;
1029  } else {
1030  switch (espconn->state){
1031  case ESPCONN_CLOSE:
1032  os_memcpy(infoarg,(void*)&pktinfo[0], sizeof(struct espconn_packet));
1033  err = ESPCONN_OK;
1034  break;
1035  case ESPCONN_NONE:
1036  os_memcpy(infoarg,(void*)&pktinfo[1], sizeof(struct espconn_packet));
1037  err = ESPCONN_OK;
1038  break;
1039  default:
1040  err = ESPCONN_ARG;
1041  break;
1042  }
1043  return err;
1044  }
1045 }
struct espconn_packet pktinfo[2]
Definition: espconn.c:36
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
#define ESPCONN_OK
Definition: espconn.h:20
uint32 packseqno
Definition: espconn.h:135
#define os_memcpy
Definition: osapi.h:36
struct espconn_packet packet_info
Definition: espconn.h:163
comon_pkt pcommon
Definition: espconn.h:170
#define ESPCONN_ARG
Definition: espconn.h:32
s8_t err_t
Definition: err.h:47
uint16 snd_buf_size
Definition: espconn.h:132
uint32 packseq_nxt
Definition: espconn.h:136
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_type type
Definition: espconn.h:101
enum espconn_state state
Definition: espconn.h:103
uint16 snd_queuelen
Definition: espconn.h:133
uint16 total_queuelen
Definition: espconn.h:134
#define TCP_SND_QUEUELEN
Definition: opt.h:964
Here is the call graph for this function:

◆ espconn_gethostbyname()

err_t espconn_gethostbyname ( struct espconn pespconn,
const char *  hostname,
ip_addr_t addr,
dns_found_callback  found 
)

Definition at line 1288 of file espconn.c.

References ICACHE_FLASH_ATTR.

1289 {
1290  return dns_gethostbyname(hostname, addr, found, pespconn);
1291 }

◆ espconn_igmp_join()

sint8 espconn_igmp_join ( ip_addr_t host_ip,
ip_addr_t multicast_ip 
)

Definition at line 414 of file espconn_udp.c.

References ERR_OK, ESPCONN_OK, ESPCONN_UDP_DEBUG, and LWIP_DEBUGF.

415 {
416  if (igmp_joingroup(host_ip, multicast_ip) != ERR_OK) {
417  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("udp_join_multigrup failed!\n"));
418  return -1;
419  };
420 
421  /* join to any IP address at the port */
422  return ESPCONN_OK;
423 }
#define ESPCONN_UDP_DEBUG
Definition: espconn_udp.h:5
#define ESPCONN_OK
Definition: espconn.h:20
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
#define ERR_OK
Definition: err.h:52

◆ espconn_igmp_leave()

sint8 espconn_igmp_leave ( ip_addr_t host_ip,
ip_addr_t multicast_ip 
)

Definition at line 396 of file espconn_udp.c.

References ERR_OK, ESPCONN_OK, ESPCONN_UDP_DEBUG, ICACHE_FLASH_ATTR, and LWIP_DEBUGF.

397 {
398  if (igmp_leavegroup(host_ip, multicast_ip) != ERR_OK) {
399  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("udp_leave_multigrup failed!\n"));
400  return -1;
401  };
402 
403  return ESPCONN_OK;
404 }
#define ESPCONN_UDP_DEBUG
Definition: espconn_udp.h:5
#define ESPCONN_OK
Definition: espconn.h:20
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
#define ERR_OK
Definition: err.h:52

◆ espconn_mdns_close()

void espconn_mdns_close ( void  )

Definition at line 119 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

120 {
121  mdns_close();
122 }

◆ espconn_mdns_disable()

void espconn_mdns_disable ( void  )

Definition at line 37 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

38 {
39  mdns_disable();
40 }

◆ espconn_mdns_enable()

void espconn_mdns_enable ( void  )

Definition at line 25 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

26 {
27  mdns_enable();
28 }

◆ espconn_mdns_get_hostname()

char* espconn_mdns_get_hostname ( void  )

Definition at line 63 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

64 {
65  return (char *)mdns_get_hostname();
66 }

◆ espconn_mdns_get_servername()

char* espconn_mdns_get_servername ( void  )

Definition at line 85 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

86 {
87  return (char *)mdns_get_servername();
88 }

◆ espconn_mdns_init()

void espconn_mdns_init ( struct mdns_info info)

Definition at line 131 of file espconn_mdns.c.

132 {
133  mdns_init(info);
134 }

◆ espconn_mdns_server_register()

void espconn_mdns_server_register ( void  )

Definition at line 96 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

97 {
98  mdns_server_register();
99 }

◆ espconn_mdns_server_unregister()

void espconn_mdns_server_unregister ( void  )

Definition at line 107 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

108 {
109  mdns_server_unregister();
110 }

◆ espconn_mdns_set_hostname()

void espconn_mdns_set_hostname ( char *  name)

Definition at line 50 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

51 {
52  mdns_set_hostname(name);
53 }

◆ espconn_mdns_set_servername()

void espconn_mdns_set_servername ( const char *  name)

Definition at line 74 of file espconn_mdns.c.

References ICACHE_FLASH_ATTR.

75 {
76  mdns_set_servername(name);
77 }

◆ espconn_port()

uint32 espconn_port ( void  )

Definition at line 1245 of file espconn.c.

References ICACHE_FLASH_ATTR, and os_random().

1246 {
1247  uint32 port = 0;
1248  static uint32 randnum = 0;
1249 
1250  do {
1251  port = os_random();
1252 
1253  if (port < 0) {
1254  port = os_random() - port;
1255  }
1256 
1257  port %= 0xc350;
1258 
1259  if (port < 0x400) {
1260  port += 0x400;
1261  }
1262 
1263  } while (port == randnum);
1264 
1265  randnum = port;
1266 
1267  return port;
1268 }
unsigned long os_random(void)
unsigned int uint32
Definition: c_types.h:54
Here is the call graph for this function:

◆ espconn_recv_hold()

sint8 espconn_recv_hold ( struct espconn pespconn)

Definition at line 549 of file espconn_tcp.c.

References ESPCONN_ARG, espconn_find_connection(), ESPCONN_OK, ICACHE_FLASH_ATTR, NULL, os_printf, _espconn_msg::recv_hold_flag, and _espconn_msg::recv_holded_buf_Len.

550 {
551  //1st, according to espconn code, have to find out the escpconn_msg by pespconn;
552  espconn_msg *pnode = NULL;
553  bool value = false;
554  if (pespconn == NULL) {
555  return ESPCONN_ARG;
556  }
557  value = espconn_find_connection(pespconn, &pnode);
558  if(value != true)
559  {
560  os_printf("RecvHold, By pespconn,find conn_msg fail\n");
561  return ESPCONN_ARG;
562  }
563 
564  //2nd, the actual operation
565  if(pnode->recv_hold_flag == 0)
566  {
567  pnode->recv_hold_flag = 1;
568  pnode->recv_holded_buf_Len = 0;
569  }
570  return ESPCONN_OK;
571 }
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define os_printf
Definition: osapi.h:62
bool espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
#define ESPCONN_ARG
Definition: espconn.h:32
uint8 recv_hold_flag
Definition: espconn.h:178
uint16 recv_holded_buf_Len
Definition: espconn.h:179
Here is the call graph for this function:

◆ espconn_recv_unhold()

sint8 espconn_recv_unhold ( struct espconn pespconn)

Definition at line 574 of file espconn_tcp.c.

References ESPCONN_ARG, espconn_find_connection(), ESPCONN_OK, ESPCONN_TCP, ICACHE_FLASH_ATTR, NULL, os_printf, _comon_pkt::pcb, _espconn_msg::pcommon, _espconn_msg::recv_hold_flag, _espconn_msg::recv_holded_buf_Len, and espconn::type.

575 {
576  //1st, according to espconn code, have to find out the escpconn_msg by pespconn;
577  espconn_msg *pnode = NULL;
578  bool value = false;
579  if (pespconn == NULL) {
580  return ESPCONN_ARG;
581  }
582  value = espconn_find_connection(pespconn, &pnode);
583  if(value != true)
584  {
585  os_printf("RecvHold, By pespconn,find conn_msg fail\n");
586  return ESPCONN_ARG;
587  }
588 
589  //2nd, the actual operation
590  if(pnode->recv_hold_flag == 1)
591  {
592  if(pespconn->type == ESPCONN_TCP) {
593  tcp_recved(pnode->pcommon.pcb, pnode->recv_holded_buf_Len);
594  }
595  pnode->recv_holded_buf_Len = 0;
596  pnode->recv_hold_flag = 0;
597  }
598  return ESPCONN_OK;
599 }
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
#define ESPCONN_OK
Definition: espconn.h:20
#define os_printf
Definition: osapi.h:62
comon_pkt pcommon
Definition: espconn.h:170
bool espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
#define ESPCONN_ARG
Definition: espconn.h:32
uint8 recv_hold_flag
Definition: espconn.h:178
enum espconn_type type
Definition: espconn.h:101
uint16 recv_holded_buf_Len
Definition: espconn.h:179
Here is the call graph for this function:

◆ espconn_regist_connectcb()

sint8 espconn_regist_connectcb ( struct espconn espconn,
espconn_connect_callback  connect_cb 
)

Definition at line 751 of file espconn.c.

References _esp_tcp::connect_callback, ESPCONN_ARG, ESPCONN_OK, ICACHE_FLASH_ATTR, NULL, espconn::proto, and espconn::tcp.

752 {
753  if (espconn == NULL) {
754  return ESPCONN_ARG;
755  }
756 
757  espconn->proto.tcp->connect_callback = connect_cb;
758  return ESPCONN_OK;
759 }
esp_tcp * tcp
Definition: espconn.h:105
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
espconn_connect_callback connect_callback
Definition: espconn.h:75
#define ESPCONN_ARG
Definition: espconn.h:32
union espconn::@1 proto

◆ espconn_regist_disconcb()

sint8 espconn_regist_disconcb ( struct espconn espconn,
espconn_connect_callback  discon_cb 
)

Definition at line 807 of file espconn.c.

References _esp_tcp::disconnect_callback, ESPCONN_ARG, ESPCONN_OK, ICACHE_FLASH_ATTR, NULL, espconn::proto, and espconn::tcp.

808 {
809  if (espconn == NULL) {
810  return ESPCONN_ARG;
811  }
812 
813  espconn ->proto.tcp->disconnect_callback = discon_cb;
814  return ESPCONN_OK;
815 }
esp_tcp * tcp
Definition: espconn.h:105
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
union espconn::@1 proto
espconn_connect_callback disconnect_callback
Definition: espconn.h:77

◆ espconn_regist_reconcb()

sint8 espconn_regist_reconcb ( struct espconn espconn,
espconn_reconnect_callback  recon_cb 
)

Definition at line 789 of file espconn.c.

References ESPCONN_ARG, ESPCONN_OK, ICACHE_FLASH_ATTR, NULL, espconn::proto, _esp_tcp::reconnect_callback, and espconn::tcp.

790 {
791  if (espconn == NULL) {
792  return ESPCONN_ARG;
793  }
794 
795  espconn ->proto.tcp->reconnect_callback = recon_cb;
796  return ESPCONN_OK;
797 }
esp_tcp * tcp
Definition: espconn.h:105
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
union espconn::@1 proto
espconn_reconnect_callback reconnect_callback
Definition: espconn.h:76

◆ espconn_regist_recvcb()

sint8 espconn_regist_recvcb ( struct espconn espconn,
espconn_recv_callback  recv_cb 
)

Definition at line 770 of file espconn.c.

References ESPCONN_ARG, ESPCONN_OK, ICACHE_FLASH_ATTR, NULL, and espconn::recv_callback.

771 {
772  if (espconn == NULL) {
773  return ESPCONN_ARG;
774  }
775 
776  espconn ->recv_callback = recv_cb;
777  return ESPCONN_OK;
778 }
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_recv_callback recv_callback
Definition: espconn.h:109

◆ espconn_regist_sentcb()

sint8 espconn_regist_sentcb ( struct espconn espconn,
espconn_sent_callback  sent_cb 
)

Definition at line 712 of file espconn.c.

References ESPCONN_ARG, ESPCONN_OK, ICACHE_FLASH_ATTR, NULL, and espconn::sent_callback.

713 {
714  if (espconn == NULL) {
715  return ESPCONN_ARG;
716  }
717 
718  espconn ->sent_callback = sent_cb;
719  return ESPCONN_OK;
720 }
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_sent_callback sent_callback
Definition: espconn.h:110

◆ espconn_regist_time()

sint8 espconn_regist_time ( struct espconn espconn,
uint32  interval,
uint8  type_flag 
)

Definition at line 905 of file espconn.c.

References ESPCONN_ARG, espconn_find_connection(), ESPCONN_OK, ICACHE_FLASH_ATTR, NULL, _espconn_msg::pcommon, _espconn_msg::pespconn, _espconn_msg::pnext, pserver_list, and _comon_pkt::timeout.

906 {
907  espconn_msg *pnode = NULL;
908  espconn_msg *ptime_msg = NULL;
909  bool value = false;
910  if ((espconn == NULL) || (type_flag > 0x01))
911  return ESPCONN_ARG;
912 
913  if (type_flag == 0x01){
914  /*set the timeout time for one active connection of the server*/
915  value = espconn_find_connection(espconn, &pnode);
916  if (value){
917  pnode->pcommon.timeout = interval;
918  return ESPCONN_OK;
919  } else
920  return ESPCONN_ARG;
921  } else {
922  /*set the timeout time for all active connection of the server*/
923  ptime_msg = pserver_list;
924  while (ptime_msg != NULL){
925  if (ptime_msg->pespconn == espconn){
926  ptime_msg->pcommon.timeout = interval;
927  return ESPCONN_OK;
928  }
929  ptime_msg = ptime_msg->pnext;
930  }
931  }
932  return ESPCONN_ARG;
933 }
struct _espconn_msg * pnext
Definition: espconn.h:175
#define NULL
Definition: def.h:47
uint32 timeout
Definition: espconn.h:160
#define ESPCONN_OK
Definition: espconn.h:20
comon_pkt pcommon
Definition: espconn.h:170
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_msg * pserver_list
Definition: espconn.c:33
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
struct espconn * pespconn
Definition: espconn.h:169
Here is the call graph for this function:

◆ espconn_regist_write_finish()

sint8 espconn_regist_write_finish ( struct espconn espconn,
espconn_connect_callback  write_finish_fn 
)

Definition at line 732 of file espconn.c.

References ESPCONN_ARG, ESPCONN_OK, ESPCONN_UDP, ICACHE_FLASH_ATTR, NULL, espconn::proto, espconn::tcp, espconn::type, and _esp_tcp::write_finish_fn.

733 {
734  if (espconn == NULL || espconn ->proto.tcp == NULL || espconn->type == ESPCONN_UDP) {
735  return ESPCONN_ARG;
736  }
737 
738  espconn ->proto.tcp->write_finish_fn = write_finish_fn;
739  return ESPCONN_OK;
740 }
esp_tcp * tcp
Definition: espconn.h:105
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_connect_callback write_finish_fn
Definition: espconn.h:78
union espconn::@1 proto
enum espconn_type type
Definition: espconn.h:101

◆ espconn_secure_accept()

sint8 espconn_secure_accept ( struct espconn espconn)

◆ espconn_secure_ca_disable()

bool espconn_secure_ca_disable ( uint8  level)

◆ espconn_secure_ca_enable()

bool espconn_secure_ca_enable ( uint8  level,
uint32  flash_sector 
)

◆ espconn_secure_cert_req_disable()

bool espconn_secure_cert_req_disable ( uint8  level)

◆ espconn_secure_cert_req_enable()

bool espconn_secure_cert_req_enable ( uint8  level,
uint32  flash_sector 
)

◆ espconn_secure_connect()

sint8 espconn_secure_connect ( struct espconn espconn)

Referenced by MQTT_Connect(), and mqtt_dns_found().

Here is the caller graph for this function:

◆ espconn_secure_delete()

sint8 espconn_secure_delete ( struct espconn espconn)

◆ espconn_secure_disconnect()

sint8 espconn_secure_disconnect ( struct espconn espconn)

Referenced by MQTT_Task(), and mqtt_tcpclient_recv().

Here is the caller graph for this function:

◆ espconn_secure_get_size()

sint16 espconn_secure_get_size ( uint8  level)

◆ espconn_secure_send()

sint8 espconn_secure_send ( struct espconn espconn,
uint8 psent,
uint16  length 
)

Referenced by mqtt_send_keepalive(), MQTT_Task(), and mqtt_tcpclient_connect_cb().

Here is the caller graph for this function:

◆ espconn_secure_sent()

sint8 espconn_secure_sent ( struct espconn espconn,
uint8 psent,
uint16  length 
)

◆ espconn_secure_set_default_certificate()

bool espconn_secure_set_default_certificate ( const uint8 certificate,
uint16  length 
)

◆ espconn_secure_set_default_private_key()

bool espconn_secure_set_default_private_key ( const uint8 private_key,
uint16  length 
)

◆ espconn_secure_set_size()

bool espconn_secure_set_size ( uint8  level,
uint16  size 
)

◆ espconn_send()

sint8 espconn_send ( struct espconn espconn,
uint8 psent,
uint16  length 
)

◆ espconn_sendto()

sint16 espconn_sendto ( struct espconn espconn,
uint8 psent,
uint16  length 
)

Definition at line 448 of file espconn.c.

References __attribute__(), ESPCONN_ARG, espconn_find_connection(), ESPCONN_OK, espconn_send(), ESPCONN_UDP, espconn_udp_sendto(), NULL, and espconn::type.

Referenced by captdnsRecv().

449 {
450  espconn_msg *pnode = NULL;
451  bool value = false;
452  err_t error = ESPCONN_OK;
453 
454  if (espconn == NULL || psent == NULL || length == 0) {
455  return ESPCONN_ARG;
456  }
457 
458  /*Find the node depend on the espconn message*/
459  value = espconn_find_connection(espconn, &pnode);
460  if (value && espconn->type == ESPCONN_UDP)
461  return espconn_udp_sendto(pnode, psent, length);
462  else
463  return ESPCONN_ARG;
464 }
err_t espconn_udp_sendto(void *arg, uint8 *psent, uint16 length)
Definition: espconn_udp.c:183
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define ESPCONN_ARG
Definition: espconn.h:32
s8_t err_t
Definition: err.h:47
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_type type
Definition: espconn.h:101
Here is the call graph for this function:
Here is the caller graph for this function:

◆ espconn_sent()

sint8 espconn_sent ( struct espconn espconn,
uint8 psent,
uint16  length 
)

Definition at line 368 of file espconn.c.

References ESPCONN_ARG, espconn_copy_disabled, espconn_copy_enabled, espconn_find_connection(), ESPCONN_MAXNUM, ESPCONN_MEM, ESPCONN_OK, espconn_pbuf_create(), ESPCONN_TCP, espconn_tcp_get_buf_count(), espconn_tcp_write(), ESPCONN_UDP, espconn_udp_sent(), ESPCONN_WRITE, ICACHE_FLASH_ATTR, _espconn_buf::len, NULL, os_zalloc, _espconn_buf::payload, _comon_pkt::pbuf, _comon_pkt::pbuf_num, _comon_pkt::pcb, _espconn_msg::pcommon, _comon_pkt::ptail, _espconn_buf::punsent, espconn::state, TCP_SND_QUEUELEN, _espconn_buf::unsent, and _comon_pkt::write_flag.

369 {
370  espconn_msg *pnode = NULL;
371  bool value = false;
372  err_t error = ESPCONN_OK;
373 
374  if (espconn == NULL || psent == NULL || length == 0) {
375  return ESPCONN_ARG;
376  }
377 
378  /*Find the node depend on the espconn message*/
379  value = espconn_find_connection(espconn, &pnode);
380 
381  if (value){
382  espconn ->state = ESPCONN_WRITE;
383  switch (espconn ->type) {
384  case ESPCONN_TCP:
385  /* calling sent function frequently,make sure last packet has been backup or sent fully*/
386  if (pnode->pcommon.write_flag){
387  espconn_buf *pbuf = NULL;
388  /*If total number of espconn_buf on the unsent lists exceeds the set maximum, return an error */
389  if (espconn_copy_enabled(pnode)){
390  if (espconn_tcp_get_buf_count(pnode->pcommon.pbuf) >= pnode ->pcommon.pbuf_num)
391  return ESPCONN_MAXNUM;
392  } else {
393  struct tcp_pcb *pcb = pnode->pcommon.pcb;
394  if (pcb->snd_queuelen >= TCP_SND_QUEUELEN)
395  return ESPCONN_MAXNUM;
396  }
397 
398  pbuf = (espconn_buf*) os_zalloc(sizeof(espconn_buf));
399  if (pbuf == NULL)
400  return ESPCONN_MEM;
401  else {
402  /*Backup the application packet information for send more data*/
403  pbuf->payload = psent;
404  pbuf->punsent = pbuf->payload;
405  pbuf->unsent = length;
406  pbuf->len = length;
407  /*insert the espconn_pbuf to the list*/
408  espconn_pbuf_create(&pnode->pcommon.pbuf, pbuf);
409  if (pnode->pcommon.ptail == NULL)
410  pnode->pcommon.ptail = pbuf;
411  }
412  /*when set the data copy option. change the flag for next packet*/
413  if (espconn_copy_disabled(pnode))
414  pnode->pcommon.write_flag = false;
415  error = espconn_tcp_write(pnode);
416 // if (error != ESPCONN_OK){
417 // /*send the application packet fail,
418 // * ensure that each allocated is deleted*/
419 // espconn_pbuf_delete(&pnode->pcommon.pbuf, pbuf);
420 // os_free(pbuf);
421 // pbuf = NULL;
422 // }
423  return error;
424  } else
425  return ESPCONN_ARG;
426  break;
427 
428  case ESPCONN_UDP:
429  return espconn_udp_sent(pnode, psent, length);
430  break;
431 
432  default :
433  break;
434  }
435  }
436  return ESPCONN_ARG;
437 }
uint16 unsent
Definition: espconn.h:143
#define espconn_copy_disabled(espconn)
Definition: espconn.h:198
err_t ICACHE_FLASH_ATTR espconn_tcp_write(void *arg)
Definition: espconn_tcp.c:667
static uint8 espconn_tcp_get_buf_count(espconn_buf *pesp_buf)
Definition: espconn.c:689
espconn_buf * ptail
Definition: espconn.h:156
void ICACHE_FLASH_ATTR espconn_pbuf_create(espconn_buf **phead, espconn_buf *pinsert)
Definition: espconn.c:136
uint16 len
Definition: espconn.h:144
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
#define ESPCONN_OK
Definition: espconn.h:20
uint8 * punsent
Definition: espconn.h:142
#define os_zalloc(s)
Definition: mem.h:44
uint8 * payload
Definition: espconn.h:141
comon_pkt pcommon
Definition: espconn.h:170
Definition: pbuf.h:76
#define ESPCONN_ARG
Definition: espconn.h:32
s8_t err_t
Definition: err.h:47
#define espconn_copy_enabled(espconn)
Definition: espconn.h:199
uint8 pbuf_num
Definition: espconn.h:162
#define ESPCONN_MAXNUM
Definition: espconn.h:25
bool write_flag
Definition: espconn.h:164
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_state state
Definition: espconn.h:103
#define TCP_SND_QUEUELEN
Definition: opt.h:964
espconn_buf * pbuf
Definition: espconn.h:155
err_t espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
Definition: espconn_udp.c:81
#define ESPCONN_MEM
Definition: espconn.h:21
Here is the call graph for this function:

◆ espconn_set_keepalive()

sint8 espconn_set_keepalive ( struct espconn espconn,
uint8  level,
void *  optarg 
)

Definition at line 1128 of file espconn.c.

References ESPCONN_ARG, espconn_find_connection(), espconn_keepalive_disabled, ESPCONN_KEEPCNT, ESPCONN_KEEPIDLE, ESPCONN_KEEPINTVL, ESPCONN_OK, ESPCONN_TCP, NULL, _comon_pkt::pcb, _espconn_msg::pcommon, and espconn::type.

1129 {
1130  espconn_msg *pnode = NULL;
1131  bool value = false;
1132  sint8 ret = ESPCONN_OK;
1133 
1134  if (espconn == NULL || optarg == NULL) {
1135  return ESPCONN_ARG;;
1136  } else if (espconn->type != ESPCONN_TCP)
1137  return ESPCONN_ARG;
1138 
1139  /*Find the node depend on the espconn message*/
1140  value = espconn_find_connection(espconn, &pnode);
1141  if (value && espconn_keepalive_disabled(pnode)) {
1142  struct tcp_pcb *pcb = pnode->pcommon.pcb;
1143  switch (level){
1144  case ESPCONN_KEEPIDLE:
1145  pcb->keep_idle = 1000 * (u32_t)(*(int*)optarg);
1146  ret = ESPCONN_OK;
1147  break;
1148  case ESPCONN_KEEPINTVL:
1149  pcb->keep_intvl = 1000 * (u32_t)(*(int*)optarg);
1150  ret = ESPCONN_OK;
1151  break;
1152  case ESPCONN_KEEPCNT:
1153  pcb->keep_cnt = (u32_t)(*(int*)optarg);
1154  ret = ESPCONN_OK;
1155  break;
1156  default:
1157  ret = ESPCONN_ARG;
1158  break;
1159  }
1160  return ret;
1161  } else
1162  return ESPCONN_ARG;
1163 }
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
#define ESPCONN_OK
Definition: espconn.h:20
unsigned long u32_t
Definition: cc.h:56
comon_pkt pcommon
Definition: espconn.h:170
#define ESPCONN_ARG
Definition: espconn.h:32
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_type type
Definition: espconn.h:101
signed char sint8
Definition: c_types.h:47
#define espconn_keepalive_disabled(espconn)
Definition: espconn.h:200
Here is the call graph for this function:

◆ espconn_set_opt()

sint8 espconn_set_opt ( struct espconn espconn,
uint8  opt 
)

Definition at line 1056 of file espconn.c.

References ESPCONN_ARG, espconn_delay_disabled, espconn_find_connection(), espconn_keepalive_disabled, espconn_keepalive_enable, ESPCONN_OK, _comon_pkt::espconn_opt, ESPCONN_TCP, ICACHE_FLASH_ATTR, NULL, _comon_pkt::pcb, _espconn_msg::pcommon, and espconn::type.

1057 {
1058  espconn_msg *pnode = NULL;
1059  struct tcp_pcb *tpcb;
1060  bool value = false;
1061 
1062  if (espconn == NULL) {
1063  return ESPCONN_ARG;;
1064  } else if (espconn->type != ESPCONN_TCP)
1065  return ESPCONN_ARG;
1066 
1067  /*Find the node depend on the espconn message*/
1068  value = espconn_find_connection(espconn, &pnode);
1069  if (value) {
1070  pnode->pcommon.espconn_opt |= opt;
1071  tpcb = pnode->pcommon.pcb;
1072  if (espconn_delay_disabled(pnode))
1073  tcp_nagle_disable(tpcb);
1074 
1075  if (espconn_keepalive_disabled(pnode))
1077 
1078  return ESPCONN_OK;
1079  } else
1080  return ESPCONN_ARG;
1081 }
#define espconn_delay_disabled(espconn)
Definition: espconn.h:195
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
#define ESPCONN_OK
Definition: espconn.h:20
comon_pkt pcommon
Definition: espconn.h:170
#define espconn_keepalive_enable(pcb)
Definition: espconn_tcp.h:13
#define ESPCONN_ARG
Definition: espconn.h:32
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
enum espconn_type type
Definition: espconn.h:101
enum espconn_option espconn_opt
Definition: espconn.h:165
#define espconn_keepalive_disabled(espconn)
Definition: espconn.h:200
Here is the call graph for this function:

◆ espconn_tcp_get_max_con()

uint8 espconn_tcp_get_max_con ( void  )

Definition at line 528 of file espconn.c.

References MEMP_NUM_TCP_PCB.

Referenced by espconn_connect().

529 {
530  uint8 tcp_num = 0;
531 
532  tcp_num = MEMP_NUM_TCP_PCB;
533 
534  return tcp_num;
535 }
#define MEMP_NUM_TCP_PCB
Definition: opt.h:251
unsigned char uint8
Definition: c_types.h:45
Here is the caller graph for this function:

◆ espconn_tcp_get_max_con_allow()

sint8 espconn_tcp_get_max_con_allow ( struct espconn espconn)

Definition at line 618 of file espconn.c.

References _espconn_msg::count_opt, ESPCONN_ARG, ESPCONN_UDP, NULL, _espconn_msg::pespconn, _espconn_msg::pnext, pserver_list, and espconn::type.

619 {
620  espconn_msg *pget_msg = NULL;
621  if ((espconn == NULL) || (espconn->type == ESPCONN_UDP))
622  return ESPCONN_ARG;
623 
624  pget_msg = pserver_list;
625  while (pget_msg != NULL){
626  if (pget_msg->pespconn == espconn){
627  return pget_msg->count_opt;
628  }
629  pget_msg = pget_msg->pnext;
630  }
631  return ESPCONN_ARG;
632 }
struct _espconn_msg * pnext
Definition: espconn.h:175
#define NULL
Definition: def.h:47
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_msg * pserver_list
Definition: espconn.c:33
enum espconn_type type
Definition: espconn.h:101
struct espconn * pespconn
Definition: espconn.h:169
uint8 count_opt
Definition: espconn.h:171

◆ espconn_tcp_set_max_con()

sint8 espconn_tcp_set_max_con ( uint8  num)

Definition at line 543 of file espconn.c.

References ESPCONN_ARG, ESPCONN_OK, linkMax, and MEMP_NUM_TCP_PCB.

544 {
545  if (num == 0 || num > linkMax)
546  return ESPCONN_ARG;
547 
548  MEMP_NUM_TCP_PCB = num;
549  return ESPCONN_OK;
550 }
#define ESPCONN_OK
Definition: espconn.h:20
#define MEMP_NUM_TCP_PCB
Definition: opt.h:251
#define ESPCONN_ARG
Definition: espconn.h:32
#define linkMax
Definition: espconn.h:193

◆ espconn_tcp_set_max_con_allow()

sint8 espconn_tcp_set_max_con_allow ( struct espconn espconn,
uint8  num 
)

Definition at line 640 of file espconn.c.

References _espconn_msg::count_opt, ESPCONN_ARG, ESPCONN_OK, ESPCONN_UDP, MEMP_NUM_TCP_PCB, NULL, _espconn_msg::pespconn, _espconn_msg::pnext, pserver_list, and espconn::type.

641 {
642  espconn_msg *pset_msg = NULL;
643  if ((espconn == NULL) || (num > MEMP_NUM_TCP_PCB) || (espconn->type == ESPCONN_UDP))
644  return ESPCONN_ARG;
645 
646  pset_msg = pserver_list;
647  while (pset_msg != NULL){
648  if (pset_msg->pespconn == espconn){
649  pset_msg->count_opt = num;
650  return ESPCONN_OK;
651  }
652  pset_msg = pset_msg->pnext;
653  }
654  return ESPCONN_ARG;
655 }
struct _espconn_msg * pnext
Definition: espconn.h:175
#define NULL
Definition: def.h:47
#define ESPCONN_OK
Definition: espconn.h:20
#define MEMP_NUM_TCP_PCB
Definition: opt.h:251
#define ESPCONN_ARG
Definition: espconn.h:32
espconn_msg * pserver_list
Definition: espconn.c:33
enum espconn_type type
Definition: espconn.h:101
struct espconn * pespconn
Definition: espconn.h:169
uint8 count_opt
Definition: espconn.h:171