Network Component  Version 7.19.0
MDK Middleware for IPv4 and IPv6 Networking
Control Interface

Functions to work with the TFTP server. More...

Functions

netStatus netTFTPs_Start (void)
 Start the TFTP server. [thread-safe]. More...
 
netStatus netTFTPs_Stop (void)
 Stop the TFTP server. [thread-safe]. More...
 
bool netTFTPs_Running (void)
 Check if the TFTP server is running. [thread-safe]. More...
 
uint16_t netTFTPs_GetPort (void)
 Get port number of the TFTP server. [thread-safe]. More...
 
netStatus netTFTPs_SetPort (uint16_t port)
 Set port number of the TFTP server. [thread-safe]. More...
 
const char * netTFTPs_GetRootPath (void)
 Retrieve path to the root directory on TFTP server. [thread-safe]. More...
 
netStatus netTFTPs_SetRootPath (const char *path)
 Set path to the root directory on TFTP server. [thread-safe]. More...
 

Description

Functions to work with the TFTP server.

Like all services, the TFTP server is normally started automatically if NET_START_SERVICE is set to 1 in the Net_Config.c configuration file. If it is disabled, the TFTP server needs to be started manually in the user application using netTFTPs_Start. At runtime, it is always possible to stop the TFTP server using the function netTFTPs_Stop. The user application can check for a running server using the netTFTPs_Running function.

To change the port of the TFTP server at runtime, first call netTFTPs_Stop (if the server is running) and then use the netTFTPs_SetPort function. Afterwards, the TFTP server needs to be (re-)started by the application calling netTFTPs_Start.

Code Example

void change_port (uint16_t port) {}
if (netTFTPs_Running() == true) {
}
}

To change the path to a root folder of the TFTP server at runtime, first call netTFTPs_Stop (if the server is running) and then use the netTFTPs_SetRootPath function. Afterwards, the TFTP server needs to be (re-)started by the application calling netTFTPs_Start.

Function Documentation

◆ netTFTPs_GetPort()

uint16_t netTFTPs_GetPort ( void  )

Get port number of the TFTP server. [thread-safe].

Returns
port number.

The function netTFTPs_GetPort returns the port that is used for the TFTP server.

Code Example

printf ("TFTP server is listening on port %d\n", netTFTPs_GetPort ());

◆ netTFTPs_GetRootPath()

const char * netTFTPs_GetRootPath ( void  )

Retrieve path to the root directory on TFTP server. [thread-safe].

Returns
pointer to root path, a null-terminated string.
  • NULL if root folder is disabled in the configuration.

The function netTFTPs_GetRootPath returns the path to the current root directory if TFTP_SERVER_ROOT_ENABLE is set to 1 in the Net_Config_TFTP_Server.h file. If this define is set to 0, the function is not available at runtime and returns NULL.

Code Example

if (netTFTPs_GetRootPath() != NULL) {
printf ("Boot files are stored here: %s\n", netTFTPs_GetRootPath ());
}

◆ netTFTPs_Running()

bool netTFTPs_Running ( void  )

Check if the TFTP server is running. [thread-safe].

Returns
  • true = Server is running.
  • false = Server is not running.

The function netTFTPs_Running checks whether the TFTP server is running. It returns true if the server is up and running.

Code Example (see netTFTPs_SetPort)

◆ netTFTPs_SetPort()

netStatus netTFTPs_SetPort ( uint16_t  port)

Set port number of the TFTP server. [thread-safe].

Parameters
[in]portport number.
Returns
status code that indicates the execution status of the function.

The function netTFTPs_SetPort sets the port that is to be used for the TFTP server. The TFTP server must not run while setting the port. If required, stop it first using netTFTPs_Stop.

The argument port specifies the port number to be used.

Possible netStatus return values:

  • netOK: Port successfully set.
  • netWrongState: TFTP server is running.

Code Example

void change_server_port (uint16_t port) {}
if (netTFTPs_Running() == true) {
}
}

◆ netTFTPs_SetRootPath()

netStatus netTFTPs_SetRootPath ( const char *  path)

Set path to the root directory on TFTP server. [thread-safe].

Parameters
[in]pathnew root path, a null-terminated string.
Returns
status code that indicates the execution status of the function.

The function netTFTPs_SetRootPath sets the path to the root directory of TFTP server if TFTP_SERVER_ROOT_ENABLE is set to 1 in the Net_Config_TFTP_Server.h file. If this define is set to 0, the function is not available at runtime. Root directory specifies a path on a storage device, where the user files are stored.

The argument path is a pointer to the new root path to be set, which is a null-terminated string. The function copies the content of the path to the root path of the TFTP server. The maximum length of the path string is limited to 79 characters.

Possible netStatus return values:

  • netOK: Root path successfully set.
  • netInvalidParameter: Invalid path parameter provided.
  • netWrongState: TFTP server is running.
  • netError: Root path not enabled in the configuration.
Note
When the function ends, the content of path becomes irrelevant and may be discarded.

Code Example

◆ netTFTPs_Start()

netStatus netTFTPs_Start ( void  )

Start the TFTP server. [thread-safe].

Returns
status code that indicates the execution status of the function.

The function netTFTPs_Start starts the TFTP server at runtime. It can be stopped again using netTFTPs_Stop.

Possible netStatus return values:

  • netOK: TFTP server started successfully.
Note
If you set the NET_START_SERVICE to 1 in Net_Config.c, all selected services will be started automatically. Thus, you only need to call this function, if you have either stopped the TFTP server previously using netTFTPs_Stop or have set NET_START_SERVICE to 0.

Code Example (see netTFTPs_SetPort)

◆ netTFTPs_Stop()

netStatus netTFTPs_Stop ( void  )

Stop the TFTP server. [thread-safe].

Returns
status code that indicates the execution status of the function.

The function netTFTPs_Stop stops the TFTP server at runtime. It can be restarted using netTFTPs_Start.

Possible netStatus return values:

  • netOK: TFTP server stopped successfully.

Code Example (see netTFTPs_SetPort)