Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 5:3f93dd1d4cb3 1 /**
sam_grove 5:3f93dd1d4cb3 2 * @file
sam_grove 5:3f93dd1d4cb3 3 * Sequential API Main thread module
sam_grove 5:3f93dd1d4cb3 4 *
sam_grove 5:3f93dd1d4cb3 5 */
sam_grove 5:3f93dd1d4cb3 6
sam_grove 5:3f93dd1d4cb3 7 /*
sam_grove 5:3f93dd1d4cb3 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
sam_grove 5:3f93dd1d4cb3 9 * All rights reserved.
sam_grove 5:3f93dd1d4cb3 10 *
sam_grove 5:3f93dd1d4cb3 11 * Redistribution and use in source and binary forms, with or without modification,
sam_grove 5:3f93dd1d4cb3 12 * are permitted provided that the following conditions are met:
sam_grove 5:3f93dd1d4cb3 13 *
sam_grove 5:3f93dd1d4cb3 14 * 1. Redistributions of source code must retain the above copyright notice,
sam_grove 5:3f93dd1d4cb3 15 * this list of conditions and the following disclaimer.
sam_grove 5:3f93dd1d4cb3 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
sam_grove 5:3f93dd1d4cb3 17 * this list of conditions and the following disclaimer in the documentation
sam_grove 5:3f93dd1d4cb3 18 * and/or other materials provided with the distribution.
sam_grove 5:3f93dd1d4cb3 19 * 3. The name of the author may not be used to endorse or promote products
sam_grove 5:3f93dd1d4cb3 20 * derived from this software without specific prior written permission.
sam_grove 5:3f93dd1d4cb3 21 *
sam_grove 5:3f93dd1d4cb3 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
sam_grove 5:3f93dd1d4cb3 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
sam_grove 5:3f93dd1d4cb3 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
sam_grove 5:3f93dd1d4cb3 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sam_grove 5:3f93dd1d4cb3 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
sam_grove 5:3f93dd1d4cb3 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
sam_grove 5:3f93dd1d4cb3 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
sam_grove 5:3f93dd1d4cb3 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sam_grove 5:3f93dd1d4cb3 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
sam_grove 5:3f93dd1d4cb3 31 * OF SUCH DAMAGE.
sam_grove 5:3f93dd1d4cb3 32 *
sam_grove 5:3f93dd1d4cb3 33 * This file is part of the lwIP TCP/IP stack.
sam_grove 5:3f93dd1d4cb3 34 *
sam_grove 5:3f93dd1d4cb3 35 * Author: Adam Dunkels <adam@sics.se>
sam_grove 5:3f93dd1d4cb3 36 *
sam_grove 5:3f93dd1d4cb3 37 */
sam_grove 5:3f93dd1d4cb3 38
sam_grove 5:3f93dd1d4cb3 39 #include "lwip/opt.h"
sam_grove 5:3f93dd1d4cb3 40
sam_grove 5:3f93dd1d4cb3 41 #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
sam_grove 5:3f93dd1d4cb3 42
sam_grove 5:3f93dd1d4cb3 43 #include "lwip/sys.h"
sam_grove 5:3f93dd1d4cb3 44 #include "lwip/memp.h"
sam_grove 5:3f93dd1d4cb3 45 #include "lwip/mem.h"
sam_grove 5:3f93dd1d4cb3 46 #include "lwip/pbuf.h"
sam_grove 5:3f93dd1d4cb3 47 #include "lwip/tcpip.h"
sam_grove 5:3f93dd1d4cb3 48 #include "lwip/init.h"
sam_grove 5:3f93dd1d4cb3 49 #include "netif/etharp.h"
sam_grove 5:3f93dd1d4cb3 50 #include "netif/ppp_oe.h"
sam_grove 5:3f93dd1d4cb3 51
sam_grove 5:3f93dd1d4cb3 52 /* global variables */
sam_grove 5:3f93dd1d4cb3 53 static tcpip_init_done_fn tcpip_init_done;
sam_grove 5:3f93dd1d4cb3 54 static void *tcpip_init_done_arg;
sam_grove 5:3f93dd1d4cb3 55 static sys_mbox_t mbox;
sam_grove 5:3f93dd1d4cb3 56
sam_grove 5:3f93dd1d4cb3 57 #if LWIP_TCPIP_CORE_LOCKING
sam_grove 5:3f93dd1d4cb3 58 /** The global semaphore to lock the stack. */
sam_grove 5:3f93dd1d4cb3 59 sys_mutex_t lock_tcpip_core;
sam_grove 5:3f93dd1d4cb3 60 #endif /* LWIP_TCPIP_CORE_LOCKING */
sam_grove 5:3f93dd1d4cb3 61
sam_grove 5:3f93dd1d4cb3 62
sam_grove 5:3f93dd1d4cb3 63 /**
sam_grove 5:3f93dd1d4cb3 64 * The main lwIP thread. This thread has exclusive access to lwIP core functions
sam_grove 5:3f93dd1d4cb3 65 * (unless access to them is not locked). Other threads communicate with this
sam_grove 5:3f93dd1d4cb3 66 * thread using message boxes.
sam_grove 5:3f93dd1d4cb3 67 *
sam_grove 5:3f93dd1d4cb3 68 * It also starts all the timers to make sure they are running in the right
sam_grove 5:3f93dd1d4cb3 69 * thread context.
sam_grove 5:3f93dd1d4cb3 70 *
sam_grove 5:3f93dd1d4cb3 71 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 72 */
sam_grove 5:3f93dd1d4cb3 73 static void
sam_grove 5:3f93dd1d4cb3 74 tcpip_thread(void *arg)
sam_grove 5:3f93dd1d4cb3 75 {
sam_grove 5:3f93dd1d4cb3 76 struct tcpip_msg *msg;
sam_grove 5:3f93dd1d4cb3 77 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 78
sam_grove 5:3f93dd1d4cb3 79 if (tcpip_init_done != NULL) {
sam_grove 5:3f93dd1d4cb3 80 tcpip_init_done(tcpip_init_done_arg);
sam_grove 5:3f93dd1d4cb3 81 }
sam_grove 5:3f93dd1d4cb3 82
sam_grove 5:3f93dd1d4cb3 83 LOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 84 while (1) { /* MAIN Loop */
sam_grove 5:3f93dd1d4cb3 85 UNLOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 86 LWIP_TCPIP_THREAD_ALIVE();
sam_grove 5:3f93dd1d4cb3 87 /* wait for a message, timeouts are processed while waiting */
sam_grove 5:3f93dd1d4cb3 88 sys_timeouts_mbox_fetch(&mbox, (void **)&msg);
sam_grove 5:3f93dd1d4cb3 89 LOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 90 switch (msg->type) {
sam_grove 5:3f93dd1d4cb3 91 #if LWIP_NETCONN
sam_grove 5:3f93dd1d4cb3 92 case TCPIP_MSG_API:
sam_grove 5:3f93dd1d4cb3 93 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
sam_grove 5:3f93dd1d4cb3 94 msg->msg.apimsg->function(&(msg->msg.apimsg->msg));
sam_grove 5:3f93dd1d4cb3 95 break;
sam_grove 5:3f93dd1d4cb3 96 #endif /* LWIP_NETCONN */
sam_grove 5:3f93dd1d4cb3 97
sam_grove 5:3f93dd1d4cb3 98 #if !LWIP_TCPIP_CORE_LOCKING_INPUT
sam_grove 5:3f93dd1d4cb3 99 case TCPIP_MSG_INPKT:
sam_grove 5:3f93dd1d4cb3 100 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg));
sam_grove 5:3f93dd1d4cb3 101 #if LWIP_ETHERNET
sam_grove 5:3f93dd1d4cb3 102 if (msg->msg.inp.netif->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
sam_grove 5:3f93dd1d4cb3 103 ethernet_input(msg->msg.inp.p, msg->msg.inp.netif);
sam_grove 5:3f93dd1d4cb3 104 } else
sam_grove 5:3f93dd1d4cb3 105 #endif /* LWIP_ETHERNET */
sam_grove 5:3f93dd1d4cb3 106 {
sam_grove 5:3f93dd1d4cb3 107 ip_input(msg->msg.inp.p, msg->msg.inp.netif);
sam_grove 5:3f93dd1d4cb3 108 }
sam_grove 5:3f93dd1d4cb3 109 memp_free(MEMP_TCPIP_MSG_INPKT, msg);
sam_grove 5:3f93dd1d4cb3 110 break;
sam_grove 5:3f93dd1d4cb3 111 #endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
sam_grove 5:3f93dd1d4cb3 112
sam_grove 5:3f93dd1d4cb3 113 #if LWIP_NETIF_API
sam_grove 5:3f93dd1d4cb3 114 case TCPIP_MSG_NETIFAPI:
sam_grove 5:3f93dd1d4cb3 115 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Netif API message %p\n", (void *)msg));
sam_grove 5:3f93dd1d4cb3 116 msg->msg.netifapimsg->function(&(msg->msg.netifapimsg->msg));
sam_grove 5:3f93dd1d4cb3 117 break;
sam_grove 5:3f93dd1d4cb3 118 #endif /* LWIP_NETIF_API */
sam_grove 5:3f93dd1d4cb3 119
sam_grove 5:3f93dd1d4cb3 120 case TCPIP_MSG_CALLBACK:
sam_grove 5:3f93dd1d4cb3 121 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
sam_grove 5:3f93dd1d4cb3 122 msg->msg.cb.function(msg->msg.cb.ctx);
sam_grove 5:3f93dd1d4cb3 123 memp_free(MEMP_TCPIP_MSG_API, msg);
sam_grove 5:3f93dd1d4cb3 124 break;
sam_grove 5:3f93dd1d4cb3 125
sam_grove 5:3f93dd1d4cb3 126 #if LWIP_TCPIP_TIMEOUT
sam_grove 5:3f93dd1d4cb3 127 case TCPIP_MSG_TIMEOUT:
sam_grove 5:3f93dd1d4cb3 128 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg));
sam_grove 5:3f93dd1d4cb3 129 sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg);
sam_grove 5:3f93dd1d4cb3 130 memp_free(MEMP_TCPIP_MSG_API, msg);
sam_grove 5:3f93dd1d4cb3 131 break;
sam_grove 5:3f93dd1d4cb3 132 case TCPIP_MSG_UNTIMEOUT:
sam_grove 5:3f93dd1d4cb3 133 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg));
sam_grove 5:3f93dd1d4cb3 134 sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg);
sam_grove 5:3f93dd1d4cb3 135 memp_free(MEMP_TCPIP_MSG_API, msg);
sam_grove 5:3f93dd1d4cb3 136 break;
sam_grove 5:3f93dd1d4cb3 137 #endif /* LWIP_TCPIP_TIMEOUT */
sam_grove 5:3f93dd1d4cb3 138
sam_grove 5:3f93dd1d4cb3 139 default:
sam_grove 5:3f93dd1d4cb3 140 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", msg->type));
sam_grove 5:3f93dd1d4cb3 141 LWIP_ASSERT("tcpip_thread: invalid message", 0);
sam_grove 5:3f93dd1d4cb3 142 break;
sam_grove 5:3f93dd1d4cb3 143 }
sam_grove 5:3f93dd1d4cb3 144 }
sam_grove 5:3f93dd1d4cb3 145 }
sam_grove 5:3f93dd1d4cb3 146
sam_grove 5:3f93dd1d4cb3 147 /**
sam_grove 5:3f93dd1d4cb3 148 * Pass a received packet to tcpip_thread for input processing
sam_grove 5:3f93dd1d4cb3 149 *
sam_grove 5:3f93dd1d4cb3 150 * @param p the received packet, p->payload pointing to the Ethernet header or
sam_grove 5:3f93dd1d4cb3 151 * to an IP header (if inp doesn't have NETIF_FLAG_ETHARP or
sam_grove 5:3f93dd1d4cb3 152 * NETIF_FLAG_ETHERNET flags)
sam_grove 5:3f93dd1d4cb3 153 * @param inp the network interface on which the packet was received
sam_grove 5:3f93dd1d4cb3 154 */
sam_grove 5:3f93dd1d4cb3 155 err_t
sam_grove 5:3f93dd1d4cb3 156 tcpip_input(struct pbuf *p, struct netif *inp)
sam_grove 5:3f93dd1d4cb3 157 {
sam_grove 5:3f93dd1d4cb3 158 #if LWIP_TCPIP_CORE_LOCKING_INPUT
sam_grove 5:3f93dd1d4cb3 159 err_t ret;
sam_grove 5:3f93dd1d4cb3 160 LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_input: PACKET %p/%p\n", (void *)p, (void *)inp));
sam_grove 5:3f93dd1d4cb3 161 LOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 162 #if LWIP_ETHERNET
sam_grove 5:3f93dd1d4cb3 163 if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
sam_grove 5:3f93dd1d4cb3 164 ret = ethernet_input(p, inp);
sam_grove 5:3f93dd1d4cb3 165 } else
sam_grove 5:3f93dd1d4cb3 166 #endif /* LWIP_ETHERNET */
sam_grove 5:3f93dd1d4cb3 167 {
sam_grove 5:3f93dd1d4cb3 168 ret = ip_input(p, inp);
sam_grove 5:3f93dd1d4cb3 169 }
sam_grove 5:3f93dd1d4cb3 170 UNLOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 171 return ret;
sam_grove 5:3f93dd1d4cb3 172 #else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
sam_grove 5:3f93dd1d4cb3 173 struct tcpip_msg *msg;
sam_grove 5:3f93dd1d4cb3 174
sam_grove 5:3f93dd1d4cb3 175 if (sys_mbox_valid(&mbox)) {
sam_grove 5:3f93dd1d4cb3 176 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT);
sam_grove 5:3f93dd1d4cb3 177 if (msg == NULL) {
sam_grove 5:3f93dd1d4cb3 178 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 179 }
sam_grove 5:3f93dd1d4cb3 180
sam_grove 5:3f93dd1d4cb3 181 msg->type = TCPIP_MSG_INPKT;
sam_grove 5:3f93dd1d4cb3 182 msg->msg.inp.p = p;
sam_grove 5:3f93dd1d4cb3 183 msg->msg.inp.netif = inp;
sam_grove 5:3f93dd1d4cb3 184 if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
sam_grove 5:3f93dd1d4cb3 185 memp_free(MEMP_TCPIP_MSG_INPKT, msg);
sam_grove 5:3f93dd1d4cb3 186 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 187 }
sam_grove 5:3f93dd1d4cb3 188 return ERR_OK;
sam_grove 5:3f93dd1d4cb3 189 }
sam_grove 5:3f93dd1d4cb3 190 return ERR_VAL;
sam_grove 5:3f93dd1d4cb3 191 #endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
sam_grove 5:3f93dd1d4cb3 192 }
sam_grove 5:3f93dd1d4cb3 193
sam_grove 5:3f93dd1d4cb3 194 /**
sam_grove 5:3f93dd1d4cb3 195 * Call a specific function in the thread context of
sam_grove 5:3f93dd1d4cb3 196 * tcpip_thread for easy access synchronization.
sam_grove 5:3f93dd1d4cb3 197 * A function called in that way may access lwIP core code
sam_grove 5:3f93dd1d4cb3 198 * without fearing concurrent access.
sam_grove 5:3f93dd1d4cb3 199 *
sam_grove 5:3f93dd1d4cb3 200 * @param f the function to call
sam_grove 5:3f93dd1d4cb3 201 * @param ctx parameter passed to f
sam_grove 5:3f93dd1d4cb3 202 * @param block 1 to block until the request is posted, 0 to non-blocking mode
sam_grove 5:3f93dd1d4cb3 203 * @return ERR_OK if the function was called, another err_t if not
sam_grove 5:3f93dd1d4cb3 204 */
sam_grove 5:3f93dd1d4cb3 205 err_t
sam_grove 5:3f93dd1d4cb3 206 tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
sam_grove 5:3f93dd1d4cb3 207 {
sam_grove 5:3f93dd1d4cb3 208 struct tcpip_msg *msg;
sam_grove 5:3f93dd1d4cb3 209
sam_grove 5:3f93dd1d4cb3 210 if (sys_mbox_valid(&mbox)) {
sam_grove 5:3f93dd1d4cb3 211 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
sam_grove 5:3f93dd1d4cb3 212 if (msg == NULL) {
sam_grove 5:3f93dd1d4cb3 213 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 214 }
sam_grove 5:3f93dd1d4cb3 215
sam_grove 5:3f93dd1d4cb3 216 msg->type = TCPIP_MSG_CALLBACK;
sam_grove 5:3f93dd1d4cb3 217 msg->msg.cb.function = function;
sam_grove 5:3f93dd1d4cb3 218 msg->msg.cb.ctx = ctx;
sam_grove 5:3f93dd1d4cb3 219 if (block) {
sam_grove 5:3f93dd1d4cb3 220 sys_mbox_post(&mbox, msg);
sam_grove 5:3f93dd1d4cb3 221 } else {
sam_grove 5:3f93dd1d4cb3 222 if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
sam_grove 5:3f93dd1d4cb3 223 memp_free(MEMP_TCPIP_MSG_API, msg);
sam_grove 5:3f93dd1d4cb3 224 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 225 }
sam_grove 5:3f93dd1d4cb3 226 }
sam_grove 5:3f93dd1d4cb3 227 return ERR_OK;
sam_grove 5:3f93dd1d4cb3 228 }
sam_grove 5:3f93dd1d4cb3 229 return ERR_VAL;
sam_grove 5:3f93dd1d4cb3 230 }
sam_grove 5:3f93dd1d4cb3 231
sam_grove 5:3f93dd1d4cb3 232 #if LWIP_TCPIP_TIMEOUT
sam_grove 5:3f93dd1d4cb3 233 /**
sam_grove 5:3f93dd1d4cb3 234 * call sys_timeout in tcpip_thread
sam_grove 5:3f93dd1d4cb3 235 *
sam_grove 5:3f93dd1d4cb3 236 * @param msec time in milliseconds for timeout
sam_grove 5:3f93dd1d4cb3 237 * @param h function to be called on timeout
sam_grove 5:3f93dd1d4cb3 238 * @param arg argument to pass to timeout function h
sam_grove 5:3f93dd1d4cb3 239 * @return ERR_MEM on memory error, ERR_OK otherwise
sam_grove 5:3f93dd1d4cb3 240 */
sam_grove 5:3f93dd1d4cb3 241 err_t
sam_grove 5:3f93dd1d4cb3 242 tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
sam_grove 5:3f93dd1d4cb3 243 {
sam_grove 5:3f93dd1d4cb3 244 struct tcpip_msg *msg;
sam_grove 5:3f93dd1d4cb3 245
sam_grove 5:3f93dd1d4cb3 246 if (sys_mbox_valid(&mbox)) {
sam_grove 5:3f93dd1d4cb3 247 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
sam_grove 5:3f93dd1d4cb3 248 if (msg == NULL) {
sam_grove 5:3f93dd1d4cb3 249 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 250 }
sam_grove 5:3f93dd1d4cb3 251
sam_grove 5:3f93dd1d4cb3 252 msg->type = TCPIP_MSG_TIMEOUT;
sam_grove 5:3f93dd1d4cb3 253 msg->msg.tmo.msecs = msecs;
sam_grove 5:3f93dd1d4cb3 254 msg->msg.tmo.h = h;
sam_grove 5:3f93dd1d4cb3 255 msg->msg.tmo.arg = arg;
sam_grove 5:3f93dd1d4cb3 256 sys_mbox_post(&mbox, msg);
sam_grove 5:3f93dd1d4cb3 257 return ERR_OK;
sam_grove 5:3f93dd1d4cb3 258 }
sam_grove 5:3f93dd1d4cb3 259 return ERR_VAL;
sam_grove 5:3f93dd1d4cb3 260 }
sam_grove 5:3f93dd1d4cb3 261
sam_grove 5:3f93dd1d4cb3 262 /**
sam_grove 5:3f93dd1d4cb3 263 * call sys_untimeout in tcpip_thread
sam_grove 5:3f93dd1d4cb3 264 *
sam_grove 5:3f93dd1d4cb3 265 * @param msec time in milliseconds for timeout
sam_grove 5:3f93dd1d4cb3 266 * @param h function to be called on timeout
sam_grove 5:3f93dd1d4cb3 267 * @param arg argument to pass to timeout function h
sam_grove 5:3f93dd1d4cb3 268 * @return ERR_MEM on memory error, ERR_OK otherwise
sam_grove 5:3f93dd1d4cb3 269 */
sam_grove 5:3f93dd1d4cb3 270 err_t
sam_grove 5:3f93dd1d4cb3 271 tcpip_untimeout(sys_timeout_handler h, void *arg)
sam_grove 5:3f93dd1d4cb3 272 {
sam_grove 5:3f93dd1d4cb3 273 struct tcpip_msg *msg;
sam_grove 5:3f93dd1d4cb3 274
sam_grove 5:3f93dd1d4cb3 275 if (sys_mbox_valid(&mbox)) {
sam_grove 5:3f93dd1d4cb3 276 msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
sam_grove 5:3f93dd1d4cb3 277 if (msg == NULL) {
sam_grove 5:3f93dd1d4cb3 278 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 279 }
sam_grove 5:3f93dd1d4cb3 280
sam_grove 5:3f93dd1d4cb3 281 msg->type = TCPIP_MSG_UNTIMEOUT;
sam_grove 5:3f93dd1d4cb3 282 msg->msg.tmo.h = h;
sam_grove 5:3f93dd1d4cb3 283 msg->msg.tmo.arg = arg;
sam_grove 5:3f93dd1d4cb3 284 sys_mbox_post(&mbox, msg);
sam_grove 5:3f93dd1d4cb3 285 return ERR_OK;
sam_grove 5:3f93dd1d4cb3 286 }
sam_grove 5:3f93dd1d4cb3 287 return ERR_VAL;
sam_grove 5:3f93dd1d4cb3 288 }
sam_grove 5:3f93dd1d4cb3 289 #endif /* LWIP_TCPIP_TIMEOUT */
sam_grove 5:3f93dd1d4cb3 290
sam_grove 5:3f93dd1d4cb3 291 #if LWIP_NETCONN
sam_grove 5:3f93dd1d4cb3 292 /**
sam_grove 5:3f93dd1d4cb3 293 * Call the lower part of a netconn_* function
sam_grove 5:3f93dd1d4cb3 294 * This function is then running in the thread context
sam_grove 5:3f93dd1d4cb3 295 * of tcpip_thread and has exclusive access to lwIP core code.
sam_grove 5:3f93dd1d4cb3 296 *
sam_grove 5:3f93dd1d4cb3 297 * @param apimsg a struct containing the function to call and its parameters
sam_grove 5:3f93dd1d4cb3 298 * @return ERR_OK if the function was called, another err_t if not
sam_grove 5:3f93dd1d4cb3 299 */
sam_grove 5:3f93dd1d4cb3 300 err_t
sam_grove 5:3f93dd1d4cb3 301 tcpip_apimsg(struct api_msg *apimsg)
sam_grove 5:3f93dd1d4cb3 302 {
sam_grove 5:3f93dd1d4cb3 303 struct tcpip_msg msg;
sam_grove 5:3f93dd1d4cb3 304 #ifdef LWIP_DEBUG
sam_grove 5:3f93dd1d4cb3 305 /* catch functions that don't set err */
sam_grove 5:3f93dd1d4cb3 306 apimsg->msg.err = ERR_VAL;
sam_grove 5:3f93dd1d4cb3 307 #endif
sam_grove 5:3f93dd1d4cb3 308
sam_grove 5:3f93dd1d4cb3 309 if (sys_mbox_valid(&mbox)) {
sam_grove 5:3f93dd1d4cb3 310 msg.type = TCPIP_MSG_API;
sam_grove 5:3f93dd1d4cb3 311 msg.msg.apimsg = apimsg;
sam_grove 5:3f93dd1d4cb3 312 sys_mbox_post(&mbox, &msg);
sam_grove 5:3f93dd1d4cb3 313 sys_arch_sem_wait(&apimsg->msg.conn->op_completed, 0);
sam_grove 5:3f93dd1d4cb3 314 return apimsg->msg.err;
sam_grove 5:3f93dd1d4cb3 315 }
sam_grove 5:3f93dd1d4cb3 316 return ERR_VAL;
sam_grove 5:3f93dd1d4cb3 317 }
sam_grove 5:3f93dd1d4cb3 318
sam_grove 5:3f93dd1d4cb3 319 #if LWIP_TCPIP_CORE_LOCKING
sam_grove 5:3f93dd1d4cb3 320 /**
sam_grove 5:3f93dd1d4cb3 321 * Call the lower part of a netconn_* function
sam_grove 5:3f93dd1d4cb3 322 * This function has exclusive access to lwIP core code by locking it
sam_grove 5:3f93dd1d4cb3 323 * before the function is called.
sam_grove 5:3f93dd1d4cb3 324 *
sam_grove 5:3f93dd1d4cb3 325 * @param apimsg a struct containing the function to call and its parameters
sam_grove 5:3f93dd1d4cb3 326 * @return ERR_OK (only for compatibility fo tcpip_apimsg())
sam_grove 5:3f93dd1d4cb3 327 */
sam_grove 5:3f93dd1d4cb3 328 err_t
sam_grove 5:3f93dd1d4cb3 329 tcpip_apimsg_lock(struct api_msg *apimsg)
sam_grove 5:3f93dd1d4cb3 330 {
sam_grove 5:3f93dd1d4cb3 331 #ifdef LWIP_DEBUG
sam_grove 5:3f93dd1d4cb3 332 /* catch functions that don't set err */
sam_grove 5:3f93dd1d4cb3 333 apimsg->msg.err = ERR_VAL;
sam_grove 5:3f93dd1d4cb3 334 #endif
sam_grove 5:3f93dd1d4cb3 335
sam_grove 5:3f93dd1d4cb3 336 LOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 337 apimsg->function(&(apimsg->msg));
sam_grove 5:3f93dd1d4cb3 338 UNLOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 339 return apimsg->msg.err;
sam_grove 5:3f93dd1d4cb3 340
sam_grove 5:3f93dd1d4cb3 341 }
sam_grove 5:3f93dd1d4cb3 342 #endif /* LWIP_TCPIP_CORE_LOCKING */
sam_grove 5:3f93dd1d4cb3 343 #endif /* LWIP_NETCONN */
sam_grove 5:3f93dd1d4cb3 344
sam_grove 5:3f93dd1d4cb3 345 #if LWIP_NETIF_API
sam_grove 5:3f93dd1d4cb3 346 #if !LWIP_TCPIP_CORE_LOCKING
sam_grove 5:3f93dd1d4cb3 347 /**
sam_grove 5:3f93dd1d4cb3 348 * Much like tcpip_apimsg, but calls the lower part of a netifapi_*
sam_grove 5:3f93dd1d4cb3 349 * function.
sam_grove 5:3f93dd1d4cb3 350 *
sam_grove 5:3f93dd1d4cb3 351 * @param netifapimsg a struct containing the function to call and its parameters
sam_grove 5:3f93dd1d4cb3 352 * @return error code given back by the function that was called
sam_grove 5:3f93dd1d4cb3 353 */
sam_grove 5:3f93dd1d4cb3 354 err_t
sam_grove 5:3f93dd1d4cb3 355 tcpip_netifapi(struct netifapi_msg* netifapimsg)
sam_grove 5:3f93dd1d4cb3 356 {
sam_grove 5:3f93dd1d4cb3 357 struct tcpip_msg msg;
sam_grove 5:3f93dd1d4cb3 358
sam_grove 5:3f93dd1d4cb3 359 if (sys_mbox_valid(&mbox)) {
sam_grove 5:3f93dd1d4cb3 360 err_t err = sys_sem_new(&netifapimsg->msg.sem, 0);
sam_grove 5:3f93dd1d4cb3 361 if (err != ERR_OK) {
sam_grove 5:3f93dd1d4cb3 362 netifapimsg->msg.err = err;
sam_grove 5:3f93dd1d4cb3 363 return err;
sam_grove 5:3f93dd1d4cb3 364 }
sam_grove 5:3f93dd1d4cb3 365
sam_grove 5:3f93dd1d4cb3 366 msg.type = TCPIP_MSG_NETIFAPI;
sam_grove 5:3f93dd1d4cb3 367 msg.msg.netifapimsg = netifapimsg;
sam_grove 5:3f93dd1d4cb3 368 sys_mbox_post(&mbox, &msg);
sam_grove 5:3f93dd1d4cb3 369 sys_sem_wait(&netifapimsg->msg.sem);
sam_grove 5:3f93dd1d4cb3 370 sys_sem_free(&netifapimsg->msg.sem);
sam_grove 5:3f93dd1d4cb3 371 return netifapimsg->msg.err;
sam_grove 5:3f93dd1d4cb3 372 }
sam_grove 5:3f93dd1d4cb3 373 return ERR_VAL;
sam_grove 5:3f93dd1d4cb3 374 }
sam_grove 5:3f93dd1d4cb3 375 #else /* !LWIP_TCPIP_CORE_LOCKING */
sam_grove 5:3f93dd1d4cb3 376 /**
sam_grove 5:3f93dd1d4cb3 377 * Call the lower part of a netifapi_* function
sam_grove 5:3f93dd1d4cb3 378 * This function has exclusive access to lwIP core code by locking it
sam_grove 5:3f93dd1d4cb3 379 * before the function is called.
sam_grove 5:3f93dd1d4cb3 380 *
sam_grove 5:3f93dd1d4cb3 381 * @param netifapimsg a struct containing the function to call and its parameters
sam_grove 5:3f93dd1d4cb3 382 * @return ERR_OK (only for compatibility fo tcpip_netifapi())
sam_grove 5:3f93dd1d4cb3 383 */
sam_grove 5:3f93dd1d4cb3 384 err_t
sam_grove 5:3f93dd1d4cb3 385 tcpip_netifapi_lock(struct netifapi_msg* netifapimsg)
sam_grove 5:3f93dd1d4cb3 386 {
sam_grove 5:3f93dd1d4cb3 387 LOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 388 netifapimsg->function(&(netifapimsg->msg));
sam_grove 5:3f93dd1d4cb3 389 UNLOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 390 return netifapimsg->msg.err;
sam_grove 5:3f93dd1d4cb3 391 }
sam_grove 5:3f93dd1d4cb3 392 #endif /* !LWIP_TCPIP_CORE_LOCKING */
sam_grove 5:3f93dd1d4cb3 393 #endif /* LWIP_NETIF_API */
sam_grove 5:3f93dd1d4cb3 394
sam_grove 5:3f93dd1d4cb3 395 /**
sam_grove 5:3f93dd1d4cb3 396 * Initialize this module:
sam_grove 5:3f93dd1d4cb3 397 * - initialize all sub modules
sam_grove 5:3f93dd1d4cb3 398 * - start the tcpip_thread
sam_grove 5:3f93dd1d4cb3 399 *
sam_grove 5:3f93dd1d4cb3 400 * @param initfunc a function to call when tcpip_thread is running and finished initializing
sam_grove 5:3f93dd1d4cb3 401 * @param arg argument to pass to initfunc
sam_grove 5:3f93dd1d4cb3 402 */
sam_grove 5:3f93dd1d4cb3 403 void
sam_grove 5:3f93dd1d4cb3 404 tcpip_init(tcpip_init_done_fn initfunc, void *arg)
sam_grove 5:3f93dd1d4cb3 405 {
sam_grove 5:3f93dd1d4cb3 406 lwip_init();
sam_grove 5:3f93dd1d4cb3 407
sam_grove 5:3f93dd1d4cb3 408 tcpip_init_done = initfunc;
sam_grove 5:3f93dd1d4cb3 409 tcpip_init_done_arg = arg;
sam_grove 5:3f93dd1d4cb3 410 if(sys_mbox_new(&mbox, TCPIP_MBOX_SIZE) != ERR_OK) {
sam_grove 5:3f93dd1d4cb3 411 LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
sam_grove 5:3f93dd1d4cb3 412 }
sam_grove 5:3f93dd1d4cb3 413 #if LWIP_TCPIP_CORE_LOCKING
sam_grove 5:3f93dd1d4cb3 414 if(sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
sam_grove 5:3f93dd1d4cb3 415 LWIP_ASSERT("failed to create lock_tcpip_core", 0);
sam_grove 5:3f93dd1d4cb3 416 }
sam_grove 5:3f93dd1d4cb3 417 #endif /* LWIP_TCPIP_CORE_LOCKING */
sam_grove 5:3f93dd1d4cb3 418
sam_grove 5:3f93dd1d4cb3 419 sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
sam_grove 5:3f93dd1d4cb3 420 }
sam_grove 5:3f93dd1d4cb3 421
sam_grove 5:3f93dd1d4cb3 422 /**
sam_grove 5:3f93dd1d4cb3 423 * Simple callback function used with tcpip_callback to free a pbuf
sam_grove 5:3f93dd1d4cb3 424 * (pbuf_free has a wrong signature for tcpip_callback)
sam_grove 5:3f93dd1d4cb3 425 *
sam_grove 5:3f93dd1d4cb3 426 * @param p The pbuf (chain) to be dereferenced.
sam_grove 5:3f93dd1d4cb3 427 */
sam_grove 5:3f93dd1d4cb3 428 static void
sam_grove 5:3f93dd1d4cb3 429 pbuf_free_int(void *p)
sam_grove 5:3f93dd1d4cb3 430 {
sam_grove 5:3f93dd1d4cb3 431 struct pbuf *q = (struct pbuf *)p;
sam_grove 5:3f93dd1d4cb3 432 pbuf_free(q);
sam_grove 5:3f93dd1d4cb3 433 }
sam_grove 5:3f93dd1d4cb3 434
sam_grove 5:3f93dd1d4cb3 435 /**
sam_grove 5:3f93dd1d4cb3 436 * A simple wrapper function that allows you to free a pbuf from interrupt context.
sam_grove 5:3f93dd1d4cb3 437 *
sam_grove 5:3f93dd1d4cb3 438 * @param p The pbuf (chain) to be dereferenced.
sam_grove 5:3f93dd1d4cb3 439 * @return ERR_OK if callback could be enqueued, an err_t if not
sam_grove 5:3f93dd1d4cb3 440 */
sam_grove 5:3f93dd1d4cb3 441 err_t
sam_grove 5:3f93dd1d4cb3 442 pbuf_free_callback(struct pbuf *p)
sam_grove 5:3f93dd1d4cb3 443 {
sam_grove 5:3f93dd1d4cb3 444 return tcpip_callback_with_block(pbuf_free_int, p, 0);
sam_grove 5:3f93dd1d4cb3 445 }
sam_grove 5:3f93dd1d4cb3 446
sam_grove 5:3f93dd1d4cb3 447 /**
sam_grove 5:3f93dd1d4cb3 448 * A simple wrapper function that allows you to free heap memory from
sam_grove 5:3f93dd1d4cb3 449 * interrupt context.
sam_grove 5:3f93dd1d4cb3 450 *
sam_grove 5:3f93dd1d4cb3 451 * @param m the heap memory to free
sam_grove 5:3f93dd1d4cb3 452 * @return ERR_OK if callback could be enqueued, an err_t if not
sam_grove 5:3f93dd1d4cb3 453 */
sam_grove 5:3f93dd1d4cb3 454 err_t
sam_grove 5:3f93dd1d4cb3 455 mem_free_callback(void *m)
sam_grove 5:3f93dd1d4cb3 456 {
sam_grove 5:3f93dd1d4cb3 457 return tcpip_callback_with_block(mem_free, m, 0);
sam_grove 5:3f93dd1d4cb3 458 }
sam_grove 5:3f93dd1d4cb3 459
sam_grove 5:3f93dd1d4cb3 460 #endif /* !NO_SYS */