1 /*********************************************************************************
\r
3 * --------------------------------------------------------------------------------
\r
5 * This file is part of MiMic
\r
6 * Copyright (C)2011 Ryo Iizuka
\r
8 * MiMic is free software: you can redistribute it and/or modify
\r
9 * it under the terms of the GNU Lesser General Public License as published
\r
10 * by the Free Software Foundation, either version 3 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU Lesser General Public License
\r
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
21 * For further information please contact.
\r
23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
26 * Parts of this file were leveraged from uIP:
\r
28 * Copyright (c) 2001-2003, Adam Dunkels.
\r
29 * All rights reserved.
\r
31 * Redistribution and use in source and binary forms, with or without
\r
32 * modification, are permitted provided that the following conditions
\r
34 * 1. Redistributions of source code must retain the above copyright
\r
35 * notice, this list of conditions and the following disclaimer.
\r
36 * 2. Redistributions in binary form must reproduce the above copyright
\r
37 * notice, this list of conditions and the following disclaimer in the
\r
38 * documentation and/or other materials provided with the distribution.
\r
39 * 3. The name of the author may not be used to endorse or promote
\r
40 * products derived from this software without specific prior
\r
41 * written permission.
\r
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
\r
44 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
45 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
\r
47 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
\r
49 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
51 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
52 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
53 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
57 * このファイルは、NyLPC_cIPv4IPv4クラスを定義します。
\r
59 #ifndef NYLPC_CIPV4TCP_H_
\r
60 #define NYLPC_CIPV4TCP_H_
\r
64 #include "NyLPC_uip.h"
\r
65 #include "NyLPC_cTcpListener.h"
\r
66 #include "NyLPC_cTcpSocket.h"
\r
67 #include "NyLPC_cIPv4Config.h"
\r
71 #endif /* __cplusplus */
\r
75 * NyLPC_cIPv4クラスは、NyLPC_cUipServiceクラスの一部として働きます。
\r
76 * 通常ユーザが操作することはありません。
\r
77 * IPv4における、ソケットクラス(NyLPC_cTcpSocketとNyLPC_cTcpListener)の管理を担当します。
\r
78 * クラスのインスタンスは、NyLPC_cUipServiceのインスタンスにより生成されます。
\r
79 * インスタンスは2つのポインタリストをもち、ここにこれらのインスタンスを登録します。
\r
80 * インスタンスは、NyLPC_cUipServiceから送られてきた受信パケットを、登録されているソケットクラスに
\r
83 typedef struct NyLPC_TcIPv4 NyLPC_TcIPv4_t;
\r
85 /**********************************************************************
\r
87 * class NyLPC_TcIPv4
\r
89 **********************************************************************/
\r
92 * 環境定数です。NyLPC_TcTcpListenerインスタンスリストの数を設定します。
\r
93 * この値は、NyLPC_cTcpListenerクラスの最大生成数になります。
\r
95 #define NyLPC_cIPv4_MAX_TCP_LISTENER 10
\r
99 * この値は、NyLPC_cTcpSocketクラスの最大生成数になります。
\r
101 #define NyLPC_cIPv4_MAX_TCP_SOCKET 10
\r
106 * NyLPC_TcIPv4クラスの構造体です。
\r
108 struct NyLPC_TcIPv4
\r
110 /** 参照しているIPスタックの環境値です。この値は、start関数が設定します。*/
\r
111 const NyLPC_TcIPv4Config_t* _ref_config;
\r
112 /** NyLPC_cTcpListernerを管理するポインタリストです。*/
\r
113 NyLPC_TcPtrTbl_t _listener_tbl;
\r
114 /** NyLPC_cTcpSocketを管理するポインタリストです。*/
\r
115 NyLPC_TcPtrTbl_t _socket_tbl;
\r
116 /** _listener_tblが使用するメモリ領域です。*/
\r
117 NyLPC_TcTcpListener_t* _listener_array_buf[NyLPC_cIPv4_MAX_TCP_LISTENER];
\r
118 /** _socket_tblが使用するメモリ領域です。*/
\r
119 NyLPC_TcTcpSocket_t* _socket_array_buf[NyLPC_cIPv4_MAX_TCP_SOCKET];
\r
124 * コンストラクタです。インスタンスを初期化します。
\r
128 void NyLPC_cIPv4_initialize(
\r
129 NyLPC_TcIPv4_t* i_inst);
\r
132 * デストラクタです。インスタンスを破棄して、確保している動的リソースを元に戻します。
\r
135 * initializeが成功したインスタンスだけが指定できます。
\r
137 void NyLPC_cIPv4_finalize(
\r
138 NyLPC_TcIPv4_t* i_inst);
\r
141 * この関数は、インスタンスにTCP/IP処理の準備をするように伝えます。
\r
144 * @param i_ref_configlation
\r
145 * IPの環境値をセットしたオブジェクトを指定します。
\r
146 * この値は、stop関数を実行するまでの間、維持してください。
\r
148 void NyLPC_cIPv4_start(
\r
149 NyLPC_TcIPv4_t* i_inst,
\r
150 const NyLPC_TcIPv4Config_t* i_ref_configlation);
\r
153 * この関数はTCP/IP処理を停止することを伝えます。
\r
156 * startで開始済みで無ければなりません。
\r
158 * 現在、接続中の接続に対する保障は未実装です。安全に使用することが出来ません。
\r
160 void NyLPC_cIPv4_stop(
\r
161 NyLPC_TcIPv4_t* i_inst);
\r
164 * この関数は、NyLPC_cTcpSocketオブジェクトを管理リストへ追加します。
\r
165 * NyLPC_cTcpSocketが使います。
\r
171 * 追加が成功するとTRUEを返します。
\r
173 NyLPC_TBool NyLPC_cIPv4_addSocket(
\r
174 NyLPC_TcIPv4_t* i_inst,
\r
175 NyLPC_TcTcpSocket_t* i_sock);
\r
178 * この関数は、NyLPC_cTcpSocketオブジェクトを管理リストから除外します。
\r
179 * NyLPC_cTcpSocketが使います。
\r
185 * 削除が成功するとTRUEを返します。
\r
187 NyLPC_TBool NyLPC_cIPv4_removeSocket(
\r
188 NyLPC_TcIPv4_t* i_inst,
\r
189 NyLPC_TcTcpSocket_t* i_sock);
\r
192 * この関数は、NyLPC_cTcpListenerオブジェクトを管理リストへ追加します。
\r
193 * NyLPC_cTcpListenerが使います。
\r
199 * 追加が成功するとTRUEを返します。
\r
201 NyLPC_TBool NyLPC_cIPv4_addListener(
\r
202 NyLPC_TcIPv4_t* i_inst,
\r
203 NyLPC_TcTcpListener_t* i_listener);
\r
206 * この関数は、NyLPC_cTcpListenerオブジェクトを管理リストから除外します。
\r
207 * NyLPC_cTcpListenerが使います。
\r
213 * 削除が成功するとTRUEを返します。
\r
215 NyLPC_TBool NyLPC_cIPv4_removeListener(
\r
216 NyLPC_TcIPv4_t* i_inst,
\r
217 NyLPC_TcTcpListener_t* i_listener);
\r
220 * この関数は、RxIPパケットを処理して、管理下のインスタンスに処理を依頼します。
\r
221 * 現在の関数は、i_rxに最大64バイトの応答パケットのイメージを格納することがあります。
\r
222 * 応答パケットは、RXに対するACKパケットです。
\r
223 * 格納の有無は戻り値を確認することで判ります。
\r
227 * RXパケットを格納したメモリアドレスです。
\r
228 * 最低でも、64バイト以上のサイズが必要です。
\r
230 * i_rxに格納したデータのサイズです。
\r
232 * i_rxに応答パケットを格納したかどうかを返します
\r
234 NyLPC_TBool NyLPC_cIPv4_rx(NyLPC_TcIPv4_t* i_inst,void* i_rx,NyLPC_TUInt16 i_rx_size);
\r
236 * この関数は、定期的にインスタンスへ実行機会を与える関数です。
\r
237 * TCPの再送、無通信タイムアウトなどを処理します。
\r
242 void NyLPC_cIPv4_periodec(NyLPC_TcIPv4_t* i_inst);
\r
246 #endif /* __cplusplus */
\r