1 /******************************************************************************
2 *
3 * Copyright 2004-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 data gateway call-in functions.
22 *
23 ******************************************************************************/
24
25 #include "bt_target.h" // Must be first to define build configuration
26
27 #include "bta/pan/bta_pan_int.h"
28 #include "osi/include/allocator.h"
29 #include "types/raw_address.h"
30
31 #if (BTA_PAN_INCLUDED == TRUE)
32
33 /*******************************************************************************
34 *
35 * Function bta_pan_ci_tx_ready
36 *
37 * Description This function sends an event to PAN indicating the phone is
38 * ready for more data and PAN should call
39 * bta_pan_co_tx_path().
40 * This function is used when the TX data path is configured
41 * to use a pull interface.
42 *
43 *
44 * Returns void
45 *
46 ******************************************************************************/
bta_pan_ci_tx_ready(uint16_t handle)47 void bta_pan_ci_tx_ready(uint16_t handle) {
48 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
49
50 p_buf->layer_specific = handle;
51 p_buf->event = BTA_PAN_CI_TX_READY_EVT;
52
53 bta_sys_sendmsg(p_buf);
54 }
55
56 /*******************************************************************************
57 *
58 * Function bta_pan_ci_rx_ready
59 *
60 * Description This function sends an event to PAN indicating the phone
61 * has data available to send to PAN and PAN should call
62 * bta_pan_co_rx_path(). This function is used when the RX
63 * data path is configured to use a pull interface.
64 *
65 *
66 * Returns void
67 *
68 ******************************************************************************/
bta_pan_ci_rx_ready(uint16_t handle)69 void bta_pan_ci_rx_ready(uint16_t handle) {
70 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
71
72 p_buf->layer_specific = handle;
73 p_buf->event = BTA_PAN_CI_RX_READY_EVT;
74
75 bta_sys_sendmsg(p_buf);
76 }
77
78 /*******************************************************************************
79 *
80 * Function bta_pan_ci_tx_flow
81 *
82 * Description This function is called to enable or disable data flow on
83 * the TX path. The phone should call this function to
84 * disable data flow when it is congested and cannot handle
85 * any more data sent by bta_pan_co_tx_write().
86 * This function is used when the
87 * TX data path is configured to use a push interface.
88 *
89 *
90 * Returns void
91 *
92 ******************************************************************************/
bta_pan_ci_tx_flow(uint16_t handle,bool enable)93 void bta_pan_ci_tx_flow(uint16_t handle, bool enable) {
94 tBTA_PAN_CI_TX_FLOW* p_buf =
95 (tBTA_PAN_CI_TX_FLOW*)osi_malloc(sizeof(tBTA_PAN_CI_TX_FLOW));
96
97 p_buf->hdr.layer_specific = handle;
98 p_buf->hdr.event = BTA_PAN_CI_TX_FLOW_EVT;
99 p_buf->enable = enable;
100
101 bta_sys_sendmsg(p_buf);
102 }
103
104 /*******************************************************************************
105 *
106 * Function bta_pan_ci_rx_write
107 *
108 * Description This function is called to send data to PAN when the RX path
109 * is configured to use a push interface. The function copies
110 * data to an event buffer and sends it to PAN.
111 *
112 *
113 * Returns void
114 *
115 ******************************************************************************/
bta_pan_ci_rx_write(uint16_t handle,const RawAddress & dst,const RawAddress & src,uint16_t protocol,uint8_t * p_data,uint16_t len,bool ext)116 void bta_pan_ci_rx_write(uint16_t handle, const RawAddress& dst,
117 const RawAddress& src, uint16_t protocol,
118 uint8_t* p_data, uint16_t len, bool ext) {
119 BT_HDR* p_buf = (BT_HDR*)osi_malloc(PAN_BUF_SIZE);
120
121 p_buf->offset = PAN_MINIMUM_OFFSET;
122
123 /* copy all other params before the data */
124 ((tBTA_PAN_DATA_PARAMS*)p_buf)->src = src;
125 ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst = dst;
126 ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol = protocol;
127 ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext = ext;
128 p_buf->len = len;
129
130 /* copy data */
131 memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, p_data, len);
132
133 p_buf->layer_specific = handle;
134 p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
135
136 bta_sys_sendmsg(p_buf);
137 }
138
139 /*******************************************************************************
140 *
141 * Function bta_pan_ci_rx_writebuf
142 *
143 * Description This function is called to send data to the phone when
144 * the RX path is configured to use a push interface with
145 * zero copy. The function sends an event to PAN containing
146 * the data buffer. The buffer will be freed by BTA; the
147 * phone must not free the buffer.
148 *
149 *
150 * Returns void
151 *
152 ******************************************************************************/
bta_pan_ci_rx_writebuf(uint16_t handle,const RawAddress & dst,const RawAddress & src,uint16_t protocol,BT_HDR * p_buf,bool ext)153 void bta_pan_ci_rx_writebuf(uint16_t handle, const RawAddress& dst,
154 const RawAddress& src, uint16_t protocol,
155 BT_HDR* p_buf, bool ext) {
156 /* copy all other params before the data */
157 ((tBTA_PAN_DATA_PARAMS*)p_buf)->src = src;
158 ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst = dst;
159 ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol = protocol;
160 ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext = ext;
161
162 p_buf->layer_specific = handle;
163 p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
164 bta_sys_sendmsg(p_buf);
165 }
166
167 /*******************************************************************************
168 *
169 * Function bta_pan_ci_readbuf
170 *
171 * Description
172 *
173 *
174 * Returns void
175 *
176 ******************************************************************************/
bta_pan_ci_readbuf(uint16_t handle,RawAddress & src,RawAddress & dst,uint16_t * p_protocol,bool * p_ext,bool * p_forward)177 BT_HDR* bta_pan_ci_readbuf(uint16_t handle, RawAddress& src, RawAddress& dst,
178 uint16_t* p_protocol, bool* p_ext, bool* p_forward) {
179 tBTA_PAN_SCB* p_scb = bta_pan_scb_by_handle(handle);
180 BT_HDR* p_buf;
181
182 if (p_scb == NULL) return NULL;
183
184 p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_scb->data_queue);
185 if (p_buf != NULL) {
186 src = ((tBTA_PAN_DATA_PARAMS*)p_buf)->src;
187 dst = ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst;
188 *p_protocol = ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol;
189 *p_ext = ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext;
190 *p_forward = ((tBTA_PAN_DATA_PARAMS*)p_buf)->forward;
191 }
192
193 return p_buf;
194 }
195
196 /*******************************************************************************
197 *
198 * Function bta_pan_ci_set_mfilters
199 *
200 * Description This function is called to set multicast filters
201 *
202 *
203 * Returns void
204 *
205 ******************************************************************************/
bta_pan_ci_set_mfilters(uint16_t handle,uint16_t num_mcast_filters,uint8_t * p_start_array,uint8_t * p_end_array)206 void bta_pan_ci_set_mfilters(uint16_t handle, uint16_t num_mcast_filters,
207 uint8_t* p_start_array, uint8_t* p_end_array) {
208 PAN_SetMulticastFilters(handle, num_mcast_filters, p_start_array,
209 p_end_array);
210 }
211
212 /*******************************************************************************
213 *
214 * Function bta_pan_ci_set_mfilters
215 *
216 * Description This function is called to set protocol filters
217 *
218 *
219 * Returns void
220 *
221 ******************************************************************************/
bta_pan_ci_set_pfilters(uint16_t handle,uint16_t num_filters,uint16_t * p_start_array,uint16_t * p_end_array)222 void bta_pan_ci_set_pfilters(uint16_t handle, uint16_t num_filters,
223 uint16_t* p_start_array, uint16_t* p_end_array) {
224 PAN_SetProtocolFilters(handle, num_filters, p_start_array, p_end_array);
225 }
226 #else
227 #include "osi/include/osi.h" // UNUSED_ATTR
228
bta_pan_ci_tx_ready(UNUSED_ATTR uint16_t handle)229 void bta_pan_ci_tx_ready(UNUSED_ATTR uint16_t handle) {}
230
bta_pan_ci_rx_ready(UNUSED_ATTR uint16_t handle)231 void bta_pan_ci_rx_ready(UNUSED_ATTR uint16_t handle) {}
232
bta_pan_ci_tx_flow(UNUSED_ATTR uint16_t handle,UNUSED_ATTR bool enable)233 void bta_pan_ci_tx_flow(UNUSED_ATTR uint16_t handle, UNUSED_ATTR bool enable) {}
234
bta_pan_ci_rx_writebuf(UNUSED_ATTR uint16_t handle,UNUSED_ATTR const RawAddress & src,UNUSED_ATTR const RawAddress & dst,UNUSED_ATTR uint16_t protocol,UNUSED_ATTR BT_HDR * p_buf,UNUSED_ATTR bool ext)235 void bta_pan_ci_rx_writebuf(UNUSED_ATTR uint16_t handle,
236 UNUSED_ATTR const RawAddress& src,
237 UNUSED_ATTR const RawAddress& dst,
238 UNUSED_ATTR uint16_t protocol,
239 UNUSED_ATTR BT_HDR* p_buf, UNUSED_ATTR bool ext) {}
240
bta_pan_ci_readbuf(UNUSED_ATTR uint16_t handle,UNUSED_ATTR RawAddress & src,UNUSED_ATTR RawAddress & dst,UNUSED_ATTR uint16_t * p_protocol,UNUSED_ATTR bool * p_ext,UNUSED_ATTR bool * p_forward)241 BT_HDR* bta_pan_ci_readbuf(UNUSED_ATTR uint16_t handle,
242 UNUSED_ATTR RawAddress& src,
243 UNUSED_ATTR RawAddress& dst,
244 UNUSED_ATTR uint16_t* p_protocol,
245 UNUSED_ATTR bool* p_ext,
246 UNUSED_ATTR bool* p_forward) {
247 return NULL;
248 }
249
bta_pan_ci_set_pfilters(UNUSED_ATTR uint16_t handle,UNUSED_ATTR uint16_t num_filters,UNUSED_ATTR uint16_t * p_start_array,UNUSED_ATTR uint16_t * p_end_array)250 void bta_pan_ci_set_pfilters(UNUSED_ATTR uint16_t handle,
251 UNUSED_ATTR uint16_t num_filters,
252 UNUSED_ATTR uint16_t* p_start_array,
253 UNUSED_ATTR uint16_t* p_end_array) {}
254
bta_pan_ci_set_mfilters(UNUSED_ATTR uint16_t handle,UNUSED_ATTR uint16_t num_mcast_filters,UNUSED_ATTR uint8_t * p_start_array,UNUSED_ATTR uint8_t * p_end_array)255 void bta_pan_ci_set_mfilters(UNUSED_ATTR uint16_t handle,
256 UNUSED_ATTR uint16_t num_mcast_filters,
257 UNUSED_ATTR uint8_t* p_start_array,
258 UNUSED_ATTR uint8_t* p_end_array) {}
259
260 #endif /* BTA_PAN_API */
261