13deb3ec6SMatthias Ringwald /* 23deb3ec6SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 33deb3ec6SMatthias Ringwald * 43deb3ec6SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 53deb3ec6SMatthias Ringwald * modification, are permitted provided that the following conditions 63deb3ec6SMatthias Ringwald * are met: 73deb3ec6SMatthias Ringwald * 83deb3ec6SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 93deb3ec6SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 103deb3ec6SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 113deb3ec6SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 123deb3ec6SMatthias Ringwald * documentation and/or other materials provided with the distribution. 133deb3ec6SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 143deb3ec6SMatthias Ringwald * contributors may be used to endorse or promote products derived 153deb3ec6SMatthias Ringwald * from this software without specific prior written permission. 163deb3ec6SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 173deb3ec6SMatthias Ringwald * personal benefit and not for any commercial purpose or for 183deb3ec6SMatthias Ringwald * monetary gain. 193deb3ec6SMatthias Ringwald * 203deb3ec6SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 213deb3ec6SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 223deb3ec6SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 233deb3ec6SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 243deb3ec6SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 253deb3ec6SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 263deb3ec6SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 273deb3ec6SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 283deb3ec6SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 293deb3ec6SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 303deb3ec6SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 313deb3ec6SMatthias Ringwald * SUCH DAMAGE. 323deb3ec6SMatthias Ringwald * 333deb3ec6SMatthias Ringwald * Please inquire about commercial licensing options at 343deb3ec6SMatthias Ringwald * [email protected] 353deb3ec6SMatthias Ringwald * 363deb3ec6SMatthias Ringwald */ 373deb3ec6SMatthias Ringwald #ifndef __ATT_SERVER_H 383deb3ec6SMatthias Ringwald #define __ATT_SERVER_H 393deb3ec6SMatthias Ringwald 403deb3ec6SMatthias Ringwald #include <stdint.h> 41591423b2SMatthias Ringwald #include "ble/att_db.h" 4213e6e052SMatthias Ringwald #include "btstack_defines.h" 433deb3ec6SMatthias Ringwald 443deb3ec6SMatthias Ringwald #if defined __cplusplus 453deb3ec6SMatthias Ringwald extern "C" { 463deb3ec6SMatthias Ringwald #endif 473deb3ec6SMatthias Ringwald 483deb3ec6SMatthias Ringwald /* API_START */ 493deb3ec6SMatthias Ringwald /* 503deb3ec6SMatthias Ringwald * @brief setup ATT server 513deb3ec6SMatthias Ringwald * @param db attribute database created by compile-gatt.ph 52591423b2SMatthias Ringwald * @param read_callback, see att_db.h, can be NULL 533deb3ec6SMatthias Ringwald * @param write_callback, see attl.h, can be NULL 543deb3ec6SMatthias Ringwald */ 553deb3ec6SMatthias Ringwald void att_server_init(uint8_t const * db, att_read_callback_t read_callback, att_write_callback_t write_callback); 563deb3ec6SMatthias Ringwald 573deb3ec6SMatthias Ringwald /* 58dc98f6d3SMatthias Ringwald * @brief register packet handler for ATT server events: 59bb38f057SMatthias Ringwald * - ATT_EVENT_CAN_SEND_NOW 60dc98f6d3SMatthias Ringwald * - ATT_EVENT_HANDLE_VALUE_INDICATION_COMPLETE 61bb38f057SMatthias Ringwald * - ATT_EVENT_MTU_EXCHANGE_COMPLETE 623deb3ec6SMatthias Ringwald * @param handler 633deb3ec6SMatthias Ringwald */ 643deb3ec6SMatthias Ringwald void att_server_register_packet_handler(btstack_packet_handler_t handler); 653deb3ec6SMatthias Ringwald 663d71c7a4SMatthias Ringwald /** 673d71c7a4SMatthias Ringwald * @brief register read/write callbacks for specific handle range 683d71c7a4SMatthias Ringwald * @param att_service_handler_t 693d71c7a4SMatthias Ringwald */ 703d71c7a4SMatthias Ringwald void att_server_register_service_handler(att_service_handler_t * handler); 713d71c7a4SMatthias Ringwald 72*cbbb12d9SMatthias Ringwald // the following functions will be removed soon 73*cbbb12d9SMatthias Ringwald 743deb3ec6SMatthias Ringwald /* 753deb3ec6SMatthias Ringwald * @brief tests if a notification or indication can be send right now 76c141988cSMatthias Ringwald * @param con_handle 773deb3ec6SMatthias Ringwald * @return 1, if packet can be sent 783deb3ec6SMatthias Ringwald */ 79c141988cSMatthias Ringwald int att_server_can_send_packet_now(hci_con_handle_t con_handle); 803deb3ec6SMatthias Ringwald 811b96b007SMatthias Ringwald /** 821b96b007SMatthias Ringwald * @brief Request emission of ATT_EVENT_CAN_SEND_NOW as soon as possible 831b96b007SMatthias Ringwald * @note ATT_EVENT_CAN_SEND_NOW might be emitted during call to this function 841b96b007SMatthias Ringwald * so packet handler should be ready to handle it 85c141988cSMatthias Ringwald * @param con_handle 861b96b007SMatthias Ringwald */ 87c141988cSMatthias Ringwald void att_server_request_can_send_now_event(hci_con_handle_t con_handle); 881b96b007SMatthias Ringwald 89bb38f057SMatthias Ringwald /** 90bb38f057SMatthias Ringwald * @brief Request callback when sending is possible 91bb38f057SMatthias Ringwald * @note callback might happend during call to this function 92bb38f057SMatthias Ringwald * @param callback_registration to point to callback function and context information 93bb38f057SMatthias Ringwald * @param con_handle 94969a5bbaSMatthias Ringwald * @return 0 if ok, error otherwise 95bb38f057SMatthias Ringwald */ 96969a5bbaSMatthias Ringwald int att_server_register_can_send_now_callback(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 97bb38f057SMatthias Ringwald 98*cbbb12d9SMatthias Ringwald // end of deprecated functions 99*cbbb12d9SMatthias Ringwald 100*cbbb12d9SMatthias Ringwald /** 101*cbbb12d9SMatthias Ringwald * @brief Request callback when sending notifcation is possible 102*cbbb12d9SMatthias Ringwald * @note callback might happend during call to this function 103*cbbb12d9SMatthias Ringwald * @param callback_registration to point to callback function and context information 104*cbbb12d9SMatthias Ringwald * @param con_handle 105*cbbb12d9SMatthias Ringwald * @return 0 if ok, error otherwise 106*cbbb12d9SMatthias Ringwald */ 107*cbbb12d9SMatthias Ringwald int att_server_request_to_send_notification(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 108*cbbb12d9SMatthias Ringwald 109*cbbb12d9SMatthias Ringwald /** 110*cbbb12d9SMatthias Ringwald * @brief Request callback when sending indication is possible 111*cbbb12d9SMatthias Ringwald * @note callback might happend during call to this function 112*cbbb12d9SMatthias Ringwald * @param callback_registration to point to callback function and context information 113*cbbb12d9SMatthias Ringwald * @param con_handle 114*cbbb12d9SMatthias Ringwald * @return 0 if ok, error otherwise 115*cbbb12d9SMatthias Ringwald */ 116*cbbb12d9SMatthias Ringwald int att_server_request_to_send_indication(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 117*cbbb12d9SMatthias Ringwald 1183deb3ec6SMatthias Ringwald /* 1193deb3ec6SMatthias Ringwald * @brief notify client about attribute value change 120c141988cSMatthias Ringwald * @param con_handle 121fc64f94aSMatthias Ringwald * @param attribute_handle 122fc64f94aSMatthias Ringwald * @param value 123fc64f94aSMatthias Ringwald * @param value_len 1243deb3ec6SMatthias Ringwald * @return 0 if ok, error otherwise 1253deb3ec6SMatthias Ringwald */ 126c141988cSMatthias Ringwald int att_server_notify(hci_con_handle_t con_handle, uint16_t attribute_handle, uint8_t *value, uint16_t value_len); 1273deb3ec6SMatthias Ringwald 1283deb3ec6SMatthias Ringwald /* 1293deb3ec6SMatthias Ringwald * @brief indicate value change to client. client is supposed to reply with an indication_response 130c141988cSMatthias Ringwald * @param con_handle 131fc64f94aSMatthias Ringwald * @param attribute_handle 132fc64f94aSMatthias Ringwald * @param value 133fc64f94aSMatthias Ringwald * @param value_len 1343deb3ec6SMatthias Ringwald * @return 0 if ok, error otherwise 1353deb3ec6SMatthias Ringwald */ 136c141988cSMatthias Ringwald int att_server_indicate(hci_con_handle_t con_handle, uint16_t attribute_handle, uint8_t *value, uint16_t value_len); 1373deb3ec6SMatthias Ringwald 138e404a688SMatthias Ringwald #ifdef ENABLE_ATT_DELAYED_READ_RESPONSE 139e404a688SMatthias Ringwald /* 140e404a688SMatthias Ringwald * @brief read response ready - called after returning ATT_READ_RESPONSE_PENDING in an att_read_callback before 141e404a688SMatthias Ringwald * @nore The ATT Server will retry handling the current ATT request 142e404a688SMatthias Ringwald * @param con_handle 143e404a688SMatthias Ringwald * @return 0 if ok, error otherwise 144e404a688SMatthias Ringwald */ 145e404a688SMatthias Ringwald int att_server_read_response_ready(hci_con_handle_t con_handle); 146e404a688SMatthias Ringwald #endif 147e404a688SMatthias Ringwald 1483deb3ec6SMatthias Ringwald /* API_END */ 1493deb3ec6SMatthias Ringwald 1503deb3ec6SMatthias Ringwald #if defined __cplusplus 1513deb3ec6SMatthias Ringwald } 1523deb3ec6SMatthias Ringwald #endif 1533deb3ec6SMatthias Ringwald 1543deb3ec6SMatthias Ringwald #endif // __ATT_SERVER_H 155