xref: /btstack/src/mesh/mesh_lower_transport.h (revision cd16791d639623fd80f4154c6c9854b9943327df)
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_LOWER_TRANSPORT_H
3977ba3d3fSMatthias Ringwald #define __MESH_LOWER_TRANSPORT_H
4077ba3d3fSMatthias Ringwald 
4177ba3d3fSMatthias Ringwald #include <stdint.h>
4277ba3d3fSMatthias Ringwald 
43f4854a5eSMatthias Ringwald #include "mesh/mesh_network.h"
44f4854a5eSMatthias Ringwald 
4577ba3d3fSMatthias Ringwald #ifdef __cplusplus
4677ba3d3fSMatthias Ringwald extern "C"
4777ba3d3fSMatthias Ringwald {
4877ba3d3fSMatthias Ringwald #endif
4977ba3d3fSMatthias Ringwald 
5077ba3d3fSMatthias Ringwald 
5177ba3d3fSMatthias Ringwald typedef enum {
5277ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_ACK = 0,
5377ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_POLL,
5477ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_UPDATE,
5577ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_REQUEST,
5677ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_OFFER,
5777ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_CLEAR,
5877ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_CLEAR_CONFIRM,
5977ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_FRIEND_SUBSCRIPTION_LIST_ADD,
6077ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_FRIEND_SUBSCRIPTION_LIST_REMOVE,
6177ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_FRIEND_FRIEND_SUBSCRIPTION_LIST_CONFIRM,
6277ba3d3fSMatthias Ringwald     MESH_TRANSPORT_OPCODE_HEARTBEAT,
6377ba3d3fSMatthias Ringwald } mesh_transport_opcode_t;
6477ba3d3fSMatthias Ringwald 
6577ba3d3fSMatthias Ringwald typedef enum {
6677ba3d3fSMatthias Ringwald     MESH_TRANSPORT_PDU_RECEIVED,
6777ba3d3fSMatthias Ringwald     MESH_TRANSPORT_PDU_SENT,
6877ba3d3fSMatthias Ringwald } mesh_transport_callback_type_t;
6977ba3d3fSMatthias Ringwald 
7077ba3d3fSMatthias Ringwald typedef enum {
71*cd16791dSMatthias Ringwald     MESH_TRANSPORT_STATUS_PARTIALLY_SEND,
7277ba3d3fSMatthias Ringwald     MESH_TRANSPORT_STATUS_SUCCESS,
7377ba3d3fSMatthias Ringwald     MESH_TRANSPORT_STATUS_SEND_FAILED,
7477ba3d3fSMatthias Ringwald     MESH_TRANSPORT_STATUS_SEND_ABORT_BY_REMOTE,
7577ba3d3fSMatthias Ringwald } mesh_transport_status_t;
7677ba3d3fSMatthias Ringwald 
7777ba3d3fSMatthias Ringwald // allocator
7877ba3d3fSMatthias Ringwald mesh_transport_pdu_t * mesh_transport_pdu_get(void);
7977ba3d3fSMatthias Ringwald void mesh_transport_pdu_free(mesh_transport_pdu_t * transport_pdu);
8077ba3d3fSMatthias Ringwald 
8177ba3d3fSMatthias Ringwald // transport getter/setter
8277ba3d3fSMatthias Ringwald uint16_t mesh_transport_nid(mesh_transport_pdu_t * transport_pdu);
8377ba3d3fSMatthias Ringwald uint16_t mesh_transport_ctl(mesh_transport_pdu_t * transport_pdu);
8477ba3d3fSMatthias Ringwald uint16_t mesh_transport_ttl(mesh_transport_pdu_t * transport_pdu);
8577ba3d3fSMatthias Ringwald uint32_t mesh_transport_seq(mesh_transport_pdu_t * transport_pdu);
8677ba3d3fSMatthias Ringwald uint32_t mesh_transport_seq_zero(mesh_transport_pdu_t * transport_pdu);
8777ba3d3fSMatthias Ringwald uint16_t mesh_transport_src(mesh_transport_pdu_t * transport_pdu);
8877ba3d3fSMatthias Ringwald uint16_t mesh_transport_dst(mesh_transport_pdu_t * transport_pdu);
89e9292fe8SMatthias Ringwald uint8_t  mesh_transport_control_opcode(mesh_transport_pdu_t * transport_pdu);
9077ba3d3fSMatthias Ringwald 
9177ba3d3fSMatthias Ringwald void mesh_transport_set_nid_ivi(mesh_transport_pdu_t * transport_pdu, uint8_t nid_ivi);
9277ba3d3fSMatthias Ringwald void mesh_transport_set_ctl_ttl(mesh_transport_pdu_t * transport_pdu, uint8_t ctl_ttl);
9377ba3d3fSMatthias Ringwald void mesh_transport_set_seq(mesh_transport_pdu_t * transport_pdu, uint32_t seq);
9477ba3d3fSMatthias Ringwald void mesh_transport_set_src(mesh_transport_pdu_t * transport_pdu, uint16_t src);
9577ba3d3fSMatthias Ringwald void mesh_transport_set_dest(mesh_transport_pdu_t * transport_pdu, uint16_t dest);
9677ba3d3fSMatthias Ringwald 
9777ba3d3fSMatthias Ringwald 
984407d0bbSMatthias Ringwald void mesh_lower_transport_init(void);
9977ba3d3fSMatthias Ringwald 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));
10077ba3d3fSMatthias Ringwald 
10177ba3d3fSMatthias Ringwald void mesh_lower_transport_message_processed_by_higher_layer(mesh_pdu_t * pdu);
10277ba3d3fSMatthias Ringwald 
103*cd16791dSMatthias Ringwald int  mesh_lower_transport_can_send_to_dest(uint16_t dest);
104*cd16791dSMatthias Ringwald void mesh_lower_transport_reserve_slot(void);
10577ba3d3fSMatthias Ringwald void mesh_lower_transport_send_pdu(mesh_pdu_t * pdu);
10677ba3d3fSMatthias Ringwald 
10777ba3d3fSMatthias Ringwald // test
10877ba3d3fSMatthias Ringwald void mesh_lower_transport_received_message(mesh_network_callback_type_t callback_type, mesh_network_pdu_t *network_pdu);
10977ba3d3fSMatthias Ringwald void mesh_lower_transport_dump(void);
11077ba3d3fSMatthias Ringwald void mesh_lower_transport_reset(void);
11177ba3d3fSMatthias Ringwald 
11277ba3d3fSMatthias Ringwald #ifdef __cplusplus
11377ba3d3fSMatthias Ringwald } /* end of extern "C" */
11477ba3d3fSMatthias Ringwald #endif
11577ba3d3fSMatthias Ringwald 
11677ba3d3fSMatthias Ringwald #endif
117