Small Testprogram to have WebAccess via Webserver to a 433Mhz tranmitter to control remotly some devices from remote, with TFTP, NTP and RMF. This could be a base to develop applications.

Dependencies:   ChaNFSSD TFTPServer RMFWeb

Dependents:   RMFWeb

Committer:
ED7418
Date:
Mon Jun 16 07:40:08 2014 +0000
Revision:
1:809b59c7a800
Parent:
0:51f1ef89ec7b
mbed-lib and other libs are a based on a project, published in a Elektor-book "ARM-microkontroller Part II".

Who changed what in which revision?

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