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 | * @(#)udp_var.h 8.1 (Berkeley) 6/10/93
|
---|
67 | * $FreeBSD: src/sys/netinet/udp_var.h,v 1.16.2.2 1999/08/29 16:29:59 peter Exp $
|
---|
68 | */
|
---|
69 |
|
---|
70 | #ifndef _UDP_VAR_H_
|
---|
71 | #define _UDP_VAR_H_
|
---|
72 |
|
---|
73 | /*
|
---|
74 | * UDP ヘッダ・ペイロードアクセスマクロ
|
---|
75 | */
|
---|
76 |
|
---|
77 | #define GET_UDP_HDR(nbuf,uhoff) ((T_UDP_HDR*)((uint8_t*)((nbuf)->buf) + uhoff))
|
---|
78 | #define GET_UDP_HDR_OFFSET(nbuf) (GET_IF_IP_HDR_SIZE(nbuf))
|
---|
79 | #define GET_UDP_SDU(nbuf,uhoff) ((uint8_t*)((nbuf)->buf) + uhoff+ UDP_HDR_SIZE)
|
---|
80 |
|
---|
81 | #define IF_IP_UDP_HDR_SIZE(nbuf) (IF_IP_HDR_SIZE(nbuf) + UDP_HDR_SIZE)
|
---|
82 | #define IF_IP_UDP_HDR_OFFSET(nbuf) (IF_IP_HDR_SIZE(nbuf))
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * TINET 1.1 との互換性のための定義
|
---|
86 | */
|
---|
87 |
|
---|
88 | #if defined(_IP4_CFG)
|
---|
89 |
|
---|
90 | #define IP4_UDP_HDR_SIZE IP_UDP_HDR_SIZE
|
---|
91 | #define IF_IP4_UDP_HDR_SIZE IF_IP_UDP_HDR_SIZE
|
---|
92 | #define GET_IP4_UDP_HDR_SIZE(nbuf) GET_IP_UDP_HDR_SIZE(nbuf)
|
---|
93 | #define GET_IF_IP4_UDP_HDR_SIZE(nbuf) GET_IF_IP_UDP_HDR_SIZE(nbuf)
|
---|
94 |
|
---|
95 | #endif /* of #if defined(_IP4_CFG) */
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * コールバック関数の定義
|
---|
99 | */
|
---|
100 |
|
---|
101 | typedef ER (*t_udp_callback)(ID cepid, FN fncd, void *p_parblk);
|
---|
102 |
|
---|
103 | /*
|
---|
104 | * UDP 通信端点
|
---|
105 | */
|
---|
106 |
|
---|
107 | /* IPv6 用 UDP 通信端点 */
|
---|
108 |
|
---|
109 | typedef struct t_udp6_cep {
|
---|
110 |
|
---|
111 | /*
|
---|
112 | * ITRON TCP/IP API、TCP 通信端点と同じメンバ
|
---|
113 | */
|
---|
114 | ATR cepatr; /* UDP 通信端点属性 */
|
---|
115 | T_IPV6EP myaddr; /* 自分のアドレス */
|
---|
116 | t_udp_callback callback; /* コールバック関数 */
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * TINET 独自のメンバ
|
---|
120 | */
|
---|
121 | uint16_t flags; /* 通信端点フラグ */
|
---|
122 | ID semid_lock; /* 通信端点ロック */
|
---|
123 | ID snd_tskid; /* 送信タスク識別子 */
|
---|
124 | ID rcv_tskid; /* 受信タスク識別子 */
|
---|
125 | ID rcvqid; /* 非コールバック用受信キュー識別子*/
|
---|
126 | T_NET_BUF *cb_netbuf; /* コールバック用受信ネットワークバッファ*/
|
---|
127 |
|
---|
128 | #ifdef UDP_CFG_NON_BLOCKING
|
---|
129 |
|
---|
130 | T_IPV6EP *snd_p_dstaddr; /* 送信相手のアドレスへのポインタ*/
|
---|
131 | T_IPV6EP *rcv_p_dstaddr; /* 受信相手のアドレスへのポインタ*/
|
---|
132 | void *snd_data; /* 送信データ領域の先頭アドレス */
|
---|
133 | int_t snd_len; /* 送信データ領域の長さ */
|
---|
134 | void *rcv_data; /* 受信データ領域の先頭アドレス */
|
---|
135 | int_t rcv_len; /* 受信データ領域の長さ */
|
---|
136 |
|
---|
137 | #endif /* of #ifdef UDP_CFG_NON_BLOCKING */
|
---|
138 |
|
---|
139 | #ifdef UDP_CFG_EXTENTIONS
|
---|
140 | ER error; /* 待ち中に発生したエラー */
|
---|
141 | #endif
|
---|
142 |
|
---|
143 | } T_UDP6_CEP;
|
---|
144 |
|
---|
145 | /* IPv4 用 UDP 通信端点 */
|
---|
146 |
|
---|
147 | typedef struct t_udp4_cep {
|
---|
148 |
|
---|
149 | /*
|
---|
150 | * ITRON TCP/IP API、TCP 通信端点と同じメンバ
|
---|
151 | */
|
---|
152 | ATR cepatr; /* UDP 通信端点属性 */
|
---|
153 | T_IPV4EP myaddr; /* 自分のアドレス */
|
---|
154 | t_udp_callback callback; /* コールバック関数 */
|
---|
155 |
|
---|
156 | /*
|
---|
157 | * TINET 独自のメンバ
|
---|
158 | */
|
---|
159 | uint16_t flags; /* 通信端点フラグ */
|
---|
160 | ID semid_lock; /* 通信端点ロック */
|
---|
161 | ID snd_tskid; /* 送信タスク識別子 */
|
---|
162 | ID rcv_tskid; /* 受信タスク識別子 */
|
---|
163 | ID rcvqid; /* 非コールバック用受信キュー識別子*/
|
---|
164 | T_NET_BUF *cb_netbuf; /* コールバック用受信ネットワークバッファ*/
|
---|
165 |
|
---|
166 | #ifdef UDP_CFG_NON_BLOCKING
|
---|
167 |
|
---|
168 | T_IPV4EP *snd_p_dstaddr; /* 送信相手のアドレスへのポインタ*/
|
---|
169 | T_IPV4EP *rcv_p_dstaddr; /* 受信相手のアドレスへのポインタ*/
|
---|
170 | void *snd_data; /* 送信データ領域の先頭アドレス */
|
---|
171 | int_t snd_len; /* 送信データ領域の長さ */
|
---|
172 | void *rcv_data; /* 受信データ領域の先頭アドレス */
|
---|
173 | int_t rcv_len; /* 受信データ領域の長さ */
|
---|
174 |
|
---|
175 | #endif /* of #ifdef UDP_CFG_NON_BLOCKING */
|
---|
176 |
|
---|
177 | #ifdef UDP_CFG_EXTENTIONS
|
---|
178 | ER error; /* 待ち中に発生したエラー */
|
---|
179 | #endif
|
---|
180 |
|
---|
181 | } T_UDP4_CEP;
|
---|
182 |
|
---|
183 | #if defined(_IP6_CFG)
|
---|
184 |
|
---|
185 | #define T_UDP_CEP T_UDP6_CEP
|
---|
186 |
|
---|
187 | #else /* of #if defined(_IP6_CFG) */
|
---|
188 |
|
---|
189 | #if defined(_IP4_CFG)
|
---|
190 |
|
---|
191 | #define T_UDP_CEP T_UDP4_CEP
|
---|
192 |
|
---|
193 | #endif /* of #if defined(_IP4_CFG) */
|
---|
194 |
|
---|
195 | #endif /* of #if defined(_IP6_CFG) */
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * UDP 通信端点フラグ
|
---|
199 | */
|
---|
200 |
|
---|
201 | #define UDP_CEP_FLG_POST_OUTPUT UINT_C(0x0200) /* 送信を開始する。 */
|
---|
202 | #define UDP_CEP_FLG_DYNAMIC UINT_C(0x0400) /* 動的生成・削除可能通信端点。 */
|
---|
203 | #define UDP_CEP_FLG_VALID UINT_C(0x0800) /* 生成済みで有効な通信端点。 */
|
---|
204 |
|
---|
205 | /*
|
---|
206 | * オブジェクト ID の最小値の定義
|
---|
207 | */
|
---|
208 |
|
---|
209 | #define TMIN_UDP_CEPID 1 /* UDP 通信端点 ID の最小値 */
|
---|
210 | #define TMIN_UDP6_CEPID 1 /* UDP/IPv6 通信端点 ID の最小値 */
|
---|
211 | #define TMIN_UDP4_CEPID (TNUM_UDP6_CEPID+1) /* UDP/IPv4 通信端点 ID の最小値 */
|
---|
212 |
|
---|
213 | /*
|
---|
214 | * SNMP の 管理情報ベース (MIB)
|
---|
215 | */
|
---|
216 |
|
---|
217 | typedef struct t_udp_stats {
|
---|
218 | uint32_t udpInDatagrams;
|
---|
219 | uint32_t udpNoPorts;
|
---|
220 | uint32_t udpInErrors;
|
---|
221 | uint32_t udpOutDatagrams;
|
---|
222 | } T_UDP_STATS;
|
---|
223 |
|
---|
224 | /*
|
---|
225 | * 関数シミュレーションマクロ
|
---|
226 | */
|
---|
227 |
|
---|
228 | #define VALID_UDP6_CEPID(id) (TMIN_UDP6_CEPID<=(id)&&(id)<=tmax_udp6_cepid)
|
---|
229 | #define VALID_UDP4_CEPID(id) (TMIN_UDP4_CEPID<=(id)&&(id)<=tmax_udp4_cepid)
|
---|
230 |
|
---|
231 | #define INDEX_UDP6_CEP(id) ((id)-TMIN_UDP6_CEPID)
|
---|
232 | #define INDEX_UDP4_CEP(id) ((id)-TMIN_UDP4_CEPID)
|
---|
233 |
|
---|
234 | #define GET_UDP6_CEP(id) (&(udp6_cep[INDEX_UDP6_CEP(id)]))
|
---|
235 | #define GET_UDP4_CEP(id) (&(udp4_cep[INDEX_UDP4_CEP(id)]))
|
---|
236 |
|
---|
237 | #define GET_UDP6_CEPID(cep) ((ID)(((cep)-udp6_cep)+TMIN_UDP6_CEPID))
|
---|
238 | #define GET_UDP4_CEPID(cep) ((ID)(((cep)-udp4_cep)+TMIN_UDP4_CEPID))
|
---|
239 |
|
---|
240 | #define VALID_TFN_UDP_CAN(t) ((t)==TFN_UDP_SND_DAT||(t)==TFN_UDP_RCV_DAT||\
|
---|
241 | (t)==TFN_UDP_ALL)
|
---|
242 |
|
---|
243 | #define VALID_UDP_CEP(cep) (((cep)->flags&UDP_CEP_FLG_VALID)!=0)
|
---|
244 | #define DYNAMIC_UDP_CEP(cep) (((cep)->flags&UDP_CEP_FLG_DYNAMIC)!=0)
|
---|
245 |
|
---|
246 | /*
|
---|
247 | * 全域変数
|
---|
248 | */
|
---|
249 |
|
---|
250 | extern T_UDP_STATS udp_stats;
|
---|
251 |
|
---|
252 | /* UDP 通信端点 */
|
---|
253 |
|
---|
254 | extern T_UDP6_CEP udp6_cep[];
|
---|
255 | extern T_UDP4_CEP udp4_cep[];
|
---|
256 |
|
---|
257 | #if defined(SUPPORT_INET6)
|
---|
258 | #define udp_cep udp6_cep
|
---|
259 | #elif defined(SUPPORT_INET4)
|
---|
260 | #define udp_cep udp4_cep
|
---|
261 | #endif
|
---|
262 |
|
---|
263 | extern const ID tmax_udp_cepid;
|
---|
264 |
|
---|
265 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
266 | extern const ID tmax_udp6_cepid;
|
---|
267 | extern const ID tmax_udp4_cepid;
|
---|
268 | #else
|
---|
269 | #define tmax_udp6_cepid tmax_udp_cepid
|
---|
270 | #define tmax_udp4_cepid tmax_udp_cepid
|
---|
271 | #endif
|
---|
272 |
|
---|
273 | /*
|
---|
274 | * TINET 1.3 との互換性のための定義
|
---|
275 | */
|
---|
276 |
|
---|
277 | #define TMIN_UDP_CCEPID TMIN_UDP_CEPID
|
---|
278 | #define TNUM_UDP_CCEPID TNUM_UDP_CEPID
|
---|
279 |
|
---|
280 | /*
|
---|
281 | * 関数
|
---|
282 | */
|
---|
283 |
|
---|
284 | /* IPv6 */
|
---|
285 |
|
---|
286 | extern uint_t udp6_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
287 | extern ER_UINT udp6_send_data (T_UDP6_CEP *cep, T_IPV6EP *p_dstaddr,
|
---|
288 | void *data, int_t len, TMO tmout);
|
---|
289 | extern ER udp6_can_snd (T_UDP6_CEP *cep, ER error);
|
---|
290 | extern ER udp6_can_rcv (T_UDP6_CEP *cep, ER error);
|
---|
291 | extern ER udp6_alloc_auto_port (T_UDP6_CEP *cep);
|
---|
292 | extern ER udp6_alloc_port (T_UDP6_CEP *cep, uint16_t portno);
|
---|
293 | extern T_UDP6_CEP*udp6_find_cep (T_NET_BUF *input, uint_t off);
|
---|
294 | extern void udp6_notify (T_NET_BUF *input, ER error);
|
---|
295 | extern void udp6_input_select (T_UDP6_CEP *cep, T_NET_BUF *input, uint_t off);
|
---|
296 |
|
---|
297 | /* IPv4 */
|
---|
298 |
|
---|
299 | extern uint_t udp4_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
300 | extern ER_UINT udp4_send_data (T_UDP4_CEP *cep, T_IPV4EP *p_dstaddr,
|
---|
301 | void *data, int_t len, TMO tmout);
|
---|
302 | extern ER udp4_can_snd (T_UDP4_CEP *cep, ER error);
|
---|
303 | extern ER udp4_can_rcv (T_UDP4_CEP *cep, ER error);
|
---|
304 | extern ER udp4_alloc_auto_port (T_UDP4_CEP *cep);
|
---|
305 | extern ER udp4_alloc_port (T_UDP4_CEP *cep, uint16_t portno);
|
---|
306 | extern T_UDP4_CEP*udp4_find_cep (T_NET_BUF *input, uint_t off);
|
---|
307 | extern void udp4_notify (T_NET_BUF *input, ER error);
|
---|
308 | extern void udp4_input_select (T_UDP4_CEP *cep, T_NET_BUF *input, uint_t off);
|
---|
309 |
|
---|
310 | /* ノンブロッキングコールを行う場合に組み込むタスク */
|
---|
311 |
|
---|
312 | extern void udp_output_task(intptr_t exinf);
|
---|
313 |
|
---|
314 | #endif /* of #ifndef _UDP_VAR_H_ */
|
---|