Home | History | Annotate | Download | only in pan
      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 "pan_api.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 "bt_utils.h"
     36 
     37 #if defined(BTA_PAN_INCLUDED) && (BTA_PAN_INCLUDED == TRUE)
     38 
     39 /*******************************************************************************
     40 **
     41 ** Function         bta_pan_ci_tx_ready
     42 **
     43 ** Description      This function sends an event to PAN indicating the phone is
     44 **                  ready for more data and PAN should call bta_pan_co_tx_path().
     45 **                  This function is used when the TX data path is configured
     46 **                  to use a pull interface.
     47 **
     48 **
     49 ** Returns          void
     50 **
     51 *******************************************************************************/
     52 void bta_pan_ci_tx_ready(UINT16 handle)
     53 {
     54     BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
     55 
     56     p_buf->layer_specific = handle;
     57     p_buf->event = BTA_PAN_CI_TX_READY_EVT;
     58 
     59     bta_sys_sendmsg(p_buf);
     60 }
     61 
     62 /*******************************************************************************
     63 **
     64 ** Function         bta_pan_ci_rx_ready
     65 **
     66 ** Description      This function sends an event to PAN indicating the phone
     67 **                  has data available to send to PAN and PAN should call
     68 **                  bta_pan_co_rx_path().  This function is used when the RX
     69 **                  data path is configured to use a pull interface.
     70 **
     71 **
     72 ** Returns          void
     73 **
     74 *******************************************************************************/
     75 void bta_pan_ci_rx_ready(UINT16 handle)
     76 {
     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 *******************************************************************************/
    100 void bta_pan_ci_tx_flow(UINT16 handle, BOOLEAN enable)
    101 {
    102     tBTA_PAN_CI_TX_FLOW  *p_buf =
    103         (tBTA_PAN_CI_TX_FLOW *)osi_malloc(sizeof(tBTA_PAN_CI_TX_FLOW));
    104 
    105     p_buf->hdr.layer_specific = handle;
    106     p_buf->hdr.event = BTA_PAN_CI_TX_FLOW_EVT;
    107     p_buf->enable = enable;
    108 
    109     bta_sys_sendmsg(p_buf);
    110 }
    111 
    112 /*******************************************************************************
    113 **
    114 ** Function         bta_pan_ci_rx_write
    115 **
    116 ** Description      This function is called to send data to PAN when the RX path
    117 **                  is configured to use a push interface.  The function copies
    118 **                  data to an event buffer and sends it to PAN.
    119 **
    120 **
    121 ** Returns          void
    122 **
    123 *******************************************************************************/
    124 void bta_pan_ci_rx_write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol,
    125                             UINT8 *p_data, UINT16 len, BOOLEAN ext)
    126 {
    127     BT_HDR *p_buf = (BT_HDR *)osi_malloc(PAN_BUF_SIZE);
    128 
    129     p_buf->offset = PAN_MINIMUM_OFFSET;
    130 
    131     /* copy all other params before the data */
    132     bdcpy(((tBTA_PAN_DATA_PARAMS *)p_buf)->src, src);
    133     bdcpy(((tBTA_PAN_DATA_PARAMS *)p_buf)->dst, dst);
    134     ((tBTA_PAN_DATA_PARAMS *)p_buf)->protocol = protocol;
    135     ((tBTA_PAN_DATA_PARAMS *)p_buf)->ext = ext;
    136     p_buf->len=len;
    137 
    138     /* copy data */
    139     memcpy((UINT8 *)(p_buf + 1) + p_buf->offset, p_data, len);
    140 
    141     p_buf->layer_specific = handle;
    142     p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
    143 
    144     bta_sys_sendmsg(p_buf);
    145 }
    146 
    147 /*******************************************************************************
    148 **
    149 ** Function         bta_pan_ci_rx_writebuf
    150 **
    151 ** Description      This function is called to send data to the phone when
    152 **                  the RX path is configured to use a push interface with
    153 **                  zero copy.  The function sends an event to PAN containing
    154 **                  the data buffer. The buffer will be freed by BTA; the
    155 **                  phone must not free the buffer.
    156 **
    157 **
    158 ** Returns          void
    159 **
    160 *******************************************************************************/
    161 void bta_pan_ci_rx_writebuf(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol,
    162                             BT_HDR *p_buf, BOOLEAN ext)
    163 {
    164 
    165     /* copy all other params before the data */
    166     bdcpy(((tBTA_PAN_DATA_PARAMS *)p_buf)->src, src);
    167     bdcpy(((tBTA_PAN_DATA_PARAMS *)p_buf)->dst, dst);
    168     ((tBTA_PAN_DATA_PARAMS *)p_buf)->protocol = protocol;
    169     ((tBTA_PAN_DATA_PARAMS *)p_buf)->ext = ext;
    170 
    171     p_buf->layer_specific = handle;
    172     p_buf->event = BTA_PAN_CI_RX_WRITEBUF_EVT;
    173     bta_sys_sendmsg(p_buf);
    174 }
    175 
    176 
    177 
    178 
    179 /*******************************************************************************
    180 **
    181 ** Function         bta_pan_ci_readbuf
    182 **
    183 ** Description
    184 **
    185 **
    186 ** Returns          void
    187 **
    188 *******************************************************************************/
    189 BT_HDR * bta_pan_ci_readbuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16* p_protocol,
    190                                  BOOLEAN* p_ext, BOOLEAN* p_forward)
    191 {
    192     tBTA_PAN_SCB * p_scb;
    193     BT_HDR * p_buf;
    194 
    195     p_scb = bta_pan_scb_by_handle(handle);
    196 
    197     p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_scb->data_queue);
    198     if (p_buf != NULL)
    199     {
    200         bdcpy(src,((tBTA_PAN_DATA_PARAMS *)p_buf)->src);
    201         bdcpy(dst,((tBTA_PAN_DATA_PARAMS *)p_buf)->dst);
    202         *p_protocol = ((tBTA_PAN_DATA_PARAMS *)p_buf)->protocol;
    203         *p_ext = ((tBTA_PAN_DATA_PARAMS *)p_buf)->ext;
    204         *p_forward = ((tBTA_PAN_DATA_PARAMS *)p_buf)->forward;
    205     }
    206 
    207     return p_buf;
    208 }
    209 
    210 
    211 /*******************************************************************************
    212 **
    213 ** Function         bta_pan_ci_set_mfilters
    214 **
    215 ** Description      This function is called to set multicast filters
    216 **
    217 **
    218 ** Returns          void
    219 **
    220 *******************************************************************************/
    221 void bta_pan_ci_set_mfilters(UINT16 handle, UINT16 num_mcast_filters, UINT8 *p_start_array,
    222                                                     UINT8 *p_end_array)
    223 {
    224 
    225     PAN_SetMulticastFilters(handle, num_mcast_filters, p_start_array, p_end_array);
    226 
    227 }
    228 
    229 
    230 /*******************************************************************************
    231 **
    232 ** Function         bta_pan_ci_set_mfilters
    233 **
    234 ** Description      This function is called to set protocol filters
    235 **
    236 **
    237 ** Returns          void
    238 **
    239 *******************************************************************************/
    240 void bta_pan_ci_set_pfilters(UINT16 handle, UINT16 num_filters, UINT16 *p_start_array, UINT16 *p_end_array)
    241 {
    242 
    243     PAN_SetProtocolFilters(handle, num_filters, p_start_array, p_end_array );
    244 
    245 }
    246 #else
    247 
    248 void bta_pan_ci_tx_ready(UINT16 handle)
    249 {
    250     UNUSED(handle);
    251 }
    252 
    253 void bta_pan_ci_rx_ready(UINT16 handle)
    254 {
    255     UNUSED(handle);
    256 }
    257 
    258 void bta_pan_ci_tx_flow(UINT16 handle, BOOLEAN enable)
    259 {
    260     UNUSED(handle);
    261     UNUSED(enable);
    262 }
    263 
    264 void bta_pan_ci_rx_writebuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16 protocol, BT_HDR *p_buf, BOOLEAN ext)
    265 {
    266     UNUSED(handle);
    267     UNUSED(src);
    268     UNUSED(dst);
    269     UNUSED(protocol);
    270     UNUSED(p_buf);
    271     UNUSED(ext);
    272 }
    273 
    274 BT_HDR * bta_pan_ci_readbuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16 *p_protocol,
    275                             BOOLEAN* p_ext, BOOLEAN* p_forward)
    276 {
    277     UNUSED(handle);
    278     UNUSED(src);
    279     UNUSED(dst);
    280     UNUSED(p_protocol);
    281     UNUSED(p_ext);
    282     UNUSED(p_forward);
    283     return NULL;
    284 }
    285 
    286 void bta_pan_ci_set_pfilters(UINT16 handle, UINT16 num_filters, UINT16 *p_start_array, UINT16 *p_end_array)
    287 {
    288     UNUSED(handle);
    289     UNUSED(num_filters);
    290     UNUSED(p_start_array);
    291     UNUSED(p_end_array);
    292 }
    293 
    294 void bta_pan_ci_set_mfilters(UINT16 handle, UINT16 num_mcast_filters, UINT8 *p_start_array,
    295                              UINT8 *p_end_array)
    296 {
    297     UNUSED(handle);
    298     UNUSED(num_mcast_filters);
    299     UNUSED(p_start_array);
    300     UNUSED(p_end_array);
    301 }
    302 
    303 #endif /* BTA_PAN_API */
    304