Home | History | Annotate | Download | only in ag
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2003-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 audio gateway call-in functions.
     22  *
     23  ******************************************************************************/
     24 
     25 #include <string.h>
     26 #include "bta_api.h"
     27 #include "bta_ag_api.h"
     28 #include "bta_ag_int.h"
     29 #include "bta_ag_ci.h"
     30 #include "gki.h"
     31 
     32 /******************************************************************************
     33 **
     34 ** Function         bta_ag_ci_rx_write
     35 **
     36 ** Description      This function is called to send data to the AG when the AG
     37 **                  is configured for AT command pass-through.  The function
     38 **                  copies data to an event buffer and sends it.
     39 **
     40 ** Returns          void
     41 **
     42 ******************************************************************************/
     43 void bta_ag_ci_rx_write(UINT16 handle, char *p_data, UINT16 len)
     44 {
     45     tBTA_AG_CI_RX_WRITE *p_buf;
     46     UINT16 len_remaining = len;
     47     char *p_data_area;
     48 
     49     if (len > (RFCOMM_DATA_POOL_BUF_SIZE - sizeof(tBTA_AG_CI_RX_WRITE) - 1))
     50         len = RFCOMM_DATA_POOL_BUF_SIZE - sizeof(tBTA_AG_CI_RX_WRITE) - 1;
     51 
     52     while (len_remaining)
     53     {
     54         if (len_remaining < len)
     55             len = len_remaining;
     56 
     57         if ((p_buf = (tBTA_AG_CI_RX_WRITE *) GKI_getbuf((UINT16)(sizeof(tBTA_AG_CI_RX_WRITE) + len + 1))) != NULL)
     58     {
     59         p_buf->hdr.event = BTA_AG_CI_RX_WRITE_EVT;
     60         p_buf->hdr.layer_specific = handle;
     61 
     62         p_data_area = (char *)(p_buf+1);        /* Point to data area after header */
     63         strncpy(p_data_area, p_data, len);
     64         p_data_area[len] = 0;
     65 
     66         bta_sys_sendmsg(p_buf);
     67         } else {
     68         APPL_TRACE_ERROR("ERROR: Unable to allocate buffer to hold AT response code. len=%i", len);
     69             break;
     70         }
     71 
     72         len_remaining-=len;
     73         p_data+=len;
     74     }
     75 }
     76 
     77 /******************************************************************************
     78 **
     79 ** Function         bta_ag_ci_slc_ready
     80 **
     81 ** Description      This function is called to notify AG that SLC is up at
     82 **                  the application. This funcion is only used when the app
     83 **                  is running in pass-through mode.
     84 **
     85 ** Returns          void
     86 **
     87 ******************************************************************************/
     88 void bta_ag_ci_slc_ready(UINT16 handle)
     89 {
     90     tBTA_AG_DATA *p_buf;
     91 
     92     if ((p_buf = (tBTA_AG_DATA *)GKI_getbuf(sizeof(tBTA_AG_DATA))) != NULL)
     93     {
     94         p_buf->hdr.event = BTA_AG_CI_SLC_READY_EVT;
     95         p_buf->hdr.layer_specific = handle;
     96         bta_sys_sendmsg(p_buf);
     97     }
     98 }
     99