This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

libMiMic(MiMic library for mbed)は、WebService機能を提供するSDKです。 mbedでWebAPIに対応したネットワークデバイスを簡単に作ることが出来ます。

libMiMicはMiMic projectで開発しています。MiMic projectについてはこちらをご覧ください。 http://nyatla.jp/mimic/wp/

構成

libMiMicはmbedRTOS上で動作し、ユーザアプリケーションにAPIを提供します。コアAPIはC言語で記述されていますが、使用頻度の高いものについてはmbed向けのC++APIが準備されています。

/media/uploads/nyatla/libmimic-sdk.png

※libMiMicはmbedの標準イーサネットドライバをしようしていません。

標準イーサネットドライバと同時に使用することはできません。

  • MiMicIP - IPv4スタックです。レテンシとメモリ消費量を抑えたuipベースのライブラリです。
  • ARP/ICMP/UDP/TCP - 基礎的なソケットAPIを提供します。APIは独自です。
  • HTTP/1.1 Server - HTTP/1.1に対応したサーバです。マルチセッション・Chunked・持続性接続に対応しています。
  • HTTP Modules - HTTP/1.1の機能モジュールです。以下のモジュールがあります。
    • ROM file provider - ROMに格納したファイルイメージを公開します。
    • File system provider - mbedファイルシステムを公開します。
    • Onchip configuration - プログラムフラッシュを利用して設定を保存します。
    • MiMicVM processor - RPCリクエスト(MiMicVM)を処理します。
    • FileUpload - ファイルアップロードを受け取ります。
    • URL decoder - HTTPリクエストを解析します。
    • UPnP handler -UPnPメッセージを処理します。
    • WebSocket - Websocketサーバです。
  • mDNS - マルチキャストDNSサービスです。
  • UPnP - UPnP/1.0の機能を提供します。UPnP handlerと協調して動作します。(現在はデバイス探索(SSDP)・デスクリプション(Description)のみ実装してあります。)
  • DHCP/APIPA - ゼロコンフィギュレーション用のモジュールです。
  • HTTP/1.1 Client
  • mbed C++ class library - mbed向けのC++CPIです。C言語のものより簡単です。

対応機種

  • mbed(mbed LPC1768)
  • LPCXpresso1769

プログラム

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

サンプル

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

チュートリアル

English

libMiMic(MiMic library for mbed) is SDK which provides Webservice functions. It can be created networking device easily using mbed.

See more MiMic information, See MiMic project website. http://nyatla.jp/mimic/wp/

Structure

libMiMic run on mbed RTOS and provides networking API to user application. This library has C++ class API for the mbed, and low-level C language API.

/media/uploads/nyatla/libmimic-sdk.png

For WebService general, it can be written in a simple C + + API.

libMiMic does not have the standard Ethernet driver of mbed. It is not possible that will be used with the standard Ethernet driver.

  • MiMicIP - IPv4 protocol stack. This is based uip which is reduced memory and latency.
  • ARP / ICMP / UDP / TCP - Those are provide basic IP protocols.
  • HTTP/1.1 Server - The Http server compatible HTTP/1.1. It supports multi-session, chunked transport, persistent connection.
  • HTTP Modules - There are addon-module for HTTP server. The following modules.
    • ROM file module - Publish the file images in ROM.
    • File system module - Publish thefiles in mbed file system.
    • Onchip configuration module - To save the network settings to the program flash via REST.
    • MiMicVM module - To handle the (MiMicVM) RPC request.
    • FileUpload module - Accept a file via HTTP POST.
    • URL dedoce module - A versatility URL decoder.
    • UPnP handle module - To handle UPnP messages.
    • UPnP - This provides UPnP/1.0 device functions. It works together with UPnP handler.
    • Websocket - websocket (version13) server
  • mDNS Service - DNS-SD protocol server.
  • UPnP - This provides UPnP/1.0 device functions which works with UPnP handler. (You have been implemented (SSDP) ? description only (Description) device search now.) It is a module zero configuration for - DHCP / APIPA. mbed C + + class library - C of mbed for + + is the CPI. It is simple than that of the C language.
  • DHCP/APIPA - It support zero-cpnfigulation.
  • mbed C++ class library. Almost APIs for Web applications are available.
  • HTTP/1.1 Client

