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 libnet
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include <protocol_map.h>
|
---|
34 | #include <ethernet_lsap.h>
|
---|
35 | #include <ethernet_protocols.h>
|
---|
36 | #include <net_hardware.h>
|
---|
37 |
|
---|
38 | #include <ipc/services.h>
|
---|
39 |
|
---|
40 | /** Maps the internetwork layer service to the network interface layer type.
|
---|
41 | *
|
---|
42 | * @param[in] nil Network interface layer service.
|
---|
43 | * @param[in] il Internetwork layer service.
|
---|
44 | * @returns Network interface layer type of the internetworking
|
---|
45 | * layer service.
|
---|
46 | * @returns Zero if mapping is not found.
|
---|
47 | */
|
---|
48 | eth_type_t protocol_map(services_t nil, services_t il)
|
---|
49 | {
|
---|
50 | switch (nil) {
|
---|
51 | case SERVICE_ETHERNET:
|
---|
52 | case SERVICE_DP8390:
|
---|
53 | switch (il) {
|
---|
54 | case SERVICE_IP:
|
---|
55 | return ETH_P_IP;
|
---|
56 | case SERVICE_ARP:
|
---|
57 | return ETH_P_ARP;
|
---|
58 | default:
|
---|
59 | return 0;
|
---|
60 | }
|
---|
61 | default:
|
---|
62 | return 0;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | /** Maps the network interface layer type to the internetwork layer service.
|
---|
67 | *
|
---|
68 | * @param[in] nil Network interface layer service.
|
---|
69 | * @param[in] protocol Network interface layer type.
|
---|
70 | * @returns Internetwork layer service of the network interface
|
---|
71 | * layer type.
|
---|
72 | * @returns Zero if mapping is not found.
|
---|
73 | */
|
---|
74 | services_t protocol_unmap(services_t nil, int protocol)
|
---|
75 | {
|
---|
76 | switch (nil) {
|
---|
77 | case SERVICE_ETHERNET:
|
---|
78 | case SERVICE_DP8390:
|
---|
79 | switch (protocol) {
|
---|
80 | case ETH_P_IP:
|
---|
81 | return SERVICE_IP;
|
---|
82 | case ETH_P_ARP:
|
---|
83 | return SERVICE_ARP;
|
---|
84 | default:
|
---|
85 | return 0;
|
---|
86 | }
|
---|
87 | default:
|
---|
88 | return 0;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | /** Maps the link service access point identifier to the Ethernet protocol
|
---|
93 | * identifier.
|
---|
94 | *
|
---|
95 | * @param[in] lsap Link service access point identifier.
|
---|
96 | * @returns Ethernet protocol identifier of the link service access
|
---|
97 | * point identifier.
|
---|
98 | * @returns ETH_LSAP_NULL if mapping is not found.
|
---|
99 | */
|
---|
100 | eth_type_t lsap_map(eth_lsap_t lsap)
|
---|
101 | {
|
---|
102 | switch (lsap) {
|
---|
103 | case ETH_LSAP_IP:
|
---|
104 | return ETH_P_IP;
|
---|
105 | case ETH_LSAP_ARP:
|
---|
106 | return ETH_P_ARP;
|
---|
107 | default:
|
---|
108 | return ETH_LSAP_NULL;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | /** Maps the Ethernet protocol identifier to the link service access point
|
---|
113 | * identifier.
|
---|
114 | *
|
---|
115 | * @param[in] ethertype Ethernet protocol identifier.
|
---|
116 | * @returns Link service access point identifier.
|
---|
117 | * @returns Zero if mapping is not found.
|
---|
118 | */
|
---|
119 | eth_lsap_t lsap_unmap(eth_type_t ethertype)
|
---|
120 | {
|
---|
121 | switch (ethertype) {
|
---|
122 | case ETH_P_IP:
|
---|
123 | return ETH_LSAP_IP;
|
---|
124 | case ETH_P_ARP:
|
---|
125 | return ETH_LSAP_ARP;
|
---|
126 | default:
|
---|
127 | return 0;
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | /** Maps the network interface layer services to the hardware types.
|
---|
132 | *
|
---|
133 | * @param[in] nil The network interface service.
|
---|
134 | * @returns The hardware type of the network interface service.
|
---|
135 | * @returns Zero if mapping is not found.
|
---|
136 | */
|
---|
137 | hw_type_t hardware_map(services_t nil)
|
---|
138 | {
|
---|
139 | switch (nil) {
|
---|
140 | case SERVICE_ETHERNET:
|
---|
141 | case SERVICE_DP8390:
|
---|
142 | return HW_ETHER;
|
---|
143 | default:
|
---|
144 | return 0;
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | /** @}
|
---|
149 | */
|
---|