| 1 | /*
|
|---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
|---|
| 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 arp
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | /** @file
|
|---|
| 34 | * ARP module.
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #ifndef NET_ARP_H_
|
|---|
| 38 | #define NET_ARP_H_
|
|---|
| 39 |
|
|---|
| 40 | #include <fibril_synch.h>
|
|---|
| 41 |
|
|---|
| 42 | #include <ipc/ipc.h>
|
|---|
| 43 | #include <ipc/services.h>
|
|---|
| 44 |
|
|---|
| 45 | #include <net/device.h>
|
|---|
| 46 | #include <net/packet.h>
|
|---|
| 47 | #include <net_hardware.h>
|
|---|
| 48 | #include <adt/generic_char_map.h>
|
|---|
| 49 | #include <adt/int_map.h>
|
|---|
| 50 | #include <adt/measured_strings.h>
|
|---|
| 51 |
|
|---|
| 52 | /** Type definition of the ARP device specific data.
|
|---|
| 53 | * @see arp_device
|
|---|
| 54 | */
|
|---|
| 55 | typedef struct arp_device arp_device_t;
|
|---|
| 56 |
|
|---|
| 57 | /** Type definition of the ARP global data.
|
|---|
| 58 | * @see arp_globals
|
|---|
| 59 | */
|
|---|
| 60 | typedef struct arp_globals arp_globals_t;
|
|---|
| 61 |
|
|---|
| 62 | /** Type definition of the ARP protocol specific data.
|
|---|
| 63 | * @see arp_proto
|
|---|
| 64 | */
|
|---|
| 65 | typedef struct arp_proto arp_proto_t;
|
|---|
| 66 |
|
|---|
| 67 | /** Type definition of the ARP address translation record.
|
|---|
| 68 | * @see arp_trans
|
|---|
| 69 | */
|
|---|
| 70 | typedef struct arp_trans arp_trans_t;
|
|---|
| 71 |
|
|---|
| 72 | /** ARP address map.
|
|---|
| 73 | *
|
|---|
| 74 | * Translates addresses.
|
|---|
| 75 | * @see generic_char_map.h
|
|---|
| 76 | */
|
|---|
| 77 | GENERIC_CHAR_MAP_DECLARE(arp_addr, arp_trans_t);
|
|---|
| 78 |
|
|---|
| 79 | /** ARP address cache.
|
|---|
| 80 | *
|
|---|
| 81 | * Maps devices to the ARP device specific data.
|
|---|
| 82 | * @see device.h
|
|---|
| 83 | */
|
|---|
| 84 | DEVICE_MAP_DECLARE(arp_cache, arp_device_t);
|
|---|
| 85 |
|
|---|
| 86 | /** ARP protocol map.
|
|---|
| 87 | *
|
|---|
| 88 | * Maps protocol identifiers to the ARP protocol specific data.
|
|---|
| 89 | * @see int_map.h
|
|---|
| 90 | */
|
|---|
| 91 | INT_MAP_DECLARE(arp_protos, arp_proto_t);
|
|---|
| 92 |
|
|---|
| 93 | /** ARP device specific data. */
|
|---|
| 94 | struct arp_device {
|
|---|
| 95 | /** Actual device hardware address. */
|
|---|
| 96 | measured_string_t *addr;
|
|---|
| 97 | /** Actual device hardware address data. */
|
|---|
| 98 | char *addr_data;
|
|---|
| 99 | /** Broadcast device hardware address. */
|
|---|
| 100 | measured_string_t *broadcast_addr;
|
|---|
| 101 | /** Broadcast device hardware address data. */
|
|---|
| 102 | char *broadcast_data;
|
|---|
| 103 | /** Device identifier. */
|
|---|
| 104 | device_id_t device_id;
|
|---|
| 105 | /** Hardware type. */
|
|---|
| 106 | hw_type_t hardware;
|
|---|
| 107 | /** Packet dimension. */
|
|---|
| 108 | packet_dimension_t packet_dimension;
|
|---|
| 109 | /** Device module phone. */
|
|---|
| 110 | int phone;
|
|---|
| 111 |
|
|---|
| 112 | /**
|
|---|
| 113 | * Protocol map.
|
|---|
| 114 | * Address map for each protocol.
|
|---|
| 115 | */
|
|---|
| 116 | arp_protos_t protos;
|
|---|
| 117 |
|
|---|
| 118 | /** Device module service. */
|
|---|
| 119 | services_t service;
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 | /** ARP global data. */
|
|---|
| 123 | struct arp_globals {
|
|---|
| 124 | /** ARP address cache. */
|
|---|
| 125 | arp_cache_t cache;
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | * The client connection processing function.
|
|---|
| 129 | * The module skeleton propagates its own one.
|
|---|
| 130 | */
|
|---|
| 131 | async_client_conn_t client_connection;
|
|---|
| 132 |
|
|---|
| 133 | /** Networking module phone. */
|
|---|
| 134 | int net_phone;
|
|---|
| 135 | /** Safety lock. */
|
|---|
| 136 | fibril_mutex_t lock;
|
|---|
| 137 | };
|
|---|
| 138 |
|
|---|
| 139 | /** ARP protocol specific data. */
|
|---|
| 140 | struct arp_proto {
|
|---|
| 141 | /** Actual device protocol address. */
|
|---|
| 142 | measured_string_t *addr;
|
|---|
| 143 | /** Actual device protocol address data. */
|
|---|
| 144 | char *addr_data;
|
|---|
| 145 | /** Address map. */
|
|---|
| 146 | arp_addr_t addresses;
|
|---|
| 147 | /** Protocol service. */
|
|---|
| 148 | services_t service;
|
|---|
| 149 | };
|
|---|
| 150 |
|
|---|
| 151 | /** ARP address translation record. */
|
|---|
| 152 | struct arp_trans {
|
|---|
| 153 | /**
|
|---|
| 154 | * Hardware address for the translation. NULL denotes an incomplete
|
|---|
| 155 | * record with possible waiters.
|
|---|
| 156 | */
|
|---|
| 157 | measured_string_t *hw_addr;
|
|---|
| 158 | /** Condition variable used for waiting for completion of the record. */
|
|---|
| 159 | fibril_condvar_t cv;
|
|---|
| 160 | };
|
|---|
| 161 |
|
|---|
| 162 | #endif
|
|---|
| 163 |
|
|---|
| 164 | /** @}
|
|---|
| 165 | */
|
|---|
| 166 |
|
|---|