summaryrefslogtreecommitdiffstats
path: root/stack/mcap/mca_dact.c
blob: 353153eb8791d6ddd53fd5f771c943cfd4b9bb72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/******************************************************************************
 *
 *  Copyright (C) 2009-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

/******************************************************************************
 *
 *  This is the implementation file for the MCAP Data Channel Action
 *  Functions.
 *
 ******************************************************************************/
#include "bt_target.h"
#include "gki.h"
#include "mca_api.h"
#include "mca_int.h"

/*******************************************************************************
**
** Function         mca_dcb_report_cong
**
** Description      This function is called to report the congestion flag.
**
** Returns          void.
**
*******************************************************************************/
void mca_dcb_report_cong (tMCA_DCB *p_dcb)
{
    tMCA_CTRL   evt_data;

    evt_data.cong_chg.cong   = p_dcb->cong;
    evt_data.cong_chg.mdl    = mca_dcb_to_hdl(p_dcb);
    evt_data.cong_chg.mdl_id = p_dcb->mdl_id;
    mca_ccb_report_event (p_dcb->p_ccb, MCA_CONG_CHG_EVT, &evt_data);
}

/*******************************************************************************
**
** Function         mca_dcb_tc_open
**
** Description      This function is called to report MCA_OPEN_IND_EVT or
**                  MCA_OPEN_CFM_EVT event.
**                  It also clears the congestion flag (dcb.cong).
**
** Returns          void.
**
*******************************************************************************/
void mca_dcb_tc_open (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
{
    tMCA_CTRL   evt_data;
    tMCA_CCB    *p_ccb = p_dcb->p_ccb;
    UINT8       event = MCA_OPEN_IND_EVT;

    if (p_data->open.param == MCA_INT)
        event = MCA_OPEN_CFM_EVT;
    p_dcb->cong  = FALSE;
    evt_data.open_cfm.mtu       = p_data->open.peer_mtu;
    evt_data.open_cfm.mdl_id    = p_dcb->mdl_id;
    evt_data.open_cfm.mdl       = mca_dcb_to_hdl(p_dcb);
    mca_ccb_event (p_ccb, MCA_CCB_DL_OPEN_EVT, NULL);
    mca_ccb_report_event (p_ccb, event, &evt_data);
}

/*******************************************************************************
**
** Function         mca_dcb_cong
**
** Description      This function sets the congestion state for the DCB.
**
** Returns          void.
**
*******************************************************************************/
void mca_dcb_cong (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
{
    p_dcb->cong  = p_data->llcong;
    mca_dcb_report_cong(p_dcb);
}

/*******************************************************************************
**
** Function         mca_dcb_free_data
**
** Description      This function frees the received message.
**
** Returns          void.
**
*******************************************************************************/
void mca_dcb_free_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
{
    GKI_freebuf (p_data);
}

/*******************************************************************************
**
** Function         mca_dcb_do_disconn
**
** Description      This function closes a data channel.
**
** Returns          void.
**
*******************************************************************************/
void mca_dcb_do_disconn (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
{
    tMCA_CLOSE  close;
    if ((p_dcb->lcid == 0) || (L2CA_DisconnectReq(p_dcb->lcid) == FALSE))
    {
        close.param  = MCA_INT;
        close.reason = L2CAP_DISC_OK;
        close.lcid   = 0;
        mca_dcb_event(p_dcb, MCA_DCB_TC_CLOSE_EVT, (tMCA_DCB_EVT *) &close);
    }
}

/*******************************************************************************
**
** Function         mca_dcb_snd_data
**
** Description      This function sends the data from application to the peer device.
**
** Returns          void.
**
*******************************************************************************/
void mca_dcb_snd_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
{
    UINT8   status;

    /* do not need to check cong, because API already checked the status */
    status = L2CA_DataWrite (p_dcb->lcid, p_data->p_pkt);
    if (status == L2CAP_DW_CONGESTED)
    {
        p_dcb->cong = TRUE;
        mca_dcb_report_cong(p_dcb);
    }
}

/*******************************************************************************
**
** Function         mca_dcb_hdl_data
**
** Description      This function reports the received data through the data
**                  callback function.
**
** Returns          void.
**
*******************************************************************************/
void mca_dcb_hdl_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
{
    (*p_dcb->p_cs->p_data_cback) (mca_dcb_to_hdl(p_dcb), (BT_HDR *)p_data);
}