blob: f755c5b2f612cfcb230535cfe44efd6337607cbc [file] [log] [blame]
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001/******************************************************************************
2 *
Evan Chue9629ba2014-01-31 11:18:47 -05003 * Copyright (C) 2010-2014 Broadcom Corporation
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08004 *
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
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080019/******************************************************************************
20 *
21 * This file contains the main LLCP entry points
22 *
23 ******************************************************************************/
24
25#include <string.h>
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080026#include "bt_types.h"
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080027#include "gki.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080028#include "llcp_api.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080029#include "llcp_defs.h"
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080030#include "llcp_int.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080031#include "nfc_int.h"
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080032#include "nfc_target.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080033
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080034tLLCP_CB llcp_cb;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080035
36/*******************************************************************************
37**
38** Function llcp_init
39**
40** Description This function is called once at startup to initialize
41** all the LLCP structures
42**
43** Returns void
44**
45*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080046void llcp_init(void) {
47 uint32_t pool_count;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080048
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080049 memset(&llcp_cb, 0, sizeof(tLLCP_CB));
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080050
Ruchi Kandoi6767aec2017-09-26 09:46:26 -070051 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080052
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080053 llcp_cb.lcb.local_link_miu =
54 (LLCP_MIU <= LLCP_MAX_MIU ? LLCP_MIU : LLCP_MAX_MIU);
55 llcp_cb.lcb.local_opt = LLCP_OPT_VALUE;
56 llcp_cb.lcb.local_wt = LLCP_WAITING_TIME;
57 llcp_cb.lcb.local_lto = LLCP_LTO_VALUE;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080058
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080059 llcp_cb.lcb.inact_timeout_init = LLCP_INIT_INACTIVITY_TIMEOUT;
60 llcp_cb.lcb.inact_timeout_target = LLCP_TARGET_INACTIVITY_TIMEOUT;
61 llcp_cb.lcb.symm_delay = LLCP_DELAY_RESP_TIME;
62 llcp_cb.lcb.data_link_timeout = LLCP_DATA_LINK_CONNECTION_TOUT;
63 llcp_cb.lcb.delay_first_pdu_timeout = LLCP_DELAY_TIME_TO_SEND_FIRST_PDU;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080064
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080065 llcp_cb.lcb.wks = LLCP_WKS_MASK_LM;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080066
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080067 /* total number of buffers for LLCP */
68 pool_count = GKI_poolcount(LLCP_POOL_ID);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080069
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080070 /* number of buffers for receiving data */
71 llcp_cb.num_rx_buff = (pool_count * LLCP_RX_BUFF_RATIO) / 100;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080072
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080073 /* rx congestion start/end threshold */
74 llcp_cb.overall_rx_congest_start =
75 (uint8_t)((llcp_cb.num_rx_buff * LLCP_RX_CONGEST_START) / 100);
76 llcp_cb.overall_rx_congest_end =
77 (uint8_t)((llcp_cb.num_rx_buff * LLCP_RX_CONGEST_END) / 100);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080078
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080079 /* max number of buffers for receiving data on logical data link */
80 llcp_cb.max_num_ll_rx_buff =
81 (uint8_t)((llcp_cb.num_rx_buff * LLCP_LL_RX_BUFF_LIMIT) / 100);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080082
Ruchi Kandoi6767aec2017-09-26 09:46:26 -070083 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080084 "num_rx_buff = %d, rx_congest_start = %d, rx_congest_end = %d, "
85 "max_num_ll_rx_buff = %d",
86 llcp_cb.num_rx_buff, llcp_cb.overall_rx_congest_start,
87 llcp_cb.overall_rx_congest_end, llcp_cb.max_num_ll_rx_buff);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080088
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080089 /* max number of buffers for transmitting data */
90 llcp_cb.max_num_tx_buff = (uint8_t)(pool_count - llcp_cb.num_rx_buff);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080091
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080092 /* max number of buffers for transmitting data on logical data link */
93 llcp_cb.max_num_ll_tx_buff =
94 (uint8_t)((llcp_cb.max_num_tx_buff * LLCP_LL_TX_BUFF_LIMIT) / 100);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080095
Ruchi Kandoi6767aec2017-09-26 09:46:26 -070096 DLOG_IF(INFO, nfc_debug_enabled)
97 << StringPrintf("max_num_tx_buff = %d, max_num_ll_tx_buff = %d",
98 llcp_cb.max_num_tx_buff, llcp_cb.max_num_ll_tx_buff);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080099
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800100 llcp_cb.ll_tx_uncongest_ntf_start_sap = LLCP_SAP_SDP + 1;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800101
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800102 LLCP_RegisterServer(LLCP_SAP_SDP, LLCP_LINK_TYPE_DATA_LINK_CONNECTION,
103 "urn:nfc:sn:sdp", llcp_sdp_proc_data);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800104}
105
106/*******************************************************************************
107**
108** Function llcp_cleanup
109**
110** Description This function is called once at closing to clean up
111**
112** Returns void
113**
114*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800115void llcp_cleanup(void) {
116 uint8_t sap;
117 tLLCP_APP_CB* p_app_cb;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800118
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700119 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800120
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800121 for (sap = LLCP_SAP_SDP; sap < LLCP_NUM_SAPS; sap++) {
122 p_app_cb = llcp_util_get_app_cb(sap);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800123
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800124 if ((p_app_cb) && (p_app_cb->p_app_cback)) {
125 LLCP_Deregister(sap);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800126 }
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800127 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800128
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800129 nfc_stop_quick_timer(&llcp_cb.lcb.inact_timer);
130 nfc_stop_quick_timer(&llcp_cb.lcb.timer);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800131}
132
133/*******************************************************************************
134**
135** Function llcp_process_timeout
136**
137** Description This function is called when an LLCP-related timeout occurs
138**
139** Returns void
140**
141*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800142void llcp_process_timeout(TIMER_LIST_ENT* p_tle) {
143 uint8_t reason;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800144
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700145 DLOG_IF(INFO, nfc_debug_enabled)
146 << StringPrintf("llcp_process_timeout: event=%d", p_tle->event);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800147
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800148 switch (p_tle->event) {
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800149 case NFC_TTYPE_LLCP_LINK_MANAGER:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800150 /* Link timeout or Symm timeout */
151 llcp_link_process_link_timeout();
152 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800153
154 case NFC_TTYPE_LLCP_LINK_INACT:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800155 /* inactivity timeout */
156 llcp_link_deactivate(LLCP_LINK_LOCAL_INITIATED);
157 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800158
159 case NFC_TTYPE_LLCP_DATA_LINK:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800160 reason = LLCP_SAP_DISCONNECT_REASON_TIMEOUT;
161 llcp_dlsm_execute((tLLCP_DLCB*)(p_tle->param), LLCP_DLC_EVENT_TIMEOUT,
162 &reason);
163 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800164
165 case NFC_TTYPE_LLCP_DELAY_FIRST_PDU:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800166 llcp_link_check_send_data();
167 break;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800168
169 default:
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800170 break;
171 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800172}
173
174/*******************************************************************************
175**
176** Function LLCP_SetTraceLevel
177**
178** Description This function sets the trace level for LLCP. If called with
179** a value of 0xFF, it simply returns the current trace level.
180**
181** Returns The new or current trace level
182**
183*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800184uint8_t LLCP_SetTraceLevel(uint8_t new_level) {
185 if (new_level != 0xFF) llcp_cb.trace_level = new_level;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800186
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800187 return (llcp_cb.trace_level);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800188}