177ba3d3fSMatthias Ringwald /* 277ba3d3fSMatthias Ringwald * Copyright (C) 2018 BlueKitchen GmbH 377ba3d3fSMatthias Ringwald * 477ba3d3fSMatthias Ringwald * Redistribution and use in source and binary forms, with or without 577ba3d3fSMatthias Ringwald * modification, are permitted provided that the following conditions 677ba3d3fSMatthias Ringwald * are met: 777ba3d3fSMatthias Ringwald * 877ba3d3fSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 977ba3d3fSMatthias Ringwald * notice, this list of conditions and the following disclaimer. 1077ba3d3fSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 1177ba3d3fSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 1277ba3d3fSMatthias Ringwald * documentation and/or other materials provided with the distribution. 1377ba3d3fSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 1477ba3d3fSMatthias Ringwald * contributors may be used to endorse or promote products derived 1577ba3d3fSMatthias Ringwald * from this software without specific prior written permission. 1677ba3d3fSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 1777ba3d3fSMatthias Ringwald * personal benefit and not for any commercial purpose or for 1877ba3d3fSMatthias Ringwald * monetary gain. 1977ba3d3fSMatthias Ringwald * 2077ba3d3fSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 2177ba3d3fSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2277ba3d3fSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 2377ba3d3fSMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 2477ba3d3fSMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2577ba3d3fSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2677ba3d3fSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2777ba3d3fSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2877ba3d3fSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2977ba3d3fSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 3077ba3d3fSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3177ba3d3fSMatthias Ringwald * SUCH DAMAGE. 3277ba3d3fSMatthias Ringwald * 3377ba3d3fSMatthias Ringwald * Please inquire about commercial licensing options at 3477ba3d3fSMatthias Ringwald * [email protected] 3577ba3d3fSMatthias Ringwald * 3677ba3d3fSMatthias Ringwald */ 3777ba3d3fSMatthias Ringwald 3877ba3d3fSMatthias Ringwald #ifndef __MESH_TRANSPORT_H 3977ba3d3fSMatthias Ringwald #define __MESH_TRANSPORT_H 4077ba3d3fSMatthias Ringwald 4177ba3d3fSMatthias Ringwald #include <stdint.h> 4277ba3d3fSMatthias Ringwald 43f4854a5eSMatthias Ringwald #include "mesh/mesh_network.h" 44f4854a5eSMatthias Ringwald #include "mesh/mesh_lower_transport.h" 45f4854a5eSMatthias Ringwald 4677ba3d3fSMatthias Ringwald #ifdef __cplusplus 4777ba3d3fSMatthias Ringwald extern "C" 4877ba3d3fSMatthias Ringwald { 4977ba3d3fSMatthias Ringwald #endif 5077ba3d3fSMatthias Ringwald 51f1219446SMatthias Ringwald // upper transport message builder 52f1219446SMatthias Ringwald typedef struct { 53f1219446SMatthias Ringwald mesh_upper_transport_pdu_t * pdu; 54ce16a729SMatthias Ringwald mesh_network_pdu_t * segment; 55f1219446SMatthias Ringwald } mesh_upper_transport_builder_t; 56f1219446SMatthias Ringwald 57f1219446SMatthias Ringwald void mesh_upper_transport_message_init(mesh_upper_transport_builder_t * builder, mesh_pdu_type_t pdu_type); 58f1219446SMatthias Ringwald void mesh_upper_transport_message_add_data(mesh_upper_transport_builder_t * builder, const uint8_t * data, uint16_t data_len); 59f1219446SMatthias Ringwald void mesh_upper_transport_message_add_uint8(mesh_upper_transport_builder_t * builder, uint8_t value); 60f1219446SMatthias Ringwald void mesh_upper_transport_message_add_uint16(mesh_upper_transport_builder_t * builder, uint16_t value); 61f1219446SMatthias Ringwald void mesh_upper_transport_message_add_uint24(mesh_upper_transport_builder_t * builder, uint16_t value); 62f1219446SMatthias Ringwald void mesh_upper_transport_message_add_uint32(mesh_upper_transport_builder_t * builder, uint16_t value); 63f1219446SMatthias Ringwald mesh_upper_transport_pdu_t * mesh_upper_transport_message_finalize(mesh_upper_transport_builder_t * builder); 64f1219446SMatthias Ringwald 65f1219446SMatthias Ringwald 664407d0bbSMatthias Ringwald void mesh_upper_transport_init(void); 6777ba3d3fSMatthias Ringwald 68404d2482SMatthias Ringwald void mesh_upper_transport_register_control_message_handler(void (*callback)(mesh_transport_callback_type_t callback_type, mesh_transport_status_t status, mesh_pdu_t * pdu)); 6977ba3d3fSMatthias Ringwald 70404d2482SMatthias Ringwald void mesh_upper_transport_register_access_message_handler(void (*callback)(mesh_transport_callback_type_t callback_type, mesh_transport_status_t status, mesh_pdu_t * pdu)); 7177ba3d3fSMatthias Ringwald 72*4802c66dSMatthias Ringwald void mesh_upper_transport_message_processed_by_higher_layer(mesh_pdu_t * pdu); 73*4802c66dSMatthias Ringwald 74*4802c66dSMatthias Ringwald void mesh_upper_transport_pdu_free(mesh_pdu_t * pdu); 75*4802c66dSMatthias Ringwald 76*4802c66dSMatthias Ringwald // Control PDUs: setup and send 77*4802c66dSMatthias Ringwald uint8_t mesh_upper_transport_setup_unsegmented_control_pdu(mesh_network_pdu_t * network_pdu, uint16_t netkey_index, uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode, 78*4802c66dSMatthias Ringwald const uint8_t * control_pdu_data, uint16_t control_pdu_len); 79*4802c66dSMatthias Ringwald 80*4802c66dSMatthias Ringwald uint8_t mesh_upper_transport_setup_segmented_control_pdu_header(mesh_upper_transport_pdu_t * upper_pdu, uint16_t netkey_index, uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode); 81*4802c66dSMatthias Ringwald 82*4802c66dSMatthias Ringwald void mesh_upper_transport_send_control_pdu(mesh_pdu_t * pdu); 83*4802c66dSMatthias Ringwald 84*4802c66dSMatthias Ringwald // Access PDUs: setup and send 8577ba3d3fSMatthias Ringwald uint8_t mesh_upper_transport_setup_access_pdu_header(mesh_pdu_t * pdu, uint16_t netkey_index, uint16_t appkey_index, 8677ba3d3fSMatthias Ringwald uint8_t ttl, uint16_t src, uint16_t dest, uint8_t szmic); 8777ba3d3fSMatthias Ringwald 8877ba3d3fSMatthias Ringwald void mesh_upper_transport_send_access_pdu(mesh_pdu_t * pdu); 89b551f24dSMatthias Ringwald 9077ba3d3fSMatthias Ringwald 91dd729594SMatthias Ringwald // test 92dd729594SMatthias Ringwald void mesh_upper_transport_dump(void); 93dd729594SMatthias Ringwald void mesh_upper_transport_reset(void); 94dd729594SMatthias Ringwald 9577ba3d3fSMatthias Ringwald #ifdef __cplusplus 9677ba3d3fSMatthias Ringwald } /* end of extern "C" */ 9777ba3d3fSMatthias Ringwald #endif 9877ba3d3fSMatthias Ringwald 9977ba3d3fSMatthias Ringwald #endif 100