Skip to content

Commit 5b73e3a

Browse files
authored
Merge pull request #507 from lealem47/improvePack
CubePack: Better USER_IO support & cleanup warnings
2 parents d3dfb15 + 29ea1af commit 5b73e3a

File tree

6 files changed

+163
-30
lines changed

6 files changed

+163
-30
lines changed

ide/STM32CUBE/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# wolfSSH for STM32 Cube IDE
1+
# wolfSSH for STM32 Cube IDE
22

33
The wolfSSH Cube Pack can be found [here](https://www.wolfssl.com/files/ide/I-CUBE-wolfSSH.pack) and is dependent on the `wolfCrypt` library.
44

55
1. The first step is to set up the wolfCrypt library in your ST project following the guide here [https://github.com/wolfSSL/wolfssl/blob/master/IDE/STM32Cube/README.md](https://github.com/wolfSSL/wolfssl/blob/master/IDE/STM32Cube/README.md). To run the wolfSSH unit tests, name the entry function `wolfSSHTest` instead of `wolfCryptDemo`.
66

77
2. Then install the wolfSSH Cube Pack in the same manner as the wolfSSL pack with CUBEMX.
88

9-
3. Open the project `.ioc` file and click the `Software Packs` drop down menu and then `Select Components`. Expand the `wolfSSH` pack and check all the components.
9+
3. Open the project `.ioc` file and click the `Software Packs` drop down menu and then `Select Components`. Expand the `wolfSSH` pack and check all the components.
1010

1111
4. In the `Software Packs` configuration category of the `.ioc` file, click on the wolfSSH pack and enable the library by checking the box.
1212

13-
5. Since LwIP is a dependency for the Cube Pack, enable LwIP in the `Middleware` configuration category of the project. Also enable the `LWIP_DNS` option in the LwIP configuration settings.
13+
5. The Pack defaults to using custom IO provided by the user. Modify `ide/STM32CUBE/userio_template.h` to supply the custom IO. If you'd like to use LwIP instead, configure the wolfSSH IO settings in the `.ioc` to enable LwIP compatibilty. You'll also have to enable LwIP in the `Middleware` configuration category of the project. Enable the `LWIP_DNS` option in the LwIP configuration settings.
1414

1515
6. Save your changes and select yes to the prompt asking about generating code.
1616

@@ -19,4 +19,12 @@ The wolfSSH Cube Pack can be found [here](https://www.wolfssl.com/files/ide/I-CU
1919
## Notes
2020
- Make sure to make [these changes](https://github.com/wolfSSL/wolfssl/tree/master/IDE/STM32Cube#stm32-printf) to redirect the printf's to the UART.
2121

22-
- If looking to enable filesystem support, the pack assumes the user has defined their own filesystem in `wolfssh/myFilesystem.h`. That file will originally contain a dummy filesystem. If going the FATFS route, make sure to replace `#define WOLFSSH_USER_FILESYSTEM` with `#define WOLFSSH_FATFS` in the `wolfSSL.I-CUBE-wolfSSH_conf.h` header file. The wolfSSL Cube Pack also defaults to disabling filesystem support so make sure to remove `#define NO_FILESYSTEM` from `wolfSSL.I-CUBE-wolfSSL_conf.h`.
22+
- If looking to enable filesystem support (required for SFTP), the pack assumes the user has defined their own filesystem in `wolfssh/myFilesystem.h`. That file will originally contain a dummy filesystem. If going the FATFS route, make sure to replace `#define WOLFSSH_USER_FILESYSTEM` with `#define WOLFSSH_FATFS` in the `wolfSSL.I-CUBE-wolfSSH_conf.h` header file. The wolfSSL Cube Pack also defaults to disabling filesystem support so make sure to remove `#define NO_FILESYSTEM` from `wolfSSL.I-CUBE-wolfSSL_conf.h`.
23+
24+
- If building with LwIP and you encounter the error `multiple definition of 'errno'` in `Middlewares/Third_Party/LwIP/system/OS/sys_arch.c`, modify the file as shown below.
25+
```
26+
#if defined(LWIP_SOCKET_SET_ERRNO) && defined(LWIP_PROVIDE_ERRNO)
27+
- int errno;
28+
+ extern int errno;
29+
#endif
30+
```

ide/STM32CUBE/default_conf.ftl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ extern ${variable.value} ${variable.name};
9494
/* ------------------------------------------------------------------------- */
9595
/* wolfSSH IO */
9696
/* ------------------------------------------------------------------------- */
97-
#define WOLFSSH_LWIP
98-
/* Remove the LWIP define and uncomment the line below to use user defined IO */
99-
/* #define WOLFSSL_USER_IO */
97+
#if defined(WOLFSSH_CONF_IO) && WOLFSSH_CONF_IO == 2
98+
#define WOLFSSH_LWIP
99+
#else
100+
#define WOLFSSH_USER_IO
101+
#endif
100102

101103
/* To be defined for the target Socket API */
102104
#define WSTARTTCP()
@@ -140,6 +142,8 @@ extern ${variable.value} ${variable.name};
140142
#define CURVE25519_SMALL
141143
#define HAVE_ED25519
142144

145+
#define WOLFSSH_IGNORE_FILE_WARN
146+
143147
typedef unsigned int size_t;
144148

145149
/* defines for unit tests */

ide/STM32CUBE/myFilesystem.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,107 +40,107 @@ typedef struct { int i; } stat_t;
4040
#define WFD int
4141
enum { O_RDWR, O_RDONLY, O_WRONLY, O_APPEND, O_CREAT, O_TRUNC, O_EXCL } ;
4242

43-
static int WFOPEN(FILE **f, const char *n, const char *m){
43+
static inline int WFOPEN(FILE **f, const char *n, const char *m){
4444
(void) n; (void) m; (void)f;
4545
return NULL;
4646
}
4747

48-
static int WFCLOSE(FILE *f) {
48+
static inline int WFCLOSE(FILE *f) {
4949
(void) f;
5050
return 0;
5151
}
5252

53-
static size_t WFREAD(void *b, size_t s, size_t n, FILE *f) {
53+
static inline size_t WFREAD(void *b, size_t s, size_t n, FILE *f) {
5454
(void) b; (void) s; (void) n; (void) f;
5555
return 0;
5656
}
5757

58-
static size_t WFWRITE(const void *b, size_t s, size_t n, FILE *f) {
58+
static inline size_t WFWRITE(const void *b, size_t s, size_t n, FILE *f) {
5959
(void) b; (void) s; (void) n; (void) f;
6060
return 0;
6161
}
6262

63-
static int WFSEEK(FILE *f, long int p, int m) {
63+
static inline int WFSEEK(FILE *f, long int p, int m) {
6464
(void) f; (void) p; (void) m;
6565
return 0;
6666
}
6767

68-
static long int WFTELL(FILE *f) {
68+
static inline long int WFTELL(FILE *f) {
6969
(void) f;
7070
return 0;
7171
}
72-
static void WREWIND(FILE *f) {
72+
static inline void WREWIND(FILE *f) {
7373
(void) f;
7474
}
7575

76-
static int WOPEN (const char* n, int f, int m) {
76+
static inline int WOPEN (const char* n, int f, int m) {
7777
(void) f; (void) n; (void) m;
7878
return 0;
7979
}
8080

81-
static int WCLOSE(int f) {
81+
static inline int WCLOSE(int f) {
8282
(void) f;
8383
return 0;
8484
}
8585

86-
static size_t WPREAD(int f, void* b, size_t c, off_t *o) {
86+
static inline size_t WPREAD(int f, void* b, size_t c, off_t *o) {
8787
(void) f; (void) b; (void) c; (void)o;
8888
return 0;
8989
}
9090

91-
static size_t WPWRITE(int f, void* b, size_t c, off_t *o) {
91+
static inline size_t WPWRITE(int f, void* b, size_t c, off_t *o) {
9292
(void) f; (void) b; (void) c; (void)o;
9393
return 0;
9494
}
9595

96-
static char *WGETCWD(void *fs, char *f, size_t l){
96+
static inline char *WGETCWD(void *fs, char *f, size_t l){
9797
(void) fs; (void) f; (void) l;
9898
return 0;
9999
}
100100

101-
static int WRMDIR(void *fs, const char *p){
101+
static inline int WRMDIR(void *fs, const char *p){
102102
(void) p;
103103
return 0;
104104
}
105105

106-
static int WMKDIR(void *fs, const char *p, mode_t m) {
106+
static inline int WMKDIR(void *fs, const char *p, mode_t m) {
107107
(void) p; (void) m;
108108
return 0;
109109
}
110110

111-
static int WREMOVE(void *fs, const char *p){
111+
static inline int WREMOVE(void *fs, const char *p){
112112
(void) fs; (void) p;
113113
return 0;
114114
}
115115

116-
static int WRENAME(void *fs, const char *p, const char *np){
116+
static inline int WRENAME(void *fs, const char *p, const char *np){
117117
(void) fs; (void) p; (void)np;
118118
return 0;
119119
}
120120

121-
static int WSTAT(const char *p, stat_t *b) {
121+
static inline int WSTAT(const char *p, stat_t *b) {
122122
(void) p; (void)b;
123123
return 0;
124124
}
125125

126-
static int WLSTAT(const char *p, stat_t *b) {
126+
static inline int WLSTAT(const char *p, stat_t *b) {
127127
(void) p; (void)b;
128128
return 0;
129129
}
130130

131-
static int WCHMOD(void *fs, const char *p, mode_t m) {
131+
static inline int WCHMOD(void *fs, const char *p, mode_t m) {
132132
(void) fs; (void) p; (void)m;
133133
return 0;
134134
}
135135

136-
static int SFTP_GetAttributes(void* fs, const char* fileName,
136+
static inline int SFTP_GetAttributes(void* fs, const char* fileName,
137137
void* atr, byte link, void* heap) {
138138
(void)fs; (void)fileName; (void)atr; (void)link; (void)heap;
139139
return 0;
140140

141141
}
142142

143-
static int SFTP_GetAttributes_Handle(void* ssh, byte* handle, int handleSz,
143+
static inline int SFTP_GetAttributes_Handle(void* ssh, byte* handle, int handleSz,
144144
void* atr) {
145145
(void)ssh; (void)handle; (void)handleSz;
146146

ide/STM32CUBE/userio_template.h

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/* userio_template.h
2+
*
3+
* Copyright (C) 2014-2023 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSH.
6+
*
7+
* wolfSSH is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSH is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
22+
#ifndef USERIO_TEMPLATE_H
23+
#define USERIO_TEMPLATE_H
24+
25+
#ifdef WOLFSSH_USER_IO
26+
27+
#define SOCK_STREAM 1
28+
#define SOCK_DGRAM 2
29+
#define SOCK_RAW 3
30+
31+
#define SOL_SOCKET 0xfff
32+
#define SO_REUSEADDR 0x0004
33+
34+
#define AF_INET 2
35+
#define INADDR_ANY ((uint32_t)0x00000000UL)
36+
37+
#define socklen_t uint32_t
38+
39+
typedef struct { int s_addr; } in_addr;
40+
41+
struct sockaddr { int i; };
42+
43+
typedef struct sockaddr sockaddr;
44+
45+
struct sockaddr_in{
46+
int sin_len;
47+
int sin_family;
48+
int sin_port;
49+
in_addr sin_addr;
50+
};
51+
52+
typedef struct sockaddr_in sockaddr_in;
53+
54+
struct hostent{
55+
char *h_name;
56+
int h_length;
57+
char **h_addr_list;
58+
};
59+
60+
typedef struct hostent hostent;
61+
62+
static inline int inet_addr(const char* n){
63+
(void) n;
64+
return 0;
65+
}
66+
67+
static inline int htons(unsigned int n){
68+
(void) n;
69+
return 0;
70+
}
71+
72+
static inline int ntohs(unsigned int n){
73+
(void) n;
74+
return 0;
75+
}
76+
77+
static inline int socket(int d, int t, int p) {
78+
(void) d; (void) t; (void) p;
79+
return 0;
80+
}
81+
82+
static inline int setsockopt(int s, int l, int n, const void *o,
83+
socklen_t len) {
84+
(void) s; (void) l; (void) n; (void) o; (void) len;
85+
return 0;
86+
}
87+
88+
static inline int getsockname(int s, struct sockaddr *n, socklen_t* len) {
89+
(void) s; (void) n; (void) len;
90+
return 0;
91+
}
92+
93+
static inline int bind(int s, const struct sockaddr *n, socklen_t l) {
94+
(void) s; (void) n; (void) l;
95+
return 0;
96+
}
97+
98+
static inline int listen(int s, int b) {
99+
(void) s; (void) b;
100+
return 0;
101+
}
102+
103+
static inline struct hostent* gethostbyname(const char* n) {
104+
(void) n;
105+
return NULL;
106+
}
107+
108+
#endif /* WOLFSSH_USER_IO */
109+
110+
#endif

src/misc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151

5252

5353
/* Check for if compiling misc.c when not needed. */
54-
#if !defined(WOLFSSH_MISC_INCLUDED) && !defined(NO_INLINE)
54+
#if !defined(WOLFSSH_MISC_INCLUDED) && !defined(NO_INLINE) && \
55+
!defined(WOLFSSH_IGNORE_FILE_WARN)
5556
#define MISC_WARNING "misc.c does not need to be compiled when using inline (NO_INLINE not defined))"
5657

5758
#ifndef _MSC_VER
@@ -60,7 +61,7 @@
6061
#pragma message("warning: " MISC_WARNING)
6162
#endif
6263

63-
#else /* !WOLFSSL_MISC_INCLUDED && !NO_INLINE */
64+
#else /* !WOLFSSL_MISC_INCLUDED && !NO_INLINE && !WOLFSSH_IGNORE_FILE_WARN */
6465

6566

6667
#ifndef min

wolfssh/test.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@
126126
#endif
127127
#define SOCKET_T int
128128
#define NUM_SOCKETS 5
129+
#elif defined(WOLFSSH_USER_IO)
130+
#include <unistd.h>
131+
#include <pthread.h>
132+
#include <fcntl.h>
133+
#include "userio_template.h"
134+
#ifndef SO_NOSIGPIPE
135+
#include <signal.h> /* ignore SIGPIPE */
136+
#endif
137+
#define SOCKET_T int
138+
#define NUM_SOCKETS 5
129139
#else /* USE_WINDOWS_API */
130140
#include <unistd.h>
131141
#include <sys/socket.h>

0 commit comments

Comments
 (0)