Synergy Software Package User's Manual
NetX/NetX Duo HTTP/HTTPS Web Server Framework

NetX Duo Web HTTP/HTTPs Server Introduction

The NetX Duo Web HTTP/HTTPs Server module provides a high-level API for hosting Hyper Text Transport Protocol (HTTP) Server on the web. The HTTP protocol utilizes Transmission Control Protocol (TCP) services to perform its function.  HTTPs is the secure version of the HTTP protocol which uses HTTP on top of the Transport Layer Security (TLS) protocol to secure underlying TCP connection.

HTTP/HTTPs server is implemented on top of NetX Duo IP and NetX Duo Packet Pool. NetX Duo IP attaches itself to appropriate link layer driver such as Ethernet/Wi-Fi/Cellular. Web HTTP server can be started over secure connection and in such case, it uses service provided by NetX Duo TLS Common.

Unsupported Features

NetXDuo HTTPs Server has not been tested on the Cellular CAT1 and Quectel BG96 Cellular Modules.

NetX Duo Web HTTP/HTTPs Server Module Features

  • NetX Web HTTP/HTTPs server is compliant with below RFCs
    • RFC1945 "Hypertext Transfer Protocol/1.0"
    • RFC 2616 "Hypertext Transfer Protocol – HTTP/1.1"
    • RFC 2818 "HTTP over TLS"
    • RFC 2581 "TCP Congestion Control"
    • RFC 1122 "Requirements for Internet Hosts", and related RFCs
  • Multipart support
  • Basic and digest authentication support
  • Custom MIME Support
  • Callback support for several key functions:
    • HTTP Authentication Callback
    • HTTP Request Notify Callback
    • HTTP Invalid Username/Password Callback
    • HTTP Insert GMT Date Header Callback
    • HTTP Cache Info Get Callback
  • Provides option to enable/disable TLS for secure communication using NetX Secure in SSP
NetXD_Web_HTTP_Server_BD.png
NetX Duo Web HTTP/HTTPs Server Module Block Diagram
Note
In the figure above, the NetX Duo Network Driver module has multiple implementation options available. See the description just after the module stack figure in Including the NetX Duo Web HTTP/HTTPs Server Module in an Application for additional details.

NetX Duo Web HTTP/HTTPs Server Module APIs Overview

The NetX Duo Web HTTP/HTTPs Server module defines APIs for creating, deleting, starting, stopping, response sending and getting information for a received HTTP request. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.

NetX Duo Web HTTP/HTTPs Server Module API Summary