Supported target

  • mbed(mbed LPC1768)
  • LPCXpresso1769

Application

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

Sample

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

Tutorial

Files at this revision

API Documentation at this revision

Comitter:
nyatla
Date:
Fri Oct 18 12:40:09 2013 +0000
Parent:
62:8be8c5924c3e
Child:
64:258e84040262
Commit message:
update core to t338; bugfix; 1.Ethernet driver setting, descripter setting; 2.TCP socket close sequence; 3.HTTP stream

Changed in this revision

core/NyLPC_cMiMicEnv.h Show annotated file Show diff for this revision Revisions of this file
core/driver/uip/EthDev.h Show annotated file Show diff for this revision Revisions of this file
core/driver/uip/EthDev_LPC17xx.c Show annotated file Show diff for this revision Revisions of this file
core/driver/uip/EtherDev_DP83848C.c Show annotated file Show diff for this revision Revisions of this file
core/driver/uip/EtherDev_LAN8720.c Show annotated file Show diff for this revision Revisions of this file
core/http/NyLPC_cHttpStream.c Show annotated file Show diff for this revision Revisions of this file
core/http/NyLPC_iHttpPtrStream.h Show annotated file Show diff for this revision Revisions of this file
core/uip/NyLPC_cTcpSocket.c Show annotated file Show diff for this revision Revisions of this file
core/uip/NyLPC_uip.h Show annotated file Show diff for this revision Revisions of this file
--- a/core/NyLPC_cMiMicEnv.h	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/NyLPC_cMiMicEnv.h	Fri Oct 18 12:40:09 2013 +0000
@@ -13,7 +13,7 @@
 #endif /* __cplusplus */
 
 
-#define NyLPC_cMiMicEnv_VERSION "MiMic/1.4.71"
+#define NyLPC_cMiMicEnv_VERSION "MiMic/1.4.73"
 
 
 #ifdef __cplusplus
--- a/core/driver/uip/EthDev.h	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/driver/uip/EthDev.h	Fri Oct 18 12:40:09 2013 +0000
@@ -42,8 +42,6 @@
   Ethernet Device Defines
  *----------------------------------------------------------------------------*/
 #define EthDev_ADDR_SIZE        6                      /*!< Ethernet Address size in bytes */
-#define EthDev_MTU_SIZE         1514                   /*!< Maximum Transmission Unit      */
-
 
 /*----------------------------------------------------------------------------
   Ethernet Device Configuration and Control Command Defines
--- a/core/driver/uip/EthDev_LPC17xx.c	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/driver/uip/EthDev_LPC17xx.c	Fri Oct 18 12:40:09 2013 +0000
@@ -20,36 +20,46 @@
  * TXバッファ
  ***********************************************************************/
 
-//TXバッファの先頭アドレス
+/**
+ * TXバッファの先頭アドレス
+ * Ethernetベースアドレス+RXメモリ領域
+ */
 #define ETH_TX_BUF_BASE (ETH_BUF_BASE+ETH_FRAG_SIZE*NUM_RX_FRAG)
 
