make tftp_* functions for context static + tftp_context
This commit is contained in:
2023-12-09 14:20:21 +01:00
parent 611ce460fb
commit 8a03831d78

View File

@@ -24,7 +24,11 @@ static tftp_custom_file_t virt_file[] = {{.name = "index.txt", .data = NULL, .le
{.name = "virtImage.bmp", .data = NULL, .len = 0, .offset = 0},
{.name = "virtImage.gif", .data = NULL, .len = 0, .offset = 0},
{.name = "virtText.txt", .data = NULL, .len = 0, .offset = 0}};
static void* tftp_open(const char* fname, const char* mode, uint8_t write);
static void tftp_close(void* handle);
static int tftp_read(void* handle, void* buf, int bytes);
static int tftp_write(void* handle, struct pbuf* p);
static struct tftp_context tftpContext_s = {.open = tftp_open, .close = tftp_close, .read = tftp_read, .write = tftp_write};
/**
* @brief tftp custom file functions to set the offset and read the data
* @param[in,out] handle Custom file handles
@@ -109,7 +113,7 @@ size_t tftp_custom_fwrite(const void* buf, size_t bytes, tftp_custom_file_t* han
* @param write Flag indicating read (0) or write (!= 0) access
* @return void* File handle supplied to other functions
*/
void* tftp_open(const char* fname, const char* mode, uint8_t write) {
static void* tftp_open(const char* fname, const char* mode, uint8_t write) {
LOG_INFO(TAG, "Opening %s", fname);
UNUSED(mode);
@@ -133,7 +137,7 @@ void* tftp_open(const char* fname, const char* mode, uint8_t write) {
*
* @param handle The handle to the file to close
*/
void tftp_close(void* handle) {
static void tftp_close(void* handle) {
LOG_INFO(TAG, "closing file");
if (handle == NULL) {
LOG_CRIT(TAG, "handle is null");
@@ -177,7 +181,7 @@ void tftp_close(void* handle) {
* @param bytes Number of bytes to copy to buf
* @return int >= 0: Success; < 0: Error
*/
int tftp_read(void* handle, void* buf, int bytes) {
static int tftp_read(void* handle, void* buf, int bytes) {
int ret = 0;
LOG_INFO(TAG, "reading file");
if (handle == NULL) {
@@ -215,7 +219,7 @@ int tftp_read(void* handle, void* buf, int bytes) {
* In other words, TFTP headers are stripped off.
* @return int >= 0: Success; < 0: Error
*/
int tftp_write(void* handle, struct pbuf* p) {
static int tftp_write(void* handle, struct pbuf* p) {
LOG_INFO(TAG, "Writing file");
tftp_custom_file_t* file = (tftp_custom_file_t*)handle;
if (file == &virt_file[VIRT_IMAGE_BMP] || file == &virt_file[VIRT_IMAGE_GIF] || file == &virt_file[VIRT_TEXT_TXT]) {
@@ -264,8 +268,6 @@ void init_index(void) {
LOG_INFO(TAG, "index.txt created");
}
struct tftp_context tftpContext_s = {.open = tftp_open, .close = tftp_close, .read = tftp_read, .write = tftp_write};
/**
* @brief Initialize tftp server
*/