diff --git a/boards/arm/frdm_k64f/doc/frdm_k64f.rst b/boards/arm/frdm_k64f/doc/frdm_k64f.rst index b67c5a8c8a0..fc2a98c1678 100644 --- a/boards/arm/frdm_k64f/doc/frdm_k64f.rst +++ b/boards/arm/frdm_k64f/doc/frdm_k64f.rst @@ -76,8 +76,7 @@ The frdm_k64f board configuration supports the following hardware features: +-----------+------------+-------------------------------------+ | SPI | on-chip | spi | +-----------+------------+-------------------------------------+ -| ETHERNET | on-chip | ethernet (work in progress, known | -| | | issues exist, see below) | +| ETHERNET | on-chip | ethernet | +-----------+------------+-------------------------------------+ | UART | on-chip | serial port-polling; | | | | serial port-interrupt | @@ -224,13 +223,6 @@ the following message: Hello World! arm -Work in progress and known issues -********************************* - -Ethernet PHY is currently initialized only at the application startup. -For successful initialization, a network cable must be connected between -the board and a host/router. If a cable is not connected when the board -is powered on or reset, the startup will be aborted with an error message. .. _FRDM-K64F Website: http://www.nxp.com/products/software-and-tools/hardware-development-tools/freedom-development-boards/freedom-development-platform-for-kinetis-k64-k63-and-k24-mcus:FRDM-K64F diff --git a/drivers/ethernet/Kconfig.mcux b/drivers/ethernet/Kconfig.mcux index 2661f2b91e7..383348e8ab5 100644 --- a/drivers/ethernet/Kconfig.mcux +++ b/drivers/ethernet/Kconfig.mcux @@ -15,6 +15,13 @@ menuconfig ETH_MCUX configuration change. if ETH_MCUX +config ETH_MCUX_PHY_TICK_MS + int "PHY poll period (ms)" + default 1000 + range 100 30000 + help + Set the PHY status polling period. + config ETH_MCUX_RX_BUFFERS int "Number of MCUX RX buffers" depends on ETH_MCUX diff --git a/drivers/ethernet/eth_mcux.c b/drivers/ethernet/eth_mcux.c index 2b1111b0898..310f53720e1 100644 --- a/drivers/ethernet/eth_mcux.c +++ b/drivers/ethernet/eth_mcux.c @@ -1,15 +1,12 @@ /* MCUX Ethernet Driver * - * Copyright (c) 2016 ARM Ltd + * Copyright (c) 2016-2017 ARM Ltd * Copyright (c) 2016 Linaro Ltd * * SPDX-License-Identifier: Apache-2.0 */ -/* The driver performs one shot PHY setup. There is no support for - * PHY disconnect, reconnect or configuration change. The PHY setup, - * implemented via MCUX contains polled code that can block the - * initialization thread for a few seconds. +/* Driver Limitations: * * There is no statistics collection for either normal operation or * error behaviour. @@ -30,11 +27,27 @@ #include "fsl_phy.h" #include "fsl_port.h" +enum eth_mcux_phy_state { + eth_mcux_phy_state_initial, + eth_mcux_phy_state_reset, + eth_mcux_phy_state_autoneg, + eth_mcux_phy_state_restart, + eth_mcux_phy_state_read_status, + eth_mcux_phy_state_read_duplex, + eth_mcux_phy_state_wait +}; + struct eth_context { struct net_if *iface; enet_handle_t enet_handle; struct k_sem tx_buf_sem; + enum eth_mcux_phy_state phy_state; + bool link_up; + phy_duplex_t phy_duplex; + phy_speed_t phy_speed; uint8_t mac_addr[6]; + struct k_work phy_work; + struct k_delayed_work delayed_phy_work; /* TODO: FIXME. This Ethernet frame sized buffer is used for * interfacing with MCUX. How it works is that hardware uses * DMA scatter buffers to receive a frame, and then public @@ -70,6 +83,137 @@ rx_buffer[CONFIG_ETH_MCUX_RX_BUFFERS][ETH_MCUX_BUFFER_SIZE]; static uint8_t __aligned(ENET_BUFF_ALIGNMENT) tx_buffer[CONFIG_ETH_MCUX_TX_BUFFERS][ETH_MCUX_BUFFER_SIZE]; +static void eth_mcux_decode_duplex_and_speed(uint32_t status, + phy_duplex_t *p_phy_duplex, + phy_speed_t *p_phy_speed) +{ + switch (status & PHY_CTL1_SPEEDUPLX_MASK) { + case PHY_CTL1_10FULLDUPLEX_MASK: + *p_phy_duplex = kPHY_FullDuplex; + *p_phy_speed = kPHY_Speed10M; + break; + case PHY_CTL1_100FULLDUPLEX_MASK: + *p_phy_duplex = kPHY_FullDuplex; + *p_phy_speed = kPHY_Speed100M; + break; + case PHY_CTL1_100HALFDUPLEX_MASK: + *p_phy_duplex = kPHY_HalfDuplex; + *p_phy_speed = kPHY_Speed100M; + break; + case PHY_CTL1_10HALFDUPLEX_MASK: + *p_phy_duplex = kPHY_HalfDuplex; + *p_phy_speed = kPHY_Speed10M; + break; + } +} + +static void eth_mcux_phy_event(struct eth_context *context) +{ + uint32_t status; + bool link_up; + phy_duplex_t phy_duplex = kPHY_FullDuplex; + phy_speed_t phy_speed = kPHY_Speed100M; + const uint32_t phy_addr = 0; + + SYS_LOG_DBG("phy_state=%d", context->phy_state); + + switch (context->phy_state) { + case eth_mcux_phy_state_initial: + /* Reset the PHY. */ + ENET_StartSMIWrite(ENET, phy_addr, PHY_BASICCONTROL_REG, + kENET_MiiWriteValidFrame, + PHY_BCTL_RESET_MASK); + context->phy_state = eth_mcux_phy_state_reset; + break; + case eth_mcux_phy_state_reset: + /* Setup PHY autonegotiation. */ + ENET_StartSMIWrite(ENET, phy_addr, PHY_AUTONEG_ADVERTISE_REG, + kENET_MiiWriteValidFrame, + (PHY_100BASETX_FULLDUPLEX_MASK | + PHY_100BASETX_HALFDUPLEX_MASK | + PHY_10BASETX_FULLDUPLEX_MASK | + PHY_10BASETX_HALFDUPLEX_MASK | 0x1U)); + context->phy_state = eth_mcux_phy_state_autoneg; + break; + case eth_mcux_phy_state_autoneg: + /* Setup PHY autonegotiation. */ + ENET_StartSMIWrite(ENET, phy_addr, PHY_BASICCONTROL_REG, + kENET_MiiWriteValidFrame, + (PHY_BCTL_AUTONEG_MASK | + PHY_BCTL_RESTART_AUTONEG_MASK)); + context->phy_state = eth_mcux_phy_state_restart; + break; + case eth_mcux_phy_state_wait: + case eth_mcux_phy_state_restart: + /* Start reading the PHY basic status. */ + ENET_StartSMIRead(ENET, phy_addr, PHY_BASICSTATUS_REG, + kENET_MiiReadValidFrame); + context->phy_state = eth_mcux_phy_state_read_status; + break; + case eth_mcux_phy_state_read_status: + /* PHY Basic status is available. */ + status = ENET_ReadSMIData(ENET); + link_up = status & PHY_BSTATUS_LINKSTATUS_MASK; + if (link_up && !context->link_up) { + /* Start reading the PHY control register. */ + ENET_StartSMIRead(ENET, phy_addr, PHY_CONTROL1_REG, + kENET_MiiReadValidFrame); + context->link_up = link_up; + context->phy_state = eth_mcux_phy_state_read_duplex; + } else if (!link_up && context->link_up) { + SYS_LOG_INF("Link down"); + context->link_up = link_up; + k_delayed_work_submit(&context->delayed_phy_work, + CONFIG_ETH_MCUX_PHY_TICK_MS); + context->phy_state = eth_mcux_phy_state_wait; + } else { + k_delayed_work_submit(&context->delayed_phy_work, + CONFIG_ETH_MCUX_PHY_TICK_MS); + context->phy_state = eth_mcux_phy_state_wait; + } + + break; + case eth_mcux_phy_state_read_duplex: + /* PHY control register is available. */ + status = ENET_ReadSMIData(ENET); + eth_mcux_decode_duplex_and_speed(status, + &phy_duplex, + &phy_speed); + if (phy_speed != context->phy_speed || + phy_duplex != context->phy_duplex) { + context->phy_speed = phy_speed; + context->phy_duplex = phy_duplex; + ENET_SetMII(ENET, + (enet_mii_speed_t) phy_speed, + (enet_mii_duplex_t) phy_duplex); + } + + SYS_LOG_INF("Enabled %sM %s-duplex mode.", + (phy_speed ? "100" : "10"), + (phy_duplex ? "full" : "half")); + k_delayed_work_submit(&context->delayed_phy_work, + CONFIG_ETH_MCUX_PHY_TICK_MS); + context->phy_state = eth_mcux_phy_state_wait; + break; + } +} + +static void eth_mcux_phy_work(struct k_work *item) +{ + struct eth_context *context = + CONTAINER_OF(item, struct eth_context, phy_work); + + eth_mcux_phy_event(context); +} + +static void eth_mcux_delayed_phy_work(struct k_work *item) +{ + struct eth_context *context = + CONTAINER_OF(item, struct eth_context, delayed_phy_work); + + eth_mcux_phy_event(context); +} + static int eth_tx(struct net_if *iface, struct net_buf *buf) { struct eth_context *context = iface->dev->driver_data; @@ -265,9 +409,6 @@ static int eth_0_init(struct device *dev) struct eth_context *context = dev->driver_data; enet_config_t enet_config; uint32_t sys_clock; - const uint32_t phy_addr = 0x0; - bool link; - status_t status; enet_buffer_config_t buffer_config = { .rxBdNumber = CONFIG_ETH_MCUX_RX_BUFFERS, .txBdNumber = CONFIG_ETH_MCUX_TX_BUFFERS, @@ -281,34 +422,24 @@ static int eth_0_init(struct device *dev) k_sem_init(&context->tx_buf_sem, CONFIG_ETH_MCUX_TX_BUFFERS, CONFIG_ETH_MCUX_TX_BUFFERS); + k_work_init(&context->phy_work, eth_mcux_phy_work); + k_delayed_work_init(&context->delayed_phy_work, + eth_mcux_delayed_phy_work); sys_clock = CLOCK_GetFreq(kCLOCK_CoreSysClk); ENET_GetDefaultConfig(&enet_config); enet_config.interrupt |= kENET_RxFrameInterrupt; enet_config.interrupt |= kENET_TxFrameInterrupt; - - status = PHY_Init(ENET, phy_addr, sys_clock); - if (status) { - SYS_LOG_ERR("PHY_Init() failed: %d", status); - return 1; - } - - PHY_GetLinkStatus(ENET, phy_addr, &link); - if (link) { - phy_speed_t phy_speed; - phy_duplex_t phy_duplex; - - PHY_GetLinkSpeedDuplex(ENET, phy_addr, &phy_speed, &phy_duplex); - enet_config.miiSpeed = (enet_mii_speed_t) phy_speed; - enet_config.miiDuplex = (enet_mii_duplex_t) phy_duplex; - - SYS_LOG_INF("Enabled %dM %s-duplex mode.", - (phy_speed ? 100 : 10), - (phy_duplex ? "full" : "half")); - } else { - SYS_LOG_INF("Link down."); - } + enet_config.interrupt |= kENET_MiiInterrupt; + /* FIXME: Workaround for lack of driver API support for multicast + * management. So, instead we want to receive all multicast + * frames "by default", or otherwise basic IPv6 features, like + * address resolution, don't work. On Kinetis Ethernet controller, + * that translates to enabling promiscuous mode. The real + * fix depends on https://jira.zephyrproject.org/browse/ZEP-1673. + */ + enet_config.macSpecialConfig |= kENET_ControlPromiscuousEnable; #if defined(CONFIG_ETH_MCUX_0_RANDOM_MAC) generate_mac(context->mac_addr); @@ -321,6 +452,8 @@ static int eth_0_init(struct device *dev) context->mac_addr, sys_clock); + ENET_SetSMI(ENET, sys_clock, false); + SYS_LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x", context->mac_addr[0], context->mac_addr[1], context->mac_addr[2], context->mac_addr[3], @@ -329,6 +462,9 @@ static int eth_0_init(struct device *dev) ENET_SetCallback(&context->enet_handle, eth_callback, dev); eth_0_config_func(); ENET_ActiveRead(ENET); + + k_work_submit(&context->phy_work); + return 0; } @@ -367,11 +503,17 @@ static void eth_mcux_error_isr(void *p) { struct device *dev = p; struct eth_context *context = dev->driver_data; + uint32_t pending = ENET_GetInterruptStatus(ENET); - ENET_ErrorIRQHandler(ENET, &context->enet_handle); + if (pending & ENET_EIR_MII_MASK) { + k_work_submit(&context->phy_work); + ENET_ClearInterruptStatus(ENET, kENET_MiiInterrupt); + } } static struct eth_context eth_0_context = { + .phy_duplex = kPHY_FullDuplex, + .phy_speed = kPHY_Speed100M, .mac_addr = { /* Freescale's OUI */ 0x00, diff --git a/ext/lib/crypto/mbedtls/configs/config-mini-tls1_2.h b/ext/lib/crypto/mbedtls/configs/config-mini-tls1_2.h new file mode 100644 index 00000000000..e39c3cfe0f7 --- /dev/null +++ b/ext/lib/crypto/mbedtls/configs/config-mini-tls1_2.h @@ -0,0 +1,91 @@ +/* + * Minimal configuration for TLS 1.1 (RFC 4346) + * + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ +/* + * 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_PLATFORM_C +#define MBEDTLS_PLATFORM_MEMORY +#define MBEDTLS_MEMORY_BUFFER_ALLOC_C +#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_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_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 + + +#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024 + +#include "mbedtls/check_config.h" + +#endif /* MBEDTLS_CONFIG_H */ diff --git a/include/net/dhcpv4.h b/include/net/dhcpv4.h index 6c0ba84955b..a330debcb93 100644 --- a/include/net/dhcpv4.h +++ b/include/net/dhcpv4.h @@ -28,7 +28,6 @@ enum net_dhcpv4_state { NET_DHCPV4_INIT, NET_DHCPV4_DISCOVER, - NET_DHCPV4_OFFER, NET_DHCPV4_REQUEST, NET_DHCPV4_RENEWAL, NET_DHCPV4_ACK, diff --git a/include/net/mqtt.h b/include/net/mqtt.h index b05d34f37bc..d7d55e63671 100644 --- a/include/net/mqtt.h +++ b/include/net/mqtt.h @@ -17,7 +17,7 @@ */ /** - * @brief mqtt_app MQTT application type + * MQTT application type */ enum mqtt_app { /** Publisher and Subscriber application */ @@ -31,9 +31,9 @@ enum mqtt_app { }; /** - * @brief struct mqtt_ctx MQTT context structure - * @details - * Context structure for the MQTT high-level API with support for QoS. + * MQTT context structure + * + * @details Context structure for the MQTT high-level API with support for QoS. * * This API is designed for asynchronous operation, so callbacks are * executed when some events must be addressed outside the MQTT routines. @@ -74,84 +74,66 @@ struct mqtt_ctx { /** Callback executed when a #MQTT_APP_PUBLISHER application receives * a MQTT PUBxxxx msg. + * If type is MQTT_PUBACK, MQTT_PUBCOMP or MQTT_PUBREC, this callback + * must return 0 if pkt_id matches the packet id of a previously + * received MQTT_PUBxxx message. If this callback returns 0, the caller + * will continue. + * Any other value will stop the QoS handshake and the caller will + * return -EINVAL. The application must discard all the messages + * already processed. * * Note: this callback must be not NULL * - * @param [in] ctx MQTT context - * @param [in] pkt_id Packet Identifier for the input MQTT msg - * @param [in] type Packet type - * @return If this callback returns 0, the caller will - * continue. - * - * @return If type is MQTT_PUBACK, MQTT_PUBCOMP or - * MQTT_PUBREC, this callback must return 0 if - * pkt_id matches the packet id of a previously - * received MQTT_PUBxxx message. - * - * @return Note: the application must discard all the - * messages already processed - * - * @return Any other value will stop the QoS handshake - * and the caller will return -EINVAL + * @param [in] ctx MQTT context + * @param [in] pkt_id Packet Identifier for the input MQTT msg + * @param [in] type Packet type */ int (*publish_tx)(struct mqtt_ctx *ctx, uint16_t pkt_id, enum mqtt_packet type); /** Callback executed when a MQTT_APP_SUBSCRIBER, - * MQTT_APP_PUBLISHER_SUBSCRIBER or MQTT_APP_SERVER application receive - * a MQTT PUBxxxx msg. + * MQTT_APP_PUBLISHER_SUBSCRIBER or MQTT_APP_SERVER applications receive + * a MQTT PUBxxxx msg. If this callback returns 0, the caller will + * continue. If type is MQTT_PUBREL this callback must return 0 if + * pkt_id matches the packet id of a previously received MQTT_PUBxxx + * message. Any other value will stop the QoS handshake and the caller + * will return -EINVAL * * Note: this callback must be not NULL * - * @param [in] ctx MQTT context - * @param [in] msg Publish message, this parameter is only used - * when the type is MQTT_PUBLISH - * @param [in] pkt_id Packet Identifier for the input msg - * @param [in] type Packet type - * @return If this callback returns 0, the caller will - * continue. - * - * @return If type is MQTT_PUBREL this callback must return - * 0 if pkt_id matches the packet id of a - * previously received MQTT_PUBxxx message. - * - * @return Note: the application must discard all the - * messages already processed - * - * @return Any other value will stop the QoS handshake - * and the caller will return -EINVAL + * @param [in] ctx MQTT context + * @param [in] msg Publish message, this parameter is only used + * when the type is MQTT_PUBLISH + * @param [in] pkt_id Packet Identifier for the input msg + * @param [in] type Packet type */ int (*publish_rx)(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg, uint16_t pkt_id, enum mqtt_packet type); /** Callback executed when a MQTT_APP_SUBSCRIBER or * MQTT_APP_PUBLISHER_SUBSCRIBER receives the MQTT SUBACK message + * If this callback returns 0, the caller will continue. Any other + * value will make the caller return -EINVAL. * * Note: this callback must be not NULL * - * @param [in] ctx MQTT context - * @param [in] pkt_id Packet Identifier for the MQTT SUBACK msg - * @param [in] items Number of elements in the qos array - * @param [in] qos Array of QoS values - * @return If this callback returns 0, the caller will - * continue - * @return Any other value will make the caller return - * -EINVAL + * @param [in] ctx MQTT context + * @param [in] pkt_id Packet Identifier for the MQTT SUBACK msg + * @param [in] items Number of elements in the qos array + * @param [in] qos Array of QoS values */ int (*subscribe)(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items, enum mqtt_qos qos[]); /** Callback executed when a MQTT_APP_SUBSCRIBER or * MQTT_APP_PUBLISHER_SUBSCRIBER receives the MQTT UNSUBACK message + * If this callback returns 0, the caller will continue. Any other value + * will make the caller return -EINVAL * * Note: this callback must be not NULL * * @param [in] ctx MQTT context * @param [in] pkt_id Packet Identifier for the MQTT SUBACK msg - * @return If this callback returns 0, the caller will - * continue - * @return Any other value will make the caller return - * -EINVAL */ int (*unsubscribe)(struct mqtt_ctx *ctx, uint16_t pkt_id); @@ -182,219 +164,253 @@ struct mqtt_ctx { }; /** - * @brief mqtt_init Initializes the MQTT context structure - * @param ctx MQTT context structure - * @param app_type See enum mqtt_app - * @return 0, always. + * Initializes the MQTT context structure + * + * @param ctx MQTT context structure + * @param app_type See enum mqtt_app + * @retval 0, always. */ int mqtt_init(struct mqtt_ctx *ctx, enum mqtt_app app_type); /** - * @brief mqtt_tx_connect Sends the MQTT CONNECT message - * @param [in] ctx MQTT context structure - * @param [in] msg MQTT CONNECT msg - * @return 0 on success - * @return -EIO on network error - * @return -ENOMEM if no data/tx buffer is available - * @return -EINVAL if invalid data was passed to this - * routine + * Sends the MQTT CONNECT message + * + * @param [in] ctx MQTT context structure + * @param [in] msg MQTT CONNECT msg + * + * @retval 0 on success + * @retval -EIO + * @retval -ENOMEM + * @retval -EINVAL */ int mqtt_tx_connect(struct mqtt_ctx *ctx, struct mqtt_connect_msg *msg); /** - * @brief mqtt_tx_disconnect Send the MQTT DISCONNECT message - * @param [in] ctx MQTT context structure - * @return 0 on success - * @return -EIO on network error - * @return -ENOMEM if no data/tx buffer is available - * @return -EINVAL if invalid data was passed to this - * routine + * Send the MQTT DISCONNECT message + * + * @param [in] ctx MQTT context structure + * + * @retval 0 on success + * @retval -EIO + * @retval -ENOMEM + * @retval -EINVAL */ int mqtt_tx_disconnect(struct mqtt_ctx *ctx); /** - * @brief mqtt_tx_puback Sends the MQTT PUBACK message with the given - * packet id - * @param [in] ctx MQTT context structure - * @param [in] id MQTT Packet Identifier - * @return 0 on success - * @return -EINVAL if an invalid parameter was passed to - * this routine - * @return -ENOMEM if a tx buffer is not available - * @return -EIO on network error + * Sends the MQTT PUBACK message with the given packet id + * + * @param [in] ctx MQTT context structure + * @param [in] id MQTT Packet Identifier + * + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM + * @retval -EIO */ int mqtt_tx_puback(struct mqtt_ctx *ctx, uint16_t id); /** - * @brief mqtt_tx_pubcomp Sends the MQTT PUBCOMP message with the given - * packet id - * @param [in] ctx MQTT context structure - * @param [in] id MQTT Packet Identifier - * @return 0 on success - * @return -EINVAL if an invalid parameter was passed to - * this routine - * @return -ENOMEM if a tx buffer is not available - * @return -EIO on network error + * Sends the MQTT PUBCOMP message with the given packet id + * + * @param [in] ctx MQTT context structure + * @param [in] id MQTT Packet Identifier + * + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM + * @retval -EIO */ int mqtt_tx_pubcomp(struct mqtt_ctx *ctx, uint16_t id); /** - * @brief mqtt_tx_pubrec Sends the MQTT PUBREC message with the given - * packet id - * @param [in] ctx MQTT context structure - * @param [in] id MQTT Packet Identifier - * @return 0 on success - * @return -EINVAL if an invalid parameter was passed to - * this routine - * @return -ENOMEM if a tx buffer is not available - * @return -EIO on network error + * Sends the MQTT PUBREC message with the given packet id + * + * @param [in] ctx MQTT context structure + * @param [in] id MQTT Packet Identifier + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM + * @retval -EIO */ int mqtt_tx_pubrec(struct mqtt_ctx *ctx, uint16_t id); /** - * @brief mqtt_tx_pubrel Sends the MQTT PUBREL message with the given - * packet id - * @param [in] ctx MQTT context structure - * @param [in] id MQTT Packet Identifier - * @return 0 on success - * @return -EINVAL if an invalid parameter was passed to - * this routine - * @return -ENOMEM if a tx buffer is not available - * @return -EIO on network error + * Sends the MQTT PUBREL message with the given packet id + * + * @param [in] ctx MQTT context structure + * @param [in] id MQTT Packet Identifier + * + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM + * @retval -EIO */ int mqtt_tx_pubrel(struct mqtt_ctx *ctx, uint16_t id); /** - * @brief mqtt_tx_publish Sends the MQTT PUBLISH message - * @param [in] ctx MQTT context structure - * @param [in] msg MQTT PUBLISH msg - * @return 0 on success - * @return -EINVAL if an invalid parameter was passed to - * this routine - * @return -ENOMEM if a tx buffer is not available - * @return -EIO on network error + * Sends the MQTT PUBLISH message + * + * @param [in] ctx MQTT context structure + * @param [in] msg MQTT PUBLISH msg + * + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM + * @retval -EIO */ int mqtt_tx_publish(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg); /** - * @brief mqtt_tx_pingreq Sends the MQTT PINGREQ message - * @param [in] ctx MQTT context structure - * @return 0 on success - * @return -EINVAL if an invalid parameter was passed to - * this routine - * @return -ENOMEM if a tx buffer is not available - * @return -EIO on network error + * Sends the MQTT PINGREQ message + * + * @param [in] ctx MQTT context structure + * + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM + * @retval -EIO */ int mqtt_tx_pingreq(struct mqtt_ctx *ctx); /** - * @brief mqtt_tx_subscribe Sends the MQTT SUBSCRIBE message - * @param [in] ctx MQTT context structure - * @param [in] pkt_id Packet identifier for the MQTT SUBSCRIBE msg - * @param [in] items Number of elements in 'topics' and 'qos' arrays - * @param [in] topics Array of 'items' elements containing C strings. - * For example: {"sensors", "lights", "doors"} - * @param [in] qos Array of 'items' elements containing MQTT QoS - * values: MQTT_QoS0, MQTT_QoS1, MQTT_QoS2. For - * example for the 'topics' array above the - * following QoS may be used: - * {MQTT_QoS0, MQTT_QoS2, MQTT_QoS1}, indicating - * that the subscription to 'lights' must be done - * with MQTT_QoS2 - * @return 0 on success - * @return -EINVAL if an invalid parameter was passed to - * this routine - * @return -ENOMEM if a tx buffer is not available - * @return -EIO on network error + * Sends the MQTT SUBSCRIBE message + * + * @param [in] ctx MQTT context structure + * @param [in] pkt_id Packet identifier for the MQTT SUBSCRIBE msg + * @param [in] items Number of elements in 'topics' and 'qos' arrays + * @param [in] topics Array of 'items' elements containing C strings. + * For example: {"sensors", "lights", "doors"} + * @param [in] qos Array of 'items' elements containing MQTT QoS values: + * MQTT_QoS0, MQTT_QoS1, MQTT_QoS2. For example for the 'topics' + * array above the following QoS may be used: {MQTT_QoS0, + * MQTT_QoS2, MQTT_QoS1}, indicating that the subscription to + * 'lights' must be done with MQTT_QoS2 + * + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM + * @retval -EIO */ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items, const char *topics[], const enum mqtt_qos qos[]); /** - * @brief mqtt_tx_unsubscribe Sends the MQTT UNSUBSCRIBE message - * @param [in] ctx MQTT context structure - * @param [in] pkt_id Packet identifier for the MQTT UNSUBSCRIBE msg - * @param [in] items Number of elements in the 'topics' array - * @param [in] topics Array of 'items' elements containing C strings - * @return + * Sends the MQTT UNSUBSCRIBE message + * + * @param [in] ctx MQTT context structure + * @param [in] pkt_id Packet identifier for the MQTT UNSUBSCRIBE msg + * @param [in] items Number of elements in the 'topics' array + * @param [in] topics Array of 'items' elements containing C strings + * + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM + * @retval -EIO */ int mqtt_tx_unsubscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items, const char *topics[]); + +/** + * Parses and validates the MQTT CONNACK msg + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * @param [in] clean_session MQTT clean session parameter + * + * @retval 0 on success + * @retval -EINVAL + */ int mqtt_rx_connack(struct mqtt_ctx *ctx, struct net_buf *rx, int clean_session); /** - * @brief mqtt_rx_puback Parses and validates the MQTT PUBACK message - * @param [in] ctx MQTT context structure - * @param [in] rx Data buffer - * @return 0 on success - * @return -EINVAL on error + * Parses and validates the MQTT PUBACK message + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * + * @retval 0 on success + * @retval -EINVAL */ int mqtt_rx_puback(struct mqtt_ctx *ctx, struct net_buf *rx); /** - * @brief mqtt_rx_pubcomp Parses and validates the MQTT PUBCOMP message - * @param [in] ctx MQTT context structure - * @param [in] rx Data buffer - * @return 0 on success - * @return -EINVAL on error + * Parses and validates the MQTT PUBCOMP message + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * + * @retval 0 on success + * @retval -EINVAL */ int mqtt_rx_pubcomp(struct mqtt_ctx *ctx, struct net_buf *rx); /** - * @brief mqtt_rx_pubrec Parses and validates the MQTT PUBREC message - * @param [in] ctx MQTT context structure - * @param [in] rx Data buffer - * @return 0 on success - * @return -EINVAL on error + * Parses and validates the MQTT PUBREC message + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * + * @retval 0 on success + * @retval -EINVAL */ int mqtt_rx_pubrec(struct mqtt_ctx *ctx, struct net_buf *rx); /** - * @brief mqtt_rx_pubrel Parses and validates the MQTT PUBREL message - * @details rx is an RX buffer from the IP stack - * @param [in] ctx MQTT context structure - * @param [in] rx Data buffer - * @return 0 on success - * @return -EINVAL on error + * Parses and validates the MQTT PUBREL message + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * + * @retval 0 on success + * @retval -EINVAL */ int mqtt_rx_pubrel(struct mqtt_ctx *ctx, struct net_buf *rx); /** - * @brief mqtt_rx_pingresp Parses the MQTT PINGRESP message - * @param [in] ctx MQTT context structure - * @param [in] rx Data buffer - * @return 0 on success - * @return -EINVAL on error + * Parses the MQTT PINGRESP message + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * + * @retval 0 on success + * @retval -EINVAL */ int mqtt_rx_pingresp(struct mqtt_ctx *ctx, struct net_buf *rx); /** - * @brief mqtt_rx_suback Parses the MQTT SUBACK message - * @param [in] ctx MQTT context structure - * @param [in] rx Data buffer - * @return 0 on success - * @return -EINVAL on error + * Parses the MQTT SUBACK message + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * + * @retval 0 on success + * @retval -EINVAL */ int mqtt_rx_suback(struct mqtt_ctx *ctx, struct net_buf *rx); /** - * @brief mqtt_rx_unsuback Parses the MQTT UNSUBACK message - * @param [in] ctx MQTT context structure - * @param [in] rx Data buffer - * @return 0 on success - * @return -EINVAL on error + * Parses the MQTT UNSUBACK message + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * + * @retval 0 on success + * @retval -EINVAL */ int mqtt_rx_unsuback(struct mqtt_ctx *ctx, struct net_buf *rx); /** - * @brief mqtt_rx_publish Parses the MQTT PUBLISH message - * @param [in] ctx MQTT context structure - * @param [in] rx Data buffer - * @return 0 on success - * @return -EINVAL on error - * @return -ENOMEM if no data buffer is available + * Parses the MQTT PUBLISH message + * + * @param [in] ctx MQTT context structure + * @param [in] rx Data buffer + * + * @retval 0 on success + * @retval -EINVAL + * @retval -ENOMEM */ int mqtt_rx_publish(struct mqtt_ctx *ctx, struct net_buf *rx); diff --git a/include/net/zoap.h b/include/net/zoap.h index b035d4c8392..e255efd8564 100644 --- a/include/net/zoap.h +++ b/include/net/zoap.h @@ -147,16 +147,18 @@ struct zoap_reply; struct zoap_resource; /** - * Type of the callback being called when a resource's method is invoked by - * remote entity. + * @typedef zoap_method_t + * @brief Type of the callback being called when a resource's method is + * invoked by the remote entity. */ typedef int (*zoap_method_t)(struct zoap_resource *resource, struct zoap_packet *request, const struct sockaddr *from); /** - * Type of the callback being called when a resource's has observers to be - * informed when an update happens. + * @typedef zoap_notify_t + * @brief Type of the callback being called when a resource's has observers + * to be informed when an update happens. */ typedef void (*zoap_notify_t)(struct zoap_resource *resource, struct zoap_observer *observer); @@ -168,6 +170,7 @@ typedef void (*zoap_notify_t)(struct zoap_resource *resource, * them, by fetching their state or requesting updates to them. */ struct zoap_resource { + /** Which function to be called for each CoAP method */ zoap_method_t get, post, put, del; zoap_notify_t notify; const char * const *path; @@ -177,7 +180,7 @@ struct zoap_resource { }; /** - * Represents a remote device that is observing a local resource. + * @brief Represents a remote device that is observing a local resource. */ struct zoap_observer { sys_snode_t list; @@ -187,7 +190,7 @@ struct zoap_observer { }; /** - * Representation of a CoAP packet. + * @brief Representation of a CoAP packet. */ struct zoap_packet { struct net_buf *buf; @@ -196,7 +199,8 @@ struct zoap_packet { }; /** - * Helper function to be called when a response matches the + * @typedef zoap_reply_t + * @brief Helper function to be called when a response matches the * a pending request. */ typedef int (*zoap_reply_t)(const struct zoap_packet *response, @@ -204,7 +208,7 @@ typedef int (*zoap_reply_t)(const struct zoap_packet *response, const struct sockaddr *from); /** - * Represents a request awaiting for an acknowledgment (ACK). + * @brief Represents a request awaiting for an acknowledgment (ACK). */ struct zoap_pending { struct zoap_packet request; @@ -212,8 +216,8 @@ struct zoap_pending { }; /** - * Represents the handler for the reply of a request, it is also used when - * observing resources. + * @brief Represents the handler for the reply of a request, it is + * also used when observing resources. */ struct zoap_reply { zoap_reply_t reply; @@ -224,48 +228,76 @@ struct zoap_reply { }; /** - * Indicates that the remote device referenced by @a addr, with @a request, - * wants to observe a resource. + * @brief Indicates that the remote device referenced by @a addr, with + * @a request, wants to observe a resource. + * + * @param observer Observer to be initialized + * @param request Request on which the observer will be based + * @param addr Address of the remote device */ void zoap_observer_init(struct zoap_observer *observer, const struct zoap_packet *request, const struct sockaddr *addr); /** - * After the observer is initialized, associate the observer with an resource. - * Returns whether this is the first observer added to this resource. + * @brief After the observer is initialized, associate the observer + * with an resource. + * + * @param resource Resource to add an observer + * @param observer Observer to be added + * + * @return true if this is the first observer added to this resource. */ bool zoap_register_observer(struct zoap_resource *resource, struct zoap_observer *observer); /** - * Remove this observer from the list of registered observers of - * that resource. + * @brief Remove this observer from the list of registered observers + * of that resource. + * + * @param resource Resource in which to remove the observer + * @param observer Observer to be removed */ void zoap_remove_observer(struct zoap_resource *resource, struct zoap_observer *observer); /** - * Returns the observer that matches address @a addr. + * @brief Returns the observer that matches address @a addr. + * + * @param observers Pointer to the array of observers + * @param len Size of the array of observers + * @param addr Address of the endpoint observing a resource + * + * @return A pointer to a observer if a match is found, NULL + * otherwise. */ struct zoap_observer *zoap_find_observer_by_addr( struct zoap_observer *observers, size_t len, const struct sockaddr *addr); /** - * Returns the next available observer representation. + * @brief Returns the next available observer representation. + * + * @param observers Pointer to the array of observers + * @param len Size of the array of observers + * + * @return A pointer to a observer if there's an available observer, + * NULL otherwise. */ struct zoap_observer *zoap_observer_next_unused( struct zoap_observer *observers, size_t len); /** - * Indicates that a reply is expected for @a request. + * @brief Indicates that a reply is expected for @a request. + * + * @param reply Reply structure to be initialized + * @param request Request from which @a reply will be based */ void zoap_reply_init(struct zoap_reply *reply, const struct zoap_packet *request); /** - * Represents the value of a CoAP option. + * @brief Represents the value of a CoAP option. * * To be used with zoap_find_options(). */ @@ -275,51 +307,97 @@ struct zoap_option { }; /** - * Parses the CoAP packet in @a buf, validating it and initializing @a pkt. - * @a buf must remain valid while @a pkt is used. Used when receiving packets. + * @brief Parses the CoAP packet in @a buf, validating it and + * initializing @a pkt. @a buf must remain valid while @a pkt is used. + * + * @param pkt Packet to be initialized from received @a buf. + * @param buf Buffer containing a CoAP packet, its @a data pointer is + * positioned on the start of the CoAP packet. + * + * @return 0 in case of success or negative in case of error. */ int zoap_packet_parse(struct zoap_packet *pkt, struct net_buf *buf); /** - * Creates a new CoAP packet from a net_buf. @a buf must remain valid while - * @a pkt is used. Used when creating packets to be sent. + * @brief Creates a new CoAP packet from a net_buf. @a buf must remain + * valid while @a pkt is used. + * + * @param pkt New packet to be initialized using the storage from @a + * buf. + * @param buf Buffer that will contain a CoAP packet + * + * @return 0 in case of success or negative in case of error. */ int zoap_packet_init(struct zoap_packet *pkt, struct net_buf *buf); /** - * Initialize a pending request with a request. The request's fields are - * copied into the pending struct, so @a request doesn't have to live for as - * long as the pending struct lives, but net_buf needs to live for at least - * that long. + * @brief Initialize a pending request with a request. + * + * The request's fields are copied into the pending struct, so @a + * request doesn't have to live for as long as the pending struct + * lives, but net_buf needs to live for at least that long. + * + * @param pending Structure representing the waiting for a + * confirmation message, initialized with data from @a request + * @param request Message waiting for confirmation + * + * @return 0 in case of success or negative in case of error. */ int zoap_pending_init(struct zoap_pending *pending, const struct zoap_packet *request); /** - * Returns the next available pending struct, that can be used to track - * the retransmission status of a request. + * @brief Returns the next available pending struct, that can be used + * to track the retransmission status of a request. + * + * @param pendings Pointer to the array of #zoap_pending structures + * @param len Size of the array of #zoap_pending structures + * + * @return pointer to a free #zoap_pending structure, NULL in case + * none could be found. */ struct zoap_pending *zoap_pending_next_unused( struct zoap_pending *pendings, size_t len); /** - * Returns the next available reply struct, so it can be used to track replies - * and notifications received. + * @brief Returns the next available reply struct, so it can be used + * to track replies and notifications received. + * + * @param replies Pointer to the array of #zoap_reply structures + * @param len Size of the array of #zoap_reply structures + * + * @return pointer to a free #zoap_reply structure, NULL in case + * none could be found. */ struct zoap_reply *zoap_reply_next_unused( struct zoap_reply *replies, size_t len); /** - * After a response is received, clear all pending retransmissions related to - * that response. + * @brief After a response is received, clear all pending + * retransmissions related to that response. + * + * @param response The received response + * @param pendings Pointer to the array of #zoap_reply structures + * @param len Size of the array of #zoap_reply structures + * + * @return pointer to the associated #zoap_pending structure, NULL in + * case none could be found. */ struct zoap_pending *zoap_pending_received( const struct zoap_packet *response, struct zoap_pending *pendings, size_t len); /** - * After a response is received, clear all pending retransmissions related to - * that response. + * @brief After a response is received, clear all pending + * retransmissions related to that response. + * + * @param response A response received + * @param from Address from which the response was received + * @param replies Pointer to the array of #zoap_reply structures + * @param len Size of the array of #zoap_reply structures + * + * @return Pointer to the reply matching the packet received, NULL if + * none could be found. */ struct zoap_reply *zoap_response_received( const struct zoap_packet *response, @@ -327,91 +405,170 @@ struct zoap_reply *zoap_response_received( struct zoap_reply *replies, size_t len); /** - * Returns the next pending about to expire, pending->timeout informs how many - * ms to next expiration. + * @brief Returns the next pending about to expire, pending->timeout + * informs how many ms to next expiration. + * + * @param pendings Pointer to the array of #zoap_pending structures + * @param len Size of the array of #zoap_pending structures + * + * @return The next #zoap_pending to expire, NULL if none is about to + * expire. */ struct zoap_pending *zoap_pending_next_to_expire( struct zoap_pending *pendings, size_t len); /** - * After a request is sent, user may want to cycle the pending retransmission - * so the timeout is updated. Returns false if this is the last - * retransmission. + * @brief After a request is sent, user may want to cycle the pending + * retransmission so the timeout is updated. + * + * @param pending Pending representation to have its timeout updated + * + * @return false if this is the last retransmission. */ bool zoap_pending_cycle(struct zoap_pending *pending); /** - * Cancels the pending retransmission, so it again becomes available. + * @brief Cancels the pending retransmission, so it again becomes + * available. + * + * @param pending Pending representation to be canceled */ void zoap_pending_clear(struct zoap_pending *pending); /** - * Cancels awaiting for this reply, so it becomes available again. + * @brief Cancels awaiting for this reply, so it becomes available + * again. + * + * @param reply The reply to be cancelled */ void zoap_reply_clear(struct zoap_reply *reply); /** - * When a request is received, call the appropriate methods of the - * matching resources. + * @brief When a request is received, call the appropriate methods of + * the matching resources. + * + * @param pkt Packet received + * @param resources Array of known resources + * @param from Address from which the packet was received + * + * @return 0 in case of success or negative in case of error. */ int zoap_handle_request(struct zoap_packet *pkt, struct zoap_resource *resources, const struct sockaddr *from); /** - * Indicates that this resource was updated and that the @a notify callback - * should be called for every registered observer. + * @brief Indicates that this resource was updated and that the @a + * notify callback should be called for every registered observer. + * + * @param resource Resource that was updated + * + * @return 0 in case of success or negative in case of error. */ int zoap_resource_notify(struct zoap_resource *resource); /** - * Returns if this request is enabling observing a resource. + * @brief Returns if this request is enabling observing a resource. + * + * @param request Request to be checked + * + * @return True if the request is enabling observing a resource, False + * otherwise */ bool zoap_request_is_observe(const struct zoap_packet *request); /** - * Returns a pointer to the start of the payload, and how much memory - * is available (to the payload), it will also insert the - * COAP_MARKER (0xFF). When the payload is already set, for example, - * for incoming packets, it will return how many bytes the payload - * occupies. + * @brief Returns a pointer to the start of the payload and its size + * + * It will insert the COAP_MARKER (0xFF), if its not set, and return the + * available size for the payload. + * + * @param pkt Packet to get (or insert) the payload + * @param len Amount of space for the payload + * + * @return pointer to the start of the payload, NULL in case of error. */ uint8_t *zoap_packet_get_payload(struct zoap_packet *pkt, uint16_t *len); /** - * Returns the internal buffer of the CoAP packet, appending the - * COAP_MARKER to the buffer if necessary. + * @brief Returns the internal buffer of the CoAP packet, appending + * the COAP_MARKER to the buffer if necessary. + * + * @param pkt Packet to get (or insert) the payload + * + * @return pointer to the net_buf storing the payload. */ struct net_buf *zoap_packet_get_buf(struct zoap_packet *pkt); /** - * Sets how much space was used by the payload. + * @brief Sets how much space was used by the payload. + * + * Used for outgoing packets, after zoap_packet_get_payload(), to + * update the internal representation with the amount of data that was + * added to the packet. + * + * @param pkt Packet to be updated + * @param len Amount of data that was added to the payload + * + * @return 0 in case of success or negative in case of error. */ int zoap_packet_set_used(struct zoap_packet *pkt, uint16_t len); /** - * Adds an option to the packet. Note that options must be added - * in numeric order of their codes. + * @brief Adds an option to the packet. + * + * Note: ptions must be added in numeric order of their codes. + * + * @param pkt Packet to be updated + * @param code Option code to add to the packet, see #zoap_option_num + * @param value Pointer to the value of the option, will be copied to the packet + * @param len Size of the data to be added + * + * @return 0 in case of success or negative in case of error. */ int zoap_add_option(struct zoap_packet *pkt, uint16_t code, const void *value, uint16_t len); /** - * Converts an option to its integer representation. It assumes that - * the number is encoded in the network byte order in the option. + * @brief Converts an option to its integer representation. + * + * Assumes that the number is encoded in the network byte order in the + * option. + * + * @param option Pointer to the option value, retrieved by + * zoap_find_options() + * + * @return The integer representation of the option */ unsigned int zoap_option_value_to_int(const struct zoap_option *option); /** - * Adds an integer value option to the packet. The option must be - * added in numeric order of their codes, and the least amount of - * bytes will be used to encode the value. + * @brief Adds an integer value option to the packet. + * + * The option must be added in numeric order of their codes, and the + * least amount of bytes will be used to encode the value. + * + * @param pkt Packet to be updated + * @param code Option code to add to the packet, see #zoap_option_num + * @param val Integer value to be added + * + * @return 0 in case of success or negative in case of error. */ int zoap_add_option_int(struct zoap_packet *pkt, uint16_t code, unsigned int val); /** - * Return the values associated with the option of value @a code. + * @brief Return the values associated with the option of value @a + * code. + * + * @param pkt CoAP packet representation + * @param code Option number to look for + * @param options Array of #zoap_option where to store the value + * of the options found + * @param veclen Number of elements in the options array + * + * @return The number of options found in packet matching code, + * negative on error. */ int zoap_find_options(const struct zoap_packet *pkt, uint16_t code, struct zoap_option *options, uint16_t veclen); @@ -435,7 +592,12 @@ enum zoap_block_size { }; /** - * Helper for converting the enumeration to the size expressed in bytes. + * @brief Helper for converting the enumeration to the size expressed + * in bytes. + * + * @param block_size The block size to be converted + * + * @return The size in bytes that the block_size represents */ static inline uint16_t zoap_block_size_to_bytes( enum zoap_block_size block_size) @@ -444,7 +606,7 @@ static inline uint16_t zoap_block_size_to_bytes( } /** - * Represents the current state of a block-wise transaction. + * @brief Represents the current state of a block-wise transaction. */ struct zoap_block_context { size_t total_size; @@ -453,103 +615,186 @@ struct zoap_block_context { }; /** - * Initializes the context of a block-wise transfer. + * @brief Initializes the context of a block-wise transfer. + * + * @param ctx The context to be initialized + * @param block_size The size of the block + * @param total_size The total size of the transfer, if known + * + * @return 0 in case of success or negative in case of error. */ int zoap_block_transfer_init(struct zoap_block_context *ctx, - enum zoap_block_size block_size, - size_t total_size); + enum zoap_block_size block_size, + size_t total_size); /** - * Add BLOCK1 option to the packet. + * @brief Add BLOCK1 option to the packet. + * + * @param pkt Packet to be updated + * @param ctx Block context from which to retrieve the + * information for the Block1 option + * + * @return 0 in case of success or negative in case of error. */ int zoap_add_block1_option(struct zoap_packet *pkt, struct zoap_block_context *ctx); /** - * Add BLOCK2 option to the packet. + * @brief Add BLOCK2 option to the packet. + * + * @param pkt Packet to be updated + * @param ctx Block context from which to retrieve the + * information for the Block2 option + * + * @return 0 in case of success or negative in case of error. */ int zoap_add_block2_option(struct zoap_packet *pkt, struct zoap_block_context *ctx); /** - * Add SIZE1 option to the packet. + * @brief Add SIZE1 option to the packet. + * + * @param pkt Packet to be updated + * @param ctx Block context from which to retrieve the + * information for the Size1 option + * + * @return 0 in case of success or negative in case of error. */ int zoap_add_size1_option(struct zoap_packet *pkt, struct zoap_block_context *ctx); /** - * Add SIZE2 option to the packet. + * @brief Add SIZE2 option to the packet. + * + * @param pkt Packet to be updated + * @param ctx Block context from which to retrieve the + * information for the Size2 option + * + * @return 0 in case of success or negative in case of error. */ int zoap_add_size2_option(struct zoap_packet *pkt, struct zoap_block_context *ctx); /** - * Retrieves BLOCK{1,2} and SIZE{1,2} from @a pkt and updates + * @brief Retrieves BLOCK{1,2} and SIZE{1,2} from @a pkt and updates * @a ctx accordingly. * - * Returns an error if the packet contains invalid options. + * @param pkt Packet in which to look for block-wise transfers options + * @param ctx Block context to be updated + * + * @return 0 in case of success or negative in case of error. */ -int zoap_update_from_block(struct zoap_packet *pkt, +int zoap_update_from_block(const struct zoap_packet *pkt, struct zoap_block_context *ctx); + /** - * Updates @a ctx so after this is called the current entry + * @brief Updates @a ctx so after this is called the current entry * indicates the correct offset in the body of data being * transferred. + * + * @param ctx Block context to be updated + * + * @return The offset in the block-wise transfer, 0 if the transfer + * has finished. */ size_t zoap_next_block(struct zoap_block_context *ctx); /** - * Returns the version present in a CoAP packet. + * @brief Returns the version present in a CoAP packet. + * + * @param pkt CoAP packet representation + * + * @return the CoAP version in packet */ uint8_t zoap_header_get_version(const struct zoap_packet *pkt); /** - * Returns the type of the packet present in the CoAP packet. + * @brief Returns the type of the CoAP packet. + * + * @param pkt CoAP packet representation + * + * @return the type of the packet */ uint8_t zoap_header_get_type(const struct zoap_packet *pkt); /** - * Returns the token associated with a CoAP packet. + * @brief Returns the token (if any) in the CoAP packet. + * + * @param pkt CoAP packet representation + * @param len Where to store the length of the token + * + * @return pointer to the start of the token in the CoAP packet. */ const uint8_t *zoap_header_get_token(const struct zoap_packet *pkt, uint8_t *len); /** - * Returns the code present in the header of a CoAP packet. + * @brief Returns the code of the CoAP packet. + * + * @param pkt CoAP packet representation + * + * @return the code present in the packet */ uint8_t zoap_header_get_code(const struct zoap_packet *pkt); /** - * Returns the message id associated with a CoAP packet. + * @brief Returns the message id associated with the CoAP packet. + * + * @param pkt CoAP packet representation + * + * @return the message id present in the packet */ uint16_t zoap_header_get_id(const struct zoap_packet *pkt); /** - * Sets the CoAP version present in the CoAP header of a packet. + * @brief Sets the version of the CoAP packet. + * + * @param pkt CoAP packet representation + * @param ver The CoAP version to set in the packet */ void zoap_header_set_version(struct zoap_packet *pkt, uint8_t ver); /** - * Sets the type of a CoAP message. + * @brief Sets the type of the CoAP packet. + * + * @param pkt CoAP packet representation + * @param type The packet type to set */ void zoap_header_set_type(struct zoap_packet *pkt, uint8_t type); /** - * Sets the token present in the CoAP header of a packet. + * @brief Sets the token in the CoAP packet. + * + * @param pkt CoAP packet representation + * @param token Token to set in the packet, will be copied + * @param tokenlen Size of the token to be set, 8 bytes maximum + * + * @return 0 in case of success or negative in case of error. */ int zoap_header_set_token(struct zoap_packet *pkt, const uint8_t *token, uint8_t tokenlen); /** - * Sets the code present in the header of a CoAP packet. + * @brief Sets the code present in the CoAP packet. + * + * @param pkt CoAP packet representation + * @param code The code set in the packet */ void zoap_header_set_code(struct zoap_packet *pkt, uint8_t code); /** - * Sets the message id associated with a CoAP packet. + * @brief Sets the message id present in the CoAP packet. + * + * @param pkt CoAP packet representation + * @param id The message id to set in the packet */ void zoap_header_set_id(struct zoap_packet *pkt, uint16_t id); +/** + * @brief Helper to generate message ids + * + * @return a new message id + */ static inline uint16_t zoap_next_id(void) { static uint16_t message_id; @@ -558,8 +803,10 @@ static inline uint16_t zoap_next_id(void) } /** - * Returns a randomly generated array of 8 bytes, that can be used as a - * message's token. + * @brief Returns a randomly generated array of 8 bytes, that can be + * used as a message's token. + * + * @return a 8-byte pseudo-random token. */ uint8_t *zoap_next_token(void); diff --git a/lib/libc/minimal/include/time.h b/lib/libc/minimal/include/time.h new file mode 100644 index 00000000000..ecb198e1ac8 --- /dev/null +++ b/lib/libc/minimal/include/time.h @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2017 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +/* Dummy time.h to fulfill the requirements of certain libraries + * i.e. mbedTLS + */ diff --git a/samples/net/dns_client/prj_qemu_x86.conf b/samples/net/dns_client/prj_qemu_x86.conf index 39410474949..9f09444f12a 100644 --- a/samples/net/dns_client/prj_qemu_x86.conf +++ b/samples/net/dns_client/prj_qemu_x86.conf @@ -29,5 +29,5 @@ CONFIG_DNS_RESOLVER_ADDITIONAL_QUERIES=1 CONFIG_NET_SAMPLES_IP_ADDRESSES=y CONFIG_NET_SAMPLES_MY_IPV6_ADDR="2001:db8::1" CONFIG_NET_SAMPLES_PEER_IPV6_ADDR="2001:db8::2" -CONFIG_NET_SAMPLES_MY_IPV4_ADDR="192.168.1.101" -CONFIG_NET_SAMPLES_PEER_IPV4_ADDR="192.168.1.10" +CONFIG_NET_SAMPLES_MY_IPV4_ADDR="192.0.2.1" +CONFIG_NET_SAMPLES_PEER_IPV4_ADDR="192.0.2.2" diff --git a/samples/net/echo_client/prj_qemu_cortex_m3.conf b/samples/net/echo_client/prj_qemu_cortex_m3.conf new file mode 100644 index 00000000000..b26453750e4 --- /dev/null +++ b/samples/net/echo_client/prj_qemu_cortex_m3.conf @@ -0,0 +1,26 @@ +CONFIG_NETWORKING=y +CONFIG_NET_IPV6=y +CONFIG_NET_IPV4=y +CONFIG_NET_UDP=y +CONFIG_NET_TCP=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_NET_LOG=y +CONFIG_NET_SLIP_TAP=y +CONFIG_SYS_LOG_SHOW_COLOR=y +CONFIG_INIT_STACKS=y +CONFIG_PRINTK=y +CONFIG_NET_STATISTICS=y +CONFIG_NET_NBUF_RX_COUNT=14 +CONFIG_NET_NBUF_TX_COUNT=14 +CONFIG_NET_NBUF_DATA_COUNT=30 +CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2 +CONFIG_NET_MAX_CONTEXTS=10 + +CONFIG_NET_SHELL=y + +CONFIG_NET_SAMPLES_IP_ADDRESSES=y +CONFIG_NET_SAMPLES_MY_IPV6_ADDR="2001:db8::2" +CONFIG_NET_SAMPLES_PEER_IPV6_ADDR="2001:db8::1" +CONFIG_NET_SAMPLES_MY_IPV4_ADDR="192.0.2.2" +CONFIG_NET_SAMPLES_PEER_IPV4_ADDR="192.0.2.1" diff --git a/samples/net/echo_server/prj_qemu_cortex_m3.conf b/samples/net/echo_server/prj_qemu_cortex_m3.conf new file mode 100644 index 00000000000..663d5d73d50 --- /dev/null +++ b/samples/net/echo_server/prj_qemu_cortex_m3.conf @@ -0,0 +1,27 @@ + +CONFIG_NETWORKING=y +CONFIG_NET_IPV6=y +CONFIG_NET_IPV4=y +CONFIG_NET_UDP=y +CONFIG_NET_TCP=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_NET_LOG=y +CONFIG_NET_SLIP_TAP=y +CONFIG_SYS_LOG_SHOW_COLOR=y +CONFIG_INIT_STACKS=y +CONFIG_PRINTK=y +CONFIG_NET_STATISTICS=y +CONFIG_NET_NBUF_RX_COUNT=16 +CONFIG_NET_NBUF_TX_COUNT=16 +CONFIG_NET_NBUF_DATA_COUNT=40 +CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2 +CONFIG_NET_MAX_CONTEXTS=16 + +CONFIG_NET_SHELL=y + +CONFIG_NET_SAMPLES_IP_ADDRESSES=y +CONFIG_NET_SAMPLES_MY_IPV6_ADDR="2001:db8::1" +CONFIG_NET_SAMPLES_PEER_IPV6_ADDR="2001:db8::2" +CONFIG_NET_SAMPLES_MY_IPV4_ADDR="192.0.2.1" +CONFIG_NET_SAMPLES_PEER_IPV4_ADDR="192.0.2.2" diff --git a/samples/net/http_server/README.rst b/samples/net/http_server/README.rst index 27b77829c60..792bbdaa1e6 100644 --- a/samples/net/http_server/README.rst +++ b/samples/net/http_server/README.rst @@ -109,7 +109,6 @@ Refer to the board documentation in Zephyr, :ref:`frdm_k64f`, for more information about this board and how to access the FRDM serial console under other operating systems. - Sample Output ============= @@ -223,6 +222,60 @@ and this is the HTML message that wget will save: