tcp_transport: Update tcp_transport to support linux build

pull/10546/head
Harshit Malpani 2022-11-08 14:24:17 +05:30
rodzic 68ded2c350
commit 0635dc36c1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: FF1193D150EF75C3
3 zmienionych plików z 20 dodań i 3 usunięć

Wyświetl plik

@ -8,7 +8,12 @@ list(APPEND srcs
"transport_ws.c")
endif()
set(req esp-tls)
if(NOT ${IDF_TARGET} STREQUAL "linux")
list(APPEND req lwip)
endif()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "private_include"
REQUIRES esp-tls lwip)
REQUIRES ${req})

Wyświetl plik

@ -6,6 +6,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "esp_tls.h"
#include "esp_log.h"
@ -13,6 +14,7 @@
#include "esp_transport.h"
#include "esp_transport_ssl.h"
#include "esp_transport_internal.h"
#include "errno.h"
#define INVALID_SOCKET (-1)

Wyświetl plik

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/random.h>
#include <sys/socket.h>
@ -16,6 +17,7 @@
#include "esp_transport_internal.h"
#include "errno.h"
#include "esp_tls_crypto.h"
#include <arpa/inet.h>
static const char *TAG = "transport_ws";
@ -145,7 +147,11 @@ static int ws_connect(esp_transport_handle_t t, const char *host, int port, int
}
unsigned char random_key[16];
getrandom(random_key, sizeof(random_key), 0);
ssize_t rc;
if ((rc = getrandom(random_key, sizeof(random_key), 0)) < 0) {
ESP_LOGD(TAG, "getrandom() returned %zd", rc);
return -1;
}
// Size of base64 coded string is equal '((input_size * 4) / 3) + (input_size / 96) + 6' including Z-term
unsigned char client_key[28] = {0};
@ -289,7 +295,11 @@ static int _ws_write(esp_transport_handle_t t, int opcode, int mask_flag, const
if (mask_flag) {
mask = &ws_header[header_len];
getrandom(ws_header + header_len, 4, 0);
ssize_t rc;
if ((rc = getrandom(ws_header + header_len, 4, 0)) < 0) {
ESP_LOGD(TAG, "getrandom() returned %zd", rc);
return -1;
}
header_len += 4;
for (i = 0; i < len; ++i) {