Index: EcnlProtoTool/trunk/ntshell/src/bits/alltypes.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/bits/alltypes.h	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/bits/alltypes.h	(revision 331)
@@ -0,0 +1,1 @@
+#include "../musl-1.1.18/include/bits/alltypes.h"
Index: EcnlProtoTool/trunk/ntshell/src/bits/fcntl.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/bits/fcntl.h	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/bits/fcntl.h	(revision 331)
@@ -0,0 +1,1 @@
+#include "../musl-1.1.18/include/bits/fcntl.h"
Index: EcnlProtoTool/trunk/ntshell/src/bits/ioctl_fix.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/bits/ioctl_fix.h	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/bits/ioctl_fix.h	(revision 331)
@@ -0,0 +1,1 @@
+#include "../musl-1.1.18/include/bits/ioctl_fix.h"
Index: EcnlProtoTool/trunk/ntshell/src/bits/signal.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/bits/signal.h	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/bits/signal.h	(revision 331)
@@ -0,0 +1,1 @@
+#include "../musl-1.1.18/include/bits/signal.h"
Index: EcnlProtoTool/trunk/ntshell/src/bits/socket.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/bits/socket.h	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/bits/socket.h	(revision 331)
@@ -0,0 +1,1 @@
+#include "../musl-1.1.18/include/bits/socket.h"
Index: EcnlProtoTool/trunk/ntshell/src/fdtable.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/fdtable.c	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/fdtable.c	(revision 331)
@@ -35,17 +35,10 @@
  *  @(#) $Id$
  */
+#include "shellif.h"
 #include <stdint.h>
-#include <stdio.h>
-#include <sys/unistd.h>
-#include <limits.h>
 #include <kernel.h>
 #include <t_syslog.h>
 #include <t_stdlib.h>
 #include <sil.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <setjmp.h>
-#include "../../../musl-1.1.12/include/poll.h"
 #include "syssvc/serial.h"
 #include "syssvc/syslog.h"
@@ -61,8 +54,9 @@
 #include <net/if_var.h>
 #include <netinet/udp_var.h>
-#include <ethernet_api.h>
+//#include <ethernet_api.h>
 #include "ff.h"
 #include "socket_stub.h"
 #include "kernel_cfg.h"
+#include <string.h>
 
 #define SIO_PORTID 1
@@ -71,11 +65,12 @@
 #define IO_TYPE_SIO		1
 #define IO_TYPE_FILE	2
-#define IO_TYPE_TCP		3
-#define IO_TYPE_UDP		4
+#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 },
-	{ 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write },
-	{ 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write },
+	{ 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 },
 };
 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0]))
@@ -94,5 +89,5 @@
 	}
 
-	return -1;
+	return -ENOMEM;
 }
 
@@ -112,5 +107,5 @@
 	struct _IO_FILE *fp = id_to_fd(type, id);
 	if (fp == NULL)
-		return -1;
+		return -EBADF;
 
 	memset(fp, 0, sizeof(struct _IO_FILE));
@@ -136,4 +131,6 @@
 	fp->read = sio_read;
 	fp->write = sio_write;
+	fp->seek = sio_seek;
+	fp->ioctl = sio_ioctl;
 
 	return fp;
@@ -160,4 +157,6 @@
 	fp->read = file_read;
 	fp->write = file_write;
+	fp->seek = file_seek;
+	fp->ioctl = file_ioctl;
 
 	return fp;
@@ -172,4 +171,30 @@
 {
 	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;
+
+	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);
 }
 
@@ -184,4 +209,6 @@
 	fp->read = tcp_fd_read;
 	fp->write = tcp_fd_write;
+	fp->seek = tcp_fd_seek;
+	fp->ioctl = tcp_fd_ioctl;
 
 	return fp;
@@ -208,4 +235,6 @@
 	fp->read = udp_fd_read;
 	fp->write = udp_fd_write;
+	fp->seek = udp_fd_seek;
+	fp->ioctl = udp_fd_ioctl;
 
 	return fp;
@@ -220,16 +249,4 @@
 {
 	return id_to_fd(IO_TYPE_UDP, udpid);
-}
-
-int shell_isatty(int fd)
-{
-	if ((fd < 0) || (fd >= fd_table_count))
-		return 0;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	if (fp->type == IO_TYPE_SIO)
-		return 1;
-
-	return 0;
 }
 
@@ -245,5 +262,5 @@
 #define TMO_MAX INT_MAX
 
-int select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
+int shell_select(int n, fd_set *__restrict rfds, fd_set *__restrict wfds, fd_set *__restrict efds, struct timeval *__restrict tv)
 {
 	ER ret;
@@ -277,8 +294,8 @@
 	}
 
-	return -1;
-}
-
-int poll(struct pollfd *fds, nfds_t nfds, int timeout)
+	return -EBADF;
+}
+
+int shell_poll(struct pollfd *fds, nfds_t nfds, int timeout)
 {
 	ER ret;
@@ -334,5 +351,5 @@
 	}
 
-	return -1;
+	return -EBADF;
 }
 
@@ -541,2 +558,11 @@
 	}
 }
+
+int shell_ioctl(int fd, int request, void *arg)
+{
+	struct _IO_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	return fp->ioctl(fp, request, arg);
+}
Index: EcnlProtoTool/trunk/ntshell/src/features.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/features.h	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/features.h	(revision 331)
@@ -0,0 +1,1 @@
+#include "../musl-1.1.18/include/features.h"
Index: EcnlProtoTool/trunk/ntshell/src/io_stub.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/io_stub.c	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/io_stub.c	(revision 331)
@@ -35,9 +35,6 @@
  *  @(#) $Id$
  */
+#include "shellif.h"
 #include <stdint.h>
-#include <stdio.h>
-#include <sys/unistd.h>
-#include <limits.h>
-#include <fcntl.h>
 #include "ff.h"
 #include <kernel.h>
@@ -45,7 +42,5 @@
 #include <t_stdlib.h>
 #include <sil.h>
-#include <stdlib.h>
 #include <string.h>
-#include <stdio.h>
 #include <setjmp.h>
 #include "syssvc/syslog.h"
@@ -61,18 +56,59 @@
 #include <net/if_var.h>
 #include <netinet/udp_var.h>
-#include <ethernet_api.h>
-#include "ff.h"
+//#include <ethernet_api.h>
 #include "socket_stub.h"
-#include "../../../musl-1.1.12/include/_dirent.h"
-#include "../../../musl-1.1.12/include/_termios.h"
-#include "ntstdio.h"
-
-int shell_open(const char * path, int flags)
-{
-	FRESULT res;
-
-	struct _IO_FILE *fp = new_file_fd(0);
-	if (fp == NULL)
-		return -1;
+//#include <sys/stat.h>
+#include "util/ntstdio.h"
+#include "usrcmd.h"
+#include "core/ntlibc.h"
+
+int fresult2errno(FRESULT res)
+{
+	switch (res) {
+	case FR_INVALID_OBJECT:
+		return -EINVAL;
+	case FR_TOO_MANY_OPEN_FILES:
+		return -ENOMEM;
+	case FR_NO_FILE:
+	case FR_NO_PATH:
+	case FR_INVALID_DRIVE:
+	case FR_INVALID_NAME:
+		return -ENOENT;
+	case FR_DISK_ERR:
+	case FR_NO_FILESYSTEM:
+	case FR_NOT_ENABLED:
+		return -ENODEV;
+	case FR_WRITE_PROTECTED:
+	case FR_DENIED:
+		return -EACCES;
+	case FR_EXIST:
+		return -EEXIST;
+	case FR_INT_ERR:
+	default:
+		return -EIO;
+	}
+}
+
+int shell_open(const char * path, int flags, void *arg)
+{
+	FRESULT res;
+	struct _IO_FILE *fp;
+
+	if (flags & O_DIRECTORY) {
+		fp = new_dir_fd(0);
+		if (fp == NULL)
+			return -ENOMEM;
+
+		DIR *dir = &fp->dir;
+		FRESULT res;
+		if ((res = f_opendir(dir, path)) != FR_OK) {
+			return fresult2errno(res);
+		}
+		return 0;
+	}
+
+	fp = new_file_fd(0);
+	if (fp == NULL)
+		return -ENOMEM;
 
 	BYTE fmd = 0;
@@ -115,5 +151,5 @@
 	}
 
-	return -1;
+	return fresult2errno(res);
 }
 
@@ -126,5 +162,5 @@
 	}
 
-	return -1;
+	return -EINVAL;
 }
 
@@ -135,5 +171,5 @@
 
 	if ((res = f_read(&fp->file, data, len, &ret)) != FR_OK)
-		return -1;
+		return -EIO;
 
 	return ret;
@@ -146,47 +182,111 @@
 
 	if ((res = f_write(&fp->file, data, len, &ret)) != FR_OK)
-		return -1;
+		return -EIO;
 
 	return ret;
 }
 
+off_t file_seek(struct _IO_FILE *fp, off_t ptr, int dir)
+{
+	switch (dir) {
+	case SEEK_SET:
+		dir = F_SEEK_SET;
+		break;
+	case SEEK_CUR:
+		dir = F_SEEK_CUR;
+		break;
+	case SEEK_END:
+		dir = F_SEEK_END;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	FRESULT res;
+	if ((res = f_seek(&fp->file, ptr, dir)) != FR_OK)
+		return -EIO;
+
+	return fp->file.fptr;
+}
+
+int file_ioctl(struct _IO_FILE *fp, int req, void *arg)
+{
+	DRESULT res;
+
+	if ((res = disk_ioctl(fp->file.fs->drv, req, arg) != RES_OK))
+		return -EINVAL;
+
+	return 0;
+}
+
 int shell_close(int fd)
 {
 	struct _IO_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
-		return -1;
+		return -EBADF;
 
 	return fp->close(fp);
 }
 
-int shell_read(int fd, char *data, int len)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -1;
+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);
 }
 
-int shell_write(int fd, char *data, int len)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -1;
+int shell_readv(int fd, const struct iovec *iov, int iovcnt)
+{
+	int result = 0;
+	struct _IO_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	const struct iovec *end = &iov[iovcnt];
+	for (; iov < end; iov++) {
+		result += fp->read(fp, (unsigned char *)iov->iov_base, iov->iov_len);
+	}
+
+	return result;
+}
+
+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);
 }
 
-int shell_lseek(int fd, int ptr, int dir)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -1;
-
-	FRESULT res;
-	if ((res = f_seek(&fp->file, ptr, dir)) != FR_OK)
-		return -1;
-
-	return fp->file.fptr;
+int shell_writev(int fd, const struct iovec *iov, int iovcnt)
+{
+	int result = 0;
+	struct _IO_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	const struct iovec *end = &iov[iovcnt];
+	for (; iov < end; iov++) {
+		result += fp->write(fp, (unsigned char *)iov->iov_base, iov->iov_len);
+	}
+
+	return result;
+}
+
+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);
+	if (ret < 0)
+		return ret;
+
+	*result = ret;
+	return 0;
 }
 
@@ -195,5 +295,5 @@
 	struct _IO_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
-		return -1;
+		return -EBADF;
 
 	memset(st, 0, sizeof(*st));
@@ -203,34 +303,31 @@
 }
 
-int fsync(int fd)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -1;
-	return -1;
-}
-
-int ftruncate(int fd, off_t length)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -1;
+int shell_fsync(int fd)
+{
+	struct _IO_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+	return -EIO;
+}
+
+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->file)) != FR_OK)
-		return -1;
-
-	return 0;
-}
-
-int ioctl(int fd, int request, va_list ap)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -1;
-	return -1;
-}
-
-int tcgetattr(int fd, struct termios *termios)
+		return fresult2errno(res);
+
+	return 0;
+}
+
+int shell_fcntl(int fd, int cmd, void *arg)
+{
+	return shell_ioctl(fd, cmd, arg);
+}
+
+int sio_tcgetattr(int fd, struct termios *termios)
 {
 	extern ntstdio_t ntstdio;
@@ -265,9 +362,9 @@
 		return 0;
 	}
-	abort();
-	return 0;
-}
-
-int tcsetattr(int fd, int optional_actions, const struct termios *termios)
+	shell_abort();
+	return 0;
+}
+
+int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)
 {
 	extern ntstdio_t ntstdio;
@@ -300,9 +397,9 @@
 		return 0;
 	}
-	abort();
-	return 0;
-}
-
-int shell_stat(const char *path, struct stat *st)
+	shell_abort();
+	return 0;
+}
+
+int shell_stat(const char *__restrict path, struct stat *__restrict st)
 {
 	FILINFO fi;
@@ -313,27 +410,29 @@
 	fi.lfsize = sizeof lfn;
 #endif
-	if (strcmp(path, ".") == 0) {
+	if (ntlibc_strcmp(path, ".") == 0) {
 		char cwd[_MAX_LFN];
 		if ((ret = f_getcwd(cwd, sizeof(cwd))) != FR_OK) {
-		return -1;
-		}
-		int l = strlen(cwd);
+			return fresult2errno(ret);
+		}
+		int l = ntlibc_strlen(cwd);
 		// ルートディレクトリの場合
 		if (cwd[l - 2] == ':' && cwd[l - 1] == '/') {
 			st->st_size = 0;
-			st->st_mtime = 0;
+			st->st_mtim.tv_nsec = 0;
+			st->st_mtim.tv_sec = 0;
 			st->st_mode = S_IFDIR;
 			return 0;
 		}
 		if ((ret = f_stat(cwd, &fi)) != FR_OK) {
-			return -1;
+			return fresult2errno(ret);
 		}
 	}
 	else if ((ret = f_stat(path, &fi)) != FR_OK) {
-		return -1;
+		return fresult2errno(ret);
 	}
 
 	st->st_size = fi.fsize;
-	st->st_mtime = fi.fdate + fi.ftime;
+	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 |= (fi.fattrib & AM_RDO) ? 0 : (S_IWUSR | S_IWGRP | S_IWOTH);
@@ -343,7 +442,12 @@
 }
 
-int shell_link(void)
-{
-	return -1;
+int shell_lstat(const char *__restrict path, struct stat *__restrict st)
+{
+	return shell_stat(path, st);
+}
+
+int shell_link(const char *a, const char *b)
+{
+	return -EPERM;
 }
 
@@ -353,15 +457,15 @@
 
 	if ((res = f_unlink(path)) != FR_OK)
-		return -1;
-
-	return 0;
-}
-
-int rmdir(const char *path)
+		return -EIO;
+
+	return 0;
+}
+
+int shell_rmdir(const char *path)
 {
 	FRESULT res;
 
 	if ((res = f_unlink(path)) != FR_OK)
-		return -1;
+		return -EIO;
 
 	return 0;
@@ -373,14 +477,17 @@
 
 	if ((res = f_rename(oldpath, newpath)) != FR_OK)
-		return -1;
-	return 0;
-}
-
-int mkdir(const char *path, mode_t mode)
+		return fresult2errno(res);
+	return 0;
+}
+
+#define S_IREAD S_IRUSR
+#define S_IWRITE S_IWUSR
+
+int shell_mkdir(const char *path, mode_t mode)
 {
 	FRESULT res;
 
 	if ((res = f_mkdir(path)) != FR_OK)
-		return -1;
+		return fresult2errno(res);
 
 	BYTE attr = 0;
@@ -397,13 +504,13 @@
 
 	if((res = f_chmod(path, attr, mask)) != FR_OK) {
-		return -1;
-	}
-
-	return 0;
-}
-
-int chmod(const char *path, mode_t mode)
-{
-	FRESULT ret;
+		return fresult2errno(res);
+	}
+
+	return 0;
+}
+
+int shell_chmod(const char *path, mode_t mode)
+{
+	FRESULT res;
 	BYTE attr = 0;
 	BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
@@ -418,12 +525,12 @@
 	}
 
-	if((ret = f_chmod(path, attr, mask)) != FR_OK) {
-		return -1;
-	}
-
-	return 0;
-}
-
-char *getcwd(char *buf, size_t size)
+	if((res = f_chmod(path, attr, mask)) != FR_OK) {
+		return fresult2errno(res);
+	}
+
+	return 0;
+}
+
+char *shell_getcwd(char *buf, size_t size)
 {
 	FRESULT ret;
@@ -435,48 +542,39 @@
 }
 
