1 | /*
|
---|
2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not 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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup tcp
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @file
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include <io/log.h>
|
---|
38 | #include "conn.h"
|
---|
39 | #include "state.h"
|
---|
40 | #include "tcp_type.h"
|
---|
41 |
|
---|
42 | /*
|
---|
43 | * User calls
|
---|
44 | */
|
---|
45 |
|
---|
46 | /** OPEN user call
|
---|
47 | *
|
---|
48 | * @param lport Local port
|
---|
49 | * @param fsock Foreign socket
|
---|
50 | * @param acpass Active/passive
|
---|
51 | * @param conn Connection
|
---|
52 | */
|
---|
53 | void tcp_uc_open(uint16_t lport, tcp_sock_t *fsock, acpass_t acpass,
|
---|
54 | tcp_conn_t **conn)
|
---|
55 | {
|
---|
56 | tcp_conn_t *nconn;
|
---|
57 | tcp_sock_t lsock;
|
---|
58 |
|
---|
59 | log_msg(LVL_DEBUG, "tcp_uc_open(%" PRIu16 ", %p, %s, %p)",
|
---|
60 | lport, fsock, acpass == ap_active ? "active" : "passive",
|
---|
61 | conn);
|
---|
62 |
|
---|
63 | lsock.port = lport;
|
---|
64 | lsock.addr.ipv4 = 0x7f000001;
|
---|
65 |
|
---|
66 | nconn = tcp_conn_new(&lsock, fsock);
|
---|
67 | tcp_conn_add(nconn);
|
---|
68 |
|
---|
69 | if (acpass == ap_active) {
|
---|
70 | /* Synchronize (initiate) connection */
|
---|
71 | tcp_conn_sync(nconn);
|
---|
72 | }
|
---|
73 |
|
---|
74 | *conn = nconn;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /** SEND user call */
|
---|
78 | void tcp_uc_send(tcp_conn_t *conn, void *data, size_t size, xflags_t flags)
|
---|
79 | {
|
---|
80 | log_msg(LVL_DEBUG, "tcp_uc_send()");
|
---|
81 | }
|
---|
82 |
|
---|
83 | /** RECEIVE user call */
|
---|
84 | void tcp_uc_receive(tcp_conn_t *conn, void *buf, size_t size, size_t *rcvd,
|
---|
85 | xflags_t *xflags)
|
---|
86 | {
|
---|
87 | log_msg(LVL_DEBUG, "tcp_uc_receive()");
|
---|
88 | }
|
---|
89 |
|
---|
90 | /** CLOSE user call */
|
---|
91 | void tcp_uc_close(tcp_conn_t *conn)
|
---|
92 | {
|
---|
93 | log_msg(LVL_DEBUG, "tcp_uc_close()");
|
---|
94 | }
|
---|
95 |
|
---|
96 | /** ABORT user call */
|
---|
97 | void tcp_uc_abort(tcp_conn_t *conn)
|
---|
98 | {
|
---|
99 | log_msg(LVL_DEBUG, "tcp_uc_abort()");
|
---|
100 | }
|
---|
101 |
|
---|
102 | /** STATUS user call */
|
---|
103 | void tcp_uc_status(tcp_conn_t *conn, tcp_conn_status_t *cstatus)
|
---|
104 | {
|
---|
105 | log_msg(LVL_DEBUG, "tcp_uc_status()");
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * Arriving segments
|
---|
111 | */
|
---|
112 |
|
---|
113 | /** Segment arrived */
|
---|
114 | void tcp_as_segment_arrived(tcp_sockpair_t *sp, tcp_segment_t *seg)
|
---|
115 | {
|
---|
116 | tcp_conn_t *conn;
|
---|
117 |
|
---|
118 | log_msg(LVL_DEBUG, "tcp_as_segment_arrived()");
|
---|
119 |
|
---|
120 | conn = tcp_conn_find(sp);
|
---|
121 | if (conn != NULL) {
|
---|
122 | tcp_conn_segment_arrived(conn, seg);
|
---|
123 | } else {
|
---|
124 | tcp_unexpected_segment(sp, seg);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | /*
|
---|
129 | * Timeouts
|
---|
130 | */
|
---|
131 |
|
---|
132 | /** User timeout */
|
---|
133 | void tcp_to_user(void)
|
---|
134 | {
|
---|
135 | log_msg(LVL_DEBUG, "tcp_to_user()");
|
---|
136 | }
|
---|
137 |
|
---|
138 | /** Retransmission timeout */
|
---|
139 | void tcp_to_retransmit(void)
|
---|
140 | {
|
---|
141 | log_msg(LVL_DEBUG, "tcp_to_retransmit()");
|
---|
142 | }
|
---|
143 |
|
---|
144 | /** Time-wait timeout */
|
---|
145 | void tcp_to_time_wait(void)
|
---|
146 | {
|
---|
147 | log_msg(LVL_DEBUG, "tcp_to_time_wait()");
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * @}
|
---|
152 | */
|
---|