Network Component  Version 6.6
MDK-Professional Middleware for IP Networking
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TFTP Server Routines

TFTP Server Routines enable the transfer of files to a TFTP Client. More...

Functions

void tftp_server_fclose (void *file)
 Close a file previously open in TFTP server.
 
void * tftp_server_fopen (const char *fname, const char *mode)
 Open a file for reading or writing in TFTP server.
 
uint32_t tftp_server_fread (void *file, uint8_t *buf, uint32_t len)
 Read block of data from a file in TFTP server.
 
uint32_t tftp_server_fwrite (void *file, const uint8_t *buf, uint32_t len)
 Write block of data to a file in TFTP server.
 
bool tftp_accept_client (const uint8_t *ip_addr, uint16_t port)
 Accept or deny connection from remote TFTP client.
 

Description

TFTP Server Routines enable the transfer of files to a TFTP Client.

TFTP routines are not reentrant.

Function Documentation

bool tftp_accept_client ( const uint8_t *  ip_addr,
uint16_t  port 
)

Accept or deny connection from remote TFTP client.

Parameters
[in]ip_addrIP address of the remote TFTP client.
[in]portport number of the remote TFTP client.
Returns
  • true = Connection from the remote client is allowed.
  • false = Connection is denied.

The function tftp_accept_client checks if a connection from the remote client is allowed. This enables remote client filtering. You can selectively decide which clients are allowed to connect to the TFTP server.

The argument ip_addr points to a buffer containing the four octets that make up the IP address of the remote machine.

The argument port specifies the port on the remote machine.

The function is in the TFTP_Server_Access.c module.

Note
This function is optional. If it does not exist in the project, the library default function is used. The library default function accepts all remote clients.

Code Example

#include "rl_net.h"
// Accept or deny connection from remote TFTP client.
// If this function is missing, all remote clients are accepted.
bool tftp_accept_client (const uint8_t *ip_addr, uint16_t port) {
/* Example
if (ip_addr[0] == 192 &&
ip_addr[1] == 168 &&
ip_addr[2] == 0 &&
ip_addr[3] == 1) {
// Accept connection.
return (true);
}
// Deny connection.
return (false);
*/
return (true);
}
void tftp_server_fclose ( void *  file)

Close a file previously open in TFTP server.

Parameters
[in]filepointer to the file to close.
Returns
none.

The function tftp_server_fclose closes the file identified by the file stream pointer in the function argument.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the TFTP_Server_FS.c module.

void * tftp_server_fopen ( const char *  fname,
const char *  mode 
)

Open a file for reading or writing in TFTP server.

Parameters
[in]fnamename of the file to open.
[in]modetype of access:
  • "rb" = opens a file for reading.
  • "wb" = opens a file for writing.
Returns
status information:
  • Pointer to an open file or
  • NULL in case of an error.

The function tftp_server_fopen opens a file for reading or writing on the server.

The argument fname specifies the name of the file to open.

The argument mode defines the type of access permitted for the file. It can have one of the following values:

ModeDescription
"rb"Opens the file for reading. If the file does not exist, then the function fails.
"wb"Opens an empty file for writing if the file does not exist. If the file exists already, then the content is cleared.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the TFTP_Server_FS.c module.

uint32_t tftp_server_fread ( void *  file,
uint8_t *  buf,
uint32_t  len 
)

Read block of data from a file in TFTP server.

Parameters
[in]filepointer to the file to read from.
[out]bufblock of memory to write data to.
[in]lenlength of data to read in bytes.
Returns
number of bytes successfully read.

The function tftp_server_fread reads len bytes from the file identified by the file stream pointer in the function argument.

The argument buf is a pointer to the buffer where the function stores the read data.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the TFTP_Server_FS.c module.

Note
The function must read len bytes. The TFTP Server stops reading and closes the file if the return value is less than len bytes.
uint32_t tftp_server_fwrite ( void *  file,
const uint8_t *  buf,
uint32_t  len 
)

Write block of data to a file in TFTP server.

Parameters
[in]filepointer to the file to write to.
[in]bufblock of memory to be written.
[in]lenlength of data to write in bytes.
Returns
number of bytes successfully written.

The function tftp_server_fwrite writes a block of data to the file identified by the file stream pointer.

The argument buf points to the buffer containing the data that is to be written to the file.

The argument len specifies the number of bytes to write to the file.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the TFTP_Server_FS.c module.

Note
The TFTP server stops writing and closes the file if the return value is less than len bytes.