MeterLogger
espconn.c
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2013-2014 Espressif Systems (Wuxi)
3  *
4  * FileName: espconn.c
5  *
6  * Description: espconn interface for user
7  *
8  * Modification history:
9  * 2014/3/31, v1.0 create this file.
10 *******************************************************************************/
11 
12 #include "lwip/netif.h"
13 #include "lwip/inet.h"
14 #include "netif/etharp.h"
15 #include "lwip/tcp.h"
16 #include "lwip/ip.h"
17 #include "lwip/init.h"
18 #include "ets_sys.h"
19 #include "os_type.h"
20 //#include "os.h"
21 #include "lwip/mem.h"
22 
23 #include "lwip/app/espconn_tcp.h"
24 #include "lwip/app/espconn_udp.h"
25 #include "lwip/app/espconn.h"
26 #include "user_interface.h"
27 
28 #ifdef MEMLEAK_DEBUG
29 static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
30 #endif
31 
35 
37 
39 /******************************************************************************
40  * FunctionName : espconn_copy_partial
41  * Description : reconnect with host
42  * Parameters : arg -- Additional argument to pass to the callback function
43  * Returns : none
44 *******************************************************************************/
46 espconn_copy_partial(struct espconn *pesp_dest, struct espconn *pesp_source)
47 {
48  pesp_dest->type = pesp_source->type;
49  pesp_dest->state = pesp_source->state;
50  if (pesp_source->type == ESPCONN_TCP){
51  pesp_dest->proto.tcp->remote_port = pesp_source->proto.tcp->remote_port;
52  pesp_dest->proto.tcp->local_port = pesp_source->proto.tcp->local_port;
53  os_memcpy(pesp_dest->proto.tcp->remote_ip, pesp_source->proto.tcp->remote_ip, 4);
54  os_memcpy(pesp_dest->proto.tcp->local_ip, pesp_source->proto.tcp->local_ip, 4);
55  pesp_dest->proto.tcp->connect_callback = pesp_source->proto.tcp->connect_callback;
56  pesp_dest->proto.tcp->reconnect_callback = pesp_source->proto.tcp->reconnect_callback;
57  pesp_dest->proto.tcp->disconnect_callback = pesp_source->proto.tcp->disconnect_callback;
58  } else {
59  pesp_dest->proto.udp->remote_port = pesp_source->proto.udp->remote_port;
60  pesp_dest->proto.udp->local_port = pesp_source->proto.udp->local_port;
61  os_memcpy(pesp_dest->proto.udp->remote_ip, pesp_source->proto.udp->remote_ip, 4);
62  os_memcpy(pesp_dest->proto.udp->local_ip, pesp_source->proto.udp->local_ip, 4);
63  }
64  pesp_dest->recv_callback = pesp_source->recv_callback;
65  pesp_dest->sent_callback = pesp_source->sent_callback;
66  pesp_dest->link_cnt = pesp_source->link_cnt;
67  pesp_dest->reverse = pesp_source->reverse;
68 }
69 
70 /******************************************************************************
71  * FunctionName : espconn_copy_partial
72  * Description : insert the node to the active connection list
73  * Parameters : arg -- Additional argument to pass to the callback function
74  * Returns : none
75 *******************************************************************************/
77 {
79 // espconn_msg *ptest = NULL;
80  if (*phead == NULL)
81  *phead = pinsert;
82  else {
83  plist = *phead;
84  while (plist->pnext != NULL) {
85  plist = plist->pnext;
86  }
87  plist->pnext = pinsert;
88  }
89  pinsert->pnext = NULL;
90 
91 /* ptest = *phead;
92  while(ptest != NULL){
93  os_printf("espconn_list_creat %p\n", ptest);
94  ptest = ptest->pnext;
95  }*/
96 }
97 
98 /******************************************************************************
99  * FunctionName : espconn_list_delete
100  * Description : remove the node from the active connection list
101  * Parameters : arg -- Additional argument to pass to the callback function
102  * Returns : none
103 *******************************************************************************/
105 {
107 // espconn_msg *ptest = NULL;
108  plist = *phead;
109  if (plist == NULL){
110  *phead = NULL;
111  } else {
112  if (plist == pdelete){
113  *phead = plist->pnext;
114  } else {
115  while (plist != NULL) {
116  if (plist->pnext == pdelete){
117  plist->pnext = pdelete->pnext;
118  }
119  plist = plist->pnext;
120  }
121  }
122  }
123 /* ptest = *phead;
124  while(ptest != NULL){
125  os_printf("espconn_list_delete %p\n", ptest);
126  ptest = ptest->pnext;
127  }*/
128 }
129 
130 /******************************************************************************
131  * FunctionName : espconn_pbuf_create
132  * Description : insert the node to the active connection list
133  * Parameters : arg -- Additional argument to pass to the callback function
134  * Returns : none
135 *******************************************************************************/
137 {
139 
140  if (*phead == NULL)
141  *phead = pinsert;
142  else {
143  plist = *phead;
144  while (plist->pnext != NULL) {
145  plist = plist->pnext;
146  }
147  plist->pnext = pinsert;
148  }
149  pinsert->pnext = NULL;
150 }
151 
152 /******************************************************************************
153  * FunctionName : espconn_pbuf_delete
154  * Description : remove the node from the active connection list
155  * Parameters : arg -- Additional argument to pass to the callback function
156  * Returns : none
157 *******************************************************************************/
159 {
161 
162  plist = *phead;
163  if (plist == NULL){
164  *phead = NULL;
165  } else {
166  if (plist == pdelete){
167  *phead = plist->pnext;
168  } else {
169  while (plist != NULL) {
170  if (plist->pnext == pdelete){
171  plist->pnext = pdelete->pnext;
172  }
173  plist = plist->pnext;
174  }
175  }
176  }
177 }
178 
179 /******************************************************************************
180  * FunctionName : espconn_find_connection
181  * Description : Initialize the server: set up a listening PCB and bind it to
182  * the defined port
183  * Parameters : espconn -- the espconn used to build server
184  * Returns : true or false
185  *******************************************************************************/
187 {
189  struct ip_addr ip_remot;
190  struct ip_addr ip_list;
191 
192  if (pespconn == NULL)
193  return false;
194 
195  /*find the active connection node*/
196  for (plist = plink_active; plist != NULL; plist = plist->pnext){
197  if (pespconn == plist->pespconn) {
198  *pnode = plist;
199  return true;
200  }
201  }
202 
203  /*find the active server node*/
204  for (plist = pserver_list; plist != NULL; plist = plist->pnext){
205  if (pespconn == plist->pespconn) {
206  if (pespconn->proto.tcp == NULL)
207  return false;
208 
209  IP4_ADDR(&ip_remot, pespconn->proto.tcp->remote_ip[0],
210  pespconn->proto.tcp->remote_ip[1],
211  pespconn->proto.tcp->remote_ip[2],
212  pespconn->proto.tcp->remote_ip[3]);
213  if ((ip_remot.addr == IPADDR_ANY) || (pespconn->proto.tcp->remote_port == 0))
214  return false;
215 
216  /*find the active connection node*/
217  for (plist = plink_active; plist != NULL; plist = plist->pnext){
218  IP4_ADDR(&ip_list, plist->pcommon.remote_ip[0],
219  plist->pcommon.remote_ip[1], plist->pcommon.remote_ip[2],
220  plist->pcommon.remote_ip[3]);
221  if ((ip_list.addr == ip_remot.addr) && (pespconn->proto.tcp->remote_port == plist->pcommon.remote_port)) {
222  *pnode = plist;
223  return true;
224  }
225  }
226  return false;
227  }
228  }
229  return false;
230 }
231 
232 /******************************************************************************
233  * FunctionName : espconn_get_acticve_num
234  * Description : get the count of simulatenously active connections
235  * Parameters : type -- the type
236  * Returns : the count of simulatenously active connections
237  *******************************************************************************/
240 {
242  uint8 num_tcp_active = 0;
243 
244  for (plist = plink_active; plist != NULL; plist = plist->pnext) {
245  if (plist->pespconn != NULL && plist->pespconn->type == type) {
246  num_tcp_active++;
247  }
248  }
249 
250  return num_tcp_active;
251 }
252 
253 /******************************************************************************
254  * FunctionName : espconn_connect
255  * Description : The function given as the connect
256  * Parameters : espconn -- the espconn used to listen the connection
257  * Returns : none
258 *******************************************************************************/
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 }
326 
327 /******************************************************************************
328  * FunctionName : espconn_create
329  * Description : sent data for client or server
330  * Parameters : espconn -- espconn to the data transmission
331  * Returns : result
332 *******************************************************************************/
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 }
358 
359 /******************************************************************************
360  * FunctionName : espconn_sent
361  * Description : sent data for client or server
362  * Parameters : espconn -- espconn to set for client or server
363  * psent -- data to send
364  * length -- length of data to send
365  * Returns : none
366 *******************************************************************************/
368 espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length)
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 }
438 
439 /******************************************************************************
440  * FunctionName : espconn_sendto
441  * Description : send data for UDP
442  * Parameters : espconn -- espconn to set for UDP
443  * psent -- data to send
444  * length -- length of data to send
445  * Returns : error
446 *******************************************************************************/
448 espconn_sendto(struct espconn *espconn, uint8 *psent, uint16 length)
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 }
465 
466 /******************************************************************************
467  * FunctionName : espconn_send
468  * Description : sent data for client or server
469  * Parameters : espconn -- espconn to set for client or server
470  * psent -- data to send
471  * length -- length of data to send
472  * Returns : none
473 *******************************************************************************/
474 
475 sint8 espconn_send(struct espconn *espconn, uint8 *psent, uint16 length) __attribute__((alias("espconn_sent")));
476 
477 /******************************************************************************
478  * FunctionName : espconn_tcp_get_wnd
479  * Description : get the window size of simulatenously active TCP connections
480  * Parameters : none
481  * Returns : the number of TCP_MSS active TCP connections
482 *******************************************************************************/
484 {
485  uint8 tcp_num = 0;
486 
487  tcp_num = (TCP_WND / TCP_MSS);
488 
489  return tcp_num;
490 }
491 /******************************************************************************
492  * FunctionName : espconn_tcp_set_max_con
493  * Description : set the window size simulatenously active TCP connections
494  * Parameters : num -- the number of TCP_MSS
495  * Returns : ESPCONN_ARG -- Illegal argument
496  * ESPCONN_OK -- No error
497 *******************************************************************************/
499 {
500  if (num == 0 || num > linkMax)
501  return ESPCONN_ARG;
502 
503  TCP_WND = (num * TCP_MSS);
504  return ESPCONN_OK;
505 }
506 
507 /******************************************************************************
508  * FunctionName : espconn_tcp_get_mss
509  * Description : get the mss size of simulatenously active TCP connections
510  * Parameters : none
511  * Returns : the size of TCP_MSS active TCP connections
512 *******************************************************************************/
514 {
515  uint16 tcp_num = 0;
516 
517  tcp_num = TCP_MSS;
518 
519  return tcp_num;
520 }
521 
522 /******************************************************************************
523  * FunctionName : espconn_tcp_get_max_con
524  * Description : get the number of simulatenously active TCP connections
525  * Parameters : espconn -- espconn to set the connect callback
526  * Returns : none
527 *******************************************************************************/
529 {
530  uint8 tcp_num = 0;
531 
532  tcp_num = MEMP_NUM_TCP_PCB;
533 
534  return tcp_num;
535 }
536 
537 /******************************************************************************
538  * FunctionName : espconn_tcp_set_max_con
539  * Description : set the number of simulatenously active TCP connections
540  * Parameters : espconn -- espconn to set the connect callback
541  * Returns : none
542 *******************************************************************************/
544 {
545  if (num == 0 || num > linkMax)
546  return ESPCONN_ARG;
547 
548  MEMP_NUM_TCP_PCB = num;
549  return ESPCONN_OK;
550 }
551 
552 /******************************************************************************
553  * FunctionName : espconn_tcp_get_max_retran
554  * Description : get the Maximum number of retransmissions of data active TCP connections
555  * Parameters : none
556  * Returns : the Maximum number of retransmissions
557 *******************************************************************************/
559 {
560  uint8 tcp_num = 0;
561 
562  tcp_num = TCP_MAXRTX;
563 
564  return tcp_num;
565 }
566 
567 /******************************************************************************
568  * FunctionName : espconn_tcp_set_max_retran
569  * Description : set the Maximum number of retransmissions of data active TCP connections
570  * Parameters : num -- the Maximum number of retransmissions
571  * Returns : result
572 *******************************************************************************/
574 {
575  if (num == 0 || num > 12)
576  return ESPCONN_ARG;
577 
578  TCP_MAXRTX = num;
579  return ESPCONN_OK;
580 }
581 
582 /******************************************************************************
583  * FunctionName : espconn_tcp_get_max_syn
584  * Description : get the Maximum number of retransmissions of SYN segments
585  * Parameters : none
586  * Returns : the Maximum number of retransmissions
587 *******************************************************************************/
589 {
590  uint8 tcp_num = 0;
591 
592  tcp_num = TCP_SYNMAXRTX;
593 
594  return tcp_num;
595 }
596 
597 /******************************************************************************
598  * FunctionName : espconn_tcp_set_max_syn
599  * Description : set the Maximum number of retransmissions of SYN segments
600  * Parameters : num -- the Maximum number of retransmissions
601  * Returns : result
602 *******************************************************************************/
604 {
605  if (num == 0 || num > 12)
606  return ESPCONN_ARG;
607 
608  TCP_SYNMAXRTX = num;
609  return ESPCONN_OK;
610 }
611 
612 /******************************************************************************
613  * FunctionName : espconn_tcp_get_max_con_allow
614  * Description : get the count of simulatenously active connections on the server
615  * Parameters : espconn -- espconn to get the count
616  * Returns : result
617 *******************************************************************************/
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 }
633 
634 /******************************************************************************
635  * FunctionName : espconn_tcp_set_max_con_allow
636  * Description : set the count of simulatenously active connections on the server
637  * Parameters : espconn -- espconn to set the count
638  * Returns : result
639 *******************************************************************************/
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 }
656 
657 /******************************************************************************
658  * FunctionName : espconn_tcp_set_buf_count
659  * Description : set the total number of espconn_buf on the unsent lists for one
660  * activate connection
661  * Parameters : espconn -- espconn to set the count
662  * num -- the total number of espconn_buf
663  * Returns : result
664 *******************************************************************************/
666 {
668  if (espconn == NULL || (num > TCP_SND_QUEUELEN))
669  return ESPCONN_ARG;
670 
671  /*find the node from the active connection list*/
672  for (plist = plink_active; plist != NULL; plist = plist->pnext){
673  if (plist->pespconn && plist->pespconn == espconn && espconn->type == ESPCONN_TCP){
674  plist->pcommon.pbuf_num = num;
675  return ESPCONN_OK;
676  }
677  }
678 
679  if (plist == NULL)
680  return ESPCONN_ARG;
681 }
682 
683 /******************************************************************************
684  * FunctionName : espconn_tcp_get_buf_count
685  * Description : get the count of the current node which has espconn_buf
686  * Parameters : pesp_buf -- the list head of espconn_buf type
687  * Returns : the count of the current node which has espconn_buf
688 *******************************************************************************/
690 {
691  espconn_buf *pbuf_list = pesp_buf;
692  uint8 pbuf_num = 0;
693 
694  /*polling the list get the count of the current node*/
695  while (pbuf_list != NULL){
696  pbuf_list = pbuf_list->pnext;
697  pbuf_num ++;
698  }
699  return pbuf_num;
700 }
701 
702 /******************************************************************************
703  * FunctionName : espconn_regist_sentcb
704  * Description : Used to specify the function that should be called when data
705  * has been successfully delivered to the remote host.
706  * Parameters : espconn -- espconn to set the sent callback
707  * sent_cb -- sent callback function to call for this espconn
708  * when data is successfully sent
709  * Returns : none
710 *******************************************************************************/
712 espconn_regist_sentcb(struct espconn *espconn, espconn_sent_callback sent_cb)
713 {
714  if (espconn == NULL) {
715  return ESPCONN_ARG;
716  }
717 
718  espconn ->sent_callback = sent_cb;
719  return ESPCONN_OK;
720 }
721 
722 /******************************************************************************
723  * FunctionName : espconn_regist_sentcb
724  * Description : Used to specify the function that should be called when data
725  * has been successfully delivered to the remote host.
726  * Parameters : espconn -- espconn to set the sent callback
727  * sent_cb -- sent callback function to call for this espconn
728  * when data is successfully sent
729  * Returns : none
730 *******************************************************************************/
732 espconn_regist_write_finish(struct espconn *espconn, espconn_connect_callback 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 }
741 
742 /******************************************************************************
743  * FunctionName : espconn_regist_connectcb
744  * Description : used to specify the function that should be called when
745  * connects to host.
746  * Parameters : espconn -- espconn to set the connect callback
747  * connect_cb -- connected callback function to call when connected
748  * Returns : none
749 *******************************************************************************/
751 espconn_regist_connectcb(struct espconn *espconn, espconn_connect_callback connect_cb)
752 {
753  if (espconn == NULL) {
754  return ESPCONN_ARG;
755  }
756 
757  espconn->proto.tcp->connect_callback = connect_cb;
758  return ESPCONN_OK;
759 }
760 
761 /******************************************************************************
762  * FunctionName : espconn_regist_recvcb
763  * Description : used to specify the function that should be called when recv
764  * data from host.
765  * Parameters : espconn -- espconn to set the recv callback
766  * recv_cb -- recv callback function to call when recv data
767  * Returns : none
768 *******************************************************************************/
770 espconn_regist_recvcb(struct espconn *espconn, espconn_recv_callback recv_cb)
771 {
772  if (espconn == NULL) {
773  return ESPCONN_ARG;
774  }
775 
776  espconn ->recv_callback = recv_cb;
777  return ESPCONN_OK;
778 }
779 
780 /******************************************************************************
781  * FunctionName : espconn_regist_reconcb
782  * Description : used to specify the function that should be called when connection
783  * because of err disconnect.
784  * Parameters : espconn -- espconn to set the err callback
785  * recon_cb -- err callback function to call when err
786  * Returns : none
787 *******************************************************************************/
789 espconn_regist_reconcb(struct espconn *espconn, espconn_reconnect_callback recon_cb)
790 {
791  if (espconn == NULL) {
792  return ESPCONN_ARG;
793  }
794 
795  espconn ->proto.tcp->reconnect_callback = recon_cb;
796  return ESPCONN_OK;
797 }
798 
799 /******************************************************************************
800  * FunctionName : espconn_regist_disconcb
801  * Description : used to specify the function that should be called when disconnect
802  * Parameters : espconn -- espconn to set the err callback
803  * discon_cb -- err callback function to call when err
804  * Returns : none
805 *******************************************************************************/
807 espconn_regist_disconcb(struct espconn *espconn, espconn_connect_callback discon_cb)
808 {
809  if (espconn == NULL) {
810  return ESPCONN_ARG;
811  }
812 
813  espconn ->proto.tcp->disconnect_callback = discon_cb;
814  return ESPCONN_OK;
815 }
816 
817 /******************************************************************************
818  * FunctionName : espconn_get_connection_info
819  * Description : used to specify the function that should be called when disconnect
820  * Parameters : espconn -- espconn to set the err callback
821  * discon_cb -- err callback function to call when err
822  * Returns : none
823 *******************************************************************************/
825 espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags)
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 }
867 
868 /******************************************************************************
869  * FunctionName : espconn_accept
870  * Description : The function given as the listen
871  * Parameters : espconn -- the espconn used to listen the connection
872  * Returns :
873 *******************************************************************************/
875 espconn_accept(struct espconn *espconn)
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 }
897 
898 /******************************************************************************
899  * FunctionName : espconn_regist_time
900  * Description : used to specify the time that should be called when don't recv data
901  * Parameters : espconn -- the espconn used to the connection
902  * interval -- the timer when don't recv data
903  * Returns : none
904 *******************************************************************************/
905 sint8 ICACHE_FLASH_ATTR espconn_regist_time(struct espconn *espconn, uint32 interval, uint8 type_flag)
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 }
934 
935 /******************************************************************************
936  * FunctionName : espconn_disconnect
937  * Description : disconnect with host
938  * Parameters : espconn -- the espconn used to disconnect the connection
939  * Returns : none
940 *******************************************************************************/
942 espconn_disconnect(struct espconn *espconn)
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 }
964 
965 /******************************************************************************
966  * FunctionName : espconn_abort
967  * Description : Forcely abort with host
968  * Parameters : espconn -- the espconn used to disconnect the connection
969  * Returns : none
970 *******************************************************************************/
972 espconn_abort(struct espconn *espconn)
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 }
994 
995 
996 /******************************************************************************
997  * FunctionName : espconn_get_packet_info
998  * Description : get the packet info with host
999  * Parameters : espconn -- the espconn used to disconnect the connection
1000  * infoarg -- the packet info
1001  * Returns : the errur code
1002 *******************************************************************************/
1004 espconn_get_packet_info(struct espconn *espconn, struct espconn_packet* infoarg)
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 }
1046 
1047 /******************************************************************************
1048  * FunctionName : espconn_set_opt
1049  * Description : set the option for connections so that we don't end up bouncing
1050  * all connections at the same time .
1051  * Parameters : espconn -- the espconn used to set the connection
1052  * opt -- the option for set
1053  * Returns : the result
1054 *******************************************************************************/
1056 espconn_set_opt(struct espconn *espconn, uint8 opt)
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 }
1082 
1083 /******************************************************************************
1084  * FunctionName : espconn_clear_opt
1085  * Description : clear the option for connections so that we don't end up bouncing
1086  * all connections at the same time .
1087  * Parameters : espconn -- the espconn used to set the connection
1088  * opt -- the option for clear
1089  * Returns : the result
1090 *******************************************************************************/
1092 espconn_clear_opt(struct espconn *espconn, uint8 opt)
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 }
1118 
1119 /******************************************************************************
1120  * FunctionName : espconn_set_keepalive
1121  * Description : access level value for connection so that we set the value for
1122  * keep alive
1123  * Parameters : espconn -- the espconn used to set the connection
1124  * level -- the connection's level
1125  * value -- the value of time(s)
1126  * Returns : access port value
1127 *******************************************************************************/
1128 sint8 ICACHE_FLASH_ATTR espconn_set_keepalive(struct espconn *espconn, uint8 level, void* optarg)
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 }
1164 
1165 /******************************************************************************
1166  * FunctionName : espconn_get_keepalive
1167  * Description : access level value for connection so that we get the value for
1168  * keep alive
1169  * Parameters : espconn -- the espconn used to get the connection
1170  * level -- the connection's level
1171  * Returns : access keep alive value
1172 *******************************************************************************/
1173 sint8 ICACHE_FLASH_ATTR espconn_get_keepalive(struct espconn *espconn, uint8 level, void *optarg)
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 }
1209 
1210 /******************************************************************************
1211  * FunctionName : espconn_delete
1212  * Description : disconnect with host
1213  * Parameters : espconn -- the espconn used to disconnect the connection
1214  * Returns : none
1215 *******************************************************************************/
1217 espconn_delete(struct espconn *espconn)
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 }
1236 
1237 /******************************************************************************
1238  * FunctionName : espconn_port
1239  * Description : access port value for client so that we don't end up bouncing
1240  * all connections at the same time .
1241  * Parameters : none
1242  * Returns : access port value
1243 *******************************************************************************/
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 }
1269 
1270 /******************************************************************************
1271  * FunctionName : espconn_gethostbyname
1272  * Description : Resolve a hostname (string) into an IP address.
1273  * Parameters : pespconn -- espconn to resolve a hostname
1274  * hostname -- the hostname that is to be queried
1275  * addr -- pointer to a ip_addr_t where to store the address if
1276  * it is already cached in the dns_table (only valid if
1277  * ESPCONN_OK is returned!)
1278  * found -- a callback function to be called on success, failure
1279  * or timeout (only if ERR_INPROGRESS is returned!)
1280  * Returns : err_t return code
1281  * - ESPCONN_OK if hostname is a valid IP address string or the host
1282  * name is already in the local names table.
1283  * - ESPCONN_INPROGRESS enqueue a request to be sent to the DNS server
1284  * for resolution if no errors are present.
1285  * - ESPCONN_ARG: dns client not initialized or invalid hostname
1286 *******************************************************************************/
1288 espconn_gethostbyname(struct espconn *pespconn, const char *hostname, ip_addr_t *addr, dns_found_callback found)
1289 {
1290  return dns_gethostbyname(hostname, addr, found, pespconn);
1291 }
1292 
1293 /******************************************************************************
1294  * FunctionName : espconn_dns_setserver
1295  * Description : Initialize one of the DNS servers.
1296  * Parameters : numdns -- the index of the DNS server to set must
1297  * be < DNS_MAX_SERVERS = 2
1298  * dnsserver -- IP address of the DNS server to set
1299  * Returns : none
1300 *******************************************************************************/
1301 void ICACHE_FLASH_ATTR
1303 {
1304  dns_setserver(numdns,dnsserver);
1305 }
1306 
uint16 unsent
Definition: espconn.h:143
#define TCP_MAXRTX
Definition: opt.h:910
sint8 ICACHE_FLASH_ATTR espconn_tcp_set_max_con(uint8 num)
Definition: espconn.c:543
sint8 ICACHE_FLASH_ATTR espconn_create(struct espconn *espconn)
Definition: espconn.c:334
struct ip_addr ip
Definition: ip_addr.h:248
uint8 ICACHE_FLASH_ATTR espconn_tcp_get_max_con(void)
Definition: espconn.c:528
#define espconn_copy_disabled(espconn)
Definition: espconn.h:198
sint8 ICACHE_FLASH_ATTR espconn_tcp_set_wnd(uint8 num)
Definition: espconn.c:498
esp_udp * udp
Definition: espconn.h:106
err_t espconn_udp_sendto(void *arg, uint8 *psent, uint16 length)
Definition: espconn_udp.c:183
sint8 ICACHE_FLASH_ATTR espconn_connect(struct espconn *espconn)
Definition: espconn.c:260
err_t ICACHE_FLASH_ATTR espconn_tcp_write(void *arg)
Definition: espconn_tcp.c:667
int local_port
Definition: espconn.h:83
void * reverse
Definition: espconn.h:112
sint8 ICACHE_FLASH_ATTR espconn_regist_reconcb(struct espconn *espconn, espconn_reconnect_callback recon_cb)
Definition: espconn.c:789
#define espconn_delay_disabled(espconn)
Definition: espconn.h:195
sint8 espconn_send(struct espconn *espconn, uint8 *psent, uint16 length) __attribute__((alias("espconn_sent")))
void ICACHE_FLASH_ATTR espconn_pbuf_delete(espconn_buf **phead, espconn_buf *pdelete)
Definition: espconn.c:158
sint8 ICACHE_FLASH_ATTR espconn_regist_disconcb(struct espconn *espconn, espconn_connect_callback discon_cb)
Definition: espconn.c:807
static uint8 espconn_tcp_get_buf_count(espconn_buf *pesp_buf)
Definition: espconn.c:689
esp_tcp * tcp
Definition: espconn.h:105
int remote_port
Definition: espconn.h:151
#define espconn_keepalive_enabled(espconn)
Definition: espconn.h:201
struct _espconn_msg * pnext
Definition: espconn.h:175
struct espconn_packet pktinfo[2]
Definition: espconn.c:36
sint8 ICACHE_FLASH_ATTR espconn_set_opt(struct espconn *espconn, uint8 opt)
Definition: espconn.c:1056
#define ESPCONN_AP_STA
Definition: espconn.h:45
espconn_buf * ptail
Definition: espconn.h:156
sint8 ICACHE_FLASH_ATTR espconn_regist_recvcb(struct espconn *espconn, espconn_recv_callback recv_cb)
Definition: espconn.c:770
void ICACHE_FLASH_ATTR espconn_pbuf_create(espconn_buf **phead, espconn_buf *pinsert)
Definition: espconn.c:136
sint8 ICACHE_FLASH_ATTR espconn_clear_opt(struct espconn *espconn, uint8 opt)
Definition: espconn.c:1092
#define STA_NETIF
Definition: espconn.h:47
uint16 len
Definition: espconn.h:144
#define NULL
Definition: def.h:47
int local_port
Definition: espconn.h:72
void * pcb
Definition: espconn.h:150
uint8 link_cnt
Definition: espconn.h:111
#define ESPCONN_ISCONN
Definition: espconn.h:34
sint8 espconn_tcp_server(struct espconn *espconn)
Definition: espconn_tcp.c:1281
sint8 ICACHE_FLASH_ATTR espconn_regist_sentcb(struct espconn *espconn, espconn_sent_callback sent_cb)
Definition: espconn.c:712
uint32 timeout
Definition: espconn.h:160
#define ESPCONN_OK
Definition: espconn.h:20
const ip_addr_t ip_addr_any ICACHE_RODATA_ATTR
Definition: ip_addr.c:44
unsigned short uint16
Definition: c_types.h:50
#define ICACHE_FLASH_ATTR
Definition: c_types.h:99
#define MEMP_NUM_TCP_PCB
Definition: opt.h:251
uint8 remote_ip[4]
Definition: espconn.h:74
sint8 ICACHE_FLASH_ATTR espconn_accept(struct espconn *espconn)
Definition: espconn.c:875
uint8 * punsent
Definition: espconn.h:142
bool wifi_get_ip_info(uint8 if_index, struct ip_info *info)
void espconn_udp_disconnect(espconn_msg *pdiscon)
Definition: espconn_udp.c:338
enum espconn_state state
Definition: espconn.h:89
#define TCP_SYNMAXRTX
Definition: opt.h:917
void * preverse
Definition: espconn.h:173
void(* espconn_connect_callback)(void *arg)
Definition: espconn.h:15
void(* espconn_recv_callback)(void *arg, char *pdata, unsigned short len)
Definition: espconn.h:95
void(* espconn_reconnect_callback)(void *arg, sint8 err)
Definition: espconn.h:16
uint32 packseqno
Definition: espconn.h:135
uint8 wifi_station_get_connect_status(void)
uint8 wifi_get_opmode(void)
sint8 ICACHE_FLASH_ATTR espconn_tcp_set_buf_count(struct espconn *espconn, uint8 num)
Definition: espconn.c:665
int remote_port
Definition: espconn.h:71
#define os_zalloc(s)
Definition: mem.h:44
#define TCP_WND
Definition: opt.h:903
uint8 remote_ip[4]
Definition: espconn.h:91
espconn_connect_callback connect_callback
Definition: espconn.h:75
#define os_memcpy
Definition: osapi.h:36
void ICACHE_FLASH_ATTR espconn_list_delete(espconn_msg **phead, espconn_msg *pdelete)
Definition: espconn.c:104
sint8 ICACHE_FLASH_ATTR espconn_set_keepalive(struct espconn *espconn, uint8 level, void *optarg)
Definition: espconn.c:1128
struct espconn_packet packet_info
Definition: espconn.h:163
#define IPADDR_ANY
Definition: ip_addr.h:100
sint8 ICACHE_FLASH_ATTR espconn_tcp_set_max_syn(uint8 num)
Definition: espconn.c:603
#define ESPCONN_RTE
Definition: espconn.h:23
uint16 ICACHE_FLASH_ATTR espconn_tcp_get_mss(void)
Definition: espconn.c:513
sint8 ICACHE_FLASH_ATTR espconn_delete(struct espconn *espconn)
Definition: espconn.c:1217
unsigned long u32_t
Definition: cc.h:56
#define os_memset
Definition: osapi.h:38
#define espconn_delay_enabled(espconn)
Definition: espconn.h:196
void(* dns_found_callback)(const char *name, ip_addr_t *ipaddr, void *callback_arg)
Definition: espconn.h:437
uint8 * payload
Definition: espconn.h:141
unsigned long os_random(void)
comon_pkt pcommon
Definition: espconn.h:170
signed short sint16
Definition: c_types.h:52
#define espconn_keepalive_enable(pcb)
Definition: espconn_tcp.h:13
Definition: pbuf.h:76
#define ESPCONN_ARG
Definition: espconn.h:32
unsigned char uint8
Definition: c_types.h:45
espconn_msg * plink_active
Definition: espconn.c:32
s8_t err_t
Definition: err.h:47
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
Definition: ip_addr.h:64
uint16 snd_buf_size
Definition: espconn.h:132
sint8 ICACHE_FLASH_ATTR espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags)
Definition: espconn.c:825
void espconn_tcp_disconnect(espconn_msg *pdiscon, u8 type)
Definition: espconn_tcp.c:498
remot_info premot[linkMax]
Definition: espconn.c:34
sint8 ICACHE_FLASH_ATTR espconn_get_packet_info(struct espconn *espconn, struct espconn_packet *infoarg)
Definition: espconn.c:1004
sint8 ICACHE_FLASH_ATTR espconn_regist_write_finish(struct espconn *espconn, espconn_connect_callback write_finish_fn)
Definition: espconn.c:732
static uint8 ICACHE_FLASH_ATTR espconn_get_acticve_num(uint8 type)
Definition: espconn.c:239
#define espconn_copy_enabled(espconn)
Definition: espconn.h:199
uint8 pbuf_num
Definition: espconn.h:162
sint8 ICACHE_FLASH_ATTR espconn_tcp_set_max_retran(uint8 num)
Definition: espconn.c:573
void(* espconn_sent_callback)(void *arg)
Definition: espconn.h:96
espconn_connect_callback write_finish_fn
Definition: espconn.h:78
#define ESPCONN_MAXNUM
Definition: espconn.h:25
espconn_msg * pserver_list
Definition: espconn.c:33
uint8 remote_ip[4]
Definition: espconn.h:152
int remote_port
Definition: espconn.h:82
sint8 ICACHE_FLASH_ATTR espconn_disconnect(struct espconn *espconn)
Definition: espconn.c:942
uint8 ICACHE_FLASH_ATTR espconn_tcp_get_max_retran(void)
Definition: espconn.c:558
err_t ICACHE_FLASH_ATTR espconn_gethostbyname(struct espconn *pespconn, const char *hostname, ip_addr_t *addr, dns_found_callback found)
Definition: espconn.c:1288
bool write_flag
Definition: espconn.h:164
uint8 ICACHE_FLASH_ATTR espconn_tcp_get_max_syn(void)
Definition: espconn.c:588
unsigned int uint32
Definition: c_types.h:54
#define espconn_printf(fmt, args...)
Definition: espconn.h:10
uint32 packseq_nxt
Definition: espconn.h:136
union espconn::@1 proto
uint32 ICACHE_FLASH_ATTR espconn_port(void)
Definition: espconn.c:1245
#define linkMax
Definition: espconn.h:193
void ICACHE_FLASH_ATTR espconn_dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
Definition: espconn.c:1302
uint8 local_ip[4]
Definition: espconn.h:73
uint8 local_ip[4]
Definition: espconn.h:84
sint8 ICACHE_FLASH_ATTR espconn_get_keepalive(struct espconn *espconn, uint8 level, void *optarg)
Definition: espconn.c:1173
bool ICACHE_FLASH_ATTR espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode)
Definition: espconn.c:186
#define AP_NETIF
Definition: espconn.h:48
espconn_reconnect_callback reconnect_callback
Definition: espconn.h:76
sint16 ICACHE_FLASH_ATTR espconn_sendto(struct espconn *espconn, uint8 *psent, uint16 length)
Definition: espconn.c:448
enum espconn_type type
Definition: espconn.h:101
sint8 espconn_udp_server(struct espconn *espconn)
Definition: espconn_udp.c:363
enum espconn_state state
Definition: espconn.h:103
unsigned char u8_t
Definition: cc.h:52
uint8 remote_ip[4]
Definition: espconn.h:85
#define TCP_MSS
Definition: opt.h:936
sint8 espconn_tcp_client(struct espconn *espconn)
Definition: espconn_tcp.c:878
espconn_connect_callback disconnect_callback
Definition: espconn.h:77
uint16 snd_queuelen
Definition: espconn.h:133
sint8 ICACHE_FLASH_ATTR espconn_regist_connectcb(struct espconn *espconn, espconn_connect_callback connect_cb)
Definition: espconn.c:751
#define ESPCONN_INPROGRESS
Definition: espconn.h:24
uint16 total_queuelen
Definition: espconn.h:134
espconn_recv_callback recv_callback
Definition: espconn.h:109
#define TCP_SND_QUEUELEN
Definition: opt.h:964
signed char sint8
Definition: c_types.h:47
sint8 ICACHE_FLASH_ATTR espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length)
Definition: espconn.c:368
uint8 ICACHE_FLASH_ATTR espconn_tcp_get_wnd(void)
Definition: espconn.c:483
#define espconn_keepalive_disable(pcb)
Definition: espconn_tcp.h:14
#define ESPCONN_AP
Definition: espconn.h:44
struct _espconn_buf * pnext
Definition: espconn.h:146
static list_node * plist
Definition: dhcpserver.c:34
sint8 ICACHE_FLASH_ATTR espconn_tcp_get_max_con_allow(struct espconn *espconn)
Definition: espconn.c:618
void ICACHE_FLASH_ATTR espconn_list_creat(espconn_msg **phead, espconn_msg *pinsert)
Definition: espconn.c:76
sint8 ICACHE_FLASH_ATTR espconn_abort(struct espconn *espconn)
Definition: espconn.c:972
sint8 ICACHE_FLASH_ATTR espconn_regist_time(struct espconn *espconn, uint32 interval, uint8 type_flag)
Definition: espconn.c:905
u32_t addr
Definition: ip_addr.h:45
struct espconn * pespconn
Definition: espconn.h:169
enum espconn_option espconn_opt
Definition: espconn.h:165
sint8 ICACHE_FLASH_ATTR espconn_tcp_set_max_con_allow(struct espconn *espconn, uint8 num)
Definition: espconn.c:640
#define espconn_keepalive_disabled(espconn)
Definition: espconn.h:200
espconn_sent_callback sent_callback
Definition: espconn.h:110
espconn_buf * pbuf
Definition: espconn.h:155
#define ESPCONN_STA
Definition: espconn.h:43
uint8 count_opt
Definition: espconn.h:171
void ICACHE_FLASH_ATTR espconn_copy_partial(struct espconn *pesp_dest, struct espconn *pesp_source)
Definition: espconn.c:46
sint8 ICACHE_FLASH_ATTR espconn_tcp_delete(struct espconn *pdeletecon)
Definition: espconn_tcp.c:1335
err_t espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
Definition: espconn_udp.c:81
int remote_port
Definition: espconn.h:90
struct __attribute__((packed))
Definition: captdns.c:53
#define IP4_ADDR(ipaddr, a, b, c, d)
Definition: ip_addr.h:139
#define ESPCONN_MEM
Definition: espconn.h:21