source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/net/ethernet.h@ 364

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

TINETとSocket APIなどを更新

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