Skip to main content

NetworkControllerApiWrapper Class

NuGet: GHIElectronics.TinyCLR.Devices.Network
Assembly: GHIElectronics.TinyCLR.Devices.Network
Namespace: GHIElectronics.TinyCLR.Devices.Network.Provider

Concrete INetworkControllerProvider backed by the native TinyCLR network HAL (lwIP + mbedTLS).

public sealed class NetworkControllerApiWrapper : INetworkControllerProvider

Constructors

NetworkControllerApiWrapper(NativeApi api)

public NetworkControllerApiWrapper(NativeApi api)

Creates a wrapper bound to the given native network API.

Properties

Api

public NativeApi Api { get; }

The native API this wrapper is bound to.

InterfaceType

public extern NetworkInterfaceType InterfaceType { get; }

Transport type of the interface — Ethernet, WiFi, or PPP. (inherited)

CommunicationInterface

public extern NetworkCommunicationInterface CommunicationInterface { get; }

Physical bus carrying the interface — built-in MAC, SPI, or UART. (inherited)

Methods

Dispose()

public void Dispose()

Releases the native network controller.

SetNetworkLinkConnectedChangedEventEnabled(bool enabled)

public extern void SetNetworkLinkConnectedChangedEventEnabled(bool enabled)

Enables or disables native delivery of link-connected-changed events.

SetNetworkAddressChangedEventEnabled(bool enabled)

public extern void SetNetworkAddressChangedEventEnabled(bool enabled)

Enables or disables native delivery of address-changed events.

Enable()

public extern void Enable()

Brings the interface up. (inherited)

EnableAsync()

public extern void EnableAsync()

Non-blocking variant of Enable that brings the interface up on a background native task.

Disable()

public extern void Disable()

Brings the interface down. (inherited)

Suspend()

public extern void Suspend()

Suspends the interface to a low-power state. (inherited)

Resume()

public extern void Resume()

Resumes a suspended interface. (inherited)

SetAsDefault()

public extern void SetAsDefault()

Promotes this controller's interface to lwIP's default route at the firmware level.

SetInterfaceSettings(NetworkInterfaceSettings settings)

public void SetInterfaceSettings(NetworkInterfaceSettings settings)

Applies the interface settings (IP address, DHCP, DNS). (inherited)

SetCommunicationInterfaceSettings(NetworkCommunicationInterfaceSettings settings)

public void SetCommunicationInterfaceSettings(NetworkCommunicationInterfaceSettings settings)

Applies the underlying physical-bus settings. (inherited)

GetLinkConnected()

public extern bool GetLinkConnected()

Returns true when the physical link is up.

Returns bool

GetIPProperties()

public extern NetworkIPProperties GetIPProperties()

Returns the current IP address, subnet, gateway, and DNS servers.

Returns NetworkIPProperties

GetInterfaceProperties()

public extern NetworkInterfaceProperties GetInterfaceProperties()

Returns interface-specific properties such as the MAC address.

Returns NetworkInterfaceProperties

Create(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)

public extern int Create(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)

Creates a native socket and returns its handle.

Returns int

Close(int socket)

public extern void Close(int socket)

Closes the given socket.

Bind(int socket, SocketAddress address)

public extern void Bind(int socket, SocketAddress address)

Binds the socket to a local address.

Listen(int socket, int backlog)

public extern void Listen(int socket, int backlog)

Places the socket into the listening state with the given backlog.

Accept(int socket)

public extern int Accept(int socket)

Accepts a pending connection and returns the new socket handle.

Returns int

Connect(int socket, SocketAddress address)

public extern void Connect(int socket, SocketAddress address)

Connects the socket to a remote address.

Available(int socket)

public extern int Available(int socket)

Returns the number of bytes available to read on the socket.

Returns int

Poll(int socket, int microSeconds, SelectMode mode)

public extern bool Poll(int socket, int microSeconds, SelectMode mode)

Polls the socket for the given mode within the timeout.

Returns bool

Send(int socket, byte[] buffer, int offset, int count, SocketFlags flags)

public extern int Send(int socket, byte[] buffer, int offset, int count, SocketFlags flags)

Sends data on a connected socket and returns the number of bytes sent.

Returns int

Receive(int socket, byte[] buffer, int offset, int count, SocketFlags flags)

public extern int Receive(int socket, byte[] buffer, int offset, int count, SocketFlags flags)

Receives data on a connected socket and returns the number of bytes read.

Returns int

SendTo(int socket, byte[] buffer, int offset, int count, SocketFlags flags, SocketAddress address)

public extern int SendTo(int socket, byte[] buffer, int offset, int count, SocketFlags flags, SocketAddress address)

Sends data to a specific address and returns the number of bytes sent.

Returns int

ReceiveFrom(int socket, byte[] buffer, int offset, int count, SocketFlags flags, ref SocketAddress address)

public extern int ReceiveFrom(int socket, byte[] buffer, int offset, int count, SocketFlags flags, ref SocketAddress address)

Receives data and reports the sender address; returns the number of bytes read.

Returns int

GetRemoteAddress(int socket, out SocketAddress address)

public extern void GetRemoteAddress(int socket, out SocketAddress address)

Gets the remote address of a connected socket.

GetLocalAddress(int socket, out SocketAddress address)

public extern void GetLocalAddress(int socket, out SocketAddress address)

Gets the local address bound to the socket.

GetOption(int socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue)

public extern void GetOption(int socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue)

Reads a socket option value.

SetOption(int socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue)

public extern void SetOption(int socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue)

Writes a socket option value.

AuthenticateAsClient(int socketHandle, string targetHost, X509Certificate caCertificate, X509Certificate clientCertificate, SslProtocols sslProtocols, SslVerification sslVerification)

public extern int AuthenticateAsClient(int socketHandle, string targetHost, X509Certificate caCertificate, X509Certificate clientCertificate, SslProtocols sslProtocols, SslVerification sslVerification)

Performs a TLS client handshake on the socket and returns the secure handle.

Returns int

AuthenticateAsServer(int socketHandle, X509Certificate certificate, SslProtocols sslProtocols)

public extern int AuthenticateAsServer(int socketHandle, X509Certificate certificate, SslProtocols sslProtocols)

Performs a TLS server handshake on the socket and returns the secure handle.

Returns int

SecureRead(int handle, byte[] buffer, int offset, int count)

public extern int SecureRead(int handle, byte[] buffer, int offset, int count)

Reads decrypted data from a secured connection.

Returns int

SecureWrite(int handle, byte[] buffer, int offset, int count)

public extern int SecureWrite(int handle, byte[] buffer, int offset, int count)

Writes data to a secured connection, encrypting it.

Returns int

GetHostByName(string name, out string canonicalName, out SocketAddress[] addresses)

public extern void GetHostByName(string name, out string canonicalName, out SocketAddress[] addresses)

Resolves a host name to its canonical name and addresses via DNS.

GetAccessPointClientLinkConnect(WiFiNetworkInterfaceSettings settings)

public extern bool GetAccessPointClientLinkConnect(WiFiNetworkInterfaceSettings settings)

Returns true when a station is connected to this access point.

Returns bool

Shutdown(int socket, SocketShutdown how)

public extern void Shutdown(int socket, SocketShutdown how)

Half-closes the socket in the given direction (lwIP shutdown).

Events

NetworkLinkConnectedChanged

public event NetworkLinkConnectedChangedEventHandler NetworkLinkConnectedChanged

Raised when the physical link goes up or down. (inherited)

NetworkAddressChanged

public event NetworkAddressChangedEventHandler NetworkAddressChanged

Raised when the IP address, gateway, or DNS servers change. (inherited)