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 uint32_t links_popped; 59 uint32_t bytes_acked; 60 bool conn_established; 61 bool recvbuf_added; 62 bool rcvd_fin; 63 }; 64 65 /* 66 * Functions that the TCP protocol logic can call to interact with the rest of 67 * the system. 68 */ 69 otMessage * tcplp_sys_new_message(otInstance *instance); 70 void tcplp_sys_free_message(otInstance *instance, otMessage *pkt); 71 void tcplp_sys_send_message(otInstance *instance, otMessage *pkt, otMessageInfo *info); 72 uint32_t tcplp_sys_get_ticks(); 73 uint32_t tcplp_sys_get_millis(); 74 void tcplp_sys_set_timer(struct tcpcb *tcb, uint8_t timer_flag, uint32_t delay); 75 void tcplp_sys_stop_timer(struct tcpcb *tcb, uint8_t timer_flag); 76 struct tcpcb *tcplp_sys_accept_ready(struct tcpcb_listen *tpl, struct in6_addr *addr, uint16_t port); 77 bool tcplp_sys_accepted_connection(struct tcpcb_listen *tpl, 78 struct tcpcb * accepted, 79 struct in6_addr * addr, 80 uint16_t port); 81 void tcplp_sys_connection_lost(struct tcpcb *tcb, uint8_t errnum); 82 void tcplp_sys_on_state_change(struct tcpcb *tcb, int newstate); 83 void tcplp_sys_log(const char *format, ...); 84 void tcplp_sys_panic(const char *format, ...); 85 bool tcplp_sys_autobind(otInstance * aInstance, 86 const otSockAddr *aPeer, 87 otSockAddr * aToBind, 88 bool aBindAddress, 89 bool aBindPort); 90 uint32_t tcplp_sys_generate_isn(); 91 92 #ifdef __cplusplus 93 } // extern "C" 94 #endif 95 96 #endif // TCPLP_H_ 97