[457] | 1 | /**
|
---|
| 2 | * @file
|
---|
| 3 | * raw API (to be used from TCPIP thread)\n
|
---|
| 4 | * See also @ref raw_raw
|
---|
| 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 | #ifndef LWIP_HDR_RAW_H
|
---|
| 39 | #define LWIP_HDR_RAW_H
|
---|
| 40 |
|
---|
| 41 | #include "lwip/opt.h"
|
---|
| 42 |
|
---|
| 43 | #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
|
---|
| 44 |
|
---|
| 45 | #include "lwip/pbuf.h"
|
---|
| 46 | #include "lwip/def.h"
|
---|
| 47 | #include "lwip/ip.h"
|
---|
| 48 | #include "lwip/ip_addr.h"
|
---|
| 49 | #include "lwip/ip6_addr.h"
|
---|
| 50 |
|
---|
| 51 | #ifdef __cplusplus
|
---|
| 52 | extern "C" {
|
---|
| 53 | #endif
|
---|
| 54 |
|
---|
| 55 | #define RAW_FLAGS_CONNECTED 0x01U
|
---|
| 56 | #define RAW_FLAGS_HDRINCL 0x02U
|
---|
| 57 | #define RAW_FLAGS_MULTICAST_LOOP 0x04U
|
---|
| 58 |
|
---|
| 59 | struct raw_pcb;
|
---|
| 60 |
|
---|
| 61 | /** Function prototype for raw pcb receive callback functions.
|
---|
| 62 | * @param arg user supplied argument (raw_pcb.recv_arg)
|
---|
| 63 | * @param pcb the raw_pcb which received data
|
---|
| 64 | * @param p the packet buffer that was received
|
---|
| 65 | * @param addr the remote IP address from which the packet was received
|
---|
| 66 | * @return 1 if the packet was 'eaten' (aka. deleted),
|
---|
| 67 | * 0 if the packet lives on
|
---|
| 68 | * If returning 1, the callback is responsible for freeing the pbuf
|
---|
| 69 | * if it's not used any more.
|
---|
| 70 | */
|
---|
| 71 | typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
|
---|
| 72 | const ip_addr_t *addr);
|
---|
| 73 |
|
---|
| 74 | /** the RAW protocol control block */
|
---|
| 75 | struct raw_pcb {
|
---|
| 76 | /* Common members of all PCB types */
|
---|
| 77 | IP_PCB;
|
---|
| 78 |
|
---|
| 79 | struct raw_pcb *next;
|
---|
| 80 |
|
---|
| 81 | u8_t protocol;
|
---|
| 82 | u8_t flags;
|
---|
| 83 |
|
---|
| 84 | #if LWIP_MULTICAST_TX_OPTIONS
|
---|
| 85 | /** outgoing network interface for multicast packets, by interface index (if nonzero) */
|
---|
| 86 | u8_t mcast_ifindex;
|
---|
| 87 | /** TTL for outgoing multicast packets */
|
---|
| 88 | u8_t mcast_ttl;
|
---|
| 89 | #endif /* LWIP_MULTICAST_TX_OPTIONS */
|
---|
| 90 |
|
---|
| 91 | /** receive callback function */
|
---|
| 92 | raw_recv_fn recv;
|
---|
| 93 | /* user-supplied argument for the recv callback */
|
---|
| 94 | void *recv_arg;
|
---|
| 95 | #if LWIP_IPV6
|
---|
| 96 | /* fields for handling checksum computations as per RFC3542. */
|
---|
| 97 | u16_t chksum_offset;
|
---|
| 98 | u8_t chksum_reqd;
|
---|
| 99 | #endif
|
---|
| 100 | };
|
---|
| 101 |
|
---|
| 102 | /* The following functions is the application layer interface to the
|
---|
| 103 | RAW code. */
|
---|
| 104 | struct raw_pcb * raw_new (u8_t proto);
|
---|
| 105 | struct raw_pcb * raw_new_ip_type(u8_t type, u8_t proto);
|
---|
| 106 | void raw_remove (struct raw_pcb *pcb);
|
---|
| 107 | err_t raw_bind (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
|
---|
| 108 | void raw_bind_netif (struct raw_pcb *pcb, const struct netif *netif);
|
---|
| 109 | err_t raw_connect (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
|
---|
| 110 | void raw_disconnect (struct raw_pcb *pcb);
|
---|
| 111 |
|
---|
| 112 | err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr);
|
---|
| 113 | err_t raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, struct netif *netif, const ip_addr_t *src_ip);
|
---|
| 114 | err_t raw_send (struct raw_pcb *pcb, struct pbuf *p);
|
---|
| 115 |
|
---|
| 116 | void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg);
|
---|
| 117 |
|
---|
| 118 | #define raw_flags(pcb) ((pcb)->flags)
|
---|
| 119 | #define raw_setflags(pcb,f) ((pcb)->flags = (f))
|
---|
| 120 |
|
---|
| 121 | #define raw_set_flags(pcb, set_flags) do { (pcb)->flags = (u8_t)((pcb)->flags | (set_flags)); } while(0)
|
---|
| 122 | #define raw_clear_flags(pcb, clr_flags) do { (pcb)->flags = (u8_t)((pcb)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
|
---|
| 123 | #define raw_is_flag_set(pcb, flag) (((pcb)->flags & (flag)) != 0)
|
---|
| 124 |
|
---|
| 125 | #define raw_init() /* Compatibility define, no init needed. */
|
---|
| 126 |
|
---|
| 127 | /* for compatibility with older implementation */
|
---|
| 128 | #define raw_new_ip6(proto) raw_new_ip_type(IPADDR_TYPE_V6, proto)
|
---|
| 129 |
|
---|
| 130 | #if LWIP_MULTICAST_TX_OPTIONS
|
---|
| 131 | #define raw_set_multicast_netif_index(pcb, idx) ((pcb)->mcast_ifindex = (idx))
|
---|
| 132 | #define raw_get_multicast_netif_index(pcb) ((pcb)->mcast_ifindex)
|
---|
| 133 | #define raw_set_multicast_ttl(pcb, value) ((pcb)->mcast_ttl = (value))
|
---|
| 134 | #define raw_get_multicast_ttl(pcb) ((pcb)->mcast_ttl)
|
---|
| 135 | #endif /* LWIP_MULTICAST_TX_OPTIONS */
|
---|
| 136 |
|
---|
| 137 | #ifdef __cplusplus
|
---|
| 138 | }
|
---|
| 139 | #endif
|
---|
| 140 |
|
---|
| 141 | #endif /* LWIP_RAW */
|
---|
| 142 |
|
---|
| 143 | #endif /* LWIP_HDR_RAW_H */
|
---|