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 * NyLPC_cIPv4クラスは、NyLPC_cUipServiceクラスの一部として働きます。
\r
65 * 通常ユーザが操作することはありません。
\r
66 * IPv4における、ソケットクラス(NyLPC_cTcpSocketとNyLPC_cTcpListener)の管理を担当します。
\r
67 * クラスのインスタンスは、NyLPC_cUipServiceのインスタンスにより生成されます。
\r
68 * インスタンスは2つのポインタリストをもち、ここにこれらのインスタンスを登録します。
\r
69 * インスタンスは、NyLPC_cUipServiceから送られてきた受信パケットを、登録されているソケットクラスに
\r
72 typedef struct NyLPC_TcIPv4 NyLPC_TcIPv4_t;
\r
74 #include "NyLPC_uip.h"
\r
75 #include "NyLPC_cTcpListener.h"
\r
76 #include "NyLPC_cTcpSocket.h"
\r
77 /**********************************************************************
\r
79 * class NyLPC_TcIPv4
\r
81 **********************************************************************/
\r
84 * 環境定数です。NyLPC_TcTcpListenerインスタンスリストの数を設定します。
\r
85 * この値は、NyLPC_cTcpListenerクラスの最大生成数になります。
\r
87 #define NyLPC_cIPv4_MAX_TCP_LISTENER 10
\r
91 * この値は、NyLPC_cTcpSocketクラスの最大生成数になります。
\r
93 #define NyLPC_cIPv4_MAX_TCP_SOCKET 10
\r
98 * NyLPC_TcIPv4クラスの構造体です。
\r
100 struct NyLPC_TcIPv4
\r
102 /** 参照しているIPスタックの環境値です。この値は、start関数が設定します。*/
\r
103 const NyLPC_TcIPv4Config_t* _ref_config;
\r
104 /** NyLPC_cTcpListernerを管理するポインタリストです。*/
\r
105 NyLPC_TcPtrTbl_t _listener_tbl;
\r
106 /** NyLPC_cTcpSocketを管理するポインタリストです。*/
\r
107 NyLPC_TcPtrTbl_t _socket_tbl;
\r
108 /** _listener_tblが使用するメモリ領域です。*/
\r
109 NyLPC_TcTcpListener_t* _listener_array_buf[NyLPC_cIPv4_MAX_TCP_LISTENER];
\r
110 /** _socket_tblが使用するメモリ領域です。*/
\r
111 NyLPC_TcTcpSocket_t* _socket_array_buf[NyLPC_cIPv4_MAX_TCP_SOCKET];
\r
116 * コンストラクタです。インスタンスを初期化します。
\r
120 void NyLPC_cIPv4_initialize(
\r
121 NyLPC_TcIPv4_t* i_inst);
\r
124 * デストラクタです。インスタンスを破棄して、確保している動的リソースを元に戻します。
\r
127 * initializeが成功したインスタンスだけが指定できます。
\r
129 void NyLPC_cIPv4_finalize(
\r
130 NyLPC_TcIPv4_t* i_inst);
\r
133 * この関数は、インスタンスにTCP/IP処理の準備をするように伝えます。
\r
136 * @param i_ref_configlation
\r
137 * IPの環境値をセットしたオブジェクトを指定します。
\r
138 * この値は、stop関数を実行するまでの間、維持してください。
\r
140 void NyLPC_cIPv4_start(
\r
141 NyLPC_TcIPv4_t* i_inst,
\r
142 const NyLPC_TcIPv4Config_t* i_ref_configlation);
\r
145 * この関数はTCP/IP処理を停止することを伝えます。
\r
148 * startで開始済みで無ければなりません。
\r
150 * 現在、接続中の接続に対する保障は未実装です。安全に使用することが出来ません。
\r
152 void NyLPC_cIPv4_stop(
\r
153 NyLPC_TcIPv4_t* i_inst);
\r
156 * この関数は、NyLPC_cTcpSocketオブジェクトを管理リストへ追加します。
\r
157 * NyLPC_cTcpSocketが使います。
\r
163 * 追加が成功するとTRUEを返します。
\r
165 NyLPC_TBool NyLPC_cIPv4_addSocket(
\r
166 NyLPC_TcIPv4_t* i_inst,
\r
167 NyLPC_TcTcpSocket_t* i_sock);
\r
170 * この関数は、NyLPC_cTcpSocketオブジェクトを管理リストから除外します。
\r
171 * NyLPC_cTcpSocketが使います。
\r
177 * 削除が成功するとTRUEを返します。
\r
179 NyLPC_TBool NyLPC_cIPv4_removeSocket(
\r
180 NyLPC_TcIPv4_t* i_inst,
\r
181 NyLPC_TcTcpSocket_t* i_sock);
\r
184 * この関数は、NyLPC_cTcpListenerオブジェクトを管理リストへ追加します。
\r
185 * NyLPC_cTcpListenerが使います。
\r
191 * 追加が成功するとTRUEを返します。
\r
193 NyLPC_TBool NyLPC_cIPv4_addListener(
\r
194 NyLPC_TcIPv4_t* i_inst,
\r
195 NyLPC_TcTcpListener_t* i_listener);
\r
198 * この関数は、NyLPC_cTcpListenerオブジェクトを管理リストから除外します。
\r
199 * NyLPC_cTcpListenerが使います。
\r
205 * 削除が成功するとTRUEを返します。
\r
207 NyLPC_TBool NyLPC_cIPv4_removeListener(
\r
208 NyLPC_TcIPv4_t* i_inst,
\r
209 NyLPC_TcTcpListener_t* i_listener);
\r
212 * この関数は、RxIPパケットを処理して、管理下のインスタンスに処理を依頼します。
\r
213 * 現在の関数は、i_rxに最大64バイトの応答パケットのイメージを格納することがあります。
\r
214 * 応答パケットは、RXに対するACKパケットです。
\r
215 * 格納の有無は戻り値を確認することで判ります。
\r
219 * RXパケットを格納したメモリアドレスです。
\r
220 * 最低でも、64バイト以上のサイズが必要です。
\r
222 * i_rxに格納したデータのサイズです。
\r
224 * i_rxに応答パケットを格納したかどうかを返します
\r
226 NyLPC_TBool NyLPC_cIPv4_rx(NyLPC_TcIPv4_t* i_inst,void* i_rx,NyLPC_TUInt16 i_rx_size);
\r
228 * この関数は、定期的にインスタンスへ実行機会を与える関数です。
\r
229 * TCPの再送、無通信タイムアウトなどを処理します。
\r
234 void NyLPC_cIPv4_periodec(NyLPC_TcIPv4_t* i_inst);
\r