79 lines
2.0 KiB
C
79 lines
2.0 KiB
C
/*
|
|
* lwftp_mod.c
|
|
*
|
|
* Created on: Feb 14, 2024
|
|
* Author: SeungJu Lim
|
|
*/
|
|
#include <lwftp.h>
|
|
#include <string.h>
|
|
#include "lwip/tcp.h"
|
|
#include "lwip/tcpip.h"
|
|
|
|
/** Enable debugging for LWFTP */
|
|
#ifndef LWFTP_DEBUG
|
|
#define LWFTP_DEBUG LWIP_DBG_ON
|
|
#endif
|
|
|
|
#define LWFTP_TRACE (LWFTP_DEBUG|LWIP_DBG_TRACE)
|
|
#define LWFTP_STATE (LWFTP_DEBUG|LWIP_DBG_STATE)
|
|
#define LWFTP_WARNING (LWFTP_DEBUG|LWIP_DBG_LEVEL_WARNING)
|
|
#define LWFTP_SERIOUS (LWFTP_DEBUG|LWIP_DBG_LEVEL_SERIOUS)
|
|
#define LWFTP_SEVERE (LWFTP_DEBUG|LWIP_DBG_LEVEL_SEVERE)
|
|
|
|
#define LOG_ERROR(format, ...) printf("ERROR: " format "\n", ##__VA_ARGS__)
|
|
#define LOG_TRACE(format, ...) printf("TRACE: " format "\n", ##__VA_ARGS__)
|
|
|
|
#define PTRNLEN(s) s,(sizeof(s)-1)
|
|
|
|
|
|
err_t lwftp_connect(lwftp_session_t *s) {
|
|
err_t error;
|
|
enum lwftp_results retval = LWFTP_RESULT_ERR_UNKNOWN;
|
|
|
|
// Check user supplied data
|
|
if ((s->control_state != LWFTP_CLOSED) || s->control_pcb || s->data_pcb
|
|
|| !s->user || !s->pass) {
|
|
LWIP_DEBUGF(LWFTP_WARNING, ("lwftp: invalid control session\n"));
|
|
retval = LWFTP_RESULT_ERR_ARGUMENT;
|
|
goto exit;
|
|
}
|
|
// Get sessions pcb
|
|
s->control_pcb = tcp_new();
|
|
if (!s->control_pcb) {
|
|
LWIP_DEBUGF(LWFTP_SERIOUS, ("lwftp: cannot alloc control_pcb (low memory?)\n"));
|
|
retval = LWFTP_RESULT_ERR_MEMORY;
|
|
goto exit;
|
|
}
|
|
// Open control session
|
|
tcp_arg(s->control_pcb, s);
|
|
tcp_err(s->control_pcb, lwftp_control_err);
|
|
tcp_recv(s->control_pcb, lwftp_control_recv);
|
|
tcp_sent(s->control_pcb, lwftp_control_sent);
|
|
error = tcp_connect(s->control_pcb, &s->server_ip, s->server_port,
|
|
lwftp_control_connected);
|
|
if (error == ERR_OK) {
|
|
retval = LWFTP_RESULT_INPROGRESS;
|
|
goto exit;
|
|
}
|
|
|
|
// Release pcbs in case of failure
|
|
LWIP_DEBUGF(LWFTP_SERIOUS, ("lwftp: cannot connect control_pcb (%s)\n", lwip_strerr(error)));
|
|
lwftp_control_close(s, -1);
|
|
|
|
exit: if (s->done_fn)
|
|
s->done_fn(s->handle, retval);
|
|
|
|
return retval;
|
|
}
|
|
|
|
//
|
|
//err_t lwftp_store(lwftp_session_t *s) {
|
|
//
|
|
//}
|
|
//err_t lwftp_retrieve(lwftp_session_t *s) {
|
|
//
|
|
//}
|
|
//err_t lwftp_close(lwftp_session_t *s) {
|
|
//
|
|
//}
|