-int chdir(const char *path)
-{
-	FRESULT ret;
-	if ((ret = f_chdir(path)) != FR_OK) {
-		return -1;
-	}
-
-	return 0;
-}
-
-int chroot(const char *path)
-{
-	abort();
-	return -1;
-}
-
-DIR *opendir(const char *path)
-{
-	DIR *dir = malloc(sizeof(DIR) + sizeof(struct dirent));
-	FRESULT ret;
-	if ((ret = f_opendir(dir, path)) != FR_OK) {
-		free(dir);
-		return NULL;
-	}
-
-	dir->dirent = &dir[1];
-	return dir;
-}
-
-int closedir(DIR *dir)
-{
-	FRESULT ret;
-	if ((ret = f_closedir(dir)) != FR_OK) {
-		free(dir);
-		return -1;
-	}
-
-	free(dir);
-	return 0;
-}
-
-struct dirent *readdir(DIR *dir)
-{
-	struct dirent *de = dir->dirent;
+int shell_chdir(const char *path)
+{
+	FRESULT res;
+	if ((res = f_chdir(path)) != FR_OK) {
+		return fresult2errno(res);
+	}
+
+	return 0;
+}
+
+int shell_chroot(const char *path)
+{
+	shell_abort();
+	return -EPERM;
+}
+
+int dir_close(struct _IO_FILE *fp)
+{
+	FRESULT res;
+	if ((res = f_closedir(&fp->dir)) != FR_OK) {
+		return fresult2errno(res);
+	}
+
+	return 0;
+}
+
+int shell_getdents(int fd, struct dirent *de, size_t len)
+{
+	if (len < sizeof(struct dirent))
+		return -EINVAL;
+
+	struct _IO_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
 	FILINFO fno;
 #if _USE_LFN
@@ -485,40 +583,117 @@
 	fno.lfsize = sizeof lfn;
 #endif
-	FRESULT ret;
-	if ((ret = f_readdir(dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
-		return NULL;
+	FRESULT res;
+	if ((res = f_readdir(&fp->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
+		return fresult2errno(res);
 	}
 
 	memset(de, 0, sizeof(*de));
 #if _USE_LFN
-	strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));
+	ntlibc_strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));
 #else
-	strlcpy(de->d_name, fno.fname, sizeof(de->d_name));
+	ntlibc_strlcpy(de->d_name, fno.fname, sizeof(de->d_name));
 #endif
 
-	return de;
-}
-
-void rewinddir(DIR *dir)
-{
-	FRESULT ret;
-	if ((ret = f_rewinddir(dir)) != FR_OK) {
-		return;
-	}
-}
-
-void seekdir(DIR *dir, long pos)
-{
-	abort();
-}
-
-long telldir(DIR *dir)
-{
-	abort();
-	return 0;
-}
-
-int shell_getpid(int n)
+	return 0;
+}
+
+size_t dir_read(struct _IO_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)
+{
+	return -EPERM;
+}
+
+off_t dir_seek(struct _IO_FILE *fp, off_t ptr, int dir)
+{
+	FRESULT res;
+
+	if (dir != SEEK_SET)
+		return -EINVAL;
+
+	if (ptr == 0) {
+		if ((res = f_rewinddir(&fp->dir)) != FR_OK) {
+			return fresult2errno(res);
+		}
+	}
+	else {
+		FILINFO fno;
+#if _USE_LFN
+		static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
+		fno.lfname = lfn;
+		fno.lfsize = sizeof lfn;
+#endif
+		if ((res = f_rewinddir(&fp->dir)) != FR_OK) {
+			return fresult2errno(res);
+		}
+
+		for (int i = 0; i < ptr; i++) {
+			if ((res = f_readdir(&fp->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
+				return fresult2errno(res);
+			}
+		}
+	}
+
+	return ptr;
+}
+
+int dir_ioctl(struct _IO_FILE *fp, int req, void *arg)
+{
+	return -EINVAL;
+}
+
+pid_t shell_getpid(void)
 {
 	return 1;
 }
+
+int shell_access(const char *path, int mode)
+{
+	struct stat st;
+	int ret;
+
+	ret = shell_stat(path, &st);
+	if (ret != 0)
+		return ret;
+
+	return 0;
+}
+
+//#include "../musl-1.1.18/include/bits/limits.h"
+#define PAGE_SIZE 4096
+
+uint32_t  __CmdBase;
+uint32_t  __CmdLimit;
+
+void *shell_brk(void *addr)
+{
+	if (addr == 0) {
+		return (void *)((intptr_t)&__CmdBase + 0x20000);
+	}
+	if ((addr >= (intptr_t)&__CmdBase + 0x20000) && (addr < &__CmdLimit)) {
+		return addr;
+	}
+	return (void *)-1;
+}
+
+void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
+{
+	if (fd != -1)
+		return -EINVAL;
+
+	if ((length >= 0) && (length <= (intptr_t)&__CmdLimit - (intptr_t)&__CmdBase - 0x20000)) {
+		return &__CmdBase + 0x20000;
+	}
+	return (void *)-1;
+}
+
+int shell_mprotect(void *addr, size_t len, int prot)
+{
+	//if ((addr >= (intptr_t)&__CmdBase + 0x20000) && ((intptr_t)addr + len < &__CmdLimit)) {
+		return 0;
+	//}
+	//return -1;
+}
Index: EcnlProtoTool/trunk/ntshell/src/main.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/main.c	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/main.c	(revision 331)
@@ -40,12 +40,10 @@
  */
 
+#include "shellif.h"
 #include <kernel.h>
-#include <t_syslog.h>
 #include <t_stdlib.h>
 #include <sil.h>
-#include <stdlib.h>
+#include <setjmp.h>
 #include <string.h>
-#include <stdio.h>
-#include <setjmp.h>
 #include "syssvc/serial.h"
 #include "syssvc/syslog.h"
@@ -64,17 +62,13 @@
 #include <net/if_var.h>
 #include <netinet/udp_var.h>
-#include <ethernet_api.h>
 #include "ffarch.h"
-#include "gpio_api.h"
 #include "ff.h"
 #include "websocket_fbs.h"
-#include "ntshell.h"
-#include "ntstdio.h"
+#include "core/ntshell.h"
+#include "core/ntlibc.h"
+#include "util/ntstdio.h"
 #include "usrcmd.h"
-#include "ntopt.h"
-
-#ifndef _MSC_VER
-void strcpy_s(char *dst, int size, const char *src);
-#endif
+#include "util/ntopt.h"
+#include "socket_stub.h"
 
 ID ws_api_mailboxid = MAIN_DATAQUEUE;
@@ -86,6 +80,13 @@
 ntstdio_t ntstdio;
 
-const uint8_t mac_addr[6] = {0x00, 0x30, 0x13, 0x06, 0x62, 0xC0};
-const char host_name[] = "GR-PEACH";
+const uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC};
+const struct utsname host_name = {
+	"TOPPERS/ASP3",
+    "GR-PEACH",
+    "3.1.0",
+    "3.1.0",
+    "GR-PEACH",
+    "toppers.jp"
+};
 
 static void netif_link_callback(T_IFNET *ether);
@@ -228,5 +229,5 @@
 	char buf[1];
 	if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)
-		return -1;
+		return -EIO;
 	return buf[0];
 }
@@ -305,5 +306,5 @@
 
 	if (exec) {
-		strcpy_s(command, sizeof(command), "mruby -b 1:/upload/main.mrb");
+		ntlibc_strlcpy(command, "mruby -b 1:/upload/main.mrb", sizeof(command));
 
 		execute_command(1);
@@ -371,13 +372,13 @@
 }
 
-int gethostname(char *name, size_t len)
-{
-	return strlcpy(name, host_name, len);
-}
-
-static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj);
+int shell_uname(struct utsname *uts)
+{
+	return memcpy(uts, &host_name, sizeof(host_name));
+}
+
+static int usrcmd_ntopt_callback(long *args, void *extobj);
 int mruby_exit_code;
 volatile int mruby_state;
-typedef void (*PowerOn_Reset_t)(int argc, char **argv);
+typedef void (*PowerOn_Reset_t)(long *args);
 jmp_buf process_exit;
 
@@ -392,10 +393,52 @@
 }
 
-static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj)
-{
+typedef struct
+{
+	const cmd_table_t *table;
+	int count;
+} cmd_table_info_t;
+
+static const cmd_table_t cmdlist[] = {
+	{"cd", "change directory", usrcmd_cd },
+	{"ls", "list files", usrcmd_ls },
+	{"cp", "copy file", usrcmd_cp },
+	{"rm", "remove file", usrcmd_rm },
+	{"mv", "move file", usrcmd_mv },
+	{"mkdir", "Make directory", usrcmd_mkdir},
+	{"hexdump", "Hex dump", usrcmd_hexdump},
+	{"info", "This is a description text string for info command.", usrcmd_info},
+	{"exit", "Exit Natural Tyny Shell", usrcmd_exit},
+};
+cmd_table_info_t cmd_table_info = { cmdlist, sizeof(cmdlist) / sizeof(cmdlist[0]) };
+
+static int usrcmd_ntopt_callback(long *args, void *extobj)
+{
+	const cmd_table_t *p = cmd_table_info.table;
+	if (ntlibc_strcmp((const char *)args[1], "help") == 0) {
+		usrcmd_help(args[0], (char **)&args[1]);
+	}
+	else for (int i = 0; i < cmd_table_info.count; i++) {
+		if (ntlibc_strcmp((const char *)args[1], p->cmd) == 0) {
+			return p->func(args[0], (char **)&args[1]);
+		}
+		p++;
+	}
 	if (setjmp(process_exit) == 0) {
-		(*((PowerOn_Reset_t *)0x18200000))(argc, argv);
+		(*((PowerOn_Reset_t *)0x18200000))(args);
 	}
 	clean_fd();
+	return 0;
+}
+
+int usrcmd_help(int argc, char **argv)
+{
+	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");
+		p++;
+	}
 	return 0;
 }
@@ -422,4 +465,10 @@
 
 void shell_exit(int exitcd)
