1 /** 2 * @file 3 * Functions to sync with TCPIP thread 4 */ 5 6 /* 7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without modification, 11 * are permitted provided that the following conditions are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 * OF SUCH DAMAGE. 31 * 32 * This file is part of the lwIP TCP/IP stack. 33 * 34 * Author: Adam Dunkels <adam@sics.se> 35 * 36 */ 37 #ifndef LWIP_HDR_TCPIP_H 38 #define LWIP_HDR_TCPIP_H 39 40 #include "lwip/opt.h" 41 42 #if !NO_SYS /* don't build if not configured for use in lwipopts.h */ 43 44 #include "lwip/err.h" 45 #include "lwip/timeouts.h" 46 #include "lwip/netif.h" 47 48 #if LWIP_L3_EVENT_MSG 49 #include "lwip/l3event.h" 50 #endif 51 52 #if defined (__cplusplus) && __cplusplus 53 extern "C" { 54 #endif 55 56 #if LWIP_TCPIP_CORE_LOCKING 57 /** The global semaphore to lock the stack. */ 58 extern sys_mutex_t lock_tcpip_core; 59 /** Lock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */ 60 #define LOCK_TCPIP_CORE() (void)sys_mutex_lock(&lock_tcpip_core) 61 /** Unlock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */ 62 #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core) 63 #else /* LWIP_TCPIP_CORE_LOCKING */ 64 #define LOCK_TCPIP_CORE() 65 #define UNLOCK_TCPIP_CORE() 66 #endif /* LWIP_TCPIP_CORE_LOCKING */ 67 68 extern int tcpip_init_finish; 69 70 struct pbuf; 71 struct netif; 72 73 /** 74 * @ingroup Tcip_interface 75 * @brief 76 * This callback checks whether initialization is done. 77 * 78 * @param[in] arg Specifies the argument to pass to tcpip_init_done. 79 * 80 * 81 * @par Return values 82 * None 83 */ 84 typedef void (*tcpip_init_done_fn)(void *arg); 85 /** Function prototype for functions passed to tcpip_callback() */ 86 typedef void (*tcpip_callback_fn)(void *ctx); 87 88 /* Forward declarations */ 89 struct tcpip_callback_msg; 90 91 /* 92 * Func Name: tcpip_init 93 */ 94 /** 95 * @ingroup Tcip_interface 96 * @brief 97 * This API initializes all sub modules and starts the tcpip_thread. 98 * 99 * @param[in] tcpip_init_done Specifies the function to call when the 100 * tcpip_thread is running and finished initializing. 101 * @param[in] arg Specifies the argument to pass to tcpip_init_done. 102 * @par Return values 103 * None 104 */ 105 void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg); 106 #if LWIP_ALLOW_SOCKET_CONFIG 107 108 /* 109 * Func Name: lwip_set_socket_num 110 */ 111 /** 112 * @ingroup TCPIP_Interfaces 113 * 114 * 115 * @brief 116 * This API is used to configure maximum number of allowed sockets in the lwIP stack. 117 * 118 * 119 * 120 * @param[in] socketnum Indicates the maximum number of sockets. 121 * 122 * @return 123 * 0: On Success\n 124 * Non Zero value: On Failure 125 * 126 * 127 * @Note 128 * \n 129 * Call this API before tcpip_init, or it will be failed. 130 * If this API is not invoked, maximum socket number is set to DEFAULT_LWIP_NUM_SOCKETS, which is defined in 131 * opt.h/lwipopts.h. 132 * @par Related Topics 133 * \n 134 * None 135 */ 136 int lwip_set_socket_num(unsigned int socketnum); 137 138 /* 139 * Func Name: lwip_get_socket_num 140 */ 141 /** 142 * @ingroup TCPIP_Interfaces 143 * 144 * 145 * @brief 146 * This API is used to get the maximum socket num setting in lwIP. 147 * 148 * 149 * @param[in] void 150 * 151 * @return 152 * current max socket number 153 * 154 * @par Required Header File 155 * tcpip.h 156 * 157 * @par Note 158 * None 159 */ 160 unsigned int lwip_get_socket_num(void); 161 #endif /* LWIP_ALLOW_SOCKET_CONFIG */ 162 163 err_t tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn); 164 err_t tcpip_input(struct pbuf *p, struct netif *inp); 165 166 #if LWIP_PLC || LWIP_IEEE802154 167 err_t tcpip_lln_inpkt(struct netif *iface, struct pbuf *p, 168 struct linklayer_addr *sender_mac, struct linklayer_addr *recver_mac, 169 netif_lln_input_fn input_lln_fn); 170 171 err_t tcpip_lln_input(struct netif *iface, struct pbuf *p, 172 struct linklayer_addr *sendermac, struct linklayer_addr *recvermac); 173 #endif 174 err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block); 175 /** 176 * @ingroup lwip_os 177 * @see tcpip_callback_with_block 178 */ 179 #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1) 180 181 #if LWIP_API_RICH 182 struct tcpip_callback_msg *tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx); 183 void tcpip_callbackmsg_delete(struct tcpip_callback_msg *msg); 184 err_t tcpip_trycallback(struct tcpip_callback_msg *msg); 185 186 /* free pbufs or heap memory from another context without blocking */ 187 err_t pbuf_free_callback(struct pbuf *p); 188 err_t mem_free_callback(void *m); 189 #endif /* LWIP_API_RICH */ 190 191 #if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS 192 err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); 193 err_t tcpip_untimeout(sys_timeout_handler h, void *arg); 194 #endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ 195 196 /** This structure defines TCP IP connections. */ 197 struct tcpip_conn { 198 struct eth_addr dst_mac; /**< Specifies the destination MAC. */ 199 ip_addr_t src_ip; /**< Specifies the source IP address. */ 200 ip_addr_t dst_ip; /**< Specifies the destination IP address of a TCP/UDP connection. 201 If lwip_connect is not called for a UDP connection, then this field will be set to 0 for that UDP connection. */ 202 u16_t ipid; /**< Retains the same value as identification field in the IP header. */ 203 u16_t srcport; /**< Specifies the source port address. */ 204 u16_t dstport; /**< Specifies the destination port address. If connect is not called for a 205 UDP connection, then this field will be set to 0 for that UDP connection. */ 206 u32_t tcpwin; /**< Specifies the TCP window of the last sent TCP packet. For a UDP connection, 207 this field is set to 0. */ 208 u32_t seqnum; /**< Specifies the TCP sequence number of the last ACKED byte of a TCP connection. 209 For a UDP connection, this field is set to 0. */ 210 u32_t acknum; /**< Specifies the TCP Ack number of the last sent packet in the TCP connection. 211 For a UDP connection, this field is set to 0. */ 212 u32_t last_payload_len; /**< Specifies the UDP/TCP payload length of the last packet sent in 213 the UDP/TCP connection. */ 214 u32_t tsval; /**< Indicates the timestamp value. This field is 0 for both TCP and UDP connections. */ 215 u32_t tsecr; /**< Indicates the timestamp echo reply. This field is 0 for both TCP and UDP connections. */ 216 }; 217 218 #if LWIP_LOWPOWER 219 void tcpip_send_msg_na(enum lowpower_msg_type type); 220 #endif 221 222 #if LWIP_L3_EVENT_MSG 223 void tcpip_send_msg_l3_event(enum l3_event_msg_type type, void *rinfo); 224 #endif 225 226 #if defined (__cplusplus) && __cplusplus 227 } 228 #endif 229 230 #endif /* !NO_SYS */ 231 232 #endif /* LWIP_HDR_TCPIP_H */ 233