diff --git a/btle/btle-sim.c b/btle/common/btle-sim.c similarity index 97% rename from btle/btle-sim.c rename to btle/common/btle-sim.c index 24f3a01e..65e4c8b1 100644 --- a/btle/btle-sim.c +++ b/btle/common/btle-sim.c @@ -1,6 +1,6 @@ /* btle-sim.c * - * Copyright (C) 2006-2021 wolfSSL Inc. + * Copyright (C) 2006-2022 wolfSSL Inc. * * This file is part of wolfSSL. (formerly known as CyaSSL) * @@ -19,6 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +/* This is a BTLE simulator to demonstrate communications between devices. + * The simulator uses IPC (pipes) to communicate between threads. + */ + #include #include #include diff --git a/btle/btle-sim.h b/btle/common/btle-sim.h similarity index 95% rename from btle/btle-sim.h rename to btle/common/btle-sim.h index 60dcf7ba..bd9ac114 100644 --- a/btle/btle-sim.h +++ b/btle/common/btle-sim.h @@ -24,9 +24,9 @@ #define BTLE_BLOCK_SIZE 16 #define _GNU_SOURCE -#include /* for strcasestr */ +#include /* for strnstr */ -#define EXIT_STRING "EXIT" +#define EXIT_STRING "exit" typedef enum { BTLE_PKT_TYPE_NULL, diff --git a/btle/ecies/Makefile b/btle/ecies/Makefile index e3505635..aaab93c1 100644 --- a/btle/ecies/Makefile +++ b/btle/ecies/Makefile @@ -1,7 +1,7 @@ # BTLE Examples Makefile CC = gcc LIB_PATH = /usr/local -CFLAGS = -Wall -I$(LIB_PATH)/include +CFLAGS = -Wall -I ../common -I$(LIB_PATH)/include LIBS = -L$(LIB_PATH)/lib # Flags @@ -31,10 +31,10 @@ debug: all %.o: %.c gcc -c $< -o $@ $(CFLAGS) -ecc-server: ecc-server.o ../btle-sim.o $(STATIC_LIB) +ecc-server: ecc-server.o ../common/btle-sim.o $(STATIC_LIB) $(CC) $^ -o $@ $(LIBS) -ecc-client: ecc-client.o ../btle-sim.o $(STATIC_LIB) +ecc-client: ecc-client.o ../common/btle-sim.o $(STATIC_LIB) $(CC) $^ -o $@ $(LIBS) clean: diff --git a/btle/ecies/ecc-client.c b/btle/ecies/ecc-client.c index 8f3ff5d7..c1cde09a 100644 --- a/btle/ecies/ecc-client.c +++ b/btle/ecies/ecc-client.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "../btle-sim.h" +#include "btle-sim.h" #ifndef WOLFSSL_USER_SETTINGS #include @@ -201,7 +201,7 @@ int main(int argc, char** argv) printf("Recv %d: %s\n", plainSz, plain); /* check for exit flag */ - if (strcasestr((char*)plain, EXIT_STRING)) { + if (strncmp((char*)plain, EXIT_STRING, strlen(EXIT_STRING)) == 0) { printf("Exit, closing connection\n"); break; } diff --git a/btle/ecies/ecc-server.c b/btle/ecies/ecc-server.c index 72d168fa..54110b79 100644 --- a/btle/ecies/ecc-server.c +++ b/btle/ecies/ecc-server.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "../btle-sim.h" +#include "btle-sim.h" #ifndef WOLFSSL_USER_SETTINGS #include @@ -191,7 +191,7 @@ int main(int argc, char** argv) } /* check for exit flag */ - if (strcasestr((char*)plain, EXIT_STRING)) { + if (strncmp((char*)plain, EXIT_STRING, strlen(EXIT_STRING)) == 0) { printf("Exit, closing connection\n"); break; } diff --git a/btle/tls/Makefile b/btle/tls/Makefile index 08d58c87..d3adc74b 100644 --- a/btle/tls/Makefile +++ b/btle/tls/Makefile @@ -1,7 +1,7 @@ # BTLE Examples Makefile CC = gcc LIB_PATH = /usr/local -CFLAGS = -Wall -I$(LIB_PATH)/include +CFLAGS = -Wall -I ../common -I $(LIB_PATH)/include LIBS = -L$(LIB_PATH)/lib # Flags @@ -31,10 +31,10 @@ debug: all %.o: %.c gcc -c $< -o $@ $(CFLAGS) -server-tls13-btle: server-tls13-btle.o ../btle-sim.o $(STATIC_LIB) +server-tls13-btle: server-tls13-btle.o ../common/btle-sim.o $(STATIC_LIB) $(CC) $^ -o $@ $(LIBS) -client-tls13-btle: client-tls13-btle.o ../btle-sim.o $(STATIC_LIB) +client-tls13-btle: client-tls13-btle.o ../common/btle-sim.o $(STATIC_LIB) $(CC) $^ -o $@ $(LIBS) clean: diff --git a/btle/tls/client-tls13-btle.c b/btle/tls/client-tls13-btle.c index 274b664e..6360d9cf 100644 --- a/btle/tls/client-tls13-btle.c +++ b/btle/tls/client-tls13-btle.c @@ -23,7 +23,7 @@ * Example TLSv1.3 client over BTLE */ -#include "../btle-sim.h" +#include "btle-sim.h" #ifndef WOLFSSL_USER_SETTINGS #include @@ -189,7 +189,7 @@ int main(int argc, char** argv) printf("Read (%d): %s\n", ret, plain); /* check for exit flag */ - if (strcasestr((char*)plain, EXIT_STRING)) { + if (strncmp((char*)plain, EXIT_STRING, strlen(EXIT_STRING)) == 0) { printf("Exit, closing connection\n"); break; } diff --git a/btle/tls/server-tls13-btle.c b/btle/tls/server-tls13-btle.c index d365b473..482bc6a0 100644 --- a/btle/tls/server-tls13-btle.c +++ b/btle/tls/server-tls13-btle.c @@ -23,7 +23,7 @@ * Example TLS v1.3 server over BTLE */ -#include "../btle-sim.h" +#include "btle-sim.h" #ifndef WOLFSSL_USER_SETTINGS #include @@ -177,7 +177,7 @@ int main(int argc, char** argv) printf("Sent (%d): %s\n", ret, echoBuffer); /* check for exit flag */ - if (strcasestr((char*)echoBuffer, EXIT_STRING)) { + if (strncmp((char*)echoBuffer, EXIT_STRING, strlen(EXIT_STRING)) == 0) { printf("Exit, closing connection\n"); break; }