Skip to content

Commit

Permalink
[protocol][sd] add scaffold.
Browse files Browse the repository at this point in the history
  • Loading branch information
tschak909 committed Nov 8, 2023
1 parent a232440 commit 202b312
Show file tree
Hide file tree
Showing 3 changed files with 339 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/network-protocol/ProtocolParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "HTTP.h"
#include "SSH.h"
#include "SMB.h"
#include "SD.h"

#include "../utils/string_utils.h"
#include "../../include/debug.h"
Expand Down Expand Up @@ -52,6 +53,9 @@ NetworkProtocol* ProtocolParser::createProtocol(std::string scheme, std::string
case "SMB"_sh:
protocol = new NetworkProtocolSMB(receiveBuffer, transmitBuffer, specialBuffer);
break;
case "SD"_sh:
protocol = new NetworkProtocolSD(receiveBuffer, transmitBuffer, specialBuffer);
break;
default:
Debug_printf("Invalid protocol: %s\n", scheme.c_str());
break;
Expand Down
126 changes: 126 additions & 0 deletions lib/network-protocol/SD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* NetworkProtocolSD
*
* Implementation
*/

#include "../../include/debug.h"

#include "SD.h"
#include "status_error_codes.h"

NetworkProtocolSD::NetworkProtocolSD(string *rx_buf, string *tx_buf, string *sp_buf)
: NetworkProtocolFS(rx_buf, tx_buf, sp_buf)
{

}

NetworkProtocolSD::~NetworkProtocolSD()
{

}

bool NetworkProtocolSD::open_file_handle()
{
return false;
}

bool NetworkProtocolSD::open_dir_handle()
{
return false;
}

bool NetworkProtocolSD::mount(EdUrlParser *url)
{
return false;
}

bool NetworkProtocolSD::umount()
{
return false;
}

void NetworkProtocolSD::fserror_to_error()
{

}

bool NetworkProtocolSD::read_file_handle(uint8_t *buf, unsigned short len)
{
return false;
}

bool NetworkProtocolSD::read_dir_entry(char *buf, unsigned short len)
{
return false;
}

bool NetworkProtocolSD::close_file_handle()
{
return false;
}

bool NetworkProtocolSD::close_dir_handle()
{
return false;
}

bool NetworkProtocolSD::write_file_handle(uint8_t *buf, unsigned short len)
{
return false;
}

uint8_t NetworkProtocolSD::special_inquiry(uint8_t cmd)
{
return 0;
}

bool NetworkProtocolSD::special_00(cmdFrame_t *cmdFrame)
{
return false;
}

bool NetworkProtocolSD::special_40(uint8_t *sp_buf, unsigned short len, cmdFrame_t *cmdFrame)
{
return false;
}

bool NetworkProtocolSD::special_80(uint8_t *sp_buf, unsigned short len, cmdFrame_t *cmdFrame)
{
return false;
}

bool NetworkProtocolSD::rename(EdUrlParser *url, cmdFrame_t *cmdFrame)
{
return false;
}

bool NetworkProtocolSD::del(EdUrlParser *url, cmdFrame_t *cmdFrame)
{
return false;
}

bool NetworkProtocolSD::mkdir(EdUrlParser *url, cmdFrame_t *cmdFrame)
{
return false;
}

bool NetworkProtocolSD::rmdir(EdUrlParser *url, cmdFrame_t *cmdFrame)
{
return false;
}

bool NetworkProtocolSD::stat()
{
return false;
}

bool NetworkProtocolSD::lock(EdUrlParser *url, cmdFrame_t *cmdFrame)
{
return false;
}

bool NetworkProtocolSD::unlock(EdUrlParser *url, cmdFrame_t *cmdFrame)
{
return false;
}
209 changes: 209 additions & 0 deletions lib/network-protocol/SD.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
#ifndef NETWORKPROTOCOLSD_H
#define NETWORKPROTOCOLSD_H

#include "FS.h"

class NetworkProtocolSD : public NetworkProtocolFS
{
public:
/**
* @brief ctor
* @param rx_buf pointer to receive buffer
* @param tx_buf pointer to transmit buffer
* @param sp_buf pointer to special buffer
* @return a NetworkProtocolFS object
*/
NetworkProtocolSD(string *rx_buf, string *tx_buf, string *sp_buf);

/**
* dTOR
*/
virtual ~NetworkProtocolSD();

/**
* @brief Return a DSTATS byte for a requested COMMAND byte.
* @param cmd The Command (0x00-0xFF) for which DSTATS is requested.
* @return a 0x00 = No payload, 0x40 = Payload to Atari, 0x80 = Payload to FujiNet, 0xFF = Command not supported.
*/
virtual uint8_t special_inquiry(uint8_t cmd);

/**
* @brief execute a command that returns no payload
* @param cmdFrame a pointer to the passed in command frame for aux1/aux2/etc
* @return error flag. TRUE on error, FALSE on success.
*/
virtual bool special_00(cmdFrame_t *cmdFrame);

/**
* @brief execute a command that returns a payload to the atari.
* @param sp_buf a pointer to the special buffer
* @param len Length of data to request from protocol. Should not be larger than buffer.
* @return error flag. TRUE on error, FALSE on success.
*/
virtual bool special_40(uint8_t *sp_buf, unsigned short len, cmdFrame_t *cmdFrame);

/**
* @brief execute a command that sends a payload to fujinet (most common, XIO)
* @param sp_buf, a pointer to the special buffer, usually a EOL terminated devicespec.
* @param len length of the special buffer, typically SPECIAL_BUFFER_SIZE
*/
virtual bool special_80(uint8_t *sp_buf, unsigned short len, cmdFrame_t *cmdFrame);

/**
* @brief Rename file specified by incoming devicespec.
* @param url pointer to EdUrlParser pointing to file/dest to rename
* @param cmdFrame the command frame
* @return TRUE on error, FALSE on success
*/
virtual bool rename(EdUrlParser *url, cmdFrame_t *cmdFrame);

/**
* @brief Delete file specified by incoming devicespec.
* @param url pointer to EdUrlParser pointing to file to delete
* @param cmdFrame the command frame
* @return TRUE on error, FALSE on success
*/
virtual bool del(EdUrlParser *url, cmdFrame_t *cmdFrame);

/**
* @brief Make directory specified by incoming devicespec.
* @param url pointer to EdUrlParser pointing to file to delete
* @param cmdFrame the command frame
* @return TRUE on error, FALSE on success
*/
virtual bool mkdir(EdUrlParser *url, cmdFrame_t *cmdFrame);

/**
* @brief Remove directory specified by incoming devicespec.
* @param url pointer to EdUrlParser pointing to file to delete
* @param cmdFrame the command frame
* @return TRUE on error, FALSE on success
*/
virtual bool rmdir(EdUrlParser *url, cmdFrame_t *cmdFrame);

/**
* @brief lock file specified by incoming devicespec.
* @param url pointer to EdUrlParser pointing to file to delete
* @param cmdFrame the command frame
* @return TRUE on error, FALSE on success
*/
virtual bool lock(EdUrlParser *url, cmdFrame_t *cmdFrame);

/**
* @brief unlock file specified by incoming devicespec.
* @param url pointer to EdUrlParser pointing to file to delete
* @param cmdFrame the command frame
* @return TRUE on error, FALSE on success
*/
virtual bool unlock(EdUrlParser *url, cmdFrame_t *cmdFrame);

protected:

/**
* Is rename implemented?
*/
bool rename_implemented = true;

/**
* Is delete implemented?
*/
bool delete_implemented = true;

/**
* Is mkdir implemented?
*/
bool mkdir_implemented = true;

/**
* Is rmdir implemented?
*/
bool rmdir_implemented = true;

/**
* @brief Open file handle, set fd
* @return FALSE if successful, TRUE on error.
*/
virtual bool open_file_handle();

/**
* @brief Open directory handle
* @return FALSE if successful, TRUE on error.
*/
virtual bool open_dir_handle();

/**
* @brief Do TNFS mount
* @param url The URL to mount
* @return false on no error, true on error.
*/
virtual bool mount(EdUrlParser *url);

/**
* @brief Unmount TNFS server specified in mountInfo.
* @return false on no error, true on error.
*/
virtual bool umount();

/**
* @brief Translate filesystem error codes to Atari error codes. Sets error in Protocol.
*/
virtual void fserror_to_error();

/**
* @brief Read from file handle
* @param buf target buffer
* @param len the number of bytes requested
* @return FALSE if success, TRUE if error
*/
virtual bool read_file_handle(uint8_t *buf, unsigned short len);

/**
* @brief read next directory entry.
* @param buf the target buffer
* @param len length of target buffer
*/
virtual bool read_dir_entry(char *buf, unsigned short len);

/**
* @brief for len requested, break up into number of required
* tnfs_write() blocks.
* @param len Requested # of bytes.
* @return TRUE on error, FALSE on success.
*/
virtual bool write_file_handle(uint8_t *buf, unsigned short len);

/**
* @brief close file handle
* @return FALSE if successful, TRUE on error.
*/
virtual bool close_file_handle();

/**
* @brief Close directory handle
* @return FALSE if successful, TRUE on error.
*/
virtual bool close_dir_handle();

private:
/**
* Last TNFS error
*/
int tnfs_error = 0;

/**
* The create permissions of the open file
*/
uint16_t perms = 0;

/**
* The resulting file handle of open file.
*/
int16_t fd = 0;

/**
* @brief get status of file, filling in filesize. mount() must have already been called.
*/
virtual bool stat();
};

#endif /* NETWORKPROTOCOLSD_H */

0 comments on commit 202b312

Please sign in to comment.