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 * Network buffer management
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 LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
sam_grove 5:3f93dd1d4cb3 42
sam_grove 5:3f93dd1d4cb3 43 #include "lwip/netbuf.h"
sam_grove 5:3f93dd1d4cb3 44 #include "lwip/memp.h"
sam_grove 5:3f93dd1d4cb3 45
sam_grove 5:3f93dd1d4cb3 46 #include <string.h>
sam_grove 5:3f93dd1d4cb3 47
sam_grove 5:3f93dd1d4cb3 48 /**
sam_grove 5:3f93dd1d4cb3 49 * Create (allocate) and initialize a new netbuf.
sam_grove 5:3f93dd1d4cb3 50 * The netbuf doesn't yet contain a packet buffer!
sam_grove 5:3f93dd1d4cb3 51 *
sam_grove 5:3f93dd1d4cb3 52 * @return a pointer to a new netbuf
sam_grove 5:3f93dd1d4cb3 53 * NULL on lack of memory
sam_grove 5:3f93dd1d4cb3 54 */
sam_grove 5:3f93dd1d4cb3 55 struct
sam_grove 5:3f93dd1d4cb3 56 netbuf *netbuf_new(void)
sam_grove 5:3f93dd1d4cb3 57 {
sam_grove 5:3f93dd1d4cb3 58 struct netbuf *buf;
sam_grove 5:3f93dd1d4cb3 59
sam_grove 5:3f93dd1d4cb3 60 buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);
sam_grove 5:3f93dd1d4cb3 61 if (buf != NULL) {
sam_grove 5:3f93dd1d4cb3 62 buf->p = NULL;
sam_grove 5:3f93dd1d4cb3 63 buf->ptr = NULL;
sam_grove 5:3f93dd1d4cb3 64 ip_addr_set_any(&buf->addr);
sam_grove 5:3f93dd1d4cb3 65 buf->port = 0;
sam_grove 5:3f93dd1d4cb3 66 #if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
sam_grove 5:3f93dd1d4cb3 67 #if LWIP_CHECKSUM_ON_COPY
sam_grove 5:3f93dd1d4cb3 68 buf->flags = 0;
sam_grove 5:3f93dd1d4cb3 69 #endif /* LWIP_CHECKSUM_ON_COPY */
sam_grove 5:3f93dd1d4cb3 70 buf->toport_chksum = 0;
sam_grove 5:3f93dd1d4cb3 71 #if LWIP_NETBUF_RECVINFO
sam_grove 5:3f93dd1d4cb3 72 ip_addr_set_any(&buf->toaddr);
sam_grove 5:3f93dd1d4cb3 73 #endif /* LWIP_NETBUF_RECVINFO */
sam_grove 5:3f93dd1d4cb3 74 #endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
sam_grove 5:3f93dd1d4cb3 75 return buf;
sam_grove 5:3f93dd1d4cb3 76 } else {
sam_grove 5:3f93dd1d4cb3 77 return NULL;
sam_grove 5:3f93dd1d4cb3 78 }
sam_grove 5:3f93dd1d4cb3 79 }
sam_grove 5:3f93dd1d4cb3 80
sam_grove 5:3f93dd1d4cb3 81 /**
sam_grove 5:3f93dd1d4cb3 82 * Deallocate a netbuf allocated by netbuf_new().
sam_grove 5:3f93dd1d4cb3 83 *
sam_grove 5:3f93dd1d4cb3 84 * @param buf pointer to a netbuf allocated by netbuf_new()
sam_grove 5:3f93dd1d4cb3 85 */
sam_grove 5:3f93dd1d4cb3 86 void
sam_grove 5:3f93dd1d4cb3 87 netbuf_delete(struct netbuf *buf)
sam_grove 5:3f93dd1d4cb3 88 {
sam_grove 5:3f93dd1d4cb3 89 if (buf != NULL) {
sam_grove 5:3f93dd1d4cb3 90 if (buf->p != NULL) {
sam_grove 5:3f93dd1d4cb3 91 pbuf_free(buf->p);
sam_grove 5:3f93dd1d4cb3 92 buf->p = buf->ptr = NULL;
sam_grove 5:3f93dd1d4cb3 93 }
sam_grove 5:3f93dd1d4cb3 94 memp_free(MEMP_NETBUF, buf);
sam_grove 5:3f93dd1d4cb3 95 }
sam_grove 5:3f93dd1d4cb3 96 }
sam_grove 5:3f93dd1d4cb3 97
sam_grove 5:3f93dd1d4cb3 98 /**
sam_grove 5:3f93dd1d4cb3 99 * Allocate memory for a packet buffer for a given netbuf.
sam_grove 5:3f93dd1d4cb3 100 *
sam_grove 5:3f93dd1d4cb3 101 * @param buf the netbuf for which to allocate a packet buffer
sam_grove 5:3f93dd1d4cb3 102 * @param size the size of the packet buffer to allocate
sam_grove 5:3f93dd1d4cb3 103 * @return pointer to the allocated memory
sam_grove 5:3f93dd1d4cb3 104 * NULL if no memory could be allocated
sam_grove 5:3f93dd1d4cb3 105 */
sam_grove 5:3f93dd1d4cb3 106 void *
sam_grove 5:3f93dd1d4cb3 107 netbuf_alloc(struct netbuf *buf, u16_t size)
sam_grove 5:3f93dd1d4cb3 108 {
sam_grove 5:3f93dd1d4cb3 109 LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
sam_grove 5:3f93dd1d4cb3 110
sam_grove 5:3f93dd1d4cb3 111 /* Deallocate any previously allocated memory. */
sam_grove 5:3f93dd1d4cb3 112 if (buf->p != NULL) {
sam_grove 5:3f93dd1d4cb3 113 pbuf_free(buf->p);
sam_grove 5:3f93dd1d4cb3 114 }
sam_grove 5:3f93dd1d4cb3 115 buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
sam_grove 5:3f93dd1d4cb3 116 if (buf->p == NULL) {
sam_grove 5:3f93dd1d4cb3 117 return NULL;
sam_grove 5:3f93dd1d4cb3 118 }
sam_grove 5:3f93dd1d4cb3 119 LWIP_ASSERT("check that first pbuf can hold size",
sam_grove 5:3f93dd1d4cb3 120 (buf->p->len >= size));
sam_grove 5:3f93dd1d4cb3 121 buf->ptr = buf->p;
sam_grove 5:3f93dd1d4cb3 122 return buf->p->payload;
sam_grove 5:3f93dd1d4cb3 123 }
sam_grove 5:3f93dd1d4cb3 124
sam_grove 5:3f93dd1d4cb3 125 /**
sam_grove 5:3f93dd1d4cb3 126 * Free the packet buffer included in a netbuf
sam_grove 5:3f93dd1d4cb3 127 *
sam_grove 5:3f93dd1d4cb3 128 * @param buf pointer to the netbuf which contains the packet buffer to free
sam_grove 5:3f93dd1d4cb3 129 */
sam_grove 5:3f93dd1d4cb3 130 void
sam_grove 5:3f93dd1d4cb3 131 netbuf_free(struct netbuf *buf)
sam_grove 5:3f93dd1d4cb3 132 {
sam_grove 5:3f93dd1d4cb3 133 LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
sam_grove 5:3f93dd1d4cb3 134 if (buf->p != NULL) {
sam_grove 5:3f93dd1d4cb3 135 pbuf_free(buf->p);
sam_grove 5:3f93dd1d4cb3 136 }
sam_grove 5:3f93dd1d4cb3 137 buf->p = buf->ptr = NULL;
sam_grove 5:3f93dd1d4cb3 138 }
sam_grove 5:3f93dd1d4cb3 139
sam_grove 5:3f93dd1d4cb3 140 /**
sam_grove 5:3f93dd1d4cb3 141 * Let a netbuf reference existing (non-volatile) data.
sam_grove 5:3f93dd1d4cb3 142 *
sam_grove 5:3f93dd1d4cb3 143 * @param buf netbuf which should reference the data
sam_grove 5:3f93dd1d4cb3 144 * @param dataptr pointer to the data to reference
sam_grove 5:3f93dd1d4cb3 145 * @param size size of the data
sam_grove 5:3f93dd1d4cb3 146 * @return ERR_OK if data is referenced
sam_grove 5:3f93dd1d4cb3 147 * ERR_MEM if data couldn't be referenced due to lack of memory
sam_grove 5:3f93dd1d4cb3 148 */
sam_grove 5:3f93dd1d4cb3 149 err_t
sam_grove 5:3f93dd1d4cb3 150 netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
sam_grove 5:3f93dd1d4cb3 151 {
sam_grove 5:3f93dd1d4cb3 152 LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;);
sam_grove 5:3f93dd1d4cb3 153 if (buf->p != NULL) {
sam_grove 5:3f93dd1d4cb3 154 pbuf_free(buf->p);
sam_grove 5:3f93dd1d4cb3 155 }
sam_grove 5:3f93dd1d4cb3 156 buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
sam_grove 5:3f93dd1d4cb3 157 if (buf->p == NULL) {
sam_grove 5:3f93dd1d4cb3 158 buf->ptr = NULL;
sam_grove 5:3f93dd1d4cb3 159 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 160 }
sam_grove 5:3f93dd1d4cb3 161 buf->p->payload = (void*)dataptr;
sam_grove 5:3f93dd1d4cb3 162 buf->p->len = buf->p->tot_len = size;
sam_grove 5:3f93dd1d4cb3 163 buf->ptr = buf->p;
sam_grove 5:3f93dd1d4cb3 164 return ERR_OK;
sam_grove 5:3f93dd1d4cb3 165 }
sam_grove 5:3f93dd1d4cb3 166
sam_grove 5:3f93dd1d4cb3 167 /**
sam_grove 5:3f93dd1d4cb3 168 * Chain one netbuf to another (@see pbuf_chain)
sam_grove 5:3f93dd1d4cb3 169 *
sam_grove 5:3f93dd1d4cb3 170 * @param head the first netbuf
sam_grove 5:3f93dd1d4cb3 171 * @param tail netbuf to chain after head, freed by this function, may not be reference after returning
sam_grove 5:3f93dd1d4cb3 172 */
sam_grove 5:3f93dd1d4cb3 173 void
sam_grove 5:3f93dd1d4cb3 174 netbuf_chain(struct netbuf *head, struct netbuf *tail)
sam_grove 5:3f93dd1d4cb3 175 {
sam_grove 5:3f93dd1d4cb3 176 LWIP_ERROR("netbuf_ref: invalid head", (head != NULL), return;);
sam_grove 5:3f93dd1d4cb3 177 LWIP_ERROR("netbuf_chain: invalid tail", (tail != NULL), return;);
sam_grove 5:3f93dd1d4cb3 178 pbuf_cat(head->p, tail->p);
sam_grove 5:3f93dd1d4cb3 179 head->ptr = head->p;
sam_grove 5:3f93dd1d4cb3 180 memp_free(MEMP_NETBUF, tail);
sam_grove 5:3f93dd1d4cb3 181 }
sam_grove 5:3f93dd1d4cb3 182
sam_grove 5:3f93dd1d4cb3 183 /**
sam_grove 5:3f93dd1d4cb3 184 * Get the data pointer and length of the data inside a netbuf.
sam_grove 5:3f93dd1d4cb3 185 *
sam_grove 5:3f93dd1d4cb3 186 * @param buf netbuf to get the data from
sam_grove 5:3f93dd1d4cb3 187 * @param dataptr pointer to a void pointer where to store the data pointer
sam_grove 5:3f93dd1d4cb3 188 * @param len pointer to an u16_t where the length of the data is stored
sam_grove 5:3f93dd1d4cb3 189 * @return ERR_OK if the information was retreived,
sam_grove 5:3f93dd1d4cb3 190 * ERR_BUF on error.
sam_grove 5:3f93dd1d4cb3 191 */
sam_grove 5:3f93dd1d4cb3 192 err_t
sam_grove 5:3f93dd1d4cb3 193 netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
sam_grove 5:3f93dd1d4cb3 194 {
sam_grove 5:3f93dd1d4cb3 195 LWIP_ERROR("netbuf_data: invalid buf", (buf != NULL), return ERR_ARG;);
sam_grove 5:3f93dd1d4cb3 196 LWIP_ERROR("netbuf_data: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
sam_grove 5:3f93dd1d4cb3 197 LWIP_ERROR("netbuf_data: invalid len", (len != NULL), return ERR_ARG;);
sam_grove 5:3f93dd1d4cb3 198
sam_grove 5:3f93dd1d4cb3 199 if (buf->ptr == NULL) {
sam_grove 5:3f93dd1d4cb3 200 return ERR_BUF;
sam_grove 5:3f93dd1d4cb3 201 }
sam_grove 5:3f93dd1d4cb3 202 *dataptr = buf->ptr->payload;
sam_grove 5:3f93dd1d4cb3 203 *len = buf->ptr->len;
sam_grove 5:3f93dd1d4cb3 204 return ERR_OK;
sam_grove 5:3f93dd1d4cb3 205 }
sam_grove 5:3f93dd1d4cb3 206
sam_grove 5:3f93dd1d4cb3 207 /**
sam_grove 5:3f93dd1d4cb3 208 * Move the current data pointer of a packet buffer contained in a netbuf
sam_grove 5:3f93dd1d4cb3 209 * to the next part.
sam_grove 5:3f93dd1d4cb3 210 * The packet buffer itself is not modified.
sam_grove 5:3f93dd1d4cb3 211 *
sam_grove 5:3f93dd1d4cb3 212 * @param buf the netbuf to modify
sam_grove 5:3f93dd1d4cb3 213 * @return -1 if there is no next part
sam_grove 5:3f93dd1d4cb3 214 * 1 if moved to the next part but now there is no next part
sam_grove 5:3f93dd1d4cb3 215 * 0 if moved to the next part and there are still more parts
sam_grove 5:3f93dd1d4cb3 216 */
sam_grove 5:3f93dd1d4cb3 217 s8_t
sam_grove 5:3f93dd1d4cb3 218 netbuf_next(struct netbuf *buf)
sam_grove 5:3f93dd1d4cb3 219 {
sam_grove 5:3f93dd1d4cb3 220 LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return -1;);
sam_grove 5:3f93dd1d4cb3 221 if (buf->ptr->next == NULL) {
sam_grove 5:3f93dd1d4cb3 222 return -1;
sam_grove 5:3f93dd1d4cb3 223 }
sam_grove 5:3f93dd1d4cb3 224 buf->ptr = buf->ptr->next;
sam_grove 5:3f93dd1d4cb3 225 if (buf->ptr->next == NULL) {
sam_grove 5:3f93dd1d4cb3 226 return 1;
sam_grove 5:3f93dd1d4cb3 227 }
sam_grove 5:3f93dd1d4cb3 228 return 0;
sam_grove 5:3f93dd1d4cb3 229 }
sam_grove 5:3f93dd1d4cb3 230
sam_grove 5:3f93dd1d4cb3 231 /**
sam_grove 5:3f93dd1d4cb3 232 * Move the current data pointer of a packet buffer contained in a netbuf
sam_grove 5:3f93dd1d4cb3 233 * to the beginning of the packet.
sam_grove 5:3f93dd1d4cb3 234 * The packet buffer itself is not modified.
sam_grove 5:3f93dd1d4cb3 235 *
sam_grove 5:3f93dd1d4cb3 236 * @param buf the netbuf to modify
sam_grove 5:3f93dd1d4cb3 237 */
sam_grove 5:3f93dd1d4cb3 238 void
sam_grove 5:3f93dd1d4cb3 239 netbuf_first(struct netbuf *buf)
sam_grove 5:3f93dd1d4cb3 240 {
sam_grove 5:3f93dd1d4cb3 241 LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
sam_grove 5:3f93dd1d4cb3 242 buf->ptr = buf->p;
sam_grove 5:3f93dd1d4cb3 243 }
sam_grove 5:3f93dd1d4cb3 244
sam_grove 5:3f93dd1d4cb3 245 #endif /* LWIP_NETCONN */