MeterLogger
Macros | Functions
espconn_udp.h File Reference
#include "lwip/app/espconn.h"
Include dependency graph for espconn_udp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ESPCONN_UDP_DEBUG   LWIP_DBG_OFF
 

Functions

sint8 espconn_udp_client (struct espconn *pespconn)
 
void espconn_udp_disconnect (espconn_msg *pdiscon)
 
sint8 espconn_udp_server (struct espconn *espconn)
 
err_t espconn_udp_sent (void *arg, uint8 *psent, uint16 length)
 
err_t espconn_udp_sendto (void *arg, uint8 *psent, uint16 length)
 

Macro Definition Documentation

◆ ESPCONN_UDP_DEBUG

#define ESPCONN_UDP_DEBUG   LWIP_DBG_OFF

Function Documentation

◆ espconn_udp_client()

sint8 espconn_udp_client ( struct espconn pespconn)

◆ espconn_udp_disconnect()

void espconn_udp_disconnect ( espconn_msg pdiscon)

Definition at line 338 of file espconn_udp.c.

References espconn_list_delete(), ICACHE_FLASH_ATTR, NULL, os_free, _comon_pkt::pcb, and _espconn_msg::pcommon.

Referenced by espconn_delete().

339 {
340  if (pdiscon == NULL) {
341  return;
342  }
343 
344  struct udp_pcb *upcb = pdiscon->pcommon.pcb;
345 
346  udp_disconnect(upcb);
347 
348  udp_remove(upcb);
349 
351 
352  os_free(pdiscon);
353  pdiscon = NULL;
354 }
void espconn_list_delete(espconn_msg **phead, espconn_msg *pdelete)
Definition: espconn.c:104
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
comon_pkt pcommon
Definition: espconn.h:170
#define os_free(s)
Definition: mem.h:40
espconn_msg * plink_active
Definition: espconn.c:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ espconn_udp_sendto()

err_t espconn_udp_sendto ( void *  arg,
uint8 psent,
uint16  length 
)

Definition at line 183 of file espconn_udp.c.

References _comon_pkt::cntr, default_interface, eagle_lwip_getif(), ERR_OK, ESPCONN_AP_STA, ESPCONN_ARG, espconn_data_sent(), ESPCONN_IF, ESPCONN_MEM, ESPCONN_RTE, ESPCONN_SENDTO, ESPCONN_UDP_DEBUG, ICACHE_FLASH_ATTR, IP4_ADDR, pbuf::len, LWIP_DEBUGF, netif_is_up, netif_set_default(), pbuf::next, NULL, pbuf::payload, pbuf_alloc(), pbuf_copy(), pbuf_free(), PBUF_RAM, PBUF_TRANSPORT, _comon_pkt::pcb, _espconn_msg::pcommon, _espconn_msg::pespconn, espconn::proto, _comon_pkt::ptrbuf, pbuf::ref, _esp_udp::remote_ip, _esp_udp::remote_port, espconn::udp, and wifi_get_opmode().

Referenced by espconn_data_sent(), and espconn_sendto().

