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