• 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 #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() or
93  *                  bta_pan_co_tx_writebuf().  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,BD_ADDR dst,BD_ADDR src,uint16_t protocol,uint8_t * p_data,uint16_t len,bool ext)123 void bta_pan_ci_rx_write(uint16_t handle, BD_ADDR dst, BD_ADDR src,
124                          uint16_t protocol, uint8_t* p_data, uint16_t len,
125                          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   bdcpy(((tBTA_PAN_DATA_PARAMS*)p_buf)->src, src);
132   bdcpy(((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,BD_ADDR dst,BD_ADDR src,uint16_t protocol,BT_HDR * p_buf,bool ext)160 void bta_pan_ci_rx_writebuf(uint16_t handle, BD_ADDR dst, BD_ADDR src,
161                             uint16_t protocol, BT_HDR* p_buf, bool ext) {
162   /* copy all other params before the data */
163   bdcpy(((tBTA_PAN_DATA_PARAMS*)p_buf)->src, src);
164   bdcpy(((tBTA_PAN_DATA_PARAMS*)p_buf)->dst, dst);
165   ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol = protocol;
166   ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext = ext;
167 
168   p_buf->layer_specific = handle;
169   p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
170   bta_sys_sendmsg(p_buf);
171 }
172 
173 /*******************************************************************************
174  *
175  * Function         bta_pan_ci_readbuf
176  *
177  * Description
178  *
179  *
180  * Returns          void
181  *
182  ******************************************************************************/
bta_pan_ci_readbuf(uint16_t handle,BD_ADDR src,BD_ADDR dst,uint16_t * p_protocol,bool * p_ext,bool * p_forward)183 BT_HDR* bta_pan_ci_readbuf(uint16_t handle, BD_ADDR src, BD_ADDR dst,
184                            uint16_t* p_protocol, bool* p_ext, bool* p_forward) {
185   tBTA_PAN_SCB* p_scb;
186   BT_HDR* p_buf;
187 
188   p_scb = bta_pan_scb_by_handle(handle);
189 
190   p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_scb->data_queue);
191   if (p_buf != NULL) {
192     bdcpy(src, ((tBTA_PAN_DATA_PARAMS*)p_buf)->src);
193     bdcpy(dst, ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst);
194     *p_protocol = ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol;
195     *p_ext = ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext;
196     *p_forward = ((tBTA_PAN_DATA_PARAMS*)p_buf)->forward;
197   }
198 
199   return p_buf;
200 }
201 
202 /*******************************************************************************
203  *
204  * Function         bta_pan_ci_set_mfilters
205  *
206  * Description      This function is called to set multicast filters
207  *
208  *
209  * Returns          void
210  *
211  ******************************************************************************/
bta_pan_ci_set_mfilters(uint16_t handle,uint16_t num_mcast_filters,uint8_t * p_start_array,uint8_t * p_end_array)212 void bta_pan_ci_set_mfilters(uint16_t handle, uint16_t num_mcast_filters,
213                              uint8_t* p_start_array, uint8_t* p_end_array) {
214   PAN_SetMulticastFilters(handle, num_mcast_filters, p_start_array,
215                           p_end_array);
216 }
217 
218 /*******************************************************************************
219  *
220  * Function         bta_pan_ci_set_mfilters
221  *
222  * Description      This function is called to set protocol filters
223  *
224  *
225  * Returns          void
226  *
227  ******************************************************************************/
bta_pan_ci_set_pfilters(uint16_t handle,uint16_t num_filters,uint16_t * p_start_array,uint16_t * p_end_array)228 void bta_pan_ci_set_pfilters(uint16_t handle, uint16_t num_filters,
229                              uint16_t* p_start_array, uint16_t* p_end_array) {
230   PAN_SetProtocolFilters(handle, num_filters, p_start_array, p_end_array);
231 }
232 #else
233 
bta_pan_ci_tx_ready(UNUSED_ATTR uint16_t handle)234 void bta_pan_ci_tx_ready(UNUSED_ATTR uint16_t handle) {}
235 
bta_pan_ci_rx_ready(UNUSED_ATTR uint16_t handle)236 void bta_pan_ci_rx_ready(UNUSED_ATTR uint16_t handle) {}
237 
bta_pan_ci_tx_flow(UNUSED_ATTR uint16_t handle,UNUSED_ATTR bool enable)238 void bta_pan_ci_tx_flow(UNUSED_ATTR uint16_t handle, UNUSED_ATTR bool enable) {}
239 
bta_pan_ci_rx_writebuf(UNUSED_ATTR uint16_t handle,UNUSED_ATTR BD_ADDR src,UNUSED_ATTR BD_ADDR dst,UNUSED_ATTR uint16_t protocol,UNUSED_ATTR BT_HDR * p_buf,UNUSED_ATTR bool ext)240 void bta_pan_ci_rx_writebuf(UNUSED_ATTR uint16_t handle,
241                             UNUSED_ATTR BD_ADDR src, UNUSED_ATTR BD_ADDR dst,
242                             UNUSED_ATTR uint16_t protocol,
243                             UNUSED_ATTR BT_HDR* p_buf, UNUSED_ATTR bool ext) {}
244 
bta_pan_ci_readbuf(UNUSED_ATTR uint16_t handle,UNUSED_ATTR BD_ADDR src,UNUSED_ATTR BD_ADDR dst,UNUSED_ATTR uint16_t * p_protocol,UNUSED_ATTR bool * p_ext,UNUSED_ATTR bool * p_forward)245 BT_HDR* bta_pan_ci_readbuf(UNUSED_ATTR uint16_t handle, UNUSED_ATTR BD_ADDR src,
246                            UNUSED_ATTR BD_ADDR dst,
247                            UNUSED_ATTR uint16_t* p_protocol,
248                            UNUSED_ATTR bool* p_ext,
249                            UNUSED_ATTR bool* p_forward) {
250   return NULL;
251 }
252 
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)253 void bta_pan_ci_set_pfilters(UNUSED_ATTR uint16_t handle,
254                              UNUSED_ATTR uint16_t num_filters,
255                              UNUSED_ATTR uint16_t* p_start_array,
256                              UNUSED_ATTR uint16_t* p_end_array) {}
257 
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)258 void bta_pan_ci_set_mfilters(UNUSED_ATTR uint16_t handle,
259                              UNUSED_ATTR uint16_t num_mcast_filters,
260                              UNUSED_ATTR uint8_t* p_start_array,
261                              UNUSED_ATTR uint8_t* p_end_array) {}
262 
263 #endif /* BTA_PAN_API */
264