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 37 /******************************************************************************* 38 ** 39 ** Function bta_gattc_ci_cache_open 40 ** 41 ** Description This function sends an event to indicate server cache open 42 ** completed. 43 ** 44 ** Parameters server_bda - server BDA of this cache. 45 ** status - BTA_GATT_OK if full buffer of data, 46 ** BTA_GATT_FAIL if an error has occurred. 47 ** 48 ** Returns void 49 ** 50 *******************************************************************************/ 51 void bta_gattc_ci_cache_open(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS status, 52 UINT16 conn_id) 53 { 54 tBTA_GATTC_CI_EVT *p_evt; 55 56 if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL) 57 { 58 p_evt->hdr.event = evt; 59 p_evt->hdr.layer_specific = conn_id; 60 61 p_evt->status = status; 62 bta_sys_sendmsg(p_evt); 63 } 64 } 65 66 /******************************************************************************* 67 ** 68 ** Function bta_gattc_ci_cache_load 69 ** 70 ** Description This function sends an event to BTA indicating the phone has 71 ** load the servere cache and ready to send it to the stack. 72 ** 73 ** Parameters server_bda - server BDA of this cache. 74 ** num_bytes_read - number of bytes read into the buffer 75 ** specified in the read callout-function. 76 ** status - BTA_GATT_OK if full buffer of data, 77 ** BTA_GATT_FAIL if an error has occurred. 78 ** 79 ** Returns void 80 ** 81 *******************************************************************************/ 82 void bta_gattc_ci_cache_load(BD_ADDR server_bda, UINT16 evt, UINT16 num_attr, 83 tBTA_GATTC_NV_ATTR *p_attr, tBTA_GATT_STATUS status, 84 UINT16 conn_id) 85 { 86 tBTA_GATTC_CI_LOAD *p_evt; 87 88 if ((p_evt = (tBTA_GATTC_CI_LOAD *) GKI_getbuf(sizeof(tBTA_GATTC_CI_LOAD))) != NULL) 89 { 90 memset(p_evt, 0, sizeof(tBTA_GATTC_CI_LOAD)); 91 92 p_evt->hdr.event = evt; 93 p_evt->hdr.layer_specific = conn_id; 94 95 p_evt->status = status; 96 p_evt->num_attr = (num_attr > BTA_GATTC_NV_LOAD_MAX) ? BTA_GATTC_NV_LOAD_MAX : num_attr; 97 98 if (p_evt->num_attr > 0 && p_attr != NULL) 99 { 100 memcpy(p_evt->attr, p_attr, p_evt->num_attr * sizeof(tBTA_GATTC_NV_ATTR)); 101 } 102 103 bta_sys_sendmsg(p_evt); 104 } 105 } 106 107 /******************************************************************************* 108 ** 109 ** Function bta_gattc_ci_cache_save 110 ** 111 ** Description This function sends an event to BTA indicating the phone has 112 ** save the servere cache. 113 ** 114 ** Parameters server_bda - server BDA of this cache. 115 ** evt - callin event code. 116 ** status - BTA_GATT_OK if full buffer of data, 117 ** BTA_GATT_ERROR if an error has occurred. 118 *8 conn_id - for this NV operation for. 119 ** 120 ** Returns void 121 ** 122 *******************************************************************************/ 123 void bta_gattc_ci_cache_save(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS status, 124 UINT16 conn_id) 125 { 126 tBTA_GATTC_CI_EVT *p_evt; 127 128 if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL) 129 { 130 p_evt->hdr.event = evt; 131 p_evt->hdr.layer_specific = conn_id; 132 133 p_evt->status = status; 134 bta_sys_sendmsg(p_evt); 135 } 136 } 137 #endif /* BTA_GATT_INCLUDED */ 138