Skip to content

Commit 52e7273

Browse files
committed
Support for ThreadX and NetX Duo. Fixes when using mingw.
1 parent b8024ea commit 52e7273

File tree

11 files changed

+395
-122
lines changed

11 files changed

+395
-122
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: 7 additions & 2 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,6 +3706,8 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_route_table_iterate_end(
37043706
WOLFSENTRY_RETURN_OK;
37053707
}
37063708

3709+
#ifndef WOLFSENTRY_NO_STDIO_STREAMS
3710+
37073711
static inline char hexdigit_ntoa(unsigned int d) {
37083712
d &= 0xf;
37093713
if (d < 10)
@@ -3792,6 +3796,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_route_format_address(
37923796
} else
37933797
WOLFSENTRY_ERROR_RETURN(OP_NOT_SUPP_FOR_PROTO);
37943798
}
3799+
#endif
37953800

37963801
#if defined(WOLFSENTRY_PROTOCOL_NAMES) || defined(WOLFSENTRY_JSON_DUMP_UTILS) || !defined(WOLFSENTRY_NO_JSON)
37973802

src/wolfsentry_util.c

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,10 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_init_thread_context(struct wolfse
812812
* the held lock can be safely locked recursively from within the
813813
* interrupt context.
814814
*/
815-
if (thread_context->id == (wolfsentry_thread_id_t)((uintptr_t)WOLFSENTRY_THREAD_NO_ID - 0xffffff))
816-
WOLFSENTRY_ATOMIC_INCREMENT(fallback_thread_id_counter, 0xffffff);
815+
if (thread_context->id == (wolfsentry_thread_id_t)((uintptr_t)WOLFSENTRY_THREAD_NO_ID - 0xffffff)) {
816+
(void)WOLFSENTRY_ATOMIC_INCREMENT(fallback_thread_id_counter, 0xffffff);
817+
}
818+
(void)fallback_thread_id_counter;
817819
WOLFSENTRY_SUCCESS_RETURN(USED_FALLBACK);
818820
} else
819821
WOLFSENTRY_RETURN_OK;
@@ -1509,6 +1511,73 @@ static int freertos_sem_destroy( sem_t * sem )
15091511

15101512
#define sem_destroy freertos_sem_destroy
15111513

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

15141583
#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 +2916,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_lock_shared2mutex_abstimed(struct
28472916
WOLFSENTRY_ERROR_RETURN(SYS_OP_FATAL);
28482917
}
28492918
}
2850-
} else
2919+
} else
28512920
ret = sem_timedwait(&lock->sem_read2write_waiters, abs_timeout);
28522921

28532922
if (ret < 0) {
@@ -3317,6 +3386,19 @@ static wolfsentry_errcode_t wolfsentry_builtin_get_time(void *context, wolfsentr
33173386
WOLFSENTRY_RETURN_OK;
33183387
}
33193388

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

33223404
#include <time.h>
@@ -4264,7 +4346,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_base64_decode(const char *src, si
42644346
const char *src_end = src + src_len;
42654347
size_t dest_len = 0;
42664348

4267-
if (WOLFSENTRY_BASE64_DECODED_BUFSPC(src, src_len) > *dest_spc)
4349+
if (WOLFSENTRY_BASE64_DECODED_BUFSPC(src, (int)src_len) > (int)*dest_spc)
42684350
WOLFSENTRY_ERROR_RETURN(BUFFER_TOO_SMALL);
42694351

42704352
for (; src < src_end; ++src) {

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: 16 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;
@@ -2489,6 +2489,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_route_set_wildcard(
24892489
struct wolfsentry_route *route,
24902490
wolfsentry_route_flags_t wildcards_to_set);
24912491

2492+
#ifndef WOLFSENTRY_NO_STDIO_STREAMS
24922493
WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_route_format_address(
24932494
WOLFSENTRY_CONTEXT_ARGS_IN,
24942495
wolfsentry_addr_family_t sa_family,
@@ -2497,6 +2498,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_route_format_address(
24972498
char *buf,
24982499
int *buflen);
24992500
/*!< \brief Render a binary address in human-readable form to a buffer */
2501+
#endif
25002502

25012503
#if defined(WOLFSENTRY_PROTOCOL_NAMES) || defined(WOLFSENTRY_JSON_DUMP_UTILS) || !defined(WOLFSENTRY_NO_JSON)
25022504

@@ -3012,7 +3014,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_event_action_list_done(
30123014
/*! @} (end wolfsentry_event) */
30133015

30143016
#ifdef WOLFSENTRY_HAVE_JSON_DOM
3015-
#include <wolfsentry/centijson_dom.h>
3017+
#include "wolfsentry/centijson_dom.h"
30163018
#endif
30173019

30183020
/*! \addtogroup wolfsentry_kv
@@ -3341,7 +3343,7 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_user_values_iterate_end(
33413343
(((((len)+3)/4)*3) - ((len) > 1 ? \
33423344
((buf)[(len)-1] == '=') : \
33433345
0) \
3344-
- ((len) > 2 ? ((buf)[(len)-2] == '=') : 0)) \
3346+
- ((len) > 2 ? ((buf)[(len)-2] == '=') : 0))
33453347
/*!< \brief Given valid base64 string `buf` of length `len`, evaluates to the exact decoded length. @hideinitializer */
33463348

33473349
WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_base64_decode(
@@ -3358,10 +3360,18 @@ WOLFSENTRY_API wolfsentry_errcode_t wolfsentry_base64_decode(
33583360
#include "wolfsentry/wolfsentry_lwip.h"
33593361
#endif
33603362

3363+
#ifdef WOLFSENTRY_NETXDUO
3364+
#include "wolfsentry/wolfsentry_netxduo.h"
3365+
#endif
3366+
33613367
/* conditionally include wolfsentry_util.h last -- none of the above rely on it.
33623368
*/
33633369
#ifndef WOLFSENTRY_NO_UTIL_H
3364-
#include <wolfsentry/wolfsentry_util.h>
3370+
#include "wolfsentry/wolfsentry_util.h"
3371+
#endif
3372+
3373+
#ifdef WOLFSENTRY_HAVE_JSON_DOM
3374+
#include "wolfsentry/wolfsentry_json.h"
33653375
#endif
33663376

33673377
#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)