1.2.2.1 Networking Presentation Layer

The MPLAB Harmony Networking Presentation Layer is an abstracted middleware layer that provides an encrypted channel. There are three interfaces for the layer:

Client - this interface starts a network session and reads and writes clear text data Provider - this interface encrypts the clear text into cipher text, and decrypts cipher text into clear text Transport - this interface transmits and receives the cipher text The linkage to the provider interface is done through function pointers to isolate it from the rest of MPLAB Harmony. This allows for any provider to be used. Please note that Microchip does not supply a commercially licensed TLS provider. wolfSSL (formerly CyaSSL) is supported as a provider for evaluation purposes only.

The transport interface is abstracted to function pointers as well, to allow for any transport to be used. Currently, only the MPLAB Harmony TCP/IP Stack is used as a transport; however, other transports can be created, such as UART transport, which can be used instead.

The MPLAB Harmony Networking Presentation Layer has a Tasks function that is used to continuously call the provider's connect and accept functions until they run to success of failure, thereby hiding this job from the application.

Abstraction Model

NET PRES Abstraction Model

Library Overview

The Library Interface routines are divided into various sub-sections, which address one of the blocks or the overall operation of the Networking Presentation Layer.

Library Interface SectionDescription
System FunctionsProvides "initialize" functions and a "tasks" function for performing general presentation layer tasks.
Socket FunctionsProvides various socket-related functions for the purpose of connecting, flushing, and setting options, among others.
Certificate Store FunctionsProvides certificate-related functions for the purpose of obtaining certificates and keys.

Configuring the Library

The configuration of the Networking Presentation Layer is done as part of the MPLAB Harmony TCP/IP Stack configuration and specific NET_PRES parameters are generated in the configuration.h.

This header file contains the configuration selection for the Networking Presentation Layer. Based on the selections made, the Networking Presentation Layer may support the selected features. These configuration settings will apply to all instances of the Networking Presentation Layer.

This header can be placed anywhere; however, the path of this header needs to be present in the include search path for a successful build. Refer to the TCP/IP Demonstrations Help section for more details.

Library Interface

This section describes the Application Programming Interface (API) functions of the Networking Presentation Layer.