+{
+	mruby_exit_code = exitcd;
+	longjmp(process_exit, 1);
+}
+
+void shell_exit_group(int exitcd)
 {
 	mruby_exit_code = exitcd;
@@ -458,5 +507,5 @@
 static int cmd_execute(const char *text, void *extobj)
 {
-	strlcpy(command, text, sizeof(command));
+	ntlibc_strlcpy(command, text, sizeof(command));
 	return execute_command(1);
 }
@@ -464,15 +513,15 @@
 int stdio_close(struct _IO_FILE *fp)
 {
-	return -1;
+	return -EPERM;
 }
 
 size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
 {
-	return -1;
+	return -EPERM;
 }
 
 size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
 {
-	return -1;
+	return -EPERM;
 }
 
@@ -507,14 +556,141 @@
 int sio_close(struct _IO_FILE *fp)
 {
-	return -1;
+	return -EPERM;
 }
 
 size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
 {
-	return -1;
+	return -EPERM;
 }
 
 size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
 {
-	return -1;
-}
+	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;
+}
+
+int shell_clock_getres(clockid_t clk_id, struct timespec *res)
+{
+	if (clk_id != CLOCK_REALTIME)
+		return -EINVAL;
+
+	memset(&res->tv_sec, 0xFF, sizeof(res->tv_sec));
+	res->tv_nsec = 0;
+
+	return 0;
+}
+
+int shell_clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+	SYSTIM now = 0;
+
+	if (clk_id != CLOCK_REALTIME)
+		return -EINVAL;
+
+	get_tim(&now);
+	tp->tv_sec = now / 1000000;
+	tp->tv_nsec = (now % 1000000) * 1000;
+
+	return 0;
+}
+
+int shell_clock_settime(clockid_t clk_id, const struct timespec *tp)
+{
+	if (clk_id != CLOCK_REALTIME)
+		return -EINVAL;
+
+	rtc_write(tp->tv_sec);
+
+	return 0;
+}
+
+sigset_t g_sigmask;
+
+int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
+{
+	if (old != NULL)
+		memcpy(old, &g_sigmask, sizeof(sigset_t));
+
+	switch (how) {
+	case SIG_BLOCK:
+		for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {
+			g_sigmask.__bits[i] |= set->__bits[i];
+		}
+		break;
+	case SIG_UNBLOCK:
+		for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {
+			g_sigmask.__bits[i] &= ~set->__bits[i];
+		}
+		break;
+	case SIG_SETMASK:
+		memcpy(&g_sigmask, set, sizeof(sigset_t));
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+struct sigaction sigtable[6];
+
+int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
+{
+	struct sigaction *sat;
+
+	switch(sig){
+	case SIGALRM:
+		sat = &sigtable[0];
+		break;
+	case SIGFPE:
+		sat = &sigtable[1];
+		break;
+	case SIGILL:
+		sat = &sigtable[2];
+		break;
+	case SIGSEGV:
+		sat = &sigtable[3];
+		break;
+	case SIGBUS:
+		sat = &sigtable[4];
+		break;
+	case SIGABRT:
+		sat = &sigtable[5];
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (old != NULL)
+		memcpy(old, sat, sizeof(struct sigaction));
+
+	memcpy(sat, sa, sizeof(struct sigaction));
+
+	return 0;
+}
+
+int shell_madvise(void *a, size_t b, int c)
+{
+	return 0;
+}
+
Index: EcnlProtoTool/trunk/ntshell/src/main.cfg
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/main.cfg	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/main.cfg	(revision 331)
@@ -61,4 +61,4 @@
 CRE_SEM(SEM_FILESYSTEM, { TA_TPRI, 1, 1 });
 
-CRE_TSK(MRUBY_TASK, { TA_NULL, 0, mruby_task, MRUBY_PRIORITY, MRUBY_STACK_SIZE, (void *)0x20600000 });
+CRE_TSK(MRUBY_TASK, { TA_NULL, 0, mruby_task, MRUBY_PRIORITY, MRUBY_STACK_SIZE, (void *)0x20100000 });
 CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 });
Index: EcnlProtoTool/trunk/ntshell/src/main.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/main.h	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/main.h	(revision 331)
@@ -56,5 +56,5 @@
 
 #define MAIN_STACK_SIZE		2048	/* メインタスクのスタック領域のサイズ */
-#define MRUBY_STACK_SIZE	0x100000	/* mruby実行タスクのスタック領域のサイズ */
+#define MRUBY_STACK_SIZE	0x00800000	/* mruby実行タスクのスタック領域のサイズ */
 
 #define NUM_MAIN_DATAQUEUE	1	/* メインタスクで待ち受けているデータキューのサイズ */
Index: EcnlProtoTool/trunk/ntshell/src/mbedcall.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/mbedcall.c	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/mbedcall.c	(revision 331)
@@ -0,0 +1,394 @@
+/*
+ *  TOPPERS ECHONET Lite Communication Middleware
+ * 
+ *  Copyright (C) 2017 Cores Co., Ltd. Japan
+ * 
+ *  ä¸è¨èä½æ¨©è
+ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
+ *  ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ãä½¿ç¨ã»è¤è£½ã»æ¹
+ *  å¤ã»åé
+å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
+ *  (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
+ *      æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
+ *      ã¹ã³ã¼ãä¸­ã«å«ã¾ãã¦ãããã¨ï¼
+ *  (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
+ *      ç¨ã§ããå½¢ã§åé
+å¸ããå ´åã«ã¯ï¼åé
+å¸ã«ä¼´ããã­ã¥ã¡ã³ãï¼å©ç¨
+ *      è
+ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
+ *      ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
+ *  (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
+ *      ç¨ã§ããªãå½¢ã§åé
+å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
+ *      ã¨ï¼
+ *    (a) åé
+å¸ã«ä¼´ããã­ã¥ã¡ã³ãï¼å©ç¨è
+ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
+ *        ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
+ *    (b) åé
+å¸ã®å½¢æ
+ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSãã­ã¸ã§ã¯ãã«
+ *        å ±åãããã¨ï¼
+ *  (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
+ *      å®³ãããï¼ä¸è¨èä½æ¨©è
+ããã³TOPPERSãã­ã¸ã§ã¯ããå
+è²¬ãããã¨ï¼
+ *      ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
+ *      ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
+ããã³TOPPERSãã­ã¸ã§ã¯ãã
+ *      å
+è²¬ãããã¨ï¼
+ * 
+ *  æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
+ã
+ *  ãã³TOPPERSãã­ã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
+ *  ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
+ *  ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ã
+ *  ã®è²¬ä»»ãè² ããªãï¼
+ * 
+ *  @(#) $Id$
+ */
+#include "shellif.h"
+#include <stdarg.h>
+#include "analogin_api.h"
+#include "gpio_api.h"
+#include "i2c_api.h"
+#include "pwmout_api.h"
+//#include "rtc_api.h"
+#include "serial_api.h"
+#include "us_ticker_api.h"
+#include "wait_api.h"
+#include "../../mbed_api/src/mbedcall.h"
+
+static inline long __exp_analogin_init(struct regs_t *r)
+{
+	analogin_init((analogin_t *)r->a, (PinName)r->b);
+	return 0;
+}
+
+static inline long __exp_analogin_read_u16(struct regs_t *r)
+{
+	return (long)analogin_read_u16((analogin_t *)r->a);
+}
+
+static inline long __exp_gpio_init(struct regs_t *r)
+{
+	gpio_init((gpio_t *)r->a, (PinName)r->b);
+	return 0;
+}
+
+static inline long __exp_gpio_mode(struct regs_t *r)
+{
+	gpio_mode((gpio_t *)r->a, (PinMode)r->b);
+	return 0;
+}
+
+static inline long __exp_gpio_dir(struct regs_t *r)
+{
+	gpio_dir((gpio_t *)r->a, (PinDirection)r->b);
+	return 0;
+}
+
+static inline long __exp_gpio_write(struct regs_t *r)
+{
+	gpio_write((gpio_t *)r->a, (int)r->b);
+	return 0;
+}
+
+static inline long __exp_gpio_read(struct regs_t *r)
+{
+	return (long)gpio_read((gpio_t *)r->a);
+}
+
+static inline long __exp_i2c_start(struct regs_t *r)
+{
+	return (long)i2c_start((i2c_t *)r->a);
+}
+
+static inline long __exp_i2c_stop(struct regs_t *r)
+{
+	return (long)i2c_stop((i2c_t *)r->a);
+}
+
+static inline long __exp_i2c_init(struct regs_t *r)
+{
+	i2c_init((i2c_t *)r->a, (PinName)r->b, (PinName)r->c);
+	return 0;
+}
+
+static inline long __exp_i2c_read(struct regs_t *r)
+{
+	return (long)i2c_read((i2c_t *)r->a, (int)r->b, (char *)r->c, (int)r->d, (int)r->e);
+}
+
+static inline long __exp_i2c_write(struct regs_t *r)
+{
+	return (long)i2c_write((i2c_t *)r->a, (int)r->b, (const char *)r->c, (int)r->d, (int)r->e);
+}
+
+static inline long __exp_i2c_byte_read(struct regs_t *r)
+{
+	return (long)i2c_byte_read((i2c_t *)r->a, (int)r->b);
+}
+
+static inline long __exp_i2c_byte_write(struct regs_t *r)
+{
+	return (long)i2c_byte_write((i2c_t *)r->a, (int)r->b);
+}
+
+static inline long __exp_pin_function(struct regs_t *r)
+{
+	return (long)pin_function((PinName)r->a, (int)r->b);
+}
+
+static inline long __exp_pin_mode(struct regs_t *r)
+{
+	return (long)pin_mode((PinName)r->a, (PinMode)r->b);
+}
+
+static inline long __exp_pwmout_free(struct regs_t *r)
+{
+	pwmout_free((pwmout_t *)r->a);
+	return 0;
+}
+
+static inline long __exp_pwmout_init(struct regs_t *r)
+{
+	pwmout_init((pwmout_t *)r->a, (PinName)r->b);
+	return 0;
+}
+
+static inline long __exp_pwmout_pulsewidth_us(struct regs_t *r)
+{
+	pwmout_pulsewidth_us((pwmout_t *)r->a, (int)r->b);
+	return 0;
+}
+
+static inline long __exp_rtc_init(struct regs_t *r)
+{
+	rtc_init();
+	return 0;
+}
+
+static inline long __exp_rtc_free(struct regs_t *r)
+{
+	rtc_free();
+	return 0;
+}
+
+static inline long __exp_rtc_isenabled(struct regs_t *r)
+{
+	return (long)rtc_isenabled();
+}
+
+static inline long __exp_rtc_read(struct regs_t *r)
+{
+	return (long)rtc_read();
+}
+
+static inline long __exp_rtc_write(struct regs_t *r)
+{
+	rtc_write((time_t)r->a);
+	return 0;
+}
+
+static inline long __exp_serial_baud(struct regs_t *r)
+{
+	serial_baud((serial_t *)r->a, (int)r->b);
+	return 0;
+}
+
+static inline long __exp_serial_init(struct regs_t *r)
+{
+	serial_init((serial_t *)r->a, (PinName)r->b, (PinName)r->c);
+	return 0;
+}
+
+static inline long __exp_serial_readable(struct regs_t *r)
+{
+	return (long)serial_readable((serial_t *)r->a);
+}
+
+static inline long __exp_serial_getc(struct regs_t *r)
+{
+	return (long)serial_getc((serial_t *)r->a);
+}
+
+static inline long __exp_serial_putc(struct regs_t *r)
+{
+	serial_putc((serial_t *)r->a, (int)r->b);
+	return 0;
+}
+
+static inline long __exp_us_ticker_init(struct regs_t *r)
+{
+	us_ticker_init();
+	return 0;
+}
+
+static inline long __exp_us_ticker_read(struct regs_t *r)
+{
+	return (long)us_ticker_read();
+}
+
+static inline long __exp_us_ticker_set_interrupt(struct regs_t *r)
+{
+	us_ticker_set_interrupt((timestamp_t)r->a);
+	return 0;
+}
+
+static inline long __exp_us_ticker_disable_interrupt(struct regs_t *r)
+{
+	us_ticker_disable_interrupt();
+	return 0;
+}
+
+static inline long __exp_us_ticker_clear_interrupt(struct regs_t *r)
+{
+	us_ticker_clear_interrupt();
+	return 0;
+}
+
+static inline long __exp_SD_begin(struct regs_t *r)
+{
+	return (long)SD_begin();
+}
+
+static long __mbedcall(struct regs_t *r)
+{
+	long ret = -ENOSYS;
+
+	shellif_into();
+
+	switch (r->n) {
+	case MBED_analogin_init:
+		ret = __exp_analogin_init(r);
+		break;
+	case MBED_analogin_read_u16:
+		ret = __exp_analogin_read_u16(r);
+		break;
+	case MBED_gpio_init:
+		ret = __exp_gpio_init(r);
+		break;
+	case MBED_gpio_mode:
+		ret = __exp_gpio_mode(r);
+		break;
+	case MBED_gpio_dir:
+		ret = __exp_gpio_dir(r);
+		break;
+	case MBED_gpio_write:
+		ret = __exp_gpio_write(r);
+		break;
+	case MBED_gpio_read:
+		ret = __exp_gpio_read(r);
+		break;
+	case MBED_i2c_start:
+		ret = __exp_i2c_start(r);
+		break;
+	case MBED_i2c_stop:
+		ret = __exp_i2c_stop(r);
+		break;
+	case MBED_i2c_init:
+		ret = __exp_i2c_init(r);
+		break;
+	case MBED_i2c_read:
+		ret = __exp_i2c_read(r);
+		break;
+	case MBED_i2c_write:
+		ret = __exp_i2c_write(r);
+		break;
+	case MBED_i2c_byte_read:
+		ret = __exp_i2c_byte_read(r);
+		break;
+	case MBED_i2c_byte_write:
+		ret = __exp_i2c_byte_write(r);
+		break;
+	case MBED_pin_function:
+		ret = __exp_pin_function(r);
+		break;
+	case MBED_pin_mode:
+		ret = __exp_pin_mode(r);
+		break;
+	case MBED_pwmout_free:
+		ret = __exp_pwmout_free(r);
+		break;
+	case MBED_pwmout_init:
+		ret = __exp_pwmout_init(r);
+		break;
+	case MBED_pwmout_pulsewidth_us:
+		ret = __exp_pwmout_pulsewidth_us(r);
+		break;
+	case MBED_rtc_init:
+		ret = __exp_rtc_init(r);
+		break;
+	case MBED_rtc_free:
+		ret = __exp_rtc_free(r);
+		break;
+	case MBED_rtc_isenabled:
+		ret = __exp_rtc_isenabled(r);
+		break;
+	case MBED_rtc_read:
+		ret = __exp_rtc_read(r);
+		break;
+	case MBED_rtc_write:
+		ret = __exp_rtc_write(r);
+		break;
+	case MBED_serial_baud:
+		ret = __exp_serial_baud(r);
+		break;
+	case MBED_serial_init:
+		ret = __exp_serial_init(r);
+		break;
+	case MBED_serial_readable:
+		ret = __exp_serial_readable(r);
+		break;
+	case MBED_serial_getc:
+		ret = __exp_serial_getc(r);
+		break;
+	case MBED_serial_putc:
+		ret = __exp_serial_putc(r);
+		break;
+	case MBED_us_ticker_init:
+		ret = __exp_us_ticker_init(r);
+		break;
+	case MBED_us_ticker_read:
+		ret = __exp_us_ticker_read(r);
+		break;
+	case MBED_us_ticker_set_interrupt:
+		ret = __exp_us_ticker_set_interrupt(r);
+		break;
+	case MBED_us_ticker_disable_interrupt:
+		ret = __exp_us_ticker_disable_interrupt(r);
+		break;
+	case MBED_us_ticker_clear_interrupt:
+		ret = __exp_us_ticker_clear_interrupt(r);
+		break;
+	case MBED_SD_begin:
+		ret = __exp_SD_begin(r);
+		break;
+	case MBED___enable_irq:
+		ret = 0;
+		break;
+	case MBED___disable_irq:
+		ret = 0;
+		break;
+	default:
+		asm("bkpt #0");
+		break;
+	}
+
+	shellif_outof();
+
+	return ret;
+}
+
+void __attribute__((naked)) __mbedcall_cp_asm()
+{
+	register long sp asm("sp");
+	asm("push	{r0, r1, r2, r3, r4, r5, r7, r12, lr}");
+	__mbedcall((struct regs_t *)sp);
+	asm("add	sp, sp, #4");
+	asm("pop	{r1, r2, r3, r4, r5, r7, r12, pc}");
+}
+
Index: EcnlProtoTool/trunk/ntshell/src/route_cfg.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/route_cfg.c	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/route_cfg.c	(revision 331)
@@ -2,5 +2,5 @@
  *  TINET (TCP/IP Protocol Stack)
  * 
- *  Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
+ *  Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
  *                   Tomakomai National College of Technology, JAPAN
  *
@@ -44,11 +44,23 @@
 #include <netinet/in_var.h>
 
+/* IPv6 に関する定義 */
+
+#ifdef _IP6_CFG
+
+#if NUM_IN6_ROUTE_ENTRY > 0
+
+T_IN6_RTENTRY routing6_tbl[NUM_IN6_ROUTE_ENTRY];
+
+#endif	/* of #if NUM_IN6_ROUTE_ENTRY > 0 */
+
+#endif	/* of #ifdef _IP6_CFG */
+
 /* IPv4 に関する定義 */
 
-#ifdef SUPPORT_INET4
+#ifdef _IP4_CFG
 
 #ifdef SUPPORT_LOOP
 
-T_IN4_RTENTRY routing_tbl[NUM_ROUTE_ENTRY] = {
+T_IN4_RTENTRY routing4_tbl[NUM_IN4_ROUTE_ENTRY] = {
 	{ 0, 0, 0 },
 	};
@@ -58,5 +70,5 @@
 #ifdef SUPPORT_PPP
 
-T_IN4_RTENTRY routing_tbl[NUM_ROUTE_ENTRY] = {
+T_IN4_RTENTRY routing4_tbl[NUM_IN4_ROUTE_ENTRY] = {
 	{ 0, 0, 0 },
 	};
@@ -66,5 +78,5 @@
 #ifdef SUPPORT_ETHER
 
-T_IN4_RTENTRY routing_tbl[NUM_ROUTE_ENTRY] = {
+T_IN4_RTENTRY routing4_tbl[NUM_IN4_ROUTE_ENTRY] = {
 
 	/* 異なる LAN、default gateway による間接配送	*/
@@ -82,15 +94,3 @@
 #endif	/* of #ifdef SUPPORT_ETHER */
 
-#endif	/* of #ifdef SUPPORT_INET4 */
-
-/* IPv6 に関する定義 */
-
-#ifdef SUPPORT_INET6
-
-#if NUM_ROUTE_ENTRY > 0
-
-T_IN6_RTENTRY routing_tbl[NUM_ROUTE_ENTRY] = { };
-
-#endif	/* of #if NUM_ROUTE_ENTRY > 0 */
-
-#endif	/* of #ifdef SUPPORT_INET6 */
+#endif	/* of #ifdef _IP4_CFG */
Index: EcnlProtoTool/trunk/ntshell/src/shellif.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/shellif.c	(revision 321)
+++ 	(revision )
@@ -1,825 +1,0 @@
-/*
- *  TOPPERS ECHONET Lite Communication Middleware
- * 
- *  Copyright (C) 2017 Cores Co., Ltd. Japan
- * 
- *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
- *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
- *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
- *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
- *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
- *      スコード中に含まれていること．
- *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
- *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
- *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
- *      の無保証規定を掲載すること．
- *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
- *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
- *      と．
- *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
- *        作権表示，この利用条件および下記の無保証規定を掲載すること．
- *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
- *        報告すること．
- *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
- *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
- *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
- *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
- *      免責すること．
- * 
- *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
- *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
- *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
- *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
- *  の責任を負わない．
- * 
- *  @(#) $Id$
- */
-#include <setjmp.h>
-#include <sys/time.h>
-#include <stdarg.h>
-#include "../../../musl-1.1.12/include/poll.h"
-#include "analogin_api.h"
-#include "gpio_api.h"
-#include "i2c_api.h"
-#include "pwmout_api.h"
-#include "rtc_api.h"
-#include "serial_api.h"
-#include "us_ticker_api.h"
-#include "wait_api.h"
-#include "usrcmd.h"
-#include "ff.h"
-#include <kernel.h>
-#include "socket_stub.h"
-
-void shellif_into();
-void shellif_outof();
-
-void __exp_analogin_init(analogin_t *obj, PinName pin)
-{
-	shellif_into();
-	analogin_init(obj, pin);
-	shellif_outof();
-}
-
-uint16_t __exp_analogin_read_u16(analogin_t *obj)
-{
-	uint16_t result;
-	shellif_into();
-	result = analogin_read_u16(obj);
-	shellif_outof();
-	return result;
-}
-
-void __exp_gpio_init(gpio_t *obj, PinName pin)
-{
-	shellif_into();
-	gpio_init(obj, pin);
-	shellif_outof();
-}
-
-void __exp_gpio_dir(gpio_t *obj, PinDirection direction)
-{
-	shellif_into();
-	gpio_dir(obj, direction);
-	shellif_outof();
-}
-
-int __exp_i2c_start(i2c_t *obj)
-{
-	int result;
-	shellif_into();
-	result = i2c_start(obj);
-	shellif_outof();
-	return result;
-}
-
-int __exp_i2c_stop(i2c_t *obj)
-{
-	int result;
-	shellif_into();
-	result = i2c_stop(obj);
-	shellif_outof();
-	return result;
-}
-
-void __exp_i2c_init(i2c_t *obj, PinName sda, PinName scl)
-{
-	shellif_into();
-	i2c_init(obj, sda, scl);
-	shellif_outof();
-}
-
-int __exp_i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
-{
-	int result;
-	shellif_into();
-	result = i2c_read(obj, address, data, length, stop);
-	shellif_outof();
-	return result;
-}
-
-int __exp_i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
-{
-	int result;
-	shellif_into();
-	result = i2c_write(obj, address, data, length, stop);
-	shellif_outof();
-	return result;
-}
-
-int __exp_i2c_byte_read(i2c_t *obj, int last)
-{
-	int result;
-	shellif_into();
-	result = i2c_byte_read(obj, last);
-	shellif_outof();
-	return result;
-}
-
-int __exp_i2c_byte_write(i2c_t *obj, int data)
-{
-	int result;
-	shellif_into();
-	result = i2c_byte_write(obj, data);
-	shellif_outof();
-	return result;
-}
-
-void __exp_pwmout_free(pwmout_t* obj)
-{
-	shellif_into();
-	pwmout_free(obj);
-	shellif_outof();
-}
-
-void __exp_pwmout_init(pwmout_t* obj, PinName pin)
-{
-	shellif_into();
-	pwmout_init(obj, pin);
-	shellif_outof();
-}
-
-void __exp_pwmout_pulsewidth_us(pwmout_t* obj, int us)
-{
-	shellif_into();
-	pwmout_pulsewidth_us(obj, us);
-	shellif_outof();
-}
-
-void __exp_rtc_init(void)
-{
-	shellif_into();
-	rtc_init();
-	shellif_outof();
-}
-
-void __exp_rtc_free(void)
-{
-	shellif_into();
-	rtc_free();
-	shellif_outof();
-}
-
-int __exp_rtc_isenabled(void)
-{
-	int result;
-	shellif_into();
-	result = rtc_isenabled();
-	shellif_outof();
-	return result;
-}
-
-time_t __exp_rtc_read(void)
-{
-	time_t result;
-	shellif_into();
-	result = rtc_read();
-	shellif_outof();
-	return result;
-}
-
-void __exp_rtc_write(time_t t)
-{
-	shellif_into();
-	rtc_write(t);
-	shellif_outof();
-}
-
-void __exp_serial_baud(serial_t *obj, int baudrate)
-{
-	shellif_into();
-	serial_baud(obj, baudrate);
-	shellif_outof();
-}
-
-void __exp_serial_init(serial_t *obj, PinName tx, PinName rx)
-{
-	shellif_into();
-	serial_init(obj, tx, rx);
-	shellif_outof();
-}
-
-int __exp_serial_readable(serial_t *obj)
-{
-	int result;
-	shellif_into();
-	result = serial_readable(obj);
-	shellif_outof();
-	return result;
-}
-
-int __exp_serial_getc(serial_t *obj)
-{
-	int result;
-	shellif_into();
-	result = serial_getc(obj);
-	shellif_outof();
-	return result;
-}
-
-void __exp_serial_putc(serial_t *obj, int c)
-{
-	shellif_into();
-	serial_putc(obj, c);
-	shellif_outof();
-}
-
-uint32_t __exp_us_ticker_read(void)
-{
-	int result;
-	shellif_into();
-	result = us_ticker_read();
-	shellif_outof();
-	return result;
-}
-
-void __exp_wait_ms(int ms)
-{
-	shellif_into();
-	wait_ms(ms);
-	shellif_outof();
-}
-
-bool __exp_SD_begin()
-{
-	bool result;
-	shellif_into();
-	result = SD_begin();
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_cd(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_cd(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_ls(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_ls(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_cp(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_cp(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_rm(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_rm(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_mv(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_mv(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_mkdir(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_mkdir(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_hexdump(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_hexdump(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_info(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_info(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_usrcmd_exit(int argc, char **argv)
-{
-	int result;
-	shellif_into();
-	result = usrcmd_exit(argc, argv);
-	shellif_outof();
-	return result;
-}
-
-void __exp_shell_abort()
-{
-	shellif_into();
-	shell_abort();
-	shellif_outof();
-}
-
-void __exp_shell_exit(int exitcd)
-{
-	shellif_into();
-	shell_exit(exitcd);
-	shellif_outof();
-}
-
-int __exp_shell_kill(int pid, int sig)
-{
-	int result;
-	shellif_into();
-	result = shell_kill(pid, sig);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_gettimeofday(struct timeval * tp, void * tzvp)
-{
-	int result;
-	shellif_into();
-	result = shell_gettimeofday(tp, tzvp);
-	shellif_outof();
-	return result;
-}
-
-void __exp_vsyslog(int priority, const char *format, va_list ap)
-{
-	shellif_into();
-	vsyslog(priority, format, ap);
-	shellif_outof();
-}
-
-int __exp_shell_open(const char * path, int flags)
-{
-	int result;
-	shellif_into();
-	result = shell_open(path, flags);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_close(int fd)
-{
-	int result;
-	shellif_into();
-	result = shell_close(fd);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_read(int fd, char *data, int len)
-{
-	int result;
-	shellif_into();
-	result = shell_read(fd, data, len);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_write(int fd, char *data, int len)
-{
-	int result;
-	shellif_into();
-	result = shell_write(fd, data, len);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_lseek(int fd, int ptr, int dir)
-{
-	int result;
-	shellif_into();
-	result = shell_lseek(fd, ptr, dir);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_fstat(int fd, struct stat * st)
-{
-	int result;
-	shellif_into();
-	result = shell_fstat(fd, st);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_stat(const char *fname, struct stat *st)
-{
-	int result;
-	shellif_into();
-	result = shell_stat(fname, st);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_link(void)
-{
-	int result;
-	shellif_into();
-	result = shell_link();
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_unlink(const char *path)
-{
-	int result;
-	shellif_into();
-	result = shell_unlink(path);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_isatty(int fd)
-{
-	int result;
-	shellif_into();
-	result = shell_isatty(fd);
-	shellif_outof();
-	return result;
-}
-
-int __exp_fsync(int fd)
-{
-	int result;
-	shellif_into();
-	result = fsync(fd);
-	shellif_outof();
-	return result;
-}
-
-int __exp_ftruncate(int fd, off_t length)
-{
-	int result;
-	shellif_into();
-	result = ftruncate(fd, length);
-	shellif_outof();
-	return result;
-}
-
-int __exp_ioctl(int fd, int request, va_list ap)
-{
-	int result;
-	shellif_into();
-	result = ioctl(fd, request, ap);
-	shellif_outof();
-	return result;
-}
-
-int __exp_tcgetattr(int fd, struct termios *termios_p)
-{
-	int result;
-	shellif_into();
-	result = tcgetattr(fd, termios_p);
-	shellif_outof();
-	return result;
-}
-
-int __exp_tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
-{
-	int result;
-	shellif_into();
-	result = tcsetattr(fd, optional_actions, termios_p);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_rename(const char *oldpath, const char *newpath)
-{
-	int result;
-	shellif_into();
-	result = shell_rename(oldpath, newpath);
-	shellif_outof();
-	return result;
-}
-
-int __exp_rmdir(const char *path)
-{
-	int result;
-	shellif_into();
-	result = rmdir(path);
-	shellif_outof();
-	return result;
-}
-
-int __exp_mkdir(const char *path, mode_t mode)
-{
-	int result;
-	shellif_into();
-	result = mkdir(path, mode);
-	shellif_outof();
-	return result;
-}
-
-int __exp_chmod(const char *path, mode_t mode)
-{
-	int result;
-	shellif_into();
-	result = chmod(path, mode);
-	shellif_outof();
-	return result;
-}
-
-char *__exp_getcwd(char *buf, size_t size)
-{
-	char *result;
-	shellif_into();
-	result = getcwd(buf, size);
-	shellif_outof();
-	return result;
-}
-
-int __exp_chdir(const char *path)
-{
-	int result;
-	shellif_into();
-	result = chdir(path);
-	shellif_outof();
-	return result;
-}
-
-int __exp_chroot(const char *path)
-{
-	int result;
-	shellif_into();
-	result = chroot(path);
-	shellif_outof();
-	return result;
-}
-
-int __exp_closedir(DIR *dir)
-{
-	int result;
-	shellif_into();
-	result = closedir(dir);
-	shellif_outof();
-	return result;
-}
-
-DIR *__exp_opendir(const char *path)
-{
-	DIR *result;
-	shellif_into();
-	result = opendir(path);
-	shellif_outof();
-	return result;
-}
-
-struct dirent *__exp_readdir(DIR *dir)
-{
-	struct dirent *result;
-	shellif_into();
-	result = readdir(dir);
-	shellif_outof();
-	return result;
-}
-
-void __exp_rewinddir(DIR *dir)
-{
-	shellif_into();
-	rewinddir(dir);
-	shellif_outof();
-}
-
-void __exp_seekdir(DIR *dir, long pos)
-{
-	shellif_into();
-	seekdir(dir, pos);
-	shellif_outof();
-}
-
-long __exp_telldir(DIR *dir)
-{
-	long result;
-	shellif_into();
-	result = telldir(dir);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shell_getpid()
-{
-	int result;
-	shellif_into();
-	result = shell_getpid();
-	shellif_outof();
-	return result;
-}
-
-int __exp_socket(int family, int type, int protocol)
-{
-	int result;
-	shellif_into();
-	result = socket(family, type, protocol);
-	shellif_outof();
-	return result;
-}
-
-int __exp_bind(int fd, const struct sockaddr *addr, socklen_t len)
-{
-	int result;
-	shellif_into();
-	result = bind(fd, addr, len);
-	shellif_outof();
-	return result;
-}
-
-int __exp_listen(int fd, int backlog)
-{
-	int result;
-	shellif_into();
-	result = listen(fd, backlog);
-	shellif_outof();
-	return result;
-}
-
-int __exp_connect(int fd, const struct sockaddr *addr, socklen_t len)
-{
-	int result;
-	shellif_into();
-	result = connect(fd, addr, len);
-	shellif_outof();
-	return result;
-}
-
-int __exp_accept(int fd, struct sockaddr *addr, socklen_t *len)
-{
-	int result;
-	shellif_into();
-	result = accept(fd, addr, len);
-	shellif_outof();
-	return result;
-}
-
-ssize_t __exp_send(int fd, const void *buf, size_t len, int flags)
-{
-	ssize_t result;
-	shellif_into();
-	result = send(fd, buf, len, flags);
-	shellif_outof();
-	return result;
-}
-
-ssize_t __exp_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
-{
-	ssize_t result;
-	shellif_into();
-	result = sendto(fd, buf, len, flags, addr, alen);
-	shellif_outof();
-	return result;
-}
-
-ssize_t __exp_recv(int fd, void *buf, size_t len, int flags)
-{
-	ssize_t result;
-	shellif_into();
-	result = recv(fd, buf, len, flags);
-	shellif_outof();
-	return result;
-}
-
-ssize_t __exp_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen)
-{
-	ssize_t result;
-	shellif_into();
-	result = recvfrom(fd, buf, len, flags, addr, alen);
-	shellif_outof();
-	return result;
-}
-
-int __exp_shutdown(int fd, int how)
-{
-	int result;
-	shellif_into();
-	result = shutdown(fd, how);
-	shellif_outof();
-	return result;
-}
-
-int __exp_getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen)
-{
-	int result;
-	shellif_into();
-	result = getsockopt(fd, level, optname, optval, optlen);
-	shellif_outof();
-	return result;
-}
-
-int __exp_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
-{
-	int result;
-	shellif_into();
-	result = setsockopt(fd, level, optname, optval, optlen);
-	shellif_outof();
-	return result;
-}
-
-int __exp_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
-{
-	int result;
-	shellif_into();
-	result = select(n, rfds, wfds, efds, tv);
-	shellif_outof();
-	return result;
-}
-
-int __exp_poll(struct pollfd *fds, nfds_t nfds, int timeout)
-{
-	int result;
-	shellif_into();
-	result = poll(fds, nfds, timeout);
-	shellif_outof();
-	return result;
-}
-
-int __exp_gethostname(char *name, size_t len)
-{
-	int result;
-	shellif_into();
-	result = gethostname(name, len);
-	shellif_outof();
-	return result;
-}
-
-int __exp_getnameinfo(const struct sockaddr *sa, socklen_t sl,
-	char *node, socklen_t nodelen,
-	char *serv, socklen_t servlen,
-	int flags)
-{
-	int result;
-	shellif_into();
-	shell_abort();
-	result = 0;
-	shellif_outof();
-	return result;
-}
-
-int __exp_getpeername(int fd, struct sockaddr *addr, socklen_t *len)
-{
-	int result;
-	shellif_into();
-	shell_abort();
-	result = 0;
-	shellif_outof();
-	return result;
-}
-
-int __exp_getsockname(int fd, struct sockaddr *addr, socklen_t *len)
-{
-	int result;
-	shellif_into();
-	shell_abort();
-	result = 0;
-	shellif_outof();
-	return result;
-}
-
-int __exp_socketpair(int family, int type, int protocol, int fd[2])
-{
-	int result;
-	shellif_into();
-	shell_abort();
-	result = 0;
-	shellif_outof();
-	return result;
-}
Index: EcnlProtoTool/trunk/ntshell/src/shellif.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/shellif.h	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/shellif.h	(revision 331)
@@ -0,0 +1,249 @@
+/*
+ *  TOPPERS ECHONET Lite Communication Middleware
+ * 
+ *  Copyright (C) 2017 Cores Co., Ltd. Japan
+ * 
+ *  ä¸è¨èä½æ¨©è
+ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
+ *  ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ãä½¿ç¨ã»è¤è£½ã»æ¹
+ *  å¤ã»åé
+å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
+ *  (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
+ *      æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
+ *      ã¹ã³ã¼ãä¸­ã«å«ã¾ãã¦ãããã¨ï¼
+ *  (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
+ *      ç¨ã§ããå½¢ã§åé
+å¸ããå ´åã«ã¯ï¼åé
+å¸ã«ä¼´ããã­ã¥ã¡ã³ãï¼å©ç¨
+ *      è
+ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
+ *      ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
+ *  (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
+ *      ç¨ã§ããªãå½¢ã§åé
+å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
+ *      ã¨ï¼
+ *    (a) åé
+å¸ã«ä¼´ããã­ã¥ã¡ã³ãï¼å©ç¨è
+ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
+ *        ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
+ *    (b) åé
+å¸ã®å½¢æ
+ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSãã­ã¸ã§ã¯ãã«
+ *        å ±åãããã¨ï¼
+ *  (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
+ *      å®³ãããï¼ä¸è¨èä½æ¨©è
+ããã³TOPPERSãã­ã¸ã§ã¯ããå
+è²¬ãããã¨ï¼
+ *      ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
+ *      ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
+ããã³TOPPERSãã­ã¸ã§ã¯ãã
+ *      å
+è²¬ãããã¨ï¼
+ * 
+ *  æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
+ã
+ *  ãã³TOPPERSãã­ã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
+ *  ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
+ *  ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ã
+ *  ã®è²¬ä»»ãè² ããªãï¼
+ * 
+ *  @(#) $Id$
+ */
+#ifndef SHELLIF_H
+#define SHELLIF_H
+
+#ifdef _MSC_VER
+#include <time.h>
+#endif
+
+#define __NEED_off_t
+#define __NEED_ssize_t
+#define __NEED_size_t
+#define __NEED_mode_t
+#define __NEED_dev_t
+#define __NEED_pid_t
+#define __NEED_gid_t
+#define __NEED_uid_t
+#define __NEED_socklen_t
+#define __NEED_nlink_t
+#define __NEED_blksize_t
+#define __NEED_blkcnt_t
+#define __NEED_ino_t
+#define __NEED_time_t
+#define __NEED_suseconds_t
+#define __NEED_struct_timeval
+#define __NEED_struct_timespec
+#define __NEED_struct_iovec
+#define __NEED_clockid_t
+#define __NEED_socklen_t
+#define __NEED_sa_family_t
+#define __NEED_sigset_t
+
+#include "../musl-1.1.18/include/bits/alltypes.h"
+
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+#define NCCS 32
+
+#include "../musl-1.1.18/include/bits/fcntl.h"
+#include "../musl-1.1.18/include/bits/termios.h"
+#include "../musl-1.1.18/include/bits/stat.h"
+#include "../musl-1.1.18/include/sys/select.h"
+#ifndef _MSC_VER
+#include "../musl-1.1.18/include/time.h"
+#endif
+#include "../musl-1.1.18/include/signal.h"
+#include "../musl-1.1.18/include/stdio.h"
+#include "../musl-1.1.18/include/sys/utsname.h"
+#include "../musl-1.1.18/include/dirent.h"
+#include "../musl-1.1.18/include/bits/ioctl.h"
+#include "../musl-1.1.18/include/fcntl.h"
+#include "../musl-1.1.18/include/bits/errno.h"
+#include "../musl-1.1.18/include/sys/socket.h"
+
+#include <stddef.h>
+#include <stdarg.h>
+
+// time.h
+#define CLOCK_REALTIME 0
+
+// dirent.h
+typedef struct __dirstream DIR;
+
+int shell_getdents(int, struct dirent *, size_t);
+// pool.h
+typedef unsigned long nfds_t;
+
+struct pollfd {
+	int fd;
+	short events;
+	short revents;
+};
+
+int shell_poll(struct pollfd *, nfds_t, int);
+
+#define POLLIN     0x001
+#define POLLOUT    0x004
+#define POLLERR    0x008
+
+// stropts.h
+int shell_ioctl(int, int, void *);
+// unistd.h
+#define STDIN_FILENO  0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+int shell_rmdir(const char *);
+int shell_ftruncate(int, off_t);
+int shell_chdir(const char *);
+char *shell_getcwd(char *, size_t);
+int shell_chroot(const char *);
+int shell_close(int);
+int shell_llseek(int, off_t, off_t *, int);
+int shell_fsync(int);
+ssize_t shell_read(int, void *, size_t);
+int shell_readv(int fd, const struct iovec *iov, int iovcnt);
+ssize_t shell_write(int, const void *, size_t);
+int shell_writev(int fd, const struct iovec *iov, int iovcnt);
+int shell_link(const char *, const char *);
+int shell_unlink(const char *);
+pid_t shell_getpid(void);
+int shell_access(const char *path, int mode);
+// signal.h
+int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old);
+int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old);
+// socket.h
+int shell_socket(int, int, int);
+int shell_connect(int, const struct sockaddr *, socklen_t);
+ssize_t shell_send(int, const void *, size_t, int);
+ssize_t shell_sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
+ssize_t shell_sendmsg(int, const struct msghdr *, int);
+int shell_bind(int, const struct sockaddr *, socklen_t);
+int shell_listen(int, int);
+int shell_accept(int, struct sockaddr *__restrict, socklen_t *__restrict);
+ssize_t shell_recv(int, void *, size_t, int);
+ssize_t shell_recvfrom(int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
+ssize_t shell_recvmsg(int, struct msghdr *, int);
+int shell_getsockopt(int, int, int, void *__restrict, socklen_t *__restrict);
+int shell_setsockopt(int, int, int, const void *, socklen_t);
+int shell_shutdown(int, int);
+// select.h
+int shell_select(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict);
+// syslog.h
+void vsyslog (int, const char *, va_list);
+// termios.h
+int sio_tcgetattr (int, struct termios *);
+int sio_tcsetattr(int, int, const struct termios *);
+// fcntl.h
+int shell_open(const char *, int, void *arg);
+int shell_fcntl(int fd, int cmd, void *arg);
+// stdio.h
+int shell_rename(const char *, const char *);
+// stat.h
+#define S_IFDIR 0040000
+#define S_IFCHR 0020000
+#define S_IFREG 0100000
+
+#define S_IRUSR 0400
+#define S_IWUSR 0200
+#define S_IRGRP 0040
+#define S_IWGRP 0020
+#define S_IROTH 0004
+#define S_IWOTH 0002
+
+int shell_chmod(const char *, mode_t);
+int shell_mkdir(const char *, mode_t);
+int shell_stat(const char *__restrict, struct stat *__restrict);
+int shell_fstat(int, struct stat *);
+int shell_lstat(const char *__restrict, struct stat *__restrict);
+
+int shell_clock_getres(clockid_t clk_id, struct timespec *res);
+int shell_clock_gettime(clockid_t clk_id, struct timespec *tp);
+int shell_clock_settime(clockid_t clk_id, const struct timespec *tp);
+int shell_gettimeofday(struct timeval *tp, void * tzvp);
+
+void shell_abort();
+void shell_exit(int exitcd);
+void shell_exit_group(int exitcd);
+int shell_kill(int pid, int sig);
+
+void *shell_brk(void *addr);
+void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset);
+// sys/mman.h
+int shell_mprotect(void *addr, size_t len, int prot);
+// TODO
+int shell_madvise(void *, size_t, int);
+int shell_uname(struct utsname *);
+// âââmusl
+
+// arduino.h
+int SD_begin();
+
+char *basename(char *);
+void shellif_into();
+void shellif_outof();
+
+struct regs_t {
+	long a;
+	long b;
+	long c;
+	long d;
+	long e;
+	long f;
+	long n;
+};
+
+void no_implement(const char *text);
+void __mbedcall_cp_asm();
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+void Kernel_StartExternal(int argc, char **argv);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SHELLIF_H */
Index: EcnlProtoTool/trunk/ntshell/src/socket_stub.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/socket_stub.c	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/socket_stub.c	(revision 331)
@@ -35,26 +35,10 @@
  *  @(#) $Id$
  */
-#include <sys/types.h>
-#include <stdint.h>
-#if 0
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#endif
-#include <fcntl.h>
-#include "sys/unistd.h"
-#include <stddef.h>
-#include <string.h>
-#include <stdlib.h>
+#include "shellif.h"
 #include <kernel.h>
 #include <t_syslog.h>
 #include <t_stdlib.h>
+#include <string.h>
 #include <sil.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
 #include <setjmp.h>
 #include "syssvc/syslog.h"
@@ -74,5 +58,6 @@
 #include "ff.h"
 #include "socket_stub.h"
-#define SO_REUSEADDR    2
+
+#define SOCKET_TIMEOUT 2000000
 
 typedef struct id_table_t {
@@ -107,5 +92,5 @@
 }
 
-	return -1;
+	return -ENOMEM;
 }
 
@@ -120,10 +105,10 @@
 		return 0;
 	}
-	return -1;
+	return -EINVAL;
 }
 
 int delete_tcp_rep(int repid)
 {
-	delete_tcp_fd(tmax_tcp_cepid + repid);
+	return delete_tcp_fd(tmax_tcp_cepid + repid);
 }
 
@@ -145,7 +130,8 @@
 typedef struct _IO_FILE SOCKET;
 
-int socket(int family, int type, int protocol)
+int shell_socket(int family, int type, int protocol)
 {
 	SOCKET *fp;
+	unsigned int flags;
 
 	switch (family) {
@@ -154,6 +140,9 @@
 		break;
 	default:
-		return -1;
-	}
+		return -EAFNOSUPPORT;
+	}
+
+	flags = type & (SOCK_CLOEXEC|SOCK_NONBLOCK);
+	type &= ~flags;
 
 	switch (type) {
@@ -165,9 +154,9 @@
 		break;
 	default:
-		return -1;
+		return -ENOPROTOOPT;
 	}
 
 	if (fp == NULL) {
-		return -1;
+		return -ENOMEM;
 	}
 
@@ -175,18 +164,16 @@
 	fp->socket.type = type;
 	fp->socket.protocol = protocol;
+	fp->socket.flags = flags;
 
 	return fp->fd;
 }
 
-int bind(int fd, const struct sockaddr *addr, socklen_t len)
+int shell_bind(int fd, const struct sockaddr *addr, socklen_t len)
 {
 	SOCKET *fp = fd_to_fp(fd);
-	if (fp == NULL) {
-		return -1;
-	}
-
-	if (fp->socket.family != addr->sa_family) {
-		return -1;
-	}
+	if (fp == NULL)
+		return -EBADF;
+	if (fp->socket.family != addr->sa_family)
+		return -EINVAL;
 
 	ER ret;
@@ -194,5 +181,5 @@
 	case AF_INET: {
 		if (len < 8) {
-			return -1;
+			return -EINVAL;
 		}
 		struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
@@ -202,13 +189,13 @@
 			ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
-				return -1;
+				return -ENOMEM;
 
 			fp->socket.buf_size = 512 + 512;
 			fp->socket.buf = id_to_buff(cepid);
-			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
 				delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
-				return -1;
+				return -ENOMEM;
 			}
 			fp->handle = cepid;
@@ -219,11 +206,11 @@
 			ID cepid = new_id(udp_cepid_table, udp_cepid_table_count);
 			if (cepid < 0)
-				return -1;
-
-			T_UDP_CCEP ccep = { 0, {ntohl(addr_in->sin_addr.s_addr), ntohs(addr_in->sin_port)}, socket_udp_callback };
+				return -ENOMEM;
+
+			T_UDP_CCEP ccep = { 0, {ntohl(addr_in->sin_addr.s_addr), ntohs(addr_in->sin_port)}, (FP)socket_udp_callback };
 			ret = udp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
 				delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
-				return -1;
+				return -ENOMEM;
 			}
 			fp->handle = cepid;
@@ -232,5 +219,5 @@
 		}
 		default:
-			return -1;
+			return -ENOPROTOOPT;
 		}
 		break;
@@ -238,5 +225,5 @@
 	case AF_INET6: {
 		if (len < 20) {
-			return -1;
+			return -EINVAL;
 		}
 		memcpy(&fp->socket.laddr4, addr, len);
@@ -248,10 +235,11 @@
 }
 
-int listen(int fd, int backlog)
+int shell_listen(int fd, int backlog)
 {
 	SOCKET *fp = fd_to_fp(fd);
-	if ((fp == NULL) || (fp->socket.type != SOCK_STREAM)) {
-		return -1;
-	}
+	if (fp == NULL)
+		return -EBADF;
+	if (fp->socket.type != SOCK_STREAM)
+		return -EINVAL;
 
 	fp->socket.backlog = backlog;
@@ -262,5 +250,5 @@
 		ID repid = new_id(tcp_repid_table, tcp_repid_table_count);
 		if (repid < 0)
-			return -1;
+			return -ENOMEM;
 
 		struct sockaddr_in *laddr = &fp->socket.laddr4;
@@ -269,5 +257,5 @@
 		if (ret != E_OK) {
 			delete_id(tcp_repid_table, tcp_repid_table_count, repid);
-			return -1;
+			return -ENOMEM;
 		}
 		fp->socket.repid = repid;
@@ -282,10 +270,11 @@
 }
 
-int connect(int fd, const struct sockaddr *addr, socklen_t len)
+int shell_connect(int fd, const struct sockaddr *addr, socklen_t len)
 {
 	SOCKET *fp = fd_to_fp(fd);
-	if ((fp == NULL) || (fp->socket.type != SOCK_STREAM)) {
-		return -1;
-	}
+	if (fp == NULL)
+		return -EBADF;
+	if (fp->socket.type != SOCK_STREAM)
+		return -EINVAL;
 
 	ER ret;
@@ -293,18 +282,18 @@
 	case AF_INET: {
 		if (len < 8) {
-			return -1;
+			return -EINVAL;
 		}
 		if (fp->socket.cepid == 0) {
 			ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
-				return -1;
+				return -ENOMEM;
 
 			fp->socket.buf_size = 512 + 512;
 			fp->socket.buf = id_to_buff(cepid);
-			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
 				delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
-				return -1;
+				return -ENOMEM;
 			}
 			fp->handle = cepid;
@@ -317,7 +306,7 @@
 		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->socket.cepid, &lep, &rep, TMO_FEVR);
+		ret = tcp_con_cep(fp->socket.cepid, &lep, &rep, SOCKET_TIMEOUT);
 		if (ret < 0) {
-			return -1;
+			return -EHOSTUNREACH;
 		}
 		break;
@@ -331,14 +320,15 @@
 }
 
-int accept(int fd, struct sockaddr *addr, socklen_t *len)
+int shell_accept(int fd, struct sockaddr *__restrict addr, socklen_t *__restrict len)
 {
 	SOCKET *lfp = fd_to_fp(fd);
-	if ((lfp == NULL) || (lfp->socket.type != SOCK_STREAM)) {
-		return -1;
-	}
+	if (lfp == NULL)
+		return -EBADF;
+	if (lfp->socket.type != SOCK_STREAM)
+		return -EINVAL;
 
 	SOCKET *fp = new_tcp_fd(0);
 	if (fp == NULL) {
-		return -1;
+		return -ENOMEM;
 	}
 
@@ -352,13 +342,13 @@
 			cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
-				return -1;
+				return -ENOMEM;
 
 			fp->socket.buf_size = 512 + 512;
 			fp->socket.buf = id_to_buff(cepid);
-			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
 				delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
-				return -1;
+				return -ENOMEM;
 			}
 			fp->handle = cepid;
@@ -375,5 +365,5 @@
 		ret = tcp_acp_cep(fp->socket.cepid, fp->socket.repid, &rep, TMO_FEVR);
 		if (ret < 0) {
-			return -1;
+			return -ENOMEM;
 		}
 		struct sockaddr_in *raddr = &fp->socket.raddr4;
@@ -385,5 +375,5 @@
 	}
 	case AF_INET6: {
-		break;
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -392,5 +382,5 @@
 		int sz = *len;
 		if (sz < 8) {
-			return -1;
+			return -EINVAL;
 		}
 		struct sockaddr_in *raddr = &fp->socket.raddr4;
@@ -404,9 +394,9 @@
 }
 
-ssize_t send(int fd, const void *buf, size_t len, int flags)
+ssize_t shell_send(int fd, const void *buf, size_t len, int flags)
 {
 	SOCKET *fp = fd_to_fp(fd);
 	if (fp == NULL) {
-		return -1;
+		return -EBADF;
 	}
 
@@ -417,13 +407,13 @@
 		case SOCK_STREAM: {
 			if (flags & MSG_OOB) {
-				ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
+				ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
 				if (ret < 0) {
-					return -1;
+					return -ECOMM;
 				}
 			}
 			else {
-				ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
+				ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
 				if (ret < 0) {
-					return -1;
+					return -ECOMM;
 				}
 			}
@@ -431,11 +421,11 @@
 		}
 		case SOCK_DGRAM: {
-			return -1;
-		}
-		}
-		break;
-	}
-	case AF_INET6: {
-		break;
+			return -EINVAL;
+		}
+		}
+		break;
+	}
+	case AF_INET6: {
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -444,9 +434,9 @@
 }
 
-ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
+ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
 {
 	SOCKET *fp = fd_to_fp(fd);
 	if (fp == NULL) {
-		return -1;
+		return -EBADF;
 	}
 
@@ -457,17 +447,17 @@
 		case SOCK_STREAM: {
 			if ((addr != NULL) && (alen != 0)) {
-				return -1;
+				return -EINVAL;
 			}
 
 			if (flags & MSG_OOB) {
-				ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
+				ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
 				if (ret < 0) {
-					return -1;
+					return -ECOMM;
 				}
 			}
 			else {
-				ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
+				ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
 				if (ret < 0) {
-					return -1;
+					return -ECOMM;
 				}
 			}
@@ -477,5 +467,5 @@
 			int sz = alen;
 			if (sz < 8) {
-				return -1;
+				return -EINVAL;
 			}
 			struct sockaddr_in *raddr = &fp->socket.raddr4;
@@ -483,15 +473,16 @@
 			memcpy(raddr, addr, sz);
 			T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
-			ret = udp_snd_dat(fp->socket.cepid, &rep, (void *)buf, len, TMO_FEVR);
+			ret = udp_snd_dat(fp->socket.cepid, &rep, (void *)buf, len,
+				(fp->socket.flags & O_NONBLOCK) ? 0 : SOCKET_TIMEOUT);
 			if (ret < 0) {
-				return -1;
-			}
-			break;
-		}
-		}
-		break;
-	}
-	case AF_INET6: {
-		break;
+				return -ECOMM;
+			}
+			break;
+		}
+		}
+		break;
+	}
+	case AF_INET6: {
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -500,9 +491,15 @@
 }
 
-ssize_t recv(int fd, void *buf, size_t len, int flags)
+ssize_t shell_sendmsg(int fd, const struct msghdr *msg, int flags)
+{
+	no_implement("sendmsg\n");
+	return -ENOSYS;
+}
+
+ssize_t shell_recv(int fd, void *buf, size_t len, int flags)
 {
 	SOCKET *fp = fd_to_fp(fd);
 	if (fp == NULL) {
-		return -1;
+		return -EBADF;
 	}
 
@@ -515,5 +512,5 @@
 				ret = tcp_rcv_oob(fp->socket.cepid, buf, len);
 				if (ret < 0) {
-					return -1;
+					return -ECOMM;
 				}
 			}
@@ -521,5 +518,5 @@
 				ret = tcp_rcv_dat(fp->socket.cepid, buf, len, TMO_FEVR);
 				if (ret < 0) {
-					return -1;
+					return -ECOMM;
 				}
 			}
@@ -528,14 +525,14 @@
 		case SOCK_DGRAM: {
 			T_IPV4EP rep = { 0, 0 };
-			ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, TMO_FEVR);
+			ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, (fp->socket.flags & O_NONBLOCK) ? 0 : TMO_FEVR);
 			if (ret < 0) {
-				return -1;
-			}
-		}
-		}
-		break;
-	}
-	case AF_INET6: {
-		break;
+				return -ECOMM;
+			}
+		}
+		}
+		break;
+	}
+	case AF_INET6: {
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -544,9 +541,9 @@
 }
 
-ssize_t recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen)
+ssize_t shell_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *__restrict addr, socklen_t *__restrict alen)
 {
 	SOCKET *fp = fd_to_fp(fd);
 	if (fp == NULL) {
-		return -1;
+		return -EBADF;
 	}
 
@@ -559,5 +556,5 @@
 				ret = tcp_rcv_oob(fp->socket.cepid, buf, len);
 				if (ret < 0) {
-					return -1;
+					return -ECOMM;
 				}
 			}
@@ -565,5 +562,5 @@
 				ret = tcp_rcv_dat(fp->socket.cepid, buf, len, TMO_FEVR);
 				if (ret < 0) {
-					return -1;
+					return -ECOMM;
 				}
 			}
@@ -574,5 +571,5 @@
 			ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, TMO_FEVR);
 			if (ret < 0) {
-				return -1;
+				return -ECOMM;
 			}
 			int sz = *alen;
@@ -590,5 +587,5 @@
 	}
 	case AF_INET6: {
-		break;
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -597,9 +594,15 @@
 }
 
-int shutdown(int fd, int how)
+ssize_t shell_recvmsg(int fd, struct msghdr *msg, int flags)
+{
+	no_implement("recvmsg\n");
+	return -ENOSYS;
+}
+
+int shell_shutdown(int fd, int how)
 {
 	SOCKET *fp = fd_to_fp(fd);
 	if (fp == NULL) {
-		return -1;
+		return -EBADF;
 	}
 
@@ -611,13 +614,13 @@
 			ret = tcp_sht_cep(fp->socket.cepid);
 			if (ret < 0) {
-				return -1;
-			}
-			break;
-		}
-		}
-		break;
-	}
-	case AF_INET6: {
-		break;
+				return -ECOMM;
+			}
+			break;
+		}
+		}
+		break;
+	}
+	case AF_INET6: {
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -626,9 +629,9 @@
 }
 