Function Name Example API Call and Description
nx_web_http_server_cache_info_callback_set nx_web_http_server_cache_info_callback_set(
NX_WEB_HTTP_SERVER *server_ptr,
UINT (*cache_info_get)(CHAR *resource,
UINT *max_age,
NX_WEB_HTTP_SERVER_DATE *date));
Set the callback to retrieve URL max age and date
nx_web_http_server_callback_data_send nx_web_http_server_callback_data_send(
NX_WEB_HTTP_SERVER *server_ptr,
VOID *data_ptr, ULONG data_length);
Send data from callback function
nx_web_http_server_callback_generate_response_header nx_web_http_server_callback_generate_response_header(
NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET **packet_pptr,
CHAR *status_code, UINT content_length,
CHAR *content_type, CHAR* additional_header);
Create a response header in a callback function
nx_web_http_server_callback_packet_send nx_web_http_server_callback_packet_send(
NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET *packet_ptr);
Send an HTTP packet from callback function
nx_web_http_server_callback_response_send nx_web_http_server_callback_response_send(
NX_WEB_HTTP_SERVER *server_ptr,
CHAR *header,
CHAR *information,
CHAR additional_info);
Send response from callback function
nx_web_http_server_content_get nx_web_http_server_content_get(NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET *packet_ptr,
ULONG byte_offset,
CHAR *destination_ptr,
UINT destination_size,
UINT *actual_size);
Get content from the request
nx_web_http_server_content_get_extended nx_web_http_server_content_get_extended(
NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET *packet_ptr, ULONG byte_offset, CHAR *destination_ptr, UINT destination_size, UINT *actual_size);
Get content from the request/supports zero length Content Length
nx_web_http_server_content_length_get nx_web_http_server_content_length_get(
NX_PACKET *packet_ptr,
UINT *content_length);
Get length of content in the request/supports Content Length of zero value
nx_web_http_server_create nx_web_http_server_create(NX_WEB_HTTP_SERVER *http_server_ptr,
CHAR *http_server_name, NX_IP *ip_ptr, UINT server_port,
FX_MEDIA *media_ptr, VOID *stack_ptr, ULONG stack_size, NX_PACKET_POOL *pool_ptr,
UINT (*authentication_check)(NX_WEB_HTTP_SERVER *server_ptr,
UINT request_type, CHAR *resource, CHAR **name, CHAR **password, CHAR **realm),
UINT (*request_notify)(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr));
Create an HTTP Server instance
nx_web_http_server_delete nx_web_http_server_delete(NX_WEB_HTTP_SERVER *http_server_ptr);
Delete an HTTP Server instance
nx_web_http_server_get_entity_content nx_web_http_server_get_entity_content(
NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET **packet_pptr, ULONG *available_offset, ULONG *available_length);
Retrieve the location and length of entity data
nx_web_http_server_get_entity_header nx_web_http_server_get_entity_header(
NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET **packet_pptr,
UCHAR *entity_header_buffer,
ULONG buffer_size);
Retrieve the contents of entity header
nx_web_http_server_gmt_callback_set nx_web_http_server_gmt_callback_set(
NX_WEB_HTTP_SERVER *server_ptr,
VOID (*gmt_get)(NX_WEB_HTTP_SERVER_DATE *date);
Set the callback to obtain GMT date and time
nx_web_http_server_invalid_userpassword_notify_set nx_web_http_server_invalid_userpassword_notify_set(
NX_WEB_HTTP_SERVER *http_server_ptr,
UINT (*invalid_username_password_callback)
(CHAR *resource, ULONG client_address, UINT request_type));
Set the callback to handle invalid user/password
nx_web_http_server_mime_maps_additional_set nx_web_http_server_mime_maps_additional_set(
NX_WEB_HTTP_SERVER *server_ptr,
NX_WEB_HTTP_SERVER_MIME_MAP *mime_maps,
UINT mime_maps_num);
Set additional MIME maps for HTML
nx_web_http_server_response_packet_allocate nx_web_http_server_response_packet_allocate(
NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET **packet_ptr,
ULONG wait_option);
Allocate a HTTP(S) packet
nx_web_http_server_packet_content_find nx_web_http_server_packet_content_find(
NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET **packet_ptr,
UINT *content_length);
Extract content length and set pointer to start of data
nx_web_http_server_packet_get nx_web_http_server_packet_get(NX_WEB_HTTP_SERVER *server_ptr,
NX_PACKET **packet_ptr);
Receive the next HTTP packet
nx_web_http_server_param_get nx_web_http_server_param_get(NX_PACKET *packet_ptr,
UINT param_number, CHAR *param_ptr,
UINT *param_size, UINT max_param_size);
Get parameter from the request
nx_web_http_server_query_get nx_web_http_server_query_get(NX_PACKET *packet_ptr,
UINT query_number, CHAR *query_ptr, CHAR *query_size,
UINT max_query_size);
Get query from the request
nx_web_http_server_response_chunked_set nx_web_http_server_response_chunked_set(
NX_WEB_HTTP_SERVER *server_ptr,
UINT chunk_size, NX_PACKET *packet_ptr);
Set chunked transfer for HTTP(S) response
nx_web_http_server_secure_configure nx_web_http_server_secure_configure(
NX_WEB_HTTP_SERVER *http_server_ptr,
const NX_SECURE_TLS_CRYPTO *crypto_table,
VOID *metadata_buffer, ULONG metadata_size,
UCHAR* packet_buffer, UINT packet_buffer_size,
NX_SECURE_X509_CERT *identity_certificate,
NX_SECURE_X509_CERT *trusted_certificates[],
UINT trusted_certs_num,
NX_SECURE_X509_CERT *remote_certificates[],
UINT remote_certs_num,
UCHAR *remote_certificate_buffer,
UINT remote_cert_buffer_size);
Configure an HTTP Server to use TLS for secure HTTPS
Note
Parameter crypto_table is a pointer to crypto cipher suite table. Suggested ciphersuite to be used is "nx_crypto_tls_ciphers_synergys7" which is a cipher suite table under NetX in SSP. For further information on Ciphersuite Refer NetX TLS User Manual.
nx_web_http_server_start nx_web_http_server_start(NX_WEB_HTTP_SERVER *http_server_ptr);
Start the HTTP Server
nx_web_http_server_stop nx_web_http_server_stop(NX_WEB_HTTP_SERVER *http_server_ptr);
Stop the HTTP Server
nx_web_http_server_type_get nx_web_http_server_type_get(NX_WEB_HTTP_SERVER *http_server_ptr,
CHAR *name, CHAR *http_type_string,
UINT *string_size);
Extract file type from Client HTTP request
Note
For details on operation and definitions for the function data structures, typedefs, defines, API data, API structures and function variables, review the associated Azure RTOS User's Manual in the References section.

Status Return Values

Name Description
NX_SUCCESS Successful connection of TCP socket.
NX_PTR_ERROR Invalid pointer input.
NX_WEB_HTTP_DATA_END End of request content
NX_WEB_HTTP_POOL_ERROR Invalid payload size in packet pool
NX_CALLER_ERROR Invalid caller of this service.
NX_WEB_HTTP_TIMEOUT HTTP Server timeout in getting
next packet of content
NX_WEB_HTTP_ERROR Internal HTTP Server error.
NX_WEB_HTTP_FAILED Query size too small
NX_CALLER_ERROR Invalid caller of this service
NX_WEB_HTTP_BOUNDARY_ALREADY_FOUND Content for the HTTP server internal multipart markers is already found
NX_WEB_HTTP_NOT_FOUND Entity header field/query not found
NX_NO_PACKET No packet available
NX_WAIT_ABORTED Requested suspension was aborted
NX_WEB_HTTP_INCOMPLETE_PUT_ERROR Improper HTTP header format
NX_INVALID_PARAMETERS Packet size cannot support protocol
NX_WEB_HTTP_IMPROPERLY_TERMINATED_PARAM Request parameter not properly terminated
NX_WEB_HTTP_NO_QUERY_PARSED No query in Client request
NX_NOT_CONNECTED The underlying TCP socket is no longer connected.
NX_SECURE_TLS_UNRECOGNIZED_MESSAGE_TYPE A received TLS message type is incorrect.
NX_SECURE_TLS_UNSUPPORTED_CIPHER Cipher provided by the remote host is not supported.
NX_SECURE_TLS_HANDSHAKE_FAILURE Message processing during the TLS handshake has failed.
NX_SECURE_TLS_HASH_MAC_VERIFY_FAILURE An incoming message failed a hash MAC check.
NX_SECURE_TLS_TCP_SEND_FAILED An underlying TCP socket send failed.
NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH An incoming message had an invalid length field.
NX_SECURE_TLS_BAD_CIPHERSPEC An incoming ChangeCipherSpec message
was incorrect.
NX_SECURE_TLS_INVALID_SERVER_CERT An incoming TLS certificate is unusable for identifying the remote TLS server.
NX_SECURE_TLS_UNSUPPORTED_PUBLIC_CIPHER The public-key cipher provided by the remote host is unsupported
NX_SECURE_TLS_NO_SUPPORTED_CIPHERS The remote host has indicated no ciphersuites that are supported by the NetX Secure TLS stack.
NX_SECURE_TLS_UNKNOWN_TLS_VERSION A received TLS message had an unknown TLS version in its header.
NX_SECURE_TLS_UNSUPPORTED_TLS_VERSION A received TLS message had a known but unsupported TLS version in its header.
NX_SECURE_TLS_ALLOCATE_PACKET_FAILED An internal TLS packet allocation failed.
NX_SECURE_TLS_INVALID_CERTIFICATE The remote host provided an invalid certificate.
NX_SECURE_TLS_ALERT_RECEIVED The remote host sent an alert indicating an error and ending the TLS session.
NX_SECURE_TLS_MISSING_CRYPTO_ROUTINE An entry in the ciphersuite table had a NULL function pointer.
NX_WEB_HTTP_EXTENSION_MIME_DEFAULT Default "text/plain" returned
Note
Lower-level drivers may return common error codes. See SSP User's Manual API References for the associated module for a definition of all relevant status return values.

NetX Duo Web HTTP/HTTPs Server Module Operational Overview

The NetX Duo Web HTTP Server module creates an IP instance that carries out NetX Duo operations and enables it for TCP services in the NetX Duo library; it then creates the Web HTTP Server instance and TCP socket for listening to client requests on configured port number.  The Web HTTP Server requires a packet pool; the module can supply one either by sharing the IP default packet pool (g_packet_pool0) or create a new one. The minimum packet payload is set by the Minimum size of packets in pool property of the Web HTTP Server module. This packet pool is used by the Web HTTP Server only to transmit packets, so the packet pool size and payload can be optimized on the expected size and number of HTTP Server packets sent out.

The NetX Duo Web HTTP Server supports both IPv4 and IPv6 connections. If the HTTP Server has clients desiring to connect over IPv6, make sure the NetX Duo IPv6 Support property is enabled in the NetX Duo Source element. It may be necessary to enable ICMPv6 checksum computation for the underlying ICMPv6 protocols. To do so, set the Checksum computation support on transmitted ICMPv6 packets and Checksum computation support on received ICMPv6 packets properties of the NetX Duo Source element to Enabled. (If the host hardware automatically computes ICMPv6 checksums, these can be left disabled.) Make sure the IPv6 Global Address of the Client host is set in the IP instance element. Thereafter, the NetX Duo does the necessary processing to enable IPv6 and ICMPv6 services required for IPv6 underlying protocols. 

The NetX Duo Web HTTP Server is also designed for use with the FileX embedded file system.

The NetX Duo Web HTTP/HTTPs server module can be used in the normal mode or secure mode

NetX Duo Web HTTP/HTTPs server module Normal Mode Operational Description

In normal mode, the communication between HTTP client and server is not secure.

Netx Duo Web HTTP/HTTPs server module Secure Mode Operational Description

In Secure mode, the communication between HTTP client and server is secured using the TLS protocol. In the thread pane, TLS protocol is represented by "Add NetX Duo TLS common [Optional]" block as shown in the figure below

NetXD_Web_HTTP_Server_TP.png
NetX Duo Web HTTP/HTTPs Server Module Component Thread-Pane View

Adding NetX Duo TLS Common block enables TLS support. The figure below shows the thread pane view of Web HTTP server with TLS support enabled.

NetXD_Web_HTTP_Server_TLS.png
NetX Duo Web HTTP/HTTPs Server Module Component with TLS Support Enabled

NetX Duo Web HTTP Server Responses

When the Web HTTP Server processes the client command, it returns an ASCII response string that includes a 3-digit numeric status code. The numeric response is used by the HTTP Client software to determine whether the operation succeeded or failed. Following is a list of various HTTP Server responses to client commands:

Web HTTP Server responses to client commands

Numeric Field Meaning
200 Request was successful
400 Request was not formed properly
401 Unauthorized request, client needs to send authentication
404 Specified resource in request was not found
500 Internal HTTP Server error
501 Request not implemented by HTTP Server
502 Service is not available

For example, a successful client request to PUT the file test.htm is responded to with the message HTTP/1.0 200 OK.

NetX Duo Web HTTP Authentication

HTTP authentication is optional and is not required for all web requests. There are two types of authentication, basic and digest. Basic authentication is equivalent to the name and password authentication found in many protocols. In HTTP basic authentication, the name and passwords are concatenated and encoded in the base64 format. The main disadvantage of basic authentication is the name and password are transmitted openly in the request, making it easy for the name and password to be stolen. Digest authentication addresses this problem by never transmitting the name and password in the request. Instead, an algorithm is used to derive a 128-bit key or digest from the name, password, and other information. The NetX Web HTTP Server supports the standard MD5 digest algorithm.

The Web HTTP Server authentication callback can decide if a requested resource requires authentication. If authentication is required and the client request did not include the proper authentication, an HTTP/1.0 401 Unauthorized response with the type of authentication required is sent to the client. The client is then expected to form a new request with the proper authentication.

NetX Duo Web HTTP Authentication Callback

The Web HTTP Server authentication callback routine is specified by the Name of Authentication Checking Function property of the HTTP Server Thread. This function is called at the beginning of each HTTP Client request. 

The callback routine provides the NetX Web HTTP Server with the username, password, and realm strings associated with the resource and returns the type of authentication necessary. If no authentication is necessary for the resource, the authentication callback should return the value of NX_WEB_HTTP_DONT_AUTHENTICATE. If basic authentication is required for the specified resource, the routine should return NX_WEB_HTTP_BASIC_AUTHENTICATE.  If MD5 digest authentication is required, the callback routine should return NX_WEB_HTTP_DIGEST_AUTHENTICATE.

The format of the authenticate callback routine is defined as:

UINT nx_web_http_server_authentication_check(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, CHAR **name, CHAR **password, CHAR **realm);

The input parameters are defined as follows:

Input Parameters Definitions

Parameter Meaning
request_type Specifies the HTTP Client request, valid requests are defined as:
NX_WEB_HTTP_SERVER_GET_REQUEST
NX_WEB_HTTP_SERVER_POST_REQUEST
NX_WEB_HTTP_SERVER_HEAD_REQUEST
NX_WEB_HTTP_SERVER_PUT_REQUEST
NX_WEB_HTTP_SERVER_DELETE_REQUEST
resource Specific resource requested.
name Destination for the pointer to the required username.
password Destination for the pointer to the required password.
realm Destination for the pointer to the realm for this authentication.

Name, password, and realm pointers are not used if NX_WEB_HTTP_DONT_AUTHENTICATE is returned by the authentication callback routine. The HTTP Server developer must ensure that the maximum size of the username and password (defined by the Maximum username length and Maximum password length properties of the NetX Duo Web HTTP Common) are large enough for the username and password specified in the authentication callback. These are both defaulted to size 20 characters.

NetX Duo Web HTTP Server Request Notify callback

If a request callback is specified, (the Name of Request Notify Callback Function property of the NetX Web HTTP Server module) the NetX Web HTTP Server forwards requests to the specified function after authentication and validity of the client request is completed without errors. The callback should indicate (by the return status) if no more processing of the client request is required (return status NX_WEB_HTTP_CALLBACK_COMPLETED), if there was an error in the callback processing, (status is non-zero), or the process was completed successfully, and the Web HTTP Server should continue processing the client request.  The format of this callback is:

UINT request_notify(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr);

To disable the request notify callback, set the Name of Request Notify Callback Function property to NULL.

NetX Duo Web HTTP Invalid Username/Password Callback

The optional Invalid Username/Password callback in the NetX Web HTTP Server module is invoked if the HTTP Server receives an invalid username-and-password combination in a client request. To set the Invalid Username/Password callback function, use the nx_web_http_server_invalid_userpassword_notify_set service.

NetX Duo Web HTTP Insert GMT Date Header Callback

The NetX Web HTTP Server supports an optional callback to insert a date header in its response messages. This callback is invoked when the Server responds to a Client PUT or GET request.  To register a GMT date callback with the HTTP Server, the nx_web_http_server_gmt_callback_set service is used.

NetX Duo Web HTTP Cache Info Get Callback

The NetX Web HTTP Server has an optional callback to request the maximum age and date from the HTTP application for a specific resource. This information is used to determine if the HTTP server sends the entire page in response to a Client Get request. If the if modified since in the Client request is not found or does not match the last modified date returned by the get-cache callback, the entire page is sent. To register the callback with the HTTP server nx_web_http_server_cache_info_callback_set service is used.

NetX Duo Web HTTP Multipart Support

Multipurpose Internet Mail Extensions (MIME) was originally intended for the SMTP protocol, but its use has spread to HTTP. MIME allows messages to contain mixed message types (for example, image/jpg and text/plain) within the same message. The NetX Web HTTP Server has added services to determine content type in HTTP messages containing MIME from the client. To enable multipart support, set the Multipart HTTP requests support property of the NetX Web HTTP Server module to enable.

NetX Duo Web HTTP/HTTPs Server Module Important Operational Notes and Limitations

NetX Duo Web HTTP/HTTPs Server Module Operational Notes

  • The NetX Duo Web HTTP Server module requires a FileX media (Block media or USB Mass Storage).  When an HTTP Server stack element is added to the project, an Add FileX box is attached to it. The configurator automatically sets up and initializes the FileX media for the server before the server is started. For more details for configuring FileX, see FileX User's Guide for the Renesas Synergy Platform.
  • The NetX Duo Web HTTP Server also requires a packet pool for transmitting packets. It can share the IP default packet pool or create a separate packet pool.
  • The NetX Duo Web HTTP/HTTPs Server component is added by clicking on the (+) sign in the thread pane window -> Azure RTOS -> NetX Duo -> Protocols -> NetX Duo Web HTTP/HTTPs Server
  • Adding the NetX Duo Web HTTP/HTTPs Server component to a project automatically adds the option to add the NetX Duo TLS component required for secure HTTP server

The NetX Duo Web HTTP/HTTPs Server properties are listed in the following table:

NetXD_Web_HTTP_Server_CP.png
NetX Duo Web HTTP/HTTPs Server Module Component Configurable Properties

In the figure above, "Common" properties are those configurable options in the NetX Duo Web HTTP/HTTPs Server that are common to all instances of the HTTP/HTTPs server in the project. The "Module" properties are specific to each instance of HTTP/HTTPs Server in the project.

NetX Duo Web HTTP/HTTPs Server Module Common Properties

  • Parameter Checking:This option removes the basic HTTP error checking. It is typically used after the application has been debugged. Default value is BSP.
  • HTTPS Support: If defined, this macro enables TLS and HTTPS. Leave undefined to free up resources if only plaintext HTTP is desired. Default value is Disable.
  • FileX Support: This option provides User to select either "FileX Stub", "FileX on USB Mass Storage" or "FileX on Block Media". Default value is Enable.
  • Multipart HTTP requests support: If defined, this option enables HTTP Server to support multipart HTTP requests. Default value is Disable.
  • Server Thread Priority: The priority of the HTTP Server thread. Default value is 16.
  • Server Thread time slicing interval (ticks): The number of timer ticks the Server thread is allowed to run before yielding to threads of the same priority. Default value is 2 ticks.
  • Server socket window size (bytes): Size of the Server TCP socket receive window. Default value is 2048 bytes.
  • Server time out (seconds): Time period for which internal services of server will suspend. Default value is set to 10 seconds (10 * NX_IP_PERIODIC_RATE).
  • Server time out for accept (seconds): Time period for which internal services will suspend for in internal nx_tcp_server_socket_accept() calls. The default value is set to 10 seconds (10 * NX_IP_PERIODIC_RATE).
  • Server time out for disconnect (seconds): Specifies the number of ThreadX ticks that internal services will suspend for in internal nx_tcp_socket_disconnect() calls. The default value is set to 10 seconds (10 * NX_IP_PERIODIC_RATE)
  • Server time out for receive (seconds): Specifies the number of ThreadX ticks that internal services will suspend for in internal nx_tcp_socket_receive() calls. The default value is set to 10 seconds (10 * NX_IP_PERIODIC_RATE)
  • Server time out for send (seconds): Specifies the number of ThreadX ticks that internal services will suspend for in internal nx_tcp_socket_send() calls. The default value is set to 10 seconds (10 * NX_IP_PERIODIC_RATE)
  • Maximum size of header field (bytes): Specifies the maximum size of the HTTP header field. Default value is 256 bytes.
  • Maximum connections in queue: Specifies the number of connections that can be queued for the HTTP Server. The default value is 4 (twice the maximum number of server sessions).
  • Maximum length of resource name: Specifies the length of the resource name. Default value is 40.
  • Number of simultaneous sessions for server: Specifies the number of simultaneous sessions for an HTTP or HTTPS server. A TCP socket and a TLS session (if HTTPS is enabled) are allocated for each session. Default value is 2.
  • Minimum size of packets in pool (bytes): Specifies the minimum size of the packets in the pool specified at Server creation. The minimum size is needed to ensure the complete HTTP header can be contained in one packet. Default value is 600 bytes.
  • Maximum number of queued transmit packets (units): This option specifies the maximum number of packets that can be enqueued on the Server socket re-transmission queue. If the number of packets enqueued reaches this number, no more packets can be sent until one or more enqueued packets are released. Default value is 20 units.
  • Server Socket Re-transmission Timeout (seconds): Timeout for Server socket re-transmission. Default value is 2 seconds.
  • Maximum number of retries per packet: This parameter sets the maximum number of re-transmissions on Server socket. Default value is 10.
  • Server Next Re-transmission timeout shift: This value is used to set the next re-transmission timeout. The current timeout is multiplied by the number of re-transmissions thus far, shifted by the value of the socket timeout shift. Default value is 1 for doubling the timeout

NetX Duo Web HTTP/HTTPs Server Module Properties

  • Name: Name of Web HTTP/HTTPs server instance. Default value is g_web_http_server0
  • Internal Thread stack size (bytes): HTTP Server thread stack size. Used as a parameter while creating web HTTP Server instance. Default value is 4096 bytes
  • TCP listening port for HTTP/HTTPS Server: TCP listening port for secured/unsecured HTTP server instance. Default value is 80.

Note: If user wants to start Web HTTP server in secured mode then user can set the port number accordingly using this property. For example, user can set 443 as port number for secured HTTP server and can set port number as 80 for unsecured HTTP server.

  • Name of authentication checking callback function: Application's authentication checking routine. If specified, this routine is called for each HTTP Client request. If this parameter is NULL, no authentication will be performed. Default value is NULL.
  • Name of request notify callback function: Application's request notify routine. If specified, this routine is called prior to the HTTP server processing of the request. This allows the resource name to be redirected or fields within a resource to be updated prior to completing the HTTP Client request. Default value is NULL.
  • Name of generated initialization function: Name of initialization function under whichweb HTTP Server instance is created. Default value is web_http_server_init0.
  • Auto Initialization: Enable/disable call to initialization function. This determines if the function specified in the Name of Generated Initialization function option is called. If set to Enable, it will invoke this function. Otherwise if set to Disable, the application must call the nx_web_http_server_create() API before using any NetX Web HTTP/HTTPs Server services.

NetX Duo Web HTTP Common Configurable Properties

The common properties are listed in the following table:

NetXD_Web_HTTP_Server_CCP.png
NetX Duo Web HTTP/HTTPs Client Module Component Common Configurable Properties
  • Type of Service: Type of network service required for the HTTP TCP requests. The network service can be of type (Normal, Minimum delay, Maximum data, Maximum reliability, Minimum cost) and the default value is Normal.
  • Fragmentation Option: This enables/disables TCP fragmentation for HTTP client request. The default value is Don't Fragment.
  • MD5 Support: This enables/disables MD5 digest support required for digest authentication. The default value is disable.
  • Time to live: This specifies maximum no. of routers the HTTP packet can pass through before it get discarded. The default is 128.
  • Maximum password length (bytes): This defines the maximum length of client supplied password. The default is 20.
  • The Maximum username length (bytes): This defines the maximum length of client supplied username. The default is 20.

NetX Duo Web HTTP/HTTPs Server Module Limitations

  • TRACE, OPTIONS, and CONNECT HTTP requests are not supported.
  • The HTTP Server supports both basic and MD5 digest authentication, but not MD5-sess.
  • No content compression is supported.
  • The packet pool associated with the HTTP Server must be large enough to hold the complete HTTP header.
  • Request pipelining is not supported

Including the NetX Duo Web HTTP/HTTPs Server Module in an Application

This section describes how to include either or both the NetX Duo Web HTTP/HTTPs Server module in an application using the SSP configurator.

Note
It is assumed you are familiar with creating a project, adding threads, adding a stack to a thread and configuring a block within the stack. If you are unfamiliar with any of these items, refer to the first few chapters of the SSP User's Manual to learn how to manage each of these important steps in creating SSP-based applications.

To add the NetX Duo Web HTTP/HTTPs Server module to an application, simply add it to a thread using the stacks selection sequence given in the following table.

NetX Duo Web HTTP/HTTPs Server Module Selection Sequence

Resource ISDE Tab Stacks Selection Sequence
g_web_http_server0 NetX Duo WebHTTP/HTTPsServer Threads New Stack> X-Ware> NetX Duo> Protocols> NetX Duo Web HTTP/HTTPsServer

When the NetX Duo Web HTTP/HTTPs Server module is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.

 

NetXD_Web_HTTP_Server_MS.png
NetX Duo Web HTTP/HTTPs Server Module Stack

In the stack above, the NetX Duo Network Driver has not been populated yet. There are multiple possible selections for the Network Driver; they are not all provided so as not to needlessly complicate the figure and the following configuration tables. The available options depend on the MCU target, but some typical options include:

  • NetX Duo Port using PPP on nxd_ppp
  • NetX Port ETHER on sf_el_nx
  • NetX Port using Cellular Framework on sf_cellular_nsal_nx
  • NetX Port using PPP on nx_ppp
  • NetX Port using Wi-Fi Framework on sf_wifi_nsal_nx

Additionally, in the stack above, the FileX stack has also not been populated yet. There are multiple possible selections for the FileX module; they are not all provided so as not to needlessly complicate the figure and the following configuration tables. The available options depend on the MCU target, but some typical options include:

  • FileX Stub
  • FileX on Block Media (implemented on Block Media Framework on sf_block_media_ram)
  • FileX on USB Mass Storage (implemented on USBX Host Class Mass Storage)

Configuring the NetX Duo Web HTTP/HTTPs Server Module

The NetX Duo Web HTTP/HTTPs Server module must be configured by the user for the desired operation. The SSP configuration window automatically identifies (by highlighting the block in red) any required configuration selections, such as interrupts or operating modes, which must be configured for lower-level modules for successful operation. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.

Note
You may want to open your ISDE, create the module and explore the property settings in parallel with looking over the following configuration table values. This helps to orient you and can be a useful hands-on approach to learning the ins and outs of developing with SSP.

Configuration Settings for the NetX Duo Web HTTP/HTTPs Server Module

ISDE Property Value Description
Parameter Checking Enable, Disable, BSP

Default: BSP
Selects if code for parameter checking is to be included in the build.
HTTPS Support Enable, Disable

Default: Disable
Select whether to enable HTTPS support.
FileX Support Enable, Disable
Default: Enable
This option provides User to select either "FileX Stub", "FileX on USB Mass Storage" or "FileX on Block Media"
Multipart HTTP requests support Enable, Disable
Default: Disable
Option enables HTTP Server to support multipart HTTP requests
Server Thread Priority 16 Priority of the HTTP Server thread
Server Thread time slicing interval (ticks) 2 Number of timer ticks the Server thread is allowed to run before yielding to threads of the same priority.
Server socket window size (bytes) 2048 Size of the Server TCP socket receive window
Server time out (seconds) 10 Server time out selection
Server time out for accept (seconds) 10 Server time out for accept selection
Server time out for disconnect (seconds) 10 Server time out for disconnect selection
Server time out for receive (seconds) 10 Server time out for receive selection
Server time out for send (seconds) 10 Server time out for send selection
Maximum size of header field (bytes) 256 maximum size of the HTTP header field
Maximum connections in queue 4 Number of connections that can be queued for the HTTP Server
Maximum length of resource name 40 Length of the resource name
Number of simultaneous sessions for server 2 Number of simultaneous sessions for an HTTP or HTTPS server. A TCP socket and a TLS session (if HTTPS is enabled) are allocated for each session.
Minimum size of packets in pool (bytes) 600 Minimum size of the packets in the pool specified at Server creation.
Maximum number of queued transmit packets (units) 20 Specifies the maximum number of packets that can be enqueued on the Server socket re-transmission queue.
Server Socket Re-transmission Timeout (seconds) 2 Timeout for Server socket re-transmission
Maximum number of retries per packet 10 Maximum number of re-transmissions on Server socket.
Server Next Re-transmission timeout shift 1 This value is used to set the next re-transmission timeout. The current timeout is multiplied by the number of re-transmissions thus far, shifted by the value of the socket timeout shift.
Name g_web_http_server0 Name of Web HTTP server instance
Internal Thread stack size (bytes) 4096 HTTP Server thread stack size
TCP listening port for HTTP/HTTPS Server 80 TCP listening port for secured/unsecured HTTP server instance
Name of authentication checking callback function NULL Name of Authentication Checking Function selection
Name of request notify callback function NULL Name of Request notify Function selection
Name of generated initialization function web_http_server_init0 Name of initialization function under which web HTTP Server instance is created
Auto Initialization Enable, Disable

Default: Enable
Auto initialization selection.
Note
The example settings and defaults are for a project using the S5D9 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

In some cases, settings other than the defaults for lower-level modules can be desirable. For example, it might be useful to select different pins for the Ethernet peripheral. The configurable properties for the lower-level stack modules are provided in the following sections for completeness and as a reference. 

Note
Most of the property settings for lower-level modules are intuitive and usually can be determined by inspection of the associated properties window from the SSP configurator.

Configuration Settings for the NetX Duo Web HTTP/HTTPs Server Lower-Level Modules

Only a small number of settings must be modified from the default for the IP layer and lower-level drivers as indicated via the red text in the thread stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and are locked to prevent user modification. The following table identifies all the settings within the properties section for the module:

Configuration Settings for the NetX Duo IP Instance

ISDE Property Value Description
Name g_ip0 Module name
IPv4 Address (use commas for separation) 192,168,0,2 IPv4 Address selection
Subnet Mask (use commas for separation) 255,255,255,0 Subnet Mask selection
Default Gateway Address (use commas for separation) 0,0,0,0 Default gateway address selection
IPv6 Global Address (use commas for separation) 0x2001, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 IPv6 global address selection
IPv6 Link Local Address (use commas for separation, All zeros means use MAC address) 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 IPv6 link local address selection
IP Helper Thread Stack Size (bytes) 2048 IP Helper Thread Stack Size (bytes) selection
IP Helper Thread Priority 3 IP Helper Thread Priority selection
ARP Enable ARP selection
ARP cache storage units Bytes, Entries

Default: Bytes
ARP cache storage units selection
ARP cache size (in storage units) 520 ARP Cache Size in Bytes/Entries selection

Note: 1 Entry = 52 Bytes
Reverse ARP Enable, Disable

Default: Disable
Reverse ARP selection
TCP Enable, Disable

Default: Enable
TCP selection
UDP Enable, Disable

Default: Enable
UDP selection
ICMP Enable, Disable

Default: Enable
ICMP selection
IGMP Enable, Disable

Default: Enable
IGMP selection
IP fragmentation Enable, Disable

Default: Disable
IP fragmentation selection
Name of generated initialization function ip_init0 Name of generated initialization function selection
Auto Initialization Enable, Disable

Default: Enable
Auto initialization function
Link status change callback NULL Link status change callback selection
Note
The example settings and defaults are for a project using the Synergy S5D9 MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the NetX Duo Web HTTP Common Instance

ISDE Property Value Description
Type of Service Normal, Minimum delay, Maximum data, Maximum reliability, Minimum cost

Default: Normal
Type of service selection.
Fragmentation option Don't fragment, Fragment okay

Default: Don't fragment
Fragmentation option selection.
MD5 Support Enable, Disable

Default: Disable
MD5 support selection.
Time to live 128 Time to live selection.
Maximum password length (bytes) 20 Maximum password length in bytes.
Maximum username length (bytes) 20 Maximum username length in bytes.
Note
The example settings and defaults are for a project using the S5D9Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the NetX Duo Common Instance

ISDE Property Value Description
Name of generated initialization function nx_common_init0 Name of generated initialization function selection
Auto Initialization Enable, Disable

Default: Enable
Auto initialization selection
Note
The example settings and defaults are for a project using the S5D9Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the NetX Duo Packet Pool Instance

ISDE Property Value Description
Name g_packet_pool0 Module name
Packet Size in Bytes 1568 Packet size selection
Number of Packets in Pool 16 Number of packets in pool selection
Name of generated initialization function packet_pool_init0 Name of generated initialization function selection
Auto Initialization Enable, Disable

Default: Enable
Auto initialization selection
Note
The example settings and defaults are for a project using the S5D9Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the NetX Duo FileX on Block Media

ISDE Property Value Description
Name g_fx_media0 Module name
Format media during initialization Enable, Disable

Default: Enabled
Enabling this will format the media
File System is on block media True, False

Default: True
Whether or not the media as filesystem support
Volume Name Volume 1 Volume name string
Number of FATs 1 Number of FATs in the media
Directory Entries 256 Number of directory entries in the root directory
Hidden Sectors 0 Number of sectors hidden before this media's boot sector
Total Sectors 3751936 Total number of sectors in the media
Bytes per Sector 512 Number of bytes per sector
Sectors per Cluster 1 Number of sectors in each cluster
Working media memory size 512 Memory allocated for file system
Name of generated initialization function fx_media_init0 Name of generated initialization function selection
Auto Initialization Enable, Disable

Default: Enable
Auto initialization selection
Note
The example settings and defaults are for a project using the S5D9Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the NetX MD5 Instance

ISDE Property Value Description
No configurable properties
Note
The example settings and defaults are for a project using the S5D9 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

Using the NetX Duo Web HTTP/HTTPs Server Module in an Application

Once the module has been configured and the files auto generated, the NetX Web HTTP/HTTPs server module is ready to be used in an application. Note that the auto generated code includes the initialization function with the name specified under the Name of generated initialization function property. This function internally calls the nx_web_http_server_create() API to create a HTTP/HTTPs server instance with the name specified under the Name property. Calls to this initialization function will be enabled or disabled depending on the Auto Initialization property value. Once the server instance is created, the typical steps in using the module in an application are:

  1. Wait for valid IP address using the nx_ip_status_check API.
  2. Start the Web HTTP Server.
    1. If user wants to start a secured HTTP server i.e HTTPS, the application should initialize device certificates by invoking the nx_secure_x509_certificate_initialize() API. The application should then configure an HTTP server to use TLS for secure HTTPS by invoking the nx_web_http_server_secure_configure() API. The application can start HTTPS server by invoking the nx_web_http_server_start() API.
    2. If user wants plain HTTP Server, application can start HTTP server by just invoking nx_web_http_server_start() API.
  3. Handle optional callbacks if registered with the HTTP Server (Authentication Check, Request Notify, GMT set, Cache get and Invalid Username).
    1. The authentication_check callback routine provides the NetX Duo Web HTTP Server with the username, password, and realm strings associated with the resource and return the type of authentication necessary. If this callback is set to NULL, no authentication will be performed.
    2. The request_notify routine is called prior to the HTTP server processing of the request. This allows the resource name to be redirected or fields within a resource to be updated prior to completing the HTTP Client request.
  4. Once the HTTP/HTTPS server is started, HTTP client can send GET/PUT/POST/HEAD/DELETE requests to the Web HTTP/HTTPS server.
  5. The application should invoke nx_web_http_server_stop() to stop the server.
  6. The application should invoke nx_web_http_server_delete () to delete all the resources associated with Web HTTP server instance.

Users do not have to worry about auto-generated code. Auto-generated code is included once the user generates the project after configuring the stack. Users only need to write the user application code in the associated file.

The following figure illustrates common steps in a typical operational flow diagram:

NetXD_Web_HTTP_Server_TA.png
Flow Diagram of a Typical NetX Duo Web HTTP/HTTPs Server Module Application