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