-int getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen)
+int shell_getsockopt(int fd, int level, int optname, void *optval, socklen_t *__restrict optlen)
 {
 	SOCKET *fp = fd_to_fp(fd);
 	if (fp == NULL) {
-		return -1;
+		return -EBADF;
 	}
 
@@ -650,5 +653,5 @@
 				ret = tcp_get_opt(fp->socket.cepid, optname, (void *)optval, *optlen);
 				if (ret < 0) {
-					return -1;
+					return -EINVAL;
 				}
 				*optlen = ret;
@@ -660,5 +663,5 @@
 			ret = udp_get_opt(fp->socket.cepid, optname, (void *)optval, *optlen);
 			if (ret < 0) {
-				return -1;
+				return -EINVAL;
 			}
 			*optlen = ret;
@@ -669,5 +672,5 @@
 	}
 	case AF_INET6: {
-		break;
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -676,9 +679,9 @@
 }
 
-int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
+int shell_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
 {
 	SOCKET *fp = fd_to_fp(fd);
 	if (fp == NULL) {
-		return -1;
+		return -EBADF;
 	}
 
@@ -700,5 +703,5 @@
 				ret = tcp_set_opt(fp->socket.cepid, optname, (void *)optval, optlen);
 				if (ret < 0) {
-					return -1;
+					return -EINVAL;
 				}
 				break;
@@ -709,13 +712,13 @@
 			ret = udp_set_opt(fp->socket.cepid, optname, (void *)optval, optlen);
 			if (ret < 0) {
-				return -1;
-			}
-			break;
-		}
-		}
-		break;
-	}
-	case AF_INET6: {
-		break;
+				return -EINVAL;
+			}
+			break;
+		}
+		}
+		break;
+	}
+	case AF_INET6: {
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -735,5 +738,5 @@
 				//return -1;
 			}
