From 3061ecca3d0fdfb87dabbf5f63c9e06c2a30f53a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 23 Aug 2018 17:08:59 +0200 Subject: o Initial import. --- .../components/iot/ipv6_stack/include/dns6_api.h | 173 ++++++++++++++ .../components/iot/ipv6_stack/include/icmp6_api.h | 253 ++++++++++++++++++++ .../components/iot/ipv6_stack/include/ipv6_api.h | 207 +++++++++++++++++ .../components/iot/ipv6_stack/include/udp_api.h | 255 +++++++++++++++++++++ 4 files changed, 888 insertions(+) create mode 100644 thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/dns6_api.h create mode 100644 thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/icmp6_api.h create mode 100644 thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/ipv6_api.h create mode 100644 thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/udp_api.h (limited to 'thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include') diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/dns6_api.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/dns6_api.h new file mode 100644 index 0000000..0f6ecd9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/dns6_api.h @@ -0,0 +1,173 @@ +/** + * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** @file dns6_api.h + * + * @defgroup iot_dns6 DNS Application Interface for Nordic's IPv6 stack + * @ingroup iot_sdk_stack + * @{ + * @brief Domain Name System module provides implementation of DNS6 service. + * + */ + +#ifndef DNS6_H__ +#define DNS6_H__ + +#include "sdk_config.h" +#include "sdk_common.h" +#include "ipv6_api.h" +#include "iot_timer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief DNS Server parameter. */ +typedef struct +{ + ipv6_addr_t addr; /**< The IPv6 address of the DNS Server. */ + uint16_t port; /**< The default UDP port of the DNS Server. */ +} dns6_server_param_t; + + +/**@brief Initialization parameters type. */ +typedef struct +{ + uint16_t local_src_port; /**< The local UDP port for reception the DNS responses. */ + dns6_server_param_t dns_server; /**< Parameters of the DNS Server. */ +} dns6_init_t; + + +/** + * @brief DNS event receive callback. + * + * @details API used to notify the application of DNS Response on specific hostname or of an error + * during resolving process. The process_result parameter indicates whether the DNS module + * was successfully processed. If the received DNS Response is malformed in a way that + * allow to assign response with specific callback (e.g. timeout occurs or hostname is not + * found), information about error is still notified to the application. The application + * should check process_result and number of IPv6 address before reading them. + * + * @param[in] process_result Notifies the application if the DNS module was processed successfully + * or if an error occurred, for example DNS server is unreachable. + * @param[in] p_hostname Identifies hostname (URL string) that was requested to bee resolved, + * e.g. "example.com". + * @param[in] p_addr Pointer to the IPv6 addresses being resolved for given hostname. In + * case addr_count variable is 0, p_addr gets NULL value and should not + * be used. + * @param[in] addr_count Number of IPv6 addresses being successfully resolved. + * + * @retval None. + */ +typedef void (* dns6_evt_handler_t) (uint32_t process_result, + const char * p_hostname, + ipv6_addr_t * p_addr, + uint16_t addr_count); + +/** + * @brief Function for initializing DNS6 module. + * + * @param[in] p_dns_init Initialization structure for DNS client. Should not be NULL. + * + * @note DNS protocol module uses UDP transport layer, therefore one UDP socket is allocated + * inside function and uses for further communication. + * + * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason + * for failure. + */ +uint32_t dns6_init(const dns6_init_t * p_dns_init); + + +/** + * @brief Function for uninitializing DNS6 module. + * + * @note Apart of DNS specific functionality, function frees previously allocated UDP socket. + * Function removes any pending queries from the sending queue, so registered user + * callbacks will not be executed. + * + * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason + * for failure. + */ +uint32_t dns6_uninit(void); + + +/** + * @brief Function for querying given URL string to DNS server, in order to get IPv6 address of + * given hostname. + * + * @param[in] p_hostname Identifies hostname (URL string) to be find, e.g. "example.com". Should + * not be NULL. + * @param[in] evt_handler Callback that is called once response is received, timeout occurred or + * internal error was detected. Should not be NULL. + * + * @note Function sends DNS Query to DNS Server to obtain all AAAA records (with IPv6 address) + * assigned to given hostname. In case DNS Server replies with more that one AAAA records + * DNS module call user defined evt_handler with addr_count indicates number of addresses. + * + * @retval NRF_SUCCESS on successful execution of procedure. + * @retval IOT_DNS6_ERR_BASE | NRF_ERROR_NO_MEM if there is no place in pending queries' queue. + * @retval IOT_PBUFFER_ERR_BASE | NRF_ERROR_NO_MEM if there is no memory for hostname allocation. + * @retval NRF_ERROR_MEMORY_MANAGER_ERR_BASE | NRF_ERROR_NO_MEM if there is no memory for packet allocation. + * @retval UDP_INTERFACE_NOT_READY if interface is not ready for sending packets e.g. interface is + * down. + * @retval Other errors indicates reason of failure. + */ +uint32_t dns6_query(const char * p_hostname, dns6_evt_handler_t evt_handler); + + +/**@brief Function for performing retransmissions of DNS queries. + * + * @note DNS module implements the retransmission mechanism by invoking this function periodically. + * So that method has to be added to IoT Timer client list and has to be called with minimum of + * DNS6_RETRANSMISSION_INTERVAL resolution. + * + * @param[in] wall_clock_value The value of the wall clock that triggered the callback. + * + * @retval None. + */ +void dns6_timeout_process(iot_timer_time_in_ms_t wall_clock_value); + + +#ifdef __cplusplus +} +#endif + +#endif //DNS6_H__ + +/**@} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/icmp6_api.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/icmp6_api.h new file mode 100644 index 0000000..b13b4b6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/icmp6_api.h @@ -0,0 +1,253 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** @file icmp6_api.h + * + * @defgroup iot_icmp6 ICMP6 Application Interface for Nordic's IPv6 stack + * @ingroup iot_sdk_stack + * @{ + * @brief Nordic Internet Control Message Protocol Application Interface for Nordic's IPv6 stack. + * + * @details This module provides basic features related to ICMPv6 support. + */ + +#ifndef ICMP6_API_H__ +#define ICMP6_API_H__ + +#include "sdk_config.h" +#include "sdk_common.h" +#include "iot_defines.h" +#include "ipv6_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ICMP6_ECHO_REQUEST_PAYLOAD_OFFSET 8 /**< Offset of echo request payload from ICMPv6 header. */ + + +/**@defgroup icmp6_code ICMPv6 codes per message type as defined in RFC 4443. + * @ingroup iot_icmp6 + * @{ + */ +#define ICMP6_DU_CODE_NO_ROUTE_TO_DESTINATION 0 /**< Code for Destination Unreachable Message when there is no route to destination. */ +#define ICMP6_DU_CODE_ADMINISTRATIVELY_PROHIBITED 1 /**< Code for Destination Unreachable Message when the communication to destination administratively prohibited. */ +#define ICMP6_DU_CODE_BEYOND_SCOPE_OF_SOURCE 2 /**< Code for Destination Unreachable Message when the destination is beyond the scope of source address. */ +#define ICMP6_DU_CODE_ADDRESS_UNREACHABLE 3 /**< Code for Destination Unreachable Message when the destination address is unreachable. */ +#define ICMP6_DU_CODE_PORT_UNREACHABLE 4 /**< Code for Destination Unreachable Message when the destination port is unreachable. */ +#define ICMP6_DU_CODE_FAILED_INGRESS_EGRESS_POLICY 5 /**< Code for Destination Unreachable Message when the source address failed on ingress/egress policy. */ +#define ICMP6_DU_CODE_REJECT_ROUTE_TO_DESTINATION 6 /**< Code for Destination Unreachable Message when the route to destination is rejected. */ + +#define ICMP6_TE_CODE_EXCEEDED_HOP_LIMIT_TRANSIT 0 /**< Code for Time Exceeded Message when the packet received had hop limit of zero. */ +#define ICMP6_TE_CODE_FAR_TIME_EXCEEDED 1 /**< Code for Time Exceeded Message to report fragmentation and reassembly timeout. */ + +#define ICMP6_PP_CODE_INVALID_HEADER 0 /**< Code for Parameter Problem Message when the header of the incoming packet was erroneous. */ +#define ICMP6_PP_CODE_UNKNOWN_NEXT_HEADER 1 /**< Code for Parameter Problem Message when the next header of the incoming packet was unrecognized. */ +#define ICMP6_PP_CODE_UNKNOWN_IPV6_OPTION 2 /**< Code for Parameter Problem Message when the option of the incoming packet was unrecognized. */ + +#define ICMP6_ERROR_MESSAGE_INVOKING_PKT_OFFSET 8 /**< Offset in the received ICMPv6 payload where the packet (partial or complete) that invoked the error message is found. */ +/* @} */ + +/** Neighbor solicitation parameters. */ +typedef struct +{ + ipv6_addr_t target_addr; /**< The IPv6 address of the target of the solicitation. MUST NOT be a multi-cast address. */ + bool add_aro; /**< Indicates if ARO option should be added. */ + uint16_t aro_lifetime; /**< The amount of time in units of 60 seconds that the router should retain the NCE for the sender of the NS. */ +} icmp6_ns_param_t; + +/**@brief Parameters associated with error message in receive and transmit paths. */ +typedef struct +{ + uint8_t type; /**< Identifies error message type, valid values as described in RFC 4443. See @ref icmp6_error_type for possible values. */ + uint8_t code; /**< Identifies code, if any associated with the error. See \ref icmp6_code and RFC 4443 for details. */ + union /**< Additional field like MTU, pointer or unused based on message type. See RFC 4443 for more details. If unused, application may ignore this field. */ + { + uint32_t mtu; /**< MTU of next hop limit, used only with ICMP6_TYPE_PACKET_TOO_LONG type. */ + uint32_t offset; /**< Offset pointing to the parameter that resulted in the ICMP6_TYPE_PARAMETER_PROBLEM error. Used only with ICMP6_TYPE_PARAMETER_PROBLEM. */ + uint32_t unused; /**< Any other error message. Is always zero. */ + } error_field; + uint8_t * p_packet; /**< Points to the start of IPv6 packet that has resulted in the error message. */ + uint16_t packet_len; /**< Length of the packet that resulted in error. The module may truncate the packet and pack only partially the packet based on configuration of ICMP6_ERROR_MESSAGE_MAX_SIZE. */ +} icmp6_error_message_param_t; + + +/**@brief ICMPv6 data RX callback. + * + * @details Asynchronous callback used to notify the application of ICMP packets received. + * By default, the application is not notified through ICMP of messages related to ECHO + * requests or any errors. However, these notifications can easily be enabled by defining + * either the ICMP6_ENABLE_ND6_MESSAGES_TO_APPLICATION or the +* ICMP6_ENABLE_ALL_MESSAGES_TO_APPLICATION if the application should handle them. + * + * @param[in] p_interface Pointer to the IPv6 interface from where the ICMP packet was received. + * @param[in] p_ip_header Pointer to the IP header of the ICMP packet received. + * @param[in] p_icmp_header Pointer to the ICMP header of the received packet. + * @param[in] process_result Notifies the application if the ICMP packet was processed successfully or if + * an error occurred, for example, if the packet was malformed. + * @param[in] p_rx_packet Packet buffer containing the packet received. p_rx_packet->p_payload + * contains the ICMP payload. + * + * @retval A provision for the application to notify the module of whether the received packet was + * processed successfully by application. The application may take ownership of the received + * packet by returning IOT_IPV6_ERR_PENDING, in which case the application must take care to + * free it using @ref iot_pbuffer_free. + */ +typedef uint32_t (*icmp6_receive_callback_t)(iot_interface_t * p_interface, + ipv6_header_t * p_ip_header, + icmp6_header_t * p_icmp_header, + uint32_t process_result, + iot_pbuffer_t * p_rx_packet); + + +/**@brief Sends ICMPv6 Error Message as defined in RFC 4443. + * + * @details API to send messages categorized under error messages. See @ref icmp6_error_type and + * RFC 4443 for valid types. + * + * @param[in] p_interface Identifies the interface on which the procedure was requested. + * Shall not be NULL. + * @param[in] p_src_addr Source IPv6 address to be used for the request. Shall not be NULL. + * @param[in] p_dest_addr Destination IPv6 address to which the message send is requested. + * Shall not be NULL. + * @param[in] p_param Parameters describing Type, code, invoking packet information any + * additional details associated with the error message. + * + * @retval NRF_SUCCESS If the send request was successful, else, an error code indicating reason for + * failure. + */ +uint32_t icmp6_error_message(const iot_interface_t * p_interface, + const ipv6_addr_t * p_src_addr, + const ipv6_addr_t * p_dest_addr, + const icmp6_error_message_param_t * p_param); + + +/**@brief Sends ICMPv6 echo request as defined in RFC4443. + * + * @details API used to send an ICMPv6 echo request packet to a specific destination address. + * The user can decide how much additional data must be sent. + * + * The application calling the function should allocate a packet before, with the type set to + * ICMP6_PACKET_TYPE in the allocation parameter. + * + * The application should pack the payload at ICMP6_ECHO_REQUEST_PAYLOAD_OFFSET. ID, + * Sequence number, ICMP Code, type checksum, etc. are filled in by the module. + * + * The application shall not free the allocated packet buffer if the procedure was successful, + * to ensure that no data copies are needed when transmitting a packet. + * + * @param[in] p_interface Pointer to the IPv6 interface to send the ICMP packet. + * @param[in] p_src_addr IPv6 source address from where the echo request is sent. + * @param[in] p_dest_addr IPv6 destination address to where the echo request is sent. + * @param[in] p_request Packet buffer containing the echo request. + * + * @retval NRF_SUCCESS If the send request was successful. + */ +uint32_t icmp6_echo_request(const iot_interface_t * p_interface, + const ipv6_addr_t * p_src_addr, + const ipv6_addr_t * p_dest_addr, + iot_pbuffer_t * p_request); + + +/**@brief Sends router solicitation message defined in RFC6775. + * + * @details API used to send a neighbor discovery message of type Router Solicitation to a specific + * destination address. If no address is known, the user should send the message to all + * routers' address (FF02::1). + * + * The function internally tries to allocate a packet buffer. EUI-64 used in the SLLAO option is + * taken from the interface parameter defined in the @ref ipv6_init() function. + * + * @param[in] p_interface Pointer to the IPv6 interface to send the ICMP packet. + * @param[in] p_src_addr IPv6 source address from where the router solicitation message is + * sent. + * @param[in] p_dest_addr IPv6 destination address to where the router solicitation message is + * sent. + * + * @retval NRF_SUCCESS If the send request was successful. + */ +uint32_t icmp6_rs_send(const iot_interface_t * p_interface, + const ipv6_addr_t * p_src_addr, + const ipv6_addr_t * p_dest_addr); + + +/**@brief Sends neighbour solicitation message defined in RFC6775. + * + * @details API used to send a neighbor discovery message of type Neighbor Solicitation to a + * specific destination address. + * + * The function internally tries to allocate a packet buffer. EUI-64 used in the SLLAO and ARO + * options is taken from the interface parameter defined in the @ref ipv6_init() function. + * + * @param[in] p_interface Pointer to the IPv6 interface to send the ICMP packet. + * @param[in] p_src_addr IPv6 source address from where the neighbor solicitation message is + * sent. + * @param[in] p_dest_addr IPv6 destination address to where the neighbor solicitation message + * is sent. + * @param[in] p_ns_param Neighbor discovery parameters. + * + * @retval NRF_SUCCESS If the send request was successful. + */ +uint32_t icmp6_ns_send(const iot_interface_t * p_interface, + const ipv6_addr_t * p_src_addr, + const ipv6_addr_t * p_dest_addr, + const icmp6_ns_param_t * p_ns_param); + + +/**@brief Registers the callback function for echo reply. + * + * @details API used to register callback to indicate the ICMP echo reply packet. Could be not used. + * + * Neighbor discovery related messages are not relayed to the application by default. + * However, this can be enabled by using the ICMP6_ENABLE_ND6_MESSAGES_TO_APPLICATION + * configuration parameter. + * + * @param[in] cb Handler called when an ICMP packet is received. + * + * @retval NRF_SUCCESS If the registration was successful. + */ +uint32_t icmp6_receive_register(icmp6_receive_callback_t cb); + +#ifdef __cplusplus +} +#endif + +#endif //ICMP6_API_H__ + +/**@} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/ipv6_api.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/ipv6_api.h new file mode 100644 index 0000000..33b8ec9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/ipv6_api.h @@ -0,0 +1,207 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** @file ipv6_api.h + * + * @defgroup iot_ipv6 IPv6 Core Application Interface for Nordic's IPv6 stack + * @ingroup iot_sdk_stack + * @{ + * @brief Nordic's IPv6 stack. Currently, only a Host role is supported. + * + * @details Nordic's IPv6 stack provides minimal implementations of ICMP, UDP for a Host, and + * IPv6 Neighbor Discovery for Host. + * Router, neighbor, and prefix cache are not maintained across BLE link disconnections or + * power cycles. + */ + +#ifndef IPV6_API_H_ +#define IPV6_API_H_ + +#include +#include "sdk_config.h" +#include "iot_common.h" +#include "iot_pbuffer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Asynchronous event identifiers type. */ +typedef enum +{ + IPV6_EVT_INTERFACE_ADD, /**< Notification of a new IPv6 interface added. */ + IPV6_EVT_INTERFACE_DELETE, /**< Notification of IPv6 interface deleted. */ + IPV6_EVT_INTERFACE_RX_DATA /**< Notification of IPv6 data, depending on configuration. For example, IPV6_ENABLE_USNUPORTED_PROTOCOLS_TO_APPLICATION. */ +} ipv6_event_id_t; + +/**@brief IPv6 address configuration. */ +typedef struct +{ + ipv6_addr_t addr; + ipv6_addr_state_t state; +} ipv6_addr_conf_t; + +/**@brief Event parameters associated with the IPV6_EVT_INTERFACE_RX_DATA event. */ +typedef struct +{ + ipv6_header_t * p_ip_header; /**< IPv6 header of the packet. */ + iot_pbuffer_t * p_rx_packet; /**< Packet buffer contains received data. */ +} ipv6_data_rx_t; + +/**@brief Asynchronous event parameter type. */ +typedef union +{ + ipv6_data_rx_t rx_event_param; /**< Parameters notified with the received IPv6 packet. */ +} ipv6_event_param_t; + +/**@brief Asynchronous event type. */ +typedef struct +{ + ipv6_event_id_t event_id; /**< Event identifier. */ + ipv6_event_param_t event_param; /**< Event parameters. */ +} ipv6_event_t; + +/**@brief Asynchronous event notification callback type. */ +typedef void (* ipv6_evt_handler_t)(iot_interface_t * p_interface, + ipv6_event_t * p_event); + +/**@brief Initialization parameters type. */ +typedef struct +{ + eui64_t * p_eui64; /**< Global identifiers EUI-64 address of device. */ + ipv6_evt_handler_t event_handler; /**< Asynchronous event notification callback registered to receive IPv6 events. */ +} ipv6_init_t; + + +/**@brief Initializes the IPv6 stack module. + * + * @param[in] p_init Initialization parameters. + * + * @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned. + */ +uint32_t ipv6_init(const ipv6_init_t * p_init); + +/**@brief Sets address to specific interface. + * + * @details API used to add or update an IPv6 address on an interface. The address can have three specific + * states that determine transmitting capabilities. + * + * @param[in] p_interface The interface on which the address must be assigned. + * @param[in] p_addr IPv6 address and state to be assigned/updated. + * + * @retval NRF_SUCCESS If the operation was successful. + * @retval NRF_ERROR_NO_MEM If no memory was available. + */ +uint32_t ipv6_address_set(const iot_interface_t * p_interface, + const ipv6_addr_conf_t * p_addr); + + +/**@brief Removes address from specific interface. + * + * @details API used to remove an IPv6 address from an interface. + * + * @param[in] p_interface The interface from which the address must be removed. + * @param[in] p_addr IPv6 address to remove. + * + * @retval NRF_SUCCESS If the operation was successful. + * @retval NRF_ERROR_NOT_FOUND If no address was found. + */ +uint32_t ipv6_address_remove(const iot_interface_t * p_interface, + const ipv6_addr_t * p_addr); + + +/**@brief Checks if given unicast address has been registered. + * + * @param[in] p_interface The interface on which IPv6 address wil be checked. + * @param[in] p_addr IPv6 address to be checked. + * + * @retval NRF_SUCCESS If the operation was successful. + * @retval NRF_ERROR_NOT_FOUND If no address was found. + */ +uint32_t ipv6_address_check(const iot_interface_t * p_interface, + const ipv6_addr_t * p_addr); + + +/**@brief Finds the best matched address and interface. + * + * @details API used to find the most suitable interface and address to a given destination address. + * + * To look only for the interface, set p_addr_r to NULL. + * + * To find the best matched address, IPV6_ADDR_STATE_PREFERRED state of address is required. + * + * @param[out] pp_interface Interface to be found. + * @param[out] p_addr_r Best matching address if procedure succeeded and this value was not NULL. + * @param[inout] p_addr_f IPv6 address for which best matching interface and/or address are requested. + * + * @retval NRF_SUCCESS If the operation was successful. + * @retval NRF_ERROR_NOT_FOUND If no interface was found. + * @retval NRF_ERROR_NOT_SUPPORTED If the operation was not supported. + */ +uint32_t ipv6_address_find_best_match(iot_interface_t ** pp_interface, + ipv6_addr_t * p_addr_r, + const ipv6_addr_t * p_addr_f); + + +/**@brief Sends IPv6 packet. + * + * @details API used to send an IPv6 packet. Which interface that packet must be sent to is determined + * by analyzing the destination address. + * + * @param[in] p_interface The interface to which the packet is to be sent. + * @param[in] p_packet IPv6 packet to send. The packet should be allocated using + * @ref iot_pbuffer_allocate, to give stack control and to release + * the memory buffer. + * + * @retval NRF_SUCCESS If the send request was successful. + * @retval NRF_ERROR_NOT_FOUND If there was a failure while looking for the interface. + * @retval NRF_ERROR_INVALID_PARAM If there was an error in processing the IPv6 packet. + * @retval NRF_ERROR_NO_MEM If no memory was available in the transport + * interface. + */ +uint32_t ipv6_send(const iot_interface_t * p_interface, iot_pbuffer_t * p_packet); + +#ifdef __cplusplus +} +#endif + +#endif //IPV6_API_H_ + +/** @} */ + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/udp_api.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/udp_api.h new file mode 100644 index 0000000..8efa378 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/ipv6_stack/include/udp_api.h @@ -0,0 +1,255 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** @file udp_api.h + * + * @defgroup iot_udp UDP Application Interface for Nordic's IPv6 stack + * @ingroup iot_sdk_stack + * @{ + * @brief Nordic User Datagram Protocol Application Interface for Nordic's IPv6 stack. + * + * @details This module provides basic features related to User Datagram Protocol (UDP) support. + */ + +#ifndef UDP_API_H__ +#define UDP_API_H__ + +#include "sdk_config.h" +#include "sdk_common.h" +#include "iot_defines.h" +#include "ipv6_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief UDP socket reference. + */ +typedef struct +{ + uint32_t socket_id; /**< UDP socket identifier. */ + void * p_app_data; /**< Pointer to application data mapped by the application to the socket. If no mapping is provided by the application using the @ref udp6_socket_app_data_set API, this pointer is NULL. */ +} udp6_socket_t; + +/** + * @brief UDP data receive callback. + * + * @details API used to notify the application of UDP packets received. If the received data is + * malformed (for example, a checksum error), the packet is still notified to the application. + * The process_result parameter indicates whether the packet was successfully processed by UDP. + * The application should check process_result before + * consuming the packet. + * + * @param[in] p_socket Reference to the socket on which the data is received. + * @param[in] p_ip6_header Pointer to the IP header of the received ICMP packet. + * @param[in] p_udp_header Pointer to the UDP header of the received packet. + * @param[in] process_result Notifies the application if the UDP packet was processed successfully success or + * if an error occurred, for example, the packet was malformed. + * @param[in] p_rx_packet Packet buffer containing the received packed. p_rx_packet->p_payload + * contains the UDP payload. + * + * @returns A provision for the application to notify the module of whether the received packet was + * processed successfully by application. The application may take ownership of the received + * packet by returning IOT_IPV6_ERR_PENDING, in which case the application must take care to + * free it using @ref iot_pbuffer_free. + */ +typedef uint32_t (* udp6_handler_t)(const udp6_socket_t * p_socket, + const ipv6_header_t * p_ip_header, + const udp6_header_t * p_udp_header, + uint32_t process_result, + iot_pbuffer_t * p_rx_packet); + + +/** + * @brief Allocates a UDP socket. + * + * @details This API should be called to be assigned a UDP socket. The maximum number of sockets that can + * be allocated using the API is determined by the define UDP6_MAX_SOCKET_COUNT. + * + * @param[out] p_socket Reference to the allocated socket is provided in the pointer if the procedure + * was successful. Should not be NULL. + * + * @retval NRF_SUCCESS If the socket was allocated successfully. Otherwise, an + * error code that indicates the reason for the failure is returned. + */ +uint32_t udp6_socket_allocate(udp6_socket_t * p_socket); + + +/** + * @brief Frees an allocated UDP socket. + * + * @details API used to free a socket allocated using @ref udp6_socket_allocate. + * + * @param[in] p_socket Handle reference to the socket. Should not be NULL. + * + * @retval NRF_SUCCESS If the socket was freed successfully. Otherwise, an + * error code that indicates the reason for the failure is returned. + * + */ +uint32_t udp6_socket_free(const udp6_socket_t * p_socket); + + +/** + * @brief Registers callback to be notified of data received on a socket. + * + * @details API to register a callback to be notified of data received on a socket. + * + * @param[in] p_socket Handle reference to the socket. Should not be NULL. + * @param[in] callback Callback being registered to receive data. Should not be NULL. + * + * @retval NRF_SUCCESS If the procedure was executed successfully. Otherwise, an + * error code that indicates the reason for the failure is returned. + * + */ +uint32_t udp6_socket_recv(const udp6_socket_t * p_socket, + const udp6_handler_t callback); + + +/** + * @brief Binds a UDP socket to a specific port and address. + * + * @details API used to bind a UDP socket to a local port and an address. + * + * @param[in] p_socket Handle reference to the socket. Should not be NULL. + * @param[in] p_src_addr Local IPv6 address to be bound on specific socket. + * @param[in] src_port Local UDP port to be bound on specific socket. + * + * @retval NRF_SUCCESS If the procedure was executed successfully. Otherwise, an + * error code that indicates the reason for the failure is returned. + * + */ +uint32_t udp6_socket_bind(const udp6_socket_t * p_socket, + const ipv6_addr_t * p_src_addr, + uint16_t src_port); + + +/** + * @brief Connects a UDP socket to aspecific port and address. + * + * @details API used to connect a UDP socket to a remote port and remote address. + * + * @param[in] p_socket Handle reference to the socket. Should not be NULL. + * @param[in] p_dest_addr IPv6 address of the remote destination. + * @param[in] dest_port Remote USP port to connect the socket to. + * + * @retval NRF_SUCCESS If the connection was established successfully. + */ +uint32_t udp6_socket_connect(const udp6_socket_t * p_socket, + const ipv6_addr_t * p_dest_addr, + uint16_t dest_port); + + +/** + * @brief Sends a UDP packet on a specific socket. + * + * @details API used to send UDP data over a UDP socket. Remote port and address must be set with + * \ref udp6_socket_connect() before using this API. + * + * Applications that call this function should allocate a packet with type + * UDP6_PACKET_TYPE (set in the allocation + * parameter) before calling the function. + * + * The application shall not free the allocated packet buffer if the procedure was + * successful, to ensure that no data copies are needed when transmitting a packet. + * + * @param[in] p_socket Handle reference to the socket. Should not be NULL. + * @param[in] p_packet Data to be transmitted on the socket. The application should allocate a packet + * buffer with type UDP6_PACKET_TYPE using \ref iot_pbuffer_allocate. + * p_packet->p_payload and p_packet->length should be appropriately + * populated by the application to contain the payload and length of the UDP + * packet, respectively. + * + * @retval NRF_SUCCESS If the procedure was executed successfully. Otherwise, an + * error code that indicates the reason for the failure is returned. + * + */ +uint32_t udp6_socket_send(const udp6_socket_t * p_socket, + iot_pbuffer_t * p_packet); + + +/** + * @brief Sends a UDP packet on a specific socket to a remote address and port. + * + * @details API used to send UDP data over a UDP socket. + * + * @param[in] p_socket Handle reference to the socket. Should not be NULL. + * @param[in] p_dest_addr IPv6 address of the remote destination. + * @param[in] dest_port Remote UDP port to which data transmission is requested. + * @param[in] p_packet Data to be transmitted on the socket. Application should allocate a + * packet buffer with type UDP6_PACKET_TYPE using \ref + * iot_pbuffer_allocate. p_packet->p_payload and p_packet->length should + * be appropriately populated by the application to contain the payload and + * length of the UDP packet, respectively. + * + * @retval NRF_SUCCESS If the procedure was executed successfully. Otherwise, an + * error code that indicates the reason for the failure is returned. + * + */ +uint32_t udp6_socket_sendto(const udp6_socket_t * p_socket, + const ipv6_addr_t * p_dest_addr, + uint16_t dest_port, + iot_pbuffer_t * p_packet); + + +/** + * @brief Sets application data for a socket. + * + * @details A utility API that allows the application to set any application specific mapping with the + * UDP Socket. The UDP module remembers the pointer provided by the application as long as the + * socket is not freed and if receive data callback is called each time as part of + * udp_socket_t. + * + * @param[in] p_socket Pointer to the socket for which the application data mapping is being set. + * A pointer to the application data should be provided by setting the + * p_socket->p_app_data field. + * + * @retval NRF_SUCCESS If the procedure was executed successfully. Otherwise, an + * error code that indicates the reason for the failure is returned. + * + */ +uint32_t udp6_socket_app_data_set(const udp6_socket_t * p_socket); + +#ifdef __cplusplus +} +#endif + +#endif //UDP_API_H__ + +/**@} */ -- cgit v1.2.3