OSDN Git Service

[automerger skipped] [automerger] Decrease length after reading from array in process...
[android-x86/system-bt.git] / bta / ag / bta_ag_ci.cc
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
27 #include "bt_common.h"
28 #include "bta_ag_api.h"
29 #include "bta_ag_ci.h"
30 #include "bta_ag_int.h"
31 #include "bta_api.h"
32
33 /******************************************************************************
34  *
35  * Function         bta_ag_ci_rx_write
36  *
37  * Description      This function is called to send data to the AG when the AG
38  *                  is configured for AT command pass-through.  The function
39  *                  copies data to an event buffer and sends it.
40  *
41  * Returns          void
42  *
43  *****************************************************************************/
44 void bta_ag_ci_rx_write(uint16_t handle, char* p_data, uint16_t len) {
45   uint16_t len_remaining = len;
46   char* p_data_area;
47
48   if (len > (RFCOMM_DATA_BUF_SIZE - sizeof(tBTA_AG_CI_RX_WRITE) - 1))
49     len = RFCOMM_DATA_BUF_SIZE - sizeof(tBTA_AG_CI_RX_WRITE) - 1;
50
51   while (len_remaining) {
52     if (len_remaining < len) len = len_remaining;
53
54     tBTA_AG_CI_RX_WRITE* p_buf =
55         (tBTA_AG_CI_RX_WRITE*)osi_malloc(sizeof(tBTA_AG_CI_RX_WRITE) + len + 1);
56     p_buf->hdr.event = BTA_AG_CI_RX_WRITE_EVT;
57     p_buf->hdr.layer_specific = handle;
58
59     p_data_area = (char*)(p_buf + 1); /* Point to data area after header */
60     strncpy(p_data_area, p_data, len);
61     p_data_area[len] = 0;
62
63     bta_sys_sendmsg(p_buf);
64
65     len_remaining -= len;
66     p_data += len;
67   }
68 }
69
70 /******************************************************************************
71  *
72  * Function         bta_ag_ci_slc_ready
73  *
74  * Description      This function is called to notify AG that SLC is up at
75  *                  the application. This funcion is only used when the app
76  *                  is running in pass-through mode.
77  *
78  * Returns          void
79  *
80  *****************************************************************************/
81 void bta_ag_ci_slc_ready(uint16_t handle) {
82   tBTA_AG_DATA* p_buf = (tBTA_AG_DATA*)osi_malloc(sizeof(tBTA_AG_DATA));
83
84   p_buf->hdr.event = BTA_AG_CI_SLC_READY_EVT;
85   p_buf->hdr.layer_specific = handle;
86
87   bta_sys_sendmsg(p_buf);
88 }