184 {
185  espconn_msg *pudp_sent = arg;
186  struct udp_pcb *upcb = pudp_sent->pcommon.pcb;
187  struct espconn *pespconn = pudp_sent->pespconn;
188  struct pbuf *p, *q ,*p_temp;
189  struct ip_addr dst_ip;
190  u16_t dst_port;
191  u8_t *data = NULL;
192  u16_t cnt = 0;
193  u16_t datalen = 0;
194  u16_t i = 0;
195  err_t err;
196  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d %p\n", __LINE__, length, upcb));
197 
198  if (pudp_sent == NULL || upcb == NULL || psent == NULL || length == 0) {
199  return ESPCONN_ARG;
200  }
201 
202  if (1470 < length) {
203  datalen = 1470;
204  } else {
205  datalen = length;
206  }
207 
208  p = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
209  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));
210 
211  if (p != NULL) {
212  q = p;
213 
214  while (q != NULL) {
215  data = (u8_t *)q->payload;
216  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, data));
217 
218  for (i = 0; i < q->len; i++) {
219  data[i] = ((u8_t *) psent)[cnt++];
220  }
221 
222  q = q->next;
223  }
224  } else {
225  return ESPCONN_MEM;
226  }
227 
228  dst_port = pespconn->proto.udp->remote_port;
229  IP4_ADDR(&dst_ip, pespconn->proto.udp->remote_ip[0],
230  pespconn->proto.udp->remote_ip[1], pespconn->proto.udp->remote_ip[2],
231  pespconn->proto.udp->remote_ip[3]);
232  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %x %d\n", __LINE__, upcb->remote_ip, upcb->remote_port));
233 
234  struct netif *sta_netif = (struct netif *)eagle_lwip_getif(0x00);
235  struct netif *ap_netif = (struct netif *)eagle_lwip_getif(0x01);
236 
237  if(wifi_get_opmode() == ESPCONN_AP_STA && default_interface == ESPCONN_AP_STA && sta_netif != NULL && ap_netif != NULL)
238  {
239  if(netif_is_up(sta_netif) && netif_is_up(ap_netif) && \
240  ip_addr_isbroadcast(&upcb->remote_ip, sta_netif) && \
241  ip_addr_isbroadcast(&upcb->remote_ip, ap_netif)) {
242 
243  p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
244  if (pbuf_copy (p_temp,p) != ERR_OK) {
245  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sendto: copying to new pbuf failed\n"));
246  return ESPCONN_ARG;
247  }
248  netif_set_default(sta_netif);
249  err = udp_sendto(upcb, p_temp, &dst_ip, dst_port);
250  pbuf_free(p_temp);
251  netif_set_default(ap_netif);
252  }
253  }
254  err = udp_sendto(upcb, p, &dst_ip, dst_port);
255 
256  if (p->ref != 0) {
257  pbuf_free(p);
258  pudp_sent->pcommon.ptrbuf = psent + datalen;
259  pudp_sent->pcommon.cntr = length - datalen;
260  if (err == ERR_OK)
261  espconn_data_sent(pudp_sent, ESPCONN_SENDTO);
262 
263  if (err > 0)
264  return ESPCONN_IF;
265  return err;
266  } else {
267  pbuf_free(p);
268  return ESPCONN_RTE;
269  }
270 }
esp_udp * udp
Definition: espconn.h:106
uint8 default_interface
struct pbuf * next
Definition: pbuf.h:78
u16_t len
Definition: pbuf.h:93
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from) ICACHE_FLASH_ATTR
Definition: pbuf.c:930
#define ESPCONN_UDP_DEBUG
Definition: espconn_udp.h:5
#define ESPCONN_AP_STA
Definition: espconn.h:45
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
Definition: pbuf.h:58
struct netif * eagle_lwip_getif(uint8 index)
uint8 wifi_get_opmode(void)
#define ESPCONN_RTE
Definition: espconn.h:23
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
void netif_set_default(struct netif *netif) ICACHE_FLASH_ATTR
Definition: netif.c:431
#define ERR_OK
Definition: err.h:52
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
Definition: netif.h:139
int remote_port
Definition: espconn.h:82
uint16 cntr
Definition: espconn.h:158
u8_t pbuf_free(struct pbuf *p) ICACHE_FLASH_ATTR
Definition: pbuf.c:685
union espconn::@1 proto
#define ESPCONN_IF
Definition: espconn.h:33
unsigned char u8_t
Definition: cc.h:52
uint8 remote_ip[4]
Definition: espconn.h:85
void * payload
Definition: pbuf.h:81
#define netif_is_up(netif)
Definition: netif.h:286
static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg, enum send_opt opt)
Definition: espconn_udp.c:47
u16_t ref
Definition: pbuf.h:106
struct espconn * pespconn
Definition: espconn.h:169
uint8 * ptrbuf
Definition: espconn.h:157
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type) ICACHE_FLASH_ATTR
Definition: pbuf.c:234
unsigned short u16_t
Definition: cc.h:54
#define IP4_ADDR(ipaddr, a, b, c, d)
Definition: ip_addr.h:139
#define ESPCONN_MEM
Definition: espconn.h:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ espconn_udp_sent()

err_t espconn_udp_sent ( void *  arg,
uint8 psent,
uint16  length 
)

Definition at line 81 of file espconn_udp.c.

