Changeset 387 for asp3_tinet_ecnl_rx/trunk/ntshell
- Timestamp:
- May 22, 2019, 4:09:18 PM (5 years ago)
- Location:
- asp3_tinet_ecnl_rx/trunk/ntshell
- Files:
-
- 4 added
- 12 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ffarch.c
r374 r387 84 84 ret2 = get_tim(&now); 85 85 if (ret2 != E_OK){ 86 printf("[ffarch] get_tim error: %s",86 syslog(LOG_NOTICE, "[ffarch] get_tim error: %s", 87 87 itron_strerror(ret2)); 88 88 return; … … 98 98 ret = tslp_tsk(timer); 99 99 if ((ret != E_OK) && (ret != E_TMOUT)) { 100 printf("[ffarch] tslp_tsk error: %s %d",100 syslog(LOG_NOTICE, "[ffarch] tslp_tsk error: %s %d", 101 101 itron_strerror(ret), timer); 102 102 break; … … 105 105 ret2 = get_tim(&now); 106 106 if (ret2 != E_OK) { 107 printf("[ffarch] get_tim error: %s",107 syslog(LOG_NOTICE, "[ffarch] get_tim error: %s", 108 108 itron_strerror(ret2)); 109 109 break; … … 150 150 #endif 151 151 if (romdisk_init()) { 152 printf("ROM disk (0:) OK!\n");152 syslog(LOG_NOTICE, "ROM disk (0:) OK!"); 153 153 } 154 154 else { 155 printf("ROM disk (0:) NG!\n");155 syslog(LOG_NOTICE, "ROM disk (0:) NG!"); 156 156 } 157 157 } … … 303 303 case FFS_RETRY_WAIT: 304 304 if (ffarch_retry_count == 0) { 305 printf("SD card (1:) initialize tired...\n");305 syslog(LOG_NOTICE, "SD card (1:) initialize tired..."); 306 306 307 307 ffarch_state = FFS_IDLE; … … 315 315 /* SDカードが入れられた場合 */ 316 316 if (((mmc_rspi_prev_status & STA_NODISK) != 0) && ((mmc_rspi_status() & STA_NODISK) == 0)) { 317 printf("SD card initializing ...\n");317 syslog(LOG_NOTICE, "SD card initializing ..."); 318 318 319 319 Sd.FatFs.fs_type = 0; 320 320 if (SD_begin()) { 321 printf("SD card (1:) OK!\n");321 syslog(LOG_NOTICE, "SD card (1:) OK!"); 322 322 323 323 /* uploadディレクトリを作成しておく */ … … 329 329 } 330 330 else { 331 printf("SD card (1:) NG!\n");331 syslog(LOG_NOTICE, "SD card (1:) NG!"); 332 332 ffarch_state = FFS_RETRY_WAIT; 333 333 ffarch_timer = 1000 * 1000; … … 336 336 /* SDカードが抜かれた場合 */ 337 337 else if (((mmc_rspi_prev_status & STA_NODISK) == 0) && ((mmc_rspi_status() & STA_NODISK) != 0)) { 338 printf("SD card unmount\n");338 syslog(LOG_NOTICE, "SD card unmount"); 339 339 340 340 f_mount(&Sd.FatFs, "1:", 0); -
asp3_tinet_ecnl_rx/trunk/ntshell/ntshell/util/ntstdio.c
r337 r387 224 224 handle->xi = xi; 225 225 handle->xo = xo; 226 handle->outptr = 0;227 handle->len = 0;228 226 handle->pos = 0; 229 227 handle->option = option; … … 232 230 static void _putc(ntstdio_t *handle, char c) 233 231 { 234 if (handle->outptr) {235 if ((handle->pos + 1) >= handle->len)236 return;237 handle->outptr[handle->pos] = (unsigned char)c;238 handle->pos++;239 return;240 }241 242 232 if (handle->xo) { 243 233 handle->xo(handle, (unsigned char)c); … … 291 281 } 292 282 283 struct put_buf_t { 284 char *outptr; 285 int len; 286 }; 287 288 static void put_buf(struct ntstdio_t *handle, unsigned char c) 289 { 290 struct put_buf_t *put_buf = (struct put_buf_t *)handle->exinf; 291 if ((handle->pos + 1) >= put_buf->len) 292 return; 293 put_buf->outptr[handle->pos] = (char)c; 294 handle->pos++; 295 } 296 293 297 int ntstdio_snprintf(char *buf, int len, const char *fmt, ...) 294 298 { 295 299 int result; 296 300 ntstdio_t handle; 301 struct put_buf_t exinf; 297 302 va_list arp; 298 303 /* Switch destination for memory */ 304 handle.xo = put_buf; 299 305 handle.option = 0; 300 handle.outptr = buf;301 handle.len = len;302 306 handle.pos = 0; 307 handle.exinf = &exinf; 308 exinf.outptr = buf; 309 exinf.len = len; 310 303 311 va_start(arp, fmt); 304 312 result = xvprintf(&handle, fmt, arp); … … 306 314 307 315 /* Terminate output string with a \0 */ 308 handle.outptr[handle.pos] = '\0';316 buf[handle.pos] = '\0'; 309 317 return result; 310 318 } -
asp3_tinet_ecnl_rx/trunk/ntshell/ntshell/util/ntstdio.h
r374 r387 74 74 NTSTDIO_XI xi; 75 75 NTSTDIO_XO xo; 76 char *outptr;77 int len;78 76 int pos; 79 77 unsigned int option; -
asp3_tinet_ecnl_rx/trunk/ntshell/src/fdtable.c
r374 r387 44 44 #include "syssvc/syslog.h" 45 45 #include "target_syssvc.h" 46 #ifndef NTSHELL_NO_SOCKET 47 #include <tinet_defs.h> 48 #include <tinet_config.h> 49 #include <net/net.h> 50 #include <net/net_endian.h> 51 #include <netinet/in.h> 52 #include <netinet/in_itron.h> 53 #include <tinet_nic_defs.h> 54 #include <tinet_cfg.h> 55 #include <netinet/in_var.h> 56 #include <net/ethernet.h> 57 #include <net/if6_var.h> 58 #include <net/net.h> 59 #include <net/if_var.h> 60 #include <netinet/udp.h> 61 #include <netinet/udp_var.h> 62 #include <netinet/tcp.h> 63 #include <netinet/tcp_var.h> 64 #include <net/net_buf.h> 65 #endif 66 #include "ff.h" 67 #include "socket_stub.h" 46 #include "fdtable.h" 68 47 #include "kernel_cfg.h" 69 48 #include <string.h> … … 71 50 #include "hal/serial_api.h" 72 51 73 static int stdio_close(struct SHELL_FILE *fp); 74 static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 75 static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 76 static size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 77 static size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 78 static size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 79 static void stdio_delete(struct SHELL_FILE *fp); 80 81 static int sio_close(struct SHELL_FILE *fp); 82 static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 83 static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 84 static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org); 85 static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg); 86 static bool_t sio_readable(struct SHELL_FILE *fp); 87 static void sio_delete(struct SHELL_FILE *fp); 88 89 IO_TYPE IO_TYPE_STDIN = { stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl, sio_readable, stdio_delete }; 90 IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl, sio_readable, stdio_delete }; 91 IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl, sio_readable, stdio_delete }; 92 IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_delete }; 93 ntstdio_t ntstdio; 52 #ifdef _DEBUG 53 static const char THIS_FILE[] = __FILE__; 54 #endif 55 56 extern IO_TYPE IO_TYPE_STDIN; 57 extern IO_TYPE IO_TYPE_STDOUT; 58 extern IO_TYPE IO_TYPE_STDERR; 94 59 95 60 static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = { 96 { 0, &IO_TYPE_STDIN, 0, .exinf = &ntstdio},97 { 1, &IO_TYPE_STDOUT, 0, .exinf = &ntstdio},98 { 2, &IO_TYPE_STDERR, 0,.exinf = &ntstdio},61 { STDIN_FILENO, &IO_TYPE_STDIN, 0 }, 62 { STDOUT_FILENO, &IO_TYPE_STDOUT, 0 }, 63 { STDERR_FILENO, &IO_TYPE_STDERR, 0 }, 99 64 }; 100 65 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0])) 101 102 extern ntstdio_t ntstdio;103 serial_t stdio_uart;104 105 unsigned char ntstdio_xi(struct ntstdio_t *handle)106 {107 return serial_getc((serial_t *)handle->exinf);108 }109 110 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)111 {112 serial_putc((serial_t *)handle->exinf, c);113 }114 115 void sys_init(intptr_t exinf)116 {117 sys_tlsf_init();118 119 serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);120 serial_baud(&stdio_uart, UART_BAUDRATE);121 serial_format(&stdio_uart, 8, ParityNone, 1);122 123 ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);124 ntstdio.exinf = (void *)&stdio_uart;125 }126 127 int stdio_close(struct SHELL_FILE *fp)128 {129 return -EPERM;130 }131 132 size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)133 {134 return -EPERM;135 }136 137 size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)138 {139 return -EPERM;140 }141 142 size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)143 {144 int i = 0;145 while (i < len) {146 int c = ntstdio_getc((struct ntstdio_t *)fp->exinf);147 data[i++] = c;148 if ((c == EOF) || (c == '\n'))149 break;150 }151 return i;152 }153 154 size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)155 {156 for (int i = 0; i < len; i++) {157 ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);158 }159 return len;160 }161 162 size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)163 {164 for (int i = 0; i < len; i++) {165 ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);166 }167 return len;168 }169 170 void stdio_delete(struct SHELL_FILE *fp)171 {172 }173 174 int sio_close(struct SHELL_FILE *fp)175 {176 return -EPERM;177 }178 179 size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)180 {181 return -EPERM;182 }183 184 size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)185 {186 return -EPERM;187 }188 189 off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org)190 {191 return -EPERM;192 }193 194 int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg)195 {196 switch (request) {197 case TIOCGWINSZ:198 return 0;199 case TCGETS:200 return sio_tcgetattr(fp->fd, (struct termios *)arg);201 case TCSETS + TCSANOW:202 case TCSETS + TCSADRAIN:203 case TCSETS + TCSAFLUSH:204 return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);205 }206 207 return -EINVAL;208 }209 210 bool_t sio_readable(struct SHELL_FILE *fp)211 {212 return fp->readevt_w != fp->readevt_r;213 }214 215 void sio_delete(struct SHELL_FILE *fp)216 {217 free((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf);218 ((struct ntstdio_t *)fp->exinf)->exinf = NULL;219 free((struct ntstdio_t *)fp->exinf);220 fp->exinf = NULL;221 }222 66 223 67 struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable) … … 247 91 if (ret < 0) { 248 92 syslog(LOG_ERROR, "sig_sem => %d", ret); 93 } 94 95 if (fp != NULL) { 96 FLGPTN flgptn = 0; 97 98 FD_SET(fp->fd, (fd_set *)&flgptn); 99 100 ret = clr_flg(FLG_SELECT_WAIT, ~flgptn); 101 if (ret != E_OK) { 102 syslog(LOG_ERROR, "clr_flg => %d", ret); 103 } 249 104 } 250 105 … … 442 297 } 443 298 444 /* TODO:コールバック化したい */445 void stdio_update_evts()446 {447 int fd = STDIN_FILENO;448 struct SHELL_FILE *fp = &fd_table[fd];449 FLGPTN flgptn = 0;450 451 if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {452 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;453 454 FD_SET(fd, (fd_set *)&flgptn);455 }456 if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {457 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;458 459 FD_SET(fd, (fd_set *)&flgptn);460 }461 462 if (flgptn != 0) {463 set_flg(FLG_SELECT_WAIT, flgptn);464 }465 }466 467 /* TODO:コールバック化したい */468 void stdio_flgptn(FLGPTN *flgptn)469 {470 int fd = STDIN_FILENO;471 struct SHELL_FILE *fp = &fd_table[fd];472 *flgptn = 0;473 474 if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {475 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;476 477 FD_SET(fd, (fd_set *)flgptn);478 }479 if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {480 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;481 482 FD_SET(fd, (fd_set *)flgptn);483 }484 }485 486 299 ER shell_get_evts(struct fd_events *evts, TMO tmout) 487 300 { 488 301 int count = 0; 489 302 SYSTIM prev, now; 303 FLGPTN flgptn; 490 304 491 305 get_tim(&prev); … … 493 307 for (;;) { 494 308 ER ret; 495 FLGPTN waitptn, flgptn,readfds = 0, writefds = 0;309 FLGPTN waitptn, readfds = 0, writefds = 0; 496 310 struct SHELL_FILE *fp = NULL; 497 498 stdio_update_evts();499 311 500 312 #ifndef NTSHELL_NO_SOCKET … … 506 318 fp = &fd_table[fd]; 507 319 508 #ifndef NTSHELL_NO_SOCKET509 320 if (FD_ISSET(fd, &evts->readfds)) { 510 321 if (fp->type->readable(fp)) { … … 517 328 } 518 329 } 519 #endif 330 520 331 if (FD_ISSET(fd, &evts->writefds)) { 521 if (fp-> writeevt_w == fp->writeevt_r) {332 if (fp->type->writable(fp)) { 522 333 FD_SET(fd, (fd_set *)&writefds); 523 334 count++; … … 549 360 return ret; 550 361 } 551 552 stdio_flgptn(&flgptn); 553 554 if (flgptn == 0) 555 return E_TMOUT; 556 } 557 flgptn &= waitptn; 558 559 /* 受け取ったフラグのみクリア */ 560 ret = clr_flg(FLG_SELECT_WAIT, ~flgptn); 561 if (ret != E_OK) { 562 syslog(LOG_ERROR, "clr_flg => %d", ret); 362 } 363 364 if (flgptn != 0) { 365 flgptn &= waitptn; 366 367 /* 受け取ったフラグのみクリア */ 368 ret = clr_flg(FLG_SELECT_WAIT, ~flgptn); 369 if (ret != E_OK) { 370 syslog(LOG_ERROR, "clr_flg => %d", ret); 371 } 563 372 } 564 373 565 374 count = 0; 566 375 for (int fd = 0; fd < fd_table_count; fd++) { 567 if (!FD_ISSET(fd, (fd_set *)&waitptn))568 continue;569 570 376 fp = &fd_table[fd]; 571 377 572 378 if (fp->readevt_w != fp->readevt_r) { 573 379 fp->readevt_r++; 574 FD_SET(fd, &evts->readfds); 380 if (FD_ISSET(fd, (fd_set *)&waitptn)) 381 FD_SET(fd, &evts->readfds); 575 382 count++; 576 383 } 577 384 if (fp->writeevt_w != fp->writeevt_r) { 578 385 fp->writeevt_r++; 579 fp->writable = 1; 580 } 581 if (fp->writable) { 582 FD_SET(fd, &evts->writefds); 386 if (FD_ISSET(fd, (fd_set *)&waitptn)) 387 FD_SET(fd, &evts->writefds); 583 388 count++; 584 389 } 585 390 if (fp->errorevt_w != fp->errorevt_r) { 586 391 fp->errorevt_r++; 587 FD_SET(fd, &evts->errorfds); 392 if (FD_ISSET(fd, (fd_set *)&waitptn)) 393 FD_SET(fd, &evts->errorfds); 588 394 count++; 589 395 } 590 396 } 591 397 592 if ( count > 0)398 if ((flgptn == 0) || (count > 0)) 593 399 break; 594 400 … … 596 402 597 403 SYSTIM elapse = now - prev; 598 if (elapse > tmout) 599 return E_TMOUT; 404 if (elapse > tmout) { 405 flgptn = 0; 406 break; 407 } 600 408 601 409 prev = now; … … 605 413 evts->count = count; 606 414 607 return E_OK;415 return (flgptn == 0) ? E_TMOUT : E_OK; 608 416 } 609 417 -
asp3_tinet_ecnl_rx/trunk/ntshell/src/fdtable.h
r386 r387 38 38 #define SOCKET_STUB_H 39 39 40 struct addrinfo {41 int ai_flags;42 int ai_family;43 int ai_socktype;44 int ai_protocol;45 socklen_t ai_addrlen;46 struct sockaddr *ai_addr;47 char *ai_canonname;48 struct addrinfo *ai_next;49 };50 51 typedef uint16_t in_port_t;52 typedef uint32_t in_addr_t;53 struct in_addr { in_addr_t s_addr; };54 55 struct sockaddr_in {56 sa_family_t sin_family;57 in_port_t sin_port;58 struct in_addr sin_addr;59 uint8_t sin_zero[8];60 };61 62 struct in6_addr63 {64 union {65 uint8_t __s6_addr[16];66 uint16_t __s6_addr16[8];67 uint32_t __s6_addr32[4];68 } __in6_union;69 };70 //#define s6_addr __in6_union.__s6_addr71 //#define s6_addr16 __in6_union.__s6_addr1672 //#define s6_addr32 __in6_union.__s6_addr3273 74 struct sockaddr_in675 {76 sa_family_t sin6_family;77 in_port_t sin6_port;78 uint32_t sin6_flowinfo;79 struct in6_addr sin6_addr;80 uint32_t sin6_scope_id;81 };82 83 typedef struct socket_t {84 int family;85 int type;86 int protocol;87 int cepid;88 int repid;89 int backlog;90 unsigned int flags;91 union {92 struct sockaddr_in laddr4;93 struct sockaddr_in6 laddr6;94 };95 union {96 struct sockaddr_in raddr4;97 struct sockaddr_in6 raddr6;98 };99 int buf_size;100 unsigned char *buf;101 void *input;102 int len;103 } socket_t;104 105 struct SHELL_DIR {106 FATFS_DIR dir;107 struct dirent dirent;108 };109 110 40 typedef const struct io_type_s IO_TYPE; 111 41 … … 131 61 int (*ioctl)(struct SHELL_FILE *, int, void *); 132 62 bool_t (*readable)(struct SHELL_FILE *); 63 bool_t (*writable)(struct SHELL_FILE *); 133 64 void (*delete)(struct SHELL_FILE *); 134 65 }; … … 152 83 void clean_fd(); 153 84 154 void sys_tlsf_init(void);155 156 85 #endif // !SOCKET_STUB_H -
asp3_tinet_ecnl_rx/trunk/ntshell/src/io_stub.c
r374 r387 45 45 #include "syssvc/serial.h" 46 46 #include "syssvc/syslog.h" 47 #include " socket_stub.h"47 #include "fdtable.h" 48 48 #include "util/ntstdio.h" 49 49 #include "usrcmd.h" … … 51 51 #include "kernel_cfg.h" 52 52 #include "target_syssvc.h" 53 54 struct SHELL_DIR { 55 FATFS_DIR dir; 56 struct dirent dirent; 57 }; 53 58 54 59 int fresult2errno(FRESULT res) … … 85 90 static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg); 86 91 static bool_t file_readable(struct SHELL_FILE *fp); 92 static bool_t file_writable(struct SHELL_FILE *fp); 87 93 static void file_delete(struct SHELL_FILE *fp); 88 94 … … 93 99 static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg); 94 100 static bool_t dir_readable(struct SHELL_FILE *fp); 101 static bool_t dir_writable(struct SHELL_FILE *fp); 95 102 static void dir_delete(struct SHELL_FILE *fp); 96 103 97 IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_ delete };98 IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_ delete };104 IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_writable, file_delete }; 105 IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_writable, dir_delete }; 99 106 100 107 int shell_open(const char *path, int flags, void *arg) … … 114 121 FRESULT res; 115 122 if ((res = f_opendir(dir, path)) != FR_OK) { 123 delete_fp(fp); 116 124 return fresult2errno(res); 117 125 } … … 165 173 } 166 174 175 delete_fp(fp); 167 176 return fresult2errno(res); 168 177 } … … 239 248 } 240 249 250 bool_t file_writable(struct SHELL_FILE *fp) 251 { 252 return fp->writable && (fp->writeevt_w == fp->writeevt_r); 253 } 254 241 255 void file_delete(struct SHELL_FILE *fp) 242 256 { … … 356 370 { 357 371 return shell_ioctl(fd, cmd, arg); 358 }359 360 extern IO_TYPE IO_TYPE_SIO;361 362 int sio_tcgetattr(int fd, struct termios *termios)363 {364 struct SHELL_FILE *fp = fd_to_fp(fd);365 if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))366 return -EBADF;367 368 ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;369 370 memset(termios, 0, sizeof(*termios));371 372 if (ntstdio->option & NTSTDIO_OPTION_LINE_ECHO) {373 termios->c_lflag |= ECHO;374 }375 else {376 termios->c_lflag &= ~ECHO;377 }378 if (ntstdio->option & NTSTDIO_OPTION_CANON) {379 termios->c_lflag |= ICANON;380 }381 else {382 termios->c_lflag &= ~ICANON;383 }384 if (ntstdio->option & NTSTDIO_OPTION_LF_CR) {385 termios->c_iflag |= INLCR;386 }387 else {388 termios->c_iflag &= ~INLCR;389 }390 if (ntstdio->option & NTSTDIO_OPTION_LF_CRLF) {391 termios->c_oflag |= ONLCR;392 }393 else {394 termios->c_oflag &= ~ONLCR;395 }396 397 return 0;398 }399 400 int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)401 {402 struct SHELL_FILE *fp = fd_to_fp(fd);403 if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))404 return -EBADF;405 406 ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;407 408 if (optional_actions == TCSANOW) {409 if (termios->c_lflag & ECHO) {410 ntstdio->option |= NTSTDIO_OPTION_LINE_ECHO;411 }412 else {413 ntstdio->option &= ~NTSTDIO_OPTION_LINE_ECHO;414 }415 if (termios->c_lflag & ICANON) {416 ntstdio->option |= NTSTDIO_OPTION_CANON;417 }418 else {419 ntstdio->option &= ~NTSTDIO_OPTION_CANON;420 }421 if (termios->c_iflag & INLCR) {422 ntstdio->option |= NTSTDIO_OPTION_LF_CR;423 }424 else {425 ntstdio->option &= ~NTSTDIO_OPTION_LF_CR;426 }427 if (termios->c_oflag & ONLCR) {428 ntstdio->option |= NTSTDIO_OPTION_LF_CRLF;429 }430 else {431 ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF;432 }433 return 0;434 }435 436 shell_abort();437 return 0;438 372 } 439 373 … … 688 622 } 689 623 624 bool_t dir_writable(struct SHELL_FILE *fp) 625 { 626 return false; 627 } 628 690 629 void dir_delete(struct SHELL_FILE *fp) 691 630 { … … 710 649 return 0; 711 650 } 712 713 #ifndef _MSC_VER714 extern uint32_t _HeapBase;715 extern uint32_t _HeapLimit;716 #else717 uint8_t _HeapBase[14 * 4096];718 #define _HeapLimit _HeapBase[sizeof(_HeapBase)]719 #endif720 721 void *shell_brk(void *addr)722 {723 if (addr == 0) {724 return (void *)(&_HeapBase);725 }726 if ((addr >= (void *)&_HeapBase) && (addr < (void *)&_HeapLimit)) {727 return addr;728 }729 return (void *)-1;730 }731 732 void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)733 {734 if (fd != -1)735 return (void *)-EINVAL;736 737 if ((length >= 0) && (length <= sizeof(&_HeapBase))) {738 return &_HeapBase;739 }740 return (void *)-1;741 }742 743 int shell_mprotect(void *addr, size_t len, int prot)744 {745 //if ((addr >= (void *)&_HeapBase) && (addr + len < (void *)&_HeapLimit)) {746 return 0;747 //}748 //return -1;749 }750 751 #include "tlsf.h"752 753 static tlsf_t sys_tlsf;754 static pool_t sys_pool;755 756 void sys_tlsf_init(void)757 {758 sys_tlsf = tlsf_create(&_HeapBase);759 if (sys_tlsf == NULL)760 return;761 762 sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&_HeapBase) + tlsf_size(), ((intptr_t)&_HeapLimit - (intptr_t)&_HeapBase) - tlsf_size());763 }764 765 void sys_fini(void)766 {767 tlsf_destroy(sys_tlsf);768 }769 770 void *malloc(size_t size)771 {772 void *result;773 wai_sem(SEM_MALLOC);774 result = tlsf_malloc(sys_tlsf, size);775 sig_sem(SEM_MALLOC);776 if (result == NULL)777 tlsf_check_pool(sys_pool);778 return result;779 }780 781 void *calloc(size_t size, size_t count)782 {783 void *result;784 wai_sem(SEM_MALLOC);785 result = tlsf_malloc(sys_tlsf, count * size);786 sig_sem(SEM_MALLOC);787 if (result != NULL)788 memset(result, 0, count * size);789 else790 tlsf_check_pool(sys_pool);791 return result;792 }793 794 void *realloc(void *ptr, size_t size)795 {796 void *result;797 wai_sem(SEM_MALLOC);798 result = tlsf_realloc(sys_tlsf, ptr, size);799 sig_sem(SEM_MALLOC);800 if (result == NULL)801 tlsf_check_pool(sys_pool);802 return result;803 }804 805 void free(void *ptr)806 {807 wai_sem(SEM_MALLOC);808 tlsf_free(sys_tlsf, ptr);809 sig_sem(SEM_MALLOC);810 }811 -
asp3_tinet_ecnl_rx/trunk/ntshell/src/net_misc.c
r374 r387 95 95 96 96 get_tid(&nc->tskid); 97 printf("[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);97 syslog(LOG_NOTICE, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf); 98 98 99 99 /* 初期化 */ … … 103 103 ret = get_tim(&time); 104 104 if (ret != E_OK) { 105 printf("[NET MISC,%d] get_tim error: %7lu,%s",105 syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %7lu,%s", 106 106 nc->cepid, time / SYSTIM_HZ, itron_strerror(ret)); 107 107 return; … … 117 117 error = tslp_tsk(timer); 118 118 if ((error != E_OK) && (error != E_TMOUT)) { 119 printf("[NET MISC,%d] tslp_tsk error: %s %d",119 syslog(LOG_NOTICE, "[NET MISC,%d] tslp_tsk error: %s %d", 120 120 nc->cepid, itron_strerror(error), timer); 121 121 break; … … 124 124 ret = get_tim(&time); 125 125 if (ret != E_OK) { 126 printf("[NET MISC,%d] get_tim error: %s",126 syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %s", 127 127 nc->cepid, itron_strerror(ret)); 128 128 break; -
asp3_tinet_ecnl_rx/trunk/ntshell/src/ntp_cli.c
r374 r387 277 277 } 278 278 279 printf("[NTP CLI,%d] recv time: %s .%09u\n",279 syslog(LOG_NOTICE, "[NTP CLI,%d] recv time: %s .%09u", 280 280 nc->cepid, nc->buf, tp.tv_nsec); 281 281 } … … 309 309 line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4); 310 310 if (line == NULL || !in6_is_addr_ipv4mapped(&nc->ipaddr6)) { 311 printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.",311 syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.", 312 312 nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ); 313 313 nc->timer = SLP_ITV; … … 317 317 #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */ 318 318 if ((line = lookup_ipaddr(&nc->snd_rmt.ipaddr, NTP_SRV_URL, DEFAULT_API_PROTO)) == NULL) { 319 printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.",319 syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.", 320 320 nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ); 321 321 nc->timer = SLP_ITV; … … 421 421 422 422 if ((error = udp_snd_dat(nc->cepid, &nc->snd_rmt, ntp, len, TMO_NBLK)) != E_WBLK) { 423 printf("[NTP CLI,%d] udp_snd_dat error: %s",423 syslog(LOG_NOTICE, "[NTP CLI,%d] udp_snd_dat error: %s", 424 424 nc->cepid, itron_strerror(error)); 425 425 return error; 426 426 } 427 427 else 428 syslog(LOG_DEBUG, "[NTP CLI,%d] udp_snd_dat: to: %s.%d \n",428 syslog(LOG_DEBUG, "[NTP CLI,%d] udp_snd_dat: to: %s.%d", 429 429 nc->cepid, ip2str(NULL, &nc->snd_rmt.ipaddr), nc->snd_rmt.portno); 430 430 … … 439 439 ret = get_tim(&time); 440 440 if (ret != E_OK) { 441 printf("[NTP CLI,%d] get_tim error: %s",441 syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s", 442 442 nc->cepid, itron_strerror(ret)); 443 443 tp->tv_sec = 0; … … 459 459 ret = set_tim(time); 460 460 if (ret != E_OK) { 461 printf("[NTP CLI,%d] set_tim error: %s",461 syslog(LOG_NOTICE, "[NTP CLI,%d] set_tim error: %s", 462 462 nc->cepid, itron_strerror(ret)); 463 463 } … … 477 477 if (len < 0 && len != E_RLWAI) { 478 478 /* E_RLWAI 以外で、0 以下の場合は、エラーを意味している。*/ 479 printf("[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,479 syslog(LOG_NOTICE, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid, 480 480 itron_strerror(len), in_strtfn(fncd)); 481 481 } … … 484 484 if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0) 485 485 { 486 printf("[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,486 syslog(LOG_NOTICE, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid, 487 487 itron_strerror(len)); 488 488 } … … 516 516 517 517 get_tid(&nc->tskid); 518 printf("[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);518 syslog(LOG_NOTICE, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf); 519 519 520 520 /* 初期化 */ … … 523 523 ret = get_tim(&time); 524 524 if (ret != E_OK) { 525 printf("[NTP CLI,%d] get_tim error: %7lu,%s",525 syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %7lu,%s", 526 526 nc->cepid, time / SYSTIM_HZ, itron_strerror(ret)); 527 527 return; … … 537 537 error = tslp_tsk(timer); 538 538 if ((error != E_OK) && (error != E_TMOUT)) { 539 printf("[NTP CLI,%d] tslp_tsk error: %s %d",539 syslog(LOG_NOTICE, "[NTP CLI,%d] tslp_tsk error: %s %d", 540 540 nc->cepid, itron_strerror(error), timer); 541 541 break; … … 544 544 ret = get_tim(&time); 545 545 if (ret != E_OK) { 546 printf("[NTP CLI,%d] get_tim error: %s",546 syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s", 547 547 nc->cepid, itron_strerror(ret)); 548 548 break; -
asp3_tinet_ecnl_rx/trunk/ntshell/src/ntshell_main.c
r374 r387 49 49 #include "syssvc/syslog.h" 50 50 #include "target_syssvc.h" 51 #include "target_serial.h" 51 52 #include "kernel_cfg.h" 52 53 #include "ffarch.h" … … 58 59 #include "util/ntopt.h" 59 60 #include "ntshell_main.h" 60 #include " socket_stub.h"61 #include "fdtable.h" 61 62 62 63 char command[NTOPT_TEXT_MAXLEN]; … … 78 79 } 79 80 81 void stdio_open(ID portid); 80 82 static int usrcmd_ntopt_callback(long *args, void *extobj); 81 83 … … 86 88 void ntshell_task_init(ID portid) 87 89 { 88 s erial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);90 stdio_open(portid); 89 91 } 90 92 … … 95 97 { 96 98 ntshell_state = 1; 97 ntshell_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL); 99 100 if (setjmp(process_exit) == 0) { 101 ntshell_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL); 102 } 103 104 fflush(stdout); 105 clean_fd(); 106 98 107 ntshell_state = 2; 99 108 } … … 139 148 printf("Unknown command found.\n"); 140 149 141 clean_fd();142 143 150 return result; 144 151 } … … 285 292 } 286 293 287 struct sigaction sigtable[7]; 288 289 int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) 290 { 291 struct sigaction *sat; 294 // musl-1.1.18\src\internal\ksigaction.h 295 struct k_sigaction { 296 void(*handler)(int); 297 unsigned long flags; 298 void(*restorer)(void); 299 unsigned mask[2]; 300 }; 301 302 struct k_sigaction sigtable[7]; 303 304 int shell_sigaction(int sig, const struct k_sigaction *__restrict sa, 305 struct k_sigaction *__restrict old, size_t size) 306 { 307 struct k_sigaction *sat; 292 308 293 309 switch(sig){ … … 318 334 319 335 if (old != NULL) 320 memcpy(old, sat, sizeof(struct sigaction));321 322 memcpy(sat, sa, sizeof(struct sigaction));336 memcpy(old, sat, offsetof(struct k_sigaction, mask) + size); 337 338 memcpy(sat, sa, offsetof(struct k_sigaction, mask) + size); 323 339 324 340 return 0; … … 368 384 } 369 385 386 int shell_nanosleep(const struct timespec *req, struct timespec *rem) 387 { 388 ER ret; 389 TMO tmo; 390 SYSTIM prev, now, diff; 391 392 if ((req == NULL) || (req->tv_nsec < 0) || (req->tv_nsec >= 1000000000)) 393 return -EINVAL; 394 395 get_tim(&prev); 396 397 tmo = req->tv_sec * 1000000 + req->tv_nsec / 1000; 398 ret = tslp_tsk(tmo); 399 if (ret == E_OK) { 400 if (rem != NULL) { 401 get_tim(&now); 402 diff = now - prev; 403 rem->tv_sec = diff / 1000000ll; 404 rem->tv_nsec = (diff - (rem->tv_sec * 1000000ll)) * 1000ll; 405 } 406 return 0; 407 } 408 else if (ret == E_TMOUT) { 409 if (rem != NULL) { 410 rem->tv_sec = 0; 411 rem->tv_nsec = 0; 412 } 413 return 0; 414 } 415 416 return -EFAULT; 417 } -
asp3_tinet_ecnl_rx/trunk/ntshell/src/ntshell_main.cfg
r374 r387 46 46 CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 }); 47 47 CRE_SEM(SEM_FILEDESC, { TA_TPRI, 1, 1 }); 48 CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 }); -
asp3_tinet_ecnl_rx/trunk/ntshell/src/shellif.h
r374 r387 74 74 #define NCCS 32 75 75 76 #include < bits/fcntl.h>77 #include < bits/termios.h>78 #include < bits/stat.h>76 #include <fcntl.h> 77 #include <termios.h> 78 #include <sys/stat.h> 79 79 #include <sys/select.h> 80 80 #include <time.h> … … 85 85 #include <sys/utsname.h> 86 86 #include <dirent.h> 87 #include < bits/ioctl.h>88 #include < bits/errno.h>87 #include <sys/ioctl.h> 88 #include <errno.h> 89 89 #include <sys/socket.h> 90 90 #else … … 132 132 // time.h 133 133 #define CLOCK_REALTIME 0 134 int shell_nanosleep(const struct timespec *req, struct timespec *rem); 134 135 135 136 // dirent.h … … 177 178 // signal.h 178 179 int shell_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict old); 179 int shell_sigaction(int sig, const struct sigaction *__restrict sa, struct sigaction *__restrict old); 180 struct k_sigaction; 181 int shell_sigaction(int sig, const struct k_sigaction *__restrict sa, 182 struct k_sigaction *__restrict old, size_t size); 180 183 // socket.h 181 184 int shell_socket(int, int, int); … … 197 200 // syslog.h 198 201 void vsyslog (int, const char *, va_list); 199 // termios.h200 int sio_tcgetattr (int, struct termios *);201 int sio_tcsetattr(int, int, const struct termios *);202 202 // fcntl.h 203 203 int shell_open(const char *, int, void *arg); -
asp3_tinet_ecnl_rx/trunk/ntshell/src/socket_stub.c
r374 r387 62 62 #include <netinet/tcp_var.h> 63 63 #include <netapp/resolver.h> 64 extern const ID tmax_tcp_cepid; 65 #include "ff.h" 66 #include "socket_stub.h" 64 #include "fdtable.h" 67 65 #include "kernel_cfg.h" 68 66 67 #ifdef _DEBUG 68 static const char THIS_FILE[] = __FILE__; 69 #endif 70 69 71 #define SOCKET_TIMEOUT 2000000 72 73 struct addrinfo { 74 int ai_flags; 75 int ai_family; 76 int ai_socktype; 77 int ai_protocol; 78 socklen_t ai_addrlen; 79 struct sockaddr *ai_addr; 80 char *ai_canonname; 81 struct addrinfo *ai_next; 82 }; 83 84 typedef uint16_t in_port_t; 85 typedef uint32_t in_addr_t; 86 struct in_addr { in_addr_t s_addr; }; 87 88 struct sockaddr_in { 89 sa_family_t sin_family; 90 in_port_t sin_port; 91 struct in_addr sin_addr; 92 uint8_t sin_zero[8]; 93 }; 94 95 struct in6_addr 96 { 97 union { 98 uint8_t __s6_addr[16]; 99 uint16_t __s6_addr16[8]; 100 uint32_t __s6_addr32[4]; 101 } __in6_union; 102 }; 103 //#define s6_addr __in6_union.__s6_addr 104 //#define s6_addr16 __in6_union.__s6_addr16 105 //#define s6_addr32 __in6_union.__s6_addr32 106 107 struct sockaddr_in6 108 { 109 sa_family_t sin6_family; 110 in_port_t sin6_port; 111 uint32_t sin6_flowinfo; 112 struct in6_addr sin6_addr; 113 uint32_t sin6_scope_id; 114 }; 115 116 typedef struct socket_t { 117 int family; 118 int type; 119 int protocol; 120 int cepid; 121 int repid; 122 int backlog; 123 unsigned int flags; 124 union { 125 struct sockaddr_in laddr4; 126 struct sockaddr_in6 laddr6; 127 }; 128 union { 129 struct sockaddr_in raddr4; 130 struct sockaddr_in6 raddr6; 131 }; 132 int buf_size; 133 unsigned char *buf; 134 void *input; 135 int len; 136 } socket_t; 70 137 71 138 #define tcp6_cre_cep tcp_cre_cep … … 82 149 #define tcp6_set_opt tcp_set_opt 83 150 84 #define udp6_del_cep udp_del_cep85 #define udp6_get_opt udp_get_opt86 #define udp6_set_opt udp_set_opt87 88 151 #ifndef SUPPORT_INET6 89 152 … … 93 156 94 157 ER udp6_cre_cep (ID cepid, T_UDP6_CCEP *pk_ccep) { return E_SYS; } 158 ER udp6_del_cep (ID cepid) { return E_SYS; } 95 159 ER_UINT udp6_snd_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout) { return E_SYS; } 96 160 ER_UINT udp6_rcv_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout) { return E_SYS; } 161 ER udp6_set_opt (ID cepid, int_t optname, void *optval, int_t optlen) { return E_SYS; } 162 ER udp6_get_opt (ID cepid, int_t optname, void *optval, int_t optlen) { return E_SYS; } 97 163 98 164 const T_IN6_ADDR *in6_get_ifaddr (int_t index) { return NULL; } … … 111 177 static int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg); 112 178 static bool_t tcp_fd_readable(struct SHELL_FILE *fp); 179 static bool_t tcp_fd_writable(struct SHELL_FILE *fp); 113 180 static void tcp_fd_delete(struct SHELL_FILE *fp); 114 181 … … 119 186 static int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg); 120 187 static bool_t udp_fd_readable(struct SHELL_FILE *fp); 188 static bool_t udp_fd_writable(struct SHELL_FILE *fp); 121 189 static void udp_fd_delete(struct SHELL_FILE *fp); 122 190 123 IO_TYPE IO_TYPE_TCP = { tcp_fd_close, tcp_fd_read, tcp_fd_write, tcp_fd_seek, tcp_fd_ioctl, tcp_fd_readable, tcp_fd_ delete };124 IO_TYPE IO_TYPE_UDP = { udp_fd_close, udp_fd_read, udp_fd_write, udp_fd_seek, udp_fd_ioctl, udp_fd_readable, udp_fd_ delete };191 IO_TYPE IO_TYPE_TCP = { tcp_fd_close, tcp_fd_read, tcp_fd_write, tcp_fd_seek, tcp_fd_ioctl, tcp_fd_readable, tcp_fd_writable, tcp_fd_delete }; 192 IO_TYPE IO_TYPE_UDP = { udp_fd_close, udp_fd_read, udp_fd_write, udp_fd_seek, udp_fd_ioctl, udp_fd_readable, udp_fd_writable, udp_fd_delete }; 125 193 126 194 typedef struct id_table_t { … … 185 253 186 254 #endif 255 256 void addrcpy(void *_dst, const void *_src, int len) 257 { 258 #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN 259 memcpy(_dst, _src, len); 260 #else 261 uint8_t *dst = (uint8_t *)_dst, *src = &((uint8_t *)_src)[len]; 262 while (src != _src) 263 *dst++ = *--src; 264 #endif 265 } 187 266 188 267 ID new_id(id_table_t *table, int count) … … 347 426 } 348 427 case SOCK_DGRAM: { 349 ID cepid = new_id(udp _cepid_table, udp_cepid_table_count);428 ID cepid = new_id(udp6_cepid_table, udp6_cepid_table_count); 350 429 if (cepid < 0) 351 430 return -ENOMEM; 352 431 353 T_UDP6_CCEP ccep = { 0, { ntohl(addr_in6->sin6_addr.__in6_union.__s6_addr), ntohs(addr_in6->sin6_port)}, (FP)socket_udp6_callback };432 T_UDP6_CCEP ccep = { 0, { { ntohl(addr_in6->sin6_addr.__in6_union.__s6_addr) }, ntohs(addr_in6->sin6_port)}, (FP)socket_udp6_callback }; 354 433 ret = udp6_cre_cep(cepid, &ccep); 355 434 if (ret != E_OK) { 356 delete_id(udp _cepid_table, udp_cepid_table_count, cepid);435 delete_id(udp6_cepid_table, udp6_cepid_table_count, cepid); 357 436 return -ENOMEM; 358 437 } … … 407 486 408 487 struct sockaddr_in6 *laddr = &socket->laddr6; 409 T_TCP6_CREP crep = { 0, { ntohl(laddr->sin6_addr.__in6_union.__s6_addr), ntohs(laddr->sin6_port)} };488 T_TCP6_CREP crep = { 0, { { ntohl(laddr->sin6_addr.__in6_union.__s6_addr) }, ntohs(laddr->sin6_port)} }; 410 489 ret = tcp6_cre_rep(repid, &crep); 411 490 if (ret != E_OK) { … … 423 502 } 424 503 425 int shell_connect(int fd, const struct sockaddr *addr, socklen_t len)504 int shell_connect(int fd, const struct sockaddr *addr, socklen_t alen) 426 505 { 427 506 SOCKET *fp = fd_to_fp(fd); … … 435 514 switch (socket->family) { 436 515 case AF_INET: { 437 if ( len < 8) {516 if (alen < sizeof(struct sockaddr_in)) { 438 517 return -EINVAL; 439 518 } … … 455 534 } 456 535 fp->handle = cepid; 536 fp->writable = 1; 457 537 socket->cepid = cepid; 458 538 } 459 539 struct sockaddr_in *laddr = &socket->laddr4; 460 540 struct sockaddr_in *raddr = &socket->raddr4; 461 memset(raddr, 0, sizeof(*raddr)); 462 memcpy(raddr, addr, len); 541 memcpy(raddr, addr, sizeof(struct sockaddr_in)); 463 542 T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) }; 464 543 T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) }; 465 544 ret = tcp_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT); 466 if (ret < 0) { 545 if (ret == E_TMOUT) { 546 return -ETIMEDOUT; 547 } 548 else if (ret < 0) { 467 549 return -EHOSTUNREACH; 468 550 } … … 470 552 } 471 553 case AF_INET6: { 472 if ( len < 20) {554 if (alen < sizeof(struct sockaddr_in6)) { 473 555 return -EINVAL; 474 556 } … … 490 572 } 491 573 fp->handle = cepid; 574 fp->writable = 1; 492 575 socket->cepid = cepid; 493 576 } 494 577 struct sockaddr_in6 *laddr = &socket->laddr6; 495 578 struct sockaddr_in6 *raddr = &socket->raddr6; 496 memset(raddr, 0, sizeof(*raddr)); 497 memcpy(raddr, addr, len); 498 T_IPV6EP lep = { ntohl(laddr->sin6_addr.__in6_union.__s6_addr), ntohs(laddr->sin6_port) }; 499 T_IPV6EP rep = { ntohl(raddr->sin6_addr.__in6_union.__s6_addr), ntohs(raddr->sin6_port) }; 579 memcpy(raddr, addr, sizeof(struct sockaddr_in6)); 580 T_IPV6EP lep; 581 addrcpy(&lep.ipaddr, &laddr->sin6_addr, 16); 582 lep.portno = ntohs(laddr->sin6_port); 583 T_IPV6EP rep; 584 addrcpy(&rep.ipaddr, &raddr->sin6_addr, 16); 585 rep.portno = ntohs(raddr->sin6_port); 500 586 ret = tcp6_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT); 501 if (ret < 0) { 587 if (ret == E_TMOUT) { 588 return -ETIMEDOUT; 589 } 590 else if (ret < 0) { 502 591 return -EHOSTUNREACH; 503 592 } … … 508 597 } 509 598 599 if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++; 600 510 601 return 0; 511 602 } 512 603 513 int shell_accept(int fd, struct sockaddr *__restrict addr, socklen_t *__restrict len)604 int shell_accept(int fd, struct sockaddr *__restrict addr, socklen_t *__restrict alen) 514 605 { 515 606 SOCKET *lfp = fd_to_fp(fd); … … 550 641 } 551 642 fp->handle = cepid; 643 fp->writable = 1; 552 644 socket->cepid = cepid; 553 645 } … … 555 647 cepid = ((socket_t *)lfp->exinf)->cepid; 556 648 fp->handle = cepid; 649 fp->writable = 1; 557 650 lfp->handle = tmax_tcp_cepid + ((socket_t *)lfp->exinf)->repid; 558 651 ((socket_t *)lfp->exinf)->cepid = 0; … … 566 659 } 567 660 struct sockaddr_in *raddr = &socket->raddr4; 568 memset(raddr, 0, sizeof( *raddr));661 memset(raddr, 0, sizeof(struct sockaddr_in)); 569 662 raddr->sin_family = AF_INET; 570 663 raddr->sin_port = htons(rep.portno); 571 664 raddr->sin_addr.s_addr = htonl(rep.ipaddr); 572 665 573 if (addr != NULL && len != NULL) {574 int sz = * len;575 if (sz < 8) {666 if (addr != NULL && alen != NULL) { 667 int sz = *alen; 668 if (sz < sizeof(struct sockaddr_in)) { 576 669 return -EINVAL; 577 670 } 578 671 struct sockaddr_in *raddr = &socket->raddr4; 579 if (sz > sizeof( *raddr))580 sz = sizeof( *raddr);672 if (sz > sizeof(struct sockaddr_in)) 673 sz = sizeof(struct sockaddr_in); 581 674 memcpy(addr, raddr, sz); 582 * len = sizeof(*raddr);675 *alen = sz; 583 676 } 584 677 break; … … 603 696 } 604 697 fp->handle = cepid; 698 fp->writable = 1; 605 699 socket->cepid = cepid; 606 700 } … … 608 702 cepid = ((socket_t *)lfp->exinf)->cepid; 609 703 fp->handle = cepid; 704 fp->writable = 1; 610 705 lfp->handle = tmax_tcp6_cepid + ((socket_t *)lfp->exinf)->repid; 611 706 ((socket_t *)lfp->exinf)->cepid = 0; … … 613 708 ((socket_t *)lfp->exinf)->buf = 0; 614 709 } 615 T_IPV6EP rep = { 0, 0 };710 T_IPV6EP rep = { { 0 }, 0 }; 616 711 ret = tcp6_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR); 617 712 if (ret < 0) { … … 619 714 } 620 715 struct sockaddr_in6 *raddr = &socket->raddr6; 621 memset(raddr, 0, sizeof( *raddr));716 memset(raddr, 0, sizeof(struct sockaddr_in6)); 622 717 raddr->sin6_family = AF_INET; 623 718 raddr->sin6_port = htons(rep.portno); 624 #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN 625 memcpy(raddr->sin6_addr.__in6_union.__s6_addr, rep.ipaddr.__u6_addr.__u6_addr8, 16); 626 #else 627 for (int i = 0; i < 16; i++) 628 raddr->sin6_addr.__in6_union.__s6_addr[i] = rep.ipaddr.__u6_addr.__u6_addr8[i]; 629 #endif 630 631 if (addr != NULL && len != NULL) { 632 int sz = *len; 633 if (sz < 8) { 719 addrcpy(&raddr->sin6_addr, &rep.ipaddr, 16); 720 721 if (addr != NULL && alen != NULL) { 722 int sz = *alen; 723 if (sz < sizeof(struct sockaddr_in6)) { 634 724 return -EINVAL; 635 725 } 636 726 struct sockaddr_in6 *raddr = &socket->raddr6; 637 if (sz > sizeof( *raddr))638 sz = sizeof( *raddr);727 if (sz > sizeof(struct sockaddr_in6)) 728 sz = sizeof(struct sockaddr_in6); 639 729 memcpy(addr, raddr, sz); 640 * len = sizeof(*raddr);730 *alen = sz; 641 731 } 642 732 break; … … 645 735 return -ENOPROTOOPT; 646 736 } 737 738 if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++; 647 739 648 740 return fp->fd; … … 673 765 } 674 766 else { 767 int temp = len; 675 768 for (;;) { 676 769 ret = tcp_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT); 677 770 if (ret < 0) { 678 if (ret == E_TMOUT) 679 return -ETIME; 680 return -ECOMM; 771 return (ret == E_TMOUT) ? -EAGAIN : -ECOMM; 681 772 } 682 773 len -= ret; … … 685 776 buf = (const void *)&((uint8_t *)buf)[ret]; 686 777 } 778 ret = temp; 687 779 } 688 780 break; 689 781 } 690 782 case SOCK_DGRAM: { 691 int sz = alen; 692 if ((addr == NULL) || (sz < 8)) { 783 if ((addr == NULL) || (alen < sizeof(struct sockaddr_in))) { 693 784 return -EINVAL; 694 785 } 695 786 struct sockaddr_in *raddr = &socket->raddr4; 696 memset(raddr, 0, sizeof(*raddr)); 697 memcpy(raddr, addr, sz); 787 memcpy(raddr, addr, sizeof(struct sockaddr_in)); 698 788 T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) }; 699 789 ret = udp_snd_dat(socket->cepid, &rep, (void *)buf, len, 700 790 (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT); 701 791 if (ret < 0) { 702 return (ret == E_TMOUT) ? -E TIME: -ECOMM;792 return (ret == E_TMOUT) ? -EAGAIN : -ECOMM; 703 793 } 704 794 break; … … 721 811 } 722 812 else { 813 int temp = len; 723 814 for (;;) { 724 815 ret = tcp6_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT); 725 816 if (ret < 0) { 726 if (ret == E_TMOUT) 727 return -ETIME; 728 return -ECOMM; 817 return (ret == E_TMOUT) ? -EAGAIN : -ECOMM; 729 818 } 730 819 len -= ret; … … 732 821 break; 733 822 buf = (const void *)&((uint8_t *)buf)[ret]; 734 } 823 } 824 ret = temp; 735 825 } 736 826 break; 737 827 } 738 828 case SOCK_DGRAM: { 739 int sz = alen; 740 if ((addr == NULL) || (sz < 8)) { 829 if ((addr == NULL) || (alen < sizeof(struct sockaddr_in6))) { 741 830 return -EINVAL; 742 831 } 743 832 struct sockaddr_in6 *raddr = &socket->raddr6; 744 memset(raddr, 0, sizeof(*raddr)); 745 memcpy(raddr, addr, sz); 746 T_IPV6EP rep = { ntohl(raddr->sin6_addr.__in6_union.__s6_addr), ntohs(raddr->sin6_port) }; 833 memcpy(raddr, addr, sizeof(struct sockaddr_in6)); 834 T_IPV6EP rep; 835 addrcpy(&rep.ipaddr, &raddr->sin6_addr, 16); 836 rep.portno = ntohs(raddr->sin6_port); 747 837 ret = udp6_snd_dat(socket->cepid, &rep, (void *)buf, len, 748 838 (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT); 749 839 if (ret < 0) { 750 return (ret == E_TMOUT) ? -E TIME: -ECOMM;840 return (ret == E_TMOUT) ? -EAGAIN : -ECOMM; 751 841 } 752 842 break; … … 758 848 return -ENOPROTOOPT; 759 849 } 850 851 if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++; 760 852 761 853 return ret; … … 800 892 syslog(LOG_ERROR, "sig_sem => %d", ret); 801 893 } 802 ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_FEVR); 894 ret = tcp_rcv_buf(socket->cepid, &socket->input, 895 (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT); 803 896 if (ret < 0) { 804 syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret); 805 return -ECOMM; 897 if ((socket->flags & O_NONBLOCK) == 0) 898 syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret); 899 return (ret == E_TMOUT) ? -EAGAIN : -ECOMM; 806 900 } 807 901 rsz = ret; … … 858 952 if ((socket->flags & O_NONBLOCK) == 0) 859 953 syslog(LOG_ERROR, "udp_rcv_buf => %d", ret); 860 return (ret == E_TMOUT) ? -E TIME: -ECOMM;954 return (ret == E_TMOUT) ? -EAGAIN : -ECOMM; 861 955 } 862 956 rsz = ret; … … 867 961 } 868 962 int sz = *alen; 869 memset(raddr, 0, sizeof(s ocket->raddr4));963 memset(raddr, 0, sizeof(struct sockaddr_in)); 870 964 raddr->sin_family = AF_INET; 871 965 raddr->sin_port = htons(rep.portno); 872 966 raddr->sin_addr.s_addr = htonl(rep.ipaddr); 873 if (sz > sizeof(s ocket->raddr4))874 sz = sizeof(s ocket->raddr4);967 if (sz > sizeof(struct sockaddr_in)) 968 sz = sizeof(struct sockaddr_in); 875 969 memcpy(addr, raddr, sz); 876 970 *alen = sz; … … 889 983 if ((addr != NULL) && (alen != NULL)) { 890 984 int sz = *alen; 891 if (sz > sizeof(s ocket->raddr4))892 sz = sizeof(s ocket->raddr4);985 if (sz > sizeof(struct sockaddr_in)) 986 sz = sizeof(struct sockaddr_in); 893 987 memcpy(addr, raddr, sz); 894 988 *alen = sz; … … 934 1028 syslog(LOG_ERROR, "sig_sem => %d", ret); 935 1029 } 936 ret = tcp6_rcv_buf(socket->cepid, &socket->input, TMO_FEVR); 1030 ret = tcp6_rcv_buf(socket->cepid, &socket->input, 1031 (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT); 937 1032 if (ret < 0) { 938 syslog(LOG_ERROR, "tcp6_rcv_buf => %d", ret); 939 return -ECOMM; 1033 if ((socket->flags & O_NONBLOCK) == 0) 1034 syslog(LOG_ERROR, "tcp6_rcv_buf => %d", ret); 1035 return (ret == E_TMOUT) ? -EAGAIN : -ECOMM; 940 1036 } 941 1037 rsz = ret; … … 986 1082 } 987 1083 988 T_IPV6EP rep = { 0, 0 };1084 T_IPV6EP rep = { { 0 }, 0 }; 989 1085 ret = udp6_rcv_dat(socket->cepid, &rep, buf, len, 990 1086 (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT); … … 992 1088 if ((socket->flags & O_NONBLOCK) == 0) 993 1089 syslog(LOG_ERROR, "udp6_rcv_buf => %d", ret); 994 return (ret == E_TMOUT) ? -E TIME: -ECOMM;1090 return (ret == E_TMOUT) ? -EAGAIN : -ECOMM; 995 1091 } 996 1092 rsz = ret; … … 1001 1097 } 1002 1098 int sz = *alen; 1003 memset(raddr, 0, sizeof(s ocket->raddr6));1099 memset(raddr, 0, sizeof(struct sockaddr_in6)); 1004 1100 raddr->sin6_family = AF_INET; 1005 1101 raddr->sin6_port = htons(rep.portno); 1006 #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN 1007 memcpy(raddr->sin6_addr.__in6_union.__s6_addr, rep.ipaddr.__u6_addr.__u6_addr8, 16); 1008 #else 1009 for (int i = 0; i < 16; i++) 1010 raddr->sin6_addr.__in6_union.__s6_addr[i] = rep.ipaddr.__u6_addr.__u6_addr8[i]; 1011 #endif 1012 if (sz > sizeof(socket->raddr6)) 1013 sz = sizeof(socket->raddr6); 1102 addrcpy(&raddr->sin6_addr, &rep.ipaddr, 16); 1103 if (sz > sizeof(struct sockaddr_in6)) 1104 sz = sizeof(struct sockaddr_in6); 1014 1105 memcpy(addr, raddr, sz); 1015 1106 *alen = sz; … … 1028 1119 if ((addr != NULL) && (alen != NULL)) { 1029 1120 int sz = *alen; 1030 if (sz > sizeof(s ocket->raddr6))1031 sz = sizeof(s ocket->raddr6);1121 if (sz > sizeof(struct sockaddr_in6)) 1122 sz = sizeof(struct sockaddr_in6); 1032 1123 memcpy(addr, raddr, sz); 1033 1124 *alen = sz; … … 1054 1145 return -ENOPROTOOPT; 1055 1146 } 1147 1148 if (fp->readevt_w != fp->readevt_r) fp->readevt_r++; 1056 1149 1057 1150 return ret; … … 1427 1520 struct sockaddr_in6 laddr; 1428 1521 laddr.sin6_family = AF_INET; 1429 #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN 1430 memcpy(laddr.sin6_addr.__in6_union.__s6_addr, laddr6->__u6_addr.__u6_addr8, 16); 1431 #else 1432 for (int i = 0; i < 16; i++) 1433 laddr.sin6_addr.__in6_union.__s6_addr[i] = laddr6->__u6_addr.__u6_addr8[i]; 1434 #endif 1522 addrcpy(&laddr.sin6_addr, laddr6, 16); 1435 1523 laddr.sin6_port = socket->laddr6.sin6_port; 1436 1524 *len = sizeof(struct sockaddr_in6); … … 1465 1553 delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid); 1466 1554 if ((ret < 0) || (ret2 < 0)) { 1467 return (ret == E_TMOUT) ? -ETIME : -EINVAL;1555 return (ret == E_TMOUT) ? -ETIMEDOUT : -EIO; 1468 1556 } 1469 1557 } … … 1494 1582 delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid); 1495 1583 if ((ret < 0) || (ret2 < 0)) { 1496 return (ret == E_TMOUT) ? -ETIME : -EINVAL;1584 return (ret == E_TMOUT) ? -ETIMEDOUT : -EIO; 1497 1585 } 1498 1586 } … … 1535 1623 int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg) 1536 1624 { 1625 socket_t *socket = (socket_t *)fp->exinf; 1626 1627 switch (req) { 1628 case F_GETFL: 1629 return socket->flags; 1630 case F_SETFL: 1631 socket->flags = (unsigned int)arg; 1632 return 0; 1633 } 1634 1537 1635 return -EINVAL; 1538 1636 } … … 1571 1669 } 1572 1670 1671 bool_t tcp_fd_writable(struct SHELL_FILE *fp) 1672 { 1673 //socket_t *socket = (socket_t *)fp->exinf; 1674 1675 return /*fp->writable &&*/ (fp->writeevt_w == fp->writeevt_r); 1676 } 1677 1573 1678 void tcp_fd_delete(struct SHELL_FILE *fp) 1574 1679 { … … 1590 1695 return E_PAR; 1591 1696 1697 socket_t *socket = (socket_t *)fp->exinf; 1592 1698 int fd = fp->fd; 1593 1699 FD_SET(fd, (fd_set *)&flgptn); … … 1603 1709 syslog(LOG_ERROR, "wai_sem => %d", ret); 1604 1710 } 1605 socket_t *socket = (socket_t *)fp->exinf;1606 1711 socket->len += len; 1607 1712 ret = sig_sem(SEM_FILEDESC); … … 1670 1775 return E_PAR; 1671 1776 1777 socket_t *socket = (socket_t *)fp->exinf; 1672 1778 int fd = fp->fd; 1673 1779 FD_SET(fd, (fd_set *)&flgptn); … … 1683 1789 syslog(LOG_ERROR, "wai_sem => %d", ret); 1684 1790 } 1685 socket_t *socket = (socket_t *)fp->exinf;1686 1791 socket->len += len; 1687 1792 ret = sig_sem(SEM_FILEDESC); … … 1806 1911 } 1807 1912 1913 bool_t udp_fd_writable(struct SHELL_FILE *fp) 1914 { 1915 //socket_t *socket = (socket_t *)fp->exinf; 1916 1917 return fp->writable && (fp->writeevt_w == fp->writeevt_r); 1918 } 1919 1808 1920 void udp_fd_delete(struct SHELL_FILE *fp) 1809 1921 { … … 1849 1961 socket->input = udppara->input; 1850 1962 socket->buf = GET_UDP_SDU(udppara->input, udppara->off); 1851 memset(&socket->raddr4, 0, sizeof(s ocket->raddr4));1963 memset(&socket->raddr4, 0, sizeof(struct sockaddr_in)); 1852 1964 socket->raddr4.sin_family = AF_INET; 1853 1965 socket->raddr4.sin_port = htons(udppara->rep4.portno); … … 1932 2044 socket->input = udppara->input; 1933 2045 socket->buf = GET_UDP_SDU(udppara->input, udppara->off); 1934 memset(&socket->raddr6, 0, sizeof(s ocket->raddr6));2046 memset(&socket->raddr6, 0, sizeof(struct sockaddr_in6)); 1935 2047 socket->raddr6.sin6_family = AF_INET; 1936 2048 socket->raddr6.sin6_port = htons(udppara->rep6.portno); 1937 #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN 1938 memcpy(socket->raddr6.sin6_addr.__in6_union.__s6_addr, udppara->rep6.ipaddr.__u6_addr.__u6_addr8, 16); 1939 #else 1940 for (int i = 0; i < 16; i++) 1941 socket->raddr6.sin6_addr.__in6_union.__s6_addr[i] = udppara->rep6.ipaddr.__u6_addr.__u6_addr8[i]; 1942 #endif 2049 addrcpy(&socket->raddr6.sin6_addr, &udppara->rep6.ipaddr, 16); 1943 2050 udppara->input->flags |= NB_FLG_NOREL_IFOUT; 1944 2051 ret = sig_sem(SEM_FILEDESC); -
asp3_tinet_ecnl_rx/trunk/ntshell/src/syscall.c
r374 r387 300 300 } 301 301 302 long SYS_rt_sigaction(long a, long b, long c ) {303 return shell_sigaction((int)a, (const struct sigaction *)b, (struct sigaction *)c);302 long SYS_rt_sigaction(long a, long b, long c, long d) { 303 return shell_sigaction((int)a, (const struct k_sigaction *)b, (struct k_sigaction *)c, (size_t)d); 304 304 } 305 305 … … 388 388 } 389 389 390 long SYS_nanosleep(long a, long b) 391 { 392 return shell_nanosleep((const struct timespec *)a, (struct timespec *)b); 393 } 394 390 395 long SYS_dup() 391 396 {
Note:
See TracChangeset
for help on using the changeset viewer.