• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file
3  * Application layered TCP connection API (to be used from TCPIP thread)\n
4  * This interface mimics the tcp callback API to the application while preventing
5  * direct linking (much like virtual functions).
6  * This way, an application can make use of other application layer protocols
7  * on top of TCP without knowing the details (e.g. TLS, proxy connection).
8  *
9  * This file contains allocation implementation that combine several layers.
10  */
11 
12 /*
13  * Copyright (c) 2017 Simon Goldschmidt
14  * All rights reserved.
15  *
16  * Redistribution and use in source and binary forms, with or without modification,
17  * are permitted provided that the following conditions are met:
18  *
19  * 1. Redistributions of source code must retain the above copyright notice,
20  *    this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright notice,
22  *    this list of conditions and the following disclaimer in the documentation
23  *    and/or other materials provided with the distribution.
24  * 3. The name of the author may not be used to endorse or promote products
25  *    derived from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
28  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
30  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
32  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
36  * OF SUCH DAMAGE.
37  *
38  * This file is part of the lwIP TCP/IP stack.
39  *
40  * Author: Simon Goldschmidt <goldsimon@gmx.de>
41  *
42  */
43 
44 #include "lwip/opt.h"
45 
46 #if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */
47 
48 #include "lwip/altcp.h"
49 #include "lwip/altcp_tcp.h"
50 #include "lwip/altcp_tls.h"
51 #include "lwip/priv/altcp_priv.h"
52 #include "lwip/mem.h"
53 
54 #include <string.h>
55 
56 #if LWIP_ALTCP_TLS
57 
58 /** This standard allocator function creates an altcp pcb for
59  * TLS over TCP */
60 struct altcp_pcb *
altcp_tls_new(struct altcp_tls_config * config,u8_t ip_type)61 altcp_tls_new(struct altcp_tls_config *config, u8_t ip_type)
62 {
63   struct altcp_pcb *inner_conn, *ret;
64   LWIP_UNUSED_ARG(ip_type);
65 
66   inner_conn = altcp_tcp_new_ip_type(ip_type);
67   if (inner_conn == NULL) {
68     return NULL;
69   }
70   ret = altcp_tls_wrap(config, inner_conn);
71   if (ret == NULL) {
72     altcp_close(inner_conn);
73   }
74   return ret;
75 }
76 
77 /** This standard allocator function creates an altcp pcb for
78  * TLS over TCP */
79 struct altcp_pcb *
altcp_tls_alloc(void * arg,u8_t ip_type)80 altcp_tls_alloc(void *arg, u8_t ip_type)
81 {
82   return altcp_tls_new((struct altcp_tls_config *)arg, ip_type);
83 }
84 
85 #endif /* LWIP_ALTCP_TLS */
86 
87 #endif /* LWIP_ALTCP */
88