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