1 /****************************************************************************** 2 * 3 * Copyright (C) 2010-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * 21 * This is the implementation file for the GATT call-in functions. 22 * 23 ******************************************************************************/ 24 25 #include "bt_target.h" 26 27 #if defined(BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE) 28 29 #include <string.h> 30 31 #include "bta_api.h" 32 #include "bta_sys.h" 33 #include "bta_gattc_ci.h" 34 #include "gki.h" 35 #include "bd.h" 36 #include "utl.h" 37 38 /******************************************************************************* 39 ** 40 ** Function bta_gattc_ci_cache_open 41 ** 42 ** Description This function sends an event to indicate server cache open 43 ** completed. 44 ** 45 ** Parameters server_bda - server BDA of this cache. 46 ** status - BTA_GATT_OK if full buffer of data, 47 ** BTA_GATT_FAIL if an error has occurred. 48 ** 49 ** Returns void 50 ** 51 *******************************************************************************/ 52 void bta_gattc_ci_cache_open(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS status, 53 UINT16 conn_id) 54 { 55 tBTA_GATTC_CI_EVT *p_evt; 56 UNUSED(server_bda); 57 58 if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL) 59 { 60 p_evt->hdr.event = evt; 61 p_evt->hdr.layer_specific = conn_id; 62 63 p_evt->status = status; 64 bta_sys_sendmsg(p_evt); 65 } 66 } 67 68 /******************************************************************************* 69 ** 70 ** Function bta_gattc_ci_cache_load 71 ** 72 ** Description This function sends an event to BTA indicating the phone has 73 ** load the servere cache and ready to send it to the stack. 74 ** 75 ** Parameters server_bda - server BDA of this cache. 76 ** num_bytes_read - number of bytes read into the buffer 77 ** specified in the read callout-function. 78 ** status - BTA_GATT_OK if full buffer of data, 79 ** BTA_GATT_FAIL if an error has occurred. 80 ** 81 ** Returns void 82 ** 83 *******************************************************************************/ 84 void bta_gattc_ci_cache_load(BD_ADDR server_bda, UINT16 evt, UINT16 num_attr, 85 tBTA_GATTC_NV_ATTR *p_attr, tBTA_GATT_STATUS status, 86 UINT16 conn_id) 87 { 88 tBTA_GATTC_CI_LOAD *p_evt; 89 UNUSED(server_bda); 90 91 if ((p_evt = (tBTA_GATTC_CI_LOAD *) GKI_getbuf(sizeof(tBTA_GATTC_CI_LOAD))) != NULL) 92 { 93 memset(p_evt, 0, sizeof(tBTA_GATTC_CI_LOAD)); 94 95 p_evt->hdr.event = evt; 96 p_evt->hdr.layer_specific = conn_id; 97 98 p_evt->status = status; 99 p_evt->num_attr = (num_attr > BTA_GATTC_NV_LOAD_MAX) ? BTA_GATTC_NV_LOAD_MAX : num_attr; 100 101 if (p_evt->num_attr > 0 && p_attr != NULL) 102 { 103 memcpy(p_evt->attr, p_attr, p_evt->num_attr * sizeof(tBTA_GATTC_NV_ATTR)); 104 } 105 106 bta_sys_sendmsg(p_evt); 107 } 108 } 109 110 /******************************************************************************* 111 ** 112 ** Function bta_gattc_ci_cache_save 113 ** 114 ** Description This function sends an event to BTA indicating the phone has 115 ** save the servere cache. 116 ** 117 ** Parameters server_bda - server BDA of this cache. 118 ** evt - callin event code. 119 ** status - BTA_GATT_OK if full buffer of data, 120 ** BTA_GATT_ERROR if an error has occurred. 121 *8 conn_id - for this NV operation for. 122 ** 123 ** Returns void 124 ** 125 *******************************************************************************/ 126 void bta_gattc_ci_cache_save(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS status, 127 UINT16 conn_id) 128 { 129 tBTA_GATTC_CI_EVT *p_evt; 130 UNUSED(server_bda); 131 132 if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL) 133 { 134 p_evt->hdr.event = evt; 135 p_evt->hdr.layer_specific = conn_id; 136 137 p_evt->status = status; 138 bta_sys_sendmsg(p_evt); 139 } 140 } 141 #endif /* BTA_GATT_INCLUDED */ 142