Skip to content

Commit 10d7f20

Browse files
committed
Support for ThreadX and NetX Duo. Fixes when using mingw.
1 parent ad7c6d8 commit 10d7f20

File tree

11 files changed

+395
-123
lines changed

11 files changed

+395
-123
lines changed

Makefile

Lines changed: 93 additions & 94 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ topic.
115115
| `DEBUG` | | Compiler debugging flag to use (default `-ggdb`) |
116116
| `OPTIM` | | The optimizer flag to use (default `-O3`) |
117117
| `HOST` | | The target host tuple, for cross-compilation (default unset, i.e. native targeting) |
118-
| `RUNTIME` | | The target runtime ecosystem -- default unset, `FreeRTOS-lwIP` and `Linux-lwIP` are recognized |
118+
| `RUNTIME` | | The target runtime ecosystem -- default unset, `FreeRTOS-lwIP`, `Linux-lwIP` and `ThreadX-NetXDuo` are recognized |
119119
| `C_WARNFLAGS` | | The warning flags to use (overriding the generally applicable defaults) |
120120
| `STATIC` | | Build statically linked unit tests |
121121
| `STRIPPED` | | Strip binaries of debugging symbols |

src/json/load_config.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
#ifdef WOLFSENTRY_LWIP
3535
#include "lwip/sockets.h"
36+
#elif defined(WOLFSENTRY_NETXDUO)
37+
#include "wolfsentry/wolfsentry_netxduo.h"
3638
#else
3739
#include <arpa/inet.h>
3840
#include <sys/socket.h>
@@ -1294,7 +1296,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
12941296
WOLFSENTRY_ERROR_RERETURN(ret);
12951297
case JSON_FALSE:
12961298
ret = wolfsentry_user_value_store_bool(
1297-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1299+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
12981300
jps->cur_keyname,
12991301
WOLFSENTRY_LENGTH_NULL_TERMINATED,
13001302
WOLFSENTRY_KV_FALSE,
@@ -1303,7 +1305,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
13031305
WOLFSENTRY_ERROR_RERETURN(ret);
13041306
case JSON_TRUE:
13051307
ret = wolfsentry_user_value_store_bool(
1306-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1308+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
13071309
jps->cur_keyname,
13081310
WOLFSENTRY_LENGTH_NULL_TERMINATED,
13091311
WOLFSENTRY_KV_TRUE,
@@ -1316,7 +1318,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
13161318
if ((ret = convert_sint64(json_type, data, data_size, &i)) < 0)
13171319
break;
13181320
ret = wolfsentry_user_value_store_sint(
1319-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1321+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
13201322
jps->cur_keyname,
13211323
WOLFSENTRY_LENGTH_NULL_TERMINATED,
13221324
i,
@@ -1327,7 +1329,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
13271329
if ((ret = convert_double(json_type, data, data_size, &d)) < 0)
13281330
WOLFSENTRY_ERROR_RERETURN(ret);
13291331
ret = wolfsentry_user_value_store_double(
1330-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1332+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
13311333
jps->cur_keyname,
13321334
WOLFSENTRY_LENGTH_NULL_TERMINATED,
13331335
d,
@@ -1339,7 +1341,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
13391341
if (data_size >= WOLFSENTRY_KV_MAX_VALUE_BYTES)
13401342
WOLFSENTRY_ERROR_RETURN(STRING_ARG_TOO_LONG);
13411343
ret = wolfsentry_user_value_store_string(
1342-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1344+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
13431345
jps->cur_keyname,
13441346
WOLFSENTRY_LENGTH_NULL_TERMINATED,
13451347
(const char *)data,
@@ -1454,7 +1456,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
14541456
if ((ret = convert_sint64(json_type, data, data_size, &i)) < 0)
14551457
WOLFSENTRY_ERROR_RERETURN(ret);
14561458
WOLFSENTRY_ERROR_RERETURN(wolfsentry_user_value_store_sint(
1457-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1459+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
14581460
jps->o_u_c.user_value.label,
14591461
jps->o_u_c.user_value.label_len,
14601462
i,
@@ -1465,7 +1467,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
14651467
if ((ret = convert_double(json_type, data, data_size, &d)) < 0)
14661468
WOLFSENTRY_ERROR_RERETURN(ret);
14671469
WOLFSENTRY_ERROR_RERETURN(wolfsentry_user_value_store_double(
1468-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1470+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
14691471
jps->o_u_c.user_value.label,
14701472
jps->o_u_c.user_value.label_len,
14711473
d,
@@ -1475,7 +1477,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
14751477
if (data_size >= WOLFSENTRY_KV_MAX_VALUE_BYTES)
14761478
WOLFSENTRY_ERROR_RETURN(STRING_ARG_TOO_LONG);
14771479
WOLFSENTRY_ERROR_RERETURN(wolfsentry_user_value_store_string(
1478-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1480+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
14791481
jps->o_u_c.user_value.label,
14801482
jps->o_u_c.user_value.label_len,
14811483
(const char *)data,
@@ -1486,7 +1488,7 @@ static wolfsentry_errcode_t handle_user_value_clause(struct wolfsentry_json_proc
14861488
if (data_size >= WOLFSENTRY_KV_MAX_VALUE_BYTES)
14871489
WOLFSENTRY_ERROR_RETURN(STRING_ARG_TOO_LONG);
14881490
WOLFSENTRY_ERROR_RERETURN(wolfsentry_user_value_store_bytes_base64(
1489-
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
1491+
JPS_WOLFSENTRY_CONTEXT_ARGS_OUT,
14901492
jps->o_u_c.user_value.label,
14911493
jps->o_u_c.user_value.label_len,
14921494
(const char *)data,

src/routes.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222

2323
#define WOLFSENTRY_SOURCE_ID WOLFSENTRY_SOURCE_ID_ROUTES_C
2424

25-
#include "wolfsentry_internal.h"
26-
2725
#ifndef WOLFSENTRY_NO_ALLOCA
2826
#include <alloca.h>
2927
#endif
3028

3129
#ifdef WOLFSENTRY_LWIP
3230
#include <lwip/inet.h>
3331
#include <lwip/sockets.h>
32+
#elif defined(WOLFSENTRY_NETXDUO)
33+
#include "wolfsentry/wolfsentry_netxduo.h"
3434
#else
3535
#include <netinet/in.h>
3636
#include <arpa/inet.h>
@@ -40,6 +40,8 @@
4040
#include <netdb.h>
4141
#endif
4242

43+
#include "wolfsentry_internal.h"
44+
4345
static inline int cmp_addrs_prefixful(
4446
const byte *left_addr,
4547
int left_addr_len,
@@ -3704,7 +3706,8 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_route_table_iterate_end(
37043706
WOLFSENTRY_RETURN_OK;
37053707
}
37063708

3707-
static int ws_decimal_ntoa(int d, char *buf, int *buflen) {
3709+
static int ws_decimal_ntoa(int d, char *buf, int *buflen)
3710+
{
37083711
if (d >= 1000) {
37093712
WOLFSENTRY_ERROR_RETURN(NUMERIC_ARG_TOO_BIG);
37103713
}
@@ -3737,7 +3740,9 @@ static int ws_decimal_ntoa(int d, char *buf, int *buflen) {
37373740
}
37383741
}
37393742

3740-
WOLFSENTRY_API int wolfsentry_inet4_ntoa(const byte *addr, unsigned int addr_bits, char *buf, int *buflen) {
3743+
int wolfsentry_inet4_ntoa(const byte *addr, unsigned int addr_bits, char *buf,
3744+
int *buflen)
3745+
{
37413746
const int b = (int)WOLFSENTRY_BITS_TO_BYTES(addr_bits);
37423747
int i;
37433748
const char *start_buf = buf;
@@ -3761,15 +3766,18 @@ WOLFSENTRY_API int wolfsentry_inet4_ntoa(const byte *addr, unsigned int addr_bit
37613766
WOLFSENTRY_RETURN_OK;
37623767
}
37633768

3764-
static inline char hexdigit_ntoa(unsigned int d) {
3769+
static inline char hexdigit_ntoa(unsigned int d)
3770+
{
37653771
d &= 0xf;
37663772
if (d < 10)
37673773
return (char)('0' + d);
37683774
else
37693775
return (char)('a' + (d - 0xa));
37703776
}
37713777

3772-
WOLFSENTRY_API int wolfsentry_inet6_ntoa(const byte *addr, unsigned int addr_bits, char *buf, int *buflen) {
3778+
int wolfsentry_inet6_ntoa(const byte *addr, unsigned int addr_bits, char *buf,
3779+
int *buflen)
3780+
{
37733781
const int b = (int)WOLFSENTRY_BITS_TO_BYTES(addr_bits);
37743782
int i;
37753783
const char *start_buf = buf;

src/wolfsentry_util.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,73 @@ static int freertos_sem_destroy( sem_t * sem )
15091509

15101510
#define sem_destroy freertos_sem_destroy
15111511

1512+
#elif defined(THREADX)
1513+
1514+
#ifndef ETIMEDOUT
1515+
#define ETIMEDOUT 110 /* Connection timed out */
1516+
#endif
1517+
1518+
#define sem_init threadx_sem_init
1519+
static int threadx_sem_init( sem_t * sem,
1520+
int pshared,
1521+
unsigned value )
1522+
{
1523+
(void)pshared;
1524+
if (tx_semaphore_create(sem, NULL, value) != TX_SUCCESS) {
1525+
errno = EINVAL;
1526+
WOLFSENTRY_RETURN_VALUE(-1);
1527+
}
1528+
WOLFSENTRY_RETURN_VALUE(0);
1529+
}
1530+
#define sem_post threadx_sem_post
1531+
static int threadx_sem_post( sem_t * sem )
1532+
{
1533+
if (tx_semaphore_put(sem) != TX_SUCCESS) {
1534+
errno = EINVAL;
1535+
WOLFSENTRY_RETURN_VALUE(-1);
1536+
}
1537+
WOLFSENTRY_RETURN_VALUE(0);
1538+
}
1539+
#define sem_timedwait threadx_sem_timedwait
1540+
static int threadx_sem_timedwait( sem_t * sem,
1541+
const struct timespec * abstime )
1542+
{
1543+
if (tx_semaphore_get(sem, (uint32_t)(TX_TICK_TIME_MS *
1544+
(abstime->tv_sec * 1000) + (abstime->tv_nsec / 1000000))) != TX_SUCCESS) {
1545+
errno = EINVAL;
1546+
WOLFSENTRY_RETURN_VALUE(-1);
1547+
}
1548+
WOLFSENTRY_RETURN_VALUE(0);
1549+
}
1550+
#define sem_wait threadx_sem_wait
1551+
static int threadx_sem_wait( sem_t * sem )
1552+
{
1553+
if (tx_semaphore_get(sem, TX_WAIT_FOREVER) != TX_SUCCESS) {
1554+
errno = EINVAL;
1555+
WOLFSENTRY_RETURN_VALUE(-1);
1556+
}
1557+
WOLFSENTRY_RETURN_VALUE(0);
1558+
}
1559+
#define sem_trywait threadx_sem_trywait
1560+
static int threadx_sem_trywait( sem_t * sem )
1561+
{
1562+
if (tx_semaphore_get(sem, TX_NO_WAIT) != TX_SUCCESS) {
1563+
errno = EINVAL;
1564+
WOLFSENTRY_RETURN_VALUE(-1);
1565+
}
1566+
WOLFSENTRY_RETURN_VALUE(0);
1567+
}
1568+
static int threadx_sem_destroy( sem_t * sem )
1569+
{
1570+
if (tx_semaphore_delete(sem) != TX_SUCCESS) {
1571+
errno = EINVAL;
1572+
WOLFSENTRY_RETURN_VALUE(-1);
1573+
}
1574+
WOLFSENTRY_RETURN_VALUE(0);
1575+
}
1576+
1577+
#define sem_destroy threadx_sem_destroy
1578+
15121579
#else
15131580

15141581
#error Semaphore builtins not implemented for target -- build wolfSentry with -DWOLFSENTRY_NO_SEM_BUILTIN, and supply semaphore implementation with struct wolfsentry_host_platform_interface argument to wolfsentry_init().
@@ -2847,7 +2914,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_lock_shared2mutex_abstimed(struct
28472914
WOLFSENTRY_ERROR_RETURN(SYS_OP_FATAL);
28482915
}
28492916
}
2850-
} else
2917+
} else
28512918
ret = sem_timedwait(&lock->sem_read2write_waiters, abs_timeout);
28522919

28532920
if (ret < 0) {
@@ -3317,6 +3384,19 @@ static wolfsentry_errcode_t wolfsentry_builtin_get_time(void *context, wolfsentr
33173384
WOLFSENTRY_RETURN_OK;
33183385
}
33193386

3387+
#elif defined(THREADX)
3388+
3389+
static wolfsentry_errcode_t wolfsentry_builtin_get_time(void *context, wolfsentry_time_t *now) {
3390+
struct timespec ts;
3391+
uint32_t tick_count;
3392+
(void)context;
3393+
tick_count = tx_time_get();
3394+
ts.tv_sec = (long)tick_count / TX_TICK_TIME_MS;
3395+
ts.tv_nsec = (long)(tick_count % TX_TICK_TIME_MS) * 1000000;
3396+
*now = ((wolfsentry_time_t)ts.tv_sec * (wolfsentry_time_t)1000000) + ((wolfsentry_time_t)ts.tv_nsec / (wolfsentry_time_t)1000);
3397+
WOLFSENTRY_RETURN_OK;
3398+
}
3399+
33203400
#else
33213401

33223402
#include <time.h>

tests/unittests.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ int lwip_inet_pton(int af, const char *src, void *dst) {
6969

7070
#endif /* !TEST_LWIP */
7171

72+
#elif defined(WOLFSENTRY_NETXDUO)
73+
74+
#include "nxd_bsd.h"
75+
/* undef OK this conflicts with the _OK macros in wolfsentry_errcodes.h */
76+
#undef OK
77+
78+
7279
#else /* !WOLFSENTRY_LWIP */
7380

7481
#include <sys/socket.h>

wolfsentry/wolfsentry.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ typedef enum {
8585
/*! @endcond */
8686
#endif
8787

88-
#include <wolfsentry/wolfsentry_settings.h>
89-
#include <wolfsentry/wolfsentry_af.h>
90-
#include <wolfsentry/wolfsentry_errcodes.h>
88+
#include "wolfsentry/wolfsentry_settings.h"
89+
#include "wolfsentry/wolfsentry_af.h"
90+
#include "wolfsentry/wolfsentry_errcodes.h"
9191

9292
struct wolfsentry_allocator;
9393
struct wolfsentry_context;
@@ -3012,7 +3012,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_event_action_list_done(
30123012
/*! @} (end wolfsentry_event) */
30133013

30143014
#ifdef WOLFSENTRY_HAVE_JSON_DOM
3015-
#include <wolfsentry/centijson_dom.h>
3015+
#include "wolfsentry/centijson_dom.h"
30163016
#endif
30173017

30183018
/*! \addtogroup wolfsentry_kv
@@ -3345,7 +3345,7 @@ WOLFSENTRY_API int wolfsentry_inet6_ntoa(const byte *addr, unsigned int addr_bit
33453345
(((((len)+3)/4)*3) - ((len) > 1 ? \
33463346
((buf)[(len)-1] == '=') : \
33473347
0) \
3348-
- ((len) > 2 ? ((buf)[(len)-2] == '=') : 0)) \
3348+
- ((len) > 2 ? ((buf)[(len)-2] == '=') : 0))
33493349
/*!< \brief Given valid base64 string `buf` of length `len`, evaluates to the exact decoded length. @hideinitializer */
33503350

33513351
WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_base64_decode(
@@ -3362,10 +3362,18 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_base64_decode(
33623362
#include "wolfsentry/wolfsentry_lwip.h"
33633363
#endif
33643364

3365+
#ifdef WOLFSENTRY_NETXDUO
3366+
#include "wolfsentry/wolfsentry_netxduo.h"
3367+
#endif
3368+
33653369
/* conditionally include wolfsentry_util.h last -- none of the above rely on it.
33663370
*/
33673371
#ifndef WOLFSENTRY_NO_UTIL_H
3368-
#include <wolfsentry/wolfsentry_util.h>
3372+
#include "wolfsentry/wolfsentry_util.h"
3373+
#endif
3374+
3375+
#ifdef WOLFSENTRY_HAVE_JSON_DOM
3376+
#include "wolfsentry/wolfsentry_json.h"
33693377
#endif
33703378

33713379
#endif /* WOLFSENTRY_H */

wolfsentry/wolfsentry_errcodes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#endif
4040

4141
typedef int32_t wolfsentry_errcode_t; /*!< \brief The structured result code type for wolfSentry. It encodes a failure or success code, a source code file ID, and a line number. */
42-
#ifdef FREERTOS
42+
#if defined(FREERTOS) || defined(THREADX)
4343
#define WOLFSENTRY_ERRCODE_FMT "%d"
4444
#elif defined(PRId32)
4545
#define WOLFSENTRY_ERRCODE_FMT "%" PRId32
@@ -143,7 +143,7 @@ static inline int WOLFSENTRY_ERROR_DECODE_LINE_NUMBER(wolfsentry_errcode_t x) {
143143

144144
#define WOLFSENTRY_ERROR_ENCODE(name) WOLFSENTRY_ERROR_ENCODE_0(WOLFSENTRY_ERROR_ID_ ## name)
145145
/*!< \brief Compute a `wolfsentry_errcode_t` encoding the current source ID and line number, and the designated short-form error `name` (e.g. `INVALID_ARG`). @hideinitializer */
146-
#define WOLFSENTRY_SUCCESS_ENCODE(x) WOLFSENTRY_ERROR_ENCODE_0(WOLFSENTRY_SUCCESS_ID_ ## x)
146+
#define WOLFSENTRY_SUCCESS_ENCODE(name) WOLFSENTRY_ERROR_ENCODE_0(WOLFSENTRY_SUCCESS_ID_ ## name)
147147
/*!< \brief Compute a `wolfsentry_errcode_t` encoding the current source ID and line number, and the designated short-form success `name` (e.g. `OK`). @hideinitializer */
148148

149149
#ifdef WOLFSENTRY_FOR_DOXYGEN
@@ -337,7 +337,9 @@ WOLFSENTRY_API const char *wolfsentry_errcode_error_name(wolfsentry_errcode_t e)
337337

338338
#if !defined(WOLFSENTRY_NO_STDIO_STREAMS) && !defined(WOLFSENTRY_NO_DIAG_MSGS)
339339

340+
#ifndef WOLFSENTRY_NETXDUO /* netxduo has its own errno.h */
340341
#include <errno.h>
342+
#endif
341343

342344
#ifdef __STRICT_ANSI__
343345
#define WOLFSENTRY_WARN(fmt,...) WOLFSENTRY_PRINTF_ERR("%s@L%d " fmt, __FILE__, __LINE__, __VA_ARGS__)

0 commit comments

Comments
 (0)