Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mesh.h Source File

mesh.h

00001 /*
00002  * Copyright (c) 2014-2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef MESH_H_
00018 #define MESH_H_
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 /* Thread network has routing cost limit 16. */
00025 #ifndef MESH_DEFAULT_HOPS_LEFT
00026 #define MESH_DEFAULT_HOPS_LEFT 16
00027 #endif
00028 
00029 typedef struct mesh_routing_route_response_s {
00030     uint8_t addr_len;
00031     uint8_t address[8];
00032     bool intercept;
00033 } mesh_routing_route_response_t;
00034 
00035 typedef int_fast8_t mesh_first_hop_fn_t(protocol_interface_info_entry_t *cur,
00036                                         uint_fast8_t dest_addr_len, const uint8_t dest_addr[],
00037                                         mesh_routing_route_response_t *resp);
00038 typedef int_fast8_t mesh_route_fn_t(protocol_interface_info_entry_t *cur,
00039                                     uint_fast8_t last_hop_addr_len, const uint8_t last_hop_addr[],
00040                                     uint_fast8_t dest_addr_len, const uint8_t dest_addr[],
00041                                     mesh_routing_route_response_t *resp);
00042 typedef int_fast8_t mesh_multicast_fn_t(protocol_interface_info_entry_t *cur, uint16_t addr, buffer_t *buf);
00043 typedef bool mesh_header_needed_fn_t(const protocol_interface_info_entry_t *cur, const buffer_t *buf);
00044 typedef bool mesh_forwardable_address_t(const protocol_interface_info_entry_t *cur, addrtype_t addr_type, const uint8_t *addr);
00045 typedef bool mesh_address_map_fn_t(protocol_interface_info_entry_t *cur, addrtype_t *addr_type, uint8_t *addr);
00046 
00047 typedef struct mesh_callbacks_s {
00048     mesh_first_hop_fn_t *first_hop;
00049     mesh_route_fn_t *route;
00050     mesh_multicast_fn_t *multicast;
00051     mesh_header_needed_fn_t *header_needed;
00052     mesh_forwardable_address_t *forwardable_address;
00053     mesh_address_map_fn_t *address_map;
00054 } mesh_callbacks_t;
00055 
00056 #ifdef HAVE_MESH
00057 buffer_t *mesh_up(buffer_t *buf);
00058 buffer_t *mesh_down(buffer_t *buf);
00059 
00060 bool mesh_address_map(protocol_interface_info_entry_t *cur, addrtype_t *addr_type, uint8_t *addr);
00061 bool mesh_forwardable_address(const protocol_interface_info_entry_t *cur, addrtype_t addr_type, const uint8_t *addr);
00062 bool mesh_header_needed(const buffer_t *buf);
00063 bool mesh_supports_multicast(void);
00064 void mesh_all_addresses_unicast(bool flag);
00065 bool mesh_short_address_is_multicast(uint16_t addr);
00066 bool mesh_short_address_is_broadcast_or_multicast(uint16_t addr);
00067 void mesh_rewrite_bc0_header(uint8_t *header);
00068 uint_fast8_t mesh_header_size(const buffer_t *buf);
00069 uint_fast8_t mesh_header_len_from_type_byte(uint8_t type);
00070 uint_fast8_t mesh_header_len_from_buffer_type_byte(const buffer_t *buf);
00071 #else
00072 #define mesh_address_map(cur, addr_type, addr) true
00073 #define mesh_forwardable_address(cur, addr_type, addr) false
00074 #define mesh_header_needed(buf) false
00075 #define mesh_rewrite_bc0_header(header) ((void) 0)
00076 #define mesh_header_size(buf) false
00077 #define mesh_header_len_from_type_byte(type) 0
00078 #endif
00079 
00080 #ifdef __cplusplus
00081 }
00082 #endif
00083 
00084 #endif /* MESH_H_ */