-			ret = tcp_cls_cep(cepid, TMO_FEVR);
+			ret = tcp_cls_cep(cepid, (fp->socket.repid != 0) ? 0 : SOCKET_TIMEOUT);
 			if (ret < 0) {
 				//return -1;
@@ -743,5 +746,5 @@
 			delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
 			if (ret < 0) {
-				return -1;
+				return -EINVAL;
 			}
 		}
@@ -752,14 +755,14 @@
 			delete_id(tcp_repid_table, tcp_repid_table_count, repid);
 			if (ret < 0) {
-				return -1;
+				return -EINVAL;
 			}
 		}
 		else {
-			return -1;
-		}
-		break;
-	}
-	case AF_INET6: {
-		break;
+			return -EINVAL;
+		}
+		break;
+	}
+	case AF_INET6: {
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -770,15 +773,20 @@
 size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
 {
-	return recv(fp->fd, dst, dstsz, 0);
+	return shell_recv(fp->fd, dst, dstsz, 0);
 }
 
 size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
 {
-	return send(fp->fd, src, srcsz, 0);
+	return shell_send(fp->fd, src, srcsz, 0);
 }
 
 off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
 {
-	return -1;
+	return -EPERM;
+}
+
+int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
+{
+	return -EINVAL;
 }
 
@@ -794,10 +802,10 @@
 		delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
 		if (ret < 0) {
-			return -1;
-		}
-		break;
-	}
-	case AF_INET6: {
-		break;
+			return -EINVAL;
+		}
+		break;
+	}
+	case AF_INET6: {
+		return -EAFNOSUPPORT;
 	}
 	}
