minor fixes

pull/4676/head
Saksik Remy 2022-01-10 10:28:14 +08:00
parent 12d3f94c98
commit 1a291870a3
4 changed files with 24 additions and 52 deletions

View File

@ -24,6 +24,7 @@ endif
OBJS:=$(WOLFSSL_BUILD)/main.o $(WOLFSSL_BUILD)/client-tls13.o
default: all
.PHONY: all clean help
define run-help =

View File

@ -1,6 +1,6 @@
/* client-tls13.c
*
* Copyright (C) 2006-2020 wolfSSL Inc.
* Copyright (C) 2006-2022 wolfSSL Inc.
*
* This file is part of wolfSSL. (formerly known as CyaSSL)
*
@ -20,33 +20,24 @@
*/
/* C Standard Library */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
/* POSIX Library */
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
/* wolfSSL Library */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfio.h>
#include <wolfssl/wolfcrypt/port/iotsafe/iotsafe.h>
#include <wolfssl/error-ssl.h>
/* IoTSAFE Certificate slots */
/* File Slot '02' is pre-provisioned with
@ -84,21 +75,16 @@
#define PEER_CERT_ID 0x05
/* Function Declarations */
extern int client_loop(const char *peer_ip, const char *peer_name, const char *peer_port, const char *temperature);
extern int client_loop(const char *peer_ip, const char *peer_name,
const char *peer_port, const char *temperature);
#if defined(USE_SECRET_CALLBACK)
static int Tls13SecretCallback(WOLFSSL* ssl, int id, const unsigned char* secret, int secretSz, void* ctx);
static int Tls13SecretCallback(WOLFSSL* ssl, int id, const unsigned char* secret,
int secretSz, void* ctx);
#endif
/* Function Definitions */
#if defined(USE_SECRET_CALLBACK)
#ifndef WOLFSSL_SSLKEYLOGFILE_OUTPUT
@ -157,12 +143,10 @@ static int Tls13SecretCallback(WOLFSSL* ssl, int id, const unsigned char* secret
return 0;
}
#endif /* USE_SECRET_CALLBACK */
int client_loop(const char *peer_ip, const char *peer_name, const char *peer_port, const char *temperature)
int client_loop(const char *peer_ip, const char *peer_name,
const char *peer_port, const char *temperature)
{
int ret = 0;

View File

@ -1,6 +1,6 @@
/* main.c
*
* Copyright (C) 2006-2020 wolfSSL Inc.
* Copyright (C) 2006-2022 wolfSSL Inc.
*
* This file is part of wolfSSL. (formerly known as CyaSSL)
*
@ -24,15 +24,11 @@
*/
/* C Standard Library */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* POSIX Library */
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
@ -40,40 +36,32 @@
#include <termios.h>
#include <signal.h>
/* wolfSSL Library */
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/port/iotsafe/iotsafe.h>
/* Variable Declarations */
static int serial_fd = -1;
/* Function Declarations */
extern int client_loop(const char *peer_ip, const char *peer_name, const char *peer_port, const char *temperature);
extern int client_loop(const char *peer_ip, const char *peer_name,
const char *peer_port, const char *temperature);
#ifdef DEBUG_UART_IO
static void print_buffer_hex(const char *buf, int len);
static void print_buffer_char(const char *buf, int len);
#endif
static int usart_init(const char *dev_name, int *fd);
static int usart_clean(int fd);
static int usart_read(char *buf, int len);
static int usart_write(const char *buf, int len);
static void show_usage(const char *program);
/* Function Definitions */
#ifdef DEBUG_UART_IO
static void print_buffer_hex(const char *buf, int len)
{
for (int i = 0; i < len; i++)
@ -85,6 +73,7 @@ static void print_buffer_char(const char *buf, int len)
for (int i = 0; i < len; i++)
printf("%c", *(buf++));
}
#endif
static int usart_init(const char *dev_name, int *fd)
{
@ -134,21 +123,18 @@ static int usart_read(char *buf, int len)
char c;
memset(buf, 0, len);
/* Read 1 byte at one time until *buf is full or a POSIX read error like timeout occurs. */
/* Read 1 byte at one time until *buf is full or a POSIX read error like
* timeout occurs. */
do
{
ret = read(serial_fd, &c, 1U);
if (ret > 0)
{
if (ret > 0) {
buf[i++] = c;
if (c == '\n')
break;
}
} while (i < len && ret > 0);
#ifdef DEBUG_UART_IO
printf("UART Read Actual : %d bytes\n", i);
#ifdef DEBUG_UART_IO_EXTRA_VERBOSE
@ -196,7 +182,8 @@ static int usart_write(const char *buf, int len)
static void show_usage(const char *program)
{
printf("\nUsage:\n");
printf("\t%s -ip SERVER_IP_ADDRESS -h SERVER_HOST_NAME -p PORT_NUMBER -t TEMPERATURE -d DEVICE_FILE_PATH\n", program);
printf("\t%s -ip SERVER_IP_ADDRESS -h SERVER_HOST_NAME -p PORT_NUMBER "
"-t TEMPERATURE -d DEVICE_FILE_PATH\n", program);
printf("\n");
printf("\t-ip <server IPv4 address eg: 127.0.0.1>\n");
printf("\t-h <server name eg: xxx.amazon.com>\n");

View File

@ -1,6 +1,6 @@
/* iotsafe.c
*
* Copyright (C) 2006-2021 wolfSSL Inc.
* Copyright (C) 2006-2022 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
@ -241,7 +241,7 @@ static int iotsafe_cmd_add_tlv_ex(char *cmd, byte tag, uint16_t len,
char *len_csim_str = (cmd + AT_CSIM_CMD_SIZE - 5);
word32 cmdlen;
cmdlen = XSTRLEN(cmd);
cmdlen = (word32)XSTRLEN(cmd);
if (cmdlen < AT_CSIM_CMD_SIZE) {
return BAD_FUNC_ARG;
}