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