1 | /*
|
---|
2 | * Copyright (c) 2015 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 TCP (Transmission Control Protocol) network module
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include <async.h>
|
---|
38 | #include <errno.h>
|
---|
39 | #include <io/log.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <task.h>
|
---|
42 |
|
---|
43 | #include "conn.h"
|
---|
44 | #include "inet.h"
|
---|
45 | #include "ncsim.h"
|
---|
46 | #include "rqueue.h"
|
---|
47 | #include "service.h"
|
---|
48 | #include "test.h"
|
---|
49 | #include "ucall.h"
|
---|
50 |
|
---|
51 | #define NAME "tcp"
|
---|
52 |
|
---|
53 | static tcp_rqueue_cb_t tcp_rqueue_cb = {
|
---|
54 | .seg_received = tcp_as_segment_arrived
|
---|
55 | };
|
---|
56 |
|
---|
57 | static errno_t tcp_init(void)
|
---|
58 | {
|
---|
59 | errno_t rc;
|
---|
60 |
|
---|
61 | log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_init()");
|
---|
62 |
|
---|
63 | rc = tcp_conns_init();
|
---|
64 | if (rc != EOK) {
|
---|
65 | assert(rc == ENOMEM);
|
---|
66 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing connections");
|
---|
67 | return ENOMEM;
|
---|
68 | }
|
---|
69 |
|
---|
70 | tcp_rqueue_init(&tcp_rqueue_cb);
|
---|
71 | tcp_rqueue_fibril_start();
|
---|
72 |
|
---|
73 | tcp_ncsim_init();
|
---|
74 | tcp_ncsim_fibril_start();
|
---|
75 |
|
---|
76 | if (0) tcp_test();
|
---|
77 |
|
---|
78 | rc = tcp_inet_init();
|
---|
79 | if (rc != EOK)
|
---|
80 | return ENOENT;
|
---|
81 |
|
---|
82 | rc = tcp_service_init();
|
---|
83 | if (rc != EOK) {
|
---|
84 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing service.");
|
---|
85 | return ENOENT;
|
---|
86 | }
|
---|
87 |
|
---|
88 | return EOK;
|
---|
89 | }
|
---|
90 |
|
---|
91 | int main(int argc, char **argv)
|
---|
92 | {
|
---|
93 | errno_t rc;
|
---|
94 |
|
---|
95 | printf(NAME ": TCP (Transmission Control Protocol) network module\n");
|
---|
96 |
|
---|
97 | rc = log_init(NAME);
|
---|
98 | if (rc != EOK) {
|
---|
99 | printf(NAME ": Failed to initialize log.\n");
|
---|
100 | return 1;
|
---|
101 | }
|
---|
102 |
|
---|
103 | rc = tcp_init();
|
---|
104 | if (rc != EOK)
|
---|
105 | return 1;
|
---|
106 |
|
---|
107 | printf(NAME ": Accepting connections.\n");
|
---|
108 | task_retval(0);
|
---|
109 | async_manager();
|
---|
110 |
|
---|
111 | /* Not reached */
|
---|
112 | return 0;
|
---|
113 | }
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * @}
|
---|
117 | */
|
---|