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], const uint8_t* data, uintptr_t len); 36 void (*send_llcp_packet)(void* user, uint16_t handle, const uint8_t* data, uintptr_t len); 37 }; 38 39 extern "C" { 40 41 /// Create a new link manager instance 42 /// # Arguments 43 /// * `ops` - Function callbacks required by the link manager 44 const LinkManager* link_manager_create(ControllerOps ops); 45 46 /// Register a new link with a peer inside the link manager 47 /// # Arguments 48 /// * `lm` - link manager pointer 49 /// * `peer` - peer address as array of 6 bytes 50 /// # Safety 51 /// - This should be called from the thread of creation 52 /// - `lm` must be a valid pointer 53 /// - `peer` must be valid for reads for 6 bytes 54 bool link_manager_add_link(const LinkManager* lm, const uint8_t (*peer)[6]); 55 56 /// Unregister a link with a peer inside the link manager 57 /// Returns true if successful 58 /// # Arguments 59 /// * `lm` - link manager pointer 60 /// * `peer` - peer address as array of 6 bytes 61 /// # Safety 62 /// - This should be called from the thread of creation 63 /// - `lm` must be a valid pointer 64 /// - `peer` must be valid for reads for 6 bytes 65 bool link_manager_remove_link(const LinkManager* lm, const uint8_t (*peer)[6]); 66 67 /// Run the Link Manager procedures 68 /// # Arguments 69 /// * `lm` - link manager pointer 70 /// # Safety 71 /// - This should be called from the thread of creation 72 /// - `lm` must be a valid pointer 73 void link_manager_tick(const LinkManager* lm); 74 75 /// Process an HCI packet with the link manager 76 /// Returns true if successful 77 /// # Arguments 78 /// * `lm` - link manager pointer 79 /// * `data` - HCI packet data 80 /// * `len` - HCI packet len 81 /// # Safety 82 /// - This should be called from the thread of creation 83 /// - `lm` must be a valid pointer 84 /// - `data` must be valid for reads of len `len` 85 bool link_manager_ingest_hci(const LinkManager* lm, const uint8_t* data, uintptr_t len); 86 87 /// Process an LMP packet from a peer with the link manager 88 /// Returns true if successful 89 /// # Arguments 90 /// * `lm` - link manager pointer 91 /// * `from` - Address of peer as array of 6 bytes 92 /// * `data` - HCI packet data 93 /// * `len` - HCI packet len 94 /// # Safety 95 /// - This should be called from the thread of creation 96 /// - `lm` must be a valid pointers 97 /// - `from` must be valid pointer for reads for 6 bytes 98 /// - `data` must be valid for reads of len `len` 99 bool link_manager_ingest_lmp(const LinkManager* lm, const uint8_t (*from)[6], const uint8_t* data, 100 uintptr_t len); 101 102 /// Deallocate the link manager instance 103 /// # Arguments 104 /// * `lm` - link manager pointer 105 /// # Safety 106 /// - This should be called from the thread of creation 107 /// - `lm` must be a valid pointers and must not be reused afterwards 108 void link_manager_destroy(const LinkManager* lm); 109 110 /// Create a new link manager instance 111 /// # Arguments 112 /// * `ops` - Function callbacks required by the link manager 113 const LinkLayer* link_layer_create(ControllerOps ops); 114 115 /// Register a new link with a peer inside the link layer 116 /// # Arguments 117 /// * `ll` - link layer pointer 118 /// * `handle` - connection handle for the link 119 /// * `peer_address` - peer address as array of 6 bytes 120 /// * `role` - connection role (peripheral or centrl) for the link 121 /// # Safety 122 /// - This should be called from the thread of creation 123 /// - `ll` must be a valid pointer 124 /// - `peer` must be valid for reads for 6 bytes 125 /// - `role` must be 0 (central) or 1 (peripheral) 126 bool link_layer_add_link(const LinkLayer* ll, uint16_t handle, const uint8_t (*peer_address)[6], 127 uint8_t role); 128 129 /// Unregister a link with a peer inside the link layer 130 /// Returns true if successful 131 /// # Arguments 132 /// * `ll` - link layer pointer 133 /// * `peer` - peer address as array of 6 bytes 134 /// # Safety 135 /// - This should be called from the thread of creation 136 /// - `ll` must be a valid pointer 137 /// - `peer` must be valid for reads for 6 bytes 138 bool link_layer_remove_link(const LinkLayer* ll, uint16_t handle); 139 140 /// Run the Link Manager procedures 141 /// # Arguments 142 /// * `ll` - link layer pointer 143 /// # Safety 144 /// - This should be called from the thread of creation 145 /// - `ll` must be a valid pointer 146 void link_layer_tick(const LinkLayer* ll); 147 148 /// Process an HCI packet with the link layer 149 /// Returns true if successful 150 /// # Arguments 151 /// * `ll` - link layer pointer 152 /// * `data` - HCI packet data 153 /// * `len` - HCI packet len 154 /// # Safety 155 /// - This should be called from the thread of creation 156 /// - `ll` must be a valid pointer 157 /// - `data` must be valid for reads of len `len` 158 bool link_layer_ingest_hci(const LinkLayer* ll, const uint8_t* data, uintptr_t len); 159 160 /// Process an LLCP packet from a peer with the link layer 161 /// Returns true if successful 162 /// # Arguments 163 /// * `ll` - link layer pointer 164 /// * `handle` - ACL handle of the connection 165 /// * `data` - HCI packet data 166 /// * `len` - HCI packet len 167 /// # Safety 168 /// - This should be called from the thread of creation 169 /// - `ll` must be a valid pointers 170 /// - `data` must be valid for reads of len `len` 171 bool link_layer_ingest_llcp(const LinkLayer* ll, uint16_t handle, const uint8_t* data, 172 uintptr_t len); 173 174 /// Query the connection handle for a CIS established with 175 /// the input CIS and CIG identifiers. 176 /// Returns true if successful 177 /// # Arguments 178 /// * `ll` - link layer pointer 179 /// * `cig_id` - Identifier of the established Cig 180 /// * `cis_id` - Identifier of the established Cis 181 /// * `cis_connection_handle` - Returns the handle of the CIS if connected 182 /// # Safety 183 /// - This should be called from the thread of creation 184 /// - `ll` must be a valid pointers 185 bool link_layer_get_cis_connection_handle(const LinkLayer* ll, uint8_t cig_id, uint8_t cis_id, 186 uint16_t* cis_connection_handle); 187 188 /// Query the CIS and CIG identifiers for a CIS established with 189 /// the input CIS connection handle. 190 /// Returns true if successful 191 /// # Arguments 192 /// * `ll` - link layer pointer 193 /// * `cis_connection_handle` - CIS connection handle 194 /// * `cig_id` - Returns the CIG identifier 195 /// * `cis_id` - Returns the CIS identifier 196 /// # Safety 197 /// - This should be called from the thread of creation 198 /// - `ll` must be a valid pointers 199 bool link_layer_get_cis_information(const LinkLayer* ll, uint16_t cis_connection_handle, 200 uint16_t* acl_connection_handle, uint8_t* cig_id, 201 uint8_t* cis_id, uint16_t* max_sdu_tx); 202 203 /// Deallocate the link layer instance 204 /// # Arguments 205 /// * `ll` - link layer pointer 206 /// # Safety 207 /// - This should be called from the thread of creation 208 /// - `ll` must be a valid pointers and must not be reused afterwards 209 void link_layer_destroy(const LinkLayer* ll); 210 211 } // extern "C" 212