| 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)
|
|---|
| 77 | tcp_test();
|
|---|
| 78 |
|
|---|
| 79 | rc = tcp_inet_init();
|
|---|
| 80 | if (rc != EOK)
|
|---|
| 81 | return ENOENT;
|
|---|
| 82 |
|
|---|
| 83 | rc = tcp_service_init();
|
|---|
| 84 | if (rc != EOK) {
|
|---|
| 85 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing service.");
|
|---|
| 86 | return ENOENT;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | return EOK;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | int main(int argc, char **argv)
|
|---|
| 93 | {
|
|---|
| 94 | errno_t rc;
|
|---|
| 95 |
|
|---|
| 96 | printf(NAME ": TCP (Transmission Control Protocol) network module\n");
|
|---|
| 97 |
|
|---|
| 98 | rc = log_init(NAME);
|
|---|
| 99 | if (rc != EOK) {
|
|---|
| 100 | printf(NAME ": Failed to initialize log.\n");
|
|---|
| 101 | return 1;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | rc = tcp_init();
|
|---|
| 105 | if (rc != EOK)
|
|---|
| 106 | return 1;
|
|---|
| 107 |
|
|---|
| 108 | printf(NAME ": Accepting connections.\n");
|
|---|
| 109 | task_retval(0);
|
|---|
| 110 | async_manager();
|
|---|
| 111 |
|
|---|
| 112 | /* Not reached */
|
|---|
| 113 | return 0;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /**
|
|---|
| 117 | * @}
|
|---|
| 118 | */
|
|---|