References _comon_pkt::cntr, default_interface, eagle_lwip_getif(), ERR_OK, ESPCONN_AP_STA, ESPCONN_ARG, espconn_data_sent(), ESPCONN_IF, ESPCONN_MEM, ESPCONN_RTE, ESPCONN_SEND, ESPCONN_UDP_DEBUG, ICACHE_FLASH_ATTR, IP4_ADDR, pbuf::len, LWIP_DEBUGF, netif_is_up, netif_set_default(), pbuf::next, NULL, pbuf::payload, pbuf_alloc(), pbuf_copy(), pbuf_free(), PBUF_RAM, PBUF_TRANSPORT, _comon_pkt::pcb, _espconn_msg::pcommon, _espconn_msg::pespconn, espconn::proto, _comon_pkt::ptrbuf, pbuf::ref, _esp_udp::remote_ip, _esp_udp::remote_port, espconn::udp, and wifi_get_opmode().

Referenced by espconn_data_sent(), and espconn_sent().

82 {
83  espconn_msg *pudp_sent = arg;
84  struct udp_pcb *upcb = pudp_sent->pcommon.pcb;
85  struct pbuf *p, *q ,*p_temp;
86  u8_t *data = NULL;
87  u16_t cnt = 0;
88  u16_t datalen = 0;
89  u16_t i = 0;
90  err_t err;
91  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d %p\n", __LINE__, length, upcb));
92 
93  if (pudp_sent == NULL || upcb == NULL || psent == NULL || length == 0) {
94  return ESPCONN_ARG;
95  }
96 
97  if (1470 < length) {
98  datalen = 1470;
99  } else {
100  datalen = length;
101  }
102 
103  p = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
104  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));
105 
106  if (p != NULL) {
107  q = p;
108 
109  while (q != NULL) {
110  data = (u8_t *)q->payload;
111  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, data));
112 
113  for (i = 0; i < q->len; i++) {
114  data[i] = ((u8_t *) psent)[cnt++];
115  }
116 
117  q = q->next;
118  }
119  } else {
120  return ESPCONN_MEM;
121  }
122 
123  upcb->remote_port = pudp_sent->pespconn->proto.udp->remote_port;
124  IP4_ADDR(&upcb->remote_ip, pudp_sent->pespconn->proto.udp->remote_ip[0],
125  pudp_sent->pespconn->proto.udp->remote_ip[1],
126  pudp_sent->pespconn->proto.udp->remote_ip[2],
127  pudp_sent->pespconn->proto.udp->remote_ip[3]);
128 
129  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %x %d\n", __LINE__, upcb->remote_ip, upcb->remote_port));
130 
131  struct netif *sta_netif = (struct netif *)eagle_lwip_getif(0x00);
132  struct netif *ap_netif = (struct netif *)eagle_lwip_getif(0x01);
133 
134  if(wifi_get_opmode() == ESPCONN_AP_STA && default_interface == ESPCONN_AP_STA && sta_netif != NULL && ap_netif != NULL)
135  {
136  if(netif_is_up(sta_netif) && netif_is_up(ap_netif) && \
137  ip_addr_isbroadcast(&upcb->remote_ip, sta_netif) && \
138  ip_addr_isbroadcast(&upcb->remote_ip, ap_netif)) {
139 
140  p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
141  if (pbuf_copy (p_temp,p) != ERR_OK) {
142  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent: copying to new pbuf failed\n"));
143  return ESPCONN_ARG;
144  }
145  netif_set_default(sta_netif);
146  err = udp_send(upcb, p_temp);
147  pbuf_free(p_temp);
148  netif_set_default(ap_netif);
149  }
150  }
151  err = udp_send(upcb, p);
152 
153  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d\n", __LINE__, err));
154 
155  if (p->ref != 0) {
156  LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));
157  pbuf_free(p);
158  pudp_sent->pcommon.ptrbuf = psent + datalen;
159  pudp_sent->pcommon.cntr = length - datalen;
160  espconn_data_sent(pudp_sent, ESPCONN_SEND);
161  if (err > 0)
162  return ESPCONN_IF;
163  return err;
164  } else {
165  pbuf_free(p);
166  return ESPCONN_RTE;
167  }
168 }
esp_udp * udp
Definition: espconn.h:106
uint8 default_interface
struct pbuf * next
Definition: pbuf.h:78
u16_t len
Definition: pbuf.h:93
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from) ICACHE_FLASH_ATTR
Definition: pbuf.c:930
#define ESPCONN_UDP_DEBUG
Definition: espconn_udp.h:5
#define ESPCONN_AP_STA
Definition: espconn.h:45
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
Definition: pbuf.h:58
struct netif * eagle_lwip_getif(uint8 index)
uint8 wifi_get_opmode(void)
#define ESPCONN_RTE
Definition: espconn.h:23
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
void netif_set_default(struct netif *netif) ICACHE_FLASH_ATTR
Definition: netif.c:431
#define ERR_OK
Definition: err.h:52
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
Definition: netif.h:139
int remote_port
Definition: espconn.h:82
uint16 cntr
Definition: espconn.h:158
u8_t pbuf_free(struct pbuf *p) ICACHE_FLASH_ATTR
Definition: pbuf.c:685
union espconn::@1 proto
#define ESPCONN_IF
Definition: espconn.h:33
unsigned char u8_t
Definition: cc.h:52
uint8 remote_ip[4]
Definition: espconn.h:85
void * payload
Definition: pbuf.h:81
#define netif_is_up(netif)
Definition: netif.h:286
static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg, enum send_opt opt)
Definition: espconn_udp.c:47
u16_t ref
Definition: pbuf.h:106
struct espconn * pespconn
Definition: espconn.h:169
uint8 * ptrbuf
Definition: espconn.h:157
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type) ICACHE_FLASH_ATTR
Definition: pbuf.c:234
unsigned short u16_t
Definition: cc.h:54
#define IP4_ADDR(ipaddr, a, b, c, d)
Definition: ip_addr.h:139
#define ESPCONN_MEM
Definition: espconn.h:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ espconn_udp_server()

