* allocTxBufで得たメモリか、初期化したNyLPC_TTxBufferHeaderメモリブロックを指定する。\r
* 送信が終わるまでの間、メモリを開放してはならない。\r
* #外部で確保したメモリについては、利用不能なケースがあるかもしれない。現在のMiMicでは、使用できることを前提としている。\r
+ * @oaram i_size\r
+ * i_bufの後ろに連結されているデータメモリの長さ\r
*/\r
typedef void (*NyLPC_TiEthernetDevice_sendTxEthFrame)(struct NyLPC_TTxBufferHeader* i_buf,unsigned short i_size);\r
/**\r
+/*********************************************************************************\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
#include "NyLPC_cNet.h"\r
#include "dhcp/NyLPC_cDhcpClient.h"\r
\r
+/*********************************************************************************\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
#ifndef NYLPC_CNET_H_\r
#define NYLPC_CNET_H_\r
\r
+/*********************************************************************************\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
#include "NyLPC_cNetConfig.h"\r
#include "../flash/NyLPC_cMiMicConfiglation.h"\r
\r
+/*********************************************************************************\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
#ifndef NYLPC_CNETCONFIG_H_\r
#define NYLPC_CNETCONFIG_H_\r
\r
-/**\r
- * httpdサーバのサンプルです。\r
- * ROMにある定義済みファイルの入出力と、クロスドメインRESTが確認できます。\r
- */\r
+/*********************************************************************************\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
#include "NyLPC_cMDnsServer.h"\r
#include "NyLPC_uipService.h"\r
#include "NyLPC_http.h"\r
const struct NyLPC_TEthAddr* NyLPC_cIPv4Arp_IPv4toEthAddr(NyLPC_TcIPv4Arp_t* i_inst,const struct NyLPC_TIPv4Addr i_ip_addr)\r
{\r
int i;\r
- struct NyLPC_TIPv4Addr ip;\r
struct NyLPC_TArpTableItem *tabptr;\r
- //LocalIPでなければ、デフォルトゲートウェイのアドレスに設定。\r
- if (!NyLPC_cIPv4Config_isLocalIP(i_inst->_cfg, &i_ip_addr)){\r
- ip = i_inst->_cfg->dr_addr;\r
- } else {\r
- ip = i_ip_addr;\r
- }\r
//ARPテーブルから検索\r
for (i = NyLPC_TcIPv4Arp_ARPTAB_SIZE - 1; i >= 0; i--) {\r
tabptr = &i_inst->arp_table[i];\r
- if (NyLPC_TIPv4Addr_isEqual(&ip,&(tabptr->ipaddr))) {\r
+ if (NyLPC_TIPv4Addr_isEqual(&i_ip_addr,&(tabptr->ipaddr))) {\r
return &tabptr->ethaddr;\r
}\r
}\r
i_inst->default_mss=i_ether_frame_len-(UIP_ETHERHEADER_LEN+UIP_TCPH_LEN + UIP_IPH_LEN);\r
return;\r
}\r
-\r
+void NyLPC_cIPv4Config_initialzeCopy(NyLPC_TcIPv4Config_t* i_inst,const NyLPC_TcIPv4Config_t* i_src)\r
+{\r
+ memcpy(i_inst,i_src,sizeof(NyLPC_TcIPv4Config_t));\r
+}\r
/**\r
* See header file.\r
*/\r
*/\r
void NyLPC_cIPv4Config_initialzeForEthernet(NyLPC_TcIPv4Config_t* i_inst,const struct NyLPC_TEthAddr* i_ether_addr,NyLPC_TUInt16 i_ether_frame_len);\r
\r
+/**\r
+ * コピーコンストラクタ\r
+ */\r
+void NyLPC_cIPv4Config_initialzeCopy(NyLPC_TcIPv4Config_t* i_inst,const NyLPC_TcIPv4Config_t* i_src);\r
+\r
\r
/**\r
* デストラクタです。インスタンスを破棄して、確保している動的リソースを元に戻します。\r
NyLPC_cIPv4Payload_setUdpTxHeaderByConnection(&ipp,&(i_inst->uip_udp_conn),i_addr,i_port);\r
NyLPC_cIPv4Payload_closeUdpTxPacket(&ipp);\r
unlockResource(i_inst);\r
- // @bug 初めての相手に対して1回目の送信は必ず失敗する。どうする?\r
+ // @bug 初めての相手に対してなら1度ARPを送っておく\r
+ if(!NyLPC_cUipService_hasArpInfo(i_addr)){\r
+ NyLPC_cUipService_sendArpRequest(i_addr);\r
+ NyLPC_cThread_sleep(30);\r
+ }\r
NyLPC_cUipService_sendIPv4Tx(buf);\r
NyLPC_cUipService_releaseTxBuf(buf);\r
NyLPC_cIPv4Payload_finalize(&ipp);\r
#define PERIODIC_TIMER (1*200)\r
#define ARP_TIMER (60*1000*10)\r
\r
+\r
+\r
/**\r
* 操作キューを確認して、タスクのステータスをアップデートします。\r
* 高速化のため、Proc-Callerを使用していません。複雑なタスク操作をするときには、書き換えてください。
NyLPC_cMutex_unlock(&(inst->_mutex));\r
return;\r
}\r
+/**\r
+ * 指定したIPアドレスに対してARPRequestを送信します。\r
+ */\r
+void NyLPC_cUipService_sendArpRequest(const struct NyLPC_TIPv4Addr* i_addr)\r
+{\r
+ void* buf;\r
+ struct TEthPacket* ethbuf;\r
+ NyLPC_TUInt16 s;\r
+ NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;\r
+ NyLPC_TUInt16 tx_len;\r
+ do{\r
+ buf=NyLPC_cUipService_allocTxBuf(64,&s);\r
+ NyLPC_cThread_sleep(10);\r
+ }while(buf==NULL);\r
+ //IPパケットのアドレスをイーサネットパケットアドレスまで後退させる。\r
+ ethbuf=(struct TEthPacket*)(((struct NyLPC_TEthernetIIHeader*)buf)-1);\r
+ //ARPパケットを作る。\r
+ NyLPC_TArpHeader_setArpRequest(&(ethbuf->data.arp),inst->_ref_config->ip_addr,&(inst->_ref_config->eth_mac),*i_addr);\r
+ tx_len=NyLPC_TEthernetIIHeader_setArpTx(&(ethbuf->header),&(inst->_ref_config->eth_mac));\r
+ //送信\r
+ NyLPC_cMutex_lock(&(inst->_mutex));\r
+ inst->_ethif->sendTxEthFrame(((struct NyLPC_TTxBufferHeader*)ethbuf)-1,tx_len);\r
+ NyLPC_cMutex_unlock(&(inst->_mutex));\r
+ return;\r
+}\r
\r
-\r
+/**\r
+ * ARPテーブルに指定したIPがあるかを返します。\r
+ */\r
+NyLPC_TBool NyLPC_cUipService_hasArpInfo(const struct NyLPC_TIPv4Addr* i_addr)\r
+{\r
+ NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;\r
+ return NyLPC_cIPv4Arp_IPv4toEthAddr(&inst->_arp,*i_addr)!=NULL;\r
+}\r
\r
\r
/**\r
* @param i_hint\r
* 取得したいメモリサイズを指定します。(このサイズは、イーサネットヘッダのサイズを含みません。)\r
* このサイズよりも小さなサイズが割り当てられることがあります。\r
+ * @param o_size\r
+ * イーサネットヘッダを除いたペイロード部分の長さ\r
* @return\r
- * 成功:IPペイロードのためのメモリブロックを返します。/失敗:NULL
+ * 成功:IPペイロードのためのメモリブロックを返します。/失敗:NULL\r
+ * 返されるメモリはブロックの[TEthPacket][payload]の構造で、[payload]のアドレスが返されます。
*/\r
void* NyLPC_cUipService_allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size)\r
{\r
- //排他処理をして、メモリを取得する。\r
NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;\r
struct NyLPC_TTxBufferHeader* ethbuf;\r
+ //排他処理をして、メモリを取得する。\r
NyLPC_cMutex_lock(&(inst->_mutex));\r
ethbuf=(struct NyLPC_TTxBufferHeader*)inst->_ethif->allocTxBuf(i_hint+sizeof(struct NyLPC_TEthernetIIHeader),o_size);\r
NyLPC_cMutex_unlock(&(inst->_mutex));\r
ip2MulticastEmacAddr(&(ethbuf->data.ipv4.destipaddr),&emac);\r
eth_dest=&emac;\r
}else{\r
- eth_dest=NyLPC_cIPv4Arp_IPv4toEthAddr(&inst->_arp,ethbuf->data.ipv4.destipaddr);\r
+ //LocalIP以外ならdefaultRootへ変換\r
+ eth_dest=NyLPC_cIPv4Arp_IPv4toEthAddr(\r
+ &inst->_arp,\r
+ NyLPC_cIPv4Config_isLocalIP(inst->_ref_config, &(ethbuf->data.ipv4.destipaddr))?(ethbuf->data.ipv4.destipaddr):(inst->_ref_config->dr_addr));\r
//IP->MAC変換をテスト。\r
if(eth_dest==NULL){\r
return NyLPC_TBool_FALSE;\r
/**\r
* 送信ペイロードメモリを返します。\r
* この関数は、リエントラントを許容します。\r
- * 取得したメモリは、releaseTxBufで必ず開放してください。\r
* @param i_hint\r
* 取得したいメモリサイズを指定します。(このサイズは、イーサネットヘッダのサイズを含みません。)\r
* このサイズよりも小さなサイズが割り当てられることがあります。\r
+ * @param o_size\r
+ * 取得メモリのイーサネットヘッダを除いたペイロード部分の長さ\r
+ * @return\r
+ * 成功:IPペイロードのためのメモリブロックを返します。/失敗:NULL\r
+ * メモリは、[TEthPacket][payload]の構造で返されます。\r
*/\r
void* NyLPC_cUipService_allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size);\r
\r
*/\r
void* NyLPC_cUipService_releaseTxBuf(void* i_buf);\r
\r
+/**\r
+ * 指定したIPアドレスを要求するARPリクエストを発行します。\r
+ */\r
+void NyLPC_cUipService_sendArpRequest(const struct NyLPC_TIPv4Addr* i_addr);\r
+\r
+/**\r
+ * ARPテーブルに指定したIPがあるかを返します。\r
+ */\r
+NyLPC_TBool NyLPC_cUipService_hasArpInfo(const struct NyLPC_TIPv4Addr* i_addr);\r
+\r
+\r
void NyLPC_cTcpSocket_periodic(\r
NyLPC_TcTcpSocket_t* i_inst);\r
\r
+\r
+\r
+\r
#ifdef __cplusplus\r
}\r
#endif /* __cplusplus */\r
const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_BROADCAST = { 0xffffffff };\r
const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_MULTICAST = NyLPC_TIPv4Addr_pack(224,0,0,0);\r
const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_MULTICAST_MASK = NyLPC_TIPv4Addr_pack(224,0,0,0);\r
-\r
+const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_APIPA_MASK = NyLPC_TIPv4Addr_pack(255,255,0,0);\r
\r
\r
NyLPC_TUInt16 NyLPC_uip_chksum(NyLPC_TUInt16 sum, const NyLPC_TUInt8 *data, NyLPC_TUInt16 len)\r
extern const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_BROADCAST;\r
extern const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_MULTICAST;\r
extern const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_MULTICAST_MASK;\r
+extern const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_APIPA_MASK;\r
\r
/**\r
* addr1とaddr2が全く同じであるかをテストします。\r
NyLPC_TIpv4Addr_set(&ip,1,2,3,4);\r
\endcode\r
*/\r
-#define NyLPC_TIPv4Addr_set(s,a0,a1,a2,a3) (s)->v=NyLPC_htonl((0xff000000&(a0<<24))|(0x00ff0000&(a1<<16))|(0x0000ff00&(a2<<8))|(0x000000ff&(a3)))\r
-#define NyLPC_TIPv4Addr_pack(a0,a1,a2,a3) {NyLPC_HTONL((0xff000000&(a0<<24))|(0x00ff0000&(a1<<16))|(0x0000ff00&(a2<<8))|(0x000000ff&(a3)))}\r
+#define NyLPC_TIPv4Addr_set(s,a0,a1,a2,a3) (s)->v=NyLPC_htonl((0xff000000&((a0)<<24))|(0x00ff0000&((a1)<<16))|(0x0000ff00&((a2)<<8))|(0x000000ff&(a3)))\r
+#define NyLPC_TIPv4Addr_pack(a0,a1,a2,a3) {NyLPC_HTONL((0xff000000&((a0)<<24))|(0x00ff0000&((a1)<<16))|(0x0000ff00&((a2)<<8))|(0x000000ff&(a3)))}\r
\r
\r
\r