The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2009-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 the MCAP Data Channel Action |
| 22 | * Functions. |
| 23 | * |
| 24 | ******************************************************************************/ |
Ian Coolidge | 468e4b9 | 2015-02-06 00:28:47 -0800 | [diff] [blame] | 25 | |
| 26 | #include <stddef.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 27 | #include "bt_target.h" |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 28 | #include "bt_utils.h" |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame] | 29 | #include "bt_common.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | #include "mca_api.h" |
| 31 | #include "mca_int.h" |
| 32 | |
| 33 | /******************************************************************************* |
| 34 | ** |
| 35 | ** Function mca_dcb_report_cong |
| 36 | ** |
| 37 | ** Description This function is called to report the congestion flag. |
| 38 | ** |
| 39 | ** Returns void. |
| 40 | ** |
| 41 | *******************************************************************************/ |
| 42 | void mca_dcb_report_cong (tMCA_DCB *p_dcb) |
| 43 | { |
| 44 | tMCA_CTRL evt_data; |
| 45 | |
| 46 | evt_data.cong_chg.cong = p_dcb->cong; |
| 47 | evt_data.cong_chg.mdl = mca_dcb_to_hdl(p_dcb); |
| 48 | evt_data.cong_chg.mdl_id = p_dcb->mdl_id; |
| 49 | mca_ccb_report_event (p_dcb->p_ccb, MCA_CONG_CHG_EVT, &evt_data); |
| 50 | } |
| 51 | |
| 52 | /******************************************************************************* |
| 53 | ** |
| 54 | ** Function mca_dcb_tc_open |
| 55 | ** |
| 56 | ** Description This function is called to report MCA_OPEN_IND_EVT or |
| 57 | ** MCA_OPEN_CFM_EVT event. |
| 58 | ** It also clears the congestion flag (dcb.cong). |
| 59 | ** |
| 60 | ** Returns void. |
| 61 | ** |
| 62 | *******************************************************************************/ |
| 63 | void mca_dcb_tc_open (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) |
| 64 | { |
| 65 | tMCA_CTRL evt_data; |
| 66 | tMCA_CCB *p_ccb = p_dcb->p_ccb; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 67 | uint8_t event = MCA_OPEN_IND_EVT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 68 | |
| 69 | if (p_data->open.param == MCA_INT) |
| 70 | event = MCA_OPEN_CFM_EVT; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 71 | p_dcb->cong = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 72 | evt_data.open_cfm.mtu = p_data->open.peer_mtu; |
| 73 | evt_data.open_cfm.mdl_id = p_dcb->mdl_id; |
| 74 | evt_data.open_cfm.mdl = mca_dcb_to_hdl(p_dcb); |
| 75 | mca_ccb_event (p_ccb, MCA_CCB_DL_OPEN_EVT, NULL); |
| 76 | mca_ccb_report_event (p_ccb, event, &evt_data); |
| 77 | } |
| 78 | |
| 79 | /******************************************************************************* |
| 80 | ** |
| 81 | ** Function mca_dcb_cong |
| 82 | ** |
| 83 | ** Description This function sets the congestion state for the DCB. |
| 84 | ** |
| 85 | ** Returns void. |
| 86 | ** |
| 87 | *******************************************************************************/ |
| 88 | void mca_dcb_cong (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) |
| 89 | { |
| 90 | p_dcb->cong = p_data->llcong; |
| 91 | mca_dcb_report_cong(p_dcb); |
| 92 | } |
| 93 | |
| 94 | /******************************************************************************* |
| 95 | ** |
| 96 | ** Function mca_dcb_free_data |
| 97 | ** |
| 98 | ** Description This function frees the received message. |
| 99 | ** |
| 100 | ** Returns void. |
| 101 | ** |
| 102 | *******************************************************************************/ |
Myles Watson | d35a648 | 2016-10-27 08:52:16 -0700 | [diff] [blame^] | 103 | void mca_dcb_free_data(UNUSED_ATTR tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 104 | { |
Pavlin Radoslavov | cceb430 | 2016-02-05 13:54:43 -0800 | [diff] [blame] | 105 | osi_free(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /******************************************************************************* |
| 109 | ** |
| 110 | ** Function mca_dcb_do_disconn |
| 111 | ** |
| 112 | ** Description This function closes a data channel. |
| 113 | ** |
| 114 | ** Returns void. |
| 115 | ** |
| 116 | *******************************************************************************/ |
Myles Watson | d35a648 | 2016-10-27 08:52:16 -0700 | [diff] [blame^] | 117 | void mca_dcb_do_disconn (tMCA_DCB *p_dcb, |
| 118 | UNUSED_ATTR tMCA_DCB_EVT *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 119 | { |
| 120 | tMCA_CLOSE close; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 121 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 122 | if ((p_dcb->lcid == 0) || (L2CA_DisconnectReq(p_dcb->lcid) == false)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 123 | { |
| 124 | close.param = MCA_INT; |
| 125 | close.reason = L2CAP_DISC_OK; |
| 126 | close.lcid = 0; |
| 127 | mca_dcb_event(p_dcb, MCA_DCB_TC_CLOSE_EVT, (tMCA_DCB_EVT *) &close); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /******************************************************************************* |
| 132 | ** |
| 133 | ** Function mca_dcb_snd_data |
| 134 | ** |
| 135 | ** Description This function sends the data from application to the peer device. |
| 136 | ** |
| 137 | ** Returns void. |
| 138 | ** |
| 139 | *******************************************************************************/ |
| 140 | void mca_dcb_snd_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) |
| 141 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 142 | uint8_t status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 143 | |
| 144 | /* do not need to check cong, because API already checked the status */ |
| 145 | status = L2CA_DataWrite (p_dcb->lcid, p_data->p_pkt); |
| 146 | if (status == L2CAP_DW_CONGESTED) |
| 147 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 148 | p_dcb->cong = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 149 | mca_dcb_report_cong(p_dcb); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /******************************************************************************* |
| 154 | ** |
| 155 | ** Function mca_dcb_hdl_data |
| 156 | ** |
| 157 | ** Description This function reports the received data through the data |
| 158 | ** callback function. |
| 159 | ** |
| 160 | ** Returns void. |
| 161 | ** |
| 162 | *******************************************************************************/ |
| 163 | void mca_dcb_hdl_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) |
| 164 | { |
| 165 | (*p_dcb->p_cs->p_data_cback) (mca_dcb_to_hdl(p_dcb), (BT_HDR *)p_data); |
| 166 | } |
| 167 | |