@@ -808,15 +816,20 @@
 size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
 {
-	return recv(fp->fd, dst, dstsz, 0);
+	return shell_recv(fp->fd, dst, dstsz, 0);
 }
 
 size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
 {
-	return send(fp->fd, src, srcsz, 0);
+	return shell_send(fp->fd, src, srcsz, 0);
 }
 
 off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
 {
-	return -1;
+	return -EPERM;
+}
+
+int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
+{
+	return -EINVAL;
 }
 
Index: EcnlProtoTool/trunk/ntshell/src/socket_stub.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/socket_stub.h	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/socket_stub.h	(revision 331)
@@ -38,12 +38,4 @@
 #define SOCKET_STUB_H
 
-typedef unsigned socklen_t;
-typedef unsigned short sa_family_t;
-
-struct sockaddr {
-	sa_family_t sa_family;
-	char sa_data[14];
-};
-
 struct addrinfo {
 	int ai_flags;
@@ -57,10 +49,4 @@
 };
 
-#define AF_INET		2
-#define AF_INET6	10
-
-#define SOCK_STREAM	1
-#define SOCK_DGRAM	2
-
 typedef uint16_t in_port_t;
 typedef uint32_t in_addr_t;
@@ -82,7 +68,7 @@
 	} __in6_union;
 };
-#define s6_addr __in6_union.__s6_addr
-#define s6_addr16 __in6_union.__s6_addr16
-#define s6_addr32 __in6_union.__s6_addr32
+//#define s6_addr __in6_union.__s6_addr
+//#define s6_addr16 __in6_union.__s6_addr16
+//#define s6_addr32 __in6_union.__s6_addr32
 
 struct sockaddr_in6
@@ -94,6 +80,4 @@
 	uint32_t        sin6_scope_id;
 };
-
-#define MSG_OOB       0x0001
 
 typedef struct socket_t {
@@ -124,4 +108,6 @@
 	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;
@@ -132,4 +118,8 @@
 	union {
 		FIL file;
+		struct {
+			DIR dir;
+			struct dirent dirent;
+		};
 		socket_t socket;
 	};
@@ -156,16 +146,30 @@
 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);
@@ -179,4 +183,8 @@
 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);
