Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers raw.h Source File

raw.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * raw API (to be used from TCPIP thread)\n
00004  * See also @ref raw_raw
00005  */
00006 
00007 /*
00008  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without modification,
00012  * are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice,
00015  *    this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright notice,
00017  *    this list of conditions and the following disclaimer in the documentation
00018  *    and/or other materials provided with the distribution.
00019  * 3. The name of the author may not be used to endorse or promote products
00020  *    derived from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00023  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00024  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00025  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00027  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00030  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00031  * OF SUCH DAMAGE.
00032  *
00033  * This file is part of the lwIP TCP/IP stack.
00034  *
00035  * Author: Adam Dunkels <adam@sics.se>
00036  *
00037  */
00038 #ifndef LWIP_HDR_RAW_H
00039 #define LWIP_HDR_RAW_H
00040 
00041 #include "lwip/opt.h"
00042 
00043 #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
00044 
00045 #include "lwip/pbuf.h"
00046 #include "lwip/def.h"
00047 #include "lwip/ip.h"
00048 #include "lwip/ip_addr.h"
00049 #include "lwip/ip6_addr.h"
00050 
00051 #ifdef __cplusplus
00052 extern "C" {
00053 #endif
00054 
00055 #define RAW_FLAGS_CONNECTED      0x01U
00056 #define RAW_FLAGS_HDRINCL        0x02U
00057 #define RAW_FLAGS_MULTICAST_LOOP 0x04U
00058 
00059 struct raw_pcb;
00060 
00061 /** Function prototype for raw pcb receive callback functions.
00062  * @param arg user supplied argument (raw_pcb.recv_arg)
00063  * @param pcb the raw_pcb which received data
00064  * @param p the packet buffer that was received
00065  * @param addr the remote IP address from which the packet was received
00066  * @return 1 if the packet was 'eaten' (aka. deleted),
00067  *         0 if the packet lives on
00068  * If returning 1, the callback is responsible for freeing the pbuf
00069  * if it's not used any more.
00070  */
00071 typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
00072     const ip_addr_t *addr);
00073 
00074 /** the RAW protocol control block */
00075 struct raw_pcb {
00076   /* Common members of all PCB types */
00077   IP_PCB;
00078 
00079   struct raw_pcb *next;
00080 
00081   u8_t protocol;
00082   u8_t flags;
00083 
00084 #if LWIP_MULTICAST_TX_OPTIONS
00085   /** outgoing network interface for multicast packets, by interface index (if nonzero) */
00086   u8_t mcast_ifindex;
00087   /** TTL for outgoing multicast packets */
00088   u8_t mcast_ttl;
00089 #endif /* LWIP_MULTICAST_TX_OPTIONS */
00090 
00091   /** receive callback function */
00092   raw_recv_fn recv;
00093   /* user-supplied argument for the recv callback */
00094   void *recv_arg;
00095 #if LWIP_IPV6
00096   /* fields for handling checksum computations as per RFC3542. */
00097   u16_t chksum_offset;
00098   u8_t  chksum_reqd;
00099 #endif
00100 };
00101 
00102 /* The following functions is the application layer interface to the
00103    RAW code. */
00104 struct raw_pcb * raw_new        (u8_t proto);
00105 struct raw_pcb * raw_new_ip_type(u8_t type, u8_t proto);
00106 void             raw_remove     (struct raw_pcb *pcb);
00107 err_t            raw_bind       (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
00108 void             raw_bind_netif (struct raw_pcb *pcb, const struct netif *netif);
00109 err_t            raw_connect    (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
00110 void             raw_disconnect (struct raw_pcb *pcb);
00111 
00112 err_t            raw_sendto     (struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr);
00113 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);
00114 err_t            raw_send       (struct raw_pcb *pcb, struct pbuf *p);
00115 
00116 void             raw_recv       (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg);
00117 
00118 #define          raw_flags(pcb) ((pcb)->flags)
00119 #define          raw_setflags(pcb,f)  ((pcb)->flags = (f))
00120 
00121 #define          raw_set_flags(pcb, set_flags)     do { (pcb)->flags = (u8_t)((pcb)->flags |  (set_flags)); } while(0)
00122 #define          raw_clear_flags(pcb, clr_flags)   do { (pcb)->flags = (u8_t)((pcb)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
00123 #define          raw_is_flag_set(pcb, flag)        (((pcb)->flags & (flag)) != 0)
00124 
00125 #define raw_init() /* Compatibility define, no init needed. */
00126 
00127 /* for compatibility with older implementation */
00128 #define raw_new_ip6(proto) raw_new_ip_type(IPADDR_TYPE_V6, proto)
00129 
00130 #if LWIP_MULTICAST_TX_OPTIONS
00131 #define raw_set_multicast_netif_index(pcb, idx) ((pcb)->mcast_ifindex = (idx))
00132 #define raw_get_multicast_netif_index(pcb)      ((pcb)->mcast_ifindex)
00133 #define raw_set_multicast_ttl(pcb, value)       ((pcb)->mcast_ttl = (value))
00134 #define raw_get_multicast_ttl(pcb)              ((pcb)->mcast_ttl)
00135 #endif /* LWIP_MULTICAST_TX_OPTIONS */
00136 
00137 #ifdef __cplusplus
00138 }
00139 #endif
00140 
00141 #endif /* LWIP_RAW */
00142 
00143 #endif /* LWIP_HDR_RAW_H */