OSDN Git Service

update libMiMic
[mimic/MiMicSDK.git] / lib / src / netif / mimicip / NyLPC_cIPv4.h
similarity index 73%
rename from lib/src/uip/NyLPC_cIPv4.h
rename to lib/src/netif/mimicip/NyLPC_cIPv4.h
index f637059..15e22fc 100644 (file)
-/*********************************************************************************\r
- * PROJECT: MiMic\r
- * --------------------------------------------------------------------------------\r
- *\r
- * This file is part of MiMic\r
- * Copyright (C)2011 Ryo Iizuka\r
- *\r
- * MiMic is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published\r
- * by the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public License\r
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- * For further information please contact.\r
- *     http://nyatla.jp/\r
- *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
- *\r
- *\r
- * Parts of this file were leveraged from uIP:\r
- *\r
- * Copyright (c) 2001-2003, Adam Dunkels.\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote\r
- *    products derived from this software without specific prior\r
- *    written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-/**\r
- * @file\r
- * このファイルは、NyLPC_cIPv4IPv4クラスを定義します。\r
- */\r
-#ifndef NYLPC_CIPV4TCP_H_\r
-#define NYLPC_CIPV4TCP_H_\r
-\r
-\r
-\r
-#include "NyLPC_uip.h"\r
-#include "NyLPC_cTcpListener.h"\r
-#include "NyLPC_cTcpSocket.h"\r
-#include "NyLPC_cIPv4Config.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif /* __cplusplus */\r
-\r
-\r
-\r
-\r
-/**********************************************************************\r
- *\r
- * class NyLPC_TcIPv4\r
- *\r
- **********************************************************************/\r
-#include "NyLPC_cIPv4_typedef.h"\r
-\r
-///**\r
-// * 環境定数です。NyLPC_TcTcpListenerインスタンスリストの数を設定します。\r
-// * この値は、NyLPC_cTcpListenerクラスの最大生成数になります。\r
-// */\r
-//#define NyLPC_cIPv4_MAX_TCP_LISTENER 10\r
-\r
-/**\r
- * Socketの最大生成数\r
- * この値は、NyLPC_cTcpSocketクラス,NyLPC_cTcpListener,NyLPC_cUdpの最大生成数になります。\r
- */\r
-#define NyLPC_cIPv4_MAX_SOCKET 10\r
-\r
-\r
-\r
-/**\r
- * NyLPC_TcIPv4クラスの構造体です。\r
- */\r
-struct NyLPC_TcIPv4\r
-{\r
-       /** 参照しているIPスタックの環境値です。この値は、start関数が設定します。*/\r
-       const NyLPC_TcIPv4Config_t* _ref_config;\r
-       /** ソケットリソースの保護用。コールバック関数から呼び出されるソケット内部のリソース保護に使用する共通MUTEX*/\r
-       NyLPC_TcMutex_t _sock_mutex;\r
-       /** リスナリソースの保護用。コールバック関数から呼び出されるソケット内部のリソース保護に使用する共通MUTEX*/\r
-       NyLPC_TcMutex_t _listener_mutex;\r
-       /** NyLPC_cTcpSocketを管理するポインタリストです。*/\r
-       NyLPC_TcPtrTbl_t _socket_tbl;\r
-       /** _socket_tblが使用するメモリ領域です。*/\r
-       NyLPC_TcBaseSocket_t* _socket_array_buf[NyLPC_cIPv4_MAX_SOCKET];\r
-       /** 0-0xfffまでを巡回するカウンタ*/\r
-       NyLPC_TUInt16 tcp_port_counter;\r
-};\r
-\r
-/**\r
- * コンストラクタです。インスタンスを初期化します。\r
- * @param i_inst\r
- * 初期化するインスタンス\r
- */\r
-void NyLPC_cIPv4_initialize(\r
-       NyLPC_TcIPv4_t* i_inst);\r
-\r
-/**\r
- * デストラクタです。インスタンスを破棄して、確保している動的リソースを元に戻します。\r
- * @param i_inst\r
- * 破棄するインスタンス\r
- * initializeが成功したインスタンスだけが指定できます。\r
- */\r
-void NyLPC_cIPv4_finalize(\r
-       NyLPC_TcIPv4_t* i_inst);\r
-\r
-/**\r
- * この関数は、インスタンスにTCP/IP処理の準備をするように伝えます。\r
- * @param i_inst\r
- * 操作するインスタンス\r
- * @param i_ref_configlation\r
- * IPの環境値をセットしたオブジェクトを指定します。\r
- * この値は、stop関数を実行するまでの間、維持してください。\r
- */\r
-void NyLPC_cIPv4_start(\r
-       NyLPC_TcIPv4_t* i_inst,\r
-       const NyLPC_TcIPv4Config_t* i_ref_configlation);\r
-\r
-/**\r
- * この関数はTCP/IP処理を停止することを伝えます。\r
- * @param i_inst\r
- * 操作するインスタンス。\r
- * startで開始済みで無ければなりません。\r
- * @note\r
- * 現在、接続中の接続に対する保障は未実装です。安全に使用することが出来ません。\r
- */\r
-void NyLPC_cIPv4_stop(\r
-       NyLPC_TcIPv4_t* i_inst);\r
-\r
-/**\r
- * この関数は、NyLPC_TcBaseSocketオブジェクトを管理リストへ追加します。\r
- * @param i_inst\r
- * 操作するインスタンス。\r
- * @param i_sock\r
- * 追加するインスタンスのポインタ\r
- * @return\r
- * 追加が成功するとTRUEを返します。\r
- */\r
-NyLPC_TBool NyLPC_cIPv4_addSocket(\r
-       NyLPC_TcIPv4_t* i_inst,\r
-       NyLPC_TcBaseSocket_t* i_sock);\r
-\r
-/**\r
- * この関数は、NyLPC_cTcpSocketオブジェクトを管理リストから除外します。\r
- * NyLPC_TcBaseSocketが使います。\r
- * @param i_inst\r
- * 操作するインスタンス。\r
- * @param i_sock\r
- * 削除するインスタンスのポインタ\r
- * @return\r
- * 削除が成功するとTRUEを返します。\r
- */\r
-NyLPC_TBool NyLPC_cIPv4_removeSocket(\r
-       NyLPC_TcIPv4_t* i_inst,\r
-       NyLPC_TcBaseSocket_t* i_sock);\r
-\r
-\r
-/**\r
- * この関数は、RxIPパケットを処理して、管理下のインスタンスに処理を依頼します。\r
- * 現在の関数は、i_rxに最大64バイトの応答パケットのイメージを格納することがあります。\r
- * 応答パケットは、RXに対するACKパケットです。\r
- * 格納の有無は戻り値を確認することで判ります。\r
- * この関数はstart-stopの間だけコールすることが出来ます。start,stopと非同期に実行しないでください。\r
- * @param i_inst\r
- * 操作するインスタンスです。\r
- * @param i_rx\r
- * RXパケットを格納したメモリアドレスです。\r
- * 最低でも、64バイト以上のサイズが必要です。\r
- * @param i_rx_size\r
- * i_rxに格納したデータのサイズです。\r
- * @return\r
- * 応答パケットを格納したメモリです。\r
- */\r
-void* NyLPC_cIPv4_rx(NyLPC_TcIPv4_t* i_inst,const void* i_rx,NyLPC_TUInt16 i_rx_size);\r
-/**\r
- * この関数は、定期的にインスタンスへ実行機会を与える関数です。\r
- * TCPの再送、無通信タイムアウトなどを処理します。\r
- * 約1秒おきに呼び出してください。\r
- * @param i_inst\r
- * 操作するインスタンスです。\r
- */\r
-void NyLPC_cIPv4_periodec(NyLPC_TcIPv4_t* i_inst);\r
-\r
-/**\r
- * ソケットリソースとコールバックの排他処理に使う共通MUTEXを返します。\r
- * このMutexはソケット同士の干渉が起こらない処理にだけ使ってください。\r
- */\r
-#define NyLPC_cIPv4_getSockMutex(i_inst) (&((i_inst)->_sock_mutex))\r
-/**\r
- * リスナーリソースとコールバックの排他処理に使う共通MUTEXを返します。\r
- */\r
-#define NyLPC_cIPv4_getListenerMutex(i_inst) (&((i_inst)->_listener_mutex))\r
-\r
-/**\r
- * ポート0で使用するポート番号を返します。\r
- * @return\r
- * 49152 - (49152+0x0ffff)番までのポートのうち、使用中でないポート番号を返します。\r
- * エラー時は0です。\r
- */\r
-NyLPC_TUInt16 NyLPC_cIPv4_getNewPortNumber(NyLPC_TcIPv4_t* i_inst);\r
-\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif /* __cplusplus */\r
-\r
-#endif\r
+/*********************************************************************************
+ * PROJECT: MiMic
+ * --------------------------------------------------------------------------------
+ *
+ * This file is part of MiMic
+ * Copyright (C)2011 Ryo Iizuka
+ *
+ * MiMic is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For further information please contact.
+ *  http://nyatla.jp/
+ *  <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
+ *
+ *
+ * Parts of this file were leveraged from uIP:
+ *
+ * Copyright (c) 2001-2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/**
+ * @file
+ * このファイルは、NyLPC_cIPv4IPv4クラスを定義します。
+ */
+#ifndef NYLPC_CIPV4TCP_H_
+#define NYLPC_CIPV4TCP_H_
+
+
+
+#include "NyLPC_os.h"
+#include "../NyLPC_NetIf_ip_types.h"
+#include "../NyLPC_cIPv4Config.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+/**********************************************************************
+ *
+ * Closs reference
+ *
+ **********************************************************************/
+
+typedef struct NyLPC_TcMiMicIpBaseSocket NyLPC_TcMiMicIpBaseSocket_t;
+
+
+/**********************************************************************
+ *
+ * class NyLPC_TcIPv4
+ *
+ **********************************************************************/
+typedef struct NyLPC_TcIPv4 NyLPC_TcIPv4_t;
+
+
+
+
+/**
+ * Socketの最大生成数
+ * この値は、NyLPC_cTcpSocketクラス,NyLPC_cTcpListener,NyLPC_cUdpの最大生成数になります。
+ */
+#define NyLPC_cIPv4_MAX_SOCKET 10
+
+
+
+/**
+ * NyLPC_TcIPv4クラスの構造体です。
+ */
+struct NyLPC_TcIPv4
+{
+    /** 参照しているIPスタックの環境値です。この値は、start関数が設定します。*/
+    const NyLPC_TcIPv4Config_t* _ref_config;
+    /** ソケットリソースの保護用。コールバック関数から呼び出されるソケット内部のリソース保護に使用する共通MUTEX*/
+    NyLPC_TcMutex_t _sock_mutex;
+    /** リスナリソースの保護用。コールバック関数から呼び出されるソケット内部のリソース保護に使用する共通MUTEX*/
+    NyLPC_TcMutex_t _listener_mutex;
+    /** 0-0xfffまでを巡回するカウンタ*/
+    NyLPC_TUInt16 tcp_port_counter;
+};
+
+/**
+ * コンストラクタです。インスタンスを初期化します。
+ * @param i_inst
+ * 初期化するインスタンス
+ */
+void NyLPC_cIPv4_initialize(
+    NyLPC_TcIPv4_t* i_inst);
+
+/**
+ * デストラクタです。インスタンスを破棄して、確保している動的リソースを元に戻します。
+ * @param i_inst
+ * 破棄するインスタンス
+ * initializeが成功したインスタンスだけが指定できます。
+ */
+void NyLPC_cIPv4_finalize(
+    NyLPC_TcIPv4_t* i_inst);
+
+/**
+ * この関数は、インスタンスにTCP/IP処理の準備をするように伝えます。
+ * @param i_inst
+ * 操作するインスタンス
+ * @param i_ref_configlation
+ * IPの環境値をセットしたオブジェクトを指定します。
+ * この値は、stop関数を実行するまでの間、維持してください。
+ */
+void NyLPC_cIPv4_start(
+    NyLPC_TcIPv4_t* i_inst,
+    const NyLPC_TcIPv4Config_t* i_ref_configlation);
+
+/**
+ * この関数はTCP/IP処理を停止することを伝えます。
+ * @param i_inst
+ * 操作するインスタンス。
+ * startで開始済みで無ければなりません。
+ * @note
+ * 現在、接続中の接続に対する保障は未実装です。安全に使用することが出来ません。
+ */
+void NyLPC_cIPv4_stop(
+    NyLPC_TcIPv4_t* i_inst);
+
+/**
+ * この関数は、RxIPパケットを処理して、管理下のインスタンスに処理を依頼します。
+ * 現在の関数は、i_rxに最大64バイトの応答パケットのイメージを格納することがあります。
+ * 応答パケットは、RXに対するACKパケットです。
+ * 格納の有無は戻り値を確認することで判ります。
+ * この関数はstart-stopの間だけコールすることが出来ます。start,stopと非同期に実行しないでください。
+ * @param i_inst
+ * 操作するインスタンスです。
+ * @param i_rx
+ * RXパケットを格納したメモリアドレスです。
+ * 最低でも、64バイト以上のサイズが必要です。
+ * @param i_rx_size
+ * i_rxに格納したデータのサイズです。
+ * @return
+ * 応答パケットを格納したメモリです。
+ */
+void* NyLPC_cIPv4_rx(NyLPC_TcIPv4_t* i_inst,const void* i_rx,NyLPC_TUInt16 i_rx_size);
+/**
+ * この関数は、定期的にインスタンスへ実行機会を与える関数です。
+ * TCPの再送、無通信タイムアウトなどを処理します。
+ * 約1秒おきに呼び出してください。
+ * @param i_inst
+ * 操作するインスタンスです。
+ */
+void NyLPC_cIPv4_periodec(NyLPC_TcIPv4_t* i_inst);
+
+/**
+ * ソケットリソースとコールバックの排他処理に使う共通MUTEXを返します。
+ * このMutexはソケット同士の干渉が起こらない処理にだけ使ってください。
+ */
+#define NyLPC_cIPv4_getSockMutex(i_inst) (&((i_inst)->_sock_mutex))
+/**
+ * リスナーリソースとコールバックの排他処理に使う共通MUTEXを返します。
+ */
+#define NyLPC_cIPv4_getListenerMutex(i_inst) (&((i_inst)->_listener_mutex))
+
+/**
+ * ポート0で使用するポート番号を返します。
+ * @return
+ * 49152 - (49152+0x0ffff)番までのポートのうち、使用中でないポート番号を返します。
+ * エラー時は0です。
+ */
+NyLPC_TUInt16 NyLPC_cIPv4_getNewPortNumber(NyLPC_TcIPv4_t* i_inst);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif