nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2010-2014 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 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This file contains the main LLCP entry points |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
| 25 | #include <string.h> |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 26 | |
| 27 | #include <android-base/stringprintf.h> |
| 28 | #include <base/logging.h> |
| 29 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 30 | #include "bt_types.h" |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 31 | #include "gki.h" |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 32 | #include "llcp_api.h" |
| 33 | #include "llcp_int.h" |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 34 | #include "nfc_int.h" |
| 35 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 36 | using android::base::StringPrintf; |
| 37 | |
| 38 | extern bool nfc_debug_enabled; |
| 39 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 40 | tLLCP_CB llcp_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 41 | |
| 42 | /******************************************************************************* |
| 43 | ** |
| 44 | ** Function llcp_init |
| 45 | ** |
| 46 | ** Description This function is called once at startup to initialize |
| 47 | ** all the LLCP structures |
| 48 | ** |
| 49 | ** Returns void |
| 50 | ** |
| 51 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 52 | void llcp_init(void) { |
| 53 | uint32_t pool_count; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 54 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 55 | memset(&llcp_cb, 0, sizeof(tLLCP_CB)); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 56 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 57 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 58 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 59 | llcp_cb.lcb.local_link_miu = |
| 60 | (LLCP_MIU <= LLCP_MAX_MIU ? LLCP_MIU : LLCP_MAX_MIU); |
| 61 | llcp_cb.lcb.local_opt = LLCP_OPT_VALUE; |
| 62 | llcp_cb.lcb.local_wt = LLCP_WAITING_TIME; |
| 63 | llcp_cb.lcb.local_lto = LLCP_LTO_VALUE; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 64 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 65 | llcp_cb.lcb.inact_timeout_init = LLCP_INIT_INACTIVITY_TIMEOUT; |
| 66 | llcp_cb.lcb.inact_timeout_target = LLCP_TARGET_INACTIVITY_TIMEOUT; |
| 67 | llcp_cb.lcb.symm_delay = LLCP_DELAY_RESP_TIME; |
| 68 | llcp_cb.lcb.data_link_timeout = LLCP_DATA_LINK_CONNECTION_TOUT; |
| 69 | llcp_cb.lcb.delay_first_pdu_timeout = LLCP_DELAY_TIME_TO_SEND_FIRST_PDU; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 70 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 71 | llcp_cb.lcb.wks = LLCP_WKS_MASK_LM; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 72 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 73 | /* total number of buffers for LLCP */ |
| 74 | pool_count = GKI_poolcount(LLCP_POOL_ID); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 75 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 76 | /* number of buffers for receiving data */ |
| 77 | llcp_cb.num_rx_buff = (pool_count * LLCP_RX_BUFF_RATIO) / 100; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 78 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 79 | /* rx congestion start/end threshold */ |
| 80 | llcp_cb.overall_rx_congest_start = |
| 81 | (uint8_t)((llcp_cb.num_rx_buff * LLCP_RX_CONGEST_START) / 100); |
| 82 | llcp_cb.overall_rx_congest_end = |
| 83 | (uint8_t)((llcp_cb.num_rx_buff * LLCP_RX_CONGEST_END) / 100); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 84 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 85 | /* max number of buffers for receiving data on logical data link */ |
| 86 | llcp_cb.max_num_ll_rx_buff = |
| 87 | (uint8_t)((llcp_cb.num_rx_buff * LLCP_LL_RX_BUFF_LIMIT) / 100); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 88 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 89 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 90 | "num_rx_buff = %d, rx_congest_start = %d, rx_congest_end = %d, " |
| 91 | "max_num_ll_rx_buff = %d", |
| 92 | llcp_cb.num_rx_buff, llcp_cb.overall_rx_congest_start, |
| 93 | llcp_cb.overall_rx_congest_end, llcp_cb.max_num_ll_rx_buff); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 94 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 95 | /* max number of buffers for transmitting data */ |
| 96 | llcp_cb.max_num_tx_buff = (uint8_t)(pool_count - llcp_cb.num_rx_buff); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 97 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 98 | /* max number of buffers for transmitting data on logical data link */ |
| 99 | llcp_cb.max_num_ll_tx_buff = |
| 100 | (uint8_t)((llcp_cb.max_num_tx_buff * LLCP_LL_TX_BUFF_LIMIT) / 100); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 101 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 102 | DLOG_IF(INFO, nfc_debug_enabled) |
| 103 | << StringPrintf("max_num_tx_buff = %d, max_num_ll_tx_buff = %d", |
| 104 | llcp_cb.max_num_tx_buff, llcp_cb.max_num_ll_tx_buff); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 105 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 106 | llcp_cb.ll_tx_uncongest_ntf_start_sap = LLCP_SAP_SDP + 1; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 107 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 108 | LLCP_RegisterServer(LLCP_SAP_SDP, LLCP_LINK_TYPE_DATA_LINK_CONNECTION, |
| 109 | "urn:nfc:sn:sdp", llcp_sdp_proc_data); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /******************************************************************************* |
| 113 | ** |
| 114 | ** Function llcp_cleanup |
| 115 | ** |
| 116 | ** Description This function is called once at closing to clean up |
| 117 | ** |
| 118 | ** Returns void |
| 119 | ** |
| 120 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 121 | void llcp_cleanup(void) { |
| 122 | uint8_t sap; |
| 123 | tLLCP_APP_CB* p_app_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 124 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 125 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 126 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 127 | for (sap = LLCP_SAP_SDP; sap < LLCP_NUM_SAPS; sap++) { |
| 128 | p_app_cb = llcp_util_get_app_cb(sap); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 129 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 130 | if ((p_app_cb) && (p_app_cb->p_app_cback)) { |
| 131 | LLCP_Deregister(sap); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 132 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 133 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 134 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 135 | nfc_stop_quick_timer(&llcp_cb.lcb.inact_timer); |
| 136 | nfc_stop_quick_timer(&llcp_cb.lcb.timer); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /******************************************************************************* |
| 140 | ** |
| 141 | ** Function llcp_process_timeout |
| 142 | ** |
| 143 | ** Description This function is called when an LLCP-related timeout occurs |
| 144 | ** |
| 145 | ** Returns void |
| 146 | ** |
| 147 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 148 | void llcp_process_timeout(TIMER_LIST_ENT* p_tle) { |
| 149 | uint8_t reason; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 150 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 151 | DLOG_IF(INFO, nfc_debug_enabled) |
| 152 | << StringPrintf("llcp_process_timeout: event=%d", p_tle->event); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 153 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 154 | switch (p_tle->event) { |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 155 | case NFC_TTYPE_LLCP_LINK_MANAGER: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 156 | /* Link timeout or Symm timeout */ |
| 157 | llcp_link_process_link_timeout(); |
| 158 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 159 | |
| 160 | case NFC_TTYPE_LLCP_LINK_INACT: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 161 | /* inactivity timeout */ |
| 162 | llcp_link_deactivate(LLCP_LINK_LOCAL_INITIATED); |
| 163 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 164 | |
| 165 | case NFC_TTYPE_LLCP_DATA_LINK: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 166 | reason = LLCP_SAP_DISCONNECT_REASON_TIMEOUT; |
| 167 | llcp_dlsm_execute((tLLCP_DLCB*)(p_tle->param), LLCP_DLC_EVENT_TIMEOUT, |
| 168 | &reason); |
| 169 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 170 | |
| 171 | case NFC_TTYPE_LLCP_DELAY_FIRST_PDU: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 172 | llcp_link_check_send_data(); |
| 173 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 174 | |
| 175 | default: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 176 | break; |
| 177 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 178 | } |