/* * Copyright (c) 2015-2018, Arm Limited and affiliates. * SPDX-License-Identifier: BSD-3-Clause * * 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 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 the copyright holder nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 thread_commissioning_api.h * \brief Thread commissioning API. * * This is a public API used for creating a commissioning device. You can create an on-mesh commissioner * and a native commissioner. */ #ifndef THREAD_COMMISSIONING_API_H_ #define THREAD_COMMISSIONING_API_H_ #ifdef __cplusplus extern "C" { #endif #include "ns_types.h" #define TRACE_GROUP_THREAD_COMMISSIONING_API "TCoA" /**< trace group definition */ /** * /enum commissioning_state_e * /brief Commissioning states. */ typedef enum { COMMISSIONING_STATE_ACCEPT, COMMISSIONING_STATE_PENDING, COMMISSIONING_STATE_REJECT, COMMISSIONING_STATE_NO_NETWORK } commissioning_state_e; /** \brief Commissioning petition response callback. * * \param interface_id Network interface ID. The request comes from this ID. * \param commissioner_session_id Commissioner session ID. * \param state State of the commissioning. * * \return 0 success, other values failure. */ typedef int (thread_commissioning_status_cb)(int8_t interface_id, uint16_t commissioner_session_id, commissioning_state_e state); /** \brief Register the commissioner interface. * * If the network interface is up, the commissioner functionality is started within the Thread network. * If there is no interface, the network needs to be scanned first. When the network is found you can add an insecure commissioner, * attach to it and start using a different communication method with the border router. * * \param interface_id Interface ID where the request was made. * \param PSKc Pre-shared key between the commissioner and the Thread network. * * \return 0 success, other values failure. */ int thread_commissioning_register(int8_t interface_id, uint8_t PSKc[16]); /** \brief Unregister the commissioner interface. * * This cleans up all the commissioner data from the device and disconnects it from the Thread network if an insecure commissioner was used. * * \param interface_id Network interface ID. The request comes from this ID. * * \return 0 success, other values failure. */ int thread_commissioning_unregister(int8_t interface_id); /** \brief Start the commissioning petition. * * If the commissioner is insecure, you need to scan the networks and select the Thread network where you want to be a commissioner. * * \param interface_id Network interface ID. The request comes from this ID. * \param commissioner_id_ptr NUL terminated commissioner ID string. * \param status_cb_ptr A callback function indicating the result of the operation. Can be NULL if no result code needed. * \return 0 Indicates success. * * \return -1 The client needs to scan the network to become an insecure commissioner. * \return Any other value indicates other failures. */ int thread_commissioning_petition_start(int8_t interface_id, char *commissioner_id_ptr, thread_commissioning_status_cb *status_cb_ptr); /** \brief Send petition keep alive. * * This function must be called in 40 second intervals. TODO rethink if this should be automatic. * * \param interface_id Network interface ID. The request comes from this ID. * \param state Commissioning state. * * \return 0 success, other values failure. */ int thread_commissioning_petition_keep_alive(int8_t interface_id, commissioning_state_e state); /** \brief Callback received when a new device is completing the joining process. * * The message may include the following meshcop TLV fields: * * State TLV * * Vendor Name TLV * * Vendor Model TLV * * Vendor SW Version TLV * * Vendor Data TLV * * Vendor Stack * * Version TLV * * Provisioning URL TLV * * \param interface_id Network interface ID. The request comes from this ID. * \param EUI64 The client identifier. * \param message_ptr A message including the meshcop TLV set. This message can be parsed using thread_meshcop_lib.h. * \param message_len The length of the message. * * \return 0 Device accepted. * \return Any other value, device rejected. */ typedef int (thread_commissioning_joiner_finalisation_cb)(int8_t interface_id, uint8_t EUI64[8], uint8_t *message_ptr, uint16_t message_len); /** \brief Add a device to commission to the Thread network. * * \param interface_id Network interface ID. The request comes from this ID. * \param short_eui64 A boolean value indicating that short EUI version is used for bloom filter generation. * \param EUI64 A pointer to EUI64 buffer. * \param PSKd_ptr A pointer to PSKd buffer. * \param PSKd_len PSKd string length, current validity check is 1-32 bytes. * \param joining_device_cb_ptr A callback function indicating the result of the operation. Can be NULL if no result code needed. * * \return 0 success, other values failure */ int thread_commissioning_device_add(int8_t interface_id, bool short_eui64, uint8_t EUI64[8], uint8_t *PSKd_ptr, uint8_t PSKd_len, thread_commissioning_joiner_finalisation_cb *joining_device_cb_ptr); /** \brief Delete a device to commission to the Thread network. * * \param interface_id Network interface ID. The request comes from this ID. * \param EUI64 A pointer to EUI64 buffer. * * \return 0 success, other values failure. */ int thread_commissioning_device_delete(int8_t interface_id, uint8_t EUI64[8]); /** \brief Get next added device details. * * \param ptr A pointer for internal looping. First, use NULL pointer, after that use return pointer. * \param interface_id Network interface ID. The request comes from this ID. * \param short_eui64 A boolean value indicating that short EUI version is used for bloom filter generation. Can be NULL when no result wanted. * \param EUI64 A pointer to EUI64 buffer. Can be NULL when no result wanted. * \param PSKd A pointer to PSKd buffer. Can be NULL when no result wanted. * \param PSKd_len Length of data in PSKd. * * \return >NULL for next iteration. * \return NULL when end of list. */ void *thread_commission_device_get_next(void *ptr, int8_t interface_id, bool *short_eui64, uint8_t EUI64[8], uint8_t PSKd[32], uint8_t *PSKd_len); /** Interfaces needed for native commissioner. * current design: * - The application configures the interface to scan available Thread networks to join * - Time passes and the user wants to start scanning for native commissioner networks. * - The application configures the interface to begin native commissioner interface scans. * - The application selects a network to connect to. * - The stack connects to that network -> interface UP event sent. * - The application starts using Commissioning API to send COMM_PET.req message triggering a DTLS handshake. * - Commission API queries the leader address and native info and uses the one that works. * * */ typedef struct thread_commissioning_link_configuration { uint8_t name[16]; /**< Name of the Thread network. utf8 string nul terminated if shorter than 16. */ uint8_t destination_address[16]; /** 0 Instance ID. * \return <= 0 fail. */ int8_t thread_commissioning_get_management_id(int8_t interface_id); /** * \brief Attach native commissioner to destination address and port. * * \param interface_id Network interface ID. * \param destination_address Destination address pointer. * \param destination_port Commissioning port. * * \return 0 attach OK. * \return < 0 fail. */ int thread_commissioning_attach(int8_t interface_id, uint8_t *destination_address, uint16_t destination_port); #ifdef __cplusplus } #endif #endif /* THREAD_COMMISSIONING_API_H_ */