source: EcnlProtoTool/trunk/asp3_dcre/tinet/net/ethernet.h@ 321

Last change on this file since 321 was 321, checked in by coas-nagasima, 7 years ago

文字コードを設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 9.7 KB
Line 
1/*
2 * TINET (TCP/IP Protocol Stack)
3 *
4 * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
5 * Tomakomai National College of Technology, JAPAN
6 *
7 * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
8 * によって公表されている GNU General Public License の Version 2 に記
9 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
10 * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
11 * 利用と呼ぶ)することを無償で許諾する.
12 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
13 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
14 * スコード中に含まれていること.
15 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
16 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
17 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
18 * の無保証規定を掲載すること.
19 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
20 * 用できない形で再配布する場合には,次の条件を満たすこと.
21 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
22 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 *
26 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
27 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
28 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
29 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
30 *
31 * @(#) $Id$
32 */
33
34/*
35 * Copyright (c) 1982, 1986, 1989, 1993
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * Fundamental constants relating to ethernet.
67 *
68 * $FreeBSD: src/sys/net/ethernet.h,v 1.9.2.1 1999/08/29 16:28:13 peter Exp $
69 *
70 */
71
72#ifndef _ETHERNET_H_
73#define _ETHERNET_H_
74
75#ifdef SUPPORT_ETHER
76
77/*
78 * フィールド長
79 */
80
81#define ETHER_ADDR_LEN 6 /* Ethernet (MAC) Address */
82#define ETHER_TYPE_LEN 2 /* Type */
83#define ETHER_CRC_LEN 0/*4*/ /* CRC */
84
85/*
86 * フレーム長 (Ethernet ヘッダと CRC を含む)
87 */
88
89#define ETHER_MIN_LEN 64
90#define ETHER_MAX_LEN (IF_MTU + sizeof(T_ETHER_HDR) + ETHER_CRC_LEN)
91
92/*
93 * Ethernet ヘッダ
94 */
95
96#ifndef IF_ETHER_NIC_HDR_ALIGN
97#error IF_ETHER_NIC_HDR_ALIGN expected.
98#endif /* of #ifndef IF_ETHER_NIC_HDR_ALIGN */
99
100typedef struct t_ether_header {
101
102#if IF_ETHER_NIC_HDR_ALIGN != 0
103
104 uint8_t align[IF_ETHER_NIC_HDR_ALIGN]; /* アライン調整 */
105
106#endif /* of #if IF_ETHER_NIC_HDR_ALIGN != 0 */
107
108 uint8_t dhost[ETHER_ADDR_LEN];
109 uint8_t shost[ETHER_ADDR_LEN];
110 uint16_t type;
111 } __attribute__((packed, aligned(2)))T_ETHER_HDR;
112
113#define GET_ETHER_HDR(nbuf) ((T_ETHER_HDR*)((nbuf)->buf))
114
115/*
116 * MAC アドレスの定義
117 */
118
119#define ETHER_MCAST_ADDR UINT_C(0x01) /* マルチキャスト・アドレス */
120#define ETHER_LOCAL_ADDR UINT_C(0x02) /* ローカル・アドレス */
121
122typedef struct t_ether_addr {
123 uint8_t lladdr[ETHER_ADDR_LEN];
124 } __attribute__((packed, aligned(2)))T_ETHER_ADDR;
125
126/*
127 * Type フィールド
128 */
129
130#define ETHER_TYPE_IP UINT_C(0x0800) /* IPv4 */
131#define ETHER_TYPE_ARP UINT_C(0x0806) /* ARP */
132#define ETHER_TYPE_IPV6 UINT_C(0x86dd) /* IPv6 */
133
134/*
135 * インタフェースの選択マクロ
136 */
137
138#define T_IF_HDR T_ETHER_HDR /* インタフェースのヘッダ */
139#define T_IF_ADDR T_ETHER_ADDR /* インタフェースのアドレス */
140#define IF_HDR_ALIGN 2 /* ヘッダのアライン単位 */
141#define IF_MTU 1500 /* インタフェースの MTU */
142
143#define IF_OUTPUT(o,d,g,t) ether_output(o,d,g,t) /* インタフェースの出力関数 */
144#define IF_RAW_OUTPUT(o,t) ether_raw_output(o,t) /* インタフェースの出力関数、アドレス解決無し */
145#define IF_SET_PROTO(b,p) (GET_ETHER_HDR(b)->type = htons(p))
146 /* インタフェースのプロトコル設定関数 */
147#define IF_SOFTC_TO_IFADDR(s) ((T_IF_ADDR*)(s)->ifaddr.lladdr)
148 /* ソフトウェア情報から MAC アドレスを取り出す */
149#define IF_GET_IFNET() ether_get_ifnet() /* ネットワークインタフェース構造体を返す。 */
150#define IF_TYPE IFT_ETHER /* インターフェースの型 */
151
152/* IPv4 関係 */
153
154#define IF_PROTO_IP ETHER_TYPE_IP /* インタフェースの IP プロトコル指定 */
155#define IF_PROTO_ARP ETHER_TYPE_ARP /* インタフェースの ARP プロトコル指定 */
156
157/* IPv6 関係 */
158
159#define MAX_IF_MADDR_CNT 2 /* インタフェースのマルチキャストアドレス配列の最大サイズ */
160#define IF_MADDR_INIT { { { 0, 0, 0, 0, 0, 0 } }, { { 0, 0, 0, 0, 0, 0 } } }
161 /* インタフェースのマルチキャストアドレス配列の初期化 */
162#define IF_PROTO_IPV6 ETHER_TYPE_IPV6 /* インタフェースの IP プロトコル指定 */
163#define IF_ADDMULTI(s) IF_ETHER_NIC_ADDMULTI(s)
164 /* マルチキャストアドレスの登録 */
165#define IF_IN6_NEED_CACHE(i) (true) /* 近隣探索キャッシュを使用する。 */
166#define IF_IN6_IFID(i,a) IF_ETHER_NIC_IN6_IFID(i,a)
167 /* インタフェース識別子の設定 */
168#define IF_IN6_RESOLVE_MULTICAST(i,m) \
169 ether_in6_resolve_multicast(i,m)
170 /* インタフェースのマルチキャストアドレスへの変換 */
171
172/*
173 * 前方参照
174 */
175
176#ifndef T_IFNET_DEFINED
177
178typedef struct t_ifnet T_IFNET;
179
180#define T_IFNET_DEFINED
181
182#endif /* of #ifndef T_IFNET_DEFINED */
183
184#ifndef T_IF_SOFTC_DEFINED
185
186typedef struct t_if_softc T_IF_SOFTC;
187
188#define T_IF_SOFTC_DEFINED
189
190#endif /* of #ifndef T_IF_SOFTC_DEFINED */
191
192#ifndef T_IN4_ADDR_DEFINED
193
194typedef uint32_t T_IN4_ADDR;
195
196#define T_IN4_ADDR_DEFINED
197
198#endif /* of #ifndef T_IN4_ADDR_DEFINED */
199
200#ifndef T_NET_BUF_DEFINED
201
202typedef struct t_net_buf T_NET_BUF;
203
204#define T_NET_BUF_DEFINED
205
206#endif /* of #ifndef T_NET_BUF_DEFINED */
207
208/*
209 * ネットワークインタフェースに依存しないソフトウェア情報
210 */
211
212#ifdef T_IF_ETHER_NIC_SOFTC
213
214struct t_if_softc {
215 T_IF_ADDR ifaddr; /* ネットワークインタフェースのアドレス */
216 uint16_t timer; /* 送信タイムアウト */
217 T_IF_ETHER_NIC_SOFTC *sc; /* ディバイス依存のソフトウェア情報 */
218 ID semid_txb_ready; /* 送信セマフォ */
219 ID semid_rxb_ready; /* 受信セマフォ */
220
221#ifdef SUPPORT_INET6
222
223 T_IF_ADDR maddrs[MAX_IF_MADDR_CNT]; /* マルチキャストアドレスリスト */
224
225#endif /* of #ifdef SUPPORT_INET6 */
226 };
227
228#endif /* of #ifdef T_IF_ETHER_NIC_SOFTC */
229
230#define IF_FLAG_UP 0x01U
231#define IF_FLAG_LINK_UP 0x10U
232
233#ifdef SUPPORT_INET6
234
235/* 前方参照 */
236
237#ifndef T_IN6_ADDR_DEFINED
238
239typedef struct t_in6_addr T_IN6_ADDR;
240
241#define T_IN6_ADDR_DEFINED
242
243#endif /* of #ifndef T_IN6_ADDR_DEFINED */
244
245/*
246 * 関数
247 */
248
249extern ER ether_in6_resolve_multicast(T_ETHER_ADDR *ifaddr, T_IN6_ADDR *maddr);
250
251#endif /* of #ifdef SUPPORT_INET6 */
252
253/*
254 * 関数
255 */
256
257extern T_IFNET *ether_get_ifnet (void);
258extern ER ether_output (T_NET_BUF *data, void *dst, T_IF_ADDR *gw, TMO tmout);
259extern ER ether_raw_output (T_NET_BUF *data, TMO tmout);
260
261/** Function prototype for netif status- or link-callback functions. */
262typedef void (*ether_status_callback_fn)(T_IFNET *ether);
263extern void ether_set_link_callback(ether_status_callback_fn link_callback);
264extern void ether_set_link_up(T_IFNET *ether);
265extern void ether_set_link_down(T_IFNET *ether);
266
267#endif /* of #ifdef SUPPORT_ETHER */
268
269#endif /* of #ifndef _ETHERNET_H_ */
Note: See TracBrowser for help on using the repository browser.