1 /* 2 * Copyright (C) 2018 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #ifndef __MESH_TRANSPORT_H 39 #define __MESH_TRANSPORT_H 40 41 #include <stdint.h> 42 43 #include "mesh/mesh_network.h" 44 #include "mesh/mesh_lower_transport.h" 45 46 #ifdef __cplusplus 47 extern "C" 48 { 49 #endif 50 51 // upper transport message builder 52 typedef struct { 53 mesh_upper_transport_pdu_t * pdu; 54 mesh_network_pdu_t * segment; 55 } mesh_upper_transport_builder_t; 56 57 void mesh_upper_transport_message_init(mesh_upper_transport_builder_t * builder, mesh_pdu_type_t pdu_type); 58 void mesh_upper_transport_message_add_data(mesh_upper_transport_builder_t * builder, const uint8_t * data, uint16_t data_len); 59 void mesh_upper_transport_message_add_uint8(mesh_upper_transport_builder_t * builder, uint8_t value); 60 void mesh_upper_transport_message_add_uint16(mesh_upper_transport_builder_t * builder, uint16_t value); 61 void mesh_upper_transport_message_add_uint24(mesh_upper_transport_builder_t * builder, uint16_t value); 62 void mesh_upper_transport_message_add_uint32(mesh_upper_transport_builder_t * builder, uint16_t value); 63 mesh_upper_transport_pdu_t * mesh_upper_transport_message_finalize(mesh_upper_transport_builder_t * builder); 64 65 66 void mesh_upper_transport_init(void); 67 68 void mesh_upper_transport_message_processed_by_higher_layer(mesh_pdu_t * pdu); 69 70 // Control PDUs 71 72 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)); 73 74 uint8_t mesh_upper_transport_setup_control_pdu(mesh_pdu_t * pdu, uint16_t netkey_index, 75 uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode, const uint8_t * control_pdu_data, uint16_t control_pdu_len); 76 77 void mesh_upper_transport_send_control_pdu(mesh_pdu_t * pdu); 78 79 // Access PDUs 80 81 82 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)); 83 84 uint8_t mesh_upper_transport_setup_access_pdu_header(mesh_pdu_t * pdu, uint16_t netkey_index, uint16_t appkey_index, 85 uint8_t ttl, uint16_t src, uint16_t dest, uint8_t szmic); 86 87 void mesh_upper_transport_send_access_pdu(mesh_pdu_t * pdu); 88 89 void mesh_upper_transport_pdu_free(mesh_pdu_t * pdu); 90 91 // test 92 void mesh_upper_transport_dump(void); 93 void mesh_upper_transport_reset(void); 94 95 #ifdef __cplusplus 96 } /* end of extern "C" */ 97 #endif 98 99 #endif 100