| 1 | /*
|
|---|
| 2 | * Copyright (c) 2012 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 inet
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | * @brief IP link provider for Ethernet
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <async.h>
|
|---|
| 38 | #include <errno.h>
|
|---|
| 39 | #include <inet/iplink_srv.h>
|
|---|
| 40 | #include <io/log.h>
|
|---|
| 41 | #include <loc.h>
|
|---|
| 42 | #include <stdio.h>
|
|---|
| 43 |
|
|---|
| 44 | #define NAME "eth"
|
|---|
| 45 |
|
|---|
| 46 | static int ethip_open(iplink_conn_t *conn);
|
|---|
| 47 | static int ethip_close(iplink_conn_t *conn);
|
|---|
| 48 | static int ethip_send(iplink_conn_t *conn, iplink_srv_sdu_t *sdu);
|
|---|
| 49 | static int ethip_get_mtu(iplink_conn_t *conn, size_t *mtu);
|
|---|
| 50 |
|
|---|
| 51 | static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
|
|---|
| 52 |
|
|---|
| 53 | static iplink_ops_t ethip_iplink_ops = {
|
|---|
| 54 | .open = ethip_open,
|
|---|
| 55 | .close = ethip_close,
|
|---|
| 56 | .send = ethip_send,
|
|---|
| 57 | .get_mtu = ethip_get_mtu
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | static iplink_srv_t test_srv;
|
|---|
| 61 |
|
|---|
| 62 | static int ethip_init(void)
|
|---|
| 63 | {
|
|---|
| 64 | int rc;
|
|---|
| 65 | service_id_t sid;
|
|---|
| 66 | category_id_t iplink_cat;
|
|---|
| 67 |
|
|---|
| 68 | test_srv.ops = ðip_iplink_ops;
|
|---|
| 69 | test_srv.arg = NULL;
|
|---|
| 70 |
|
|---|
| 71 | async_set_client_connection(ethip_client_conn);
|
|---|
| 72 |
|
|---|
| 73 | rc = loc_server_register(NAME);
|
|---|
| 74 | if (rc != EOK) {
|
|---|
| 75 | log_msg(LVL_ERROR, "Failed registering server.");
|
|---|
| 76 | return rc;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | rc = loc_service_register("net/eth0", &sid);
|
|---|
| 80 | if (rc != EOK) {
|
|---|
| 81 | log_msg(LVL_ERROR, "Failed registering service net/eth0.");
|
|---|
| 82 | return rc;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | rc = loc_category_get_id("iplink", &iplink_cat, IPC_FLAG_BLOCKING);
|
|---|
| 86 | if (rc != EOK) {
|
|---|
| 87 | log_msg(LVL_ERROR, "Failed resolving category 'iplink'.");
|
|---|
| 88 | return rc;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | rc = loc_service_add_to_cat(sid, iplink_cat);
|
|---|
| 92 | if (rc != EOK) {
|
|---|
| 93 | log_msg(LVL_ERROR, "Failed adding net/eth0 to category.");
|
|---|
| 94 | return rc;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | return EOK;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
|---|
| 101 | {
|
|---|
| 102 | log_msg(LVL_DEBUG, "ethip_client_conn()");
|
|---|
| 103 | iplink_conn(iid, icall, &test_srv);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | static int ethip_open(iplink_conn_t *conn)
|
|---|
| 107 | {
|
|---|
| 108 | log_msg(LVL_DEBUG, "ethip_open()");
|
|---|
| 109 | return EOK;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | static int ethip_close(iplink_conn_t *conn)
|
|---|
| 113 | {
|
|---|
| 114 | log_msg(LVL_DEBUG, "ethip_open()");
|
|---|
| 115 | return EOK;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | static int ethip_send(iplink_conn_t *conn, iplink_srv_sdu_t *sdu)
|
|---|
| 119 | {
|
|---|
| 120 | log_msg(LVL_DEBUG, "ethip_send()");
|
|---|
| 121 | return EOK;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | static int ethip_get_mtu(iplink_conn_t *conn, size_t *mtu)
|
|---|
| 125 | {
|
|---|
| 126 | log_msg(LVL_DEBUG, "ethip_get_mtu()");
|
|---|
| 127 | *mtu = 1500;
|
|---|
| 128 | return EOK;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | int main(int argc, char *argv[])
|
|---|
| 132 | {
|
|---|
| 133 | int rc;
|
|---|
| 134 |
|
|---|
| 135 | printf(NAME ": HelenOS IP over Ethernet service\n");
|
|---|
| 136 |
|
|---|
| 137 | if (log_init(NAME, LVL_DEBUG) != EOK) {
|
|---|
| 138 | printf(NAME ": Failed to initialize logging.\n");
|
|---|
| 139 | return 1;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | rc = ethip_init();
|
|---|
| 143 | if (rc != EOK)
|
|---|
| 144 | return 1;
|
|---|
| 145 |
|
|---|
| 146 | printf(NAME ": Accepting connections.\n");
|
|---|
| 147 | task_retval(0);
|
|---|
| 148 | async_manager();
|
|---|
| 149 |
|
|---|
| 150 | /* Not reached */
|
|---|
| 151 | return 0;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /** @}
|
|---|
| 155 | */
|
|---|