source: azure_iot_hub/trunk/asp3_dcre/tinet/net/ethernet.h@ 388

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

Azure IoT Hub Device C SDK を使ったサンプルの追加

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