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 "bta/pan/bta_pan_int.h"
26 #include "internal_include/bt_target.h"
27 #include "osi/include/allocator.h"
28 #include "stack/include/bt_hdr.h"
29 #include "types/raw_address.h"
30
31 void bta_pan_sm_execute(tBTA_PAN_SCB* p_scb, uint16_t event,
32 tBTA_PAN_DATA* p_data);
33
34 /*******************************************************************************
35 *
36 * Function bta_pan_ci_tx_ready
37 *
38 * Description This function sends an event to PAN indicating the phone is
39 * ready for more data and PAN should call
40 * bta_pan_co_tx_path().
41 * This function is used when the TX data path is configured
42 * to use a pull interface.
43 *
44 *
45 * Returns void
46 *
47 ******************************************************************************/
bta_pan_ci_tx_ready(uint16_t handle)48 void bta_pan_ci_tx_ready(uint16_t handle) {
49 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
50
51 p_buf->layer_specific = handle;
52 p_buf->event = BTA_PAN_CI_TX_READY_EVT;
53
54 bta_sys_sendmsg(p_buf);
55 }
56
57 /*******************************************************************************
58 *
59 * Function bta_pan_ci_rx_ready
60 *
61 * Description This function sends an event to PAN indicating the phone
62 * has data available to send to PAN and PAN should call
63 * bta_pan_co_rx_path(). This function is used when the RX
64 * data path is configured to use a pull interface.
65 *
66 *
67 * Returns void
68 *
69 ******************************************************************************/
bta_pan_ci_rx_ready(uint16_t handle)70 void bta_pan_ci_rx_ready(uint16_t handle) {
71 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
72
73 p_buf->layer_specific = handle;
74 p_buf->event = BTA_PAN_CI_RX_READY_EVT;
75
76 bta_sys_sendmsg(p_buf);
77 }
78
79 /*******************************************************************************
80 *
81 * Function bta_pan_ci_tx_flow
82 *
83 * Description This function is called to enable or disable data flow on
84 * the TX path. The phone should call this function to
85 * disable data flow when it is congested and cannot handle
86 * any more data sent by bta_pan_co_tx_write().
87 * This function is used when the
88 * TX data path is configured to use a push interface.
89 *
90 *
91 * Returns void
92 *
93 ******************************************************************************/
bta_pan_ci_tx_flow(uint16_t handle,bool enable)94 void bta_pan_ci_tx_flow(uint16_t handle, bool enable) {
95 tBTA_PAN_CI_TX_FLOW* p_buf =
96 (tBTA_PAN_CI_TX_FLOW*)osi_malloc(sizeof(tBTA_PAN_CI_TX_FLOW));
97
98 p_buf->hdr.layer_specific = handle;
99 p_buf->hdr.event = BTA_PAN_CI_TX_FLOW_EVT;
100 p_buf->enable = enable;
101
102 bta_sys_sendmsg(p_buf);
103 }
104
105 /*******************************************************************************
106 *
107 * Function bta_pan_ci_rx_write
108 *
109 * Description This function is called to send data to PAN when the RX path
110 * is configured to use a push interface. The function copies
111 * data to an event buffer and sends it to PAN.
112 *
113 *
114 * Returns void
115 *
116 ******************************************************************************/
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)117 void bta_pan_ci_rx_write(uint16_t handle, const RawAddress& dst,
118 const RawAddress& src, uint16_t protocol,
119 uint8_t* p_data, uint16_t len, bool ext) {
120 BT_HDR* p_buf = (BT_HDR*)osi_malloc(PAN_BUF_SIZE);
121
122 p_buf->offset = PAN_MINIMUM_OFFSET;
123
124 /* copy all other params before the data */
125 ((tBTA_PAN_DATA_PARAMS*)p_buf)->src = src;
126 ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst = dst;
127 ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol = protocol;
128 ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext = ext;
129 p_buf->len = len;
130
131 /* copy data */
132 memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, p_data, len);
133
134 p_buf->layer_specific = handle;
135 p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
136
137 bta_sys_sendmsg(p_buf);
138 }
139
140 /*******************************************************************************
141 *
142 * Function bta_pan_ci_rx_writebuf
143 *
144 * Description This function is called to send data to the phone when
145 * the RX path is configured to use a push interface with
146 * zero copy. The function sends an event to PAN containing
147 * the data buffer. The buffer will be freed by BTA; the
148 * phone must not free the buffer.
149 *
150 *
151 * Returns void
152 *
153 ******************************************************************************/
bta_pan_ci_rx_writebuf(uint16_t handle,const RawAddress & dst,const RawAddress & src,uint16_t protocol,BT_HDR * p_buf,bool ext)154 void bta_pan_ci_rx_writebuf(uint16_t handle, const RawAddress& dst,
155 const RawAddress& src, uint16_t protocol,
156 BT_HDR* p_buf, bool ext) {
157 /* copy all other params before the data */
158 ((tBTA_PAN_DATA_PARAMS*)p_buf)->src = src;
159 ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst = dst;
160 ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol = protocol;
161 ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext = ext;
162
163 p_buf->layer_specific = handle;
164 p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
165 bta_sys_sendmsg(p_buf);
166 }
167
168 /*******************************************************************************
169 *
170 * Function bta_pan_ci_readbuf
171 *
172 * Description
173 *
174 *
175 * Returns void
176 *
177 ******************************************************************************/
bta_pan_ci_readbuf(uint16_t handle,RawAddress & src,RawAddress & dst,uint16_t * p_protocol,bool * p_ext,bool * p_forward)178 BT_HDR* bta_pan_ci_readbuf(uint16_t handle, RawAddress& src, RawAddress& dst,
179 uint16_t* p_protocol, bool* p_ext, bool* p_forward) {
180 tBTA_PAN_SCB* p_scb = bta_pan_scb_by_handle(handle);
181 BT_HDR* p_buf;
182
183 if (p_scb == NULL) return NULL;
184
185 p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_scb->data_queue);
186 if (p_buf != NULL) {
187 src = ((tBTA_PAN_DATA_PARAMS*)p_buf)->src;
188 dst = ((tBTA_PAN_DATA_PARAMS*)p_buf)->dst;
189 *p_protocol = ((tBTA_PAN_DATA_PARAMS*)p_buf)->protocol;
190 *p_ext = ((tBTA_PAN_DATA_PARAMS*)p_buf)->ext;
191 *p_forward = ((tBTA_PAN_DATA_PARAMS*)p_buf)->forward;
192 }
193
194 return p_buf;
195 }
196