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_LOWER_TRANSPORT_H 39 #define __MESH_LOWER_TRANSPORT_H 40 41 #include <stdint.h> 42 43 #include "mesh/mesh_network.h" 44 #include "btstack_bool.h" 45 46 #ifdef __cplusplus 47 extern "C" 48 { 49 #endif 50 51 52 typedef enum { 53 MESH_TRANSPORT_OPCODE_ACK = 0, 54 MESH_TRANSPORT_OPCODE_FRIEND_POLL, 55 MESH_TRANSPORT_OPCODE_FRIEND_UPDATE, 56 MESH_TRANSPORT_OPCODE_FRIEND_REQUEST, 57 MESH_TRANSPORT_OPCODE_FRIEND_OFFER, 58 MESH_TRANSPORT_OPCODE_FRIEND_CLEAR, 59 MESH_TRANSPORT_OPCODE_FRIEND_CLEAR_CONFIRM, 60 MESH_TRANSPORT_OPCODE_FRIEND_FRIEND_SUBSCRIPTION_LIST_ADD, 61 MESH_TRANSPORT_OPCODE_FRIEND_FRIEND_SUBSCRIPTION_LIST_REMOVE, 62 MESH_TRANSPORT_OPCODE_FRIEND_FRIEND_SUBSCRIPTION_LIST_CONFIRM, 63 MESH_TRANSPORT_OPCODE_HEARTBEAT, 64 } mesh_transport_opcode_t; 65 66 typedef enum { 67 MESH_TRANSPORT_PDU_RECEIVED, 68 MESH_TRANSPORT_PDU_SENT, 69 } mesh_transport_callback_type_t; 70 71 typedef enum { 72 MESH_TRANSPORT_STATUS_PARTIALLY_SEND, 73 MESH_TRANSPORT_STATUS_SUCCESS, 74 MESH_TRANSPORT_STATUS_SEND_FAILED, 75 MESH_TRANSPORT_STATUS_SEND_ABORT_BY_REMOTE, 76 } mesh_transport_status_t; 77 78 // allocator 79 mesh_transport_pdu_t * mesh_transport_pdu_get(void); 80 void mesh_transport_pdu_free(mesh_transport_pdu_t * transport_pdu); 81 82 // transport getter/setter 83 uint16_t mesh_transport_nid(mesh_transport_pdu_t * transport_pdu); 84 uint16_t mesh_transport_ctl(mesh_transport_pdu_t * transport_pdu); 85 uint16_t mesh_transport_ttl(mesh_transport_pdu_t * transport_pdu); 86 uint32_t mesh_transport_seq(mesh_transport_pdu_t * transport_pdu); 87 uint32_t mesh_transport_seq_zero(mesh_transport_pdu_t * transport_pdu); 88 uint16_t mesh_transport_src(mesh_transport_pdu_t * transport_pdu); 89 uint16_t mesh_transport_dst(mesh_transport_pdu_t * transport_pdu); 90 uint8_t mesh_transport_control_opcode(mesh_transport_pdu_t * transport_pdu); 91 92 void mesh_transport_set_nid_ivi(mesh_transport_pdu_t * transport_pdu, uint8_t nid_ivi); 93 void mesh_transport_set_ctl_ttl(mesh_transport_pdu_t * transport_pdu, uint8_t ctl_ttl); 94 void mesh_transport_set_seq(mesh_transport_pdu_t * transport_pdu, uint32_t seq); 95 void mesh_transport_set_src(mesh_transport_pdu_t * transport_pdu, uint16_t src); 96 void mesh_transport_set_dest(mesh_transport_pdu_t * transport_pdu, uint16_t dest); 97 98 99 void mesh_lower_transport_init(void); 100 void mesh_lower_transport_set_higher_layer_handler(void (*pdu_handler)( mesh_transport_callback_type_t callback_type, mesh_transport_status_t status, mesh_pdu_t * pdu)); 101 102 void mesh_lower_transport_message_processed_by_higher_layer(mesh_pdu_t * pdu); 103 104 bool mesh_lower_transport_can_send_to_dest(uint16_t dest); 105 void mesh_lower_transport_reserve_slot(void); 106 void mesh_lower_transport_send_pdu(mesh_pdu_t * pdu); 107 108 // test 109 void mesh_lower_transport_received_message(mesh_network_callback_type_t callback_type, mesh_network_pdu_t *network_pdu); 110 void mesh_lower_transport_dump(void); 111 void mesh_lower_transport_reset(void); 112 113 #ifdef __cplusplus 114 } /* end of extern "C" */ 115 #endif 116 117 #endif 118