Index: EcnlProtoTool/trunk/ntshell/src/syscall.c
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/syscall.c	(revision 331)
+++ EcnlProtoTool/trunk/ntshell/src/syscall.c	(revision 331)
@@ -0,0 +1,977 @@
+/*
+ *  TOPPERS ECHONET Lite Communication Middleware
+ * 
+ *  Copyright (C) 2017 Cores Co., Ltd. Japan
+ * 
+ *  ä¸è¨èä½æ¨©è
+ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
+ *  ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ãä½¿ç¨ã»è¤è£½ã»æ¹
+ *  å¤ã»åé
+å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
+ *  (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
+ *      æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
+ *      ã¹ã³ã¼ãä¸­ã«å«ã¾ãã¦ãããã¨ï¼
+ *  (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
+ *      ç¨ã§ããå½¢ã§åé
+å¸ããå ´åã«ã¯ï¼åé
+å¸ã«ä¼´ããã­ã¥ã¡ã³ãï¼å©ç¨
+ *      è
+ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
+ *      ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
+ *  (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
+ *      ç¨ã§ããªãå½¢ã§åé
+å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
+ *      ã¨ï¼
+ *    (a) åé
+å¸ã«ä¼´ããã­ã¥ã¡ã³ãï¼å©ç¨è
+ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
+ *        ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
+ *    (b) åé
+å¸ã®å½¢æ
+ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSãã­ã¸ã§ã¯ãã«
+ *        å ±åãããã¨ï¼
+ *  (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
+ *      å®³ãããï¼ä¸è¨èä½æ¨©è
+ããã³TOPPERSãã­ã¸ã§ã¯ããå
+è²¬ãããã¨ï¼
+ *      ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
+ *      ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
+ããã³TOPPERSãã­ã¸ã§ã¯ãã
+ *      å
+è²¬ãããã¨ï¼
+ * 
+ *  æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
+ã
+ *  ãã³TOPPERSãã­ã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
+ *  ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
+ *  ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ã
+ *  ã®è²¬ä»»ãè² ããªãï¼
+ * 
+ *  @(#) $Id$
+ */
+#define _CRT_NO_TIME_T
+#include "../../musl-1.1.18/include/bits/syscall.h"
+#include "shellif.h"
+#include <t_syslog.h>
+#include "MBRZA1H.h"
+
+void *thread_area;
+void *tid_address;
+
+// https://os.mbed.com/users/dkato/code/FlashAccess/#652a093cf264
+void flash_access_cache_control(void) {
+    unsigned int assoc;
+
+    /* ==== Cleaning and invalidation of the L1 data cache ==== */
+    __v7_all_cache(2);
+    __DSB();
+
+    /* ==== Cleaning and invalidation of the L2 cache ==== */
+    if (PL310->AUX_CNT & (1<<16)) {
+        assoc = 16;
+    } else {
+        assoc =  8;
+    }
+    PL310->INV_WAY = (1 << assoc) - 1;
+    while(PL310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate
+    PL310->CACHE_SYNC = 0x0;
+
+    /* ==== Invalidate all TLB entries ==== */
+    __ca9u_inv_tlb_all();
+
+    /* ==== Invalidate the L1 instruction cache ==== */
+    __v7_inv_icache_all();
+    __DSB();
+    __ISB();
+}
+
+void no_implement(const char *text)
+{
+	syslog(LOG_ERROR, text);
+	asm("bkpt #0");
+}
+
+static long __syscall(struct regs_t *r)
+{
+	long ret = -ENOSYS;
+
+	shellif_into();
+
+	switch (r->n) {
+	case SYS__llseek:
+		return shell_llseek(r->a, (((off_t)r->b) << 32) + (off_t)r->c, (off_t *)r->d, r->e);
+	case SYS__newselect:
+		ret = shell_select(r->a, (fd_set *)r->b, (fd_set *)r->c, (fd_set *)r->d, (struct timeval *)r->e);
+		break;
+	case SYS_accept:
+		ret = shell_accept(r->a, (struct sockaddr *)r->b, (socklen_t *)r->c);
+		break;
+	case SYS_access:
+		ret = shell_access((const char *)r->a, r->b);
+		break;
+	case SYS_acct:
+		no_implement("acct\n");
+		break;
+	case SYS_adjtimex:
+		no_implement("adjtimex\n");
+		break;
+#ifdef SYS_arch_prctl
+	case SYS_arch_prctl:
+		no_implement("arch_prctl\n");
+		break;
+#endif
+	case SYS_bind:
+		ret = shell_bind(r->a, (const struct sockaddr *)r->b, (socklen_t)r->c);
+		break;
+	case SYS_brk:
+		ret = (long)shell_brk((void *)r->a);
+		break;
+#ifdef SYS_cachectl
+	case SYS_cachectl:
+		no_implement("cachectl\n");
+		break;
+#endif
+#ifdef SYS_cacheflush
+	case SYS_cacheflush:
+		no_implement("cacheflush\n");
+		break;
+#endif
+	case SYS_capget:
+		no_implement("capget\n");
+		break;
+	case SYS_capset:
+		no_implement("capset\n");
+		break;
+	case SYS_chdir:
+		ret = shell_chdir((const char *)r->a);
+		break;
+	case SYS_chmod:
+		ret = shell_chmod((const char *)r->a, (mode_t)r->b);
+		break;
+	case SYS_chown32:
+		no_implement("chown\n");
+		break;
+	case SYS_chroot:
+		ret = shell_chroot((const char *)r->a);
+		break;
+	case SYS_clock_adjtime:
+		no_implement("clock_adjtime\n");
+		break;
+	case SYS_clock_getres:
+		ret = shell_clock_getres((clockid_t)r->a, (struct timespec *)r->b);
+		break;
+	case SYS_clock_gettime:
+		ret = shell_clock_gettime((clockid_t)r->a, (struct timespec *)r->b);
+		break;
+	case SYS_clock_nanosleep:
+		no_implement("clock_nanosleep\n");
+		break;
+	case SYS_clock_settime:
+		ret = shell_clock_settime((clockid_t)r->a, (const struct timespec *)r->b);
+		break;
+	case SYS_clone:
+		no_implement("clone\n");
+		break;
+	case SYS_close:
+		ret = shell_close(r->a);
+		break;
+	case SYS_connect:
+		ret = shell_connect(r->a, (const struct sockaddr *)r->b, (socklen_t)r->c);
+		break;
+	case SYS_delete_module:
+		no_implement("delete_module\n");
+		break;
+	case SYS_dup:
+		no_implement("dup\n");
+		break;
+	case SYS_dup2:
+		no_implement("dup2\n");
+		break;
+	case SYS_dup3:
+		no_implement("dup3\n");
+		break;
+	case SYS_epoll_create:
+		no_implement("epoll_create\n");
+		break;
+	case SYS_epoll_create1:
+		no_implement("epoll_create1\n");
+		break;
+	case SYS_epoll_ctl:
+		no_implement("epoll_ctl\n");
+		break;
+	case SYS_epoll_pwait:
+		no_implement("epoll_pwait\n");
+		break;
+	case SYS_epoll_wait:
+		no_implement("epoll_wait\n");
+		break;
+	case SYS_eventfd:
+		no_implement("eventfd\n");
+		break;
+	case SYS_eventfd2:
+		no_implement("eventfd2\n");
+		break;
+	case SYS_execve:
+		no_implement("execve\n");
+		break;
+	case SYS_exit:
+		shell_exit(r->a);
+		ret = 0;
+		break;
+	case SYS_exit_group:
+		shell_exit_group(r->a);
+		ret = 0;
+		break;
+	case SYS_faccessat:
+		no_implement("faccessat\n");
+		break;
+	case SYS_fadvise64_64:
+		no_implement("fadvise64_64\n");
+		break;
+	case SYS_fallocate:
+		no_implement("fallocate\n");
+		break;
+	case SYS_fanotify_init:
+		no_implement("fanotify_init\n");
+		break;
+	case SYS_fanotify_mark:
+		no_implement("fanotify_mark\n");
+		break;
+	case SYS_fchdir:
+		no_implement("fchdir\n");
+		break;
+	case SYS_fchmod:
+		no_implement("fchmod\n");
+		break;
+	case SYS_fchmodat:
+		no_implement("fchmodat\n");
+		break;
+	case SYS_fchown32:
+		no_implement("fchown\n");
+		break;
+	case SYS_fchownat:
+		no_implement("fchownat\n");
+		break;
+	case SYS_fcntl64:
+		ret = shell_fcntl((int)r->a, (int)r->b, (void *)r->c);
+		break;
+	case SYS_fdatasync:
+		no_implement("fdatasync\n");
+		break;
+	case SYS_fgetxattr:
+		no_implement("fgetxattr\n");
+		break;
+	case SYS_flistxattr:
+		no_implement("flistxattr\n");
+		break;
+	case SYS_flock:
+		no_implement("flock\n");
+		break;
+	case SYS_fork:
+		no_implement("fork\n");
+		break;
+	case SYS_fremovexattr:
+		no_implement("fremovexattr\n");
+		break;
+	case SYS_fsetxattr:
+		no_implement("fsetxattr\n");
+		break;
+	case SYS_fstat64:
+		ret = shell_fstat((int)r->a, (struct stat *)r->b);
+		break;
+	case SYS_fstatat64:
+		no_implement("fstatat64\n");
+		break;
+	case SYS_fstatfs:
+		no_implement("fstatfs\n");
+		break;
+	case SYS_fstatfs64:
+		no_implement("fstatfs64\n");
+		break;
+	case SYS_fsync:
+		ret = shell_fsync(r->a);
+		break;
+	case SYS_ftruncate64:
+		ret = shell_ftruncate((int)r->a, (((off_t)r->b) << 32) + (off_t)r->c);
+		break;
+	case SYS_futex:
+		no_implement("futex\n");
+		break;
+	case SYS_futimesat:
+		no_implement("futimesat\n");
+		break;
+	case SYS_getcpu:
+		no_implement("getcpu\n");
+		break;
+	case SYS_getcwd:
+		ret = (long)shell_getcwd((char *)r->a, (size_t)r->b);
+		break;
+	case SYS_getdents64:
+		ret = shell_getdents((int)r->a, (struct dirent *)r->b, (size_t)r->c);	// TODO
+		break;
+	case SYS_getegid32:
+		no_implement("getegid\n");
+		break;
+	case SYS_geteuid32:
+		no_implement("geteuid\n");
+		break;
+	case SYS_getgid32:
+		no_implement("getgid\n");
+		break;
+	case SYS_getgroups32:
+		no_implement("getgroups\n");
+		break;
+	case SYS_getitimer:
+		no_implement("getitimer\n");
+		break;
+	case SYS_getpgid:
+		no_implement("getpgid\n");
+		break;
+	case SYS_getpid:
+		ret = shell_getpid();
+		break;
+	case SYS_getppid:
+		no_implement("getppid\n");
+		break;
+	case SYS_getpriority:
+		no_implement("getpriority\n");
+		break;
+	case SYS_getresgid32:
+		no_implement("getresgid\n");
+		break;
+	case SYS_getresuid32:
+		no_implement("getresuid\n");
+		break;
+#ifdef SYS_getrlimit
+	case SYS_getrlimit:
+		no_implement("getrlimit\n");
+		break;
+#endif
+	case SYS_getrusage:
+		no_implement("getrusage\n");
+		break;
+	case SYS_getsid:
+		no_implement("getsid\n");
+		break;
+	case SYS_getsockopt:
+		ret = shell_getsockopt(r->a, r->b, r->c, (void *)r->d, (socklen_t *)r->e);
+		break;
+	case SYS_gettid:
+		no_implement("gettid\n");
+		break;
+	case SYS_gettimeofday:
+		ret = shell_gettimeofday((struct timeval *)r->a, (void *)r->b);
+		break;
+	case SYS_getuid32:
+		no_implement("getuid\n");
+		break;
+	case SYS_getxattr:
+		no_implement("getxattr\n");
+		break;
+	case SYS_init_module:
+		no_implement("init_module\n");
+		break;
+	case SYS_inotify_add_watch:
+		no_implement("inotify_add_watch\n");
+		break;
+	case SYS_inotify_init:
+		no_implement("inotify_init\n");
+		break;
+	case SYS_inotify_init1:
+		no_implement("inotify_init1\n");
+		break;
+	case SYS_inotify_rm_watch:
+		no_implement("inotify_rm_watch\n");
+		break;
+	case SYS_ioctl:
+		ret = shell_ioctl((int)r->a, (int)r->b, (void *)r->c);
+		break;
+#ifdef SYS_ioperm
+	case SYS_ioperm:
+		no_implement("ioperm\n");
+		break;
+#endif
+#ifdef SYS_iopl
+	case SYS_iopl:
+		no_implement("iopl\n");
+		break;
+#endif
+#ifdef SYS_ipc
+	case SYS_ipc:
+		no_implement("ipc\n");
+		break;
+#endif
+#ifdef SYS_ipc
+	case SYS_ipc:
+		no_implement("ipc\n");
+		break;
+#endif
+	case SYS_kill:
+		ret = shell_kill(r->a, r->b);
+		break;
+	case SYS_lchown32:
+		no_implement("lchown\n");
+		break;
+	case SYS_lgetxattr:
+		no_implement("lgetxattr\n");
+		break;
+	case SYS_link:
+		ret = shell_link((const char *)r->a, (const char *)r->b);
+		break;
+	case SYS_linkat:
+		no_implement("linkat\n");
+		break;
+	case SYS_listen:
+		ret = shell_listen(r->a, r->b);
+		break;
+	case SYS_listxattr:
+		no_implement("listxattr\n");
+		break;
+	case SYS_llistxattr:
+		no_implement("llistxattr\n");
+		break;
+	case SYS_lremovexattr:
+		no_implement("lremovexattr\n");
+		break;
+	case SYS_lsetxattr:
+		no_implement("lsetxattr\n");
+		break;
+	case SYS_lstat64:
+		ret = shell_lstat((const char *__restrict)r->a, (struct stat *__restrict)r->b);
+		break;
+	case SYS_madvise:
+		ret = shell_madvise((void *)r->a, (size_t)r->b, (int)r->c);	// TODO
+		break;
+	case SYS_mincore:
+		no_implement("mincore\n");
+		break;
+	case SYS_mkdir:
+		ret = shell_mkdir((const char *)r->a, (mode_t)r->b);
+		break;
+	case SYS_mkdirat:
+		no_implement("mkdirat\n");
+		break;
+	case SYS_mknod:
+		no_implement("mknod\n");
+		break;
+	case SYS_mknodat:
+		no_implement("mknodat\n");
+		break;
+	case SYS_mlock:
+		no_implement("mlock\n");
+		break;
+	case SYS_mlockall:
+		no_implement("mlockall\n");
+		break;
+	case SYS_mmap2:
+		ret = (int)shell_mmap2((void *)r->a, (size_t)r->b, r->c, r->d, r->e, (off_t)r->f);
+		break;
+	case SYS_mount:
+		no_implement("mount\n");
+		break;
+	case SYS_mprotect:
+		return shell_mprotect((void *)r->a, (size_t)r->b, r->c);
+		break;
+	case SYS_mq_getsetattr:
+		no_implement("mq_getsetattr\n");
+		break;
+	case SYS_mq_notify:
+		no_implement("mq_notify\n");
+		break;
+	case SYS_mq_open:
+		no_implement("mq_open\n");
+		break;
+	case SYS_mq_timedreceive:
+		no_implement("mq_timedreceive\n");
+		break;
+	case SYS_mq_timedsend:
+		no_implement("mq_timedsend\n");
+		break;
+	case SYS_mq_unlink:
+		no_implement("mq_unlink\n");
+		break;
+	case SYS_mremap:
+		no_implement("mremap\n");
+		break;
+	case SYS_msgctl:
+		no_implement("msgctl\n");
+		break;
+	case SYS_msgget:
+		no_implement("msgget\n");
+		break;
+	case SYS_msgrcv:
+		no_implement("msgrcv\n");
+		break;
+	case SYS_msgsnd:
+		no_implement("msgsnd\n");
+		break;
+	case SYS_msync:
+		no_implement("msync\n");
+		break;
+	case SYS_munlock:
+		no_implement("munlock\n");
+		break;
+	case SYS_munlockall:
+		no_implement("munlockall\n");
+		break;
+	case SYS_munmap:
+		no_implement("munmap\n");
+		break;
+	case SYS_nanosleep:
+		no_implement("nanosleep\n");
+		break;
+	case SYS_nice:
+		no_implement("nice\n");
+		break;
+	case SYS_open:
+		ret = shell_open((const char *)r->a, (int)r->b, (void *)r->c);
+		break;
+	case SYS_openat:
+		no_implement("openat\n");
+		break;
+	case SYS_pause:
+		no_implement("pause\n");
+		break;
+	case SYS_personality:
+		no_implement("personality\n");
+		break;
+	case SYS_pipe:
+		no_implement("pipe\n");
+		break;
+	case SYS_pipe2:
+		no_implement("pipe2\n");
+		break;
+	case SYS_pivot_root:
+		no_implement("pivot_root\n");
+		break;
+	case SYS_poll:
+		ret = shell_poll((struct pollfd *)r->a, (nfds_t)r->b, (int)r->c);
+		break;
+	case SYS_ppoll:
+		no_implement("ppoll\n");
+		break;
+	case SYS_prctl:
+		no_implement("prctl\n");
+		break;
+	case SYS_pread64:
+		no_implement("pread64\n");
+		break;
+	case SYS_preadv:
+		no_implement("preadv\n");
+		break;
+	case SYS_prlimit64:
+		no_implement("prlimit64\n");
+		break;
+	case SYS_process_vm_readv:
+		no_implement("process_vm_readv\n");
+		break;
+	case SYS_process_vm_writev:
+		no_implement("process_vm_writev\n");
+		break;
+	case SYS_pselect6:
+		no_implement("pselect6\n");
+		break;
+	case SYS_ptrace:
+		no_implement("ptrace\n");
+		break;
+	case SYS_pwrite64:
+		no_implement("pwrite64\n");
+		break;
+	case SYS_pwritev:
+		no_implement("pwritev\n");
+		break;
+	case SYS_quotactl:
+		no_implement("quotactl\n");
+		break;
+	case SYS_read:
+		ret = shell_read((int)r->a, (void *)r->b, (size_t)r->c);
+		break;
+	case SYS_readahead:
+		no_implement("readahead\n");
+		break;
+	case SYS_readlink:
+		no_implement("readlink\n");
+		break;
+	case SYS_readlinkat:
+		no_implement("readlinkat\n");
+		break;
+	case SYS_readv:
+		ret = shell_readv((int)r->a, (const struct iovec *)r->b, (int)r->c);
+		break;
+	case SYS_recv:
+		ret = shell_recv(r->a, (void *)r->b, (size_t)r->c, r->d);
+		break;
+	case SYS_recvfrom:
+		if (r->e == 0)
+			ret = shell_recv(r->a, (void *)r->b, (size_t)r->c, r->d);
+		else
+			ret = shell_recvfrom(r->a, (void *)r->b, (size_t)r->c, r->d, (struct sockaddr *)r->e, (socklen_t *)r->f);
+		break;
+	case SYS_recvmsg:
+		ret = shell_recvmsg(r->a, (struct msghdr *)r->b, (size_t)r->c);
+		break;
+	case SYS_reboot:
+		no_implement("reboot\n");
+		break;
+	case SYS_recvmmsg:
+		no_implement("recvmmsg\n");
+		break;
+	case SYS_remap_file_pages:
+		no_implement("remap_file_pages\n");
+		break;
+	case SYS_removexattr:
+		no_implement("removexattr\n");
+		break;
+	case SYS_rename:
+		ret = shell_rename((const char *)r->a, (const char *)r->b);
+		break;
+	case SYS_renameat:
+		no_implement("renameat\n");
+		break;
+	case SYS_rmdir:
+		ret = shell_rmdir((const char *)r->a);
+		break;
+	case SYS_rt_sigaction:
+		ret = shell_sigaction(r->a, (const struct sigaction *)r->b, (struct sigaction *)r->c);
+		break;
+	case SYS_rt_sigpending:
+		no_implement("rt_sigpending\n");
+		break;
+	case SYS_rt_sigprocmask:
+		ret = shell_sigprocmask(r->a, (const sigset_t *)r->b, (sigset_t *)r->c);
+		break;
+	case SYS_rt_sigqueueinfo:
+		no_implement("rt_sigqueueinfo\n");
+		break;
+	case SYS_rt_sigsuspend:
+		no_implement("rt_sigsuspend\n");
+		break;
+	case SYS_rt_sigtimedwait:
+		no_implement("rt_sigtimedwait\n");
+		break;
+	case SYS_send:
+		ret = shell_send(r->a, (const void *)r->b, (size_t)r->c, r->d);
+		break;
+	case SYS_sendmsg:
+		ret = shell_sendmsg(r->a, (const struct msghdr *)r->b, (size_t)r->c);
+		break;
+	case SYS_sendto:
+		if (r->e == 0)
+			ret = shell_send(r->a, (const void *)r->b, (size_t)r->c, r->d);
+		else
+			ret = shell_sendto(r->a, (const void *)r->b, (size_t)r->c, r->d, (const struct sockaddr *)r->e, (socklen_t)r->f);
+		break;
+	case SYS_setsockopt:
+		ret = shell_setsockopt(r->a, r->b, r->c, (const void *)r->d, (socklen_t)r->e);
+		break;
+	case SYS_shutdown:
+		ret = shell_shutdown(r->a, r->b);
+		break;
+	case SYS_sched_get_priority_max:
+		no_implement("sched_get_priority_max\n");
+		break;
+	case SYS_sched_get_priority_min:
+		no_implement("sched_get_priority_min\n");
+		break;
+	case SYS_sched_getaffinity:
+		no_implement("sched_getaffinity\n");
+		break;
+	case SYS_sched_getparam:
+		no_implement("sched_getparam\n");
+		break;
+	case SYS_sched_getscheduler:
+		no_implement("sched_getscheduler\n");
+		break;
+	case SYS_sched_rr_get_interval:
+		no_implement("sched_rr_get_interval\n");
+		break;
+	case SYS_sched_setaffinity:
+		no_implement("sched_setaffinity\n");
+		break;
+	case SYS_sched_setparam:
+		no_implement("sched_setparam\n");
+		break;
+	case SYS_sched_setscheduler:
+		no_implement("sched_setscheduler\n");
+		break;
+	case SYS_sched_yield:
+		no_implement("sched_yield\n");
+		break;
+	case SYS_semctl:
+		no_implement("semctl\n");
+		break;
+	case SYS_semget:
+		no_implement("semget\n");
+		break;
+	case SYS_semop:
+		no_implement("semop\n");
+		break;
+	case SYS_semtimedop:
+		no_implement("semtimedop\n");
+		break;
+	case SYS_sendfile64:
+		no_implement("sendfile\n");
+		break;
+	case SYS_sendmmsg:
+		no_implement("sendmmsg\n");
+		break;
+	case SYS_set_robust_list:
+		no_implement("set_robust_list\n");
+		break;
+#ifdef SYS_set_thread_area
+	case SYS_set_thread_area:
+		thread_area = (void *)r->a;
+		__asm__ __volatile__ ( "mcr p15,0,%0,c13,c0,3" :: "r"(thread_area) );
+		ret = 0;
+		break;
+#endif
+	case SYS_set_tid_address:
+		tid_address = (void *)r->a;
+		ret = 0;
+		break;
+	case SYS_setdomainname:
+		no_implement("setdomainname\n");
+		break;
+	case SYS_setfsgid32:
+		no_implement("setfsgid\n");
+		break;
+	case SYS_setfsuid32:
+		no_implement("setfsuid\n");
+		break;
+	case SYS_setgroups32:
+		no_implement("setgroups\n");
+		break;
+	case SYS_sethostname:
+		no_implement("sethostname\n");
+		break;
+	case SYS_setitimer:
+		no_implement("setitimer\n");
+		break;
+	case SYS_setns:
+		no_implement("setns\n");
+		break;
+	case SYS_setpgid:
+		no_implement("setpgid\n");
+		break;
+	case SYS_setpriority:
+		no_implement("setpriority\n");
+		break;
+	case SYS_setrlimit:
+		no_implement("setrlimit\n");
+		break;
+	case SYS_setsid:
+		no_implement("setsid\n");
+		break;
+	case SYS_settimeofday:
+		no_implement("settimeofday\n");
+		break;
+	case SYS_setxattr:
+		no_implement("setxattr\n");
+		break;
+	case SYS_shmat:
+		no_implement("shmat\n");
+		break;
+	case SYS_shmctl:
+		no_implement("shmctl\n");
+		break;
+	case SYS_shmdt:
+		no_implement("shmdt\n");
+		break;
+	case SYS_shmget:
+		no_implement("shmget\n");
+		break;
+	case SYS_sigaltstack:
+		no_implement("sigaltstack\n");
+		break;
+	case SYS_signalfd:
+		no_implement("signalfd\n");
+		break;
+	case SYS_signalfd4:
+		no_implement("signalfd4\n");
+		break;
+	case SYS_socket:
+		ret = shell_socket(r->a, r->b, r->c);
+		break;
+	case SYS_splice:
+		no_implement("splice\n");
+		break;
+	case SYS_stat64:
+		ret = shell_stat((const char *)r->a, (struct stat *)r->b);
+		break;
+	case SYS_statfs64:
+		no_implement("statfs64\n");
+		break;
+	case SYS_swapoff:
+		no_implement("swapoff\n");
+		break;
+	case SYS_swapon:
+		no_implement("swapon\n");
+		break;
+	case SYS_symlink:
+		no_implement("symlink\n");
+		break;
+	case SYS_symlinkat:
+		no_implement("symlinkat\n");
+		break;
+	case SYS_sync:
+		no_implement("sync\n");
+		break;
+#ifdef SYS_sync_file_range
+	case SYS_sync_file_range:
+		no_implement("sync_file_range\n");
+		break;
+#endif
+	case SYS_sync_file_range2:
+		no_implement("sync_file_range2\n");
+		break;
+	case SYS_syncfs:
+		no_implement("syncfs\n");
+		break;
+	case SYS_sysinfo:
+		no_implement("sysinfo\n");
+		break;
+	case SYS_syslog:
+		no_implement("syslog\n");
+		break;
+	case SYS_tee:
+		no_implement("tee\n");
+		break;
+	case SYS_tgkill:
+		no_implement("tgkill\n");
+		break;
+	case SYS_timer_create:
+		no_implement("timer_create\n");
+		break;
+	case SYS_timer_delete:
+		no_implement("timer_delete\n");
+		break;
+	case SYS_timer_getoverrun:
+		no_implement("timer_getoverrun\n");
+		break;
+	case SYS_timer_gettime:
+		no_implement("timer_gettime\n");
+		break;
+	case SYS_timer_settime:
+		no_implement("timer_settime\n");
+		break;
+	case SYS_timerfd_create:
+		no_implement("timerfd_create\n");
+		break;
+	case SYS_timerfd_gettime:
+		no_implement("timerfd_gettime\n");
+		break;
+	case SYS_timerfd_settime:
+		no_implement("timerfd_settime\n");
+		break;
+	case SYS_times:
+		no_implement("times\n");
+		break;
+	case SYS_tkill:
+		no_implement("tkill\n");
+		break;
+	case SYS_truncate64:
+		no_implement("truncate\n");
+		break;
+	case SYS_ugetrlimit:
+		no_implement("ugetrlimit\n");
+		break;
+	case SYS_umask:
+		no_implement("umask\n");
+		break;
+	case SYS_umount2:
+		no_implement("umount2\n");
+		break;
+	case SYS_uname:
+		ret = shell_uname((struct utsname *)r->a);
+		break;
+	case SYS_unlink:
+		ret = shell_unlink((const char *)r->a);
+		break;
+	case SYS_unlinkat:
+		no_implement("unlinkat\n");
+		break;
+	case SYS_unshare:
+		no_implement("unshare\n");
+		break;
+	case SYS_utimensat:
+		no_implement("utimensat\n");
+		break;
+	case SYS_utimes:
+		no_implement("utimes\n");
+		break;
+	case SYS_vhangup:
+		no_implement("vhangup\n");
+		break;
+	case SYS_vmsplice:
+		no_implement("vmsplice\n");
+		break;
+	case SYS_wait4:
+		no_implement("wait4\n");
+		break;
+	case SYS_waitid:
+		no_implement("waitid\n");
+		break;
+	case SYS_write:
+		ret = shell_write((int)r->a, (const void *)r->b, (size_t)r->c);
+		break;
+	case SYS_writev:
+		ret = shell_writev((int)r->a, (const struct iovec *)r->b, (size_t)r->c);
+		break;
+	default:
+		switch (r->n) {
+		case 0xf0002:
+			flash_access_cache_control();
+			ret = 0;
+			break;
+		case 0xf0005:
+			// __set_thread_area
+			thread_area = (void *)r->a;
+			__asm__ __volatile__ ( "mcr p15,0,%0,c13,c0,3" :: "r"(thread_area) );
+			ret = 0;
+			break;
+		default:
+			asm("bkpt #0");
+			break;
+		}
+		break;
+	}
+
+	shellif_outof();
+
+	return ret;
+}
+
+void __attribute__((naked)) __syscall_cp_asm()
+{
+	register long sp asm("sp");
+	asm("push	{r0, r1, r2, r3, r4, r5, r7, r12, lr}");
+	__syscall((struct regs_t *)sp);
+	asm("add	sp, sp, #4");
+	asm("pop	{r1, r2, r3, r4, r5, r7, r12, pc}");
+}
+
+/*
+ *  ã¹ã¼ããã¤ã¶ã³ã¼ã«
+ */
+void __attribute__((naked)) _kernel_svc_handler(void)
+{
+	register long r0 asm("r0");
+	asm("srsfd	#0x13!");
+	asm("stmfd	sp!, {r0-r3,r12,lr}");
+	asm("mrs	r0, spsr");
+	asm("tst	r0, #0x20");
+	asm("ldrneh	r0, [lr,#-2]");
+	asm("bicne	r0, r0, #0xFF00");
+	asm("ldreq	r0, [lr,#-4]");
+	asm("biceq	r0, r0, #0xFF000000");
+	switch (r0){
+	case 0:
+		asm("str	%0, [sp,#0x18]" :: "r"(__syscall_cp_asm));
+		break;
+	case 1:
+		asm("str	%0, [sp,#0x18]" :: "r"(__mbedcall_cp_asm));
+		break;
+	}
+	asm("ldmfd	sp!, {r0-r3,r12,lr}");
+	asm("rfefd	sp!");
+}
Index: EcnlProtoTool/trunk/ntshell/src/tinet_app_config.h
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/tinet_app_config.h	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/tinet_app_config.h	(revision 331)
@@ -2,5 +2,5 @@
  *  TINET (TCP/IP Protocol Stack)
  * 
- *  Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
+ *  Copyright (C) 2001-2012 by Dep. of Computer Science and Engineering
  *                   Tomakomai National College of Technology, JAPAN
  *
@@ -62,12 +62,4 @@
 
 /*
- *  TCPの能動オープンのみサポートすることを指定する。
- */
-
-#ifdef UNDEF_TCP_CFG_PASSIVE_OPEN
-#undef TCP_CFG_PASSIVE_OPEN
-#endif
-
-/*
  *  TCP 通信端点の送受信ウィンドバッファの省コピー機能
  *    注意: Makefile で指定している。
@@ -98,11 +90,15 @@
 #ifdef USE_TCP_MSS_SEG
 
+#ifdef SUPPORT_INET6
+
+#define TCP_CFG_SWBUF_CSAVE_MAX_SIZE	(IF_HDR_SIZE + IPV6_MMTU)	/* 最大サイズ */
+
+#else	/* of #ifdef SUPPORT_INET6 */
+
 #ifdef SUPPORT_INET4
 #define TCP_CFG_SWBUF_CSAVE_MAX_SIZE	(IF_HDR_SIZE + IP4_MSS)		/* 最大サイズ */
 #endif
 
-#ifdef SUPPORT_INET6
-#define TCP_CFG_SWBUF_CSAVE_MAX_SIZE	(IF_HDR_SIZE + IPV6_MMTU)	/* 最大サイズ */
-#endif
+#endif	/* of #ifdef SUPPORT_INET6 */
 
 #else	/* of #ifdef USE_TCP_MSS_SEG */
@@ -135,11 +131,15 @@
 #endif
 
+#ifdef SUPPORT_INET6
+
+#define MAX_TCP_SND_SEG			TCP6_MSS
+
+#else	/* of #ifdef SUPPORT_INET6 */
+
 #ifdef SUPPORT_INET4
 #define MAX_TCP_SND_SEG			TCP_MSS
 #endif
 
-#ifdef SUPPORT_INET6
-#define MAX_TCP_SND_SEG			TCP6_MSS
-#endif
+#endif	/* of #ifdef SUPPORT_INET6 */
 
 #endif	/* of #ifdef USE_TCP_MSS_SEG */
@@ -155,11 +155,15 @@
 #endif
 
+#ifdef SUPPORT_INET6
+
+#define DEF_TCP_RCV_SEG			TCP6_MSS
+
+#else	/* of #ifdef SUPPORT_INET6 */
+
 #ifdef SUPPORT_INET4
 #define DEF_TCP_RCV_SEG			TCP_MSS
 #endif
 
-#ifdef SUPPORT_INET6
-#define DEF_TCP_RCV_SEG			TCP6_MSS
-#endif
+#endif	/* of #ifdef SUPPORT_INET6 */
 
 #endif	/* of #ifdef USE_TCP_MSS_SEG */
@@ -235,7 +239,28 @@
 #define UDP_CFG_EXTENTIONS
 
+/* IPv6 に関する定義 */
+
+#ifdef SUPPORT_PPP
+
+#define NUM_IN6_STATIC_ROUTE_ENTRY	0
+#define NUM_IN6_REDIRECT_ROUTE_ENTRY	0
+
+#endif	/* of #ifdef SUPPORT_PPP */
+
+#ifdef SUPPORT_LOOP
+
+#define NUM_IN6_STATIC_ROUTE_ENTRY	0
+#define NUM_IN6_REDIRECT_ROUTE_ENTRY	0
+
+#endif	/* of #ifdef SUPPORT_LOOP */
+
+#ifdef SUPPORT_ETHER
+
+#define NUM_IN6_STATIC_ROUTE_ENTRY	0
+#define NUM_IN6_REDIRECT_ROUTE_ENTRY	1
+
+#endif	/* of #ifdef SUPPORT_ETHER */
+
 /* IPv4 に関する定義 */
-
-#ifdef SUPPORT_INET4
 
 #ifdef SUPPORT_PPP
@@ -253,6 +278,6 @@
 #endif
 
-#define NUM_STATIC_ROUTE_ENTRY		1
-#define NUM_REDIRECT_ROUTE_ENTRY	0
+#define NUM_IN4_STATIC_ROUTE_ENTRY	1
+#define NUM_IN4_REDIRECT_ROUTE_ENTRY	0
 
 #endif	/* of #ifdef SUPPORT_PPP */
@@ -260,5 +285,5 @@
 #ifdef SUPPORT_ETHER
 
-#ifdef DHCP_CFG
+#ifdef DHCP4_CLI_CFG
 
 #define IPV4_ADDR_LOCAL			MAKE_IPV4_ADDR(0,0,0,0)
@@ -266,5 +291,5 @@
 #define IPV4_ADDR_DEFAULT_GW		MAKE_IPV4_ADDR(0,0,0,0)
 
-#else	/* of #ifdef DHCP_CFG */
+#else	/* of #ifdef DHCP4_CLI_CFG */
 
 #define IPV4_ADDR_LOCAL			MAKE_IPV4_ADDR(192,168,137,110)
@@ -272,8 +297,8 @@
 #define IPV4_ADDR_DEFAULT_GW		MAKE_IPV4_ADDR(192,168,137,1)
 
-#endif	/* of #ifdef DHCP_CFG */
-
-#define NUM_STATIC_ROUTE_ENTRY		3
-#define NUM_REDIRECT_ROUTE_ENTRY	1
+#endif	/* of #ifdef DHCP4_CLI_CFG */
+
+#define NUM_IN4_STATIC_ROUTE_ENTRY	3
+#define NUM_IN4_REDIRECT_ROUTE_ENTRY	1
 
 #endif	/* of #ifdef SUPPORT_ETHER */
@@ -281,37 +306,8 @@
 #ifdef SUPPORT_LOOP
 
-#define NUM_STATIC_ROUTE_ENTRY		1
-#define NUM_REDIRECT_ROUTE_ENTRY	0
+#define NUM_IN4_STATIC_ROUTE_ENTRY	1
+#define NUM_IN4_REDIRECT_ROUTE_ENTRY	0
 
 #endif	/* of #ifdef SUPPORT_LOOP */
-
-#endif	/* of #ifdef SUPPORT_INET4 */
-
-/* IPv6 に関する定義 */
-
-#ifdef SUPPORT_INET6
-
-#ifdef SUPPORT_PPP
-
-#define NUM_STATIC_ROUTE_ENTRY		0
-#define NUM_REDIRECT_ROUTE_ENTRY	0
-
-#endif	/* of #ifdef SUPPORT_PPP */
-
-#ifdef SUPPORT_LOOP
-
-#define NUM_STATIC_ROUTE_ENTRY		0
-#define NUM_REDIRECT_ROUTE_ENTRY	0
-
-#endif	/* of #ifdef SUPPORT_LOOP */
-
-#ifdef SUPPORT_ETHER
-
-#define NUM_STATIC_ROUTE_ENTRY		0
-#define NUM_REDIRECT_ROUTE_ENTRY	1
-
-#endif	/* of #ifdef SUPPORT_ETHER */
-
-#endif	/* of #ifdef SUPPORT_INET6 */
 
 /*
@@ -420,5 +416,5 @@
  *    IPv6 でのみ割り当てる。
  *
- *    RX62N Ethernet Controler のディバイスドライバ（if_rx62n）の最低割当て長は、
+ *    MBED Ethernet Controler のディバイスドライバ（if_mbed）の最低割当て長は、
  *    イーサネットフレームの最短長である 60（CRC の 4 オクテットを除き、
  *    更にアラインして 62）オクテットである。
Index: EcnlProtoTool/trunk/ntshell/src/tinet_main.cfg
===================================================================
--- EcnlProtoTool/trunk/ntshell/src/tinet_main.cfg	(revision 321)
+++ EcnlProtoTool/trunk/ntshell/src/tinet_main.cfg	(revision 331)
@@ -43,4 +43,6 @@
 #include "main.h"
 
+INCLUDE("netinet/ip_igmp.cfg");
+
 /* DHCP クライアント */
 /*INCLUDE("netapp/tinet_dhcp4_cli.cfg");*/
@@ -49,48 +51,26 @@
 /* ECHONET Lite UDP 通信端点 */
 
-#ifdef SUPPORT_INET4
+VRID_TCP_REP (USR_TCP_REP1);
+VRID_TCP_REP (USR_TCP_REP2);
+VRID_TCP_REP (USR_TCP_REP3);
+VRID_TCP_REP (USR_TCP_REP4);
 
-VRID_TCP4_REP (USR_TCP_REP1);
-VRID_TCP4_REP (USR_TCP_REP2);
-VRID_TCP4_REP (USR_TCP_REP3);
-VRID_TCP4_REP (USR_TCP_REP4);
+VRID_TCP_CEP (USR_TCP_CEP1);
+VRID_TCP_CEP (USR_TCP_CEP2);
+VRID_TCP_CEP (USR_TCP_CEP3);
+VRID_TCP_CEP (USR_TCP_CEP4);
+VRID_TCP_CEP (USR_TCP_CEP5);
+VRID_TCP_CEP (USR_TCP_CEP6);
+VRID_TCP_CEP (USR_TCP_CEP7);
+VRID_TCP_CEP (USR_TCP_CEP8);
 
-VRID_TCP4_CEP (USR_TCP_CEP1);
-VRID_TCP4_CEP (USR_TCP_CEP2);
-VRID_TCP4_CEP (USR_TCP_CEP3);
-VRID_TCP4_CEP (USR_TCP_CEP4);
-VRID_TCP4_CEP (USR_TCP_CEP5);
-VRID_TCP4_CEP (USR_TCP_CEP6);
-VRID_TCP4_CEP (USR_TCP_CEP7);
-VRID_TCP4_CEP (USR_TCP_CEP8);
+VRID_UDP_CEP (USR_UDP_CEP1);
+VRID_UDP_CEP (USR_UDP_CEP2);
+VRID_UDP_CEP (USR_UDP_CEP3);
+VRID_UDP_CEP (USR_UDP_CEP4);
 
-VRID_UDP4_CEP (USR_UDP_CEP1);
-VRID_UDP4_CEP (USR_UDP_CEP2);
-VRID_UDP4_CEP (USR_UDP_CEP3);
-VRID_UDP4_CEP (USR_UDP_CEP4);
+VRID_UDP6_CEP (USR_UDP6_CEP1);
+VRID_UDP6_CEP (USR_UDP6_CEP2);
+VRID_UDP6_CEP (USR_UDP6_CEP3);
+VRID_UDP6_CEP (USR_UDP6_CEP4);
 
-#endif	/* of #ifdef SUPPORT_INET4 */
-
-#ifdef SUPPORT_INET6
-
-VRID_TCP6_REP (USR_TCP_REP1);
-VRID_TCP6_REP (USR_TCP_REP2);
-VRID_TCP6_REP (USR_TCP_REP3);
-VRID_TCP6_REP (USR_TCP_REP4);
-
-VRID_TCP6_CEP (USR_TCP_CEP1);
-VRID_TCP6_CEP (USR_TCP_CEP2);
-VRID_TCP6_CEP (USR_TCP_CEP3);
-VRID_TCP6_CEP (USR_TCP_CEP4);
-VRID_TCP6_CEP (USR_TCP_CEP5);
-VRID_TCP6_CEP (USR_TCP_CEP6);
-VRID_TCP6_CEP (USR_TCP_CEP7);
-VRID_TCP6_CEP (USR_TCP_CEP8);
-
-VRID_UDP6_CEP (USR_UDP_CEP1);
-VRID_UDP6_CEP (USR_UDP_CEP2);
-VRID_UDP6_CEP (USR_UDP_CEP3);
-VRID_UDP6_CEP (USR_UDP_CEP4);
-
-#endif	/* of #ifdef SUPPORT_INET6 */
-
