1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 // This file is autogenerated by: 18 // cbindgen --config cbindgen.toml src/ffi.rs -o include/rootcanal_rs.h 19 // Don't modify manually. 20 21 struct LinkManager; 22 struct LinkLayer; 23 24 #include <stdint.h> 25 26 /// Link Manager callbacks 27 struct ControllerOps { 28 void* user_pointer; 29 uint16_t (*get_handle)(void* user, const uint8_t (*address)[6]); 30 void (*get_address)(void* user, uint16_t handle, uint8_t (*result)[6]); 31 uint64_t (*get_extended_features)(void* user, uint8_t features_page); 32 uint64_t (*get_le_features)(void* user); 33 uint64_t (*get_le_event_mask)(void* user); 34 void (*send_hci_event)(void* user, const uint8_t* data, uintptr_t len); 35 void (*send_lmp_packet)(void* user, const uint8_t (*to)[6], 36 const uint8_t* data, uintptr_t len); 37 void (*send_llcp_packet)(void* user, uint16_t handle, const uint8_t* data, 38 uintptr_t len); 39 }; 40 41 extern "C" { 42 43 /// Create a new link manager instance 44 /// # Arguments 45 /// * `ops` - Function callbacks required by the link manager 46 const LinkManager* link_manager_create(ControllerOps ops); 47 48 /// Register a new link with a peer inside the link manager 49 /// # Arguments 50 /// * `lm` - link manager pointer 51 /// * `peer` - peer address as array of 6 bytes 52 /// # Safety 53 /// - This should be called from the thread of creation 54 /// - `lm` must be a valid pointer 55 /// - `peer` must be valid for reads for 6 bytes 56 bool link_manager_add_link(const LinkManager* lm, const uint8_t (*peer)[6]); 57 58 /// Unregister a link with a peer inside the link manager 59 /// Returns true if successful 60 /// # Arguments 61 /// * `lm` - link manager pointer 62 /// * `peer` - peer address as array of 6 bytes 63 /// # Safety 64 /// - This should be called from the thread of creation 65 /// - `lm` must be a valid pointer 66 /// - `peer` must be valid for reads for 6 bytes 67 bool link_manager_remove_link(const LinkManager* lm, const uint8_t (*peer)[6]); 68 69 /// Run the Link Manager procedures 70 /// # Arguments 71 /// * `lm` - link manager pointer 72 /// # Safety 73 /// - This should be called from the thread of creation 74 /// - `lm` must be a valid pointer 75 void link_manager_tick(const LinkManager* lm); 76 77 /// Process an HCI packet with the link manager 78 /// Returns true if successful 79 /// # Arguments 80 /// * `lm` - link manager pointer 81 /// * `data` - HCI packet data 82 /// * `len` - HCI packet len 83 /// # Safety 84 /// - This should be called from the thread of creation 85 /// - `lm` must be a valid pointer 86 /// - `data` must be valid for reads of len `len` 87 bool link_manager_ingest_hci(const LinkManager* lm, const uint8_t* data, 88 uintptr_t len); 89 90 /// Process an LMP packet from a peer with the link manager 91 /// Returns true if successful 92 /// # Arguments 93 /// * `lm` - link manager pointer 94 /// * `from` - Address of peer as array of 6 bytes 95 /// * `data` - HCI packet data 96 /// * `len` - HCI packet len 97 /// # Safety 98 /// - This should be called from the thread of creation 99 /// - `lm` must be a valid pointers 100 /// - `from` must be valid pointer for reads for 6 bytes 101 /// - `data` must be valid for reads of len `len` 102 bool link_manager_ingest_lmp(const LinkManager* lm, const uint8_t (*from)[6], 103 const uint8_t* data, uintptr_t len); 104 105 /// Deallocate the link manager instance 106 /// # Arguments 107 /// * `lm` - link manager pointer 108 /// # Safety 109 /// - This should be called from the thread of creation 110 /// - `lm` must be a valid pointers and must not be reused afterwards 111 void link_manager_destroy(const LinkManager* lm); 112 113 /// Create a new link manager instance 114 /// # Arguments 115 /// * `ops` - Function callbacks required by the link manager 116 const LinkLayer* link_layer_create(ControllerOps ops); 117 118 /// Register a new link with a peer inside the link layer 119 /// # Arguments 120 /// * `ll` - link layer pointer 121 /// * `handle` - connection handle for the link 122 /// * `peer_address` - peer address as array of 6 bytes 123 /// * `role` - connection role (peripheral or centrl) for the link 124 /// # Safety 125 /// - This should be called from the thread of creation 126 /// - `ll` must be a valid pointer 127 /// - `peer` must be valid for reads for 6 bytes 128 /// - `role` must be 0 (central) or 1 (peripheral) 129 bool link_layer_add_link(const LinkLayer* ll, uint16_t handle, 130 const uint8_t (*peer_address)[6], uint8_t role); 131 132 /// Unregister a link with a peer inside the link layer 133 /// Returns true if successful 134 /// # Arguments 135 /// * `ll` - link layer pointer 136 /// * `peer` - peer address as array of 6 bytes 137 /// # Safety 138 /// - This should be called from the thread of creation 139 /// - `ll` must be a valid pointer 140 /// - `peer` must be valid for reads for 6 bytes 141 bool link_layer_remove_link(const LinkLayer* ll, uint16_t handle); 142 143 /// Run the Link Manager procedures 144 /// # Arguments 145 /// * `ll` - link layer pointer 146 /// # Safety 147 /// - This should be called from the thread of creation 148 /// - `ll` must be a valid pointer 149 void link_layer_tick(const LinkLayer* ll); 150 151 /// Process an HCI packet with the link layer 152 /// Returns true if successful 153 /// # Arguments 154 /// * `ll` - link layer pointer 155 /// * `data` - HCI packet data 156 /// * `len` - HCI packet len 157 /// # Safety 158 /// - This should be called from the thread of creation 159 /// - `ll` must be a valid pointer 160 /// - `data` must be valid for reads of len `len` 161 bool link_layer_ingest_hci(const LinkLayer* ll, const uint8_t* data, 162 uintptr_t len); 163 164 /// Process an LLCP packet from a peer with the link layer 165 /// Returns true if successful 166 /// # Arguments 167 /// * `ll` - link layer pointer 168 /// * `handle` - ACL handle of the connection 169 /// * `data` - HCI packet data 170 /// * `len` - HCI packet len 171 /// # Safety 172 /// - This should be called from the thread of creation 173 /// - `ll` must be a valid pointers 174 /// - `data` must be valid for reads of len `len` 175 bool link_layer_ingest_llcp(const LinkLayer* ll, uint16_t handle, 176 const uint8_t* data, uintptr_t len); 177 178 /// Query the connection handle for a CIS established with 179 /// the input CIS and CIG identifiers. 180 /// Returns true if successful 181 /// # Arguments 182 /// * `ll` - link layer pointer 183 /// * `cig_id` - Identifier of the established Cig 184 /// * `cis_id` - Identifier of the established Cis 185 /// * `cis_connection_handle` - Returns the handle of the CIS if connected 186 /// # Safety 187 /// - This should be called from the thread of creation 188 /// - `ll` must be a valid pointers 189 bool link_layer_get_cis_connection_handle(const LinkLayer* ll, uint8_t cig_id, 190 uint8_t cis_id, 191 uint16_t* cis_connection_handle); 192 193 /// Query the CIS and CIG identifiers for a CIS established with 194 /// the input CIS connection handle. 195 /// Returns true if successful 196 /// # Arguments 197 /// * `ll` - link layer pointer 198 /// * `cis_connection_handle` - CIS connection handle 199 /// * `cig_id` - Returns the CIG identifier 200 /// * `cis_id` - Returns the CIS identifier 201 /// # Safety 202 /// - This should be called from the thread of creation 203 /// - `ll` must be a valid pointers 204 bool link_layer_get_cis_information(const LinkLayer* ll, 205 uint16_t cis_connection_handle, 206 uint16_t* acl_connection_handle, 207 uint8_t* cig_id, uint8_t* cis_id, 208 uint16_t* max_sdu_tx); 209 210 /// Deallocate the link layer instance 211 /// # Arguments 212 /// * `ll` - link layer pointer 213 /// # Safety 214 /// - This should be called from the thread of creation 215 /// - `ll` must be a valid pointers and must not be reused afterwards 216 void link_layer_destroy(const LinkLayer* ll); 217 218 } // extern "C" 219