Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers altcp.h Source File

altcp.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Application layered TCP connection API (to be used from TCPIP thread)\n
00004  *
00005  * This file contains the generic API.
00006  * For more details see @ref altcp_api.
00007  */
00008 
00009 /*
00010  * Copyright (c) 2017 Simon Goldschmidt
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  * 2. Redistributions in binary form must reproduce the above copyright notice,
00019  *    this list of conditions and the following disclaimer in the documentation
00020  *    and/or other materials provided with the distribution.
00021  * 3. The name of the author may not be used to endorse or promote products
00022  *    derived from this software without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00025  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00026  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00027  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00028  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00029  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00032  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00033  * OF SUCH DAMAGE.
00034  *
00035  * This file is part of the lwIP TCP/IP stack.
00036  *
00037  * Author: Simon Goldschmidt <goldsimon@gmx.de>
00038  *
00039  */
00040 #ifndef LWIP_HDR_ALTCP_H
00041 #define LWIP_HDR_ALTCP_H
00042 
00043 #include "lwip/opt.h"
00044 
00045 #if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */
00046 
00047 #include "lwip/tcpbase.h"
00048 #include "lwip/err.h"
00049 #include "lwip/pbuf.h"
00050 #include "lwip/ip_addr.h"
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 
00056 struct altcp_pcb;
00057 struct altcp_functions;
00058 
00059 typedef err_t (*altcp_accept_fn)(void *arg, struct altcp_pcb *new_conn, err_t err);
00060 typedef err_t (*altcp_connected_fn)(void *arg, struct altcp_pcb *conn, err_t err);
00061 typedef err_t (*altcp_recv_fn)(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err);
00062 typedef err_t (*altcp_sent_fn)(void *arg, struct altcp_pcb *conn, u16_t len);
00063 typedef err_t (*altcp_poll_fn)(void *arg, struct altcp_pcb *conn);
00064 typedef void  (*altcp_err_fn)(void *arg, err_t err);
00065 
00066 typedef struct altcp_pcb* (*altcp_new_fn)(void *arg, u8_t ip_type);
00067 
00068 struct altcp_pcb {
00069   const struct altcp_functions *fns;
00070   struct altcp_pcb *inner_conn;
00071   void *arg;
00072   void *state;
00073   /* application callbacks */
00074   altcp_accept_fn     accept;
00075   altcp_connected_fn  connected;
00076   altcp_recv_fn       recv;
00077   altcp_sent_fn       sent;
00078   altcp_poll_fn       poll;
00079   altcp_err_fn        err;
00080   u8_t pollinterval;
00081 };
00082 
00083 /** @ingroup altcp */
00084 typedef struct altcp_allocator_s {
00085   /** Allocator function */
00086   altcp_new_fn  alloc;
00087   /** Argument to allocator function */
00088   void         *arg;
00089 } altcp_allocator_t;
00090 
00091 struct altcp_pcb *altcp_new(altcp_allocator_t *allocator);
00092 struct altcp_pcb *altcp_new_ip6(altcp_allocator_t *allocator);
00093 struct altcp_pcb *altcp_new_ip_type(altcp_allocator_t *allocator, u8_t ip_type);
00094 
00095 void altcp_arg (struct altcp_pcb *conn, void *arg);
00096 void altcp_accept (struct altcp_pcb *conn, altcp_accept_fn accept);
00097 void altcp_recv (struct altcp_pcb *conn, altcp_recv_fn recv);
00098 void altcp_sent (struct altcp_pcb *conn, altcp_sent_fn sent);
00099 void altcp_poll (struct altcp_pcb *conn, altcp_poll_fn poll, u8_t interval);
00100 void altcp_err (struct altcp_pcb *conn, altcp_err_fn err);
00101 
00102 void  altcp_recved (struct altcp_pcb *conn, u16_t len);
00103 err_t altcp_bind (struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port);
00104 err_t altcp_connect (struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected);
00105 
00106 /* return conn for source code compatibility to tcp callback API only */
00107 struct altcp_pcb *altcp_listen_with_backlog_and_err (struct altcp_pcb *conn, u8_t backlog, err_t *err);
00108 #define altcp_listen_with_backlog(conn, backlog) altcp_listen_with_backlog_and_err(conn, backlog, NULL)
00109 /** @ingroup altcp */
00110 #define altcp_listen(conn) altcp_listen_with_backlog_and_err(conn, TCP_DEFAULT_LISTEN_BACKLOG, NULL)
00111 
00112 void altcp_abort (struct altcp_pcb *conn);
00113 err_t altcp_close (struct altcp_pcb *conn);
00114 err_t altcp_shutdown (struct altcp_pcb *conn, int shut_rx, int shut_tx);
00115 
00116 err_t altcp_write (struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags);
00117 err_t altcp_output (struct altcp_pcb *conn);
00118 
00119 u16_t altcp_mss (struct altcp_pcb *conn);
00120 u16_t altcp_sndbuf (struct altcp_pcb *conn);
00121 u16_t altcp_sndqueuelen (struct altcp_pcb *conn);
00122 void  altcp_nagle_disable(struct altcp_pcb *conn);
00123 void  altcp_nagle_enable(struct altcp_pcb *conn);
00124 int   altcp_nagle_disabled(struct altcp_pcb *conn);
00125 
00126 void  altcp_setprio (struct altcp_pcb *conn, u8_t prio);
00127 
00128 err_t altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port);
00129 ip_addr_t *altcp_get_ip(struct altcp_pcb *conn, int local);
00130 u16_t altcp_get_port(struct altcp_pcb *conn, int local);
00131 
00132 #ifdef LWIP_DEBUG
00133 enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn);
00134 #endif
00135 
00136 #ifdef __cplusplus
00137 }
00138 #endif
00139 
00140 #else /* LWIP_ALTCP */
00141 
00142 /* ALTCP disabled, define everything to link against tcp callback API (e.g. to get a small non-ssl httpd) */
00143 
00144 #include "lwip/tcp.h"
00145 
00146 #define altcp_accept_fn tcp_accept_fn
00147 #define altcp_connected_fn tcp_connected_fn
00148 #define altcp_recv_fn tcp_recv_fn
00149 #define altcp_sent_fn tcp_sent_fn
00150 #define altcp_poll_fn tcp_poll_fn
00151 #define altcp_err_fn tcp_err_fn
00152 
00153 #define altcp_pcb tcp_pcb
00154 #define altcp_tcp_new_ip_type tcp_new_ip_type
00155 #define altcp_tcp_new tcp_new
00156 #define altcp_tcp_new_ip6 tcp_new_ip6
00157 
00158 #define altcp_new(allocator) tcp_new()
00159 #define altcp_new_ip6(allocator) tcp_new_ip6()
00160 #define altcp_new_ip_type(allocator, ip_type) tcp_new_ip_type(ip_type)
00161 
00162 #define altcp_arg tcp_arg
00163 #define altcp_accept tcp_accept
00164 #define altcp_recv tcp_recv
00165 #define altcp_sent tcp_sent
00166 #define altcp_poll tcp_poll
00167 #define altcp_err tcp_err
00168 
00169 #define altcp_recved tcp_recved
00170 #define altcp_bind tcp_bind
00171 #define altcp_connect tcp_connect
00172 
00173 #define altcp_listen_with_backlog_and_err tcp_listen_with_backlog_and_err
00174 #define altcp_listen_with_backlog tcp_listen_with_backlog
00175 #define altcp_listen tcp_listen
00176 
00177 #define altcp_abort tcp_abort
00178 #define altcp_close tcp_close
00179 #define altcp_shutdown tcp_shutdown
00180 
00181 #define altcp_write tcp_write
00182 #define altcp_output tcp_output
00183 
00184 #define altcp_mss tcp_mss
00185 #define altcp_sndbuf tcp_sndbuf
00186 #define altcp_sndqueuelen tcp_sndqueuelen
00187 #define altcp_nagle_disable tcp_nagle_disable
00188 #define altcp_nagle_enable tcp_nagle_enable
00189 #define altcp_nagle_disabled tcp_nagle_disabled
00190 #define altcp_setprio tcp_setprio
00191 
00192 #define altcp_get_tcp_addrinfo tcp_get_tcp_addrinfo
00193 #define altcp_get_ip(pcb, local) ((local) ? (&(pcb)->local_ip) : (&(pcb)->remote_ip))
00194 
00195 #ifdef LWIP_DEBUG
00196 #define altcp_dbg_get_tcp_state tcp_dbg_get_tcp_state
00197 #endif
00198 
00199 #endif /* LWIP_ALTCP */
00200 
00201 #endif /* LWIP_HDR_ALTCP_H */