1 /*********************************************************************************
3 * --------------------------------------------------------------------------------
5 * This file is part of MiMic
6 * Copyright (C)2011 Ryo Iizuka
8 * MiMic is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * For further information please contact.
23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
25 *********************************************************************************/
27 #ifndef NyLPC_MiMicIpNetIf_protected_H
28 #define NyLPC_MiMicIpNetIf_protected_H
29 #include "NyLPC_cMiMicIpNetIf.h"
31 #include "NyLPC_cIPv4Arp.h"
32 #include "NyLPC_cIPv4.h"
33 #include "NyLPC_cIPv4IComp.h"
34 #include "../driver/ethernet/EthDev.h"
35 #include "NyLPC_cMiMicIpTcpSocket.h"
36 #include "NyLPC_cMiMicIpUdpSocket.h"
37 #include "NyLPC_cMiMicIpTcpListener.h"
39 /**********************************************************************
41 * NyLPC_TcUipService_t
43 **********************************************************************/
46 #endif /* __cplusplus */
48 //#define NyLPC_TcUipService_SIZE_OF_REPLY_BUF 128
52 struct NyLPC_TcMiMicIpNetIf
54 volatile NyLPC_TUInt16 _status; /**< ステータスビット*/
55 NyLPC_TcSemaphore_t _emac_semapho; /** EMACの制御用セマフォです。*/
56 NyLPC_TcStopwatch_t _arp_sw; /**<ARP用のストップウォッチ*/
57 NyLPC_TcStopwatch_t _periodic_sw; /**<周期実行用のストップウォッチ*/
59 NyLPC_TcIPv4Arp_t _arp;
61 NyLPC_TcIPv4_t _tcpv4;
63 NyLPC_TcIPv4IComp_t _icomp;
64 /** (Ethernetメモリ排他制御用)*/
65 NyLPC_TcMutex_t _mutex;
66 const struct TiEthernetDevice* _ethif;
67 struct NyLPC_TNetInterfaceInfo _netinfo;
71 /** 唯一のサービスインスタンス - Single service instance*/
72 extern NyLPC_TcMiMicIpNetIf_t* _NyLPC_TcMiMicIpNetIf_inst;
76 * システムで唯一のUIPサービスを初期化します。1度だけ実行できます。
78 NyLPC_TBool NyLPC_cMiMicIpNetIf_initialize(NyLPC_TcMiMicIpNetIf_t* i_inst);
81 * サービスが初期化済みならtrueです。 - true if service was initialized.
83 #define NyLPC_cMiMicIpNetIf_isInitService() (_NyLPC_TcMiMicIpNetIf_inst!=NULL)
87 #define NyLPC_cMiMicIpNetIf_isRun() NyLPC_TUInt16_isBitOn(_NyLPC_TcMiMicIpNetIf_inst->_status,NyLPC_TcMiMicIpNetIf_STATUSBIT_IS_RUNNING)
90 /**********************************************************************
92 **********************************************************************/
94 #define NyLPC_TcMiMicIpNetIf_STATUSBIT_IS_RUNNING 0
95 #define NyLPC_TcMiMicIpNetIf_ORDER_START 1
96 #define NyLPC_TcMiMicIpNetIf_ORDER_STOP 2
100 #define INST_TYPE_NyLPC_Unknown 0
101 #define INST_TYPE_NyLPC_TcTcpListener 1
102 #define INST_TYPE_NyLPC_TcTcpSocket 2
105 /**********************************************************************
109 **********************************************************************/
112 * NyLPC_cUipService_allocTxBufが返却するメモリサイズ。
115 #define NyLPC_cMiMicIpNetIf_SYS_TX_BUF_SIZE (64-sizeof(struct NyLPC_TEthernetIIHeader))
119 * IPv4パケットをネットワークに送信します。
120 * この関数は、リエントラントを許容します。
121 * @param i_eth_payload
122 * NyLPC_cUipService_getTxFrame、または、NyLPC_cUipService_recvIPv4Rxで得たバッファに、
123 * IPv4パケットを書きこんだものを指定してください。
125 void NyLPC_cMiMicIpNetIf_sendIPv4Tx(void* i_eth_payload);
129 * この関数は、リエントラントを許容します。
131 * 取得したいメモリサイズを指定します。(このサイズは、イーサネットヘッダのサイズを含みません。)
132 * このサイズよりも小さなサイズが割り当てられることがあります。
134 * 取得メモリのイーサネットヘッダを除いたペイロード部分の長さ
136 * 成功:IPペイロードのためのメモリブロックを返します。/失敗:NULL
137 * メモリは、[TEthPacket][payload]の構造で返されます。
139 void* NyLPC_cMiMicIpNetIf_allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size);
142 * システム用の小さな送信ペイロードメモリを返します。
143 * この関数は、リエントラントを許容します。
144 * 返却するメモリブロックのサイズが小さいこと、メモリが確実に返される点がNyLPC_cUipService_allocTxBufと異なります。
145 * この関数が返すメモリのサイズは、NyLPC_cUipService_SYS_TX_BUF_SIZEの値です。
146 * 関数を使用するコードでは開始時に1度だけNyLPC_cUipService_SYS_TX_BUF_SIZEの値を確認して下さい。
148 void* NyLPC_cMiMicIpNetIf_allocSysTxBuf(void);
151 * allocTxbufで確保したメモリを開放します。
153 void* NyLPC_cMiMicIpNetIf_releaseTxBuf(void* i_buf);
156 * 指定したIPアドレスを要求するARPリクエストを発行します。
158 void NyLPC_cMiMicIpNetIf_sendArpRequest(const struct NyLPC_TIPv4Addr* i_addr);
161 * ARPテーブルに指定したIPがあるかを返します。
163 NyLPC_TBool NyLPC_cMiMicIpNetIf_hasArpInfo(const struct NyLPC_TIPv4Addr* i_addr);
166 void NyLPC_cMiMicIpNetIf_releaseTcpSocketMemory(const NyLPC_TcMiMicIpTcpSocket_t* i_inst);
167 void NyLPC_cMiMicIpNetIf_releaseUdpSocketMemory(const NyLPC_TcMiMicIpUdpSocket_t* i_inst);
168 void NyLPC_cMiMicIpNetIf_releaseTcpListenerMemory(const NyLPC_TcMiMicIpTcpListener_t* i_inst);
170 NyLPC_TcMiMicIpTcpListener_t* NyLPC_cMiMicIpNetIf_getListenerByPeerPort(NyLPC_TUInt16 i_port);
171 NyLPC_TcMiMicIpUdpSocket_t* NyLPC_cMiMicIpNetIf_getMatchUdpSocket(NyLPC_TUInt16 i_lport);
172 NyLPC_TBool NyLPC_cMiMicIpNetIf_isClosedTcpPort(NyLPC_TUInt16 i_lport);
173 NyLPC_TcMiMicIpUdpSocket_t* NyLPC_cMiMicIpNetIf_getMatchMulticastUdpSocket(
174 const struct NyLPC_TIPv4Addr* i_mcast_ip,NyLPC_TUInt16 i_lport);
175 NyLPC_TcMiMicIpTcpSocket_t* NyLPC_cMiMicIpNetIf_getMatchTcpSocket(
176 NyLPC_TUInt16 i_lport,struct NyLPC_TIPv4Addr i_rip,NyLPC_TUInt16 i_rport);
177 void NyLPC_cMiMicIpNetIf_callPeriodic(void);
178 void NyLPC_cMiMicIpNetIf_callSocketStart(const NyLPC_TcIPv4Config_t* i_cfg);
179 void NyLPC_cMiMicIpNetIf_callSocketStop(void);
187 #endif /* __cplusplus */