1 /**
2 * @file
3 * Sequential API Main thread module
4 *
5 */
6
7 /*
8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 * OF SUCH DAMAGE.
32 *
33 * This file is part of the lwIP TCP/IP stack.
34 *
35 * Author: Adam Dunkels <adam@sics.se>
36 *
37 */
38
39 #include "lwip/opt.h"
40
41 #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
42
43 #include "lwip/priv/tcpip_priv.h"
44 #include "lwip/sys.h"
45 #include "lwip/memp.h"
46 #include "lwip/mem.h"
47 #include "lwip/init.h"
48 #include "lwip/ip.h"
49 #include "lwip/pbuf.h"
50 #include "lwip/etharp.h"
51 #include "netif/ethernet.h"
52 #if LWIP_PACKET
53 #include "lwip/af_packet.h"
54 #endif
55
56 #define TCPIP_MSG_VAR_REF(name) API_VAR_REF(name)
57 #define TCPIP_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct tcpip_msg, name)
58 #define TCPIP_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM)
59 #define TCPIP_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_TCPIP_MSG_API, name)
60
61 /* global variables */
62 static tcpip_init_done_fn tcpip_init_done;
63 static void *tcpip_init_done_arg;
64 static sys_mbox_t mbox;
65
66 #if LWIP_TCPIP_CORE_LOCKING
67 /** The global semaphore to lock the stack. */
68 sys_mutex_t lock_tcpip_core;
69 #endif /* LWIP_TCPIP_CORE_LOCKING */
70
71 #if LWIP_TIMERS
72 /* wait for a message, timeouts are processed while waiting */
73 #define TCPIP_MBOX_FETCH(mbox, msg) sys_timeouts_mbox_fetch(mbox, msg)
74 #else /* LWIP_TIMERS */
75 /* wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
76 #define TCPIP_MBOX_FETCH(mbox, msg) sys_mbox_fetch(mbox, msg)
77 #endif /* LWIP_TIMERS */
78
79 /**
80 * The main lwIP thread. This thread has exclusive access to lwIP core functions
81 * (unless access to them is not locked). Other threads communicate with this
82 * thread using message boxes.
83 *
84 * It also starts all the timers to make sure they are running in the right
85 * thread context.
86 *
87 * @param arg unused argument
88 */
89 static void
tcpip_thread(void * arg)90 tcpip_thread(void *arg)
91 {
92 struct tcpip_msg *msg;
93 LWIP_UNUSED_ARG(arg);
94
95 if (tcpip_init_done != NULL) {
96 tcpip_init_done(tcpip_init_done_arg);
97 }
98
99 LOCK_TCPIP_CORE();
100 while (1) { /* MAIN Loop */
101 UNLOCK_TCPIP_CORE();
102 LWIP_TCPIP_THREAD_ALIVE();
103 /* wait for a message, timeouts are processed while waiting */
104 TCPIP_MBOX_FETCH(&mbox, (void **)&msg);
105 LOCK_TCPIP_CORE();
106 if (msg == NULL) {
107 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: NULL\n"));
108 LWIP_ASSERT("tcpip_thread: invalid message", 0);
109 continue;
110 }
111 switch (msg->type) {
112 #if !LWIP_TCPIP_CORE_LOCKING
113 case TCPIP_MSG_API:
114 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
115 msg->msg.api_msg.function(msg->msg.api_msg.msg);
116 break;
117 case TCPIP_MSG_API_CALL:
118 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API CALL message %p\n", (void *)msg));
119 msg->msg.api_call.arg->err = msg->msg.api_call.function(msg->msg.api_call.arg);
120 sys_sem_signal(msg->msg.api_call.sem);
121 break;
122 #endif /* !LWIP_TCPIP_CORE_LOCKING */
123
124 #if !LWIP_TCPIP_CORE_LOCKING_INPUT
125 case TCPIP_MSG_INPKT:
126 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg));
127 msg->msg.inp.input_fn(msg->msg.inp.p, msg->msg.inp.netif);
128 memp_free(MEMP_TCPIP_MSG_INPKT, msg);
129 break;
130 #endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */
131
132 #if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS
133 case TCPIP_MSG_TIMEOUT:
134 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg));
135 sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg);
136 memp_free(MEMP_TCPIP_MSG_API, msg);
137 break;
138 case TCPIP_MSG_UNTIMEOUT:
139 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg));
140 sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg);
141 memp_free(MEMP_TCPIP_MSG_API, msg);
142 break;
143 #endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */
144
145 case TCPIP_MSG_CALLBACK:
146 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
147 msg->msg.cb.function(msg->msg.cb.ctx);
148 memp_free(MEMP_TCPIP_MSG_API, msg);
149 break;
150
151 case TCPIP_MSG_CALLBACK_STATIC:
152 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK_STATIC %p\n", (void *)msg));
153 msg->msg.cb.function(msg->msg.cb.ctx);
154 break;
155 #ifdef LWIP_NETIF_DRV
156 case TCPIP_MSG_DRV:
157 LWIP_DEBUGF(NETIF_DEBUG, ("tcpip_thread: DRV %p\n", (void *)msg));
158 msg->msg.drv.drv_fn(msg->msg.drv.netif, msg->msg.drv.event);
159 memp_free(MEMP_NETIF_DRV_MSG, msg);
160 break;
161 #endif
162 default:
163 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", msg->type));
164 LWIP_ASSERT("tcpip_thread: invalid message", 0);
165 break;
166 }
167 }
168 }
169
170 #ifdef LWIP_NETIF_DRV
171 /**
172 * Pass a received packet to tcpip_thread for input processing
173 *
174 * @param p the received packet
175 * @param inp the network interface on which the packet was received
176 * @param input_fn input function to call
177 */
178 err_t
tcpip_signal_netif_event(struct netif * inp,u32_t event,netif_drv_fn drv_fn)179 tcpip_signal_netif_event(struct netif *inp, u32_t event, netif_drv_fn drv_fn)
180 {
181 struct tcpip_msg *msg;
182
183 LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
184
185 msg = (struct tcpip_msg *)memp_malloc(MEMP_NETIF_DRV_MSG);
186 if (msg == NULL) {
187 return ERR_MEM;
188 }
189
190 msg->type = TCPIP_MSG_DRV;
191 //msg->msg.inp.p = p;
192 msg->msg.drv.netif = inp;
193 msg->msg.drv.event = event;
194 msg->msg.drv.drv_fn = drv_fn;
195 if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
196 memp_free(MEMP_NETIF_DRV_MSG, msg);
197 return ERR_MEM;
198 }
199 return ERR_OK;
200 }
201 #endif
202
203 /**
204 * Pass a received packet to tcpip_thread for input processing
205 *
206 * @param p the received packet
207 * @param inp the network interface on which the packet was received
208 * @param input_fn input function to call
209 */
210 err_t
tcpip_inpkt(struct pbuf * p,struct netif * inp,netif_input_fn input_fn)211 tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
212 {
213 #if LWIP_TCPIP_CORE_LOCKING_INPUT
214 err_t ret;
215 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_inpkt: PACKET %p/%p\n", (void *)p, (void *)inp));
216 LOCK_TCPIP_CORE();
217 ret = input_fn(p, inp);
218 UNLOCK_TCPIP_CORE();
219 return ret;
220 #else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
221 struct tcpip_msg *msg;
222
223 LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
224
225 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT);
226 if (msg == NULL) {
227 return ERR_MEM;
228 }
229
230 msg->type = TCPIP_MSG_INPKT;
231 msg->msg.inp.p = p;
232 msg->msg.inp.netif = inp;
233 msg->msg.inp.input_fn = input_fn;
234 if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
235 memp_free(MEMP_TCPIP_MSG_INPKT, msg);
236 return ERR_MEM;
237 }
238 return ERR_OK;
239 #endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
240 }
241
242 /**
243 * @ingroup lwip_os
244 * Pass a received packet to tcpip_thread for input processing with
245 * ethernet_input or ip_input. Don't call directly, pass to netif_add()
246 * and call netif->input().
247 *
248 * @param p the received packet, p->payload pointing to the Ethernet header or
249 * to an IP header (if inp doesn't have NETIF_FLAG_ETHARP or
250 * NETIF_FLAG_ETHERNET flags)
251 * @param inp the network interface on which the packet was received
252 */
253 err_t
tcpip_input(struct pbuf * p,struct netif * inp)254 tcpip_input(struct pbuf *p, struct netif *inp)
255 {
256 #if LWIP_PACKET
257 /* packet type data just return ok. */
258 if(!packet_input_hook(p, inp))
259 {
260 pbuf_free(p);
261 return 0;
262 }
263 else
264 #endif
265 #if LWIP_ETHERNET
266 if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
267 return tcpip_inpkt(p, inp, ethernet_input);
268 } else
269 #endif /* LWIP_ETHERNET */
270 return tcpip_inpkt(p, inp, ip_input);
271 }
272
273 /**
274 * Call a specific function in the thread context of
275 * tcpip_thread for easy access synchronization.
276 * A function called in that way may access lwIP core code
277 * without fearing concurrent access.
278 *
279 * @param function the function to call
280 * @param ctx parameter passed to f
281 * @param block 1 to block until the request is posted, 0 to non-blocking mode
282 * @return ERR_OK if the function was called, another err_t if not
283 */
284 err_t
tcpip_callback_with_block(tcpip_callback_fn function,void * ctx,u8_t block)285 tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
286 {
287 struct tcpip_msg *msg;
288
289 LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
290
291 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
292 if (msg == NULL) {
293 return ERR_MEM;
294 }
295
296 msg->type = TCPIP_MSG_CALLBACK;
297 msg->msg.cb.function = function;
298 msg->msg.cb.ctx = ctx;
299 if (block) {
300 sys_mbox_post(&mbox, msg);
301 } else {
302 if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
303 memp_free(MEMP_TCPIP_MSG_API, msg);
304 return ERR_MEM;
305 }
306 }
307 return ERR_OK;
308 }
309
310 #if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS
311 /**
312 * call sys_timeout in tcpip_thread
313 *
314 * @param msecs time in milliseconds for timeout
315 * @param h function to be called on timeout
316 * @param arg argument to pass to timeout function h
317 * @return ERR_MEM on memory error, ERR_OK otherwise
318 */
319 err_t
tcpip_timeout(u32_t msecs,sys_timeout_handler h,void * arg)320 tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
321 {
322 struct tcpip_msg *msg;
323
324 LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
325
326 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
327 if (msg == NULL) {
328 return ERR_MEM;
329 }
330
331 msg->type = TCPIP_MSG_TIMEOUT;
332 msg->msg.tmo.msecs = msecs;
333 msg->msg.tmo.h = h;
334 msg->msg.tmo.arg = arg;
335 sys_mbox_post(&mbox, msg);
336 return ERR_OK;
337 }
338
339 /**
340 * call sys_untimeout in tcpip_thread
341 *
342 * @param h function to be called on timeout
343 * @param arg argument to pass to timeout function h
344 * @return ERR_MEM on memory error, ERR_OK otherwise
345 */
346 err_t
tcpip_untimeout(sys_timeout_handler h,void * arg)347 tcpip_untimeout(sys_timeout_handler h, void *arg)
348 {
349 struct tcpip_msg *msg;
350
351 LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
352
353 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
354 if (msg == NULL) {
355 return ERR_MEM;
356 }
357
358 msg->type = TCPIP_MSG_UNTIMEOUT;
359 msg->msg.tmo.h = h;
360 msg->msg.tmo.arg = arg;
361 sys_mbox_post(&mbox, msg);
362 return ERR_OK;
363 }
364 #endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */
365
366
367 /**
368 * Sends a message to TCPIP thread to call a function. Caller thread blocks on
369 * on a provided semaphore, which ist NOT automatically signalled by TCPIP thread,
370 * this has to be done by the user.
371 * It is recommended to use LWIP_TCPIP_CORE_LOCKING since this is the way
372 * with least runtime overhead.
373 *
374 * @param fn function to be called from TCPIP thread
375 * @param apimsg argument to API function
376 * @param sem semaphore to wait on
377 * @return ERR_OK if the function was called, another err_t if not
378 */
379 err_t
tcpip_send_msg_wait_sem(tcpip_callback_fn fn,void * apimsg,sys_sem_t * sem)380 tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem)
381 {
382 #if LWIP_TCPIP_CORE_LOCKING
383 LWIP_UNUSED_ARG(sem);
384 LOCK_TCPIP_CORE();
385 fn(apimsg);
386 UNLOCK_TCPIP_CORE();
387 return ERR_OK;
388 #else /* LWIP_TCPIP_CORE_LOCKING */
389 TCPIP_MSG_VAR_DECLARE(msg);
390
391 LWIP_ASSERT("semaphore not initialized", sys_sem_valid(sem));
392 LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
393
394 TCPIP_MSG_VAR_ALLOC(msg);
395 TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API;
396 TCPIP_MSG_VAR_REF(msg).msg.api_msg.function = fn;
397 TCPIP_MSG_VAR_REF(msg).msg.api_msg.msg = apimsg;
398 sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg));
399 sys_arch_sem_wait(sem, 0);
400 TCPIP_MSG_VAR_FREE(msg);
401 return ERR_OK;
402 #endif /* LWIP_TCPIP_CORE_LOCKING */
403 }
404
405 /**
406 * Synchronously calls function in TCPIP thread and waits for its completion.
407 * It is recommended to use LWIP_TCPIP_CORE_LOCKING (preferred) or
408 * LWIP_NETCONN_SEM_PER_THREAD.
409 * If not, a semaphore is created and destroyed on every call which is usually
410 * an expensive/slow operation.
411 * @param fn Function to call
412 * @param call Call parameters
413 * @return Return value from tcpip_api_call_fn
414 */
415 err_t
tcpip_api_call(tcpip_api_call_fn fn,struct tcpip_api_call_data * call)416 tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
417 {
418 #if LWIP_TCPIP_CORE_LOCKING
419 err_t err;
420 LOCK_TCPIP_CORE();
421 err = fn(call);
422 UNLOCK_TCPIP_CORE();
423 return err;
424 #else /* LWIP_TCPIP_CORE_LOCKING */
425 TCPIP_MSG_VAR_DECLARE(msg);
426
427 #if !LWIP_NETCONN_SEM_PER_THREAD
428 err_t err = sys_sem_new(&call->sem, 0);
429 if (err != ERR_OK) {
430 return err;
431 }
432 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
433
434 LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
435
436 TCPIP_MSG_VAR_ALLOC(msg);
437 TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API_CALL;
438 TCPIP_MSG_VAR_REF(msg).msg.api_call.arg = call;
439 TCPIP_MSG_VAR_REF(msg).msg.api_call.function = fn;
440 #if LWIP_NETCONN_SEM_PER_THREAD
441 TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = LWIP_NETCONN_THREAD_SEM_GET();
442 #else /* LWIP_NETCONN_SEM_PER_THREAD */
443 TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = &call->sem;
444 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
445 sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg));
446 sys_arch_sem_wait(TCPIP_MSG_VAR_REF(msg).msg.api_call.sem, 0);
447 TCPIP_MSG_VAR_FREE(msg);
448
449 #if !LWIP_NETCONN_SEM_PER_THREAD
450 sys_sem_free(&call->sem);
451 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
452
453 return call->err;
454 #endif /* LWIP_TCPIP_CORE_LOCKING */
455 }
456
457 /**
458 * Allocate a structure for a static callback message and initialize it.
459 * This is intended to be used to send "static" messages from interrupt context.
460 *
461 * @param function the function to call
462 * @param ctx parameter passed to function
463 * @return a struct pointer to pass to tcpip_trycallback().
464 */
465 struct tcpip_callback_msg*
tcpip_callbackmsg_new(tcpip_callback_fn function,void * ctx)466 tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx)
467 {
468 struct tcpip_msg *msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
469 if (msg == NULL) {
470 return NULL;
471 }
472 msg->type = TCPIP_MSG_CALLBACK_STATIC;
473 msg->msg.cb.function = function;
474 msg->msg.cb.ctx = ctx;
475 return (struct tcpip_callback_msg*)msg;
476 }
477
478 /**
479 * Free a callback message allocated by tcpip_callbackmsg_new().
480 *
481 * @param msg the message to free
482 */
483 void
tcpip_callbackmsg_delete(struct tcpip_callback_msg * msg)484 tcpip_callbackmsg_delete(struct tcpip_callback_msg* msg)
485 {
486 memp_free(MEMP_TCPIP_MSG_API, msg);
487 }
488
489 /**
490 * Try to post a callback-message to the tcpip_thread mbox
491 * This is intended to be used to send "static" messages from interrupt context.
492 *
493 * @param msg pointer to the message to post
494 * @return sys_mbox_trypost() return code
495 */
496 err_t
tcpip_trycallback(struct tcpip_callback_msg * msg)497 tcpip_trycallback(struct tcpip_callback_msg* msg)
498 {
499 LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox));
500 return sys_mbox_trypost(&mbox, msg);
501 }
502
503 /**
504 * @ingroup lwip_os
505 * Initialize this module:
506 * - initialize all sub modules
507 * - start the tcpip_thread
508 *
509 * @param initfunc a function to call when tcpip_thread is running and finished initializing
510 * @param arg argument to pass to initfunc
511 */
512 void
tcpip_init(tcpip_init_done_fn initfunc,void * arg)513 tcpip_init(tcpip_init_done_fn initfunc, void *arg)
514 {
515 lwip_init();
516
517 tcpip_init_done = initfunc;
518 tcpip_init_done_arg = arg;
519 if (sys_mbox_new(&mbox, TCPIP_MBOX_SIZE) != ERR_OK) {
520 LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
521 }
522 #if LWIP_TCPIP_CORE_LOCKING
523 if (sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
524 LWIP_ASSERT("failed to create lock_tcpip_core", 0);
525 }
526 #endif /* LWIP_TCPIP_CORE_LOCKING */
527
528 sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
529 }
530
531 /**
532 * Simple callback function used with tcpip_callback to free a pbuf
533 * (pbuf_free has a wrong signature for tcpip_callback)
534 *
535 * @param p The pbuf (chain) to be dereferenced.
536 */
537 static void
pbuf_free_int(void * p)538 pbuf_free_int(void *p)
539 {
540 struct pbuf *q = (struct pbuf *)p;
541 pbuf_free(q);
542 }
543
544 /**
545 * A simple wrapper function that allows you to free a pbuf from interrupt context.
546 *
547 * @param p The pbuf (chain) to be dereferenced.
548 * @return ERR_OK if callback could be enqueued, an err_t if not
549 */
550 err_t
pbuf_free_callback(struct pbuf * p)551 pbuf_free_callback(struct pbuf *p)
552 {
553 return tcpip_callback_with_block(pbuf_free_int, p, 0);
554 }
555
556 /**
557 * A simple wrapper function that allows you to free heap memory from
558 * interrupt context.
559 *
560 * @param m the heap memory to free
561 * @return ERR_OK if callback could be enqueued, an err_t if not
562 */
563 err_t
mem_free_callback(void * m)564 mem_free_callback(void *m)
565 {
566 return tcpip_callback_with_block(mem_free, m, 0);
567 }
568
569 #endif /* !NO_SYS */
570