1/******************************************************************************
2 *
3 *  Copyright (C) 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"
26
27#include <string.h>
28
29#include "gki.h"
30#include "pan_api.h"
31#include "bta_api.h"
32#include "bta_pan_api.h"
33#include "bta_pan_ci.h"
34#include "bta_pan_int.h"
35#include "bt_utils.h"
36
37#if defined(BTA_PAN_INCLUDED) && (BTA_PAN_INCLUDED == TRUE)
38
39/*******************************************************************************
40**
41** Function         bta_pan_ci_tx_ready
42**
43** Description      This function sends an event to PAN indicating the phone is
44**                  ready for more data and PAN should call bta_pan_co_tx_path().
45**                  This function is used when the TX data path is configured
46**                  to use a pull interface.
47**
48**
49** Returns          void
50**
51*******************************************************************************/
52void bta_pan_ci_tx_ready(UINT16 handle)
53{
54    BT_HDR  *p_buf;
55
56    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
57    {
58        p_buf->layer_specific = handle;
59        p_buf->event = BTA_PAN_CI_TX_READY_EVT;
60        bta_sys_sendmsg(p_buf);
61    }
62}
63
64/*******************************************************************************
65**
66** Function         bta_pan_ci_rx_ready
67**
68** Description      This function sends an event to PAN indicating the phone
69**                  has data available to send to PAN and PAN should call
70**                  bta_pan_co_rx_path().  This function is used when the RX
71**                  data path is configured to use a pull interface.
72**
73**
74** Returns          void
75**
76*******************************************************************************/
77void bta_pan_ci_rx_ready(UINT16 handle)
78{
79    BT_HDR  *p_buf;
80
81    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
82    {
83        p_buf->layer_specific = handle;
84        p_buf->event = BTA_PAN_CI_RX_READY_EVT;
85        bta_sys_sendmsg(p_buf);
86    }
87}
88
89/*******************************************************************************
90**
91** Function         bta_pan_ci_tx_flow
92**
93** Description      This function is called to enable or disable data flow on
94**                  the TX path.  The phone should call this function to
95**                  disable data flow when it is congested and cannot handle
96**                  any more data sent by bta_pan_co_tx_write() or
97**                  bta_pan_co_tx_writebuf().  This function is used when the
98**                  TX data path is configured to use a push interface.
99**
100**
101** Returns          void
102**
103*******************************************************************************/
104void bta_pan_ci_tx_flow(UINT16 handle, BOOLEAN enable)
105{
106    tBTA_PAN_CI_TX_FLOW  *p_buf;
107
108    if ((p_buf = (tBTA_PAN_CI_TX_FLOW *) GKI_getbuf(sizeof(tBTA_PAN_CI_TX_FLOW))) != NULL)
109    {
110        p_buf->hdr.layer_specific = handle;
111        p_buf->hdr.event = BTA_PAN_CI_TX_FLOW_EVT;
112        p_buf->enable = enable;
113        bta_sys_sendmsg(p_buf);
114    }
115}
116
117/*******************************************************************************
118**
119** Function         bta_pan_ci_rx_write
120**
121** Description      This function is called to send data to PAN when the RX path
122**                  is configured to use a push interface.  The function copies
123**                  data to an event buffer and sends it to PAN.
124**
125**
126** Returns          void
127**
128*******************************************************************************/
129void bta_pan_ci_rx_write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol,
130                            UINT8 *p_data, UINT16 len, BOOLEAN ext)
131{
132    BT_HDR * p_buf;
133
134    if((p_buf = (BT_HDR *) GKI_getpoolbuf(PAN_POOL_ID)) != NULL)
135    {
136
137
138        p_buf->offset = PAN_MINIMUM_OFFSET;
139
140        /* copy all other params before the data */
141        bdcpy(((tBTA_PAN_DATA_PARAMS *)p_buf)->src, src);
142        bdcpy(((tBTA_PAN_DATA_PARAMS *)p_buf)->dst, dst);
143        ((tBTA_PAN_DATA_PARAMS *)p_buf)->protocol = protocol;
144        ((tBTA_PAN_DATA_PARAMS *)p_buf)->ext = ext;
145        p_buf->len=len;
146
147        /* copy data */
148        memcpy((UINT8 *)(p_buf + 1) + p_buf->offset, p_data, len);
149
150        p_buf->layer_specific = handle;
151        p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
152        bta_sys_sendmsg(p_buf);
153    }
154
155}
156
157/*******************************************************************************
158**
159** Function         bta_pan_ci_rx_writebuf
160**
161** Description      This function is called to send data to the phone when
162**                  the RX path is configured to use a push interface with
163**                  zero copy.  The function sends an event to PAN containing
164**                  the data buffer.  The buffer must be allocated using
165**                  functions GKI_getbuf() or GKI_getpoolbuf().  The buffer
166**                  will be freed by BTA; the phone must not free the buffer.
167**
168**
169** Returns          void
170**
171*******************************************************************************/
172void bta_pan_ci_rx_writebuf(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol,
173                            BT_HDR *p_buf, BOOLEAN ext)
174{
175
176    /* copy all other params before the data */
177    bdcpy(((tBTA_PAN_DATA_PARAMS *)p_buf)->src, src);
178    bdcpy(((tBTA_PAN_DATA_PARAMS *)p_buf)->dst, dst);
179    ((tBTA_PAN_DATA_PARAMS *)p_buf)->protocol = protocol;
180    ((tBTA_PAN_DATA_PARAMS *)p_buf)->ext = ext;
181
182    p_buf->layer_specific = handle;
183    p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
184    bta_sys_sendmsg(p_buf);
185}
186
187
188
189
190/*******************************************************************************
191**
192** Function         bta_pan_ci_readbuf
193**
194** Description
195**
196**
197** Returns          void
198**
199*******************************************************************************/
200BT_HDR * bta_pan_ci_readbuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16* p_protocol,
201                                 BOOLEAN* p_ext, BOOLEAN* p_forward)
202{
203    tBTA_PAN_SCB * p_scb;
204    BT_HDR * p_buf;
205
206    p_scb = bta_pan_scb_by_handle(handle);
207
208    p_buf =  (BT_HDR *)GKI_dequeue(&p_scb->data_queue);
209
210    if(p_buf)
211    {
212        bdcpy(src,((tBTA_PAN_DATA_PARAMS *)p_buf)->src);
213        bdcpy(dst,((tBTA_PAN_DATA_PARAMS *)p_buf)->dst);
214        *p_protocol = ((tBTA_PAN_DATA_PARAMS *)p_buf)->protocol;
215        *p_ext = ((tBTA_PAN_DATA_PARAMS *)p_buf)->ext;
216        *p_forward = ((tBTA_PAN_DATA_PARAMS *)p_buf)->forward;
217    }
218
219    return p_buf;
220}
221
222
223/*******************************************************************************
224**
225** Function         bta_pan_ci_set_mfilters
226**
227** Description      This function is called to set multicast filters
228**
229**
230** Returns          void
231**
232*******************************************************************************/
233void bta_pan_ci_set_mfilters(UINT16 handle, UINT16 num_mcast_filters, UINT8 *p_start_array,
234                                                    UINT8 *p_end_array)
235{
236
237    PAN_SetMulticastFilters(handle, num_mcast_filters, p_start_array, p_end_array);
238
239}
240
241
242/*******************************************************************************
243**
244** Function         bta_pan_ci_set_mfilters
245**
246** Description      This function is called to set protocol filters
247**
248**
249** Returns          void
250**
251*******************************************************************************/
252void bta_pan_ci_set_pfilters(UINT16 handle, UINT16 num_filters, UINT16 *p_start_array, UINT16 *p_end_array)
253{
254
255    PAN_SetProtocolFilters(handle, num_filters, p_start_array, p_end_array );
256
257}
258#else
259
260void bta_pan_ci_tx_ready(UINT16 handle)
261{
262    UNUSED(handle);
263}
264
265void bta_pan_ci_rx_ready(UINT16 handle)
266{
267    UNUSED(handle);
268}
269
270void bta_pan_ci_tx_flow(UINT16 handle, BOOLEAN enable)
271{
272    UNUSED(handle);
273    UNUSED(enable);
274}
275
276void bta_pan_ci_rx_writebuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16 protocol, BT_HDR *p_buf, BOOLEAN ext)
277{
278    UNUSED(handle);
279    UNUSED(src);
280    UNUSED(dst);
281    UNUSED(protocol);
282    UNUSED(p_buf);
283    UNUSED(ext);
284}
285
286BT_HDR * bta_pan_ci_readbuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16 *p_protocol,
287                            BOOLEAN* p_ext, BOOLEAN* p_forward)
288{
289    UNUSED(handle);
290    UNUSED(src);
291    UNUSED(dst);
292    UNUSED(p_protocol);
293    UNUSED(p_ext);
294    UNUSED(p_forward);
295    return NULL;
296}
297
298void bta_pan_ci_set_pfilters(UINT16 handle, UINT16 num_filters, UINT16 *p_start_array, UINT16 *p_end_array)
299{
300    UNUSED(handle);
301    UNUSED(num_filters);
302    UNUSED(p_start_array);
303    UNUSED(p_end_array);
304}
305
306void bta_pan_ci_set_mfilters(UINT16 handle, UINT16 num_mcast_filters, UINT8 *p_start_array,
307                             UINT8 *p_end_array)
308{
309    UNUSED(handle);
310    UNUSED(num_mcast_filters);
311    UNUSED(p_start_array);
312    UNUSED(p_end_array);
313}
314
315#endif /* BTA_PAN_API */
316