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 * Implementation of raw protocol PCBs for low-level handling of
sam_grove 5:3f93dd1d4cb3 4 * different types of protocols besides (or overriding) those
sam_grove 5:3f93dd1d4cb3 5 * already available in lwIP.
sam_grove 5:3f93dd1d4cb3 6 *
sam_grove 5:3f93dd1d4cb3 7 */
sam_grove 5:3f93dd1d4cb3 8
sam_grove 5:3f93dd1d4cb3 9 /*
sam_grove 5:3f93dd1d4cb3 10 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
sam_grove 5:3f93dd1d4cb3 11 * All rights reserved.
sam_grove 5:3f93dd1d4cb3 12 *
sam_grove 5:3f93dd1d4cb3 13 * Redistribution and use in source and binary forms, with or without modification,
sam_grove 5:3f93dd1d4cb3 14 * are permitted provided that the following conditions are met:
sam_grove 5:3f93dd1d4cb3 15 *
sam_grove 5:3f93dd1d4cb3 16 * 1. Redistributions of source code must retain the above copyright notice,
sam_grove 5:3f93dd1d4cb3 17 * this list of conditions and the following disclaimer.
sam_grove 5:3f93dd1d4cb3 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
sam_grove 5:3f93dd1d4cb3 19 * this list of conditions and the following disclaimer in the documentation
sam_grove 5:3f93dd1d4cb3 20 * and/or other materials provided with the distribution.
sam_grove 5:3f93dd1d4cb3 21 * 3. The name of the author may not be used to endorse or promote products
sam_grove 5:3f93dd1d4cb3 22 * derived from this software without specific prior written permission.
sam_grove 5:3f93dd1d4cb3 23 *
sam_grove 5:3f93dd1d4cb3 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
sam_grove 5:3f93dd1d4cb3 25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
sam_grove 5:3f93dd1d4cb3 26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
sam_grove 5:3f93dd1d4cb3 27 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sam_grove 5:3f93dd1d4cb3 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
sam_grove 5:3f93dd1d4cb3 29 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
sam_grove 5:3f93dd1d4cb3 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
sam_grove 5:3f93dd1d4cb3 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sam_grove 5:3f93dd1d4cb3 32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
sam_grove 5:3f93dd1d4cb3 33 * OF SUCH DAMAGE.
sam_grove 5:3f93dd1d4cb3 34 *
sam_grove 5:3f93dd1d4cb3 35 * This file is part of the lwIP TCP/IP stack.
sam_grove 5:3f93dd1d4cb3 36 *
sam_grove 5:3f93dd1d4cb3 37 * Author: Adam Dunkels <adam@sics.se>
sam_grove 5:3f93dd1d4cb3 38 *
sam_grove 5:3f93dd1d4cb3 39 */
sam_grove 5:3f93dd1d4cb3 40
sam_grove 5:3f93dd1d4cb3 41 #include "lwip/opt.h"
sam_grove 5:3f93dd1d4cb3 42
sam_grove 5:3f93dd1d4cb3 43 #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
sam_grove 5:3f93dd1d4cb3 44
sam_grove 5:3f93dd1d4cb3 45 #include "lwip/def.h"
sam_grove 5:3f93dd1d4cb3 46 #include "lwip/memp.h"
sam_grove 5:3f93dd1d4cb3 47 #include "lwip/ip_addr.h"
sam_grove 5:3f93dd1d4cb3 48 #include "lwip/netif.h"
sam_grove 5:3f93dd1d4cb3 49 #include "lwip/raw.h"
sam_grove 5:3f93dd1d4cb3 50 #include "lwip/stats.h"
sam_grove 5:3f93dd1d4cb3 51 #include "arch/perf.h"
sam_grove 5:3f93dd1d4cb3 52
sam_grove 5:3f93dd1d4cb3 53 #include <string.h>
sam_grove 5:3f93dd1d4cb3 54
sam_grove 5:3f93dd1d4cb3 55 /** The list of RAW PCBs */
sam_grove 5:3f93dd1d4cb3 56 static struct raw_pcb *raw_pcbs;
sam_grove 5:3f93dd1d4cb3 57
sam_grove 5:3f93dd1d4cb3 58 /**
sam_grove 5:3f93dd1d4cb3 59 * Determine if in incoming IP packet is covered by a RAW PCB
sam_grove 5:3f93dd1d4cb3 60 * and if so, pass it to a user-provided receive callback function.
sam_grove 5:3f93dd1d4cb3 61 *
sam_grove 5:3f93dd1d4cb3 62 * Given an incoming IP datagram (as a chain of pbufs) this function
sam_grove 5:3f93dd1d4cb3 63 * finds a corresponding RAW PCB and calls the corresponding receive
sam_grove 5:3f93dd1d4cb3 64 * callback function.
sam_grove 5:3f93dd1d4cb3 65 *
sam_grove 5:3f93dd1d4cb3 66 * @param p pbuf to be demultiplexed to a RAW PCB.
sam_grove 5:3f93dd1d4cb3 67 * @param inp network interface on which the datagram was received.
sam_grove 5:3f93dd1d4cb3 68 * @return - 1 if the packet has been eaten by a RAW PCB receive
sam_grove 5:3f93dd1d4cb3 69 * callback function. The caller MAY NOT not reference the
sam_grove 5:3f93dd1d4cb3 70 * packet any longer, and MAY NOT call pbuf_free().
sam_grove 5:3f93dd1d4cb3 71 * @return - 0 if packet is not eaten (pbuf is still referenced by the
sam_grove 5:3f93dd1d4cb3 72 * caller).
sam_grove 5:3f93dd1d4cb3 73 *
sam_grove 5:3f93dd1d4cb3 74 */
sam_grove 5:3f93dd1d4cb3 75 u8_t
sam_grove 5:3f93dd1d4cb3 76 raw_input(struct pbuf *p, struct netif *inp)
sam_grove 5:3f93dd1d4cb3 77 {
sam_grove 5:3f93dd1d4cb3 78 struct raw_pcb *pcb, *prev;
sam_grove 5:3f93dd1d4cb3 79 struct ip_hdr *iphdr;
sam_grove 5:3f93dd1d4cb3 80 s16_t proto;
sam_grove 5:3f93dd1d4cb3 81 u8_t eaten = 0;
sam_grove 5:3f93dd1d4cb3 82
sam_grove 5:3f93dd1d4cb3 83 LWIP_UNUSED_ARG(inp);
sam_grove 5:3f93dd1d4cb3 84
sam_grove 5:3f93dd1d4cb3 85 iphdr = (struct ip_hdr *)p->payload;
sam_grove 5:3f93dd1d4cb3 86 proto = IPH_PROTO(iphdr);
sam_grove 5:3f93dd1d4cb3 87
sam_grove 5:3f93dd1d4cb3 88 prev = NULL;
sam_grove 5:3f93dd1d4cb3 89 pcb = raw_pcbs;
sam_grove 5:3f93dd1d4cb3 90 /* loop through all raw pcbs until the packet is eaten by one */
sam_grove 5:3f93dd1d4cb3 91 /* this allows multiple pcbs to match against the packet by design */
sam_grove 5:3f93dd1d4cb3 92 while ((eaten == 0) && (pcb != NULL)) {
sam_grove 5:3f93dd1d4cb3 93 if ((pcb->protocol == proto) &&
sam_grove 5:3f93dd1d4cb3 94 (ip_addr_isany(&pcb->local_ip) ||
sam_grove 5:3f93dd1d4cb3 95 ip_addr_cmp(&(pcb->local_ip), &current_iphdr_dest))) {
sam_grove 5:3f93dd1d4cb3 96 #if IP_SOF_BROADCAST_RECV
sam_grove 5:3f93dd1d4cb3 97 /* broadcast filter? */
sam_grove 5:3f93dd1d4cb3 98 if ((pcb->so_options & SOF_BROADCAST) || !ip_addr_isbroadcast(&current_iphdr_dest, inp))
sam_grove 5:3f93dd1d4cb3 99 #endif /* IP_SOF_BROADCAST_RECV */
sam_grove 5:3f93dd1d4cb3 100 {
sam_grove 5:3f93dd1d4cb3 101 /* receive callback function available? */
sam_grove 5:3f93dd1d4cb3 102 if (pcb->recv != NULL) {
sam_grove 5:3f93dd1d4cb3 103 /* the receive callback function did not eat the packet? */
sam_grove 5:3f93dd1d4cb3 104 if (pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr()) != 0) {
sam_grove 5:3f93dd1d4cb3 105 /* receive function ate the packet */
sam_grove 5:3f93dd1d4cb3 106 p = NULL;
sam_grove 5:3f93dd1d4cb3 107 eaten = 1;
sam_grove 5:3f93dd1d4cb3 108 if (prev != NULL) {
sam_grove 5:3f93dd1d4cb3 109 /* move the pcb to the front of raw_pcbs so that is
sam_grove 5:3f93dd1d4cb3 110 found faster next time */
sam_grove 5:3f93dd1d4cb3 111 prev->next = pcb->next;
sam_grove 5:3f93dd1d4cb3 112 pcb->next = raw_pcbs;
sam_grove 5:3f93dd1d4cb3 113 raw_pcbs = pcb;
sam_grove 5:3f93dd1d4cb3 114 }
sam_grove 5:3f93dd1d4cb3 115 }
sam_grove 5:3f93dd1d4cb3 116 }
sam_grove 5:3f93dd1d4cb3 117 /* no receive callback function was set for this raw PCB */
sam_grove 5:3f93dd1d4cb3 118 }
sam_grove 5:3f93dd1d4cb3 119 /* drop the packet */
sam_grove 5:3f93dd1d4cb3 120 }
sam_grove 5:3f93dd1d4cb3 121 prev = pcb;
sam_grove 5:3f93dd1d4cb3 122 pcb = pcb->next;
sam_grove 5:3f93dd1d4cb3 123 }
sam_grove 5:3f93dd1d4cb3 124 return eaten;
sam_grove 5:3f93dd1d4cb3 125 }
sam_grove 5:3f93dd1d4cb3 126
sam_grove 5:3f93dd1d4cb3 127 /**
sam_grove 5:3f93dd1d4cb3 128 * Bind a RAW PCB.
sam_grove 5:3f93dd1d4cb3 129 *
sam_grove 5:3f93dd1d4cb3 130 * @param pcb RAW PCB to be bound with a local address ipaddr.
sam_grove 5:3f93dd1d4cb3 131 * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
sam_grove 5:3f93dd1d4cb3 132 * bind to all local interfaces.
sam_grove 5:3f93dd1d4cb3 133 *
sam_grove 5:3f93dd1d4cb3 134 * @return lwIP error code.
sam_grove 5:3f93dd1d4cb3 135 * - ERR_OK. Successful. No error occured.
sam_grove 5:3f93dd1d4cb3 136 * - ERR_USE. The specified IP address is already bound to by
sam_grove 5:3f93dd1d4cb3 137 * another RAW PCB.
sam_grove 5:3f93dd1d4cb3 138 *
sam_grove 5:3f93dd1d4cb3 139 * @see raw_disconnect()
sam_grove 5:3f93dd1d4cb3 140 */
sam_grove 5:3f93dd1d4cb3 141 err_t
sam_grove 5:3f93dd1d4cb3 142 raw_bind(struct raw_pcb *pcb, ip_addr_t *ipaddr)
sam_grove 5:3f93dd1d4cb3 143 {
sam_grove 5:3f93dd1d4cb3 144 ip_addr_set(&pcb->local_ip, ipaddr);
sam_grove 5:3f93dd1d4cb3 145 return ERR_OK;
sam_grove 5:3f93dd1d4cb3 146 }
sam_grove 5:3f93dd1d4cb3 147
sam_grove 5:3f93dd1d4cb3 148 /**
sam_grove 5:3f93dd1d4cb3 149 * Connect an RAW PCB. This function is required by upper layers
sam_grove 5:3f93dd1d4cb3 150 * of lwip. Using the raw api you could use raw_sendto() instead
sam_grove 5:3f93dd1d4cb3 151 *
sam_grove 5:3f93dd1d4cb3 152 * This will associate the RAW PCB with the remote address.
sam_grove 5:3f93dd1d4cb3 153 *
sam_grove 5:3f93dd1d4cb3 154 * @param pcb RAW PCB to be connected with remote address ipaddr and port.
sam_grove 5:3f93dd1d4cb3 155 * @param ipaddr remote IP address to connect with.
sam_grove 5:3f93dd1d4cb3 156 *
sam_grove 5:3f93dd1d4cb3 157 * @return lwIP error code
sam_grove 5:3f93dd1d4cb3 158 *
sam_grove 5:3f93dd1d4cb3 159 * @see raw_disconnect() and raw_sendto()
sam_grove 5:3f93dd1d4cb3 160 */
sam_grove 5:3f93dd1d4cb3 161 err_t
sam_grove 5:3f93dd1d4cb3 162 raw_connect(struct raw_pcb *pcb, ip_addr_t *ipaddr)
sam_grove 5:3f93dd1d4cb3 163 {
sam_grove 5:3f93dd1d4cb3 164 ip_addr_set(&pcb->remote_ip, ipaddr);
sam_grove 5:3f93dd1d4cb3 165 return ERR_OK;
sam_grove 5:3f93dd1d4cb3 166 }
sam_grove 5:3f93dd1d4cb3 167
sam_grove 5:3f93dd1d4cb3 168
sam_grove 5:3f93dd1d4cb3 169 /**
sam_grove 5:3f93dd1d4cb3 170 * Set the callback function for received packets that match the
sam_grove 5:3f93dd1d4cb3 171 * raw PCB's protocol and binding.
sam_grove 5:3f93dd1d4cb3 172 *
sam_grove 5:3f93dd1d4cb3 173 * The callback function MUST either
sam_grove 5:3f93dd1d4cb3 174 * - eat the packet by calling pbuf_free() and returning non-zero. The
sam_grove 5:3f93dd1d4cb3 175 * packet will not be passed to other raw PCBs or other protocol layers.
sam_grove 5:3f93dd1d4cb3 176 * - not free the packet, and return zero. The packet will be matched
sam_grove 5:3f93dd1d4cb3 177 * against further PCBs and/or forwarded to another protocol layers.
sam_grove 5:3f93dd1d4cb3 178 *
sam_grove 5:3f93dd1d4cb3 179 * @return non-zero if the packet was free()d, zero if the packet remains
sam_grove 5:3f93dd1d4cb3 180 * available for others.
sam_grove 5:3f93dd1d4cb3 181 */
sam_grove 5:3f93dd1d4cb3 182 void
sam_grove 5:3f93dd1d4cb3 183 raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg)
sam_grove 5:3f93dd1d4cb3 184 {
sam_grove 5:3f93dd1d4cb3 185 /* remember recv() callback and user data */
sam_grove 5:3f93dd1d4cb3 186 pcb->recv = recv;
sam_grove 5:3f93dd1d4cb3 187 pcb->recv_arg = recv_arg;
sam_grove 5:3f93dd1d4cb3 188 }
sam_grove 5:3f93dd1d4cb3 189
sam_grove 5:3f93dd1d4cb3 190 /**
sam_grove 5:3f93dd1d4cb3 191 * Send the raw IP packet to the given address. Note that actually you cannot
sam_grove 5:3f93dd1d4cb3 192 * modify the IP headers (this is inconsistent with the receive callback where
sam_grove 5:3f93dd1d4cb3 193 * you actually get the IP headers), you can only specify the IP payload here.
sam_grove 5:3f93dd1d4cb3 194 * It requires some more changes in lwIP. (there will be a raw_send() function
sam_grove 5:3f93dd1d4cb3 195 * then.)
sam_grove 5:3f93dd1d4cb3 196 *
sam_grove 5:3f93dd1d4cb3 197 * @param pcb the raw pcb which to send
sam_grove 5:3f93dd1d4cb3 198 * @param p the IP payload to send
sam_grove 5:3f93dd1d4cb3 199 * @param ipaddr the destination address of the IP packet
sam_grove 5:3f93dd1d4cb3 200 *
sam_grove 5:3f93dd1d4cb3 201 */
sam_grove 5:3f93dd1d4cb3 202 err_t
sam_grove 5:3f93dd1d4cb3 203 raw_sendto(struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr)
sam_grove 5:3f93dd1d4cb3 204 {
sam_grove 5:3f93dd1d4cb3 205 err_t err;
sam_grove 5:3f93dd1d4cb3 206 struct netif *netif;
sam_grove 5:3f93dd1d4cb3 207 ip_addr_t *src_ip;
sam_grove 5:3f93dd1d4cb3 208 struct pbuf *q; /* q will be sent down the stack */
sam_grove 5:3f93dd1d4cb3 209
sam_grove 5:3f93dd1d4cb3 210 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_sendto\n"));
sam_grove 5:3f93dd1d4cb3 211
sam_grove 5:3f93dd1d4cb3 212 /* not enough space to add an IP header to first pbuf in given p chain? */
sam_grove 5:3f93dd1d4cb3 213 if (pbuf_header(p, IP_HLEN)) {
sam_grove 5:3f93dd1d4cb3 214 /* allocate header in new pbuf */
sam_grove 5:3f93dd1d4cb3 215 q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM);
sam_grove 5:3f93dd1d4cb3 216 /* new header pbuf could not be allocated? */
sam_grove 5:3f93dd1d4cb3 217 if (q == NULL) {
sam_grove 5:3f93dd1d4cb3 218 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("raw_sendto: could not allocate header\n"));
sam_grove 5:3f93dd1d4cb3 219 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 220 }
sam_grove 5:3f93dd1d4cb3 221 if (p->tot_len != 0) {
sam_grove 5:3f93dd1d4cb3 222 /* chain header q in front of given pbuf p */
sam_grove 5:3f93dd1d4cb3 223 pbuf_chain(q, p);
sam_grove 5:3f93dd1d4cb3 224 }
sam_grove 5:3f93dd1d4cb3 225 /* { first pbuf q points to header pbuf } */
sam_grove 5:3f93dd1d4cb3 226 LWIP_DEBUGF(RAW_DEBUG, ("raw_sendto: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
sam_grove 5:3f93dd1d4cb3 227 } else {
sam_grove 5:3f93dd1d4cb3 228 /* first pbuf q equals given pbuf */
sam_grove 5:3f93dd1d4cb3 229 q = p;
sam_grove 5:3f93dd1d4cb3 230 if(pbuf_header(q, -IP_HLEN)) {
sam_grove 5:3f93dd1d4cb3 231 LWIP_ASSERT("Can't restore header we just removed!", 0);
sam_grove 5:3f93dd1d4cb3 232 return ERR_MEM;
sam_grove 5:3f93dd1d4cb3 233 }
sam_grove 5:3f93dd1d4cb3 234 }
sam_grove 5:3f93dd1d4cb3 235
sam_grove 5:3f93dd1d4cb3 236 if ((netif = ip_route(ipaddr)) == NULL) {
sam_grove 5:3f93dd1d4cb3 237 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
sam_grove 5:3f93dd1d4cb3 238 ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr)));
sam_grove 5:3f93dd1d4cb3 239 /* free any temporary header pbuf allocated by pbuf_header() */
sam_grove 5:3f93dd1d4cb3 240 if (q != p) {
sam_grove 5:3f93dd1d4cb3 241 pbuf_free(q);
sam_grove 5:3f93dd1d4cb3 242 }
sam_grove 5:3f93dd1d4cb3 243 return ERR_RTE;
sam_grove 5:3f93dd1d4cb3 244 }
sam_grove 5:3f93dd1d4cb3 245
sam_grove 5:3f93dd1d4cb3 246 #if IP_SOF_BROADCAST
sam_grove 5:3f93dd1d4cb3 247 /* broadcast filter? */
sam_grove 5:3f93dd1d4cb3 248 if (((pcb->so_options & SOF_BROADCAST) == 0) && ip_addr_isbroadcast(ipaddr, netif)) {
sam_grove 5:3f93dd1d4cb3 249 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
sam_grove 5:3f93dd1d4cb3 250 /* free any temporary header pbuf allocated by pbuf_header() */
sam_grove 5:3f93dd1d4cb3 251 if (q != p) {
sam_grove 5:3f93dd1d4cb3 252 pbuf_free(q);
sam_grove 5:3f93dd1d4cb3 253 }
sam_grove 5:3f93dd1d4cb3 254 return ERR_VAL;
sam_grove 5:3f93dd1d4cb3 255 }
sam_grove 5:3f93dd1d4cb3 256 #endif /* IP_SOF_BROADCAST */
sam_grove 5:3f93dd1d4cb3 257
sam_grove 5:3f93dd1d4cb3 258 if (ip_addr_isany(&pcb->local_ip)) {
sam_grove 5:3f93dd1d4cb3 259 /* use outgoing network interface IP address as source address */
sam_grove 5:3f93dd1d4cb3 260 src_ip = &(netif->ip_addr);
sam_grove 5:3f93dd1d4cb3 261 } else {
sam_grove 5:3f93dd1d4cb3 262 /* use RAW PCB local IP address as source address */
sam_grove 5:3f93dd1d4cb3 263 src_ip = &(pcb->local_ip);
sam_grove 5:3f93dd1d4cb3 264 }
sam_grove 5:3f93dd1d4cb3 265
sam_grove 5:3f93dd1d4cb3 266 #if LWIP_NETIF_HWADDRHINT
sam_grove 5:3f93dd1d4cb3 267 netif->addr_hint = &(pcb->addr_hint);
sam_grove 5:3f93dd1d4cb3 268 #endif /* LWIP_NETIF_HWADDRHINT*/
sam_grove 5:3f93dd1d4cb3 269 err = ip_output_if (q, src_ip, ipaddr, pcb->ttl, pcb->tos, pcb->protocol, netif);
sam_grove 5:3f93dd1d4cb3 270 #if LWIP_NETIF_HWADDRHINT
sam_grove 5:3f93dd1d4cb3 271 netif->addr_hint = NULL;
sam_grove 5:3f93dd1d4cb3 272 #endif /* LWIP_NETIF_HWADDRHINT*/
sam_grove 5:3f93dd1d4cb3 273
sam_grove 5:3f93dd1d4cb3 274 /* did we chain a header earlier? */
sam_grove 5:3f93dd1d4cb3 275 if (q != p) {
sam_grove 5:3f93dd1d4cb3 276 /* free the header */
sam_grove 5:3f93dd1d4cb3 277 pbuf_free(q);
sam_grove 5:3f93dd1d4cb3 278 }
sam_grove 5:3f93dd1d4cb3 279 return err;
sam_grove 5:3f93dd1d4cb3 280 }
sam_grove 5:3f93dd1d4cb3 281
sam_grove 5:3f93dd1d4cb3 282 /**
sam_grove 5:3f93dd1d4cb3 283 * Send the raw IP packet to the address given by raw_connect()
sam_grove 5:3f93dd1d4cb3 284 *
sam_grove 5:3f93dd1d4cb3 285 * @param pcb the raw pcb which to send
sam_grove 5:3f93dd1d4cb3 286 * @param p the IP payload to send
sam_grove 5:3f93dd1d4cb3 287 *
sam_grove 5:3f93dd1d4cb3 288 */
sam_grove 5:3f93dd1d4cb3 289 err_t
sam_grove 5:3f93dd1d4cb3 290 raw_send(struct raw_pcb *pcb, struct pbuf *p)
sam_grove 5:3f93dd1d4cb3 291 {
sam_grove 5:3f93dd1d4cb3 292 return raw_sendto(pcb, p, &pcb->remote_ip);
sam_grove 5:3f93dd1d4cb3 293 }
sam_grove 5:3f93dd1d4cb3 294
sam_grove 5:3f93dd1d4cb3 295 /**
sam_grove 5:3f93dd1d4cb3 296 * Remove an RAW PCB.
sam_grove 5:3f93dd1d4cb3 297 *
sam_grove 5:3f93dd1d4cb3 298 * @param pcb RAW PCB to be removed. The PCB is removed from the list of
sam_grove 5:3f93dd1d4cb3 299 * RAW PCB's and the data structure is freed from memory.
sam_grove 5:3f93dd1d4cb3 300 *
sam_grove 5:3f93dd1d4cb3 301 * @see raw_new()
sam_grove 5:3f93dd1d4cb3 302 */
sam_grove 5:3f93dd1d4cb3 303 void
sam_grove 5:3f93dd1d4cb3 304 raw_remove(struct raw_pcb *pcb)
sam_grove 5:3f93dd1d4cb3 305 {
sam_grove 5:3f93dd1d4cb3 306 struct raw_pcb *pcb2;
sam_grove 5:3f93dd1d4cb3 307 /* pcb to be removed is first in list? */
sam_grove 5:3f93dd1d4cb3 308 if (raw_pcbs == pcb) {
sam_grove 5:3f93dd1d4cb3 309 /* make list start at 2nd pcb */
sam_grove 5:3f93dd1d4cb3 310 raw_pcbs = raw_pcbs->next;
sam_grove 5:3f93dd1d4cb3 311 /* pcb not 1st in list */
sam_grove 5:3f93dd1d4cb3 312 } else {
sam_grove 5:3f93dd1d4cb3 313 for(pcb2 = raw_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
sam_grove 5:3f93dd1d4cb3 314 /* find pcb in raw_pcbs list */
sam_grove 5:3f93dd1d4cb3 315 if (pcb2->next != NULL && pcb2->next == pcb) {
sam_grove 5:3f93dd1d4cb3 316 /* remove pcb from list */
sam_grove 5:3f93dd1d4cb3 317 pcb2->next = pcb->next;
sam_grove 5:3f93dd1d4cb3 318 }
sam_grove 5:3f93dd1d4cb3 319 }
sam_grove 5:3f93dd1d4cb3 320 }
sam_grove 5:3f93dd1d4cb3 321 memp_free(MEMP_RAW_PCB, pcb);
sam_grove 5:3f93dd1d4cb3 322 }
sam_grove 5:3f93dd1d4cb3 323
sam_grove 5:3f93dd1d4cb3 324 /**
sam_grove 5:3f93dd1d4cb3 325 * Create a RAW PCB.
sam_grove 5:3f93dd1d4cb3 326 *
sam_grove 5:3f93dd1d4cb3 327 * @return The RAW PCB which was created. NULL if the PCB data structure
sam_grove 5:3f93dd1d4cb3 328 * could not be allocated.
sam_grove 5:3f93dd1d4cb3 329 *
sam_grove 5:3f93dd1d4cb3 330 * @param proto the protocol number of the IPs payload (e.g. IP_PROTO_ICMP)
sam_grove 5:3f93dd1d4cb3 331 *
sam_grove 5:3f93dd1d4cb3 332 * @see raw_remove()
sam_grove 5:3f93dd1d4cb3 333 */
sam_grove 5:3f93dd1d4cb3 334 struct raw_pcb *
sam_grove 5:3f93dd1d4cb3 335 raw_new(u8_t proto)
sam_grove 5:3f93dd1d4cb3 336 {
sam_grove 5:3f93dd1d4cb3 337 struct raw_pcb *pcb;
sam_grove 5:3f93dd1d4cb3 338
sam_grove 5:3f93dd1d4cb3 339 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_new\n"));
sam_grove 5:3f93dd1d4cb3 340
sam_grove 5:3f93dd1d4cb3 341 pcb = (struct raw_pcb *)memp_malloc(MEMP_RAW_PCB);
sam_grove 5:3f93dd1d4cb3 342 /* could allocate RAW PCB? */
sam_grove 5:3f93dd1d4cb3 343 if (pcb != NULL) {
sam_grove 5:3f93dd1d4cb3 344 /* initialize PCB to all zeroes */
sam_grove 5:3f93dd1d4cb3 345 memset(pcb, 0, sizeof(struct raw_pcb));
sam_grove 5:3f93dd1d4cb3 346 pcb->protocol = proto;
sam_grove 5:3f93dd1d4cb3 347 pcb->ttl = RAW_TTL;
sam_grove 5:3f93dd1d4cb3 348 pcb->next = raw_pcbs;
sam_grove 5:3f93dd1d4cb3 349 raw_pcbs = pcb;
sam_grove 5:3f93dd1d4cb3 350 }
sam_grove 5:3f93dd1d4cb3 351 return pcb;
sam_grove 5:3f93dd1d4cb3 352 }
sam_grove 5:3f93dd1d4cb3 353
sam_grove 5:3f93dd1d4cb3 354 #endif /* LWIP_RAW */