source: asp3_tinet_ecnl_rx/trunk/asp3_dcre/tinet/net/ethernet.h@ 342

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

syscallが関数呼びになるよう変更
他更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 10.9 KB
Line 
1/*
2 * TINET (TCP/IP Protocol Stack)
3 *
4 * Copyright (C) 2001-2017 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: ethernet.h 1524 2018-04-25 13:48:23Z coas-nagasima $
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
100#if defined(__RX) || defined(_MSC_VER)
101#if defined(__RX)
102#pragma pack
103#else
104#pragma pack(push, 1)
105#endif
106typedef struct t_ether_header {
107
108#if IF_ETHER_NIC_HDR_ALIGN != 0
109
110 uint8_t align[IF_ETHER_NIC_HDR_ALIGN]; /* アライン調整 */
111
112#endif /* of #if IF_ETHER_NIC_HDR_ALIGN != 0 */
113
114 uint8_t dhost[ETHER_ADDR_LEN];
115 uint8_t shost[ETHER_ADDR_LEN];
116 uint16_t type;
117 } T_ETHER_HDR;
118#if defined(__RX)
119#pragma packoption
120#else
121#pragma pack(pop)
122#endif
123
124#elif defined(TOPPERS_S810_CLG3_85) /* of #if defined(__RX) */
125
126typedef struct t_ether_header {
127
128#if IF_ETHER_NIC_HDR_ALIGN != 0
129
130 uint8_t align[IF_ETHER_NIC_HDR_ALIGN]; /* アライン調整 */
131
132#endif /* of #if IF_ETHER_NIC_HDR_ALIGN != 0 */
133
134 uint8_t dhost[ETHER_ADDR_LEN];
135 uint8_t shost[ETHER_ADDR_LEN];
136 uint16_t type;
137 } T_ETHER_HDR;
138
139#else /* of #if defined(__RX) */
140
141typedef struct t_ether_header {
142
143#if IF_ETHER_NIC_HDR_ALIGN != 0
144
145 uint8_t align[IF_ETHER_NIC_HDR_ALIGN]; /* アライン調整 */
146
147#endif /* of #if IF_ETHER_NIC_HDR_ALIGN != 0 */
148
149 uint8_t dhost[ETHER_ADDR_LEN];
150 uint8_t shost[ETHER_ADDR_LEN];
151 uint16_t type;
152 } __attribute__((packed, aligned(2))) T_ETHER_HDR;
153
154#endif /* of #if defined(__RX) */
155
156#define GET_ETHER_HDR(nbuf) ((T_ETHER_HDR*)((nbuf)->buf))
157
158/*
159 * MAC アドレスの定義
160 */
161
162#define ETHER_MCAST_ADDR UINT_C(0x01) /* マルチキャスト・アドレス */
163#define ETHER_LOCAL_ADDR UINT_C(0x02) /* ローカル・アドレス */
164
165typedef struct t_ether_addr {
166 uint8_t lladdr[ETHER_ADDR_LEN];
167 } __attribute__((packed, aligned(2))) T_ETHER_ADDR;
168
169/*
170 * Type フィールド
171 */
172
173#define ETHER_TYPE_IP UINT_C(0x0800) /* IPv4 */
174#define ETHER_TYPE_ARP UINT_C(0x0806) /* ARP */
175#define ETHER_TYPE_IPV6 UINT_C(0x86dd) /* IPv6 */
176
177/*
178 * インタフェースの選択マクロ
179 */
180
181#define T_IF_HDR T_ETHER_HDR /* インタフェースのヘッダ */
182#define T_IF_ADDR T_ETHER_ADDR /* インタフェースのアドレス */
183#define IF_HDR_ALIGN 2 /* ヘッダのアライン単位 */
184#define IF_MTU 1500 /* インタフェースの MTU */
185#define IF_MIN_LEN ETHER_MIN_LEN /* インターフェースフレームの最短長 */
186
187#define IF_OUTPUT(o,d,g,t) ether_output(o,d,g,t) /* インタフェースの出力関数 */
188#define IF_RAW_OUTPUT(o,t) ether_raw_output(o,t) /* インタフェースの出力関数、アドレス解決無し */
189#define IF_SET_PROTO(b,p) (GET_ETHER_HDR(b)->type = htons(p))
190 /* インタフェースのプロトコル設定関数 */
191#define IF_SOFTC_TO_IFADDR(s) ((T_IF_ADDR*)(s)->ifaddr.lladdr)
192 /* ソフトウェア情報から MAC アドレスを取り出す */
193#define IF_GET_IFNET() ether_get_ifnet() /* ネットワークインタフェース構造体を返す。 */
194#define IF_TYPE IFT_ETHER /* インタフェースの型 */
195#define IF_SRAND() ether_srand() /* インタフェースの乱数初期値 */
196
197/* IPv4 関係 */
198
199#define IF_PROTO_IP ETHER_TYPE_IP /* インタフェースの IPv4 プロトコル指定 */
200#define IF_PROTO_ARP ETHER_TYPE_ARP /* インタフェースの ARP プロトコル指定 */
201
202/* IPv6 関係 */
203
204#define MAX_IF_MADDR_CNT 2 /* インタフェースのマルチキャストアドレス配列の最大サイズ */
205#define IF_MADDR_INIT { { { 0, 0, 0, 0, 0, 0 } }, { { 0, 0, 0, 0, 0, 0 } } }
206 /* インタフェースのマルチキャストアドレス配列の初期化 */
207#define IF_PROTO_IPV6 ETHER_TYPE_IPV6 /* インタフェースの IPv6 プロトコル指定 */
208#define IF_ADDMULTI(s) IF_ETHER_NIC_ADDMULTI(s)
209 /* マルチキャストアドレスの登録 */
210#define IF_IN6_NEED_CACHE(i) (true) /* 近隣探索キャッシュを使用する。 */
211#define IF_IN6_IFID(i,a) IF_ETHER_NIC_IN6_IFID(i,a)
212 /* インタフェース識別子の設定 */
213#define IF_IN6_RESOLVE_MULTICAST(i,m) \
214 ether_in6_resolve_multicast(i,m)
215 /* インタフェースのマルチキャストアドレスへの変換 */
216
217#define IF_FLAG_UP 0x01U
218#define IF_FLAG_LINK_UP 0x10U
219
220/*
221 * 前方参照
222 */
223
224#ifndef T_IFNET_DEFINED
225
226typedef struct t_ifnet T_IFNET;
227
228#define T_IFNET_DEFINED
229
230#endif /* of #ifndef T_IFNET_DEFINED */
231
232#ifndef T_IF_SOFTC_DEFINED
233
234typedef struct t_if_softc T_IF_SOFTC;
235
236#define T_IF_SOFTC_DEFINED
237
238#endif /* of #ifndef T_IF_SOFTC_DEFINED */
239
240#ifndef T_IN4_ADDR_DEFINED
241
242typedef uint32_t T_IN4_ADDR;
243
244#define T_IN4_ADDR_DEFINED
245
246#endif /* of #ifndef T_IN4_ADDR_DEFINED */
247
248#ifndef T_NET_BUF_DEFINED
249
250typedef struct t_net_buf T_NET_BUF;
251
252#define T_NET_BUF_DEFINED
253
254#endif /* of #ifndef T_NET_BUF_DEFINED */
255
256/*
257 * ネットワークインタフェースに依存しないソフトウェア情報
258 */
259
260#ifdef T_IF_ETHER_NIC_SOFTC
261
262struct t_if_softc {
263 T_IF_ADDR ifaddr; /* ネットワークインタフェースのアドレス */
264 uint16_t timer; /* 送信タイムアウト */
265 T_IF_ETHER_NIC_SOFTC *sc; /* ディバイス依存のソフトウェア情報 */
266 ID semid_txb_ready; /* 送信セマフォ */
267 ID semid_rxb_ready; /* 受信セマフォ */
268
269#ifdef _IP6_CFG
270
271 T_IF_ADDR maddrs[MAX_IF_MADDR_CNT]; /* マルチキャストアドレスリスト */
272
273#endif /* of #ifdef _IP6_CFG */
274 };
275
276#endif /* of #ifdef T_IF_ETHER_NIC_SOFTC */
277
278/*
279 * 変数
280 */
281
282#ifdef ETHER_CFG_COLLECT_ADDR
283
284T_ETHER_ADDR ether_collect_addr;
285
286#endif /* of #ifdef ETHER_CFG_COLLECT_ADDR */
287
288/*
289 * 関数
290 */
291
292#ifdef _IP6_CFG
293
294/* 前方参照 */
295
296#ifndef T_IN6_ADDR_DEFINED
297
298typedef struct t_in6_addr T_IN6_ADDR;
299
300#define T_IN6_ADDR_DEFINED
301
302#endif /* of #ifndef T_IN6_ADDR_DEFINED */
303
304extern ER ether_in6_resolve_multicast(T_ETHER_ADDR *ifaddr, const T_IN6_ADDR *maddr);
305
306#endif /* of #ifdef _IP6_CFG */
307
308extern T_IFNET *ether_get_ifnet (void);
309extern ER ether_output (T_NET_BUF *data, const void *dst, T_IF_ADDR *gw, TMO tmout);
310extern ER ether_raw_output (T_NET_BUF *data, TMO tmout);
311extern uint32_t ether_srand (void);
312
313typedef void (*ether_status_callback_fn)(T_IFNET *ether);
314extern void ether_set_link_callback(ether_status_callback_fn link_callback);
315extern void ether_set_link_up();
316extern void ether_set_link_down();
317extern void ether_set_up();
318extern void ether_set_down();
319
320#endif /* of #ifdef SUPPORT_ETHER */
321
322#endif /* of #ifndef _ETHERNET_H_ */
Note: See TracBrowser for help on using the repository browser.