1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_BLE_HS_MBUF_ 21 #define H_BLE_HS_MBUF_ 22 23 /** 24 * @brief Bluetooth Host chained memory buffer (mbuf) 25 * @defgroup bt_host_mbuf Bluetooth Host chained memory buffer (mbuf) 26 * @ingroup bt_host 27 * @{ 28 */ 29 30 #include <inttypes.h> 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 struct os_mbuf; 36 37 /** 38 * Allocates an mbuf suitable for an ATT command packet. The resulting packet 39 * has sufficient leading space for: 40 * - ACL data header 41 * - L2CAP B-frame header 42 * - Largest ATT command base (prepare write request / response). 43 * 44 * @return An empty mbuf on success, NULLl on error. 45 */ 46 struct os_mbuf *ble_hs_mbuf_att_pkt(void); 47 48 /** 49 * Allocates an mbuf and fills it with the contents of the specified flat 50 * buffer. 51 * 52 * @param buf The flat buffer to copy from. 53 * @param len The length of the flat buffer. 54 * 55 * @return A newly-allocated mbuf on success, NULL on error. 56 */ 57 struct os_mbuf *ble_hs_mbuf_from_flat(const void *buf, uint16_t len); 58 59 /** 60 * Copies the contents of an mbuf into the specified flat buffer. If the flat 61 * buffer is too small to contain the mbuf's contents, it is filled to capacity 62 * and BLE_HS_EMSGSIZE is returned. 63 * 64 * @param om The mbuf to copy from. 65 * @param flat The destination flat buffer. 66 * @param max_len The size of the flat buffer. 67 * @param out_copy_len The number of bytes actually copied gets written here. 68 * 69 * @return 0 on success or BLE host core return code on error. 70 */ 71 int ble_hs_mbuf_to_flat(const struct os_mbuf *om, void *flat, uint16_t max_len, 72 uint16_t *out_copy_len); 73 74 #ifdef __cplusplus 75 } 76 #endif 77 78 /** 79 * @} 80 */ 81 82 #endif 83