Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c	(revision 374)
@@ -68,50 +68,213 @@
 #include "kernel_cfg.h"
 #include <string.h>
-
-#define IO_TYPE_FREE	0
-#define IO_TYPE_SIO		1
-#define IO_TYPE_FILE	2
-#define IO_TYPE_DIR		3
-#define IO_TYPE_TCP		4
-#define IO_TYPE_UDP	5
-
-static struct _IO_FILE fd_table[8 * sizeof(FLGPTN)] = {
-	{ 0, IO_TYPE_SIO, 0, stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl },
-	{ 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl },
-	{ 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl },
+#include "util/ntstdio.h"
+#include "hal/serial_api.h"
+
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
+static int stdio_close(struct SHELL_FILE *fp);
+static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static void stdio_delete(struct SHELL_FILE *fp);
+
+static int sio_close(struct SHELL_FILE *fp);
+static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t sio_readable(struct SHELL_FILE *fp);
+static void sio_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_STDIN = { stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
+IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
+IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
+IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_delete };
+ntstdio_t ntstdio;
+
+static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = {
+	{ 0, &IO_TYPE_STDIN, 0, .exinf = &ntstdio },
+	{ 1, &IO_TYPE_STDOUT, 0, .exinf = &ntstdio },
+	{ 2, &IO_TYPE_STDERR, 0,.exinf = &ntstdio },
 };
 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0]))
 
-static int new_fd(int type, int id)
-{
+extern ntstdio_t ntstdio;
+extern serial_t stdio_uart;
+
+unsigned char ntstdio_xi(struct ntstdio_t *handle)
+{
+	return serial_getc((serial_t *)handle->exinf);
+}
+
+void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
+{
+	serial_putc((serial_t *)handle->exinf, c);
+}
+
+void sys_init(intptr_t exinf)
+{
+	ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
+	ntstdio.exinf = (void *)&stdio_uart;
+}
+
+int stdio_close(struct SHELL_FILE *fp)
+{
+	return -EPERM;
+}
+
+size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	int i = 0;
+	while (i < len) {
+		int c = ntstdio_getc((struct ntstdio_t *)fp->exinf);
+		data[i++] = c;
+		if ((c == EOF) || (c == '\n'))
+			break;
+	}
+	return i;
+}
+
+size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	for (int i = 0; i < len; i++) {
+		ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
+	}
+	return len;
+}
+
+size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	for (int i = 0; i < len; i++) {
+		ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
+	}
+	return len;
+}
+
+void stdio_delete(struct SHELL_FILE *fp)
+{
+}
+
+int sio_close(struct SHELL_FILE *fp)
+{
+	return -EPERM;
+}
+
+size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org)
+{
+	return -EPERM;
+}
+
+int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg)
+{
+	switch (request) {
+	case TIOCGWINSZ:
+		return 0;
+	case TCGETS:
+		return sio_tcgetattr(fp->fd, (struct termios *)arg);
+	case TCSETS + TCSANOW:
+	case TCSETS + TCSADRAIN:
+	case TCSETS + TCSAFLUSH:
+		return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
+	}
+
+	return -EINVAL;
+}
+
+bool_t sio_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+void sio_delete(struct SHELL_FILE *fp)
+{
+	free((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf);
+	((struct ntstdio_t *)fp->exinf)->exinf = NULL;
+	free((struct ntstdio_t *)fp->exinf);
+	fp->exinf = NULL;
+}
+
+struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable)
+{
+	struct SHELL_FILE *fp = NULL;
+	ER ret;
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
 	for (int fd = 3; fd < fd_table_count; fd++) {
-		struct _IO_FILE *fp = &fd_table[fd];
-		if (fp->type != IO_TYPE_FREE)
+		fp = &fd_table[fd];
+		if (fp->type != NULL)
 			continue;
 
-		memset(fp, 0, sizeof(struct _IO_FILE));
+		memset(fp, 0, sizeof(struct SHELL_FILE));
 		fp->fd = fd;
 		fp->type = type;
 		fp->handle = id;
-		return fd;
-	}
-
-	return -ENOMEM;
-}
-
-static struct _IO_FILE *id_to_fd(int type, int id)
-{
+		fp->writable = writable;
+		break;
+	}
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
+
+	return fp;
+}
+
+struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id)
+{
+	struct SHELL_FILE *fp = NULL;
+	ER ret;
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
 	for (int fd = 3; fd < fd_table_count; fd++) {
-		struct _IO_FILE *fp = &fd_table[fd];
+		fp = &fd_table[fd];
 		if ((fp->type == type) && (fp->handle == id))
-			return fp;
-	}
-
-	return NULL;
-}
-
-static int delete_fd(int type, int id)
-{
-	struct _IO_FILE *fp = id_to_fd(type, id);
+			break;
+	}
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
+
+	return fp;
+}
+
+int delete_fd_by_id(IO_TYPE *type, int id)
+{
+	struct SHELL_FILE *fp = id_to_fd(type, id);
 	if (fp == NULL)
 		return -EBADF;
@@ -120,18 +283,26 @@
 }
 
-int delete_fp(struct _IO_FILE *fp)
-{
-	free(fp->pfile);
-	fp->pfile = NULL;
-	free(fp->pdir);
-	fp->pdir = NULL;
-	free(fp->psock);
-	fp->psock = NULL;
-	memset(fp, 0, sizeof(struct _IO_FILE));
+int delete_fp(struct SHELL_FILE *fp)
+{
+	ER ret;
+
+	fp->type->delete(fp);
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
+	memset(fp, 0, sizeof(struct SHELL_FILE));
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
 
 	return 0;
 }
 
-struct _IO_FILE *fd_to_fp(int fd)
+struct SHELL_FILE *fd_to_fp(int fd)
 {
 	if ((fd < 0) || (fd >= fd_table_count))
@@ -140,151 +311,5 @@
 }
 
-struct _IO_FILE *new_sio_fd(int sioid)
-{
-	int fd = new_fd(IO_TYPE_SIO, sioid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = sio_close;
-	fp->read = sio_read;
-	fp->write = sio_write;
-	fp->seek = sio_seek;
-	fp->ioctl = sio_ioctl;
-	fp->writable = 1;
-
-	return fp;
-}
-
-int delete_sio_fd(int sioid)
-{
-	return delete_fd(IO_TYPE_SIO, sioid);
-}
-
-struct _IO_FILE *sioid_to_fd(int sioid)
-{
-	return id_to_fd(IO_TYPE_SIO, sioid);
-}
-
-struct _IO_FILE *new_file_fd(int fileid)
-{
-	int fd = new_fd(IO_TYPE_FILE, fileid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = file_close;
-	fp->read = file_read;
-	fp->write = file_write;
-	fp->seek = file_seek;
-	fp->ioctl = file_ioctl;
-	fp->writable = 1;
-	fp->pfile = malloc(sizeof(FIL));
-	memset(fp->pfile, 0, sizeof(FIL));
-
-	return fp;
-}
-
-int delete_file_fd(int fileid)
-{
-	return delete_fd(IO_TYPE_FILE, fileid);
-}
-
-struct _IO_FILE *fileid_to_fd(int fileid)
-{
-	return id_to_fd(IO_TYPE_FILE, fileid);
-}
-
-struct _IO_FILE *new_dir_fd(int fileid)
-{
-	int fd = new_fd(IO_TYPE_DIR, fileid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = dir_close;
-	fp->read = dir_read;
-	fp->write = dir_write;
-	fp->seek = dir_seek;
-	fp->ioctl = dir_ioctl;
-	fp->writable = 0;
-	fp->pdir = malloc(sizeof(struct _IO_DIR));
-	memset(fp->pdir, 0, sizeof(struct _IO_DIR));
-
-	return fp;
-}
-
-int delete_dir_fd(int dirid)
-{
-	return delete_fd(IO_TYPE_DIR, dirid);
-}
-
-struct _IO_FILE *dirid_to_fd(int dirid)
-{
-	return id_to_fd(IO_TYPE_DIR, dirid);
-}
-
-#ifndef NTSHELL_NO_SOCKET
-struct _IO_FILE *new_tcp_fd(int tcpid)
-{
-	int fd = new_fd(IO_TYPE_TCP, tcpid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = tcp_fd_close;
-	fp->read = tcp_fd_read;
-	fp->write = tcp_fd_write;
-	fp->seek = tcp_fd_seek;
-	fp->ioctl = tcp_fd_ioctl;
-	fp->writable = 0;
-	fp->psock = malloc(sizeof(socket_t));
-	memset(fp->psock, 0, sizeof(socket_t));
-
-	return fp;
-}
-
-int delete_tcp_fd(int tcpid)
-{
-	return delete_fd(IO_TYPE_TCP, tcpid);
-}
-
-struct _IO_FILE *tcpid_to_fd(int tcpid)
-{
-	return id_to_fd(IO_TYPE_TCP, tcpid);
-}
-
-struct _IO_FILE *new_udp_fd(int udpid)
-{
-	int fd = new_fd(IO_TYPE_UDP, udpid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = udp_fd_close;
-	fp->read = udp_fd_read;
-	fp->write = udp_fd_write;
-	fp->seek = udp_fd_seek;
-	fp->ioctl = udp_fd_ioctl;
-	fp->writable = 1;
-	fp->psock = malloc(sizeof(socket_t));
-	memset(fp->psock, 0, sizeof(socket_t));
-
-	return fp;
-}
-
-int delete_udp_fd(int udpid)
-{
-	return delete_fd(IO_TYPE_UDP, udpid);
-}
-
-struct _IO_FILE *udpid_to_fd(int udpid)
-{
-	return id_to_fd(IO_TYPE_UDP, udpid);
-}
-
-#endif
-
-void memor(void *dst, void *src, size_t len)
+void memand(void *dst, void *src, size_t len)
 {
 	uint8_t *d = (uint8_t *)dst;
@@ -293,5 +318,5 @@
 
 	while (s < e) {
-		*d++ |= *s++;
+		*d++ &= *s++;
 	}
 }
@@ -336,20 +361,20 @@
 
 	ret = shell_get_evts(&evts, tmout);
-	if (rfds != NULL)
-		memset(rfds, 0, sizeof(fd_set));
-	if (wfds != NULL)
-		memset(wfds, 0, sizeof(fd_set));
-	if (efds != NULL)
-		memset(efds, 0, sizeof(fd_set));
 	if (ret == E_OK) {
 		if (rfds != NULL)
-			memor(rfds, &evts.readfds, sizeof(fd_set));
+			memand(rfds, &evts.readfds, sizeof(fd_set));
 		if (wfds != NULL)
-			memor(wfds, &evts.writefds, sizeof(fd_set));
+			memand(wfds, &evts.writefds, sizeof(fd_set));
 		if (efds != NULL)
-			memor(efds, &evts.errorfds, sizeof(fd_set));
+			memand(efds, &evts.errorfds, sizeof(fd_set));
 		return evts.count;
 	}
 	if (ret == E_TMOUT) {
+		if (rfds != NULL)
+			memset(rfds, 0, sizeof(fd_set));
+		if (wfds != NULL)
+			memset(wfds, 0, sizeof(fd_set));
+		if (efds != NULL)
+			memset(efds, 0, sizeof(fd_set));
 		return 0;
 	}
@@ -419,18 +444,13 @@
 {
 	int fd = STDIN_FILENO;
-	struct _IO_FILE *fp = &fd_table[fd];
-	T_SERIAL_RPOR rpor;
+	struct SHELL_FILE *fp = &fd_table[fd];
 	FLGPTN flgptn = 0;
 
-	ER ret = serial_ref_por(SIO_PORTID, &rpor);
-	if (ret != E_OK)
-		return;
-
-	if (rpor.reacnt != 0) {
+	if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
 		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
 
 		FD_SET(fd, (fd_set *)&flgptn);
 	}
-	if (rpor.wricnt != 0) {
+	if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
 		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
 
@@ -447,18 +467,13 @@
 {
 	int fd = STDIN_FILENO;
-	struct _IO_FILE *fp = &fd_table[fd];
-	T_SERIAL_RPOR rpor;
+	struct SHELL_FILE *fp = &fd_table[fd];
 	*flgptn = 0;
 
-	ER ret = serial_ref_por(SIO_PORTID, &rpor);
-	if (ret != E_OK)
-		return;
-
-	if (rpor.reacnt != 0) {
+	if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
 		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
 
 		FD_SET(fd, (fd_set *)flgptn);
 	}
-	if (rpor.wricnt != 0) {
+	if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
 		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
 
@@ -466,169 +481,4 @@
 	}
 }
-
-#ifndef NTSHELL_NO_SOCKET
-
-ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)
-{
-	struct _IO_FILE *fp = tcpid_to_fd(cepid);
-	FLGPTN flgptn = 0;
-	ER ret;
-	int len;
-
-	if (fp == NULL)
-		return E_PAR;
-
-	int fd = fp->fd;
-	FD_SET(fd, (fd_set *)&flgptn);
-
-	switch (fncd) {
-	case TFN_TCP_RCV_BUF:
-		len = *(int *)p_parblk;
-		if (len <= 0)
-			return E_OK;
-
-		ret = wai_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "wai_sem => %d", ret);
-		}
-		fp->psock->len += len;
-		ret = sig_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "sig_sem => %d", ret);
-		}
-
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_RCV_DAT:
-		len = *(int *)p_parblk;
-		if (len <= 0)
-			return E_OK;
-
-		ret = wai_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "wai_sem => %d", ret);
-		}
-		fp->psock->len += len;
-		ret = sig_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "sig_sem => %d", ret);
-		}
-
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_SND_DAT:
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_CAN_CEP:
-		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_DEL_REP:
-		delete_tcp_rep(cepid);
-		return E_OK;
-
-	case TFN_TCP_DEL_CEP:
-		delete_tcp_fd(cepid);
-		return E_OK;
-
-	default:
-		return E_OK;
-	}
-}
-
-ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)
-{
-	struct _IO_FILE *fp = udpid_to_fd(cepid);
-	FLGPTN flgptn = 0;
-	int len;
-
-	if (fp == NULL)
-		return E_PAR;
-
-	int fd = fp->fd;
-	FD_SET(fd, (fd_set *)&flgptn);
-
-	switch (fncd) {
-	case TEV_UDP_RCV_DAT:
-	{
-		T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
-		len = udppara->len;
-		if (len <= 0)
-			return E_OK;
-
-		ER ret = wai_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "wai_sem => %d", ret);
-		}
-		fp->psock->len = len;
-		if (fp->psock->input != NULL) {
-			ret = rel_net_buf(fp->psock->input);
-			if (ret < 0) {
-				syslog(LOG_ERROR, "rel_net_buf => %d", ret);
-			}
-		}
-		fp->psock->input = udppara->input;
-		fp->psock->buf = GET_UDP_SDU(udppara->input, udppara->off);
-		memset(&fp->psock->raddr4, 0, sizeof(fp->psock->raddr4));
-		fp->psock->raddr4.sin_family = AF_INET;
-		fp->psock->raddr4.sin_port = htons(udppara->rep4.portno);
-		fp->psock->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);
-		udppara->input->flags |= NB_FLG_NOREL_IFOUT;
-		ret = sig_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "sig_sem => %d", ret);
-		}
-
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-	}
-	case TFN_UDP_CRE_CEP:
-		return E_OK;
-
-	case TFN_UDP_RCV_DAT:
-		len = *(int *)p_parblk;
-		if (len <= 0)
-			return E_OK;
-
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_SND_DAT:
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_CAN_CEP:
-		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_DEL_CEP:
-		delete_udp_fd(cepid);
-		return E_OK;
-
-	default:
-		return E_OK;
-	}
-}
-
-#endif
 
 ER shell_get_evts(struct fd_events *evts, TMO tmout)