-#define NUM_OF_1536_BUF 3
+#define NUM_OF_MAX_BUF  3
 #define NUM_OF_512_BUF  3
 #define NUM_OF_256_BUF  4
 #define NUM_OF_128_BUF 16
 
 /**
+ * FULLサイズのEthernetFrame送信メモリのサイズ。
+ * ここで最大送信サイズを制限する。
+ * 通常は1460+20+20+14=1514バイト
+ */
+#define MAX_TX_ETHERNET_FRAME_SIZE  1514
+
+/**
  * TXメモリブロックの配置
- * 12360バイト
+ * 9246バイト
  */
 struct TTxMemoryBlock
 {
     struct{
         struct NyLPC_TTxBufferHeader h;
-        NyLPC_TUInt8 b[1536];
-    }buf1536[NUM_OF_1536_BUF];//(4+1536)*3=4620
+        NyLPC_TUInt8 b[MAX_TX_ETHERNET_FRAME_SIZE];
+    }buf_max[NUM_OF_MAX_BUF];//(4+MAX_TX_ETHERNET_FRAME_SIZE(1514))*3=? default=4554
     struct{
         struct NyLPC_TTxBufferHeader h;
         NyLPC_TUInt8 b[512];
-    }buf512[NUM_OF_512_BUF];//(4+512)*3=1548
+    }buf_512[NUM_OF_512_BUF];//(4+512)*3=1548
     struct{
         struct NyLPC_TTxBufferHeader h;
         NyLPC_TUInt8 b[256];
-    }buf256[NUM_OF_256_BUF];//(4+256)*4=1560
+    }buf_256[NUM_OF_256_BUF];//(4+256)*4=1560
     struct{
         struct NyLPC_TTxBufferHeader h;
         NyLPC_TUInt8 b[128];
-    }buf128[NUM_OF_128_BUF];//(4+128)*16=1584
+    }buf_128[NUM_OF_128_BUF];//(4+128)*16=1584
 };
 
 //メモリブロックの定義
@@ -63,26 +73,26 @@
     int x;
     NyLPC_TUInt8 r1,r2,r3,r4;
     r1=r2=r3=r4=0;
