@nataliapc/mcp-openmsx 1.1.5 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +41 -2
  2. package/dist/openmsx.js +9 -0
  3. package/dist/server.js +502 -327
  4. package/dist/utils.js +17 -0
  5. package/package.json +4 -1
  6. package/resources/audio/toc.json +31 -0
  7. package/resources/bios/Calling_BIOS_from_MSX-DOS.md +75 -0
  8. package/resources/bios/MSX2_SUBROM_BIOS_calls.md +734 -0
  9. package/resources/bios/MSX_BIOS_calls.md +1046 -0
  10. package/resources/bios/toc.json +24 -0
  11. package/resources/book--msx2-technical-handbook/Appendix1__BIOS_Listing.md +1464 -0
  12. package/resources/book--msx2-technical-handbook/Appendix2__Math-Pack.md +427 -0
  13. package/resources/book--msx2-technical-handbook/Appendix3__Bit_Block_Transfer.md +182 -0
  14. package/resources/book--msx2-technical-handbook/Appendix4__Work_Area_Listing.md +1637 -0
  15. package/resources/book--msx2-technical-handbook/Appendix5__VRAM_Map.md +145 -0
  16. package/resources/book--msx2-technical-handbook/Appendix6__IO_Map.md +128 -0
  17. package/resources/book--msx2-technical-handbook/Appendix8_10__Control_Codes_and_Escape_Sequences.md +76 -0
  18. package/resources/book--msx2-technical-handbook/Chapter1__MSX_System_Overview.md +402 -0
  19. package/resources/book--msx2-technical-handbook/Chapter2__BASIC.md +2148 -0
  20. package/resources/book--msx2-technical-handbook/Chapter3__MSX-DOS.md +2577 -0
  21. package/resources/book--msx2-technical-handbook/Chapter4a__VDP_and_Display_Screen.md +2052 -0
  22. package/resources/book--msx2-technical-handbook/Chapter4b__VDP_and_Display_Screen.md +3311 -0
  23. package/resources/book--msx2-technical-handbook/Chapter5a__Access_to_Peripherals_through_BIOS.md +2714 -0
  24. package/resources/book--msx2-technical-handbook/Chapter5b__Access_to_Peripherals_through_BIOS.md +1263 -0
  25. package/resources/book--msx2-technical-handbook/MSX_Kun_BASIC_Compiler.md +220 -0
  26. package/resources/book--msx2-technical-handbook/toc.json +82 -0
  27. package/resources/book--the-msx-red-book/the_msx_red_book.md +10349 -0
  28. package/resources/book--the-msx-red-book/toc.json +12 -0
  29. package/resources/msx-dos/MSX-DOS_2_Function_Specifications.md +1366 -0
  30. package/resources/msx-dos/MSX-DOS_2_Program_Interface_Specification.md +963 -0
  31. package/resources/msx-dos/toc.json +18 -0
  32. package/resources/msx-unapi/Ethernet_UNAPI_specification_1.1.md +369 -0
  33. package/resources/msx-unapi/Introduction_to_MSX-UNAPI.md +132 -0
  34. package/resources/msx-unapi/MSX_UNAPI_specification_1.1.md +679 -0
  35. package/resources/msx-unapi/TCP-IP_UNAPI_specification.md +2361 -0
  36. package/resources/msx-unapi/toc.json +27 -0
  37. package/resources/others/toc.json +11 -0
  38. package/resources/processors/Z80_R800_instruction_set.md +482 -0
  39. package/resources/processors/toc.json +24 -0
  40. package/resources/processors/z80-undocumented.tex +5617 -0
  41. package/resources/processors/z80_detailed_instruction_set.md +2025 -0
  42. package/resources/programming/toc.json +121 -0
  43. package/resources/system/MSX_IO_ports_overview.md +554 -0
  44. package/resources/system/toc.json +18 -0
  45. package/resources/video/V9938_Technical_Data_Book.md +3623 -0
  46. package/resources/video/V9958_Technical_Data_Book.md +417 -0
  47. package/resources/video/V9990_Programmers_Manual_Banzai.html +1582 -0
  48. package/resources/video/VDP_TMS9918A.txt +709 -0
  49. package/resources/video/toc.json +28 -0