@@ -642,5 +492,5 @@
 		ER ret;
 		FLGPTN waitptn, flgptn, readfds = 0, writefds = 0;
-		struct _IO_FILE *fp = NULL;
+		struct SHELL_FILE *fp = NULL;
 
 		stdio_update_evts();
@@ -656,36 +506,8 @@
 #ifndef NTSHELL_NO_SOCKET
 			if (FD_ISSET(fd, &evts->readfds)) {
-				if ((fp->type == IO_TYPE_TCP) && (fp->psock->cepid != 0)) {
-					if (fp->psock->len == 0) {
-						ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_NBLK);
-						if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
-							syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
-							//return ret;
-						}
-						if (ret > 0) {
-							ret = wai_sem(SEM_FILEDESC);
-							if (ret < 0) {
-								syslog(LOG_ERROR, "wai_sem => %d", ret);
-							}
-							fp->psock->len += ret;
-							ret = sig_sem(SEM_FILEDESC);
-							if (ret < 0) {
-								syslog(LOG_ERROR, "sig_sem => %d", ret);
-							}
-						}
-					}
-					else ret = 1;
-					if (ret > 0) {
-						FD_SET(fd, (fd_set *)&readfds);
-						count++;
-						if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
-					}
-				}
-				else if ((fp->type == IO_TYPE_UDP) && (fp->psock->cepid != 0)) {
-					if (fp->psock->input != NULL) {
-						FD_SET(fd, (fd_set *)&readfds);
-						count++;
-						if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
-					}
+				if (fp->type->readable(fp)) {
+					FD_SET(fd, (fd_set *)&readfds);
+					count++;
+					if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
 				}
 				else {
@@ -786,5 +608,5 @@
 void clean_fd()
 {
-	struct _IO_FILE *fp = NULL;
+	struct SHELL_FILE *fp = NULL;
 	for (int fd = 3; fd < fd_table_count; fd++) {
 		fp = &fd_table[fd];
@@ -792,5 +614,5 @@
 			continue;
 
-		fp->close(fp);
+		fp->type->close(fp);
 
 		delete_fp(fp);
@@ -800,9 +622,9 @@
 int shell_ioctl(int fd, int request, void *arg)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
 
-	return fp->ioctl(fp, request, arg);
+	return fp->type->ioctl(fp, request, arg);
 }
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c	(revision 374)
@@ -1,7 +1,7 @@
 /*
  *  TOPPERS ECHONET Lite Communication Middleware
- * 
+ *
  *  Copyright (C) 2017 Cores Co., Ltd. Japan
- * 
+ *
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
  *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
@@ -26,5 +26,5 @@
  *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
  *      免責すること．
- * 
+ *
  *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
  *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
@@ -32,5 +32,5 @@
  *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
  *  の責任を負わない．
- * 
+ *
  *  @(#) $Id$
  */
@@ -43,4 +43,5 @@
 #include <sil.h>
 #include <string.h>
+#include "syssvc/serial.h"
 #include "syssvc/syslog.h"
 #include "socket_stub.h"
@@ -49,4 +50,5 @@
 #include "core/ntlibc.h"
 #include "kernel_cfg.h"
+#include "target_syssvc.h"
 
 int fresult2errno(FRESULT res)
@@ -77,15 +79,37 @@
 }
 
-int shell_open(const char * path, int flags, void *arg)
-{
-	FRESULT res;
-	struct _IO_FILE *fp;
+static int file_close(struct SHELL_FILE *fp);
+static size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t file_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t file_readable(struct SHELL_FILE *fp);
+static void file_delete(struct SHELL_FILE *fp);
+
+static int dir_close(struct SHELL_FILE *fp);
+static size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t dir_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t dir_readable(struct SHELL_FILE *fp);
+static void dir_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_delete };
+IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_delete };
+
+int shell_open(const char *path, int flags, void *arg)
+{
+	FRESULT res;
+	struct SHELL_FILE *fp;
 
 	if (flags & O_DIRECTORY) {
-		fp = new_dir_fd(0);
+		fp = new_fp(&IO_TYPE_DIR, 0, 0);
 		if (fp == NULL)
 			return -ENOMEM;
 
-		DIR *dir = &fp->pdir->dir;
+		fp->exinf = malloc(sizeof(struct SHELL_DIR));
+		memset(fp->exinf, 0, sizeof(struct SHELL_DIR));
+
+		FATFS_DIR *dir = &((struct SHELL_DIR *)fp->exinf)->dir;
 		FRESULT res;
 		if ((res = f_opendir(dir, path)) != FR_OK) {
@@ -95,7 +119,10 @@
 	}
 
-	fp = new_file_fd(0);
+	fp = new_fp(&IO_TYPE_FILE, 0, 1);
 	if (fp == NULL)
 		return -ENOMEM;
+
+	fp->exinf = malloc(sizeof(FIL));
+	memset(fp->exinf, 0, sizeof(FIL));
 
 	BYTE fmd = 0;
@@ -133,5 +160,5 @@
 	}
 
-	if ((res = f_open(fp->pfile, path, fmd)) == FR_OK) {
+	if ((res = f_open((FIL *)fp->exinf, path, fmd)) == FR_OK) {
 		fp->handle = fp->fd;
 		return fp->fd;
@@ -141,9 +168,9 @@
 }
 
-int file_close(struct _IO_FILE *fp)
-{
-	FRESULT res;
-
-	if ((res = f_close(fp->pfile)) == FR_OK) {
+int file_close(struct SHELL_FILE *fp)
+{
+	FRESULT res;
+
+	if ((res = f_close((FIL *)fp->exinf)) == FR_OK) {
 		return 0;
 	}
@@ -152,10 +179,10 @@
 }
 
-size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
+size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
 {
 	unsigned int ret = 0;
 	FRESULT res;
 
-	if ((res = f_read(fp->pfile, data, len, &ret)) != FR_OK)
+	if ((res = f_read((FIL *)fp->exinf, data, len, &ret)) != FR_OK)
 		return -EIO;
 
@@ -163,10 +190,10 @@
 }
 
-size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
+size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
 {
 	unsigned int ret = 0;
 	FRESULT res;
 
-	if ((res = f_write(fp->pfile, data, len, &ret)) != FR_OK)
+	if ((res = f_write((FIL *)fp->exinf, data, len, &ret)) != FR_OK)
 		return -EIO;
 
@@ -174,5 +201,5 @@
 }
 
-off_t file_seek(struct _IO_FILE *fp, off_t ptr, int dir)
+off_t file_seek(struct SHELL_FILE *fp, off_t ptr, int dir)
 {
 	switch (dir) {
@@ -191,15 +218,15 @@
 
 	FRESULT res;
-	if ((res = f_seek(fp->pfile, ptr, dir)) != FR_OK)
+	if ((res = f_seek((FIL *)fp->exinf, ptr, dir)) != FR_OK)
 		return -EIO;
 
-	return fp->pfile->fptr;
-}
-
-int file_ioctl(struct _IO_FILE *fp, int req, void *arg)
+	return ((FIL *)fp->exinf)->fptr;
+}
+
+int file_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	DRESULT res;
 
-	if ((res = disk_ioctl(fp->pfile->fs->drv, req, arg) != RES_OK))
+	if ((res = disk_ioctl(((FIL *)fp->exinf)->fs->drv, req, arg) != RES_OK))
 		return -EINVAL;
 
@@ -207,11 +234,22 @@
 }
 
+bool_t file_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+void file_delete(struct SHELL_FILE *fp)
+{
+	free((FIL *)fp->exinf);
+	fp->exinf = NULL;
+}
+
 int shell_close(int fd)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	int ret = fp->close(fp);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	int ret = fp->type->close(fp);
 
 	delete_fp(fp);
@@ -222,9 +260,9 @@
 ssize_t shell_read(int fd, void *data, size_t len)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	return fp->read(fp, (unsigned char *)data, len);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	return fp->type->read(fp, (unsigned char *)data, len);
 }
 
@@ -232,5 +270,5 @@
 {
 	int result = 0;
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -238,5 +276,5 @@
 	const struct iovec *end = &iov[iovcnt];
 	for (; iov < end; iov++) {
-		result += fp->read(fp, (unsigned char *)iov->iov_base, iov->iov_len);
+		result += fp->type->read(fp, (unsigned char *)iov->iov_base, iov->iov_len);
 	}
 
@@ -246,9 +284,9 @@
 ssize_t shell_write(int fd, const void *data, size_t len)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	return fp->write(fp, (unsigned char *)data, len);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	return fp->type->write(fp, (unsigned char *)data, len);
 }
 
@@ -256,5 +294,5 @@
 {
 	int result = 0;
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -262,5 +300,5 @@
 	const struct iovec *end = &iov[iovcnt];
 	for (; iov < end; iov++) {
-		result += fp->write(fp, (unsigned char *)iov->iov_base, iov->iov_len);
+		result += fp->type->write(fp, (unsigned char *)iov->iov_base, iov->iov_len);
 	}
 
@@ -270,9 +308,9 @@
 int shell_llseek(int fd, off_t ptr, off_t *result, int dir)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	off_t ret = fp->seek(fp, ptr, dir);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	off_t ret = fp->type->seek(fp, ptr, dir);
 	if (ret < 0)
 		return ret;
@@ -284,5 +322,5 @@
 int shell_fstat(int fd, struct stat * st)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -296,5 +334,5 @@
 int shell_fsync(int fd)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -304,10 +342,10 @@
 int shell_ftruncate(int fd, off_t length)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	FRESULT res;
-	if ((res = f_truncate(fp->pfile)) != FR_OK)
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	FRESULT res;
+	if ((res = f_truncate((FIL *)fp->exinf)) != FR_OK)
 		return fresult2errno(res);
 
@@ -320,72 +358,80 @@
 }
 
+extern IO_TYPE IO_TYPE_SIO;
+
 int sio_tcgetattr(int fd, struct termios *termios)
 {
-	extern ntstdio_t ntstdio;
-
-	if (fd == STDIN_FILENO) {
-		memset(termios, 0, sizeof(*termios));
-
-		if (ntstdio.option & NTSTDIO_OPTION_LINE_ECHO) {
-			termios->c_lflag |= ECHO;
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
+		return -EBADF;
+
+	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
+
+	memset(termios, 0, sizeof(*termios));
+
+	if (ntstdio->option & NTSTDIO_OPTION_LINE_ECHO) {
+		termios->c_lflag |= ECHO;
+	}
+	else {
+		termios->c_lflag &= ~ECHO;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_CANON) {
+		termios->c_lflag |= ICANON;
+	}
+	else {
+		termios->c_lflag &= ~ICANON;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_LF_CR) {
+		termios->c_iflag |= INLCR;
+	}
+	else {
+		termios->c_iflag &= ~INLCR;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_LF_CRLF) {
+		termios->c_oflag |= ONLCR;
+	}
+	else {
+		termios->c_oflag &= ~ONLCR;
+	}
+
+	return 0;
+}
+
+int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
+		return -EBADF;
+
+	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
+
+	if (optional_actions == TCSANOW) {
+		if (termios->c_lflag & ECHO) {
+			ntstdio->option |= NTSTDIO_OPTION_LINE_ECHO;
 		}
 		else {
-			termios->c_lflag &= ~ECHO;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_CANON) {
-			termios->c_lflag |= ICANON;
+			ntstdio->option &= ~NTSTDIO_OPTION_LINE_ECHO;
+		}
+		if (termios->c_lflag & ICANON) {
+			ntstdio->option |= NTSTDIO_OPTION_CANON;
 		}
 		else {
-			termios->c_lflag &= ~ICANON;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_LF_CR) {
-			termios->c_iflag |= INLCR;
+			ntstdio->option &= ~NTSTDIO_OPTION_CANON;
+		}
+		if (termios->c_iflag & INLCR) {
+			ntstdio->option |= NTSTDIO_OPTION_LF_CR;
 		}
 		else {
-			termios->c_iflag &= ~INLCR;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_LF_CRLF) {
-			termios->c_oflag |= ONLCR;
+			ntstdio->option &= ~NTSTDIO_OPTION_LF_CR;
+		}
+		if (termios->c_oflag & ONLCR) {
+			ntstdio->option |= NTSTDIO_OPTION_LF_CRLF;
 		}
 		else {
-			termios->c_oflag &= ~ONLCR;
+			ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF;
 		}
 		return 0;
 	}
-	shell_abort();
-	return 0;
-}
-
-int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)
-{
-	extern ntstdio_t ntstdio;
-
-	if ((fd == STDIN_FILENO) && (optional_actions == TCSANOW)) {
-		if (termios->c_lflag & ECHO) {
-			ntstdio.option |= NTSTDIO_OPTION_LINE_ECHO;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_LINE_ECHO;
-		}
-		if (termios->c_lflag & ICANON) {
-			ntstdio.option |= NTSTDIO_OPTION_CANON;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_CANON;
-		}
-		if (termios->c_iflag & INLCR) {
-			ntstdio.option |= NTSTDIO_OPTION_LF_CR;
-		}
-		else{
-			ntstdio.option &= ~NTSTDIO_OPTION_LF_CR;
-		}
-		if (termios->c_oflag & ONLCR) {
-			ntstdio.option |= NTSTDIO_OPTION_LF_CRLF;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_LF_CRLF;
-		}
-		return 0;
-	}
+
 	shell_abort();
 	return 0;
@@ -396,11 +442,11 @@
 	FILINFO fi;
 	FRESULT ret;
-#if _USE_LFN
-	static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
+#if FF_USE_LFN
+	static char lfn[FF_MAX_LFN + 1];   /* Buffer to store the LFN */
 	fi.lfname = lfn;
 	fi.lfsize = sizeof lfn;
 #endif
 	if (strcmp(path, ".") == 0) {
-		char cwd[_MAX_LFN];
+		char cwd[FF_MAX_LFN];
 		if ((ret = f_getcwd(cwd, sizeof(cwd))) != FR_OK) {
 			return fresult2errno(ret);
@@ -426,5 +472,5 @@
 	st->st_mtim.tv_nsec = 0;
 	st->st_mtim.tv_sec = fi.fdate + fi.ftime;
-	st->st_mode  = (S_IRUSR | S_IRGRP | S_IROTH);
+	st->st_mode = (S_IRUSR | S_IRGRP | S_IROTH);
 	st->st_mode |= (fi.fattrib & AM_RDO) ? 0 : (S_IWUSR | S_IWGRP | S_IWOTH);
 	st->st_mode |= (fi.fattrib & (AM_DIR | AM_VOL)) ? S_IFDIR : S_IFREG;
@@ -485,6 +531,6 @@
 	BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
 
-	if(mode & S_IREAD) {
-		if((mode & S_IWRITE) == 0) {
+	if (mode & S_IREAD) {
+		if ((mode & S_IWRITE) == 0) {
 			attr |= AM_RDO;
 		}
@@ -494,5 +540,5 @@
 	}
 
-	if((res = f_chmod(path, attr, mask)) != FR_OK) {
+	if ((res = f_chmod(path, attr, mask)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -507,6 +553,6 @@
 	BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
 
-	if(mode & S_IREAD) {
-		if((mode & S_IWRITE) == 0) {
+	if (mode & S_IREAD) {
+		if ((mode & S_IWRITE) == 0) {
 			attr |= AM_RDO;
 		}
@@ -516,5 +562,5 @@
 	}
 
-	if((res = f_chmod(path, attr, mask)) != FR_OK) {
+	if ((res = f_chmod(path, attr, mask)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -526,5 +572,5 @@
 {
 	FRESULT ret;
-	if((ret = f_getcwd(buf, size)) != FR_OK) {
+	if ((ret = f_getcwd(buf, size)) != FR_OK) {
 		return NULL;
 	}
@@ -549,8 +595,8 @@
 }
 
-int dir_close(struct _IO_FILE *fp)
-{
-	FRESULT res;
-	if ((res = f_closedir(&fp->pdir->dir)) != FR_OK) {
+int dir_close(struct SHELL_FILE *fp)
+{
+	FRESULT res;
+	if ((res = f_closedir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -564,21 +610,21 @@
 		return -EINVAL;
 
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
 
 	FILINFO fno;
-#if _USE_LFN
-	static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
+#if FF_USE_LFN
+	static char lfn[FF_MAX_LFN + 1];   /* Buffer to store the LFN */
 	fno.lfname = lfn;
 	fno.lfsize = sizeof lfn;
 #endif
 	FRESULT res;
-	if ((res = f_readdir(&fp->pdir->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
+	if ((res = f_readdir(&((struct SHELL_DIR *)fp->exinf)->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
 		return fresult2errno(res);
 	}
 
 	memset(de, 0, sizeof(*de));
-#if _USE_LFN
+#if FF_USE_LFN
 	ntlibc_strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));
 #else
@@ -589,15 +635,15 @@
 }
 
-size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
+size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
 {
 	return -EPERM;
 }
 
-size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
+size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
 {
 	return -EPERM;
 }
 
-off_t dir_seek(struct _IO_FILE *fp, off_t ptr, int dir)
+off_t dir_seek(struct SHELL_FILE *fp, off_t ptr, int dir)
 {
 	FRESULT res;
@@ -607,5 +653,5 @@
 
 	if (ptr == 0) {
-		if ((res = f_rewinddir(&fp->pdir->dir)) != FR_OK) {
+		if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 			return fresult2errno(res);
 		}
@@ -613,15 +659,15 @@
 	else {
 		FILINFO fno;
-#if _USE_LFN
-		static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
+#if FF_USE_LFN
+		static char lfn[FF_MAX_LFN + 1];   /* Buffer to store the LFN */
 		fno.lfname = lfn;
 		fno.lfsize = sizeof lfn;
 #endif
-		if ((res = f_rewinddir(&fp->pdir->dir)) != FR_OK) {
+		if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 			return fresult2errno(res);
 		}
 
 		for (int i = 0; i < ptr; i++) {
-			if ((res = f_readdir(&fp->pdir->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
+			if ((res = f_readdir(&((struct SHELL_DIR *)fp->exinf)->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
 				return fresult2errno(res);
 			}
@@ -632,7 +678,18 @@
 }
 
-int dir_ioctl(struct _IO_FILE *fp, int req, void *arg)
+int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	return -EINVAL;
+}
+
+bool_t dir_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+void dir_delete(struct SHELL_FILE *fp)
+{
+	free((struct SHELL_DIR *)fp->exinf);
+	fp->exinf = NULL;
 }
 
@@ -687,68 +744,6 @@
 {
 	//if ((addr >= (void *)&__HeapBase) && (addr + len < (void *)&__HeapLimit)) {
-		return 0;
-	//}
-	//return -1;
-}
-
-#include "tlsf.h"
-
-static tlsf_t sys_tlsf;
-static pool_t sys_pool;
-
-void sys_init(void)
-{
-	sys_tlsf = tlsf_create(&__HeapBase);
-	if (sys_tlsf == NULL)
-		return;
-
-	sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&__HeapBase) + tlsf_size(), ((intptr_t)&__HeapLimit - (intptr_t)&__HeapBase) - tlsf_size());
-}
-
-void sys_fini(void)
-{
-	tlsf_destroy(sys_tlsf);
-}
-
-void *malloc(size_t size)
-{
-	void *result;
-	wai_sem(SEM_MALLOC);
-	result = tlsf_malloc(sys_tlsf, size);
-	sig_sem(SEM_MALLOC);
-	if (result == NULL)
-		tlsf_check_pool(sys_pool);
-	return result;
-}
-
-void *calloc(size_t size, size_t count)
-{
-	void *result;
-	wai_sem(SEM_MALLOC);
-	result = tlsf_malloc(sys_tlsf, count * size);
-	sig_sem(SEM_MALLOC);
-	if (result != NULL)
-		memset(result, 0, count * size);
-	else
-		tlsf_check_pool(sys_pool);
-	return result;
-}
-
-void *realloc(void *ptr, size_t size)
-{
-	void *result;
-	wai_sem(SEM_MALLOC);
-	result = tlsf_realloc(sys_tlsf, ptr, size);
-	sig_sem(SEM_MALLOC);
-	if (result == NULL)
-		tlsf_check_pool(sys_pool);
-	return result;
-}
-
-void free(void *ptr)
-{
-	wai_sem(SEM_MALLOC);
-	tlsf_free(sys_tlsf, ptr);
-	sig_sem(SEM_MALLOC);
-}
-
+	return 0;
+//}
+//return -1;
+}
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c	(revision 374)
@@ -60,7 +60,5 @@
 #include "kernel_cfg.h"
 #include "tinet_cfg.h"
-#include "util/ntstdio.h"
-
-extern ntstdio_t ntstdio;
+#include <stdio.h>
 
 T_DHCP4_CLI_CONTEXT *dhcp4_cli_initialize(ID tskid, ID cepid);
@@ -97,5 +95,5 @@
 
 	get_tid(&nc->tskid);
-	ntstdio_printf(&ntstdio, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
+	printf("[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
 
 	/* 初期化 */
@@ -105,5 +103,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %7lu,%s",
+		printf("[NET MISC,%d] get_tim error: %7lu,%s",
 			nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
 		return;
@@ -119,5 +117,5 @@
 		error = tslp_tsk(timer);
 		if ((error != E_OK) && (error != E_TMOUT)) {
-			ntstdio_printf(&ntstdio, "[NET MISC,%d] tslp_tsk error: %s %d",
+			printf("[NET MISC,%d] tslp_tsk error: %s %d",
 				nc->cepid, itron_strerror(error), timer);
 			break;
@@ -126,5 +124,5 @@
 		ret = get_tim(&time);
 		if (ret != E_OK) {
-			ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %s",
+			printf("[NET MISC,%d] get_tim error: %s",
 				nc->cepid, itron_strerror(ret));
 			break;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c	(revision 374)
@@ -59,9 +59,7 @@
 #include <netapp/resolver.h>
 #include "core/ntlibc.h"
-#include "util/ntstdio.h"
+#include <stdio.h>
 #include "ntp_cli.h"
 #include "kernel_cfg.h"
-
-extern ntstdio_t ntstdio;
 
 #if defined(SUPPORT_INET6)
@@ -280,5 +278,5 @@
 
 	if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
-		ntstdio_printf(&ntstdio, "[PING] unknown host.\n");
+		printf("[PING] unknown host.\n");
 		return 0;
 	}
@@ -299,18 +297,18 @@
 #if defined(SUPPORT_INET4)
 	if (apip == API_PROTO_IPV6) {
-		ntstdio_printf(&ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
+		printf("[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
 		ping6(&addr, (uint_t)tmo, (uint_t)size);
 	}
 	else {
 		addr4 = ntohl(addr.s6_addr32[3]);
-		ntstdio_printf(&ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));
+		printf("[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));
 		ping4(&addr4, (uint_t)tmo, (uint_t)size);
 	}
 #else /* of #if defined(SUPPORT_INET4) */
-	ntstdio_printf(&ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
+	printf("[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
 	ping6(&addr, (uint_t)tmo, (uint_t)size);
 #endif	/* of #if defined(SUPPORT_INET4) */
 #else	/* of #if defined(SUPPORT_INET6) */
-	ntstdio_printf(&ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));
+	printf("[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));
 	ping4(&addr, (uint_t)tmo, (uint_t)size);
 #endif	/* of #if defined(SUPPORT_INET6) */
@@ -331,13 +329,13 @@
 		pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0);
 		temp[pos] = '\0';
-		ntstdio_printf(&ntstdio, "DHCPv4 server: %s,\n", temp);
-		ntstdio_printf(&ntstdio, "  Renew:       %u:%02u:%02u,\n",
+		printf("DHCPv4 server: %s,\n", temp);
+		printf("  Renew:       %u:%02u:%02u,\n",
 			renew / 3600, (renew / 60) % 60, renew % 60);
-		ntstdio_printf(&ntstdio, "  Rebind:      %u:%02u:%02u, Expire:   %u:%02u:%02u.\n",
+		printf("  Rebind:      %u:%02u:%02u, Expire:   %u:%02u:%02u.\n",
 			rebind / 3600, (rebind / 60) % 60, rebind % 60,
 			expire / 3600, (expire / 60) % 60, expire % 60);
 	}
 	else if (ret == E_OBJ)
-		ntstdio_printf(&ntstdio, "DHCPv4 server: not available.\n");
+		printf("DHCPv4 server: not available.\n");
 }
 
@@ -351,9 +349,9 @@
 	if (ntlibc_strcmp(argv[1], "rel") == 0) {
 		ret = dhcp4c_rel_info();
-		ntstdio_printf(&ntstdio, "dhcp4c_rel_info %d\n", ret);
+		printf("dhcp4c_rel_info %d\n", ret);
 	}
 	else if (ntlibc_strcmp(argv[1], "renew") == 0) {
 		ret = dhcp4c_renew_info();
-		ntstdio_printf(&ntstdio, "dhcp4c_renew_info %d\n", ret);
+		printf("dhcp4c_renew_info %d\n", ret);
 	}
 	else {
@@ -383,8 +381,8 @@
 		else {
 			for (c = 1; c <= *ptr; c++)
-				ntstdio_printf(&ntstdio, "%c", *(ptr + c));
+				printf("%c", *(ptr + c));
 			ptr += *ptr + 1;
 			if (*ptr)
-				ntstdio_printf(&ntstdio, ".");
+				printf(".");
 		}
 	}
@@ -406,16 +404,16 @@
 		return error;
 
-	ntstdio_printf(&ntstdio, "    mname:   ");
+	printf("    mname:   ");
 	rn_offset = s_show_dns_domain_name(msg, offset);
-	ntstdio_putc(&ntstdio, '\n');
-	ntstdio_printf(&ntstdio, "    rname:   ");
+	putchar('\n');
+	printf("    rname:   ");
 	s_show_dns_domain_name(msg, rn_offset);
-	ntstdio_putc(&ntstdio, '\n');
-
-	ntstdio_printf(&ntstdio, "    serial:  %d\n", soa.serial);
-	ntstdio_printf(&ntstdio, "    refresh: %d\n", soa.refresh);
-	ntstdio_printf(&ntstdio, "    retry:   %d\n", soa.retry);
-	ntstdio_printf(&ntstdio, "    expirel: %d\n", soa.expire);
-	ntstdio_printf(&ntstdio, "    minimum: %d\n", soa.minimum);
+	putchar('\n');
+
+	printf("    serial:  %d\n", soa.serial);
+	printf("    refresh: %d\n", soa.refresh);
+	printf("    retry:   %d\n", soa.retry);
+	printf("    expirel: %d\n", soa.expire);
+	printf("    minimum: %d\n", soa.minimum);
 
 	return E_OK;
@@ -433,5 +431,5 @@
 	int		scount;
 
-	ntstdio_printf(&ntstdio, "question   section: %d\n", rslv->dns_hdr.qdcount);
+	printf("question   section: %d\n", rslv->dns_hdr.qdcount);
 	offset = rslv->qd_offset;
 	for (scount = 1; scount <= rslv->dns_hdr.qdcount; scount++) {
@@ -439,7 +437,7 @@
 			return error;
 
-		ntstdio_printf(&ntstdio, "%2d: ", scount);
+		printf("%2d: ", scount);
 		s_show_dns_domain_name(msg, offset);
-		ntstdio_printf(&ntstdio, "\n    type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));
+		printf("\n    type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));
 		offset = error;
 	}
@@ -463,12 +461,12 @@
 	int pos;
 
-	ntstdio_printf(&ntstdio, "%10s section: %d\n", title, scount);
+	printf("%10s section: %d\n", title, scount);
 	for (count = 1; count <= scount; count++) {
 		if ((error = dns_analyze_rr(&rr, offset, msg, length)) < 0)
 			return error;
 
-		ntstdio_printf(&ntstdio, "%2d: ", count);
+		printf("%2d: ", count);
 		s_show_dns_domain_name(msg, offset);
-		ntstdio_printf(&ntstdio, "\n    type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",
+		printf("\n    type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",
 			dns_strtype(rr.type), dns_strclass(rr.class), rr.ttl, rr.rdlength, rr.rdata_offset);
 
@@ -479,15 +477,15 @@
 			pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
 			temp[pos] = '\0';
-			ntstdio_printf(&ntstdio, "    IPv4 addr: %s\n", temp);
+			printf("    IPv4 addr: %s\n", temp);
 			break;
 		case DNS_TYPE_NS:
-			ntstdio_printf(&ntstdio, "    host: ");
+			printf("    host: ");
 			s_show_dns_domain_name(msg, rr.rdata_offset);
-			ntstdio_putc(&ntstdio, '\n');
+			putchar('\n');
 			break;
 		case DNS_TYPE_CNAME:
-			ntstdio_printf(&ntstdio, "    host: ");
+			printf("    host: ");
 			s_show_dns_domain_name(msg, rr.rdata_offset);
-			ntstdio_putc(&ntstdio, '\n');
+			putchar('\n');
 			break;
 		case DNS_TYPE_SOA:
@@ -495,7 +493,7 @@
 			break;
 		case DNS_TYPE_PTR:
-			ntstdio_printf(&ntstdio, "     PTR: ");
+			printf("     PTR: ");
 			s_show_dns_domain_name(msg, rr.rdata_offset);
-			ntstdio_putc(&ntstdio, '\n');
+			putchar('\n');
 			break;
 		case DNS_TYPE_AAAA:
@@ -503,17 +501,17 @@
 			pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
 			temp[pos] = '\0';
-			ntstdio_printf(&ntstdio, "    IPv6 addr: %s\n", temp);
+			printf("    IPv6 addr: %s\n", temp);
 			break;
 		default:
-			ntstdio_printf(&ntstdio, "    data: ");
+			printf("    data: ");
 			col = 32;
 			for (dcount = 0; dcount < rr.rdlength; dcount++) {
-				ntstdio_printf(&ntstdio, "%02x", *(msg + rr.rdata_offset + dcount));
+				printf("%02x", *(msg + rr.rdata_offset + dcount));
 				if (--col == 0) {
-					ntstdio_printf(&ntstdio, "\n          ");
+					printf("\n          ");
 					col = 32;
 				}
 			}
-			ntstdio_putc(&ntstdio, '\n');
+			putchar('\n');
 			break;
 		}
@@ -539,9 +537,9 @@
 #if defined(SUPPORT_INET6)
 
-	ntstdio_printf(&ntstdio, "domain name:     %s\n", dns_in6_get_dname());
+	printf("domain name:     %s\n", dns_in6_get_dname());
 
 #else	/* of #if defined(SUPPORT_INET6) */
 
-	ntstdio_printf(&ntstdio, "domain name:     %s\n", dns_in4_get_dname());
+	printf("domain name:     %s\n", dns_in4_get_dname());
 
 #endif	/* of #if defined(SUPPORT_INET6) */
@@ -549,11 +547,11 @@
 #if defined(SUPPORT_INET6)
 	dns_in6_get_addr(&in6_addr);
-	ntstdio_printf(&ntstdio, "IPv6 DNS server: ");
+	printf("IPv6 DNS server: ");
 	if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr))
-		ntstdio_printf(&ntstdio, "not available.\n");
+		printf("not available.\n");
 	else {
 		pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
 		temp[pos] = '\0';
-		ntstdio_printf(&ntstdio, "%s.\n", temp);
+		printf("%s.\n", temp);
 	}
 #endif	/* of #if defined(SUPPORT_INET6) */
@@ -561,11 +559,11 @@
 #if defined(SUPPORT_INET4)
 	dns_in4_get_addr(&in4_addr);
-	ntstdio_printf(&ntstdio, "IPv4 DNS server: ");
+	printf("IPv4 DNS server: ");
 	if (in4_addr == IPV4_ADDRANY)
-		ntstdio_printf(&ntstdio, "not available.\n");
+		printf("not available.\n");
 	else {
 		pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
 		temp[pos] = '\0';
-		ntstdio_printf(&ntstdio, "%s.\n", temp);
+		printf("%s.\n", temp);
 	}
 #endif	/* of #if defined(SUPPORT_INET4) */
@@ -604,5 +602,5 @@
 	line = skip_blanks(resolv_options(&flags, line, DEFAULT_API_PROTO));
 	if ((flags & (DNS_LUP_FLAGS_PROTO_IPV6 | DNS_LUP_FLAGS_PROTO_IPV4)) == 0) {
-		ntstdio_printf(&ntstdio, "DNS server not available.\n");
+		printf("DNS server not available.\n");
 		return 0;
 	}
@@ -620,47 +618,47 @@
 
 	if ((error = tget_mpf(MPF_RSLV_SRBUF, (void*)&msg, TMO_FEVR)) != E_OK) {
-		ntstdio_printf(&ntstdio, "get buffer error: %s.\n", itron_strerror(error));
+		printf("get buffer error: %s.\n", itron_strerror(error));
 		return 0;
 	}
 
 	if ((length = dns_lookup_host(flags | DNS_LUP_FLAGS_MSG, line, msg, DNS_UDP_MSG_LENGTH, &rslv)) < 0) {
-		//ntstdio_printf(&ntstdio, "error: %s.\n", itron_strerror(length));
+		//printf("error: %s.\n", itron_strerror(length));
 		goto err_ret;
 	}
 
 	dly_tsk(1 * 1000);
-	ntstdio_printf(&ntstdio, "DNS header: flags: ");
+	printf("DNS header: flags: ");
 	if (rslv.dns_hdr.code & (DNS_QR_RESPONSE | DNS_AUTHORITATIVE |
 		DNS_TRUN_CATION | DNS_RECURSION_DESIRED | DNS_RECURSION_AVAILABLE)) {
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");
-		ntstdio_printf(&ntstdio, " ");
-	}
-	ntstdio_printf(&ntstdio, "opcode: ");
-	ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");
-	ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");
-	ntstdio_printf(&ntstdio, ", rcode: %s.\n",
+		printf((rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");
+		printf((rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");
+		printf((rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");
+		printf((rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");
+		printf((rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");
+		printf(" ");
+	}
+	printf("opcode: ");
+	printf((rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");
+	printf((rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");
+	printf(", rcode: %s.\n",
 		(rslv.dns_hdr.code & DNS_RCODE_MASK) > DNS_RCODE_REFUSED
 		? "6" : rcode_str[rslv.dns_hdr.code & DNS_RCODE_MASK]);
 
 	if ((offset = show_dns_qdsection(msg, length, &rslv)) < 0) {
-		ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
+		printf("msg error: %s.\n", itron_strerror(offset));
 	}
 	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.ancount, rslv.an_offset, "answer")) < 0) {
-		ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
+		printf("msg error: %s.\n", itron_strerror(offset));
 	}
 	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.nscount, rslv.ns_offset, "authority")) < 0) {
-		ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
+		printf("msg error: %s.\n", itron_strerror(offset));
 	}
 	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.arcount, rslv.ar_offset, "additional")) < 0) {
-		ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
+		printf("msg error: %s.\n", itron_strerror(offset));
 	}
 
 err_ret:
 	if ((error = rel_mpf(MPF_RSLV_SRBUF, msg)) != E_OK)
-		ntstdio_printf(&ntstdio, "release buffer error: %s.\n", itron_strerror(error));
+		printf("release buffer error: %s.\n", itron_strerror(error));
 	return 0;
 }
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c	(revision 374)
@@ -50,7 +50,5 @@
 #include <t_syslog.h>
 #include "kernel_cfg.h"
-#include "util/ntstdio.h"
-
-extern ntstdio_t ntstdio;
+#include <stdio.h>
 
 #endif	/* of #if defined(TARGET_KERNEL_ASP) */
@@ -279,5 +277,5 @@
 	}
 
-	ntstdio_printf(&ntstdio, "[NTP CLI,%d] recv time: %s .%09u\n",
+	printf("[NTP CLI,%d] recv time: %s .%09u\n",
 		nc->cepid, nc->buf, tp.tv_nsec);
 }
@@ -311,5 +309,5 @@
 		line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4);
 		if (line == NULL || !in6_is_addr_ipv4mapped(&nc->ipaddr6)) {
-			ntstdio_printf(&ntstdio, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
+			printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
 				nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
 			nc->timer = SLP_ITV;
@@ -319,5 +317,5 @@
 #else	/* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
 		if ((line = lookup_ipaddr(&nc->snd_rmt.ipaddr, NTP_SRV_URL, DEFAULT_API_PROTO)) == NULL) {
-			ntstdio_printf(&ntstdio, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
+			printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
 				nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
 			nc->timer = SLP_ITV;
@@ -423,5 +421,5 @@
 
 	if ((error = udp_snd_dat(nc->cepid, &nc->snd_rmt, ntp, len, TMO_NBLK)) != E_WBLK) {
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] udp_snd_dat error: %s",
+		printf("[NTP CLI,%d] udp_snd_dat error: %s",
 			nc->cepid, itron_strerror(error));
 		return error;
@@ -441,5 +439,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s",
+		printf("[NTP CLI,%d] get_tim error: %s",
 			nc->cepid, itron_strerror(ret));
 		tp->tv_sec = 0;
@@ -461,5 +459,5 @@
 	ret = set_tim(time);
 	if (ret != E_OK) {
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] set_tim error: %s",
+		printf("[NTP CLI,%d] set_tim error: %s",
 			nc->cepid, itron_strerror(ret));
 	}
@@ -479,5 +477,5 @@
 	if (len < 0 && len != E_RLWAI) {
 		/* E_RLWAI 以外で、0 以下の場合は、エラーを意味している。*/
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
+		printf("[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
 			itron_strerror(len), in_strtfn(fncd));
 	}
@@ -486,5 +484,5 @@
 			if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0)
 			{
-				ntstdio_printf(&ntstdio, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
+				printf("[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
 					itron_strerror(len));
 			}
@@ -518,5 +516,5 @@
 
 	get_tid(&nc->tskid);
-	ntstdio_printf(&ntstdio, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
+	printf("[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
 
 	/* 初期化 */
@@ -525,5 +523,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %7lu,%s",
+		printf("[NTP CLI,%d] get_tim error: %7lu,%s",
 			nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
 		return;
@@ -539,5 +537,5 @@
 		error = tslp_tsk(timer);
 		if ((error != E_OK) && (error != E_TMOUT)) {
-			ntstdio_printf(&ntstdio, "[NTP CLI,%d] tslp_tsk error: %s %d",
+			printf("[NTP CLI,%d] tslp_tsk error: %s %d",
 				nc->cepid, itron_strerror(error), timer);
 			break;
@@ -546,5 +544,5 @@
 		ret = get_tim(&time);
 		if (ret != E_OK) {
-			ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s",
+			printf("[NTP CLI,%d] get_tim error: %s",
 				nc->cepid, itron_strerror(ret));
 			break;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c	(revision 374)
@@ -59,10 +59,6 @@
 #include "ntshell_main.h"
 #include "socket_stub.h"
-#include "usb_hbth.h"
-
-extern int bt_bnep_mode;
 
 char command[NTOPT_TEXT_MAXLEN];
-ntstdio_t ntstdio;
 
 extern uint8_t mac_addr[6];
@@ -87,33 +83,8 @@
 volatile int ntshell_state;
 jmp_buf process_exit;
-void sys_init(void);
-NTSHELL_SERIAL_READ ntshell_serial_read = 0;
-NTSHELL_SERIAL_WRITE ntshell_serial_write = 0;
-void *ntshell_serial_extobj;
-
-unsigned char ntstdio_xi(struct ntstdio_t *handle)
-{
-	unsigned char buf[1];
-	ntshell_serial_read((char *)buf, 1, ntshell_serial_extobj);
-	return buf[0];
-}
-
-void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
-{
-	char buf[1];
-	buf[0] = c;
-	ntshell_serial_write(buf, 1, ntshell_serial_extobj);
-}
-
-void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
-	NTSHELL_SERIAL_WRITE func_write, void *extobj)
-{
-	ntshell_serial_read = func_read;
-	ntshell_serial_write = func_write;
-	ntshell_serial_extobj = extobj;
-
-	sys_init();
-
-	ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
+
+void ntshell_task_init(ID portid)
+{
+	serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
 }
 
@@ -177,8 +148,7 @@
 	const cmd_table_t *p = cmd_table_info.table;
 	for (int i = 0; i < cmd_table_info.count; i++) {
-		ntstdio_puts(&ntstdio, p->cmd);
-		ntstdio_puts(&ntstdio, "\t:");
-		ntstdio_puts(&ntstdio, p->desc);
-		ntstdio_puts(&ntstdio, "\n");
+		fwrite(p->cmd, strlen(p->cmd), 1, stdout);
+		fwrite("\t:", strlen("\t:"), 1, stdout);
+		puts(p->desc);
 		p++;
 	}
@@ -206,4 +176,5 @@
 int execute_command(int wait)
 {
+	T_RTSK rtsk;
 	ER ret;
 
@@ -228,4 +199,8 @@
 	do {
 		tslp_tsk(100000);
+
+		ret = ref_tsk(NTSHELL_TASK, &rtsk);
+		if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT))
+			ntshell_state = 3;
 	} while(ntshell_state == 1);
 
@@ -237,83 +212,4 @@
 	ntlibc_strlcpy(command, text, sizeof(command));
 	return execute_command(1);
-}
-
-int stdio_close(struct _IO_FILE *fp)
-{
-	return -EPERM;
-}
-
-size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	int i = 0;
-	while (i < len) {
-		int c = ntstdio_getc(&ntstdio);
-		data[i++] = c;
-		if ((c == EOF) || (c == '\n'))
-			break;
-	}
-	return i;
-}
-
-size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	for (int i = 0; i < len; i++) {
-		ntstdio_putc(&ntstdio, data[i]);
-	}
-	return len;
-}
-
-size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	for (int i = 0; i < len; i++) {
-		ntstdio_putc(&ntstdio, data[i]);
-	}
-	return len;
-}
-
-int sio_close(struct _IO_FILE *fp)
-{
-	return -EPERM;
-}
-
-size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)
-{
-	return -EPERM;
-}
-
-int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)
-{
-	switch (request) {
-	case TIOCGWINSZ:
-		return 0;
-	case TCGETS:
-		return sio_tcgetattr(fp->fd, (struct termios *)arg);
-	case TCSETS + TCSANOW:
-	case TCSETS + TCSADRAIN:
-	case TCSETS + TCSAFLUSH:
-		return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
-	}
-
-	return -EINVAL;
 }
 
@@ -456,2 +352,18 @@
 }
 
+int shell_kill(int pid, int sig)
+{
+	DebugBreak();
+	return -1;
+}
+
+int shell_gettimeofday(struct timeval *tv, void *tzvp)
+{
+	SYSTIM time;
+	if (!tv) return 0;
+	get_tim(&time);
+	tv->tv_sec = time / 1000000;
+	tv->tv_usec = time - (tv->tv_sec * 1000000);
+	return 0;
+}
+
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.cfg
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.cfg	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.cfg	(revision 374)
@@ -41,6 +41,7 @@
 #include "ntshell_main.h"
 
-CRE_TSK(NTSHELL_TASK, { TA_NULL, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL });
+ATT_INI({ TA_NULL, 0, sys_init });
+
+CRE_TSK(NTSHELL_TASK, { TA_FPU, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL });
 CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 });
 CRE_SEM(SEM_FILEDESC, { TA_TPRI, 1, 1 });
-CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 });
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h	(revision 374)
@@ -76,7 +76,9 @@
 extern PRI main_task_priority;
 
+/* ntshellの初期化 */
+void sys_init(intptr_t exinf);
+
 /* ntshellタスク初期化 */
-void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
-	NTSHELL_SERIAL_WRITE func_write, void *extobj);
+void ntshell_task_init(ID portid);
 
 /* ntshellタスク */
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h	(revision 374)
@@ -134,5 +134,5 @@
 
 // dirent.h
-typedef struct __dirstream DIR;
+typedef struct __dirstream FATFS_DIR;
 
 int shell_getdents(int, struct dirent *, size_t);
@@ -303,5 +303,4 @@
 #endif
 
-struct tm *gmtime_r(const time_t *t, struct tm *tm);
 void *malloc(size_t size);
 void *calloc(size_t size, size_t count);
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c	(revision 374)
@@ -57,5 +57,8 @@
 #include <netinet/udp_var.h>
 #include <net/net_buf.h>
-//#include <netinet/tcp_var.h>
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_var.h>
 #include <netapp/resolver.h>
 extern const ID tmax_tcp_cepid;
@@ -64,5 +67,28 @@
 #include "kernel_cfg.h"
 
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
 #define SOCKET_TIMEOUT 2000000
+
+static int tcp_fd_close(struct SHELL_FILE *fp);
+static size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t tcp_fd_readable(struct SHELL_FILE *fp);
+static void tcp_fd_delete(struct SHELL_FILE *fp);
+
+static int udp_fd_close(struct SHELL_FILE *fp);
+static size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t udp_fd_readable(struct SHELL_FILE *fp);
+static void udp_fd_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_TCP = { tcp_fd_close, tcp_fd_read, tcp_fd_write, tcp_fd_seek, tcp_fd_ioctl, tcp_fd_readable, tcp_fd_delete };
+IO_TYPE IO_TYPE_UDP = { udp_fd_close, udp_fd_read, udp_fd_write, udp_fd_seek, udp_fd_ioctl, udp_fd_readable, udp_fd_delete };
 
 typedef struct id_table_t {
@@ -116,10 +142,5 @@
 }
 
-int delete_tcp_rep(int repid)
-{
-	return delete_tcp_fd(tmax_tcp_cepid + repid);
-}
-
-typedef struct _IO_FILE SOCKET;
+typedef struct SHELL_FILE SOCKET;
 
 int shell_socket(int family, int type, int protocol)
@@ -141,8 +162,18 @@
 	switch (type) {
 	case SOCK_STREAM:
-		fp = new_tcp_fd(0);
+		fp = new_fp(&IO_TYPE_TCP, 0, 0);
+		if (fp == NULL)
+			return -ENOMEM;
+
+		fp->exinf = malloc(sizeof(socket_t));
+		memset(fp->exinf, 0, sizeof(socket_t));
 		break;
 	case SOCK_DGRAM:
-		fp = new_udp_fd(0);
+		fp = new_fp(&IO_TYPE_UDP, 0, 1);
+		if (fp == NULL)
+			return -ENOMEM;
+
+		fp->exinf = malloc(sizeof(socket_t));
+		memset(fp->exinf, 0, sizeof(socket_t));
 		break;
 	default:
@@ -150,12 +181,9 @@
 	}
 
-	if (fp == NULL) {
-		return -ENOMEM;
-	}
-
-	fp->psock->family = family;
-	fp->psock->type = type;
-	fp->psock->protocol = protocol;
-	fp->psock->flags = flags;
+	socket_t *socket = (socket_t *)fp->exinf;
+	socket->family = family;
+	socket->type = type;
+	socket->protocol = protocol;
+	socket->flags = flags;
 
 	return fp->fd;
@@ -167,5 +195,6 @@
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->psock->family != addr->sa_family)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->family != addr->sa_family)
 		return -EINVAL;
 
@@ -177,6 +206,6 @@
 		}
 		struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
-		memcpy(&fp->psock->laddr4, addr, len);
-		switch (fp->psock->type) {
+		memcpy(&socket->laddr4, addr, len);
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
@@ -184,10 +213,10 @@
 				return -ENOMEM;
 
-			fp->psock->buf_size = 512 + 512;
-			fp->psock->buf = malloc(fp->psock->buf_size);
+			socket->buf_size = 512 + 512;
+			socket->buf = malloc(socket->buf_size);
 #ifdef _DEBUG
-			memset(fp->psock->buf, 0, fp->psock->buf_size);
+			memset(socket->buf, 0, socket->buf_size);
 #endif
-			T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
@@ -196,5 +225,5 @@
 			}
 			fp->handle = cepid;
-			fp->psock->cepid = cepid;
+			socket->cepid = cepid;
 			break;
 		}
@@ -211,5 +240,5 @@
 			}
 			fp->handle = cepid;
-			fp->psock->cepid = cepid;
+			socket->cepid = cepid;
 			break;
 		}
@@ -223,5 +252,5 @@
 			return -EINVAL;
 		}
-		memcpy(&fp->psock->laddr4, addr, len);
+		memcpy(&socket->laddr4, addr, len);
 		break;
 	}
@@ -236,11 +265,12 @@
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->psock->type != SOCK_STREAM)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->type != SOCK_STREAM)
 		return -EINVAL;
 
-	fp->psock->backlog = backlog;
+	socket->backlog = backlog;
 
 	ER ret;
-	switch (fp->psock->family) {
+	switch (socket->family) {
 	case AF_INET: {
 		ID repid = new_id(tcp_repid_table, tcp_repid_table_count);
@@ -248,5 +278,5 @@
 			return -ENOMEM;
 
-		struct sockaddr_in *laddr = &fp->psock->laddr4;
+		struct sockaddr_in *laddr = &socket->laddr4;
 		T_TCP_CREP crep = { 0, {ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port)} };
 		ret = tcp_cre_rep(repid, &crep);
@@ -255,5 +285,5 @@
 			return -ENOMEM;
 		}
-		fp->psock->repid = repid;
+		socket->repid = repid;
 		break;
 	}
@@ -271,24 +301,25 @@
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->psock->type != SOCK_STREAM)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->type != SOCK_STREAM)
 		return -EINVAL;
 
 	ER ret;
-	switch (fp->psock->family) {
+	switch (socket->family) {
 	case AF_INET: {
 		if (len < 8) {
 			return -EINVAL;
 		}
-		if (fp->psock->cepid == 0) {
+		if (socket->cepid == 0) {
 			ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
 				return -ENOMEM;
 
-			fp->psock->buf_size = 512 + 512;
-			fp->psock->buf = malloc(fp->psock->buf_size);
+			socket->buf_size = 512 + 512;
+			socket->buf = malloc(socket->buf_size);
 #ifdef _DEBUG
-			memset(fp->psock->buf, 0, fp->psock->buf_size);
+			memset(socket->buf, 0, socket->buf_size);
 #endif
-			T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
@@ -297,13 +328,13 @@
 			}
 			fp->handle = cepid;
-			fp->psock->cepid = cepid;
-		}
-		struct sockaddr_in *laddr = &fp->psock->laddr4;
-		struct sockaddr_in *raddr = &fp->psock->raddr4;
+			socket->cepid = cepid;
+		}
+		struct sockaddr_in *laddr = &socket->laddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
 		memset(raddr, 0, sizeof(*raddr));
 		memcpy(raddr, addr, len);
 		T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) };
 		T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
-		ret = tcp_con_cep(fp->psock->cepid, &lep, &rep, SOCKET_TIMEOUT);
+		ret = tcp_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
 		if (ret < 0) {
 			return -EHOSTUNREACH;
@@ -324,29 +355,32 @@
 	if (lfp == NULL)
 		return -EBADF;
-	if (lfp->psock->type != SOCK_STREAM)
+	if (((socket_t *)lfp->exinf)->type != SOCK_STREAM)
 		return -EINVAL;
 
-	SOCKET *fp = new_tcp_fd(0);
-	if (fp == NULL) {
+	SOCKET *fp = new_fp(&IO_TYPE_TCP, 0, 0);
+	if (fp == NULL)
 		return -ENOMEM;
-	}
-
-	memcpy(fp->psock, lfp->psock, offsetof(socket_t, buf_size));
+
+	fp->exinf = malloc(sizeof(socket_t));
+	memset(fp->exinf, 0, sizeof(socket_t));
+
+	memcpy(fp->exinf, lfp->exinf, offsetof(socket_t, buf_size));
 
 	ER ret;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
 		ID cepid;
-		if (fp->psock->cepid == 0) {
+		if (socket->cepid == 0) {
 			cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
 				return -ENOMEM;
 
-			fp->psock->buf_size = 512 + 512;
-			fp->psock->buf = malloc(fp->psock->buf_size);
+			socket->buf_size = 512 + 512;
+			socket->buf = malloc(socket->buf_size);
 #ifdef _DEBUG
-			memset(fp->psock->buf, 0, fp->psock->buf_size);
+			memset(socket->buf, 0, socket->buf_size);
 #endif
-			T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
@@ -355,20 +389,20 @@
 			}
 			fp->handle = cepid;
-			fp->psock->cepid = cepid;
+			socket->cepid = cepid;
 		}
 		else {
-			cepid = lfp->psock->cepid;
+			cepid = ((socket_t *)lfp->exinf)->cepid;
 			fp->handle = cepid;
-			lfp->handle = tmax_tcp_cepid + lfp->psock->repid;
-			lfp->psock->cepid = 0;
-			lfp->psock->buf_size = 0;
-			lfp->psock->buf = 0;
+			lfp->handle = tmax_tcp_cepid + ((socket_t *)lfp->exinf)->repid;
+			((socket_t *)lfp->exinf)->cepid = 0;
+			((socket_t *)lfp->exinf)->buf_size = 0;
+			((socket_t *)lfp->exinf)->buf = 0;
 		}
 		T_IPV4EP rep = { 0, 0 };
-		ret = tcp_acp_cep(fp->psock->cepid, fp->psock->repid, &rep, TMO_FEVR);
+		ret = tcp_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR);
 		if (ret < 0) {
 			return -ENOMEM;
 		}
-		struct sockaddr_in *raddr = &fp->psock->raddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
 		memset(raddr, 0, sizeof(*raddr));
 		raddr->sin_family = AF_INET;
@@ -387,5 +421,5 @@
 			return -EINVAL;
 		}
-		struct sockaddr_in *raddr = &fp->psock->raddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
 		if (sz > sizeof(*raddr))
 			sz = sizeof(*raddr);
@@ -405,7 +439,8 @@
 
 	int ret = 0;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			if ((addr != NULL) || (alen != 0)) {
@@ -414,5 +449,5 @@
 
 			if (flags & MSG_OOB) {
-				ret = tcp_snd_oob(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
+				ret = tcp_snd_oob(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
 				if (ret < 0) {
 					return -ECOMM;
@@ -421,5 +456,5 @@
 			else {
 				for (;;) {
-					ret = tcp_snd_dat(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
+					ret = tcp_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
 					if (ret < 0) {
 						if (ret == E_TMOUT)
@@ -440,10 +475,10 @@
 				return -EINVAL;
 			}
-			struct sockaddr_in *raddr = &fp->psock->raddr4;
+			struct sockaddr_in *raddr = &socket->raddr4;
 			memset(raddr, 0, sizeof(*raddr));
 			memcpy(raddr, addr, sz);
 			T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
-			ret = udp_snd_dat(fp->psock->cepid, &rep, (void *)buf, len,
-				(fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+			ret = udp_snd_dat(socket->cepid, &rep, (void *)buf, len,
+				(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
 			if (ret < 0) {
 				return (ret == E_TMOUT) ? -ETIME : -ECOMM;
@@ -476,10 +511,11 @@
 
 	int ret = 0;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			if (flags & MSG_OOB) {
-				ret = tcp_rcv_oob(fp->psock->cepid, buf, len);
+				ret = tcp_rcv_oob(socket->cepid, buf, len);
 				if (ret < 0) {
 					syslog(LOG_ERROR, "tcp_rcv_oob => %d", ret);
@@ -489,15 +525,15 @@
 			else {
 				int rsz, tmp;
-				if (fp->psock->input == NULL) {
+				if (socket->input == NULL) {
 					ret = wai_sem(SEM_FILEDESC);
 					if (ret < 0) {
 						syslog(LOG_ERROR, "wai_sem => %d", ret);
 					}
-					fp->psock->len = 0;
+					socket->len = 0;
 					ret = sig_sem(SEM_FILEDESC);
 					if (ret < 0) {
 						syslog(LOG_ERROR, "sig_sem => %d", ret);
 					}
-					ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_FEVR);
+					ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_FEVR);
 					if (ret < 0) {
 						syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
@@ -507,15 +543,15 @@
 				}
 				else
-					rsz = fp->psock->len;
+					rsz = socket->len;
 				tmp = rsz;
 				if (rsz > len)
 					rsz = len;
 				if (rsz >= 0) {
-					memcpy(buf, fp->psock->input, rsz);
+					memcpy(buf, socket->input, rsz);
 					ret = wai_sem(SEM_FILEDESC);
 					if (ret < 0) {
 						syslog(LOG_ERROR, "wai_sem => %d", ret);
 					}
-					fp->psock->len = tmp - rsz;
+					socket->len = tmp - rsz;
 					ret = sig_sem(SEM_FILEDESC);
 					if (ret < 0) {
@@ -523,9 +559,9 @@
 					}
 					if (tmp - rsz == 0) {
-						fp->psock->input = NULL;
+						socket->input = NULL;
 					}
 					else
-						fp->psock->input = (void *)&((uint8_t *)fp->psock->input)[rsz];
-					ret = tcp_rel_buf(fp->psock->cepid, rsz);
+						socket->input = (void *)&((uint8_t *)socket->input)[rsz];
+					ret = tcp_rel_buf(socket->cepid, rsz);
 					if ((ret != E_OBJ) && (ret < 0)) {
 						syslog(LOG_ERROR, "tcp_rel_buf => %d", ret);
@@ -538,5 +574,5 @@
 		}
 		case SOCK_DGRAM: {
-			struct sockaddr_in *raddr = &fp->psock->raddr4;
+			struct sockaddr_in *raddr = &socket->raddr4;
 			int rsz;
 			ret = wai_sem(SEM_FILEDESC);
@@ -544,5 +580,5 @@
 				syslog(LOG_ERROR, "wai_sem => %d", ret);
 			}
-			T_NET_BUF *input = fp->psock->input;
+			T_NET_BUF *input = socket->input;
 			if (input == NULL) {
 				ret = sig_sem(SEM_FILEDESC);
@@ -552,8 +588,9 @@
 
 				T_IPV4EP rep = { 0, 0 };
-				ret = udp_rcv_dat(fp->psock->cepid, &rep, buf, len,
-					(fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+				ret = udp_rcv_dat(socket->cepid, &rep, buf, len,
+					(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
 				if (ret < 0) {
-					syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
+					if ((socket->flags & O_NONBLOCK) == 0)
+						syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
 					return (ret == E_TMOUT) ? -ETIME : -ECOMM;
 				}
@@ -565,10 +602,10 @@
 					}
 					int sz = *alen;
-					memset(raddr, 0, sizeof(fp->psock->raddr4));
+					memset(raddr, 0, sizeof(socket->raddr4));
 					raddr->sin_family = AF_INET;
 					raddr->sin_port = htons(rep.portno);
 					raddr->sin_addr.s_addr = htonl(rep.ipaddr);
-					if (sz > sizeof(fp->psock->raddr4))
-						sz = sizeof(fp->psock->raddr4);
+					if (sz > sizeof(socket->raddr4))
+						sz = sizeof(socket->raddr4);
 					memcpy(addr, raddr, sz);
 					*alen = sz;
@@ -580,13 +617,13 @@
 			}
 			else {
-				rsz = fp->psock->len;
-				void *pbuf = fp->psock->buf;
-				fp->psock->input = NULL;
-				fp->psock->len = 0;
-				fp->psock->buf = NULL;
+				rsz = socket->len;
+				void *pbuf = socket->buf;
+				socket->input = NULL;
+				socket->len = 0;
+				socket->buf = NULL;
 				if ((addr != NULL) && (alen != NULL)) {
 					int sz = *alen;
-					if (sz > sizeof(fp->psock->raddr4))
-						sz = sizeof(fp->psock->raddr4);
+					if (sz > sizeof(socket->raddr4))
+						sz = sizeof(socket->raddr4);
 					memcpy(addr, raddr, sz);
 					*alen = sz;
@@ -632,9 +669,10 @@
 
 	ER ret;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
-			ret = tcp_sht_cep(fp->psock->cepid);
+			ret = tcp_sht_cep(socket->cepid);
 			if (ret < 0) {
 				return -ECOMM;
@@ -661,7 +699,8 @@
 
 	ER ret;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			switch (level) {
@@ -669,5 +708,5 @@
 				switch (optname) {
 				case SO_REUSEADDR:
-					if (fp->psock->flags & SO_REUSEADDR) {
+					if (socket->flags & SO_REUSEADDR) {
 						*(bool *)optval = true;
 					}
@@ -677,5 +716,5 @@
 					break;
 				case SO_KEEPALIVE:
-					if (fp->psock->flags & SO_KEEPALIVE) {
+					if (socket->flags & SO_KEEPALIVE) {
 						*(bool *)optval = true;
 					}
@@ -692,5 +731,5 @@
 				break;
 			case IPPROTO_TCP:
-				ret = tcp_get_opt(fp->psock->cepid, optname, (void *)optval, *optlen);
+				ret = tcp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
 				if (ret < 0) {
 					return -EINVAL;
@@ -706,5 +745,5 @@
 			switch (level) {
 			case IPPROTO_UDP:
-				ret = udp_get_opt(fp->psock->cepid, optname, (void *)optval, *optlen);
+				ret = udp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
 				if (ret < 0) {
 					return -EINVAL;
@@ -736,7 +775,8 @@
 
 	ER ret;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			switch (level){
@@ -745,16 +785,16 @@
 				case SO_REUSEADDR:
 					if (*(bool *)optval) {
-						fp->psock->flags |= SO_REUSEADDR;
+						socket->flags |= SO_REUSEADDR;
 					}
 					else {
-						fp->psock->flags &= ~SO_REUSEADDR;
+						socket->flags &= ~SO_REUSEADDR;
 					}
 					break;
 				case SO_KEEPALIVE:
 					if (*(bool *)optval) {
-						fp->psock->flags |= SO_KEEPALIVE;
+						socket->flags |= SO_KEEPALIVE;
 					}
 					else {
-						fp->psock->flags &= ~SO_KEEPALIVE;
+						socket->flags &= ~SO_KEEPALIVE;
 					}
 					break;
@@ -764,5 +804,5 @@
 				break;
 			case IPPROTO_TCP:
-				ret = tcp_set_opt(fp->psock->cepid, optname, (void *)optval, optlen);
+				ret = tcp_set_opt(socket->cepid, optname, (void *)optval, optlen);
 				if (ret < 0) {
 					return -EINVAL;
@@ -777,5 +817,5 @@
 			switch (level){
 			case IPPROTO_UDP:
-				ret = udp_set_opt(fp->psock->cepid, optname, (void *)optval, optlen);
+				ret = udp_set_opt(socket->cepid, optname, (void *)optval, optlen);
 				if (ret < 0) {
 					return -EINVAL;
@@ -809,7 +849,8 @@
 
 	socklen_t size = *len;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		struct sockaddr_in *raddr = &fp->psock->raddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
 		*len = sizeof(struct sockaddr_in);
 		if (size > sizeof(struct sockaddr_in))
@@ -837,5 +878,6 @@
 
 	socklen_t size = *len;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
 		const T_IN4_ADDR *laddr4 = in4_get_ifaddr(0);
@@ -843,5 +885,5 @@
 		laddr.sin_family = AF_INET;
 		laddr.sin_addr.s_addr = htonl(*laddr4);
-		laddr.sin_port = fp->psock->laddr4.sin_port;
+		laddr.sin_port = socket->laddr4.sin_port;
 		memset(&laddr.sin_zero, 0, sizeof(laddr.sin_zero));
 		*len = sizeof(struct sockaddr_in);
@@ -859,21 +901,20 @@
 }
 
-int tcp_fd_close(struct _IO_FILE *fp)
+int tcp_fd_close(struct SHELL_FILE *fp)
 {
 	ER ret, ret2;
 
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		if (fp->psock->cepid != 0) {
-			ID cepid = fp->psock->cepid;
+		if (socket->cepid != 0) {
+			ID cepid = socket->cepid;
 			ret = tcp_sht_cep(cepid);
 			if (ret < 0) {
 				//return -1;
 			}
-			ret = tcp_cls_cep(cepid, (fp->psock->repid != 0) ? 0 : SOCKET_TIMEOUT);
+			ret = tcp_cls_cep(cepid, (socket->repid != 0) ? 0 : SOCKET_TIMEOUT);
 			ret2 = tcp_del_cep(cepid);
-			free(fp->psock->buf);
-			fp->psock->buf = NULL;
-			delete_tcp_fd(cepid);
+			//delete_fd_by_id(&IO_TYPE_TCP, cepid);
 			delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
 			if ((ret < 0) || (ret2 < 0)) {
@@ -881,10 +922,8 @@
 			}
 		}
-		else if (fp->psock->repid != 0) {
-			ID repid = fp->psock->repid;
+		else if (socket->repid != 0) {
+			ID repid = socket->repid;
 			ret = tcp_del_rep(repid);
-			free(fp->psock->buf);
-			fp->psock->buf = NULL;
-			delete_tcp_fd(tmax_tcp_cepid + repid);
+			//delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + repid);
 			delete_id(tcp_repid_table, tcp_repid_table_count, repid);
 			if (ret < 0) {
@@ -893,6 +932,4 @@
 		}
 		else {
-			free(fp->psock->buf);
-			fp->psock->buf = NULL;
 			return -EINVAL;
 		}
@@ -907,36 +944,157 @@
 }
 
-size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
+size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
 {
 	return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
 }
 
-size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
+size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
 {
 	return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
 }
 
-off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
+off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
 {
 	return -EPERM;
 }
 
-int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
+int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	return -EINVAL;
 }
 
-int udp_fd_close(struct _IO_FILE *fp)
+bool_t tcp_fd_readable(struct SHELL_FILE *fp)
+{
+	ER ret;
+
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->cepid != 0) {
+		if (socket->len == 0) {
+			ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_NBLK);
+			if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
+				syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
+				//return ret;
+			}
+			if (ret > 0) {
+				ret = wai_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "wai_sem => %d", ret);
+				}
+				socket->len += ret;
+				ret = sig_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "sig_sem => %d", ret);
+				}
+			}
+		}
+		else ret = 1;
+		if (ret > 0) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void tcp_fd_delete(struct SHELL_FILE *fp)
+{
+	socket_t *socket = (socket_t *)fp->exinf;
+	free(socket->buf);
+	socket->buf = NULL;
+	free(fp->exinf);
+	fp->exinf = NULL;
+}
+
+ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)
+{
+	struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_TCP, cepid);
+	FLGPTN flgptn = 0;
+	ER ret;
+	int len;
+
+	if (fp == NULL)
+		return E_PAR;
+
+	int fd = fp->fd;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	switch (fncd) {
+	case TFN_TCP_RCV_BUF:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket_t *socket = (socket_t *)fp->exinf;
+		socket->len += len;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_RCV_DAT:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket->len += len;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_SND_DAT:
+		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_CAN_CEP:
+		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_DEL_REP:
+		delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + cepid);
+		return E_OK;
+
+	case TFN_TCP_DEL_CEP:
+		delete_fd_by_id(&IO_TYPE_TCP, cepid);
+		return E_OK;
+
+	default:
+		return E_OK;
+	}
+}
+
+int udp_fd_close(struct SHELL_FILE *fp)
 {
 	ER ret;
 	ID cepid;
 
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		cepid = fp->psock->cepid;
+		cepid = socket->cepid;
 		ret = udp_del_cep(cepid);
-		//free(fp->psock->buf);
-		//fp->psock->buf = NULL;
-		delete_udp_fd(cepid);
+		//delete_fd_by_id(&IO_TYPE_UDP, cepid);
 		delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
 		if (ret < 0) {
@@ -953,22 +1111,126 @@
 }
 
-size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
+size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
 {
 	return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
 }
 
-size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
+size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
 {
 	return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
 }
 
-off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
+off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
 {
 	return -EPERM;
 }
 
-int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
+int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	return -EINVAL;
+}
+
+bool_t udp_fd_readable(struct SHELL_FILE *fp)
+{
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->cepid != 0) {
+		if (socket->input != NULL) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void udp_fd_delete(struct SHELL_FILE *fp)
+{
+	//socket_t *socket = (socket_t *)fp->exinf;
+	//free(socket->buf);
+	//socket->buf = NULL;
+	free(fp->exinf);
+	fp->exinf = NULL;
+}
+
+ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)
+{
+	struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_UDP, cepid);
+	FLGPTN flgptn = 0;
+	int len;
+
+	if (fp == NULL)
+		return E_PAR;
+
+	int fd = fp->fd;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	switch (fncd) {
+	case TEV_UDP_RCV_DAT:
+	{
+		T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
+		len = udppara->len;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ER ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket_t *socket = (socket_t *)fp->exinf;
+		socket->len = len;
+		if (socket->input != NULL) {
+			ret = rel_net_buf(socket->input);
+			if (ret < 0) {
+				syslog(LOG_ERROR, "rel_net_buf => %d", ret);
+			}
+		}
+		socket->input = udppara->input;
+		socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
+		memset(&socket->raddr4, 0, sizeof(socket->raddr4));
+		socket->raddr4.sin_family = AF_INET;
+		socket->raddr4.sin_port = htons(udppara->rep4.portno);
+		socket->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);
+		udppara->input->flags |= NB_FLG_NOREL_IFOUT;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+	}
+	case TFN_UDP_CRE_CEP:
+		return E_OK;
+
+	case TFN_UDP_RCV_DAT:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_SND_DAT:
+		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_CAN_CEP:
+		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_DEL_CEP:
+		delete_fd_by_id(&IO_TYPE_UDP, cepid);
+		return E_OK;
+
+	default:
+		return E_OK;
+	}
 }
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h	(revision 374)
@@ -103,18 +103,15 @@
 } socket_t;
 
-struct _IO_DIR {
-	DIR dir;
+struct SHELL_DIR {
+	FATFS_DIR dir;
 	struct dirent dirent;
 };
 
-struct _IO_FILE {
+typedef const struct io_type_s IO_TYPE;
+
+struct SHELL_FILE {
 	int fd;
-	int type;
+	IO_TYPE *type;
 	int handle;
-	int (*close)(struct _IO_FILE *);
-	size_t (*read)(struct _IO_FILE *, unsigned char *, size_t);
-	size_t (*write)(struct _IO_FILE *, const unsigned char *, size_t);
-	off_t (*seek)(struct _IO_FILE *, off_t, int);
-	int (*ioctl)(struct _IO_FILE *, int, void *);
 	int readevt_r;
 	int readevt_w;
@@ -124,9 +121,15 @@
 	int errorevt_r;
 	int errorevt_w;
-	union {
-		FIL *pfile;
-		struct _IO_DIR *pdir;
-		socket_t *psock;
-	};
+	void *exinf;
+};
+
+struct io_type_s {
+	int (*close)(struct SHELL_FILE *);
+	size_t (*read)(struct SHELL_FILE *, unsigned char *, size_t);
+	size_t (*write)(struct SHELL_FILE *, const unsigned char *, size_t);
+	off_t (*seek)(struct SHELL_FILE *, off_t, int);
+	int (*ioctl)(struct SHELL_FILE *, int, void *);
+	bool_t (*readable)(struct SHELL_FILE *);
+	void (*delete)(struct SHELL_FILE *);
 };
 
@@ -141,65 +144,10 @@
 #endif
 
-extern int stdio_close(struct _IO_FILE *fp);
-extern size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
+struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable);
+int delete_fd_by_id(IO_TYPE *type, int id);
+struct SHELL_FILE *fd_to_fp(int fd);
+struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id);
 
-extern int sio_close(struct _IO_FILE *fp);
-extern size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int sio_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int file_close(struct _IO_FILE *fp);
-extern size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t file_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int file_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int dir_close(struct _IO_FILE *fp);
-extern size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t dir_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int dir_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int tcp_fd_close(struct _IO_FILE *fp);
-extern size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int udp_fd_close(struct _IO_FILE *fp);
-extern size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-struct _IO_FILE *fd_to_fp(int fd);
-
-struct _IO_FILE *new_sio_fd(int sioid);
-int delete_sio_fd(int sioid);
-struct _IO_FILE *sioid_to_fd(int sioid);
-
-struct _IO_FILE *new_file_fd(int fileid);
-int delete_file_fd(int fileid);
-struct _IO_FILE *fileid_to_fd(int fileid);
-
-struct _IO_FILE *new_dir_fd(int dirid);
-int delete_dir_fd(int dirid);
-struct _IO_FILE *dirid_to_fd(int dirid);
-
-struct _IO_FILE *new_tcp_fd(int tcpid);
-int delete_tcp_fd(int tcpid);
-struct _IO_FILE *tcpid_to_fd(int tcpid);
-
-struct _IO_FILE *new_udp_fd(int udpid);
-int delete_udp_fd(int udpid);
-struct _IO_FILE *udpid_to_fd(int udpid);
-
-int delete_fp(struct _IO_FILE *fp);
-int delete_tcp_rep(int repid);
+int delete_fp(struct SHELL_FILE *fp);
 void clean_fd();
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c	(revision 367)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c	(revision 374)
@@ -48,9 +48,9 @@
 
 	/* ==== Cleaning and invalidation of the L1 data cache ==== */
-	__v7_all_cache(2);
+	L1C_CleanInvalidateDCacheAll();
 	__DSB();
 
 	/* ==== Cleaning and invalidation of the L2 cache ==== */
-	if (PL310->AUX_CNT & (1 << 16)) {
+	if (L2C_310->AUX_CNT & (1 << 16)) {
 		assoc = 16;
 	}
@@ -58,13 +58,13 @@
 		assoc = 8;
 	}
-	PL310->INV_WAY = (1 << assoc) - 1;
-	while (PL310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate
-	PL310->CACHE_SYNC = 0x0;
+	L2C_310->INV_WAY = (1 << assoc) - 1;
+	while (L2C_310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate
+	L2C_310->CACHE_SYNC = 0x0;
 
 	/* ==== Invalidate all TLB entries ==== */
-	__ca9u_inv_tlb_all();
+	MMU_InvalidateTLB();
 
 	/* ==== Invalidate the L1 instruction cache ==== */
-	__v7_inv_icache_all();
+	L1C_InvalidateICacheAll();
 	__DSB();
 	__ISB();
@@ -184,5 +184,6 @@
 }
 
-long SYS_fdatasync() {
+long SYS_fdatasync(long a) {
+	//int fdatasync(int fd)
 	return no_implement("fdatasync\n");
 }
@@ -200,10 +201,11 @@
 }
 
-long SYS_futex() {
-	int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
+long SYS_futex(long a, long b, long c, long d, long e, long f) {
+	//int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
 	return no_implement("futex\n");
 }
 
-long SYS_futimesat() {
+long SYS_futimesat(long a, long b, long c) {
+	//int futimesat(int dirfd, const char *pathname, const struct timeval times[2])
 	return no_implement("futimesat\n");
 }
@@ -281,5 +283,6 @@
 }
 
-long SYS_munmap() {
+long SYS_munmap(long a, long b) {
+	//int munmap(void *start, size_t len)
 	return no_implement("munmap\n");
 }
@@ -293,9 +296,13 @@
 }
 
-long SYS_pread64() {
+long SYS_pread64(long a, long b, long c, long d) {
+	//#define pread64 pread
+	//ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
 	return no_implement("pread64\n");
 }
 
-long SYS_pwrite64() {
+long SYS_pwrite64(long a, long b, long c, long d) {
+	//#define pwrite64 pwrite
+	//ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
 	return no_implement("pwrite64\n");
 }
@@ -337,5 +344,6 @@
 }
 
-long SYS_rt_sigqueueinfo() {
+long SYS_rt_sigqueueinfo(long a, long b, long c) {
+	//int rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *uinfo)
 	return no_implement("rt_sigqueueinfo\n");
 }
@@ -361,9 +369,11 @@
 }
 
-long SYS_sched_setscheduler() {
+long SYS_sched_setscheduler(long a, long b, long c) {
+	//int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param)
 	return no_implement("sched_setscheduler\n");
 }
 
-long SYS_set_robust_list() {
+long SYS_set_robust_list(long a, long b) {
+	//long set_robust_list(struct robust_list_head *head, size_t len)
 	return no_implement("set_robust_list\n");
 }
@@ -401,9 +411,11 @@
 }
 
-long SYS_utimensat() {
+long SYS_utimensat(long a, long b, long c, long d) {
+	//int utimensat(int fd, const char *path, const struct timespec times[2], int flags)
 	return no_implement("utimensat\n");
 }
 
-long SYS_utimes() {
+long SYS_utimes(long a, long b) {
+	//int utimes(const char *path, const struct timeval times[2])
 	return no_implement("utimes\n");
 }
@@ -417,57 +429,134 @@
 }
 
-long SYS_dup()
-{
+long SYS_dup(long a) {
+	//int dup(int fd)
 	return no_implement("dup\n");
 }
 
-long SYS_dup2()
-{
+long SYS_dup2(long a, long b) {
+	//int dup2(int old, int new)
 	return no_implement("dup2\n");
 }
 
-long SYS_pipe()
-{
+long SYS_pipe(long a) {
+	//int pipe(int fd[2])
 	return no_implement("pipe\n");
 }
 
-long SYS_readlink()
-{
+long SYS_readlink(long a, long b, long c) {
+	//ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
 	return no_implement("readlink\n");
 }
 
-long SYS_symlink()
-{
+long SYS_symlink(long a, long b) {
+	//int symlink(const char *existing, const char *new)
 	return no_implement("symlink\n");
 }
 
-long SYS_umask()
-{
+long SYS_umask(long a) {
+	//mode_t umask(mode_t mode)
 	return no_implement("umask\n");
 }
 
-long SYS_execve()
-{
+long SYS_execve(long a, long b, long c) {
+	//int execve(const char *path, char *const argv[], char *const envp[])
 	return no_implement("execve\n");
 }
 
-long SYS_fork()
-{
+long SYS_fork() {
+	//pid_t fork(void)
 	return no_implement("fork\n");
 }
 
-long SYS_wait4()
-{
+long SYS_wait4(long a, long b, long c, long d) {
+	//pid_t wait4(pid_t pid, int *status, int options, struct rusage *usage)
 	return no_implement("wait4\n");
 }
 
-long SYS_socketpair()
-{
+long SYS_socketpair(long a, long b, long c, long d) {
+	//int socketpair(int domain, int type, int protocol, int fd[2])
 	return no_implement("socketpair\n");
 }
 
-long SYS_flock()
-{
+long SYS_flock(long a, long b) {
+	//int flock(int fd, int op)
 	return no_implement("flock\n");
+}
+
+long SYS_fchdir()
+{
+	return no_implement("fchdir\n");
+}
+
+long SYS_getegid32()
+{
+	return no_implement("getegid32\n");
+}
+
+long SYS_geteuid32()
+{
+	return no_implement("geteuid32\n");
+}
+
+long SYS_getgid32()
+{
+	return no_implement("getgid32\n");
+}
+
+long SYS_pipe2()
+{
+	return no_implement("pipe2\n");
+}
+
+long SYS_setgid32()
+{
+	return no_implement("setgid32\n");
+}
+
+long SYS_setpgid()
+{
+	return no_implement("setpgid\n");
+}
+
+long SYS_setsid()
+{
+	return no_implement("setsid\n");
+}
+
+long SYS_setuid32()
+{
+	return no_implement("setuid32\n");
+}
+
+long SYS_tgkill()
+{
+	return no_implement("tgkill\n");
+}
+
+long SYS_nanosleep(long a, long b) {
+	//int nanosleep(const struct timespec *req, struct timespec *rem)
+	return no_implement("nanosleep\n");
+}
+
+long SYS_prlimit64(long a, long b, long c, long d) {
+	//#define prlimit64 prlimit
+	//int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit)
+	return no_implement("prlimit64\n");
+}
+
+long SYS_sched_getaffinity(long a, long b, long c) {
+	//int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
+	return no_implement("sched_getaffinity\n");
+}
+
+long SYS_sysinfo(long a) {
+	//int sysinfo(struct sysinfo *info)
+	return no_implement("sysinfo\n");
+}
+
+long SYS_ugetrlimit(long a, long b) {
+	//#define SYS_getrlimit SYS_ugetrlimit
+	//int getrlimit(int resource, struct rlimit *rlim)
+	return no_implement("ugetrlimit\n");
 }
 
