BeRTOS
Functions
tftp.h File Reference

TFTP protocol implementation. More...

#include <cfg/compiler.h>
#include <lwip/sockets.h>
#include <io/kfile.h>

Go to the source code of this file.

Functions

int tftp_init (TftpSession *ctx, unsigned short port, mtime_t timeout)
 Init a server session.
KFiletftp_listen (TftpSession *ctx, char *filename, size_t len, TftpOpenMode *mode)
 Listen for incoming tftp sessions.

Detailed Description

TFTP protocol implementation.

This module implements a TFTP server with a handy KFile interface. The call to tftp_listen() will block until a client tries to connect, then it returns a KFile. If you want to accept the transfer, start reading from the handle and the transfer will continue. Otherwise, don't access it and immediately call kfile_close(). Close the KFile when you're done.

The usage pattern is as follows:

 // initialize a TFTP session
 tftp_init();
 // start listening for connections
 KFile *f = tftp_listen();
 // now you can check the returned file name
 // and change behaviour at runtime
 if (!strcmp(filename, "firmware.bin"))
     // do something
 else if (!strcmp(filename, "conf.ini"))
     // update the configuration
 kfile_close(f);
Author:
Luca Ottaviano <lottaviano@develer.com>

Definition in file tftp.h.


Function Documentation

int tftp_init ( TftpSession *  ctx,
unsigned short  port,
mtime_t  timeout 
)

Init a server session.

Create a IPv4 session on all addresses and port port.

Parameters:
ctxContext to be initialized as server
portPort to listen incoming connections
timeoutTimeout to be used for tftp connections
Returns:
0 if successful, -1 otherwise

Definition at line 296 of file tftp.c.

KFile* tftp_listen ( TftpSession *  ctx,
char *  filename,
size_t  len,
TftpOpenMode *  mode 
)

Listen for incoming tftp sessions.

Note:
Only write requests are accepted.
Parameters:
ctxInitialized TftpChannel
filenameString to be filled with file name to be written
lenLength of the filename
modeOpen mode for the returned KFile
Returns:
KFile pointer to read from

Definition at line 247 of file tftp.c.