1195972f6Sopenharmony_ci/** 2195972f6Sopenharmony_ci * @file 3195972f6Sopenharmony_ci * Application layered TCP connection API (to be used from TCPIP thread)\n 4195972f6Sopenharmony_ci * This interface mimics the tcp callback API to the application while preventing 5195972f6Sopenharmony_ci * direct linking (much like virtual functions). 6195972f6Sopenharmony_ci * This way, an application can make use of other application layer protocols 7195972f6Sopenharmony_ci * on top of TCP without knowing the details (e.g. TLS, proxy connection). 8195972f6Sopenharmony_ci * 9195972f6Sopenharmony_ci * This file contains allocation implementation that combine several layers. 10195972f6Sopenharmony_ci */ 11195972f6Sopenharmony_ci 12195972f6Sopenharmony_ci/* 13195972f6Sopenharmony_ci * Copyright (c) 2017 Simon Goldschmidt 14195972f6Sopenharmony_ci * All rights reserved. 15195972f6Sopenharmony_ci * 16195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 17195972f6Sopenharmony_ci * are permitted provided that the following conditions are met: 18195972f6Sopenharmony_ci * 19195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, 20195972f6Sopenharmony_ci * this list of conditions and the following disclaimer. 21195972f6Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, 22195972f6Sopenharmony_ci * this list of conditions and the following disclaimer in the documentation 23195972f6Sopenharmony_ci * and/or other materials provided with the distribution. 24195972f6Sopenharmony_ci * 3. The name of the author may not be used to endorse or promote products 25195972f6Sopenharmony_ci * derived from this software without specific prior written permission. 26195972f6Sopenharmony_ci * 27195972f6Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 28195972f6Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29195972f6Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 30195972f6Sopenharmony_ci * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 31195972f6Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 32195972f6Sopenharmony_ci * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33195972f6Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34195972f6Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 35195972f6Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 36195972f6Sopenharmony_ci * OF SUCH DAMAGE. 37195972f6Sopenharmony_ci * 38195972f6Sopenharmony_ci * This file is part of the lwIP TCP/IP stack. 39195972f6Sopenharmony_ci * 40195972f6Sopenharmony_ci * Author: Simon Goldschmidt <goldsimon@gmx.de> 41195972f6Sopenharmony_ci * 42195972f6Sopenharmony_ci */ 43195972f6Sopenharmony_ci 44195972f6Sopenharmony_ci#include "lwip/opt.h" 45195972f6Sopenharmony_ci 46195972f6Sopenharmony_ci#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ 47195972f6Sopenharmony_ci 48195972f6Sopenharmony_ci#include "lwip/altcp.h" 49195972f6Sopenharmony_ci#include "lwip/altcp_tcp.h" 50195972f6Sopenharmony_ci#include "lwip/altcp_tls.h" 51195972f6Sopenharmony_ci#include "lwip/priv/altcp_priv.h" 52195972f6Sopenharmony_ci#include "lwip/mem.h" 53195972f6Sopenharmony_ci 54195972f6Sopenharmony_ci#include <string.h> 55195972f6Sopenharmony_ci 56195972f6Sopenharmony_ci#if LWIP_ALTCP_TLS 57195972f6Sopenharmony_ci 58195972f6Sopenharmony_ci/** This standard allocator function creates an altcp pcb for 59195972f6Sopenharmony_ci * TLS over TCP */ 60195972f6Sopenharmony_cistruct altcp_pcb * 61195972f6Sopenharmony_cialtcp_tls_new(struct altcp_tls_config *config, u8_t ip_type) 62195972f6Sopenharmony_ci{ 63195972f6Sopenharmony_ci struct altcp_pcb *inner_conn, *ret; 64195972f6Sopenharmony_ci LWIP_UNUSED_ARG(ip_type); 65195972f6Sopenharmony_ci 66195972f6Sopenharmony_ci inner_conn = altcp_tcp_new_ip_type(ip_type); 67195972f6Sopenharmony_ci if (inner_conn == NULL) { 68195972f6Sopenharmony_ci return NULL; 69195972f6Sopenharmony_ci } 70195972f6Sopenharmony_ci ret = altcp_tls_wrap(config, inner_conn); 71195972f6Sopenharmony_ci if (ret == NULL) { 72195972f6Sopenharmony_ci altcp_close(inner_conn); 73195972f6Sopenharmony_ci } 74195972f6Sopenharmony_ci return ret; 75195972f6Sopenharmony_ci} 76195972f6Sopenharmony_ci 77195972f6Sopenharmony_ci/** This standard allocator function creates an altcp pcb for 78195972f6Sopenharmony_ci * TLS over TCP */ 79195972f6Sopenharmony_cistruct altcp_pcb * 80195972f6Sopenharmony_cialtcp_tls_alloc(void *arg, u8_t ip_type) 81195972f6Sopenharmony_ci{ 82195972f6Sopenharmony_ci return altcp_tls_new((struct altcp_tls_config *)arg, ip_type); 83195972f6Sopenharmony_ci} 84195972f6Sopenharmony_ci 85195972f6Sopenharmony_ci#endif /* LWIP_ALTCP_TLS */ 86195972f6Sopenharmony_ci 87195972f6Sopenharmony_ci#endif /* LWIP_ALTCP */ 88