1 /*
2  *  Copyright (c) 2018, Sam Kumar <samkumar@cs.berkeley.edu>
3  *  Copyright (c) 2018, University of California, Berkeley
4  *  All rights reserved.
5  *
6  *  Redistribution and use in source and binary forms, with or without
7  *  modification, are permitted provided that the following conditions are met:
8  *  1. Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  *  2. Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *  3. Neither the name of the copyright holder nor the
14  *     names of its contributors may be used to endorse or promote products
15  *     derived from this software without specific prior written permission.
16  *
17  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  *  POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /**
31  * @file
32  *   This file defines the interface between TCPlp and the host network stack
33  *   (OpenThread, in this case). It is based on content taken from TCPlp,
34  *   modified to work with this port of TCPlp to OpenThread.
35  */
36 
37 #ifndef TCPLP_H_
38 #define TCPLP_H_
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include <errno.h>
45 #include <openthread/ip6.h>
46 #include <openthread/message.h>
47 #include "bsdtcp/ip6.h"
48 #include "bsdtcp/tcp.h"
49 #include "bsdtcp/tcp_fsm.h"
50 #include "bsdtcp/tcp_timer.h"
51 #include "bsdtcp/tcp_var.h"
52 
53 #define RELOOKUP_REQUIRED -1
54 #define CONN_LOST_NORMAL 0
55 
56 struct tcplp_signals
57 {
58     struct tcpcb* accepted_connection;
59     uint32_t      links_popped;
60     uint32_t      bytes_acked;
61     bool          conn_established;
62     bool          recvbuf_added;
63     bool          rcvd_fin;
64 };
65 
66 /*
67  * Functions that the TCP protocol logic can call to interact with the rest of
68  * the system.
69  */
70 otMessage *   tcplp_sys_new_message(otInstance *aInstance);
71 void          tcplp_sys_free_message(otInstance *aInstance, otMessage *aMessage);
72 void          tcplp_sys_send_message(otInstance *aInstance, otMessage *aMessage, otMessageInfo *aMessageInfo);
73 uint32_t      tcplp_sys_get_ticks();
74 uint32_t      tcplp_sys_get_millis();
75 void          tcplp_sys_set_timer(struct tcpcb *aTcb, uint8_t aTimerFlag, uint32_t aDelay);
76 void          tcplp_sys_stop_timer(struct tcpcb *aTcb, uint8_t aTimerFlag);
77 struct tcpcb *tcplp_sys_accept_ready(struct tcpcb_listen *aTcbListen, struct in6_addr *aAddr, uint16_t aPort);
78 bool          tcplp_sys_accepted_connection(struct tcpcb_listen *aTcbListen,
79                                             struct tcpcb *       aAccepted,
80                                             struct in6_addr *    aAddr,
81                                             uint16_t             aPort);
82 void          tcplp_sys_connection_lost(struct tcpcb *aTcb, uint8_t aErrNum);
83 void          tcplp_sys_on_state_change(struct tcpcb *aTcb, int aNewState);
84 void          tcplp_sys_log(const char *aFormat, ...);
85 void          tcplp_sys_panic(const char *aFormat, ...);
86 bool          tcplp_sys_autobind(otInstance *      aInstance,
87                                  const otSockAddr *aPeer,
88                                  otSockAddr *      aToBind,
89                                  bool              aBindAddress,
90                                  bool              aBindPort);
91 uint32_t      tcplp_sys_generate_isn();
92 
93 #ifdef __cplusplus
94 } // extern "C"
95 #endif
96 
97 #endif // TCPLP_H_
98