1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/lib/plat/optee/lws-plat-optee.c

262 lines
5.4 KiB
C
Raw Permalink Normal View History

/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "private-lib-core.h"
2017-01-17 07:01:02 +08:00
2019-01-15 06:59:48 +08:00
#if !defined(LWS_WITH_NETWORK)
#include <crypto/crypto.h>
#endif
int errno;
#if !defined(LWS_WITH_NETWORK)
char *
strcpy(char *dest, const char *src)
{
char *desto = dest;
while (*src)
*(dest++) = *(src++);
*(dest++) = '\0';
return desto;
}
char *strncpy(char *dest, const char *src, size_t limit)
{
char *desto = dest;
while (*src && limit--)
*(dest++) = *(src++);
if (limit)
*(dest++) = '\0';
return desto;
}
#endif
2018-08-01 06:52:03 +08:00
int lws_plat_apply_FD_CLOEXEC(int n)
{
2018-08-01 06:52:03 +08:00
return 0;
}
2017-01-17 07:01:02 +08:00
void TEE_GenerateRandom(void *randomBuffer, uint32_t randomBufferLen);
2019-01-15 06:59:48 +08:00
#if defined(LWS_WITH_NETWORK)
uint64_t
lws_now_usecs(void)
2017-01-17 07:01:02 +08:00
{
return ((unsigned long long)time(NULL)) * 1000000;
}
2019-01-15 06:59:48 +08:00
#endif
size_t
lws_get_random(struct lws_context *context, void *buf, size_t len)
2017-01-17 07:01:02 +08:00
{
2019-01-15 06:59:48 +08:00
#if defined(LWS_WITH_NETWORK)
2017-01-17 07:01:02 +08:00
TEE_GenerateRandom(buf, len);
2019-01-15 06:59:48 +08:00
#else
crypto_rng_read(buf, len);
#endif
2017-01-17 07:01:02 +08:00
return len;
}
2019-01-15 06:59:48 +08:00
static const char * const colours[] = {
"[31;1m", /* LLL_ERR */
"[36;1m", /* LLL_WARN */
"[35;1m", /* LLL_NOTICE */
"[32;1m", /* LLL_INFO */
"[34;1m", /* LLL_DEBUG */
"[33;1m", /* LLL_PARSER */
"[33;1m", /* LLL_HEADER */
"[33;1m", /* LLL_EXT */
"[33;1m", /* LLL_CLIENT */
"[33;1m", /* LLL_LATENCY */
"[30;1m", /* LLL_USER */
};
void lwsl_emit_optee(int level, const char *line)
2017-01-17 07:01:02 +08:00
{
2019-01-15 06:59:48 +08:00
char buf[50], linecp[512];
int n, m = LWS_ARRAY_SIZE(colours) - 1;
lwsl_timestamp(level, buf, sizeof(buf));
n = 1 << (LWS_ARRAY_SIZE(colours) - 1);
while (n) {
if (level & n)
break;
m--;
n >>= 1;
}
n = strlen(line);
if ((unsigned int)n > sizeof(linecp) - 1)
n = sizeof(linecp) - 1;
2019-02-15 08:46:30 +08:00
if (n) {
2019-01-15 06:59:48 +08:00
memcpy(linecp, line, n - 1);
2019-02-15 08:46:30 +08:00
linecp[n - 1] = '\0';
} else
linecp[0] = '\0';
2019-01-15 06:59:48 +08:00
EMSG("%c%s%s%s%c[0m", 27, colours[m], buf, linecp, 27);
2017-01-17 07:01:02 +08:00
}
2019-01-15 06:59:48 +08:00
int
lws_plat_set_nonblocking(lws_sockfd_type fd)
{
return 0;
}
2017-01-17 07:01:02 +08:00
int
lws_plat_drop_app_privileges(struct lws_context *context, int actually_init)
2017-01-17 07:01:02 +08:00
{
return 0;
2017-01-17 07:01:02 +08:00
}
int
2017-01-17 07:01:02 +08:00
lws_plat_context_early_init(void)
{
return 0;
}
void
2017-01-17 07:01:02 +08:00
lws_plat_context_early_destroy(struct lws_context *context)
{
}
void
2017-01-17 07:01:02 +08:00
lws_plat_context_late_destroy(struct lws_context *context)
{
#if defined(LWS_WITH_NETWORK)
2017-01-17 07:01:02 +08:00
if (context->lws_lookup)
lws_free(context->lws_lookup);
#endif
}
lws_fop_fd_t
2017-12-20 10:44:21 +08:00
_lws_plat_file_open(const struct lws_plat_file_ops *fops,
const char *filename, const char *vpath, lws_fop_flags_t *flags)
2017-01-17 07:01:02 +08:00
{
2017-02-25 12:42:45 +08:00
return NULL;
2017-01-17 07:01:02 +08:00
}
int
2017-03-03 12:38:10 +08:00
_lws_plat_file_close(lws_fop_fd_t *fop_fd)
2017-01-17 07:01:02 +08:00
{
return 0;
}
lws_fileofs_t
2017-02-25 12:42:45 +08:00
_lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
2017-01-17 07:01:02 +08:00
{
return 0;
}
int
2017-02-25 12:42:45 +08:00
_lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
uint8_t *buf, lws_filepos_t len)
2017-01-17 07:01:02 +08:00
{
return 0;
}
int
2017-02-25 12:42:45 +08:00
_lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
uint8_t *buf, lws_filepos_t len)
2017-01-17 07:01:02 +08:00
{
return 0;
}
int
2017-01-17 07:01:02 +08:00
lws_plat_init(struct lws_context *context,
const struct lws_context_creation_info *info)
2017-01-17 07:01:02 +08:00
{
#if defined(LWS_WITH_NETWORK)
2020-10-11 07:43:46 +01:00
/* context has the global fd lookup array */
2017-01-17 07:01:02 +08:00
context->lws_lookup = lws_zalloc(sizeof(struct lws *) *
2017-10-04 07:10:39 +08:00
context->max_fds, "lws_lookup");
2017-01-17 07:01:02 +08:00
if (context->lws_lookup == NULL) {
lwsl_err("OOM on lws_lookup array for %d connections\n",
context->max_fds);
return 1;
}
2017-02-06 14:35:30 +08:00
lwsl_notice(" mem: platform fd map: %5lu bytes\n",
(long)sizeof(struct lws *) * context->max_fds);
#endif
2017-01-17 07:01:02 +08:00
#ifdef LWS_WITH_PLUGINS
if (info->plugin_dirs)
lws_plat_plugins_init(context, info->plugin_dirs);
#endif
return 0;
}
int
lws_plat_write_file(const char *filename, void *buf, size_t len)
{
return 1;
}
int
lws_plat_read_file(const char *filename, void *buf, int len)
{
return -1;
}
int
lws_plat_recommended_rsa_bits(void)
{
return 4096;
}
int
lws_plat_ntpclient_config(struct lws_context *context)
{
#if 0
char *ntpsrv = getenv("LWS_NTP_SERVER");
if (ntpsrv && strlen(ntpsrv) < 64) {
lws_system_blob_heap_append(lws_system_get_blob(context,
LWS_SYSBLOB_TYPE_NTP_SERVER, 0),
(const uint8_t *)ntpsrv,
strlen(ntpsrv));
return 1;
}
#endif
return 0;
}
void
lws_msleep(unsigned int ms)
{
}