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