-    for(x=0;x<NUM_OF_1536_BUF;x++){
-        if(_txbuf->buf1536[x].h.is_lock || _txbuf->buf1536[x].h.ref>0){
+    for(x=0;x<NUM_OF_MAX_BUF;x++){
+        if(_txbuf->buf_max[x].h.is_lock || _txbuf->buf_max[x].h.ref>0){
             r1++;
             continue;
         }
     }
     for(x=0;x<NUM_OF_512_BUF;x++){
-        if(_txbuf->buf512[x].h.is_lock || _txbuf->buf512[x].h.ref>0){
+        if(_txbuf->buf_512[x].h.is_lock || _txbuf->buf_512[x].h.ref>0){
             r2++;
             continue;
         }
     }
     for(x=0;x<NUM_OF_256_BUF;x++){
-        if(_txbuf->buf256[x].h.is_lock || _txbuf->buf256[x].h.ref>0){
+        if(_txbuf->buf_256[x].h.is_lock || _txbuf->buf_256[x].h.ref>0){
             r3++;
             continue;
         }
     }
     for(x=0;x<NUM_OF_128_BUF;x++){
-        if(_txbuf->buf128[x].h.is_lock || _txbuf->buf128[x].h.ref>0){
+        if(_txbuf->buf_128[x].h.is_lock || _txbuf->buf_128[x].h.ref>0){
             r4++;
             continue;
         }
@@ -104,21 +114,21 @@
         TX_STAT_INFO( x ) = 0;
     }
     //TXバッファを初期化
-    for(x=0;x<NUM_OF_1536_BUF;x++){
-        _txbuf->buf1536[x].h.is_lock=NyLPC_TUInt8_FALSE;
-        _txbuf->buf1536[x].h.ref=0;
+    for(x=0;x<NUM_OF_MAX_BUF;x++){
+        _txbuf->buf_max[x].h.is_lock=NyLPC_TUInt8_FALSE;
+        _txbuf->buf_max[x].h.ref=0;
     }
     for(x=0;x<NUM_OF_512_BUF;x++){
-        _txbuf->buf512[x].h.is_lock=NyLPC_TUInt8_FALSE;
-        _txbuf->buf512[x].h.ref=0;
+        _txbuf->buf_512[x].h.is_lock=NyLPC_TUInt8_FALSE;
+        _txbuf->buf_512[x].h.ref=0;
     }
     for(x=0;x<NUM_OF_256_BUF;x++){
-        _txbuf->buf256[x].h.is_lock=NyLPC_TUInt8_FALSE;
-        _txbuf->buf256[x].h.ref=0;
+        _txbuf->buf_256[x].h.is_lock=NyLPC_TUInt8_FALSE;
+        _txbuf->buf_256[x].h.ref=0;
     }
     for(x=0;x<NUM_OF_128_BUF;x++){
-        _txbuf->buf128[x].h.is_lock=NyLPC_TUInt8_FALSE;
-        _txbuf->buf128[x].h.ref=0;
+        _txbuf->buf_128[x].h.is_lock=NyLPC_TUInt8_FALSE;
+        _txbuf->buf_128[x].h.ref=0;
     }
     /* Set LPC_EMAC Transmit Descriptor Registers. */
     LPC_EMAC->TxDescriptor = TX_DESC_BASE;
@@ -147,44 +157,44 @@
     }
     switch(buf_type){
     case 3:
-        for(i=0;i<NUM_OF_1536_BUF;i++){
+        for(i=0;i<NUM_OF_MAX_BUF;i++){
             //未参照かつ送信中でないもの。
-            if(_txbuf->buf1536[i].h.ref>0 || _txbuf->buf1536[i].h.is_lock){
+            if(_txbuf->buf_max[i].h.ref>0 || _txbuf->buf_max[i].h.is_lock){
                 continue;
             }
-            _txbuf->buf1536[i].h.ref++;
-            *o_size=1536;
-            return &(_txbuf->buf1536[i].h);
+            _txbuf->buf_max[i].h.ref++;
+            *o_size=MAX_TX_ETHERNET_FRAME_SIZE;
+            return &(_txbuf->buf_max[i].h);
         }
     case 2:
         for(i=0;i<NUM_OF_512_BUF;i++){
             //未参照かつ送信中でないもの。
-            if(_txbuf->buf512[i].h.ref>0 || _txbuf->buf512[i].h.is_lock){
+            if(_txbuf->buf_512[i].h.ref>0 || _txbuf->buf_512[i].h.is_lock){
                 continue;
             }
             *o_size=512;
-            _txbuf->buf512[i].h.ref++;
-            return &(_txbuf->buf512[i].h);
+            _txbuf->buf_512[i].h.ref++;
+            return &(_txbuf->buf_512[i].h);
         }
     case 1:
         for(i=0;i<NUM_OF_256_BUF;i++){
             //未参照かつ送信中でないもの。
-            if(_txbuf->buf256[i].h.ref>0 || (_txbuf->buf256[i].h.is_lock)){
+            if(_txbuf->buf_256[i].h.ref>0 || (_txbuf->buf_256[i].h.is_lock)){
                 continue;
             }
             *o_size=256;
-            _txbuf->buf256[i].h.ref++;
-            return &(_txbuf->buf256[i].h);
+            _txbuf->buf_256[i].h.ref++;
+            return &(_txbuf->buf_256[i].h);
         }
     default:
         for(i=0;i<NUM_OF_128_BUF;i++){
             //未参照かつ送信中でないもの。
-            if(_txbuf->buf128[i].h.ref>0 || (_txbuf->buf128[i].h.is_lock)){
+            if(_txbuf->buf_128[i].h.ref>0 || (_txbuf->buf_128[i].h.is_lock)){
                 continue;
             }
             *o_size=128;
-            _txbuf->buf128[i].h.ref++;
-            return &(_txbuf->buf128[i].h);
+            _txbuf->buf_128[i].h.ref++;
+            return &(_txbuf->buf_128[i].h);
         }
     }
     return NULL;
@@ -279,9 +289,11 @@
     if (i_size > ETH_FRAG_SIZE){
         i_size = ETH_FRAG_SIZE;
     }
+
     //送信処理
     TX_DESC_PACKET( Index ) = ( unsigned long )(i_buf+1);
-    TX_DESC_CTRL( Index ) = ( i_size | TCTRL_LAST | TCTRL_INT );
+    //See UM10360.pdf Table 181. Transmit descriptor control word
+    TX_DESC_CTRL( Index ) = ((i_size-1) | TCTRL_LAST | TCTRL_INT );
     LPC_EMAC->TxProduceIndex = IndexNext;
     return;
 }
--- a/core/driver/uip/EtherDev_DP83848C.c	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/driver/uip/EtherDev_DP83848C.c	Fri Oct 18 12:40:09 2013 +0000
@@ -107,7 +107,7 @@
 #define emacWAIT_FOR_LINK_TO_ESTABLISH_MS 500
 
 /* Short delay used in several places during the initialisation process. */
-#define emacSHORT_DELAY_MS                 2
+#define emacSHORT_DELAY_MS                 10
 
 /* Hardware specific bit definitions. */
 #define emacPINSEL2_VALUE           ( 0x50150105 )
@@ -200,8 +200,6 @@
     EthDev_LPC17xx_prevRxDescriptor();
     EthDev_LPC17xx_prevTxDescriptor();
 
-    /* Receive broadcast and perfect match packets */
-    LPC_EMAC->RxFilterCtrl = RFC_UCAST_EN | RFC_BCAST_EN | RFC_PERFECT_EN;
 
     /* Setup the PHY. */
     prvConfigurePHY();
@@ -213,19 +211,19 @@
     }
 
     /* Receive Broadcast and Perfect Match Packets */
-    LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN;
-
-    /* Reset all interrupts */
-    LPC_EMAC->IntClear = 0xffff;
-
-    /* Enable receive and transmit mode of MAC Ethernet core */
-    LPC_EMAC->Command |= ( CR_RX_EN | CR_TX_EN );
-    LPC_EMAC->MAC1 |= MAC1_REC_EN;
+    LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN | RFC_MCAST_EN;
 
     //Ethernetの割込み開始設定
     NyLPC_cIsr_enterCritical();
     {
+        /* Reset all interrupts */
+        LPC_EMAC->IntClear = 0xffff;
         LPC_EMAC->IntEnable = ( INT_RX_DONE | INT_TX_DONE );
+
+        /* Enable receive and transmit mode of MAC Ethernet core */
+        LPC_EMAC->Command |= ( CR_RX_EN | CR_TX_EN );
+        LPC_EMAC->MAC1 |= MAC1_REC_EN;
+
         /* Set the interrupt priority to the max permissible to cause some
         interrupt nesting. */
         NVIC_SetPriority( ENET_IRQn, configEMAC_INTERRUPT_PRIORITY );
--- a/core/driver/uip/EtherDev_LAN8720.c	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/driver/uip/EtherDev_LAN8720.c	Fri Oct 18 12:40:09 2013 +0000
@@ -97,7 +97,7 @@
 #define emacWAIT_FOR_LINK_TO_ESTABLISH_MS 500
 
 /* Short delay used in several places during the initialisation process. */
-#define emacSHORT_DELAY_MS 2
+#define emacSHORT_DELAY_MS 10
 
 /* Hardware specific bit definitions. */
 #define emacPINSEL2_VALUE           ( 0x50150105 )
@@ -194,8 +194,6 @@
     EthDev_LPC17xx_prevRxDescriptor();
     EthDev_LPC17xx_prevTxDescriptor();
 
-    /* Receive broadcast and perfect match packets */
-    LPC_EMAC->RxFilterCtrl = RFC_UCAST_EN | RFC_BCAST_EN | RFC_PERFECT_EN;
 
     /* Setup the PHY. */
     prvConfigurePHY();
@@ -207,19 +205,18 @@
     }
 
     /* Receive Broadcast and Perfect Match Packets */
-    LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN;
-
-    /* Reset all interrupts */
-    LPC_EMAC->IntClear = 0xffff;
-
-    /* Enable receive and transmit mode of MAC Ethernet core */
-    LPC_EMAC->Command |= ( CR_RX_EN | CR_TX_EN );
-    LPC_EMAC->MAC1 |= MAC1_REC_EN;
+    LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN | RFC_MCAST_EN;
 
     //Ethernetの割込み開始設定
     NyLPC_cIsr_enterCritical();
     {
+        /* Reset all interrupts */
+        LPC_EMAC->IntClear = 0xffff;
         LPC_EMAC->IntEnable = ( INT_RX_DONE | INT_TX_DONE );
+        /* Enable receive and transmit mode of MAC Ethernet core */
+        LPC_EMAC->Command |= ( CR_RX_EN | CR_TX_EN );
+        LPC_EMAC->MAC1 |= MAC1_REC_EN;
+
         /* Set the interrupt priority to the max permissible to cause some
         interrupt nesting. */
         NVIC_SetPriority( ENET_IRQn, configEMAC_INTERRUPT_PRIORITY );
--- a/core/http/NyLPC_cHttpStream.c	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/http/NyLPC_cHttpStream.c	Fri Oct 18 12:40:09 2013 +0000
@@ -168,7 +168,10 @@
         memcpy(inst->txb+inst->tx_len,src,free_size);
         inst->tx_len+=free_size;
         //書き込み
-        flush_func(i_inst);
+        if(!flush_func(i_inst)){
+            //書込みエラー・・・
+            return NyLPC_TBool_FALSE;
+        }
         //読み出し位置の調整
         l-=free_size;
         src+=free_size;
--- a/core/http/NyLPC_iHttpPtrStream.h	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/http/NyLPC_iHttpPtrStream.h	Fri Oct 18 12:40:09 2013 +0000
@@ -52,7 +52,7 @@
 /**
  * HTTP通信タイムアウトのデフォルト値
  */
-#define NyLPC_TiHttpPtrStream_DEFAULT_HTTP_TIMEOUT (5*1000)
+#define NyLPC_TiHttpPtrStream_DEFAULT_HTTP_TIMEOUT (8*1000)
 
 
 typedef NyLPC_TInt32 (*NyLPC_TiHttpPtrStream_pread)(void* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_timeout);
--- a/core/uip/NyLPC_cTcpSocket.c	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/uip/NyLPC_cTcpSocket.c	Fri Oct 18 12:40:09 2013 +0000
@@ -1238,8 +1238,6 @@
                 }
             }
         }
-//      //MSSとWNDの更新
-//      i_inst->uip_connr.peer_mss = i_inst->uip_connr.default_mss;//@bug じゃないのこれ。peer_mss勝手に上書きしたらダメだろ
         //どちらにしろ、ACK送信
         if(is_new_packet && (in_tcpflag & TCP_FIN)){
             //FINがあるときは、ステータスをCLOSE_WAITへセットして、ACKを返す。
@@ -1259,14 +1257,17 @@
         break;
     case UIP_FIN_WAIT_1:
         //FIN受信->CLOSINGへ
-        if(is_new_packet && (in_tcpflag & TCP_FIN)){
-            i_inst->uip_connr.rcv_nxt32++;
-            if(num_of_noack==0){
-                //FINとACKを受信
-                i_inst->tcpstateflags=UIP_TIME_WAIT;
-            }else{
-                //FINのみ
-                i_inst->tcpstateflags=UIP_CLOSING;
+        if(is_new_packet){
+            i_inst->uip_connr.rcv_nxt32+=data_size;
+            if(in_tcpflag & TCP_FIN){
+                i_inst->uip_connr.rcv_nxt32++;
+                if(num_of_noack==0){
+                    //FINとACKを受信
+                    i_inst->tcpstateflags=UIP_TIME_WAIT;
+                }else{
+                    //FINのみ
+                    i_inst->tcpstateflags=UIP_CLOSING;
+                }
             }
         }else if(num_of_noack==0){
             //ACKのみ
--- a/core/uip/NyLPC_uip.h	Thu Oct 03 04:53:11 2013 +0000
+++ b/core/uip/NyLPC_uip.h	Fri Oct 18 12:40:09 2013 +0000
@@ -155,21 +155,7 @@
  */
 #define UIP_MAXRTX      8
 
-/**
- * The maximum number of times a SYN segment should be retransmitted
- * before a connection request should be deemed to have been
- * unsuccessful.
- *
- * This should not need to be changed.
- */
-#define UIP_MAXSYNRTX      5
-/**
- * How long a connection should stay in the TIME_WAIT state.
- *
- * This configiration option has no real implication, and it should be
- * left untouched.
- */
-#define UIP_TIME_WAIT_TIMEOUT 120
+