1 /******************************************************************************
3 * Copyright 2004-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This is the implementation file for data gateway call-in functions.
23 ******************************************************************************/
25 #include "bt_target.h" // Must be first to define build configuration
27 #include "bta/pan/bta_pan_int.h"
28 #include "osi/include/allocator.h"
29 #include "types/raw_address.h"
31 #if (BTA_PAN_INCLUDED == TRUE)
33 /*******************************************************************************
35 * Function bta_pan_ci_tx_ready
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.
46 ******************************************************************************/
47 void bta_pan_ci_tx_ready(uint16_t handle) {
48 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
50 p_buf->layer_specific = handle;
51 p_buf->event = BTA_PAN_CI_TX_READY_EVT;
53 bta_sys_sendmsg(p_buf);
56 /*******************************************************************************
58 * Function bta_pan_ci_rx_ready
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.
68 ******************************************************************************/
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));
72 p_buf->layer_specific = handle;
73 p_buf->event = BTA_PAN_CI_RX_READY_EVT;
75 bta_sys_sendmsg(p_buf);
78 /*******************************************************************************
80 * Function bta_pan_ci_tx_flow
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.
92 ******************************************************************************/
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));
97 p_buf->hdr.layer_specific = handle;
98 p_buf->hdr.event = BTA_PAN_CI_TX_FLOW_EVT;
99 p_buf->enable = enable;
101 bta_sys_sendmsg(p_buf);
104 /*******************************************************************************
106 * Function bta_pan_ci_rx_write
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.
115 ******************************************************************************/
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);
121 p_buf->offset = PAN_MINIMUM_OFFSET;
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;
131 memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, p_data, len);
133 p_buf->layer_specific = handle;
134 p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
136 bta_sys_sendmsg(p_buf);
139 /*******************************************************************************
141 * Function bta_pan_ci_rx_writebuf
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.
152 ******************************************************************************/
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;
162 p_buf->layer_specific = handle;
163 p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
164 bta_sys_sendmsg(p_buf);
167 /*******************************************************************************
169 * Function bta_pan_ci_readbuf
176 ******************************************************************************/
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);
182 if (p_scb == NULL) return NULL;
184 p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_scb->data_queue);
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;
196 /*******************************************************************************
198 * Function bta_pan_ci_set_mfilters
200 * Description This function is called to set multicast filters
205 ******************************************************************************/
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,
212 /*******************************************************************************
214 * Function bta_pan_ci_set_mfilters
216 * Description This function is called to set protocol filters
221 ******************************************************************************/
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);
227 #include "osi/include/osi.h" // UNUSED_ATTR
229 void bta_pan_ci_tx_ready(UNUSED_ATTR uint16_t handle) {}
231 void bta_pan_ci_rx_ready(UNUSED_ATTR uint16_t handle) {}
233 void bta_pan_ci_tx_flow(UNUSED_ATTR uint16_t handle, UNUSED_ATTR bool enable) {}
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) {}
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) {
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) {}
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) {}
260 #endif /* BTA_PAN_API */