1 | /*
|
---|
2 | * TOPPERS PROJECT Home Network Working Group Software
|
---|
3 | *
|
---|
4 | * Copyright (C) 2017-2019 Cores Co., Ltd. Japan
|
---|
5 | *
|
---|
6 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
7 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
8 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
9 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
10 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
11 | * スコード中に含まれていること.
|
---|
12 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
13 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
14 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
15 | * の無保証規定を掲載すること.
|
---|
16 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
17 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
18 | * と.
|
---|
19 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
20 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
21 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
22 | * 報告すること.
|
---|
23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
25 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
26 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
27 | * 免責すること.
|
---|
28 | *
|
---|
29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
31 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
32 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
33 | * の責任を負わない.
|
---|
34 | *
|
---|
35 | * @(#) $Id$
|
---|
36 | */
|
---|
37 | #include "shellif.h"
|
---|
38 | #include <stdint.h>
|
---|
39 | #include <kernel.h>
|
---|
40 | #include <t_syslog.h>
|
---|
41 | #include <t_stdlib.h>
|
---|
42 | #include <sil.h>
|
---|
43 | #include "syssvc/serial.h"
|
---|
44 | #include "syssvc/syslog.h"
|
---|
45 | #include "target_syssvc.h"
|
---|
46 | #include "fdtable.h"
|
---|
47 | #include "kernel_cfg.h"
|
---|
48 | #include <string.h>
|
---|
49 | #include "util/ntstdio.h"
|
---|
50 | #include "hal/serial_api.h"
|
---|
51 |
|
---|
52 | #ifdef _DEBUG
|
---|
53 | static const char THIS_FILE[] = __FILE__;
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | static int pipe_close(struct SHELL_FILE *fp);
|
---|
57 | static size_t pipe_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
|
---|
58 | static size_t pipe_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
|
---|
59 | static off_t pipe_seek(struct SHELL_FILE *fp, off_t ofs, int org);
|
---|
60 | static int pipe_ioctl(struct SHELL_FILE *fp, int req, void *arg);
|
---|
61 | static bool_t pipe_readable(struct SHELL_FILE *fp);
|
---|
62 | static bool_t pipe_writable(struct SHELL_FILE *fp);
|
---|
63 | static void pipe_delete(struct SHELL_FILE *fp);
|
---|
64 |
|
---|
65 | IO_TYPE IO_TYPE_PIPE = { pipe_close, pipe_read, pipe_write, pipe_seek, pipe_ioctl, pipe_readable, pipe_writable, pipe_delete };
|
---|
66 |
|
---|
67 | struct SHELL_PIPE {
|
---|
68 | unsigned int flags;
|
---|
69 | struct SHELL_PIPE *pair;
|
---|
70 | unsigned char buff[64];
|
---|
71 | };
|
---|
72 |
|
---|
73 | int shell_pipe(int *fds)
|
---|
74 | {
|
---|
75 | struct SHELL_FILE *fp1 = new_fp(&IO_TYPE_PIPE, 0, 0);
|
---|
76 | if (fp1 == NULL)
|
---|
77 | return -ENOMEM;
|
---|
78 | fp1->exinf = calloc(1, sizeof(struct SHELL_PIPE));
|
---|
79 |
|
---|
80 | struct SHELL_FILE *fp2 = new_fp(&IO_TYPE_PIPE, 0, 0);
|
---|
81 | if (fp2 == NULL) {
|
---|
82 | delete_fp(fp1);
|
---|
83 | return -ENOMEM;
|
---|
84 | }
|
---|
85 | fp2->exinf = calloc(1, sizeof(struct SHELL_PIPE));
|
---|
86 | ((struct SHELL_PIPE *)fp2->exinf)->pair = fp1;
|
---|
87 | ((struct SHELL_PIPE *)fp1->exinf)->pair = fp2;
|
---|
88 |
|
---|
89 | fds[0] = fp1->fd;
|
---|
90 | fds[1] = fp2->fd;
|
---|
91 |
|
---|
92 | return 0;
|
---|
93 | }
|
---|
94 |
|
---|
95 | int pipe_close(struct SHELL_FILE *fp)
|
---|
96 | {
|
---|
97 | return -ENOSYS;
|
---|
98 | }
|
---|
99 |
|
---|
100 | size_t pipe_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
|
---|
101 | {
|
---|
102 | return -ENOSYS;
|
---|
103 | }
|
---|
104 |
|
---|
105 | size_t pipe_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
|
---|
106 | {
|
---|
107 | return -ENOSYS;
|
---|
108 | }
|
---|
109 |
|
---|
110 | off_t pipe_seek(struct SHELL_FILE *fp, off_t ofs, int org)
|
---|
111 | {
|
---|
112 | return -ENOSYS;
|
---|
113 | }
|
---|
114 |
|
---|
115 | int pipe_ioctl(struct SHELL_FILE *fp, int req, void *arg)
|
---|
116 | {
|
---|
117 | switch (req) {
|
---|
118 | case F_GETFD:
|
---|
119 | *(unsigned int *)arg = ((struct SHELL_PIPE *)fp->exinf)->flags;
|
---|
120 | return 0;
|
---|
121 | case F_SETFD:
|
---|
122 | ((struct SHELL_PIPE *)fp->exinf)->flags = (unsigned int)arg;
|
---|
123 | return 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 | return -ENOSYS;
|
---|
127 | }
|
---|
128 |
|
---|
129 | bool_t pipe_readable(struct SHELL_FILE *fp)
|
---|
130 | {
|
---|
131 | return false;
|
---|
132 | }
|
---|
133 |
|
---|
134 | bool_t pipe_writable(struct SHELL_FILE *fp)
|
---|
135 | {
|
---|
136 | return false;
|
---|
137 | }
|
---|
138 |
|
---|
139 | void pipe_delete(struct SHELL_FILE *fp)
|
---|
140 | {
|
---|
141 | free((struct SHELL_PIPE *)fp->exinf);
|
---|
142 | fp->exinf = NULL;
|
---|
143 | }
|
---|