sint8 espconn_udp_server ( struct espconn espconn)

Definition at line 363 of file espconn_udp.c.

References espconn_list_creat(), ESPCONN_MEM, ESPCONN_OK, espconn_udp_recv(), ICACHE_FLASH_ATTR, IP_ADDR_ANY, _esp_udp::local_port, NULL, os_zalloc, _comon_pkt::pcb, _espconn_msg::pcommon, _espconn_msg::pespconn, espconn::proto, and espconn::udp.

Referenced by espconn_create().

364 {
365  struct udp_pcb *upcb = NULL;
366  espconn_msg *pserver = NULL;
367  upcb = udp_new();
368 
369  if (upcb == NULL) {
370  return ESPCONN_MEM;
371  } else {
372  pserver = (espconn_msg *)os_zalloc(sizeof(espconn_msg));
373 
374  if (pserver == NULL) {
375  udp_remove(upcb);
376  return ESPCONN_MEM;
377  }
378 
379  pserver->pcommon.pcb = upcb;
380  pserver->pespconn = pespconn;
381  espconn_list_creat(&plink_active, pserver);
382  udp_bind(upcb, IP_ADDR_ANY, pserver->pespconn->proto.udp->local_port);
383  udp_recv(upcb, espconn_udp_recv, (void *)pserver);
384  return ESPCONN_OK;
385  }
386 }
esp_udp * udp
Definition: espconn.h:106
int local_port
Definition: espconn.h:83
static void ICACHE_FLASH_ATTR espconn_udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
Definition: espconn_udp.c:283
#define NULL
Definition: def.h:47
void * pcb
Definition: espconn.h:150
#define ESPCONN_OK
Definition: espconn.h:20
#define os_zalloc(s)
Definition: mem.h:44
void espconn_list_creat(espconn_msg **phead, espconn_msg *pinsert)
Definition: espconn.c:76
comon_pkt pcommon
Definition: espconn.h:170
#define IP_ADDR_ANY
Definition: ip_addr.h:92
union espconn::@1 proto
struct espconn * pespconn
Definition: espconn.h:169
espconn_msg * plink_active
Definition: espconn.c:32
#define ESPCONN_MEM
Definition: espconn.h:21
Here is the call graph for this function:
Here is the caller graph for this function: