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