text stringlengths 9 39.2M | dir stringlengths 25 226 | lang stringclasses 163 values | created_date timestamp[s] | updated_date timestamp[s] | repo_name stringclasses 751 values | repo_full_name stringclasses 752 values | star int64 1.01k 183k | len_tokens int64 1 18.5M |
|---|---|---|---|---|---|---|---|---|
```c
/** @file
* @brief mbed TLS initialization
*
* Initialize the mbed TLS library like setup the heap etc.
*/
/*
*
*/
#include <zephyr/init.h>
#include <zephyr/app_memory/app_memdomain.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/random/random.h>
#include <mbedtls/entropy.h>
#include <mbedtls/platform_time.h>
#include <mbedtls/debug.h>
#if defined(CONFIG_MBEDTLS)
#if !defined(CONFIG_MBEDTLS_CFG_FILE)
#include "mbedtls/config.h"
#else
#include CONFIG_MBEDTLS_CFG_FILE
#endif /* CONFIG_MBEDTLS_CFG_FILE */
#endif
#if defined(CONFIG_MBEDTLS_ENABLE_HEAP) && \
defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
#include <mbedtls/memory_buffer_alloc.h>
#if !defined(CONFIG_MBEDTLS_HEAP_SIZE)
#error "Please set heap size to be used. Set value to CONFIG_MBEDTLS_HEAP_SIZE \
option."
#endif
static unsigned char _mbedtls_heap[CONFIG_MBEDTLS_HEAP_SIZE];
static void init_heap(void)
{
mbedtls_memory_buffer_alloc_init(_mbedtls_heap, sizeof(_mbedtls_heap));
}
#else
#define init_heap(...)
#endif /* CONFIG_MBEDTLS_ENABLE_HEAP && MBEDTLS_MEMORY_BUFFER_ALLOC_C */
#if defined(CONFIG_MBEDTLS_ZEPHYR_ENTROPY)
static const struct device *const entropy_dev =
DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_entropy));
int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len,
size_t *olen)
{
int ret;
uint16_t request_len = len > UINT16_MAX ? UINT16_MAX : len;
ARG_UNUSED(data);
if (output == NULL || olen == NULL || len == 0) {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
if (!IS_ENABLED(CONFIG_ENTROPY_HAS_DRIVER)) {
sys_rand_get(output, len);
*olen = len;
return 0;
}
if (!device_is_ready(entropy_dev)) {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
ret = entropy_get_entropy(entropy_dev, (uint8_t *)output, request_len);
if (ret < 0) {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
*olen = request_len;
return 0;
}
#endif /* CONFIG_MBEDTLS_ZEPHYR_ENTROPY */
static int _mbedtls_init(void)
{
init_heap();
#if defined(CONFIG_MBEDTLS_DEBUG_LEVEL)
mbedtls_debug_set_threshold(CONFIG_MBEDTLS_DEBUG_LEVEL);
#endif
#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_CLIENT)
if (psa_crypto_init() != PSA_SUCCESS) {
return -EIO;
}
#endif
return 0;
}
#if defined(CONFIG_MBEDTLS_INIT)
SYS_INIT(_mbedtls_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
#endif
/* if CONFIG_MBEDTLS_INIT is not defined then this function
* should be called by the platform before any mbedtls functionality
* is used
*/
int mbedtls_init(void)
{
return _mbedtls_init();
}
/* TLS 1.3 ticket lifetime needs a timing interface */
mbedtls_ms_time_t mbedtls_ms_time(void)
{
return (mbedtls_ms_time_t)k_uptime_get();
}
#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
/* MBEDTLS_PSA_CRYPTO_C requires a random generator to work and this can
* be achieved through either legacy MbedTLS modules
* (ENTROPY + CTR_DRBG/HMAC_DRBG) or provided externally by enabling the
* CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG. In the latter case the following
* callback functions needs to be defined.
*/
psa_status_t mbedtls_psa_external_get_random(
mbedtls_psa_external_random_context_t *context,
uint8_t *output, size_t output_size, size_t *output_length)
{
(void) context;
if (sys_csrand_get(output, output_size) != 0) {
return PSA_ERROR_GENERIC_ERROR;
}
*output_length = output_size;
return PSA_SUCCESS;
}
#endif
``` | /content/code_sandbox/modules/mbedtls/zephyr_init.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 870 |
```unknown
# TLS/DTLS related options
menu "Mbed TLS configuration"
depends on MBEDTLS_BUILTIN && MBEDTLS_CFG_FILE = "config-tls-generic.h"
menu "TLS"
config MBEDTLS_TLS_VERSION_1_2
bool "Support for TLS 1.2 (DTLS 1.2)"
select MBEDTLS_CIPHER
select MBEDTLS_MD
if MBEDTLS_TLS_VERSION_1_2
config MBEDTLS_DTLS
bool "Support for DTLS"
config MBEDTLS_SSL_EXPORT_KEYS
bool "Support for exporting SSL key block and master secret"
config MBEDTLS_SSL_ALPN
bool "Support for setting the supported Application Layer Protocols"
endif
endmenu # TLS
menu "Ciphersuite configuration"
comment "Supported key exchange modes"
config MBEDTLS_KEY_EXCHANGE_ALL_ENABLED
bool "All available ciphersuite modes"
select MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
select MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
select MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
select MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
select MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
config MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
bool "PSK based ciphersuite modes"
config MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
bool "DHE-PSK based ciphersuite modes"
config MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
bool "ECDHE-PSK based ciphersuite modes"
depends on MBEDTLS_ECDH_C
config MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
bool "RSA-PSK based ciphersuite modes"
config MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED
bool
default y
depends on \
MBEDTLS_KEY_EXCHANGE_PSK_ENABLED || \
MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED || \
MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED || \
MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
config MBEDTLS_PSK_MAX_LEN
int "Max size of TLS pre-shared keys"
default 32
depends on MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED
help
Max size of TLS pre-shared keys, in bytes.
config MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
bool "RSA-only based ciphersuite modes"
default y if UOSCORE || UEDHOC
select MBEDTLS_MD
select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY if PSA_CRYPTO_CLIENT
select PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC if PSA_CRYPTO_CLIENT
select PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT if PSA_CRYPTO_CLIENT
config MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
bool "DHE-RSA based ciphersuite modes"
config MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
bool "ECDHE-RSA based ciphersuite modes"
depends on MBEDTLS_ECDH_C
config MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
bool "ECDHE-ECDSA based ciphersuite modes"
depends on MBEDTLS_ECDH_C && MBEDTLS_ECDSA_C
config MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
bool "ECDH-ECDSA based ciphersuite modes"
depends on (MBEDTLS_ECDH_C && MBEDTLS_ECDSA_C) || (PSA_WANT_ALG_ECDH && PSA_WANT_ALG_ECDSA)
config MBEDTLS_ECDSA_DETERMINISTIC
bool "Deterministic ECDSA (RFC 6979)"
config MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
bool "ECDH-RSA based ciphersuite modes"
depends on MBEDTLS_ECDH_C
config MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
bool "ECJPAKE based ciphersuite modes"
depends on MBEDTLS_ECJPAKE_C
config MBEDTLS_HKDF_C
bool "HMAC-based Extract-and-Expand Key Derivation Function"
comment "Elliptic curve libraries"
config MBEDTLS_ECDH_C
bool "Elliptic curve Diffie-Hellman library"
depends on MBEDTLS_ECP_C
config MBEDTLS_ECDSA_C
bool "Elliptic curve DSA library"
depends on MBEDTLS_ECP_C
config MBEDTLS_ECJPAKE_C
bool "Elliptic curve J-PAKE library"
depends on MBEDTLS_ECP_C
config MBEDTLS_ECP_C
bool "Elliptic curve over GF(p) library"
default y if UOSCORE || UEDHOC
if MBEDTLS_ECP_C
comment "Supported elliptic curves"
config MBEDTLS_ECP_ALL_ENABLED
bool "All available elliptic curves"
select MBEDTLS_ECP_DP_SECP192R1_ENABLED
select MBEDTLS_ECP_DP_SECP192R1_ENABLED
select MBEDTLS_ECP_DP_SECP224R1_ENABLED
select MBEDTLS_ECP_DP_SECP256R1_ENABLED
select MBEDTLS_ECP_DP_SECP384R1_ENABLED
select MBEDTLS_ECP_DP_SECP521R1_ENABLED
select MBEDTLS_ECP_DP_SECP192K1_ENABLED
select MBEDTLS_ECP_DP_SECP224K1_ENABLED
select MBEDTLS_ECP_DP_SECP256K1_ENABLED
select MBEDTLS_ECP_DP_BP256R1_ENABLED
select MBEDTLS_ECP_DP_BP384R1_ENABLED
select MBEDTLS_ECP_DP_BP512R1_ENABLED
select MBEDTLS_ECP_DP_CURVE25519_ENABLED
select MBEDTLS_ECP_DP_CURVE448_ENABLED
select MBEDTLS_ECP_NIST_OPTIM
config MBEDTLS_ECP_DP_SECP192R1_ENABLED
bool "SECP192R1 elliptic curve"
config MBEDTLS_ECP_DP_SECP224R1_ENABLED
bool "SECP224R1 elliptic curve"
config MBEDTLS_ECP_DP_SECP256R1_ENABLED
bool "SECP256R1 elliptic curve"
default y if UOSCORE || UEDHOC
config MBEDTLS_ECP_DP_SECP384R1_ENABLED
bool "SECP384R1 elliptic curve"
config MBEDTLS_ECP_DP_SECP521R1_ENABLED
bool "SECP521R1 elliptic curve"
config MBEDTLS_ECP_DP_SECP192K1_ENABLED
bool "SECP192K1 elliptic curve"
config MBEDTLS_ECP_DP_SECP224K1_ENABLED
bool "SECP224K1 elliptic curve"
config MBEDTLS_ECP_DP_SECP256K1_ENABLED
bool "SECP256K1 elliptic curve"
config MBEDTLS_ECP_DP_BP256R1_ENABLED
bool "BP256R1 elliptic curve"
config MBEDTLS_ECP_DP_BP384R1_ENABLED
bool "BP384R1 elliptic curve"
config MBEDTLS_ECP_DP_BP512R1_ENABLED
bool "BP512R1 elliptic curve"
config MBEDTLS_ECP_DP_CURVE25519_ENABLED
bool "CURVE25519 elliptic curve"
config MBEDTLS_ECP_DP_CURVE448_ENABLED
bool "CURVE448 elliptic curve"
config MBEDTLS_ECP_NIST_OPTIM
bool "NSIT curves optimization"
endif
comment "Supported ciphers and cipher modes"
config MBEDTLS_CIPHER_ALL_ENABLED
bool "All available ciphers and modes"
select MBEDTLS_CIPHER_AES_ENABLED
select MBEDTLS_CIPHER_CAMELLIA_ENABLED
select MBEDTLS_CIPHER_DES_ENABLED
select MBEDTLS_CIPHER_CHACHA20_ENABLED
select MBEDTLS_CIPHER_CCM_ENABLED
select MBEDTLS_CIPHER_GCM_ENABLED
select MBEDTLS_CIPHER_MODE_XTS_ENABLED
select MBEDTLS_CIPHER_MODE_CBC_ENABLED
select MBEDTLS_CIPHER_MODE_CTR_ENABLED
select MBEDTLS_CHACHAPOLY_AEAD_ENABLED
config MBEDTLS_SOME_AEAD_CIPHER_ENABLED
bool
default y
depends on \
MBEDTLS_CIPHER_AES_ENABLED || \
MBEDTLS_CIPHER_CAMELLIA_ENABLED
config MBEDTLS_SOME_CIPHER_ENABLED
bool
default y
depends on \
MBEDTLS_SOME_AEAD_CIPHER_ENABLED || \
MBEDTLS_CIPHER_DES_ENABLED || \
MBEDTLS_CIPHER_CHACHA20_ENABLED
config MBEDTLS_CIPHER_AES_ENABLED
bool "AES block cipher"
if MBEDTLS_CIPHER_AES_ENABLED
config MBEDTLS_AES_ROM_TABLES
bool "Use precomputed AES tables stored in ROM."
config MBEDTLS_AES_FEWER_TABLES
bool "Reduce the size of precomputed AES tables by ~6kB"
default y
depends on MBEDTLS_AES_ROM_TABLES
help
Reduce the size of the AES tables at a tradeoff of more
arithmetic operations at runtime. Specifically 4 table
lookups are converted to 1 table lookup, 3 additions
and 6 bit shifts.
config MBEDTLS_CIPHER_MODE_XTS_ENABLED
bool "Xor-encrypt-xor with ciphertext stealing mode (XTS) for AES"
endif # MBEDTLS_CIPHER_AES_ENABLED
config MBEDTLS_CIPHER_CAMELLIA_ENABLED
bool "Camellia block cipher"
config MBEDTLS_CIPHER_DES_ENABLED
bool "DES block cipher"
config MBEDTLS_CIPHER_CHACHA20_ENABLED
bool "ChaCha20 stream cipher"
if MBEDTLS_SOME_AEAD_CIPHER_ENABLED
config MBEDTLS_CIPHER_CCM_ENABLED
bool "Counter with CBC-MAC (CCM) mode for 128-bit block cipher"
default y if UOSCORE || UEDHOC
config MBEDTLS_CIPHER_GCM_ENABLED
bool "Galois/Counter Mode (GCM) for symmetric ciphers"
endif # MBEDTLS_SOME_AEAD_CIPHER_ENABLED
if MBEDTLS_SOME_CIPHER_ENABLED
config MBEDTLS_CIPHER_MODE_CBC_ENABLED
bool "Cipher Block Chaining mode (CBC) for symmetric ciphers"
default y if !NET_L2_OPENTHREAD
config MBEDTLS_CIPHER_MODE_CTR_ENABLED
bool "Counter Block Cipher mode (CTR) for symmetric ciphers"
endif # MBEDTLS_SOME_CIPHER_ENABLED
config MBEDTLS_CHACHAPOLY_AEAD_ENABLED
bool "ChaCha20-Poly1305 AEAD algorithm"
depends on MBEDTLS_CIPHER_CHACHA20_ENABLED && MBEDTLS_POLY1305
config MBEDTLS_CMAC
bool "CMAC (Cipher-based Message Authentication Code) mode for block ciphers."
depends on MBEDTLS_CIPHER_AES_ENABLED || MBEDTLS_CIPHER_DES_ENABLED
comment "Supported hash algorithms"
config MBEDTLS_HASH_ALL_ENABLED
bool "All available MAC methods"
select MBEDTLS_MD5
select MBEDTLS_SHA1
select MBEDTLS_SHA224
select MBEDTLS_SHA256
select MBEDTLS_SHA384
select MBEDTLS_SHA512
select MBEDTLS_POLY1305
config MBEDTLS_MD5
bool "MD5 hash algorithm"
config MBEDTLS_SHA1
bool "SHA-1 hash algorithm"
config MBEDTLS_SHA224
bool "SHA-224 hash algorithm"
config MBEDTLS_SHA256
bool "SHA-256 hash algorithm"
default y
config MBEDTLS_SHA256_SMALLER
bool "Smaller SHA-256 implementation"
depends on MBEDTLS_SHA256
default y
help
Enable an implementation of SHA-256 that has a
smaller ROM footprint but also lower performance.
config MBEDTLS_SHA384
bool "SHA-384 hash algorithm"
config MBEDTLS_SHA512
bool "SHA-512 hash algorithm"
config MBEDTLS_POLY1305
bool "Poly1305 hash family"
endmenu
comment "Random number generators"
config MBEDTLS_CTR_DRBG_ENABLED
bool "CTR_DRBG AES-256-based random generator"
depends on MBEDTLS_CIPHER_AES_ENABLED
default y
config MBEDTLS_HMAC_DRBG_ENABLED
bool "HMAC_DRBG random generator"
select MBEDTLS_MD
comment "Other configurations"
config MBEDTLS_CIPHER
bool "generic cipher layer."
default y if PSA_WANT_ALG_CMAC
config MBEDTLS_MD
bool "generic message digest layer."
config MBEDTLS_GENPRIME_ENABLED
bool "prime-number generation code."
config MBEDTLS_PEM_CERTIFICATE_FORMAT
bool "Support for PEM certificate format"
help
By default only DER (binary) format of certificates is supported. Enable
this option to enable support for PEM format.
config MBEDTLS_HAVE_ASM
bool "Use of assembly code"
default y if !ARM
help
Enable use of assembly code in mbedTLS. This improves the performances
of asymmetric cryptography, however this might have an impact on the
code size.
config MBEDTLS_ENTROPY_ENABLED
bool "MbedTLS generic entropy pool"
depends on MBEDTLS_SHA256 || MBEDTLS_SHA384 || MBEDTLS_SHA512
default y if MBEDTLS_ZEPHYR_ENTROPY
config MBEDTLS_OPENTHREAD_OPTIMIZATIONS_ENABLED
bool "MbedTLS optimizations for OpenThread"
depends on NET_L2_OPENTHREAD
default y if !NET_SOCKETS_SOCKOPT_TLS
help
Enable some OpenThread specific mbedTLS optimizations that allows to
save some RAM/ROM when OpenThread is used. Note, that when application
aims to use other mbedTLS services on top of OpenThread (e.g. secure
sockets), it's advised to disable this option.
config MBEDTLS_USER_CONFIG_ENABLE
bool "User mbedTLS config file"
help
Enable user mbedTLS config file that will be included at the end of
the generic config file.
config MBEDTLS_USER_CONFIG_FILE
string "User configuration file for mbed TLS" if MBEDTLS_USER_CONFIG_ENABLE
help
User config file that can contain mbedTLS configs that were not
covered by the generic config file.
config MBEDTLS_SERVER_NAME_INDICATION
bool "Support for RFC 6066 server name indication (SNI) in SSL"
help
Enable this to support RFC 6066 server name indication (SNI) in SSL.
This requires that MBEDTLS_X509_CRT_PARSE_C is also set.
config MBEDTLS_PK_WRITE_C
bool "The generic public (asymmetric) key writer"
help
Enable generic public key write functions.
config MBEDTLS_HAVE_TIME_DATE
bool "Date/time validation in mbed TLS"
help
System has time.h, time(), and an implementation for gmtime_r().
There also need to be a valid time source in the system, as mbedTLS
expects a valid date/time for certificate validation."
config MBEDTLS_PKCS5_C
bool "Password-based encryption functions"
select MBEDTLS_MD
help
Enable PKCS5 functions
config MBEDTLS_SSL_CACHE_C
bool "SSL session cache support"
help
"This option enables simple SSL cache implementation (server side)."
if MBEDTLS_SSL_CACHE_C
config MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT
int "Default timeout for SSL cache entires"
default 86400
config MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES
int "Maximum number of SSL cache entires"
default 5
endif # MBEDTLS_SSL_CACHE_C
config MBEDTLS_SSL_EXTENDED_MASTER_SECRET
bool "(D)TLS Extended Master Secret extension"
depends on MBEDTLS_TLS_VERSION_1_2
help
Enable support for the (D)TLS Extended Master Secret extension
which ensures that master secrets are different for every
connection and every session.
choice MBEDTLS_PSA_CRYPTO_RNG_SOURCE
prompt "Select random source for built-in PSA crypto"
depends on MBEDTLS_PSA_CRYPTO_C
default MBEDTLS_PSA_CRYPTO_LEGACY_RNG
config MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
bool "Use a cryptographically secure driver as random source"
depends on CSPRNG_ENABLED
help
Use cryptographically secure random generator to provide random data
instead of legacy MbedTLS modules (ENTROPY + CTR_DRBG/HMAC_DRBG).
config MBEDTLS_PSA_CRYPTO_LEGACY_RNG
bool "Use legacy modules to generate random data"
select MBEDTLS_ENTROPY_ENABLED
select MBEDTLS_HMAC_DRBG_ENABLED if !MBEDTLS_CTR_DRBG_ENABLED
help
Use legacy MbedTLS modules (ENTROPY + CTR_DRBG/HMAC_DRBG) as random
source generators.
endchoice
config MBEDTLS_PSA_CRYPTO_C
bool "Platform Security Architecture cryptography API"
depends on !BUILD_WITH_TFM
default y if UOSCORE || UEDHOC
config MBEDTLS_USE_PSA_CRYPTO
bool "Use PSA APIs instead of legacy MbedTLS when possible"
default y if MBEDTLS_PSA_CRYPTO_CLIENT
help
Use PSA APIs instead of legacy MbedTLS functions in TLS/DTLS and other
"intermediate" modules such as PK, MD and Cipher.
config MBEDTLS_PSA_CRYPTO_CLIENT
bool
default y
depends on BUILD_WITH_TFM || MBEDTLS_PSA_CRYPTO_C
select PSA_CRYPTO_CLIENT
config MBEDTLS_LMS
bool "Support LMS signature schemes"
depends on MBEDTLS_PSA_CRYPTO_CLIENT
depends on MBEDTLS_SHA256
select PSA_WANT_ALG_SHA_256
config MBEDTLS_PSA_P256M_DRIVER_ENABLED
bool "P256-M driver"
depends on MBEDTLS_PSA_CRYPTO_C
imply PSA_WANT_ALG_SHA_256
help
Enable support for the optimized sofware implementation of the secp256r1
curve through the standard PSA API.
config MBEDTLS_PSA_P256M_DRIVER_RAW
bool "Access p256-m driver directly (without PSA interface)"
depends on MBEDTLS_PSA_P256M_DRIVER_ENABLED
help
Allow direct access to the p256-m driver interface.
Warning: Usage of this Kconfig option is prohibited in Zephyr's codebase.
Users can enable it in case of very memory-constrained devices, but be aware that the p256-m interface is absolutely not guaranted to remain stable over time.
config MBEDTLS_SSL_DTLS_CONNECTION_ID
bool "DTLS Connection ID extension"
depends on MBEDTLS_DTLS
help
Enable support for the DTLS Connection ID extension
which allows to identify DTLS connections across changes
in the underlying transport.
config MBEDTLS_NIST_KW_C
bool "NIST key wrap"
depends on MBEDTLS_CIPHER_AES_ENABLED
help
Key Wrapping mode for 128-bit block ciphers,
as defined in NIST SP 800-38F.
config MBEDTLS_DHM_C
bool "Diffie-Hellman-Merkle mode"
help
Used by the following key exchanges,
DHE-RSA, DHE-PSK
config MBEDTLS_X509_CRL_PARSE_C
bool "X509 CRL parsing"
help
Used by X509 CRL parsing
config MBEDTLS_X509_CSR_WRITE_C
bool "X509 Certificate Signing Requests writing"
help
For X.509 certificate request writing.
config MBEDTLS_X509_CSR_PARSE_C
bool "X509 Certificate Signing Request parsing"
help
For reading X.509 certificate request.
endmenu
``` | /content/code_sandbox/modules/mbedtls/Kconfig.tls-generic | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 4,226 |
```c
/*
*
*/
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(mbedtls, CONFIG_MBEDTLS_LOG_LEVEL);
#include "zephyr_mbedtls_priv.h"
void zephyr_mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str)
{
const char *p, *basename = file;
int str_len;
ARG_UNUSED(ctx);
if (!file || !str) {
return;
}
/* Extract basename from file */
if (IS_ENABLED(CONFIG_MBEDTLS_DEBUG_EXTRACT_BASENAME_AT_RUNTIME)) {
for (p = basename = file; *p != '\0'; p++) {
if (*p == '/' || *p == '\\') {
basename = p + 1;
}
}
}
str_len = strlen(str);
if (IS_ENABLED(CONFIG_MBEDTLS_DEBUG_STRIP_NEWLINE)) {
/* Remove newline only when it exists */
if (str_len > 0 && str[str_len - 1] == '\n') {
str_len--;
}
}
switch (level) {
case 0:
case 1:
LOG_ERR("%s:%04d: %.*s", basename, line, str_len, str);
break;
case 2:
LOG_WRN("%s:%04d: %.*s", basename, line, str_len, str);
break;
case 3:
LOG_INF("%s:%04d: %.*s", basename, line, str_len, str);
break;
default:
LOG_DBG("%s:%04d: %.*s", basename, line, str_len, str);
break;
}
}
``` | /content/code_sandbox/modules/mbedtls/debug.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 355 |
```objective-c
/**
* \file config-thread.h
*
* \brief Minimal configuration for using TLS as part of Thread
*/
/*
*
*
* **********
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* **********
*
* **********
*
* This program is free software; you can redistribute it and/or modify
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* **********
*/
/*
* Minimal configuration for using TLS a part of Thread
* path_to_url
*
* Distinguishing features:
* - no RSA or classic DH, fully based on ECC
* - no X.509
* - support for experimental EC J-PAKE key exchange
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_HAVE_ASM
/* mbed TLS feature support */
#define MBEDTLS_AES_ROM_TABLES
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_ECP_NIST_OPTIM
#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_PROTO_DTLS
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
#define MBEDTLS_SSL_EXPORT_KEYS
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_CMAC_C
#define MBEDTLS_ECJPAKE_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_HMAC_DRBG_C
#define MBEDTLS_MD_C
#define MBEDTLS_OID_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SSL_COOKIE_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
/* For tests using ssl-opt.sh */
#define MBEDTLS_NET_C
#define MBEDTLS_TIMING_C
/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES
/* Save RAM by adjusting to our exact needs */
#define MBEDTLS_MPI_MAX_SIZE 32 // 256 bits is 32 bytes
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-thread.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 722 |
```objective-c
/**
* \file config-mini-tls1_1.h
*
* \brief Minimal configuration for TLS 1.1 (RFC 4346)
*/
/*
*
*
* **********
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* **********
*
* **********
*
* This program is free software; you can redistribute it and/or modify
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* **********
*/
/*
* Minimal configuration for TLS 1.1 (RFC 4346), implementing only the
* required ciphersuite: MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_HAVE_ASM
#define MBEDTLS_HAVE_TIME
#define MBEDTLS_PLATFORM_MS_TIME_ALT
/* mbed TLS feature support */
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_SSL_PROTO_TLS1_1
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_DES_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_MD_C
#define MBEDTLS_MD5_C
#define MBEDTLS_NET_C
#define MBEDTLS_OID_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_RSA_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_USE_C
/* For test certificates */
#define MBEDTLS_BASE64_C
#define MBEDTLS_CERTS_C
#define MBEDTLS_PEM_PARSE_C
/* For testing with compat.sh */
#define MBEDTLS_FS_IO
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-mini-tls1_1.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 598 |
```unknown
# Cryptography primitive options for mbed TLS
config ZEPHYR_MBEDTLS_MODULE
bool
config MBEDTLS_PROMPTLESS
bool
help
Symbol to disable the prompt for MBEDTLS selection.
This symbol may be used internally in a Kconfig tree to hide the
mbed TLS menu prompt and instead handle the selection of MBEDTLS from
dependent sub-configurations and thus prevent stuck symbol behavior.
rsource "Kconfig.psa"
menuconfig MBEDTLS
bool "mbed TLS Support" if !MBEDTLS_PROMPTLESS
help
This option enables the mbedTLS cryptography library.
if MBEDTLS
choice MBEDTLS_IMPLEMENTATION
prompt "Select implementation"
default MBEDTLS_BUILTIN
config MBEDTLS_BUILTIN
bool "Use Zephyr in-tree mbedTLS version"
help
Link with mbedTLS sources included with Zephyr distribution.
Included mbedTLS version is well integrated with and supported
by Zephyr, and the recommended choice for most users.
config MBEDTLS_LIBRARY
bool "Use external mbedTLS library"
help
Use external, out-of-tree prebuilt mbedTLS library. For advanced
users only.
endchoice
config CUSTOM_MBEDTLS_CFG_FILE
bool "Custom mbed TLS configuration file"
help
Allow user defined input for the MBEDTLS_CFG_FILE setting.
You can specify the actual configuration file using the
MBEDTLS_CFG_FILE setting.
config MBEDTLS_CFG_FILE
string "mbed TLS configuration file" if CUSTOM_MBEDTLS_CFG_FILE
depends on MBEDTLS_BUILTIN
default "config-tls-generic.h"
help
Use a specific mbedTLS configuration file. The default config file
file can be tweaked with Kconfig. The default configuration is
suitable to communicate with majority of HTTPS servers on the Internet,
but has relatively many features enabled. To optimize resources for
special TLS usage, use available Kconfig options, or select an
alternative config.
rsource "Kconfig.tls-generic"
config MBEDTLS_SSL_MAX_CONTENT_LEN
int "Max payload size for TLS protocol message"
default 1500
depends on MBEDTLS_BUILTIN
help
The TLS standards mandate max payload size of 16384 bytes. So, for
maximum operability and for general-purpose usage, that value must
be used. For specific usages, that value can be largely decreased.
E.g. for DTLS, payload size is limited by UDP datagram size, and
even for HTTPS REST API, the payload can be limited to max size of
(REST request, REST response, server certificate(s)).
mbedTLS uses this value separate for input and output buffers, so
twice this value will be allocated (on mbedTLS own heap, so the
value of MBEDTLS_HEAP_SIZE should accommodate that).
module = MBEDTLS
module-str = Log level mbedTLS library debug hook
source "subsys/logging/Kconfig.template.log_config"
config MBEDTLS_DEBUG
bool "mbed TLS debug activation"
help
Enable debugging activation for mbed TLS configuration. If you use
mbedTLS/Zephyr integration (e.g. native TLS sockets), this will
activate debug logging.
If you use mbedTLS directly instead, you will need to perform
additional configuration yourself: call
mbedtls_ssl_conf_dbg(&mbedtls.conf, zephyr_mbedtls_debug, NULL);
function in your application. Alternatively implement your own debug
hook function if zephyr_mbedtls_debug() doesn't suit your needs.
if MBEDTLS_DEBUG
config MBEDTLS_DEBUG_LEVEL
int
default 4 if MBEDTLS_LOG_LEVEL_DBG
default 3 if MBEDTLS_LOG_LEVEL_INF
default 2 if MBEDTLS_LOG_LEVEL_WRN
default 1 if MBEDTLS_LOG_LEVEL_ERR
default 0
range 0 4
help
Default mbed TLS debug logging level for Zephyr integration code
(from ext/lib/crypto/mbedtls/include/mbedtls/debug.h):
0 No debug
1 Error
2 State change
3 Information
4 Verbose
This makes Zephyr call mbedtls_debug_set_threshold() function during
mbedTLS initialization, with the configured debug log level.
choice MBEDTLS_DEBUG_EXTRACT_BASENAME
prompt "Extract basename from filenames"
default MBEDTLS_DEBUG_EXTRACT_BASENAME_AT_BUILDTIME if "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr"
default MBEDTLS_DEBUG_EXTRACT_BASENAME_AT_RUNTIME
config MBEDTLS_DEBUG_EXTRACT_BASENAME_AT_BUILDTIME
bool "Buildtime"
help
Adds compile options, which should convert full source paths in
__FILE__ macro to files' basenames. This will reduce code footprint
when debug messages are enabled.
This is compiler dependent, so if it does not work then please
fallback to MBEDTLS_DEBUG_EXTRACT_BASENAME_AT_RUNTIME instead.
config MBEDTLS_DEBUG_EXTRACT_BASENAME_AT_RUNTIME
bool "Runtime"
help
Filename passed as argument to debug hook will be stripped from
directory, so that only basename part is left and logged.
config MBEDTLS_DEBUG_EXTRACT_BASENAME_DISABLED
bool "Disabled"
help
Disable basename extraction from filenames in log mesasges. This will
result in full paths or paths relative to west root directory
appearing in log messages generated by mbedTLS library.
endchoice
config MBEDTLS_DEBUG_STRIP_NEWLINE
bool "Strip newlines"
default y
help
Attempt to strip last character from logged string when it is a
newline.
endif # MBEDTLS_DEBUG
config MBEDTLS_MEMORY_DEBUG
bool "mbed TLS memory debug activation"
depends on MBEDTLS_BUILTIN
help
Enable debugging of buffer allocator memory issues. Automatically
prints (to stderr) all (fatal) messages on memory allocation
issues. Enables function for 'debug output' of allocated memory.
config MBEDTLS_TEST
bool "Compile internal self test functions"
depends on MBEDTLS_BUILTIN
help
Enable self test function for the crypto algorithms
config MBEDTLS_INSTALL_PATH
string "mbedTLS install path"
depends on MBEDTLS_LIBRARY
help
This option holds the path where the mbedTLS libraries and headers are
installed. Make sure this option is properly set when MBEDTLS_LIBRARY
is enabled otherwise the build will fail.
config MBEDTLS_ENABLE_HEAP
bool "Global heap for mbed TLS"
help
This option enables the mbedtls to use the heap. This setting must
be global so that various applications and libraries in Zephyr do not
try to do this themselves as there can be only one heap defined
in mbedtls. If this is enabled, and MBEDTLS_INIT is enabled then the
Zephyr will, during the device startup, initialize the heap automatically.
config MBEDTLS_HEAP_SIZE
int "Heap size for mbed TLS"
default 10240 if OPENTHREAD_COMMISSIONER || OPENTHREAD_JOINER
default 512
depends on MBEDTLS_ENABLE_HEAP
help
The mbedtls routines will use this heap if enabled.
See ext/lib/crypto/mbedtls/include/mbedtls/config.h and
MBEDTLS_MEMORY_BUFFER_ALLOC_C option for details. That option is not
enabled by default.
Default value for the heap size is not set as it depends on the
application. For streaming communication with arbitrary (HTTPS)
servers on the Internet, 32KB + overheads (up to another 20KB) may
be needed. For some dedicated and specific usage of mbedtls API, the
1000 bytes might be ok.
config MBEDTLS_INIT
bool "Initialize mbed TLS at boot"
default y
help
By default mbed TLS will be initialized at Zephyr init. Disabling this option
will defer the initialization until explicitly called.
config MBEDTLS_SHELL
bool "mbed TLS shell"
depends on MBEDTLS
depends on SHELL
help
Enable mbed TLS shell module, which allows to show debug information
about mbed TLS library, such as heap usage.
config MBEDTLS_ZEPHYR_ENTROPY
bool "mbed TLS entropy source based on Zephyr entropy driver"
depends on MBEDTLS
help
This option enables the entropy source based on Zephyr entropy driver
for mbed TLS. The entropy source is registered automatically during
system initialization.
config MBEDTLS_ZEROIZE_ALT
bool "mbed TLS alternate mbedtls_platform_zeroize implementation"
help
mbed TLS configuration supplies an alternate implementation of
mbedtls_platform_zeroize.
config APP_LINK_WITH_MBEDTLS
bool "Link 'app' with MBEDTLS"
default y
help
Add MBEDTLS header files to the 'app' include path. It may be
disabled if the include paths for MBEDTLS are causing aliasing
issues for 'app'.
endif # MBEDTLS
``` | /content/code_sandbox/modules/mbedtls/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,949 |
```objective-c
/*
*
*
* Minimal configuration for DTLS 1.2 for Zephyr with PSK and AES-CCM
* ciphersuites.
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
#define MBEDTLS_MEMORY_ALIGN_MULTIPLE (sizeof(void *))
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_PLATFORM_EXIT_ALT
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#define MBEDTLS_PLATFORM_PRINTF_ALT
#if defined(CONFIG_MBEDTLS_TEST)
#define MBEDTLS_SELF_TEST
#define MBEDTLS_DEBUG_C
#else
#define MBEDTLS_ENTROPY_C
#endif
/* mbed TLS feature support */
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_PROTO_DTLS
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_DES_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_MD_C
#define MBEDTLS_MD5_C
#define MBEDTLS_OID_C
#define MBEDTLS_RSA_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_CCM_C
#define MBEDTLS_SSL_COOKIE_C
/* For test certificates */
#define MBEDTLS_BASE64_C
#define MBEDTLS_CERTS_C
#if defined(CONFIG_MBEDTLS_DEBUG)
#define MBEDTLS_ERROR_C
#define MBEDTLS_DEBUG_C
#define MBEDTLS_SSL_DEBUG_ALL
#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
#endif
#define MBEDTLS_SSL_MAX_CONTENT_LEN 1500
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-mini-dtls1_2.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 572 |
```objective-c
/*
*
*
* Minimal configuration for TLS 1.2 (RFC 5246) for Zephyr, implementing only
* a few of the most popular ciphersuites.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
#define MBEDTLS_MEMORY_ALIGN_MULTIPLE (sizeof(void *))
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_PLATFORM_EXIT_ALT
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#define MBEDTLS_PLATFORM_PRINTF_ALT
#define MBEDTLS_PLATFORM_SNPRINTF_ALT
#if !defined(CONFIG_ARM)
#define MBEDTLS_HAVE_ASM
#endif
#if defined(CONFIG_MBEDTLS_TEST)
#define MBEDTLS_SELF_TEST
#define MBEDTLS_DEBUG_C
#else
#define MBEDTLS_ENTROPY_C
#endif
/* mbed TLS feature support */
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_SSL_PROTO_TLS1_2
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_DES_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_MD_C
#define MBEDTLS_MD5_C
#define MBEDTLS_OID_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_RSA_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_USE_C
/* For test certificates */
#define MBEDTLS_BASE64_C
#define MBEDTLS_CERTS_C
#if defined(CONFIG_MBEDTLS_DEBUG)
#define MBEDTLS_ERROR_C
#define MBEDTLS_DEBUG_C
#define MBEDTLS_SSL_DEBUG_ALL
#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
#endif
#define MBEDTLS_SSL_MAX_CONTENT_LEN CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-mini-tls1_2.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 530 |
```objective-c
/*
* Minimal configuration for DTLS 1.2 with PSK and AES-CCM ciphersuites
*
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* This file is part of mbed TLS (path_to_url
*/
/*
* Minimal configuration for TLS 1.2 with PSK and AES-CCM ciphersuites
* Distinguishing features:
* - no bignum, no PK, no X509
* - fully modern and secure (provided the pre-shared keys have high entropy)
* - very low record overhead with CCM-8
* - optimized for low RAM usage
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
#define MBEDTLS_MEMORY_ALIGN_MULTIPLE (sizeof(void *))
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_PLATFORM_EXIT_ALT
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#define MBEDTLS_PLATFORM_PRINTF_ALT
#if defined(CONFIG_MBEDTLS_TEST)
#define MBEDTLS_SELF_TEST
#define MBEDTLS_DEBUG_C
#else
#define MBEDTLS_ENTROPY_C
#endif
/* mbed TLS feature support */
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_PROTO_DTLS
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_MD_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SSL_COOKIE_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES
/* Save some RAM by adjusting to your exact needs */
#define MBEDTLS_PSK_MAX_LEN 16 /* 128-bits keys are generally enough */
/*
* You should adjust this to the exact number of sources you're using: default
* is the "platform_entropy_poll" source, but you may want to add other ones
* Minimum is 2 for the entropy test suite.
*/
#define MBEDTLS_ENTROPY_MAX_SOURCES 2
/*
* Use only CCM_8 ciphersuites, and
* save ROM and a few bytes of RAM by specifying our own ciphersuite list
*/
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8
/*
* Allow to save RAM at the expense of interoperability: do this only if you
* control both ends of the connection! (See comments in "mbedtls/ssl.h".)
* The optimal size here depends on the typical size of records.
*/
#define MBEDTLS_SSL_MAX_CONTENT_LEN CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-coap.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 737 |
```objective-c
/**
* \file config-suite-b.h
*
* \brief Minimal configuration for TLS NSA Suite B Profile (RFC 6460)
*/
/*
*
*
* **********
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* **********
*
* **********
*
* This program is free software; you can redistribute it and/or modify
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* **********
*/
/*
* Minimal configuration for TLS NSA Suite B Profile (RFC 6460)
*
* Distinguishing features:
* - no RSA or classic DH, fully based on ECC
* - optimized for low RAM usage
*
* Possible improvements:
* - if 128-bit security is enough, disable secp384r1 and SHA-512
* - use embedded certs in DER format and disable PEM_PARSE_C and BASE64_C
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_HAVE_ASM
#define MBEDTLS_HAVE_TIME
#define MBEDTLS_PLATFORM_MS_TIME_ALT
/* mbed TLS feature support */
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#define MBEDTLS_SSL_PROTO_TLS1_2
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECDSA_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_GCM_C
#define MBEDTLS_MD_C
#define MBEDTLS_NET_C
#define MBEDTLS_OID_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SHA384_C
#define MBEDTLS_SHA512_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_USE_C
/* For test certificates */
#define MBEDTLS_BASE64_C
#define MBEDTLS_CERTS_C
#define MBEDTLS_PEM_PARSE_C
/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES
/* Save RAM by adjusting to our exact needs */
#define MBEDTLS_MPI_MAX_SIZE 48 // 384 bits is 48 bytes
/* Save RAM at the expense of speed, see ecp.h */
#define MBEDTLS_ECP_WINDOW_SIZE 2
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0
/* Significant speed benefit at the expense of some ROM */
#define MBEDTLS_ECP_NIST_OPTIM
/*
* You should adjust this to the exact number of sources you're using: default
* is the "mbedtls_platform_entropy_poll" source, but you may want to add other ones.
* Minimum is 2 for the entropy test suite.
*/
#define MBEDTLS_ENTROPY_MAX_SOURCES 2
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */
#define MBEDTLS_SSL_CIPHERSUITES \
MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, \
MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
/*
* Save RAM at the expense of interoperability: do this only if you control
* both ends of the connection! (See comments in "mbedtls/ssl.h".)
* The minimum size here depends on the certificate chain used as well as the
* typical size of records.
*/
#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-suite-b.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 976 |
```objective-c
/*
*
*/
/* This file was automatically generated by create_psa_files.py
* from: ../../../modules/crypto/mbedtls/include/psa/crypto_config.h
* Do not edit it manually.
*/
#ifndef CONFIG_PSA_H
#define CONFIG_PSA_H
#if defined(CONFIG_PSA_WANT_ALG_CBC_NO_PADDING)
#define PSA_WANT_ALG_CBC_NO_PADDING 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_CBC_PKCS7)
#define PSA_WANT_ALG_CBC_PKCS7 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_CCM)
#define PSA_WANT_ALG_CCM 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_CCM_STAR_NO_TAG)
#define PSA_WANT_ALG_CCM_STAR_NO_TAG 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_CMAC)
#define PSA_WANT_ALG_CMAC 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_CFB)
#define PSA_WANT_ALG_CFB 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_CHACHA20_POLY1305)
#define PSA_WANT_ALG_CHACHA20_POLY1305 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_CTR)
#define PSA_WANT_ALG_CTR 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_DETERMINISTIC_ECDSA)
#define PSA_WANT_ALG_DETERMINISTIC_ECDSA 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_ECB_NO_PADDING)
#define PSA_WANT_ALG_ECB_NO_PADDING 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_ECDH)
#define PSA_WANT_ALG_ECDH 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_FFDH)
#define PSA_WANT_ALG_FFDH 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_ECDSA)
#define PSA_WANT_ALG_ECDSA 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_JPAKE)
#define PSA_WANT_ALG_JPAKE 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_GCM)
#define PSA_WANT_ALG_GCM 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_HKDF)
#define PSA_WANT_ALG_HKDF 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_HKDF_EXTRACT)
#define PSA_WANT_ALG_HKDF_EXTRACT 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_HKDF_EXPAND)
#define PSA_WANT_ALG_HKDF_EXPAND 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_HMAC)
#define PSA_WANT_ALG_HMAC 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_MD5)
#define PSA_WANT_ALG_MD5 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_OFB)
#define PSA_WANT_ALG_OFB 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_PBKDF2_HMAC)
#define PSA_WANT_ALG_PBKDF2_HMAC 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128)
#define PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_RIPEMD160)
#define PSA_WANT_ALG_RIPEMD160 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_RSA_OAEP)
#define PSA_WANT_ALG_RSA_OAEP 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_RSA_PKCS1V15_CRYPT)
#define PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_RSA_PKCS1V15_SIGN)
#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_RSA_PSS)
#define PSA_WANT_ALG_RSA_PSS 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA_1)
#define PSA_WANT_ALG_SHA_1 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA_224)
#define PSA_WANT_ALG_SHA_224 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA_256)
#define PSA_WANT_ALG_SHA_256 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA_384)
#define PSA_WANT_ALG_SHA_384 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA_512)
#define PSA_WANT_ALG_SHA_512 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA3_224)
#define PSA_WANT_ALG_SHA3_224 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA3_256)
#define PSA_WANT_ALG_SHA3_256 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA3_384)
#define PSA_WANT_ALG_SHA3_384 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_SHA3_512)
#define PSA_WANT_ALG_SHA3_512 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_STREAM_CIPHER)
#define PSA_WANT_ALG_STREAM_CIPHER 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_TLS12_PRF)
#define PSA_WANT_ALG_TLS12_PRF 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_TLS12_PSK_TO_MS)
#define PSA_WANT_ALG_TLS12_PSK_TO_MS 1
#endif
#if defined(CONFIG_PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS)
#define PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_BRAINPOOL_P_R1_256)
#define PSA_WANT_ECC_BRAINPOOL_P_R1_256 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_BRAINPOOL_P_R1_384)
#define PSA_WANT_ECC_BRAINPOOL_P_R1_384 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_BRAINPOOL_P_R1_512)
#define PSA_WANT_ECC_BRAINPOOL_P_R1_512 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_MONTGOMERY_255)
#define PSA_WANT_ECC_MONTGOMERY_255 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_MONTGOMERY_448)
#define PSA_WANT_ECC_MONTGOMERY_448 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_SECP_K1_192)
#define PSA_WANT_ECC_SECP_K1_192 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_SECP_K1_256)
#define PSA_WANT_ECC_SECP_K1_256 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_SECP_R1_192)
#define PSA_WANT_ECC_SECP_R1_192 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_SECP_R1_224)
#define PSA_WANT_ECC_SECP_R1_224 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_SECP_R1_256)
#define PSA_WANT_ECC_SECP_R1_256 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_SECP_R1_384)
#define PSA_WANT_ECC_SECP_R1_384 1
#endif
#if defined(CONFIG_PSA_WANT_ECC_SECP_R1_521)
#define PSA_WANT_ECC_SECP_R1_521 1
#endif
#if defined(CONFIG_PSA_WANT_DH_RFC7919_2048)
#define PSA_WANT_DH_RFC7919_2048 1
#endif
#if defined(CONFIG_PSA_WANT_DH_RFC7919_3072)
#define PSA_WANT_DH_RFC7919_3072 1
#endif
#if defined(CONFIG_PSA_WANT_DH_RFC7919_4096)
#define PSA_WANT_DH_RFC7919_4096 1
#endif
#if defined(CONFIG_PSA_WANT_DH_RFC7919_6144)
#define PSA_WANT_DH_RFC7919_6144 1
#endif
#if defined(CONFIG_PSA_WANT_DH_RFC7919_8192)
#define PSA_WANT_DH_RFC7919_8192 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_DERIVE)
#define PSA_WANT_KEY_TYPE_DERIVE 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_PASSWORD)
#define PSA_WANT_KEY_TYPE_PASSWORD 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_PASSWORD_HASH)
#define PSA_WANT_KEY_TYPE_PASSWORD_HASH 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_HMAC)
#define PSA_WANT_KEY_TYPE_HMAC 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_AES)
#define PSA_WANT_KEY_TYPE_AES 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_ARIA)
#define PSA_WANT_KEY_TYPE_ARIA 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_CAMELLIA)
#define PSA_WANT_KEY_TYPE_CAMELLIA 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_CHACHA20)
#define PSA_WANT_KEY_TYPE_CHACHA20 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_DES)
#define PSA_WANT_KEY_TYPE_DES 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
#define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY)
#define PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_RAW_DATA)
#define PSA_WANT_KEY_TYPE_RAW_DATA 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY)
#define PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC)
#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT)
#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT)
#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE)
#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE)
#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC)
#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT)
#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT)
#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE)
#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_DH_KEY_PAIR_BASIC)
#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_BASIC 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT)
#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT)
#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT 1
#endif
#if defined(CONFIG_PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE)
#define PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE 1
#endif
#endif /* CONFIG_PSA_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-psa.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 2,646 |
```objective-c
/*
* Minimal configuration for using TLS as part of Thread
*
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* This file is part of mbed TLS (path_to_url
*/
/*
* Minimal configuration for using TLS a part of Thread
* path_to_url
*
* Distinguishing features:
* - no RSA or classic DH, fully based on ECC
* - no X.509
* - support for experimental EC J-PAKE key exchange
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
#define MBEDTLS_MEMORY_ALIGN_MULTIPLE (sizeof(void *))
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_PLATFORM_EXIT_ALT
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#define MBEDTLS_PLATFORM_PRINTF_ALT
#if !defined(CONFIG_ARM)
#define MBEDTLS_HAVE_ASM
#endif
#if defined(CONFIG_MBEDTLS_TEST)
#define MBEDTLS_SELF_TEST
#define MBEDTLS_DEBUG_C
#else
#define MBEDTLS_ENTROPY_C
#endif
/* mbed TLS feature support */
#define MBEDTLS_AES_ROM_TABLES
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_ECP_NIST_OPTIM
#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_PROTO_DTLS
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
#define MBEDTLS_SSL_EXPORT_KEYS
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_CMAC_C
#define MBEDTLS_ECJPAKE_C
#define MBEDTLS_ECP_C
#define MBEDTLS_HMAC_DRBG_C
#define MBEDTLS_MD_C
#define MBEDTLS_OID_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SSL_COOKIE_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES
/* Save RAM by adjusting to our exact needs */
#define MBEDTLS_MPI_MAX_SIZE 32 // 256 bits is 32 bytes
#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-threadnet.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 701 |
```objective-c
/**
* \file config-ccm-psk-tls1_2.h
*
* \brief Minimal configuration for TLS 1.2 with PSK and AES-CCM ciphersuites
*/
/*
*
*
* **********
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* **********
*
* **********
*
* This program is free software; you can redistribute it and/or modify
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* **********
*/
/*
* Minimal configuration for TLS 1.2 with PSK and AES-CCM ciphersuites
* Distinguishing features:
* - no bignum, no PK, no X509
* - fully modern and secure (provided the pre-shared keys have high entropy)
* - very low record overhead with CCM-8
* - optimized for low RAM usage
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
//#define MBEDTLS_HAVE_TIME /* Optionally used in Hello messages */
/* Other MBEDTLS_HAVE_XXX flags irrelevant for this configuration */
/* mbed TLS feature support */
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_SSL_PROTO_TLS1_2
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_MD_C
#define MBEDTLS_NET_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES
/* Save some RAM by adjusting to your exact needs */
#define MBEDTLS_PSK_MAX_LEN 16 /* 128-bits keys are generally enough */
/*
* You should adjust this to the exact number of sources you're using: default
* is the "platform_entropy_poll" source, but you may want to add other ones
* Minimum is 2 for the entropy test suite.
*/
#define MBEDTLS_ENTROPY_MAX_SOURCES 2
/*
* Use only CCM_8 ciphersuites, and
* save ROM and a few bytes of RAM by specifying our own ciphersuite list
*/
#define MBEDTLS_SSL_CIPHERSUITES \
MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, \
MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8
/*
* Save RAM at the expense of interoperability: do this only if you control
* both ends of the connection! (See comments in "mbedtls/ssl.h".)
* The optimal size here depends on the typical size of records.
*/
#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-ccm-psk-tls1_2.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 753 |
```objective-c
/**
* \file config-no-entropy.h
*
* \brief Minimal configuration of features that do not require an entropy source
*/
/*
*
*
* **********
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* **********
*
* **********
*
* This program is free software; you can redistribute it and/or modify
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* **********
*/
/*
* Minimal configuration of features that do not require an entropy source
* Distinguishing features:
* - no entropy module
* - no TLS protocol implementation available due to absence of an entropy
* source
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_HAVE_ASM
#define MBEDTLS_HAVE_TIME
#define MBEDTLS_PLATFORM_MS_TIME_ALT
/* mbed TLS feature support */
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_CIPHER_PADDING_PKCS7
#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
#define MBEDTLS_ECP_NIST_OPTIM
#define MBEDTLS_ECDSA_DETERMINISTIC
#define MBEDTLS_PK_RSA_ALT_SUPPORT
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_PKCS1_V21
#define MBEDTLS_SELF_TEST
#define MBEDTLS_VERSION_FEATURES
#define MBEDTLS_X509_CHECK_KEY_USAGE
#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
/* mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BASE64_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_ECDSA_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ERROR_C
#define MBEDTLS_GCM_C
#define MBEDTLS_HMAC_DRBG_C
#define MBEDTLS_MD_C
#define MBEDTLS_OID_C
#define MBEDTLS_PEM_PARSE_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_PK_WRITE_C
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_RSA_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SHA384_C
#define MBEDTLS_SHA512_C
#define MBEDTLS_VERSION_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_CRL_PARSE_C
//#define MBEDTLS_CMAC_C
/* Miscellaneous options */
#define MBEDTLS_AES_ROM_TABLES
#include "check_config.h"
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-no-entropy.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 734 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_MBEDTLS_PRIV_H_
#define ZEPHYR_MODULES_MBEDTLS_PRIV_H_
void zephyr_mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str);
#endif /* ZEPHYR_MODULES_MBEDTLS_PRIV_H_ */
``` | /content/code_sandbox/modules/mbedtls/include/zephyr_mbedtls_priv.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 69 |
```objective-c
/*
*
*/
#ifndef MBEDTLS_INIT_H
#define MBEDTLS_INIT_H
/* This should be called by platforms that do not wish to
* have mbedtls initialised during kernel startup
*/
int mbedtls_init(void);
#endif /* MBEDTLS_INIT_H */
``` | /content/code_sandbox/modules/mbedtls/include/mbedtls_init.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 53 |
```unknown
config ZEPHYR_HAL_ST_MODULE
bool
config HAS_STLIB
bool
config HAS_STMEMSC
bool
if HAS_STMEMSC
config USE_STDC_A3G4250D
bool
config USE_STDC_AIS2DW12
bool
config USE_STDC_AIS328DQ
bool
config USE_STDC_AIS3624DQ
bool
config USE_STDC_H3LIS100DL
bool
config USE_STDC_H3LIS331DL
bool
config USE_STDC_HTS221
bool
config USE_STDC_I3G4250D
bool
config USE_STDC_IIS2DH
bool
config USE_STDC_IIS2DLPC
bool
config USE_STDC_IIS2ICLX
bool
config USE_STDC_IIS2MDC
bool
config USE_STDC_IIS328DQ
bool
config USE_STDC_IIS3DHHC
bool
config USE_STDC_IIS3DWB
bool
config USE_STDC_ILPS22QS
bool
config USE_STDC_ISM303DAC
bool
config USE_STDC_ISM330DHCX
bool
config USE_STDC_ISM330DLC
bool
config USE_STDC_L20G20IS
bool
config USE_STDC_L3GD20H
bool
config USE_STDC_LIS25BA
bool
config USE_STDC_LIS2DE12
bool
config USE_STDC_LIS2DH12
bool
config USE_STDC_LIS2DS12
bool
config USE_STDC_LIS2DTW12
bool
config USE_STDC_LIS2DU12
bool
config USE_STDC_LIS2DUX12
bool
config USE_STDC_LIS2DW12
bool
config USE_STDC_LIS2HH12
bool
config USE_STDC_LIS2MDL
bool
config USE_STDC_LIS331DLH
bool
config USE_STDC_LIS3DE
bool
config USE_STDC_LIS3DHH
bool
config USE_STDC_LIS3DH
bool
config USE_STDC_LIS3DSH
bool
config USE_STDC_LIS3MDL
bool
config USE_STDC_LPS22DF
bool
config USE_STDC_LPS22HB
bool
config USE_STDC_LPS22HH
bool
config USE_STDC_LPS25HB
bool
config USE_STDC_LPS27HHW
bool
config USE_STDC_LPS28DFW
bool
config USE_STDC_LPS33HW
bool
config USE_STDC_LPS33K
bool
config USE_STDC_LPS33W
bool
config USE_STDC_LSM303AGR
bool
config USE_STDC_LSM303AH
bool
config USE_STDC_LSM6DS3
bool
config USE_STDC_LSM6DS3TR
bool
config USE_STDC_LSM6DSL
bool
config USE_STDC_LSM6DSM
bool
config USE_STDC_LSM6DSO
bool
config USE_STDC_LSM6DSO16IS
bool
config USE_STDC_LSM6DSO32
bool
config USE_STDC_LSM6DSOX
bool
config USE_STDC_LSM6DSR
bool
config USE_STDC_LSM6DSRX
bool
config USE_STDC_LSM6DSV16X
bool
config USE_STDC_LSM9DS1
bool
config USE_STDC_STTS22H
bool
config USE_STDC_STTS751
bool
endif # HAS_STMEMSC
``` | /content/code_sandbox/modules/hal_st/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 779 |
```unknown
config ZEPHYR_ZCBOR_MODULE
bool
config ZCBOR
bool "zcbor CBOR library"
depends on ZEPHYR_ZCBOR_MODULE
help
zcbor CBOR encoder/decoder library
if ZCBOR
config ZCBOR_CANONICAL
bool "Produce canonical CBOR"
help
Enabling this will prevent zcbor from creating lists and maps with
indefinite-length arrays (it will still decode them properly).
config ZCBOR_STOP_ON_ERROR
bool "Stop on error when processing"
help
This makes all functions abort their execution if called when an error
has already happened.
config ZCBOR_VERBOSE
bool "Make zcbor code print messages"
config ZCBOR_ASSERT
def_bool ASSERT
config ZCBOR_BIG_ENDIAN
def_bool BIG_ENDIAN
config ZCBOR_MAX_STR_LEN
int "Default max length when calling zcbor_tstr_put_term()"
default 256
help
This can be manually used if no other value is readily available, but
using this is discouraged.
endif # ZCBOR
``` | /content/code_sandbox/modules/zcbor/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 236 |
```unknown
menuconfig UOSCORE
bool "UOSCORE library"
depends on ZCBOR
depends on ZCBOR_CANONICAL
depends on MBEDTLS
help
This option enables the UOSCORE library.
if UOSCORE
config UOSCORE_DEBUG
bool "Debug logs in the uoscore library"
endif # UOSCORE
menuconfig UEDHOC
bool "UEDHOC library"
depends on ZCBOR
depends on ZCBOR_CANONICAL
depends on MBEDTLS
help
This option enables the UEDHOC library.
if UEDHOC
config UEDHOC_DEBUG
bool "Debug logs in the uedhoc library"
endif # UEDHOC
``` | /content/code_sandbox/modules/uoscore-uedhoc/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 161 |
```objective-c
/*
*
*
* Generic configuration for TLS, manageable by Kconfig.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
#define MBEDTLS_MEMORY_ALIGN_MULTIPLE (sizeof(void *))
#define MBEDTLS_PLATFORM_EXIT_ALT
#define MBEDTLS_NO_PLATFORM_ENTROPY
#if defined(CONFIG_MBEDTLS_ZEROIZE_ALT)
#define MBEDTLS_PLATFORM_ZEROIZE_ALT
#endif
#if defined(CONFIG_MBEDTLS_ZEPHYR_ENTROPY)
#define MBEDTLS_ENTROPY_HARDWARE_ALT
#else
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#endif
#if defined(CONFIG_MBEDTLS_HAVE_ASM)
#define MBEDTLS_HAVE_ASM
#endif
#if defined(CONFIG_MBEDTLS_LMS)
#define MBEDTLS_LMS_C
#endif
#if defined(CONFIG_MBEDTLS_HAVE_TIME_DATE)
#define MBEDTLS_HAVE_TIME
#define MBEDTLS_HAVE_TIME_DATE
#define MBEDTLS_PLATFORM_MS_TIME_ALT
#endif
#if defined(CONFIG_MBEDTLS_TEST)
#define MBEDTLS_SELF_TEST
#define MBEDTLS_DEBUG_C
#endif
/* mbedTLS feature support */
/* Supported TLS versions */
#if defined(CONFIG_MBEDTLS_TLS_VERSION_1_2)
#define MBEDTLS_SSL_PROTO_TLS1_2
#endif
#if defined(CONFIG_MBEDTLS_TLS_VERSION_1_2)
/* Modules required for TLS */
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#endif
#if defined(CONFIG_MBEDTLS_DTLS)
#define MBEDTLS_SSL_PROTO_DTLS
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
#define MBEDTLS_SSL_COOKIE_C
#endif
/* Supported key exchange methods */
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_PSK_MAX_LEN)
#define MBEDTLS_PSK_MAX_LEN CONFIG_MBEDTLS_PSK_MAX_LEN
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECDSA_DETERMINISTIC)
#define MBEDTLS_ECDSA_DETERMINISTIC
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_HKDF_C)
#define MBEDTLS_HKDF_C
#endif
/* Supported cipher modes */
#if defined(CONFIG_MBEDTLS_CIPHER_AES_ENABLED)
#define MBEDTLS_AES_C
#endif
#if defined(CONFIG_MBEDTLS_AES_ROM_TABLES)
#define MBEDTLS_AES_ROM_TABLES
#endif
#if defined(CONFIG_MBEDTLS_AES_FEWER_TABLES)
#define MBEDTLS_AES_FEWER_TABLES
#endif
#if defined(CONFIG_MBEDTLS_CIPHER_CAMELLIA_ENABLED)
#define MBEDTLS_CAMELLIA_C
#endif
#if defined(CONFIG_MBEDTLS_CIPHER_DES_ENABLED)
#define MBEDTLS_DES_C
#endif
#if defined(CONFIG_MBEDTLS_CIPHER_CHACHA20_ENABLED)
#define MBEDTLS_CHACHA20_C
#endif
#if defined(CONFIG_MBEDTLS_CIPHER_CCM_ENABLED)
#define MBEDTLS_CCM_C
#endif
#if defined(CONFIG_MBEDTLS_CIPHER_GCM_ENABLED)
#define MBEDTLS_GCM_C
#endif
#if defined(CONFIG_MBEDTLS_CIPHER_MODE_XTS_ENABLED)
#define MBEDTLS_CIPHER_MODE_XTS
#endif
#if defined(CONFIG_MBEDTLS_CIPHER_MODE_CBC_ENABLED)
#define MBEDTLS_CIPHER_MODE_CBC
#endif
#if defined(CONFIG_MBEDTLS_CIPHER_MODE_CTR_ENABLED)
#define MBEDTLS_CIPHER_MODE_CTR
#endif
/* Supported elliptic curve libraries */
#if defined(CONFIG_MBEDTLS_ECDH_C)
#define MBEDTLS_ECDH_C
#endif
#if defined(CONFIG_MBEDTLS_ECDSA_C)
#define MBEDTLS_ECDSA_C
#endif
#if defined(CONFIG_MBEDTLS_ECJPAKE_C)
#define MBEDTLS_ECJPAKE_C
#endif
#if defined(CONFIG_MBEDTLS_ECP_C)
#define MBEDTLS_ECP_C
#endif
/* Supported elliptic curves */
#if defined(CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED)
#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED)
#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED)
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED)
#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED)
#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED)
#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED)
#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED)
#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED)
#define MBEDTLS_ECP_DP_BP256R1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED)
#define MBEDTLS_ECP_DP_BP384R1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED)
#define MBEDTLS_ECP_DP_BP512R1_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED)
#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_DP_CURVE448_ENABLED)
#define MBEDTLS_ECP_DP_CURVE448_ENABLED
#endif
#if defined(CONFIG_MBEDTLS_ECP_NIST_OPTIM)
#define MBEDTLS_ECP_NIST_OPTIM
#endif
/* Supported hash algorithms */
#if defined(CONFIG_MBEDTLS_MD5)
#define MBEDTLS_MD5_C
#endif
#if defined(CONFIG_MBEDTLS_SHA1)
#define MBEDTLS_SHA1_C
#endif
#if defined(CONFIG_MBEDTLS_SHA224)
#define MBEDTLS_SHA224_C
#endif
#if defined(CONFIG_MBEDTLS_SHA256)
#define MBEDTLS_SHA256_C
#endif
#if defined(CONFIG_MBEDTLS_SHA256_SMALLER)
#define MBEDTLS_SHA256_SMALLER
#endif
#if defined(CONFIG_MBEDTLS_SHA384)
#define MBEDTLS_SHA384_C
#endif
#if defined(CONFIG_MBEDTLS_SHA512)
#define MBEDTLS_SHA512_C
#endif
#if defined(CONFIG_MBEDTLS_POLY1305)
#define MBEDTLS_POLY1305_C
#endif
#if defined(CONFIG_MBEDTLS_CMAC)
#define MBEDTLS_CMAC_C
#endif
/* mbedTLS modules */
#if defined(CONFIG_MBEDTLS_CTR_DRBG_ENABLED)
#define MBEDTLS_CTR_DRBG_C
#endif
#if defined(CONFIG_MBEDTLS_HMAC_DRBG_ENABLED)
#define MBEDTLS_HMAC_DRBG_C
#endif
#if defined(CONFIG_MBEDTLS_DEBUG)
#define MBEDTLS_ERROR_C
#define MBEDTLS_DEBUG_C
#define MBEDTLS_SSL_DEBUG_ALL
#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
#endif
#if defined(CONFIG_MBEDTLS_MEMORY_DEBUG)
#define MBEDTLS_MEMORY_DEBUG
#endif
#if defined(CONFIG_MBEDTLS_CHACHAPOLY_AEAD_ENABLED)
#define MBEDTLS_CHACHAPOLY_C
#endif
#if defined(CONFIG_MBEDTLS_GENPRIME_ENABLED)
#define MBEDTLS_GENPRIME
#endif
#if defined(CONFIG_MBEDTLS_ENTROPY_ENABLED)
#define MBEDTLS_ENTROPY_C
#endif
#if defined(CONFIG_MBEDTLS_SSL_EXPORT_KEYS)
#define MBEDTLS_SSL_EXPORT_KEYS
#endif
#if defined(CONFIG_MBEDTLS_SSL_ALPN)
#define MBEDTLS_SSL_ALPN
#endif
#if defined(CONFIG_MBEDTLS_CIPHER)
#define MBEDTLS_CIPHER_C
#endif
#if defined(CONFIG_MBEDTLS_MD)
#define MBEDTLS_MD_C
#endif
/* Automatic dependencies */
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
#define MBEDTLS_DHM_C
#endif
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED)
#define MBEDTLS_RSA_C
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_PKCS1_V21
#endif
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED)
#define MBEDTLS_X509_CRT_PARSE_C
#endif
#if defined(CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT) && \
defined(MBEDTLS_X509_CRT_PARSE_C)
#define MBEDTLS_PEM_PARSE_C
#define MBEDTLS_BASE64_C
#endif
#if defined(MBEDTLS_X509_CRT_PARSE_C)
#define MBEDTLS_X509_USE_C
#endif
#if defined(MBEDTLS_DHM_C) || \
defined(MBEDTLS_ECP_C) || \
defined(MBEDTLS_RSA_C) || \
defined(MBEDTLS_X509_USE_C) || \
defined(MBEDTLS_GENPRIME)
#define MBEDTLS_BIGNUM_C
#endif
#if defined(MBEDTLS_RSA_C) || \
defined(MBEDTLS_X509_USE_C)
#define MBEDTLS_OID_C
#endif
#if defined(MBEDTLS_X509_USE_C)
#define MBEDTLS_PK_PARSE_C
#endif
#if defined(CONFIG_MBEDTLS_PK_WRITE_C)
#define MBEDTLS_PK_WRITE_C
#endif
#if defined(MBEDTLS_PK_PARSE_C) || defined(MBEDTLS_PK_WRITE_C)
#define MBEDTLS_PK_C
#endif
#if defined(MBEDTLS_ECDSA_C) || defined(MBEDTLS_X509_USE_C)
#define MBEDTLS_ASN1_PARSE_C
#endif
#if defined(MBEDTLS_ECDSA_C) || defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_WRITE_C)
#define MBEDTLS_ASN1_WRITE_C
#endif
#if defined(CONFIG_MBEDTLS_PKCS5_C)
#define MBEDTLS_PKCS5_C
#endif
#define MBEDTLS_SSL_IN_CONTENT_LEN CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN
#define MBEDTLS_SSL_OUT_CONTENT_LEN CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN
/* Enable OpenThread optimizations. */
#if defined(CONFIG_MBEDTLS_OPENTHREAD_OPTIMIZATIONS_ENABLED)
#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */
#define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */
#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */
#endif
#if defined(CONFIG_MBEDTLS_SERVER_NAME_INDICATION) && \
defined(MBEDTLS_X509_CRT_PARSE_C)
#define MBEDTLS_SSL_SERVER_NAME_INDICATION
#endif
#if defined(CONFIG_MBEDTLS_SSL_CACHE_C)
#define MBEDTLS_SSL_CACHE_C
#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT CONFIG_MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT
#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES CONFIG_MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES
#endif
#if defined(CONFIG_MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
#endif
#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
#endif
#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_C)
#define MBEDTLS_PSA_CRYPTO_C
#define MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
#if defined(CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED)
#define MBEDTLS_PSA_P256M_DRIVER_ENABLED
#endif
#if defined(CONFIG_ARCH_POSIX) && !defined(CONFIG_PICOLIBC)
#define MBEDTLS_PSA_KEY_SLOT_COUNT 64
#define MBEDTLS_PSA_CRYPTO_STORAGE_C
#define MBEDTLS_PSA_ITS_FILE_C
#define MBEDTLS_FS_IO
#endif
#endif /* CONFIG_MBEDTLS_PSA_CRYPTO_C */
#if defined(CONFIG_MBEDTLS_USE_PSA_CRYPTO)
#define MBEDTLS_USE_PSA_CRYPTO
#endif
#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_CLIENT)
#define MBEDTLS_PSA_CRYPTO_CLIENT
#define MBEDTLS_PSA_CRYPTO_CONFIG
#define MBEDTLS_PSA_CRYPTO_CONFIG_FILE "config-psa.h"
#endif
#if defined(CONFIG_MBEDTLS_TLS_VERSION_1_2) && defined(CONFIG_MBEDTLS_PSA_CRYPTO_C)
#define MBEDTLS_SSL_ENCRYPT_THEN_MAC
#endif
#if defined(CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID)
#define MBEDTLS_SSL_DTLS_CONNECTION_ID
#endif
#if defined(CONFIG_MBEDTLS_NIST_KW_C)
#define MBEDTLS_NIST_KW_C
#endif
#if defined(CONFIG_MBEDTLS_DHM_C)
#define MBEDTLS_DHM_C
#endif
#if defined(CONFIG_MBEDTLS_X509_CRL_PARSE_C)
#define MBEDTLS_X509_CRL_PARSE_C
#endif
#if defined(CONFIG_MBEDTLS_X509_CSR_WRITE_C)
#define MBEDTLS_X509_CSR_WRITE_C
#define MBEDTLS_X509_CREATE_C
#endif
#if defined(CONFIG_MBEDTLS_X509_CSR_PARSE_C)
#define MBEDTLS_X509_CSR_PARSE_C
#endif
#if defined(CONFIG_MBEDTLS_USER_CONFIG_FILE)
#include CONFIG_MBEDTLS_USER_CONFIG_FILE
#endif
#endif /* MBEDTLS_CONFIG_H */
``` | /content/code_sandbox/modules/mbedtls/configs/config-tls-generic.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 3,301 |
```unknown
config ZEPHYR_TRUSTED_FIRMWARE_A_MODULE
bool
menuconfig BUILD_WITH_TFA
bool "Build with TF-A as the Secure Execution Environment"
help
When enabled, this option instructs the Zephyr build process to
additionally generate a TF-A image for the Secure Execution
environment, along with the Zephyr image. The Zephyr image
itself is to be executed in the Non-Secure Processing Environment.
if BUILD_WITH_TFA
config TFA_MAKE_BUILD_TYPE_DEBUG
bool "Debug build"
help
When enabled, the build type of TF-A would be debug.
endif # BUILD_WITH_TFA
``` | /content/code_sandbox/modules/trusted-firmware-a/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 139 |
```unknown
# WPA Supplicant configuration options
#
#
#
config WIFI_NM_WPA_SUPPLICANT
bool "WPA Suplicant from hostap project [EXPERIMENTAL]"
select POSIX_TIMERS
select POSIX_SIGNALS
select POSIX_API
select FILE_SYSTEM
select NET_SOCKETS
select NET_SOCKETS_PACKET
select NET_SOCKETPAIR
select NET_L2_WIFI_MGMT
select WIFI_NM
select EXPERIMENTAL
select COMMON_LIBC_MALLOC
help
WPA supplicant as a network management backend for WIFI_NM.
if WIFI_NM_WPA_SUPPLICANT
config COMMON_LIBC_MALLOC_ARENA_SIZE
default 85000 if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE && !MBEDTLS_ENABLE_HEAP
default 40000 if WIFI_NM_WPA_SUPPLICANT_AP
# 8192 for MbedTLS heap
default 21808 if MBEDTLS_ENABLE_HEAP
# 30K is mandatory, but might need more for long duration use cases
default 30000
config WIFI_NM_WPA_SUPPLICANT_THREAD_STACK_SIZE
int "Stack size for wpa_supplicant thread"
default 8192
config WIFI_NM_WPA_SUPPLICANT_WQ_STACK_SIZE
int "Stack size for wpa_supplicant iface workqueue"
default 6144
config WIFI_NM_WPA_SUPPLICANT_WQ_PRIO
int "Thread priority of wpa_supplicant iface workqueue"
default 7
# Currently we default ZVFS_OPEN_MAX to 16 in lib/posix/Kconfig
# l2_packet - 1
# ctrl_iface - 2 * socketpairs = 4(local and global)
# z_wpa_event_sock - 1 socketpair = 2
# Remaining left for the applications running in default configuration
# Supplicant API is stack heavy (buffers + snprintfs) and control interface
# uses socketpair which pushes the stack usage causing overflow for 2048 bytes.
# So we set SYSTEM_WORKQUEUE_STACK_SIZE default to 2560 in kernel/Kconfig
module = WIFI_NM_WPA_SUPPLICANT
module-str = WPA supplicant
source "subsys/logging/Kconfig.template.log_config"
config WIFI_NM_WPA_SUPPLICANT_DEBUG_LEVEL
int "Min compiled-in debug message level for WPA supplicant"
default 0 if WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL_DBG # MSG_EXCESSIVE
default 3 if WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL_INF # MSG_INFO
default 4 if WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL_WRN # MSG_WARNING
default 5 if WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL_ERR # MSG_ERROR
default 6
help
Minimum priority level of a debug message emitted by WPA supplicant that
is compiled-in the firmware. See wpa_debug.h file of the supplicant for
available levels and functions for emitting the messages. Note that
runtime filtering can also be configured in addition to the compile-time
filtering.
# Memory optimizations
config WIFI_NM_WPA_SUPPLICANT_ADVANCED_FEATURES
bool "Advanced features"
default y
if WIFI_NM_WPA_SUPPLICANT_ADVANCED_FEATURES
config WIFI_NM_WPA_SUPPLICANT_ROBUST_AV
bool "Robust Audio Video streaming support"
default y
# Hidden as these are mandatory for WFA certification
config WIFI_NM_WPA_SUPPLICANT_WMM_AC
bool
default y
config WIFI_NM_WPA_SUPPLICANT_MBO
bool
default y
config WIFI_NM_WPA_SUPPLICANT_WNM
bool "Wireless Network Management support"
default y
config WIFI_NM_WPA_SUPPLICANT_RRM
bool "Radio Resource Management support"
default y
endif
config WIFI_NM_WPA_SUPPLICANT_WEP
bool "WEP (Legacy crypto) support"
choice WIFI_NM_WPA_SUPPLICANT_CRYPTO_BACKEND
prompt "WPA supplicant crypto implementation"
default WIFI_NM_WPA_SUPPLICANT_CRYPTO
help
Select the crypto implementation to use for WPA supplicant.
WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT support enterprise
and DPP. And use Mbedtls PSA apis for HW acceleration.
config WIFI_NM_WPA_SUPPLICANT_CRYPTO
bool "Crypto support for WiFi"
select MBEDTLS
select MBEDTLS_SHA1
select MBEDTLS_CIPHER
select MBEDTLS_CIPHER_MODE_CTR_ENABLED
select MBEDTLS_CIPHER_MODE_CBC_ENABLED
select MBEDTLS_CIPHER_AES_ENABLED
select MBEDTLS_ECP_C
select MBEDTLS_ECP_ALL_ENABLED
select MBEDTLS_CMAC
select MBEDTLS_PKCS5_C
select MBEDTLS_PK_WRITE_C
select MBEDTLS_ECDH_C
select MBEDTLS_ECDSA_C
select MBEDTLS_ECJPAKE_C
select MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
select MBEDTLS_KEY_EXCHANGE_ALL_ENABLED
config WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT
bool "Crypto Mbedtls alt support for WiFi"
select MBEDTLS
select MBEDTLS_CIPHER_MODE_CTR_ENABLED
select MBEDTLS_CIPHER_MODE_CBC_ENABLED
select MBEDTLS_CIPHER_AES_ENABLED
select MBEDTLS_CIPHER_DES_ENABLED
select MBEDTLS_SHA1
select MBEDTLS_ENTROPY_ENABLED
select MBEDTLS_CIPHER
select MBEDTLS_ECP_C
select MBEDTLS_ECP_ALL_ENABLED
select MBEDTLS_CMAC
select MBEDTLS_PKCS5_C
select MBEDTLS_PK_WRITE_C
select MBEDTLS_ECDH_C
select MBEDTLS_ECDSA_C
select MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
select MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
select MBEDTLS_NIST_KW_C
select MBEDTLS_DHM_C
select MBEDTLS_HKDF_C
select MBEDTLS_SERVER_NAME_INDICATION
select MBEDTLS_X509_CRL_PARSE_C
config WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
bool "No Crypto support for WiFi"
endchoice
config WIFI_NM_WPA_SUPPLICANT_CRYPTO_MBEDTLS_PSA
bool "Crypto Platform Secure Architecture support for WiFi"
default y if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ALT
help
Support Mbedtls 3.x to use PSA apis instead of legacy apis.
config WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
bool "Enterprise Crypto support for WiFi"
select MBEDTLS_PEM_CERTIFICATE_FORMAT
depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
config WIFI_NM_WPA_SUPPLICANT_WPA3
bool "WPA3 support"
depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
default y
config WIFI_NM_WPA_SUPPLICANT_AP
bool "AP mode support"
config WIFI_NM_WPA_SUPPLICANT_WPS
bool "WPS support"
depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
config WIFI_NM_WPA_SUPPLICANT_P2P
bool "P2P mode support"
select WIFI_NM_WPA_SUPPLICANT_AP
select WIFI_NM_WPA_SUPPLICANT_WPS
config WIFI_NM_WPA_SUPPLICANT_EAPOL
bool "EAPoL supplicant"
default y if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
config WIFI_NM_WPA_SUPPLICANT_CLI
bool "CLI support for wpa_supplicant"
default n
config WIFI_NM_WPA_SUPPLICANT_INF_MON
bool "Monitor the net mgmt event to add/del interface"
default y
config WIFI_NM_WPA_SUPPLICANT_BSS_MAX_IDLE_TIME
int "BSS max idle timeout in seconds"
range 0 64000
default 300
help
BSS max idle timeout is the period for which AP may keep a client
in associated state while there is no traffic from that particular
client. Set 0 to disable inclusion of BSS max idle time tag in
association request. If a non-zero value is set, STA can suggest a
timeout by including BSS max idle period in the association request.
AP may choose to consider or ignore the STA's preferred value.
Ref: Sec 11.21.13 of IEEE Std 802.11-2020
config WIFI_NM_WPA_SUPPLICANT_NO_DEBUG
bool "Disable printing of debug messages, saves code size significantly"
config WIFI_NM_WPA_SUPPLICANT_DPP
bool "WFA Easy Connect DPP"
select DPP
select DPP2
select DPP3
select GAS
select GAS_SERVER
select OFFCHANNEL
select MBEDTLS_X509_CSR_WRITE_C
select MBEDTLS_X509_CSR_PARSE_C
config WPA_CLI
bool "WPA CLI support"
help
Enable WPA CLI support for wpa_supplicant.
if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
config MBEDTLS_SSL_MAX_CONTENT_LEN
default 16384
endif
# Create hidden config options that are used in hostap. This way we do not need
# to mark them as allowed for CI checks, and also someone else cannot use the
# same name options.
config SME
bool
default y
config NO_CONFIG_WRITE
bool
default y
config NO_CONFIG_BLOBS
bool
default y if !WIFI_NM_WPA_SUPPLICANT_DPP && !WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
config CTRL_IFACE
bool
default y
config CTRL_IFACE_ZEPHYR
bool
default y
config NO_RANDOM_POOL
bool
default y
config WNM
bool
config NO_WPA
bool
default y if WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
config NO_PBKDF2
bool
default y if WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
config SAE_PK
bool
config FST
bool
config TESTING_OPTIONS
bool
config AP
bool
depends on WIFI_NM_WPA_SUPPLICANT_AP
default y if WIFI_NM_WPA_SUPPLICANT_AP
config NO_RADIUS
bool
config NO_VLAN
bool
config NO_ACCOUNTING
bool
config NEED_AP_MLME
bool
config IEEE80211AX
bool
config EAP_SERVER
bool
config EAP_SERVER_IDENTITY
bool
config P2P
bool
config GAS
bool
config GAS_SERVER
bool
config OFFCHANNEL
bool
config WPS
bool
config WSC
bool
config EAP_TLS
bool
config IEEE8021X_EAPOL
bool
config EAP_PEAP
bool
config EAP_TTLS
bool
config EAP_MD5
bool
config EAP_MSCHAPv2
bool
config EAP_LEAP
bool
config EAP_PSK
bool
config EAP_FAST
bool
config EAP_PAX
bool
config EAP_SAKE
bool
config EAP_GPSK
bool
config EAP_PWD
bool
config EAP_EKE
bool
config EAP_IKEv2
bool
config IEEE8021X_EAPOL
bool
config CRYPTO_INTERNAL
bool
config ECC
bool
config MBO
bool
config NO_STDOUT_DEBUG
bool
config SAE
bool
config SHA256
bool
config SHA384
bool
config SHA512
bool
config SUITEB192
bool
config WEP
bool
default y if WIFI_NM_WPA_SUPPLICANT_WEP
config WPA_CRYPTO
bool
config WPA_SUPP_CRYPTO
bool
config ROBUST_AV
bool
default y
depends on WIFI_NM_WPA_SUPPLICANT_ROBUST_AV
config RRM
bool
default y
depends on WIFI_NM_WPA_SUPPLICANT_RRM
config WMM_AC
bool
config DPP
bool
config DPP2
bool
config DPP3
bool
config NW_SEL_RELIABILITY
bool
default y
depends on WIFI_NM_WPA_SUPPLICANT_NW_SEL_RELIABILITY
choice WIFI_NM_WPA_SUPPLICANT_NW_SEL
prompt "WPA supplicant Network selection criterion"
default WIFI_NM_WPA_SUPPLICANT_NW_SEL_THROUGHPUT
help
Select the network selection method for the supplicant.
config WIFI_NM_WPA_SUPPLICANT_NW_SEL_THROUGHPUT
bool "Throughput based network selection"
help
Select the network based on throughput.
config WIFI_NM_WPA_SUPPLICANT_NW_SEL_RELIABILITY
bool "Reliability based network selection"
help
Select the network based on reliability.
endchoice
config SAE_PWE_EARLY_EXIT
bool "Exit early if PWE if found"
help
In order to mitigate side channel attacks, even if the PWE is found the WPA
supplicant goes through full iterations, but in some low-resource systems
this can be intensive, so, add an option to exit early.
Note that this is highly insecure and shouldn't be used in production
endif # WIFI_NM_WPA_SUPPLICANT
``` | /content/code_sandbox/modules/hostap/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 2,767 |
```objective-c
/*
*
*/
#ifndef __SUPP_EVENTS_H__
#define __SUPP_EVENTS_H__
#include <zephyr/net/wifi_mgmt.h>
/* Connectivity Events */
#define _NET_MGMT_SUPPLICANT_LAYER NET_MGMT_LAYER_L3
#define _NET_MGMT_SUPPLICANT_CODE 0x157
#define _NET_MGMT_SUPPLICANT_BASE (NET_MGMT_LAYER(_NET_MGMT_SUPPLICANT_LAYER) | \
NET_MGMT_LAYER_CODE(_NET_MGMT_SUPPLICANT_CODE) | \
NET_MGMT_IFACE_BIT)
#define _NET_MGMT_SUPPLICANT_EVENT (NET_MGMT_EVENT_BIT | _NET_MGMT_SUPPLICANT_BASE)
enum net_event_supplicant_cmd {
NET_EVENT_SUPPLICANT_CMD_READY = 1,
NET_EVENT_SUPPLICANT_CMD_NOT_READY,
NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED,
NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING,
NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED,
NET_EVENT_SUPPLICANT_CMD_INT_EVENT,
NET_EVENT_WIFI_CMD_MAX
};
#define NET_EVENT_SUPPLICANT_READY \
(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_READY)
#define NET_EVENT_SUPPLICANT_NOT_READY \
(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_NOT_READY)
#define NET_EVENT_SUPPLICANT_IFACE_ADDED \
(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED)
#define NET_EVENT_SUPPLICANT_IFACE_REMOVED \
(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED)
#define NET_EVENT_SUPPLICANT_IFACE_REMOVING \
(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING)
#define NET_EVENT_SUPPLICANT_INT_EVENT \
(_NET_MGMT_SUPPLICANT_EVENT | NET_EVENT_SUPPLICANT_CMD_INT_EVENT)
int supplicant_send_wifi_mgmt_event(const char *ifname,
enum net_event_wifi_cmd event,
void *status,
size_t len);
int supplicant_generate_state_event(const char *ifname,
enum net_event_supplicant_cmd event,
int status);
int supplicant_send_wifi_mgmt_conn_event(void *ctx, int status_code);
int supplicant_send_wifi_mgmt_disc_event(void *ctx, int reason_code);
#ifdef CONFIG_AP
int supplicant_send_wifi_mgmt_ap_status(void *ctx,
enum net_event_wifi_cmd event,
enum wifi_ap_status);
int supplicant_send_wifi_mgmt_ap_sta_event(void *ctx,
enum net_event_wifi_cmd event,
void *data);
#endif /* CONFIG_AP */
#define REASON_CODE_LEN 18
#define NM_WIFI_EVENT_STR_LEN 64
#define ETH_ALEN 6
union supplicant_event_data {
struct supplicant_event_auth_reject {
int auth_type;
int auth_transaction;
int status_code;
uint8_t bssid[ETH_ALEN];
} auth_reject;
struct supplicant_event_connected {
uint8_t bssid[ETH_ALEN];
char ssid[WIFI_SSID_MAX_LEN];
int id;
} connected;
struct supplicant_event_disconnected {
uint8_t bssid[ETH_ALEN];
int reason_code;
int locally_generated;
} disconnected;
struct supplicant_event_assoc_reject {
int status_code;
int reason_code;
} assoc_reject;
struct supplicant_event_temp_disabled {
int id;
char ssid[WIFI_SSID_MAX_LEN];
unsigned int auth_failures;
unsigned int duration;
char reason_code[REASON_CODE_LEN];
} temp_disabled;
struct supplicant_event_reenabled {
int id;
char ssid[WIFI_SSID_MAX_LEN];
} reenabled;
struct supplicant_event_bss_added {
unsigned int id;
uint8_t bssid[ETH_ALEN];
} bss_added;
struct supplicant_event_bss_removed {
unsigned int id;
uint8_t bssid[ETH_ALEN];
} bss_removed;
struct supplicant_event_network_added {
unsigned int id;
} network_added;
struct supplicant_event_network_removed {
unsigned int id;
} network_removed;
char supplicant_event_str[NM_WIFI_EVENT_STR_LEN];
};
enum supplicant_event_num {
SUPPLICANT_EVENT_CONNECTED,
SUPPLICANT_EVENT_DISCONNECTED,
SUPPLICANT_EVENT_ASSOC_REJECT,
SUPPLICANT_EVENT_AUTH_REJECT,
SUPPLICANT_EVENT_TERMINATING,
SUPPLICANT_EVENT_SSID_TEMP_DISABLED,
SUPPLICANT_EVENT_SSID_REENABLED,
SUPPLICANT_EVENT_SCAN_STARTED,
SUPPLICANT_EVENT_SCAN_RESULTS,
SUPPLICANT_EVENT_SCAN_FAILED,
SUPPLICANT_EVENT_BSS_ADDED,
SUPPLICANT_EVENT_BSS_REMOVED,
SUPPLICANT_EVENT_NETWORK_NOT_FOUND,
SUPPLICANT_EVENT_NETWORK_ADDED,
SUPPLICANT_EVENT_NETWORK_REMOVED,
SUPPLICANT_EVENT_DSCP_POLICY,
};
struct supplicant_int_event_data {
enum supplicant_event_num event;
void *data;
size_t data_len;
};
#endif /* __SUPP_EVENTS_H__ */
``` | /content/code_sandbox/modules/hostap/src/supp_events.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,087 |
```objective-c
/*
*
*/
#ifndef __SUPP_MAIN_H_
#define __SUPP_MAIN_H_
#if !defined(CONFIG_NET_DHCPV4)
static inline void net_dhcpv4_start(struct net_if *iface)
{
ARG_UNUSED(iface);
}
static inline void net_dhcpv4_stop(struct net_if *iface)
{
ARG_UNUSED(iface);
}
#else
#include <zephyr/net/dhcpv4.h>
#endif
struct wpa_global *zephyr_get_default_supplicant_context(void);
struct wpa_supplicant *zephyr_get_handle_by_ifname(const char *ifname);
struct wpa_supplicant_event_msg {
bool global;
void *ctx;
unsigned int event;
void *data;
};
int zephyr_wifi_send_event(const struct wpa_supplicant_event_msg *msg);
#endif /* __SUPP_MAIN_H_ */
``` | /content/code_sandbox/modules/hostap/src/supp_main.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 176 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_SUPP_MGMT_H
#define ZEPHYR_SUPP_MGMT_H
#include <zephyr/net/wifi_mgmt.h>
#ifndef MAX_SSID_LEN
#define MAX_SSID_LEN 32
#endif
#ifndef MAC_ADDR_LEN
#define MAC_ADDR_LEN 6
#endif
#define MAC_STR_LEN 18 /* for ':' or '-' separated MAC address string */
#define CHAN_NUM_LEN 6 /* for space-separated channel numbers string */
/**
* @brief Get version
*
* @param dev: Wi-Fi interface name to use
* @param params: version to fill
*
* @return: 0 for OK; <0 for ERROR
*/
int supplicant_get_version(const struct device *dev, struct wifi_version *params);
/**
* @brief Request a connection
*
* @param dev: Wi-Fi interface name to use
* @param params: Connection details
*
* @return: 0 for OK; -1 for ERROR
*/
int supplicant_connect(const struct device *dev, struct wifi_connect_req_params *params);
/**
* @brief Forces station to disconnect and stops any subsequent scan
* or connection attempts
*
* @param dev: Wi-Fi interface name to use
*
* @return: 0 for OK; -1 for ERROR
*/
int supplicant_disconnect(const struct device *dev);
/**
* @brief
*
* @param dev: Wi-Fi interface name to use
* @param status: Status structure to fill
*
* @return: 0 for OK; -1 for ERROR
*/
int supplicant_status(const struct device *dev, struct wifi_iface_status *status);
/**
* @brief Request a scan
*
* @param dev Wi-Fi interface name to use
* @param params Scan parameters
* @param cb Callback to be called for each scan result
*
* @return 0 for OK; -1 for ERROR
*/
int supplicant_scan(const struct device *dev, struct wifi_scan_params *params,
scan_result_cb_t cb);
#if defined(CONFIG_NET_STATISTICS_WIFI) || defined(__DOXYGEN__)
/**
* @brief Get Wi-Fi statistics
*
* @param dev Wi-Fi interface name to use
* @param stats Pointer to stats structure to fill
*
* @return 0 for OK; -1 for ERROR
*/
int supplicant_get_stats(const struct device *dev, struct net_stats_wifi *stats);
#endif /* CONFIG_NET_STATISTICS_WIFI || __DOXYGEN__ */
/** Flush PMKSA cache entries
*
* @param dev Pointer to the device structure for the driver instance.
*
* @return 0 if ok, < 0 if error
*/
int supplicant_pmksa_flush(const struct device *dev);
/**
* @brief Set Wi-Fi power save configuration
*
* @param dev Wi-Fi interface name to use
* @param params Power save parameters to set
*
* @return 0 for OK; -1 for ERROR
*/
int supplicant_set_power_save(const struct device *dev, struct wifi_ps_params *params);
/**
* @brief Set Wi-Fi TWT parameters
*
* @param dev Wi-Fi interface name to use
* @param params TWT parameters to set
* @return 0 for OK; -1 for ERROR
*/
int supplicant_set_twt(const struct device *dev, struct wifi_twt_params *params);
/**
* @brief Get Wi-Fi power save configuration
*
* @param dev Wi-Fi interface name to use
* @param config Address of power save configuration to fill
* @return 0 for OK; -1 for ERROR
*/
int supplicant_get_power_save_config(const struct device *dev, struct wifi_ps_config *config);
/**
* @brief Set Wi-Fi Regulatory domain
*
* @param dev Wi-Fi interface name to use
* @param reg_domain Regulatory domain to set
* @return 0 for OK; -1 for ERROR
*/
int supplicant_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_domain);
/**
* @brief Set Wi-Fi mode of operation
*
* @param dev Wi-Fi interface name to use
* @param mode Mode setting to set
* @return 0 for OK; -1 for ERROR
*/
int supplicant_mode(const struct device *dev, struct wifi_mode_info *mode);
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
/** Set Wi-Fi enterprise mode CA/client Cert and key
*
* @param dev Pointer to the device structure for the driver instance
* @param file Pointer to the CA/client Cert and key.
*
* @return 0 if ok, < 0 if error
*/
int supplicant_add_enterprise_creds(const struct device *dev,
struct wifi_enterprise_creds_params *creds);
#endif
/**
* @brief Set Wi-Fi packet filter for sniffing operation
*
* @param dev Wi-Fi interface name to use
* @param filter Filter settings to set
* @return 0 for OK; -1 for ERROR
*/
int supplicant_filter(const struct device *dev, struct wifi_filter_info *filter);
/**
* @brief Set Wi-Fi channel for monitor or TX injection mode
*
* @param dev Wi-Fi interface name to use
* @param channel Channel settings to set
* @return 0 for OK; -1 for ERROR
*/
int supplicant_channel(const struct device *dev, struct wifi_channel_info *channel);
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM
/** Send bss transition query
*
* @param dev Pointer to the device structure for the driver instance.
* @param reason query reason
*
* @return 0 if ok, < 0 if error
*/
int supplicant_btm_query(const struct device *dev, uint8_t reason);
#endif
/** Get Wi-Fi connection parameters recently used
*
* @param dev Pointer to the device structure for the driver instance
* @param params the Wi-Fi connection parameters recently used
*
* @return 0 if ok, < 0 if error
*/
int supplicant_get_wifi_conn_params(const struct device *dev,
struct wifi_connect_req_params *params);
#ifdef CONFIG_AP
/**
* @brief Set Wi-Fi AP configuration
*
* @param dev Wi-Fi interface name to use
* @param params AP configuration parameters to set
* @return 0 for OK; -1 for ERROR
*/
int supplicant_ap_enable(const struct device *dev,
struct wifi_connect_req_params *params);
/**
* @brief Disable Wi-Fi AP
* @param dev Wi-Fi interface name to use
* @return 0 for OK; -1 for ERROR
*/
int supplicant_ap_disable(const struct device *dev);
/**
* @brief Set Wi-Fi AP STA disconnect
* @param dev Wi-Fi interface name to use
* @param mac_addr MAC address of the station to disconnect
* @return 0 for OK; -1 for ERROR
*/
int supplicant_ap_sta_disconnect(const struct device *dev,
const uint8_t *mac_addr);
#endif /* CONFIG_AP */
/**
* @brief Dispatch DPP operations
*
* @param dev Wi-Fi interface name to use
* @param dpp_params DPP action enum and params in string
* @return 0 for OK; -1 for ERROR
*/
int supplicant_dpp_dispatch(const struct device *dev,
struct wifi_dpp_params *params);
#endif /* ZEPHYR_SUPP_MGMT_H */
``` | /content/code_sandbox/modules/hostap/src/supp_api.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,552 |
```c
/*
*
*/
#include "supp_events.h"
#include "includes.h"
#include "common.h"
#include "common/ieee802_11_defs.h"
#include "wpa_supplicant_i.h"
#ifdef CONFIG_AP
#include "ap/sta_info.h"
#include "ap/ieee802_11.h"
#include "ap/hostapd.h"
#endif /* CONFIG_AP */
#include <zephyr/net/wifi_mgmt.h>
/* Re-defines MAC2STR with address of the element */
#define MACADDR2STR(a) &(a)[0], &(a)[1], &(a)[2], &(a)[3], &(a)[4], &(a)[5]
static const struct wpa_supp_event_info {
const char *event_str;
enum supplicant_event_num event;
} wpa_supp_event_info[] = {
{ "CTRL-EVENT-CONNECTED", SUPPLICANT_EVENT_CONNECTED },
{ "CTRL-EVENT-DISCONNECTED", SUPPLICANT_EVENT_DISCONNECTED },
{ "CTRL-EVENT-ASSOC-REJECT", SUPPLICANT_EVENT_ASSOC_REJECT },
{ "CTRL-EVENT-AUTH-REJECT", SUPPLICANT_EVENT_AUTH_REJECT },
{ "CTRL-EVENT-SSID-TEMP-DISABLED", SUPPLICANT_EVENT_SSID_TEMP_DISABLED },
{ "CTRL-EVENT-SSID-REENABLED", SUPPLICANT_EVENT_SSID_REENABLED },
{ "CTRL-EVENT-BSS-ADDED", SUPPLICANT_EVENT_BSS_ADDED },
{ "CTRL-EVENT-BSS-REMOVED", SUPPLICANT_EVENT_BSS_REMOVED },
{ "CTRL-EVENT-TERMINATING", SUPPLICANT_EVENT_TERMINATING },
{ "CTRL-EVENT-SCAN-STARTED", SUPPLICANT_EVENT_SCAN_STARTED },
{ "CTRL-EVENT-SCAN-RESULTS", SUPPLICANT_EVENT_SCAN_RESULTS },
{ "CTRL-EVENT-SCAN-FAILED", SUPPLICANT_EVENT_SCAN_FAILED },
{ "CTRL-EVENT-NETWORK-NOT-FOUND", SUPPLICANT_EVENT_NETWORK_NOT_FOUND },
{ "CTRL-EVENT-NETWORK-ADDED", SUPPLICANT_EVENT_NETWORK_ADDED },
{ "CTRL-EVENT-NETWORK-REMOVED", SUPPLICANT_EVENT_NETWORK_REMOVED },
{ "CTRL-EVENT-DSCP-POLICY", SUPPLICANT_EVENT_DSCP_POLICY },
};
static void copy_mac_addr(const unsigned int *src, uint8_t *dst)
{
int i;
for (i = 0; i < ETH_ALEN; i++) {
dst[i] = src[i];
}
}
static enum wifi_conn_status wpas_to_wifi_mgmt_conn_status(int status)
{
switch (status) {
case WLAN_STATUS_SUCCESS:
return WIFI_STATUS_CONN_SUCCESS;
case WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT:
return WIFI_STATUS_CONN_WRONG_PASSWORD;
/* Handle non-supplicant errors */
case -ETIMEDOUT:
return WIFI_STATUS_CONN_TIMEOUT;
default:
return WIFI_STATUS_CONN_FAIL;
}
}
static enum wifi_disconn_reason wpas_to_wifi_mgmt_disconn_status(int status)
{
switch (status) {
case WIFI_REASON_DISCONN_SUCCESS:
return WIFI_REASON_DISCONN_SUCCESS;
case WLAN_REASON_DEAUTH_LEAVING:
return WIFI_REASON_DISCONN_AP_LEAVING;
case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
return WIFI_REASON_DISCONN_INACTIVITY;
case WLAN_REASON_UNSPECIFIED:
/* fall through */
default:
return WIFI_REASON_DISCONN_UNSPECIFIED;
}
}
static int supplicant_process_status(struct supplicant_int_event_data *event_data,
char *supplicant_status)
{
int ret = 1; /* For cases where parsing is not being done*/
int i;
union supplicant_event_data *data;
unsigned int tmp_mac_addr[ETH_ALEN];
unsigned int event_prefix_len;
char *event_no_prefix;
struct wpa_supp_event_info event_info;
data = (union supplicant_event_data *)event_data->data;
for (i = 0; i < ARRAY_SIZE(wpa_supp_event_info); i++) {
if (strncmp(supplicant_status, wpa_supp_event_info[i].event_str,
strlen(wpa_supp_event_info[i].event_str)) == 0) {
event_info = wpa_supp_event_info[i];
break;
}
}
if (i >= ARRAY_SIZE(wpa_supp_event_info)) {
/* This is not a bug but rather implementation gap (intentional or not) */
wpa_printf(MSG_DEBUG, "Event not supported: %s", supplicant_status);
return -ENOTSUP;
}
/* Skip the event prefix and a space */
event_prefix_len = strlen(event_info.event_str) + 1;
event_no_prefix = supplicant_status + event_prefix_len;
event_data->event = event_info.event;
switch (event_data->event) {
case SUPPLICANT_EVENT_CONNECTED:
ret = sscanf(event_no_prefix, "- Connection to"
MACSTR, MACADDR2STR(tmp_mac_addr));
event_data->data_len = sizeof(data->connected);
copy_mac_addr(tmp_mac_addr, data->connected.bssid);
break;
case SUPPLICANT_EVENT_DISCONNECTED:
ret = sscanf(event_no_prefix,
MACSTR" reason=%d", MACADDR2STR(tmp_mac_addr),
&data->disconnected.reason_code);
event_data->data_len = sizeof(data->disconnected);
copy_mac_addr(tmp_mac_addr, data->disconnected.bssid);
break;
case SUPPLICANT_EVENT_ASSOC_REJECT:
/* TODO */
break;
case SUPPLICANT_EVENT_AUTH_REJECT:
ret = sscanf(event_no_prefix, MACSTR
" auth_type=%u auth_transaction=%u status_code=%u",
MACADDR2STR(tmp_mac_addr),
&data->auth_reject.auth_type,
&data->auth_reject.auth_transaction,
&data->auth_reject.status_code);
event_data->data_len = sizeof(data->auth_reject);
copy_mac_addr(tmp_mac_addr, data->auth_reject.bssid);
break;
case SUPPLICANT_EVENT_SSID_TEMP_DISABLED:
ret = sscanf(event_no_prefix,
"id=%d ssid=%s auth_failures=%u duration=%d reason=%s",
&data->temp_disabled.id, data->temp_disabled.ssid,
&data->temp_disabled.auth_failures,
&data->temp_disabled.duration,
data->temp_disabled.reason_code);
event_data->data_len = sizeof(data->temp_disabled);
break;
case SUPPLICANT_EVENT_SSID_REENABLED:
ret = sscanf(event_no_prefix,
"id=%d ssid=%s", &data->reenabled.id,
data->reenabled.ssid);
event_data->data_len = sizeof(data->reenabled);
break;
case SUPPLICANT_EVENT_BSS_ADDED:
ret = sscanf(event_no_prefix, "%u "MACSTR,
&data->bss_added.id,
MACADDR2STR(tmp_mac_addr));
copy_mac_addr(tmp_mac_addr, data->bss_added.bssid);
event_data->data_len = sizeof(data->bss_added);
break;
case SUPPLICANT_EVENT_BSS_REMOVED:
ret = sscanf(event_no_prefix,
"%u "MACSTR,
&data->bss_removed.id,
MACADDR2STR(tmp_mac_addr));
event_data->data_len = sizeof(data->bss_removed);
copy_mac_addr(tmp_mac_addr, data->bss_removed.bssid);
break;
case SUPPLICANT_EVENT_TERMINATING:
case SUPPLICANT_EVENT_SCAN_STARTED:
case SUPPLICANT_EVENT_SCAN_RESULTS:
case SUPPLICANT_EVENT_SCAN_FAILED:
case SUPPLICANT_EVENT_NETWORK_NOT_FOUND:
case SUPPLICANT_EVENT_NETWORK_ADDED:
case SUPPLICANT_EVENT_NETWORK_REMOVED:
strncpy(data->supplicant_event_str, event_info.event_str,
sizeof(data->supplicant_event_str) - 1);
event_data->data_len = strlen(data->supplicant_event_str) + 1;
case SUPPLICANT_EVENT_DSCP_POLICY:
/* TODO */
break;
default:
break;
}
if (ret <= 0) {
wpa_printf(MSG_ERROR, "%s Parse failed: %s",
event_info.event_str, strerror(errno));
}
return ret;
}
int supplicant_send_wifi_mgmt_conn_event(void *ctx, int status_code)
{
struct wpa_supplicant *wpa_s = ctx;
int status = wpas_to_wifi_mgmt_conn_status(status_code);
enum net_event_wifi_cmd event;
if (!wpa_s || !wpa_s->current_ssid) {
return -EINVAL;
}
if (wpa_s->current_ssid->mode == WPAS_MODE_AP) {
event = NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT;
} else {
event = NET_EVENT_WIFI_CMD_CONNECT_RESULT;
}
return supplicant_send_wifi_mgmt_event(wpa_s->ifname,
event,
(void *)&status,
sizeof(int));
}
int supplicant_send_wifi_mgmt_disc_event(void *ctx, int reason_code)
{
struct wpa_supplicant *wpa_s = ctx;
int status = wpas_to_wifi_mgmt_disconn_status(reason_code);
enum net_event_wifi_cmd event;
if (!wpa_s || !wpa_s->current_ssid) {
return -EINVAL;
}
if (wpa_s->wpa_state >= WPA_COMPLETED) {
if (wpa_s->current_ssid->mode == WPAS_MODE_AP) {
event = NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT;
} else {
event = NET_EVENT_WIFI_CMD_DISCONNECT_RESULT;
}
} else {
if (wpa_s->current_ssid->mode == WPAS_MODE_AP) {
event = NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT;
} else {
event = NET_EVENT_WIFI_CMD_CONNECT_RESULT;
}
}
return supplicant_send_wifi_mgmt_event(wpa_s->ifname,
event,
(void *)&status,
sizeof(int));
}
#ifdef CONFIG_AP
static enum wifi_link_mode get_sta_link_mode(struct wpa_supplicant *wpa_s, struct sta_info *sta)
{
if (sta->flags & WLAN_STA_HE) {
return WIFI_6;
} else if (sta->flags & WLAN_STA_VHT) {
return WIFI_5;
} else if (sta->flags & WLAN_STA_HT) {
return WIFI_4;
} else if (sta->flags & WLAN_STA_NONERP) {
return WIFI_1;
} else if (wpa_s->assoc_freq > 4000) {
return WIFI_2;
} else if (wpa_s->assoc_freq > 2000) {
return WIFI_3;
} else {
return WIFI_LINK_MODE_UNKNOWN;
}
}
static bool is_twt_capable(struct wpa_supplicant *wpa_s, struct sta_info *sta)
{
return hostapd_get_he_twt_responder(wpa_s->ap_iface->bss[0], IEEE80211_MODE_AP);
}
int supplicant_send_wifi_mgmt_ap_status(void *ctx,
enum net_event_wifi_cmd event,
enum wifi_ap_status ap_status)
{
struct wpa_supplicant *wpa_s = ctx;
int status = ap_status;
return supplicant_send_wifi_mgmt_event(wpa_s->ifname,
event,
(void *)&status,
sizeof(int));
}
int supplicant_send_wifi_mgmt_ap_sta_event(void *ctx,
enum net_event_wifi_cmd event,
void *data)
{
struct sta_info *sta = data;
struct wpa_supplicant *wpa_s = ctx;
struct wifi_ap_sta_info sta_info = { 0 };
if (!wpa_s || !sta) {
return -EINVAL;
}
memcpy(sta_info.mac, sta->addr, sizeof(sta_info.mac));
if (event == NET_EVENT_WIFI_CMD_AP_STA_CONNECTED) {
sta_info.link_mode = get_sta_link_mode(wpa_s, sta);
sta_info.twt_capable = is_twt_capable(wpa_s, sta);
}
return supplicant_send_wifi_mgmt_event(wpa_s->ifname,
event,
(void *)&sta_info,
sizeof(sta_info));
}
#endif /* CONFIG_AP */
int supplicant_send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event,
void *supplicant_status, size_t len)
{
struct net_if *iface = net_if_get_by_index(net_if_get_by_name(ifname));
union supplicant_event_data data;
struct supplicant_int_event_data event_data;
if (!iface) {
wpa_printf(MSG_ERROR, "Could not find iface for %s", ifname);
return -ENODEV;
}
switch (event) {
case NET_EVENT_WIFI_CMD_CONNECT_RESULT:
wifi_mgmt_raise_connect_result_event(
iface,
*(int *)supplicant_status);
break;
case NET_EVENT_WIFI_CMD_DISCONNECT_RESULT:
wifi_mgmt_raise_disconnect_result_event(
iface,
*(int *)supplicant_status);
break;
#ifdef CONFIG_AP
case NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT:
wifi_mgmt_raise_ap_enable_result_event(iface,
*(int *)supplicant_status);
break;
case NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT:
wifi_mgmt_raise_ap_disable_result_event(iface,
*(int *)supplicant_status);
break;
case NET_EVENT_WIFI_CMD_AP_STA_CONNECTED:
wifi_mgmt_raise_ap_sta_connected_event(iface,
(struct wifi_ap_sta_info *)supplicant_status);
break;
case NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED:
wifi_mgmt_raise_ap_sta_disconnected_event(iface,
(struct wifi_ap_sta_info *)supplicant_status);
break;
#endif /* CONFIG_AP */
case NET_EVENT_SUPPLICANT_CMD_INT_EVENT:
event_data.data = &data;
if (supplicant_process_status(&event_data, (char *)supplicant_status) > 0) {
net_mgmt_event_notify_with_info(NET_EVENT_SUPPLICANT_INT_EVENT,
iface, &event_data, sizeof(event_data));
}
break;
default:
wpa_printf(MSG_ERROR, "Unsupported event %d", event);
return -EINVAL;
}
return 0;
}
int supplicant_generate_state_event(const char *ifname,
enum net_event_supplicant_cmd event,
int status)
{
struct net_if *iface;
iface = net_if_get_by_index(net_if_get_by_name(ifname));
if (!iface) {
wpa_printf(MSG_ERROR, "Could not find iface for %s", ifname);
return -ENODEV;
}
switch (event) {
case NET_EVENT_SUPPLICANT_CMD_READY:
net_mgmt_event_notify(NET_EVENT_SUPPLICANT_READY, iface);
break;
case NET_EVENT_SUPPLICANT_CMD_NOT_READY:
net_mgmt_event_notify(NET_EVENT_SUPPLICANT_NOT_READY, iface);
break;
case NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED:
net_mgmt_event_notify(NET_EVENT_SUPPLICANT_IFACE_ADDED, iface);
break;
case NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING:
net_mgmt_event_notify(NET_EVENT_SUPPLICANT_IFACE_REMOVING, iface);
break;
case NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED:
net_mgmt_event_notify_with_info(NET_EVENT_SUPPLICANT_IFACE_REMOVED,
iface, &status, sizeof(status));
break;
default:
wpa_printf(MSG_ERROR, "Unsupported event %d", event);
return -EINVAL;
}
return 0;
}
``` | /content/code_sandbox/modules/hostap/src/supp_events.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 3,317 |
```c
/**
*
*/
#include <stdarg.h>
#include <zephyr/logging/log.h>
#include <zephyr/kernel.h>
#include <zephyr/net/wifi_mgmt.h>
#include "includes.h"
#include "common.h"
#include "common/defs.h"
#include "wpa_supplicant/config.h"
#include "wpa_supplicant_i.h"
#include "driver_i.h"
#include "supp_main.h"
#include "supp_api.h"
#include "wpa_cli_zephyr.h"
#include "supp_events.h"
extern struct k_sem wpa_supplicant_ready_sem;
extern struct wpa_global *global;
/* save the last wifi connection parameters */
static struct wifi_connect_req_params last_wifi_conn_params;
enum requested_ops {
CONNECT = 0,
DISCONNECT
};
enum status_thread_state {
STATUS_THREAD_STOPPED = 0,
STATUS_THREAD_RUNNING,
};
#define OP_STATUS_POLLING_INTERVAL 1
#define CONNECTION_SUCCESS 0
#define CONNECTION_FAILURE 1
#define CONNECTION_TERMINATED 2
#define DISCONNECT_TIMEOUT_MS 5000
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
static struct wifi_enterprise_creds_params enterprise_creds;
#endif
K_MUTEX_DEFINE(wpa_supplicant_mutex);
extern struct k_work_q *get_workq(void);
struct wpa_supp_api_ctrl {
const struct device *dev;
enum requested_ops requested_op;
enum status_thread_state status_thread_state;
int connection_timeout; /* in seconds */
struct k_work_sync sync;
bool terminate;
};
static struct wpa_supp_api_ctrl wpas_api_ctrl;
static void supp_shell_connect_status(struct k_work *work);
static K_WORK_DELAYABLE_DEFINE(wpa_supp_status_work,
supp_shell_connect_status);
#define wpa_cli_cmd_v(cmd, ...) ({ \
bool status; \
\
if (zephyr_wpa_cli_cmd_v(cmd, ##__VA_ARGS__) < 0) { \
wpa_printf(MSG_ERROR, \
"Failed to execute wpa_cli command: %s", \
cmd); \
status = false; \
} else { \
status = true; \
} \
\
status; \
})
static struct wpa_supplicant *get_wpa_s_handle(const struct device *dev)
{
struct net_if *iface = net_if_lookup_by_dev(dev);
char if_name[CONFIG_NET_INTERFACE_NAME_LEN + 1];
struct wpa_supplicant *wpa_s;
int ret;
if (!iface) {
wpa_printf(MSG_ERROR, "Interface for device %s not found", dev->name);
return NULL;
}
ret = net_if_get_name(iface, if_name, sizeof(if_name));
if (!ret) {
wpa_printf(MSG_ERROR, "Cannot get interface name (%d)", ret);
return NULL;
}
wpa_s = zephyr_get_handle_by_ifname(if_name);
if (!wpa_s) {
wpa_printf(MSG_ERROR, "Interface %s not found", if_name);
return NULL;
}
return wpa_s;
}
#define WPA_SUPP_STATE_POLLING_MS 10
static int wait_for_disconnect_complete(const struct device *dev)
{
int ret = 0;
int attempts = 0;
struct wpa_supplicant *wpa_s = get_wpa_s_handle(dev);
unsigned int max_attempts = DISCONNECT_TIMEOUT_MS / WPA_SUPP_STATE_POLLING_MS;
if (!wpa_s) {
ret = -ENODEV;
wpa_printf(MSG_ERROR, "Failed to get wpa_s handle");
goto out;
}
while (wpa_s->wpa_state != WPA_DISCONNECTED) {
if (attempts++ > max_attempts) {
ret = -ETIMEDOUT;
wpa_printf(MSG_WARNING, "Failed to disconnect from network");
break;
}
k_sleep(K_MSEC(WPA_SUPP_STATE_POLLING_MS));
}
out:
return ret;
}
static void supp_shell_connect_status(struct k_work *work)
{
static int seconds_counter;
int status = CONNECTION_SUCCESS;
int conn_result = CONNECTION_FAILURE;
struct wpa_supplicant *wpa_s;
struct wpa_supp_api_ctrl *ctrl = &wpas_api_ctrl;
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
if (ctrl->status_thread_state == STATUS_THREAD_RUNNING && ctrl->terminate) {
status = CONNECTION_TERMINATED;
goto out;
}
wpa_s = get_wpa_s_handle(ctrl->dev);
if (!wpa_s) {
status = CONNECTION_FAILURE;
goto out;
}
if (ctrl->requested_op == CONNECT && wpa_s->wpa_state != WPA_COMPLETED) {
if (ctrl->connection_timeout > 0 &&
seconds_counter++ > ctrl->connection_timeout) {
if (!wpa_cli_cmd_v("disconnect")) {
goto out;
}
conn_result = -ETIMEDOUT;
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
NET_EVENT_WIFI_CMD_CONNECT_RESULT,
(void *)&conn_result, sizeof(int));
status = CONNECTION_FAILURE;
goto out;
}
k_work_reschedule_for_queue(get_workq(), &wpa_supp_status_work,
K_SECONDS(OP_STATUS_POLLING_INTERVAL));
ctrl->status_thread_state = STATUS_THREAD_RUNNING;
k_mutex_unlock(&wpa_supplicant_mutex);
return;
}
out:
seconds_counter = 0;
ctrl->status_thread_state = STATUS_THREAD_STOPPED;
k_mutex_unlock(&wpa_supplicant_mutex);
}
static struct hostapd_hw_modes *get_mode_by_band(struct wpa_supplicant *wpa_s, uint8_t band)
{
enum hostapd_hw_mode hw_mode;
bool is_6ghz = (band == WIFI_FREQ_BAND_6_GHZ) ? true : false;
if (band == WIFI_FREQ_BAND_2_4_GHZ) {
hw_mode = HOSTAPD_MODE_IEEE80211G;
} else if ((band == WIFI_FREQ_BAND_5_GHZ) ||
(band == WIFI_FREQ_BAND_6_GHZ)) {
hw_mode = HOSTAPD_MODE_IEEE80211A;
} else {
return NULL;
}
return get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, hw_mode, is_6ghz);
}
static int wpa_supp_supported_channels(struct wpa_supplicant *wpa_s, uint8_t band, char **chan_list)
{
struct hostapd_hw_modes *mode = NULL;
int i;
int offset, retval;
int size;
char *_chan_list;
mode = get_mode_by_band(wpa_s, band);
if (!mode) {
wpa_printf(MSG_ERROR, "Unsupported or invalid band: %d", band);
return -EINVAL;
}
size = ((mode->num_channels) * CHAN_NUM_LEN) + 1;
_chan_list = k_malloc(size);
if (!_chan_list) {
wpa_printf(MSG_ERROR, "Mem alloc failed for channel list");
return -ENOMEM;
}
retval = 0;
offset = 0;
for (i = 0; i < mode->num_channels; i++) {
retval = snprintf(_chan_list + offset, CHAN_NUM_LEN, " %d",
mode->channels[i].freq);
offset += retval;
}
*chan_list = _chan_list;
return 0;
}
static int wpa_supp_band_chan_compat(struct wpa_supplicant *wpa_s, uint8_t band, uint8_t channel)
{
struct hostapd_hw_modes *mode = NULL;
int i;
mode = get_mode_by_band(wpa_s, band);
if (!mode) {
wpa_printf(MSG_ERROR, "Unsupported or invalid band: %d", band);
return -EINVAL;
}
for (i = 0; i < mode->num_channels; i++) {
if (mode->channels[i].chan == channel) {
return mode->channels[i].freq;
}
}
wpa_printf(MSG_ERROR, "Channel %d not supported for band %d", channel, band);
return -EINVAL;
}
static inline void wpa_supp_restart_status_work(void)
{
/* Terminate synchronously */
wpas_api_ctrl.terminate = 1;
k_work_flush_delayable(&wpa_supp_status_work, &wpas_api_ctrl.sync);
wpas_api_ctrl.terminate = 0;
/* Start afresh */
k_work_reschedule_for_queue(get_workq(), &wpa_supp_status_work, K_MSEC(10));
}
static inline int chan_to_freq(int chan)
{
/* We use global channel list here and also use the widest
* op_class for 5GHz channels as there is no user input
* for these (yet).
*/
int freq = -1;
int op_classes[] = {81, 82, 128};
int op_classes_size = ARRAY_SIZE(op_classes);
for (int i = 0; i < op_classes_size; i++) {
freq = ieee80211_chan_to_freq(NULL, op_classes[i], chan);
if (freq > 0) {
break;
}
}
if (freq <= 0) {
wpa_printf(MSG_ERROR, "Invalid channel %d", chan);
return -1;
}
return freq;
}
static inline enum wifi_frequency_bands wpas_band_to_zephyr(enum wpa_radio_work_band band)
{
switch (band) {
case BAND_2_4_GHZ:
return WIFI_FREQ_BAND_2_4_GHZ;
case BAND_5_GHZ:
return WIFI_FREQ_BAND_5_GHZ;
default:
return WIFI_FREQ_BAND_UNKNOWN;
}
}
static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int proto)
{
switch (key_mgmt) {
case WPA_KEY_MGMT_NONE:
return WIFI_SECURITY_TYPE_NONE;
case WPA_KEY_MGMT_PSK:
if (proto == WPA_PROTO_RSN) {
return WIFI_SECURITY_TYPE_PSK;
} else {
return WIFI_SECURITY_TYPE_WPA_PSK;
}
case WPA_KEY_MGMT_PSK_SHA256:
return WIFI_SECURITY_TYPE_PSK_SHA256;
case WPA_KEY_MGMT_SAE:
return WIFI_SECURITY_TYPE_SAE;
default:
return WIFI_SECURITY_TYPE_UNKNOWN;
}
}
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
int supplicant_add_enterprise_creds(const struct device *dev,
struct wifi_enterprise_creds_params *creds)
{
int ret = 0;
if (!creds) {
ret = -1;
wpa_printf(MSG_ERROR, "enterprise creds is NULL");
goto out;
}
memcpy((void *)&enterprise_creds, (void *)creds,
sizeof(struct wifi_enterprise_creds_params));
out:
return ret;
}
static int wpas_config_process_blob(struct wpa_config *config, char *name, uint8_t *data,
uint32_t data_len)
{
struct wpa_config_blob *blob;
if (!data || !data_len) {
return -1;
}
blob = os_zalloc(sizeof(*blob));
if (blob == NULL) {
return -1;
}
blob->data = os_zalloc(data_len);
if (blob->data == NULL) {
os_free(blob);
return -1;
}
blob->name = os_strdup(name);
if (blob->name == NULL) {
wpa_config_free_blob(blob);
return -1;
}
os_memcpy(blob->data, data, data_len);
blob->len = data_len;
wpa_config_set_blob(config, blob);
return 0;
}
#endif
static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s,
struct wifi_connect_req_params *params,
bool mode_ap)
{
struct add_network_resp resp = {0};
char *chan_list = NULL;
struct net_eth_addr mac = {0};
int ret = 0;
if (!wpa_cli_cmd_v("remove_network all")) {
goto out;
}
ret = z_wpa_ctrl_add_network(&resp);
if (ret) {
wpa_printf(MSG_ERROR, "Failed to add network");
goto out;
}
wpa_printf(MSG_DEBUG, "NET added: %d", resp.network_id);
if (mode_ap) {
if (!wpa_cli_cmd_v("set_network %d mode 2", resp.network_id)) {
goto out;
}
}
if (!wpa_cli_cmd_v("set_network %d ssid \"%s\"",
resp.network_id, params->ssid)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d scan_ssid 1", resp.network_id)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d key_mgmt NONE", resp.network_id)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d ieee80211w 0", resp.network_id)) {
goto out;
}
if (params->band != WIFI_FREQ_BAND_UNKNOWN) {
ret = wpa_supp_supported_channels(wpa_s, params->band, &chan_list);
if (ret < 0) {
goto rem_net;
}
if (chan_list) {
if (!wpa_cli_cmd_v("set_network %d scan_freq%s", resp.network_id,
chan_list)) {
k_free(chan_list);
goto out;
}
k_free(chan_list);
}
}
if (params->security != WIFI_SECURITY_TYPE_NONE) {
/* SAP - only open and WPA2-PSK are supported for now */
if (mode_ap && params->security != WIFI_SECURITY_TYPE_PSK) {
ret = -1;
wpa_printf(MSG_ERROR, "Unsupported security type: %d",
params->security);
goto rem_net;
}
/* Except for WPA-PSK, rest all are under WPA2 */
if (params->security != WIFI_SECURITY_TYPE_WPA_PSK) {
if (!wpa_cli_cmd_v("set_network %d proto RSN",
resp.network_id)) {
goto out;
}
}
if (params->security == WIFI_SECURITY_TYPE_SAE_HNP ||
params->security == WIFI_SECURITY_TYPE_SAE_H2E ||
params->security == WIFI_SECURITY_TYPE_SAE_AUTO) {
if (params->sae_password) {
if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"",
resp.network_id, params->sae_password)) {
goto out;
}
} else {
if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"",
resp.network_id, params->psk)) {
goto out;
}
}
if (params->security == WIFI_SECURITY_TYPE_SAE_H2E ||
params->security == WIFI_SECURITY_TYPE_SAE_AUTO) {
if (!wpa_cli_cmd_v("set sae_pwe %d",
(params->security == WIFI_SECURITY_TYPE_SAE_H2E)
? 1
: 2)) {
goto out;
}
}
if (!wpa_cli_cmd_v("set_network %d key_mgmt SAE", resp.network_id)) {
goto out;
}
} else if (params->security == WIFI_SECURITY_TYPE_PSK_SHA256) {
if (!wpa_cli_cmd_v("set_network %d psk \"%s\"",
resp.network_id, params->psk)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-PSK-SHA256",
resp.network_id)) {
goto out;
}
} else if (params->security == WIFI_SECURITY_TYPE_PSK ||
params->security == WIFI_SECURITY_TYPE_WPA_PSK) {
if (!wpa_cli_cmd_v("set_network %d psk \"%s\"",
resp.network_id, params->psk)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-PSK",
resp.network_id)) {
goto out;
}
if (params->security == WIFI_SECURITY_TYPE_WPA_PSK) {
if (!wpa_cli_cmd_v("set_network %d proto WPA",
resp.network_id)) {
goto out;
}
}
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
} else if (params->security == WIFI_SECURITY_TYPE_EAP_TLS) {
if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-EAP",
resp.network_id)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d proto RSN",
resp.network_id)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d eap TLS",
resp.network_id)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d anonymous_identity \"%s\"",
resp.network_id, params->anon_id)) {
goto out;
}
if (wpas_config_process_blob(wpa_s->conf, "ca_cert",
enterprise_creds.ca_cert,
enterprise_creds.ca_cert_len)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d ca_cert \"blob://ca_cert\"",
resp.network_id)) {
goto out;
}
if (wpas_config_process_blob(wpa_s->conf, "client_cert",
enterprise_creds.client_cert,
enterprise_creds.client_cert_len)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d client_cert \"blob://client_cert\"",
resp.network_id)) {
goto out;
}
if (wpas_config_process_blob(wpa_s->conf, "private_key",
enterprise_creds.client_key,
enterprise_creds.client_key_len)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d private_key \"blob://private_key\"",
resp.network_id)) {
goto out;
}
if (!wpa_cli_cmd_v("set_network %d private_key_passwd \"%s\"",
resp.network_id, params->key_passwd)) {
goto out;
}
#endif
} else {
ret = -1;
wpa_printf(MSG_ERROR, "Unsupported security type: %d",
params->security);
goto rem_net;
}
if (params->mfp) {
if (!wpa_cli_cmd_v("set_network %d ieee80211w %d",
resp.network_id, params->mfp)) {
goto out;
}
}
}
if (params->channel != WIFI_CHANNEL_ANY) {
int freq;
if (params->band != WIFI_FREQ_BAND_UNKNOWN) {
freq = wpa_supp_band_chan_compat(wpa_s, params->band, params->channel);
if (freq < 0) {
goto rem_net;
}
} else {
freq = chan_to_freq(params->channel);
if (freq < 0) {
ret = -1;
wpa_printf(MSG_ERROR, "Invalid channel %d",
params->channel);
goto rem_net;
}
}
if (mode_ap) {
if (!wpa_cli_cmd_v("set_network %d frequency %d",
resp.network_id, freq)) {
goto out;
}
} else {
if (!wpa_cli_cmd_v("set_network %d scan_freq %d",
resp.network_id, freq)) {
goto out;
}
}
}
memcpy((void *)&mac, params->bssid, WIFI_MAC_ADDR_LEN);
if (net_eth_is_addr_broadcast(&mac) ||
net_eth_is_addr_multicast(&mac)) {
wpa_printf(MSG_ERROR, "Invalid BSSID. Configuration "
"of multicast or broadcast MAC is not allowed.");
ret = -EINVAL;
goto rem_net;
}
if (!net_eth_is_addr_unspecified(&mac)) {
char bssid_str[MAC_STR_LEN] = {0};
snprintf(bssid_str, MAC_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
params->bssid[0], params->bssid[1], params->bssid[2],
params->bssid[3], params->bssid[4], params->bssid[5]);
if (!wpa_cli_cmd_v("set_network %d bssid %s",
resp.network_id, bssid_str)) {
goto out;
}
}
/* enable and select network */
if (!wpa_cli_cmd_v("enable_network %d", resp.network_id)) {
goto out;
}
if (!wpa_cli_cmd_v("select_network %d", resp.network_id)) {
goto out;
}
memset(&last_wifi_conn_params, 0, sizeof(struct wifi_connect_req_params));
memcpy((void *)&last_wifi_conn_params, params, sizeof(struct wifi_connect_req_params));
return 0;
rem_net:
if (!wpa_cli_cmd_v("remove_network %d", resp.network_id)) {
goto out;
}
out:
return ret;
}
static int wpas_disconnect_network(const struct device *dev, int cur_mode)
{
struct net_if *iface = net_if_lookup_by_dev(dev);
struct wpa_supplicant *wpa_s;
bool is_ap = false;
int ret = 0;
if (!iface) {
ret = -ENOENT;
wpa_printf(MSG_ERROR, "Interface for device %s not found", dev->name);
return ret;
}
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -1;
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
goto out;
}
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
if (wpa_s->current_ssid && wpa_s->current_ssid->mode != cur_mode) {
ret = -EBUSY;
wpa_printf(MSG_ERROR, "Interface %s is not in %s mode", dev->name,
cur_mode == WPAS_MODE_INFRA ? "STA" : "AP");
goto out;
}
is_ap = (cur_mode == WPAS_MODE_AP);
wpas_api_ctrl.dev = dev;
wpas_api_ctrl.requested_op = DISCONNECT;
if (!wpa_cli_cmd_v("disconnect")) {
goto out;
}
out:
k_mutex_unlock(&wpa_supplicant_mutex);
if (ret) {
wpa_printf(MSG_ERROR, "Disconnect failed: %s", strerror(-ret));
return ret;
}
wpa_supp_restart_status_work();
ret = wait_for_disconnect_complete(dev);
#ifdef CONFIG_AP
if (is_ap) {
supplicant_send_wifi_mgmt_ap_status(wpa_s,
NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT,
ret == 0 ? WIFI_STATUS_AP_SUCCESS : WIFI_STATUS_AP_FAIL);
} else {
#else
{
#endif /* CONFIG_AP */
wifi_mgmt_raise_disconnect_complete_event(iface, ret);
}
return ret;
}
/* Public API */
int supplicant_connect(const struct device *dev, struct wifi_connect_req_params *params)
{
struct wpa_supplicant *wpa_s;
int ret = 0;
if (!net_if_is_admin_up(net_if_lookup_by_dev(dev))) {
wpa_printf(MSG_ERROR,
"Interface %s is down, dropping connect",
dev->name);
return -1;
}
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -1;
wpa_printf(MSG_ERROR, "Device %s not found", dev->name);
goto out;
}
/* Allow connect in STA mode only even if we are connected already */
if (wpa_s->current_ssid && wpa_s->current_ssid->mode != WPAS_MODE_INFRA) {
ret = -EBUSY;
wpa_printf(MSG_ERROR, "Interface %s is not in STA mode", dev->name);
goto out;
}
ret = wpas_add_and_config_network(wpa_s, params, false);
if (ret) {
wpa_printf(MSG_ERROR, "Failed to add and configure network for STA mode: %d", ret);
goto out;
}
wpas_api_ctrl.dev = dev;
wpas_api_ctrl.requested_op = CONNECT;
wpas_api_ctrl.connection_timeout = params->timeout;
out:
k_mutex_unlock(&wpa_supplicant_mutex);
if (!ret) {
wpa_supp_restart_status_work();
}
return ret;
}
int supplicant_disconnect(const struct device *dev)
{
return wpas_disconnect_network(dev, WPAS_MODE_INFRA);
}
int supplicant_status(const struct device *dev, struct wifi_iface_status *status)
{
struct net_if *iface = net_if_lookup_by_dev(dev);
struct wpa_supplicant *wpa_s;
int ret = -1;
struct wpa_signal_info *si = NULL;
struct wpa_conn_info *conn_info = NULL;
if (!iface) {
ret = -ENOENT;
wpa_printf(MSG_ERROR, "Interface for device %s not found", dev->name);
return ret;
}
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
wpa_printf(MSG_ERROR, "Device %s not found", dev->name);
goto out;
}
si = os_zalloc(sizeof(struct wpa_signal_info));
if (!si) {
wpa_printf(MSG_ERROR, "Failed to allocate memory for signal info");
goto out;
}
status->state = wpa_s->wpa_state; /* 1-1 Mapping */
if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
struct wpa_ssid *ssid = wpa_s->current_ssid;
u8 channel;
struct signal_poll_resp signal_poll;
u8 *_ssid = ssid->ssid;
size_t ssid_len = ssid->ssid_len;
struct status_resp cli_status;
bool is_ap;
int proto;
int key_mgmt;
if (!ssid) {
wpa_printf(MSG_ERROR, "Failed to get current ssid");
goto out;
}
is_ap = ssid->mode == WPAS_MODE_AP;
/* For AP its always the configured one */
proto = is_ap ? ssid->proto : wpa_s->wpa_proto;
key_mgmt = is_ap ? ssid->key_mgmt : wpa_s->key_mgmt;
os_memcpy(status->bssid, wpa_s->bssid, WIFI_MAC_ADDR_LEN);
status->band = wpas_band_to_zephyr(wpas_freq_to_band(wpa_s->assoc_freq));
status->security = wpas_key_mgmt_to_zephyr(key_mgmt, proto);
status->mfp = ssid->ieee80211w; /* Same mapping */
ieee80211_freq_to_chan(wpa_s->assoc_freq, &channel);
status->channel = channel;
if (ssid_len == 0) {
int _res = z_wpa_ctrl_status(&cli_status);
if (_res < 0) {
ssid_len = 0;
} else {
ssid_len = cli_status.ssid_len;
}
_ssid = cli_status.ssid;
}
os_memcpy(status->ssid, _ssid, ssid_len);
status->ssid_len = ssid_len;
status->iface_mode = ssid->mode;
if (wpa_s->connection_set == 1) {
status->link_mode = wpa_s->connection_he ? WIFI_6 :
wpa_s->connection_vht ? WIFI_5 :
wpa_s->connection_ht ? WIFI_4 :
wpa_s->connection_g ? WIFI_3 :
wpa_s->connection_a ? WIFI_2 :
wpa_s->connection_b ? WIFI_1 :
WIFI_0;
} else {
status->link_mode = WIFI_LINK_MODE_UNKNOWN;
}
status->rssi = -WPA_INVALID_NOISE;
if (status->iface_mode == WIFI_MODE_INFRA) {
ret = z_wpa_ctrl_signal_poll(&signal_poll);
if (!ret) {
status->rssi = signal_poll.rssi;
} else {
wpa_printf(MSG_WARNING, "%s:Failed to read RSSI", __func__);
}
}
conn_info = os_zalloc(sizeof(struct wpa_conn_info));
if (!conn_info) {
wpa_printf(MSG_ERROR, "%s:Failed to allocate memory\n",
__func__);
ret = -ENOMEM;
goto out;
}
ret = wpa_drv_get_conn_info(wpa_s, conn_info);
if (!ret) {
status->beacon_interval = conn_info->beacon_interval;
status->dtim_period = conn_info->dtim_period;
status->twt_capable = conn_info->twt_capable;
} else {
wpa_printf(MSG_WARNING, "%s: Failed to get connection info\n",
__func__);
status->beacon_interval = 0;
status->dtim_period = 0;
status->twt_capable = false;
ret = 0;
}
os_free(conn_info);
} else {
ret = 0;
}
out:
os_free(si);
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
/* Below APIs are not natively supported by WPA supplicant, so,
* these are just wrappers around driver offload APIs. But it is
* transparent to the user.
*
* In the future these might be implemented natively by the WPA
* supplicant.
*/
static const struct wifi_mgmt_ops *const get_wifi_mgmt_api(const struct device *dev)
{
struct net_wifi_mgmt_offload *api = (struct net_wifi_mgmt_offload *)dev->api;
return api ? api->wifi_mgmt_api : NULL;
}
int supplicant_get_version(const struct device *dev, struct wifi_version *params)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->get_version) {
wpa_printf(MSG_ERROR, "get_version not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->get_version(dev, params);
}
int supplicant_scan(const struct device *dev, struct wifi_scan_params *params,
scan_result_cb_t cb)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->scan) {
wpa_printf(MSG_ERROR, "Scan not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->scan(dev, params, cb);
}
#ifdef CONFIG_NET_STATISTICS_WIFI
int supplicant_get_stats(const struct device *dev, struct net_stats_wifi *stats)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->get_stats) {
wpa_printf(MSG_ERROR, "Get stats not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->get_stats(dev, stats);
}
#endif /* CONFIG_NET_STATISTICS_WIFI */
int supplicant_pmksa_flush(const struct device *dev)
{
struct wpa_supplicant *wpa_s;
int ret = 0;
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -1;
wpa_printf(MSG_ERROR, "Device %s not found", dev->name);
goto out;
}
if (!wpa_cli_cmd_v("pmksa_flush")) {
ret = -1;
wpa_printf(MSG_ERROR, "pmksa_flush failed");
goto out;
}
out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
int supplicant_set_power_save(const struct device *dev, struct wifi_ps_params *params)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->set_power_save) {
wpa_printf(MSG_ERROR, "Set power save not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->set_power_save(dev, params);
}
int supplicant_set_twt(const struct device *dev, struct wifi_twt_params *params)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->set_twt) {
wpa_printf(MSG_ERROR, "Set TWT not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->set_twt(dev, params);
}
int supplicant_get_power_save_config(const struct device *dev,
struct wifi_ps_config *config)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->get_power_save_config) {
wpa_printf(MSG_ERROR, "Get power save config not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->get_power_save_config(dev, config);
}
int supplicant_reg_domain(const struct device *dev,
struct wifi_reg_domain *reg_domain)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->reg_domain) {
wpa_printf(MSG_ERROR, "Regulatory domain not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->reg_domain(dev, reg_domain);
}
int supplicant_mode(const struct device *dev, struct wifi_mode_info *mode)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->mode) {
wpa_printf(MSG_ERROR, "Setting mode not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->mode(dev, mode);
}
int supplicant_filter(const struct device *dev, struct wifi_filter_info *filter)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->filter) {
wpa_printf(MSG_ERROR, "Setting filter not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->filter(dev, filter);
}
int supplicant_channel(const struct device *dev, struct wifi_channel_info *channel)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
if (!wifi_mgmt_api || !wifi_mgmt_api->channel) {
wpa_printf(MSG_ERROR, "Setting channel not supported");
return -ENOTSUP;
}
return wifi_mgmt_api->channel(dev, channel);
}
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM
int supplicant_btm_query(const struct device *dev, uint8_t reason)
{
struct wpa_supplicant *wpa_s;
int ret = -1;
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -1;
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
goto out;
}
if (!wpa_cli_cmd_v("wnm_bss_query %d", reason)) {
goto out;
}
ret = 0;
out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
#endif
int supplicant_get_wifi_conn_params(const struct device *dev,
struct wifi_connect_req_params *params)
{
struct wpa_supplicant *wpa_s;
int ret = 0;
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -1;
wpa_printf(MSG_ERROR, "Device %s not found", dev->name);
goto out;
}
memcpy(params, &last_wifi_conn_params, sizeof(struct wifi_connect_req_params));
out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
#ifdef CONFIG_AP
int supplicant_ap_enable(const struct device *dev,
struct wifi_connect_req_params *params)
{
struct wpa_supplicant *wpa_s;
int ret;
if (!net_if_is_admin_up(net_if_lookup_by_dev(dev))) {
wpa_printf(MSG_ERROR,
"Interface %s is down, dropping connect",
dev->name);
return -1;
}
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -1;
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
goto out;
}
if (wpa_s->wpa_state != WPA_DISCONNECTED) {
ret = -EBUSY;
wpa_printf(MSG_ERROR, "Interface %s is not in disconnected state", dev->name);
goto out;
}
/* No need to check for existing network to join for SoftAP*/
wpa_s->conf->ap_scan = 2;
ret = wpas_add_and_config_network(wpa_s, params, true);
if (ret) {
wpa_printf(MSG_ERROR, "Failed to add and configure network for AP mode: %d", ret);
goto out;
}
out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
int supplicant_ap_disable(const struct device *dev)
{
struct wpa_supplicant *wpa_s;
int ret = -1;
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -1;
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
goto out;
}
ret = wpas_disconnect_network(dev, WPAS_MODE_AP);
if (ret) {
wpa_printf(MSG_ERROR, "Failed to disconnect from network");
goto out;
}
/* Restore ap_scan to default value */
wpa_s->conf->ap_scan = 1;
out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
int supplicant_ap_sta_disconnect(const struct device *dev,
const uint8_t *mac_addr)
{
struct wpa_supplicant *wpa_s;
int ret = -1;
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -1;
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
goto out;
}
if (!mac_addr) {
ret = -EINVAL;
wpa_printf(MSG_ERROR, "Invalid MAC address");
goto out;
}
if (!wpa_cli_cmd_v("disassociate %02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2],
mac_addr[3], mac_addr[4], mac_addr[5])) {
goto out;
}
ret = 0;
out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
#endif /* CONFIG_AP */
static const char *dpp_params_to_args_curve(int curve)
{
switch (curve) {
case WIFI_DPP_CURVES_P_256:
return "P-256";
case WIFI_DPP_CURVES_P_384:
return "P-384";
case WIFI_DPP_CURVES_P_512:
return "P-521";
case WIFI_DPP_CURVES_BP_256:
return "BP-256";
case WIFI_DPP_CURVES_BP_384:
return "BP-384";
case WIFI_DPP_CURVES_BP_512:
return "BP-512";
default:
return "P-256";
}
}
static const char *dpp_params_to_args_conf(int conf)
{
switch (conf) {
case WIFI_DPP_CONF_STA:
return "sta-dpp";
case WIFI_DPP_CONF_AP:
return "ap-dpp";
case WIFI_DPP_CONF_QUERY:
return "query";
default:
return "sta-dpp";
}
}
static const char *dpp_params_to_args_role(int role)
{
switch (role) {
case WIFI_DPP_ROLE_CONFIGURATOR:
return "configurator";
case WIFI_DPP_ROLE_ENROLLEE:
return "enrollee";
case WIFI_DPP_ROLE_EITHER:
return "either";
default:
return "either";
}
}
static void dpp_ssid_bin2str(char *dst, uint8_t *src, int max_len)
{
uint8_t *end = src + strlen(src);
/* do 4 bytes convert first */
for (; (src + 4) < end; src += 4) {
snprintf(dst, max_len, "%02x%02x%02x%02x",
src[0], src[1], src[2], src[3]);
dst += 8;
}
/* then do 1 byte convert */
for (; src < end; src++) {
snprintf(dst, max_len, "%02x", src[0]);
dst += 2;
}
}
#define SUPPLICANT_DPP_CMD_BUF_SIZE 384
#define STR_CUR_TO_END(cur) (cur) = (&(cur)[0] + strlen((cur)))
int supplicant_dpp_dispatch(const struct device *dev,
struct wifi_dpp_params *params)
{
char *pos;
static char dpp_cmd_buf[SUPPLICANT_DPP_CMD_BUF_SIZE] = {0};
char *end = &dpp_cmd_buf[SUPPLICANT_DPP_CMD_BUF_SIZE - 2];
memset(dpp_cmd_buf, 0x0, SUPPLICANT_DPP_CMD_BUF_SIZE);
pos = &dpp_cmd_buf[0];
switch (params->action) {
case WIFI_DPP_CONFIGURATOR_ADD:
strncpy(pos, "DPP_CONFIGURATOR_ADD", end - pos);
STR_CUR_TO_END(pos);
if (params->configurator_add.curve) {
snprintf(pos, end - pos, " curve=%s",
dpp_params_to_args_curve(params->configurator_add.curve));
STR_CUR_TO_END(pos);
}
if (params->configurator_add.net_access_key_curve) {
snprintf(pos, end - pos, " net_access_key_curve=%s",
dpp_params_to_args_curve(
params->configurator_add.net_access_key_curve));
}
break;
case WIFI_DPP_AUTH_INIT:
strncpy(pos, "DPP_AUTH_INIT", end - pos);
STR_CUR_TO_END(pos);
if (params->auth_init.peer) {
snprintf(pos, end - pos, " peer=%d", params->auth_init.peer);
STR_CUR_TO_END(pos);
}
if (params->auth_init.conf) {
snprintf(pos, end - pos, " conf=%s",
dpp_params_to_args_conf(
params->auth_init.conf));
STR_CUR_TO_END(pos);
}
if (params->auth_init.ssid[0]) {
strncpy(pos, " ssid=", end - pos);
STR_CUR_TO_END(pos);
dpp_ssid_bin2str(pos, params->auth_init.ssid,
WIFI_SSID_MAX_LEN * 2);
STR_CUR_TO_END(pos);
}
if (params->auth_init.configurator) {
snprintf(pos, end - pos, " configurator=%d",
params->auth_init.configurator);
STR_CUR_TO_END(pos);
}
if (params->auth_init.role) {
snprintf(pos, end - pos, " role=%s",
dpp_params_to_args_role(
params->auth_init.role));
}
break;
case WIFI_DPP_QR_CODE:
strncpy(pos, "DPP_QR_CODE", end - pos);
STR_CUR_TO_END(pos);
if (params->dpp_qr_code[0]) {
snprintf(pos, end - pos, " %s", params->dpp_qr_code);
}
break;
case WIFI_DPP_CHIRP:
strncpy(pos, "DPP_CHIRP", end - pos);
STR_CUR_TO_END(pos);
if (params->chirp.id) {
snprintf(pos, end - pos, " own=%d", params->chirp.id);
STR_CUR_TO_END(pos);
}
if (params->chirp.freq) {
snprintf(pos, end - pos, " listen=%d", params->chirp.freq);
}
break;
case WIFI_DPP_LISTEN:
strncpy(pos, "DPP_LISTEN", end - pos);
STR_CUR_TO_END(pos);
if (params->listen.freq) {
snprintf(pos, end - pos, " %d", params->listen.freq);
STR_CUR_TO_END(pos);
}
if (params->listen.role) {
snprintf(pos, end - pos, " role=%s",
dpp_params_to_args_role(
params->listen.role));
}
break;
case WIFI_DPP_BOOTSTRAP_GEN:
strncpy(pos, "DPP_BOOTSTRAP_GEN", end - pos);
STR_CUR_TO_END(pos);
if (params->bootstrap_gen.type) {
strncpy(pos, " type=qrcode", end - pos);
STR_CUR_TO_END(pos);
}
if (params->bootstrap_gen.op_class &&
params->bootstrap_gen.chan) {
snprintf(pos, end - pos, " chan=%d/%d",
params->bootstrap_gen.op_class,
params->bootstrap_gen.chan);
STR_CUR_TO_END(pos);
}
/* mac is mandatory, even if it is zero mac address */
snprintf(pos, end - pos, " mac=%02x:%02x:%02x:%02x:%02x:%02x",
params->bootstrap_gen.mac[0], params->bootstrap_gen.mac[1],
params->bootstrap_gen.mac[2], params->bootstrap_gen.mac[3],
params->bootstrap_gen.mac[4], params->bootstrap_gen.mac[5]);
STR_CUR_TO_END(pos);
if (params->bootstrap_gen.curve) {
snprintf(pos, end - pos, " curve=%s",
dpp_params_to_args_curve(params->bootstrap_gen.curve));
}
break;
case WIFI_DPP_BOOTSTRAP_GET_URI:
snprintf(pos, end - pos, "DPP_BOOTSTRAP_GET_URI %d", params->id);
break;
case WIFI_DPP_SET_CONF_PARAM:
strncpy(pos, "SET dpp_configurator_params", end - pos);
STR_CUR_TO_END(pos);
if (params->configurator_set.peer) {
snprintf(pos, end - pos, " peer=%d", params->configurator_set.peer);
STR_CUR_TO_END(pos);
}
if (params->configurator_set.conf) {
snprintf(pos, end - pos, " conf=%s",
dpp_params_to_args_conf(
params->configurator_set.conf));
STR_CUR_TO_END(pos);
}
if (params->configurator_set.ssid[0]) {
strncpy(pos, " ssid=", end - pos);
STR_CUR_TO_END(pos);
dpp_ssid_bin2str(pos, params->configurator_set.ssid,
WIFI_SSID_MAX_LEN * 2);
STR_CUR_TO_END(pos);
}
if (params->configurator_set.configurator) {
snprintf(pos, end - pos, " configurator=%d",
params->configurator_set.configurator);
STR_CUR_TO_END(pos);
}
if (params->configurator_set.role) {
snprintf(pos, end - pos, " role=%s",
dpp_params_to_args_role(
params->configurator_set.role));
STR_CUR_TO_END(pos);
}
if (params->configurator_set.curve) {
snprintf(pos, end - pos, " curve=%s",
dpp_params_to_args_curve(params->configurator_set.curve));
STR_CUR_TO_END(pos);
}
if (params->configurator_set.net_access_key_curve) {
snprintf(pos, end - pos, " net_access_key_curve=%s",
dpp_params_to_args_curve(
params->configurator_set.net_access_key_curve));
}
break;
case WIFI_DPP_SET_WAIT_RESP_TIME:
snprintf(pos, end - pos, "SET dpp_resp_wait_time %d",
params->dpp_resp_wait_time);
break;
default:
wpa_printf(MSG_ERROR, "Unknown DPP action");
return -1;
}
wpa_printf(MSG_DEBUG, "%s", dpp_cmd_buf);
if (zephyr_wpa_cli_cmd_resp(dpp_cmd_buf, params->resp)) {
return -1;
}
return 0;
}
``` | /content/code_sandbox/modules/hostap/src/supp_api.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 10,587 |
```c
/*
*
*/
/* @file
* @brief wpa_cli implementation for Zephyr OS
*/
#include <zephyr/kernel.h>
#include <zephyr/shell/shell.h>
#include <zephyr/init.h>
#include "wpa_cli_zephyr.h"
static int cmd_wpa_cli(const struct shell *sh,
size_t argc,
const char *argv[])
{
ARG_UNUSED(sh);
if (argc == 1) {
shell_error(sh, "Missing argument");
return -EINVAL;
}
argv[argc] = "interactive";
argc++;
/* Remove wpa_cli from the argument list */
return zephyr_wpa_ctrl_zephyr_cmd(argc - 1, &argv[1]);
}
/* Persisting with "wpa_cli" naming for compatibility with Wi-Fi
* certification applications and scripts.
*/
SHELL_CMD_REGISTER(wpa_cli,
NULL,
"wpa_cli commands (only for internal use)",
cmd_wpa_cli);
``` | /content/code_sandbox/modules/hostap/src/wpa_cli.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 210 |
```unknown
config ZEPHYR_CMSIS_NN_MODULE
bool
menuconfig CMSIS_NN
bool "CMSIS-NN Library Support"
depends on CPU_CORTEX_M
select CMSIS_DSP
help
This option enables the CMSIS-NN library.
if CMSIS_NN
config CMSIS_NN_ACTIVATION
bool "Activation"
help
This option enables the NN libraries for the activation layers
It can perform activation layers, including ReLU (Rectified
Linear Unit), sigmoid, and tanh.
config CMSIS_NN_BASICMATH
bool "Basic Math for NN"
help
This option enables the NN libraries for the basic maths operations.
It adds functionality for element-wise add and multiplication functions.
config CMSIS_NN_CONCATENATION
bool "Concatenation"
help
This option enables the NN libraries for the concatenation layers.
config CMSIS_NN_CONVOLUTION
bool "Convolution"
imply CMSIS_NN_NNSUPPORT
help
Collection of convolution, depthwise convolution functions and
their variants. The convolution is implemented in 2 steps: im2col
and GEMM. GEMM is performed with CMSIS-DSP arm_mat_mult similar options.
config CMSIS_NN_FULLYCONNECTED
bool "Fully Connected"
imply CMSIS_NN_NNSUPPORT
help
Collection of fully-connected and matrix multiplication functions.
config CMSIS_NN_NNSUPPORT
bool "NN Support"
help
When off, its default behavior is all tables are included.
config CMSIS_NN_POOLING
bool "Pooling"
imply CMSIS_NN_NNSUPPORT
help
This option enables pooling layers, including max pooling,
and average pooling.
config CMSIS_NN_RESHAPE
bool "Reshape"
help
This option enables the NN libraries for the reshape layers.
config CMSIS_NN_SOFTMAX
bool "Softmax"
help
This option enables the NN libraries for the softmax layers (exp2 based).
config CMSIS_NN_SVD
bool "SVD"
imply CMSIS_NN_NNSUPPORT
help
This option enabled the NN libraries for Single Value Decomposition Filter layers.
config CMSIS_NN_LSTM
bool "Long Short-Term Memory"
help
This option enables the NN libraries for Long Short-Term Memory.
endif #CMSIS_NN
``` | /content/code_sandbox/modules/cmsis-nn/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 507 |
```unknown
config ZEPHYR_HAL_INFINEON_MODULE
bool
if SOC_FAMILY_INFINEON_CAT1 || SOC_FAMILY_PSOC6_LEGACY
config USE_INFINEON_ADC
bool
help
Enable Analog-to-Digital Converter (ADC) HAL module driver for Infineon devices
config USE_INFINEON_I2C
bool
help
Enable Inter-Integrated Circuit Interface (I2C) HAL module driver for Infineon devices
config USE_INFINEON_RTC
bool
help
Enable Real-Time Clock (RTC) HAL module driver for Infineon devices
config USE_INFINEON_SDIO
bool
help
Enable Secure Digital Input/Output interface (SDIO) HAL module for Infineon devices
driver
config USE_INFINEON_SDHC
bool
help
Enable SDHC HAL module for Infineon devices
driver
config USE_INFINEON_SPI
bool
help
Enable Serial Peripheral Interface (SPI) HAL module driver for Infineon devices
config USE_INFINEON_TIMER
bool
help
Enable Timer (Timer/Counter) HAL module driver for Infineon devices
config USE_INFINEON_LPTIMER
bool
help
Enable Low-Power Timer (LPTimer) HAL module driver for Infineon devices
config USE_INFINEON_TRNG
bool
help
Enable True Random Number Generator (TRNG) HAL module driver for Infineon devices
config USE_INFINEON_UART
bool
help
Enable Universal Asynchronous Receiver/Transmitter (UART) HAL module
driver for Infineon devices
config USE_INFINEON_PWM
bool
help
Enable Pulse Width Modulator (PWM) HAL module
driver for Infineon devices
config USE_INFINEON_WDT
bool
help
Enable WATCHDOG TIMER (WDT) HAL module
driver for Infineon devices
config USE_INFINEON_FLASH
bool
help
Enable Flash HAL module driver for Infineon devices
config USE_INFINEON_ABSTRACTION_RTOS
bool "Abstraction RTOS component (Zephyr support)"
help
Enable Abstraction RTOS component with Zephyr support
config USE_INFINEON_SMIF
bool
help
Enable SMIF HAL driver for Infineon devices
endif # SOC_FAMILY_INFINEON_CAT1 || SOC_FAMILY_PSOC6_LEGACY
``` | /content/code_sandbox/modules/hal_infineon/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 508 |
```c
/*
*
*/
#include <stdint.h>
const uint8_t brcm_patchram_format = 0x01;
/* Configuration Data Records (Write_RAM) */
#ifndef FW_DATBLOCK_SEPARATE_FROM_APPLICATION
const uint8_t brcm_patchram_buf[] = {
#include <bt_firmware.hcd.inc>
};
const int brcm_patch_ram_length = sizeof(brcm_patchram_buf);
#endif /* FW_DATBLOCK_SEPARATE_FROM_APPLICATION */
``` | /content/code_sandbox/modules/hal_infineon/btstack-integration/w_bt_firmware_controller.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 97 |
```c
/***********************************************************************************************//**
* \file cyabs_rtos_zephyr.c
*
* \brief
* Implementation for Zephyr RTOS abstraction
*
***************************************************************************************************
* \copyright
* an affiliate of Cypress Semiconductor Corporation
*
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**************************************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <cy_utils.h>
#include <cyabs_rtos.h>
#if defined(__cplusplus)
extern "C" {
#endif
/*
* Error Converter
*/
/* Last received error status */
static cy_rtos_error_t dbgErr;
cy_rtos_error_t cy_rtos_last_error(void)
{
return dbgErr;
}
/* Converts internal error type to external error type */
static cy_rslt_t error_converter(cy_rtos_error_t internalError)
{
cy_rslt_t value;
switch (internalError) {
case 0:
value = CY_RSLT_SUCCESS;
break;
case -EAGAIN:
value = CY_RTOS_TIMEOUT;
break;
case -EINVAL:
value = CY_RTOS_BAD_PARAM;
break;
case -ENOMEM:
value = CY_RTOS_NO_MEMORY;
break;
default:
value = CY_RTOS_GENERAL_ERROR;
break;
}
/* Update the last known error status */
dbgErr = internalError;
return value;
}
static void free_thead_obj(cy_thread_t *thread)
{
/* Free allocated stack buffer */
if ((*thread)->memptr != NULL) {
k_free((*thread)->memptr);
}
/* Free object */
k_free(*thread);
}
/*
* Threads
*/
static void thread_entry_function_wrapper(void *p1, void *p2, void *p3)
{
CY_UNUSED_PARAMETER(p3);
((cy_thread_entry_fn_t)p2)(p1);
}
cy_rslt_t cy_rtos_create_thread(cy_thread_t *thread, cy_thread_entry_fn_t entry_function,
const char *name, void *stack, uint32_t stack_size,
cy_thread_priority_t priority, cy_thread_arg_t arg)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
cy_rtos_error_t status_internal = 0;
if ((thread == NULL) || (stack_size < CY_RTOS_MIN_STACK_SIZE)) {
status = CY_RTOS_BAD_PARAM;
} else if ((stack != NULL) && (0 != (((uint32_t)stack) & CY_RTOS_ALIGNMENT_MASK))) {
status = CY_RTOS_ALIGNMENT_ERROR;
} else {
void *stack_alloc = NULL;
k_tid_t my_tid = NULL;
/* Allocate cy_thread_t object */
*thread = k_malloc(sizeof(k_thread_wrapper_t));
/* Allocate stack if NULL was passed */
if ((uint32_t *)stack == NULL) {
stack_alloc = k_aligned_alloc(Z_KERNEL_STACK_OBJ_ALIGN,
K_KERNEL_STACK_LEN(stack_size));
/* Store pointer to allocated stack,
* NULL if not allocated by cy_rtos_thread_create (passed by application).
*/
(*thread)->memptr = stack_alloc;
} else {
stack_alloc = stack;
(*thread)->memptr = NULL;
}
if (stack_alloc == NULL) {
status = CY_RTOS_NO_MEMORY;
} else {
/* Create thread */
my_tid = k_thread_create(&(*thread)->z_thread, stack_alloc, stack_size,
thread_entry_function_wrapper,
(cy_thread_arg_t)arg, (void *)entry_function, NULL,
priority, 0, K_NO_WAIT);
/* Set thread name */
status_internal = k_thread_name_set(my_tid, name);
/* NOTE: k_thread_name_set returns -ENOSYS if thread name
* configuration option not enabled.
*/
}
if ((my_tid == NULL) || ((status_internal != 0) && (status_internal != -ENOSYS))) {
status = CY_RTOS_GENERAL_ERROR;
/* Free allocated thread object and stack buffer */
free_thead_obj(thread);
}
}
return status;
}
cy_rslt_t cy_rtos_exit_thread(void)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (k_is_in_isr()) {
status = CY_RTOS_GENERAL_ERROR;
} else {
cy_thread_t thread = (cy_thread_t)k_current_get();
/* Abort thread */
k_thread_abort((k_tid_t)&(thread)->z_thread);
CODE_UNREACHABLE;
}
return status;
}
cy_rslt_t cy_rtos_terminate_thread(cy_thread_t *thread)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (thread == NULL) {
status = CY_RTOS_BAD_PARAM;
} else if (k_is_in_isr()) {
status = CY_RTOS_GENERAL_ERROR;
} else {
/* Abort thread */
k_thread_abort((k_tid_t)&(*thread)->z_thread);
/* Free allocated stack buffer */
if ((*thread)->memptr != NULL) {
k_free((*thread)->memptr);
}
}
return status;
}
cy_rslt_t cy_rtos_is_thread_running(cy_thread_t *thread, bool *running)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if ((thread == NULL) || (running == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
*running = (k_current_get() == &(*thread)->z_thread) ? true : false;
}
return status;
}
cy_rslt_t cy_rtos_get_thread_state(cy_thread_t *thread, cy_thread_state_t *state)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if ((thread == NULL) || (state == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
if (k_is_in_isr()) {
*state = CY_THREAD_STATE_UNKNOWN;
} else if (k_current_get() == &(*thread)->z_thread) {
*state = CY_THREAD_STATE_RUNNING;
}
if (((*thread)->z_thread.base.thread_state & _THREAD_DEAD) != 0) {
*state = CY_THREAD_STATE_TERMINATED;
} else {
switch ((*thread)->z_thread.base.thread_state) {
case _THREAD_DUMMY:
*state = CY_THREAD_STATE_UNKNOWN;
break;
case _THREAD_PRESTART:
*state = CY_THREAD_STATE_INACTIVE;
break;
case _THREAD_SUSPENDED:
case _THREAD_PENDING:
*state = CY_THREAD_STATE_BLOCKED;
break;
case _THREAD_QUEUED:
*state = CY_THREAD_STATE_READY;
break;
default:
*state = CY_THREAD_STATE_UNKNOWN;
break;
}
}
}
return status;
}
cy_rslt_t cy_rtos_join_thread(cy_thread_t *thread)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
cy_rtos_error_t status_internal;
if (thread == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
if (*thread != NULL) {
/* Sleep until a thread exits */
status_internal = k_thread_join(&(*thread)->z_thread, K_FOREVER);
status = error_converter(status_internal);
if (status == CY_RSLT_SUCCESS) {
/* Free allocated thread object and stack buffer */
free_thead_obj(thread);
}
}
}
return status;
}
cy_rslt_t cy_rtos_get_thread_handle(cy_thread_t *thread)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (thread == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
*thread = (cy_thread_t)k_current_get();
}
return status;
}
cy_rslt_t cy_rtos_wait_thread_notification(cy_time_t timeout_ms)
{
cy_rtos_error_t status_internal;
cy_rslt_t status = CY_RSLT_SUCCESS;
if (timeout_ms == CY_RTOS_NEVER_TIMEOUT) {
status_internal = k_sleep(K_FOREVER);
} else {
status_internal = k_msleep((int32_t)timeout_ms);
if (status_internal == 0) {
status = CY_RTOS_TIMEOUT;
}
}
if ((status_internal < 0) && (status_internal != K_TICKS_FOREVER)) {
status = error_converter(status_internal);
}
return status;
}
cy_rslt_t cy_rtos_thread_set_notification(cy_thread_t *thread, bool in_isr)
{
CY_UNUSED_PARAMETER(in_isr);
cy_rslt_t status = CY_RSLT_SUCCESS;
if (thread == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
k_wakeup(&(*thread)->z_thread);
}
return status;
}
/*
* Mutexes
*/
cy_rslt_t cy_rtos_init_mutex2(cy_mutex_t *mutex, bool recursive)
{
cy_rtos_error_t status_internal;
cy_rslt_t status;
/* Non recursive mutex is not supported by Zephyr */
CY_UNUSED_PARAMETER(recursive);
if (mutex == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Initialize a mutex object */
status_internal = k_mutex_init(mutex);
status = error_converter(status_internal);
}
return status;
}
cy_rslt_t cy_rtos_get_mutex(cy_mutex_t *mutex, cy_time_t timeout_ms)
{
cy_rtos_error_t status_internal;
cy_rslt_t status;
if (mutex == NULL) {
status = CY_RTOS_BAD_PARAM;
} else if (k_is_in_isr()) {
/* Mutexes may not be locked in ISRs */
status = CY_RTOS_GENERAL_ERROR;
} else {
/* Convert timeout value */
k_timeout_t k_timeout =
(timeout_ms == CY_RTOS_NEVER_TIMEOUT) ? K_FOREVER : K_MSEC(timeout_ms);
/* Lock a mutex */
status_internal = k_mutex_lock(mutex, k_timeout);
status = error_converter(status_internal);
}
return status;
}
cy_rslt_t cy_rtos_set_mutex(cy_mutex_t *mutex)
{
cy_rtos_error_t status_internal;
cy_rslt_t status;
if (mutex == NULL) {
status = CY_RTOS_BAD_PARAM;
} else if (k_is_in_isr()) {
/* Mutexes may not be unlocked in ISRs */
status = CY_RTOS_GENERAL_ERROR;
} else {
/* Unlock a mutex */
status_internal = k_mutex_unlock(mutex);
status = error_converter(status_internal);
}
return status;
}
cy_rslt_t cy_rtos_deinit_mutex(cy_mutex_t *mutex)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (mutex == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Force unlock mutex, do not care about return */
(void)k_mutex_unlock(mutex);
}
return status;
}
/*
* Semaphores
*/
cy_rslt_t cy_rtos_init_semaphore(cy_semaphore_t *semaphore, uint32_t maxcount, uint32_t initcount)
{
cy_rtos_error_t status_internal;
cy_rslt_t status;
if (semaphore == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Initialize a semaphore object */
status_internal = k_sem_init(semaphore, initcount, maxcount);
status = error_converter(status_internal);
}
return status;
}
cy_rslt_t cy_rtos_get_semaphore(cy_semaphore_t *semaphore, cy_time_t timeout_ms, bool in_isr)
{
CY_UNUSED_PARAMETER(in_isr);
cy_rtos_error_t status_internal;
cy_rslt_t status;
if (semaphore == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Convert timeout value */
k_timeout_t k_timeout;
if (k_is_in_isr()) {
/* NOTE: Based on Zephyr documentation when k_sem_take
* is called from ISR timeout must be set to K_NO_WAIT.
*/
k_timeout = K_NO_WAIT;
} else if (timeout_ms == CY_RTOS_NEVER_TIMEOUT) {
k_timeout = K_FOREVER;
} else {
k_timeout = K_MSEC(timeout_ms);
}
/* Take a semaphore */
status_internal = k_sem_take(semaphore, k_timeout);
status = error_converter(status_internal);
if (k_is_in_isr() && (status_internal == -EBUSY)) {
status = CY_RSLT_SUCCESS;
}
}
return status;
}
cy_rslt_t cy_rtos_set_semaphore(cy_semaphore_t *semaphore, bool in_isr)
{
CY_UNUSED_PARAMETER(in_isr);
cy_rslt_t status = CY_RSLT_SUCCESS;
if (semaphore == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Give a semaphore */
k_sem_give(semaphore);
}
return status;
}
cy_rslt_t cy_rtos_get_count_semaphore(cy_semaphore_t *semaphore, size_t *count)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if ((semaphore == NULL) || (count == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
*count = k_sem_count_get(semaphore);
}
return status;
}
cy_rslt_t cy_rtos_deinit_semaphore(cy_semaphore_t *semaphore)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (semaphore == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
k_sem_reset(semaphore);
}
return status;
}
/*
* Events
*/
cy_rslt_t cy_rtos_init_event(cy_event_t *event)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (event == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Initialize an event object */
k_event_init(event);
}
return status;
}
cy_rslt_t cy_rtos_setbits_event(cy_event_t *event, uint32_t bits, bool in_isr)
{
CY_UNUSED_PARAMETER(in_isr);
cy_rslt_t status = CY_RSLT_SUCCESS;
if (event == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Post the new bits */
k_event_post(event, bits);
}
return status;
}
cy_rslt_t cy_rtos_clearbits_event(cy_event_t *event, uint32_t bits, bool in_isr)
{
CY_UNUSED_PARAMETER(in_isr);
cy_rslt_t status = CY_RSLT_SUCCESS;
if (event == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
uint32_t current_bits;
/* Reads events value */
status = cy_rtos_getbits_event(event, ¤t_bits);
/* Set masked value */
k_event_set(event, (~bits & current_bits));
}
return status;
}
cy_rslt_t cy_rtos_getbits_event(cy_event_t *event, uint32_t *bits)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if ((event == NULL) || (bits == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
/* NOTE: Zephyr does not provide function for get bits,
* retrieve it from event object.
*/
*bits = event->events;
}
return status;
}
cy_rslt_t cy_rtos_waitbits_event(cy_event_t *event, uint32_t *bits, bool clear, bool all,
cy_time_t timeout)
{
cy_rslt_t status;
if ((event == NULL) || (bits == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
uint32_t wait_for = *bits;
k_timeout_t k_timeout =
(timeout == CY_RTOS_NEVER_TIMEOUT) ? K_FOREVER : K_MSEC(timeout);
if (all) {
/* Wait for all of the specified events */
*bits = k_event_wait_all(event, wait_for, false, k_timeout);
} else {
/* Wait for any of the specified events */
*bits = k_event_wait(event, wait_for, false, k_timeout);
}
/* Check timeout */
status = (*bits == 0) ? CY_RTOS_TIMEOUT : CY_RSLT_SUCCESS;
/* Return full current events */
cy_rtos_getbits_event(event, bits);
/* Crear bits if required */
if ((status == CY_RSLT_SUCCESS) && (clear == true)) {
cy_rtos_clearbits_event(event, wait_for, false);
}
}
return status;
}
cy_rslt_t cy_rtos_deinit_event(cy_event_t *event)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (event != NULL) {
/* Clear event */
k_event_set(event, 0);
} else {
status = CY_RTOS_BAD_PARAM;
}
return status;
}
/*
* Queues
*/
cy_rslt_t cy_rtos_init_queue(cy_queue_t *queue, size_t length, size_t itemsize)
{
cy_rtos_error_t status_internal;
cy_rslt_t status;
if (queue == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Initialize a message queue */
status_internal = k_msgq_alloc_init(queue, itemsize, length);
status = error_converter(status_internal);
}
return status;
}
cy_rslt_t cy_rtos_put_queue(cy_queue_t *queue, const void *item_ptr, cy_time_t timeout_ms,
bool in_isr)
{
CY_UNUSED_PARAMETER(in_isr);
cy_rtos_error_t status_internal;
cy_rslt_t status;
if ((queue == NULL) || (item_ptr == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Convert timeout value */
k_timeout_t k_timeout;
if (k_is_in_isr()) {
k_timeout = K_NO_WAIT;
} else if (timeout_ms == CY_RTOS_NEVER_TIMEOUT) {
k_timeout = K_FOREVER;
} else {
k_timeout = K_MSEC(timeout_ms);
}
/* Send a message to a message queue */
status_internal = k_msgq_put(queue, item_ptr, k_timeout);
status = error_converter(status_internal);
}
return status;
}
cy_rslt_t cy_rtos_get_queue(cy_queue_t *queue, void *item_ptr, cy_time_t timeout_ms, bool in_isr)
{
CY_UNUSED_PARAMETER(in_isr);
cy_rtos_error_t status_internal;
cy_rslt_t status;
if ((queue == NULL) || (item_ptr == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Convert timeout value */
k_timeout_t k_timeout;
if (k_is_in_isr()) {
k_timeout = K_NO_WAIT;
} else if (timeout_ms == CY_RTOS_NEVER_TIMEOUT) {
k_timeout = K_FOREVER;
} else {
k_timeout = K_MSEC(timeout_ms);
}
/* Receive a message from a message queue */
status_internal = k_msgq_get(queue, item_ptr, k_timeout);
status = error_converter(status_internal);
}
return status;
}
cy_rslt_t cy_rtos_count_queue(cy_queue_t *queue, size_t *num_waiting)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if ((queue == NULL) || (num_waiting == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Get the number of messages in a message queue */
*num_waiting = k_msgq_num_used_get(queue);
}
return status;
}
cy_rslt_t cy_rtos_space_queue(cy_queue_t *queue, size_t *num_spaces)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if ((queue == NULL) || (num_spaces == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Get the amount of free space in a message queue */
*num_spaces = k_msgq_num_free_get(queue);
}
return status;
}
cy_rslt_t cy_rtos_reset_queue(cy_queue_t *queue)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (queue == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Reset a message queue */
k_msgq_purge(queue);
}
return status;
}
cy_rslt_t cy_rtos_deinit_queue(cy_queue_t *queue)
{
cy_rtos_error_t status_internal;
cy_rslt_t status;
if (queue == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Reset a message queue */
status = cy_rtos_reset_queue(queue);
if (status == CY_RSLT_SUCCESS) {
/* Release allocated buffer for a queue */
status_internal = k_msgq_cleanup(queue);
status = error_converter(status_internal);
}
}
return status;
}
/*
* Timers
*/
static void zephyr_timer_event_handler(struct k_timer *timer)
{
cy_timer_t *_timer = (cy_timer_t *)timer;
((cy_timer_callback_t)_timer->callback_function)(
(cy_timer_callback_arg_t)_timer->arg);
}
cy_rslt_t cy_rtos_init_timer(cy_timer_t *timer, cy_timer_trigger_type_t type,
cy_timer_callback_t fun, cy_timer_callback_arg_t arg)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if ((timer == NULL) || (fun == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
timer->callback_function = (void *)fun;
timer->trigger_type = (uint32_t)type;
timer->arg = (void *)arg;
k_timer_init(&timer->z_timer, zephyr_timer_event_handler, NULL);
}
return status;
}
cy_rslt_t cy_rtos_start_timer(cy_timer_t *timer, cy_time_t num_ms)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (timer == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
if ((cy_timer_trigger_type_t)timer->trigger_type == CY_TIMER_TYPE_ONCE) {
/* Called once only */
k_timer_start(&timer->z_timer, K_MSEC(num_ms), K_NO_WAIT);
} else {
/* Called periodically until stopped */
k_timer_start(&timer->z_timer, K_MSEC(num_ms), K_MSEC(num_ms));
}
}
return status;
}
cy_rslt_t cy_rtos_stop_timer(cy_timer_t *timer)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (timer == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Stop timer */
k_timer_stop(&timer->z_timer);
}
return status;
}
cy_rslt_t cy_rtos_is_running_timer(cy_timer_t *timer, bool *state)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if ((timer == NULL) || (state == NULL)) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Check if running */
*state = (k_timer_remaining_get(&timer->z_timer) != 0u);
}
return status;
}
cy_rslt_t cy_rtos_deinit_timer(cy_timer_t *timer)
{
cy_rslt_t status;
if (timer == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
bool running;
/* Get current timer state */
status = cy_rtos_is_running_timer(timer, &running);
/* Check if running */
if ((status == CY_RSLT_SUCCESS) && (running)) {
/* Stop timer */
status = cy_rtos_stop_timer(timer);
}
}
return status;
}
/*
* Time
*/
cy_rslt_t cy_rtos_get_time(cy_time_t *tval)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (tval == NULL) {
status = CY_RTOS_BAD_PARAM;
} else {
/* Get system uptime (32-bit version) */
*tval = k_uptime_get_32();
}
return status;
}
cy_rslt_t cy_rtos_delay_milliseconds(cy_time_t num_ms)
{
cy_rslt_t status = CY_RSLT_SUCCESS;
if (k_is_in_isr()) {
status = CY_RTOS_GENERAL_ERROR;
} else {
k_msleep(num_ms);
}
return status;
}
#if defined(__cplusplus)
}
#endif
``` | /content/code_sandbox/modules/hal_infineon/abstraction-rtos/source/COMPONENT_ZEPHYR/cyabs_rtos_zephyr.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 5,408 |
```c
/*
*
*/
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(wifi_supplicant, CONFIG_WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL);
#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include <poll.h>
#if !defined(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE) && !defined(CONFIG_MBEDTLS_ENABLE_HEAP)
#include <mbedtls/platform.h>
#endif /* !CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE && !CONFIG_MBEDTLS_ENABLE_HEAP */
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_MBEDTLS_PSA
#include "supp_psa_api.h"
#endif
#include <zephyr/net/wifi_mgmt.h>
#include <zephyr/net/wifi_nm.h>
#include <zephyr/net/socket.h>
static K_THREAD_STACK_DEFINE(supplicant_thread_stack,
CONFIG_WIFI_NM_WPA_SUPPLICANT_THREAD_STACK_SIZE);
static struct k_thread tid;
static K_THREAD_STACK_DEFINE(iface_wq_stack, CONFIG_WIFI_NM_WPA_SUPPLICANT_WQ_STACK_SIZE);
#define IFACE_NOTIFY_TIMEOUT_MS 1000
#define IFACE_NOTIFY_RETRY_MS 10
#include "supp_main.h"
#include "supp_api.h"
#include "supp_events.h"
#include "includes.h"
#include "common.h"
#include "eloop.h"
#include "wpa_supplicant/config.h"
#include "wpa_supplicant_i.h"
#include "fst/fst.h"
#include "includes.h"
#include "wpa_cli_zephyr.h"
static const struct wifi_mgmt_ops mgmt_ops = {
.get_version = supplicant_get_version,
.scan = supplicant_scan,
.connect = supplicant_connect,
.disconnect = supplicant_disconnect,
.iface_status = supplicant_status,
#ifdef CONFIG_NET_STATISTICS_WIFI
.get_stats = supplicant_get_stats,
#endif
.set_power_save = supplicant_set_power_save,
.set_twt = supplicant_set_twt,
.get_power_save_config = supplicant_get_power_save_config,
.reg_domain = supplicant_reg_domain,
.mode = supplicant_mode,
.filter = supplicant_filter,
.channel = supplicant_channel,
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM
.btm_query = supplicant_btm_query,
#endif
.get_conn_params = supplicant_get_wifi_conn_params,
#ifdef CONFIG_AP
.ap_enable = supplicant_ap_enable,
.ap_disable = supplicant_ap_disable,
.ap_sta_disconnect = supplicant_ap_sta_disconnect,
#endif /* CONFIG_AP */
.dpp_dispatch = supplicant_dpp_dispatch,
.pmksa_flush = supplicant_pmksa_flush,
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
.enterprise_creds = supplicant_add_enterprise_creds,
#endif
};
DEFINE_WIFI_NM_INSTANCE(wifi_supplicant, &mgmt_ops);
#define WRITE_TIMEOUT 100 /* ms */
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON
#define INTERFACE_EVENT_MASK (NET_EVENT_IF_ADMIN_UP | NET_EVENT_IF_ADMIN_DOWN)
#endif
struct supplicant_context {
struct wpa_global *supplicant;
struct net_mgmt_event_callback cb;
struct net_if *iface;
char if_name[CONFIG_NET_INTERFACE_NAME_LEN + 1];
int event_socketpair[2];
struct k_work iface_work;
struct k_work_q iface_wq;
int (*iface_handler)(struct supplicant_context *ctx, struct net_if *iface);
};
static struct supplicant_context *get_default_context(void)
{
static struct supplicant_context ctx;
return &ctx;
}
struct wpa_global *zephyr_get_default_supplicant_context(void)
{
return get_default_context()->supplicant;
}
struct k_work_q *get_workq(void)
{
return &get_default_context()->iface_wq;
}
int zephyr_wifi_send_event(const struct wpa_supplicant_event_msg *msg)
{
struct supplicant_context *ctx;
struct pollfd fds[1];
int ret;
/* TODO: Fix this to get the correct container */
ctx = get_default_context();
if (ctx->event_socketpair[1] < 0) {
ret = -ENOENT;
goto out;
}
fds[0].fd = ctx->event_socketpair[0];
fds[0].events = POLLOUT;
fds[0].revents = 0;
ret = zsock_poll(fds, 1, WRITE_TIMEOUT);
if (ret < 0) {
ret = -errno;
LOG_ERR("Cannot write event (%d)", ret);
goto out;
}
ret = zsock_send(ctx->event_socketpair[1], msg, sizeof(*msg), 0);
if (ret < 0) {
ret = -errno;
LOG_WRN("Event send failed (%d)", ret);
goto out;
}
if (ret != sizeof(*msg)) {
ret = -EMSGSIZE;
LOG_WRN("Event partial send (%d)", ret);
goto out;
}
ret = 0;
out:
return ret;
}
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON
static int send_event(const struct wpa_supplicant_event_msg *msg)
{
return zephyr_wifi_send_event(msg);
}
static bool is_wanted_interface(struct net_if *iface)
{
if (!net_if_is_wifi(iface)) {
return false;
}
/* TODO: check against a list of valid interfaces */
return true;
}
#endif
struct wpa_supplicant *zephyr_get_handle_by_ifname(const char *ifname)
{
struct wpa_supplicant *wpa_s = NULL;
struct supplicant_context *ctx = get_default_context();
wpa_s = wpa_supplicant_get_iface(ctx->supplicant, ifname);
if (!wpa_s) {
wpa_printf(MSG_ERROR, "%s: Unable to get wpa_s handle for %s\n", __func__, ifname);
return NULL;
}
return wpa_s;
}
static int get_iface_count(struct supplicant_context *ctx)
{
/* FIXME, should not access ifaces as it is supplicant internal data */
struct wpa_supplicant *wpa_s;
unsigned int count = 0;
for (wpa_s = ctx->supplicant->ifaces; wpa_s; wpa_s = wpa_s->next) {
count += 1;
}
return count;
}
static int add_interface(struct supplicant_context *ctx, struct net_if *iface)
{
struct wpa_supplicant *wpa_s;
char ifname[IFNAMSIZ + 1] = { 0 };
int ret, retry = 0, count = IFACE_NOTIFY_TIMEOUT_MS / IFACE_NOTIFY_RETRY_MS;
ret = net_if_get_name(iface, ifname, sizeof(ifname) - 1);
if (ret < 0) {
LOG_ERR("Cannot get interface %d (%p) name", net_if_get_by_iface(iface), iface);
goto out;
}
LOG_DBG("Adding interface %s [%d] (%p)", ifname, net_if_get_by_iface(iface), iface);
ret = zephyr_wpa_cli_global_cmd_v("interface_add %s %s %s %s",
ifname, "zephyr", "zephyr", "zephyr");
if (ret) {
LOG_ERR("Failed to add interface %s", ifname);
goto out;
}
while (retry++ < count && !wpa_supplicant_get_iface(ctx->supplicant, ifname)) {
k_sleep(K_MSEC(IFACE_NOTIFY_RETRY_MS));
}
wpa_s = wpa_supplicant_get_iface(ctx->supplicant, ifname);
if (wpa_s == NULL) {
LOG_ERR("Failed to add iface %s", ifname);
goto out;
}
wpa_s->conf->filter_ssids = 1;
wpa_s->conf->ap_scan = 1;
/* Default interface, kick start supplicant */
if (get_iface_count(ctx) > 0) {
ctx->iface = iface;
net_if_get_name(iface, ctx->if_name, CONFIG_NET_INTERFACE_NAME_LEN);
}
ret = zephyr_wpa_ctrl_init(wpa_s);
if (ret) {
LOG_ERR("Failed to initialize supplicant control interface");
goto out;
}
ret = wifi_nm_register_mgd_type_iface(wifi_nm_get_instance("wifi_supplicant"),
WIFI_TYPE_STA,
iface);
if (ret) {
LOG_ERR("Failed to register mgd iface with native stack %s (%d)",
ifname, ret);
goto out;
}
supplicant_generate_state_event(ifname, NET_EVENT_SUPPLICANT_CMD_IFACE_ADDED, 0);
if (get_iface_count(ctx) == 1) {
supplicant_generate_state_event(ifname, NET_EVENT_SUPPLICANT_CMD_READY, 0);
}
ret = 0;
out:
return ret;
}
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON
static int del_interface(struct supplicant_context *ctx, struct net_if *iface)
{
struct wpa_supplicant_event_msg msg;
struct wpa_supplicant *wpa_s;
union wpa_event_data *event = NULL;
int ret, retry = 0, count = IFACE_NOTIFY_TIMEOUT_MS / IFACE_NOTIFY_RETRY_MS;
char ifname[IFNAMSIZ + 1] = { 0 };
ret = net_if_get_name(iface, ifname, sizeof(ifname) - 1);
if (ret < 0) {
LOG_ERR("Cannot get interface %d (%p) name", net_if_get_by_iface(iface), iface);
goto out;
}
LOG_DBG("Removing interface %s %d (%p)", ifname, net_if_get_by_iface(iface), iface);
event = os_zalloc(sizeof(*event));
if (!event) {
ret = -ENOMEM;
LOG_ERR("Failed to allocate event data");
goto out;
}
wpa_s = wpa_supplicant_get_iface(ctx->supplicant, ifname);
if (!wpa_s) {
ret = -ENOENT;
LOG_ERR("Failed to get wpa_s handle for %s", ifname);
goto out;
}
supplicant_generate_state_event(ifname, NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVING, 0);
if (sizeof(event->interface_status.ifname) < strlen(ifname)) {
wpa_printf(MSG_ERROR, "Interface name too long: %s (max: %d)",
ifname, sizeof(event->interface_status.ifname));
goto out;
}
os_memcpy(event->interface_status.ifname, ifname, strlen(ifname));
event->interface_status.ievent = EVENT_INTERFACE_REMOVED;
msg.global = true;
msg.ctx = ctx->supplicant;
msg.event = EVENT_INTERFACE_STATUS;
msg.data = event;
ret = send_event(&msg);
if (ret) {
/* We failed notify WPA supplicant about interface removal.
* There is not much we can do, interface is still registered
* with WPA supplicant so we cannot unregister NM etc.
*/
wpa_printf(MSG_ERROR, "Failed to send event: %d", ret);
goto out;
}
while (retry++ < count && wpa_s->wpa_state != WPA_INTERFACE_DISABLED) {
k_sleep(K_MSEC(IFACE_NOTIFY_RETRY_MS));
}
if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) {
LOG_ERR("Failed to notify remove interface %s", ifname);
supplicant_generate_state_event(ifname, NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED, -1);
goto out;
}
zephyr_wpa_ctrl_deinit(wpa_s);
ret = zephyr_wpa_cli_global_cmd_v("interface_remove %s", ifname);
if (ret) {
LOG_ERR("Failed to remove interface %s", ifname);
supplicant_generate_state_event(ifname, NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED,
-EINVAL);
goto out;
}
ret = wifi_nm_unregister_mgd_iface(wifi_nm_get_instance("wpa_supplicant"), iface);
if (ret) {
LOG_ERR("Failed to unregister mgd iface %s with native stack (%d)",
ifname, ret);
goto out;
}
if (get_iface_count(ctx) == 0) {
supplicant_generate_state_event(ifname, NET_EVENT_SUPPLICANT_CMD_NOT_READY, 0);
}
supplicant_generate_state_event(ifname, NET_EVENT_SUPPLICANT_CMD_IFACE_REMOVED, 0);
out:
if (event) {
os_free(event);
}
return ret;
}
#endif
static void iface_work_handler(struct k_work *work)
{
struct supplicant_context *ctx = CONTAINER_OF(work, struct supplicant_context,
iface_work);
int ret;
ret = (*ctx->iface_handler)(ctx, ctx->iface);
if (ret < 0) {
LOG_ERR("Interface %d (%p) handler failed (%d)",
net_if_get_by_iface(ctx->iface), ctx->iface, ret);
}
}
/* As the mgmt thread stack is limited, use a separate work queue for any network
* interface add/delete.
*/
static void submit_iface_work(struct supplicant_context *ctx,
struct net_if *iface,
int (*handler)(struct supplicant_context *ctx,
struct net_if *iface))
{
ctx->iface_handler = handler;
k_work_submit_to_queue(&ctx->iface_wq, &ctx->iface_work);
}
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON
static void interface_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)
{
struct supplicant_context *ctx = CONTAINER_OF(cb, struct supplicant_context,
cb);
if ((mgmt_event & INTERFACE_EVENT_MASK) != mgmt_event) {
return;
}
if (!is_wanted_interface(iface)) {
LOG_DBG("Ignoring event (0x%02x) from interface %d (%p)",
mgmt_event, net_if_get_by_iface(iface), iface);
return;
}
if (mgmt_event == NET_EVENT_IF_ADMIN_UP) {
LOG_INF("Network interface %d (%p) up", net_if_get_by_iface(iface), iface);
submit_iface_work(ctx, iface, add_interface);
return;
}
if (mgmt_event == NET_EVENT_IF_ADMIN_DOWN) {
LOG_INF("Network interface %d (%p) down", net_if_get_by_iface(iface), iface);
submit_iface_work(ctx, iface, del_interface);
return;
}
}
#endif
static void iface_cb(struct net_if *iface, void *user_data)
{
struct supplicant_context *ctx = user_data;
int ret;
if (!net_if_is_wifi(iface)) {
return;
}
if (!net_if_is_admin_up(iface)) {
return;
}
ret = add_interface(ctx, iface);
if (ret < 0) {
return;
}
}
static int setup_interface_monitoring(struct supplicant_context *ctx, struct net_if *iface)
{
ARG_UNUSED(iface);
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON
net_mgmt_init_event_callback(&ctx->cb, interface_handler,
INTERFACE_EVENT_MASK);
net_mgmt_add_event_callback(&ctx->cb);
#endif
net_if_foreach(iface_cb, ctx);
return 0;
}
static void event_socket_handler(int sock, void *eloop_ctx, void *user_data)
{
struct supplicant_context *ctx = user_data;
struct wpa_supplicant_event_msg msg;
int ret;
ARG_UNUSED(eloop_ctx);
ARG_UNUSED(ctx);
ret = zsock_recv(sock, &msg, sizeof(msg), 0);
if (ret < 0) {
LOG_ERR("Failed to recv the message (%d)", -errno);
return;
}
if (ret != sizeof(msg)) {
LOG_ERR("Received incomplete message: got: %d, expected:%d",
ret, sizeof(msg));
return;
}
LOG_DBG("Passing message %d to wpa_supplicant", msg.event);
if (msg.global) {
wpa_supplicant_event_global(msg.ctx, msg.event, msg.data);
} else {
wpa_supplicant_event(msg.ctx, msg.event, msg.data);
}
if (msg.data) {
union wpa_event_data *data = msg.data;
/* Free up deep copied data */
if (msg.event == EVENT_AUTH) {
os_free((char *)data->auth.ies);
} else if (msg.event == EVENT_RX_MGMT) {
os_free((char *)data->rx_mgmt.frame);
} else if (msg.event == EVENT_TX_STATUS) {
os_free((char *)data->tx_status.data);
} else if (msg.event == EVENT_ASSOC) {
os_free((char *)data->assoc_info.addr);
os_free((char *)data->assoc_info.req_ies);
os_free((char *)data->assoc_info.resp_ies);
os_free((char *)data->assoc_info.resp_frame);
} else if (msg.event == EVENT_ASSOC_REJECT) {
os_free((char *)data->assoc_reject.bssid);
os_free((char *)data->assoc_reject.resp_ies);
} else if (msg.event == EVENT_DEAUTH) {
os_free((char *)data->deauth_info.addr);
os_free((char *)data->deauth_info.ie);
} else if (msg.event == EVENT_DISASSOC) {
os_free((char *)data->disassoc_info.addr);
os_free((char *)data->disassoc_info.ie);
} else if (msg.event == EVENT_UNPROT_DEAUTH) {
os_free((char *)data->unprot_deauth.sa);
os_free((char *)data->unprot_deauth.da);
} else if (msg.event == EVENT_UNPROT_DISASSOC) {
os_free((char *)data->unprot_disassoc.sa);
os_free((char *)data->unprot_disassoc.da);
}
os_free(msg.data);
}
}
static int register_supplicant_event_socket(struct supplicant_context *ctx)
{
int ret;
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, ctx->event_socketpair);
if (ret < 0) {
ret = -errno;
LOG_ERR("Failed to initialize socket (%d)", ret);
return ret;
}
eloop_register_read_sock(ctx->event_socketpair[0], event_socket_handler, NULL, ctx);
return 0;
}
static void handler(void)
{
struct supplicant_context *ctx;
struct wpa_params params;
#if !defined(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE) && !defined(CONFIG_MBEDTLS_ENABLE_HEAP)
/* Needed for crypto operation as default is no-op and fails */
mbedtls_platform_set_calloc_free(calloc, free);
#endif /* !CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE && !CONFIG_MBEDTLS_ENABLE_HEAP */
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_MBEDTLS_PSA
supp_psa_crypto_init();
#endif
ctx = get_default_context();
k_work_queue_init(&ctx->iface_wq);
k_work_queue_start(&ctx->iface_wq, iface_wq_stack,
K_THREAD_STACK_SIZEOF(iface_wq_stack),
CONFIG_WIFI_NM_WPA_SUPPLICANT_WQ_PRIO,
NULL);
k_work_init(&ctx->iface_work, iface_work_handler);
memset(¶ms, 0, sizeof(params));
params.wpa_debug_level = CONFIG_WIFI_NM_WPA_SUPPLICANT_DEBUG_LEVEL;
ctx->supplicant = wpa_supplicant_init(¶ms);
if (ctx->supplicant == NULL) {
LOG_ERR("Failed to initialize %s", "wpa_supplicant");
goto err;
}
LOG_INF("%s initialized", "wpa_supplicant");
if (fst_global_init()) {
LOG_ERR("Failed to initialize %s", "FST");
goto out;
}
#if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE)
if (!fst_global_add_ctrl(fst_ctrl_cli)) {
LOG_WRN("Failed to add CLI FST ctrl");
}
#endif
zephyr_global_wpa_ctrl_init();
register_supplicant_event_socket(ctx);
submit_iface_work(ctx, NULL, setup_interface_monitoring);
(void)wpa_supplicant_run(ctx->supplicant);
supplicant_generate_state_event(ctx->if_name, NET_EVENT_SUPPLICANT_CMD_NOT_READY, 0);
eloop_unregister_read_sock(ctx->event_socketpair[0]);
zephyr_global_wpa_ctrl_deinit();
fst_global_deinit();
out:
wpa_supplicant_deinit(ctx->supplicant);
zsock_close(ctx->event_socketpair[0]);
zsock_close(ctx->event_socketpair[1]);
err:
os_free(params.pid_file);
}
static int init(void)
{
/* We create a thread that handles all supplicant connections */
k_thread_create(&tid, supplicant_thread_stack,
K_THREAD_STACK_SIZEOF(supplicant_thread_stack),
(k_thread_entry_t)handler, NULL, NULL, NULL,
0, 0, K_NO_WAIT);
return 0;
}
SYS_INIT(init, APPLICATION, 0);
``` | /content/code_sandbox/modules/hostap/src/supp_main.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 4,519 |
```linker script
*(.time_critical*)
``` | /content/code_sandbox/modules/hal_rpi_pico/timecritical.ld | linker script | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 6 |
```objective-c
/***********************************************************************************************//**
* \file cyabs_rtos_impl.h
*
* \brief
* Internal definitions for RTOS abstraction layer
*
***************************************************************************************************
* \copyright
* an affiliate of Cypress Semiconductor Corporation
*
*
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**************************************************************************************************/
#pragma once
#include <stdbool.h>
#include <zephyr/kernel.h>
#ifdef __cplusplus
extern "C"
{
#endif
/*
* Constants
*/
#define CY_RTOS_MIN_STACK_SIZE 300 /** Minimum stack size in bytes */
#define CY_RTOS_ALIGNMENT 0x00000008UL /** Minimum alignment for RTOS objects */
#define CY_RTOS_ALIGNMENT_MASK 0x00000007UL /** Mask for checking the alignment of */
/*
* Type Definitions
*/
/* RTOS thread priority */
typedef enum {
CY_RTOS_PRIORITY_MIN = CONFIG_NUM_PREEMPT_PRIORITIES - 1,
CY_RTOS_PRIORITY_LOW = (CONFIG_NUM_PREEMPT_PRIORITIES * 6 / 7),
CY_RTOS_PRIORITY_BELOWNORMAL = (CONFIG_NUM_PREEMPT_PRIORITIES * 5 / 7),
CY_RTOS_PRIORITY_NORMAL = (CONFIG_NUM_PREEMPT_PRIORITIES * 4 / 7),
CY_RTOS_PRIORITY_ABOVENORMAL = (CONFIG_NUM_PREEMPT_PRIORITIES * 3 / 7),
CY_RTOS_PRIORITY_HIGH = (CONFIG_NUM_PREEMPT_PRIORITIES * 2 / 7),
CY_RTOS_PRIORITY_REALTIME = (CONFIG_NUM_PREEMPT_PRIORITIES * 1 / 7),
CY_RTOS_PRIORITY_MAX = 0
} cy_thread_priority_t;
/** \cond INTERNAL */
typedef struct {
struct k_thread z_thread;
void *memptr;
} k_thread_wrapper_t;
typedef struct {
struct k_timer z_timer;
uint32_t trigger_type;
uint32_t status;
void *callback_function;
void *arg;
} k_timer_wrapper_t;
/** \endcond */
/* Zephyr definition of a thread handle */
typedef k_thread_wrapper_t *cy_thread_t;
/* Argument passed to the entry function of a thread */
typedef void *cy_thread_arg_t;
/* Zephyr definition of a mutex */
typedef struct k_mutex cy_mutex_t;
/* Zephyr definition of a semaphore */
typedef struct k_sem cy_semaphore_t;
/* Zephyr definition of an event */
typedef struct k_event cy_event_t;
/* Zephyr definition of a message queue */
typedef struct k_msgq cy_queue_t;
/* Zephyr definition of a timer */
typedef k_timer_wrapper_t cy_timer_t;
/* Argument passed to the timer callback function */
typedef void *cy_timer_callback_arg_t;
/* Time in milliseconds */
typedef uint32_t cy_time_t;
/* Zephyr definition of a error status */
typedef int cy_rtos_error_t;
#ifdef __cplusplus
} /* extern "C" */
#endif
``` | /content/code_sandbox/modules/hal_infineon/abstraction-rtos/include/COMPONENT_ZEPHYR/cyabs_rtos_impl.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 640 |
```unknown
config HAS_RPI_PICO
bool
config PICOSDK_USE_UART
bool
help
Use the UART driver from pico-sdk
config PICOSDK_USE_GPIO
bool
help
Use the GPIO driver from pico-sdk
config PICOSDK_USE_FLASH
bool
help
Use the flash driver from pico-sdk
config PICOSDK_USE_PWM
bool
help
Use the PWM driver from pico-sdk
config PICOSDK_USE_ADC
bool
help
Use the ADC driver from pico-sdk
config PICOSDK_USE_DMA
bool
help
Use the DMA driver from pico-sdk
config PICOSDK_USE_PIO
bool
select PICOSDK_USE_CLAIM
help
Use the PIO driver from pico-sdk
config PICOSDK_USE_CLAIM
bool
help
Use the "claim" driver from pico-sdk
config PICOSDK_USE_TIMER
bool
help
Use the TIMER driver from pico-sdk
config PICOSDK_USE_RTC
bool
help
Use the RTC driver from pico-sdk
``` | /content/code_sandbox/modules/hal_rpi_pico/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 233 |
```objective-c
/*
*
*/
/* File intentionally left blank. It's expected by pico-sdk, but isn't used. */
``` | /content/code_sandbox/modules/hal_rpi_pico/pico/version.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 24 |
```objective-c
/*
*
*/
/*
* Originally this file is generated by pico-sdk, and some files
* try to include it. Therefore, we have to provide that file,
* with this exact name.
* Since this file ends up included in all pico-sdk code, it's
* used to inject workarounds to make pico-sdk compile with Zephyr.
*/
#ifndef _CONFIG_AUTOGEN_H_
#define _CONFIG_AUTOGEN_H_
/* WORKAROUNDS */
/*
* static_assert is not supported, so BUILD_ASSERT is used instead.
* BUILD_ASSERT is included through toolchain.h.
*/
#include <zephyr/toolchain.h>
#if !defined(__cplusplus) && !defined(static_assert)
#define static_assert(expr, msg...) BUILD_ASSERT((expr), "" msg)
#endif /* static_assert && __cplusplus__ */
/* Convert uses of asm, which is not supported in c99, to __asm */
#define asm __asm
/* Disable binary info */
#define PICO_NO_BINARY_INFO 1
/* Zephyr compatible way of forcing inline */
#ifndef __always_inline
#define __always_inline ALWAYS_INLINE
#endif /* __always_inline */
/* Two definitions required for the flash driver */
#define __STRING(x) #x
#ifndef __noinline
#define __noinline __attribute__((noinline))
#endif
#endif
``` | /content/code_sandbox/modules/hal_rpi_pico/pico/config_autogen.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 271 |
```unknown
# affiliates <open-source-office@arm.com></text>
config ARM_ETHOS_U
bool "Ethos-U core driver"
default n
depends on MULTITHREADING
help
This option enables the Arm Ethos-U core driver.
if ARM_ETHOS_U
menu "Arm Ethos-U NPU configuration"
choice ARM_ETHOS_U_NPU_CONFIG
prompt "Arm Ethos-U NPU configuration"
default ARM_ETHOS_U55_128
config ARM_ETHOS_U55_64
bool "using Ethos-U55 with 64 macs"
config ARM_ETHOS_U55_128
bool "using Ethos-U55 with 128 macs"
config ARM_ETHOS_U55_256
bool "using Ethos-U55 with 256 macs"
config ARM_ETHOS_U65_128
bool "using Ethos-U65 with 128 macs"
config ARM_ETHOS_U65_256
bool "using Ethos-U65 with 256 macs"
config ARM_ETHOS_U65_512
bool "using Ethos-U65 with 512 macs"
endchoice
endmenu
config ARM_ETHOS_U_NPU_NAME
string
default "ethos-u55-64" if ARM_ETHOS_U55_64
default "ethos-u55-128" if ARM_ETHOS_U55_128
default "ethos-u55-256" if ARM_ETHOS_U55_256
default "ethos-u65-128" if ARM_ETHOS_U65_128
default "ethos-u65-256" if ARM_ETHOS_U65_256
default "ethos-u65-512" if ARM_ETHOS_U65_512
help
Name of the used Arm NPU
choice "ARM_ETHOS_U_LOG_LEVEL_CHOICE"
prompt "Max compiled-in log level for arm_ethos_u"
default ARM_ETHOS_U_LOG_LEVEL_WRN
depends on STDOUT_CONSOLE
config ARM_ETHOS_U_LOG_LEVEL_NONE
bool "None"
config ARM_ETHOS_U_LOG_LEVEL_ERR
bool "Error"
config ARM_ETHOS_U_LOG_LEVEL_WRN
bool "Warning"
config ARM_ETHOS_U_LOG_LEVEL_INF
bool "Info"
config ARM_ETHOS_U_LOG_LEVEL_DBG
bool "Debug"
config ARM_ETHOS_U_LOG_LEVEL_DEFAULT
bool "Default"
endchoice
config ARM_ETHOS_U_LOG_LEVEL
int
depends on STDOUT_CONSOLE
default 0 if ARM_ETHOS_U_LOG_LEVEL_NONE
default 1 if ARM_ETHOS_U_LOG_LEVEL_ERR
default 2 if ARM_ETHOS_U_LOG_LEVEL_WRN
default 3 if ARM_ETHOS_U_LOG_LEVEL_INF
default 4 if ARM_ETHOS_U_LOG_LEVEL_DBG
endif
``` | /content/code_sandbox/modules/hal_ethos_u/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 567 |
```unknown
menu "Input device settings"
config LV_Z_POINTER_INPUT
bool "Input lvgl pointer"
default y
depends on INPUT
depends on DT_HAS_ZEPHYR_LVGL_POINTER_INPUT_ENABLED
config LV_Z_POINTER_INPUT_MSGQ_COUNT
int "Input pointer queue message count"
default 10
depends on LV_Z_POINTER_INPUT
help
Size of the pointer message queue buffering input events.
config LV_Z_BUTTON_INPUT
bool "Input lvgl button"
default y
depends on INPUT
depends on DT_HAS_ZEPHYR_LVGL_BUTTON_INPUT_ENABLED
config LV_Z_BUTTON_INPUT_MSGQ_COUNT
int "Input button queue message count"
default 4
depends on LV_Z_BUTTON_INPUT
help
Size of the button message queue buffering input events.
config LV_Z_ENCODER_INPUT
bool "Input lvgl encoder"
default y
depends on INPUT
depends on DT_HAS_ZEPHYR_LVGL_ENCODER_INPUT_ENABLED
config LV_Z_ENCODER_INPUT_MSGQ_COUNT
int "Input encoder queue message count"
default 4
depends on LV_Z_ENCODER_INPUT
help
Size of the encoder message queue buffering input events.
config LV_Z_KEYPAD_INPUT
bool "Input lvgl keypad"
default y
depends on INPUT
depends on DT_HAS_ZEPHYR_LVGL_KEYPAD_INPUT_ENABLED
config LV_Z_KEYPAD_INPUT_MSGQ_COUNT
int "Input keypad queue message count"
default 4
depends on LV_Z_KEYPAD_INPUT
help
Size of the keypad message queue buffering input events.
endmenu
``` | /content/code_sandbox/modules/lvgl/Kconfig.input | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 335 |
```c
/*
*
*/
#include <zephyr/kernel.h>
#include <lvgl.h>
#include "lvgl_display.h"
void lvgl_flush_cb_24bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
uint16_t w = area->x2 - area->x1 + 1;
uint16_t h = area->y2 - area->y1 + 1;
struct lvgl_display_flush flush;
flush.disp_drv = disp_drv;
flush.x = area->x1;
flush.y = area->y1;
flush.desc.buf_size = w * 3U * h;
flush.desc.width = w;
flush.desc.pitch = w;
flush.desc.height = h;
flush.buf = (void *)color_p;
lvgl_flush_display(&flush);
}
void lvgl_set_px_cb_24bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, lv_color_t color, lv_opa_t opa)
{
uint8_t *buf_xy = buf + x * 3U + y * 3U * buf_w;
lv_color32_t converted_color;
#ifdef CONFIG_LV_COLOR_DEPTH_32
if (opa != LV_OPA_COVER) {
lv_color_t mix_color;
mix_color.ch.red = *buf_xy;
mix_color.ch.green = *(buf_xy + 1);
mix_color.ch.blue = *(buf_xy + 2);
color = lv_color_mix(color, mix_color, opa);
}
#endif
converted_color.full = lv_color_to32(color);
*buf_xy = converted_color.ch.red;
*(buf_xy + 1) = converted_color.ch.green;
*(buf_xy + 2) = converted_color.ch.blue;
}
``` | /content/code_sandbox/modules/lvgl/lvgl_display_24bit.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 402 |
```c
/*
*
*/
#include <zephyr/kernel.h>
#include <errno.h>
#include "lvgl_display.h"
#ifdef CONFIG_LV_Z_FLUSH_THREAD
K_SEM_DEFINE(flush_complete, 0, 1);
/* Message queue will only ever need to queue one message */
K_MSGQ_DEFINE(flush_queue, sizeof(struct lvgl_display_flush), 1, 1);
void lvgl_flush_thread_entry(void *arg1, void *arg2, void *arg3)
{
struct lvgl_display_flush flush;
struct lvgl_disp_data *data;
while (1) {
k_msgq_get(&flush_queue, &flush, K_FOREVER);
data = (struct lvgl_disp_data *)flush.disp_drv->user_data;
display_write(data->display_dev, flush.x, flush.y, &flush.desc,
flush.buf);
lv_disp_flush_ready(flush.disp_drv);
k_sem_give(&flush_complete);
}
}
K_THREAD_DEFINE(lvgl_flush_thread, CONFIG_LV_Z_FLUSH_THREAD_STACK_SIZE,
lvgl_flush_thread_entry, NULL, NULL, NULL,
K_PRIO_COOP(CONFIG_LV_Z_FLUSH_THREAD_PRIO), 0, 0);
void lvgl_wait_cb(lv_disp_drv_t *disp_drv)
{
k_sem_take(&flush_complete, K_FOREVER);
}
#endif /* CONFIG_LV_Z_FLUSH_THREAD */
#ifdef CONFIG_LV_Z_USE_ROUNDER_CB
void lvgl_rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area)
{
#if CONFIG_LV_Z_AREA_X_ALIGNMENT_WIDTH != 1
__ASSERT(POPCOUNT(CONFIG_LV_Z_AREA_X_ALIGNMENT_WIDTH) == 1, "Invalid X alignment width");
area->x1 &= ~(CONFIG_LV_Z_AREA_X_ALIGNMENT_WIDTH - 1);
area->x2 |= (CONFIG_LV_Z_AREA_X_ALIGNMENT_WIDTH - 1);
#endif
#if CONFIG_LV_Z_AREA_Y_ALIGNMENT_WIDTH != 1
__ASSERT(POPCOUNT(CONFIG_LV_Z_AREA_Y_ALIGNMENT_WIDTH) == 1, "Invalid Y alignment width");
area->y1 &= ~(CONFIG_LV_Z_AREA_Y_ALIGNMENT_WIDTH - 1);
area->y2 |= (CONFIG_LV_Z_AREA_Y_ALIGNMENT_WIDTH - 1);
#endif
}
#else
#define lvgl_rounder_cb NULL
#endif
int set_lvgl_rendering_cb(lv_disp_drv_t *disp_drv)
{
int err = 0;
struct lvgl_disp_data *data = (struct lvgl_disp_data *)disp_drv->user_data;
#ifdef CONFIG_LV_Z_FLUSH_THREAD
disp_drv->wait_cb = lvgl_wait_cb;
#endif
switch (data->cap.current_pixel_format) {
case PIXEL_FORMAT_ARGB_8888:
disp_drv->flush_cb = lvgl_flush_cb_32bit;
disp_drv->rounder_cb = lvgl_rounder_cb;
#ifdef CONFIG_LV_COLOR_DEPTH_32
disp_drv->set_px_cb = NULL;
#else
disp_drv->set_px_cb = lvgl_set_px_cb_32bit;
#endif
break;
case PIXEL_FORMAT_RGB_888:
disp_drv->flush_cb = lvgl_flush_cb_24bit;
disp_drv->rounder_cb = lvgl_rounder_cb;
disp_drv->set_px_cb = lvgl_set_px_cb_24bit;
break;
case PIXEL_FORMAT_RGB_565:
case PIXEL_FORMAT_BGR_565:
disp_drv->flush_cb = lvgl_flush_cb_16bit;
disp_drv->rounder_cb = lvgl_rounder_cb;
#ifdef CONFIG_LV_COLOR_DEPTH_16
disp_drv->set_px_cb = NULL;
#else
disp_drv->set_px_cb = lvgl_set_px_cb_16bit;
#endif
break;
case PIXEL_FORMAT_MONO01:
case PIXEL_FORMAT_MONO10:
disp_drv->flush_cb = lvgl_flush_cb_mono;
disp_drv->rounder_cb = lvgl_rounder_cb_mono;
disp_drv->set_px_cb = lvgl_set_px_cb_mono;
break;
default:
disp_drv->flush_cb = NULL;
disp_drv->rounder_cb = NULL;
disp_drv->set_px_cb = NULL;
err = -ENOTSUP;
break;
}
return err;
}
void lvgl_flush_display(struct lvgl_display_flush *request)
{
#ifdef CONFIG_LV_Z_FLUSH_THREAD
/*
* LVGL will only start a flush once the previous one is complete,
* so we can reset the flush state semaphore here.
*/
k_sem_reset(&flush_complete);
k_msgq_put(&flush_queue, request, K_FOREVER);
/* Explicitly yield, in case the calling thread is a cooperative one */
k_yield();
#else
/* Write directly to the display */
struct lvgl_disp_data *data =
(struct lvgl_disp_data *)request->disp_drv->user_data;
display_write(data->display_dev, request->x, request->y,
&request->desc, request->buf);
lv_disp_flush_ready(request->disp_drv);
#endif
}
``` | /content/code_sandbox/modules/lvgl/lvgl_display.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,085 |
```c
/*
*
*/
#include "lvgl_mem.h"
#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include <zephyr/sys/sys_heap.h>
#ifdef CONFIG_LV_Z_MEMORY_POOL_CUSTOM_SECTION
#define HEAP_MEM_ATTRIBUTES Z_GENERIC_SECTION(.lvgl_heap) __aligned(8)
#else
#define HEAP_MEM_ATTRIBUTES __aligned(8)
#endif /* CONFIG_LV_Z_MEMORY_POOL_CUSTOM_SECTION */
static char lvgl_heap_mem[CONFIG_LV_Z_MEM_POOL_SIZE] HEAP_MEM_ATTRIBUTES;
static struct sys_heap lvgl_heap;
static struct k_spinlock lvgl_heap_lock;
void *lvgl_malloc(size_t size)
{
k_spinlock_key_t key;
void *ret;
key = k_spin_lock(&lvgl_heap_lock);
ret = sys_heap_alloc(&lvgl_heap, size);
k_spin_unlock(&lvgl_heap_lock, key);
return ret;
}
void *lvgl_realloc(void *ptr, size_t size)
{
k_spinlock_key_t key;
void *ret;
key = k_spin_lock(&lvgl_heap_lock);
ret = sys_heap_realloc(&lvgl_heap, ptr, size);
k_spin_unlock(&lvgl_heap_lock, key);
return ret;
}
void lvgl_free(void *ptr)
{
k_spinlock_key_t key;
key = k_spin_lock(&lvgl_heap_lock);
sys_heap_free(&lvgl_heap, ptr);
k_spin_unlock(&lvgl_heap_lock, key);
}
void lvgl_print_heap_info(bool dump_chunks)
{
k_spinlock_key_t key;
key = k_spin_lock(&lvgl_heap_lock);
sys_heap_print_info(&lvgl_heap, dump_chunks);
k_spin_unlock(&lvgl_heap_lock, key);
}
void lvgl_heap_init(void)
{
sys_heap_init(&lvgl_heap, &lvgl_heap_mem[0], CONFIG_LV_Z_MEM_POOL_SIZE);
}
``` | /content/code_sandbox/modules/lvgl/lvgl_mem.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 384 |
```c
/*
*
*/
#include <zephyr/shell/shell.h>
#include <lvgl.h>
#include <zephyr/autoconf.h>
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
#include "lvgl_mem.h"
#endif
#ifdef CONFIG_LV_USE_MONKEY
static lv_monkey_t *lvgl_monkeys[CONFIG_LV_Z_MAX_MONKEY_COUNT];
static const char *lvgl_monkey_indev_as_string(lv_monkey_t *monkey)
{
lv_indev_t *input_device;
input_device = lv_monkey_get_indev(monkey);
if (!input_device || !input_device->driver) {
return "unknown";
}
switch (input_device->driver->type) {
case LV_INDEV_TYPE_POINTER:
return "pointer";
case LV_INDEV_TYPE_KEYPAD:
return "keypad";
case LV_INDEV_TYPE_BUTTON:
return "button";
case LV_INDEV_TYPE_ENCODER:
return "encoder";
default:
return "unknown";
}
}
static int lvgl_monkey_indev_from_string(const char *str, lv_indev_type_t *input_device)
{
if (strcmp(str, "pointer") == 0) {
*input_device = LV_INDEV_TYPE_POINTER;
} else if (strcmp(str, "keypad") == 0) {
*input_device = LV_INDEV_TYPE_KEYPAD;
} else if (strcmp(str, "button") == 0) {
*input_device = LV_INDEV_TYPE_BUTTON;
} else if (strcmp(str, "encoder") == 0) {
*input_device = LV_INDEV_TYPE_ENCODER;
} else {
return -EINVAL;
}
return 0;
}
static void dump_monkey_info(const struct shell *sh)
{
shell_print(sh, "id device active");
for (size_t i = 0; i < CONFIG_LV_Z_MAX_MONKEY_COUNT; i++) {
if (lvgl_monkeys[i] != NULL) {
shell_print(sh, "%-4u %-9s %-3s", i,
lvgl_monkey_indev_as_string(lvgl_monkeys[i]),
lv_monkey_get_enable(lvgl_monkeys[i]) ? "yes" : "no");
}
}
}
static int cmd_lvgl_monkey(const struct shell *sh, size_t argc, char *argv[])
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);
dump_monkey_info(sh);
shell_print(sh, "");
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
static int cmd_lvgl_monkey_create(const struct shell *sh, size_t argc, char *argv[])
{
bool created_monkey = false;
lv_monkey_config_t default_config;
lv_monkey_config_init(&default_config);
if (argc == 2) {
if (lvgl_monkey_indev_from_string(argv[1], &default_config.type) < 0) {
shell_error(sh, "Invalid monkey input device %s", argv[1]);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
}
for (size_t i = 0; i < CONFIG_LV_Z_MAX_MONKEY_COUNT; i++) {
if (lvgl_monkeys[i] == NULL) {
lvgl_monkeys[i] = lv_monkey_create(&default_config);
lv_monkey_set_enable(lvgl_monkeys[i], true);
created_monkey = true;
break;
}
}
if (!created_monkey) {
shell_error(sh, "Error creating monkey instance");
return -ENOSPC;
}
dump_monkey_info(sh);
return 0;
}
static int cmd_lvgl_monkey_set(const struct shell *sh, size_t argc, char *argv[])
{
int index;
index = atoi(argv[1]);
if (index < 0 || index >= CONFIG_LV_Z_MAX_MONKEY_COUNT || lvgl_monkeys[index] == NULL) {
shell_error(sh, "Invalid monkey index");
return -ENOEXEC;
}
if (strcmp(argv[2], "active") == 0) {
lv_monkey_set_enable(lvgl_monkeys[index], true);
} else if (strcmp(argv[2], "inactive") == 0) {
lv_monkey_set_enable(lvgl_monkeys[index], false);
} else {
shell_error(sh, "Invalid monkey state %s", argv[2]);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
dump_monkey_info(sh);
return 0;
}
#endif /* CONFIG_LV_USE_MONKEY */
static int cmd_lvgl_stats(const struct shell *sh, size_t argc, char *argv[])
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
static int cmd_lvgl_stats_memory(const struct shell *sh, size_t argc, char *argv[])
{
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
bool dump_chunks = false;
if (argc == 2) {
if (strcmp(argv[1], "-c") == 0) {
dump_chunks = true;
} else {
shell_error(sh, "unsupported option %s", argv[1]);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
}
lvgl_print_heap_info(dump_chunks);
return 0;
#else
ARG_UNUSED(argc);
ARG_UNUSED(argv);
shell_error(sh, "Set CONFIG_LV_Z_MEM_POOL_SYS_HEAP to enable memory statistics support.");
return -ENOTSUP;
#endif
}
SHELL_STATIC_SUBCMD_SET_CREATE(lvgl_cmd_stats,
SHELL_CMD_ARG(memory, NULL,
"Show LVGL memory statistics\n"
"Usage: lvgl stats memory [-c]\n"
"-c dump chunk information",
cmd_lvgl_stats_memory, 1, 1),
SHELL_SUBCMD_SET_END);
#ifdef CONFIG_LV_USE_MONKEY
SHELL_STATIC_SUBCMD_SET_CREATE(
lvgl_cmd_monkey,
SHELL_CMD_ARG(create, NULL,
"Create a new monkey instance (default: pointer)\n"
"Usage: lvgl monkey create [pointer|keypad|button|encoder]",
cmd_lvgl_monkey_create, 1, 1),
SHELL_CMD_ARG(set, NULL,
"Activate/deactive a monkey instance\n"
"Usage: lvgl monkey set <index> <active|inactive>\n",
cmd_lvgl_monkey_set, 3, 0),
SHELL_SUBCMD_SET_END);
#endif /* CONFIG_LV_USE_MONKEY */
SHELL_STATIC_SUBCMD_SET_CREATE(
lvgl_cmds, SHELL_CMD(stats, &lvgl_cmd_stats, "Show LVGL statistics", cmd_lvgl_stats),
#ifdef CONFIG_LV_USE_MONKEY
SHELL_CMD(monkey, &lvgl_cmd_monkey, "LVGL monkey testing", cmd_lvgl_monkey),
#endif /* CONFIG_LV_USE_MONKEY */
SHELL_SUBCMD_SET_END);
SHELL_CMD_REGISTER(lvgl, &lvgl_cmds, "LVGL shell commands", NULL);
``` | /content/code_sandbox/modules/lvgl/lvgl_shell.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,525 |
```c
/*
*
*/
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <lvgl.h>
#include "lvgl_display.h"
#include "lvgl_common_input.h"
#ifdef CONFIG_LV_Z_USE_FILESYSTEM
#include "lvgl_fs.h"
#endif
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
#include "lvgl_mem.h"
#endif
#include LV_MEM_CUSTOM_INCLUDE
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(lvgl, CONFIG_LV_Z_LOG_LEVEL);
static lv_disp_drv_t disp_drv;
struct lvgl_disp_data disp_data = {
.blanking_on = false,
};
#define DISPLAY_NODE DT_CHOSEN(zephyr_display)
#ifdef CONFIG_LV_Z_BUFFER_ALLOC_STATIC
static lv_disp_draw_buf_t disp_buf;
#define DISPLAY_WIDTH DT_PROP(DISPLAY_NODE, width)
#define DISPLAY_HEIGHT DT_PROP(DISPLAY_NODE, height)
#define BUFFER_SIZE \
(CONFIG_LV_Z_BITS_PER_PIXEL * \
((CONFIG_LV_Z_VDB_SIZE * DISPLAY_WIDTH * DISPLAY_HEIGHT) / 100) / 8)
#define NBR_PIXELS_IN_BUFFER (BUFFER_SIZE * 8 / CONFIG_LV_Z_BITS_PER_PIXEL)
/* NOTE: depending on chosen color depth buffer may be accessed using uint8_t *,
* uint16_t * or uint32_t *, therefore buffer needs to be aligned accordingly to
* prevent unaligned memory accesses.
*/
static uint8_t buf0[BUFFER_SIZE]
#ifdef CONFIG_LV_Z_VBD_CUSTOM_SECTION
Z_GENERIC_SECTION(.lvgl_buf)
#endif
__aligned(CONFIG_LV_Z_VDB_ALIGN);
#ifdef CONFIG_LV_Z_DOUBLE_VDB
static uint8_t buf1[BUFFER_SIZE]
#ifdef CONFIG_LV_Z_VBD_CUSTOM_SECTION
Z_GENERIC_SECTION(.lvgl_buf)
#endif
__aligned(CONFIG_LV_Z_VDB_ALIGN);
#endif /* CONFIG_LV_Z_DOUBLE_VDB */
#endif /* CONFIG_LV_Z_BUFFER_ALLOC_STATIC */
#if CONFIG_LV_Z_LOG_LEVEL != 0
/*
* In LVGLv8 the signature of the logging callback has changes and it no longer
* takes the log level as an integer argument. Instead, the log level is now
* already part of the buffer passed to the logging callback. It's not optimal
* but we need to live with it and parse the buffer manually to determine the
* level and then truncate the string we actually pass to the logging framework.
*/
static void lvgl_log(const char *buf)
{
/*
* This is ugly and should be done in a loop or something but as it
* turned out, Z_LOG()'s first argument (that specifies the log level)
* cannot be an l-value...
*
* We also assume lvgl is sane and always supplies the level string.
*/
switch (buf[1]) {
case 'E':
LOG_ERR("%s", buf + strlen("[Error] "));
break;
case 'W':
LOG_WRN("%s", buf + strlen("[Warn] "));
break;
case 'I':
LOG_INF("%s", buf + strlen("[Info] "));
break;
case 'T':
LOG_DBG("%s", buf + strlen("[Trace] "));
break;
case 'U':
LOG_INF("%s", buf + strlen("[User] "));
break;
}
}
#endif
#ifdef CONFIG_LV_Z_BUFFER_ALLOC_STATIC
static int lvgl_allocate_rendering_buffers(lv_disp_drv_t *disp_driver)
{
struct lvgl_disp_data *data = (struct lvgl_disp_data *)disp_driver->user_data;
int err = 0;
if (data->cap.x_resolution <= DISPLAY_WIDTH) {
disp_driver->hor_res = data->cap.x_resolution;
} else {
LOG_ERR("Horizontal resolution is larger than maximum");
err = -ENOTSUP;
}
if (data->cap.y_resolution <= DISPLAY_HEIGHT) {
disp_driver->ver_res = data->cap.y_resolution;
} else {
LOG_ERR("Vertical resolution is larger than maximum");
err = -ENOTSUP;
}
disp_driver->draw_buf = &disp_buf;
#ifdef CONFIG_LV_Z_DOUBLE_VDB
lv_disp_draw_buf_init(disp_driver->draw_buf, &buf0, &buf1, NBR_PIXELS_IN_BUFFER);
#else
lv_disp_draw_buf_init(disp_driver->draw_buf, &buf0, NULL, NBR_PIXELS_IN_BUFFER);
#endif /* CONFIG_LV_Z_DOUBLE_VDB */
return err;
}
#else
static int lvgl_allocate_rendering_buffers(lv_disp_drv_t *disp_driver)
{
void *buf0 = NULL;
void *buf1 = NULL;
uint16_t buf_nbr_pixels;
uint32_t buf_size;
struct lvgl_disp_data *data = (struct lvgl_disp_data *)disp_driver->user_data;
disp_driver->hor_res = data->cap.x_resolution;
disp_driver->ver_res = data->cap.y_resolution;
buf_nbr_pixels = (CONFIG_LV_Z_VDB_SIZE * disp_driver->hor_res * disp_driver->ver_res) / 100;
/* one horizontal line is the minimum buffer requirement for lvgl */
if (buf_nbr_pixels < disp_driver->hor_res) {
buf_nbr_pixels = disp_driver->hor_res;
}
switch (data->cap.current_pixel_format) {
case PIXEL_FORMAT_ARGB_8888:
buf_size = 4 * buf_nbr_pixels;
break;
case PIXEL_FORMAT_RGB_888:
buf_size = 3 * buf_nbr_pixels;
break;
case PIXEL_FORMAT_RGB_565:
buf_size = 2 * buf_nbr_pixels;
break;
case PIXEL_FORMAT_MONO01:
case PIXEL_FORMAT_MONO10:
buf_size = buf_nbr_pixels / 8;
buf_size += (buf_nbr_pixels % 8) == 0 ? 0 : 1;
break;
default:
return -ENOTSUP;
}
buf0 = LV_MEM_CUSTOM_ALLOC(buf_size);
if (buf0 == NULL) {
LOG_ERR("Failed to allocate memory for rendering buffer");
return -ENOMEM;
}
#ifdef CONFIG_LV_Z_DOUBLE_VDB
buf1 = LV_MEM_CUSTOM_ALLOC(buf_size);
if (buf1 == NULL) {
LV_MEM_CUSTOM_FREE(buf0);
LOG_ERR("Failed to allocate memory for rendering buffer");
return -ENOMEM;
}
#endif
disp_driver->draw_buf = LV_MEM_CUSTOM_ALLOC(sizeof(lv_disp_draw_buf_t));
if (disp_driver->draw_buf == NULL) {
LV_MEM_CUSTOM_FREE(buf0);
LV_MEM_CUSTOM_FREE(buf1);
LOG_ERR("Failed to allocate memory to store rendering buffers");
return -ENOMEM;
}
lv_disp_draw_buf_init(disp_driver->draw_buf, buf0, buf1, buf_nbr_pixels);
return 0;
}
#endif /* CONFIG_LV_Z_BUFFER_ALLOC_STATIC */
static int lvgl_init(void)
{
const struct device *display_dev = DEVICE_DT_GET(DISPLAY_NODE);
int err = 0;
if (!device_is_ready(display_dev)) {
LOG_ERR("Display device not ready.");
return -ENODEV;
}
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
lvgl_heap_init();
#endif
#if CONFIG_LV_Z_LOG_LEVEL != 0
lv_log_register_print_cb(lvgl_log);
#endif
lv_init();
#ifdef CONFIG_LV_Z_USE_FILESYSTEM
lvgl_fs_init();
#endif
disp_data.display_dev = display_dev;
display_get_capabilities(display_dev, &disp_data.cap);
lv_disp_drv_init(&disp_drv);
disp_drv.user_data = (void *)&disp_data;
#ifdef CONFIG_LV_Z_FULL_REFRESH
disp_drv.full_refresh = 1;
#endif
err = lvgl_allocate_rendering_buffers(&disp_drv);
if (err != 0) {
return err;
}
if (set_lvgl_rendering_cb(&disp_drv) != 0) {
LOG_ERR("Display not supported.");
return -ENOTSUP;
}
if (lv_disp_drv_register(&disp_drv) == NULL) {
LOG_ERR("Failed to register display device.");
return -EPERM;
}
err = lvgl_init_input_devices();
if (err < 0) {
LOG_ERR("Failed to initialize input devices.");
return err;
}
return 0;
}
SYS_INIT(lvgl_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
``` | /content/code_sandbox/modules/lvgl/lvgl.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,758 |
```unknown
config LV_Z_SHELL
bool "LVGL Shell"
depends on SHELL
help
Enable LVGL shell for testing.
if LV_Z_SHELL
config LV_Z_MAX_MONKEY_COUNT
int "Maximum number of monkeys"
default 4
depends on LV_USE_MONKEY
help
Number of monkey instances that can exist in parallel
endif
``` | /content/code_sandbox/modules/lvgl/Kconfig.shell | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 78 |
```c
/*
*
*/
#include <zephyr/kernel.h>
#include <lvgl.h>
#include "lvgl_display.h"
void lvgl_flush_cb_16bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
uint16_t w = area->x2 - area->x1 + 1;
uint16_t h = area->y2 - area->y1 + 1;
struct lvgl_display_flush flush;
flush.disp_drv = disp_drv;
flush.x = area->x1;
flush.y = area->y1;
flush.desc.buf_size = w * 2U * h;
flush.desc.width = w;
flush.desc.pitch = w;
flush.desc.height = h;
flush.buf = (void *)color_p;
lvgl_flush_display(&flush);
}
#ifndef CONFIG_LV_COLOR_DEPTH_16
void lvgl_set_px_cb_16bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, lv_color_t color, lv_opa_t opa)
{
uint16_t *buf_xy = (uint16_t *)(buf + x * 2U + y * 2U * buf_w);
*buf_xy = lv_color_to16(color);
}
#endif
``` | /content/code_sandbox/modules/lvgl/lvgl_display_16bit.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 287 |
```unknown
menu "Memory manager settings"
config LV_Z_BITS_PER_PIXEL
int "Bits per pixel"
default 32
range 1 32
depends on LV_Z_BUFFER_ALLOC_STATIC
help
Number of bits per pixel.
choice LV_Z_MEMORY_POOL
prompt "Memory pool"
default LV_Z_MEM_POOL_SYS_HEAP
help
Memory pool to use for lvgl allocated objects
config LV_Z_MEM_POOL_HEAP_LIB_C
bool "C library Heap"
depends on !MINIMAL_LIBC || (COMMON_LIBC_MALLOC_ARENA_SIZE != 0)
help
Use C library malloc and free to allocate objects on the C library heap
config LV_Z_MEM_POOL_SYS_HEAP
bool "User space lvgl pool"
select SYS_HEAP_INFO
help
Use a dedicated memory pool from a private sys heap.
endchoice
config LV_Z_MEM_POOL_SIZE
int "Memory pool size"
default 2048
depends on LV_Z_MEM_POOL_SYS_HEAP
help
Size of the memory pool in bytes
config LV_Z_MEMORY_POOL_CUSTOM_SECTION
bool "Link memory pool to custom section"
depends on LV_Z_MEM_POOL_SYS_HEAP
help
Place LVGL memory pool in custom section, with tag ".lvgl_heap".
This can be used by custom linker scripts to relocate the LVGL
memory pool to a custom location, such as tightly coupled or
external memory.
config LV_Z_VDB_SIZE
int "Rendering buffer size"
default 100 if LV_Z_FULL_REFRESH
default 10
range 1 100
help
Size of the buffer used for rendering screen content as a percentage
of total display size.
config LV_Z_DOUBLE_VDB
bool "Use two rendering buffers"
help
Use two buffers to render and flush data in parallel
config LV_Z_FULL_REFRESH
bool "Force full refresh mode"
help
Force full refresh of display on update. When combined with
LV_Z_VDB_SIZE, this setting can improve performance for display
controllers that require a framebuffer to be present in system memory,
since the controller can render the LVGL framebuffer directly
config LV_Z_VDB_ALIGN
int "Rending buffer alignment"
default 4
depends on LV_Z_BUFFER_ALLOC_STATIC
help
Rendering buffer alignment. Depending on chosen color depth,
buffer may be accessed as a uint8_t *, uint16_t *, or uint32_t *,
so buffer must be aligned to prevent unaligned memory access
config LV_Z_VBD_CUSTOM_SECTION
bool "Link rendering buffers to custom section"
depends on LV_Z_BUFFER_ALLOC_STATIC
help
Place LVGL rendering buffers in custom section, with tag ".lvgl_buf".
This can be used by custom linker scripts to relocate the LVGL
rendering buffers to a custom location, such as tightly coupled or
external memory.
choice LV_Z_RENDERING_BUFFER_ALLOCATION
prompt "Rendering Buffer Allocation"
default LV_Z_BUFFER_ALLOC_STATIC
help
Type of allocation that should be used for allocating rendering buffers
config LV_Z_BUFFER_ALLOC_STATIC
bool "Static"
help
Rendering buffers are statically allocated based on the following
configuration parameters:
* Horizontal screen resolution
* Vertical screen resolution
* Rendering buffer size
* Bytes per pixel
config LV_Z_BUFFER_ALLOC_DYNAMIC
bool "Dynamic"
help
Rendering buffers are dynamically allocated based on the actual
display parameters
endchoice
endmenu
``` | /content/code_sandbox/modules/lvgl/Kconfig.memory | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 723 |
```c
/*
*
*/
#include <zephyr/kernel.h>
#include <lvgl.h>
#include "lvgl_display.h"
void lvgl_flush_cb_mono(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
uint16_t w = area->x2 - area->x1 + 1;
uint16_t h = area->y2 - area->y1 + 1;
struct lvgl_disp_data *data = (struct lvgl_disp_data *)disp_drv->user_data;
const struct device *display_dev = data->display_dev;
struct display_buffer_descriptor desc;
const bool is_epd = data->cap.screen_info & SCREEN_INFO_EPD;
const bool is_last = lv_disp_flush_is_last(disp_drv);
if (is_epd && !data->blanking_on && !is_last) {
/*
* Turn on display blanking when using an EPD
* display. This prevents updates and the associated
* flicker if the screen is rendered in multiple
* steps.
*/
display_blanking_on(display_dev);
data->blanking_on = true;
}
desc.buf_size = (w * h) / 8U;
desc.width = w;
desc.pitch = w;
desc.height = h;
display_write(display_dev, area->x1, area->y1, &desc, (void *)color_p);
if (data->cap.screen_info & SCREEN_INFO_DOUBLE_BUFFER) {
display_write(display_dev, area->x1, area->y1, &desc, (void *)color_p);
}
if (is_epd && is_last && data->blanking_on) {
/*
* The entire screen has now been rendered. Update the
* display by disabling blanking.
*/
display_blanking_off(display_dev);
data->blanking_on = false;
}
lv_disp_flush_ready(disp_drv);
}
void lvgl_set_px_cb_mono(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, lv_color_t color, lv_opa_t opa)
{
struct lvgl_disp_data *data = (struct lvgl_disp_data *)disp_drv->user_data;
uint8_t *buf_xy;
uint8_t bit;
if (data->cap.screen_info & SCREEN_INFO_MONO_VTILED) {
buf_xy = buf + x + y / 8 * buf_w;
if (data->cap.screen_info & SCREEN_INFO_MONO_MSB_FIRST) {
bit = 7 - y % 8;
} else {
bit = y % 8;
}
} else {
buf_xy = buf + x / 8 + y * buf_w / 8;
if (data->cap.screen_info & SCREEN_INFO_MONO_MSB_FIRST) {
bit = 7 - x % 8;
} else {
bit = x % 8;
}
}
if (data->cap.current_pixel_format == PIXEL_FORMAT_MONO10) {
if (color.full == 0) {
*buf_xy &= ~BIT(bit);
} else {
*buf_xy |= BIT(bit);
}
} else {
if (color.full == 0) {
*buf_xy |= BIT(bit);
} else {
*buf_xy &= ~BIT(bit);
}
}
}
void lvgl_rounder_cb_mono(lv_disp_drv_t *disp_drv, lv_area_t *area)
{
struct lvgl_disp_data *data = (struct lvgl_disp_data *)disp_drv->user_data;
if (data->cap.screen_info & SCREEN_INFO_X_ALIGNMENT_WIDTH) {
area->x1 = 0;
area->x2 = data->cap.x_resolution - 1;
} else {
if (data->cap.screen_info & SCREEN_INFO_MONO_VTILED) {
area->y1 &= ~0x7;
area->y2 |= 0x7;
} else {
area->x1 &= ~0x7;
area->x2 |= 0x7;
}
}
}
``` | /content/code_sandbox/modules/lvgl/lvgl_display_mono.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 897 |
```c
/*
*
*/
#include <zephyr/kernel.h>
#include <lvgl.h>
#include "lvgl_display.h"
void lvgl_flush_cb_32bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
uint16_t w = area->x2 - area->x1 + 1;
uint16_t h = area->y2 - area->y1 + 1;
struct lvgl_display_flush flush;
flush.disp_drv = disp_drv;
flush.x = area->x1;
flush.y = area->y1;
flush.desc.buf_size = w * 4U * h;
flush.desc.width = w;
flush.desc.pitch = w;
flush.desc.height = h;
flush.buf = (void *)color_p;
lvgl_flush_display(&flush);
}
#ifndef CONFIG_LV_COLOR_DEPTH_32
void lvgl_set_px_cb_32bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, lv_color_t color, lv_opa_t opa)
{
uint32_t *buf_xy = (uint32_t *)(buf + x * 4U + y * 4U * buf_w);
if (opa == LV_OPA_COVER) {
/* Do not mix if not required */
*buf_xy = lv_color_to32(color);
} else {
lv_color_t bg_color = *((lv_color_t *)buf_xy);
*buf_xy = lv_color_to32(lv_color_mix(color, bg_color, opa));
}
}
#endif
``` | /content/code_sandbox/modules/lvgl/lvgl_display_32bit.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 353 |
```unknown
config ZEPHYR_LVGL_MODULE
bool
config LVGL
bool "LVGL support"
help
This option enables the LVGL graphics library.
if LVGL
config LV_USE_MONKEY
bool
config LV_DPI_DEF
int
config LV_CONF_SKIP
bool
default n
config LV_USE_LOG
bool
config LV_LOG_LEVEL_NONE
bool
config LV_LOG_LEVEL_ERROR
bool
config LV_LOG_LEVEL_WARN
bool
config LV_LOG_LEVEL_INFO
bool
config LV_LOG_LEVEL_USER
bool
config LV_LOG_LEVEL_TRACE
bool
config LV_Z_LOG_LEVEL
int
default 0 if LV_LOG_LEVEL_NONE || !LV_USE_LOG
default 1 if LV_LOG_LEVEL_ERROR
default 2 if LV_LOG_LEVEL_WARN
default 3 if LV_LOG_LEVEL_INFO
default 3 if LV_LOG_LEVEL_USER
default 4 if LV_LOG_LEVEL_TRACE
config LV_Z_USE_ROUNDER_CB
bool
default y if LV_Z_AREA_X_ALIGNMENT_WIDTH != 1 || LV_Z_AREA_Y_ALIGNMENT_WIDTH != 1
config APP_LINK_WITH_LVGL
bool "Link 'app' with LVGL"
default y
help
Add LVGL header files to the 'app' include path. It may be
disabled if the include paths for LVGL are causing aliasing
issues for 'app'.
config LV_Z_USE_FILESYSTEM
bool "LVGL file system support"
depends on FILE_SYSTEM
default y if FILE_SYSTEM
help
Enable LittlevGL file system
choice LV_COLOR_DEPTH
default LV_COLOR_DEPTH_16
prompt "Color depth (bits per pixel)"
config LV_COLOR_DEPTH_32
bool "32: ARGB8888"
config LV_COLOR_DEPTH_16
bool "16: RGB565"
config LV_COLOR_DEPTH_8
bool "8: RGB232"
config LV_COLOR_DEPTH_1
bool "1: monochrome"
endchoice
config LV_COLOR_16_SWAP
bool
config LV_Z_FLUSH_THREAD
bool "Flush LVGL frames in a separate thread"
help
Flush LVGL frames in a separate thread, while the primary thread
renders the next LVGL frame. Can be disabled if the performance
gain this approach offers is not required
if LV_Z_FLUSH_THREAD
config LV_Z_FLUSH_THREAD_STACK_SIZE
int "Stack size for flushing thread"
default 1024
help
Stack size for LVGL flush thread, which will call display_write
config LV_Z_FLUSH_THREAD_PRIO
int "LVGL flush thread priority"
default 0
help
Cooperative priority of LVGL flush thread.
endif # LV_Z_FLUSH_THREAD
config LV_Z_AREA_X_ALIGNMENT_WIDTH
int "Frame X alignment size"
default 1
help
Number of pixels, X axis should be rounded to. Should be used to override
the current frame dimensions to meet display and/or LCD host
controller requirements. The value must be power of 2.
config LV_Z_AREA_Y_ALIGNMENT_WIDTH
int "Frame Y alignment size"
default 1
help
Number of pixels, Y axis should be rounded to. Should be used to override
the current frame dimensions to meet display and/or LCD host
controller requirements. The value must be power of 2.
config LV_USE_GPU_STM32_DMA2D
bool
config LV_GPU_DMA2D_CMSIS_INCLUDE
string
help
Must be defined to include path of CMSIS header of target processor
e.g. "stm32f769xx.h" or "stm32f429xx.h"
rsource "Kconfig.memory"
rsource "Kconfig.input"
rsource "Kconfig.shell"
endif
``` | /content/code_sandbox/modules/lvgl/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 772 |
```c
/*
*
*/
#include "lvgl_common_input.h"
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <lvgl_input_device.h>
#include "lvgl_pointer_input.h"
#include "lvgl_button_input.h"
#include "lvgl_encoder_input.h"
#include "lvgl_keypad_input.h"
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);
lv_indev_t *lvgl_input_get_indev(const struct device *dev)
{
struct lvgl_common_input_data *common_data = dev->data;
return common_data->indev;
}
static void lvgl_input_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
const struct device *dev = drv->user_data;
const struct lvgl_common_input_config *cfg = dev->config;
struct lvgl_common_input_data *common_data = dev->data;
if (k_msgq_get(cfg->event_msgq, data, K_NO_WAIT) != 0) {
memcpy(data, &common_data->previous_event, sizeof(lv_indev_data_t));
if (drv->type == LV_INDEV_TYPE_ENCODER) {
data->enc_diff = 0; /* For encoders, clear last movement */
}
data->continue_reading = false;
return;
}
memcpy(&common_data->previous_event, data, sizeof(lv_indev_data_t));
data->continue_reading = k_msgq_num_used_get(cfg->event_msgq) > 0;
}
int lvgl_input_register_driver(lv_indev_type_t indev_type, const struct device *dev)
{
/* Currently no indev binding has its dedicated data
* if that ever changes ensure that `lvgl_common_input_data`
* remains the first member
*/
struct lvgl_common_input_data *common_data = dev->data;
if (common_data == NULL) {
return -EINVAL;
}
lv_indev_drv_init(&common_data->indev_drv);
common_data->indev_drv.type = indev_type;
common_data->indev_drv.read_cb = lvgl_input_read_cb;
common_data->indev_drv.user_data = (void *)dev;
common_data->indev = lv_indev_drv_register(&common_data->indev_drv);
if (common_data->indev == NULL) {
return -EINVAL;
}
return 0;
}
#define LV_DEV_INIT(node_id, init_fn) \
do { \
int ret = init_fn(DEVICE_DT_GET(node_id)); \
if (ret) { \
return ret; \
} \
} while (0);
int lvgl_init_input_devices(void)
{
#ifdef CONFIG_LV_Z_POINTER_INPUT
DT_FOREACH_STATUS_OKAY_VARGS(zephyr_lvgl_pointer_input, LV_DEV_INIT,
lvgl_pointer_input_init);
#endif /* CONFIG_LV_Z_POINTER_INPUT */
#ifdef CONFIG_LV_Z_BUTTON_INPUT
DT_FOREACH_STATUS_OKAY_VARGS(zephyr_lvgl_button_input, LV_DEV_INIT, lvgl_button_input_init);
#endif /* CONFIG_LV_Z_BUTTON_INPUT */
#ifdef CONFIG_LV_Z_ENCODER_INPUT
DT_FOREACH_STATUS_OKAY_VARGS(zephyr_lvgl_encoder_input, LV_DEV_INIT,
lvgl_encoder_input_init);
#endif /* CONFIG_LV_Z_ENCODER_INPUT */
#ifdef CONFIG_LV_Z_KEYPAD_INPUT
DT_FOREACH_STATUS_OKAY_VARGS(zephyr_lvgl_keypad_input, LV_DEV_INIT, lvgl_keypad_input_init);
#endif /* CONFIG_LV_Z_KEYPAD_INPUT */
return 0;
}
``` | /content/code_sandbox/modules/lvgl/input/lvgl_common_input.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 763 |
```c
/*
*
*/
#define DT_DRV_COMPAT zephyr_lvgl_button_input
#include "lvgl_common_input.h"
#include "lvgl_button_input.h"
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);
struct lvgl_button_input_config {
struct lvgl_common_input_config common_config; /* Needs to be first member */
const uint16_t *input_codes;
uint8_t num_codes;
const lv_coord_t *coordinates;
};
static void lvgl_button_process_event(struct input_event *evt, void *user_data)
{
const struct device *dev = user_data;
struct lvgl_common_input_data *data = dev->data;
const struct lvgl_button_input_config *cfg = dev->config;
uint8_t i;
for (i = 0; i < cfg->num_codes; i++) {
if (evt->code == cfg->input_codes[i]) {
break;
}
}
if (i == cfg->num_codes) {
LOG_DBG("Ignored input event: %u", evt->code);
return;
}
data->pending_event.btn_id = i;
data->pending_event.state = evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
if (k_msgq_put(cfg->common_config.event_msgq, &data->pending_event, K_NO_WAIT) != 0) {
LOG_WRN("Could not put input data into queue");
}
}
int lvgl_button_input_init(const struct device *dev)
{
struct lvgl_common_input_data *data = dev->data;
const struct lvgl_button_input_config *cfg = dev->config;
int ret;
ret = lvgl_input_register_driver(LV_INDEV_TYPE_BUTTON, dev);
if (ret < 0) {
return ret;
}
lv_indev_set_button_points(data->indev, (const lv_point_t *)cfg->coordinates);
return ret;
}
#define ASSERT_PROPERTIES(inst) \
BUILD_ASSERT(DT_INST_PROP_LEN(inst, input_codes) * 2 == \
DT_INST_PROP_LEN(inst, coordinates), \
"Property coordinates must contain one coordinate per input-code.")
#define LVGL_BUTTON_INPUT_DEFINE(inst) \
ASSERT_PROPERTIES(inst); \
LVGL_INPUT_DEFINE(inst, button, CONFIG_LV_Z_BUTTON_INPUT_MSGQ_COUNT, \
lvgl_button_process_event); \
static const uint16_t lvgl_button_input_codes_##inst[] = DT_INST_PROP(inst, input_codes); \
static const lv_coord_t lvgl_button_coordinates_##inst[] = \
DT_INST_PROP(inst, coordinates); \
static const struct lvgl_button_input_config lvgl_button_input_config_##inst = { \
.common_config.event_msgq = &LVGL_INPUT_EVENT_MSGQ(inst, button), \
.input_codes = lvgl_button_input_codes_##inst, \
.num_codes = DT_INST_PROP_LEN(inst, input_codes), \
.coordinates = lvgl_button_coordinates_##inst, \
}; \
static struct lvgl_common_input_data lvgl_common_input_data_##inst; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_common_input_data_##inst, \
&lvgl_button_input_config_##inst, POST_KERNEL, \
CONFIG_INPUT_INIT_PRIORITY, NULL);
DT_INST_FOREACH_STATUS_OKAY(LVGL_BUTTON_INPUT_DEFINE)
``` | /content/code_sandbox/modules/lvgl/input/lvgl_button_input.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 714 |
```c
/*
*
*/
#include <lvgl.h>
#include <zephyr/kernel.h>
#include <zephyr/fs/fs.h>
#include "lvgl_fs.h"
#include "lv_conf.h"
#include LV_MEM_CUSTOM_INCLUDE
static bool lvgl_fs_ready(struct _lv_fs_drv_t *drv)
{
return true;
}
static lv_fs_res_t errno_to_lv_fs_res(int err)
{
switch (err) {
case 0:
return LV_FS_RES_OK;
case -EIO:
/*Low level hardware error*/
return LV_FS_RES_HW_ERR;
case -EBADF:
/*Error in the file system structure */
return LV_FS_RES_FS_ERR;
case -ENOENT:
/*Driver, file or directory is not exists*/
return LV_FS_RES_NOT_EX;
case -EFBIG:
/*Disk full*/
return LV_FS_RES_FULL;
case -EACCES:
/*Access denied. Check 'fs_open' modes and write protect*/
return LV_FS_RES_DENIED;
case -EBUSY:
/*The file system now can't handle it, try later*/
return LV_FS_RES_BUSY;
case -ENOMEM:
/*Not enough memory for an internal operation*/
return LV_FS_RES_OUT_OF_MEM;
case -EINVAL:
/*Invalid parameter among arguments*/
return LV_FS_RES_INV_PARAM;
case -ENOTSUP:
/*Not supported by the filesystem*/
return LV_FS_RES_NOT_IMP;
default:
return LV_FS_RES_UNKNOWN;
}
}
static void *lvgl_fs_open(struct _lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode)
{
int err;
int zmode = FS_O_CREATE;
void *file;
/* LVGL is passing absolute paths without the root slash add it back
* by decrementing the path pointer.
*/
path--;
zmode |= (mode & LV_FS_MODE_WR) ? FS_O_WRITE : 0;
zmode |= (mode & LV_FS_MODE_RD) ? FS_O_READ : 0;
file = LV_MEM_CUSTOM_ALLOC(sizeof(struct fs_file_t));
if (!file) {
return NULL;
}
fs_file_t_init((struct fs_file_t *)file);
err = fs_open((struct fs_file_t *)file, path, zmode);
if (err) {
LV_MEM_CUSTOM_FREE(file);
return NULL;
}
return file;
}
static lv_fs_res_t lvgl_fs_close(struct _lv_fs_drv_t *drv, void *file)
{
int err;
err = fs_close((struct fs_file_t *)file);
LV_MEM_CUSTOM_FREE(file);
return errno_to_lv_fs_res(err);
}
static lv_fs_res_t lvgl_fs_read(struct _lv_fs_drv_t *drv, void *file, void *buf, uint32_t btr,
uint32_t *br)
{
int err;
err = fs_read((struct fs_file_t *)file, buf, btr);
if (err > 0) {
if (br != NULL) {
*br = err;
}
err = 0;
} else if (br != NULL) {
*br = 0U;
}
return errno_to_lv_fs_res(err);
}
static lv_fs_res_t lvgl_fs_write(struct _lv_fs_drv_t *drv, void *file, const void *buf,
uint32_t btw, uint32_t *bw)
{
int err;
err = fs_write((struct fs_file_t *)file, buf, btw);
if (err == btw) {
if (bw != NULL) {
*bw = btw;
}
err = 0;
} else if (err < 0) {
if (bw != NULL) {
*bw = 0U;
}
} else {
if (bw != NULL) {
*bw = err;
}
err = -EFBIG;
}
return errno_to_lv_fs_res(err);
}
static lv_fs_res_t lvgl_fs_seek(struct _lv_fs_drv_t *drv, void *file, uint32_t pos,
lv_fs_whence_t whence)
{
int err, fs_whence;
switch (whence) {
case LV_FS_SEEK_END:
fs_whence = FS_SEEK_END;
break;
case LV_FS_SEEK_CUR:
fs_whence = FS_SEEK_CUR;
break;
case LV_FS_SEEK_SET:
default:
fs_whence = FS_SEEK_SET;
break;
}
err = fs_seek((struct fs_file_t *)file, pos, fs_whence);
return errno_to_lv_fs_res(err);
}
static lv_fs_res_t lvgl_fs_tell(struct _lv_fs_drv_t *drv, void *file, uint32_t *pos_p)
{
off_t pos;
pos = fs_tell((struct fs_file_t *)file);
if (pos < 0) {
return errno_to_lv_fs_res(pos);
}
*pos_p = pos;
return LV_FS_RES_OK;
}
static void *lvgl_fs_dir_open(struct _lv_fs_drv_t *drv, const char *path)
{
void *dir;
int err;
/* LVGL is passing absolute paths without the root slash add it back
* by decrementing the path pointer.
*/
path--;
dir = LV_MEM_CUSTOM_ALLOC(sizeof(struct fs_dir_t));
if (!dir) {
return NULL;
}
fs_dir_t_init((struct fs_dir_t *)dir);
err = fs_opendir((struct fs_dir_t *)dir, path);
if (err) {
LV_MEM_CUSTOM_FREE(dir);
return NULL;
}
return dir;
}
static lv_fs_res_t lvgl_fs_dir_read(struct _lv_fs_drv_t *drv, void *dir, char *fn)
{
/* LVGL expects a string as return parameter but the format of the
* string is not documented.
*/
return LV_FS_RES_NOT_IMP;
}
static lv_fs_res_t lvgl_fs_dir_close(struct _lv_fs_drv_t *drv, void *dir)
{
int err;
err = fs_closedir((struct fs_dir_t *)dir);
LV_MEM_CUSTOM_FREE(dir);
return errno_to_lv_fs_res(err);
}
static lv_fs_drv_t fs_drv;
void lvgl_fs_init(void)
{
lv_fs_drv_init(&fs_drv);
/* LVGL uses letter based mount points, just pass the root slash as a
* letter. Note that LVGL will remove the drive letter, or in this case
* the root slash, from the path passed via the FS callbacks.
* Zephyr FS API assumes this slash is present so we will need to add
* it back.
*/
fs_drv.letter = '/';
fs_drv.ready_cb = lvgl_fs_ready;
fs_drv.open_cb = lvgl_fs_open;
fs_drv.close_cb = lvgl_fs_close;
fs_drv.read_cb = lvgl_fs_read;
fs_drv.write_cb = lvgl_fs_write;
fs_drv.seek_cb = lvgl_fs_seek;
fs_drv.tell_cb = lvgl_fs_tell;
fs_drv.dir_open_cb = lvgl_fs_dir_open;
fs_drv.dir_read_cb = lvgl_fs_dir_read;
fs_drv.dir_close_cb = lvgl_fs_dir_close;
lv_fs_drv_register(&fs_drv);
}
``` | /content/code_sandbox/modules/lvgl/lvgl_fs.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,539 |
```c
/*
*
*/
#define DT_DRV_COMPAT zephyr_lvgl_encoder_input
#include "lvgl_common_input.h"
#include "lvgl_encoder_input.h"
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);
struct lvgl_encoder_input_config {
struct lvgl_common_input_config common_config; /* Needs to be first member */
int rotation_input_code;
int button_input_code;
};
static void lvgl_encoder_process_event(struct input_event *evt, void *user_data)
{
const struct device *dev = user_data;
struct lvgl_common_input_data *data = dev->data;
const struct lvgl_encoder_input_config *cfg = dev->config;
if (evt->code == cfg->rotation_input_code) {
data->pending_event.enc_diff = evt->value;
} else if (evt->code == cfg->button_input_code) {
data->pending_event.state = evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
data->pending_event.enc_diff = 0;
data->pending_event.key = LV_KEY_ENTER;
} else {
LOG_DBG("Ignored input event: %u", evt->code);
return;
}
if (k_msgq_put(cfg->common_config.event_msgq, &data->pending_event, K_NO_WAIT) != 0) {
LOG_WRN("Could not put input data into queue");
}
}
int lvgl_encoder_input_init(const struct device *dev)
{
return lvgl_input_register_driver(LV_INDEV_TYPE_ENCODER, dev);
}
#define BUTTON_CODE(inst) DT_INST_PROP_OR(inst, button_input_code, -1)
#define ROTATION_CODE(inst) DT_INST_PROP(inst, rotation_input_code)
#define ASSERT_PROPERTIES(inst) \
BUILD_ASSERT(IN_RANGE(ROTATION_CODE(inst), 0, 65536), \
"Property rotation-input-code needs to be between 0 and 65536."); \
BUILD_ASSERT(!DT_INST_NODE_HAS_PROP(inst, button_input_code) || \
IN_RANGE(BUTTON_CODE(inst), 0, 65536), \
"Property button-input-code needs to be between 0 and 65536."); \
BUILD_ASSERT(ROTATION_CODE(inst) != BUTTON_CODE(inst), \
"Property rotation-input-code and button-input-code should not be equal.")
#define LVGL_ENCODER_INPUT_DEFINE(inst) \
ASSERT_PROPERTIES(inst); \
LVGL_INPUT_DEFINE(inst, encoder, CONFIG_LV_Z_ENCODER_INPUT_MSGQ_COUNT, \
lvgl_encoder_process_event); \
static const struct lvgl_encoder_input_config lvgl_encoder_input_config_##inst = { \
.common_config.event_msgq = &LVGL_INPUT_EVENT_MSGQ(inst, encoder), \
.rotation_input_code = ROTATION_CODE(inst), \
.button_input_code = BUTTON_CODE(inst), \
}; \
static struct lvgl_common_input_data lvgl_common_input_data_##inst; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_common_input_data_##inst, \
&lvgl_encoder_input_config_##inst, POST_KERNEL, \
CONFIG_INPUT_INIT_PRIORITY, NULL);
DT_INST_FOREACH_STATUS_OKAY(LVGL_ENCODER_INPUT_DEFINE)
``` | /content/code_sandbox/modules/lvgl/input/lvgl_encoder_input.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 689 |
```c
/*
*
*/
#define DT_DRV_COMPAT zephyr_lvgl_pointer_input
#include "lvgl_common_input.h"
#include "lvgl_pointer_input.h"
#include <lvgl_display.h>
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);
struct lvgl_pointer_input_config {
struct lvgl_common_input_config common_config; /* Needs to be first member */
bool swap_xy;
bool invert_x;
bool invert_y;
};
struct lvgl_pointer_input_data {
struct lvgl_common_input_data common_data;
uint32_t point_x;
uint32_t point_y;
};
static void lvgl_pointer_process_event(struct input_event *evt, void *user_data)
{
const struct device *dev = user_data;
const struct lvgl_pointer_input_config *cfg = dev->config;
struct lvgl_pointer_input_data *data = dev->data;
lv_disp_t *disp = lv_disp_get_default();
struct lvgl_disp_data *disp_data = disp->driver->user_data;
struct display_capabilities *cap = &disp_data->cap;
lv_point_t *point = &data->common_data.pending_event.point;
switch (evt->code) {
case INPUT_ABS_X:
if (cfg->swap_xy) {
data->point_y = evt->value;
} else {
data->point_x = evt->value;
}
break;
case INPUT_ABS_Y:
if (cfg->swap_xy) {
data->point_x = evt->value;
} else {
data->point_y = evt->value;
}
break;
case INPUT_BTN_TOUCH:
data->common_data.pending_event.state =
evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
break;
}
if (!evt->sync) {
return;
}
lv_point_t tmp_point = {
.x = data->point_x,
.y = data->point_y,
};
if (cfg->invert_x) {
if (cap->current_orientation == DISPLAY_ORIENTATION_NORMAL ||
cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
tmp_point.x = cap->x_resolution - tmp_point.x;
} else {
tmp_point.x = cap->y_resolution - tmp_point.x;
}
}
if (cfg->invert_y) {
if (cap->current_orientation == DISPLAY_ORIENTATION_NORMAL ||
cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
tmp_point.y = cap->y_resolution - tmp_point.y;
} else {
tmp_point.y = cap->x_resolution - tmp_point.y;
}
}
/* rotate touch point to match display rotation */
switch (cap->current_orientation) {
case DISPLAY_ORIENTATION_NORMAL:
point->x = tmp_point.x;
point->y = tmp_point.y;
break;
case DISPLAY_ORIENTATION_ROTATED_90:
point->x = tmp_point.y;
point->y = cap->y_resolution - tmp_point.x;
break;
case DISPLAY_ORIENTATION_ROTATED_180:
point->x = cap->x_resolution - tmp_point.x;
point->y = cap->y_resolution - tmp_point.y;
break;
case DISPLAY_ORIENTATION_ROTATED_270:
point->x = cap->x_resolution - tmp_point.y;
point->y = tmp_point.x;
break;
default:
LOG_ERR("Invalid display orientation");
break;
}
/* filter readings within display */
if (point->x <= 0) {
point->x = 0;
} else if (point->x >= cap->x_resolution) {
point->x = cap->x_resolution - 1;
}
if (point->y <= 0) {
point->y = 0;
} else if (point->y >= cap->y_resolution) {
point->y = cap->y_resolution - 1;
}
if (k_msgq_put(cfg->common_config.event_msgq, &data->common_data.pending_event,
K_NO_WAIT) != 0) {
LOG_WRN("Could not put input data into queue");
}
}
int lvgl_pointer_input_init(const struct device *dev)
{
return lvgl_input_register_driver(LV_INDEV_TYPE_POINTER, dev);
}
#define LVGL_POINTER_INPUT_DEFINE(inst) \
LVGL_INPUT_DEFINE(inst, pointer, CONFIG_LV_Z_POINTER_INPUT_MSGQ_COUNT, \
lvgl_pointer_process_event); \
static const struct lvgl_pointer_input_config lvgl_pointer_input_config_##inst = { \
.common_config.event_msgq = &LVGL_INPUT_EVENT_MSGQ(inst, pointer), \
.swap_xy = DT_INST_PROP(inst, swap_xy), \
.invert_x = DT_INST_PROP(inst, invert_x), \
.invert_y = DT_INST_PROP(inst, invert_y), \
}; \
static struct lvgl_pointer_input_data lvgl_pointer_input_data_##inst; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_pointer_input_data_##inst, \
&lvgl_pointer_input_config_##inst, POST_KERNEL, \
CONFIG_INPUT_INIT_PRIORITY, NULL);
DT_INST_FOREACH_STATUS_OKAY(LVGL_POINTER_INPUT_DEFINE)
``` | /content/code_sandbox/modules/lvgl/input/lvgl_pointer_input.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,109 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_LVGL_BUTTON_INPUT_H_
#define ZEPHYR_MODULES_LVGL_LVGL_BUTTON_INPUT_H_
#include <zephyr/device.h>
#ifdef __cplusplus
extern "C" {
#endif
int lvgl_button_input_init(const struct device *dev);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_MODULES_LVGL_LVGL_BUTTON_INPUT_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_button_input.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 92 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_FS_H_
#define ZEPHYR_MODULES_LVGL_FS_H_
#ifdef __cplusplus
extern "C" {
#endif
void lvgl_fs_init(void);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_MODULES_LVGL_FS_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_fs.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 67 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_INPUT_DEVICE_H_
#define ZEPHYR_MODULES_LVGL_INPUT_DEVICE_H_
#include <zephyr/device.h>
#include <lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
lv_indev_t *lvgl_input_get_indev(const struct device *dev);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_MODULES_LVGL_INPUT_DEVICE_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_input_device.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 94 |
```c
/*
*
*/
#define DT_DRV_COMPAT zephyr_lvgl_keypad_input
#include "lvgl_common_input.h"
#include "lvgl_keypad_input.h"
#include <zephyr/sys/util.h>
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);
struct lvgl_keypad_input_config {
struct lvgl_common_input_config common_config; /* Needs to be first member */
const uint16_t *input_codes;
const uint16_t *lvgl_codes;
uint8_t num_codes;
};
static void lvgl_keypad_process_event(struct input_event *evt, void *user_data)
{
const struct device *dev = user_data;
struct lvgl_common_input_data *data = dev->data;
const struct lvgl_keypad_input_config *cfg = dev->config;
uint8_t i;
for (i = 0; i < cfg->num_codes; i++) {
if (evt->code == cfg->input_codes[i]) {
data->pending_event.key = cfg->lvgl_codes[i];
break;
}
}
if (i == cfg->num_codes) {
LOG_WRN("Ignored input event: %u", evt->code);
return;
}
data->pending_event.state = evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
if (k_msgq_put(cfg->common_config.event_msgq, &data->pending_event, K_NO_WAIT) != 0) {
LOG_WRN("Could not put input data into keypad queue");
}
}
int lvgl_keypad_input_init(const struct device *dev)
{
return lvgl_input_register_driver(LV_INDEV_TYPE_KEYPAD, dev);
}
#define ASSERT_PROPERTIES(inst) \
BUILD_ASSERT(DT_INST_PROP_LEN(inst, input_codes) == DT_INST_PROP_LEN(inst, lvgl_codes), \
"Property input-codes must have the same length as lvgl-codes.");
#define LVGL_KEYPAD_INPUT_DEFINE(inst) \
ASSERT_PROPERTIES(inst); \
LVGL_INPUT_DEFINE(inst, keypad, CONFIG_LV_Z_KEYPAD_INPUT_MSGQ_COUNT, \
lvgl_keypad_process_event); \
static const uint16_t lvgl_keypad_input_codes_##inst[] = DT_INST_PROP(inst, input_codes); \
static const uint16_t lvgl_keypad_lvgl_codes_##inst[] = DT_INST_PROP(inst, lvgl_codes); \
static const struct lvgl_keypad_input_config lvgl_keypad_input_config_##inst = { \
.common_config.event_msgq = &LVGL_INPUT_EVENT_MSGQ(inst, keypad), \
.input_codes = lvgl_keypad_input_codes_##inst, \
.lvgl_codes = lvgl_keypad_lvgl_codes_##inst, \
.num_codes = DT_INST_PROP_LEN(inst, input_codes), \
}; \
static struct lvgl_common_input_data lvgl_common_input_data_##inst; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_common_input_data_##inst, \
&lvgl_keypad_input_config_##inst, POST_KERNEL, \
CONFIG_INPUT_INIT_PRIORITY, NULL);
DT_INST_FOREACH_STATUS_OKAY(LVGL_KEYPAD_INPUT_DEFINE)
``` | /content/code_sandbox/modules/lvgl/input/lvgl_keypad_input.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 685 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_LVGL_ENCODER_INPUT_H_
#define ZEPHYR_MODULES_LVGL_LVGL_ENCODER_INPUT_H_
#include <zephyr/device.h>
#ifdef __cplusplus
extern "C" {
#endif
int lvgl_encoder_input_init(const struct device *dev);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_MODULES_LVGL_LVGL_ENCODER_INPUT_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_encoder_input.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 95 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_LVGL_POINTER_INPUT_H_
#define ZEPHYR_MODULES_LVGL_LVGL_POINTER_INPUT_H_
#include <zephyr/device.h>
#ifdef __cplusplus
extern "C" {
#endif
int lvgl_pointer_input_init(const struct device *dev);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_MODULES_LVGL_LVGL_POINTER_INPUT_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_pointer_input.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 92 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_LVGL_COMMON_INPUT_H_
#define ZEPHYR_MODULES_LVGL_LVGL_COMMON_INPUT_H_
#include <lvgl.h>
#include <zephyr/device.h>
#include <zephyr/input/input.h>
#ifdef __cplusplus
extern "C" {
#endif
struct lvgl_common_input_config {
struct k_msgq *event_msgq;
};
struct lvgl_common_input_data {
lv_indev_drv_t indev_drv;
lv_indev_t *indev;
lv_indev_data_t pending_event;
lv_indev_data_t previous_event;
};
int lvgl_input_register_driver(lv_indev_type_t indev_type, const struct device *dev);
int lvgl_init_input_devices(void);
#define LVGL_INPUT_EVENT_MSGQ(inst, type) lvgl_input_msgq_##type##_##inst
#define LVGL_INPUT_DEVICE(inst) DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(inst, input))
#define LVGL_COORD_VALID(coord) IN_RANGE(coord, LV_COORD_MIN, LV_COORD_MAX)
#define LVGL_KEY_VALID(key) IN_RANGE(key, 0, UINT8_MAX)
#define LVGL_INPUT_DEFINE(inst, type, msgq_size, process_evt_cb) \
INPUT_CALLBACK_DEFINE(LVGL_INPUT_DEVICE(inst), process_evt_cb, \
(void *)DEVICE_DT_INST_GET(inst)); \
K_MSGQ_DEFINE(lvgl_input_msgq_##type##_##inst, sizeof(lv_indev_data_t), msgq_size, 4)
#ifdef __cplusplus
}
#endif
/** @} */
#endif /* ZEPHYR_MODULES_LVGL_LVGL_COMMON_INPUT_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_common_input.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 351 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_LVGL_KEYPAD_INPUT_H_
#define ZEPHYR_MODULES_LVGL_LVGL_KEYPAD_INPUT_H_
#include <zephyr/device.h>
#ifdef __cplusplus
extern "C" {
#endif
int lvgl_keypad_input_init(const struct device *dev);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_MODULES_LVGL_LVGL_KEYPAD_INPUT_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_keypad_input.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 96 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_MEM_H_
#define ZEPHYR_MODULES_LVGL_MEM_H_
#include <stdlib.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
void *lvgl_malloc(size_t size);
void *lvgl_realloc(void *ptr, size_t size);
void lvgl_free(void *ptr);
void lvgl_print_heap_info(bool dump_chunks);
void lvgl_heap_init(void);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_MODULES_LVGL_MEM_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_mem.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 118 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_LV_CONF_H_
#define ZEPHYR_MODULES_LVGL_LV_CONF_H_
/* Memory manager settings */
#define LV_MEMCPY_MEMSET_STD 1
#define LV_MEM_CUSTOM 1
#if defined(CONFIG_LV_Z_MEM_POOL_HEAP_LIB_C)
#define LV_MEM_CUSTOM_INCLUDE "stdlib.h"
#define LV_MEM_CUSTOM_ALLOC malloc
#define LV_MEM_CUSTOM_REALLOC realloc
#define LV_MEM_CUSTOM_FREE free
#else
#define LV_MEM_CUSTOM_INCLUDE "lvgl_mem.h"
#define LV_MEM_CUSTOM_ALLOC lvgl_malloc
#define LV_MEM_CUSTOM_REALLOC lvgl_realloc
#define LV_MEM_CUSTOM_FREE lvgl_free
#endif
/* HAL settings */
#define LV_TICK_CUSTOM 1
#define LV_TICK_CUSTOM_INCLUDE <zephyr/kernel.h>
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (k_uptime_get_32())
/* Misc settings */
#define LV_SPRINTF_CUSTOM 1
#define LV_SPRINTF_INCLUDE "stdio.h"
#define lv_snprintf snprintf
#define lv_vsnprintf vsnprintf
/*
* Needed because of a workaround for a GCC bug,
* see path_to_url
*/
#define LV_CONF_SUPPRESS_DEFINE_CHECK 1
#endif /* ZEPHYR_MODULES_LVGL_LV_CONF_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lv_conf.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 271 |
```c
/*
* lfs util functions
*
*/
#include "lfs_util.h"
/* Use the LFS naive CRC implementation until it has been decided which CRC to
* use for LittleFS.
*/
/* Software CRC implementation with small lookup table */
uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size)
{
static const uint32_t rtable[16] = {
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c,
};
const uint8_t *data = buffer;
for (size_t i = 0; i < size; i++) {
crc = (crc >> 4) ^ rtable[(crc ^ (data[i] >> 0)) & 0xf];
crc = (crc >> 4) ^ rtable[(crc ^ (data[i] >> 4)) & 0xf];
}
return crc;
}
``` | /content/code_sandbox/modules/littlefs/zephyr_lfs_crc.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 318 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_LVGL_DISPLAY_H_
#define ZEPHYR_MODULES_LVGL_DISPLAY_H_
#include <zephyr/drivers/display.h>
#include <lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
struct lvgl_disp_data {
const struct device *display_dev;
struct display_capabilities cap;
bool blanking_on;
};
struct lvgl_display_flush {
lv_disp_drv_t *disp_drv;
uint16_t x;
uint16_t y;
struct display_buffer_descriptor desc;
void *buf;
};
void lvgl_flush_cb_mono(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
void lvgl_flush_cb_16bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
void lvgl_flush_cb_24bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
void lvgl_flush_cb_32bit(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
void lvgl_set_px_cb_mono(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, lv_color_t color, lv_opa_t opa);
void lvgl_set_px_cb_16bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, lv_color_t color, lv_opa_t opa);
void lvgl_set_px_cb_24bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, lv_color_t color, lv_opa_t opa);
void lvgl_set_px_cb_32bit(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y, lv_color_t color, lv_opa_t opa);
void lvgl_rounder_cb_mono(lv_disp_drv_t *disp_drv, lv_area_t *area);
int set_lvgl_rendering_cb(lv_disp_drv_t *disp_drv);
void lvgl_flush_display(struct lvgl_display_flush *request);
#ifdef CONFIG_LV_Z_USE_ROUNDER_CB
void lvgl_rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area);
#endif
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_MODULES_LVGL_DISPLAY_H_ */
``` | /content/code_sandbox/modules/lvgl/include/lvgl_display.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 553 |
```unknown
config ZEPHYR_LITTLEFS_MODULE
bool
# Configuration of LittleFS is found in subsys/fs/Kconfig.littlefs for historic
# reasons.
``` | /content/code_sandbox/modules/littlefs/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 36 |
```cmake
#
include_guard(GLOBAL)
set(NANOPB_SRC_ROOT_FOLDER ${ZEPHYR_NANOPB_MODULE_DIR})
list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_NANOPB_MODULE_DIR}/extra)
find_package(Nanopb REQUIRED)
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
message(FATAL_ERROR "'protoc' not found, please ensure protoc is installed\
and in path. See path_to_url")
else()
message(STATUS "Found protoc: ${PROTOBUF_PROTOC_EXECUTABLE}")
endif()
add_custom_target(nanopb_generated_headers)
# Usage:
# list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
# include(nanopb)
#
# zephyr_nanopb_sources(<target> <proto-files>)
#
# Generate source and header files from provided .proto files and
# add these as sources to the specified target.
function(zephyr_nanopb_sources target)
# Turn off the default nanopb behavior
set(NANOPB_GENERATE_CPP_STANDALONE OFF)
nanopb_generate_cpp(proto_srcs proto_hdrs RELPATH ${CMAKE_CURRENT_SOURCE_DIR} ${ARGN})
target_include_directories(${target} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_sources(${target} PRIVATE ${proto_srcs} ${proto_hdrs})
# Create unique target name for generated header list
string(MD5 unique_chars "${proto_hdrs}")
set(gen_target_name ${target}_proto_${unique_chars})
add_custom_target(${gen_target_name} DEPENDS ${proto_hdrs})
add_dependencies(nanopb_generated_headers ${gen_target_name})
endfunction()
``` | /content/code_sandbox/modules/nanopb/nanopb.cmake | cmake | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 364 |
```unknown
config ZEPHYR_NANOPB_MODULE
bool
menuconfig NANOPB
bool "Nanopb Support"
# Nanopb requires c_std_11 compiler features like _Static_assert
select REQUIRES_STD_C11
help
This option enables the Nanopb library and generator.
if NANOPB
config NANOPB_ENABLE_MALLOC
bool "Malloc usage"
help
This option enables dynamic allocation support in the decoder.
config NANOPB_MAX_REQUIRED_FIELDS
int "Max number of required fields"
default 64
help
Maximum number of proto2 required fields to check for presence.
Default and minimum value is 64.
config NANOPB_NO_ERRMSG
bool "Disable error messages"
help
Disable error message support to save code size. Only error
information is the true/false return value.
config NANOPB_BUFFER_ONLY
bool "Buffers only"
help
Disable support for custom streams. Only supports encoding and
decoding with memory buffers. Speeds up execution and slightly
decreases code size.
config NANOPB_WITHOUT_64BIT
bool "Disable 64-bit integer fields"
help
Disable support of 64-bit integer fields, for old compilers or
for a slight speedup on 8-bit platforms.
config NANOPB_ENCODE_ARRAYS_UNPACKED
bool "Encode arrays unpacked"
help
Encode scalar arrays in the unpacked format, which takes up more
space.
Only to be used when the decoder on the receiving side cannot
process packed arrays, such as protobuf.js versions before 2020.
config NANOPB_VALIDATE_UTF8
bool "Validate UTF-8"
help
Check whether incoming strings are valid UTF-8 sequences.
Adds a small performance and code size penalty.
endif # NANOPB
``` | /content/code_sandbox/modules/nanopb/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 383 |
```unknown
menu "ACPI driver support"
config ACPI
bool
if ACPI
config ACPI_DSDT_SUPPORT
bool "Build source code for DSDT ACPICA support"
default y if PCIE
help
Build source code for DSDT support
endif #ACPI
endmenu
``` | /content/code_sandbox/modules/acpica/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 65 |
```unknown
config ZEPHYR_TFLITE-MICRO_MODULE
bool
config TENSORFLOW_LITE_MICRO
bool "TensorFlow Lite Micro Support"
select REQUIRES_FULL_LIBCPP
help
This option enables the TensorFlow Lite Micro library.
if CPU_CORTEX_M
config TENSORFLOW_LITE_MICRO_CMSIS_NN_KERNELS
bool "TensorFlow Lite Micro with optimized CMSIS-NN kernels"
depends on TENSORFLOW_LITE_MICRO
select CMSIS_NN
select CMSIS_NN_ACTIVATION
select CMSIS_NN_BASICMATH
select CMSIS_NN_CONCATENATION
select CMSIS_NN_CONVOLUTION
select CMSIS_NN_FULLYCONNECTED
select CMSIS_NN_NNSUPPORT
select CMSIS_NN_POOLING
select CMSIS_NN_RESHAPE
select CMSIS_NN_SOFTMAX
select CMSIS_NN_SVD
select CMSIS_NN_LSTM
help
This option adds support for CMSIS-NN optimized kernels when using TensorFlow Lite Micro.
endif # CPU_CORTEX_M
``` | /content/code_sandbox/modules/tflite-micro/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 228 |
```objective-c
/*
*
*
* Origin of this file is the LittleFS lfs_util.h file adjusted for Zephyr
* specific needs.
*/
#ifndef ZEPHYR_LFS_CONFIG_H
#define ZEPHYR_LFS_CONFIG_H
/* System includes */
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
#ifndef LFS_NO_MALLOC
#include <stdlib.h>
#endif
#ifndef LFS_NO_ASSERT
#include <zephyr/sys/__assert.h>
#endif
#if !defined(LFS_NO_DEBUG) || \
!defined(LFS_NO_WARN) || \
!defined(LFS_NO_ERROR) || \
defined(LFS_YES_TRACE)
#include <zephyr/logging/log.h>
#ifdef LFS_LOG_REGISTER
LOG_MODULE_REGISTER(littlefs, CONFIG_FS_LOG_LEVEL);
#endif
#include <stdio.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
/* Logging functions when using LittleFS with Zephyr. */
#ifndef LFS_TRACE
#ifdef LFS_YES_TRACE
#define LFS_TRACE(fmt, ...) LOG_DBG("%s:%d:trace: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define LFS_TRACE(...)
#endif
#endif
#ifndef LFS_DEBUG
#define LFS_DEBUG(fmt, ...) LOG_DBG("%s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#endif
#ifndef LFS_WARN
#define LFS_WARN(fmt, ...) LOG_WRN("%s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#endif
#ifndef LFS_ERROR
#define LFS_ERROR(fmt, ...) LOG_ERR("%s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#endif
/* Runtime assertions */
#ifndef LFS_ASSERT
#define LFS_ASSERT(test) __ASSERT_NO_MSG(test)
#endif
/* Builtin functions, these may be replaced by more efficient */
/* toolchain-specific implementations. LFS_NO_INTRINSICS falls back to a more */
/* expensive basic C implementation for debugging purposes */
/* Min/max functions for unsigned 32-bit numbers */
static inline uint32_t lfs_max(uint32_t a, uint32_t b)
{
return (a > b) ? a : b;
}
static inline uint32_t lfs_min(uint32_t a, uint32_t b)
{
return (a < b) ? a : b;
}
/* Align to nearest multiple of a size */
static inline uint32_t lfs_aligndown(uint32_t a, uint32_t alignment)
{
return a - (a % alignment);
}
static inline uint32_t lfs_alignup(uint32_t a, uint32_t alignment)
{
return lfs_aligndown(a + alignment-1, alignment);
}
/* Find the smallest power of 2 greater than or equal to a */
static inline uint32_t lfs_npw2(uint32_t a)
{
#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM))
return 32 - __builtin_clz(a-1);
#else
uint32_t r = 0;
uint32_t s;
a -= 1;
s = (a > 0xffff) << 4; a >>= s; r |= s;
s = (a > 0xff) << 3; a >>= s; r |= s;
s = (a > 0xf) << 2; a >>= s; r |= s;
s = (a > 0x3) << 1; a >>= s; r |= s;
return (r | (a >> 1)) + 1;
#endif
}
/* Count the number of trailing binary zeros in a */
/* lfs_ctz(0) may be undefined */
static inline uint32_t lfs_ctz(uint32_t a)
{
#if !defined(LFS_NO_INTRINSICS) && defined(__GNUC__)
return __builtin_ctz(a);
#else
return lfs_npw2((a & -a) + 1) - 1;
#endif
}
/* Count the number of binary ones in a */
static inline uint32_t lfs_popc(uint32_t a)
{
#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM))
return __builtin_popcount(a);
#else
a = a - ((a >> 1) & 0x55555555);
a = (a & 0x33333333) + ((a >> 2) & 0x33333333);
return (((a + (a >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24;
#endif
}
/* Find the sequence comparison of a and b, this is the distance */
/* between a and b ignoring overflow */
static inline int lfs_scmp(uint32_t a, uint32_t b)
{
return (int)(unsigned int)(a - b);
}
/* Convert between 32-bit little-endian and native order */
static inline uint32_t lfs_fromle32(uint32_t a)
{
#if defined(CONFIG_LITTLE_ENDIAN)
return a;
#elif !defined(LFS_NO_INTRINSICS)
return __builtin_bswap32(a);
#else
return (((uint8_t *)&a)[0] << 0) |
(((uint8_t *)&a)[1] << 8) |
(((uint8_t *)&a)[2] << 16) |
(((uint8_t *)&a)[3] << 24);
#endif
}
static inline uint32_t lfs_tole32(uint32_t a)
{
return lfs_fromle32(a);
}
/* Convert between 32-bit big-endian and native order */
static inline uint32_t lfs_frombe32(uint32_t a)
{
#if defined(CONFIG_BIG_ENDIAN)
return a;
#elif !defined(LFS_NO_INTRINSICS)
return __builtin_bswap32(a);
#else
return (((uint8_t *)&a)[0] << 24) |
(((uint8_t *)&a)[1] << 16) |
(((uint8_t *)&a)[2] << 8) |
(((uint8_t *)&a)[3] << 0);
#endif
}
static inline uint32_t lfs_tobe32(uint32_t a)
{
return lfs_frombe32(a);
}
/* Calculate CRC-32 with polynomial = 0x04c11db7 */
uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size);
/* Allocate memory, only used if buffers are not provided to littlefs */
/* Note, memory must be 64-bit aligned */
static inline void *lfs_malloc(size_t size)
{
#ifndef LFS_NO_MALLOC
return malloc(size);
#else
(void)size;
return NULL;
#endif
}
/* Deallocate memory, only used if buffers are not provided to littlefs */
static inline void lfs_free(void *p)
{
#ifndef LFS_NO_MALLOC
free(p);
#else
(void)p;
#endif
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* ZEPHYR_LFS_CONFIG_H */
``` | /content/code_sandbox/modules/littlefs/zephyr_lfs_config.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,495 |
```unknown
config ZEPHYR_THRIFT_MODULE
bool
menuconfig THRIFT
bool "Support for Thrift [EXPERIMENTAL]"
select EXPERIMENTAL
depends on CPP
depends on STD_CPP17
depends on CPP_EXCEPTIONS
depends on POSIX_API
help
Enable this option to support Apache Thrift
if THRIFT
config THRIFT_SSL_SOCKET
bool "TSSLSocket support for Thrift"
depends on MBEDTLS
depends on MBEDTLS_PEM_CERTIFICATE_FORMAT
depends on NET_SOCKETS_SOCKOPT_TLS
help
Enable this option to support TSSLSocket for Thrift
module = THRIFT
module-str = THRIFT
source "subsys/logging/Kconfig.template.log_config"
endif # THRIFT
``` | /content/code_sandbox/modules/thrift/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 167 |
```unknown
config ZEPHYR_LZ4_MODULE
bool
config LZ4
bool "Lz4 data compression and decompression"
help
This option enables lz4 compression & decompression library
support.
``` | /content/code_sandbox/modules/lz4/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 46 |
```cmake
find_program(THRIFT_EXECUTABLE thrift)
if(NOT THRIFT_EXECUTABLE)
message(FATAL_ERROR "The 'thrift' command was not found")
endif()
function(thrift
target # CMake target (for dependencies / headers)
lang # The language for generated sources
lang_opts # Language options (e.g. ':no_skeleton')
out_dir # Output directory for generated files
# (do not include 'gen-cpp', etc)
source_file # The .thrift source file
options # Additional thrift options
# Generated files in ${ARGN}
)
file(MAKE_DIRECTORY ${out_dir})
add_custom_command(
OUTPUT ${ARGN}
COMMAND
${THRIFT_EXECUTABLE}
--gen ${lang}${lang_opts}
-o ${out_dir}
${source_file}
${options}
DEPENDS ${source_file}
)
target_include_directories(${target} PRIVATE ${out_dir}/gen-${lang})
endfunction()
``` | /content/code_sandbox/modules/thrift/cmake/thrift.cmake | cmake | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 223 |
```c++
/*
*
*/
#include <zephyr/kernel.h>
#include <thrift/concurrency/Mutex.h>
namespace apache
{
namespace thrift
{
namespace concurrency
{
class Mutex::impl
{
public:
k_spinlock_key_t key;
struct k_spinlock lock;
};
Mutex::Mutex()
{
impl_ = std::make_shared<Mutex::impl>();
}
void Mutex::lock() const
{
while (!trylock()) {
k_msleep(1);
}
}
bool Mutex::trylock() const
{
return k_spin_trylock(&impl_->lock, &impl_->key) == 0;
}
bool Mutex::timedlock(int64_t milliseconds) const
{
k_timepoint_t end = sys_timepoint_calc(K_MSEC(milliseconds));
do {
if (trylock()) {
return true;
}
k_msleep(5);
} while(!sys_timepoint_expired(end));
return false;
}
void Mutex::unlock() const
{
k_spin_unlock(&impl_->lock, impl_->key);
}
void *Mutex::getUnderlyingImpl() const
{
return &impl_->lock;
}
} // namespace concurrency
} // namespace thrift
} // namespace apache
``` | /content/code_sandbox/modules/thrift/src/thrift/concurrency/Mutex.cpp | c++ | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 249 |
```objective-c
/*
*
*/
#ifndef _THRIFT_SERVER_TFDSERVER_H_
#define _THRIFT_SERVER_TFDSERVER_H_ 1
#include <memory>
#include <vector>
#include <thrift/transport/TServerTransport.h>
namespace apache
{
namespace thrift
{
namespace transport
{
class TFDServer : public TServerTransport
{
public:
/**
* Constructor.
*
* @param fd file descriptor of the socket
*/
TFDServer(int fd);
virtual ~TFDServer();
virtual bool isOpen() const override;
virtual THRIFT_SOCKET getSocketFD() override;
virtual void close() override;
virtual void interrupt() override;
virtual void interruptChildren() override;
protected:
TFDServer() : TFDServer(-1){};
virtual std::shared_ptr<TTransport> acceptImpl() override;
int fd;
std::vector<std::shared_ptr<TTransport>> children;
};
} // namespace transport
} // namespace thrift
} // namespace apache
#endif /* _THRIFT_SERVER_TFDSERVER_H_ */
``` | /content/code_sandbox/modules/thrift/src/thrift/server/TFDServer.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 214 |
```objective-c
/*
*
*/
/* config.h. Generated from config.hin by configure. */
/* config.hin. Generated from configure.ac by autoheader. */
#ifndef ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_
#define ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_
/* Possible value for SIGNED_RIGHT_SHIFT_IS */
#define ARITHMETIC_RIGHT_SHIFT 1
/* Define to 1 if you have the <arpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 1
/* Define to 1 if you have the `clock_gettime' function. */
#define HAVE_CLOCK_GETTIME 1
/* define if the compiler supports basic C++11 syntax */
#define HAVE_CXX11 1
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define to 1 if you have the `gethostbyname' function. */
#define HAVE_GETHOSTBYNAME 1
/* Define to 1 if you have the `gettimeofday' function. */
#define HAVE_GETTIMEOFDAY 1
/* Define to 1 if you have the `inet_ntoa' function. */
#define HAVE_INET_NTOA 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise. */
#define HAVE_MALLOC 1
/* Define to 1 if you have the `memmove' function. */
#define HAVE_MEMMOVE 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the `mkdir' function. */
#define HAVE_MKDIR 1
/* Define to 1 if you have the <netdb.h> header file. */
#define HAVE_NETDB_H 1
/* Define to 1 if you have the <netinet/in.h> header file. */
#define HAVE_NETINET_IN_H 1
/* Define to 1 if you have the <poll.h> header file. */
#define HAVE_POLL_H 1
/* Define to 1 if you have the <pthread.h> header file. */
#define HAVE_PTHREAD_H 1
/* Define to 1 if the system has the type `ptrdiff_t'. */
#define HAVE_PTRDIFF_T 1
/* Define to 1 if your system has a GNU libc compatible `realloc' function, and to 0 otherwise. */
#define HAVE_REALLOC 1
/* Define to 1 if you have the <sched.h> header file. */
#define HAVE_SCHED_H 1
/* Define to 1 if you have the `select' function. */
#define HAVE_SELECT 1
/* Define to 1 if you have the `socket' function. */
#define HAVE_SOCKET 1
/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
/* Define to 1 if you have the `strerror' function. */
#define HAVE_STRERROR 1
/* Define to 1 if you have the `strerror_r' function. */
#define HAVE_STRERROR_R 1
/* Define to 1 if you have the `strftime' function. */
#define HAVE_STRFTIME 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the `strstr' function. */
#define HAVE_STRSTR 1
/* Define to 1 if you have the `strtol' function. */
#define HAVE_STRTOL 1
/* Define to 1 if you have the `strtoul' function. */
#define HAVE_STRTOUL 1
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#define HAVE_SYS_IOCTL_H 1
/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1
/* Define to 1 if you have the <sys/select.h> header file. */
#define HAVE_SYS_SELECT_H 1
/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the `vprintf' function. */
#define HAVE_VPRINTF 1
/* define if zlib is available */
/* #undef HAVE_ZLIB */
/* Possible value for SIGNED_RIGHT_SHIFT_IS */
#define LOGICAL_RIGHT_SHIFT 2
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
/* Define to the type of arg 1 for `select'. */
#define SELECT_TYPE_ARG1 int
/* Define to the type of args 2, 3 and 4 for `select'. */
#define SELECT_TYPE_ARG234 (fd_set *)
/* Define to the type of arg 5 for `select'. */
#define SELECT_TYPE_ARG5 (struct timeval *)
/* Indicates the effect of the right shift operator on negative signed integers */
#define SIGNED_RIGHT_SHIFT_IS 1
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Possible value for SIGNED_RIGHT_SHIFT_IS */
#define UNKNOWN_RIGHT_SHIFT 3
#endif /* ZEPHYR_MODULES_THRIFT_SRC_THRIFT_CONFIG_H_ */
``` | /content/code_sandbox/modules/thrift/src/thrift/config.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,468 |
```objective-c
/*
*
*/
/*
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing,
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* specific language governing permissions and limitations
*/
#ifndef _THRIFT_SERVER_TCONNECTEDCLIENT_H_
#define _THRIFT_SERVER_TCONNECTEDCLIENT_H_ 1
#include <memory>
#include <thrift/TProcessor.h>
#include <thrift/protocol/TProtocol.h>
#include <thrift/server/TServer.h>
#include <thrift/transport/TTransport.h>
namespace apache
{
namespace thrift
{
namespace server
{
/**
* This represents a client connected to a TServer. The
* processing loop for a client must provide some required
* functionality common to all implementations so it is
* encapsulated here.
*/
class TConnectedClient
{
public:
/**
* Constructor.
*
* @param[in] processor the TProcessor
* @param[in] inputProtocol the input TProtocol
* @param[in] outputProtocol the output TProtocol
* @param[in] eventHandler the server event handler
* @param[in] client the TTransport representing the client
*/
TConnectedClient(
const std::shared_ptr<apache::thrift::TProcessor> &processor,
const std::shared_ptr<apache::thrift::protocol::TProtocol> &inputProtocol,
const std::shared_ptr<apache::thrift::protocol::TProtocol> &outputProtocol,
const std::shared_ptr<apache::thrift::server::TServerEventHandler> &eventHandler,
const std::shared_ptr<apache::thrift::transport::TTransport> &client);
/**
* Destructor.
*/
~TConnectedClient();
/**
* Drive the client until it is done.
* The client processing loop is:
*
* [optional] call eventHandler->createContext once
* [optional] call eventHandler->processContext per request
* call processor->process per request
* handle expected transport exceptions:
* END_OF_FILE means the client is gone
* INTERRUPTED means the client was interrupted
* by TServerTransport::interruptChildren()
* handle unexpected transport exceptions by logging
* handle standard exceptions by logging
* handle unexpected exceptions by logging
* cleanup()
*/
void run();
protected:
/**
* Cleanup after a client. This happens if the client disconnects,
* or if the server is stopped, or if an exception occurs.
*
* The cleanup processing is:
* [optional] call eventHandler->deleteContext once
* close the inputProtocol's TTransport
* close the outputProtocol's TTransport
* close the client
*/
virtual void cleanup();
private:
std::shared_ptr<apache::thrift::TProcessor> processor_;
std::shared_ptr<apache::thrift::protocol::TProtocol> inputProtocol_;
std::shared_ptr<apache::thrift::protocol::TProtocol> outputProtocol_;
std::shared_ptr<apache::thrift::server::TServerEventHandler> eventHandler_;
std::shared_ptr<apache::thrift::transport::TTransport> client_;
/**
* Context acquired from the eventHandler_ if one exists.
*/
void *opaqueContext_;
};
} // namespace server
} // namespace thrift
} // namespace apache
#endif // #ifndef _THRIFT_SERVER_TCONNECTEDCLIENT_H_
``` | /content/code_sandbox/modules/thrift/src/thrift/server/TConnectedClient.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 779 |
```objective-c
/*
*
*/
/*
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing,
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* specific language governing permissions and limitations
*/
#ifndef _THRIFT_SERVER_TSIMPLESERVER_H_
#define _THRIFT_SERVER_TSIMPLESERVER_H_ 1
#include <thrift/server/TServerFramework.h>
namespace apache
{
namespace thrift
{
namespace server
{
/**
* This is the most basic simple server. It is single-threaded and runs a
* continuous loop of accepting a single connection, processing requests on
* that connection until it closes, and then repeating.
*/
class TSimpleServer : public TServerFramework
{
public:
TSimpleServer(
const std::shared_ptr<apache::thrift::TProcessorFactory> &processorFactory,
const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&transportFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory> &protocolFactory);
TSimpleServer(
const std::shared_ptr<apache::thrift::TProcessor> &processor,
const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&transportFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory> &protocolFactory);
TSimpleServer(
const std::shared_ptr<apache::thrift::TProcessorFactory> &processorFactory,
const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&inputTransportFactory,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&outputTransportFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
&inputProtocolFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
&outputProtocolFactory);
TSimpleServer(
const std::shared_ptr<apache::thrift::TProcessor> &processor,
const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&inputTransportFactory,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&outputTransportFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
&inputProtocolFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
&outputProtocolFactory);
~TSimpleServer();
protected:
void onClientConnected(const std::shared_ptr<TConnectedClient> &pClient) override
/* override */;
void onClientDisconnected(TConnectedClient *pClient) override /* override */;
private:
void setConcurrentClientLimit(int64_t newLimit) override; // hide
};
} // namespace server
} // namespace thrift
} // namespace apache
#endif // #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_
``` | /content/code_sandbox/modules/thrift/src/thrift/server/TSimpleServer.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 757 |
```c++
/*
*
*/
/*
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing,
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* specific language governing permissions and limitations
*/
#include <algorithm>
#include <functional>
#include <stdexcept>
#include <stdint.h>
#include <thrift/server/TServerFramework.h>
namespace apache
{
namespace thrift
{
namespace server
{
// using apache::thrift::concurrency::Synchronized;
using apache::thrift::protocol::TProtocol;
using apache::thrift::protocol::TProtocolFactory;
using apache::thrift::transport::TServerTransport;
using apache::thrift::transport::TTransport;
using apache::thrift::transport::TTransportException;
using apache::thrift::transport::TTransportFactory;
using std::bind;
using std::shared_ptr;
using std::string;
TServerFramework::TServerFramework(const shared_ptr<TProcessorFactory> &processorFactory,
const shared_ptr<TServerTransport> &serverTransport,
const shared_ptr<TTransportFactory> &transportFactory,
const shared_ptr<TProtocolFactory> &protocolFactory)
: TServer(processorFactory, serverTransport, transportFactory, protocolFactory),
clients_(0), hwm_(0), limit_(INT64_MAX)
{
}
TServerFramework::TServerFramework(const shared_ptr<TProcessor> &processor,
const shared_ptr<TServerTransport> &serverTransport,
const shared_ptr<TTransportFactory> &transportFactory,
const shared_ptr<TProtocolFactory> &protocolFactory)
: TServer(processor, serverTransport, transportFactory, protocolFactory), clients_(0),
hwm_(0), limit_(INT64_MAX)
{
}
TServerFramework::TServerFramework(const shared_ptr<TProcessorFactory> &processorFactory,
const shared_ptr<TServerTransport> &serverTransport,
const shared_ptr<TTransportFactory> &inputTransportFactory,
const shared_ptr<TTransportFactory> &outputTransportFactory,
const shared_ptr<TProtocolFactory> &inputProtocolFactory,
const shared_ptr<TProtocolFactory> &outputProtocolFactory)
: TServer(processorFactory, serverTransport, inputTransportFactory, outputTransportFactory,
inputProtocolFactory, outputProtocolFactory),
clients_(0), hwm_(0), limit_(INT64_MAX)
{
}
TServerFramework::TServerFramework(const shared_ptr<TProcessor> &processor,
const shared_ptr<TServerTransport> &serverTransport,
const shared_ptr<TTransportFactory> &inputTransportFactory,
const shared_ptr<TTransportFactory> &outputTransportFactory,
const shared_ptr<TProtocolFactory> &inputProtocolFactory,
const shared_ptr<TProtocolFactory> &outputProtocolFactory)
: TServer(processor, serverTransport, inputTransportFactory, outputTransportFactory,
inputProtocolFactory, outputProtocolFactory),
clients_(0), hwm_(0), limit_(INT64_MAX)
{
}
TServerFramework::~TServerFramework() = default;
template <typename T> static void releaseOneDescriptor(const string &name, T &pTransport)
{
if (pTransport) {
try {
pTransport->close();
} catch (const TTransportException &ttx) {
string errStr =
string("TServerFramework " + name + " close failed: ") + ttx.what();
GlobalOutput(errStr.c_str());
}
}
}
void TServerFramework::serve()
{
shared_ptr<TTransport> client;
shared_ptr<TTransport> inputTransport;
shared_ptr<TTransport> outputTransport;
shared_ptr<TProtocol> inputProtocol;
shared_ptr<TProtocol> outputProtocol;
// Start the server listening
serverTransport_->listen();
// Run the preServe event to indicate server is now listening
// and that it is safe to connect.
if (eventHandler_) {
eventHandler_->preServe();
}
// Fetch client from server
for (;;) {
try {
// Dereference any resources from any previous client creation
// such that a blocking accept does not hold them indefinitely.
outputProtocol.reset();
inputProtocol.reset();
outputTransport.reset();
inputTransport.reset();
client.reset();
// If we have reached the limit on the number of concurrent
// clients allowed, wait for one or more clients to drain before
// accepting another.
{
// Synchronized sync(mon_);
while (clients_ >= limit_) {
// mon_.wait();
}
}
client = serverTransport_->accept();
inputTransport = inputTransportFactory_->getTransport(client);
outputTransport = outputTransportFactory_->getTransport(client);
if (!outputProtocolFactory_) {
inputProtocol = inputProtocolFactory_->getProtocol(inputTransport,
outputTransport);
outputProtocol = inputProtocol;
} else {
inputProtocol = inputProtocolFactory_->getProtocol(inputTransport);
outputProtocol =
outputProtocolFactory_->getProtocol(outputTransport);
}
newlyConnectedClient(shared_ptr<TConnectedClient>(
new TConnectedClient(
getProcessor(inputProtocol, outputProtocol, client),
inputProtocol, outputProtocol, eventHandler_, client),
bind(&TServerFramework::disposeConnectedClient, this,
std::placeholders::_1)));
} catch (TTransportException &ttx) {
releaseOneDescriptor("inputTransport", inputTransport);
releaseOneDescriptor("outputTransport", outputTransport);
releaseOneDescriptor("client", client);
if (ttx.getType() == TTransportException::TIMED_OUT ||
ttx.getType() == TTransportException::CLIENT_DISCONNECT) {
// Accept timeout and client disconnect - continue processing.
continue;
} else if (ttx.getType() == TTransportException::END_OF_FILE ||
ttx.getType() == TTransportException::INTERRUPTED) {
// Server was interrupted. This only happens when stopping.
break;
} else {
// All other transport exceptions are logged.
// State of connection is unknown. Done.
string errStr = string("TServerTransport died: ") + ttx.what();
GlobalOutput(errStr.c_str());
break;
}
}
}
releaseOneDescriptor("serverTransport", serverTransport_);
}
int64_t TServerFramework::getConcurrentClientLimit() const
{
// Synchronized sync(mon_);
return limit_;
}
int64_t TServerFramework::getConcurrentClientCount() const
{
// Synchronized sync(mon_);
return clients_;
}
int64_t TServerFramework::getConcurrentClientCountHWM() const
{
// Synchronized sync(mon_);
return hwm_;
}
void TServerFramework::setConcurrentClientLimit(int64_t newLimit)
{
if (newLimit < 1) {
throw std::invalid_argument("newLimit must be greater than zero");
}
// Synchronized sync(mon_);
limit_ = newLimit;
if (limit_ - clients_ > 0) {
// mon_.notify();
}
}
void TServerFramework::stop()
{
// Order is important because serve() releases serverTransport_ when it is
// interrupted, which closes the socket that interruptChildren uses.
serverTransport_->interruptChildren();
serverTransport_->interrupt();
}
void TServerFramework::newlyConnectedClient(const shared_ptr<TConnectedClient> &pClient)
{
{
// Synchronized sync(mon_);
++clients_;
hwm_ = (std::max)(hwm_, clients_);
}
onClientConnected(pClient);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
void TServerFramework::disposeConnectedClient(TConnectedClient *pClient)
{
onClientDisconnected(pClient);
delete pClient;
// Synchronized sync(mon_);
if (limit_ - --clients_ > 0) {
// mon_.notify();
}
}
#pragma GCC diagnostic pop
} // namespace server
} // namespace thrift
} // namespace apache
``` | /content/code_sandbox/modules/thrift/src/thrift/server/TServerFramework.cpp | c++ | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,729 |
```objective-c
/*
*
*/
/*
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing,
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* specific language governing permissions and limitations
*/
#ifndef _THRIFT_SERVER_TSERVERFRAMEWORK_H_
#define _THRIFT_SERVER_TSERVERFRAMEWORK_H_ 1
#include <memory>
#include <stdint.h>
#include <thrift/TProcessor.h>
#include <thrift/server/TConnectedClient.h>
#include <thrift/server/TServer.h>
#include <thrift/transport/TServerTransport.h>
#include <thrift/transport/TTransport.h>
namespace apache
{
namespace thrift
{
namespace server
{
/**
* TServerFramework provides a single consolidated processing loop for
* servers. By having a single processing loop, behavior between servers
* is more predictable and maintenance cost is lowered. Implementations
* of TServerFramework must provide a method to deal with a client that
* connects and one that disconnects.
*
* While this functionality could be rolled directly into TServer, and
* probably should be, it would break the TServer interface contract so
* to maintain backwards compatibility for third party servers, no TServers
* were harmed in the making of this class.
*/
class TServerFramework : public TServer
{
public:
TServerFramework(
const std::shared_ptr<apache::thrift::TProcessorFactory> &processorFactory,
const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&transportFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory> &protocolFactory);
TServerFramework(
const std::shared_ptr<apache::thrift::TProcessor> &processor,
const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&transportFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory> &protocolFactory);
TServerFramework(
const std::shared_ptr<apache::thrift::TProcessorFactory> &processorFactory,
const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&inputTransportFactory,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&outputTransportFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
&inputProtocolFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
&outputProtocolFactory);
TServerFramework(
const std::shared_ptr<apache::thrift::TProcessor> &processor,
const std::shared_ptr<apache::thrift::transport::TServerTransport> &serverTransport,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&inputTransportFactory,
const std::shared_ptr<apache::thrift::transport::TTransportFactory>
&outputTransportFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
&inputProtocolFactory,
const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>
&outputProtocolFactory);
~TServerFramework();
/**
* Accept clients from the TServerTransport and add them for processing.
* Call stop() on another thread to interrupt processing
* and return control to the caller.
* Post-conditions (return guarantees):
* The serverTransport will be closed.
*/
virtual void serve() override;
/**
* Interrupt serve() so that it meets post-conditions and returns.
*/
virtual void stop() override;
/**
* Get the concurrent client limit.
* \returns the concurrent client limit
*/
virtual int64_t getConcurrentClientLimit() const;
/**
* Get the number of currently connected clients.
* \returns the number of currently connected clients
*/
virtual int64_t getConcurrentClientCount() const;
/**
* Get the highest number of concurrent clients.
* \returns the highest number of concurrent clients
*/
virtual int64_t getConcurrentClientCountHWM() const;
/**
* Set the concurrent client limit. This can be changed while
* the server is serving however it will not necessarily be
* enforced until the next client is accepted and added. If the
* limit is lowered below the number of connected clients, no
* action is taken to disconnect the clients.
* The default value used if this is not called is INT64_MAX.
* \param[in] newLimit the new limit of concurrent clients
* \throws std::invalid_argument if newLimit is less than 1
*/
virtual void setConcurrentClientLimit(int64_t newLimit);
protected:
/**
* A client has connected. The implementation is responsible for managing the
* lifetime of the client object. This is called during the serve() thread,
* therefore a failure to return quickly will result in new client connection
* delays.
*
* \param[in] pClient the newly connected client
*/
virtual void onClientConnected(const std::shared_ptr<TConnectedClient> &pClient) = 0;
/**
* A client has disconnected.
* When called:
* The server no longer tracks the client.
* The client TTransport has already been closed.
* The implementation must not delete the pointer.
*
* \param[in] pClient the disconnected client
*/
virtual void onClientDisconnected(TConnectedClient *pClient) = 0;
private:
/**
* Common handling for new connected clients. Implements concurrent
* client rate limiting after onClientConnected returns by blocking the
* serve() thread if the limit has been reached.
*/
void newlyConnectedClient(const std::shared_ptr<TConnectedClient> &pClient);
/**
* Smart pointer client deletion.
* Calls onClientDisconnected and then deletes pClient.
*/
void disposeConnectedClient(TConnectedClient *pClient);
/**
* The number of concurrent clients.
*/
int64_t clients_;
/**
* The high water mark of concurrent clients.
*/
int64_t hwm_;
/**
* The limit on the number of concurrent clients.
*/
int64_t limit_;
};
} // namespace server
} // namespace thrift
} // namespace apache
#endif // #ifndef _THRIFT_SERVER_TSERVERFRAMEWORK_H_
``` | /content/code_sandbox/modules/thrift/src/thrift/server/TServerFramework.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,482 |
```c++
/*
*
*/
#include <array>
#include <system_error>
#include <errno.h>
#include <zephyr/posix/poll.h>
#include <zephyr/posix/sys/eventfd.h>
#include <zephyr/posix/unistd.h>
#include <thrift/transport/TFDTransport.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include "thrift/server/TFDServer.h"
LOG_MODULE_REGISTER(TFDServer, LOG_LEVEL_INF);
using namespace std;
namespace apache
{
namespace thrift
{
namespace transport
{
class xport : public TVirtualTransport<xport>
{
public:
xport(int fd) : xport(fd, eventfd(0, EFD_SEMAPHORE))
{
}
xport(int fd, int efd) : fd(fd), efd(efd)
{
__ASSERT(fd >= 0, "invalid fd %d", fd);
__ASSERT(efd >= 0, "invalid efd %d", efd);
LOG_DBG("created xport with fd %d and efd %d", fd, efd);
}
~xport()
{
close();
}
virtual uint32_t read_virt(uint8_t *buf, uint32_t len) override
{
int r;
array<pollfd, 2> pollfds = {
(pollfd){
.fd = fd,
.events = POLLIN,
.revents = 0,
},
(pollfd){
.fd = efd,
.events = POLLIN,
.revents = 0,
},
};
if (!isOpen()) {
return 0;
}
r = poll(&pollfds.front(), pollfds.size(), -1);
if (r == -1) {
if (efd == -1 || fd == -1) {
/* channel has been closed */
return 0;
}
LOG_ERR("failed to poll fds %d, %d: %d", fd, efd, errno);
throw system_error(errno, system_category(), "poll");
}
for (auto &pfd : pollfds) {
if (pfd.revents & POLLNVAL) {
LOG_DBG("fd %d is invalid", pfd.fd);
return 0;
}
}
if (pollfds[0].revents & POLLIN) {
r = ::read(fd, buf, len);
if (r == -1) {
LOG_ERR("failed to read %d bytes from fd %d: %d", len, fd, errno);
system_error(errno, system_category(), "read");
}
__ASSERT_NO_MSG(r > 0);
return uint32_t(r);
}
__ASSERT_NO_MSG(pollfds[1].revents & POLLIN);
return 0;
}
virtual void write_virt(const uint8_t *buf, uint32_t len) override
{
if (!isOpen()) {
throw TTransportException(TTransportException::END_OF_FILE);
}
for (int r = 0; len > 0; buf += r, len -= r) {
r = ::write(fd, buf, len);
if (r == -1) {
LOG_ERR("writing %u bytes to fd %d failed: %d", len, fd, errno);
throw system_error(errno, system_category(), "write");
}
__ASSERT_NO_MSG(r > 0);
}
}
void interrupt()
{
if (!isOpen()) {
return;
}
constexpr uint64_t x = 0xb7e;
int r = ::write(efd, &x, sizeof(x));
if (r == -1) {
LOG_ERR("writing %zu bytes to fd %d failed: %d", sizeof(x), efd, errno);
throw system_error(errno, system_category(), "write");
}
__ASSERT_NO_MSG(r > 0);
LOG_DBG("interrupted xport with fd %d and efd %d", fd, efd);
// there is no interrupt() method in the parent class, but the intent of
// interrupt() is to prevent future communication on this transport. The
// most reliable way we have of doing this is to close it :-)
close();
}
void close() override
{
if (isOpen()) {
::close(efd);
LOG_DBG("closed xport with fd %d and efd %d", fd, efd);
efd = -1;
// we only have a copy of fd and do not own it
fd = -1;
}
}
bool isOpen() const override
{
return fd >= 0 && efd >= 0;
}
protected:
int fd;
int efd;
};
TFDServer::TFDServer(int fd) : fd(fd)
{
}
TFDServer::~TFDServer()
{
interruptChildren();
interrupt();
}
bool TFDServer::isOpen() const
{
return fd >= 0;
}
shared_ptr<TTransport> TFDServer::acceptImpl()
{
if (!isOpen()) {
throw TTransportException(TTransportException::INTERRUPTED);
}
children.push_back(shared_ptr<TTransport>(new xport(fd)));
return children.back();
}
THRIFT_SOCKET TFDServer::getSocketFD()
{
return fd;
}
void TFDServer::close()
{
// we only have a copy of fd and do not own it
fd = -1;
}
void TFDServer::interrupt()
{
close();
}
void TFDServer::interruptChildren()
{
for (auto c : children) {
auto child = reinterpret_cast<xport *>(c.get());
child->interrupt();
}
children.clear();
}
} // namespace transport
} // namespace thrift
} // namespace apache
``` | /content/code_sandbox/modules/thrift/src/thrift/server/TFDServer.cpp | c++ | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,280 |
```objective-c
/*
*
*/
/*
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing,
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* specific language governing permissions and limitations
*/
#ifndef _THRIFT_SERVER_TSERVER_H_
#define _THRIFT_SERVER_TSERVER_H_ 1
#include <thrift/TProcessor.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TServerTransport.h>
#include <memory>
namespace apache
{
namespace thrift
{
namespace server
{
using apache::thrift::TProcessor;
using apache::thrift::protocol::TBinaryProtocolFactory;
using apache::thrift::protocol::TProtocol;
using apache::thrift::protocol::TProtocolFactory;
using apache::thrift::transport::TServerTransport;
using apache::thrift::transport::TTransport;
using apache::thrift::transport::TTransportFactory;
/**
* Virtual interface class that can handle events from the server core. To
* use this you should subclass it and implement the methods that you care
* about. Your subclass can also store local data that you may care about,
* such as additional "arguments" to these methods (stored in the object
* instance's state).
*/
class TServerEventHandler
{
public:
virtual ~TServerEventHandler() = default;
/**
* Called before the server begins.
*/
virtual void preServe()
{
}
/**
* Called when a new client has connected and is about to being processing.
*/
virtual void *createContext(std::shared_ptr<TProtocol> input,
std::shared_ptr<TProtocol> output)
{
(void)input;
(void)output;
return nullptr;
}
/**
* Called when a client has finished request-handling to delete server
* context.
*/
virtual void deleteContext(void *serverContext, std::shared_ptr<TProtocol> input,
std::shared_ptr<TProtocol> output)
{
(void)serverContext;
(void)input;
(void)output;
}
/**
* Called when a client is about to call the processor.
*/
virtual void processContext(void *serverContext, std::shared_ptr<TTransport> transport)
{
(void)serverContext;
(void)transport;
}
protected:
/**
* Prevent direct instantiation.
*/
TServerEventHandler() = default;
};
/**
* Thrift server.
*
*/
class TServer
{
public:
~TServer() = default;
virtual void serve() = 0;
virtual void stop()
{
}
// Allows running the server as a Runnable thread
void run()
{
serve();
}
std::shared_ptr<TProcessorFactory> getProcessorFactory()
{
return processorFactory_;
}
std::shared_ptr<TServerTransport> getServerTransport()
{
return serverTransport_;
}
std::shared_ptr<TTransportFactory> getInputTransportFactory()
{
return inputTransportFactory_;
}
std::shared_ptr<TTransportFactory> getOutputTransportFactory()
{
return outputTransportFactory_;
}
std::shared_ptr<TProtocolFactory> getInputProtocolFactory()
{
return inputProtocolFactory_;
}
std::shared_ptr<TProtocolFactory> getOutputProtocolFactory()
{
return outputProtocolFactory_;
}
std::shared_ptr<TServerEventHandler> getEventHandler()
{
return eventHandler_;
}
protected:
TServer(const std::shared_ptr<TProcessorFactory> &processorFactory)
: processorFactory_(processorFactory)
{
setInputTransportFactory(
std::shared_ptr<TTransportFactory>(new TTransportFactory()));
setOutputTransportFactory(
std::shared_ptr<TTransportFactory>(new TTransportFactory()));
setInputProtocolFactory(
std::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
setOutputProtocolFactory(
std::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
}
TServer(const std::shared_ptr<TProcessor> &processor)
: processorFactory_(new TSingletonProcessorFactory(processor))
{
setInputTransportFactory(
std::shared_ptr<TTransportFactory>(new TTransportFactory()));
setOutputTransportFactory(
std::shared_ptr<TTransportFactory>(new TTransportFactory()));
setInputProtocolFactory(
std::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
setOutputProtocolFactory(
std::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
}
TServer(const std::shared_ptr<TProcessorFactory> &processorFactory,
const std::shared_ptr<TServerTransport> &serverTransport)
: processorFactory_(processorFactory), serverTransport_(serverTransport)
{
setInputTransportFactory(
std::shared_ptr<TTransportFactory>(new TTransportFactory()));
setOutputTransportFactory(
std::shared_ptr<TTransportFactory>(new TTransportFactory()));
setInputProtocolFactory(
std::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
setOutputProtocolFactory(
std::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
}
TServer(const std::shared_ptr<TProcessor> &processor,
const std::shared_ptr<TServerTransport> &serverTransport)
: processorFactory_(new TSingletonProcessorFactory(processor)),
serverTransport_(serverTransport)
{
setInputTransportFactory(
std::shared_ptr<TTransportFactory>(new TTransportFactory()));
setOutputTransportFactory(
std::shared_ptr<TTransportFactory>(new TTransportFactory()));
setInputProtocolFactory(
std::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
setOutputProtocolFactory(
std::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
}
TServer(const std::shared_ptr<TProcessorFactory> &processorFactory,
const std::shared_ptr<TServerTransport> &serverTransport,
const std::shared_ptr<TTransportFactory> &transportFactory,
const std::shared_ptr<TProtocolFactory> &protocolFactory)
: processorFactory_(processorFactory), serverTransport_(serverTransport),
inputTransportFactory_(transportFactory),
outputTransportFactory_(transportFactory), inputProtocolFactory_(protocolFactory),
outputProtocolFactory_(protocolFactory)
{
}
TServer(const std::shared_ptr<TProcessor> &processor,
const std::shared_ptr<TServerTransport> &serverTransport,
const std::shared_ptr<TTransportFactory> &transportFactory,
const std::shared_ptr<TProtocolFactory> &protocolFactory)
: processorFactory_(new TSingletonProcessorFactory(processor)),
serverTransport_(serverTransport), inputTransportFactory_(transportFactory),
outputTransportFactory_(transportFactory), inputProtocolFactory_(protocolFactory),
outputProtocolFactory_(protocolFactory)
{
}
TServer(const std::shared_ptr<TProcessorFactory> &processorFactory,
const std::shared_ptr<TServerTransport> &serverTransport,
const std::shared_ptr<TTransportFactory> &inputTransportFactory,
const std::shared_ptr<TTransportFactory> &outputTransportFactory,
const std::shared_ptr<TProtocolFactory> &inputProtocolFactory,
const std::shared_ptr<TProtocolFactory> &outputProtocolFactory)
: processorFactory_(processorFactory), serverTransport_(serverTransport),
inputTransportFactory_(inputTransportFactory),
outputTransportFactory_(outputTransportFactory),
inputProtocolFactory_(inputProtocolFactory),
outputProtocolFactory_(outputProtocolFactory)
{
}
TServer(const std::shared_ptr<TProcessor> &processor,
const std::shared_ptr<TServerTransport> &serverTransport,
const std::shared_ptr<TTransportFactory> &inputTransportFactory,
const std::shared_ptr<TTransportFactory> &outputTransportFactory,
const std::shared_ptr<TProtocolFactory> &inputProtocolFactory,
const std::shared_ptr<TProtocolFactory> &outputProtocolFactory)
: processorFactory_(new TSingletonProcessorFactory(processor)),
serverTransport_(serverTransport), inputTransportFactory_(inputTransportFactory),
outputTransportFactory_(outputTransportFactory),
inputProtocolFactory_(inputProtocolFactory),
outputProtocolFactory_(outputProtocolFactory)
{
}
/**
* Get a TProcessor to handle calls on a particular connection.
*
* This method should only be called once per connection (never once per
* call). This allows the TProcessorFactory to return a different processor
* for each connection if it desires.
*/
std::shared_ptr<TProcessor> getProcessor(std::shared_ptr<TProtocol> inputProtocol,
std::shared_ptr<TProtocol> outputProtocol,
std::shared_ptr<TTransport> transport)
{
TConnectionInfo connInfo;
connInfo.input = inputProtocol;
connInfo.output = outputProtocol;
connInfo.transport = transport;
return processorFactory_->getProcessor(connInfo);
}
// Class variables
std::shared_ptr<TProcessorFactory> processorFactory_;
std::shared_ptr<TServerTransport> serverTransport_;
std::shared_ptr<TTransportFactory> inputTransportFactory_;
std::shared_ptr<TTransportFactory> outputTransportFactory_;
std::shared_ptr<TProtocolFactory> inputProtocolFactory_;
std::shared_ptr<TProtocolFactory> outputProtocolFactory_;
std::shared_ptr<TServerEventHandler> eventHandler_;
public:
void setInputTransportFactory(std::shared_ptr<TTransportFactory> inputTransportFactory)
{
inputTransportFactory_ = inputTransportFactory;
}
void setOutputTransportFactory(std::shared_ptr<TTransportFactory> outputTransportFactory)
{
outputTransportFactory_ = outputTransportFactory;
}
void setInputProtocolFactory(std::shared_ptr<TProtocolFactory> inputProtocolFactory)
{
inputProtocolFactory_ = inputProtocolFactory;
}
void setOutputProtocolFactory(std::shared_ptr<TProtocolFactory> outputProtocolFactory)
{
outputProtocolFactory_ = outputProtocolFactory;
}
void setServerEventHandler(std::shared_ptr<TServerEventHandler> eventHandler)
{
eventHandler_ = eventHandler;
}
};
/**
* Helper function to increase the max file descriptors limit
* for the current process and all of its children.
* By default, tries to increase it to as much as 2^24.
*/
#ifdef HAVE_SYS_RESOURCE_H
int increase_max_fds(int max_fds = (1 << 24));
#endif
} // namespace server
} // namespace thrift
} // namespace apache
#endif // #ifndef _THRIFT_SERVER_TSERVER_H_
``` | /content/code_sandbox/modules/thrift/src/thrift/server/TServer.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 2,228 |
```objective-c
/*
*
*/
#ifndef _THRIFT_TRANSPORT_TSSLSERVERSOCKET_H_
#define _THRIFT_TRANSPORT_TSSLSERVERSOCKET_H_ 1
#include <thrift/transport/TServerSocket.h>
namespace apache
{
namespace thrift
{
namespace transport
{
class TSSLSocketFactory;
/**
* Server socket that accepts SSL connections.
*/
class TSSLServerSocket : public TServerSocket
{
public:
/**
* Constructor. Binds to all interfaces.
*
* @param port Listening port
* @param factory SSL socket factory implementation
*/
TSSLServerSocket(int port, std::shared_ptr<TSSLSocketFactory> factory);
/**
* Constructor. Binds to the specified address.
*
* @param address Address to bind to
* @param port Listening port
* @param factory SSL socket factory implementation
*/
TSSLServerSocket(const std::string &address, int port,
std::shared_ptr<TSSLSocketFactory> factory);
/**
* Constructor. Binds to all interfaces.
*
* @param port Listening port
* @param sendTimeout Socket send timeout
* @param recvTimeout Socket receive timeout
* @param factory SSL socket factory implementation
*/
TSSLServerSocket(int port, int sendTimeout, int recvTimeout,
std::shared_ptr<TSSLSocketFactory> factory);
void listen() override;
void close() override;
protected:
std::shared_ptr<TSocket> createSocket(THRIFT_SOCKET socket) override;
std::shared_ptr<TSSLSocketFactory> factory_;
};
} // namespace transport
} // namespace thrift
} // namespace apache
#endif
``` | /content/code_sandbox/modules/thrift/src/thrift/transport/TSSLServerSocket.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 362 |
```objective-c
/*
*
*/
/*
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
*
* path_to_url
*
* Unless required by applicable law or agreed to in writing,
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* specific language governing permissions and limitations
*/
#ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_
#define _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ 1
#include <thrift/protocol/TProtocol.h>
#include <thrift/protocol/TVirtualProtocol.h>
#include <memory>
namespace apache
{
namespace thrift
{
namespace protocol
{
/**
* The default binary protocol for thrift. Writes all data in a very basic
* binary format, essentially just spitting out the raw bytes.
*
*/
template <class Transport_, class ByteOrder_ = TNetworkBigEndian>
class TBinaryProtocolT : public TVirtualProtocol<TBinaryProtocolT<Transport_, ByteOrder_>>
{
public:
static const int32_t VERSION_MASK = ((int32_t)0xffff0000);
static const int32_t VERSION_1 = ((int32_t)0x80010000);
// VERSION_2 (0x80020000) was taken by TDenseProtocol (which has since been removed)
TBinaryProtocolT(std::shared_ptr<Transport_> trans)
: TVirtualProtocol<TBinaryProtocolT<Transport_, ByteOrder_>>(trans),
trans_(trans.get()), string_limit_(0), container_limit_(0), strict_read_(false),
strict_write_(true)
{
}
TBinaryProtocolT(std::shared_ptr<Transport_> trans, int32_t string_limit,
int32_t container_limit, bool strict_read, bool strict_write)
: TVirtualProtocol<TBinaryProtocolT<Transport_, ByteOrder_>>(trans),
trans_(trans.get()), string_limit_(string_limit),
container_limit_(container_limit), strict_read_(strict_read),
strict_write_(strict_write)
{
}
void setStringSizeLimit(int32_t string_limit)
{
string_limit_ = string_limit;
}
void setContainerSizeLimit(int32_t container_limit)
{
container_limit_ = container_limit;
}
void setStrict(bool strict_read, bool strict_write)
{
strict_read_ = strict_read;
strict_write_ = strict_write;
}
/**
* Writing functions.
*/
/*ol*/ uint32_t writeMessageBegin(const std::string &name, const TMessageType messageType,
const int32_t seqid);
/*ol*/ uint32_t writeMessageEnd();
inline uint32_t writeStructBegin(const char *name);
inline uint32_t writeStructEnd();
inline uint32_t writeFieldBegin(const char *name, const TType fieldType,
const int16_t fieldId);
inline uint32_t writeFieldEnd();
inline uint32_t writeFieldStop();
inline uint32_t writeMapBegin(const TType keyType, const TType valType,
const uint32_t size);
inline uint32_t writeMapEnd();
inline uint32_t writeListBegin(const TType elemType, const uint32_t size);
inline uint32_t writeListEnd();
inline uint32_t writeSetBegin(const TType elemType, const uint32_t size);
inline uint32_t writeSetEnd();
inline uint32_t writeBool(const bool value);
inline uint32_t writeByte(const int8_t byte);
inline uint32_t writeI16(const int16_t i16);
inline uint32_t writeI32(const int32_t i32);
inline uint32_t writeI64(const int64_t i64);
inline uint32_t writeDouble(const double dub);
template <typename StrType> inline uint32_t writeString(const StrType &str);
inline uint32_t writeBinary(const std::string &str);
/**
* Reading functions
*/
/*ol*/ uint32_t readMessageBegin(std::string &name, TMessageType &messageType,
int32_t &seqid);
/*ol*/ uint32_t readMessageEnd();
inline uint32_t readStructBegin(std::string &name);
inline uint32_t readStructEnd();
inline uint32_t readFieldBegin(std::string &name, TType &fieldType, int16_t &fieldId);
inline uint32_t readFieldEnd();
inline uint32_t readMapBegin(TType &keyType, TType &valType, uint32_t &size);
inline uint32_t readMapEnd();
inline uint32_t readListBegin(TType &elemType, uint32_t &size);
inline uint32_t readListEnd();
inline uint32_t readSetBegin(TType &elemType, uint32_t &size);
inline uint32_t readSetEnd();
inline uint32_t readBool(bool &value);
// Provide the default readBool() implementation for std::vector<bool>
using TVirtualProtocol<TBinaryProtocolT<Transport_, ByteOrder_>>::readBool;
inline uint32_t readByte(int8_t &byte);
inline uint32_t readI16(int16_t &i16);
inline uint32_t readI32(int32_t &i32);
inline uint32_t readI64(int64_t &i64);
inline uint32_t readDouble(double &dub);
template <typename StrType> inline uint32_t readString(StrType &str);
inline uint32_t readBinary(std::string &str);
int getMinSerializedSize(TType type) override;
void checkReadBytesAvailable(TSet &set) override
{
trans_->checkReadBytesAvailable(set.size_ * getMinSerializedSize(set.elemType_));
}
void checkReadBytesAvailable(TList &list) override
{
trans_->checkReadBytesAvailable(list.size_ * getMinSerializedSize(list.elemType_));
}
void checkReadBytesAvailable(TMap &map) override
{
int elmSize =
getMinSerializedSize(map.keyType_) + getMinSerializedSize(map.valueType_);
trans_->checkReadBytesAvailable(map.size_ * elmSize);
}
protected:
template <typename StrType> uint32_t readStringBody(StrType &str, int32_t sz);
Transport_ *trans_;
int32_t string_limit_;
int32_t container_limit_;
// Enforce presence of version identifier
bool strict_read_;
bool strict_write_;
};
typedef TBinaryProtocolT<TTransport> TBinaryProtocol;
typedef TBinaryProtocolT<TTransport, TNetworkLittleEndian> TLEBinaryProtocol;
/**
* Constructs binary protocol handlers
*/
template <class Transport_, class ByteOrder_ = TNetworkBigEndian>
class TBinaryProtocolFactoryT : public TProtocolFactory
{
public:
TBinaryProtocolFactoryT()
: string_limit_(0), container_limit_(0), strict_read_(false), strict_write_(true)
{
}
TBinaryProtocolFactoryT(int32_t string_limit, int32_t container_limit, bool strict_read,
bool strict_write)
: string_limit_(string_limit), container_limit_(container_limit),
strict_read_(strict_read), strict_write_(strict_write)
{
}
~TBinaryProtocolFactoryT() override = default;
void setStringSizeLimit(int32_t string_limit)
{
string_limit_ = string_limit;
}
void setContainerSizeLimit(int32_t container_limit)
{
container_limit_ = container_limit;
}
void setStrict(bool strict_read, bool strict_write)
{
strict_read_ = strict_read;
strict_write_ = strict_write;
}
std::shared_ptr<TProtocol> getProtocol(std::shared_ptr<TTransport> trans) override
{
std::shared_ptr<Transport_> specific_trans =
std::dynamic_pointer_cast<Transport_>(trans);
TProtocol *prot;
if (specific_trans) {
prot = new TBinaryProtocolT<Transport_, ByteOrder_>(
specific_trans, string_limit_, container_limit_, strict_read_,
strict_write_);
} else {
prot = new TBinaryProtocolT<TTransport, ByteOrder_>(
trans, string_limit_, container_limit_, strict_read_,
strict_write_);
}
return std::shared_ptr<TProtocol>(prot);
}
private:
int32_t string_limit_;
int32_t container_limit_;
bool strict_read_;
bool strict_write_;
};
typedef TBinaryProtocolFactoryT<TTransport> TBinaryProtocolFactory;
typedef TBinaryProtocolFactoryT<TTransport, TNetworkLittleEndian> TLEBinaryProtocolFactory;
} // namespace protocol
} // namespace thrift
} // namespace apache
#include <thrift/protocol/TBinaryProtocol.tcc>
#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_
``` | /content/code_sandbox/modules/thrift/src/thrift/protocol/TBinaryProtocol.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,829 |
```objective-c
/*
*
*/
#ifndef _THRIFT_TRANSPORT_TSERVERSOCKET_H_
#define _THRIFT_TRANSPORT_TSERVERSOCKET_H_ 1
#include <functional>
#include <thrift/concurrency/Mutex.h>
#include <thrift/transport/PlatformSocket.h>
#include <thrift/transport/TServerTransport.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#include <zephyr/posix/sys/socket.h>
#endif
#ifdef HAVE_NETDB_H
#include <zephyr/posix/netdb.h>
#endif
namespace apache
{
namespace thrift
{
namespace transport
{
class TSocket;
/**
* Server socket implementation of TServerTransport. Wrapper around a unix
* socket listen and accept calls.
*
*/
class TServerSocket : public TServerTransport
{
public:
typedef std::function<void(THRIFT_SOCKET fd)> socket_func_t;
const static int DEFAULT_BACKLOG = 1024;
/**
* Constructor.
*
* @param port Port number to bind to
*/
TServerSocket(int port);
/**
* Constructor.
*
* @param port Port number to bind to
* @param sendTimeout Socket send timeout
* @param recvTimeout Socket receive timeout
*/
TServerSocket(int port, int sendTimeout, int recvTimeout);
/**
* Constructor.
*
* @param address Address to bind to
* @param port Port number to bind to
*/
TServerSocket(const std::string &address, int port);
/**
* Constructor used for unix sockets.
*
* @param path Pathname for unix socket.
*/
TServerSocket(const std::string &path);
~TServerSocket() override;
bool isOpen() const override;
void setSendTimeout(int sendTimeout);
void setRecvTimeout(int recvTimeout);
void setAcceptTimeout(int accTimeout);
void setAcceptBacklog(int accBacklog);
void setRetryLimit(int retryLimit);
void setRetryDelay(int retryDelay);
void setKeepAlive(bool keepAlive)
{
keepAlive_ = keepAlive;
}
void setTcpSendBuffer(int tcpSendBuffer);
void setTcpRecvBuffer(int tcpRecvBuffer);
// listenCallback gets called just before listen, and after all Thrift
// setsockopt calls have been made. If you have custom setsockopt
// things that need to happen on the listening socket, this is the place to do it.
void setListenCallback(const socket_func_t &listenCallback)
{
listenCallback_ = listenCallback;
}
// acceptCallback gets called after each accept call, on the newly created socket.
// It is called after all Thrift setsockopt calls have been made. If you have
// custom setsockopt things that need to happen on the accepted
// socket, this is the place to do it.
void setAcceptCallback(const socket_func_t &acceptCallback)
{
acceptCallback_ = acceptCallback;
}
// When enabled (the default), new children TSockets will be constructed so
// they can be interrupted by TServerTransport::interruptChildren().
// This is more expensive in terms of system calls (poll + recv) however
// ensures a connected client cannot interfere with TServer::stop().
//
// When disabled, TSocket children do not incur an additional poll() call.
// Server-side reads are more efficient, however a client can interfere with
// the server's ability to shutdown properly by staying connected.
//
// Must be called before listen(); mode cannot be switched after that.
// \throws std::logic_error if listen() has been called
void setInterruptableChildren(bool enable);
THRIFT_SOCKET getSocketFD() override
{
return serverSocket_;
}
int getPort() const;
std::string getPath() const;
bool isUnixDomainSocket() const;
void listen() override;
void interrupt() override;
void interruptChildren() override;
void close() override;
protected:
std::shared_ptr<TTransport> acceptImpl() override;
virtual std::shared_ptr<TSocket> createSocket(THRIFT_SOCKET client);
bool interruptableChildren_;
std::shared_ptr<THRIFT_SOCKET> pChildInterruptSockReader_; // if interruptableChildren_ this
// is shared with child TSockets
void _setup_sockopts();
void _setup_tcp_sockopts();
private:
void notify(THRIFT_SOCKET notifySock);
void _setup_unixdomain_sockopts();
protected:
int port_;
std::string address_;
std::string path_;
THRIFT_SOCKET serverSocket_;
int acceptBacklog_;
int sendTimeout_;
int recvTimeout_;
int accTimeout_;
int retryLimit_;
int retryDelay_;
int tcpSendBuffer_;
int tcpRecvBuffer_;
bool keepAlive_;
bool listening_;
concurrency::Mutex rwMutex_; // thread-safe interrupt
THRIFT_SOCKET interruptSockWriter_; // is notified on interrupt()
THRIFT_SOCKET
interruptSockReader_; // is used in select/poll with serverSocket_ for interruptability
THRIFT_SOCKET childInterruptSockWriter_; // is notified on interruptChildren()
socket_func_t listenCallback_;
socket_func_t acceptCallback_;
};
} // namespace transport
} // namespace thrift
} // namespace apache
#endif // #ifndef _THRIFT_TRANSPORT_TSERVERSOCKET_H_
``` | /content/code_sandbox/modules/thrift/src/thrift/transport/TServerSocket.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,113 |
```objective-c
/*
*
*/
#ifndef _THRIFT_TRANSPORT_TSSLSOCKET_H_
#define _THRIFT_TRANSPORT_TSSLSOCKET_H_ 1
// Put this first to avoid WIN32 build failure
#include <thrift/transport/TSocket.h>
#include <string>
#include <thrift/concurrency/Mutex.h>
#include <zephyr/posix/sys/socket.h>
namespace apache
{
namespace thrift
{
namespace transport
{
class AccessManager;
class SSLContext;
enum SSLProtocol {
SSLTLS = 0, // Supports SSLv2 and SSLv3 handshake but only negotiates at TLSv1_0 or later.
// SSLv2 = 1, // HORRIBLY INSECURE!
SSLv3 = 2, // Supports SSLv3 only - also horribly insecure!
TLSv1_0 = 3, // Supports TLSv1_0 or later.
TLSv1_1 = 4, // Supports TLSv1_1 or later.
TLSv1_2 = 5, // Supports TLSv1_2 or later.
LATEST = TLSv1_2
};
#define TSSL_EINTR 0
#define TSSL_DATA 1
/**
* Initialize OpenSSL library. This function, or some other
* equivalent function to initialize OpenSSL, must be called before
* TSSLSocket is used. If you set TSSLSocketFactory to use manual
* OpenSSL initialization, you should call this function or otherwise
* ensure OpenSSL is initialized yourself.
*/
void initializeOpenSSL();
/**
* Cleanup OpenSSL library. This function should be called to clean
* up OpenSSL after use of OpenSSL functionality is finished. If you
* set TSSLSocketFactory to use manual OpenSSL initialization, you
* should call this function yourself or ensure that whatever
* initialized OpenSSL cleans it up too.
*/
void cleanupOpenSSL();
/**
* OpenSSL implementation for SSL socket interface.
*/
class TSSLSocket : public TSocket
{
public:
~TSSLSocket() override;
/**
* TTransport interface.
*/
void open() override;
/**
* Set whether to use client or server side SSL handshake protocol.
*
* @param flag Use server side handshake protocol if true.
*/
void server(bool flag)
{
server_ = flag;
}
/**
* Determine whether the SSL socket is server or client mode.
*/
bool server() const
{
return server_;
}
/**
* Set AccessManager.
*
* @param manager Instance of AccessManager
*/
virtual void access(std::shared_ptr<AccessManager> manager)
{
access_ = manager;
}
/**
* Set eventSafe flag if libevent is used.
*/
void setLibeventSafe()
{
eventSafe_ = true;
}
/**
* Determines whether SSL Socket is libevent safe or not.
*/
bool isLibeventSafe() const
{
return eventSafe_;
}
void authenticate(bool required);
protected:
/**
* Constructor.
*/
TSSLSocket(std::shared_ptr<SSLContext> ctx,
std::shared_ptr<TConfiguration> config = nullptr);
/**
* Constructor with an interrupt signal.
*/
TSSLSocket(std::shared_ptr<SSLContext> ctx,
std::shared_ptr<THRIFT_SOCKET> interruptListener,
std::shared_ptr<TConfiguration> config = nullptr);
/**
* Constructor, create an instance of TSSLSocket given an existing socket.
*
* @param socket An existing socket
*/
TSSLSocket(std::shared_ptr<SSLContext> ctx, THRIFT_SOCKET socket,
std::shared_ptr<TConfiguration> config = nullptr);
/**
* Constructor, create an instance of TSSLSocket given an existing socket that can be
* interrupted.
*
* @param socket An existing socket
*/
TSSLSocket(std::shared_ptr<SSLContext> ctx, THRIFT_SOCKET socket,
std::shared_ptr<THRIFT_SOCKET> interruptListener,
std::shared_ptr<TConfiguration> config = nullptr);
/**
* Constructor.
*
* @param host Remote host name
* @param port Remote port number
*/
TSSLSocket(std::shared_ptr<SSLContext> ctx, std::string host, int port,
std::shared_ptr<TConfiguration> config = nullptr);
/**
* Constructor with an interrupt signal.
*
* @param host Remote host name
* @param port Remote port number
*/
TSSLSocket(std::shared_ptr<SSLContext> ctx, std::string host, int port,
std::shared_ptr<THRIFT_SOCKET> interruptListener,
std::shared_ptr<TConfiguration> config = nullptr);
/**
* Authorize peer access after SSL handshake completes.
*/
virtual void authorize();
/**
* Initiate SSL handshake if not already initiated.
*/
void initializeHandshake();
/**
* Initiate SSL handshake params.
*/
void initializeHandshakeParams();
/**
* Check if SSL handshake is completed or not.
*/
bool checkHandshake();
/**
* Waits for an socket or shutdown event.
*
* @throw TTransportException::INTERRUPTED if interrupted is signaled.
*
* @return TSSL_EINTR if EINTR happened on the underlying socket
* TSSL_DATA if data is available on the socket.
*/
unsigned int waitForEvent(bool wantRead);
void openSecConnection(struct addrinfo *res);
bool server_;
std::shared_ptr<SSLContext> ctx_;
std::shared_ptr<AccessManager> access_;
friend class TSSLSocketFactory;
private:
bool handshakeCompleted_;
int readRetryCount_;
bool eventSafe_;
void init();
};
/**
* SSL socket factory. SSL sockets should be created via SSL factory.
* The factory will automatically initialize and cleanup openssl as long as
* there is a TSSLSocketFactory instantiated, and as long as the static
* boolean manualOpenSSLInitialization_ is set to false, the default.
*
* If you would like to initialize and cleanup openssl yourself, set
* manualOpenSSLInitialization_ to true and TSSLSocketFactory will no
* longer be responsible for openssl initialization and teardown.
*
* It is the responsibility of the code using TSSLSocketFactory to
* ensure that the factory lifetime exceeds the lifetime of any sockets
* it might create. If this is not guaranteed, a socket may call into
* openssl after the socket factory has cleaned up openssl! This
* guarantee is unnecessary if manualOpenSSLInitialization_ is true,
* however, since it would be up to the consuming application instead.
*/
class TSSLSocketFactory
{
public:
/**
* Constructor/Destructor
*
* @param protocol The SSL/TLS protocol to use.
*/
TSSLSocketFactory(SSLProtocol protocol = SSLTLS);
virtual ~TSSLSocketFactory();
/**
* Create an instance of TSSLSocket with a fresh new socket.
*/
virtual std::shared_ptr<TSSLSocket> createSocket();
/**
* Create an instance of TSSLSocket with a fresh new socket, which is interruptable.
*/
virtual std::shared_ptr<TSSLSocket>
createSocket(std::shared_ptr<THRIFT_SOCKET> interruptListener);
/**
* Create an instance of TSSLSocket with the given socket.
*
* @param socket An existing socket.
*/
virtual std::shared_ptr<TSSLSocket> createSocket(THRIFT_SOCKET socket);
/**
* Create an instance of TSSLSocket with the given socket which is interruptable.
*
* @param socket An existing socket.
*/
virtual std::shared_ptr<TSSLSocket>
createSocket(THRIFT_SOCKET socket, std::shared_ptr<THRIFT_SOCKET> interruptListener);
/**
* Create an instance of TSSLSocket.
*
* @param host Remote host to be connected to
* @param port Remote port to be connected to
*/
virtual std::shared_ptr<TSSLSocket> createSocket(const std::string &host, int port);
/**
* Create an instance of TSSLSocket.
*
* @param host Remote host to be connected to
* @param port Remote port to be connected to
*/
virtual std::shared_ptr<TSSLSocket>
createSocket(const std::string &host, int port,
std::shared_ptr<THRIFT_SOCKET> interruptListener);
/**
* Set ciphers to be used in SSL handshake process.
*
* @param ciphers A list of ciphers
*/
virtual void ciphers(const std::string &enable);
/**
* Enable/Disable authentication.
*
* @param required Require peer to present valid certificate if true
*/
virtual void authenticate(bool required);
/**
* Load server certificate.
*
* @param path Path to the certificate file
* @param format Certificate file format
*/
virtual void loadCertificate(const char *path, const char *format = "PEM");
virtual void loadCertificateFromBuffer(const char *aCertificate,
const char *format = "PEM");
/**
* Load private key.
*
* @param path Path to the private key file
* @param format Private key file format
*/
virtual void loadPrivateKey(const char *path, const char *format = "PEM");
virtual void loadPrivateKeyFromBuffer(const char *aPrivateKey, const char *format = "PEM");
/**
* Load trusted certificates from specified file.
*
* @param path Path to trusted certificate file
*/
virtual void loadTrustedCertificates(const char *path, const char *capath = nullptr);
virtual void loadTrustedCertificatesFromBuffer(const char *aCertificate,
const char *aChain = nullptr);
/**
* Default randomize method.
*/
virtual void randomize();
/**
* Override default OpenSSL password callback with getPassword().
*/
void overrideDefaultPasswordCallback();
/**
* Set/Unset server mode.
*
* @param flag Server mode if true
*/
virtual void server(bool flag);
/**
* Determine whether the socket is in server or client mode.
*
* @return true, if server mode, or, false, if client mode
*/
virtual bool server() const;
/**
* Set AccessManager.
*
* @param manager The AccessManager instance
*/
virtual void access(std::shared_ptr<AccessManager> manager)
{
access_ = manager;
}
static void setManualOpenSSLInitialization(bool manualOpenSSLInitialization)
{
manualOpenSSLInitialization_ = manualOpenSSLInitialization;
}
protected:
std::shared_ptr<SSLContext> ctx_;
/**
* Override this method for custom password callback. It may be called
* multiple times at any time during a session as necessary.
*
* @param password Pass collected password to OpenSSL
* @param size Maximum length of password including NULL character
*/
virtual void getPassword(std::string & /* password */, int /* size */)
{
}
private:
bool server_;
std::shared_ptr<AccessManager> access_;
static concurrency::Mutex mutex_;
static uint64_t count_;
THRIFT_EXPORT static bool manualOpenSSLInitialization_;
void setup(std::shared_ptr<TSSLSocket> ssl);
static int passwordCallback(char *password, int size, int, void *data);
};
/**
* SSL exception.
*/
class TSSLException : public TTransportException
{
public:
TSSLException(const std::string &message)
: TTransportException(TTransportException::INTERNAL_ERROR, message)
{
}
const char *what() const noexcept override
{
if (message_.empty()) {
return "TSSLException";
} else {
return message_.c_str();
}
}
};
struct SSLContext {
int verifyMode = TLS_PEER_VERIFY_REQUIRED;
net_ip_protocol_secure protocol = IPPROTO_TLS_1_0;
};
/**
* Callback interface for access control. It's meant to verify the remote host.
* It's constructed when application starts and set to TSSLSocketFactory
* instance. It's passed onto all TSSLSocket instances created by this factory
* object.
*/
class AccessManager
{
public:
enum Decision {
DENY = -1, // deny access
SKIP = 0, // cannot make decision, move on to next (if any)
ALLOW = 1 // allow access
};
/**
* Destructor
*/
virtual ~AccessManager() = default;
/**
* Determine whether the peer should be granted access or not. It's called
* once after the SSL handshake completes successfully, before peer certificate
* is examined.
*
* If a valid decision (ALLOW or DENY) is returned, the peer certificate is
* not to be verified.
*
* @param sa Peer IP address
* @return True if the peer is trusted, false otherwise
*/
virtual Decision verify(const sockaddr_storage & /* sa */) noexcept
{
return DENY;
}
/**
* Determine whether the peer should be granted access or not. It's called
* every time a DNS subjectAltName/common name is extracted from peer's
* certificate.
*
* @param host Client mode: host name returned by TSocket::getHost()
* Server mode: host name returned by TSocket::getPeerHost()
* @param name SubjectAltName or common name extracted from peer certificate
* @param size Length of name
* @return True if the peer is trusted, false otherwise
*
* Note: The "name" parameter may be UTF8 encoded.
*/
virtual Decision verify(const std::string & /* host */, const char * /* name */,
int /* size */) noexcept
{
return DENY;
}
/**
* Determine whether the peer should be granted access or not. It's called
* every time an IP subjectAltName is extracted from peer's certificate.
*
* @param sa Peer IP address retrieved from the underlying socket
* @param data IP address extracted from certificate
* @param size Length of the IP address
* @return True if the peer is trusted, false otherwise
*/
virtual Decision verify(const sockaddr_storage & /* sa */, const char * /* data */,
int /* size */) noexcept
{
return DENY;
}
};
typedef AccessManager::Decision Decision;
class DefaultClientAccessManager : public AccessManager
{
public:
// AccessManager interface
Decision verify(const sockaddr_storage &sa) noexcept override;
Decision verify(const std::string &host, const char *name, int size) noexcept override;
Decision verify(const sockaddr_storage &sa, const char *data, int size) noexcept override;
};
} // namespace transport
} // namespace thrift
} // namespace apache
#endif
``` | /content/code_sandbox/modules/thrift/src/thrift/transport/TSSLSocket.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 3,225 |
```objective-c
/*
*
*/
#ifndef your_sha256_hashYPE_H_
#define your_sha256_hashYPE_H_
namespace apache::thrift::transport
{
enum ThriftTLScertificateType {
Thrift_TLS_CA_CERT_TAG,
Thrift_TLS_SERVER_CERT_TAG,
Thrift_TLS_PRIVATE_KEY,
};
} // namespace apache::thrift::transport
#endif /* your_sha256_hashYPE_H_ */
``` | /content/code_sandbox/modules/thrift/src/thrift/transport/ThriftTLScertificateType.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 81 |
```c++
/*
*
*/
#include <cstring>
#include <zephyr/net/tls_credentials.h>
#include <zephyr/posix/sys/socket.h>
#include <zephyr/posix/unistd.h>
#include <thrift/thrift_export.h>
#include <thrift/transport/TSSLServerSocket.h>
#include <thrift/transport/TSSLSocket.h>
#include <thrift/transport/ThriftTLScertificateType.h>
#include <thrift/transport/TSocketUtils.h>
template <class T> inline void *cast_sockopt(T *v)
{
return reinterpret_cast<void *>(v);
}
void destroyer_of_fine_sockets(THRIFT_SOCKET *ssock);
namespace apache
{
namespace thrift
{
namespace transport
{
/**
* SSL server socket implementation.
*/
TSSLServerSocket::TSSLServerSocket(int port, std::shared_ptr<TSSLSocketFactory> factory)
: TServerSocket(port), factory_(factory)
{
factory_->server(true);
}
TSSLServerSocket::TSSLServerSocket(const std::string &address, int port,
std::shared_ptr<TSSLSocketFactory> factory)
: TServerSocket(address, port), factory_(factory)
{
factory_->server(true);
}
TSSLServerSocket::TSSLServerSocket(int port, int sendTimeout, int recvTimeout,
std::shared_ptr<TSSLSocketFactory> factory)
: TServerSocket(port, sendTimeout, recvTimeout), factory_(factory)
{
factory_->server(true);
}
std::shared_ptr<TSocket> TSSLServerSocket::createSocket(THRIFT_SOCKET client)
{
if (interruptableChildren_) {
return factory_->createSocket(client, pChildInterruptSockReader_);
} else {
return factory_->createSocket(client);
}
}
void TSSLServerSocket::listen()
{
THRIFT_SOCKET sv[2];
// Create the socket pair used to interrupt
if (-1 == THRIFT_SOCKETPAIR(AF_LOCAL, SOCK_STREAM, 0, sv)) {
GlobalOutput.perror("TServerSocket::listen() socketpair() interrupt",
THRIFT_GET_SOCKET_ERROR);
interruptSockWriter_ = THRIFT_INVALID_SOCKET;
interruptSockReader_ = THRIFT_INVALID_SOCKET;
} else {
interruptSockWriter_ = sv[1];
interruptSockReader_ = sv[0];
}
// Create the socket pair used to interrupt all clients
if (-1 == THRIFT_SOCKETPAIR(AF_LOCAL, SOCK_STREAM, 0, sv)) {
GlobalOutput.perror("TServerSocket::listen() socketpair() childInterrupt",
THRIFT_GET_SOCKET_ERROR);
childInterruptSockWriter_ = THRIFT_INVALID_SOCKET;
pChildInterruptSockReader_.reset();
} else {
childInterruptSockWriter_ = sv[1];
pChildInterruptSockReader_ = std::shared_ptr<THRIFT_SOCKET>(
new THRIFT_SOCKET(sv[0]), destroyer_of_fine_sockets);
}
// Validate port number
if (port_ < 0 || port_ > 0xFFFF) {
throw TTransportException(TTransportException::BAD_ARGS,
"Specified port is invalid");
}
// Resolve host:port strings into an iterable of struct addrinfo*
AddressResolutionHelper resolved_addresses;
try {
resolved_addresses.resolve(address_, std::to_string(port_), SOCK_STREAM,
AI_PASSIVE | AI_V4MAPPED);
} catch (const std::system_error &e) {
GlobalOutput.printf("getaddrinfo() -> %d; %s", e.code().value(), e.what());
close();
throw TTransportException(TTransportException::NOT_OPEN,
"Could not resolve host for server socket.");
}
// we may want to try to bind more than once, since THRIFT_NO_SOCKET_CACHING doesn't
// always seem to work. The client can configure the retry variables.
int retries = 0;
int errno_copy = 0;
// -- TCP socket -- //
auto addr_iter = AddressResolutionHelper::Iter{};
// Via DNS or somehow else, single hostname can resolve into many addresses.
// Results may contain perhaps a mix of IPv4 and IPv6. Here, we iterate
// over what system gave us, picking the first address that works.
do {
if (!addr_iter) {
// init + recycle over many retries
addr_iter = resolved_addresses.iterate();
}
auto trybind = *addr_iter++;
serverSocket_ = socket(trybind->ai_family, trybind->ai_socktype, IPPROTO_TLS_1_2);
if (serverSocket_ == -1) {
errno_copy = THRIFT_GET_SOCKET_ERROR;
continue;
}
_setup_sockopts();
_setup_tcp_sockopts();
static const sec_tag_t sec_tag_list[3] = {
Thrift_TLS_CA_CERT_TAG, Thrift_TLS_SERVER_CERT_TAG, Thrift_TLS_PRIVATE_KEY};
int ret = setsockopt(serverSocket_, SOL_TLS, TLS_SEC_TAG_LIST, sec_tag_list,
sizeof(sec_tag_list));
if (ret != 0) {
throw TTransportException(TTransportException::NOT_OPEN,
"set TLS_SEC_TAG_LIST failed");
}
#ifdef IPV6_V6ONLY
if (trybind->ai_family == AF_INET6) {
int zero = 0;
if (-1 == setsockopt(serverSocket_, IPPROTO_IPV6, IPV6_V6ONLY,
cast_sockopt(&zero), sizeof(zero))) {
GlobalOutput.perror("TServerSocket::listen() IPV6_V6ONLY ",
THRIFT_GET_SOCKET_ERROR);
}
}
#endif // #ifdef IPV6_V6ONLY
if (0 == ::bind(serverSocket_, trybind->ai_addr,
static_cast<int>(trybind->ai_addrlen))) {
break;
}
errno_copy = THRIFT_GET_SOCKET_ERROR;
// use short circuit evaluation here to only sleep if we need to
} while ((retries++ < retryLimit_) && (THRIFT_SLEEP_SEC(retryDelay_) == 0));
// retrieve bind info
if (port_ == 0 && retries <= retryLimit_) {
struct sockaddr_storage sa;
socklen_t len = sizeof(sa);
std::memset(&sa, 0, len);
if (::getsockname(serverSocket_, reinterpret_cast<struct sockaddr *>(&sa), &len) <
0) {
errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::getPort() getsockname() ", errno_copy);
} else {
if (sa.ss_family == AF_INET6) {
const auto *sin =
reinterpret_cast<const struct sockaddr_in6 *>(&sa);
port_ = ntohs(sin->sin6_port);
} else {
const auto *sin = reinterpret_cast<const struct sockaddr_in *>(&sa);
port_ = ntohs(sin->sin_port);
}
}
}
// throw error if socket still wasn't created successfully
if (serverSocket_ == THRIFT_INVALID_SOCKET) {
GlobalOutput.perror("TServerSocket::listen() socket() ", errno_copy);
close();
throw TTransportException(TTransportException::NOT_OPEN,
"Could not create server socket.", errno_copy);
}
// throw an error if we failed to bind properly
if (retries > retryLimit_) {
char errbuf[1024];
THRIFT_SNPRINTF(errbuf, sizeof(errbuf),
"TServerSocket::listen() Could not bind to port %d", port_);
GlobalOutput(errbuf);
close();
throw TTransportException(TTransportException::NOT_OPEN, "Could not bind",
errno_copy);
}
if (listenCallback_) {
listenCallback_(serverSocket_);
}
// Call listen
if (-1 == ::listen(serverSocket_, acceptBacklog_)) {
errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() listen() ", errno_copy);
close();
throw TTransportException(TTransportException::NOT_OPEN, "Could not listen",
errno_copy);
}
// The socket is now listening!
listening_ = true;
}
void TSSLServerSocket::close()
{
rwMutex_.lock();
if (pChildInterruptSockReader_ != nullptr &&
*pChildInterruptSockReader_ != THRIFT_INVALID_SOCKET) {
::THRIFT_CLOSESOCKET(*pChildInterruptSockReader_);
*pChildInterruptSockReader_ = THRIFT_INVALID_SOCKET;
}
rwMutex_.unlock();
TServerSocket::close();
}
} // namespace transport
} // namespace thrift
} // namespace apache
``` | /content/code_sandbox/modules/thrift/src/thrift/transport/TSSLServerSocket.cpp | c++ | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,854 |
```objective-c
/*
*
*/
#if FFCONF_DEF != 80286
#error "Configuration version mismatch"
#endif
/*
* Overrides of FF_ options from ffconf.h
*/
#if defined(CONFIG_FS_FATFS_READ_ONLY)
#undef FF_FS_READONLY
#define FF_FS_READONLY CONFIG_FS_FATFS_READ_ONLY
#endif /* defined(CONFIG_FS_FATFS_READ_ONLY) */
#if defined(CONFIG_FS_FATFS_MKFS)
#undef FF_USE_MKFS
#define FF_USE_MKFS CONFIG_FS_FATFS_MKFS
#else
/* Note that by default the ffconf.h disables MKFS */
#undef FF_USE_MKFS
#define FF_USE_MKFS 1
#endif /* defined(CONFIG_FS_FATFS_MKFS) */
#if defined(CONFIG_FS_FATFS_CODEPAGE)
#undef FF_CODE_PAGE
#define FF_CODE_PAGE CONFIG_FS_FATFS_CODEPAGE
#else
/* Note that default value, in ffconf.h, for FF_CODE_PAGE is 932 */
#undef FF_CODE_PAGE
#define FF_CODE_PAGE 437
#endif /* defined(CONFIG_FS_FATFS_CODEPAGE) */
#if defined(CONFIG_FS_FATFS_FF_USE_LFN)
#if CONFIG_FS_FATFS_FF_USE_LFN <= 3
#undef FF_USE_LFN
#define FF_USE_LFN CONFIG_FS_FATFS_FF_USE_LFN
#else
#error Invalid LFN buffer location
#endif
#endif /* defined(CONFIG_FS_FATFS_LFN) */
#if defined(CONFIG_FS_FATFS_MAX_LFN)
#undef FF_MAX_LFN
#define FF_MAX_LFN CONFIG_FS_FATFS_MAX_LFN
#endif /* defined(CONFIG_FS_FATFS_MAX_LFN) */
#if defined(CONFIG_FS_FATFS_MIN_SS)
#undef FF_MIN_SS
#define FF_MIN_SS CONFIG_FS_FATFS_MIN_SS
#endif /* defined(CONFIG_FS_FATFS_MIN_SS) */
#if defined(CONFIG_FS_FATFS_MAX_SS)
#undef FF_MAX_SS
#define FF_MAX_SS CONFIG_FS_FATFS_MAX_SS
#endif /* defined(CONFIG_FS_FATFS_MAX_SS) */
#if defined(CONFIG_FS_FATFS_EXFAT)
#undef FF_FS_EXFAT
#define FF_FS_EXFAT CONFIG_FS_FATFS_EXFAT
#endif /* defined(CONFIG_FS_FATFS_EXFAT) */
#if defined(CONFIG_FS_FATFS_REENTRANT)
#undef FF_FS_REENTRANT
#undef FF_FS_TIMEOUT
#include <zephyr/kernel.h>
#define FF_FS_REENTRANT CONFIG_FS_FATFS_REENTRANT
#define FF_FS_TIMEOUT K_FOREVER
#endif /* defined(CONFIG_FS_FATFS_REENTRANT) */
/*
* These options are override from default values, but have no Kconfig
* options.
*/
#undef FF_FS_TINY
#define FF_FS_TINY 1
#undef FF_FS_NORTC
#define FF_FS_NORTC 1
/* Zephyr uses FF_VOLUME_STRS */
#undef FF_STR_VOLUME_ID
#define FF_STR_VOLUME_ID 1
/* By default FF_STR_VOLUME_ID in ffconf.h is 0, which means that
* FF_VOLUME_STRS is not used. Zephyr uses FF_VOLUME_STRS, which
* by default holds 8 possible strings representing mount points,
* and FF_VOLUMES needs to reflect that, which means that dolt
* value of 1 is overridden here with 8.
*/
#undef FF_VOLUMES
#define FF_VOLUMES 8
/*
* Options provided below have been added to ELM FAT source code to
* support Zephyr specific features, and are not part of ffconf.h.
*/
/*
* The FS_FATFS_WINDOW_ALIGNMENT is used to align win buffer of FATFS structure
* to allow more optimal use with MCUs that require specific bufer alignment
* for DMA to work.
*/
#if defined(CONFIG_FS_FATFS_WINDOW_ALIGNMENT)
#define FS_FATFS_WINDOW_ALIGNMENT CONFIG_FS_FATFS_WINDOW_ALIGNMENT
#else
#define FS_FATFS_WINDOW_ALIGNMENT 1
#endif /* defined(CONFIG_FS_FATFS_WINDOW_ALIGNMENT) */
``` | /content/code_sandbox/modules/fatfs/zephyr_fatfs_config.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 841 |
```c
/*
*
*/
/* The file is based on template file by (C)ChaN, 2019, as
* available from FAT FS module source:
* path_to_url
* and has been previously avaialble from directory for that module
* under name zfs_diskio.c.
*/
#include <ff.h>
#include <diskio.h> /* FatFs lower layer API */
#include <zfs_diskio.h> /* Zephyr specific FatFS API */
#include <zephyr/storage/disk_access.h>
static const char * const pdrv_str[] = {FF_VOLUME_STRS};
/* Get Drive Status */
DSTATUS disk_status(BYTE pdrv)
{
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
if (disk_access_status(pdrv_str[pdrv]) != 0) {
return STA_NOINIT;
} else {
return RES_OK;
}
}
/* Initialize a Drive */
DSTATUS disk_initialize(BYTE pdrv)
{
uint8_t param = DISK_IOCTL_POWER_ON;
return disk_ioctl(pdrv, CTRL_POWER, ¶m);
}
/* Read Sector(s) */
DRESULT disk_read(BYTE pdrv, BYTE *buff, LBA_t sector, UINT count)
{
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
if (disk_access_read(pdrv_str[pdrv], buff, sector, count) != 0) {
return RES_ERROR;
} else {
return RES_OK;
}
}
/* Write Sector(s) */
DRESULT disk_write(BYTE pdrv, const BYTE *buff, LBA_t sector, UINT count)
{
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
if (disk_access_write(pdrv_str[pdrv], buff, sector, count) != 0) {
return RES_ERROR;
} else {
return RES_OK;
}
}
/* Miscellaneous Functions */
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
{
int ret = RES_OK;
uint32_t sector_size = 0;
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
switch (cmd) {
case CTRL_SYNC:
if (disk_access_ioctl(pdrv_str[pdrv],
DISK_IOCTL_CTRL_SYNC, buff) != 0) {
ret = RES_ERROR;
}
break;
case GET_SECTOR_COUNT:
if (disk_access_ioctl(pdrv_str[pdrv],
DISK_IOCTL_GET_SECTOR_COUNT, buff) != 0) {
ret = RES_ERROR;
}
break;
case GET_SECTOR_SIZE:
/* Zephyr's DISK_IOCTL_GET_SECTOR_SIZE returns sector size as a
* 32-bit number while FatFS's GET_SECTOR_SIZE is supposed to
* return a 16-bit number.
*/
if ((disk_access_ioctl(pdrv_str[pdrv],
DISK_IOCTL_GET_SECTOR_SIZE, §or_size) == 0) &&
(sector_size == (uint16_t)sector_size)) {
*(uint16_t *)buff = (uint16_t)sector_size;
} else {
ret = RES_ERROR;
}
break;
case GET_BLOCK_SIZE:
if (disk_access_ioctl(pdrv_str[pdrv],
DISK_IOCTL_GET_ERASE_BLOCK_SZ, buff) != 0) {
ret = RES_ERROR;
}
break;
/* Optional IOCTL command used by Zephyr fs_unmount implementation,
* not called by FATFS
*/
case CTRL_POWER:
if (((*(uint8_t *)buff)) == DISK_IOCTL_POWER_OFF) {
/* Power disk off */
if (disk_access_ioctl(pdrv_str[pdrv],
DISK_IOCTL_CTRL_DEINIT,
NULL) != 0) {
ret = RES_ERROR;
}
} else {
/* Power disk on */
if (disk_access_ioctl(pdrv_str[pdrv],
DISK_IOCTL_CTRL_INIT,
NULL) != 0) {
ret = STA_NOINIT;
}
}
break;
default:
ret = RES_PARERR;
break;
}
return ret;
}
``` | /content/code_sandbox/modules/fatfs/zfs_diskio.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 901 |
```c
/*
* OS Dependent Functions for FatFs
*
*
*/
/* The file is based on template file by (C)ChaN, 2022, as
* available from FAT FS module source:
* path_to_url
*/
#include <zephyr/kernel.h>
#include <ff.h>
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
/* Allocate a memory block */
void *ff_memalloc(UINT msize)
{
return k_malloc(msize);
}
/* Free a memory block */
void ff_memfree(void *mblock)
{
k_free(mblock);
}
#endif /* FF_USE_LFN == 3 */
#if FF_FS_REENTRANT /* Mutual exclusion */
/* Table of Zephyr mutex. One for each volume and an extra one for the ff system.
* See also the template file used as reference. Link is available in the header of this file.
*/
static struct k_mutex fs_reentrant_mutex[FF_VOLUMES + 1];
/* Create a Mutex
* Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES)
* Returns 1: Succeeded or 0: Could not create the mutex
*/
int ff_mutex_create(int vol)
{
return (int)(k_mutex_init(&fs_reentrant_mutex[vol]) == 0);
}
/* Delete a Mutex
* Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES)
*/
void ff_mutex_delete(int vol)
{
/* (nothing to do) */
(void)vol;
}
/* Request Grant to Access the Volume
* Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES)
* Returns 1: Succeeded or 0: Timeout
*/
int ff_mutex_take(int vol)
{
return (int)(k_mutex_lock(&fs_reentrant_mutex[vol], FF_FS_TIMEOUT) == 0);
}
/* Release Grant to Access the Volume
* Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES)
*/
void ff_mutex_give(int vol)
{
k_mutex_unlock(&fs_reentrant_mutex[vol]);
}
#endif /* FF_FS_REENTRANT */
``` | /content/code_sandbox/modules/fatfs/zfs_ffsystem.c | c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 482 |
```unknown
config ZEPHYR_FATFSFS_MODULE
bool
# Configuration of ELM FAT is found in subsys/fs/Kconfig.fatfs for historic
# reasons.
``` | /content/code_sandbox/modules/fatfs/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 38 |
```objective-c
/*
*
*/
#ifndef ZEPHYR_MODULES_FATFS_ZFS_DISKIO_H_
#define ZEPHYR_MODULES_FATFS_ZFS_DISKIO_H_
/*
* Header file for Zephyr specific portions of the FatFS disk interface.
* These APIs are internal to Zephyr's FatFS VFS implementation
*/
/*
* Values that can be passed to buffer pointer used by disk_ioctl() when
* sending CTRL_POWER IOCTL
*/
#define DISK_IOCTL_POWER_OFF 0x0
#define DISK_IOCTL_POWER_ON 0x1
#endif /* ZEPHYR_MODULES_FATFS_ZFS_DISKIO_H_ */
``` | /content/code_sandbox/modules/fatfs/zfs_diskio.h | objective-c | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 131 |
```unknown
config ZEPHYR_HAL_GIGADEVICE_MODULE
bool
config GD32_HAS_AF_PINMUX
bool
help
This option should be selected if the series use an AF pinmux model.
config GD32_HAS_AFIO_PINMUX
bool
help
This option should be selected if the series use an AFIO pinmux model.
config HAS_GD32_HAL
bool
select HAS_CMSIS_CORE if ARM
if HAS_GD32_HAL
choice GD32_HXTAL_FREQUENCY
prompt "High speed external oscillator clock frequency"
default GD32_HXTAL_FIRMWARE_DEFINED if \
SOC_SERIES_GD32F403 || SOC_SERIES_GD32F4XX || SOC_SERIES_GD32F3X0
default GD32_HXTAL_25MHZ if SOC_SERIES_GD32VF103 || SOC_SERIES_GD32E50X
default GD32_HXTAL_8MHZ if SOC_SERIES_GD32E10X
help
Define value of high speed crystal oscillator (HXTAL) in Hz
This value sets the frequency of the oscillator.
config GD32_HXTAL_FIRMWARE_DEFINED
bool "Firmware defined"
depends on !SOC_SERIES_GD32VF103
depends on !SOC_SERIES_GD32E10X
help
Use default frequency defined in firmware for HXTAL
This is using for SoCs (e.g. gd32f4xx, gd32f3x0, etc ...)
that have default HXTAL definitions in firmware.
config GD32_HXTAL_8MHZ
bool "8MHz"
depends on SOC_SERIES_GD32VF103 || SOC_SERIES_GD32E10X
help
Use 8MHz oscillator for HXTAL
config GD32_HXTAL_25MHZ
bool "25MHz"
depends on SOC_SERIES_GD32VF103 || SOC_SERIES_GD32E10X
help
Use 25MHz oscillator for HXTAL
endchoice
config GD32_HAS_IRC_32K
bool
help
Use 32KHz oscillator for low speed internal RC Oscillator
config GD32_HAS_IRC_40K
bool
help
Use 40KHz oscillator for low speed internal RC Oscillator
config GD32_LOW_SPEED_IRC_FREQUENCY
int
default 32000 if GD32_HAS_IRC_32K
default 40000 if GD32_HAS_IRC_40K
help
Define value of low speed internal RC oscillator (IRC) in Hz
config GD32_DBG_SUPPORT
bool "Use GD32 Debug features"
select USE_GD32_DBG
default y
help
Enable GD32 Debug features.
This option makes allows using functions that access to
DBG_CTL register such as dbg_periph_enable().
config USE_GD32_ADC
bool
help
Enable GD32 Analog-to-Digital Converter (ADC) HAL module driver
config USE_GD32_BKP
bool
help
Enable GD32 Backup Registers (BKP) HAL module driver
config USE_GD32_CAN
bool
help
Enable GD32 Controller Area Network (CAN) HAL module driver
config USE_GD32_CEC
bool
help
Enable GD32 Consumer Electronics Control (CEC) HAL module driver
config USE_GD32_CMP
bool
help
Enable GD32 Comparator (CMP) HAL module driver
config USE_GD32_CRC
bool
help
Enable GD32 Cyclic redundancy check calculation unit (CRC) HAL
module driver
config USE_GD32_CTC
bool
help
Enable GD32 Clock Trim Controller (CTC) HAL module driver
config USE_GD32_DAC
bool
help
Enable GD32 Digital-to-Analog Converter (DAC) HAL module driver
config USE_GD32_DBG
bool
help
Enable GD32 Debug (DBG) HAL module driver
config USE_GD32_DCI
bool
help
Enable GD32 Digital Camera Interface (DCI) HAL module driver
config USE_GD32_DMA
bool
help
Enable GD32 Direct Memory Access controller (DMA) HAL module driver
config USE_GD32_ENET
bool
help
Enable GD32 Ethernet (ENET) HAL module driver
config USE_GD32_EXMC
bool
help
Enable GD32 External Memory Controller (EXMC) HAL module driver
config USE_GD32_EXTI
bool
help
Enable GD32 Interrupt/Event controller (EXTI) HAL module driver
config USE_GD32_FMC
bool
help
Enable GD32 Flash Memory Controller (FMC) HAL module driver
config USE_GD32_FWDGT
bool
help
Enable GD32 Free Watchdog Timer (FWDGT) HAL module driver
config USE_GD32_GPIO
bool
default y
help
Enable GD32 General-purpose and Alternate-Function I/Os
(GPIO and AFIO) HAL module driver
config USE_GD32_I2C
bool
help
Enable GD32 Inter-Integrated Circuit Interface (I2C) HAL module driver
config USE_GD32_IPA
bool
help
Enable GD32 Image Processing Accelerator (IPA) HAL module driver
config USE_GD32_IREF
bool
help
Enable GD32 Programmable Current Reference (IREF) HAL module driver
config USE_GD32_MISC
bool
help
Enable GD32 System Utilities (MISC) HAL module driver
config USE_GD32_PMU
bool
help
Enable GD32 Power Management Unit (PMU) HAL module driver
config USE_GD32_RCU
bool
default y
help
Enable GD32 Reset and Clock Unit (RCU) HAL module driver
config USE_GD32_RTC
bool
help
Enable GD32 Real-Time Clock (RTC) HAL module driver
config USE_GD32_SDIO
bool
help
Enable GD32 Secure Digital Input/Output interface (SDIO) HAL module
driver
config USE_GD32_SPI
bool
help
Enable GD32 Serial Peripheral Interface(SPI) HAL module driver
config USE_GD32_SQPI
bool
help
Enable GD32 Serial/Quad Parallel Interface (SQPI) HAL module driver
config USE_GD32_SHRTIMER
bool
help
Enable GD32 Super High-Resolution Timer (SHRTIMER) HAL module driver
config USE_GD32_SYSCFG
bool
help
Enable GD32 System Configuration (SYSCFG) HAL module driver
config USE_GD32_TIMER
bool
help
Enable GD32 Timer (TIMER) HAL module driver
config USE_GD32_TLI
bool
help
Enable GD32 TFT-LCD Interface (TLI) HAL module driver
config USE_GD32_TMU
bool
help
Enable GD32 Trigonometric Math Unit (TMU) HAL module driver
config USE_GD32_TRNG
bool
help
Enable GD32 True Random Number Generator (TRNG) HAL module driver
config USE_GD32_TSI
bool
help
Enable GD32 Touch Sensing Interface (TSI) HAL module driver
config USE_GD32_USART
bool
help
Enable GD32 Universal Synchronous/Asynchronous Receiver/Transmitter
(USART) HAL module driver
config USE_GD32_USBD
bool
help
Enable GD32 Universal Serial Bus full-speed Device interface (USBD)
HAL module driver
config USE_GD32_USBFS
bool
help
Enable GD32 Universal Serial Bus on-the-go Full-Speed (USBFS) HAL
module driver
config USE_GD32_USBHS
bool
help
Enable GD32 Universal Serial Bus High-Speed interface (USBHS) HAL
module driver
config USE_GD32_WWDGT
bool
help
Enable GD32 Window Watchdog Timer (WWDGT) HAL module driver
endif # HAS_GD32_HAL
``` | /content/code_sandbox/modules/hal_gigadevice/Kconfig | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 1,718 |
```c++
/*
*
*/
#include <thrift/thrift-config.h>
#include <cstring>
#include <errno.h>
#include <memory>
#include <string>
#ifdef HAVE_ARPA_INET_H
#include <zephyr/posix/arpa/inet.h>
#endif
#include <sys/types.h>
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#include <zephyr/net/tls_credentials.h>
#include <fcntl.h>
#include <thrift/TToString.h>
#include <thrift/concurrency/Mutex.h>
#include <thrift/transport/PlatformSocket.h>
#include <thrift/transport/TSSLSocket.h>
#include <thrift/transport/ThriftTLScertificateType.h>
using namespace apache::thrift::concurrency;
using std::string;
struct CRYPTO_dynlock_value {
Mutex mutex;
};
namespace apache
{
namespace thrift
{
namespace transport
{
static bool matchName(const char *host, const char *pattern, int size);
static char uppercase(char c);
// TSSLSocket implementation
TSSLSocket::TSSLSocket(std::shared_ptr<SSLContext> ctx, std::shared_ptr<TConfiguration> config)
: TSocket(config), server_(false), ctx_(ctx)
{
init();
}
TSSLSocket::TSSLSocket(std::shared_ptr<SSLContext> ctx,
std::shared_ptr<THRIFT_SOCKET> interruptListener,
std::shared_ptr<TConfiguration> config)
: TSocket(config), server_(false), ctx_(ctx)
{
init();
interruptListener_ = interruptListener;
}
TSSLSocket::TSSLSocket(std::shared_ptr<SSLContext> ctx, THRIFT_SOCKET socket,
std::shared_ptr<TConfiguration> config)
: TSocket(socket, config), server_(false), ctx_(ctx)
{
init();
}
TSSLSocket::TSSLSocket(std::shared_ptr<SSLContext> ctx, THRIFT_SOCKET socket,
std::shared_ptr<THRIFT_SOCKET> interruptListener,
std::shared_ptr<TConfiguration> config)
: TSocket(socket, interruptListener, config), server_(false), ctx_(ctx)
{
init();
}
TSSLSocket::TSSLSocket(std::shared_ptr<SSLContext> ctx, string host, int port,
std::shared_ptr<TConfiguration> config)
: TSocket(host, port, config), server_(false), ctx_(ctx)
{
init();
}
TSSLSocket::TSSLSocket(std::shared_ptr<SSLContext> ctx, string host, int port,
std::shared_ptr<THRIFT_SOCKET> interruptListener,
std::shared_ptr<TConfiguration> config)
: TSocket(host, port, config), server_(false), ctx_(ctx)
{
init();
interruptListener_ = interruptListener;
}
TSSLSocket::~TSSLSocket()
{
close();
}
template <class T> inline void *cast_sockopt(T *v)
{
return reinterpret_cast<void *>(v);
}
void TSSLSocket::authorize()
{
}
void TSSLSocket::openSecConnection(struct addrinfo *res)
{
socket_ = socket(res->ai_family, res->ai_socktype, ctx_->protocol);
if (socket_ == THRIFT_INVALID_SOCKET) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::open() socket() " + getSocketInfo(), errno_copy);
throw TTransportException(TTransportException::NOT_OPEN, "socket()", errno_copy);
}
static const sec_tag_t sec_tag_list[3] = {
Thrift_TLS_CA_CERT_TAG, Thrift_TLS_SERVER_CERT_TAG, Thrift_TLS_PRIVATE_KEY};
int ret =
setsockopt(socket_, SOL_TLS, TLS_SEC_TAG_LIST, sec_tag_list, sizeof(sec_tag_list));
if (ret != 0) {
throw TTransportException(TTransportException::NOT_OPEN,
"set TLS_SEC_TAG_LIST failed");
}
ret = setsockopt(socket_, SOL_TLS, TLS_PEER_VERIFY, &(ctx_->verifyMode),
sizeof(ctx_->verifyMode));
if (ret != 0) {
throw TTransportException(TTransportException::NOT_OPEN,
"set TLS_PEER_VERIFY failed");
}
ret = setsockopt(socket_, SOL_TLS, TLS_HOSTNAME, host_.c_str(), host_.size());
if (ret != 0) {
throw TTransportException(TTransportException::NOT_OPEN, "set TLS_HOSTNAME failed");
}
// Send timeout
if (sendTimeout_ > 0) {
setSendTimeout(sendTimeout_);
}
// Recv timeout
if (recvTimeout_ > 0) {
setRecvTimeout(recvTimeout_);
}
if (keepAlive_) {
setKeepAlive(keepAlive_);
}
// Linger
setLinger(lingerOn_, lingerVal_);
// No delay
setNoDelay(noDelay_);
#ifdef SO_NOSIGPIPE
{
int one = 1;
setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one));
}
#endif
// Uses a low min RTO if asked to.
#ifdef TCP_LOW_MIN_RTO
if (getUseLowMinRto()) {
int one = 1;
setsockopt(socket_, IPPROTO_TCP, TCP_LOW_MIN_RTO, &one, sizeof(one));
}
#endif
// Set the socket to be non blocking for connect if a timeout exists
int flags = THRIFT_FCNTL(socket_, THRIFT_F_GETFL, 0);
if (connTimeout_ > 0) {
if (-1 == THRIFT_FCNTL(socket_, THRIFT_F_SETFL, flags | THRIFT_O_NONBLOCK)) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::open() THRIFT_FCNTL() " + getSocketInfo(),
errno_copy);
throw TTransportException(TTransportException::NOT_OPEN,
"THRIFT_FCNTL() failed", errno_copy);
}
} else {
if (-1 == THRIFT_FCNTL(socket_, THRIFT_F_SETFL, flags & ~THRIFT_O_NONBLOCK)) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::open() THRIFT_FCNTL " + getSocketInfo(),
errno_copy);
throw TTransportException(TTransportException::NOT_OPEN,
"THRIFT_FCNTL() failed", errno_copy);
}
}
// Connect the socket
ret = connect(socket_, res->ai_addr, static_cast<int>(res->ai_addrlen));
// success case
if (ret == 0) {
goto done;
}
if ((THRIFT_GET_SOCKET_ERROR != THRIFT_EINPROGRESS) &&
(THRIFT_GET_SOCKET_ERROR != THRIFT_EWOULDBLOCK)) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::open() connect() " + getSocketInfo(), errno_copy);
throw TTransportException(TTransportException::NOT_OPEN, "connect() failed",
errno_copy);
}
struct THRIFT_POLLFD fds[1];
std::memset(fds, 0, sizeof(fds));
fds[0].fd = socket_;
fds[0].events = THRIFT_POLLOUT;
ret = THRIFT_POLL(fds, 1, connTimeout_);
if (ret > 0) {
// Ensure the socket is connected and that there are no errors set
int val;
socklen_t lon;
lon = sizeof(int);
int ret2 = getsockopt(socket_, SOL_SOCKET, SO_ERROR, cast_sockopt(&val), &lon);
if (ret2 == -1) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::open() getsockopt() " + getSocketInfo(),
errno_copy);
throw TTransportException(TTransportException::NOT_OPEN, "getsockopt()",
errno_copy);
}
// no errors on socket, go to town
if (val == 0) {
goto done;
}
GlobalOutput.perror("TSocket::open() error on socket (after THRIFT_POLL) " +
getSocketInfo(),
val);
throw TTransportException(TTransportException::NOT_OPEN, "socket open() error",
val);
} else if (ret == 0) {
// socket timed out
string errStr = "TSocket::open() timed out " + getSocketInfo();
GlobalOutput(errStr.c_str());
throw TTransportException(TTransportException::NOT_OPEN, "open() timed out");
} else {
// error on THRIFT_POLL()
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::open() THRIFT_POLL() " + getSocketInfo(), errno_copy);
throw TTransportException(TTransportException::NOT_OPEN, "THRIFT_POLL() failed",
errno_copy);
}
done:
// Set socket back to normal mode (blocking)
if (-1 == THRIFT_FCNTL(socket_, THRIFT_F_SETFL, flags)) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::open() THRIFT_FCNTL " + getSocketInfo(), errno_copy);
throw TTransportException(TTransportException::NOT_OPEN, "THRIFT_FCNTL() failed",
errno_copy);
}
setCachedAddress(res->ai_addr, static_cast<socklen_t>(res->ai_addrlen));
}
void TSSLSocket::init()
{
handshakeCompleted_ = false;
readRetryCount_ = 0;
eventSafe_ = false;
}
void TSSLSocket::open()
{
if (isOpen() || server()) {
throw TTransportException(TTransportException::BAD_ARGS);
}
// Validate port number
if (port_ < 0 || port_ > 0xFFFF) {
throw TTransportException(TTransportException::BAD_ARGS,
"Specified port is invalid");
}
struct addrinfo hints, *res, *res0;
res = nullptr;
res0 = nullptr;
int error;
char port[sizeof("65535")];
std::memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
sprintf(port, "%d", port_);
error = getaddrinfo(host_.c_str(), port, &hints, &res0);
if (error == DNS_EAI_NODATA) {
hints.ai_flags &= ~AI_ADDRCONFIG;
error = getaddrinfo(host_.c_str(), port, &hints, &res0);
}
if (error) {
string errStr = "TSocket::open() getaddrinfo() " + getSocketInfo() +
string(THRIFT_GAI_STRERROR(error));
GlobalOutput(errStr.c_str());
close();
throw TTransportException(TTransportException::NOT_OPEN,
"Could not resolve host for client socket.");
}
// Cycle through all the returned addresses until one
// connects or push the exception up.
for (res = res0; res; res = res->ai_next) {
try {
openSecConnection(res);
break;
} catch (TTransportException &) {
if (res->ai_next) {
close();
} else {
close();
freeaddrinfo(res0); // cleanup on failure
throw;
}
}
}
// Free address structure memory
freeaddrinfo(res0);
}
TSSLSocketFactory::TSSLSocketFactory(SSLProtocol protocol)
: ctx_(std::make_shared<SSLContext>()), server_(false)
{
switch (protocol) {
case SSLTLS:
break;
case TLSv1_0:
break;
case TLSv1_1:
ctx_->protocol = IPPROTO_TLS_1_1;
break;
case TLSv1_2:
ctx_->protocol = IPPROTO_TLS_1_2;
break;
default:
throw TTransportException(TTransportException::BAD_ARGS,
"Specified protocol is invalid");
}
}
TSSLSocketFactory::~TSSLSocketFactory()
{
}
std::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket()
{
std::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_));
setup(ssl);
return ssl;
}
std::shared_ptr<TSSLSocket>
TSSLSocketFactory::createSocket(std::shared_ptr<THRIFT_SOCKET> interruptListener)
{
std::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, interruptListener));
setup(ssl);
return ssl;
}
std::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(THRIFT_SOCKET socket)
{
std::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, socket));
setup(ssl);
return ssl;
}
std::shared_ptr<TSSLSocket>
TSSLSocketFactory::createSocket(THRIFT_SOCKET socket,
std::shared_ptr<THRIFT_SOCKET> interruptListener)
{
std::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, socket, interruptListener));
setup(ssl);
return ssl;
}
std::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(const string &host, int port)
{
std::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, host, port));
setup(ssl);
return ssl;
}
std::shared_ptr<TSSLSocket>
TSSLSocketFactory::createSocket(const string &host, int port,
std::shared_ptr<THRIFT_SOCKET> interruptListener)
{
std::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, host, port, interruptListener));
setup(ssl);
return ssl;
}
static void tlsCredtErrMsg(string &errors, const int status);
void TSSLSocketFactory::setup(std::shared_ptr<TSSLSocket> ssl)
{
ssl->server(server());
if (access_ == nullptr && !server()) {
access_ = std::shared_ptr<AccessManager>(new DefaultClientAccessManager);
}
if (access_ != nullptr) {
ssl->access(access_);
}
}
void TSSLSocketFactory::ciphers(const string &enable)
{
}
void TSSLSocketFactory::authenticate(bool required)
{
if (required) {
ctx_->verifyMode = TLS_PEER_VERIFY_REQUIRED;
} else {
ctx_->verifyMode = TLS_PEER_VERIFY_NONE;
}
}
void TSSLSocketFactory::loadCertificate(const char *path, const char *format)
{
if (path == nullptr || format == nullptr) {
throw TTransportException(
TTransportException::BAD_ARGS,
"loadCertificateChain: either <path> or <format> is nullptr");
}
if (strcmp(format, "PEM") == 0) {
} else {
throw TSSLException("Unsupported certificate format: " + string(format));
}
}
void TSSLSocketFactory::loadCertificateFromBuffer(const char *aCertificate, const char *format)
{
if (aCertificate == nullptr || format == nullptr) {
throw TTransportException(TTransportException::BAD_ARGS,
"loadCertificate: either <path> or <format> is nullptr");
}
if (strcmp(format, "PEM") == 0) {
const int status = tls_credential_add(Thrift_TLS_SERVER_CERT_TAG,
TLS_CREDENTIAL_SERVER_CERTIFICATE,
aCertificate, strlen(aCertificate) + 1);
if (status != 0) {
string errors;
tlsCredtErrMsg(errors, status);
throw TSSLException("tls_credential_add: " + errors);
}
} else {
throw TSSLException("Unsupported certificate format: " + string(format));
}
}
void TSSLSocketFactory::loadPrivateKey(const char *path, const char *format)
{
if (path == nullptr || format == nullptr) {
throw TTransportException(TTransportException::BAD_ARGS,
"loadPrivateKey: either <path> or <format> is nullptr");
}
if (strcmp(format, "PEM") == 0) {
if (0) {
string errors;
// tlsCredtErrMsg(errors, status);
throw TSSLException("SSL_CTX_use_PrivateKey_file: " + errors);
}
}
}
void TSSLSocketFactory::loadPrivateKeyFromBuffer(const char *aPrivateKey, const char *format)
{
if (aPrivateKey == nullptr || format == nullptr) {
throw TTransportException(TTransportException::BAD_ARGS,
"loadPrivateKey: either <path> or <format> is nullptr");
}
if (strcmp(format, "PEM") == 0) {
const int status =
tls_credential_add(Thrift_TLS_PRIVATE_KEY, TLS_CREDENTIAL_PRIVATE_KEY,
aPrivateKey, strlen(aPrivateKey) + 1);
if (status != 0) {
string errors;
tlsCredtErrMsg(errors, status);
throw TSSLException("SSL_CTX_use_PrivateKey: " + errors);
}
} else {
throw TSSLException("Unsupported certificate format: " + string(format));
}
}
void TSSLSocketFactory::loadTrustedCertificates(const char *path, const char *capath)
{
if (path == nullptr) {
throw TTransportException(TTransportException::BAD_ARGS,
"loadTrustedCertificates: <path> is nullptr");
}
if (0) {
string errors;
// tlsCredtErrMsg(errors, status);
throw TSSLException("SSL_CTX_load_verify_locations: " + errors);
}
}
void TSSLSocketFactory::loadTrustedCertificatesFromBuffer(const char *aCertificate,
const char *aChain)
{
if (aCertificate == nullptr) {
throw TTransportException(TTransportException::BAD_ARGS,
"loadTrustedCertificates: aCertificate is empty");
}
const int status = tls_credential_add(Thrift_TLS_CA_CERT_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
aCertificate, strlen(aCertificate) + 1);
if (status != 0) {
string errors;
tlsCredtErrMsg(errors, status);
throw TSSLException("X509_STORE_add_cert: " + errors);
}
if (aChain) {
}
}
void TSSLSocketFactory::randomize()
{
}
void TSSLSocketFactory::overrideDefaultPasswordCallback()
{
}
void TSSLSocketFactory::server(bool flag)
{
server_ = flag;
ctx_->verifyMode = TLS_PEER_VERIFY_NONE;
}
bool TSSLSocketFactory::server() const
{
return server_;
}
int TSSLSocketFactory::passwordCallback(char *password, int size, int, void *data)
{
auto *factory = (TSSLSocketFactory *)data;
string userPassword;
factory->getPassword(userPassword, size);
int length = static_cast<int>(userPassword.size());
if (length > size) {
length = size;
}
strncpy(password, userPassword.c_str(), length);
userPassword.assign(userPassword.size(), '*');
return length;
}
// extract error messages from error queue
static void tlsCredtErrMsg(string &errors, const int status)
{
if (status == EACCES) {
errors = "Access to the TLS credential subsystem was denied";
} else if (status == ENOMEM) {
errors = "Not enough memory to add new TLS credential";
} else if (status == EEXIST) {
errors = "TLS credential of specific tag and type already exists";
} else {
errors = "Unknown error";
}
}
/**
* Default implementation of AccessManager
*/
Decision DefaultClientAccessManager::verify(const sockaddr_storage &sa) noexcept
{
(void)sa;
return SKIP;
}
Decision DefaultClientAccessManager::verify(const string &host, const char *name, int size) noexcept
{
if (host.empty() || name == nullptr || size <= 0) {
return SKIP;
}
return (matchName(host.c_str(), name, size) ? ALLOW : SKIP);
}
Decision DefaultClientAccessManager::verify(const sockaddr_storage &sa, const char *data,
int size) noexcept
{
bool match = false;
if (sa.ss_family == AF_INET && size == sizeof(in_addr)) {
match = (memcmp(&((sockaddr_in *)&sa)->sin_addr, data, size) == 0);
} else if (sa.ss_family == AF_INET6 && size == sizeof(in6_addr)) {
match = (memcmp(&((sockaddr_in6 *)&sa)->sin6_addr, data, size) == 0);
}
return (match ? ALLOW : SKIP);
}
/**
* Match a name with a pattern. The pattern may include wildcard. A single
* wildcard "*" can match up to one component in the domain name.
*
* @param host Host name, typically the name of the remote host
* @param pattern Name retrieved from certificate
* @param size Size of "pattern"
* @return True, if "host" matches "pattern". False otherwise.
*/
bool matchName(const char *host, const char *pattern, int size)
{
bool match = false;
int i = 0, j = 0;
while (i < size && host[j] != '\0') {
if (uppercase(pattern[i]) == uppercase(host[j])) {
i++;
j++;
continue;
}
if (pattern[i] == '*') {
while (host[j] != '.' && host[j] != '\0') {
j++;
}
i++;
continue;
}
break;
}
if (i == size && host[j] == '\0') {
match = true;
}
return match;
}
// This is to work around the Turkish locale issue, i.e.,
// toupper('i') != toupper('I') if locale is "tr_TR"
char uppercase(char c)
{
if ('a' <= c && c <= 'z') {
return c + ('A' - 'a');
}
return c;
}
} // namespace transport
} // namespace thrift
} // namespace apache
``` | /content/code_sandbox/modules/thrift/src/thrift/transport/TSSLSocket.cpp | c++ | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 4,740 |
```unknown
# Configuration for the crypto modules in the TF-M Module
if BUILD_WITH_TFM
if TFM_PARTITION_CRYPTO
config TFM_CRYPTO_RNG_MODULE_ENABLED
bool "Random number generator crypto module"
default y
help
Enables the random number generator module within the crypto partition.
Unset this option if 'psa_generate_random' is not used.
config TFM_CRYPTO_KEY_MODULE_ENABLED
bool "KEY crypto module"
default y
help
Enables the KEY crypto module within the crypto partition.
Unset this option if the functionality provided by 'crypto_key_management.c'
is not used.
config TFM_CRYPTO_AEAD_MODULE_ENABLED
bool "AEAD crypto module"
default y
help
Enables the AEAD crypto module within the crypto partition.
Unset this option if the functionality provided by 'crypto_aead.c'
is not used.
config TFM_CRYPTO_MAC_MODULE_ENABLED
bool "MAC crypto module"
default y
help
Enables the MAC crypto module within the crypto partition.
Unset this option if the functionality provided by 'crypto_mac.c'
is not used.
config TFM_CRYPTO_HASH_MODULE_ENABLED
bool "HASH crypto module"
default y
help
Enables the HASH crypto module within the crypto partition.
Unset this option if the functionality provided by 'crypto_hash.c'
is not used.
config TFM_CRYPTO_CIPHER_MODULE_ENABLED
bool "CIPHER crypto module"
default y
help
Enables the CIPHER crypto module within the crypto partition.
Unset this option if the functionality provided by 'crypto_cipher.c'
is not used.
config TFM_CRYPTO_ASYM_ENCRYPT_MODULE_ENABLED
bool "ASYM ENCRYPT crypto module"
default y
help
Enables the ASYM ENCRYPT crypto module within the crypto partition.
Unset this option if the encrypt functionality provided by 'crypto_asymmetric.c'
is not used.
config TFM_CRYPTO_ASYM_SIGN_MODULE_ENABLED
bool "ASYM SIGN crypto module"
default y
help
Enables the ASYM SIGN crypto module within the crypto partition.
Unset this option if the sign functionality provided by 'crypto_asymmetric.c'
is not used.
config TFM_CRYPTO_KEY_DERIVATION_MODULE_ENABLED
bool "KEY DERIVATION crypto module"
default y
help
Enables the KEY_DERIVATION crypto module within the crypto partition.
Unset this option if the functionality provided by 'crypto_key_derivation.c'
is not used.
endif # TFM_PARTITION_CRYPTO
endif # BUILD_WITH_TFM
``` | /content/code_sandbox/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules | unknown | 2016-05-26T17:54:19 | 2024-08-16T18:09:06 | zephyr | zephyrproject-rtos/zephyr | 10,307 | 528 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.