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 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  APPLICATION INTERFACE DEFINITION                       RELEASE        */
26 /*                                                                        */
27 /*    nxd_telnet_client.h                                 PORTABLE C      */
28 /*                                                           6.1.9        */
29 /*  AUTHOR                                                                */
30 /*                                                                        */
31 /*    Yuxin Zhou, Microsoft Corporation                                   */
32 /*                                                                        */
33 /*  DESCRIPTION                                                           */
34 /*                                                                        */
35 /*    This file defines the NetX Duo TELNET Protocol for Clients,         */
36 /*    including all data types and external references.                   */
37 /*    It is assumed that nx_api.h and nx_port.h have already been         */
38 /*    included.                                                           */
39 /*                                                                        */
40 /*  RELEASE HISTORY                                                       */
41 /*                                                                        */
42 /*    DATE              NAME                      DESCRIPTION             */
43 /*                                                                        */
44 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
45 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
46 /*                                            resulting in version 6.1    */
47 /*  10-15-2021     Yuxin Zhou               Modified comment(s), included */
48 /*                                            necessary header file,      */
49 /*                                            resulting in version 6.1.9  */
50 /*                                                                        */
51 /**************************************************************************/
52 
53 #ifndef NXD_TELNET_CLIENT_H
54 #define NXD_TELNET_CLIENT_H
55 
56 /* Determine if a C++ compiler is being used.  If so, ensure that standard
57    C is used to process the API information.  */
58 
59 #ifdef   __cplusplus
60 
61 /* Yes, C++ compiler is present.  Use standard C.  */
62 extern   "C" {
63 
64 #endif
65 
66 #include "nx_api.h"
67 
68 /* Define the TELNET ID.  */
69 
70 #define NX_TELNET_CLIENT_ID                        0x54454C4DUL
71 
72 
73 
74 /* Define TELNET TCP socket create options.  */
75 
76 #ifndef NX_TELNET_TOS
77 #define NX_TELNET_TOS                       NX_IP_NORMAL
78 #endif
79 
80 #ifndef NX_TELNET_FRAGMENT_OPTION
81 #define NX_TELNET_FRAGMENT_OPTION           NX_DONT_FRAGMENT
82 #endif
83 
84 
85 #ifndef NX_TELNET_TIME_TO_LIVE
86 #define NX_TELNET_TIME_TO_LIVE              0x80
87 #endif
88 
89 
90 /* Define the TELNET Server TCP port number.  */
91 #ifndef  NX_TELNET_SERVER_PORT
92 #define NX_TELNET_SERVER_PORT               23          /* Default Port for TELNET server                       */
93 #endif
94 
95 /* Define return code constants.  */
96 
97 #define NX_TELNET_ERROR                     0xF0        /* TELNET internal error                                */
98 #define NX_TELNET_TIMEOUT                   0xF1        /* TELNET timeout occurred                              */
99 #define NX_TELNET_FAILED                    0xF2        /* TELNET error                                         */
100 #define NX_TELNET_NOT_CONNECTED             0xF3        /* TELNET not connected error                           */
101 #define NX_TELNET_NOT_DISCONNECTED          0xF4        /* TELNET not disconnected error                        */
102 #define NX_TELNET_INVALID_PARAMETER         0xF5        /* Invalid non pointer input to Telnet function         */
103 
104 
105 /* Define the TELNET Client structure.  */
106 
107 typedef struct NX_TELNET_CLIENT_STRUCT
108 {
109     ULONG           nx_telnet_client_id;                               /* TELNET Client ID                      */
110     CHAR           *nx_telnet_client_name;                             /* Name of this TELNET client            */
111     NX_IP          *nx_telnet_client_ip_ptr;                           /* Pointer to associated IP structure    */
112     NX_TCP_SOCKET   nx_telnet_client_socket;                           /* Client TELNET socket                  */
113 } NX_TELNET_CLIENT;
114 
115 
116 #ifndef NX_TELNET_SOURCE_CODE
117 
118 /* Application caller is present, perform API mapping.  */
119 
120 /* Determine if error checking is desired.  If so, map API functions
121    to the appropriate error checking front-ends.  Otherwise, map API
122    functions to the core functions that actually perform the work.
123    Note: error checking is enabled by default.  */
124 
125 #ifdef NX_DISABLE_ERROR_CHECKING
126 
127 /* Services without error checking.  */
128 
129 #define nxd_telnet_client_connect                   _nxd_telnet_client_connect
130 #define nx_telnet_client_connect                    _nx_telnet_client_connect
131 #define nx_telnet_client_create                     _nx_telnet_client_create
132 #define nx_telnet_client_delete                     _nx_telnet_client_delete
133 #define nx_telnet_client_disconnect                 _nx_telnet_client_disconnect
134 #define nx_telnet_client_packet_receive             _nx_telnet_client_packet_receive
135 #define nx_telnet_client_packet_send                _nx_telnet_client_packet_send
136 
137 #else
138 
139 /* Services with error checking.  */
140 
141 #define nxd_telnet_client_connect                   _nxde_telnet_client_connect
142 #define nx_telnet_client_connect                    _nxe_telnet_client_connect
143 #define nx_telnet_client_create                     _nxe_telnet_client_create
144 #define nx_telnet_client_delete                     _nxe_telnet_client_delete
145 #define nx_telnet_client_disconnect                 _nxe_telnet_client_disconnect
146 #define nx_telnet_client_packet_receive             _nxe_telnet_client_packet_receive
147 #define nx_telnet_client_packet_send                _nxe_telnet_client_packet_send
148 #define nx_telnet_server_create                     _nxe_telnet_server_create
149 
150 #endif
151 
152 /* Define the prototypes accessible to the application software.  */
153 UINT    nxd_telnet_client_connect(NX_TELNET_CLIENT *my_client, NXD_ADDRESS *server_ip_address, UINT server_port, ULONG wait_option);
154 UINT    nx_telnet_client_connect(NX_TELNET_CLIENT *client_ptr, ULONG server_ip_address, UINT server_port, ULONG wait_option);
155 UINT    nx_telnet_client_create(NX_TELNET_CLIENT *client_ptr, CHAR *client_name, NX_IP *ip_ptr, ULONG window_size);
156 UINT    nx_telnet_client_delete(NX_TELNET_CLIENT *client_ptr);
157 UINT    nx_telnet_client_disconnect(NX_TELNET_CLIENT *client_ptr, ULONG wait_option);
158 UINT    nx_telnet_client_packet_receive(NX_TELNET_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option);
159 UINT    nx_telnet_client_packet_send(NX_TELNET_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONG wait_option);
160 
161 
162 #else
163 
164 /* TELNET source code is being compiled, do not perform any API mapping.  */
165 UINT    _nxde_telnet_client_connect(NX_TELNET_CLIENT *my_client, NXD_ADDRESS *server_ip_address, UINT server_port, ULONG wait_option);
166 UINT    _nxd_telnet_client_connect(NX_TELNET_CLIENT *my_client, NXD_ADDRESS *server_ip_address, UINT server_port, ULONG wait_option);
167 
168 UINT    _nxe_telnet_client_connect(NX_TELNET_CLIENT *client_ptr, ULONG server_ip_address, UINT server_port, ULONG wait_option);
169 UINT    _nx_telnet_client_connect(NX_TELNET_CLIENT *client_ptr, ULONG server_ip_address, UINT server_port, ULONG wait_option);
170 UINT    _nxe_telnet_client_create(NX_TELNET_CLIENT *client_ptr, CHAR *client_name, NX_IP *ip_ptr, ULONG window_size);
171 UINT    _nx_telnet_client_create(NX_TELNET_CLIENT *client_ptr, CHAR *client_name, NX_IP *ip_ptr, ULONG window_size);
172 UINT    _nxe_telnet_client_delete(NX_TELNET_CLIENT *client_ptr);
173 UINT    _nx_telnet_client_delete(NX_TELNET_CLIENT *client_ptr);
174 UINT    _nxe_telnet_client_disconnect(NX_TELNET_CLIENT *client_ptr, ULONG wait_option);
175 UINT    _nx_telnet_client_disconnect(NX_TELNET_CLIENT *client_ptr, ULONG wait_option);
176 UINT    _nxe_telnet_client_packet_receive(NX_TELNET_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option);
177 UINT    _nx_telnet_client_packet_receive(NX_TELNET_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option);
178 UINT    _nxe_telnet_client_packet_send(NX_TELNET_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONG wait_option);
179 UINT    _nx_telnet_client_packet_send(NX_TELNET_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONG wait_option);
180 
181 
182 #endif
183 
184 /* Determine if a C++ compiler is being used.  If so, complete the standard
185    C conditional started above.  */
186 #ifdef   __cplusplus
187         }
188 #endif
189 
190 #endif  /* NXD_TELNET_CLIENT_H */
191