| [21580dd] | 1 | /*
|
|---|
| [2f19103] | 2 | * Copyright (c) 2015 Jiri Svoboda
|
|---|
| [21580dd] | 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
|
|---|
| [89e57cee] | 30 | * @{
|
|---|
| [21580dd] | 31 | */
|
|---|
| 32 |
|
|---|
| [c5808b41] | 33 | /**
|
|---|
| 34 | * @file TCP (Transmission Control Protocol) network module
|
|---|
| [21580dd] | 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <async.h>
|
|---|
| [e98b1d5] | 38 | #include <errno.h>
|
|---|
| [c5808b41] | 39 | #include <io/log.h>
|
|---|
| 40 | #include <stdio.h>
|
|---|
| 41 | #include <task.h>
|
|---|
| [21580dd] | 42 |
|
|---|
| [2989c7e] | 43 | #include "conn.h"
|
|---|
| [42f61f01] | 44 | #include "inet.h"
|
|---|
| [8218b6b] | 45 | #include "ncsim.h"
|
|---|
| [c5808b41] | 46 | #include "rqueue.h"
|
|---|
| [779541b] | 47 | #include "service.h"
|
|---|
| [c5808b41] | 48 | #include "test.h"
|
|---|
| [d14840d] | 49 | #include "ucall.h"
|
|---|
| [21580dd] | 50 |
|
|---|
| [c5808b41] | 51 | #define NAME "tcp"
|
|---|
| [21580dd] | 52 |
|
|---|
| [d14840d] | 53 | static tcp_rqueue_cb_t tcp_rqueue_cb = {
|
|---|
| 54 | .seg_received = tcp_as_segment_arrived
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| [b7fd2a0] | 57 | static errno_t tcp_init(void)
|
|---|
| [7c8267b] | 58 | {
|
|---|
| [b7fd2a0] | 59 | errno_t rc;
|
|---|
| [21580dd] | 60 |
|
|---|
| [a1a101d] | 61 | log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_init()");
|
|---|
| [1812a0d] | 62 |
|
|---|
| [2989c7e] | 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 |
|
|---|
| [d14840d] | 70 | tcp_rqueue_init(&tcp_rqueue_cb);
|
|---|
| [88a6819] | 71 | tcp_rqueue_fibril_start();
|
|---|
| [1812a0d] | 72 |
|
|---|
| [c76e926] | 73 | tcp_ncsim_init();
|
|---|
| [88a6819] | 74 | tcp_ncsim_fibril_start();
|
|---|
| [a4ee3ab2] | 75 |
|
|---|
| [1433ecda] | 76 | if (0)
|
|---|
| 77 | tcp_test();
|
|---|
| [c76e926] | 78 |
|
|---|
| [42f61f01] | 79 | rc = tcp_inet_init();
|
|---|
| 80 | if (rc != EOK)
|
|---|
| [1812a0d] | 81 | return ENOENT;
|
|---|
| [21580dd] | 82 |
|
|---|
| [779541b] | 83 | rc = tcp_service_init();
|
|---|
| 84 | if (rc != EOK) {
|
|---|
| 85 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing service.");
|
|---|
| 86 | return ENOENT;
|
|---|
| 87 | }
|
|---|
| [1812a0d] | 88 |
|
|---|
| 89 | return EOK;
|
|---|
| [21580dd] | 90 | }
|
|---|
| 91 |
|
|---|
| [c5808b41] | 92 | int main(int argc, char **argv)
|
|---|
| [7c8267b] | 93 | {
|
|---|
| [b7fd2a0] | 94 | errno_t rc;
|
|---|
| [2e99277] | 95 |
|
|---|
| [c5808b41] | 96 | printf(NAME ": TCP (Transmission Control Protocol) network module\n");
|
|---|
| [7c8267b] | 97 |
|
|---|
| [267f235] | 98 | rc = log_init(NAME);
|
|---|
| [0578271] | 99 | if (rc != EOK) {
|
|---|
| [c5808b41] | 100 | printf(NAME ": Failed to initialize log.\n");
|
|---|
| 101 | return 1;
|
|---|
| [21580dd] | 102 | }
|
|---|
| [7c8267b] | 103 |
|
|---|
| [ecff3d9] | 104 | rc = tcp_init();
|
|---|
| 105 | if (rc != EOK)
|
|---|
| 106 | return 1;
|
|---|
| 107 |
|
|---|
| 108 | printf(NAME ": Accepting connections.\n");
|
|---|
| [c76e926] | 109 | task_retval(0);
|
|---|
| [c5808b41] | 110 | async_manager();
|
|---|
| [849ed54] | 111 |
|
|---|
| [c5808b41] | 112 | /* Not reached */
|
|---|
| 113 | return 0;
|
|---|
| [014dd57b] | 114 | }
|
|---|
| 115 |
|
|---|
| [c5808b41] | 116 | /**
|
|---|
| 117 | * @}
|
|---|
| [21580dd] | 118 | */
|
|---|