@@ -0,0 +1,2361 @@
1
+ # TCP/IP UNAPI specification
2
+
3
+ ## Index
4
+
5
+ [1. Introduction](#1-introduction)
6
+
7
+ [1.1. Design goals](#11-design-goals)
8
+
9
+ [1.2. Specification scope](#12-specification-scope)
10
+
11
+ [1.3. Modularity](#13-modularity)
12
+
13
+ [2. API identifier and version](#2-api-identifier-and-version)
14
+
15
+ [3. Error codes](#3-error-codes)
16
+
17
+ [4. API routines](#4-api-routines)
18
+
19
+ [4.1. Information gathering routines](#41-information-gathering-routines)
20
+
21
+ [4.1.1. UNAPI_GET_INFO: Obtain the implementation name and version](#411-unapi_get_info-obtain-the-implementation-name-and-version)
22
+
23
+ [4.1.2. TCPIP_GET_CAPAB: Get information about the TCP/IP capabilities and features](#412-tcpip_get_capab-get-information-about-the-tcpip-capabilities-and-features)
24
+
25
+ [4.1.3. TCPIP_GET_IPINFO: Get IP address](#413-tcpip_get_ipinfo-get-ip-address)
26
+
27
+ [4.1.4. TCPIP_NET_STATE: Get network state](#414-tcpip_net_state-get-network-state)
28
+
29
+ [4.2. ICMP echo request (PING) routines](#42-icmp-echo-request-ping-routines)
30
+
31
+ [4.2.1. TCPIP_SEND_ECHO: Send ICMP echo message (PING)](#421-tcpip_send_echo-send-icmp-echo-message-ping)
32
+
33
+ [4.2.2. TCPIP_RCV_ECHO: Retrieve ICMP echo response message](#422-tcpip_rcv_echo-retrieve-icmp-echo-response-message)
34
+
35
+ [4.3. Host name resolution routines](#43-host-name-resolution-routines)
36
+
37
+ [4.3.1. TCPIP_DNS_Q: Start a host name resolution query](#431-tcpip_dns_q-start-a-host-name-resolution-query)
38
+
39
+ [4.3.2. TCPIP_DNS_S: Obtains the host name resolution process state and result](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result)
40
+
41
+ [4.4. UDP protocol related routines](#44-udp-protocol-related-routines)
42
+
43
+ [4.4.1. TCPIP_UDP_OPEN: Open a UDP connection](#441-tcpip_udp_open-open-a-udp-connection)
44
+
45
+ [4.4.2. TCPIP_UDP_CLOSE: Close a UDP connection](#442-tcpip_udp_close-close-a-udp-connection)
46
+
47
+ [4.4.3. TCPIP_UDP_STATE: Get the state of a UDP connection](#443-tcpip_udp_state-get-the-state-of-a-udp-connection)
48
+
49
+ [4.4.4. TCPIP_UDP_SEND: Send an UDP datagram](#444-tcpip_udp_send-send-an-udp-datagram)
50
+
51
+ [4.4.5. TCPIP_UDP_RCV: Retrieve an incoming UDP datagram](#445-tcpip_udp_rcv-retrieve-an-incoming-udp-datagram)
52
+
53
+ [4.5. TCP protocol related routines](#45-tcp-protocol-related-routines)
54
+
55
+ [4.5.1. TCPIP_TCP_OPEN: Open a TCP connection](#451-tcpip_tcp_open-open-a-tcp-connection)
56
+
57
+ [4.5.2. TCPIP_TCP_CLOSE: Close a TCP connection](#452-tcpip_tcp_close-close-a-tcp-connection)
58
+
59
+ [4.5.3. TCPIP_TCP_ABORT: Abort a TCP connection](#453-tcpip_tcp_abort-abort-a-tcp-connection)
60
+
61
+ [4.5.4. TCPIP_TCP_STATE: Get the state of a TCP connection](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection)
62
+
63
+ [4.5.5. TCPIP_TCP_SEND: Send data a TCP connection](#455-tcpip_tcp_send-send-data-a-tcp-connection)
64
+
65
+ [4.5.6. TCPIP_TCP_RCV: Receive data from a TCP connection](#456-tcpip_tcp_rcv-receive-data-from-a-tcp-connection)
66
+
67
+ [4.5.7. TCPIP_TCP_DISCARD: Discard data in the output buffer of a TCP connection](#457-tcpip_tcp_discard-discard-data-in-the-output-buffer-of-a-tcp-connection)
68
+
69
+ [4.6. Raw IP connections related routines](#46-raw-ip-connections-related-routines)
70
+
71
+ [4.6.1. TCPIP_RAW_OPEN: Open a raw IP connection](#461-tcpip_raw_open-open-a-raw-ip-connection)
72
+
73
+ [4.6.2. TCPIP_RAW_CLOSE: Close a raw IP connection](#462-tcpip_raw_close-close-a-raw-ip-connection)
74
+
75
+ [4.6.3. TCPIP_RAW_STATE: Get the state of a raw IP connection](#463-tcpip_raw_state-get-the-state-of-a-raw-ip-connection)
76
+
77
+ [4.6.4. TCPIP_RAW_SEND: Send a raw IP datagram](#464-tcpip_raw_send-send-a-raw-ip-datagram)
78
+
79
+ [4.6.5. TCPIP_RAW_RCV: Retrieve an incoming raw IP datagram](#465-tcpip_raw_rcv-retrieve-an-incoming-raw-ip-datagram)
80
+
81
+ [4.7. Configuration related routines](#47-configuration-related-routines)
82
+
83
+ [4.7.1. TCPIP_CONFIG_AUTOIP: Enable or disable the automatic IP addresses retrieval](#471-tcpip_config_autoip-enable-or-disable-the-automatic-ip-addresses-retrieval)
84
+
85
+ [4.7.2. TCPIP_CONFIG_IP: Manually configure an IP address](#472-tcpip_config_ip-manually-configure-an-ip-address)
86
+
87
+ [4.7.3. TCPIP_CONFIG_TTL: Get/set the value of TTL and TOS for outgoing datagrams](#473-tcpip_config_ttl-getset-the-value-of-ttl-and-tos-for-outgoing-datagrams)
88
+
89
+ [4.7.4. TCPIP_CONFIG_PING: Get/set the automatic PING reply flag](#474-tcpip_config_ping-getset-the-automatic-ping-reply-flag)
90
+
91
+ [4.8. Miscellaneous routines](#48-miscellaneous-routines)
92
+
93
+ [4.8.1. TCPIP_WAIT: Wait for a processing step to run](#481-tcpip_wait-wait-for-a-processing-step-to-run)
94
+
95
+ ## 1. Introduction
96
+
97
+ MSX-UNAPI is a standard procedure for defining, discovering and using new APIs
98
+ (Application Program Interfaces) for MSX computers. The MSX-UNAPI specification is
99
+ described [in a separate document](MSX%20UNAPI%20specification%201.1.md).
100
+
101
+ This document describes an UNAPI compliant API intended for software that implements
102
+ a TCP/IP stack, that is, software that provides networking capabilities by using the IP
103
+ family of protocols. The functionality provided by this API is focused mainly on
104
+ communicating with other computers by using the TCP and UDP protocols, but there are
105
+ also some additional routines that allow for example performing domain name resolution
106
+ by querying DNS servers.
107
+
108
+ The intended client software applications for this API are networking related applications
109
+ such as Telnet, FTP or e-mail clients. Any software willing to transmit or receive data by
110
+ using the TCP or UDP protocols can make use of implementations of this specification.
111
+ This document is targeted at both developers of TCP/IP UNAPI implementations, and
112
+ developers of client applications for these implementations.
113
+
114
+ ### 1.1. Design goals
115
+
116
+ There were two main goals when designing this specification:
117
+
118
+ * _Simplicity_. This specification's intent is to provide the simplest API that will allow
119
+ to develop useful networking applications for MSX computers.
120
+
121
+ * _Modularity_. Most of the capabilities provided by this API are optional, and there
122
+ are means to get information about which capabilities are supported by a given
123
+ implementation. This allows to create from minimal to complete
124
+ implementations, as well as providing a clean way to develop an implementation
125
+ in an incremental way.
126
+
127
+ ### 1.2. Specification scope
128
+
129
+ In order to achieve the simplicity goal, this specification deals with the most basic
130
+ capabilities required in order to develop client networking applications. These capabilities
131
+ are:
132
+
133
+ * Communicating via TCP connections.
134
+ * Communicating via UDP datagrams.
135
+ * Converting domain names to IP addresses by querying DNS servers.
136
+ * Sending ICMP echo request messages (PINGs) and retrieving their answers.
137
+ * Communicating via raw IP datagrams.
138
+
139
+ Other capabilities that are usually part of TCP/IP stacks, but which are not necessary in
140
+ order to develop most client applications, are not covered by this specification. In
141
+ particular, this specification does NOT deal with:
142
+
143
+ * The link layer protocol / physical transport medium used (serial cable, modem,
144
+ Ethernet network, wireless network, joystick cable, or whatever medium is
145
+ used).
146
+ * The procedure for establishing and closing a network connection, if applicable.
147
+ * The configuration parameters of the implementation, other than basic
148
+ parameters such as the IP addresses to use and wether to set these IP
149
+ addresses manually or automatically (for example setting the user name and
150
+ password for establishing a network connection is not covered).
151
+ * Sending and receiving ICMP messages, other than echo messages (PINGs).
152
+ * Configuring routing tables.
153
+ * Converting IP addresses into hardware addresses using ARP or an equivalent
154
+ protocol, when applicable.
155
+
156
+ Note that this does not impose any restriction on implementations for actually providing
157
+ these features. For example, an implementation may deal internally with ICMP
158
+ messages; an Ethernet based implementation will most probably use ARP to convert IP
159
+ addresses to hardware addreses; and it is expected that implementations will be
160
+ delivered with the appropriate advanced configuration tools, when needed. The key
161
+ concept is that these capabilities may exist but are not covered by this specification.
162
+
163
+ ### 1.3. Modularity
164
+
165
+ In order to achieve the modularity goal, most of the capabilities defined in this
166
+ specification are optional; implementations may choose to implement the full
167
+ specification, or only a subset of it. Of course, the less capabilities are implemented by a
168
+ given implementation, the greater are the chances that a particular client application will
169
+ not work with it, especially the most basic capabilities. For example, an implementation
170
+ not providing any support for TCP connections will not be very useful; on the other hand,
171
+ an implementation that supports TCP and UDP but does not support raw IP connections
172
+ will probably still work fine with most client applications.
173
+
174
+ The modularity feature is implemented in two ways:
175
+
176
+ 1. There is a routine, [TCPIP_GET_CAPAB](#412-tcpip_get_capab-get-information-about-the-tcpip-capabilities-and-features), that returns a
177
+ "capabilities vector". This vector holds one bit for each capability that is defined
178
+ in this specification; when the bit is set it means that the capability is
179
+ implemented.
180
+ 2. All routines defined in this specification return an error code in register A. One of
181
+ these codes is "Not implemented", and is returned whenever a routine related to
182
+ an unimplemented capability is invoked (certain routines return this error or not
183
+ depending on the input parameters).
184
+
185
+ For more details on which routines can be invoked (and how) depending on the
186
+ supported capabilities, see the routines descriptions themselves.
187
+
188
+ ## 2. API identifier and version
189
+
190
+ The API identifier for the specification described in this document is: "TCP/IP" (without
191
+ the quotes). Remember that per the UNAPI specification, API identifiers are caseinsensitive.
192
+ The TCP/IP API version described in this document is 1.1. This is the API specification
193
+ version that the mandatory implementation information routine must return in DE (see
194
+ [UNAPI_GET_INFO](#411-unapi_get_info-obtain-the-implementation-name-and-version)).
195
+
196
+ ## 3. Error codes
197
+
198
+ All routines defined in this specification return an error code in register A. This section
199
+ lists all the possible error codes; the numeric value, a mnemonic and a short description
200
+ is provided for each one. Each routine description has an errors section which explains
201
+ with detail which error codes can be returned for that routine, and for which reasons is
202
+ each one returned.
203
+
204
+ | Code | Mnemonic | Description |
205
+ |----|---|---|
206
+ | 0 | ERR_OK | Operation completed successfully |
207
+ | 1 | ERR_NOT_IMP | Capability not implemented |
208
+ | 2 | ERR_NO_NETWORK | No network connection available |
209
+ | 3 | ERR_NO_DATA | No incoming data available |
210
+ | 4 | ERR_INV_PARAM | Invalid input parameter |
211
+ | 5 | ERR_QUERY_EXISTS | Another query is already in progress |
212
+ | 6 | ERR_INV_IP | Invalid IP address |
213
+ | 7 | ERR_NO_DNS | No DNS servers are configured |
214
+ | 8 | ERR_DNS | Error returned by DNS server |
215
+ | 9 | ERR_NO_FREE_CONN | No free connections available |
216
+ | 10 | ERR_CONN_EXISTS | Connection already exists |
217
+ | 11 | ERR_NO_CONN | Connection does not exists |
218
+ | 12 | ERR_CONN_STATE | Invalid connection state |
219
+ | 13 | ERR_BUFFER | Insufficient output buffer space |
220
+ | 14 | ERR_LARGE_DGRAM | Datagram is too large |
221
+ | 15 | ERR_INV_OPER | Invalid operation |
222
+
223
+ ## 4. API routines
224
+
225
+ This version of the TCP/IP API consists of 30 mandatory routines, which are described
226
+ below. API implementations may define their own additional implementation-specific
227
+ routines, as described in the MSX-UNAPI specification.
228
+
229
+ Routines are grouped in subsections by related behavior. Useful information concerning
230
+ all the routines on a given subsection is provided at the beginning of each subsection.
231
+ Some routines exchange data with the client application by using a memory buffer. Per
232
+ the UNAPI specification, implementations may not allow the destination address to be a
233
+ page 1 address (in the range 4000h-7FFFh). Client software should not use this range as
234
+ destination address when invoking these routines, in order to correctly interoperate with
235
+ such implementations.
236
+
237
+ ### 4.1. Information gathering routines
238
+
239
+ These routines allow to obtain various information about the implementation capabilities,
240
+ working parameters, and current state.
241
+
242
+ ### 4.1.1. UNAPI_GET_INFO: Obtain the implementation name and version
243
+
244
+ * Input:
245
+ * A = 0
246
+
247
+ * Output:
248
+ * A = Error code
249
+ * HL = Address of the implementation name string
250
+ * DE = API specification version supported. D=primary, E=secondary.
251
+ * BC = API implementation version. B=primary, C=secondary.
252
+
253
+ This routine is mandatory for all implementations of all UNAPI compliant APIs. It returns
254
+ basic information about the implementation itself: the implementation version, the
255
+ supported API version, and a pointer to the implementation description string.
256
+
257
+ The implementation name string must be placed in the same slot or segment of the
258
+ implementation code (or in page 3), must be zero terminated, must consist of printable
259
+ characters, and must be at most 63 characters long (not including the terminating zero).
260
+ Refer to the MSX-UNAPI specification for more details.
261
+
262
+ **ERROR CODES**
263
+
264
+ This routine never fails. ERR_OK is always returned.
265
+
266
+ ### 4.1.2. TCPIP_GET_CAPAB: Get information about the TCP/IP capabilities and features
267
+
268
+ * Input:
269
+ * A = 1
270
+ * B = Index of information block to retrieve:
271
+ * 1: Capabilities and features flags, link level protocol
272
+ * 2: Connection pool size and status
273
+ * 3: Maximum datagram size allowed
274
+ * 4: Second set of capabilities and features flags
275
+
276
+ * Output:
277
+ * A = Error code
278
+
279
+ When information block 1 requested:
280
+
281
+ * HL = Capabilities flags
282
+ * DE = Features flags
283
+ * B = Link level protocol used
284
+
285
+ When information block 2 requested:
286
+
287
+ * B = Maximum simultaneous TCP connections supported
288
+ * C = Maximum simultaneous UDP connections supported
289
+ * D = Free TCP connections currently available
290
+ * E = Free UDP connections currently available
291
+ * H = Maximum simultaneous raw IP connections supported
292
+ * L = Free raw IP connections currently available
293
+
294
+ When information block 3 requested:
295
+
296
+ * HL = Maximum incoming datagram size supported
297
+ * DE = Maximum outgoing datagram size supported
298
+
299
+ When information block 4 requested:
300
+
301
+ * HL = Second set of capabilities flags
302
+ * DE = Second set of features flags (currently unused, always zero)
303
+
304
+ As explained in ["Modularity"](#13-modularity), the TCP/IP UNAPI specification is modular, meaning that
305
+ implementators may choose to include only a certain funcionality subset in the
306
+ developed implementations. This is the routine that gives information about the
307
+ capabilities actually available in the implementation in which it is invoked. It also
308
+ provides information about other implementation working parameters that may be useful
309
+ for client applications.
310
+
311
+ The **capabilities flags** is the most important piece of information, and should be
312
+ retrieved by all client applications at startup time, before trying to actually perform any
313
+ TCP/IP related operation. It consists of a bitfield in which each bit is associated to one of
314
+ the capabilities provided by the routines described in this specification. When the bit is
315
+ one, the capability is available, and client applications can safely invoke the routines that
316
+ provide the capability. When the bit is zero, the capability is not implemented, and trying
317
+ to invoke any of the associated routines will result in the routine returning a
318
+ ERR_NOT_IMP error code. (Some routines depend on a given capability or not depending
319
+ on the input parameters; more details are given on each routine description).
320
+
321
+ The first set of capabilities flags (returned whe information block 1 is requested) is as follows.
322
+ Bit 0 is LSB of register L, bit 8 is LSB of register H.
323
+
324
+ * Bit 0: Send ICMP echo messages (PINGs) and retrieve the answers
325
+ * Bit 1: Resolve host names by querying a local hosts file or database
326
+ * Bit 2: Resolve host names by querying a DNS server
327
+ * Bit 3: Open TCP connections in active mode
328
+ * Bit 4: Open TCP connections in passive mode, with specified remote socket
329
+ * Bit 5: Open TCP connections in passive mode, with unsepecified remote socket
330
+ * Bit 6: Send and receive TCP urgent data
331
+ * Bit 7: Explicitly set the PUSH * Bit when sending TCP data
332
+ * Bit 8: Send data to a TCP connection before the ESTABLISHED state is reached
333
+ * Bit 9: Discard data in the output buffer of a TCP connection
334
+ * Bit 10: Open UDP connections
335
+ * Bit 11: Open raw IP connections
336
+ * Bit 12: Explicitly set the TTL and ToS for outgoing datagrams
337
+ * Bit 13: Explicitly set the automatic reply to PINGs on or off
338
+ * Bit 14: Automatically obtain the IP addresses, by using DHCP or an equivalent protocol (deprecated)
339
+ * Bit 15: Get the TTL and ToS for outgoing datagrams
340
+
341
+ The second set of capabilities flags (returned whe information block 4 is requested) is as follows.
342
+
343
+ * Bit 0: Automatically obtain the local IP address, subnet mask and default gateway, by using DHCP or an equivalent protocol
344
+ * Bit 1: Automatically obtain the IP addresses of the DNS servers, by using DHCP or an equivalent protocol
345
+ * Bit 2: Manually set the local IP address
346
+ * Bit 3: Manually set the peer IP address
347
+ * Bit 4: Manually set the subnet mask IP address
348
+ * Bit 5: Manually set the default gateway IP address
349
+ * Bit 6: Manually set the primary DNS server IP address
350
+ * Bit 7: Manually set the secondary DNS server IP address
351
+ * Bit 8: Use [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security) in TCP active connections
352
+ * Bit 9: Use [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security) in TCP passive connections
353
+ * Bits 10-15: Unused
354
+
355
+ Bit 14 of the primary set is deprecated and kept for compatibility with version 1.0 of the specification.
356
+ It must be set if at least one of bits 0 and 1 of the secondary set is set.
357
+
358
+ The **features flags** provide additional information about the internal working
359
+ parameters of the implementation. These parameters have no direct influence on the
360
+ specification routines (no ERR_NOT_IMP error will ever be returned as a result of one of
361
+ these features being missing), but client applications may indirectly make use of this
362
+ information to decide how to behave.
363
+
364
+ The first (and currently only) set of features flags (returned whe information block 1 is requested) is as follows.
365
+ Bit 0 is LSB of register E, bit 8 is LSB of register D.
366
+
367
+ * Bit 0: Physical link is point to point
368
+ * Bit 1: Physical link is wireless
369
+ * Bit 2: Connection pool is shared by TCP, UDP and raw IP (see explanation about maximum simultaneus connection support below)
370
+ * Bit 3: Checking network state requires sending a packet in looback mode, or other expensive (time consuming) procedure
371
+ * Bit 4: The TCP/IP handling code is assisted by external hardware
372
+ * Bit 5: The loopback address (127.x.x.x) is supported
373
+ * Bit 6: A host name resolution cache is implemented
374
+ * Bit 7: IP datagram fragmentation is supported
375
+ * Bit 8: User timeout suggested when opening a TCP connection is actually applied
376
+ * Bit 9: TTL can be specified in the parameters block of [TCPIP_SEND_ECHO](#421-tcpip_send_echo-send-icmp-echo-message-ping)
377
+ * Bit 10: [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query) is a blocking operation
378
+ * Bit 11: [TCPIP_TCP_OPEN](#451-tcpip_tcp_open-open-a-tcp-connection) is a blocking operation
379
+ * Bit 12: The server certificate can be verified when opening a TCP connection with TLS in [TCPIP_TCP_OPEN](#451-tcpip_tcp_open-open-a-tcp-connection)
380
+ * Bits 13-15: Unused
381
+
382
+ **Note for client application developers:** Bit 15 of the first set of capabilities flags,
383
+ the entire second set of capabilities flags, and bits 9-12 of the first set of features flags
384
+ were introduced in version 1.1 of the specification. They aren't presend on implementations of version 1.0.
385
+
386
+ The **link level protocol used** byte may be one of the following. Future versions of this
387
+ specification may define additional codes.
388
+
389
+ * 0: Other/Unespecified
390
+ * 1: SLIP
391
+ * 2: PPP
392
+ * 3: Ethernet
393
+ * 4: WiFi
394
+
395
+ The **connection pool size and status** block informs about how many TCP, UDP and
396
+ raw IP connections can be handled simultaneously by the implementation, as well as
397
+ how many free connections are currently available. If the TCP, UDP or raw IP protocols
398
+ are not supported at all (as indicated in the capabilities flags), then the maximum and
399
+ free connection count for that protocol should be returned as zero.
400
+
401
+ When the _"Connection pool is shared by TCP, UDP and raw IP"_ feature bit is set, it
402
+ means that there is one single group of free connections for both TCP, UDP and raw IP,
403
+ rather than one separate group for each protocol. This implies that the "maximum
404
+ simultaneuos connections" and "current free connections" values always will be the same
405
+ for all three protocols, and opening a new connection for any of the protocols will cause
406
+ all three free connection counters to decrease.
407
+
408
+ The **maximum datagram size allowed** block informs about the maximum size of IP
409
+ datagrams (including IP and higher level protocol headers, but not including any link
410
+ level header) the implementation can handle. The implementation may silently discard
411
+ any incoming datagrams larger than the maximum incoming datagram size, but client
412
+ applications may usually ignore this fact. More important is the maximum outgoing
413
+ datagram size, since client applications need to take in account this value when
414
+ performing an operation that involves directly sending datagrams (such as sending UDP
415
+ data or raw IP datagrams).
416
+
417
+ All implementations are required to support a minimum datagram size of 576 bytes, as
418
+ per the IP protocol specification.
419
+
420
+ **ERROR CODES**
421
+
422
+ * ERR_OK
423
+
424
+ The requested information block has been returned.
425
+
426
+ * ERR_INV_PAR
427
+
428
+ Invalid information block index specified.
429
+
430
+ ### 4.1.3. TCPIP_GET_IPINFO: Get IP address
431
+
432
+ * Input:
433
+ * A = 2
434
+ * B = Index of address to obtain:
435
+ * 1: Local IP address
436
+ * 2: Peer IP address
437
+ * 3: Subnet mask
438
+ * 4: Default gateway
439
+ * 5: Primary DNS server IP address
440
+ * 6: Secondary DNS server IP address
441
+
442
+ * Output:
443
+ * A = Error code
444
+ * L.H.E.D = Requested address
445
+
446
+ This routine returns one of the IP address parameters used by the implementation, as
447
+ currently configured. If an address is not configured, then it is returned as 0.0.0.0.
448
+
449
+ The addresses are returned in the format L.H.E.D. For example, 1.2.3.4 is returned as
450
+ HL=0201h, DE=0403h. This makes easier to store and retrieve addresses in memory
451
+ using simple `ld (IP),hl : ld(IP+2),de` or equivalent instructions.
452
+
453
+ **ERROR CODES**
454
+
455
+ * ERR_OK
456
+
457
+ The requested IP address has been returned.
458
+
459
+ * ERR_INV_PAR
460
+
461
+ An invalid value for B has been specified at input, or the specified address type does not
462
+ make sense for the implementation (for example the subnet mask or the default
463
+ gateway when the link layer protocol is PPP, or the peer address on an Ethernet
464
+ network).
465
+
466
+ ### 4.1.4. TCPIP_NET_STATE: Get network state
467
+
468
+ * Input:
469
+ * A = 3
470
+
471
+ * Output:
472
+ * A = Error code
473
+ * B = Current network state:
474
+ * 0: Closed
475
+ * 1: Opening
476
+ * 2: Open
477
+ * 3: Closing
478
+ * 255: Unknown
479
+
480
+ This routine returns the current state of the network availability. It is only possible to
481
+ send and receive data when the network state is "Open"; it may or may not be possible
482
+ as well when the returned state is "Unknown".
483
+
484
+ The "Closed" state may refer to a logical close (for example, no connection has been
485
+ established in case of serial communications using the PPP protocol) or to a physical
486
+ medium unavailability (for example, no cable is connected in case of an Ethernet
487
+ network).
488
+
489
+ The "Opening" state means that the implementation is actively trying to reach the
490
+ "Open" state, but the actions that are actually performed for this depend on each
491
+ implementation. For example, it may mean "connecting to the ISP" in case of modem
492
+ communications, or "obtaining addresses via DHCP" in case of an Ethernet network.
493
+
494
+ There are no restrictions on the possible transitions from any of these states to any
495
+ other. For example, an implementation could pass from "Opening" to "Closed" again if an
496
+ error is detected during the opening process. Or, it could toggle between "Open" and
497
+ "Closed" directly if no special setup or shutdown process is required.
498
+
499
+ Implementations should return the "Checking network state requires an expensive
500
+ procedure" feature flag set if calling this routine implies performing a time consuming
501
+ procedure (such as sending a loopback packet), in order to inform client that it should
502
+ not be called too often.
503
+
504
+ **ERROR CODES**
505
+
506
+ This routine never fails. ERR_OK is always returned.
507
+
508
+ ### 4.2. ICMP echo request (PING) routines
509
+
510
+ These routines allow to send ICMP echo request messages (known as PINGs) and to
511
+ retrieve the received responses.
512
+
513
+ ### 4.2.1. TCPIP_SEND_ECHO: Send ICMP echo message (PING)
514
+
515
+ * Input:
516
+ * A = 4
517
+ * HL = Address of echo parameters block
518
+
519
+ * Output:
520
+ * A = Error code
521
+
522
+ This routine sends an ICMP echo request (a PING) with the specified parameters. A
523
+ parameters block with the following format must be supplied:
524
+
525
+ * +0 (4): IP address of the destination machine
526
+ * +4 (1): TTL for the datagram
527
+ * +5 (2): ICMP identifier
528
+ * +7 (2): ICMP sequence number
529
+ * +9 (2): Data length, 0 to maximum datagram size - 28
530
+
531
+ The datagram will be send with the value specified if the _"TTL can be specified in the parameters block of
532
+ TCPIP_SEND_ECHO"_ feature flag is set. If it isn't, the implementation will choose by itself the value to use.
533
+
534
+ It is possible to choose the size of the data area of the ICMP message, but not its
535
+ contents; these must be always the byte sequence 0 1 2 ... 253 254 255 0 1 2...
536
+ appropriately truncated to match the specified size.
537
+
538
+ The identifier and the data number can help on matching requests and replies (an echo
539
+ reply will always have these values identical to the ones of its associated echo request),
540
+ they can be any 16 bit number. The TTL value should normally be set to 255, in order to
541
+ maximize the probability of the packet arriving to its destination.
542
+
543
+ Replies to ICMP echo messages (in the form of ICMP echo response messages) can be
544
+ obtained by using the [TCPIP_RCV_ECHO](#422-tcpip_rcv_echo-retrieve-icmp-echo-response-message) routine.
545
+
546
+ **ERROR CODES**
547
+
548
+ * ERR_OK
549
+
550
+ The ICMP echo message packet has been sent.
551
+
552
+ * ERR_NOT_IMP
553
+
554
+ The _"Send ICMP echo messages"_ capability flag is not set. The implementation does not
555
+ support sending ICMP echo messages.
556
+
557
+ * ERR_NO_NETWORK
558
+
559
+ There is no network connection available.
560
+
561
+ * ERR_LARGE_DGRAM
562
+
563
+ Invalid data length specified. The maximum data length allowed is equal to the
564
+ maximum outgoing datagram size minus 28 (the size of the IP and ICMP headers
565
+ combined).
566
+
567
+ ### 4.2.2. TCPIP_RCV_ECHO: Retrieve ICMP echo response message
568
+
569
+ * Input:
570
+ * A = 5
571
+ * HL = Address for the echo parameters block
572
+
573
+ * Output:
574
+ * A = Error code
575
+
576
+ This routine retrieves the parameters associated to the oldest received ICMP echo
577
+ response message (usually received as a reply of an echo message sent via
578
+ [TCPIP_SEND_ECHO](#421-tcpip_send_echo-send-icmp-echo-message-ping)), and copies them to the address supplied in HL. It also removes the
579
+ message information from the implementation internal buffers, so that the next call to
580
+ this routine will either return information for the next message received, or a
581
+ ERR_NO_DATA error if no more messages are available. Implementations are required to
582
+ have internal buffer space to hold data for only one echo response message, but may
583
+ choose to provide space for more than one; echo response messages received when the
584
+ buffer space is full are silently discarded.
585
+
586
+ The parameters block has the same format as the one used by [TCPIP_SEND_ECHO](#421-tcpip_send_echo-send-icmp-echo-message-ping), only
587
+ that now the parameters refer to the received echo response message, not to a message
588
+ to be sent. It is not possible to retrieve the data part of the echo response messages
589
+ received.
590
+
591
+ **ERROR CODES**
592
+
593
+ * ERR_OK
594
+
595
+ The ICMP echo response message parameters have been copied to the specified address.
596
+
597
+ * ERR_NOT_IMP
598
+
599
+ The _"Send ICMP echo messages"_ capability flag is not set. The implementation does not
600
+ support receiving ICMP echo response messages.
601
+
602
+ * ERR_NO_DATA
603
+
604
+ No new ICMP echo response messages have been received and the implementation's
605
+ buffer for incoming messages is empty.
606
+
607
+ ### 4.3. Host name resolution routines
608
+
609
+ These routines allow to resolve a host name, that is, to convert host names to the
610
+ appropriate IP addresses. Depending on the supported capabilities, host names may be
611
+ resolved by using a local hosts file or equivalent mechanism, by querying a DNS server,
612
+ or both.
613
+
614
+ ### 4.3.1. TCPIP_DNS_Q: Start a host name resolution query
615
+
616
+ * Input:
617
+ * A = 6
618
+ * HL = Address of the host name to be resolved, zero terminated
619
+ * B = Flags, when set to 1 they instruct the resolver to:
620
+ * bit 0: Only abort the query currently in progress, if there is any (other flags and registers are then ignored)
621
+ * bit 1: Assume that the passed name is an IP address, and return an error if this is not true
622
+ * bit 2: If there is a query in progress already, do NOT abort it and return an error instead
623
+
624
+ * Output:
625
+ * A = Error code
626
+ * B = status after the routine returns:
627
+ * 0: a query to a DNS server is in progress
628
+ * 1: the name represented an IP address
629
+ * 2: the name could be resolved locally
630
+ * L.H.E.D = Resolved IP address (only if no error occurred and B=1 or 2 is returned)
631
+
632
+ This routine, together with its counterpart [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result)
633
+ explained later, allows to obtain
634
+ the IP address associated to a given host name (for example "smtp.mailserver.com"),
635
+ which may be up to 255 characters long. To achieve this, the DNS servers whose IP
636
+ addresses are currenly configured (see [TCPIP_GET_IPINFO](#413-tcpip_get_ipinfo-get-ip-address) routine) are queried. If the
637
+ implementation supports a local hosts file or an equivalent mechanism (as indicated by
638
+ the homonym capability flag), then it is queried first, and only when no match is found is
639
+ the DNS server queried.
640
+
641
+ Strings that directly represent an IP address (for example "120.200.0.34") must also be
642
+ accepted by this routine, making then easy to develop programs that accept both host
643
+ names and IP addresses as a user supplied parameter. This functionality is mandatory
644
+ even if the implementation does not support host name resolution by local hosts file nor
645
+ by querying DNS servers (that is, even if the _"Resolve host names by querying a local
646
+ hosts file"_ and _"Resolve host names by querying a DNS server"_ capability flags are both
647
+ not set).
648
+
649
+ After the host name is examined, there are three possibilities regarding how the host
650
+ name can be resolved:
651
+
652
+ 1. _The name represents an IP address._ In that case, the result is directly returned
653
+ in registers HL and DE, and B=1 is returned.
654
+ 2. _The name can be resolved locally_, by using a local hosts file or the resolver
655
+ cache. In that case, the result is directly returned in registers HL and DE, and
656
+ B=2 is returned.
657
+ 3. _A query to a DNS server is needed to resolve the name._ In that case, the query
658
+ is started and B=0 is immediately returned; the query processing will continue in
659
+ background. TCP_DNS_S must be invoked in order to know when the query has
660
+ finished, and to get the result.
661
+
662
+ The implementation can use the _"TCPIP_DNS_Q is a blocking operation"_ feature flag to announce that
663
+ this routine may query DNS servers and that in this case it won't return to the caller until
664
+ such process is completed or fails (thus never returning the "a query to a DNS server is in progress" state).
665
+ Client applications may use this flag to be aware that the routine may take a long time to return.
666
+
667
+ In the first two cases, the result must be cached so that a later call to [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result) will
668
+ return it as well. That way, client applications may ignore the fact that some names will
669
+ be resolved locally (that is, they can ignore the returned values in B, HL and DE), and
670
+ always invoke TCP_DNS_S to get the result of the name resolution process.
671
+
672
+ As stated above, the only mandatory capability of this routine is to parse strings
673
+ representing IP addresses. Resolution of host names via local hosts file, and resolution
674
+ via queries to DNS servers, are both optional capabilities. Depending of which of these
675
+ capabilities are supported, implementations should behave as follows when a host name
676
+ that does not represent an IP address is requested to be resolved:
677
+
678
+ * _None of the capabilities is supported:_ An ERR_NOT_IMP error must be returned.
679
+ * _Only local hosts file is supported:_ The host name must be searched in the local
680
+ hosts file. If not found, a "Host name not found" error must be cached so a later
681
+ call to [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result) will return it. (See the description of [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result) for
682
+ details on this error)
683
+ * _Only queries to DNS servers are supported:_ A query to the configured DNS
684
+ server must be started.
685
+ * _Both capabilities are supported:_ The host name must be searched in the local
686
+ hosts file. If not found, a query to the configured DNS server must be started.
687
+
688
+ If there is already a query in progress when [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query) is executed, normally this
689
+ query will be aborted in order to initiate the new one (only one query can be handled at
690
+ a time). However, if B:2 is set at input and there is a query in progress, then this query
691
+ will not be aborted and a ERR_QUERY_EXSITS will be returned instead.
692
+
693
+ How the implementation performs queries to DNS servers is outside this specification,
694
+ however it is expected that all implementations will follow some basic procedures:
695
+
696
+ * The primary DNS server will be queried, and in case of failure, the secondary
697
+ server will be queried.
698
+ * The "recursive query" flag in the packets send to the DNS servers will be set, but
699
+ if the server does not support recursive queries and the address of another DNS
700
+ server is obtained instead of the requested IP address, then this server will in
701
+ turn be queried.
702
+ * A total timeout for the entire process will be implemented so that a client
703
+ application invoking [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result) in a loop will not hang forever waiting for a
704
+ result.
705
+
706
+ However the implementation behaves, the process must be transparent for client
707
+ applications, which will rely exclusively on the results returned by [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query) and
708
+ [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result) routines.
709
+
710
+ **Note for implementors:** The following algorithm should be followed when
711
+ implementing this routine, to ensure that it behaves properly and returns the
712
+ appropriate error codes depending on the input parameters and the supported
713
+ capabilities.
714
+
715
+ ```
716
+ Is B:0 set?
717
+ Yes: Abort the current query, if any
718
+ Return ERR_OK, B=0
719
+ Is there a query in progress?
720
+ Yes: Is B:2 set?
721
+ Yes: Return ERR_QUERY_EXISTS
722
+ No: Abort the current query
723
+ Try to parse host name as an IP address
724
+ Success?
725
+ Yes: Cache the result so that TCPIP_DNS_S will return it
726
+ Return ERR_OK, B=1, and the address in HL,DE
727
+ B:1 was set?
728
+ Yes: Return ERR_INV_IP
729
+ Are the local hosts file mechanism capability, and the querying DNS servers capability, both NOT supported?
730
+ Yes: Return ERR_NOT_IMP
731
+ Is the local hosts file mechanism supported?
732
+ Yes: Is the host name in the local hosts file?
733
+ Yes: Cache the result so that TCPIP_DNS_S will return it
734
+ Return ERR_OK, B=2, and the address in HL,DE
735
+ Is DNS querying supported?
736
+ No: Cache a "Host name not found error" so that TCPIP_DNS_S will return it (see description of TCPIP_DNS_S)
737
+ Return ERR_OK, B=0
738
+ Is DNS cache supported?
739
+ Yes: Is the host name in the DNS cache?
740
+ Yes: Cache the result so that TCPIP_DNS_S will return it
741
+ Return ERR_OK, B=2, and the address in HL,DE
742
+ Is network available?
743
+ No: Return ERR_NO_NETWORK
744
+ Is there any DNS server configured?
745
+ No: return ERR_NO_DNS
746
+ Start querying the primary DNS server, or the secondary, if primary is not configured
747
+ Return ERR_OK, B=0
748
+ ```
749
+
750
+ Please note that the result is cached only if ERR_OK is returned. If any other error code
751
+ is returned, then [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result) must still return the same result as before [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query)
752
+ was invoked.
753
+
754
+ **Note for client application developers:** Below is an example of a simple way of using
755
+ the [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query)/S routines pair. For simplicity it is assumed that the implementation
756
+ routines can be called directly, without need for slot or segment switching.
757
+
758
+ ```
759
+ ;* Start the query
760
+
761
+ ld hl,HOST_NAME
762
+ xor a
763
+ call TCPIP_DNS_Q
764
+ or a
765
+ jp nz,ERROR_Q ;Jump to error management code
766
+
767
+ ;* Wait until either a result or an error is returned
768
+
769
+ WAIT:
770
+ xor a
771
+ call TCPIP_DNS_S
772
+ cp 1 ;Query is still in progress
773
+ jr z,WAIT
774
+ cp 3 ;Query finished with error
775
+ jp z,ERROR_S ;Jump to error management code
776
+ ;From here, A can only be equal to 2
777
+ ld (IP_ADD),hl ;Store the result
778
+ ld (IP_ADD+2),de
779
+ ...
780
+
781
+ HOST_NAME: db "name.host.com",0
782
+ IP_ADD: ds 4
783
+ ```
784
+
785
+ Note that in this example, we don't care about HOST_NAME representing an IP address
786
+ or being resolved locally. We just invoke [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result) to get the resolved IP address,
787
+ without checking how it was obtained. This will be enough in most cases.
788
+
789
+ **ERROR CODES**
790
+
791
+ * ERR_OK
792
+
793
+ A DNS query is in progress, or the name resolution process has finished and the result
794
+ has been cached for [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result).
795
+
796
+ * ERR_INV_PARAM
797
+
798
+ An unused flag was set in B.
799
+
800
+ * ERR_INV_IP
801
+
802
+ The host name does not represent an IP address and the routine was invoked with B:1
803
+ set.
804
+
805
+ * ERR_NOT_IMP
806
+
807
+ The host name does not represent an IP address, and neither the "Resolve host names
808
+ by querying a local hosts file" nor the "Resolve host names by querying a DNS server"
809
+ capabilities are supported.
810
+
811
+ * ERR_QUERY_EXISTS
812
+
813
+ The routine was invoked with B:0 set and there is another query in progress.
814
+
815
+ * ERR_NO_NETWORK
816
+
817
+ A query to a DNS server must start, but there is no network connectivity available.
818
+
819
+ * ERR_NO_DNS
820
+
821
+ A query to a DNS server must start, but there are no DNS server addresses configured.
822
+
823
+ ### 4.3.2. TCPIP_DNS_S: Obtains the host name resolution process state and result
824
+
825
+ * Input:
826
+ * A = 7
827
+ * B = Flags, when set to 1 they instruct the resolver to:
828
+ * bit 0: Clear any existing result or error condition after the execution (except if there is a query in progress)
829
+
830
+ * Output:
831
+ * A = Error code
832
+ * B = DNS error code (when error is ERR_DNS)
833
+ * B = Current query status (when error is ERR_OK):
834
+ * 0: There is no query in progress, nor any result nor error code available
835
+ * 1: There is a query in progress
836
+ * 2: Query is complete
837
+ * C = Current query substatus (when error is ERR_OK and B=1):
838
+ * 0: Unknown
839
+ * 1: Querying the primary DNS server
840
+ * 2: Querying the secondary DNS server
841
+ * 3: Querying another DNS server
842
+ * C = Resolution proces type (when error is ERR_OK and B=2):
843
+ * 0: The name was obtained by querying a DNS server
844
+ * 1: The name was a direct representation of an IP address
845
+ * 2: The name was resolved locally
846
+ * L.H.E.D = Resolved IP address (when error is ERR_OK and B=2)
847
+
848
+ This routine is the complementary of [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query). It allow to obtain the status of the
849
+ current host name resolution process (which was initiated via an invocation to
850
+ [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query)); and if the query process has finished, it returns either the resulting IP
851
+ addres or an appropriate error code.
852
+
853
+ As explained in the description of [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query), in certain circumstances the host name
854
+ can be resolved locally, without having to actually query any DNS server. In that case,
855
+ the result is cached so that [TCPIP_DNS_S](#432-tcpip_dns_s-obtains-the-host-name-resolution-process-state-and-result) returns it as well; that way, client applications
856
+ do not need to worry about a DNS query being actually performed or not (see the
857
+ sample code in the description of [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query)).
858
+
859
+ If B:0 is set at input, the current result is cleared after the routine returns, so that a
860
+ later invocation of the routine will return B=0 (no query is in progress and no result is
861
+ available). If B:0 is not set at input, successive invocations of the routine will always
862
+ return the same result, until an invocation of [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query) that returns ERR_OK is
863
+ performed. Note that B:0 is ignored if there is a query in progress.
864
+
865
+ If ERR_DNS is returned, then B returns an error code with more detailed error
866
+ information. Below are the possible error codes that B can return; codes 1 to 15 are
867
+ directly returned by a DNS server (as defined in RFC1035), other codes are generated by
868
+ the implementation itself. Errors 1 and 4 should never be obtained if the implementation
869
+ is working properly.
870
+
871
+ * 0: Unknown error
872
+ * 1: Invalid query packet format
873
+ * 2: DNS server failure
874
+ * 3: The specified host name does not exist
875
+ * 4: The DNS server does not support this kind of query
876
+ * 5: Query refused
877
+ * 6-15: Undefined error codes
878
+ * 16: One of the queried DNS servers did not reply
879
+ * 17: Total process timeout expired
880
+ * 18: Query cancelled by the user ([TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query) was executed with B:0 set)
881
+ * 19: Network connectivity was lost during the process
882
+ * 20: The obtained reply did not contain REPLY nor AUTHORITATIVE
883
+ * 21: The obtained reply is truncated
884
+
885
+ Note that this routine does never return ERR_NOT_IMP, since it is required that
886
+ [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query) is implemented to at least parse strings representing IP addresses.
887
+
888
+ **ERROR CODES**
889
+
890
+ * ERR_OK
891
+
892
+ A DNS query is in progress, or a DNS query has finished without errors, or no query is in
893
+ progress and results from a past query are not available.
894
+
895
+ * ERR_DNS
896
+
897
+ A DNS query has finished with errors, see register B for more details.
898
+
899
+ ### 4.4. UDP protocol related routines
900
+
901
+ These routines allow to send and receive data by using the UDP protocol. Even if UDP is
902
+ a datagram based, connectionless protocol, a connections-like mechanism is used; here
903
+ an "UDP connection" is simply a pair formed by the local IP address + a local port
904
+ number. When sending UDP data, the connection number and the remote IP address and
905
+ port must be specified; when a UDP datagram is received on a given connection, the
906
+ remote IP address and port are retrieved as well.
907
+
908
+ UDP connections are identified by connection numbers, which may be any number in the
909
+ range 1 to 254. The numbers actually used depend on the implementation; client
910
+ applications should handle these numbers as opaque values.
911
+
912
+ There is a "intended connection lifetime" parameter that is to be specified when opening
913
+ the connection: _transient_, which means that the connection is intended to be closed
914
+ when the client application finishes; and _resident_, which means that the connection is
915
+ intended to be used by a resident program. The only behavioral difference between
916
+ these two modes as far as this specification is concerned, is that all open transient
917
+ connections are closed when [TCPIP_UDP_CLOSE](#442-tcpip_udp_close-close-a-udp-connection) is invoked and zero is specified as the
918
+ connection number, being the resident connections unaffected.
919
+
920
+ This specification does not define how implementations should handle incoming UDP
921
+ datagrams whose destination port number is not associated with any open UDP
922
+ connection. These datagrams can be silently discarded, or implementation specific
923
+ routines can be defined to handle them.
924
+
925
+ ### 4.4.1. TCPIP_UDP_OPEN: Open a UDP connection
926
+
927
+ * Input:
928
+ * A = 8
929
+ * HL = Local port number (FFFFh: random port)
930
+ * B = Intended connection lifetime:
931
+ * 0: Transient
932
+ * 1: Resident
933
+
934
+ * Output:
935
+ * A = Error code
936
+ * B = Connection number
937
+
938
+ This routine opens a new UDP connection. This process does not imply any type of
939
+ negotiation or data exchange with any remote host; all that happens is that a connection
940
+ number is associated with a local port number.
941
+
942
+ The port number should not be zero, as this means "unespecified port" in the UDP
943
+ protocol, and this is not supported by this specification. Also, it should not be in the
944
+ range FFF0h-FFFEh, these port numbers are reserved for internal use of the
945
+ implementations.
946
+
947
+ When FFFFh is specified as the port number, the implementation must use a randomly
948
+ chosen port number. This port will be in the range 16384-32767, and will never be a
949
+ port number used by another open UDP connection.
950
+
951
+ Once the connection is open, UDP datagrams data can be sent and received by using the
952
+ [TCPIP_UDP_SEND](#444-tcpip_udp_send-send-an-udp-datagram) and [TCPIP_UDP_RCV](#445-tcpip_udp_rcv-retrieve-an-incoming-udp-datagram) routines. The connection can be closed by using
953
+ [TCPIP_UDP_CLOSE](#442-tcpip_udp_close-close-a-udp-connection). These routines expect the connection number returned by
954
+ [TCPIP_UDP_OPEN](#441-tcpip_udp_open-open-a-udp-connection) as an input parameter.
955
+
956
+ **ERROR CODES**
957
+
958
+ * ERR_OK
959
+
960
+ The connection has been created successfully. The returned connection number is valid.
961
+
962
+ * ERR_NOT_IMP
963
+
964
+ The _"Open UDP connections"_ capability flag is not set. The implementation does not
965
+ support sending and receiving UDP datagrams.
966
+
967
+ * ERR_INV_PARAM
968
+
969
+ - The "intended connection lifetime" parameter has an invalid value.
970
+ - Zero has been specified as the local port.
971
+ - The local port is in the range FFF0h-FFFEh.
972
+
973
+ * ERR_CONN_EXISTS
974
+
975
+ Other UDP connection exists which has the same local port assigned.
976
+
977
+ * ERR_NO_FREE_CONN
978
+
979
+ There are no free UDP connections available.
980
+
981
+ ### 4.4.2. TCPIP_UDP_CLOSE: Close a UDP connection
982
+
983
+ * Input:
984
+ * A = 9
985
+ * B = Connection number, 0 to close all open transient UDP connections
986
+
987
+ * Output:
988
+ * A = Error code
989
+
990
+ This routine closes the specified UDP connection. This process does not imply any type of
991
+ negotiation or data exchange with any remote host; all that happens is that the
992
+ connection number is freed and all the pending incoming datagrams for the connection
993
+ are discarded.
994
+
995
+ All the existing connections that were open in "transient" lifetime mode are closed if zero
996
+ is specified as the connection number.
997
+
998
+ **ERROR CODES**
999
+
1000
+ * ERR_OK
1001
+
1002
+ The connection(s) has (have) been closed successfully.
1003
+
1004
+ * ERR_NOT_IMP
1005
+
1006
+ The "Open UDP connections" capability flag is not set. The implementation does not
1007
+ support sending and receiving UDP datagrams.
1008
+
1009
+ * ERR_NO_CONN
1010
+
1011
+ There is no connection open with the specified number.
1012
+
1013
+ ### 4.4.3. TCPIP_UDP_STATE: Get the state of a UDP connection
1014
+
1015
+ * Input:
1016
+ * A = 10
1017
+ * B = Connection number
1018
+
1019
+ * Output:
1020
+ * A = Error code
1021
+ * HL = Local port number
1022
+ * B = Number of pending incoming datagrams
1023
+ * DE = Size of oldest pending incoming datagram (data part only)
1024
+
1025
+ This routine retrieves information about the UDP connection with the specified number.
1026
+
1027
+ _"Number of pending incoming datagrams"_ indicates how many UDP datagrams whose
1028
+ destination port matches the connection's associated port have been received and
1029
+ cached by the implementation; these datagrams can be retrieved by using the
1030
+ [TCPIP_UDP_RCV](#445-tcpip_udp_rcv-retrieve-an-incoming-udp-datagram) routine. Implementations are required to have buffer space for only one
1031
+ incoming UDP datagram per connection, but may optionally have space for more.
1032
+ Datagrams received when this buffer is full are silently discarded.
1033
+
1034
+ _"Number of pending incoming datagrams"_ may actually be smaller than the actual
1035
+ number of pending datagrams, if the implementation knows than there are received
1036
+ datagrams but has no means to know how many. The following rules apply: if no
1037
+ pending datagrams are available, then B=0; if at least one pending datagram is
1038
+ available, then B>0 but less than or equal to the number of pending datagrams.
1039
+ Applications willing to retrieve all the pending datagrams for a UDP connection should
1040
+ not rely on this number; instead, they should invoke [TCPIP_UDP_RCV](#445-tcpip_udp_rcv-retrieve-an-incoming-udp-datagram) repeatedly until
1041
+ ERR_NO_DATA is returned.
1042
+
1043
+ _"Size of oldest pending datagram"_ indicates the size of the data part of the datagram
1044
+ that will be retrieved by the next call to [TCPIP_UDP_RCV](#445-tcpip_udp_rcv-retrieve-an-incoming-udp-datagram). It is zero if the datagram
1045
+ contains no data apart from the UDP header, and contains no meaningful information if
1046
+ there are no pending datagrams (that is, if B=0 is returned).
1047
+
1048
+ **ERROR CODES**
1049
+
1050
+ * ERR_OK
1051
+
1052
+ The requested information has been retrieved.
1053
+
1054
+ * ERR_NOT_IMP
1055
+
1056
+ The _"Open UDP connections"_ capability flag is not set. The implementation does not
1057
+ support sending and receiving UDP datagrams.
1058
+
1059
+ * ERR_NO_CONN
1060
+
1061
+ There is no connection open with the specified number.
1062
+
1063
+ ### 4.4.4. TCPIP_UDP_SEND: Send an UDP datagram
1064
+
1065
+ * Input:
1066
+ * A = 11
1067
+ * B = Connection number
1068
+ * HL = Address of datagram data
1069
+ * DE = Address of parameters block
1070
+
1071
+ * Output:
1072
+ * A = Error code
1073
+
1074
+ This routine sends a block of data in the form od an UDP datagram. The local port used
1075
+ to compose the datagram is the one associated to the specified connection; the remote
1076
+ IP address and port are took from the parameters block. The format of the parameters
1077
+ block is as follows:
1078
+
1079
+ * +0 (4): Destination IP address
1080
+ * +4 (2): Destination port
1081
+ * +6 (2): Data length
1082
+
1083
+ The maximum allowed value for the datagram data length is equal to the maximum
1084
+ outgoing datagram size supported, minus 28 (the combined size of the IP and UDP
1085
+ headers).
1086
+
1087
+ Implementations are expected to send the datagram immediately. At most, the routine
1088
+ can block while waiting for another datagram transmission in progress to finish; or the
1089
+ datagram can be cached to be sent at a later time, provided that the time between
1090
+ routine invocation and actual datagram send is very small (unnoticeable for the user).
1091
+
1092
+ **ERROR CODES**
1093
+
1094
+ * ERR_OK
1095
+
1096
+ The datagram has been sent.
1097
+
1098
+ * ERR_NOT_IMP
1099
+
1100
+ The "Open UDP connections" capability flag is not set. The implementation does not
1101
+ support sending and receiving UDP datagrams.
1102
+
1103
+ * ERR_NO_CONN
1104
+
1105
+ There is no connection open with the specified number.
1106
+
1107
+ * ERR_NO_NETWORK
1108
+
1109
+ No network connectivity is currently available.
1110
+
1111
+ * ERR_LARGE_DGRAM
1112
+
1113
+ The data length specified in the parameters block is larger than the maximum outgoing
1114
+ datagram size supported minus 28.
1115
+
1116
+ ### 4.4.5. TCPIP_UDP_RCV: Retrieve an incoming UDP datagram
1117
+
1118
+ * Input:
1119
+ * A = 12
1120
+ * B = Connection number
1121
+ * HL = Address for datagram data
1122
+ * DE = Maximum data size to retrieve
1123
+
1124
+ * Output:
1125
+ * A = Error code
1126
+ * L.H.E.D = Source IP address
1127
+ * IX = Source port
1128
+ * BC = Actual received data size
1129
+
1130
+ This routine retrieves the data part and information parameters of the oldest received
1131
+ UDP datagram for the given connection, and removes the datagram from the
1132
+ implementation's internal buffer. Implementations are required to have buffer space for
1133
+ only one incoming UDP datagram per connection, but may optionally have space for
1134
+ more. Datagrams received when this buffer is full are silently discarded.
1135
+
1136
+ The data part of the datagram, without the IP and UDP headers, will be copied to the
1137
+ address pointed by HL. The entire datagram data part will be copied if its length is
1138
+ smaller or equal than the "maximum data size" parameter passed in DE; otherwise, only
1139
+ the first DE bytes will be copied and the rest of the datagram data will be discarded
1140
+ (DE=FFFFh can be specified with the meaning of "get the whole datagram"). No data
1141
+ will be copied at all if DE=0. Remember that it is possible to check the datagram data
1142
+ size in advance by using [TCPIP_UDP_STATE](#443-tcpip_udp_state-get-the-state-of-a-udp-connection).
1143
+
1144
+ Information about the originator of the datagram will be returned in registers HL, DE,
1145
+ and IX. Register BC will contain the datagram data size as it was received, which may be
1146
+ larger than the number of bytes actually retrieved.
1147
+
1148
+ **ERROR CODES**
1149
+
1150
+ * ERR_OK
1151
+
1152
+ The datagram data and information have been retrieved.
1153
+
1154
+ * ERR_NOT_IMP
1155
+
1156
+ The _"Open UDP connections"_ capability flag is not set. The implementation does not
1157
+ support sending and receiving UDP datagrams.
1158
+
1159
+ * ERR_NO_CONN
1160
+
1161
+ There is no connection open with the specified number.
1162
+
1163
+ * ERR_NO_DATA
1164
+
1165
+ There are no pending incoming datagrams for the specified connection.
1166
+
1167
+ ### 4.5. TCP protocol related routines
1168
+
1169
+ These routines allow to send and receive data by using the TCP protocol. TCP is a
1170
+ connection based protocol, and thus this specification defines TCP connections as the
1171
+ way to manage TCP communications. A connection is defined by two pairs of IP address + port,
1172
+ one for the local computer and another one for the remote computer.
1173
+
1174
+ TCP connections are identified by connection numbers, which may be any number in the
1175
+ range 1 to 254. The numbers actually used depend on the implementation; client
1176
+ applications should handle these numbers as opaque values.
1177
+
1178
+ There is a "intended connection lifetime" parameter that is to be specified when opening
1179
+ the connection: _transient_, which means that the connection is intended to be closed
1180
+ when the client application finishes; and _resident_, which means that the connection is
1181
+ intended to be used by a resident program. The only behavioral difference between
1182
+ these two modes as far as this specification is concerned, is that all open transient
1183
+ connections are closed when [TCPIP_TCP_CLOSE](#452-tcpip_tcp_close-close-a-tcp-connection) is invoked and zero is specified as the
1184
+ connection number, being the resident connections unaffected. The same applies to
1185
+ [TCPIP_TCP_ABORT](#453-tcpip_tcp_abort-abort-a-tcp-connection).
1186
+
1187
+ ### 4.5.1. TCPIP_TCP_OPEN: Open a TCP connection
1188
+
1189
+ * Input:
1190
+ * A = 13
1191
+ * HL = Address of parameters block
1192
+
1193
+ * Output:
1194
+ * A = Error code
1195
+ * B = Connection number
1196
+ * C = Close reason (only if A=ERR_NO_CONN)
1197
+
1198
+ This routine opens a new TCP connection using the information specified in the
1199
+ parameters block. The format of this block is:
1200
+
1201
+ * +0 (4): Remote IP address (0.0.0.0 for unespecified remote socket)
1202
+ * +4 (2): Remote port (ignored if unespecified remote socket)
1203
+ * +6 (2): Local port, FFFFh for a random value
1204
+ * +8 (2): Suggestion for user timeout value
1205
+ * +10 (1): Flags:
1206
+ * bit 0: Set for passive connection
1207
+ * bit 1: Set for resident connection
1208
+ * bit 2: Use TLS
1209
+ * bit 3: Verify the server certificate (only when using TLS on an active connection)
1210
+ * bits 4-7: Unused, must be zero
1211
+ * +11 (2): Address of the server host name for certificate validation,
1212
+ or zero to skip host name validation (only when using TLS on an active connection and
1213
+ "Verify the server certificate" is set)
1214
+
1215
+ If the connection is open in active mode, a remote IP address and a remote port must be
1216
+ specified. The implementation must start trying to actively establish a connection (that
1217
+ is, a SYN segment must be sent and connection must enter the SYN-SENT state), and
1218
+ must continue processing the connection establishment in background.
1219
+
1220
+ If the connection is open in passive mode, there is the option to leave the remote IP
1221
+ address unespecified (by specifying it as 0.0.0.0), meaning that a connection from any
1222
+ host will be accepted; the remote port is ignored in this case. The implementation must
1223
+ simply enter the LISTEN state when a connection is open in passive mode.
1224
+
1225
+ Only one connection can exist with the same combination of local port, remote IP
1226
+ address and remote port. Passive connections with unespecified remote socket are an
1227
+ exception: more than one connection can exist with the same local port and 0.0.0.0 as
1228
+ the remote IP address. In this case, when a connection request is received for that local
1229
+ port, the implementation must choose one of these connections, and there is no way for
1230
+ client applications to decide which one is chosen.
1231
+
1232
+ When FFFFh is specified as the local port, the implementation must use a randomly
1233
+ chosen port number. This port will be in the range 16384-32767, and will never be a
1234
+ port number used by another open TCP connection.
1235
+
1236
+ Although the TCP standard allows to transform a passive connection into an active one
1237
+ by opening it again, this is not allowed in this specification. On the other hand, sending
1238
+ data to an active connection before it reaches the ESTABLISHED state may or may not
1239
+ be supported by the implementation, depending on the value of the "Send data to a TCP
1240
+ connection before the ESTABLISHED state is reached" capability flag. When this is
1241
+ supported, data is cached internally by the implementation, and then sent when the
1242
+ ESTABLISHED state is reached.
1243
+
1244
+ The "user timeout" is a suggested value for a timer that is activated when new data is
1245
+ sent to the connection, and is stopped when the acknowledgment (ACK) arrives for that
1246
+ data. If this timer expires, the host is considered to be unreachable and the connection
1247
+ is aborted. This timer is also applied to the connection initiation (that is, it is also the
1248
+ maximum time that can elapse until the acknowledgment for a sent SYN segment
1249
+ arrives). The specified value is interpreted as follows:
1250
+
1251
+ * 1 to 1080: Value for the timer in seconds (1 second to 18 minutes).
1252
+ * 0: Use the default value for the timer, as chosen by the implementation.
1253
+ * FFFFh: Infinite, data is retransmitted indefinitely until either the
1254
+ acknowledgment arrives, the connection is aborted or an RST segment arrives.
1255
+
1256
+ Note that this value is just a suggestion: implementations may ignore it and use their
1257
+ own value, or they may not implement this timeout at all.
1258
+
1259
+ Once the connection is open, TCP data can be sent and received by using the
1260
+ [TCPIP_TCP_SEND](#455-tcpip_tcp_send-send-data-a-tcp-connection) and [TCPIP_TCP_RCV](#456-tcpip_tcp_rcv-receive-data-from-a-tcp-connection) routines. The connection can be closed by using
1261
+ [TCPIP_UDP_CLOSE](#442-tcpip_udp_close-close-a-udp-connection), or aborted by using [TCPIP_TCP_ABORT](#453-tcpip_tcp_abort-abort-a-tcp-connection). These routines expect the
1262
+ connection number returned by [TCPIP_TCP_OPEN](#451-tcpip_tcp_open-open-a-tcp-connection) as an input parameter.
1263
+
1264
+ The implementation may use the _"TCPIP_TCP_OPEN is a blocking operation"_ to announce that
1265
+ the routine will go throught the entire connection process synchronously, and will not return
1266
+ until either the connection is completed (the ESTABLISHED or the CLOSE_WAIT state is reached)
1267
+ or fails. Client applications may use this flag to be aware that the routine may take a long time to return.
1268
+
1269
+ If _"TCPIP_TCP_OPEN is a blocking operation"_ is set and the connection establishment fails, then a ERR_NO_CONN error
1270
+ must be returned in A. In this case, a close reason must be returned in register C; the list of possible
1271
+ close reasons is the same one used in [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection).
1272
+
1273
+ **Note for client application developers:** The usual procedure after opening an active connection
1274
+ is to enter a loop to wait while the connection is being established (while the connection status
1275
+ returned by [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection) is either
1276
+ SYN-SEND or SYN-RECEIVED). When entering such a loop
1277
+ it's important to take in account that the server might send data and close the connection
1278
+ very quickly, thus progressing to the CLOSE_WAIT state and not giving TCPIP_TCP_STATE the opportunity to
1279
+ ever return ESTABLISHED as the state of the connection. Therefore, applications should NOT
1280
+ assume that TCPIP_TCP_STATE will eventually return ESTABLISHED as the state of the connection;
1281
+ they should check for CLOSE_WAIT as well (or even better, for robustness they should detect any
1282
+ unexpected state and abort the connection).
1283
+
1284
+ #### About TLS support
1285
+
1286
+ **Note:** TLS support was introduced in version 1.1 of the specification. Implementations of version
1287
+ 1.0 don't provide any support for TLS and will always ignore the "Verify the server certificate" flag and
1288
+ the "Address of the server host name for certificate validation" field in the parameters block.
1289
+
1290
+ When the "Use TLS" flag is not set in the connection parameters block, the connection
1291
+ must be done without using TLS. When the flag is set there are the following possibilities:
1292
+
1293
+ * The connection is active
1294
+
1295
+ * "Verify the server certificate" flag is not set: the implementation must not
1296
+ perform any kind of validation for the certificate provided by the server.
1297
+
1298
+ * "Verify the server certificate" flag is not set and "Address of the server host name for certificate validation"
1299
+ is non-zero: the validity of the certificate provided by the server must be verified, and if there is any error, then the connection must be closed immediately. As part of the validation, the host name in the certificate must be compared
1300
+ against the host name supplied in the parameters block; if they aren't identical the certificate is considered
1301
+ to be invalid.
1302
+
1303
+ * "Verify the server certificate" flag is not set and "Address of the server host name for certificate validation"
1304
+ is zero: the validity of the certificate provided by the server must be verified, and if there is any error, then the connection must be closed immediately. However the host name in the certificate must be ignored.
1305
+
1306
+ * The connection is passive
1307
+
1308
+ * The implementation must provide a valid certificate to be checked by the client that
1309
+ initiated the connection.
1310
+
1311
+ If the _The server certificate can be verified when opening a TCP connection with TLS_ feature flag
1312
+ is not set, then the server certificate is never verified and the implementation always ignores
1313
+ the value of the "Verify the server certificate" flag of the connection parameters block, acting as if it was zero.
1314
+
1315
+ If the connection needs to be closed due to a TLS related error, it's strongly recommended to provide
1316
+ a meaningful code in the "Close reason" field when [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection)
1317
+ is executed for the connection.
1318
+
1319
+ In order to properly handle TLS the implementation will need to store and handle certificates and private keys.
1320
+ How this is done is outside the scope of this specification.
1321
+
1322
+ **ERROR CODES**
1323
+
1324
+ * ERR_OK
1325
+
1326
+ The connection has been open with the specified parameters. The returned connection
1327
+ number is valid.
1328
+
1329
+ * ERR_NOT_IMP
1330
+
1331
+ - The connection is required to be open in active mode, but the _"Open TCP connections
1332
+ in active mode"_ capability flag is not set.
1333
+ - The connection is required to be open in passive mode with specified remote socker,
1334
+ but the _"Open TCP connections in passive mode, with specified remote socket"_ capability
1335
+ flag is not set.
1336
+ - The connection is required to be open in passive mode with unespecified remote
1337
+ socker, but the _"Open TCP connections in passive mode, with unespecified remote
1338
+ socket"_ capability flag is not set.
1339
+ - The connection is required to be active and to use TLS, but the
1340
+ _"Use TLS in TCP active connections"_ capability flag is not set.
1341
+ - The connection is required to be passive and to use TLS, but the
1342
+ _"Use TLS in TCP passive connections"_ capability flag is not set.
1343
+
1344
+ * ERR_INV_PARAM
1345
+
1346
+ - An invalid value for the user timeout was specified.
1347
+ - 0.0.0.0 was specified as the remote IP address when trying to open a connection in
1348
+ active mode.
1349
+ - An unused flag was set.
1350
+
1351
+ * ERR_NO_NETWORK
1352
+
1353
+ No network connectivity is currently available.
1354
+
1355
+ * ERR_CONN_EXISTS
1356
+
1357
+ There is a TCP connection already open with the same combination of local port, remote
1358
+ IP address and remote port.
1359
+
1360
+ * ERR_NO_FREE_CONN
1361
+
1362
+ There are no free TCP connections available.
1363
+
1364
+ * ERR_NO_CONN
1365
+
1366
+ The _"TCPIP_TCP_OPEN is a blocking operation"_ feature flag is set and the connection failed.
1367
+
1368
+ ### 4.5.2. TCPIP_TCP_CLOSE: Close a TCP connection
1369
+
1370
+ * Input:
1371
+ * A = 14
1372
+ * B = Connection number, 0 to close all open transient TCP connections
1373
+
1374
+ * Output:
1375
+ * A = Error code
1376
+
1377
+ This routine initiates the closing procedure for a TCP connection. As per the TCP protocol,
1378
+ closing a connection implies that it is not possible to send new data to it, but the other
1379
+ side can still sending new data (and we can still receiving it); the connection will not be
1380
+ freed until both sides have exchanged a FIN segment. To immediately destroy the
1381
+ connection, [TCPIP_TCP_ABORT](#453-tcpip_tcp_abort-abort-a-tcp-connection) should be used instead.
1382
+
1383
+ All the existing connections that were open in "transient" lifetime mode are closed if zero
1384
+ is specified as the connection number.
1385
+
1386
+ After a connection is explicitly closed with this routine the implementation may discard any
1387
+ incoming data that hasn't yet been consumed by client applications.
1388
+
1389
+ **ERROR CODES**
1390
+
1391
+ * ERR_OK
1392
+
1393
+ The connection has been closed.
1394
+
1395
+ * ERR_NOT_IMP
1396
+
1397
+ The implementation does not support TCP connections at all (none of the _"Open TCP
1398
+ connections in active mode"_, _"Open TCP connections in passive mode, with specified
1399
+ remote socket"_ or _"Open TCP connections in passive mode, with unespecified remote
1400
+ socket"_ capability flags is set).
1401
+
1402
+ * ERR_NO_CONN
1403
+
1404
+ There is no connection open with the specified number.
1405
+
1406
+ ### 4.5.3. TCPIP_TCP_ABORT: Abort a TCP connection
1407
+
1408
+ * Input:
1409
+ * A = 15
1410
+ * B = Connection number, 0 to abort all open transient TCP connections
1411
+
1412
+ * Output:
1413
+ * A = Error code
1414
+
1415
+ This routine aborts the TCP connection with the specified number. An RST segment is
1416
+ sent if appropriate (according to the TCP protocol specification), and then the connection
1417
+ is freed immediately.
1418
+
1419
+ All the existing connections that were open in "transient" lifetime mode are aborted if
1420
+ zero is specified as the connection number.
1421
+
1422
+ **ERROR CODES**
1423
+
1424
+ * ERR_OK
1425
+
1426
+ The connection has been aborted.
1427
+
1428
+ * ERR_NOT_IMP
1429
+
1430
+ The implementation does not support TCP connections at all (none of the _"Open TCP
1431
+ connections in active mode"_, _"Open TCP connections in passive mode, with specified
1432
+ remote socket"_ or _"Open TCP connections in passive mode, with unespecified remote
1433
+ socket"_ capability flags is set).
1434
+
1435
+ * ERR_NO_CONN
1436
+
1437
+ There is no connection open with the specified number.
1438
+
1439
+ ### 4.5.4. TCPIP_TCP_STATE: Get the state of a TCP connection
1440
+
1441
+ * Input:
1442
+ * A = 16
1443
+ * B = Connection number
1444
+ * HL = Pointer in TPA for connection information block (0 if not needed)
1445
+
1446
+ * Output:
1447
+ * A = Error code
1448
+ * B = Connection state
1449
+ * C = Connection flags (if the connection exists and is in the ESTABLISHED or CLOSE_WAIT state)
1450
+ * C = Close reason (if the connection doesn't exist)
1451
+ * HL = Number of total available incoming bytes
1452
+ * DE = Number of urgent available incoming bytes
1453
+ * IX = Available free space in the output buffer (FFFFh = infinite)
1454
+
1455
+ This routine returns information about the current state of an open TCP connection. It is
1456
+ useful mainly to know if data can be sent to the connection, and if so how many output
1457
+ buffer space is available; as well as to know if incoming data is available.
1458
+
1459
+ The connection information block is 8 bytes long. If a non-zero pointer is passed in HL,
1460
+ and if no error is returned, it will be filled with the following information about the
1461
+ connection:
1462
+
1463
+ * +0 (4): Remote IP address
1464
+ * +4 (2): Remote port
1465
+ * +6 (2): Local port
1466
+
1467
+ The **connection state** value encodes the current connection state as defined in the TCP
1468
+ specification. It will be one of the following values:
1469
+
1470
+ * 0: Unknown
1471
+ * 1: LISTEN
1472
+ * 2: SYN-SENT
1473
+ * 3: SYN-RECEIVED
1474
+ * 4: ESTABLISHED
1475
+ * 5: FIN-WAIT-1
1476
+ * 6: FIN-WAIT-2
1477
+ * 7: CLOSE-WAIT
1478
+ * 8: CLOSING
1479
+ * 9: LAST-ACK
1480
+ * 10: TIME-WAIT
1481
+
1482
+ If the connection uses TLS the implementation must not return ESTABLISHED as the state
1483
+ of the connection before the TLS handshake has finished and all the involved certificates
1484
+ have been verified; SYN-SENT (for active connections) or SYN-RECEIVED (for passive connections)
1485
+ should be returned instead.
1486
+
1487
+ The **connection flags** value is returned onlye when the connection exists
1488
+ (no error is returned in A) and is in the ESTABLISHED or CLOSE_WAIT state,
1489
+ and contains the following information:
1490
+
1491
+ * Bit 0: The connection uses TLS
1492
+ * Bits 1-7: Unused, always zero
1493
+
1494
+ The **close reason** value is meaningful only when ERR_NO_CONN is returned in A, and
1495
+ contains an optional indication of why the connection is closed. It may be one of the
1496
+ following values ("Unknown" should be returned if the implementation does not support
1497
+ reporting close reasons):
1498
+
1499
+ * 0: Unknown
1500
+ * 1: This connection has never been used since the implementation was initialized.
1501
+ * 2: The [TCPIP_TCP_CLOSE](#452-tcpip_tcp_close-close-a-tcp-connection) method was called.
1502
+ * 3: The [TCPIP_TCP_ABORT](#453-tcpip_tcp_abort-abort-a-tcp-connection) method was called.
1503
+ * 4: A RST segment was received (the connection was refused or aborted by the remote host).
1504
+ * 5: The user timeout expired.
1505
+ * 6: The connection establishment timeout expired.
1506
+ * 7: Network connection was lost while the TCP connection was open.
1507
+ * 8: ICMP "Destination unreachable" message received.
1508
+ * 9: TLS: The server did not provide a certificate.
1509
+ * 10: TLS: Invalid server certificate.
1510
+ * 11: TLS: Invalid server certificate (the host name didn't match the name provided in the parameters block when opening the connection).
1511
+ * 12: TLS: Invalid server certificate (expired).
1512
+ * 13: TLS: Invalid server certificate (self-signed).
1513
+ * 14: TLS: Invalid server certificate (untrusted root).
1514
+ * 15: TLS: Invalid server certificate (revoked).
1515
+ * 16: TLS: Invalid server certificate (invalid certificate authority).
1516
+ * 17: TLS: Invalid server certificate (invalid TLS version or cypher suite).
1517
+ * 18: TLS: Our certificate was rejected by the peer.
1518
+ * 19: TLS: Other error.
1519
+ * 20-127: Reserved for future versions of the specification.
1520
+ * 128-255: Implementation specific reasons.
1521
+
1522
+ The 128-255 range is for implementation specific reasons, implementations are free to return these with any meaning
1523
+ if none of the standard codes is appropriate for a given close reason.
1524
+
1525
+ The **Number of total available incoming bytes** value indicates how many bytes have
1526
+ been received by this connection and can be retrieved by using the [TCPIP_TCP_RCV](#456-tcpip_tcp_rcv-receive-data-from-a-tcp-connection)
1527
+ routine. The **Number of urgent available incoming bytes** value indicates how many
1528
+ of these bytes are urgent data (this value will always be zero if the implementation does
1529
+ not support TCP urgent data, as per the "Send and receive TCP urgent data" capability
1530
+ flag).
1531
+
1532
+ The **Available free space in the output buffer** value indicates how many data can be
1533
+ queued by calling the [TCPIP_TCP_SEND](#455-tcpip_tcp_send-send-data-a-tcp-connection) routine. This free space decreases when a call to
1534
+ that routine is made, and increases when the buffered data is sent an acknowledged. A
1535
+ value of FFFFh means that there is no practical buffer space limit and a call to
1536
+ [TCPIP_TCP_SEND](#455-tcpip_tcp_send-send-data-a-tcp-connection) will never return an ERR_BUFFER error.
1537
+
1538
+ **Note for implementation developers:**: As stated in the description of [TCPIP_TCP_OPEN](#451-tcpip_tcp_open-open-a-tcp-connection),
1539
+ client applications should not assume that TCPIP_TCP_STATE will ever report the ESTABLISHED state (it could report CLOSE_WAIT on the first
1540
+ call after opening the connection if the server sends data and then closes the connection fast enough).
1541
+ However, for robustness it is recommended that implementations return ESTABLISHED as the current state of the
1542
+ connection when the actual state is CLOSE_WAIT but there's still incoming data that hasn't been yet consumed
1543
+ by the application.
1544
+
1545
+ **ERROR CODES**
1546
+
1547
+ * ERR_OK
1548
+
1549
+ The connection has been aborted.
1550
+
1551
+ * ERR_NOT_IMP
1552
+
1553
+ The implementation does not support TCP connections at all (none of the "Open TCP
1554
+ connections in active mode", "Open TCP connections in passive mode, with specified
1555
+ remote socket" or "Open TCP connections in passive mode, with unespecified remote
1556
+ socket" capability flags is set).
1557
+
1558
+ * ERR_NO_CONN
1559
+
1560
+ There is no connection open with the specified number.
1561
+
1562
+ ### 4.5.5. TCPIP_TCP_SEND: Send data a TCP connection
1563
+
1564
+ * Input:
1565
+ * A = 17
1566
+ * B = Connection number
1567
+ * DE = Address of the data to be sent
1568
+ * HL = Length of the data to be sent
1569
+ * C = Flags:
1570
+ * bit 0: Send the data PUSHed
1571
+ * bit 1: The data is urgent
1572
+
1573
+ * Output:
1574
+ * A = Error code
1575
+
1576
+ This routine enqueues data to be sent by a TCP connection. The data is sent in the form
1577
+ of TCP segments at the appropriate times, depending on the sending window available,
1578
+ the data acknoledgements received from the remote host, and the possible data sending
1579
+ optimization algorithms used by the implementation (see the TCP protocol specification
1580
+ for more details).
1581
+
1582
+ All implementations must accept data to be enqueued when the connection is in the
1583
+ ESTABLISHED or CLOSE-WAIT state. Optionally, implementations may accept also data
1584
+ when the connection is in the SYN-SENT or SYN-RECEIVED state (the _"Send data to a
1585
+ TCP connection before the ESTABLISHED state is reached"_ capability flag must be set);
1586
+ in this case, enqueued data is sent as soon as the ESTABLISHED state is set. In all other
1587
+ connection states, this routine must return a ERR_CONN_STATE error.
1588
+
1589
+ Implementations will tipically have a limited buffer space to enqueue TCP outgoing data.
1590
+ The free space on this buffer can be checked by invoking the [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection) routine.
1591
+ Trying to enqueue more data than buffer space available will result on a ERR_BUFFER
1592
+ error being returned. All implementations are required to have at least 512 bytes of TCP
1593
+ output buffer space.
1594
+
1595
+ If the _"Explicitly set the PUSH bit when sending TCP data"_ capability flag is set, it is
1596
+ possible to indicate that the data is intended to be PUSHed; in this case, the data
1597
+ enqueued by the involved call and any other data previously enqueued is sent
1598
+ immediately (bypassing any possible data grouping algorithm being used), and the PUSH
1599
+ bit is set on the outgoing datagrams for this data. If the capability is not supported, the
1600
+ PUSH flag is ignored.
1601
+
1602
+ Invoking this routine with HL=0 is allowed and must not result in any error
1603
+ (if the specified connection is valid). If the "Send the data PUSHed" flag is set and the
1604
+ capability is implemented, then this causes all the enqueued data to be
1605
+ sent immediately; otherwise, nothing is done.
1606
+
1607
+ If the _"Send and receive TCP urgent data"_ capability flag is set, then all the data
1608
+ enqueued by the involved call will be set in segments with the URG bit set. If the
1609
+ capability is not supported, the "urgent data" flag is ignored.
1610
+
1611
+ **Note for client application developers:** The following pseudocode shows the
1612
+ recommended approach for sending data to a TCP connection. The idea is to feed the
1613
+ connection with data until the output buffer space is full (which is signaled by
1614
+ ERR_BUFFER), and then to give the implementation an opportunity to send the data and
1615
+ free the buffer (which is achieved by calling [TCPIP_WAIT](#481-tcpip_wait-wait-for-a-processing-step-to-run)_INT). BlockSize can be any
1616
+ value between 1 and 512. A, B, DE and HL refer to the Z80 registers.
1617
+
1618
+ ```
1619
+ BlockSize = 128
1620
+ RemainigSize = (amount of data to send)
1621
+ DataAddress = (address of data to send)
1622
+
1623
+ do
1624
+ do
1625
+ B = ConnectionNumber
1626
+ DE = DataAddress
1627
+ HL = min(RemainingSize, BlockSize)
1628
+ call TCPIP_TCP_SEND
1629
+ error = A
1630
+ if(error = ERR_BUFFER)
1631
+ call TCPIP_WAIT
1632
+ while(error = ERR_BUFFER)
1633
+
1634
+ RemainigSize = RemainingSize - HL
1635
+ DataAddress = DataAddress + HL
1636
+ while(RemainingSize > 0 and error != 0)
1637
+
1638
+ if(error != 0)
1639
+ ProcessError(error)
1640
+ ```
1641
+
1642
+ **ERROR CODES**
1643
+
1644
+ * ERR_OK
1645
+
1646
+ The data has been successfully enqueued for sending.
1647
+
1648
+ * ERR_NOT_IMP
1649
+
1650
+ The implementation does not support TCP connections at all (none of the _"Open TCP
1651
+ connections in active mode"_, _"Open TCP connections in passive mode, with specified
1652
+ remote socket"_ or _"Open TCP connections in passive mode, with unespecified remote
1653
+ socket"_ capability flags is set).
1654
+
1655
+ * ERR_NO_CONN
1656
+
1657
+ There is no connection open with the specified number.
1658
+
1659
+ * ERR_INV_PARAM
1660
+
1661
+ An unused bit was set in the flags byte.
1662
+
1663
+ * ERR_CONN_STATE
1664
+
1665
+ - The connection is in the SYN-SENT or SYN-RECEIVED state, and the "Send data to a
1666
+ TCP connection before the ESTABLISHED state is reached" capability flag is not set.
1667
+ - The connection is in the LISTEN, FIN-WAIT-1, FIN-WAIT-2, CLOSING, LAST-ACK or
1668
+ TIME-WAIT state.
1669
+
1670
+ * ERR_BUFFER
1671
+
1672
+ There is not enough free output buffer to enqueue all the specified data.
1673
+
1674
+ ### 4.5.6. TCPIP_TCP_RCV: Receive data from a TCP connection
1675
+
1676
+ * Input:
1677
+ * A = 18
1678
+ * B = Connection number
1679
+ * DE = Address for the retrieved data
1680
+ * HL = Length of the data to be obtained
1681
+
1682
+ * Output:
1683
+ * A = Error code
1684
+ * BC = Total number of bytes that have been actually retrieved
1685
+ * HL = Number of urgent data bytes that have been retrieved (placed at the beginning of the received data block)
1686
+
1687
+ This routine copies to the specified address as much enqueued incoming data bytes as
1688
+ specified in the HL register. If there is less data available, then all the available data is
1689
+ retrieved, and if no data is available at all, then no data is retrieved; in any case, the
1690
+ number of bytes actually retrieved is returned in BC. Having retrieved less data than
1691
+ requested or having retrieved no data at all is not considered an error.
1692
+
1693
+ It is possible to check how many incoming data bytes are available by invoking the
1694
+ [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection) routine, but this is not mandatory since as mentioned above, trying
1695
+ to get more data than available is allowed.
1696
+
1697
+ If the _"Send and receive TCP urgent data"_ capability flag is set, then it is possible than
1698
+ part of the received data is urgent. In that case, the urgent data is placed at the
1699
+ beginning of the retrieved data block, and a value will be returned in HL telling how
1700
+ many of the retrieved bytes are urgent. HL will be zero if no urgent data has been
1701
+ received, or if receiving urgent data is not supported by the implementation.
1702
+
1703
+ Note that unlike when sending TCP data, it is not necessray for client applications to
1704
+ worry about the implementation's buffer space for incoming data to be exhausted, since
1705
+ this is handled by the TCP protocol itself (if the buffer is full, the implementation will
1706
+ simply close the receiving window and the remote host will not send more data). Also,
1707
+ this routine can be safely called regardless of the state the TCP connection is in; if the
1708
+ current state does not allow receiving data, then simply no data will be retrieved at all
1709
+ and BC will be returned as zero.
1710
+
1711
+ **ERROR CODES**
1712
+
1713
+ * ERR_OK
1714
+
1715
+ The data has been successfully retrieved.
1716
+
1717
+ * ERR_NOT_IMP
1718
+
1719
+ The implementation does not support TCP connections at all (none of the _"Open TCP
1720
+ connections in active mode"_, _"Open TCP connections in passive mode, with specified
1721
+ remote socket"_ or _"Open TCP connections in passive mode, with unespecified remote
1722
+ socket"_ capability flags is set).
1723
+
1724
+ * ERR_NO_CONN
1725
+
1726
+ There is no connection open with the specified number.
1727
+
1728
+ ### 4.5.7. TCPIP_TCP_DISCARD: Discard data in the output buffer of a TCP connection
1729
+
1730
+ * Input:
1731
+ * A = 19
1732
+ * B = Connection number
1733
+
1734
+ * Output:
1735
+ * A = Error code
1736
+
1737
+ This routine discards all data in the output buffer of a TCP connection, that is, removes from the
1738
+ appropriate output buffer the data that has been enqueued to be sent by
1739
+ [TCPIP_TCP_SEND](#455-tcpip_tcp_send-send-data-a-tcp-connection) but has not been sent yet.
1740
+
1741
+ **ERROR CODES**
1742
+
1743
+ * ERR_OK
1744
+
1745
+ The data has been successfully retrieved.
1746
+
1747
+ * ERR_NOT_IMP
1748
+
1749
+ - The implementation does not support TCP connections at all (none of the _"Open TCP
1750
+ connections in active mode"_, _"Open TCP connections in passive mode, with specified
1751
+ remote socket"_ or _"Open TCP connections in passive mode, with unespecified remote
1752
+ socket"_ capability flags is set).
1753
+ - The "Discard data in the output buffer of a TCP connection" capability flag is not set.
1754
+
1755
+ * ERR_NO_CONN
1756
+
1757
+ There is no connection open with the specified number.
1758
+
1759
+ ### 4.6. Raw IP connections related routines
1760
+
1761
+ These routines allow to send and receive data by using a transport protocol which is not
1762
+ TCP nor UDP. This is achieved by opening a raw IP connection for a given protocol code.
1763
+ When sending data, the implementation will add a IP header with the given protocol
1764
+ code and the specified destination IP address to the supplied block of data, and the
1765
+ result will be sent as a IP datagram; receiving data works by the implementation
1766
+ capturing and enqueueing all incoming datagrams having the given protocol specified in
1767
+ the IP header, and returning them when the client application requests them.
1768
+
1769
+ Raw IP connections are identified by connection numbers, which may be any number in
1770
+ the range 1 to 254. The numbers actually used depend on the implementation; client
1771
+ applications should handle these numbers as opaque values.
1772
+
1773
+ There is a "intended connection lifetime" parameter that is to be specified when opening
1774
+ the connection: _transient_, which means that the connection is intended to be closed
1775
+ when the client application finishes; and _resident_, which means that the connection is
1776
+ intended to be used by a resident program. The only behavioral difference between
1777
+ these two modes as far as this specification is concerned, is that all open transient
1778
+ connections are closed when [TCPIP_RAW_CLOSE](#462-tcpip_raw_close-close-a-raw-ip-connection) is invoked and zero is specified as the
1779
+ connection number, being the resident connections unaffected.
1780
+
1781
+ ### 4.6.1. TCPIP_RAW_OPEN: Open a raw IP connection
1782
+
1783
+ * Input:
1784
+ * A = 20
1785
+ * B = Transport protocol code
1786
+ * C = Intended connection lifetime:
1787
+ * 0: Transient
1788
+ * 1: Resident
1789
+
1790
+ * Output:
1791
+ * A = Error code
1792
+ * B = Connection number
1793
+
1794
+ This routine opens a raw IP connection for the specified transport protocol code. This
1795
+ process does not imply any type of negotiation or data exchange with any remote host;
1796
+ all that happens is that a connection number is associated with the protocol code.
1797
+
1798
+ While the connection is open, the implementation will capture and enqueue all the
1799
+ incoming datagrams that have the specified value in the protocol field; the client
1800
+ application can retrieve them by using the [TCPIP_RAW_RCV](#465-tcpip_raw_rcv-retrieve-an-incoming-raw-ip-datagram) routine. Also, it is possible
1801
+ to send datagrams which will have the specified value in the protocol field of the IP
1802
+ header by using the [TCPIP_RAW_SEND](#464-tcpip_raw_send-send-a-raw-ip-datagram) routine, and to close the connection by using
1803
+ [TCPIP_RAW_CLOSE](#462-tcpip_raw_close-close-a-raw-ip-connection). These routines expect the connection number returned by
1804
+ [TCPIP_RAW_OPEN](#461-tcpip_raw_open-open-a-raw-ip-connection) as an input parameter.
1805
+
1806
+ If the transport protocol code for TCP, UDP or ICMP is specified, the implementation
1807
+ behavior is undefined. It could capture only the packets that are not associated to any
1808
+ open TCP or UDP connection, or it could effetively capture all the incoming datagrams for
1809
+ the specified protocol and render all open connections for that protocol useless.
1810
+ It is not possible to open more than one connection for the same protocol code.
1811
+
1812
+ **ERROR CODES**
1813
+
1814
+ * ERR_OK
1815
+
1816
+ The connection has been successfully open. The returned connection number is valid.
1817
+
1818
+ * ERR_NOT_IMP
1819
+
1820
+ The _"Open raw IP connections"_ capability flags is not set. The implementation does not
1821
+ support raw IP connections.
1822
+
1823
+ * ERR_CONN_EXISTS
1824
+
1825
+ A raw IP connection for the specified protocol already exists.
1826
+
1827
+ * ERR_NO_FREE_CONN
1828
+
1829
+ There are no free raw IP connections available.
1830
+
1831
+ ### 4.6.2. TCPIP_RAW_CLOSE: Close a raw IP connection
1832
+
1833
+ * Input:
1834
+ * A = 21
1835
+ * B = Connection number, 0 to close all open transient UDP connections
1836
+
1837
+ * Output: A = Error code
1838
+
1839
+ This routine closes the specified raw IP connection. This process does not imply any type
1840
+ of negotiation or data exchange with any remote host; all that happens is that the
1841
+ connection number is freed and all the pending incoming datagrams for the connection
1842
+ are discarded. Also, the implementation will stop capturing datagrams with the protocol
1843
+ number associated to the connection in the IP header.
1844
+
1845
+ All the existing connections that were open in "transient" lifetime mode are closed if zero
1846
+ is specified as the connection number.
1847
+
1848
+ **ERROR CODES**
1849
+
1850
+ * ERR_OK
1851
+
1852
+ The connection has been closed successfully.
1853
+
1854
+ * ERR_NOT_IMP
1855
+
1856
+ The _"Open raw IP connections"_ capability flags is not set. The implementation does not
1857
+ support raw IP connections.
1858
+
1859
+ * ERR_NO_CONN
1860
+
1861
+ There is no connection open with the specified number.
1862
+
1863
+ ### 4.6.3. TCPIP_RAW_STATE: Get the state of a raw IP connection
1864
+
1865
+ * Input:
1866
+ * A = 22
1867
+ * B = Connection number
1868
+
1869
+ * Output:
1870
+ * A = Error code
1871
+ * B = Associated protocol code
1872
+ * HL = Number of pending incoming datagrams
1873
+ * DE = Size of the oldest pending incoming datagram
1874
+
1875
+ This routine retrieves information about the raw connection with the specified number.
1876
+
1877
+ _"Number of pending incoming datagrams"_ indicates how many datagrams whose
1878
+ protocol code in the IP header matches the connection's associated protocol code have
1879
+ been received and cached by the implementation; these datagrams can be retrieved by
1880
+ using the [TCPIP_RAW_RCV](#465-tcpip_raw_rcv-retrieve-an-incoming-raw-ip-datagram) routine. Implementations are required to have buffer space
1881
+ for only one incoming IP datagram per connection, but may optionally have space for
1882
+ more. Datagrams received when this buffer is full are silently discarded.
1883
+
1884
+ _"Size of oldest pending datagram"_ indicates the size of the data part of the datagram
1885
+ that will be retrieved by the next call to [TCPIP_RAW_RCV](#465-tcpip_raw_rcv-retrieve-an-incoming-raw-ip-datagram). It is zero if the datagram
1886
+ contains no data apart from the IP header itself, and contains no meaningful information
1887
+ if there are no pending datagrams (that is, if B=0 is returned).
1888
+
1889
+ **ERROR CODES**
1890
+
1891
+ * ERR_OK
1892
+
1893
+ The requested information has been retrieved.
1894
+
1895
+ * ERR_NOT_IMP
1896
+
1897
+ The _"Open raw IP connections"_ capability flags is not set. The implementation does not
1898
+ support raw IP connections.
1899
+
1900
+ * ERR_NO_CONN
1901
+
1902
+ There is no connection open with the specified number.
1903
+
1904
+ ### 4.6.4. TCPIP_RAW_SEND: Send a raw IP datagram
1905
+
1906
+ * Input:
1907
+ * A = 23
1908
+ * B = Connection number
1909
+ * HL = Address of datagram data
1910
+ * DE = Address of parameters block
1911
+
1912
+ * Output:
1913
+ * A = Error code
1914
+
1915
+ This routine sends a block of data in the form of an IP datagram. The implementation
1916
+ will prepend the passed data block with a IP header composed from the protocol code
1917
+ associated to the connection and the data in the parameters block. The format of the
1918
+ parameters block is as follows:
1919
+
1920
+ * +0 (4): Destination IP address
1921
+ * +4 (2): Data length
1922
+
1923
+ The maximum allowed value for the datagram data length is equal to the maximum
1924
+ outgoing datagram size supported, minus 20 (the size of the IP header).
1925
+
1926
+ Implementations are expected to send the datagram immediately. At most, the routine
1927
+ can block while waiting for another datagram transmission in progress to finish; or the
1928
+ datagram can be cached to be sent at a later time, provided that the time between
1929
+ routine invocation and actual datagram send is very small (unnoticeable for the user).
1930
+
1931
+ **ERROR CODES**
1932
+
1933
+ * ERR_OK
1934
+
1935
+ The datagram has been sent.
1936
+
1937
+ * ERR_NOT_IMP
1938
+
1939
+ The _"Open raw IP connections"_ capability flags is not set. The implementation does not
1940
+ support raw IP connections.
1941
+
1942
+ * ERR_NO_CONN
1943
+
1944
+ There is no connection open with the specified number.
1945
+
1946
+ * ERR_NO_NETWORK
1947
+
1948
+ No network connectivity is currently available.
1949
+
1950
+ * ERR_LARGE_DGRAM
1951
+
1952
+ The data length specified in the parameters block is larger than the maximum outgoing
1953
+ datagram size supported minus 20.
1954
+
1955
+ ### 4.6.5. TCPIP_RAW_RCV: Retrieve an incoming raw IP datagram
1956
+
1957
+ * Input:
1958
+ * A = 24
1959
+ * B = Connection number
1960
+ * HL = Address for datagram data
1961
+ * DE = Maximum data size to retrieve
1962
+
1963
+ * Output:
1964
+ * A = Error code
1965
+ * L.H.E.D = Source IP address
1966
+ * BC = Actual received data size
1967
+
1968
+ This routine retrieves the data part and information parameters of the oldest received IP
1969
+ datagram for the given connection, and removes the datagram from the
1970
+ implementation's internal buffer. Implementations are required to have buffer space for
1971
+ only one incoming IP datagram per connection, but may optionally have space for more.
1972
+ Datagrams received when this buffer is full are silently discarded.
1973
+
1974
+ The data part of the datagram, without the IP header, will be copied to the address
1975
+ pointed by HL. The entire datagram data part will be copied if its length is smaller or
1976
+ equal than the "maximum data size" parameter passed in DE; otherwise, only the first
1977
+ DE bytes will be copied and the rest of the datagram data will be discarded (DE=FFFFh
1978
+ can be specified with the meaning of "get the whole datagram"). No data will be copied
1979
+ at all if DE=0. Remember that it is possible to check the datagram data size in advance
1980
+ by using [TCPIP_RAW_STATE](#463-tcpip_raw_state-get-the-state-of-a-raw-ip-connection).
1981
+
1982
+ Information about the originator of the datagram will be returned in registers HL and DE.
1983
+ Register BC will contain the datagram data size as it was received, which may be larger
1984
+ than the number of bytes actually retrieved.
1985
+
1986
+ **ERROR CODES**
1987
+
1988
+ * ERR_OK
1989
+
1990
+ The datagram data and information has been retrieved.
1991
+
1992
+ * ERR_NOT_IMP
1993
+
1994
+ The _"Open raw IP connections"_ capability flags is not set. The implementation does not
1995
+ support raw IP connections.
1996
+
1997
+ * ERR_NO_CONN
1998
+
1999
+ There is no connection open with the specified number.
2000
+
2001
+ * ERR_NO_DATA
2002
+
2003
+ There are no pending incoming datagrams for the specified connection.
2004
+
2005
+ ### 4.7. Configuration related routines
2006
+
2007
+ These routines allow to configure various working parameters of the implementation.
2008
+
2009
+ ### 4.7.1. TCPIP_CONFIG_AUTOIP: Enable or disable the automatic IP addresses retrieval
2010
+
2011
+ * Input:
2012
+ * A = 25
2013
+ * B = action to perform:
2014
+ * 0: Get current configuration
2015
+ * 1: Set configuration
2016
+ * C = Configuration to set (only if B=1):
2017
+ * bit 0: Set to automatically retrieve local IP address, subnet mask and default gateway
2018
+ * bit 1: Set to automatically retrieve DNS servers addresses
2019
+ * bits 2-7: Unused, must be zero
2020
+
2021
+ * Output:
2022
+ * A = Error code
2023
+ * C = Configuration after the routine execution (same format as C at input)
2024
+
2025
+ This routine configures how the various IP addresses used by the system should be
2026
+ obtained. Two groups of addresses can be configured sepparately: the first group is
2027
+ composed of the local IP address, the subnet mask and the default gateway address (the
2028
+ latter two are ignored when they make no sense for the implementation, for example in
2029
+ case of a PPP link); the second group is composed of the primary and secondary DNS
2030
+ server addresses.
2031
+
2032
+ This routine is intended to be called in two scenarios:
2033
+
2034
+ - To set "automatic" when the current setting is "manual" and all the involved addresses
2035
+ are 0.0.0.0. In this case, the implementation must try to automatically obtain the
2036
+ addresses from a remote source (tipically a DHCP server); in case of failure in this
2037
+ procedure, the involved addresses must remain to 0.0.0.0. The implementation should
2038
+ retry the address retrieval procedure a reasonable number of times because giving out in
2039
+ case of failure.
2040
+ - To set "manual" when the current setting is "automatic" and no IP addresses have
2041
+ been obatined yet (that is, the involved addresses are still 0.0.0.0).
2042
+
2043
+ Behavior in other cases in undefined. In particular:
2044
+
2045
+ - When changing from "manual" to "automatic" and the involved IP addresses already
2046
+ have a value, the implementation may either discard the addresses values and start the
2047
+ address retrieval procedure, or use the already configured addresses as if they were
2048
+ obtained automatically.
2049
+ - When changing from "automatic" to "manual" and the involved IP addresses already
2050
+ have a value, the implementation may either maintain the obtained addresses or reset
2051
+ them to 0.0.0.0.
2052
+
2053
+ Addresses on a group not set to automatic retrieving are expected to be manually set by
2054
+ the user, by using the [TCPIP_CONFIG_IP](#472-tcpip_config_ip-manually-configure-an-ip-address)S routine,
2055
+ after the implementation is installed/initialized; otherwise they will remain with the value 0.0.0.0 indefinitely.
2056
+
2057
+ Implementations supporting automatic address retrieval should default to automatically
2058
+ retrieve all addresses when installed/initialized.
2059
+
2060
+ **ERROR CODES**
2061
+
2062
+ * ERR_OK
2063
+
2064
+ The setting has been successfully changed or the current setting has been returned.
2065
+
2066
+ * ERR_NOT_IMP
2067
+
2068
+ * B=1 and C:0 is set, but the _"Automatically obtain the local IP address, subnet mask and default gateway,
2069
+ by using DHCP or an equivalent protocol"_ capability flag is not set. The
2070
+ implementation does not support automatical retrieval of these addresses.
2071
+
2072
+ * B=1 and C:1 is set, but the _"Automatically obtain the IP addresses of the DNS servers,
2073
+ by using DHCP or an equivalent protocol"_ capability flag is not set. The
2074
+ implementation does not support automatical retrieval of these addresses.
2075
+
2076
+ * ERR_INV_PAR
2077
+
2078
+ An invalid value for B or C has been specified at input.
2079
+
2080
+ ### 4.7.2. TCPIP_CONFIG_IP: Manually configure an IP address
2081
+
2082
+ * Input:
2083
+ * A = 26
2084
+ * B = Index of address to set:
2085
+ * 1: Local IP address
2086
+ * 2: Peer IP address
2087
+ * 3: Subnet mask
2088
+ * 4: Default gateway
2089
+ * 5: Primary DNS server IP address
2090
+ * 6: Secondary DNS server IP address
2091
+ * L.H.E.D = Address value
2092
+
2093
+ * Output:
2094
+ * A = Error code
2095
+
2096
+ This routine allows to manually set the value of one of the IP addresses used by the
2097
+ system. The addresses group of the involved address should have been previously
2098
+ configured as "manual setting" (see [TCPIP_CONFIG_AUTOIP](#471-tcpip_config_autoip-enable-or-disable-the-automatic-ip-addresses-retrieval) routine),
2099
+ otherwise the behavior is undefined.
2100
+
2101
+ The addresses are supplied in the format L.H.E.D. For example, 1.2.3.4 would be
2102
+ specified as HL=0201h, DE=0403h.
2103
+
2104
+ All addresses should default to 0.0.0.0 when the implementation is installed/initialized,
2105
+ unless the implementation installer provides a mechanism to explicitly set the IP
2106
+ addresses at install time.
2107
+
2108
+ This routine is intended to be invoked when the address is configured for manual setting
2109
+ (see the [TCPIP_CONFIG_AUTOIP](#471-tcpip_config_autoip-enable-or-disable-the-automatic-ip-addresses-retrieval) routine).
2110
+ If invoked then the address is configured for
2111
+ automatic retrieval, the behavior is undefined: the implementation may either replace
2112
+ the obtained address with the one supplied, or may simply ignore the routine call and
2113
+ preserve the previous address.
2114
+
2115
+ Note that it is possible for an address to not being configurable neither manually with this routine
2116
+ nor automatically via DCHP or a similar mechanism (see [TCPIP_CONFIG_AUTOIP](#471-tcpip_config_autoip-enable-or-disable-the-automatic-ip-addresses-retrieval)).
2117
+ In this case the implementation decides by itself the value of that address at install time,
2118
+ and from the point of view of client applications it's a hardcoded address.
2119
+
2120
+ **ERROR CODES**
2121
+
2122
+ * ERR_OK
2123
+
2124
+ The address has been successfully set.
2125
+
2126
+ * ERR_NOT_IMP
2127
+
2128
+ The associated _"Manually set the ... IP address"_ capability flag is not set.
2129
+ The implementation does not support automatical retrieval of the specified address.
2130
+
2131
+ * ERR_INV_PAR
2132
+
2133
+ An invalid value for B has been specified at input, or the specified address type does not
2134
+ make sense for the implementation (for example the subnet mask or the default
2135
+ gateway when the link layer protocol is PPP, or the peer address on an Ethernet
2136
+ network).
2137
+
2138
+ ### 4.7.3. TCPIP_CONFIG_TTL: Get/set the value of TTL and TOS for outgoing datagrams
2139
+
2140
+ * Input:
2141
+ * A = 27
2142
+ * B = Action to perform:
2143
+ * 0: Get current values
2144
+ * 1: Set values
2145
+ * D = New value for TTL (only if B=1)
2146
+ * E = New value for ToS (only if B=1)
2147
+
2148
+ * Output:
2149
+ * A = Error code
2150
+ * D = Value of TTL after the routine execution
2151
+ * E = Value of ToS after the routine execution
2152
+
2153
+ This routine gets or sets the value of the TTL (Time to live) and ToS (Type of service)
2154
+ that are used by the implementation for all the outgoing datagrams. These values apply
2155
+ to all datagrams, it is not possible to set the value per datagram, per connection or per
2156
+ protocol.
2157
+
2158
+ It is not possible to change only the TTL or only the ToS. If only one of the values is to
2159
+ be changed, then the routine must be called with B=0, the desired value must be
2160
+ changed (D or E), and then the routine must be called with B=1.
2161
+
2162
+ Implementations should default to TTL=64 and ToS=0 when installed/initialized whenever possible.
2163
+
2164
+ **ERROR CODES**
2165
+
2166
+ * ERR_OK
2167
+
2168
+ The values have been successfully set or obtained.
2169
+
2170
+ * ERR_INV_PAR
2171
+
2172
+ An invalid value for B has been specified at input.
2173
+
2174
+ * ERR_NOT_IMP
2175
+
2176
+ * B=0 at input but the _"Get the TTL and ToS used for outgoing datagrams"_ capability flag is not set.
2177
+ The implementation does not support reading these values.
2178
+
2179
+ * B=1 at input but the _"Explicitly set the TTL and ToS for outgoing datagrams"_ capability
2180
+ flags is not set. The implementation does not support explicitly setting these values.
2181
+
2182
+ ### 4.7.4. TCPIP_CONFIG_PING: Get/set the automatic PING reply flag
2183
+
2184
+ * Input:
2185
+ * A = 28
2186
+ * B = Action to perform:
2187
+ * 0: Get current flag value
2188
+ * 1: Set flag value
2189
+ * C = New flag value (only if B=1):
2190
+ * 0: Off
2191
+ * 1: On
2192
+
2193
+ * Output:
2194
+ * A = Error code
2195
+ * C = Flag value after the routine execution
2196
+
2197
+ This routine gets or sets the value of the automatic PING reply flag. When it is ON, ICMP
2198
+ echo request messages (PING requests) received by the implementation are
2199
+ automatically replied (an ICMP echo reply message is sent in response, immediately or
2200
+ as soon as possible). When it is OFF, ICMP echo request messages received are ignored.
2201
+
2202
+ If this flag cannot be changed by the user (because PING requests are always replied or
2203
+ always ignored), this routine must return ERR_NOT_IMP when invoked with B=1, but
2204
+ must still return the appropriate flag value when invoked with B=0.
2205
+
2206
+ The value of this flag should default to ON (if supported) when the implementation is
2207
+ installed/initialized.
2208
+
2209
+ **ERROR CODES**
2210
+
2211
+ * ERR_OK
2212
+
2213
+ The flag value has been successfully set or obtained.
2214
+
2215
+ * ERR_NOT_IMP
2216
+
2217
+ B=1 at input but the _"Explicitly set the automatic reply to PINGs on or off"_ capability
2218
+ flags is not set. The implementation does not support explicitly changing the flag value.
2219
+
2220
+ * ERR_INV_PAR
2221
+
2222
+ An invalid value for B or C has been specified at input.
2223
+
2224
+ ### 4.8. Miscellaneous routines
2225
+
2226
+ These routines perform various tasks on the implementation.
2227
+
2228
+ ### 4.8.1. TCPIP_WAIT: Wait for a processing step to run
2229
+
2230
+ * Input:
2231
+ * A = 29
2232
+
2233
+ * Output:
2234
+ * A = Error code
2235
+
2236
+ Implementations of the TCP/IP UNAPI specification are expected to be resident
2237
+ programs, that is, software that runs in background, aside from the user's code running
2238
+ in foreground.
2239
+
2240
+ Usually, and especially for implementations which are not assisted by external hardware,
2241
+ the "run in background" behavior is achieved by hooking to the standard 50 or 60Hz
2242
+ timer interrup available on the MSX system. The TCP/IP processing (retrieving
2243
+ datagrams, processing them, sending new datagrams, updating timers, and so on) is
2244
+ then done in "processing steps", one per timer interrupt, in which a series of operations
2245
+ are performed depending on the available incoming datagrams and the state of timers
2246
+ and other internal variables.
2247
+
2248
+ Since the timer interrupts may happen at any moment, implementations need to take in
2249
+ account the case in which the interrupt happens in the middle of the execution of one of
2250
+ the exposed routines, so that the processing done during the interrupt does not conflict
2251
+ with the (possibly half-done) processing performed by the routine, especially when the
2252
+ internal state of the implementation is modified by the routine.
2253
+
2254
+ The easiest way to avoid such conflicts is to simply set a flag when one of the exposed
2255
+ routines starts its execution, and to reset it when the routine execution finishes. Then,
2256
+ when the implementation's timer interrupt service routine starts, it checks the flag, and
2257
+ when it is set, the processing step is delayed to the next timer interrupt.
2258
+
2259
+ This poses a problem: if the client software executes implementation routines in quick
2260
+ succession (for example, inside a loop that waits for incoming data from a connection),
2261
+ then no processing steps may be done in a long time, which can result in data loss or
2262
+ other misbehavior of the implementation.
2263
+
2264
+ The [TCPIP_WAIT](#481-tcpip_wait-wait-for-a-processing-step-to-run) routine helps to solve this problem. On implementations that perform
2265
+ its internal processing in processing steps, this routine should block until the next
2266
+ processing step is finished. Client applications that repeatedly execute implementation
2267
+ routines in a loop should call this routine once per loop iteration, to ensure that the
2268
+ implementation's processing steps are performed.
2269
+
2270
+ On implementations that do not perform work based on processing steps (for example
2271
+ implementations whose processing is done entirely by external hardware and are
2272
+ therefore not tied to the timer interrupt), this routine can simply do nothing.
2273
+ This routine should return with interrupts enabled.
2274
+
2275
+ **Note for implementors:** The easiest way to implement this routine is to look at the two
2276
+ byte system variable stored at address FC9Eh. The value of this variable changes
2277
+ whenever a timer interrupt occurs. Thus, it is enough to continuously look at the variable
2278
+ value until it changes. Here is a sample implementation of this concept:
2279
+
2280
+ ```
2281
+ TIMER: equ 0FC9Eh
2282
+
2283
+ WAIT:
2284
+ ei
2285
+ ld de,(PREV_TIMER)
2286
+ WAIT2:
2287
+ ld hl,(TIMER)
2288
+ ld (PREV_TIMER),hl
2289
+ ld a,h
2290
+ cp d
2291
+ ret nz
2292
+ ld a,l
2293
+ cp e
2294
+ ret nz
2295
+ jr WAIT2
2296
+
2297
+ PREV_TIMER:
2298
+ dw 0
2299
+ ```
2300
+
2301
+ **ERROR CODES**
2302
+
2303
+ This routine never fails. ERR_OK is always returned.
2304
+
2305
+
2306
+ ## 5. Change log
2307
+
2308
+ This section lists the changes introduced in all the existing versions of the specification.
2309
+
2310
+ ### Version 1.1
2311
+
2312
+ - Added support for TLS on TCP connections:
2313
+ - TLS related capability and feature flags added to [TCPIP_GET_CAPAB](#412-tcpip_get_capab-get-information-about-the-tcpip-capabilities-and-features)
2314
+ - A new flag to request TLS, and an optional field for the server host name, added to the
2315
+ connection parameters block in [TCPIP_TCP_OPEN](#451-tcpip_tcp_open-open-a-tcp-connection)
2316
+ - [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection) now returns a flag
2317
+ that indicates if the connection is using TLS
2318
+ - [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection) defines new
2319
+ TLS related cause reasons
2320
+
2321
+ - `TCPIP_TCP_FLUSH` has been renamed to `TCPIP_TCP_DISCARD` to avoid confussions, since "flush"
2322
+ in the context of data connections usually means "send all the existing data" and not "discard data without sending it".
2323
+
2324
+ - The description of `TCPIP_TCP_SEND` now includes the fact that requesting to send zero bytes is allowed,
2325
+ and results in all the enqueued data being send in the PUSH flag is specified.
2326
+ This was true in v1.0 of the specification too, but not it's explicitly documented.
2327
+
2328
+ - Added bit 15 of the first set of capabilities flags, the entire second set of capabilities flags,
2329
+ bits 9-12 of the first set of features flags, and the WiFi link layer protocol identifier to
2330
+ [TCPIP_GET_CAPAB](#412-tcpip_get_capab-get-information-about-the-tcpip-capabilities-and-features)
2331
+
2332
+ - [TCPIP_SEND_ECHO](#421-tcpip_send_echo-send-icmp-echo-message-ping) is now allowed to ignore the supplied value
2333
+ for TTL, if the _"TTL can be specified in the parameters block of TCPIP_SEND_ECHO"_ capability flag is not set.
2334
+
2335
+ - The _"Automatically obtain the IP addresses, by using DHCP or an equivalent protocol"_ capability flag is now
2336
+ deprecated, replaced by the new two more granular flags in the second flags block.
2337
+
2338
+ - [TCPIP_CONFIG_IP](#472-tcpip_config_ip-manually-configure-an-ip-address) can now return ERR_NOT_IMP
2339
+ if the associated _"Manually set the ... IP address"_ capability flag for the address whose change was attempted
2340
+ is not set.
2341
+
2342
+ - [TCPIP_CONFIG_TTL](#473-tcpip_config_ttl-getset-the-value-of-ttl-and-tos-for-outgoing-datagrams) can now return
2343
+ ERR_NOT_IMP if getting the current values was requested but the _"Get the TTL used for outgoing datagrams"_
2344
+ capability flag is not set.
2345
+
2346
+ - Added an explanation about the _"TCPIP_DNS_Q is a blocking operation"_ feature flag
2347
+ n the description of [TCPIP_DNS_Q](#431-tcpip_dns_q-start-a-host-name-resolution-query).
2348
+
2349
+ - Added an explanation about the _"TCPIP_TCP_OPEN is a blocking operation"_ feature flag,
2350
+ about the _"TLS is supported for TCP connections"_ feature flag and about
2351
+ the ESTABLISHED and CLOSE-WAIT states in the description of [TCPIP_TCP_OPEN](#451-tcpip_tcp_open-open-a-tcp-connection).
2352
+
2353
+ - Added ERR_NO_CONN as a possible error code for [TCPIP_TCP_OPEN](#451-tcpip_tcp_open-open-a-tcp-connection),
2354
+ and a close reason to be returned in C when that error is returned.
2355
+
2356
+ - Added the remark about returning ESTABLISHED state on CLOSE_WAIT with pending incoming data in
2357
+ [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection).
2358
+
2359
+ - Added implementation specific close reasons for [TCPIP_TCP_STATE](#454-tcpip_tcp_state-get-the-state-of-a-tcp-connection).
2360
+
2361
+ - Added the remark about discarding pending incoming data in [TCPIP_TCP_CLOSE](#452-tcpip_tcp_close-close-a-tcp-connection)