1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Duo Component                                                    */
17 /**                                                                       */
18 /**   TELNET Client Protocol                                              */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_TELNET_SOURCE_CODE
24 
25 
26 /* Force error checking to be disabled in this module */
27 
28 #ifndef NX_DISABLE_ERROR_CHECKING
29 #define NX_DISABLE_ERROR_CHECKING
30 #endif
31 
32 /* Include necessary system files.  */
33 
34 #include    "nx_api.h"
35 #include    "nx_ip.h"
36 #include    "nxd_telnet_client.h"
37 
38 
39 
40 /* Bring in externs for caller checking code.  */
41 
42 NX_CALLER_CHECKING_EXTERNS
43 
44 /**************************************************************************/
45 /*                                                                        */
46 /*  FUNCTION                                               RELEASE        */
47 /*                                                                        */
48 /*    _nxde_telnet_client_connect                         PORTABLE C      */
49 /*                                                           6.1          */
50 /*  AUTHOR                                                                */
51 /*                                                                        */
52 /*    Yuxin Zhou, Microsoft Corporation                                   */
53 /*                                                                        */
54 /*  DESCRIPTION                                                           */
55 /*                                                                        */
56 /*    This function checks for errors in the TELNET client connect call.  */
57 /*                                                                        */
58 /*                                                                        */
59 /*  INPUT                                                                 */
60 /*                                                                        */
61 /*    client_ptr                            Pointer to TELNET client      */
62 /*    server_ip                             TELNET server IPv6 address    */
63 /*    server_port                           Server TCP port (usually 23)  */
64 /*    wait_option                           Specifies how long to wait    */
65 /*                                                                        */
66 /*  OUTPUT                                                                */
67 /*                                                                        */
68 /*    status                                Completion status             */
69 /*                                                                        */
70 /*  CALLS                                                                 */
71 /*                                                                        */
72 /*    _nxde_telnet_client_connect           Actual client connect call    */
73 /*                                                                        */
74 /*  CALLED BY                                                             */
75 /*                                                                        */
76 /*    Application Code                                                    */
77 /*                                                                        */
78 /*  RELEASE HISTORY                                                       */
79 /*                                                                        */
80 /*    DATE              NAME                      DESCRIPTION             */
81 /*                                                                        */
82 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
83 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
84 /*                                            resulting in version 6.1    */
85 /*                                                                        */
86 /**************************************************************************/
_nxde_telnet_client_connect(NX_TELNET_CLIENT * client_ptr,NXD_ADDRESS * server_ip_address,UINT server_port,ULONG wait_option)87 UINT  _nxde_telnet_client_connect(NX_TELNET_CLIENT *client_ptr, NXD_ADDRESS *server_ip_address,
88                                   UINT server_port, ULONG wait_option)
89 {
90 
91 UINT    status;
92 
93 
94     /* Check for invalid input pointers.  */
95     if ((client_ptr == NX_NULL) || (!server_ip_address))
96     {
97         return(NX_PTR_ERROR);
98     }
99 
100     /* Check for invalid non pointer input.  */
101     if (client_ptr -> nx_telnet_client_id != NX_TELNET_CLIENT_ID)
102     {
103         return NX_TELNET_INVALID_PARAMETER;
104     }
105 
106     /* Check for appropriate caller.  */
107     NX_THREADS_ONLY_CALLER_CHECKING
108 
109     /* Call actual client connect function.  */
110     status =  _nxd_telnet_client_connect(client_ptr, server_ip_address, server_port, wait_option);
111 
112     /* Return completion status.  */
113     return(status);
114 }
115 
116 /**************************************************************************/
117 /*                                                                        */
118 /*  FUNCTION                                               RELEASE        */
119 /*                                                                        */
120 /*    _nxd_telnet_client_connect                          PORTABLE C      */
121 /*                                                           6.1          */
122 /*  AUTHOR                                                                */
123 /*                                                                        */
124 /*    Yuxin Zhou, Microsoft Corporation                                   */
125 /*                                                                        */
126 /*  DESCRIPTION                                                           */
127 /*                                                                        */
128 /*    This function connects a previously created TELNET instance with    */
129 /*    the TCP port at the specified address.                              */
130 /*                                                                        */
131 /*                                                                        */
132 /*  INPUT                                                                 */
133 /*                                                                        */
134 /*    client_ptr                            Pointer to TELNET client      */
135 /*    server_ip_address                     TELNET server address         */
136 /*    server_port                           Server TCP port (usually 23)  */
137 /*    wait_option                           Specifies how long to wait    */
138 /*                                                                        */
139 /*  OUTPUT                                                                */
140 /*                                                                        */
141 /*    status                                Completion status             */
142 /*                                                                        */
143 /*  CALLS                                                                 */
144 /*                                                                        */
145 /*    nxd_tcp_client_socket_connect         Connect to TELNET server      */
146 /*    nx_tcp_client_socket_bind             Bind client socket to port    */
147 /*    nx_tcp_client_socket_unbind           Unbind client socket from port*/
148 /*                                                                        */
149 /*  CALLED BY                                                             */
150 /*                                                                        */
151 /*    Application Code                                                    */
152 /*                                                                        */
153 /*  RELEASE HISTORY                                                       */
154 /*                                                                        */
155 /*    DATE              NAME                      DESCRIPTION             */
156 /*                                                                        */
157 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
158 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
159 /*                                            resulting in version 6.1    */
160 /*                                                                        */
161 /**************************************************************************/
_nxd_telnet_client_connect(NX_TELNET_CLIENT * client_ptr,NXD_ADDRESS * server_ip_address,UINT server_port,ULONG wait_option)162 UINT  _nxd_telnet_client_connect(NX_TELNET_CLIENT *client_ptr, NXD_ADDRESS *server_ip_address,
163                                  UINT server_port, ULONG wait_option)
164 
165 {
166 
167 UINT        status;
168 
169 
170     /* Determine if the client is still in a not connected state.  */
171     if (client_ptr -> nx_telnet_client_socket.nx_tcp_socket_state != NX_TCP_CLOSED)
172     {
173 
174         /* Already connected, return an error.  */
175         return(NX_TELNET_NOT_DISCONNECTED);
176     }
177 
178     /* Bind the client control socket.  */
179     status =  nx_tcp_client_socket_bind(&(client_ptr -> nx_telnet_client_socket), NX_ANY_PORT, wait_option);
180 
181     /* Check for an error.  */
182     if (status != NX_SUCCESS)
183     {
184 
185         /* Unable to bind socket to port. */
186         return(status);
187     }
188 
189     /* Connect the socket to the TELNET server using the 'duo' (support IPv4 and IPv6 addresses types)
190        tcp connect service.  */
191     status =  nxd_tcp_client_socket_connect(&(client_ptr -> nx_telnet_client_socket),
192                                            server_ip_address, server_port, wait_option);
193 
194     /* Check for an error.  */
195     if (status != NX_SUCCESS)
196     {
197 
198         /* Unbind the socket.  */
199         nx_tcp_client_socket_unbind(&(client_ptr -> nx_telnet_client_socket));
200 
201         /* Unable to connect socket to server TELNET control port. */
202         return(status);
203     }
204 
205     /* Return success to caller.  */
206     return(NX_SUCCESS);
207 }
208 
209 
210 
211 /**************************************************************************/
212 /*                                                                        */
213 /*  FUNCTION                                               RELEASE        */
214 /*                                                                        */
215 /*    _nxe_telnet_client_connect                          PORTABLE C      */
216 /*                                                           6.1          */
217 /*  AUTHOR                                                                */
218 /*                                                                        */
219 /*    Yuxin Zhou, Microsoft Corporation                                   */
220 /*                                                                        */
221 /*  DESCRIPTION                                                           */
222 /*                                                                        */
223 /*    This function checks for errors in the TELNET client connect call.  */
224 /*                                                                        */
225 /*                                                                        */
226 /*  INPUT                                                                 */
227 /*                                                                        */
228 /*    client_ptr                            Pointer to TELNET client      */
229 /*    server_ip                             TELNET server IP address      */
230 /*    server_port                           Server TCP port (usually 23)  */
231 /*    wait_option                           Specifies how long to wait    */
232 /*                                                                        */
233 /*  OUTPUT                                                                */
234 /*                                                                        */
235 /*    status                                Completion status             */
236 /*                                                                        */
237 /*  CALLS                                                                 */
238 /*                                                                        */
239 /*    _nxe_telnet_client_connect            Actual client connect call    */
240 /*                                                                        */
241 /*  CALLED BY                                                             */
242 /*                                                                        */
243 /*    Application Code                                                    */
244 /*                                                                        */
245 /*  RELEASE HISTORY                                                       */
246 /*                                                                        */
247 /*    DATE              NAME                      DESCRIPTION             */
248 /*                                                                        */
249 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
250 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
251 /*                                            resulting in version 6.1    */
252 /*                                                                        */
253 /**************************************************************************/
_nxe_telnet_client_connect(NX_TELNET_CLIENT * client_ptr,ULONG server_ip,UINT server_port,ULONG wait_option)254 UINT  _nxe_telnet_client_connect(NX_TELNET_CLIENT *client_ptr, ULONG server_ip, UINT server_port, ULONG wait_option)
255 {
256 
257 #ifndef NX_DISABLE_IPV4
258 UINT    status;
259 
260 
261     /* Check for invalid input pointers.  */
262     if ((client_ptr == NX_NULL) || (client_ptr -> nx_telnet_client_id != NX_TELNET_CLIENT_ID))
263         return(NX_PTR_ERROR);
264 
265     /* Check for an invalid server IP address.  */
266     if (server_ip == 0)
267         return(NX_IP_ADDRESS_ERROR);
268 
269     /* Check for appropriate caller.  */
270     NX_THREADS_ONLY_CALLER_CHECKING
271 
272     /* Call actual client connect function.  */
273     status =  _nx_telnet_client_connect(client_ptr, server_ip, server_port, wait_option);
274 
275     /* Return completion status.  */
276     return(status);
277 #else
278     NX_PARAMETER_NOT_USED(client_ptr);
279     NX_PARAMETER_NOT_USED(server_ip);
280     NX_PARAMETER_NOT_USED(server_port);
281     NX_PARAMETER_NOT_USED(wait_option);
282 
283     return(NX_NOT_SUPPORTED);
284 #endif /* NX_DISABLE_IPV4 */
285 }
286 
287 
288 /**************************************************************************/
289 /*                                                                        */
290 /*  FUNCTION                                               RELEASE        */
291 /*                                                                        */
292 /*    _nx_telnet_client_connect                           PORTABLE C      */
293 /*                                                           6.1          */
294 /*  AUTHOR                                                                */
295 /*                                                                        */
296 /*    Yuxin Zhou, Microsoft Corporation                                   */
297 /*                                                                        */
298 /*  DESCRIPTION                                                           */
299 /*                                                                        */
300 /*    This function converts the IPv4 address to a NetX Duo NXD_ADDRESS   */
301 /*    data and forwarded to the NetX Duo Telnet connect function,         */
302 /*    nxd_telnet_client_connect to connect a previously created TELNET    */
303 /*    instance with the TCP port at the specified IPv4 address.           */
304 /*                                                                        */
305 /*    This serves primarily as a wrapper function for backward            */
306 /*    compatibility with NetX Telnet applications.                        */
307 /*                                                                        */
308 /*                                                                        */
309 /*  INPUT                                                                 */
310 /*                                                                        */
311 /*    client_ptr                            Pointer to TELNET client      */
312 /*    server_ip_address                     TELNET server IPv4 address    */
313 /*    server_port                           Server TCP port (usually 23)  */
314 /*    wait_option                           Specifies how long to wait    */
315 /*                                                                        */
316 /*  OUTPUT                                                                */
317 /*                                                                        */
318 /*    status                                Completion status             */
319 /*                                                                        */
320 /*  CALLS                                                                 */
321 /*                                                                        */
322 /*    nxd_tcp_client_socket_connect         Connect to TELNET server      */
323 /*                                                                        */
324 /*  CALLED BY                                                             */
325 /*                                                                        */
326 /*    Application Code                                                    */
327 /*                                                                        */
328 /*  RELEASE HISTORY                                                       */
329 /*                                                                        */
330 /*    DATE              NAME                      DESCRIPTION             */
331 /*                                                                        */
332 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
333 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
334 /*                                            resulting in version 6.1    */
335 /*                                                                        */
336 /**************************************************************************/
_nx_telnet_client_connect(NX_TELNET_CLIENT * client_ptr,ULONG server_ip_address,UINT server_port,ULONG wait_option)337 UINT  _nx_telnet_client_connect(NX_TELNET_CLIENT *client_ptr, ULONG server_ip_address,
338                                 UINT server_port, ULONG wait_option)
339 {
340 #ifndef NX_DISABLE_IPV4
341 NXD_ADDRESS server_ipduo_address;
342 
343     /* Construct an IP address structure, and fill in IPv4 address information. */
344     server_ipduo_address.nxd_ip_version = NX_IP_VERSION_V4;
345     server_ipduo_address.nxd_ip_address.v4 = server_ip_address;
346 
347     /* Invoke the real connection call. */
348     return (_nxd_telnet_client_connect(client_ptr, &server_ipduo_address, server_port, wait_option));
349 #else
350     NX_PARAMETER_NOT_USED(client_ptr);
351     NX_PARAMETER_NOT_USED(server_ip_address);
352     NX_PARAMETER_NOT_USED(server_port);
353     NX_PARAMETER_NOT_USED(wait_option);
354 
355     return(NX_NOT_SUPPORTED);
356 #endif /* NX_DISABLE_IPV4 */
357 }
358 
359 
360 /**************************************************************************/
361 /*                                                                        */
362 /*  FUNCTION                                               RELEASE        */
363 /*                                                                        */
364 /*    _nxe_telnet_client_create                           PORTABLE C      */
365 /*                                                           6.1          */
366 /*  AUTHOR                                                                */
367 /*                                                                        */
368 /*    Yuxin Zhou, Microsoft Corporation                                   */
369 /*                                                                        */
370 /*  DESCRIPTION                                                           */
371 /*                                                                        */
372 /*    This function checks for errors in the TELNET client create call.   */
373 /*                                                                        */
374 /*                                                                        */
375 /*  INPUT                                                                 */
376 /*                                                                        */
377 /*    client_ptr                            Pointer to TELNET client      */
378 /*    client_name                           Name of this TELNET client    */
379 /*    ip_ptr                                Pointer to IP instance        */
380 /*    window_size                           Size of TCP receive window    */
381 /*                                                                        */
382 /*  OUTPUT                                                                */
383 /*                                                                        */
384 /*    status                                Completion status             */
385 /*                                                                        */
386 /*  CALLS                                                                 */
387 /*                                                                        */
388 /*    _nx_telnet_client_create              Actual client create call     */
389 /*                                                                        */
390 /*  CALLED BY                                                             */
391 /*                                                                        */
392 /*    Application Code                                                    */
393 /*                                                                        */
394 /*  RELEASE HISTORY                                                       */
395 /*                                                                        */
396 /*    DATE              NAME                      DESCRIPTION             */
397 /*                                                                        */
398 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
399 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
400 /*                                            resulting in version 6.1    */
401 /*                                                                        */
402 /**************************************************************************/
_nxe_telnet_client_create(NX_TELNET_CLIENT * client_ptr,CHAR * client_name,NX_IP * ip_ptr,ULONG window_size)403 UINT  _nxe_telnet_client_create(NX_TELNET_CLIENT *client_ptr, CHAR *client_name, NX_IP *ip_ptr, ULONG window_size)
404 {
405 
406 UINT    status;
407 
408 
409     /* Check for invalid input pointers.  */
410     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) ||
411         (client_ptr == NX_NULL) || (client_ptr -> nx_telnet_client_id == NX_TELNET_CLIENT_ID))
412         return(NX_PTR_ERROR);
413 
414     /* Call actual client create function.  */
415     status =  _nx_telnet_client_create(client_ptr, client_name, ip_ptr, window_size);
416 
417     /* Return completion status.  */
418     return(status);
419 }
420 
421 
422 /**************************************************************************/
423 /*                                                                        */
424 /*  FUNCTION                                               RELEASE        */
425 /*                                                                        */
426 /*    _nx_telnet_client_create                            PORTABLE C      */
427 /*                                                           6.1          */
428 /*  AUTHOR                                                                */
429 /*                                                                        */
430 /*    Yuxin Zhou, Microsoft Corporation                                   */
431 /*                                                                        */
432 /*  DESCRIPTION                                                           */
433 /*                                                                        */
434 /*    This function creates an TELNET client instance.                    */
435 /*                                                                        */
436 /*                                                                        */
437 /*  INPUT                                                                 */
438 /*                                                                        */
439 /*    client_ptr                            Pointer to TELNET client      */
440 /*    client_name                           Name of this TELNET client    */
441 /*    ip_ptr                                Pointer to IP instance        */
442 /*    window_size                           Size of TCP receive window    */
443 /*                                                                        */
444 /*  OUTPUT                                                                */
445 /*                                                                        */
446 /*    status                                Completion status             */
447 /*                                                                        */
448 /*  CALLS                                                                 */
449 /*                                                                        */
450 /*    nx_tcp_socket_create                  Create TCP socket             */
451 /*                                                                        */
452 /*  CALLED BY                                                             */
453 /*                                                                        */
454 /*    Application Code                                                    */
455 /*                                                                        */
456 /*  RELEASE HISTORY                                                       */
457 /*                                                                        */
458 /*    DATE              NAME                      DESCRIPTION             */
459 /*                                                                        */
460 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
461 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
462 /*                                            resulting in version 6.1    */
463 /*                                                                        */
464 /**************************************************************************/
_nx_telnet_client_create(NX_TELNET_CLIENT * client_ptr,CHAR * client_name,NX_IP * ip_ptr,ULONG window_size)465 UINT  _nx_telnet_client_create(NX_TELNET_CLIENT *client_ptr, CHAR *client_name, NX_IP *ip_ptr, ULONG window_size)
466 {
467 
468 UINT    status;
469 
470 
471     /* Clear the client TELNET control block.  */
472     memset((void *) client_ptr, 0, sizeof(NX_TELNET_CLIENT));
473 
474     /* Create the TCP control socket.  */
475     status =  nx_tcp_socket_create(ip_ptr, &(client_ptr -> nx_telnet_client_socket), client_name,
476                                         NX_TELNET_TOS, NX_TELNET_FRAGMENT_OPTION, NX_TELNET_TIME_TO_LIVE, window_size,
477                                         NX_NULL, NX_NULL);
478 
479     /* Check for an error.  */
480     if (status)
481     {
482 
483         /* Return an error.  */
484         return(NX_TELNET_ERROR);
485     }
486 
487     /* Save off the remaining information.  */
488 
489     /* Save the client name.  */
490     client_ptr -> nx_telnet_client_name =  client_name;
491 
492     /* Save the IP pointer.  */
493     client_ptr -> nx_telnet_client_ip_ptr =  ip_ptr;
494 
495     /* Set the TELNET client id.  */
496     client_ptr -> nx_telnet_client_id =  NX_TELNET_CLIENT_ID;
497 
498     /* Return success to caller.  */
499     return(NX_SUCCESS);
500 }
501 
502 
503 
504 /**************************************************************************/
505 /*                                                                        */
506 /*  FUNCTION                                               RELEASE        */
507 /*                                                                        */
508 /*    _nxe_telnet_client_delete                           PORTABLE C      */
509 /*                                                           6.1          */
510 /*  AUTHOR                                                                */
511 /*                                                                        */
512 /*    Yuxin Zhou, Microsoft Corporation                                   */
513 /*                                                                        */
514 /*  DESCRIPTION                                                           */
515 /*                                                                        */
516 /*    This function checks for errors in the TELNET client delete call.   */
517 /*                                                                        */
518 /*                                                                        */
519 /*  INPUT                                                                 */
520 /*                                                                        */
521 /*    client_ptr                            Pointer to TELNET client      */
522 /*                                                                        */
523 /*  OUTPUT                                                                */
524 /*                                                                        */
525 /*    status                                Completion status             */
526 /*                                                                        */
527 /*  CALLS                                                                 */
528 /*                                                                        */
529 /*    _nx_telnet_client_delete              Actual client delete call     */
530 /*                                                                        */
531 /*  CALLED BY                                                             */
532 /*                                                                        */
533 /*    Application Code                                                    */
534 /*                                                                        */
535 /*  RELEASE HISTORY                                                       */
536 /*                                                                        */
537 /*    DATE              NAME                      DESCRIPTION             */
538 /*                                                                        */
539 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
540 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
541 /*                                            resulting in version 6.1    */
542 /*                                                                        */
543 /**************************************************************************/
_nxe_telnet_client_delete(NX_TELNET_CLIENT * client_ptr)544 UINT  _nxe_telnet_client_delete(NX_TELNET_CLIENT *client_ptr)
545 {
546 
547 UINT    status;
548 
549 
550     /* Check for invalid input pointers.  */
551     if ((client_ptr == NX_NULL) || (client_ptr -> nx_telnet_client_id != NX_TELNET_CLIENT_ID))
552         return(NX_PTR_ERROR);
553 
554     /* Check for appropriate caller.  */
555     NX_THREADS_ONLY_CALLER_CHECKING
556 
557     /* Call actual client delete function.  */
558     status =  _nx_telnet_client_delete(client_ptr);
559 
560     /* Return completion status.  */
561     return(status);
562 }
563 
564 
565 /**************************************************************************/
566 /*                                                                        */
567 /*  FUNCTION                                               RELEASE        */
568 /*                                                                        */
569 /*    _nx_telnet_client_delete                            PORTABLE C      */
570 /*                                                           6.2.1        */
571 /*  AUTHOR                                                                */
572 /*                                                                        */
573 /*    Yuxin Zhou, Microsoft Corporation                                   */
574 /*                                                                        */
575 /*  DESCRIPTION                                                           */
576 /*                                                                        */
577 /*    This function deletes a previously created TELNET client instance.  */
578 /*                                                                        */
579 /*                                                                        */
580 /*  INPUT                                                                 */
581 /*                                                                        */
582 /*    client_ptr                            Pointer to TELNET client      */
583 /*                                                                        */
584 /*  OUTPUT                                                                */
585 /*                                                                        */
586 /*    status                                Completion status             */
587 /*                                                                        */
588 /*  CALLS                                                                 */
589 /*                                                                        */
590 /*    nx_tcp_socket_delete                  Delete TCP socket             */
591 /*                                                                        */
592 /*  CALLED BY                                                             */
593 /*                                                                        */
594 /*    Application Code                                                    */
595 /*                                                                        */
596 /*  RELEASE HISTORY                                                       */
597 /*                                                                        */
598 /*    DATE              NAME                      DESCRIPTION             */
599 /*                                                                        */
600 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
601 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
602 /*                                            resulting in version 6.1    */
603 /*  03-08-2023     Wenhui Xie               Modified comment(s),          */
604 /*                                            cleared the client ID,      */
605 /*                                            resulting in version 6.2.1  */
606 /*                                                                        */
607 /**************************************************************************/
_nx_telnet_client_delete(NX_TELNET_CLIENT * client_ptr)608 UINT  _nx_telnet_client_delete(NX_TELNET_CLIENT *client_ptr)
609 {
610 
611     /* Determine if the client is still in an established state.  */
612     if (client_ptr -> nx_telnet_client_socket.nx_tcp_socket_state == NX_TCP_ESTABLISHED)
613     {
614 
615         /* Still connected, return an error.  */
616         return(NX_TELNET_NOT_DISCONNECTED);
617     }
618 
619     /* Clear the client ID.  */
620     client_ptr -> nx_telnet_client_id = 0;
621 
622     /* Delete the socket.  */
623     nx_tcp_socket_delete(&(client_ptr -> nx_telnet_client_socket));
624 
625     /* Return success to caller.  */
626     return(NX_SUCCESS);
627 }
628 
629 
630 /**************************************************************************/
631 /*                                                                        */
632 /*  FUNCTION                                               RELEASE        */
633 /*                                                                        */
634 /*    _nxe_telnet_client_disconnect                       PORTABLE C      */
635 /*                                                           6.1          */
636 /*  AUTHOR                                                                */
637 /*                                                                        */
638 /*    Yuxin Zhou, Microsoft Corporation                                   */
639 /*                                                                        */
640 /*  DESCRIPTION                                                           */
641 /*                                                                        */
642 /*    This function checks for errors in the TELNET client disconnect.    */
643 /*                                                                        */
644 /*                                                                        */
645 /*  INPUT                                                                 */
646 /*                                                                        */
647 /*    client_ptr                            Pointer to TELNET client      */
648 /*    wait_option                           Specifies how long to wait    */
649 /*                                                                        */
650 /*  OUTPUT                                                                */
651 /*                                                                        */
652 /*    status                                Completion status             */
653 /*                                                                        */
654 /*  CALLS                                                                 */
655 /*                                                                        */
656 /*    _nx_telnet_client_disconnect          Actual client disconnect call */
657 /*                                                                        */
658 /*  CALLED BY                                                             */
659 /*                                                                        */
660 /*    Application Code                                                    */
661 /*                                                                        */
662 /*  RELEASE HISTORY                                                       */
663 /*                                                                        */
664 /*    DATE              NAME                      DESCRIPTION             */
665 /*                                                                        */
666 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
667 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
668 /*                                            resulting in version 6.1    */
669 /*                                                                        */
670 /**************************************************************************/
_nxe_telnet_client_disconnect(NX_TELNET_CLIENT * client_ptr,ULONG wait_option)671 UINT  _nxe_telnet_client_disconnect(NX_TELNET_CLIENT *client_ptr, ULONG wait_option)
672 {
673 
674 UINT    status;
675 
676 
677     /* Check for invalid input pointers.  */
678     if ((client_ptr == NX_NULL) || (client_ptr -> nx_telnet_client_id != NX_TELNET_CLIENT_ID))
679         return(NX_PTR_ERROR);
680 
681     /* Check for appropriate caller.  */
682     NX_THREADS_ONLY_CALLER_CHECKING
683 
684     /* Call actual client disconnect function.  */
685     status =  _nx_telnet_client_disconnect(client_ptr, wait_option);
686 
687     /* Return completion status.  */
688     return(status);
689 }
690 
691 
692 /**************************************************************************/
693 /*                                                                        */
694 /*  FUNCTION                                               RELEASE        */
695 /*                                                                        */
696 /*    _nx_telnet_client_disconnect                        PORTABLE C      */
697 /*                                                           6.1          */
698 /*  AUTHOR                                                                */
699 /*                                                                        */
700 /*    Yuxin Zhou, Microsoft Corporation                                   */
701 /*                                                                        */
702 /*  DESCRIPTION                                                           */
703 /*                                                                        */
704 /*    This function disconnects a previously established TELNET           */
705 /*    connection.                                                         */
706 /*                                                                        */
707 /*                                                                        */
708 /*  INPUT                                                                 */
709 /*                                                                        */
710 /*    client_ptr                            Pointer to TELNET client      */
711 /*    wait_option                           Specifies how long to wait    */
712 /*                                                                        */
713 /*  OUTPUT                                                                */
714 /*                                                                        */
715 /*    status                                Completion status             */
716 /*                                                                        */
717 /*  CALLS                                                                 */
718 /*                                                                        */
719 /*    nx_tcp_client_socket_unbind           Unbind a socket               */
720 /*    nx_tcp_socket_disconnect              Disconnect a socket           */
721 /*                                                                        */
722 /*  CALLED BY                                                             */
723 /*                                                                        */
724 /*    Application Code                                                    */
725 /*                                                                        */
726 /*  RELEASE HISTORY                                                       */
727 /*                                                                        */
728 /*    DATE              NAME                      DESCRIPTION             */
729 /*                                                                        */
730 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
731 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
732 /*                                            resulting in version 6.1    */
733 /*                                                                        */
734 /**************************************************************************/
_nx_telnet_client_disconnect(NX_TELNET_CLIENT * client_ptr,ULONG wait_option)735 UINT  _nx_telnet_client_disconnect(NX_TELNET_CLIENT *client_ptr, ULONG wait_option)
736 {
737 
738 
739     /* Determine if the client is still in an established state.  */
740     if (client_ptr -> nx_telnet_client_socket.nx_tcp_socket_state != NX_TCP_ESTABLISHED)
741     {
742 
743         /* Not connected, return an error.  */
744         return(NX_TELNET_NOT_CONNECTED);
745     }
746 
747     /* Disconnect and unbind the socket.  */
748     nx_tcp_socket_disconnect(&(client_ptr -> nx_telnet_client_socket), wait_option);
749     nx_tcp_client_socket_unbind(&(client_ptr -> nx_telnet_client_socket));
750 
751     /* Return success to caller.  */
752     return(NX_SUCCESS);
753 }
754 
755 
756 /**************************************************************************/
757 /*                                                                        */
758 /*  FUNCTION                                               RELEASE        */
759 /*                                                                        */
760 /*    _nxe_telnet_client_packet_receive                   PORTABLE C      */
761 /*                                                           6.1          */
762 /*  AUTHOR                                                                */
763 /*                                                                        */
764 /*    Yuxin Zhou, Microsoft Corporation                                   */
765 /*                                                                        */
766 /*  DESCRIPTION                                                           */
767 /*                                                                        */
768 /*    This function checks for errors in the TELNET client packet         */
769 /*    receive call.                                                       */
770 /*                                                                        */
771 /*                                                                        */
772 /*  INPUT                                                                 */
773 /*                                                                        */
774 /*    client_ptr                            Pointer to TELNET client      */
775 /*    packet_ptr                            Destination for packet ptr    */
776 /*    wait_option                           Specifies how long to wait    */
777 /*                                                                        */
778 /*  OUTPUT                                                                */
779 /*                                                                        */
780 /*    status                                Completion status             */
781 /*                                                                        */
782 /*  CALLS                                                                 */
783 /*                                                                        */
784 /*    _nx_telnet_client_packet_receive      Actual client packet receive  */
785 /*                                            call                        */
786 /*                                                                        */
787 /*  CALLED BY                                                             */
788 /*                                                                        */
789 /*    Application Code                                                    */
790 /*                                                                        */
791 /*  RELEASE HISTORY                                                       */
792 /*                                                                        */
793 /*    DATE              NAME                      DESCRIPTION             */
794 /*                                                                        */
795 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
796 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
797 /*                                            resulting in version 6.1    */
798 /*                                                                        */
799 /**************************************************************************/
_nxe_telnet_client_packet_receive(NX_TELNET_CLIENT * client_ptr,NX_PACKET ** packet_ptr,ULONG wait_option)800 UINT  _nxe_telnet_client_packet_receive(NX_TELNET_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option)
801 {
802 
803 UINT    status;
804 
805 
806     /* Check for invalid input pointers.  */
807     if ((client_ptr == NX_NULL) || (client_ptr -> nx_telnet_client_id != NX_TELNET_CLIENT_ID) || (packet_ptr == NX_NULL))
808         return(NX_PTR_ERROR);
809 
810     /* Check for appropriate caller.  */
811     NX_THREADS_ONLY_CALLER_CHECKING
812 
813     /* Call actual client packet receive function.  */
814     status =  _nx_telnet_client_packet_receive(client_ptr, packet_ptr, wait_option);
815 
816     /* Return completion status.  */
817     return(status);
818 }
819 
820 
821 /**************************************************************************/
822 /*                                                                        */
823 /*  FUNCTION                                               RELEASE        */
824 /*                                                                        */
825 /*    _nx_telnet_client_packet_receive                    PORTABLE C      */
826 /*                                                           6.1          */
827 /*  AUTHOR                                                                */
828 /*                                                                        */
829 /*    Yuxin Zhou, Microsoft Corporation                                   */
830 /*                                                                        */
831 /*  DESCRIPTION                                                           */
832 /*                                                                        */
833 /*    This function checks for errors in the TELNET client packet         */
834 /*    receive call.                                                       */
835 /*                                                                        */
836 /*                                                                        */
837 /*  INPUT                                                                 */
838 /*                                                                        */
839 /*    client_ptr                            Pointer to TELNET client      */
840 /*    packet_ptr                            Destination for packet ptr    */
841 /*    wait_option                           Specifies how long to wait    */
842 /*                                                                        */
843 /*  OUTPUT                                                                */
844 /*                                                                        */
845 /*    status                                Completion status             */
846 /*                                                                        */
847 /*  CALLS                                                                 */
848 /*                                                                        */
849 /*    nx_tcp_socket_receive                 Receive TCP packet            */
850 /*                                                                        */
851 /*  CALLED BY                                                             */
852 /*                                                                        */
853 /*    Application Code                                                    */
854 /*                                                                        */
855 /*  RELEASE HISTORY                                                       */
856 /*                                                                        */
857 /*    DATE              NAME                      DESCRIPTION             */
858 /*                                                                        */
859 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
860 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
861 /*                                            resulting in version 6.1    */
862 /*                                                                        */
863 /**************************************************************************/
_nx_telnet_client_packet_receive(NX_TELNET_CLIENT * client_ptr,NX_PACKET ** packet_ptr,ULONG wait_option)864 UINT  _nx_telnet_client_packet_receive(NX_TELNET_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option)
865 {
866 
867 UINT    status;
868 
869     /* Attempt to receive a packet from the TCP socket.  */
870     status =  nx_tcp_socket_receive(&(client_ptr -> nx_telnet_client_socket), packet_ptr, wait_option);
871 
872     /* Return completion status.  */
873     return(status);
874 }
875 
876 
877 /**************************************************************************/
878 /*                                                                        */
879 /*  FUNCTION                                               RELEASE        */
880 /*                                                                        */
881 /*    _nxe_telnet_client_packet_send                      PORTABLE C      */
882 /*                                                           6.1          */
883 /*  AUTHOR                                                                */
884 /*                                                                        */
885 /*    Yuxin Zhou, Microsoft Corporation                                   */
886 /*                                                                        */
887 /*  DESCRIPTION                                                           */
888 /*                                                                        */
889 /*    This function checks for errors in the TELNET client packet         */
890 /*    send call.                                                          */
891 /*                                                                        */
892 /*                                                                        */
893 /*  INPUT                                                                 */
894 /*                                                                        */
895 /*    client_ptr                            Pointer to TELNET client      */
896 /*    packet_ptr                            Pointer to packet to send     */
897 /*    wait_option                           Specifies how long to wait    */
898 /*                                                                        */
899 /*  OUTPUT                                                                */
900 /*                                                                        */
901 /*    status                                Completion status             */
902 /*                                                                        */
903 /*  CALLS                                                                 */
904 /*                                                                        */
905 /*    _nx_telnet_client_packet_send         Actual client packet send     */
906 /*                                            call                        */
907 /*                                                                        */
908 /*  CALLED BY                                                             */
909 /*                                                                        */
910 /*    Application Code                                                    */
911 /*                                                                        */
912 /*  RELEASE HISTORY                                                       */
913 /*                                                                        */
914 /*    DATE              NAME                      DESCRIPTION             */
915 /*                                                                        */
916 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
917 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
918 /*                                            resulting in version 6.1    */
919 /*                                                                        */
920 /**************************************************************************/
_nxe_telnet_client_packet_send(NX_TELNET_CLIENT * client_ptr,NX_PACKET * packet_ptr,ULONG wait_option)921 UINT  _nxe_telnet_client_packet_send(NX_TELNET_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONG wait_option)
922 {
923 
924 UINT    status;
925 
926 
927     /* Check for invalid input pointers.  */
928     if ((client_ptr == NX_NULL) || (client_ptr -> nx_telnet_client_id != NX_TELNET_CLIENT_ID) || (packet_ptr == NX_NULL))
929         return(NX_PTR_ERROR);
930 
931     /* Check for appropriate caller.  */
932     NX_THREADS_ONLY_CALLER_CHECKING
933 
934     /* Call actual client packet send function.  */
935     status =  _nx_telnet_client_packet_send(client_ptr, packet_ptr, wait_option);
936 
937     /* Return completion status.  */
938     return(status);
939 }
940 
941 
942 /**************************************************************************/
943 /*                                                                        */
944 /*  FUNCTION                                               RELEASE        */
945 /*                                                                        */
946 /*    _nx_telnet_client_packet_send                       PORTABLE C      */
947 /*                                                           6.1          */
948 /*  AUTHOR                                                                */
949 /*                                                                        */
950 /*    Yuxin Zhou, Microsoft Corporation                                   */
951 /*                                                                        */
952 /*  DESCRIPTION                                                           */
953 /*                                                                        */
954 /*    This function checks for errors in the TELNET client packet         */
955 /*    send call.                                                          */
956 /*                                                                        */
957 /*                                                                        */
958 /*  INPUT                                                                 */
959 /*                                                                        */
960 /*    client_ptr                            Pointer to TELNET client      */
961 /*    packet_ptr                            Pointer to packet to send     */
962 /*    wait_option                           Specifies how long to wait    */
963 /*                                                                        */
964 /*  OUTPUT                                                                */
965 /*                                                                        */
966 /*    status                                Completion status             */
967 /*                                                                        */
968 /*  CALLS                                                                 */
969 /*                                                                        */
970 /*    nx_tcp_socket_send                    Send TCP packet               */
971 /*                                                                        */
972 /*  CALLED BY                                                             */
973 /*                                                                        */
974 /*    Application Code                                                    */
975 /*                                                                        */
976 /*  RELEASE HISTORY                                                       */
977 /*                                                                        */
978 /*    DATE              NAME                      DESCRIPTION             */
979 /*                                                                        */
980 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
981 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
982 /*                                            resulting in version 6.1    */
983 /*                                                                        */
984 /**************************************************************************/
_nx_telnet_client_packet_send(NX_TELNET_CLIENT * client_ptr,NX_PACKET * packet_ptr,ULONG wait_option)985 UINT  _nx_telnet_client_packet_send(NX_TELNET_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONG wait_option)
986 {
987 
988 UINT    status;
989 
990     /* Attempt to send a packet on the TCP socket.  */
991     status =  nx_tcp_socket_send(&(client_ptr -> nx_telnet_client_socket), packet_ptr, wait_option);
992 
993     /* Return completion status.  */
994     return(status);
995 }
996