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 "common/bt_target.h"
26
27 #if defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE)
28
29 #include <string.h>
30
31 #include "bta/bta_api.h"
32 #include "bta/bta_sys.h"
33 #include "bta/bta_gattc_ci.h"
34 #include "bta/utl.h"
35 #include "osi/allocator.h"
36
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 *******************************************************************************/
bta_gattc_ci_cache_open(BD_ADDR server_bda,UINT16 evt,tBTA_GATT_STATUS status,UINT16 conn_id)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 *) osi_malloc(sizeof(tBTA_GATTC_CI_EVT))) != NULL) {
59 p_evt->hdr.event = evt;
60 p_evt->hdr.layer_specific = conn_id;
61
62 p_evt->status = status;
63 bta_sys_sendmsg(p_evt);
64 }
65 }
66
67 /*******************************************************************************
68 **
69 ** Function bta_gattc_ci_cache_load
70 **
71 ** Description This function sends an event to BTA indicating the phone has
72 ** load the servere cache and ready to send it to the stack.
73 **
74 ** Parameters server_bda - server BDA of this cache.
75 ** num_bytes_read - number of bytes read into the buffer
76 ** specified in the read callout-function.
77 ** status - BTA_GATT_OK if full buffer of data,
78 ** BTA_GATT_FAIL if an error has occurred.
79 **
80 ** Returns void
81 **
82 *******************************************************************************/
bta_gattc_ci_cache_load(BD_ADDR server_bda,UINT16 evt,UINT16 num_attr,tBTA_GATTC_NV_ATTR * p_attr,tBTA_GATT_STATUS status,UINT16 conn_id)83 void bta_gattc_ci_cache_load(BD_ADDR server_bda, UINT16 evt, UINT16 num_attr,
84 tBTA_GATTC_NV_ATTR *p_attr, tBTA_GATT_STATUS status,
85 UINT16 conn_id)
86 {
87 tBTA_GATTC_CI_LOAD *p_evt;
88 UNUSED(server_bda);
89
90 if ((p_evt = (tBTA_GATTC_CI_LOAD *) osi_malloc(sizeof(tBTA_GATTC_CI_LOAD))) != NULL) {
91 memset(p_evt, 0, sizeof(tBTA_GATTC_CI_LOAD));
92
93 p_evt->hdr.event = evt;
94 p_evt->hdr.layer_specific = conn_id;
95
96 p_evt->status = status;
97 p_evt->num_attr = (num_attr > BTA_GATTC_NV_LOAD_MAX) ? BTA_GATTC_NV_LOAD_MAX : num_attr;
98
99 if (p_evt->num_attr > 0 && p_attr != NULL) {
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 *******************************************************************************/
bta_gattc_ci_cache_save(BD_ADDR server_bda,UINT16 evt,tBTA_GATT_STATUS status,UINT16 conn_id)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 UNUSED(server_bda);
128
129 if ((p_evt = (tBTA_GATTC_CI_EVT *) osi_malloc(sizeof(tBTA_GATTC_CI_EVT))) != NULL) {
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 /* GATTC_INCLUDED */
138