1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: net_cons.c 317 2017-08-03 13:14:26Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * ãããã¯ã¼ã¯çµç±ã³ã³ã½ã¼ã«å
|
---|
48 | ¥åºå
|
---|
49 | */
|
---|
50 |
|
---|
51 | #include <stdarg.h>
|
---|
52 | #include <string.h>
|
---|
53 |
|
---|
54 | #ifdef TARGET_KERNEL_ASP
|
---|
55 |
|
---|
56 | #include <kernel.h>
|
---|
57 | #include <sil.h>
|
---|
58 | #include <syssvc/serial.h>
|
---|
59 | #include <syssvc/logtask.h>
|
---|
60 | #include <t_syslog.h>
|
---|
61 | #include "kernel_cfg.h"
|
---|
62 | #include "tinet_cfg.h"
|
---|
63 |
|
---|
64 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
65 |
|
---|
66 | #ifdef TARGET_KERNEL_JSP
|
---|
67 |
|
---|
68 | #include <s_services.h>
|
---|
69 | #include <t_services.h>
|
---|
70 | #include "kernel_id.h"
|
---|
71 | #include "tinet_id.h"
|
---|
72 |
|
---|
73 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
74 |
|
---|
75 | #include <netinet/in.h>
|
---|
76 | #include <netinet/in_itron.h>
|
---|
77 |
|
---|
78 | #include <netapp/netapp.h>
|
---|
79 | #include <netapp/netapp_var.h>
|
---|
80 | #include <netapp/net_cons.h>
|
---|
81 |
|
---|
82 | #ifdef USE_NET_CONS
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * ãã¯ãå®ç¾©
|
---|
86 | */
|
---|
87 |
|
---|
88 | /* ãªãã¼ã ã®è§£é¤ */
|
---|
89 |
|
---|
90 | #undef syslog
|
---|
91 | #undef serial_rea_dat
|
---|
92 | #undef serial_ctl_por
|
---|
93 |
|
---|
94 | #define EOF (-1)
|
---|
95 |
|
---|
96 | /* TELNET ãªãã·ã§ã³ */
|
---|
97 |
|
---|
98 | #define TELNET_OPT_SE (240)
|
---|
99 | #define TELNET_OPT_NOP (241)
|
---|
100 | #define TELNET_OPT_DM (242)
|
---|
101 | #define TELNET_OPT_BRK (243)
|
---|
102 | #define TELNET_OPT_IP (244)
|
---|
103 | #define TELNET_OPT_AO (245)
|
---|
104 | #define TELNET_OPT_AYT (246)
|
---|
105 | #define TELNET_OPT_EC (247)
|
---|
106 | #define TELNET_OPT_EL (248)
|
---|
107 | #define TELNET_OPT_GA (249)
|
---|
108 | #define TELNET_OPT_SB (250)
|
---|
109 | #define TELNET_OPT_WILL (251)
|
---|
110 | #define TELNET_OPT_WONT (252)
|
---|
111 | #define TELNET_OPT_DO (253)
|
---|
112 | #define TELNET_OPT_DONT (254)
|
---|
113 | #define TELNET_OPT_IAC (255)
|
---|
114 |
|
---|
115 | #if defined(SUPPORT_INET6)
|
---|
116 | #define API_PROTO '6'
|
---|
117 | #else
|
---|
118 | #define API_PROTO '4'
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | /*
|
---|
122 | * å¤æ°
|
---|
123 | */
|
---|
124 |
|
---|
125 | /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */
|
---|
126 |
|
---|
127 | uint8_t net_cons_swbuf[NET_CONS_SWBUF_SIZE];
|
---|
128 | uint8_t net_cons_rwbuf[NET_CONS_RWBUF_SIZE];
|
---|
129 |
|
---|
130 | bool_t connected = false; /* ã³ãã¯ã·ã§ã³ã®ç¶æ
|
---|
131 | */
|
---|
132 | bool_t wait_accept = false; /* æ¥ç¶è¦æ±å¾
|
---|
133 | ã¡ä¸ */
|
---|
134 |
|
---|
135 | #if defined(SUPPORT_INET6)
|
---|
136 |
|
---|
137 | T_IPV6EP dst;
|
---|
138 |
|
---|
139 | #else /* of #if defined(SUPPORT_INET6) */
|
---|
140 |
|
---|
141 | #if defined(SUPPORT_INET4)
|
---|
142 |
|
---|
143 | T_IPV4EP dst;
|
---|
144 |
|
---|
145 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
146 |
|
---|
147 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
148 |
|
---|
149 | uint8_t *snd_buff = NULL;
|
---|
150 | uint8_t *rcv_buff = NULL;
|
---|
151 | uint_t snd_off = 0;
|
---|
152 | uint_t rcv_off = 0;
|
---|
153 | uint_t net_ioctl = IOCTL_NULL;
|
---|
154 | ER_UINT snd_len = 0;
|
---|
155 | ER_UINT rcv_len = 0;
|
---|
156 |
|
---|
157 | /*
|
---|
158 | * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ°
|
---|
159 | */
|
---|
160 |
|
---|
161 | ER
|
---|
162 | callback_nblk_net_cons (ID cepid, FN fncd, void *p_parblk)
|
---|
163 | {
|
---|
164 | ER error = E_OK;
|
---|
165 | SYSTIM now;
|
---|
166 |
|
---|
167 | switch (fncd) {
|
---|
168 |
|
---|
169 | case TFN_TCP_ACP_CEP:
|
---|
170 | get_tim(&now);
|
---|
171 | if (*(ER*)p_parblk == E_OK) {
|
---|
172 | syslog(LOG_NOTICE, "[NCS%c:%02u CBN] conct: %7lu, from: %s.%u",
|
---|
173 | API_PROTO, cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
174 | connected = true;
|
---|
175 | }
|
---|
176 | else
|
---|
177 | syslog(LOG_NOTICE, "[NCS%c:%02d CBN] error: %s",
|
---|
178 | API_PROTO, itron_strerror(*(ER*)p_parblk));
|
---|
179 | snd_len = snd_off = rcv_len = rcv_off = 0;
|
---|
180 | wait_accept = false;
|
---|
181 | break;
|
---|
182 |
|
---|
183 | case TFN_TCP_CLS_CEP:
|
---|
184 | case TFN_TCP_RCV_BUF:
|
---|
185 | case TFN_TCP_GET_BUF:
|
---|
186 | case TFN_TCP_RCV_DAT:
|
---|
187 | case TFN_TCP_SND_DAT:
|
---|
188 | case TFN_TCP_CON_CEP:
|
---|
189 | case TFN_TCP_SND_OOB:
|
---|
190 | default:
|
---|
191 | error = E_PAR;
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | return error;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * éä¿¡ãããã¡ã®ãã©ãã·ã¥
|
---|
199 | */
|
---|
200 |
|
---|
201 | void
|
---|
202 | flush_snd_buff (void)
|
---|
203 | {
|
---|
204 | ER_UINT error;
|
---|
205 |
|
---|
206 | if (connected) {
|
---|
207 | syscall(wai_sem(SEM_NET_CONS_SEND));
|
---|
208 | if (snd_off > 0) {
|
---|
209 | if ((error = tcp_snd_buf(NET_CONS_CEPID, snd_off)) != E_OK && error != E_CLS)
|
---|
210 | syslog(LOG_NOTICE, "[NCS%c:%02d SND] flush send error: %s",
|
---|
211 | API_PROTO, NET_CONS_CEPID, itron_strerror(error));
|
---|
212 | snd_len = snd_off = 0;
|
---|
213 | }
|
---|
214 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
215 | }
|
---|
216 | return;
|
---|
217 | }
|
---|
218 |
|
---|
219 | /*
|
---|
220 | * æåéä¿¡
|
---|
221 | */
|
---|
222 |
|
---|
223 | void
|
---|
224 | cons_putchar (ID portid, char ch)
|
---|
225 | {
|
---|
226 | ER_UINT error;
|
---|
227 |
|
---|
228 | if (connected) {
|
---|
229 | if (ch == '\n' && (net_ioctl & IOCTL_CRLF) != 0)
|
---|
230 | cons_putchar(portid, '\r');
|
---|
231 | syscall(wai_sem(SEM_NET_CONS_SEND));
|
---|
232 | if (snd_off >= snd_len) {
|
---|
233 | if ((error = tcp_snd_buf(NET_CONS_CEPID, snd_off)) != E_OK) {
|
---|
234 | if (error != E_CLS)
|
---|
235 | syslog(LOG_NOTICE, "[NCS%c:%02d SND] send buff error: %s",
|
---|
236 | API_PROTO, NET_CONS_CEPID, itron_strerror(error));
|
---|
237 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
238 | return;
|
---|
239 | }
|
---|
240 | snd_off = 0;
|
---|
241 | if ((snd_len = tcp_get_buf(NET_CONS_CEPID, (void*)&snd_buff, TMO_FEVR)) <= 0) {
|
---|
242 | if (snd_len != E_CLS)
|
---|
243 | syslog(LOG_NOTICE, "[NCS%c:%02d SND] get buff error: %s",
|
---|
244 | API_PROTO, NET_CONS_CEPID, itron_strerror(snd_len));
|
---|
245 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
246 | return;
|
---|
247 | }
|
---|
248 | }
|
---|
249 | snd_buff[snd_off ++] = ch;
|
---|
250 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
251 | }
|
---|
252 | else
|
---|
253 | serial_wri_dat(portid, &ch, sizeof(ch));
|
---|
254 | }
|
---|
255 |
|
---|
256 | /*
|
---|
257 | * æååä¿¡ï¼å¤æãªãï¼
|
---|
258 | */
|
---|
259 |
|
---|
260 | static int_t
|
---|
261 | cons_getchar_raw (void)
|
---|
262 | {
|
---|
263 | ER error = E_OK;
|
---|
264 |
|
---|
265 | if (connected) {
|
---|
266 | if (rcv_off >= rcv_len) {
|
---|
267 | rcv_off = 0;
|
---|
268 | if ((error = tcp_rel_buf(NET_CONS_CEPID, rcv_len)) != E_OK) {
|
---|
269 | if (error != E_CLS)
|
---|
270 | syslog(LOG_NOTICE, "[NCS%c:%02d RCV] release buff error: %s",
|
---|
271 | API_PROTO, NET_CONS_CEPID, itron_strerror(error));
|
---|
272 | discon_net_cons();
|
---|
273 | return EOF;
|
---|
274 | }
|
---|
275 | if ((rcv_len = tcp_rcv_buf(NET_CONS_CEPID, (void*)&rcv_buff, TMO_FEVR)) == 0) {
|
---|
276 | discon_net_cons();
|
---|
277 | return EOF;
|
---|
278 | }
|
---|
279 | else if (rcv_len < 0) {
|
---|
280 | if (rcv_len != E_CLS)
|
---|
281 | syslog(LOG_NOTICE, "[NCS%c:%02d RCV] recieve buff error: %s",
|
---|
282 | API_PROTO, NET_CONS_CEPID, itron_strerror(rcv_len));
|
---|
283 | discon_net_cons();
|
---|
284 | return EOF;
|
---|
285 | }
|
---|
286 | }
|
---|
287 | return rcv_buff[rcv_off ++];
|
---|
288 | }
|
---|
289 | else
|
---|
290 | return EOF;
|
---|
291 | }
|
---|
292 |
|
---|
293 | /*
|
---|
294 | * æååä¿¡ï¼TELNET ãªãã·ã§ã³ãã¹ãããï¼
|
---|
295 | */
|
---|
296 |
|
---|
297 | int_t
|
---|
298 | cons_getchar (ID portid)
|
---|
299 | {
|
---|
300 | T_SERIAL_RPOR rpor;
|
---|
301 | int_t ch;
|
---|
302 | char uch;
|
---|
303 | ER error;
|
---|
304 |
|
---|
305 | if (!wait_accept && !connected) {
|
---|
306 | wait_accept = true;
|
---|
307 | error = TCP_ACP_CEP(NET_CONS_CEPID, NET_CONS_REPID, &dst, TMO_NBLK);
|
---|
308 | #if 0
|
---|
309 | syslog(LOG_NOTICE, "[NCS%c:%02d ACP] status: %s",
|
---|
310 | API_PROTO, NET_CONS_CEPID, itron_strerror(error));
|
---|
311 | #endif
|
---|
312 | if (error != E_WBLK)
|
---|
313 | return EOF;
|
---|
314 | }
|
---|
315 |
|
---|
316 | while (true) {
|
---|
317 | if (connected) {
|
---|
318 | while ((ch = cons_getchar_raw()) == TELNET_OPT_IAC || ch == '\0') {
|
---|
319 | if (ch != '\0') {
|
---|
320 | switch (ch = cons_getchar_raw()) {
|
---|
321 | case TELNET_OPT_WILL:
|
---|
322 | case TELNET_OPT_WONT:
|
---|
323 | case TELNET_OPT_DO:
|
---|
324 | case TELNET_OPT_DONT:
|
---|
325 | cons_getchar_raw();
|
---|
326 | break;
|
---|
327 | case TELNET_OPT_SB:
|
---|
328 | while ((ch = cons_getchar_raw()) != EOF && ch != TELNET_OPT_IAC) {
|
---|
329 | if ((ch = cons_getchar_raw()) == EOF || ch == TELNET_OPT_SE)
|
---|
330 | break;
|
---|
331 | }
|
---|
332 | break;
|
---|
333 | default:
|
---|
334 | break;
|
---|
335 | }
|
---|
336 | }
|
---|
337 | }
|
---|
338 | if (ch != '\n') {
|
---|
339 | if ((net_ioctl & IOCTL_ECHO) != 0 && ch != EOF) {
|
---|
340 | cons_putchar(portid, ch);
|
---|
341 | flush_snd_buff();
|
---|
342 | }
|
---|
343 | return ch;
|
---|
344 | }
|
---|
345 | }
|
---|
346 |
|
---|
347 | else if (serial_ref_por(portid, &rpor) == E_OK && rpor.reacnt > 0) {
|
---|
348 | if (serial_rea_dat(portid, &uch, sizeof(uch)) > 0)
|
---|
349 | return uch;
|
---|
350 | else
|
---|
351 | return EOF;
|
---|
352 | }
|
---|
353 | dly_tsk(100);
|
---|
354 | }
|
---|
355 | return EOF;
|
---|
356 | }
|
---|
357 |
|
---|
358 | /*
|
---|
359 | * ã³ãã¯ã·ã§ã³ãåæ
|
---|
360 | */
|
---|
361 |
|
---|
362 | ER
|
---|
363 | discon_net_cons (void)
|
---|
364 | {
|
---|
365 | ER error = E_OK;
|
---|
366 | SYSTIM now;
|
---|
367 |
|
---|
368 | if (connected) {
|
---|
369 | syscall(wai_sem(SEM_NET_CONS_SEND));
|
---|
370 | if (snd_off > 0) {
|
---|
371 | if ((error = tcp_snd_buf(NET_CONS_CEPID, snd_off)) != E_OK && error != E_CLS)
|
---|
372 | syslog(LOG_NOTICE, "[NCS%c:%02d SND] send buff error: %s",
|
---|
373 | API_PROTO, NET_CONS_CEPID, itron_strerror(error));
|
---|
374 | }
|
---|
375 | if ((error = tcp_sht_cep(NET_CONS_CEPID)) != E_OK)
|
---|
376 | syslog(LOG_NOTICE, "[NCS%c:%02d SHT] shutdown error: %s",
|
---|
377 | API_PROTO, NET_CONS_CEPID, itron_strerror(error));
|
---|
378 | if ((error = tcp_cls_cep(NET_CONS_CEPID, TMO_FEVR)) != E_OK)
|
---|
379 | syslog(LOG_NOTICE, "[NCS%c:%02d CLS] close error: %s",
|
---|
380 | API_PROTO, NET_CONS_CEPID, itron_strerror(error));
|
---|
381 | connected = false;
|
---|
382 | syscall(sig_sem(SEM_NET_CONS_SEND));
|
---|
383 | get_tim(&now);
|
---|
384 | syslog(LOG_NOTICE, "[NCS%c:%02u SND] discn: %7lu, from: %s.%u",
|
---|
385 | API_PROTO, NET_CONS_CEPID, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
386 | }
|
---|
387 | return error;
|
---|
388 | }
|
---|
389 |
|
---|
390 | /*
|
---|
391 | * ã·ãªã¢ã«ãã¼ãã®å¶å¾¡
|
---|
392 | */
|
---|
393 |
|
---|
394 | ER
|
---|
395 | net_serial_ctl_por (ID portid, uint_t ioctl)
|
---|
396 | {
|
---|
397 | net_ioctl = ioctl;
|
---|
398 | return serial_ctl_por(portid, ioctl);
|
---|
399 | }
|
---|
400 |
|
---|
401 | /*
|
---|
402 | * ãã°åºå
|
---|
403 | */
|
---|
404 |
|
---|
405 | ER
|
---|
406 | net_syslog (uint_t prio, const char *format, ...)
|
---|
407 | {
|
---|
408 | #if defined(SUPPORT_INET4)
|
---|
409 | T_IN4_ADDR *addr;
|
---|
410 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
411 |
|
---|
412 | ulong_t val;
|
---|
413 | SYSLOG log;
|
---|
414 | va_list ap;
|
---|
415 | char padchar, *str;
|
---|
416 | int_t ch, width, left, i;
|
---|
417 | bool_t longflag;
|
---|
418 |
|
---|
419 | if (connected) {
|
---|
420 | syscall(wai_sem(SEM_NET_CONS_PRINTF));
|
---|
421 | va_start(ap, format);
|
---|
422 | while ((ch = *format ++) != '\0') {
|
---|
423 | if (ch != '%') { /* æ¸å¼æå®ä»¥å¤ */
|
---|
424 | cons_putchar(CONSOLE_PORTID, (char)ch);
|
---|
425 | continue;
|
---|
426 | }
|
---|
427 |
|
---|
428 | width = 0;
|
---|
429 | longflag = false;
|
---|
430 | padchar = ' ';
|
---|
431 |
|
---|
432 | if (ch == '-') { /* 左詰ã */
|
---|
433 | format ++;
|
---|
434 | left = -1;
|
---|
435 | }
|
---|
436 | else
|
---|
437 | left = 1;
|
---|
438 |
|
---|
439 | if ((ch = *format ++) == '0') { /* ä¸ä½æ¡ã® 0 */
|
---|
440 | padchar = '0';
|
---|
441 | ch = *format ++;
|
---|
442 | }
|
---|
443 |
|
---|
444 | while ('0' <= ch && ch <= '9') { /* åºåå¹
|
---|
445 | */
|
---|
446 | width = width * 10 + ch - '0';
|
---|
447 | ch = *format ++;
|
---|
448 | }
|
---|
449 |
|
---|
450 | while (ch == 'l') { /* long (long) ã®æå® */
|
---|
451 | longflag = true;
|
---|
452 | ch = *format ++;
|
---|
453 | }
|
---|
454 |
|
---|
455 | switch (ch) {
|
---|
456 | case 'd':
|
---|
457 | val = longflag ? (ulong_t)va_arg(ap, long_t)
|
---|
458 | : (ulong_t)va_arg(ap, int_t);
|
---|
459 | if ((long_t)val >= 0)
|
---|
460 | cons_putnumber(CONSOLE_PORTID, val, 10, radhex, width * left, false, padchar);
|
---|
461 | else
|
---|
462 | cons_putnumber(CONSOLE_PORTID, -val, 10, radhex, width * left, true, padchar);
|
---|
463 | break;
|
---|
464 |
|
---|
465 | case 'u':
|
---|
466 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
467 | : (ulong_t)va_arg(ap, uint_t);
|
---|
468 | cons_putnumber(CONSOLE_PORTID, val, 10, radhex, width * left, false, padchar);
|
---|
469 | break;
|
---|
470 |
|
---|
471 | case 'x':
|
---|
472 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
473 | : (ulong_t)va_arg(ap, uint_t);
|
---|
474 | cons_putnumber(CONSOLE_PORTID, val, 16, radhex, width * left, false, padchar);
|
---|
475 | break;
|
---|
476 |
|
---|
477 | case 'X':
|
---|
478 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
479 | : (ulong_t)va_arg(ap, uint_t);
|
---|
480 | cons_putnumber(CONSOLE_PORTID, val, 16, radHEX, width * left, false, padchar);
|
---|
481 | break;
|
---|
482 |
|
---|
483 | case 'c':
|
---|
484 | ch = va_arg(ap, int_t);
|
---|
485 | cons_putchar(CONSOLE_PORTID, (char)ch);
|
---|
486 | break;
|
---|
487 |
|
---|
488 | case 's':
|
---|
489 | str = va_arg(ap, char*);
|
---|
490 | while ((ch = *str ++) != '\0') {
|
---|
491 | cons_putchar(CONSOLE_PORTID, (char)ch);
|
---|
492 | width --;
|
---|
493 | }
|
---|
494 | while (width -- > 0)
|
---|
495 | cons_putchar(CONSOLE_PORTID, ' ');
|
---|
496 | break;
|
---|
497 |
|
---|
498 | case 'I':
|
---|
499 |
|
---|
500 | #if defined(SUPPORT_INET4)
|
---|
501 |
|
---|
502 | addr = va_arg(ap, T_IN4_ADDR*);
|
---|
503 | put_ipv4addr(CONSOLE_PORTID, addr, width);
|
---|
504 |
|
---|
505 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
506 |
|
---|
507 | #if defined(SUPPORT_INET6)
|
---|
508 |
|
---|
509 | str = va_arg(ap, char*);
|
---|
510 | put_ipv6addr(CONSOLE_PORTID, (T_IN6_ADDR *)str, width);
|
---|
511 |
|
---|
512 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
513 |
|
---|
514 | break;
|
---|
515 |
|
---|
516 | case 'M':
|
---|
517 | str = va_arg(ap, char*);
|
---|
518 | put_macaddr(CONSOLE_PORTID, (uint8_t *)str, width);
|
---|
519 | break;
|
---|
520 |
|
---|
521 | case '%':
|
---|
522 | cons_putchar(CONSOLE_PORTID, '%');
|
---|
523 | break;
|
---|
524 |
|
---|
525 | case '0':
|
---|
526 | format --;
|
---|
527 | break;
|
---|
528 |
|
---|
529 | default:
|
---|
530 | break;
|
---|
531 | }
|
---|
532 |
|
---|
533 | }
|
---|
534 | va_end(ap);
|
---|
535 | cons_putchar(CONSOLE_PORTID, '\n');
|
---|
536 | flush_snd_buff();
|
---|
537 | syscall(sig_sem(SEM_NET_CONS_PRINTF));
|
---|
538 | return E_OK;
|
---|
539 | }
|
---|
540 | else {
|
---|
541 | log.logtype = LOG_TYPE_COMMENT;
|
---|
542 | log.loginfo[0] = (intptr_t)format;
|
---|
543 | i = 1;
|
---|
544 | va_start(ap, format);
|
---|
545 |
|
---|
546 | while ((ch = *format++) != '\0' && i < TMAX_LOGINFO) {
|
---|
547 | if (ch != '%') {
|
---|
548 | continue;
|
---|
549 | }
|
---|
550 |
|
---|
551 | longflag = false;
|
---|
552 |
|
---|
553 | ch = *format++;
|
---|
554 | while ('0' <= ch && ch <= '9') {
|
---|
555 | ch = *format++;
|
---|
556 | }
|
---|
557 |
|
---|
558 | while (ch == 'l') { /* long (long) ã®æå® */
|
---|
559 | longflag = true;
|
---|
560 | ch = *format ++;
|
---|
561 | }
|
---|
562 |
|
---|
563 | switch (ch) {
|
---|
564 | case 'd':
|
---|
565 | log.loginfo[i++] = longflag
|
---|
566 | ? (intptr_t)va_arg(ap, long_t)
|
---|
567 | : (intptr_t)va_arg(ap, int_t);
|
---|
568 | break;
|
---|
569 | case 'u':
|
---|
570 | case 'x':
|
---|
571 | case 'X':
|
---|
572 | log.loginfo[i++] = longflag
|
---|
573 | ? (intptr_t)va_arg(ap, ulong_t)
|
---|
574 | : (intptr_t)va_arg(ap, uint_t);
|
---|
575 | break;
|
---|
576 | case 'p':
|
---|
577 | log.loginfo[i++] = (intptr_t)va_arg(ap, void *);
|
---|
578 | break;
|
---|
579 | case 'c':
|
---|
580 | log.loginfo[i++] = (intptr_t)va_arg(ap, int_t);
|
---|
581 | break;
|
---|
582 | case 's':
|
---|
583 | log.loginfo[i++] = (intptr_t)va_arg(ap, const char *);
|
---|
584 | break;
|
---|
585 | case '\0':
|
---|
586 | format--;
|
---|
587 | break;
|
---|
588 | default:
|
---|
589 | break;
|
---|
590 | }
|
---|
591 | }
|
---|
592 | va_end(ap);
|
---|
593 |
|
---|
594 | #ifdef TARGET_KERNEL_ASP
|
---|
595 |
|
---|
596 | return(syslog_wri_log(prio, &log));
|
---|
597 |
|
---|
598 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
599 |
|
---|
600 | #ifdef TARGET_KERNEL_JSP
|
---|
601 |
|
---|
602 | return(vwri_log(prio, &log));
|
---|
603 |
|
---|
604 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
605 |
|
---|
606 | }
|
---|
607 | }
|
---|
608 |
|
---|
609 | #endif /* of #ifdef USE_NET_CONS */
|
---|