NameDescription
System Functions
NET_PRES_DeinitializeDeinitializes the Network Presentation Layer Instance.
NET_PRES_InitializeInitializes the Network Presentation Layer sub-system with the configuration data.
NET_PRES_ReinitializeReinitializes the instance of the presentation layer.
NET_PRES_TasksMPLAB Harmony tasks function used for general presentation layer tasks.
NET_PRES_StatusProvides the current status of the MPLAB Harmony Networking Presentation Layer.
Socket Functions
NET_PRES_SocketBindBinds a socket to a local address.
NET_PRES_SocketCloseDisconnects an open socket and destroys the socket handle, releasing the associated resources.
NET_PRES_SocketConnectConnects a client socket.
NET_PRES_SocketDiscardDiscards any pending data in the RX FIFO.
NET_PRES_SocketDisconnectDisconnects an open socket.
NET_PRES_SocketEncryptSocketThis function turns an insecure socket into a secure socket. Details: This function will turn an unencrypted socket into an encrypted socket and starts encryption negotiation.
NET_PRES_SocketFlushImmediately transmits all pending TX data.
NET_PRES_SocketGetTransportHandleThis function returns the transport layer handle. Details: This function returns the transport layer handle for a valid socket
NET_PRES_SocketInfoGetObtains information about a currently open socket.
NET_PRES_SocketIsConnectedDetermines whether a socket has an established connection.
NET_PRES_SocketIsNegotiatingEncryptionThis function checks if encryption negotiation is still in progress.
NET_PRES_SocketIsOpenModeSupportedChecks to see if a mode is supported by open.
NET_PRES_SocketIsSecureThis function checks whether a connection is secure.
NET_PRES_SocketLastErrorThis function returns the last error code for this socket. Details: This function will return the last error code that was set for this socket and it will clear the current error code. An error code is set whenever a socket operation fails for some missing functionality, bad parameter, etc.
NET_PRES_SocketOpenOpens a presentation socket.
NET_PRES_SocketOptionsGetAllows the options for a socket such as, current RX/TX buffer size, etc., to be obtained.
NET_PRES_SocketOptionsSetAllows setting options to a socket like adjust RX/TX buffer size, etc.
NET_PRES_SocketPeekReads a specified number of data bytes from the RX buffer/FIFO without removing them from the buffer.
NET_PRES_SocketReadReads an array of data bytes from a socket's RX buffer/FIFO.
NET_PRES_SocketReadIsReadyDetermines how many bytes can be read from the RX buffer.
NET_PRES_SocketRemoteBindBinds a socket to a remote local address.
NET_PRES_SocketSignalHandlerDeregisterDeregisters a previously registered socket signal handler.
NET_PRES_SocketSignalHandlerRegisterRegisters a socket signal handler.
NET_PRES_SocketWasResetSelf-clearing semaphore indicating socket reset.
NET_PRES_SocketWriteTakes a buffer and sends it to the encryption provider.
NET_PRES_SocketWriteIsReadyDetermines how much free space is available in the TX buffer.
Certificate Store Functions
NET_PRES_CertStoreGetCACertsThis function gets the CA certificates from the store,
NET_PRES_CertStoreGetServerCertThis function gets a server certificate and key from the certificate store.
Data Types and Constants
_NET_PRES_EncProviderObjectDefines the data that the presentation layer needs from the provider.
_NET_PRES_TransportObjectDefines the data that the transport layer needs to provide to the Networking Presentation Layer.
NET_PRES_INDEXSets the type for the presentation layer index.
NET_PRES_INIT_DATAInitializes a Presentation layer.
NET_PRES_INST_DATAInitializes a Presentation layer.
NET_PRES_SIGNAL_FUNCTIONMPLAB Harmony Networking Presentation Layer Signal function.
NET_PRES_SIGNAL_HANDLESets the type for the presentation layer signal handle.
NET_PRES_SKT_HANDLE_TSets the type for the presentation layer socket handle.
NET_PRES_ADDRESSNET_PRES address
NET_PRES_EncProviderConnectConnects the function to the provider.
NET_PRES_EncProviderConnectionCloseDefines the close function to the provider.
NET_PRES_EncProviderDeinitDefines the deinitialization function for the provider.
NET_PRES_EncProviderInitDefines the initialization function to the encryption provider.
NET_PRES_EncProviderIsInitializedDetermines whether the encryption provider has been initialized.
NET_PRES_EncProviderObjectDefines the data that the presentation layer needs from the provider.
NET_PRES_EncProviderOpenDefines the open connection function to the provider.
NET_PRES_EncProviderReadDefines the read function to the provider
NET_PRES_EncProviderWriteDefines the write function to the provider.
NET_PRES_EncSessionStatusDefines the enumeration for the state and status of the encrypted portion of a connection.
NET_PRES_SKT_ADDR_TNET_PRES address type
NET_PRES_SKT_ERROR_TNET_PRES error type
NET_PRES_SKT_OPTION_TYPENET_PRES option type
NET_PRES_SKT_PORT_TSets the type for the presentation layer port.
NET_PRES_SKT_TNET_PRES socket type
NET_PRES_TRANS_ADDR_TDefines a generic address structure to pass to the transport layer.
NET_PRES_TRANS_ADDRESS_TYPEDefines the enumeration for the type of address.
NET_PRES_TRANS_OPTION_TDefines the enumeration for the type of options.
NET_PRES_TransBindBinds a socket to a local address.
NET_PRES_TransBoolGeneric function prototype for functions that return a bool.
NET_PRES_TransCloseFunction prototype for functions that closes a socket.
NET_PRES_TransDiscardFunction prototype for functions that clears a socket's RX buffer.
NET_PRES_TransHandlerRegisterFunction prototype that registers a handler with a socket.
NET_PRES_TransOpenOpens a presentation socket.
NET_PRES_TransOptionSets of gets a socket's options.
NET_PRES_TransPeekFunction prototype for functions that peeks on the socket's buffer.
NET_PRES_TransportObjectDefines the data that the transport layer needs to provide to the Networking Presentation Layer.
NET_PRES_TransReadDefines the read function provided by the transport layer.
NET_PRES_TransReadyDefines the ready function provided by the transport layer.
NET_PRES_TransSignalHandlerDeregisterFunction prototype that deregisters a handler with a socket.
NET_PRES_TransSocketInfoGetFunction prototype for functions that gets the information on a socket.
NET_PRES_TransWriteDefines the write function provided by the transport layer.
NET_PRES_INVALID_SOCKETInvalid socket indicator macro.
NET_PRES_CERTSTORE_HThis is macro NET_PRES_CERTSTORE_H.
NET_PRES_ENCRYPTION_PROVIDER_API_HThis is macro NET_PRES_ENCRYPTION_PROVIDER_API_H.
NET_PRES_SOCKET_APIThis is macro NET_PRES_SOCKET_API.
NET_PRES_TRANSPORT_API_HThis is macro NET_PRES_TRANSPORT_API_H.
NET_PRES_HThis is macro NET_PRES_H.
NET_PRES_EncProviderReadReadyDefines the read ready function to the provider
NET_PRES_EncProviderWriteReadyDefines the write ready function to the provider.
NET_PRES_TransIsPortDefaultSecuredChecks to see if a port is encrypted by default.
NET_PRES_EncProviderMaxOutputSizeDefines the maximum output size function to the provider.
NET_PRES_EncProviderOutputSizeDefines the output size function to the provider.