Ignore:
Timestamp:
Jan 21, 2018, 12:10:09 AM (6 years ago)
Author:
coas-nagasima
Message:

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

Location:
EcnlProtoTool/trunk/ntshell
Files:
10 added
2 deleted
31 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/ntshell/.cproject

    r279 r331  
    8585                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/asp3_dcre/mbed/targets/hal/TARGET_RENESAS/TARGET_RZ_A1H}&quot;"/>
    8686                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/asp3_dcre/mbed/targets/hal/TARGET_RENESAS/TARGET_RZ_A1H/TARGET_MBED_MBRZA1H}&quot;"/>
    87                                                                         <listOptionValue builtIn="false" value="&quot;${workspace_loc:/mruby-1.2.0/include}&quot;"/>
     87                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/mruby-1.3.0/include}&quot;"/>
    8888                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/asp3_dcre}&quot;"/>
    8989                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/ntshell/src}&quot;"/>
  • EcnlProtoTool/trunk/ntshell/.info

    r279 r331  
    44GCC_STRING=5.2-GNUARM-NONE_v16.01
    55VERSION_IDE=
    6 E2STUDIO_VERSION=5.3.1.002
     6E2STUDIO_VERSION=5.4.0.018
    77ACTIVE_CONFIGURATION=Debug
  • EcnlProtoTool/trunk/ntshell/Debug/Makefile

    r321 r331  
    203203ifdef USE_CXX
    204204        APPL_CXXOBJS := main.o
    205         APPL_COBJS := fdtable.o io_stub.o socket_stub.o ffarch.o time.o tlsf.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntstdio.o ntopt.o shellif.o
    206 else
    207         APPL_COBJS := main.o fdtable.o io_stub.o socket_stub.o ffarch.o time.o tlsf.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntstdio.o ntopt.o shellif.o
     205        APPL_COBJS := fdtable.o io_stub.o socket_stub.o ffarch.o fftime.o tlsf.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o mbedcall.o
     206else
     207        APPL_COBJS := main.o fdtable.o io_stub.o socket_stub.o ffarch.o fftime.o tlsf.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o mbedcall.o
    208208endif
    209209APPL_COBJS := $(APPL_COBJS) log_output.o vasyslog.o t_perror.o strerror.o
     
    214214endif
    215215
    216 #
    217 #  ネットワークサービスの定義
    218 #
    219 
    220 NO_USE_TINET_LIBRARY = true
    221 
    222 #  ネットワークインタフェースの選択、何れか一つ選択する。
    223 
    224 NET_IF = ether
    225 
    226 #  イーサネット・ディバイスドライバの選択
    227 
    228 NET_DEV = if_mbed
    229 
    230 #  ネットワーク層の選択
    231 
    232 #SUPPORT_INET6 = true
    233 SUPPORT_INET4 = true
    234 
    235 #  API に組込む機能の選択
    236 
    237 #API_CFG_IP4MAPPED_ADDR = true
    238 
    239 #  トランスポート層の選択
    240 
    241 SUPPORT_TCP = true
    242 SUPPORT_UDP = true
    243 
    244 #
    245 #  システムサービスの Makefile のインクルード
    246 #
    247 include $(SRCDIR)/tinet/Makefile.tinet
     216TINETDIR = tinet
     217ifdef TINETDIR
     218        #
     219        #  ネットワークサービスの定義
     220        #
     221        NO_USE_TINET_LIBRARY = true
     222
     223        #  ネットワークインタフェースの選択、何れか一つ選択する。
     224        NET_IF = ether
     225
     226        #  イーサネット・ディバイスドライバの選択
     227        NET_DEV = if_mbed
     228
     229        #  ネットワーク層の選択
     230        #SUPPORT_INET6 = true
     231        SUPPORT_INET4 = true
     232
     233        #  API に組込む機能の選択
     234        #API_CFG_IP4MAPPED_ADDR = true
     235
     236        #  トランスポート層の選択
     237        SUPPORT_TCP = true
     238        SUPPORT_UDP = true
     239
     240        # IGMPを有効に設定
     241        SUPPORT_IGMP = true
     242
     243        #
     244        #  ネットワークサービスの Makefile のインクルード
     245        #
     246        include $(SRCDIR)/$(TINETDIR)/Makefile.tinet
     247endif
    248248
    249249#
     
    272272#all: check $(OBJNAME).srec
    273273endif
    274         ruby ../shellif.rb
    275274        $(OBJCOPY) -B arm -I binary -O elf32-littlearm --rename-section .data=.boot $(OBJNAME).bin $(OBJNAME)_bin.o
    276275
     
    280279#  コンフィギュレータに関する定義
    281280#
    282 CFG_TABS := --api-table $(SRCDIR)/tinet/tcpip_api.def:tcpip \
     281ifndef TINETDIR
     282  CFG_TRB := -T $(TARGETDIR)/target_kernel.trb
     283  CFG_TABS := --api-table $(SRCDIR)/kernel/kernel_api.def \
     284                        --symval-table $(SRCDIR)/kernel/kernel_sym.def $(CFG_TABS)
     285else
     286  CFG_TRB := -T $(TINET_ROOT)/tinet.trb:tcpip -T $(TARGETDIR)/target_kernel.trb:kernel
     287  CFG_TABS := --api-table $(TINET_ROOT)/tcpip_api.def:tcpip \
    283288                        --api-table $(SRCDIR)/kernel/kernel_api.def:kernel \
    284289                        --symval-table $(SRCDIR)/tinet/tcpip_sym.def \
    285290                        --symval-table $(SRCDIR)/kernel/kernel_sym.def $(CFG_TABS)
     291endif
    286292CFG_ASMOBJS := $(CFG_ASMOBJS)
    287293CFG_COBJS := kernel_cfg.o $(CFG_COBJS)
     
    353359#
    354360KERNEL_LIB_OBJS = $(KERNEL_ASMOBJS) $(KERNEL_COBJS) $(KERNEL_LCOBJS)
    355 SYSSVC_OBJS = $(SYSSVC_ASMOBJS) $(SYSSVC_COBJS)
     361SYSSVC_OBJS = $(SYSSVC_ASMOBJS) $(SYSSVC_COBJS) $(HIDDEN_OBJS)
    356362APPL_OBJS = $(APPL_ASMOBJS) $(APPL_COBJS) $(APPL_CXXOBJS) $(APPL_BINOBJS)
    357363ALL_OBJS = $(START_OBJS) $(APPL_OBJS) $(SYSSVC_OBJS) $(CFG_OBJS) \
     
    395401cfg1_out.c cfg1_out.db: cfg1_out.timestamp ;
    396402cfg1_out.timestamp: $(APPL_CFG) $(TECSGEN_TIMESTAMP)
     403        echo $(CFG_TABS)
    397404        $(CFG) --pass 1 --kernel asp $(INCLUDES) $(CFG_TABS) \
    398405                                                -M $(DEPDIR)/cfg1_out_c.d $(TARGET_KERNEL_CFG) $<
     
    410417$(CFG2_OUT_SRCS) cfg2_out.db: kernel_cfg.timestamp ;
    411418kernel_cfg.timestamp: cfg1_out.db cfg1_out.syms cfg1_out.srec
    412         $(CFG) --pass 2 --kernel asp $(INCLUDES) -T $(TARGET_TCPIP_TRB):tcpip -T $(TARGET_KERNEL_TRB):kernel
     419        $(CFG) --pass 2 --kernel asp $(INCLUDES) $(CFG_TRB)
    413420
    414421#
     
    483490        rm -f cfg1_out.syms cfg1_out.srec $(CFG1_OUT)
    484491        rm -f cfg1_out.timestamp cfg1_out.c cfg1_out.db
    485         rm -f $(TECSGENDIR)/*
     492        rm -rf $(TECSGENDIR)
    486493ifndef KERNEL_LIB
    487494        rm -f libkernel.a
  • EcnlProtoTool/trunk/ntshell/fatfs/ff.c

    r321 r331  
    1919#include "ff.h"                 /* Declarations of FatFs API */
    2020#include "diskio.h"             /* Declarations of disk I/O functions */
    21 
     21#include "util/ntstdio.h"
     22#include "shellif.h"
    2223
    2324/*--------------------------------------------------------------------------
     
    39093910                                        if (dir[DIR_Attr] & AM_DIR) {   /* The new object is a directory */
    39103911                                                temp_new_path = (TCHAR *)ff_memalloc((_MAX_LFN + 1) * sizeof(WCHAR));
    3911                                                 snprintf(temp_new_path, _MAX_LFN, "%s/%s", path_new, basename((char *)path_old));
     3912                                                ntstdio_snprintf(temp_new_path, _MAX_LFN, "%s/%s", path_new, basename((char *)path_old));
    39123913                                                res = follow_path(&djn, temp_new_path);
    39133914                                        }
  • EcnlProtoTool/trunk/ntshell/fatfs/ff.h

    r321 r331  
    162162        const TCHAR*    pat;    /* Pointer to the name matching pattern */
    163163#endif
    164         struct dirent *dirent;
    165164} DIR;
    166165
  • EcnlProtoTool/trunk/ntshell/fatfs/ffarch.c

    r321 r331  
    3939 */
    4040
     41#include "shellif.h"
    4142#include <kernel.h>
    4243#include <stdlib.h>
     
    5051#include "ff.h"
    5152#include "tlsf.h"
    52 #include "ntstdio.h"
     53#include "util/ntstdio.h"
    5354
    5455#define SIO_PORTID 1
     
    5859static pool_t sys_pool;
    5960
    60 uint32_t  __HeapBase;
    61 uint32_t  __HeapLimit;
     61uint8_t shell_heap[64 * 1024];
    6262FATFS RomDisk;
    6363
     
    118118void sys_init(void)
    119119{
    120         sys_tlsf = tlsf_create(&__HeapBase);
     120        sys_tlsf = tlsf_create(&shell_heap);
    121121        if (sys_tlsf == NULL)
    122122                return;
    123123
    124         sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&__HeapBase) + tlsf_size(), ((size_t)&__HeapLimit - (size_t)&__HeapBase) - tlsf_size());
     124        sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&shell_heap) + tlsf_size(), sizeof(shell_heap) - tlsf_size());
    125125}
    126126
  • EcnlProtoTool/trunk/ntshell/fatfs/fftime.c

    r330 r331  
    3030#include "ff.h"
    3131
     32int shell_errno;
     33
    3234/* 2000-03-01 (mod 400 year, immediately after feb29 */
    3335#define LEAPOCH (946684800LL + 86400*(31+29))
     
    200202        * __secs_to_zone cannot safely handle them. */
    201203        if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) {
    202                 errno = EOVERFLOW;
     204                shell_errno = EOVERFLOW;
    203205                return 0;
    204206        }
    205207        //TODO:__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone);
    206208        if (__secs_to_tm((long long)*t /*+ tm->__tm_gmtoff*/, tm) < 0) {
    207                 errno = EOVERFLOW;
     209                shell_errno = EOVERFLOW;
    208210                return 0;
    209211        }
     
    220222{
    221223        if (__secs_to_tm(*t, tm) < 0) {
    222                 errno = EOVERFLOW;
     224                shell_errno = EOVERFLOW;
    223225                return 0;
    224226        }
     
    249251
    250252error:
    251         errno = EOVERFLOW;
     253        shell_errno = EOVERFLOW;
    252254        return -1;
    253255}
     
    258260        struct tm _tm;
    259261
    260         time(&temp);
     262        temp = rtc_read();
    261263        gmtime_r(&temp, &_tm);
    262264
  • EcnlProtoTool/trunk/ntshell/fatfs/sdfs.h

    r321 r331  
    2424
    2525#include <stdint.h>
    26 #include <time.h>
     26//#include <time.h>
     27#define __NEED_time_t
     28#include "../musl-1.1.18/include/bits/alltypes.h"
    2729#include "gpio_api.h"
    2830#include "spi_api.h"
  • EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.c

    r321 r331  
    5757}
    5858
     59int ntlibc_strlcpy(char *des, const char *src, int n)
     60{
     61        char *d = des, *e = &des[n];
     62        const char *s = src;
     63        while (*s && d < e) {
     64                *d = *s;
     65                d++;
     66                s++;
     67        }
     68        *d++ = '\0';
     69        return (int)d - (int)des;
     70}
     71
    5972char *ntlibc_strcat(char *des, const char *src)
    6073{
     
    7184        *d = '\0';
    7285        return des;
     86}
     87
     88int ntlibc_strlcat(char *des, const char *src, int n)
     89{
     90        char *d = des, *e = &des[n];
     91        const char *s = src;
     92        while (*d && d < e) {
     93                d++;
     94        }
     95        while (*s && d < e) {
     96                *d = *s;
     97                d++;
     98                s++;
     99        }
     100        *d++ = '\0';
     101        return (int)d - (int)des;
    73102}
    74103
     
    223252}
    224253
     254unsigned long ntlibc_strtoul(const char *restrict nptr, char **restrict endptr, int base)
     255{
     256        int cnt;
     257        int num = 0;
     258        int ofs = 0;
     259        int sign = 0;
     260        int scnt = 0;
     261        char *p = (char *)nptr;
     262        while (*p != '\0') {
     263                if (!ntlibc_isdigit(*p)) {
     264                        if (*p == ' ') {
     265                                ofs++;
     266                        }
     267                        if (*p == '+') {
     268                                sign = 0;
     269                                ofs++;
     270                                if (scnt++ > 0) {
     271                                        *endptr = p;
     272                                        break;
     273                                }
     274                        }
     275                        if (*p == '-') {
     276                                sign = 1;
     277                                ofs++;
     278                                if (scnt++ > 0) {
     279                                        *endptr = p;
     280                                        break;
     281                                }
     282                        }
     283                        *endptr = p;
     284                        break;
     285                }
     286                p++;
     287        }
     288        for (cnt = ofs; (nptr[cnt] >= '0') && (nptr[cnt] <= '9'); cnt++) {
     289                num = 10 * num + (nptr[cnt] - '0');
     290        }
     291        if (sign) {
     292                return -num;
     293        }
     294        else {
     295                return num;
     296        }
     297}
     298
    225299char *ntlibc_strchr(const char *s, int c)
    226300{
  • EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.h

    r321 r331  
    4040int ntlibc_strlen(const char *s);
    4141char *ntlibc_strcpy(char *des, const char *src);
     42int ntlibc_strlcpy(char *des, const char *src, int n);
    4243char *ntlibc_strcat(char *des, const char *src);
     44int ntlibc_strlcat(char *des, const char *src, int n);
    4345int ntlibc_strcmp(const char *s1, const char *s2);
    4446int ntlibc_stricmp(const char *s1, const char *s2);
     
    5052int ntlibc_tolower(int c);
    5153int ntlibc_atoi(const char *nptr);
     54unsigned long ntlibc_strtoul(const char *__restrict nptr, char **__restrict endptr, int base);
    5255char *ntlibc_strchr(const char *s, int c);
    5356char *ntlibc_utoa(unsigned int value, char *s, int radix);
  • EcnlProtoTool/trunk/ntshell/ntshell/core/ntshell.c

    r321 r331  
    3333#include <string.h>
    3434#include "ntshell.h"
     35#include "core/ntlibc.h"
    3536
    3637int ntshell_exit;
     
    107108 * @param HANDLE A pointer of the handle.
    108109 */
    109 #define PROMPT_WRITE(HANDLE)            SERIAL_WRITE((HANDLE), (HANDLE)->prompt, strlen((HANDLE)->prompt))
     110#define PROMPT_WRITE(HANDLE)            SERIAL_WRITE((HANDLE), (HANDLE)->prompt, ntlibc_strlen((HANDLE)->prompt))
    110111
    111112/**
     
    114115 * @param HANDLE A pointer of the handle.
    115116 */
    116 #define PROMPT_NEWLINE(HANDLE)          SERIAL_WRITE((HANDLE), NTSHELL_PROMPT_NEWLINE, strlen(NTSHELL_PROMPT_NEWLINE))
     117#define PROMPT_NEWLINE(HANDLE)          SERIAL_WRITE((HANDLE), NTSHELL_PROMPT_NEWLINE, ntlibc_strlen(NTSHELL_PROMPT_NEWLINE))
    117118
    118119/**
     
    399400                                 * Found the suggestion.
    400401                                 */
    401                                 int n = strlen((const char *)buf);
     402                                int n = ntlibc_strlen((const char *)buf);
    402403                                VTSEND_ERASE_LINE(ntshell);
    403404                                VTSEND_CURSOR_HEAD(ntshell);
     
    429430                         * Found the suggestion.
    430431                         */
    431                         int n = strlen((const char *)buf);
     432                        int n = ntlibc_strlen((const char *)buf);
    432433                        VTSEND_ERASE_LINE(ntshell);
    433434                        VTSEND_CURSOR_HEAD(ntshell);
     
    441442                         * Recall the previous input text string.
    442443                         */
    443                         int n = strlen(SUGGEST_SOURCE(ntshell));
     444                        int n = ntlibc_strlen(SUGGEST_SOURCE(ntshell));
    444445                        VTSEND_ERASE_LINE(ntshell);
    445446                        VTSEND_CURSOR_HEAD(ntshell);
     
    484485        UNUSED_VARIABLE(ch);
    485486        text_editor_get_text(GET_EDITOR(ntshell), buf, sizeof(buf));
    486         len = strlen((const char *)buf);
     487        len = ntlibc_strlen((const char *)buf);
    487488        VTSEND_CURSOR_HEAD(ntshell);
    488489        PROMPT_WRITE(ntshell);
     
    606607        p->func_callback = func_callback;
    607608        p->extobj = extobj;
    608         strcpy(p->prompt, NTSHELL_PROMPT_DEFAULT);
     609        ntlibc_strcpy(p->prompt, NTSHELL_PROMPT_DEFAULT);
    609610
    610611        p->vtrecv.user_data = p;
     
    666667        }
    667668
    668         strcpy(p->prompt, prompt);
     669        ntlibc_strcpy(p->prompt, prompt);
    669670}
    670671
  • EcnlProtoTool/trunk/ntshell/ntshell/core/text_history.c

    r321 r331  
    3333#include <string.h>
    3434#include "text_history.h"
     35#include "core/ntlibc.h"
    3536
    3637/**
     
    145146        char *buf, const int siz)
    146147{
    147         const int text_len = strlen((const char *)text);
     148        const int text_len = ntlibc_strlen((const char *)text);
    148149        int found = 0;
    149150        int i;
     
    151152                int target = (p->rp + i) % TEXTHISTORY_DEPTH;
    152153                char *txtp = p->history + (TEXTHISTORY_MAXLEN * target);
    153                 const int target_len = strlen((const char *)txtp);
     154                const int target_len = ntlibc_strlen((const char *)txtp);
    154155                int comp_len = (target_len < text_len) ? target_len : text_len;
    155                 if ((strncmp(
     156                if ((ntlibc_strncmp(
    156157                        (const char *)txtp,
    157158                        (const char *)text, comp_len) == 0) && (comp_len > 0)) {
    158159                        if (found == index) {
    159                                 if (siz <= strlen(txtp)) {
     160                                if (siz <= ntlibc_strlen(txtp)) {
    160161                                        return -1;
    161162                                }
    162                                 strcpy((char *)buf, (char *)txtp);
     163                                ntlibc_strcpy((char *)buf, (char *)txtp);
    163164                                return 0;
    164165                        }
  • EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c

    r321 r331  
    3131 */
    3232
     33#include "shellif.h"
    3334#include <kernel.h>
     35#include <string.h>
    3436#include <t_syslog.h>
    3537#include <t_stdlib.h>
    3638#include <sil.h>
    37 #include <stdlib.h>
    38 #include <string.h>
    39 #include <stdio.h>
    40 #include <setjmp.h>
    4139#include "syssvc/syslog.h"
    4240#include "kernel_cfg.h"
     
    4644#include "ff.h"
    4745#include "usrcmd.h"
    48 #include "ntstdio.h"
    49 #include "ntshell.h"
     46#include "core/ntshell.h"
     47#include "core/ntlibc.h"
     48#include "util/ntstdio.h"
    5049
    5150extern ntstdio_t ntstdio;
    5251extern int ntshell_exit;
     52
     53/* musl_getopt from msul */
     54char *optarg;
     55int /*optind=1, opterr=1, */optopt, optpos, optreset=0;
     56extern int optind, opterr;
     57
     58static void ntstdio_write(ntstdio_t *handle, const char *str, int l)
     59{
     60        for (; *str && l >= 0; l--) {
     61                ntstdio_putc(handle, *str++);
     62        }
     63}
     64
     65static void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
     66{
     67        ntstdio_puts(&ntstdio, a);
     68        ntstdio_write(&ntstdio, b, ntlibc_strlen(b));
     69        ntstdio_write(&ntstdio, c, l);
     70        ntstdio_putc(&ntstdio, '\n');
     71}
     72
     73static int musl_getopt(int argc, char * const argv[], const char *optstring)
     74{
     75        int i;
     76        wchar_t c, d;
     77        int k, l;
     78        char *optchar;
     79
     80        if (!optind || optreset) {
     81                optreset = 0;
     82                optpos = 0;
     83                optind = 1;
     84        }
     85
     86        if (optind >= argc || !argv[optind])
     87                return -1;
     88
     89        if (argv[optind][0] != '-') {
     90                if (optstring[0] == '-') {
     91                        optarg = argv[optind++];
     92                        return 1;
     93                }
     94                return -1;
     95        }
     96
     97        if (!argv[optind][1])
     98                return -1;
     99
     100        if (argv[optind][1] == '-' && !argv[optind][2])
     101                return optind++, -1;
     102
     103        if (!optpos) optpos++;
     104        if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) {
     105                k = 1;
     106                c = 0xfffd; /* replacement char */
     107        }
     108        optchar = argv[optind]+optpos;
     109        optopt = c;
     110        optpos += k;
     111
     112        if (!argv[optind][optpos]) {
     113                optind++;
     114                optpos = 0;
     115        }
     116
     117        if (optstring[0] == '-' || optstring[0] == '+')
     118                optstring++;
     119
     120        i = 0;
     121        d = 0;
     122        do {
     123                l = mbtowc(&d, optstring+i, MB_LEN_MAX);
     124                if (l>0) i+=l; else i++;
     125        } while (l && d != c);
     126
     127        if (d != c) {
     128                if (optstring[0] != ':' && opterr)
     129                        __getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
     130                return '?';
     131        }
     132        if (optstring[i] == ':') {
     133                if (optstring[i+1] == ':') optarg = 0;
     134                else if (optind >= argc) {
     135                        if (optstring[0] == ':') return ':';
     136                        if (opterr) __getopt_msg(argv[0],
     137                                ": option requires an argument: ",
     138                                optchar, k);
     139                        return '?';
     140                }
     141                if (optstring[i+1] != ':' || optpos) {
     142                        optarg = argv[optind++] + optpos;
     143                        optpos = 0;
     144                }
     145        }
     146        return c;
     147}
    53148
    54149int shell_kill(int pid, int sig)
     
    99194        size_t i, j;
    100195        if (!s || !*s) return ".";
    101         i = strlen(s) - 1;
     196        i = ntlibc_strlen(s) - 1;
    102197        for (j = 0; j <= i; j++) if (s[j] == ':') { s = &s[j + 1]; i -= j; break; }
    103198        for (; i&&s[i] == '/'; i--) s[i] = 0;
     
    111206        size_t i, j;
    112207        if (!s || !*s) return ".";
    113         i = strlen(s) - 1;
     208        i = ntlibc_strlen(s) - 1;
    114209        for (j = 0; j <= i; j++) if (s[j] == ':') { s = &s[j + 1]; i -= j; break; }
    115210        for (; s[i] == '/'; i--) if (!i) return (s == _s) ? "/" : _s;
     
    141236        }
    142237
    143         strlcat(path, "\n", sizeof(path));
     238        ntlibc_strlcat(path, "\n", sizeof(path));
    144239        ntstdio_printf(&ntstdio, path);
    145240
     
    287382        char *pattern_p = NULL, *basename_p = NULL, *dirname_p = NULL;
    288383        char default_pattern[_MAX_LFN] = "";
    289         int i;
     384        int c;
    290385        BYTE list_option = 0;
    291386
    292         for (i = 1; i < argc; i++) {
    293                 if (argv[i][0] == '-') {
    294                         if (argv[i][1] == 'a') {
    295                                 list_option |= LS_ALL;
    296                         }
    297                         else if (argv[i][1] == 'l') {
    298                                 list_option |= LS_LONG;
    299                         }
    300                         continue;
    301                 }
    302                 if (argv[i][0] != '\0') {       /* pattern matching ? */
    303                         pattern_p = &argv[i][0];
     387        while ((c = musl_getopt(argc, argv, "al")) != -1) {
     388                switch (c) {
     389                case 'a':
     390                        list_option |= LS_ALL;
    304391                        break;
    305                 }
    306         }
     392                case 'l':
     393                        list_option |= LS_LONG;
     394                        break;
     395                default:
     396                        break;
     397                }
     398        }
     399        pattern_p = *(argv + optind);
    307400
    308401        if (pattern_p != NULL)
    309                 strlcpy(default_pattern, pattern_p, sizeof(default_pattern));
     402                ntlibc_strlcpy(default_pattern, pattern_p, sizeof(default_pattern));
    310403        basename_p = basename(pattern_p);
    311404        dirname_p = dirname(default_pattern);
    312405        if (((dirname_p[0] == '/') && (basename_p[0] == '/')) ||
    313                 (!strncmp(dirname_p, ".", strlen(dirname_p)) && !strncmp(basename_p, ".", strlen(basename_p))))
     406                (!ntlibc_strncmp(dirname_p, ".", ntlibc_strlen(dirname_p)) && !ntlibc_strncmp(basename_p, ".", ntlibc_strlen(basename_p))))
    314407        {
    315408                basename_p = NULL;
     
    499592}
    500593
     594extern WCHAR Utf8_to_Utf16(const char *, int *); /* in ff.c */
     595extern void Utf16_to_Utf8(unsigned char *, int *, UINT); /* in ff.c */
     596#define HEXDUMP_EXTRA_FOR_UTF8 3 /* need extra buffer size */
     597#define CCOLOR_RESET    0
     598#define CCOLOR_BLACK    30
     599#define CCOLOR_RED              31
     600#define CCOLOR_GREEN    32
     601#define CCOLOR_YELLOW   33
     602#define CCOLOR_BLUE             34
     603#define CCOLOR_MAGENTA  35
     604#define CCOLOR_CYAN             36
     605#define CCOLOR_WHITE    37
     606enum {
     607        HEXDUMP_OPT_DEFAULT = 1 << 0,
     608        HEXDUMP_OPT_UTF8 = 1 << 1,
     609};
     610
    501611int usrcmd_hexdump(int argc, char **argv)
    502612{
    503613        FRESULT res;
    504614        FIL fsrc;
    505         unsigned char data[16 + 1];
    506         unsigned char ascii[sizeof("\x1B[31m0\x1B[0m\x1B[31m1\x1B[0m\x1B[31m2\x1B[0m\x1B[31m3\x1B[0m\x1B[31m4\x1B[0m\x1B[31m5\x1B[0m\x1B[31m6\x1B[0m\x1B[31m7\x1B[0m\x1B[31m8\x1B[0m\x1B[31m9\x1B[0m\x1B[31ma\x1B[0m\x1B[31mb\x1B[0m\x1B[31mc\x1B[0m\x1B[31md\x1B[0m\x1B[31me\x1B[0m\x1B[31mf\x1B[0m")];
     615        unsigned char data[16 + 1 + HEXDUMP_EXTRA_FOR_UTF8];
     616        unsigned char ascii[sizeof("\x1B[31m0\x1B[0m\x1B[31m1\x1B[0m\x1B[31m2\x1B[0m\x1B[31m3\x1B[0m\x1B[31m4\x1B[0m\x1B[31m5\x1B[0m\x1B[31m6\x1B[0m\x1B[31m7\x1B[0m\x1B[31m8\x1B[0m\x1B[31m9\x1B[0m\x1B[31ma\x1B[0m\x1B[31mb\x1B[0m\x1B[31mc\x1B[0m\x1B[31md\x1B[0m\x1B[31me\x1B[0m\x1B[31mf\x1B[0m") + HEXDUMP_EXTRA_FOR_UTF8];
    507617        char line[sizeof("00000000: 00 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 00 : \n") + sizeof(ascii)];
    508 
    509         if (argc != 2) {
    510                 ntstdio_printf(&ntstdio, "hexdump file\n");
    511         }
    512 
    513         if ((res = f_open(&fsrc, argv[1], FA_OPEN_EXISTING | FA_READ)) != FR_OK) {
     618        TCHAR *filename_p = NULL;
     619        int op, option_flag = HEXDUMP_OPT_DEFAULT;
     620        char *option_ptr, *option_endptr, ccolor, utf8_done_flg, utf8_odd_bytes = 0;
     621        unsigned int op_offset = 0, op_size = 0, op_end = 0;
     622
     623        while ((op = musl_getopt(argc, argv, "hduos0123456789xX")) != -1) {
     624                switch (op) {
     625                case 'h': /* help */
     626                        ntstdio_printf(&ntstdio, " hexdump [OPTION] file\n");
     627                        ntstdio_printf(&ntstdio, "  -h : help\n");
     628                        ntstdio_printf(&ntstdio, "  -d : print all byte with convert and color [in character area] (default)\n");
     629                        ntstdio_printf(&ntstdio, "  -u : try print UTF-8 code [in character area]\n");
     630                        ntstdio_printf(&ntstdio, "  -oOFFSET : print start offset address from top\n");
     631                        ntstdio_printf(&ntstdio, "  -sSIZE   : print size\n");
     632                        break;
     633                case 'd': /* print one byte character [in character area] (default) */
     634                        option_flag |= HEXDUMP_OPT_DEFAULT;
     635                        break;
     636                case 'u': /* try print UTF-8 code [in character area] */
     637                        option_flag |= HEXDUMP_OPT_UTF8;
     638                        break;
     639                case 'o': /* print start offset address from top */
     640                        option_ptr = *(argv + optind);
     641                        op_offset = ntlibc_strtoul(&option_ptr[2], &option_endptr, 0);
     642                        break;
     643                case 's': /* print size */
     644                        option_ptr = *(argv + optind);
     645                        op_size = ntlibc_strtoul(&option_ptr[2], &option_endptr, 0);
     646                        break;
     647                default:
     648                        break;
     649                }
     650        }
     651        filename_p = *(argv + optind);
     652        if (filename_p == NULL)
     653                return 0;
     654
     655        if ((res = f_open(&fsrc, filename_p, FA_OPEN_EXISTING | FA_READ)) != FR_OK) {
    514656                put_rc("f_open", res);
    515657                return 0;
    516658        }
    517659
    518         for (int i = 0; i < fsrc.fsize; i += 16) {
     660        /* position adjusting */
     661        if (op_offset >= fsrc.fsize) {
     662                ntstdio_printf(&ntstdio, "error : input offset is bigger than file size(0x%X).\n", fsrc.fsize);
     663                return 0;
     664        }
     665        op_end = op_offset + op_size;
     666        if ((op_size == 0) || (op_end >= fsrc.fsize))
     667                op_end = fsrc.fsize;
     668        f_lseek(&fsrc, op_offset);
     669
     670        for (int i = op_offset; i < op_end; i += 16) {
    519671                ascii[0] = '\0';
    520672                line[0] = '\0';
     
    526678
    527679                UINT br = 0;
    528                 if ((res = f_read(&fsrc, data, 16, &br)) != FR_OK) {
     680                if ((res = f_read(&fsrc, data, 16 + HEXDUMP_EXTRA_FOR_UTF8, &br)) != FR_OK) {
    529681                        put_rc("f_read", res);
    530682                        f_close(&fsrc);
    531683                        return 0;
    532684                }
    533                 data[16] = '\0';
     685                data[br] = '\0';
     686                f_lseek(&fsrc, i + 16);
     687                if (br > 16) br = 16;
    534688
    535689                char *apos = ascii;
     
    544698                        rst -= len;
    545699
     700                        len = 0;
     701                        utf8_done_flg = 0;
     702                        ccolor = CCOLOR_RESET;
     703
    546704                        if (c < 0x20) {
    547                                 len = ntstdio_snprintf(apos, arst , "\x1B[31m%c\x1B[0m", c + 0x40);
    548                         }
    549                         else if (c == 0xFF) {
    550                                 len = ntstdio_snprintf(apos, arst, "\x1B[32m%c\x1B[0m", 'E');
     705                                ccolor = CCOLOR_RED;
     706                                c = c + 0x40;
    551707                        }
    552708                        else {
    553                                 len = ntstdio_snprintf(apos, arst, "%c", c);
    554                         }
     709                                if (option_flag & HEXDUMP_OPT_UTF8) { /* try UTF-8 */
     710                                        /* check character code */
     711                                        int bf_utf8_bytes, af_utf8_bytes;
     712                                        unsigned char utf8_code[4];
     713                                        WCHAR utf16_code;
     714
     715                                        utf16_code = Utf8_to_Utf16(&data[j], &bf_utf8_bytes);       /* try UTF-8 -> UTF-16 */
     716                                        Utf16_to_Utf8(utf8_code, &af_utf8_bytes, (UINT)utf16_code); /* try UTF-16 -> UTF-8 */
     717                                        if ((af_utf8_bytes <= 3 && bf_utf8_bytes == af_utf8_bytes) &&
     718                                                !memcmp(&data[j], utf8_code, af_utf8_bytes)) { /* size & code match */
     719                                                utf8_done_flg = 1;
     720                                                for (int k = 1; k < af_utf8_bytes; k++) { /* pos */
     721                                                        if (j + k >= 16)
     722                                                                break;
     723                                                        if (j + k != 7)
     724                                                                len = ntstdio_snprintf(pos, rst, "%02X ", data[j + k]);
     725                                                        else
     726                                                                len = ntstdio_snprintf(pos, rst, "%02X-", data[j + k]);
     727                                                        pos += len;
     728                                                        rst -= len;
     729                                                }
     730                                                memcpy(apos, &data[j], af_utf8_bytes); /* apos */
     731                                                apos[af_utf8_bytes] = 0;
     732                                                len = af_utf8_bytes;
     733                                                j += af_utf8_bytes - 1;
     734                                                if (af_utf8_bytes > 1) {
     735                                                        utf8_odd_bytes = j < 15 ? af_utf8_bytes - 2 : af_utf8_bytes - 1;
     736                                                }
     737                                        }
     738                                }
     739                        }
     740
     741                        if (utf8_odd_bytes > 0 && j < 15) {
     742                                apos += len;
     743                                arst -= len;
     744                                len = ntstdio_snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", CCOLOR_RESET, ' ');
     745                                utf8_odd_bytes--;
     746                        }
     747                        else if (utf8_done_flg == 0) {
     748                                if (c >= 0x80 && c < 0x9F) {
     749                                        ccolor = CCOLOR_RED;
     750                                        c = c - 0x60;
     751                                }
     752                                else if (c >= 0xA0 && c < 0xDF) {
     753                                        ccolor = CCOLOR_GREEN;
     754                                        c = c - 0x60;
     755                                }
     756                                else if (c >= 0xE0 && c < 0xFF) {
     757                                        ccolor = CCOLOR_GREEN;
     758                                        c = c - 0xC0;
     759                                }
     760                                else if (c == 0x7F || c == 0x9F || c == 0xDF || c == 0xFF) {
     761                                        ccolor = CCOLOR_CYAN;
     762                                        c = '?';
     763                                }
     764                                len = ntstdio_snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", ccolor, c);
     765                        }
     766
    555767                        apos += len;
    556768                        arst -= len;
     
    570782                rst -= len;
    571783
    572                 ntstdio_printf(&ntstdio, line);
     784                ntstdio_puts(&ntstdio, line);
    573785        }
    574786
     
    584796                return 0;
    585797        }
    586         if (strcmp(argv[1], "sys") == 0) {
     798        if (ntlibc_strcmp(argv[1], "sys") == 0) {
    587799                ntstdio_printf(&ntstdio, "GR-PEACH Monitor\n");
    588800                return 0;
    589801        }
    590         if (strcmp(argv[1], "ver") == 0) {
     802        if (ntlibc_strcmp(argv[1], "ver") == 0) {
    591803                int mj, mn, bd;
    592804                ntshell_version(&mj, &mn, &bd);
  • EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.h

    r321 r331  
    4343} cmd_table_t;
    4444
    45 extern int usrcmd_cd(int argc, char **argv);
    46 extern int usrcmd_ls(int argc, char **argv);
    47 extern int usrcmd_cp(int argc, char **argv);
    48 extern int usrcmd_rm(int argc, char **argv);
    49 extern int usrcmd_mv(int argc, char **argv);
    50 extern int usrcmd_mkdir(int argc, char **argv);
    51 extern int usrcmd_hexdump(int argc, char **argv);
     45int usrcmd_cd(int argc, char **argv);
     46int usrcmd_ls(int argc, char **argv);
     47int usrcmd_cp(int argc, char **argv);
     48int usrcmd_rm(int argc, char **argv);
     49int usrcmd_mv(int argc, char **argv);
     50int usrcmd_mkdir(int argc, char **argv);
     51int usrcmd_hexdump(int argc, char **argv);
    5252
    53 extern int usrcmd_help(int argc, char **argv);
    54 extern int usrcmd_info(int argc, char **argv);
    55 extern int usrcmd_exit(int argc, char **argv);
     53int usrcmd_help(int argc, char **argv);
     54int usrcmd_info(int argc, char **argv);
     55int usrcmd_exit(int argc, char **argv);
    5656
    57 extern void shell_abort();
    58 extern void shell_exit(int exitcd);
    59 extern int shell_kill(int pid, int sig);
    60 extern int shell_gettimeofday(struct timeval * tp, void * tzvp);
     57void shell_abort();
     58void shell_exit(int exitcd);
     59int shell_kill(int pid, int sig);
     60int shell_gettimeofday(struct timeval * tp, void * tzvp);
    6161
    6262#endif
  • EcnlProtoTool/trunk/ntshell/ntshell/util/ntopt.c

    r321 r331  
    131131        int argc;
    132132        char argv[NTOPT_TEXT_MAXLEN];
    133         char *argvp[NTOPT_TEXT_MAXARGS];
     133        char *argvp[1 + NTOPT_TEXT_MAXARGS];
    134134        int i;
    135135        int total;
     
    146146        for (i = 0; i < argc; i++) {
    147147                int len;
    148                 argvp[i] = ntopt_get_text(
     148                argvp[i + 1] = ntopt_get_text(
    149149                        str, i, p, NTOPT_TEXT_MAXLEN - total, &len);
    150150                if (total + len + 1 < NTOPT_TEXT_MAXLEN) {
     
    156156                }
    157157        }
     158        argvp[0] = (char *)argc;
    158159
    159         return func(argc, &argvp[0], extobj);
     160        return func((long *)&argvp[0], extobj);
    160161}
  • EcnlProtoTool/trunk/ntshell/ntshell/util/ntopt.h

    r321 r331  
    5555 * @return A return value.
    5656 */
    57 typedef int (*NTOPT_CALLBACK)(int argc, char **argv, void *extobj);
     57typedef int (*NTOPT_CALLBACK)(long *args, void *extobj);
    5858
    5959#ifdef __cplusplus
  • EcnlProtoTool/trunk/ntshell/ntshell/util/ntstdio.c

    r321 r331  
    241241
    242242        if (handle->xo) {
    243                 handle->xo((unsigned char)c);
     243                handle->xo(handle, (unsigned char)c);
    244244        }
    245245        handle->pos++;
     
    266266void ntstdio_fputs(ntstdio_t *handle, NTSTDIO_XO xo, const char *str)
    267267{
    268         void(*pf)(unsigned char);
     268        NTSTDIO_XO pf;
    269269
    270270        /* Save current output device */
     
    314314        int result;
    315315        va_list arp;
    316         void(*pf)(unsigned char);
     316        NTSTDIO_XO pf;
    317317
    318318        /* Save current output device */
     
    334334        extern void shell_exit(int cd);
    335335
    336         int c = handle->xi();
     336        int c = handle->xi(handle);
    337337        if (handle->option & NTSTDIO_OPTION_LF_CR) {
    338338                if (c == '\r')
     
    362362        for (;;) {
    363363                /* Get a char from the incoming stream */
    364                 c = handle->xi();
     364                c = handle->xi(handle);
    365365                if (!c) {
    366366                        /* End of stream */
     
    398398int ntstdio_fgets(ntstdio_t *handle, NTSTDIO_XI xi, char *buf, int len)
    399399{
    400         unsigned char(*pf)(void);
     400        NTSTDIO_XI pf;
    401401        int n;
    402402
  • EcnlProtoTool/trunk/ntshell/ntshell/util/ntstdio.h

    r321 r331  
    6767#define NTSTDIO_OPTION_LF_CR        (1 << 3)
    6868
    69 typedef unsigned char (*NTSTDIO_XI)(void);
    70 typedef void (*NTSTDIO_XO)(unsigned char c);
     69typedef unsigned char (*NTSTDIO_XI)(struct ntstdio_t *handle);
     70typedef void (*NTSTDIO_XO)(struct ntstdio_t *handle, unsigned char c);
    7171
    72 typedef struct {
    73     NTSTDIO_XI xi;
    74     NTSTDIO_XO xo;
    75     char *outptr;
     72typedef struct ntstdio_t {
     73        NTSTDIO_XI xi;
     74        NTSTDIO_XO xo;
     75        char *outptr;
    7676        int len;
    7777        int pos;
    78     unsigned int option;
     78        unsigned int option;
    7979} ntstdio_t;
    8080
  • EcnlProtoTool/trunk/ntshell/src/fdtable.c

    r321 r331  
    3535 *  @(#) $Id$
    3636 */
     37#include "shellif.h"
    3738#include <stdint.h>
    38 #include <stdio.h>
    39 #include <sys/unistd.h>
    40 #include <limits.h>
    4139#include <kernel.h>
    4240#include <t_syslog.h>
    4341#include <t_stdlib.h>
    4442#include <sil.h>
    45 #include <stdlib.h>
    46 #include <string.h>
    47 #include <stdio.h>
    48 #include <setjmp.h>
    49 #include "../../../musl-1.1.12/include/poll.h"
    5043#include "syssvc/serial.h"
    5144#include "syssvc/syslog.h"
     
    6154#include <net/if_var.h>
    6255#include <netinet/udp_var.h>
    63 #include <ethernet_api.h>
     56//#include <ethernet_api.h>
    6457#include "ff.h"
    6558#include "socket_stub.h"
    6659#include "kernel_cfg.h"
     60#include <string.h>
    6761
    6862#define SIO_PORTID 1
     
    7165#define IO_TYPE_SIO             1
    7266#define IO_TYPE_FILE    2
    73 #define IO_TYPE_TCP             3
    74 #define IO_TYPE_UDP             4
     67#define IO_TYPE_DIR             3
     68#define IO_TYPE_TCP             4
     69#define IO_TYPE_UDP             5
    7570
    7671static struct _IO_FILE fd_table[8 * sizeof(FLGPTN)] = {
    77         { 0, IO_TYPE_SIO, 0, stdio_close, stdin_read, stdio_write },
    78         { 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write },
    79         { 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write },
     72        { 0, IO_TYPE_SIO, 0, stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl },
     73        { 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl },
     74        { 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl },
    8075};
    8176#define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0]))
     
    9489        }
    9590
    96         return -1;
     91        return -ENOMEM;
    9792}
    9893
     
    112107        struct _IO_FILE *fp = id_to_fd(type, id);
    113108        if (fp == NULL)
    114                 return -1;
     109                return -EBADF;
    115110
    116111        memset(fp, 0, sizeof(struct _IO_FILE));
     
    136131        fp->read = sio_read;
    137132        fp->write = sio_write;
     133        fp->seek = sio_seek;
     134        fp->ioctl = sio_ioctl;
    138135
    139136        return fp;
     
    160157        fp->read = file_read;
    161158        fp->write = file_write;
     159        fp->seek = file_seek;
     160        fp->ioctl = file_ioctl;
    162161
    163162        return fp;
     
    172171{
    173172        return id_to_fd(IO_TYPE_FILE, fileid);
     173}
     174
     175struct _IO_FILE *new_dir_fd(int fileid)
     176{
     177        int fd = new_fd(IO_TYPE_DIR, fileid);
     178        if ((fd < 0) || (fd >= fd_table_count))
     179                return NULL;
     180
     181        struct _IO_FILE *fp = &fd_table[fd];
     182        fp->close = dir_close;
     183        fp->read = dir_read;
     184        fp->write = dir_write;
     185        fp->seek = dir_seek;
     186        fp->ioctl = dir_ioctl;
     187
     188        return fp;
     189}
     190
     191int delete_dir_fd(int dirid)
     192{
     193        return delete_fd(IO_TYPE_DIR, dirid);
     194}
     195
     196struct _IO_FILE *dirid_to_fd(int dirid)
     197{
     198        return id_to_fd(IO_TYPE_DIR, dirid);
    174199}
    175200
     
    184209        fp->read = tcp_fd_read;
    185210        fp->write = tcp_fd_write;
     211        fp->seek = tcp_fd_seek;
     212        fp->ioctl = tcp_fd_ioctl;
    186213
    187214        return fp;
     
    208235        fp->read = udp_fd_read;
    209236        fp->write = udp_fd_write;
     237        fp->seek = udp_fd_seek;
     238        fp->ioctl = udp_fd_ioctl;
    210239
    211240        return fp;
     
    220249{
    221250        return id_to_fd(IO_TYPE_UDP, udpid);
    222 }
    223 
    224 int shell_isatty(int fd)
    225 {
    226         if ((fd < 0) || (fd >= fd_table_count))
    227                 return 0;
    228 
    229         struct _IO_FILE *fp = &fd_table[fd];
    230         if (fp->type == IO_TYPE_SIO)
    231                 return 1;
    232 
    233         return 0;
    234251}
    235252
     
    245262#define TMO_MAX INT_MAX
    246263
    247 int select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
     264int shell_select(int n, fd_set *__restrict rfds, fd_set *__restrict wfds, fd_set *__restrict efds, struct timeval *__restrict tv)
    248265{
    249266        ER ret;
     
    277294        }
    278295
    279         return -1;
    280 }
    281 
    282 int poll(struct pollfd *fds, nfds_t nfds, int timeout)
     296        return -EBADF;
     297}
     298
     299int shell_poll(struct pollfd *fds, nfds_t nfds, int timeout)
    283300{
    284301        ER ret;
     
    334351        }
    335352
    336         return -1;
     353        return -EBADF;
    337354}
    338355
     
    541558        }
    542559}
     560
     561int shell_ioctl(int fd, int request, void *arg)
     562{
     563        struct _IO_FILE *fp = fd_to_fp(fd);
     564        if (fp == NULL)
     565                return -EBADF;
     566
     567        return fp->ioctl(fp, request, arg);
     568}
  • EcnlProtoTool/trunk/ntshell/src/io_stub.c

    r321 r331  
    3535 *  @(#) $Id$
    3636 */
     37#include "shellif.h"
    3738#include <stdint.h>
    38 #include <stdio.h>
    39 #include <sys/unistd.h>
    40 #include <limits.h>
    41 #include <fcntl.h>
    4239#include "ff.h"
    4340#include <kernel.h>
     
    4542#include <t_stdlib.h>
    4643#include <sil.h>
    47 #include <stdlib.h>
    4844#include <string.h>
    49 #include <stdio.h>
    5045#include <setjmp.h>
    5146#include "syssvc/syslog.h"
     
    6156#include <net/if_var.h>
    6257#include <netinet/udp_var.h>
    63 #include <ethernet_api.h>
    64 #include "ff.h"
     58//#include <ethernet_api.h>
    6559#include "socket_stub.h"
    66 #include "../../../musl-1.1.12/include/_dirent.h"
    67 #include "../../../musl-1.1.12/include/_termios.h"
    68 #include "ntstdio.h"
    69 
    70 int shell_open(const char * path, int flags)
    71 {
    72         FRESULT res;
    73 
    74         struct _IO_FILE *fp = new_file_fd(0);
    75         if (fp == NULL)
    76                 return -1;
     60//#include <sys/stat.h>
     61#include "util/ntstdio.h"
     62#include "usrcmd.h"
     63#include "core/ntlibc.h"
     64
     65int fresult2errno(FRESULT res)
     66{
     67        switch (res) {
     68        case FR_INVALID_OBJECT:
     69                return -EINVAL;
     70        case FR_TOO_MANY_OPEN_FILES:
     71                return -ENOMEM;
     72        case FR_NO_FILE:
     73        case FR_NO_PATH:
     74        case FR_INVALID_DRIVE:
     75        case FR_INVALID_NAME:
     76                return -ENOENT;
     77        case FR_DISK_ERR:
     78        case FR_NO_FILESYSTEM:
     79        case FR_NOT_ENABLED:
     80                return -ENODEV;
     81        case FR_WRITE_PROTECTED:
     82        case FR_DENIED:
     83                return -EACCES;
     84        case FR_EXIST:
     85                return -EEXIST;
     86        case FR_INT_ERR:
     87        default:
     88                return -EIO;
     89        }
     90}
     91
     92int shell_open(const char * path, int flags, void *arg)
     93{
     94        FRESULT res;
     95        struct _IO_FILE *fp;
     96
     97        if (flags & O_DIRECTORY) {
     98                fp = new_dir_fd(0);
     99                if (fp == NULL)
     100                        return -ENOMEM;
     101
     102                DIR *dir = &fp->dir;
     103                FRESULT res;
     104                if ((res = f_opendir(dir, path)) != FR_OK) {
     105                        return fresult2errno(res);
     106                }
     107                return 0;
     108        }
     109
     110        fp = new_file_fd(0);
     111        if (fp == NULL)
     112                return -ENOMEM;
    77113
    78114        BYTE fmd = 0;
     
    115151        }
    116152
    117         return -1;
     153        return fresult2errno(res);
    118154}
    119155
     
    126162        }
    127163
    128         return -1;
     164        return -EINVAL;
    129165}
    130166
     
    135171
    136172        if ((res = f_read(&fp->file, data, len, &ret)) != FR_OK)
    137                 return -1;
     173                return -EIO;
    138174
    139175        return ret;
     
    146182
    147183        if ((res = f_write(&fp->file, data, len, &ret)) != FR_OK)
    148                 return -1;
     184                return -EIO;
    149185
    150186        return ret;
    151187}
    152188
     189off_t file_seek(struct _IO_FILE *fp, off_t ptr, int dir)
     190{
     191        switch (dir) {
     192        case SEEK_SET:
     193                dir = F_SEEK_SET;
     194                break;
     195        case SEEK_CUR:
     196                dir = F_SEEK_CUR;
     197                break;
     198        case SEEK_END:
     199                dir = F_SEEK_END;
     200                break;
     201        default:
     202                return -EINVAL;
     203        }
     204
     205        FRESULT res;
     206        if ((res = f_seek(&fp->file, ptr, dir)) != FR_OK)
     207                return -EIO;
     208
     209        return fp->file.fptr;
     210}
     211
     212int file_ioctl(struct _IO_FILE *fp, int req, void *arg)
     213{
     214        DRESULT res;
     215
     216        if ((res = disk_ioctl(fp->file.fs->drv, req, arg) != RES_OK))
     217                return -EINVAL;
     218
     219        return 0;
     220}
     221
    153222int shell_close(int fd)
    154223{
    155224        struct _IO_FILE *fp = fd_to_fp(fd);
    156225        if (fp == NULL)
    157                 return -1;
     226                return -EBADF;
    158227
    159228        return fp->close(fp);
    160229}
    161230
    162 int shell_read(int fd, char *data, int len)
    163 {
    164         struct _IO_FILE *fp = fd_to_fp(fd);
    165         if (fp == NULL)
    166                 return -1;
     231ssize_t shell_read(int fd, void *data, size_t len)
     232{
     233        struct _IO_FILE *fp = fd_to_fp(fd);
     234        if (fp == NULL)
     235                return -EBADF;
    167236
    168237        return fp->read(fp, (unsigned char *)data, len);
    169238}
    170239
    171 int shell_write(int fd, char *data, int len)
    172 {
    173         struct _IO_FILE *fp = fd_to_fp(fd);
    174         if (fp == NULL)
    175                 return -1;
     240int shell_readv(int fd, const struct iovec *iov, int iovcnt)
     241{
     242        int result = 0;
     243        struct _IO_FILE *fp = fd_to_fp(fd);
     244        if (fp == NULL)
     245                return -EBADF;
     246
     247        const struct iovec *end = &iov[iovcnt];
     248        for (; iov < end; iov++) {
     249                result += fp->read(fp, (unsigned char *)iov->iov_base, iov->iov_len);
     250        }
     251
     252        return result;
     253}
     254
     255ssize_t shell_write(int fd, const void *data, size_t len)
     256{
     257        struct _IO_FILE *fp = fd_to_fp(fd);
     258        if (fp == NULL)
     259                return -EBADF;
    176260
    177261        return fp->write(fp, (unsigned char *)data, len);
    178262}
    179263
    180 int shell_lseek(int fd, int ptr, int dir)
    181 {
    182         struct _IO_FILE *fp = fd_to_fp(fd);
    183         if (fp == NULL)
    184                 return -1;
    185 
    186         FRESULT res;
    187         if ((res = f_seek(&fp->file, ptr, dir)) != FR_OK)
    188                 return -1;
    189 
    190         return fp->file.fptr;
     264int shell_writev(int fd, const struct iovec *iov, int iovcnt)
     265{
     266        int result = 0;
     267        struct _IO_FILE *fp = fd_to_fp(fd);
     268        if (fp == NULL)
     269                return -EBADF;
     270
     271        const struct iovec *end = &iov[iovcnt];
     272        for (; iov < end; iov++) {
     273                result += fp->write(fp, (unsigned char *)iov->iov_base, iov->iov_len);
     274        }
     275
     276        return result;
     277}
     278
     279int shell_llseek(int fd, off_t ptr, off_t *result, int dir)
     280{
     281        struct _IO_FILE *fp = fd_to_fp(fd);
     282        if (fp == NULL)
     283                return -EBADF;
     284
     285        off_t ret = fp->seek(fp, ptr, dir);
     286        if (ret < 0)
     287                return ret;
     288
     289        *result = ret;
     290        return 0;
    191291}
    192292
     
    195295        struct _IO_FILE *fp = fd_to_fp(fd);
    196296        if (fp == NULL)
    197                 return -1;
     297                return -EBADF;
    198298
    199299        memset(st, 0, sizeof(*st));
     
    203303}
    204304
    205 int fsync(int fd)
    206 {
    207         struct _IO_FILE *fp = fd_to_fp(fd);
    208         if (fp == NULL)
    209                 return -1;
    210         return -1;
    211 }
    212 
    213 int ftruncate(int fd, off_t length)
    214 {
    215         struct _IO_FILE *fp = fd_to_fp(fd);
    216         if (fp == NULL)
    217                 return -1;
     305int shell_fsync(int fd)
     306{
     307        struct _IO_FILE *fp = fd_to_fp(fd);
     308        if (fp == NULL)
     309                return -EBADF;
     310        return -EIO;
     311}
     312
     313int shell_ftruncate(int fd, off_t length)
     314{
     315        struct _IO_FILE *fp = fd_to_fp(fd);
     316        if (fp == NULL)
     317                return -EBADF;
    218318
    219319        FRESULT res;
    220320        if ((res = f_truncate(&fp->file)) != FR_OK)
    221                 return -1;
    222 
    223         return 0;
    224 }
    225 
    226 int ioctl(int fd, int request, va_list ap)
    227 {
    228         struct _IO_FILE *fp = fd_to_fp(fd);
    229         if (fp == NULL)
    230                 return -1;
    231         return -1;
    232 }
    233 
    234 int tcgetattr(int fd, struct termios *termios)
     321                return fresult2errno(res);
     322
     323        return 0;
     324}
     325
     326int shell_fcntl(int fd, int cmd, void *arg)
     327{
     328        return shell_ioctl(fd, cmd, arg);
     329}
     330
     331int sio_tcgetattr(int fd, struct termios *termios)
    235332{
    236333        extern ntstdio_t ntstdio;
     
    265362                return 0;
    266363        }
    267         abort();
    268         return 0;
    269 }
    270 
    271 int tcsetattr(int fd, int optional_actions, const struct termios *termios)
     364        shell_abort();
     365        return 0;
     366}
     367
     368int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)
    272369{
    273370        extern ntstdio_t ntstdio;
     
    300397                return 0;
    301398        }
    302         abort();
    303         return 0;
    304 }
    305 
    306 int shell_stat(const char *path, struct stat *st)
     399        shell_abort();
     400        return 0;
     401}
     402
     403int shell_stat(const char *__restrict path, struct stat *__restrict st)
    307404{
    308405        FILINFO fi;
     
    313410        fi.lfsize = sizeof lfn;
    314411#endif
    315         if (strcmp(path, ".") == 0) {
     412        if (ntlibc_strcmp(path, ".") == 0) {
    316413                char cwd[_MAX_LFN];
    317414                if ((ret = f_getcwd(cwd, sizeof(cwd))) != FR_OK) {
    318                 return -1;
    319                 }
    320                 int l = strlen(cwd);
     415                        return fresult2errno(ret);
     416                }
     417                int l = ntlibc_strlen(cwd);
    321418                // ルートディレクトリの場合
    322419                if (cwd[l - 2] == ':' && cwd[l - 1] == '/') {
    323420                        st->st_size = 0;
    324                         st->st_mtime = 0;
     421                        st->st_mtim.tv_nsec = 0;
     422                        st->st_mtim.tv_sec = 0;
    325423                        st->st_mode = S_IFDIR;
    326424                        return 0;
    327425                }
    328426                if ((ret = f_stat(cwd, &fi)) != FR_OK) {
    329                         return -1;
     427                        return fresult2errno(ret);
    330428                }
    331429        }
    332430        else if ((ret = f_stat(path, &fi)) != FR_OK) {
    333                 return -1;
     431                return fresult2errno(ret);
    334432        }
    335433
    336434        st->st_size = fi.fsize;
    337         st->st_mtime = fi.fdate + fi.ftime;
     435        st->st_mtim.tv_nsec = 0;
     436        st->st_mtim.tv_sec = fi.fdate + fi.ftime;
    338437        st->st_mode  = (S_IRUSR | S_IRGRP | S_IROTH);
    339438        st->st_mode |= (fi.fattrib & AM_RDO) ? 0 : (S_IWUSR | S_IWGRP | S_IWOTH);
     
    343442}
    344443
    345 int shell_link(void)
    346 {
    347         return -1;
     444int shell_lstat(const char *__restrict path, struct stat *__restrict st)
     445{
     446        return shell_stat(path, st);
     447}
     448
     449int shell_link(const char *a, const char *b)
     450{
     451        return -EPERM;
    348452}
    349453
     
    353457
    354458        if ((res = f_unlink(path)) != FR_OK)
    355                 return -1;
    356 
    357         return 0;
    358 }
    359 
    360 int rmdir(const char *path)
     459                return -EIO;
     460
     461        return 0;
     462}
     463
     464int shell_rmdir(const char *path)
    361465{
    362466        FRESULT res;
    363467
    364468        if ((res = f_unlink(path)) != FR_OK)
    365                 return -1;
     469                return -EIO;
    366470
    367471        return 0;
     
    373477
    374478        if ((res = f_rename(oldpath, newpath)) != FR_OK)
    375                 return -1;
    376         return 0;
    377 }
    378 
    379 int mkdir(const char *path, mode_t mode)
     479                return fresult2errno(res);
     480        return 0;
     481}
     482
     483#define S_IREAD S_IRUSR
     484#define S_IWRITE S_IWUSR
     485
     486int shell_mkdir(const char *path, mode_t mode)
    380487{
    381488        FRESULT res;
    382489
    383490        if ((res = f_mkdir(path)) != FR_OK)
    384                 return -1;
     491                return fresult2errno(res);
    385492
    386493        BYTE attr = 0;
     
    397504
    398505        if((res = f_chmod(path, attr, mask)) != FR_OK) {
    399                 return -1;
    400         }
    401 
    402         return 0;
    403 }
    404 
    405 int chmod(const char *path, mode_t mode)
    406 {
    407         FRESULT ret;
     506                return fresult2errno(res);
     507        }
     508
     509        return 0;
     510}
     511
     512int shell_chmod(const char *path, mode_t mode)
     513{
     514        FRESULT res;
    408515        BYTE attr = 0;
    409516        BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
     
    418525        }
    419526
    420         if((ret = f_chmod(path, attr, mask)) != FR_OK) {
    421                 return -1;
    422         }
    423 
    424         return 0;
    425 }
    426 
    427 char *getcwd(char *buf, size_t size)
     527        if((res = f_chmod(path, attr, mask)) != FR_OK) {
     528                return fresult2errno(res);
     529        }
     530
     531        return 0;
     532}
     533
     534char *shell_getcwd(char *buf, size_t size)
    428535{
    429536        FRESULT ret;
     
    435542}
    436543
    437 int chdir(const char *path)
    438 {
    439         FRESULT ret;
    440         if ((ret = f_chdir(path)) != FR_OK) {
    441                 return -1;
    442         }
    443 
    444         return 0;
    445 }
    446 
    447 int chroot(const char *path)
    448 {
    449         abort();
    450         return -1;
    451 }
    452 
    453 DIR *opendir(const char *path)
    454 {
    455         DIR *dir = malloc(sizeof(DIR) + sizeof(struct dirent));
    456         FRESULT ret;
    457         if ((ret = f_opendir(dir, path)) != FR_OK) {
    458                 free(dir);
    459                 return NULL;
    460         }
    461 
    462         dir->dirent = &dir[1];
    463         return dir;
    464 }
    465 
    466 int closedir(DIR *dir)
    467 {
    468         FRESULT ret;
    469         if ((ret = f_closedir(dir)) != FR_OK) {
    470                 free(dir);
    471                 return -1;
    472         }
    473 
    474         free(dir);
    475         return 0;
    476 }
    477 
    478 struct dirent *readdir(DIR *dir)
    479 {
    480         struct dirent *de = dir->dirent;
     544int shell_chdir(const char *path)
     545{
     546        FRESULT res;
     547        if ((res = f_chdir(path)) != FR_OK) {
     548                return fresult2errno(res);
     549        }
     550
     551        return 0;
     552}
     553
     554int shell_chroot(const char *path)
     555{
     556        shell_abort();
     557        return -EPERM;
     558}
     559
     560int dir_close(struct _IO_FILE *fp)
     561{
     562        FRESULT res;
     563        if ((res = f_closedir(&fp->dir)) != FR_OK) {
     564                return fresult2errno(res);
     565        }
     566
     567        return 0;
     568}
     569
     570int shell_getdents(int fd, struct dirent *de, size_t len)
     571{
     572        if (len < sizeof(struct dirent))
     573                return -EINVAL;
     574
     575        struct _IO_FILE *fp = fd_to_fp(fd);
     576        if (fp == NULL)
     577                return -EBADF;
     578
    481579        FILINFO fno;
    482580#if _USE_LFN
     
    485583        fno.lfsize = sizeof lfn;
    486584#endif
    487         FRESULT ret;
    488         if ((ret = f_readdir(dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
    489                 return NULL;
     585        FRESULT res;
     586        if ((res = f_readdir(&fp->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
     587                return fresult2errno(res);
    490588        }
    491589
    492590        memset(de, 0, sizeof(*de));
    493591#if _USE_LFN
    494         strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));
     592        ntlibc_strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));
    495593#else
    496         strlcpy(de->d_name, fno.fname, sizeof(de->d_name));
     594        ntlibc_strlcpy(de->d_name, fno.fname, sizeof(de->d_name));
    497595#endif
    498596
    499         return de;
    500 }
    501 
    502 void rewinddir(DIR *dir)
    503 {
    504         FRESULT ret;
    505         if ((ret = f_rewinddir(dir)) != FR_OK) {
    506                 return;
    507         }
    508 }
    509 
    510 void seekdir(DIR *dir, long pos)
    511 {
    512         abort();
    513 }
    514 
    515 long telldir(DIR *dir)
    516 {
    517         abort();
    518         return 0;
    519 }
    520 
    521 int shell_getpid(int n)
     597        return 0;
     598}
     599
     600size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
     601{
     602        return -EPERM;
     603}
     604
     605size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
     606{
     607        return -EPERM;
     608}
     609
     610off_t dir_seek(struct _IO_FILE *fp, off_t ptr, int dir)
     611{
     612        FRESULT res;
     613
     614        if (dir != SEEK_SET)
     615                return -EINVAL;
     616
     617        if (ptr == 0) {
     618                if ((res = f_rewinddir(&fp->dir)) != FR_OK) {
     619                        return fresult2errno(res);
     620                }
     621        }
     622        else {
     623                FILINFO fno;
     624#if _USE_LFN
     625                static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
     626                fno.lfname = lfn;
     627                fno.lfsize = sizeof lfn;
     628#endif
     629                if ((res = f_rewinddir(&fp->dir)) != FR_OK) {
     630                        return fresult2errno(res);
     631                }
     632
     633                for (int i = 0; i < ptr; i++) {
     634                        if ((res = f_readdir(&fp->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
     635                                return fresult2errno(res);
     636                        }
     637                }
     638        }
     639
     640        return ptr;
     641}
     642
     643int dir_ioctl(struct _IO_FILE *fp, int req, void *arg)
     644{
     645        return -EINVAL;
     646}
     647
     648pid_t shell_getpid(void)
    522649{
    523650        return 1;
    524651}
     652
     653int shell_access(const char *path, int mode)
     654{
     655        struct stat st;
     656        int ret;
     657
     658        ret = shell_stat(path, &st);
     659        if (ret != 0)
     660                return ret;
     661
     662        return 0;
     663}
     664
     665//#include "../musl-1.1.18/include/bits/limits.h"
     666#define PAGE_SIZE 4096
     667
     668uint32_t  __CmdBase;
     669uint32_t  __CmdLimit;
     670
     671void *shell_brk(void *addr)
     672{
     673        if (addr == 0) {
     674                return (void *)((intptr_t)&__CmdBase + 0x20000);
     675        }
     676        if ((addr >= (intptr_t)&__CmdBase + 0x20000) && (addr < &__CmdLimit)) {
     677                return addr;
     678        }
     679        return (void *)-1;
     680}
     681
     682void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
     683{
     684        if (fd != -1)
     685                return -EINVAL;
     686
     687        if ((length >= 0) && (length <= (intptr_t)&__CmdLimit - (intptr_t)&__CmdBase - 0x20000)) {
     688                return &__CmdBase + 0x20000;
     689        }
     690        return (void *)-1;
     691}
     692
     693int shell_mprotect(void *addr, size_t len, int prot)
     694{
     695        //if ((addr >= (intptr_t)&__CmdBase + 0x20000) && ((intptr_t)addr + len < &__CmdLimit)) {
     696                return 0;
     697        //}
     698        //return -1;
     699}
  • EcnlProtoTool/trunk/ntshell/src/main.c

    r321 r331  
    4040 */
    4141
     42#include "shellif.h"
    4243#include <kernel.h>
    43 #include <t_syslog.h>
    4444#include <t_stdlib.h>
    4545#include <sil.h>
    46 #include <stdlib.h>
     46#include <setjmp.h>
    4747#include <string.h>
    48 #include <stdio.h>
    49 #include <setjmp.h>
    5048#include "syssvc/serial.h"
    5149#include "syssvc/syslog.h"
     
    6462#include <net/if_var.h>
    6563#include <netinet/udp_var.h>
    66 #include <ethernet_api.h>
    6764#include "ffarch.h"
    68 #include "gpio_api.h"
    6965#include "ff.h"
    7066#include "websocket_fbs.h"
    71 #include "ntshell.h"
    72 #include "ntstdio.h"
     67#include "core/ntshell.h"
     68#include "core/ntlibc.h"
     69#include "util/ntstdio.h"
    7370#include "usrcmd.h"
    74 #include "ntopt.h"
    75 
    76 #ifndef _MSC_VER
    77 void strcpy_s(char *dst, int size, const char *src);
    78 #endif
     71#include "util/ntopt.h"
     72#include "socket_stub.h"
    7973
    8074ID ws_api_mailboxid = MAIN_DATAQUEUE;
     
    8680ntstdio_t ntstdio;
    8781
    88 const uint8_t mac_addr[6] = {0x00, 0x30, 0x13, 0x06, 0x62, 0xC0};
    89 const char host_name[] = "GR-PEACH";
     82const uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC};
     83const struct utsname host_name = {
     84        "TOPPERS/ASP3",
     85    "GR-PEACH",
     86    "3.1.0",
     87    "3.1.0",
     88    "GR-PEACH",
     89    "toppers.jp"
     90};
    9091
    9192static void netif_link_callback(T_IFNET *ether);
     
    228229        char buf[1];
    229230        if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)
    230                 return -1;
     231                return -EIO;
    231232        return buf[0];
    232233}
     
    305306
    306307        if (exec) {
    307                 strcpy_s(command, sizeof(command), "mruby -b 1:/upload/main.mrb");
     308                ntlibc_strlcpy(command, "mruby -b 1:/upload/main.mrb", sizeof(command));
    308309
    309310                execute_command(1);
     
    371372}
    372373
    373 int gethostname(char *name, size_t len)
    374 {
    375         return strlcpy(name, host_name, len);
    376 }
    377 
    378 static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj);
     374int shell_uname(struct utsname *uts)
     375{
     376        return memcpy(uts, &host_name, sizeof(host_name));
     377}
     378
     379static int usrcmd_ntopt_callback(long *args, void *extobj);
    379380int mruby_exit_code;
    380381volatile int mruby_state;
    381 typedef void (*PowerOn_Reset_t)(int argc, char **argv);
     382typedef void (*PowerOn_Reset_t)(long *args);
    382383jmp_buf process_exit;
    383384
     
    392393}
    393394
    394 static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj)
    395 {
     395typedef struct
     396{
     397        const cmd_table_t *table;
     398        int count;
     399} cmd_table_info_t;
     400
     401static const cmd_table_t cmdlist[] = {
     402        {"cd", "change directory", usrcmd_cd },
     403        {"ls", "list files", usrcmd_ls },
     404        {"cp", "copy file", usrcmd_cp },
     405        {"rm", "remove file", usrcmd_rm },
     406        {"mv", "move file", usrcmd_mv },
     407        {"mkdir", "Make directory", usrcmd_mkdir},
     408        {"hexdump", "Hex dump", usrcmd_hexdump},
     409        {"info", "This is a description text string for info command.", usrcmd_info},
     410        {"exit", "Exit Natural Tyny Shell", usrcmd_exit},
     411};
     412cmd_table_info_t cmd_table_info = { cmdlist, sizeof(cmdlist) / sizeof(cmdlist[0]) };
     413
     414static int usrcmd_ntopt_callback(long *args, void *extobj)
     415{
     416        const cmd_table_t *p = cmd_table_info.table;
     417        if (ntlibc_strcmp((const char *)args[1], "help") == 0) {
     418                usrcmd_help(args[0], (char **)&args[1]);
     419        }
     420        else for (int i = 0; i < cmd_table_info.count; i++) {
     421                if (ntlibc_strcmp((const char *)args[1], p->cmd) == 0) {
     422                        return p->func(args[0], (char **)&args[1]);
     423                }
     424                p++;
     425        }
    396426        if (setjmp(process_exit) == 0) {
    397                 (*((PowerOn_Reset_t *)0x18200000))(argc, argv);
     427                (*((PowerOn_Reset_t *)0x18200000))(args);
    398428        }
    399429        clean_fd();
     430        return 0;
     431}
     432
     433int usrcmd_help(int argc, char **argv)
     434{
     435        const cmd_table_t *p = cmd_table_info.table;
     436        for (int i = 0; i < cmd_table_info.count; i++) {
     437                ntstdio_puts(&ntstdio, p->cmd);
     438                ntstdio_puts(&ntstdio, "\t:");
     439                ntstdio_puts(&ntstdio, p->desc);
     440                ntstdio_puts(&ntstdio, "\n");
     441                p++;
     442        }
    400443        return 0;
    401444}
     
    422465
    423466void shell_exit(int exitcd)
     467{
     468        mruby_exit_code = exitcd;
     469        longjmp(process_exit, 1);
     470}
     471
     472void shell_exit_group(int exitcd)
    424473{
    425474        mruby_exit_code = exitcd;
     
    458507static int cmd_execute(const char *text, void *extobj)
    459508{
    460         strlcpy(command, text, sizeof(command));
     509        ntlibc_strlcpy(command, text, sizeof(command));
    461510        return execute_command(1);
    462511}
     
    464513int stdio_close(struct _IO_FILE *fp)
    465514{
    466         return -1;
     515        return -EPERM;
    467516}
    468517
    469518size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    470519{
    471         return -1;
     520        return -EPERM;
    472521}
    473522
    474523size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    475524{
    476         return -1;
     525        return -EPERM;
    477526}
    478527
     
    507556int sio_close(struct _IO_FILE *fp)
    508557{
    509         return -1;
     558        return -EPERM;
    510559}
    511560
    512561size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    513562{
    514         return -1;
     563        return -EPERM;
    515564}
    516565
    517566size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    518567{
    519         return -1;
    520 }
     568        return -EPERM;
     569}
     570
     571off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)
     572{
     573        return -EPERM;
     574}
     575
     576int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)
     577{
     578        switch (request) {
     579        case TIOCGWINSZ:
     580                return 0;
     581        case TCGETS:
     582                return sio_tcgetattr(fp->fd, (struct termios *)arg);
     583        case TCSETS + TCSANOW:
     584        case TCSETS + TCSADRAIN:
     585        case TCSETS + TCSAFLUSH:
     586                return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
     587        }
     588
     589        return -EINVAL;
     590}
     591
     592int shell_clock_getres(clockid_t clk_id, struct timespec *res)
     593{
     594        if (clk_id != CLOCK_REALTIME)
     595                return -EINVAL;
     596
     597        memset(&res->tv_sec, 0xFF, sizeof(res->tv_sec));
     598        res->tv_nsec = 0;
     599
     600        return 0;
     601}
     602
     603int shell_clock_gettime(clockid_t clk_id, struct timespec *tp)
     604{
     605        SYSTIM now = 0;
     606
     607        if (clk_id != CLOCK_REALTIME)
     608                return -EINVAL;
     609
     610        get_tim(&now);
     611        tp->tv_sec = now / 1000000;
     612        tp->tv_nsec = (now % 1000000) * 1000;
     613
     614        return 0;
     615}
     616
     617int shell_clock_settime(clockid_t clk_id, const struct timespec *tp)
     618{
     619        if (clk_id != CLOCK_REALTIME)
     620                return -EINVAL;
     621
     622        rtc_write(tp->tv_sec);
     623
     624        return 0;
     625}
     626
     627sigset_t g_sigmask;
     628
     629int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
     630{
     631        if (old != NULL)
     632                memcpy(old, &g_sigmask, sizeof(sigset_t));
     633
     634        switch (how) {
     635        case SIG_BLOCK:
     636                for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {
     637                        g_sigmask.__bits[i] |= set->__bits[i];
     638                }
     639                break;
     640        case SIG_UNBLOCK:
     641                for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {
     642                        g_sigmask.__bits[i] &= ~set->__bits[i];
     643                }
     644                break;
     645        case SIG_SETMASK:
     646                memcpy(&g_sigmask, set, sizeof(sigset_t));
     647                break;
     648        default:
     649                return -EINVAL;
     650        }
     651
     652        return 0;
     653}
     654
     655struct sigaction sigtable[6];
     656
     657int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
     658{
     659        struct sigaction *sat;
     660
     661        switch(sig){
     662        case SIGALRM:
     663                sat = &sigtable[0];
     664                break;
     665        case SIGFPE:
     666                sat = &sigtable[1];
     667                break;
     668        case SIGILL:
     669                sat = &sigtable[2];
     670                break;
     671        case SIGSEGV:
     672                sat = &sigtable[3];
     673                break;
     674        case SIGBUS:
     675                sat = &sigtable[4];
     676                break;
     677        case SIGABRT:
     678                sat = &sigtable[5];
     679                break;
     680        default:
     681                return -EINVAL;
     682        }
     683
     684        if (old != NULL)
     685                memcpy(old, sat, sizeof(struct sigaction));
     686
     687        memcpy(sat, sa, sizeof(struct sigaction));
     688
     689        return 0;
     690}
     691
     692int shell_madvise(void *a, size_t b, int c)
     693{
     694        return 0;
     695}
     696
  • EcnlProtoTool/trunk/ntshell/src/main.cfg

    r321 r331  
    6161CRE_SEM(SEM_FILESYSTEM, { TA_TPRI, 1, 1 });
    6262
    63 CRE_TSK(MRUBY_TASK, { TA_NULL, 0, mruby_task, MRUBY_PRIORITY, MRUBY_STACK_SIZE, (void *)0x20600000 });
     63CRE_TSK(MRUBY_TASK, { TA_NULL, 0, mruby_task, MRUBY_PRIORITY, MRUBY_STACK_SIZE, (void *)0x20100000 });
    6464CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 });
  • EcnlProtoTool/trunk/ntshell/src/main.h

    r321 r331  
    5656
    5757#define MAIN_STACK_SIZE         2048    /* メインタスクのスタック領域のサイズ */
    58 #define MRUBY_STACK_SIZE        0x100000        /* mruby実行タスクのスタック領域のサイズ */
     58#define MRUBY_STACK_SIZE        0x00800000      /* mruby実行タスクのスタック領域のサイズ */
    5959
    6060#define NUM_MAIN_DATAQUEUE      1       /* メインタスクで待ち受けているデータキューのサイズ */
  • EcnlProtoTool/trunk/ntshell/src/route_cfg.c

    r321 r331  
    22 *  TINET (TCP/IP Protocol Stack)
    33 *
    4  *  Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
     4 *  Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
    55 *                   Tomakomai National College of Technology, JAPAN
    66 *
     
    4444#include <netinet/in_var.h>
    4545
     46/* IPv6 に関する定義 */
     47
     48#ifdef _IP6_CFG
     49
     50#if NUM_IN6_ROUTE_ENTRY > 0
     51
     52T_IN6_RTENTRY routing6_tbl[NUM_IN6_ROUTE_ENTRY];
     53
     54#endif  /* of #if NUM_IN6_ROUTE_ENTRY > 0 */
     55
     56#endif  /* of #ifdef _IP6_CFG */
     57
    4658/* IPv4 に関する定義 */
    4759
    48 #ifdef SUPPORT_INET4
     60#ifdef _IP4_CFG
    4961
    5062#ifdef SUPPORT_LOOP
    5163
    52 T_IN4_RTENTRY routing_tbl[NUM_ROUTE_ENTRY] = {
     64T_IN4_RTENTRY routing4_tbl[NUM_IN4_ROUTE_ENTRY] = {
    5365        { 0, 0, 0 },
    5466        };
     
    5870#ifdef SUPPORT_PPP
    5971
    60 T_IN4_RTENTRY routing_tbl[NUM_ROUTE_ENTRY] = {
     72T_IN4_RTENTRY routing4_tbl[NUM_IN4_ROUTE_ENTRY] = {
    6173        { 0, 0, 0 },
    6274        };
     
    6678#ifdef SUPPORT_ETHER
    6779
    68 T_IN4_RTENTRY routing_tbl[NUM_ROUTE_ENTRY] = {
     80T_IN4_RTENTRY routing4_tbl[NUM_IN4_ROUTE_ENTRY] = {
    6981
    7082        /* 異なる LAN、default gateway による間接配送      */
     
    8294#endif  /* of #ifdef SUPPORT_ETHER */
    8395
    84 #endif  /* of #ifdef SUPPORT_INET4 */
    85 
    86 /* IPv6 に関する定義 */
    87 
    88 #ifdef SUPPORT_INET6
    89 
    90 #if NUM_ROUTE_ENTRY > 0
    91 
    92 T_IN6_RTENTRY routing_tbl[NUM_ROUTE_ENTRY] = { };
    93 
    94 #endif  /* of #if NUM_ROUTE_ENTRY > 0 */
    95 
    96 #endif  /* of #ifdef SUPPORT_INET6 */
     96#endif  /* of #ifdef _IP4_CFG */
  • EcnlProtoTool/trunk/ntshell/src/socket_stub.c

    r321 r331  
    3535 *  @(#) $Id$
    3636 */
    37 #include <sys/types.h>
    38 #include <stdint.h>
    39 #if 0
    40 #include <sys/socket.h>
    41 #include <sys/un.h>
    42 #include <netinet/in.h>
    43 #include <netinet/tcp.h>
    44 #include <arpa/inet.h>
    45 #include <netdb.h>
    46 #endif
    47 #include <fcntl.h>
    48 #include "sys/unistd.h"
    49 #include <stddef.h>
    50 #include <string.h>
    51 #include <stdlib.h>
     37#include "shellif.h"
    5238#include <kernel.h>
    5339#include <t_syslog.h>
    5440#include <t_stdlib.h>
     41#include <string.h>
    5542#include <sil.h>
    56 #include <stdlib.h>
    57 #include <string.h>
    58 #include <stdio.h>
    5943#include <setjmp.h>
    6044#include "syssvc/syslog.h"
     
    7458#include "ff.h"
    7559#include "socket_stub.h"
    76 #define SO_REUSEADDR    2
     60
     61#define SOCKET_TIMEOUT 2000000
    7762
    7863typedef struct id_table_t {
     
    10792}
    10893
    109         return -1;
     94        return -ENOMEM;
    11095}
    11196
     
    120105                return 0;
    121106        }
    122         return -1;
     107        return -EINVAL;
    123108}
    124109
    125110int delete_tcp_rep(int repid)
    126111{
    127         delete_tcp_fd(tmax_tcp_cepid + repid);
     112        return delete_tcp_fd(tmax_tcp_cepid + repid);
    128113}
    129114
     
    145130typedef struct _IO_FILE SOCKET;
    146131
    147 int socket(int family, int type, int protocol)
     132int shell_socket(int family, int type, int protocol)
    148133{
    149134        SOCKET *fp;
     135        unsigned int flags;
    150136
    151137        switch (family) {
     
    154140                break;
    155141        default:
    156                 return -1;
    157         }
     142                return -EAFNOSUPPORT;
     143        }
     144
     145        flags = type & (SOCK_CLOEXEC|SOCK_NONBLOCK);
     146        type &= ~flags;
    158147
    159148        switch (type) {
     
    165154                break;
    166155        default:
    167                 return -1;
     156                return -ENOPROTOOPT;
    168157        }
    169158
    170159        if (fp == NULL) {
    171                 return -1;
     160                return -ENOMEM;
    172161        }
    173162
     
    175164        fp->socket.type = type;
    176165        fp->socket.protocol = protocol;
     166        fp->socket.flags = flags;
    177167
    178168        return fp->fd;
    179169}
    180170
    181 int bind(int fd, const struct sockaddr *addr, socklen_t len)
     171int shell_bind(int fd, const struct sockaddr *addr, socklen_t len)
    182172{
    183173        SOCKET *fp = fd_to_fp(fd);
    184         if (fp == NULL) {
    185                 return -1;
    186         }
    187 
    188         if (fp->socket.family != addr->sa_family) {
    189                 return -1;
    190         }
     174        if (fp == NULL)
     175                return -EBADF;
     176        if (fp->socket.family != addr->sa_family)
     177                return -EINVAL;
    191178
    192179        ER ret;
     
    194181        case AF_INET: {
    195182                if (len < 8) {
    196                         return -1;
     183                        return -EINVAL;
    197184                }
    198185                struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
     
    202189                        ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
    203190                        if (cepid < 0)
    204                                 return -1;
     191                                return -ENOMEM;
    205192
    206193                        fp->socket.buf_size = 512 + 512;
    207194                        fp->socket.buf = id_to_buff(cepid);
    208                         T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
     195                        T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
    209196                        ret = tcp_cre_cep(cepid, &ccep);
    210197                        if (ret != E_OK) {
    211198                                delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
    212                                 return -1;
     199                                return -ENOMEM;
    213200                        }
    214201                        fp->handle = cepid;
     
    219206                        ID cepid = new_id(udp_cepid_table, udp_cepid_table_count);
    220207                        if (cepid < 0)
    221                                 return -1;
    222 
    223                         T_UDP_CCEP ccep = { 0, {ntohl(addr_in->sin_addr.s_addr), ntohs(addr_in->sin_port)}, socket_udp_callback };
     208                                return -ENOMEM;
     209
     210                        T_UDP_CCEP ccep = { 0, {ntohl(addr_in->sin_addr.s_addr), ntohs(addr_in->sin_port)}, (FP)socket_udp_callback };
    224211                        ret = udp_cre_cep(cepid, &ccep);
    225212                        if (ret != E_OK) {
    226213                                delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
    227                                 return -1;
     214                                return -ENOMEM;
    228215                        }
    229216                        fp->handle = cepid;
     
    232219                }
    233220                default:
    234                         return -1;
     221                        return -ENOPROTOOPT;
    235222                }
    236223                break;
     
    238225        case AF_INET6: {
    239226                if (len < 20) {
    240                         return -1;
     227                        return -EINVAL;
    241228                }
    242229                memcpy(&fp->socket.laddr4, addr, len);
     
    248235}
    249236
    250 int listen(int fd, int backlog)
     237int shell_listen(int fd, int backlog)
    251238{
    252239        SOCKET *fp = fd_to_fp(fd);
    253         if ((fp == NULL) || (fp->socket.type != SOCK_STREAM)) {
    254                 return -1;
    255         }
     240        if (fp == NULL)
     241                return -EBADF;
     242        if (fp->socket.type != SOCK_STREAM)
     243                return -EINVAL;
    256244
    257245        fp->socket.backlog = backlog;
     
    262250                ID repid = new_id(tcp_repid_table, tcp_repid_table_count);
    263251                if (repid < 0)
    264                         return -1;
     252                        return -ENOMEM;
    265253
    266254                struct sockaddr_in *laddr = &fp->socket.laddr4;
     
    269257                if (ret != E_OK) {
    270258                        delete_id(tcp_repid_table, tcp_repid_table_count, repid);
    271                         return -1;
     259                        return -ENOMEM;
    272260                }
    273261                fp->socket.repid = repid;
     
    282270}
    283271
    284 int connect(int fd, const struct sockaddr *addr, socklen_t len)
     272int shell_connect(int fd, const struct sockaddr *addr, socklen_t len)
    285273{
    286274        SOCKET *fp = fd_to_fp(fd);
    287         if ((fp == NULL) || (fp->socket.type != SOCK_STREAM)) {
    288                 return -1;
    289         }
     275        if (fp == NULL)
     276                return -EBADF;
     277        if (fp->socket.type != SOCK_STREAM)
     278                return -EINVAL;
    290279
    291280        ER ret;
     
    293282        case AF_INET: {
    294283                if (len < 8) {
    295                         return -1;
     284                        return -EINVAL;
    296285                }
    297286                if (fp->socket.cepid == 0) {
    298287                        ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
    299288                        if (cepid < 0)
    300                                 return -1;
     289                                return -ENOMEM;
    301290
    302291                        fp->socket.buf_size = 512 + 512;
    303292                        fp->socket.buf = id_to_buff(cepid);
    304                         T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
     293                        T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
    305294                        ret = tcp_cre_cep(cepid, &ccep);
    306295                        if (ret != E_OK) {
    307296                                delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
    308                                 return -1;
     297                                return -ENOMEM;
    309298                        }
    310299                        fp->handle = cepid;
     
    317306                T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) };
    318307                T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
    319                 ret = tcp_con_cep(fp->socket.cepid, &lep, &rep, TMO_FEVR);
     308                ret = tcp_con_cep(fp->socket.cepid, &lep, &rep, SOCKET_TIMEOUT);
    320309                if (ret < 0) {
    321                         return -1;
     310                        return -EHOSTUNREACH;
    322311                }
    323312                break;
     
    331320}
    332321
    333 int accept(int fd, struct sockaddr *addr, socklen_t *len)
     322int shell_accept(int fd, struct sockaddr *__restrict addr, socklen_t *__restrict len)
    334323{
    335324        SOCKET *lfp = fd_to_fp(fd);
    336         if ((lfp == NULL) || (lfp->socket.type != SOCK_STREAM)) {
    337                 return -1;
    338         }
     325        if (lfp == NULL)
     326                return -EBADF;
     327        if (lfp->socket.type != SOCK_STREAM)
     328                return -EINVAL;
    339329
    340330        SOCKET *fp = new_tcp_fd(0);
    341331        if (fp == NULL) {
    342                 return -1;
     332                return -ENOMEM;
    343333        }
    344334
     
    352342                        cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
    353343                        if (cepid < 0)
    354                                 return -1;
     344                                return -ENOMEM;
    355345
    356346                        fp->socket.buf_size = 512 + 512;
    357347                        fp->socket.buf = id_to_buff(cepid);
    358                         T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, socket_tcp_callback };
     348                        T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
    359349                        ret = tcp_cre_cep(cepid, &ccep);
    360350                        if (ret != E_OK) {
    361351                                delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
    362                                 return -1;
     352                                return -ENOMEM;
    363353                        }
    364354                        fp->handle = cepid;
     
    375365                ret = tcp_acp_cep(fp->socket.cepid, fp->socket.repid, &rep, TMO_FEVR);
    376366                if (ret < 0) {
    377                         return -1;
     367                        return -ENOMEM;
    378368                }
    379369                struct sockaddr_in *raddr = &fp->socket.raddr4;
     
    385375        }
    386376        case AF_INET6: {
    387                 break;
     377                return -EAFNOSUPPORT;
    388378        }
    389379        }
     
    392382                int sz = *len;
    393383                if (sz < 8) {
    394                         return -1;
     384                        return -EINVAL;
    395385                }
    396386                struct sockaddr_in *raddr = &fp->socket.raddr4;
     
    404394}
    405395
    406 ssize_t send(int fd, const void *buf, size_t len, int flags)
     396ssize_t shell_send(int fd, const void *buf, size_t len, int flags)
    407397{
    408398        SOCKET *fp = fd_to_fp(fd);
    409399        if (fp == NULL) {
    410                 return -1;
     400                return -EBADF;
    411401        }
    412402
     
    417407                case SOCK_STREAM: {
    418408                        if (flags & MSG_OOB) {
    419                                 ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
     409                                ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
    420410                                if (ret < 0) {
    421                                         return -1;
     411                                        return -ECOMM;
    422412                                }
    423413                        }
    424414                        else {
    425                                 ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
     415                                ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
    426416                                if (ret < 0) {
    427                                         return -1;
     417                                        return -ECOMM;
    428418                                }
    429419                        }
     
    431421                }
    432422                case SOCK_DGRAM: {
    433                         return -1;
    434                 }
    435                 }
    436                 break;
    437         }
    438         case AF_INET6: {
    439                 break;
     423                        return -EINVAL;
     424                }
     425                }
     426                break;
     427        }
     428        case AF_INET6: {
     429                return -EAFNOSUPPORT;
    440430        }
    441431        }
     
    444434}
    445435
    446 ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
     436ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
    447437{
    448438        SOCKET *fp = fd_to_fp(fd);
    449439        if (fp == NULL) {
    450                 return -1;
     440                return -EBADF;
    451441        }
    452442
     
    457447                case SOCK_STREAM: {
    458448                        if ((addr != NULL) && (alen != 0)) {
    459                                 return -1;
     449                                return -EINVAL;
    460450                        }
    461451
    462452                        if (flags & MSG_OOB) {
    463                                 ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
     453                                ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
    464454                                if (ret < 0) {
    465                                         return -1;
     455                                        return -ECOMM;
    466456                                }
    467457                        }
    468458                        else {
    469                                 ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, TMO_FEVR);
     459                                ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
    470460                                if (ret < 0) {
    471                                         return -1;
     461                                        return -ECOMM;
    472462                                }
    473463                        }
     
    477467                        int sz = alen;
    478468                        if (sz < 8) {
    479                                 return -1;
     469                                return -EINVAL;
    480470                        }
    481471                        struct sockaddr_in *raddr = &fp->socket.raddr4;
     
    483473                        memcpy(raddr, addr, sz);
    484474                        T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
    485                         ret = udp_snd_dat(fp->socket.cepid, &rep, (void *)buf, len, TMO_FEVR);
     475                        ret = udp_snd_dat(fp->socket.cepid, &rep, (void *)buf, len,
     476                                (fp->socket.flags & O_NONBLOCK) ? 0 : SOCKET_TIMEOUT);
    486477                        if (ret < 0) {
    487                                 return -1;
    488                         }
    489                         break;
    490                 }
    491                 }
    492                 break;
    493         }
    494         case AF_INET6: {
    495                 break;
     478                                return -ECOMM;
     479                        }
     480                        break;
     481                }
     482                }
     483                break;
     484        }
     485        case AF_INET6: {
     486                return -EAFNOSUPPORT;
    496487        }
    497488        }
     
    500491}
    501492
    502 ssize_t recv(int fd, void *buf, size_t len, int flags)
     493ssize_t shell_sendmsg(int fd, const struct msghdr *msg, int flags)
     494{
     495        no_implement("sendmsg\n");
     496        return -ENOSYS;
     497}
     498
     499ssize_t shell_recv(int fd, void *buf, size_t len, int flags)
    503500{
    504501        SOCKET *fp = fd_to_fp(fd);
    505502        if (fp == NULL) {
    506                 return -1;
     503                return -EBADF;
    507504        }
    508505
     
    515512                                ret = tcp_rcv_oob(fp->socket.cepid, buf, len);
    516513                                if (ret < 0) {
    517                                         return -1;
     514                                        return -ECOMM;
    518515                                }
    519516                        }
     
    521518                                ret = tcp_rcv_dat(fp->socket.cepid, buf, len, TMO_FEVR);
    522519                                if (ret < 0) {
    523                                         return -1;
     520                                        return -ECOMM;
    524521                                }
    525522                        }
     
    528525                case SOCK_DGRAM: {
    529526                        T_IPV4EP rep = { 0, 0 };
    530                         ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, TMO_FEVR);
     527                        ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, (fp->socket.flags & O_NONBLOCK) ? 0 : TMO_FEVR);
    531528                        if (ret < 0) {
    532                                 return -1;
    533                         }
    534                 }
    535                 }
    536                 break;
    537         }
    538         case AF_INET6: {
    539                 break;
     529                                return -ECOMM;
     530                        }
     531                }
     532                }
     533                break;
     534        }
     535        case AF_INET6: {
     536                return -EAFNOSUPPORT;
    540537        }
    541538        }
     
    544541}
    545542
    546 ssize_t recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen)
     543ssize_t shell_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *__restrict addr, socklen_t *__restrict alen)
    547544{
    548545        SOCKET *fp = fd_to_fp(fd);
    549546        if (fp == NULL) {
    550                 return -1;
     547                return -EBADF;
    551548        }
    552549
     
    559556                                ret = tcp_rcv_oob(fp->socket.cepid, buf, len);
    560557                                if (ret < 0) {
    561                                         return -1;
     558                                        return -ECOMM;
    562559                                }
    563560                        }
     
    565562                                ret = tcp_rcv_dat(fp->socket.cepid, buf, len, TMO_FEVR);
    566563                                if (ret < 0) {
    567                                         return -1;
     564                                        return -ECOMM;
    568565                                }
    569566                        }
     
    574571                        ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, TMO_FEVR);
    575572                        if (ret < 0) {
    576                                 return -1;
     573                                return -ECOMM;
    577574                        }
    578575                        int sz = *alen;
     
    590587        }
    591588        case AF_INET6: {
    592                 break;
     589                return -EAFNOSUPPORT;
    593590        }
    594591        }
     
    597594}
    598595
    599 int shutdown(int fd, int how)
     596ssize_t shell_recvmsg(int fd, struct msghdr *msg, int flags)
     597{
     598        no_implement("recvmsg\n");
     599        return -ENOSYS;
     600}
     601
     602int shell_shutdown(int fd, int how)
    600603{
    601604        SOCKET *fp = fd_to_fp(fd);
    602605        if (fp == NULL) {
    603                 return -1;
     606                return -EBADF;
    604607        }
    605608
     
    611614                        ret = tcp_sht_cep(fp->socket.cepid);
    612615                        if (ret < 0) {
    613                                 return -1;
    614                         }
    615                         break;
    616                 }
    617                 }
    618                 break;
    619         }
    620         case AF_INET6: {
    621                 break;
     616                                return -ECOMM;
     617                        }
     618                        break;
     619                }
     620                }
     621                break;
     622        }
     623        case AF_INET6: {
     624                return -EAFNOSUPPORT;
    622625        }
    623626        }
     
    626629}
    627630
    628 int getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen)
     631int shell_getsockopt(int fd, int level, int optname, void *optval, socklen_t *__restrict optlen)
    629632{
    630633        SOCKET *fp = fd_to_fp(fd);
    631634        if (fp == NULL) {
    632                 return -1;
     635                return -EBADF;
    633636        }
    634637
     
    650653                                ret = tcp_get_opt(fp->socket.cepid, optname, (void *)optval, *optlen);
    651654                                if (ret < 0) {
    652                                         return -1;
     655                                        return -EINVAL;
    653656                                }
    654657                                *optlen = ret;
     
    660663                        ret = udp_get_opt(fp->socket.cepid, optname, (void *)optval, *optlen);
    661664                        if (ret < 0) {
    662                                 return -1;
     665                                return -EINVAL;
    663666                        }
    664667                        *optlen = ret;
     
    669672        }
    670673        case AF_INET6: {
    671                 break;
     674                return -EAFNOSUPPORT;
    672675        }
    673676        }
     
    676679}
    677680
    678 int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
     681int shell_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
    679682{
    680683        SOCKET *fp = fd_to_fp(fd);
    681684        if (fp == NULL) {
    682                 return -1;
     685                return -EBADF;
    683686        }
    684687
     
    700703                                ret = tcp_set_opt(fp->socket.cepid, optname, (void *)optval, optlen);
    701704                                if (ret < 0) {
    702                                         return -1;
     705                                        return -EINVAL;
    703706                                }
    704707                                break;
     
    709712                        ret = udp_set_opt(fp->socket.cepid, optname, (void *)optval, optlen);
    710713                        if (ret < 0) {
    711                                 return -1;
    712                         }
    713                         break;
    714                 }
    715                 }
    716                 break;
    717         }
    718         case AF_INET6: {
    719                 break;
     714                                return -EINVAL;
     715                        }
     716                        break;
     717                }
     718                }
     719                break;
     720        }
     721        case AF_INET6: {
     722                return -EAFNOSUPPORT;
    720723        }
    721724        }
     
    735738                                //return -1;
    736739                        }
    737                         ret = tcp_cls_cep(cepid, TMO_FEVR);
     740                        ret = tcp_cls_cep(cepid, (fp->socket.repid != 0) ? 0 : SOCKET_TIMEOUT);
    738741                        if (ret < 0) {
    739742                                //return -1;
     
    743746                        delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
    744747                        if (ret < 0) {
    745                                 return -1;
     748                                return -EINVAL;
    746749                        }
    747750                }
     
    752755                        delete_id(tcp_repid_table, tcp_repid_table_count, repid);
    753756                        if (ret < 0) {
    754                                 return -1;
     757                                return -EINVAL;
    755758                        }
    756759                }
    757760                else {
    758                         return -1;
    759                 }
    760                 break;
    761         }
    762         case AF_INET6: {
    763                 break;
     761                        return -EINVAL;
     762                }
     763                break;
     764        }
     765        case AF_INET6: {
     766                return -EAFNOSUPPORT;
    764767        }
    765768        }
     
    770773size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
    771774{
    772         return recv(fp->fd, dst, dstsz, 0);
     775        return shell_recv(fp->fd, dst, dstsz, 0);
    773776}
    774777
    775778size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
    776779{
    777         return send(fp->fd, src, srcsz, 0);
     780        return shell_send(fp->fd, src, srcsz, 0);
    778781}
    779782
    780783off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
    781784{
    782         return -1;
     785        return -EPERM;
     786}
     787
     788int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
     789{
     790        return -EINVAL;
    783791}
    784792
     
    794802                delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
    795803                if (ret < 0) {
    796                         return -1;
    797                 }
    798                 break;
    799         }
    800         case AF_INET6: {
    801                 break;
     804                        return -EINVAL;
     805                }
     806                break;
     807        }
     808        case AF_INET6: {
     809                return -EAFNOSUPPORT;
    802810        }
    803811        }
     
    808816size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
    809817{
    810         return recv(fp->fd, dst, dstsz, 0);
     818        return shell_recv(fp->fd, dst, dstsz, 0);
    811819}
    812820
    813821size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
    814822{
    815         return send(fp->fd, src, srcsz, 0);
     823        return shell_send(fp->fd, src, srcsz, 0);
    816824}
    817825
    818826off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
    819827{
    820         return -1;
     828        return -EPERM;
     829}
     830
     831int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
     832{
     833        return -EINVAL;
    821834}
    822835
  • EcnlProtoTool/trunk/ntshell/src/socket_stub.h

    r321 r331  
    3838#define SOCKET_STUB_H
    3939
    40 typedef unsigned socklen_t;
    41 typedef unsigned short sa_family_t;
    42 
    43 struct sockaddr {
    44         sa_family_t sa_family;
    45         char sa_data[14];
    46 };
    47 
    4840struct addrinfo {
    4941        int ai_flags;
     
    5749};
    5850
    59 #define AF_INET         2
    60 #define AF_INET6        10
    61 
    62 #define SOCK_STREAM     1
    63 #define SOCK_DGRAM      2
    64 
    6551typedef uint16_t in_port_t;
    6652typedef uint32_t in_addr_t;
     
    8268        } __in6_union;
    8369};
    84 #define s6_addr __in6_union.__s6_addr
    85 #define s6_addr16 __in6_union.__s6_addr16
    86 #define s6_addr32 __in6_union.__s6_addr32
     70//#define s6_addr __in6_union.__s6_addr
     71//#define s6_addr16 __in6_union.__s6_addr16
     72//#define s6_addr32 __in6_union.__s6_addr32
    8773
    8874struct sockaddr_in6
     
    9480        uint32_t        sin6_scope_id;
    9581};
    96 
    97 #define MSG_OOB       0x0001
    9882
    9983typedef struct socket_t {
     
    124108        size_t (*read)(struct _IO_FILE *, unsigned char *, size_t);
    125109        size_t (*write)(struct _IO_FILE *, const unsigned char *, size_t);
     110        off_t (*seek)(struct _IO_FILE *, off_t, int);
     111        int (*ioctl)(struct _IO_FILE *, int, void *);
    126112        int readevt_r;
    127113        int readevt_w;
     
    132118        union {
    133119                FIL file;
     120                struct {
     121                        DIR dir;
     122                        struct dirent dirent;
     123                };
    134124                socket_t socket;
    135125        };
     
    156146extern size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
    157147extern size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
     148extern off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org);
     149extern int sio_ioctl(struct _IO_FILE *fp, int req, void *arg);
    158150
    159151extern int file_close(struct _IO_FILE *fp);
    160152extern size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
    161153extern size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
     154extern off_t file_seek(struct _IO_FILE *fp, off_t ofs, int org);
     155extern int file_ioctl(struct _IO_FILE *fp, int req, void *arg);
     156
     157extern int dir_close(struct _IO_FILE *fp);
     158extern size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
     159extern size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
     160extern off_t dir_seek(struct _IO_FILE *fp, off_t ofs, int org);
     161extern int dir_ioctl(struct _IO_FILE *fp, int req, void *arg);
    162162
    163163extern int tcp_fd_close(struct _IO_FILE *fp);
    164164extern size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
    165165extern size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
     166extern off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org);
     167extern int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg);
    166168
    167169extern int udp_fd_close(struct _IO_FILE *fp);
    168170extern size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
    169171extern size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
     172extern off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org);
     173extern int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg);
    170174
    171175struct _IO_FILE *fd_to_fp(int fd);
     
    179183struct _IO_FILE *fileid_to_fd(int fileid);
    180184
     185struct _IO_FILE *new_dir_fd(int dirid);
     186int delete_dir_fd(int dirid);
     187struct _IO_FILE *dirid_to_fd(int dirid);
     188
    181189struct _IO_FILE *new_tcp_fd(int tcpid);
    182190int delete_tcp_fd(int tcpid);
  • EcnlProtoTool/trunk/ntshell/src/tinet_app_config.h

    r321 r331  
    22 *  TINET (TCP/IP Protocol Stack)
    33 *
    4  *  Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
     4 *  Copyright (C) 2001-2012 by Dep. of Computer Science and Engineering
    55 *                   Tomakomai National College of Technology, JAPAN
    66 *
     
    6262
    6363/*
    64  *  TCPの能動オープンのみサポートすることを指定する。
    65  */
    66 
    67 #ifdef UNDEF_TCP_CFG_PASSIVE_OPEN
    68 #undef TCP_CFG_PASSIVE_OPEN
    69 #endif
    70 
    71 /*
    7264 *  TCP 通信端点の送受信ウィンドバッファの省コピー機能
    7365 *    注意: Makefile で指定している。
     
    9890#ifdef USE_TCP_MSS_SEG
    9991
     92#ifdef SUPPORT_INET6
     93
     94#define TCP_CFG_SWBUF_CSAVE_MAX_SIZE    (IF_HDR_SIZE + IPV6_MMTU)       /* 最大サイズ */
     95
     96#else   /* of #ifdef SUPPORT_INET6 */
     97
    10098#ifdef SUPPORT_INET4
    10199#define TCP_CFG_SWBUF_CSAVE_MAX_SIZE    (IF_HDR_SIZE + IP4_MSS)         /* 最大サイズ */
    102100#endif
    103101
    104 #ifdef SUPPORT_INET6
    105 #define TCP_CFG_SWBUF_CSAVE_MAX_SIZE    (IF_HDR_SIZE + IPV6_MMTU)       /* 最大サイズ */
    106 #endif
     102#endif  /* of #ifdef SUPPORT_INET6 */
    107103
    108104#else   /* of #ifdef USE_TCP_MSS_SEG */
     
    135131#endif
    136132
     133#ifdef SUPPORT_INET6
     134
     135#define MAX_TCP_SND_SEG                 TCP6_MSS
     136
     137#else   /* of #ifdef SUPPORT_INET6 */
     138
    137139#ifdef SUPPORT_INET4
    138140#define MAX_TCP_SND_SEG                 TCP_MSS
    139141#endif
    140142
    141 #ifdef SUPPORT_INET6
    142 #define MAX_TCP_SND_SEG                 TCP6_MSS
    143 #endif
     143#endif  /* of #ifdef SUPPORT_INET6 */
    144144
    145145#endif  /* of #ifdef USE_TCP_MSS_SEG */
     
    155155#endif
    156156
     157#ifdef SUPPORT_INET6
     158
     159#define DEF_TCP_RCV_SEG                 TCP6_MSS
     160
     161#else   /* of #ifdef SUPPORT_INET6 */
     162
    157163#ifdef SUPPORT_INET4
    158164#define DEF_TCP_RCV_SEG                 TCP_MSS
    159165#endif
    160166
    161 #ifdef SUPPORT_INET6
    162 #define DEF_TCP_RCV_SEG                 TCP6_MSS
    163 #endif
     167#endif  /* of #ifdef SUPPORT_INET6 */
    164168
    165169#endif  /* of #ifdef USE_TCP_MSS_SEG */
     
    235239#define UDP_CFG_EXTENTIONS
    236240
     241/* IPv6 に関する定義 */
     242
     243#ifdef SUPPORT_PPP
     244
     245#define NUM_IN6_STATIC_ROUTE_ENTRY      0
     246#define NUM_IN6_REDIRECT_ROUTE_ENTRY    0
     247
     248#endif  /* of #ifdef SUPPORT_PPP */
     249
     250#ifdef SUPPORT_LOOP
     251
     252#define NUM_IN6_STATIC_ROUTE_ENTRY      0
     253#define NUM_IN6_REDIRECT_ROUTE_ENTRY    0
     254
     255#endif  /* of #ifdef SUPPORT_LOOP */
     256
     257#ifdef SUPPORT_ETHER
     258
     259#define NUM_IN6_STATIC_ROUTE_ENTRY      0
     260#define NUM_IN6_REDIRECT_ROUTE_ENTRY    1
     261
     262#endif  /* of #ifdef SUPPORT_ETHER */
     263
    237264/* IPv4 に関する定義 */
    238 
    239 #ifdef SUPPORT_INET4
    240265
    241266#ifdef SUPPORT_PPP
     
    253278#endif
    254279
    255 #define NUM_STATIC_ROUTE_ENTRY          1
    256 #define NUM_REDIRECT_ROUTE_ENTRY        0
     280#define NUM_IN4_STATIC_ROUTE_ENTRY      1
     281#define NUM_IN4_REDIRECT_ROUTE_ENTRY    0
    257282
    258283#endif  /* of #ifdef SUPPORT_PPP */
     
    260285#ifdef SUPPORT_ETHER
    261286
    262 #ifdef DHCP_CFG
     287#ifdef DHCP4_CLI_CFG
    263288
    264289#define IPV4_ADDR_LOCAL                 MAKE_IPV4_ADDR(0,0,0,0)
     
    266291#define IPV4_ADDR_DEFAULT_GW            MAKE_IPV4_ADDR(0,0,0,0)
    267292
    268 #else   /* of #ifdef DHCP_CFG */
     293#else   /* of #ifdef DHCP4_CLI_CFG */
    269294
    270295#define IPV4_ADDR_LOCAL                 MAKE_IPV4_ADDR(192,168,137,110)
     
    272297#define IPV4_ADDR_DEFAULT_GW            MAKE_IPV4_ADDR(192,168,137,1)
    273298
    274 #endif  /* of #ifdef DHCP_CFG */
    275 
    276 #define NUM_STATIC_ROUTE_ENTRY          3
    277 #define NUM_REDIRECT_ROUTE_ENTRY        1
     299#endif  /* of #ifdef DHCP4_CLI_CFG */
     300
     301#define NUM_IN4_STATIC_ROUTE_ENTRY      3
     302#define NUM_IN4_REDIRECT_ROUTE_ENTRY    1
    278303
    279304#endif  /* of #ifdef SUPPORT_ETHER */
     
    281306#ifdef SUPPORT_LOOP
    282307
    283 #define NUM_STATIC_ROUTE_ENTRY          1
    284 #define NUM_REDIRECT_ROUTE_ENTRY        0
     308#define NUM_IN4_STATIC_ROUTE_ENTRY      1
     309#define NUM_IN4_REDIRECT_ROUTE_ENTRY    0
    285310
    286311#endif  /* of #ifdef SUPPORT_LOOP */
    287 
    288 #endif  /* of #ifdef SUPPORT_INET4 */
    289 
    290 /* IPv6 に関する定義 */
    291 
    292 #ifdef SUPPORT_INET6
    293 
    294 #ifdef SUPPORT_PPP
    295 
    296 #define NUM_STATIC_ROUTE_ENTRY          0
    297 #define NUM_REDIRECT_ROUTE_ENTRY        0
    298 
    299 #endif  /* of #ifdef SUPPORT_PPP */
    300 
    301 #ifdef SUPPORT_LOOP
    302 
    303 #define NUM_STATIC_ROUTE_ENTRY          0
    304 #define NUM_REDIRECT_ROUTE_ENTRY        0
    305 
    306 #endif  /* of #ifdef SUPPORT_LOOP */
    307 
    308 #ifdef SUPPORT_ETHER
    309 
    310 #define NUM_STATIC_ROUTE_ENTRY          0
    311 #define NUM_REDIRECT_ROUTE_ENTRY        1
    312 
    313 #endif  /* of #ifdef SUPPORT_ETHER */
    314 
    315 #endif  /* of #ifdef SUPPORT_INET6 */
    316312
    317313/*
     
    420416 *    IPv6 でのみ割り当てる。
    421417 *
    422  *    RX62N Ethernet Controler のディバイスドライバ(if_rx62n)の最低割当て長は、
     418 *    MBED Ethernet Controler のディバイスドライバ(if_mbed)の最低割当て長は、
    423419 *    イーサネットフレームの最短長である 60(CRC の 4 オクテットを除き、
    424420 *    更にアラインして 62)オクテットである。
  • EcnlProtoTool/trunk/ntshell/src/tinet_main.cfg

    r321 r331  
    4343#include "main.h"
    4444
     45INCLUDE("netinet/ip_igmp.cfg");
     46
    4547/* DHCP クライアント */
    4648/*INCLUDE("netapp/tinet_dhcp4_cli.cfg");*/
     
    4951/* ECHONET Lite UDP 通信端点 */
    5052
    51 #ifdef SUPPORT_INET4
     53VRID_TCP_REP (USR_TCP_REP1);
     54VRID_TCP_REP (USR_TCP_REP2);
     55VRID_TCP_REP (USR_TCP_REP3);
     56VRID_TCP_REP (USR_TCP_REP4);
    5257
    53 VRID_TCP4_REP (USR_TCP_REP1);
    54 VRID_TCP4_REP (USR_TCP_REP2);
    55 VRID_TCP4_REP (USR_TCP_REP3);
    56 VRID_TCP4_REP (USR_TCP_REP4);
     58VRID_TCP_CEP (USR_TCP_CEP1);
     59VRID_TCP_CEP (USR_TCP_CEP2);
     60VRID_TCP_CEP (USR_TCP_CEP3);
     61VRID_TCP_CEP (USR_TCP_CEP4);
     62VRID_TCP_CEP (USR_TCP_CEP5);
     63VRID_TCP_CEP (USR_TCP_CEP6);
     64VRID_TCP_CEP (USR_TCP_CEP7);
     65VRID_TCP_CEP (USR_TCP_CEP8);
    5766
    58 VRID_TCP4_CEP (USR_TCP_CEP1);
    59 VRID_TCP4_CEP (USR_TCP_CEP2);
    60 VRID_TCP4_CEP (USR_TCP_CEP3);
    61 VRID_TCP4_CEP (USR_TCP_CEP4);
    62 VRID_TCP4_CEP (USR_TCP_CEP5);
    63 VRID_TCP4_CEP (USR_TCP_CEP6);
    64 VRID_TCP4_CEP (USR_TCP_CEP7);
    65 VRID_TCP4_CEP (USR_TCP_CEP8);
     67VRID_UDP_CEP (USR_UDP_CEP1);
     68VRID_UDP_CEP (USR_UDP_CEP2);
     69VRID_UDP_CEP (USR_UDP_CEP3);
     70VRID_UDP_CEP (USR_UDP_CEP4);
    6671
    67 VRID_UDP4_CEP (USR_UDP_CEP1);
    68 VRID_UDP4_CEP (USR_UDP_CEP2);
    69 VRID_UDP4_CEP (USR_UDP_CEP3);
    70 VRID_UDP4_CEP (USR_UDP_CEP4);
     72VRID_UDP6_CEP (USR_UDP6_CEP1);
     73VRID_UDP6_CEP (USR_UDP6_CEP2);
     74VRID_UDP6_CEP (USR_UDP6_CEP3);
     75VRID_UDP6_CEP (USR_UDP6_CEP4);
    7176
    72 #endif  /* of #ifdef SUPPORT_INET4 */
    73 
    74 #ifdef SUPPORT_INET6
    75 
    76 VRID_TCP6_REP (USR_TCP_REP1);
    77 VRID_TCP6_REP (USR_TCP_REP2);
    78 VRID_TCP6_REP (USR_TCP_REP3);
    79 VRID_TCP6_REP (USR_TCP_REP4);
    80 
    81 VRID_TCP6_CEP (USR_TCP_CEP1);
    82 VRID_TCP6_CEP (USR_TCP_CEP2);
    83 VRID_TCP6_CEP (USR_TCP_CEP3);
    84 VRID_TCP6_CEP (USR_TCP_CEP4);
    85 VRID_TCP6_CEP (USR_TCP_CEP5);
    86 VRID_TCP6_CEP (USR_TCP_CEP6);
    87 VRID_TCP6_CEP (USR_TCP_CEP7);
    88 VRID_TCP6_CEP (USR_TCP_CEP8);
    89 
    90 VRID_UDP6_CEP (USR_UDP_CEP1);
    91 VRID_UDP6_CEP (USR_UDP_CEP2);
    92 VRID_UDP6_CEP (USR_UDP_CEP3);
    93 VRID_UDP6_CEP (USR_UDP_CEP4);
    94 
    95 #endif  /* of #ifdef SUPPORT_INET6 */
    96 
  • EcnlProtoTool/trunk/ntshell/webserver/base64.c

    r321 r331  
    77
    88#include "base64.h"
     9#include "core/ntlibc.h"
    910
    1011static const char base64_encode_chars[] =
     
    8586    unsigned char *pdst;
    8687    int i, j = 0, k = 0;
    87     size_t srcsiz = strlen((const char *)src);
     88    size_t srcsiz = ntlibc_strlen((const char *)src);
    8889
    8990    if ((srcsiz % 4) != 0) {
  • EcnlProtoTool/trunk/ntshell/webserver/http_parser.c

    r321 r331  
    2929#include <string.h>
    3030#include <limits.h>
     31#include "core/ntlibc.h"
    3132
    3233#ifndef ULLONG_MAX
     
    23712372  if (u->field_set & (1 << UF_PORT)) {
    23722373    /* Don't bother with endp; we've already validated the string */
    2373     unsigned long v = strtoul(buf + u->field_data[UF_PORT].off, NULL, 10);
     2374    unsigned long v = ntlibc_strtoul(buf + u->field_data[UF_PORT].off, NULL, 10);
    23742375
    23752376    /* Ports have a max value of 2^16 */
  • EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.c

    r321 r331  
    4545#include "kernel_cfg.h"
    4646#include "syssvc/syslog.h"
    47 #include "ntstdio.h"
     47#include "util/ntstdio.h"
    4848
    4949#ifndef _MSC_VER
    5050#ifndef strcat_s
    51 #define strcat_s(dst, dsz, src) strcat(dst, src)
     51#define strcat_s(dst, dsz, src) ntlibc_strcat(dst, src)
    5252#endif
    5353#endif
     
    7575        res = f_opendir(&dir, path);
    7676        if (res == FR_OK) {
    77                 i = strlen(path);
     77                i = ntlibc_strlen(path);
    7878                for (;;) {
    7979                        res = f_readdir(&dir, &fno);
  • EcnlProtoTool/trunk/ntshell/webserver/httpd.c

    r321 r331  
    4343#include "syssvc/syslog.h"
    4444#include "http-strings.h"
     45#include <tinet_defs.h>
     46#include <tinet_config.h>
    4547#include "netinet/in.h"
    4648#include "netinet/in_var.h"
     49#include "netinet/in_itron.h"
    4750#include "httpd.h"
    4851#include "httpd-fs.h"
     
    5053#include "base64.h"
    5154#include "sha1.h"
    52 #include "ntstdio.h"
     55#include "util/ntstdio.h"
     56#include "core/ntlibc.h"
    5357
    5458#define TRUE 1
     
    8286
    8387#ifndef _MSC_VER
     88#define strnlen httpd_strnlen
    8489/* strnlen() is a POSIX.2008 addition. Can't rely on it being available so
    8590 * define it ourselves.
     
    99104void strcpy_s(char *dst, int size, const char *src)
    100105{
    101         int slen = strlen(src);
     106        int slen = ntlibc_strlen(src);
    102107        if (slen >= size)
    103108                slen = size - 1;
     
    108113void strcat_s(char *dst, int size, const char *src)
    109114{
    110         int dlen = strlen(dst);
    111         int slen = strlen(src);
     115        int dlen = ntlibc_strlen(dst);
     116        int slen = ntlibc_strlen(src);
    112117        if (dlen + slen >= size)
    113118                slen = size - 1 - dlen;
     
    223228        struct message *m = &s->message;
    224229
    225         if (strncmp("Referer", buf, len) == 0) {
     230        if (ntlibc_strncmp("Referer", buf, len) == 0) {
    226231                m->num_headers = 1;
    227232        }
    228         else if (strncmp("Host", buf, len) == 0) {
     233        else if (ntlibc_strncmp("Host", buf, len) == 0) {
    229234                m->num_headers = 2;
    230235        }
    231         else if (strncmp("Upgrade", buf, len) == 0) {
     236        else if (ntlibc_strncmp("Upgrade", buf, len) == 0) {
    232237                m->num_headers = 3;
    233238        }
    234         else if (strncmp("Connection", buf, len) == 0) {
     239        else if (ntlibc_strncmp("Connection", buf, len) == 0) {
    235240                m->num_headers = 4;
    236241        }
    237         else if (strncmp("Sec-WebSocket-Key", buf, len) == 0) {
     242        else if (ntlibc_strncmp("Sec-WebSocket-Key", buf, len) == 0) {
    238243                m->num_headers = 5;
    239244        }
    240         else if (strncmp("Origin", buf, len) == 0) {
     245        else if (ntlibc_strncmp("Origin", buf, len) == 0) {
    241246                m->num_headers = 6;
    242247        }
    243         else if (strncmp("Sec-WebSocket-Protocol", buf, len) == 0) {
     248        else if (ntlibc_strncmp("Sec-WebSocket-Protocol", buf, len) == 0) {
    244249                m->num_headers = 7;
    245250        }
    246         else if (strncmp("Sec-WebSocket-Version", buf, len) == 0) {
     251        else if (ntlibc_strncmp("Sec-WebSocket-Version", buf, len) == 0) {
    247252                m->num_headers = 8;
    248253        }
     
    329334                        s->in.state = IN_STATE_UPLOAD;
    330335                }
    331                 else if (strcmp(s->filename, uploding->filename) == 0) {
     336                else if (ntlibc_strcmp(s->filename, uploding->filename) == 0) {
    332337                        ntstdio_printf(&ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
    333338                        goto error;
     
    559564        char *ptr;
    560565
    561         len = strlen(statushdr);
     566        len = ntlibc_strlen(statushdr);
    562567        tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR);
    563568
     
    574579                        tcp_snd_dat(s->cepid, "/~", len, TMO_FEVR);
    575580                }
    576                 len = strlen(s->filename);
     581                len = ntlibc_strlen(s->filename);
    577582                tcp_snd_dat(s->cepid, s->filename, len, TMO_FEVR);
    578583                if (s->query != NULL) {
    579584                        tcp_snd_dat(s->cepid, "?", 1, TMO_FEVR);
    580                         len = strlen(s->query);
     585                        len = ntlibc_strlen(s->query);
    581586                        tcp_snd_dat(s->cepid, s->query, len, TMO_FEVR);
    582587                }
     
    590595                tcp_snd_dat(s->cepid, (void *)http_content_type_binary, len, TMO_FEVR);
    591596        }
    592         else if (strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 ||
    593                 strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) {
     597        else if (ntlibc_strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 ||
     598                ntlibc_strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) {
    594599                len = sizeof(http_content_type_html) - 1;
    595600                tcp_snd_dat(s->cepid, (void *)http_content_type_html, len, TMO_FEVR);
    596601        }
    597         else if (strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) {
     602        else if (ntlibc_strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) {
    598603                len = sizeof(http_content_type_css) - 1;
    599604                tcp_snd_dat(s->cepid, (void *)http_content_type_css, len, TMO_FEVR);
    600605        }
    601         else if (strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) {
     606        else if (ntlibc_strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) {
    602607                len = sizeof(http_content_type_js) - 1;
    603608                tcp_snd_dat(s->cepid, (void *)http_content_type_js, len, TMO_FEVR);
    604609        }
    605         else if (strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) {
     610        else if (ntlibc_strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) {
    606611                len = sizeof(http_content_type_json) - 1;
    607612                tcp_snd_dat(s->cepid, (void *)http_content_type_json, len, TMO_FEVR);
    608613        }
    609         else if (strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) {
     614        else if (ntlibc_strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) {
    610615                len = sizeof(http_content_type_png) - 1;
    611616                tcp_snd_dat(s->cepid, (void *)http_content_type_png, len, TMO_FEVR);
    612617        }
    613         else if (strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) {
     618        else if (ntlibc_strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) {
    614619                len = sizeof(http_content_type_gif) - 1;
    615620                tcp_snd_dat(s->cepid, (void *)http_content_type_gif, len, TMO_FEVR);
    616621        }
    617         else if (strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) {
     622        else if (ntlibc_strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) {
    618623                len = sizeof(http_content_type_jpg) - 1;
    619624                tcp_snd_dat(s->cepid, (void *)http_content_type_jpg, len, TMO_FEVR);
    620625        }
    621         else if (strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) {
     626        else if (ntlibc_strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) {
    622627                len = sizeof(http_content_type_svg) - 1;
    623628                tcp_snd_dat(s->cepid, (void *)http_content_type_svg, len, TMO_FEVR);
    624629        }
    625         else if (strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) {
     630        else if (ntlibc_strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) {
    626631                len = sizeof(http_content_type_text) - 1;
    627632                tcp_snd_dat(s->cepid, (void *)http_content_type_text, len, TMO_FEVR);
    628633        }
    629         else if (strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) {
     634        else if (ntlibc_strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) {
    630635                len = sizeof(http_content_type_eot) - 1;
    631636                tcp_snd_dat(s->cepid, (void *)http_content_type_eot, len, TMO_FEVR);
    632637        }
    633         else if (strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) {
     638        else if (ntlibc_strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) {
    634639                len = sizeof(http_content_type_ttf) - 1;
    635640                tcp_snd_dat(s->cepid, (void *)http_content_type_ttf, len, TMO_FEVR);
    636641        }
    637         else if (strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) {
     642        else if (ntlibc_strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) {
    638643                len = sizeof(http_content_type_woff) - 1;
    639644                tcp_snd_dat(s->cepid, (void *)http_content_type_woff, len, TMO_FEVR);
    640645        }
    641         else if (strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) {
     646        else if (ntlibc_strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) {
    642647                len = sizeof(http_content_type_woff2) - 1;
    643648                tcp_snd_dat(s->cepid, (void *)http_content_type_woff2, len, TMO_FEVR);
    644649        }
    645         else if (strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) {
     650        else if (ntlibc_strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) {
    646651                len = sizeof(http_content_type_ico) - 1;
    647652                tcp_snd_dat(s->cepid, (void *)http_content_type_ico, len, TMO_FEVR);
     
    656661                tcp_snd_dat(s->cepid, (void *)http_content_length, len, TMO_FEVR);
    657662                ntstdio_snprintf(s->temp, sizeof(s->temp), "%d\r\n", s->file.len);
    658                 tcp_snd_dat(s->cepid, (void *)s->temp, strlen(s->temp), TMO_FEVR);
     663                tcp_snd_dat(s->cepid, (void *)s->temp, ntlibc_strlen(s->temp), TMO_FEVR);
    659664        }
    660665
     
    732737        int len;
    733738
    734         len = strlen(statushdr);
     739        len = ntlibc_strlen(statushdr);
    735740        tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR);
    736741
    737742        len = sizeof(http_upgrade) - 1;
    738743        tcp_snd_dat(s->cepid, (void *)http_upgrade, len, TMO_FEVR);
    739         len = strlen(s->message.upgrade);
     744        len = ntlibc_strlen(s->message.upgrade);
    740745        tcp_snd_dat(s->cepid, s->message.upgrade, len, TMO_FEVR);
    741746        len = sizeof(http_crnl) - 1;
     
    744749        len = sizeof(http_connection) - 1;
    745750        tcp_snd_dat(s->cepid, (void *)http_connection, len, TMO_FEVR);
    746         len = strlen(s->message.connection);
     751        len = ntlibc_strlen(s->message.connection);
    747752        tcp_snd_dat(s->cepid, s->message.connection, len, TMO_FEVR);
    748753        len = sizeof(http_crnl) - 1;
     
    751756        len = sizeof(http_sec_websocket_accept) - 1;
    752757        tcp_snd_dat(s->cepid, (void *)http_sec_websocket_accept, len, TMO_FEVR);
    753         len = strlen(s->message.response_key);
     758        len = ntlibc_strlen(s->message.response_key);
    754759        tcp_snd_dat(s->cepid, s->message.response_key, len, TMO_FEVR);
    755760        len = sizeof(http_crnl) - 1;
     
    758763        len = sizeof(http_sec_websocket_protocol) - 1;
    759764        tcp_snd_dat(s->cepid, (void *)http_sec_websocket_protocol, len, TMO_FEVR);
    760         len = strlen(s->message.sec_websocket_protocol);
     765        len = ntlibc_strlen(s->message.sec_websocket_protocol);
    761766        tcp_snd_dat(s->cepid, s->message.sec_websocket_protocol, len, TMO_FEVR);
    762767        len = sizeof(http_crnl) - 1;
Note: See TracChangeset for help on using the changeset viewer.