1 /***************************************************************************
2 * Copyright (C) 2014 by Franck Jullien *
3 * franck.jullien@gmail.com *
5 * Based on ./src/server/telnet_server.c *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 ***************************************************************************/
25 #include <server/telnet_server.h>
29 #include "jsp_server.h"
31 static char *jsp_port
;
33 /**A skim of the relevant RFCs suggests that if my application simply sent the
34 * characters IAC DONT LINEMODE (\377\376\042) as soon as the client connects,
35 * the client should be forced into character mode. However it doesn't make any difference.
38 static const char * const negotiate
=
39 "\xFF\xFB\x03" /* IAC WILL Suppress Go Ahead */
40 "\xFF\xFB\x01" /* IAC WILL Echo */
41 "\xFF\xFD\x03" /* IAC DO Suppress Go Ahead */
42 "\xFF\xFE\x01"; /* IAC DON'T Echo */
44 /* The only way we can detect that the socket is closed is the first time
45 * we write to it, we will fail. Subsequent write operations will
48 static int telnet_write(struct connection
*connection
, const void *data
, int len
)
50 struct telnet_connection
*t_con
= connection
->priv
;
52 return ERROR_SERVER_REMOTE_CLOSED
;
54 if (connection_write(connection
, data
, len
) == len
)
57 return ERROR_SERVER_REMOTE_CLOSED
;
60 int jsp_poll_read(void *priv
)
62 struct jsp_service
*jsp_service
= (struct jsp_service
*)priv
;
63 unsigned char out_buffer
[10];
64 unsigned char in_buffer
[10];
68 if (!jsp_service
->connection
)
71 memset(out_buffer
, 0, 10);
73 or1k_adv_jtag_jsp_xfer(jsp_service
->jtag_info
, &out_len
, out_buffer
, &in_len
, in_buffer
);
75 telnet_write(jsp_service
->connection
, in_buffer
, in_len
);
80 static int jsp_new_connection(struct connection
*connection
)
82 struct telnet_connection
*telnet_connection
= malloc(sizeof(struct telnet_connection
));
83 struct jsp_service
*jsp_service
= connection
->service
->priv
;
85 connection
->priv
= telnet_connection
;
87 /* initialize telnet connection information */
88 telnet_connection
->closed
= 0;
89 telnet_connection
->line_size
= 0;
90 telnet_connection
->line_cursor
= 0;
91 telnet_connection
->option_size
= 0;
92 telnet_connection
->state
= TELNET_STATE_DATA
;
94 /* negotiate telnet options */
95 telnet_write(connection
, negotiate
, strlen(negotiate
));
97 /* print connection banner */
98 if (jsp_service
->banner
) {
99 telnet_write(connection
, jsp_service
->banner
, strlen(jsp_service
->banner
));
100 telnet_write(connection
, "\r\n", 2);
103 jsp_service
->connection
= connection
;
105 int retval
= target_register_timer_callback(&jsp_poll_read
, 1, 1, jsp_service
);
106 if (ERROR_OK
!= retval
)
112 static int jsp_input(struct connection
*connection
)
115 unsigned char buffer
[TELNET_BUFFER_SIZE
];
116 unsigned char *buf_p
;
117 struct telnet_connection
*t_con
= connection
->priv
;
118 struct jsp_service
*jsp_service
= connection
->service
->priv
;
120 bytes_read
= connection_read(connection
, buffer
, TELNET_BUFFER_SIZE
);
123 return ERROR_SERVER_REMOTE_CLOSED
;
124 else if (bytes_read
== -1) {
125 LOG_ERROR("error during read: %s", strerror(errno
));
126 return ERROR_SERVER_REMOTE_CLOSED
;
131 switch (t_con
->state
) {
132 case TELNET_STATE_DATA
:
134 t_con
->state
= TELNET_STATE_IAC
;
138 unsigned char in_buffer
[10];
139 or1k_adv_jtag_jsp_xfer(jsp_service
->jtag_info
,
140 &out_len
, buf_p
, &in_len
,
143 telnet_write(connection
,
147 case TELNET_STATE_IAC
:
150 t_con
->state
= TELNET_STATE_DONT
;
153 t_con
->state
= TELNET_STATE_DO
;
156 t_con
->state
= TELNET_STATE_WONT
;
159 t_con
->state
= TELNET_STATE_WILL
;
163 case TELNET_STATE_SB
:
165 case TELNET_STATE_SE
:
167 case TELNET_STATE_WILL
:
168 case TELNET_STATE_WONT
:
169 case TELNET_STATE_DO
:
170 case TELNET_STATE_DONT
:
171 t_con
->state
= TELNET_STATE_DATA
;
174 LOG_ERROR("unknown telnet state");
185 static int jsp_connection_closed(struct connection
*connection
)
187 struct telnet_connection
*t_con
= connection
->priv
;
188 struct jsp_service
*jsp_service
= connection
->service
->priv
;
192 t_con
->prompt
= NULL
;
195 int retval
= target_unregister_timer_callback(&jsp_poll_read
, jsp_service
);
196 if (ERROR_OK
!= retval
)
199 if (connection
->priv
) {
200 free(connection
->priv
);
201 connection
->priv
= NULL
;
203 LOG_ERROR("BUG: connection->priv == NULL");
208 int jsp_init(struct or1k_jtag
*jtag_info
, char *banner
)
210 struct jsp_service
*jsp_service
= malloc(sizeof(struct jsp_service
));
211 jsp_service
->banner
= banner
;
212 jsp_service
->jtag_info
= jtag_info
;
214 return add_service("jsp",
219 jsp_connection_closed
,
223 COMMAND_HANDLER(handle_jsp_port_command
)
225 return CALL_COMMAND_HANDLER(server_pipe_command
, &jsp_port
);
228 static const struct command_registration jsp_command_handlers
[] = {
231 .handler
= handle_jsp_port_command
,
233 .help
= "Specify port on which to listen "
234 "for incoming JSP telnet connections.",
235 .usage
= "[port_num]",
237 COMMAND_REGISTRATION_DONE
240 int jsp_register_commands(struct command_context
*cmd_ctx
)
242 jsp_port
= strdup("7777");
243 return register_commands(cmd_ctx
, NULL
, jsp_command_handlers
);
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)