mirror of https://github.com/wolfSSL/wolfssh.git
add chmod support, update readme and example app
parent
4f9e6b5732
commit
5fb496b9aa
|
@ -1,15 +1,48 @@
|
|||
This is example code for adding a wolfSSH echoserver to a MPLABX project.
|
||||
|
||||
The steps to use the code is as follows:
|
||||
1) Add wolfssh.c source file to project build.
|
||||
2) Make sure that current MPLABX project handles setting up TCP stack (see MPLABX examples for this /microchip/harmony/XXX/apps/examples/)
|
||||
3) Add include path to wolfssh root directory.
|
||||
4) Add preprocessor macro WOLFSSL_USER_SETTINGS (this is so wolfssl/wolfssh includes user_settings.h) to the project properties.
|
||||
5) Add include path to user_settings.h to project properties.
|
||||
6) Add APP_SSH_Tasks() and APP_SSH_Initialize() declarations to app.h header file.
|
||||
7) Add call to APP_SSH_Initialize() to system_init.c
|
||||
8) Add call to APP_SSH_Tasks() to system_tasks.c
|
||||
For SAMV71:
|
||||
|
||||
For the current project this was tested with the heap and stack set to 200,000 each. This was not trimed to see the minumum possible heap and stack usage yet. The TX buffer size used was set to 1024. The example needs to use wolfssl versions that are later than 4/5/2018 (mid v3.14.0) for hardware acceleration and versions v3.14.0 and later for software only.
|
||||
1) Import the .mc3 settings. Create a new project for SAMV71, click on CM for content manager. Click "Load Manifest" and select the ide/mplabx/mcc-manifest-samv71.yml file and then click apply.
|
||||
2) Open MCC then click "Import" and import ide/mplabx/wolfssh-sftp-server-samv71.mc3 and then click "Generate"
|
||||
3) Adjust the "Preprocessor macros" to include WOLFSSH_IGNORE_FILE_WARN and WOLFSSL_USER_SETTINGS
|
||||
4) Create a user_sttings.h file in config/sam_v71_xult_freertos that includes config.h i.e.
|
||||
|
||||
user_settings.h
|
||||
```
|
||||
1 #ifndef USER_SETTINGS_H
|
||||
2 #define USER_SETTINGS_H
|
||||
3 #include "config.h"
|
||||
4 #endif
|
||||
```
|
||||
|
||||
5) Remove the generated app.c from Source Files
|
||||
6) Download wolfssh into src/third_party/wolfssh, for example:
|
||||
|
||||
```
|
||||
cd src/third_party
|
||||
git clone git@github.com:wolfssl/wolfssh
|
||||
```
|
||||
|
||||
7) Right click on the project and add existing item. Select src/third_party/wolfssh/ide/mplabx/wolfssh.c
|
||||
8) Right click on the project and add existing folder. Select src/third_party/wolfssh/src
|
||||
9) Increase the heap size to 200,000 by right clicking on the project, selecting "Properties"->"x32-ld"
|
||||
10) In "Header Files"/config/sam_v71_xult_freertos/configuration.h alter the configuration to support wolfSSH
|
||||
|
||||
```
|
||||
// wolfSSH
|
||||
#define WOLFSSL_WOLFSSH
|
||||
#ifndef NO_FILESYSTEM
|
||||
#define WOLFSSH_SFTP
|
||||
#endif
|
||||
#define WOLFSSH_NO_HMAC_SHA2_512
|
||||
#define DEFAULT_WINDOW_SZ 16384
|
||||
```
|
||||
|
||||
If present remove NO_FILESYSTEM and NO_SIG_WRAPPER. Add NO_WOLFSSL_DIR.
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
For the current project this was tested with the heap and stack set to 200,000 each. This was not trimed to see the minumum possible heap and stack usage yet. The TX buffer size used was set to 1024. The example was developed with wolfssh version 1.4.20.
|
||||
|
||||
After building and flashing the board a wolfSSH echoserver will be open on port 22 which can be connected to by using the example client bundled with wolfSSH. ```./examples/client/client -u jill -P upthehill -h 192.168.1.120 -p 22```
|
||||
|
|
|
@ -4,3 +4,5 @@
|
|||
EXTRA_DIST+= ide/mplabx/README.md
|
||||
EXTRA_DIST+= ide/mplabx/user_settings.h
|
||||
EXTRA_DIST+= ide/mplabx/wolfssh.c
|
||||
EXTRA_DIST+= ide/mplabx/mcc-manifest-samv71.yml
|
||||
EXTRA_DIST+= ide/mplabx/wolfssh-sftp-server-samv71.mc3
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# This file has been autogenerated by MPLAB Code Configurator. Please do not edit this file.
|
||||
|
||||
manifest_file_version: 1.0.0
|
||||
project: wolfssh_sftp_server_freertos
|
||||
creation_date: 2025-03-19T10:17:34.824+07:00[Asia/Jakarta]
|
||||
operating_system: Mac OS X
|
||||
mcc_mode: IDE
|
||||
mcc_mode_version: v6.20
|
||||
device_name: ATSAMV71Q21B
|
||||
compiler: XC32 4.35
|
||||
mcc_version: 5.5.0
|
||||
mcc_core_version: 5.7.0
|
||||
content_manager_version: 5.0.1
|
||||
is_mcc_offline: false
|
||||
is_using_prerelease_versions: false
|
||||
mcc_content_registries: https://registry.npmjs.org/
|
||||
device_library: {library_class: com.microchip.mcc.harmony.Harmony3Library, name: Harmony
|
||||
V3, version: 1.4.1}
|
||||
packs: {name: SAMV71_DFP, version: 4.12.237}
|
||||
modules:
|
||||
- {name: core, type: HARMONY, version: v3.13.1}
|
||||
- {name: csp, type: HARMONY, version: v3.18.0}
|
||||
- {name: CMSIS_5, type: HARMONY, version: 5.9.0}
|
||||
- {name: wolfssl, type: HARMONY, version: v5.4.0}
|
||||
- {name: net, type: HARMONY, version: v3.11.0}
|
||||
- {name: bsp, type: HARMONY, version: v3.17.0}
|
||||
- {name: crypto, type: HARMONY, version: wolfssl}
|
||||
- {name: CMSIS-FreeRTOS, type: HARMONY, version: v10.5.1}
|
File diff suppressed because it is too large
Load Diff
|
@ -440,27 +440,16 @@ static void CreateTestFile(void)
|
|||
char testData[] = "Test Data";
|
||||
SYS_FS_ERROR fsError;
|
||||
|
||||
/* Test change to the root directory */
|
||||
result = SYS_FS_DirectoryChange("/mnt/myDrive1");
|
||||
if(result != SYS_FS_RES_SUCCESS) {
|
||||
fsError = SYS_FS_Error();
|
||||
SYS_CONSOLE_PRINT("Change to root failed! Error: %d\r\n", fsError);
|
||||
return;
|
||||
}
|
||||
SYS_CONSOLE_PRINT("Changed to root directory\r\n");
|
||||
|
||||
/* Try to create and write to a test file */
|
||||
fileHandle = SYS_FS_FileOpen("test.txt", (SYS_FS_FILE_OPEN_WRITE));
|
||||
if(fileHandle == SYS_FS_HANDLE_INVALID)
|
||||
{
|
||||
if (fileHandle == SYS_FS_HANDLE_INVALID) {
|
||||
fsError = SYS_FS_Error();
|
||||
SYS_CONSOLE_PRINT("File open failed! Error: %d\r\n", fsError);
|
||||
return;
|
||||
}
|
||||
|
||||
result = SYS_FS_FileWrite(fileHandle, testData, strlen(testData));
|
||||
if(result == -1)
|
||||
{
|
||||
if(result == -1) {
|
||||
fsError = SYS_FS_Error();
|
||||
SYS_CONSOLE_PRINT("File write failed! Error: %d\r\n", fsError);
|
||||
SYS_FS_FileClose(fileHandle);
|
||||
|
@ -468,7 +457,7 @@ static void CreateTestFile(void)
|
|||
}
|
||||
|
||||
SYS_FS_FileClose(fileHandle);
|
||||
SYS_CONSOLE_PRINT("File operations successful!\r\n");
|
||||
SYS_CONSOLE_PRINT("\tCreated test.txt file example successful!\r\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -482,18 +471,23 @@ static int CheckDriveStatus(void)
|
|||
/* Try to get current drive */
|
||||
memset(cwdBuf, 0, sizeof(cwdBuf));
|
||||
if (SYS_FS_CurrentDriveGet(cwdBuf) == SYS_FS_RES_SUCCESS) {
|
||||
SYS_CONSOLE_PRINT("Current drive: %s\r\n", cwdBuf);
|
||||
} else {
|
||||
SYS_CONSOLE_PRINT("Failed to get current drive: %d\r\n", SYS_FS_Error());
|
||||
SYS_CONSOLE_PRINT("\tCurrent drive: %s\r\n", cwdBuf);
|
||||
}
|
||||
else {
|
||||
SYS_CONSOLE_PRINT("\tFailed to get current drive: %d\r\n",
|
||||
SYS_FS_Error());
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
/* Try to get current directory */
|
||||
memset(cwdBuf, 0, sizeof(cwdBuf));
|
||||
if (SYS_FS_CurrentWorkingDirectoryGet(cwdBuf, sizeof(cwdBuf)) == SYS_FS_RES_SUCCESS) {
|
||||
SYS_CONSOLE_PRINT("Current directory: %s\r\n", cwdBuf);
|
||||
} else {
|
||||
SYS_CONSOLE_PRINT("Failed to get current directory: %d\r\n", SYS_FS_Error());
|
||||
if (SYS_FS_CurrentWorkingDirectoryGet(cwdBuf, sizeof(cwdBuf)) ==
|
||||
SYS_FS_RES_SUCCESS) {
|
||||
SYS_CONSOLE_PRINT("\tCurrent directory: %s\r\n", cwdBuf);
|
||||
}
|
||||
else {
|
||||
SYS_CONSOLE_PRINT("\tFailed to get current directory: %d\r\n",
|
||||
SYS_FS_Error());
|
||||
ret = -1;
|
||||
}
|
||||
CreateTestFile();
|
||||
|
@ -507,10 +501,11 @@ static int TryMount(void)
|
|||
int ret = 0;
|
||||
|
||||
/* Try mounting */
|
||||
if(SYS_FS_Mount(APP_DEVICE_NAME, APP_MOUNT_NAME, APP_FS_TYPE, 0, NULL) ==
|
||||
if (SYS_FS_Mount(APP_DEVICE_NAME, APP_MOUNT_NAME, APP_FS_TYPE, 0, NULL) ==
|
||||
SYS_FS_RES_SUCCESS) {
|
||||
SYS_CONSOLE_PRINT("Filesystem mounted\r\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
int err = (int)SYS_FS_Error();
|
||||
|
||||
if (err == SYS_FS_ERROR_NOT_READY) {
|
||||
|
@ -772,7 +767,6 @@ void APP_Tasks ( void )
|
|||
SYS_CONSOLE_PRINT("Total heap free = %d bytes\r\n", xPortGetFreeHeapSize());
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!TCPIP_TCP_IsConnected(wolfSSH_get_fd(ssh))) {
|
||||
SYS_CONSOLE_PRINT("TCP socket was disconnected\r\n");
|
||||
appData.state = APP_SSH_CLEANUP;
|
||||
|
@ -796,31 +790,7 @@ void APP_Tasks ( void )
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = wolfSSH_worker(ssh, NULL);
|
||||
error = wolfSSH_get_error(ssh);
|
||||
if (ret == WS_REKEYING) {
|
||||
/* In a rekey, keeping turning the crank. */
|
||||
break;
|
||||
}
|
||||
|
||||
if (error == WS_WANT_READ || error == WS_WANT_WRITE ||
|
||||
error == WS_WINDOW_FULL) {
|
||||
ret = error;
|
||||
break;
|
||||
}
|
||||
|
||||
if (error == WS_EOF) {
|
||||
appData.state = APP_SSH_CLEANUP;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != WS_SUCCESS && ret != WS_CHAN_RXD) {
|
||||
/* If not successful and no channel data, leave. */
|
||||
appData.state = APP_SSH_CLEANUP;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = wolfSSH_stream_peek(ssh, peek_buf, sizeof(peek_buf));
|
||||
if (ret > 0) {
|
||||
/* Yes, process the SFTP data. */
|
||||
|
@ -832,21 +802,37 @@ void APP_Tasks ( void )
|
|||
}
|
||||
if (error == WS_WANT_READ || error == WS_WANT_WRITE ||
|
||||
error == WS_CHAN_RXD || error == WS_REKEYING ||
|
||||
error == WS_WINDOW_FULL)
|
||||
error == WS_WINDOW_FULL) {
|
||||
ret = error;
|
||||
}
|
||||
if (error == WS_EOF) {
|
||||
appData.state = APP_SSH_CLEANUP;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (ret == WS_REKEYING) {
|
||||
break;
|
||||
}
|
||||
else if (ret < 0) {
|
||||
error = wolfSSH_get_error(ssh);
|
||||
if (error == WS_EOF) {
|
||||
appData.state = APP_SSH_CLEANUP;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = wolfSSH_worker(ssh, NULL);
|
||||
error = wolfSSH_get_error(ssh);
|
||||
if (ret == WS_REKEYING) {
|
||||
SYS_CONSOLE_PRINT("Doing rekeying\r\n");
|
||||
/* In a rekey, keeping turning the crank. */
|
||||
break;
|
||||
}
|
||||
|
||||
if (error == WS_WANT_READ || error == WS_WANT_WRITE ||
|
||||
error == WS_WINDOW_FULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (error == WS_EOF) {
|
||||
appData.state = APP_SSH_CLEANUP;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -859,6 +845,12 @@ void APP_Tasks ( void )
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != WS_SUCCESS && ret != WS_CHAN_RXD) {
|
||||
/* If not successful and no channel data, leave. */
|
||||
appData.state = APP_SSH_CLEANUP;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/* echo ssh input (example code from wolfssh/echoserver/echoserver.c) */
|
||||
|
|
22
src/port.c
22
src/port.c
|
@ -660,6 +660,28 @@ int wPread(WFD fd, unsigned char* buf, unsigned int sz,
|
|||
|
||||
#endif
|
||||
|
||||
#ifndef NO_FILESYSTEM
|
||||
#if defined(MICROCHIP_MPLAB_HARMONY)
|
||||
int wChmod(const char *path, int mode)
|
||||
{
|
||||
SYS_FS_RESULT ret;
|
||||
SYS_FS_FILE_DIR_ATTR attr = 0;
|
||||
|
||||
/* mode is the octal value i.e 666 is 0x1B6 */
|
||||
if ((mode & 0x180) != 0x180) { /* not octal 6XX read only */
|
||||
attr |= SYS_FS_ATTR_RDO;
|
||||
}
|
||||
|
||||
/* toggle the read only attribute */
|
||||
ret = SYS_FS_FileDirectoryModeSet(path, attr, SYS_FS_ATTR_RDO);
|
||||
if (ret != SYS_FS_RES_SUCCESS) {
|
||||
WLOG(WS_LOG_SFTP, "Failed to set file/dir mode");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* NO_FILESYSTEM */
|
||||
#ifndef WSTRING_USER
|
||||
|
||||
char* wstrdup(const char* s1, void* heap, int type)
|
||||
|
|
|
@ -401,8 +401,9 @@ extern "C" {
|
|||
|
||||
#define FLUSH_STD(a)
|
||||
|
||||
WOLFSSH_API int wfopen(WFILE* f, const char* filenmae,
|
||||
WOLFSSH_LOCAL int wfopen(WFILE* f, const char* filenmae,
|
||||
SYS_FS_FILE_OPEN_ATTRIBUTES mode);
|
||||
WOLFSSH_LOCAL int wChmod(const char *path, int mode);
|
||||
|
||||
#define WFOPEN(fs,f,fn,m) wfopen(*(f),(fn),(m))
|
||||
#define WFCLOSE(fs,f) SYS_FS_FileClose(*(f))
|
||||
|
@ -413,7 +414,7 @@ extern "C" {
|
|||
#define WREWIND(fs,s) SYS_FS_FileSeek(*(s), 0, SYS_FS_SEEK_SET)
|
||||
#define WSEEK_END SYS_FS_SEEK_END
|
||||
#define WBADFILE SYS_FS_HANDLE_INVALID
|
||||
#define WCHMOD(fs,f,m) (0) /* Not available */
|
||||
#define WCHMOD(fs,f,m) wChmod((f),(m))
|
||||
#define WFCHMOD(fs,fd,m) (0)
|
||||
#undef WFGETS
|
||||
#define WFGETS(b,s,f) SYS_FS_FileStringGet((f), (b), (s))
|
||||
|
|
Loading…
Reference in New Issue