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 | * NFA interface to LLCP |
| 22 | * |
| 23 | ******************************************************************************/ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 24 | #include <android-base/stringprintf.h> |
| 25 | #include <base/logging.h> |
| 26 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 27 | #include "nfa_p2p_api.h" |
| 28 | #include "nfa_p2p_int.h" |
| 29 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 30 | using android::base::StringPrintf; |
| 31 | |
| 32 | extern bool nfc_debug_enabled; |
| 33 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 34 | /***************************************************************************** |
| 35 | ** Constants |
| 36 | *****************************************************************************/ |
| 37 | |
| 38 | /******************************************************************************* |
| 39 | ** |
| 40 | ** Function NFA_P2pRegisterServer |
| 41 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 42 | ** Description This function is called to listen to a SAP as server on |
| 43 | ** LLCP. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 44 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 45 | ** NFA_P2P_REG_SERVER_EVT will be returned with status and |
| 46 | ** handle. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 47 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 48 | ** If server_sap is set to NFA_P2P_ANY_SAP, then NFA will |
| 49 | ** allocate a SAP between LLCP_LOWER_BOUND_SDP_SAP and |
| 50 | ** LLCP_UPPER_BOUND_SDP_SAP Otherwise, server_sap must be |
| 51 | ** between (LLCP_SDP_SAP + 1) and LLCP_UPPER_BOUND_SDP_SAP |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 52 | ** |
| 53 | ** link_type : NFA_P2P_LLINK_TYPE and/or NFA_P2P_DLINK_TYPE |
| 54 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 55 | ** Note: If RF discovery is started, |
| 56 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 57 | ** happen before calling this function |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 58 | ** |
| 59 | ** Returns NFA_STATUS_OK if successfully initiated |
| 60 | ** NFA_STATUS_FAILED otherwise |
| 61 | ** |
| 62 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 63 | tNFA_STATUS NFA_P2pRegisterServer(uint8_t server_sap, |
| 64 | tNFA_P2P_LINK_TYPE link_type, |
| 65 | char* p_service_name, |
| 66 | tNFA_P2P_CBACK* p_cback) { |
| 67 | tNFA_P2P_API_REG_SERVER* p_msg; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 68 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 69 | DLOG_IF(INFO, nfc_debug_enabled) |
| 70 | << StringPrintf("server_sap:0x%02x, link_type:0x%x, SN:<%s>", server_sap, |
| 71 | link_type, p_service_name); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 72 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 73 | if ((server_sap != NFA_P2P_ANY_SAP) && |
| 74 | ((server_sap <= LLCP_SAP_SDP) || |
| 75 | (server_sap > LLCP_UPPER_BOUND_SDP_SAP))) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 76 | LOG(ERROR) << StringPrintf("server_sap must be between %d and %d", |
| 77 | LLCP_SAP_SDP + 1, LLCP_UPPER_BOUND_SDP_SAP); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 78 | return (NFA_STATUS_FAILED); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 79 | } else if (((link_type & NFA_P2P_LLINK_TYPE) == 0x00) && |
| 80 | ((link_type & NFA_P2P_DLINK_TYPE) == 0x00)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 81 | LOG(ERROR) << StringPrintf("link type (0x%x) must be specified", link_type); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 82 | return (NFA_STATUS_FAILED); |
| 83 | } |
| 84 | |
| 85 | if ((p_msg = (tNFA_P2P_API_REG_SERVER*)GKI_getbuf( |
| 86 | sizeof(tNFA_P2P_API_REG_SERVER))) != NULL) { |
| 87 | p_msg->hdr.event = NFA_P2P_API_REG_SERVER_EVT; |
| 88 | |
| 89 | p_msg->server_sap = server_sap; |
| 90 | p_msg->link_type = link_type; |
| 91 | |
| 92 | strncpy(p_msg->service_name, p_service_name, LLCP_MAX_SN_LEN); |
| 93 | p_msg->service_name[LLCP_MAX_SN_LEN] = 0; |
| 94 | |
| 95 | p_msg->p_cback = p_cback; |
| 96 | |
| 97 | nfa_sys_sendmsg(p_msg); |
| 98 | |
| 99 | return (NFA_STATUS_OK); |
| 100 | } |
| 101 | |
| 102 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /******************************************************************************* |
| 106 | ** |
| 107 | ** Function NFA_P2pRegisterClient |
| 108 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 109 | ** Description This function is called to register a client service on |
| 110 | ** LLCP. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 111 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 112 | ** NFA_P2P_REG_CLIENT_EVT will be returned with status and |
| 113 | ** handle. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 114 | ** |
| 115 | ** link_type : NFA_P2P_LLINK_TYPE and/or NFA_P2P_DLINK_TYPE |
| 116 | ** |
| 117 | ** Returns NFA_STATUS_OK if successfully initiated |
| 118 | ** NFA_STATUS_FAILED otherwise |
| 119 | ** |
| 120 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 121 | tNFA_STATUS NFA_P2pRegisterClient(tNFA_P2P_LINK_TYPE link_type, |
| 122 | tNFA_P2P_CBACK* p_cback) { |
| 123 | tNFA_P2P_API_REG_CLIENT* p_msg; |
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) << StringPrintf("link_type:0x%x", link_type); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 126 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 127 | if (((link_type & NFA_P2P_LLINK_TYPE) == 0x00) && |
| 128 | ((link_type & NFA_P2P_DLINK_TYPE) == 0x00)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 129 | LOG(ERROR) << StringPrintf("link type (0x%x) must be specified", link_type); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 130 | return (NFA_STATUS_FAILED); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | if ((p_msg = (tNFA_P2P_API_REG_CLIENT*)GKI_getbuf( |
| 134 | sizeof(tNFA_P2P_API_REG_CLIENT))) != NULL) { |
| 135 | p_msg->hdr.event = NFA_P2P_API_REG_CLIENT_EVT; |
| 136 | |
| 137 | p_msg->p_cback = p_cback; |
| 138 | p_msg->link_type = link_type; |
| 139 | |
| 140 | nfa_sys_sendmsg(p_msg); |
| 141 | |
| 142 | return (NFA_STATUS_OK); |
| 143 | } |
| 144 | |
| 145 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /******************************************************************************* |
| 149 | ** |
| 150 | ** Function NFA_P2pDeregister |
| 151 | ** |
| 152 | ** Description This function is called to stop listening to a SAP as server |
| 153 | ** or stop client service on LLCP. |
| 154 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 155 | ** Note: If this function is called to de-register a server and RF |
| 156 | ** discovery is started, |
| 157 | ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should |
| 158 | ** happen before calling this function |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 159 | ** |
| 160 | ** Returns NFA_STATUS_OK if successfully initiated |
| 161 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 162 | ** NFA_STATUS_FAILED otherwise |
| 163 | ** |
| 164 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 165 | tNFA_STATUS NFA_P2pDeregister(tNFA_HANDLE handle) { |
| 166 | tNFA_P2P_API_DEREG* p_msg; |
| 167 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 168 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 169 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:0x%02X", handle); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 170 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 171 | xx = handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 172 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 173 | if ((xx >= NFA_P2P_NUM_SAP) || (nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 174 | LOG(ERROR) << StringPrintf("Handle is invalid or not registered"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 175 | return (NFA_STATUS_BAD_HANDLE); |
| 176 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 177 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 178 | if ((p_msg = (tNFA_P2P_API_DEREG*)GKI_getbuf(sizeof(tNFA_P2P_API_DEREG))) != |
| 179 | NULL) { |
| 180 | p_msg->hdr.event = NFA_P2P_API_DEREG_EVT; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 181 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 182 | p_msg->handle = handle; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 183 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 184 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 185 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 186 | return (NFA_STATUS_OK); |
| 187 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 188 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 189 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /******************************************************************************* |
| 193 | ** |
| 194 | ** Function NFA_P2pAcceptConn |
| 195 | ** |
| 196 | ** Description This function is called to accept a request of data link |
| 197 | ** connection to a listening SAP on LLCP after receiving |
| 198 | ** NFA_P2P_CONN_REQ_EVT. |
| 199 | ** |
| 200 | ** Returns NFA_STATUS_OK if successfully initiated |
| 201 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 202 | ** NFA_STATUS_FAILED otherwise |
| 203 | ** |
| 204 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 205 | tNFA_STATUS NFA_P2pAcceptConn(tNFA_HANDLE handle, uint16_t miu, uint8_t rw) { |
| 206 | tNFA_P2P_API_ACCEPT_CONN* p_msg; |
| 207 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 208 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 209 | DLOG_IF(INFO, nfc_debug_enabled) |
| 210 | << StringPrintf("handle:0x%02X, MIU:%d, RW:%d", handle, miu, rw); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 211 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 212 | xx = handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 213 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 214 | if (!(xx & NFA_P2P_HANDLE_FLAG_CONN)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 215 | LOG(ERROR) << StringPrintf("Connection Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 216 | return (NFA_STATUS_BAD_HANDLE); |
| 217 | } else { |
| 218 | xx &= ~NFA_P2P_HANDLE_FLAG_CONN; |
| 219 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 220 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 221 | if ((xx >= LLCP_MAX_DATA_LINK) || (nfa_p2p_cb.conn_cb[xx].flags == 0)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 222 | LOG(ERROR) << StringPrintf("Connection Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 223 | return (NFA_STATUS_BAD_HANDLE); |
| 224 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 225 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 226 | if ((miu < LLCP_DEFAULT_MIU) || (nfa_p2p_cb.local_link_miu < miu)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 227 | LOG(ERROR) << StringPrintf("MIU(%d) must be between %d and %d", miu, |
| 228 | LLCP_DEFAULT_MIU, nfa_p2p_cb.local_link_miu); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 229 | } else if ((p_msg = (tNFA_P2P_API_ACCEPT_CONN*)GKI_getbuf( |
| 230 | sizeof(tNFA_P2P_API_ACCEPT_CONN))) != NULL) { |
| 231 | p_msg->hdr.event = NFA_P2P_API_ACCEPT_CONN_EVT; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 232 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 233 | p_msg->conn_handle = handle; |
| 234 | p_msg->miu = miu; |
| 235 | p_msg->rw = rw; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 236 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 237 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 238 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 239 | return (NFA_STATUS_OK); |
| 240 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 241 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 242 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /******************************************************************************* |
| 246 | ** |
| 247 | ** Function NFA_P2pRejectConn |
| 248 | ** |
| 249 | ** Description This function is called to reject a request of data link |
| 250 | ** connection to a listening SAP on LLCP after receiving |
| 251 | ** NFA_P2P_CONN_REQ_EVT. |
| 252 | ** |
| 253 | ** Returns NFA_STATUS_OK if successfully initiated |
| 254 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 255 | ** NFA_STATUS_FAILED otherwise |
| 256 | ** |
| 257 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 258 | tNFA_STATUS NFA_P2pRejectConn(tNFA_HANDLE handle) { |
| 259 | tNFA_P2P_API_REJECT_CONN* p_msg; |
| 260 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 261 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 262 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:0x%02X", handle); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 263 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 264 | xx = handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 265 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 266 | if (!(xx & NFA_P2P_HANDLE_FLAG_CONN)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 267 | LOG(ERROR) << StringPrintf("Connection Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 268 | return (NFA_STATUS_BAD_HANDLE); |
| 269 | } else { |
| 270 | xx &= ~NFA_P2P_HANDLE_FLAG_CONN; |
| 271 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 272 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 273 | if ((xx >= LLCP_MAX_DATA_LINK) || (nfa_p2p_cb.conn_cb[xx].flags == 0)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 274 | LOG(ERROR) << StringPrintf("Connection Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 275 | return (NFA_STATUS_BAD_HANDLE); |
| 276 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 277 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 278 | if ((p_msg = (tNFA_P2P_API_REJECT_CONN*)GKI_getbuf( |
| 279 | sizeof(tNFA_P2P_API_REJECT_CONN))) != NULL) { |
| 280 | p_msg->hdr.event = NFA_P2P_API_REJECT_CONN_EVT; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 281 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 282 | p_msg->conn_handle = handle; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 283 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 284 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 285 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 286 | return (NFA_STATUS_OK); |
| 287 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 288 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 289 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /******************************************************************************* |
| 293 | ** |
| 294 | ** Function NFA_P2pDisconnect |
| 295 | ** |
| 296 | ** Description This function is called to disconnect an existing or |
| 297 | ** connecting data link connection. |
| 298 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 299 | ** discard any pending data on data link connection if flush is |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 300 | ** set to TRUE |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 301 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 302 | ** NFA_P2P_DISC_EVT will be returned after data link connection |
| 303 | ** is disconnected |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 304 | ** |
| 305 | ** Returns NFA_STATUS_OK if successfully initiated |
| 306 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 307 | ** NFA_STATUS_FAILED otherwise |
| 308 | ** |
| 309 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 310 | tNFA_STATUS NFA_P2pDisconnect(tNFA_HANDLE handle, bool flush) { |
| 311 | tNFA_P2P_API_DISCONNECT* p_msg; |
| 312 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 313 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 314 | DLOG_IF(INFO, nfc_debug_enabled) |
| 315 | << StringPrintf("handle:0x%02X, flush=%d", handle, flush); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 316 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 317 | xx = handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 318 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 319 | if (xx & NFA_P2P_HANDLE_FLAG_CONN) { |
| 320 | xx &= ~NFA_P2P_HANDLE_FLAG_CONN; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 321 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 322 | if ((xx >= LLCP_MAX_DATA_LINK) || (nfa_p2p_cb.conn_cb[xx].flags == 0)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 323 | LOG(ERROR) << StringPrintf("Connection Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 324 | return (NFA_STATUS_BAD_HANDLE); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 325 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 326 | } else { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 327 | LOG(ERROR) << StringPrintf("Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 328 | return (NFA_STATUS_BAD_HANDLE); |
| 329 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 330 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 331 | if ((p_msg = (tNFA_P2P_API_DISCONNECT*)GKI_getbuf( |
| 332 | sizeof(tNFA_P2P_API_DISCONNECT))) != NULL) { |
| 333 | p_msg->hdr.event = NFA_P2P_API_DISCONNECT_EVT; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 334 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 335 | p_msg->conn_handle = handle; |
| 336 | p_msg->flush = flush; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 337 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 338 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 339 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 340 | return (NFA_STATUS_OK); |
| 341 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 342 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 343 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /******************************************************************************* |
| 347 | ** |
| 348 | ** Function NFA_P2pConnectByName |
| 349 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 350 | ** Description This function is called to create a connection-oriented |
| 351 | ** transport by a service name. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 352 | ** NFA_P2P_CONNECTED_EVT if success |
| 353 | ** NFA_P2P_DISC_EVT if failed |
| 354 | ** |
| 355 | ** Returns NFA_STATUS_OK if successfully initiated |
| 356 | ** NFA_STATUS_BAD_HANDLE if client is not registered |
| 357 | ** NFA_STATUS_FAILED otherwise |
| 358 | ** |
| 359 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 360 | tNFA_STATUS NFA_P2pConnectByName(tNFA_HANDLE client_handle, |
| 361 | char* p_service_name, uint16_t miu, |
| 362 | uint8_t rw) { |
| 363 | tNFA_P2P_API_CONNECT* p_msg; |
| 364 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 365 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 366 | DLOG_IF(INFO, nfc_debug_enabled) |
| 367 | << StringPrintf("client_handle:0x%x, SN:<%s>, MIU:%d, RW:%d", |
| 368 | client_handle, p_service_name, miu, rw); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 369 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 370 | xx = client_handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 371 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 372 | if ((xx >= NFA_P2P_NUM_SAP) || (nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 373 | LOG(ERROR) << StringPrintf("Client Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 374 | return (NFA_STATUS_BAD_HANDLE); |
| 375 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 376 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 377 | if ((miu < LLCP_DEFAULT_MIU) || |
| 378 | (nfa_p2p_cb.llcp_state != NFA_P2P_LLCP_STATE_ACTIVATED) || |
| 379 | (nfa_p2p_cb.local_link_miu < miu)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 380 | LOG(ERROR) << StringPrintf( |
| 381 | "MIU(%d) must be between %d and %d or LLCP " |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 382 | "link is not activated", |
| 383 | miu, LLCP_DEFAULT_MIU, nfa_p2p_cb.local_link_miu); |
| 384 | } else if ((p_msg = (tNFA_P2P_API_CONNECT*)GKI_getbuf( |
| 385 | sizeof(tNFA_P2P_API_CONNECT))) != NULL) { |
| 386 | p_msg->hdr.event = NFA_P2P_API_CONNECT_EVT; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 387 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 388 | strncpy(p_msg->service_name, p_service_name, LLCP_MAX_SN_LEN); |
| 389 | p_msg->service_name[LLCP_MAX_SN_LEN] = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 390 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 391 | p_msg->dsap = LLCP_INVALID_SAP; |
| 392 | p_msg->miu = miu; |
| 393 | p_msg->rw = rw; |
| 394 | p_msg->client_handle = client_handle; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 395 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 396 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 397 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 398 | return (NFA_STATUS_OK); |
| 399 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 400 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 401 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /******************************************************************************* |
| 405 | ** |
| 406 | ** Function NFA_P2pConnectBySap |
| 407 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 408 | ** Description This function is called to create a connection-oriented |
| 409 | ** transport by a SAP. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 410 | ** NFA_P2P_CONNECTED_EVT if success |
| 411 | ** NFA_P2P_DISC_EVT if failed |
| 412 | ** |
| 413 | ** Returns NFA_STATUS_OK if successfully initiated |
| 414 | ** NFA_STATUS_BAD_HANDLE if client is not registered |
| 415 | ** NFA_STATUS_FAILED otherwise |
| 416 | ** |
| 417 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 418 | tNFA_STATUS NFA_P2pConnectBySap(tNFA_HANDLE client_handle, uint8_t dsap, |
| 419 | uint16_t miu, uint8_t rw) { |
| 420 | tNFA_P2P_API_CONNECT* p_msg; |
| 421 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 422 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 423 | DLOG_IF(INFO, nfc_debug_enabled) |
| 424 | << StringPrintf("client_handle:0x%x, DSAP:0x%02X, MIU:%d, RW:%d", |
| 425 | client_handle, dsap, miu, rw); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 426 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 427 | xx = client_handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 428 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 429 | if ((xx >= NFA_P2P_NUM_SAP) || (nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 430 | LOG(ERROR) << StringPrintf("Client Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 431 | return (NFA_STATUS_BAD_HANDLE); |
| 432 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 433 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 434 | if ((miu < LLCP_DEFAULT_MIU) || |
| 435 | (nfa_p2p_cb.llcp_state != NFA_P2P_LLCP_STATE_ACTIVATED) || |
| 436 | (nfa_p2p_cb.local_link_miu < miu)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 437 | LOG(ERROR) << StringPrintf( |
| 438 | "MIU(%d) must be between %d and %d, or LLCP " |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 439 | "link is not activated", |
| 440 | miu, LLCP_DEFAULT_MIU, nfa_p2p_cb.local_link_miu); |
| 441 | } else if ((p_msg = (tNFA_P2P_API_CONNECT*)GKI_getbuf( |
| 442 | sizeof(tNFA_P2P_API_CONNECT))) != NULL) { |
| 443 | p_msg->hdr.event = NFA_P2P_API_CONNECT_EVT; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 444 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 445 | p_msg->service_name[LLCP_MAX_SN_LEN] = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 446 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 447 | p_msg->dsap = dsap; |
| 448 | p_msg->miu = miu; |
| 449 | p_msg->rw = rw; |
| 450 | p_msg->client_handle = client_handle; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 451 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 452 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 453 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 454 | return (NFA_STATUS_OK); |
| 455 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 456 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 457 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /******************************************************************************* |
| 461 | ** |
| 462 | ** Function NFA_P2pSendUI |
| 463 | ** |
| 464 | ** Description This function is called to send data on connectionless |
| 465 | ** transport. |
| 466 | ** |
| 467 | ** Returns NFA_STATUS_OK if successfully initiated |
| 468 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 469 | ** NFA_STATUS_BAD_LENGTH if data length is more than remote |
| 470 | ** link MIU |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 471 | ** NFA_STATUS_CONGESTED if congested |
| 472 | ** NFA_STATUS_FAILED otherwise |
| 473 | ** |
| 474 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 475 | tNFA_STATUS NFA_P2pSendUI(tNFA_HANDLE handle, uint8_t dsap, uint16_t length, |
| 476 | uint8_t* p_data) { |
| 477 | tNFA_P2P_API_SEND_UI* p_msg; |
| 478 | tNFA_STATUS ret_status = NFA_STATUS_FAILED; |
| 479 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 480 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 481 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 482 | "handle:0x%X, DSAP:0x%02X, length:%d", handle, dsap, length); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 483 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 484 | GKI_sched_lock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 485 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 486 | xx = handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 487 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 488 | if ((xx >= NFA_P2P_NUM_SAP) || (nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 489 | LOG(ERROR) << StringPrintf("Handle (0x%X) is not valid", handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 490 | ret_status = NFA_STATUS_BAD_HANDLE; |
| 491 | } else if (length > nfa_p2p_cb.remote_link_miu) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 492 | LOG(ERROR) << StringPrintf( |
| 493 | "handle:0x%X, length(%d) must be less than remote " |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 494 | "link MIU(%d)", |
| 495 | handle, length, nfa_p2p_cb.remote_link_miu); |
| 496 | ret_status = NFA_STATUS_BAD_LENGTH; |
| 497 | } else if (nfa_p2p_cb.sap_cb[xx].flags & NFA_P2P_SAP_FLAG_LLINK_CONGESTED) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 498 | LOG(WARNING) << StringPrintf( |
| 499 | "handle:0x%X, logical data link is already congested", handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 500 | ret_status = NFA_STATUS_CONGESTED; |
| 501 | } else if (LLCP_IsLogicalLinkCongested( |
| 502 | (uint8_t)xx, nfa_p2p_cb.sap_cb[xx].num_pending_ui_pdu, |
| 503 | nfa_p2p_cb.total_pending_ui_pdu, |
| 504 | nfa_p2p_cb.total_pending_i_pdu)) { |
| 505 | nfa_p2p_cb.sap_cb[xx].flags |= NFA_P2P_SAP_FLAG_LLINK_CONGESTED; |
| 506 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 507 | LOG(WARNING) << StringPrintf("handle:0x%X, logical data link is congested", |
| 508 | handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 509 | ret_status = NFA_STATUS_CONGESTED; |
| 510 | } else if ((p_msg = (tNFA_P2P_API_SEND_UI*)GKI_getbuf( |
| 511 | sizeof(tNFA_P2P_API_SEND_UI))) != NULL) { |
| 512 | p_msg->hdr.event = NFA_P2P_API_SEND_UI_EVT; |
| 513 | |
| 514 | p_msg->handle = handle; |
| 515 | p_msg->dsap = dsap; |
| 516 | |
| 517 | p_msg->p_msg = (NFC_HDR*)GKI_getpoolbuf(LLCP_POOL_ID); |
| 518 | if (p_msg->p_msg != NULL) { |
| 519 | p_msg->p_msg->len = length; |
| 520 | p_msg->p_msg->offset = LLCP_MIN_OFFSET; |
| 521 | memcpy(((uint8_t*)(p_msg->p_msg + 1) + p_msg->p_msg->offset), p_data, |
| 522 | length); |
| 523 | |
| 524 | /* increase number of tx UI PDU which is not processed by NFA for |
| 525 | * congestion control */ |
| 526 | nfa_p2p_cb.sap_cb[xx].num_pending_ui_pdu++; |
| 527 | nfa_p2p_cb.total_pending_ui_pdu++; |
| 528 | nfa_sys_sendmsg(p_msg); |
| 529 | |
| 530 | ret_status = NFA_STATUS_OK; |
| 531 | } else { |
| 532 | GKI_freebuf(p_msg); |
| 533 | |
| 534 | nfa_p2p_cb.sap_cb[xx].flags |= NFA_P2P_SAP_FLAG_LLINK_CONGESTED; |
| 535 | ret_status = NFA_STATUS_CONGESTED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 536 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 537 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 538 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 539 | GKI_sched_unlock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 540 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 541 | return (ret_status); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /******************************************************************************* |
| 545 | ** |
| 546 | ** Function NFA_P2pReadUI |
| 547 | ** |
| 548 | ** Description This function is called to read data on connectionless |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 549 | ** transport when receiving NFA_P2P_DATA_EVT with |
| 550 | ** NFA_P2P_LLINK_TYPE. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 551 | ** |
| 552 | ** - Remote SAP who sent UI PDU is returned. |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 553 | ** - Information of UI PDU up to max_data_len is copied into |
| 554 | ** p_data. |
| 555 | ** - If more information of UI PDU or more UI PDU in queue then |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 556 | ** more is returned to TRUE. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 557 | ** - Information of next UI PDU is not concatenated. |
| 558 | ** |
| 559 | ** Returns NFA_STATUS_OK if successfully initiated |
| 560 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 561 | ** |
| 562 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 563 | tNFA_STATUS NFA_P2pReadUI(tNFA_HANDLE handle, uint32_t max_data_len, |
| 564 | uint8_t* p_remote_sap, uint32_t* p_data_len, |
| 565 | uint8_t* p_data, bool* p_more) { |
| 566 | tNFA_STATUS ret_status; |
| 567 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 568 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 569 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:0x%X", handle); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 570 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 571 | GKI_sched_lock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 572 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 573 | xx = handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 574 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 575 | if ((xx >= NFA_P2P_NUM_SAP) || (nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 576 | LOG(ERROR) << StringPrintf("Handle (0x%X) is not valid", handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 577 | ret_status = NFA_STATUS_BAD_HANDLE; |
| 578 | } else { |
| 579 | *p_more = LLCP_ReadLogicalLinkData((uint8_t)xx, max_data_len, p_remote_sap, |
| 580 | p_data_len, p_data); |
| 581 | ret_status = NFA_STATUS_OK; |
| 582 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 583 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 584 | GKI_sched_unlock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 585 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 586 | return (ret_status); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | /******************************************************************************* |
| 590 | ** |
| 591 | ** Function NFA_P2pFlushUI |
| 592 | ** |
| 593 | ** Description This function is called to flush data on connectionless |
| 594 | ** transport. |
| 595 | ** |
| 596 | ** Returns NFA_STATUS_OK if successfully initiated |
| 597 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 598 | ** |
| 599 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 600 | tNFA_STATUS NFA_P2pFlushUI(tNFA_HANDLE handle, uint32_t* p_length) { |
| 601 | tNFA_STATUS ret_status; |
| 602 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 603 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 604 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:0x%X", handle); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 605 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 606 | GKI_sched_lock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 607 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 608 | xx = handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 609 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 610 | if ((xx >= NFA_P2P_NUM_SAP) || (nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 611 | LOG(ERROR) << StringPrintf("Handle (0x%X) is not valid", handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 612 | ret_status = NFA_STATUS_BAD_HANDLE; |
| 613 | *p_length = 0; |
| 614 | } else { |
| 615 | *p_length = LLCP_FlushLogicalLinkRxData((uint8_t)xx); |
| 616 | ret_status = NFA_STATUS_OK; |
| 617 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 618 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 619 | GKI_sched_unlock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 620 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 621 | return (ret_status); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /******************************************************************************* |
| 625 | ** |
| 626 | ** Function NFA_P2pSendData |
| 627 | ** |
| 628 | ** Description This function is called to send data on connection-oriented |
| 629 | ** transport. |
| 630 | ** |
| 631 | ** Returns NFA_STATUS_OK if successfully initiated |
| 632 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 633 | ** NFA_STATUS_BAD_LENGTH if data length is more than remote MIU |
| 634 | ** NFA_STATUS_CONGESTED if congested |
| 635 | ** NFA_STATUS_FAILED otherwise |
| 636 | ** |
| 637 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 638 | tNFA_STATUS NFA_P2pSendData(tNFA_HANDLE handle, uint16_t length, |
| 639 | uint8_t* p_data) { |
| 640 | tNFA_P2P_API_SEND_DATA* p_msg; |
| 641 | tNFA_STATUS ret_status = NFA_STATUS_FAILED; |
| 642 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 643 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 644 | DLOG_IF(INFO, nfc_debug_enabled) |
| 645 | << StringPrintf("handle:0x%X, length:%d", handle, length); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 646 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 647 | GKI_sched_lock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 648 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 649 | xx = handle & NFA_HANDLE_MASK; |
| 650 | xx &= ~NFA_P2P_HANDLE_FLAG_CONN; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 651 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 652 | if ((!(handle & NFA_P2P_HANDLE_FLAG_CONN)) || (xx >= LLCP_MAX_DATA_LINK) || |
| 653 | (nfa_p2p_cb.conn_cb[xx].flags == 0)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 654 | LOG(ERROR) << StringPrintf("Handle(0x%X) is not valid", handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 655 | ret_status = NFA_STATUS_BAD_HANDLE; |
| 656 | } else if (nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_REMOTE_RW_ZERO) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 657 | LOG(ERROR) << StringPrintf("handle:0x%X, Remote set RW to 0 (flow off)", |
| 658 | handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 659 | ret_status = NFA_STATUS_FAILED; |
| 660 | } else if (nfa_p2p_cb.conn_cb[xx].remote_miu < length) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 661 | LOG(ERROR) << StringPrintf("handle:0x%X, Data more than remote MIU(%d)", |
| 662 | handle, nfa_p2p_cb.conn_cb[xx].remote_miu); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 663 | ret_status = NFA_STATUS_BAD_LENGTH; |
| 664 | } else if (nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_CONGESTED) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 665 | LOG(WARNING) << StringPrintf( |
| 666 | "handle:0x%X, data link connection is already " |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 667 | "congested", |
| 668 | handle); |
| 669 | ret_status = NFA_STATUS_CONGESTED; |
| 670 | } else if (LLCP_IsDataLinkCongested(nfa_p2p_cb.conn_cb[xx].local_sap, |
| 671 | nfa_p2p_cb.conn_cb[xx].remote_sap, |
| 672 | nfa_p2p_cb.conn_cb[xx].num_pending_i_pdu, |
| 673 | nfa_p2p_cb.total_pending_ui_pdu, |
| 674 | nfa_p2p_cb.total_pending_i_pdu)) { |
| 675 | nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_CONGESTED; |
| 676 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 677 | LOG(WARNING) << StringPrintf( |
| 678 | "handle:0x%X, data link connection is congested", handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 679 | ret_status = NFA_STATUS_CONGESTED; |
| 680 | } else if ((p_msg = (tNFA_P2P_API_SEND_DATA*)GKI_getbuf( |
| 681 | sizeof(tNFA_P2P_API_SEND_DATA))) != NULL) { |
| 682 | p_msg->hdr.event = NFA_P2P_API_SEND_DATA_EVT; |
| 683 | |
| 684 | p_msg->conn_handle = handle; |
| 685 | |
| 686 | p_msg->p_msg = (NFC_HDR*)GKI_getpoolbuf(LLCP_POOL_ID); |
| 687 | if (p_msg->p_msg != NULL) { |
| 688 | p_msg->p_msg->len = length; |
| 689 | p_msg->p_msg->offset = LLCP_MIN_OFFSET; |
| 690 | memcpy(((uint8_t*)(p_msg->p_msg + 1) + p_msg->p_msg->offset), p_data, |
| 691 | length); |
| 692 | |
| 693 | /* increase number of tx I PDU which is not processed by NFA for |
| 694 | * congestion control */ |
| 695 | nfa_p2p_cb.conn_cb[xx].num_pending_i_pdu++; |
| 696 | nfa_p2p_cb.total_pending_i_pdu++; |
| 697 | nfa_sys_sendmsg(p_msg); |
| 698 | |
| 699 | ret_status = NFA_STATUS_OK; |
| 700 | } else { |
| 701 | GKI_freebuf(p_msg); |
| 702 | nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_CONGESTED; |
| 703 | ret_status = NFA_STATUS_CONGESTED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 704 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 705 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 706 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 707 | GKI_sched_unlock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 708 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 709 | return (ret_status); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /******************************************************************************* |
| 713 | ** |
| 714 | ** Function NFA_P2pReadData |
| 715 | ** |
| 716 | ** Description This function is called to read data on connection-oriented |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 717 | ** transport when receiving NFA_P2P_DATA_EVT with |
| 718 | ** NFA_P2P_DLINK_TYPE. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 719 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 720 | ** - Information of I PDU is copied into p_data up to |
| 721 | ** max_data_len. |
| 722 | ** - If more information of I PDU or more I PDU in queue, then |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 723 | ** more is returned to TRUE. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 724 | ** - Information of next I PDU is not concatenated. |
| 725 | ** |
| 726 | ** Returns NFA_STATUS_OK if successfully initiated |
| 727 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 728 | ** |
| 729 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 730 | tNFA_STATUS NFA_P2pReadData(tNFA_HANDLE handle, uint32_t max_data_len, |
| 731 | uint32_t* p_data_len, uint8_t* p_data, |
| 732 | bool* p_more) { |
| 733 | tNFA_STATUS ret_status; |
| 734 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 735 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 736 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:0x%X", handle); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 737 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 738 | GKI_sched_lock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 739 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 740 | xx = handle & NFA_HANDLE_MASK; |
| 741 | xx &= ~NFA_P2P_HANDLE_FLAG_CONN; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 742 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 743 | if ((!(handle & NFA_P2P_HANDLE_FLAG_CONN)) || (xx >= LLCP_MAX_DATA_LINK) || |
| 744 | (nfa_p2p_cb.conn_cb[xx].flags == 0)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 745 | LOG(ERROR) << StringPrintf("Handle(0x%X) is not valid", handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 746 | ret_status = NFA_STATUS_BAD_HANDLE; |
| 747 | } else { |
| 748 | *p_more = LLCP_ReadDataLinkData(nfa_p2p_cb.conn_cb[xx].local_sap, |
| 749 | nfa_p2p_cb.conn_cb[xx].remote_sap, |
| 750 | max_data_len, p_data_len, p_data); |
| 751 | ret_status = NFA_STATUS_OK; |
| 752 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 753 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 754 | GKI_sched_unlock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 755 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 756 | return (ret_status); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /******************************************************************************* |
| 760 | ** |
| 761 | ** Function NFA_P2pFlushData |
| 762 | ** |
| 763 | ** Description This function is called to flush data on connection-oriented |
| 764 | ** transport. |
| 765 | ** |
| 766 | ** Returns NFA_STATUS_OK if successfully initiated |
| 767 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 768 | ** |
| 769 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 770 | tNFA_STATUS NFA_P2pFlushData(tNFA_HANDLE handle, uint32_t* p_length) { |
| 771 | tNFA_STATUS ret_status; |
| 772 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 773 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 774 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:0x%X", handle); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 775 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 776 | GKI_sched_lock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 777 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 778 | xx = handle & NFA_HANDLE_MASK; |
| 779 | xx &= ~NFA_P2P_HANDLE_FLAG_CONN; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 780 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 781 | if ((!(handle & NFA_P2P_HANDLE_FLAG_CONN)) || (xx >= LLCP_MAX_DATA_LINK) || |
| 782 | (nfa_p2p_cb.conn_cb[xx].flags == 0)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 783 | LOG(ERROR) << StringPrintf("Handle(0x%X) is not valid", handle); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 784 | ret_status = NFA_STATUS_BAD_HANDLE; |
| 785 | } else { |
| 786 | *p_length = LLCP_FlushDataLinkRxData(nfa_p2p_cb.conn_cb[xx].local_sap, |
| 787 | nfa_p2p_cb.conn_cb[xx].remote_sap); |
| 788 | ret_status = NFA_STATUS_OK; |
| 789 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 790 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 791 | GKI_sched_unlock(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 792 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 793 | return (ret_status); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | /******************************************************************************* |
| 797 | ** |
| 798 | ** Function NFA_P2pSetLocalBusy |
| 799 | ** |
| 800 | ** Description This function is called to stop or resume incoming data on |
| 801 | ** connection-oriented transport. |
| 802 | ** |
| 803 | ** Returns NFA_STATUS_OK if successfully initiated |
| 804 | ** NFA_STATUS_BAD_HANDLE if handle is not valid |
| 805 | ** NFA_STATUS_FAILED otherwise |
| 806 | ** |
| 807 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 808 | tNFA_STATUS NFA_P2pSetLocalBusy(tNFA_HANDLE conn_handle, bool is_busy) { |
| 809 | tNFA_P2P_API_SET_LOCAL_BUSY* p_msg; |
| 810 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 811 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 812 | DLOG_IF(INFO, nfc_debug_enabled) |
| 813 | << StringPrintf("conn_handle:0x%02X, is_busy:%d", conn_handle, is_busy); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 814 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 815 | xx = conn_handle & NFA_HANDLE_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 816 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 817 | if (!(xx & NFA_P2P_HANDLE_FLAG_CONN)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 818 | LOG(ERROR) << StringPrintf("Connection Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 819 | return (NFA_STATUS_BAD_HANDLE); |
| 820 | } else { |
| 821 | xx &= ~NFA_P2P_HANDLE_FLAG_CONN; |
| 822 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 823 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 824 | if ((xx >= LLCP_MAX_DATA_LINK) || (nfa_p2p_cb.conn_cb[xx].flags == 0)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 825 | LOG(ERROR) << StringPrintf("Connection Handle is not valid"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 826 | return (NFA_STATUS_BAD_HANDLE); |
| 827 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 828 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 829 | if ((p_msg = (tNFA_P2P_API_SET_LOCAL_BUSY*)GKI_getbuf( |
| 830 | sizeof(tNFA_P2P_API_SET_LOCAL_BUSY))) != NULL) { |
| 831 | p_msg->hdr.event = NFA_P2P_API_SET_LOCAL_BUSY_EVT; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 832 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 833 | p_msg->conn_handle = conn_handle; |
| 834 | p_msg->is_busy = is_busy; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 835 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 836 | nfa_sys_sendmsg(p_msg); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 837 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 838 | return (NFA_STATUS_OK); |
| 839 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 840 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 841 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /******************************************************************************* |
| 845 | ** |
| 846 | ** Function NFA_P2pGetLinkInfo |
| 847 | ** |
| 848 | ** Description This function is called to get local/remote link MIU and |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 849 | ** Well-Known Service list encoded as a 16-bit field of |
| 850 | ** connected LLCP. NFA_P2P_LINK_INFO_EVT will be returned. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 851 | ** |
| 852 | ** Returns NFA_STATUS_OK if successfully initiated |
| 853 | ** NFA_STATUS_BAD_HANDLE if server or client is not registered |
| 854 | ** NFA_STATUS_FAILED otherwise |
| 855 | ** |
| 856 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 857 | tNFA_STATUS NFA_P2pGetLinkInfo(tNFA_HANDLE handle) { |
| 858 | tNFA_P2P_API_GET_LINK_INFO* p_msg; |
| 859 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 860 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 861 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:0x%x", handle); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 862 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 863 | if (nfa_p2p_cb.llcp_state != NFA_P2P_LLCP_STATE_ACTIVATED) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 864 | LOG(ERROR) << StringPrintf("LLCP link is not activated"); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 865 | return (NFA_STATUS_FAILED); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | xx = handle & NFA_HANDLE_MASK; |
| 869 | |
| 870 | if ((xx >= NFA_P2P_NUM_SAP) || (nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 871 | LOG(ERROR) << StringPrintf("Handle is invalid or not registered"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 872 | return (NFA_STATUS_BAD_HANDLE); |
| 873 | } |
| 874 | |
| 875 | if ((p_msg = (tNFA_P2P_API_GET_LINK_INFO*)GKI_getbuf( |
| 876 | sizeof(tNFA_P2P_API_GET_LINK_INFO))) != NULL) { |
| 877 | p_msg->hdr.event = NFA_P2P_API_GET_LINK_INFO_EVT; |
| 878 | |
| 879 | p_msg->handle = handle; |
| 880 | |
| 881 | nfa_sys_sendmsg(p_msg); |
| 882 | |
| 883 | return (NFA_STATUS_OK); |
| 884 | } |
| 885 | |
| 886 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /******************************************************************************* |
| 890 | ** |
| 891 | ** Function NFA_P2pGetRemoteSap |
| 892 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 893 | ** Description This function is called to get SAP associated by service |
| 894 | ** name on connected remote LLCP. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 895 | ** NFA_P2P_SDP_EVT will be returned. |
| 896 | ** |
| 897 | ** Returns NFA_STATUS_OK if successfully initiated |
| 898 | ** NFA_STATUS_BAD_HANDLE if server or client is not registered |
| 899 | ** NFA_STATUS_FAILED otherwise |
| 900 | ** |
| 901 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 902 | tNFA_STATUS NFA_P2pGetRemoteSap(tNFA_HANDLE handle, char* p_service_name) { |
| 903 | tNFA_P2P_API_GET_REMOTE_SAP* p_msg; |
| 904 | tNFA_HANDLE xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 905 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 906 | DLOG_IF(INFO, nfc_debug_enabled) |
| 907 | << StringPrintf("handle:0x%x, SN:<%s>", handle, p_service_name); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 908 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 909 | if (nfa_p2p_cb.llcp_state != NFA_P2P_LLCP_STATE_ACTIVATED) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 910 | LOG(ERROR) << StringPrintf("LLCP link is not activated"); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 911 | return (NFA_STATUS_FAILED); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | xx = handle & NFA_HANDLE_MASK; |
| 915 | |
| 916 | if ((xx >= NFA_P2P_NUM_SAP) || (nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 917 | LOG(ERROR) << StringPrintf("Handle is invalid or not registered"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 918 | return (NFA_STATUS_BAD_HANDLE); |
| 919 | } |
| 920 | |
| 921 | if ((p_msg = (tNFA_P2P_API_GET_REMOTE_SAP*)GKI_getbuf( |
| 922 | sizeof(tNFA_P2P_API_GET_REMOTE_SAP))) != NULL) { |
| 923 | p_msg->hdr.event = NFA_P2P_API_GET_REMOTE_SAP_EVT; |
| 924 | |
| 925 | p_msg->handle = handle; |
| 926 | |
| 927 | strncpy(p_msg->service_name, p_service_name, LLCP_MAX_SN_LEN); |
| 928 | p_msg->service_name[LLCP_MAX_SN_LEN] = 0; |
| 929 | |
| 930 | nfa_sys_sendmsg(p_msg); |
| 931 | |
| 932 | return (NFA_STATUS_OK); |
| 933 | } |
| 934 | |
| 935 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /******************************************************************************* |
| 939 | ** |
| 940 | ** Function NFA_P2pSetLLCPConfig |
| 941 | ** |
| 942 | ** Description This function is called to change LLCP config parameters. |
| 943 | ** Application must call while LLCP is not activated. |
| 944 | ** |
| 945 | ** Parameters descriptions (default value) |
| 946 | ** - Local Link MIU (LLCP_MIU) |
| 947 | ** - Option parameter (LLCP_OPT_VALUE) |
| 948 | ** - Response Waiting Time Index (LLCP_WAITING_TIME) |
| 949 | ** - Local Link Timeout (LLCP_LTO_VALUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 950 | ** - Inactivity Timeout as initiator role |
| 951 | ** (LLCP_INIT_INACTIVITY_TIMEOUT) |
| 952 | ** - Inactivity Timeout as target role |
| 953 | ** (LLCP_TARGET_INACTIVITY_TIMEOUT) |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 954 | ** - Delay SYMM response (LLCP_DELAY_RESP_TIME) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 955 | ** - Data link connection timeout |
| 956 | ** (LLCP_DATA_LINK_CONNECTION_TOUT) |
| 957 | ** - Delay timeout to send first PDU as initiator |
| 958 | ** (LLCP_DELAY_TIME_TO_SEND_FIRST_PDU) |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 959 | ** |
| 960 | ** Returns NFA_STATUS_OK if successfully initiated |
| 961 | ** NFA_STATUS_FAILED otherwise |
| 962 | ** |
| 963 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 964 | tNFA_STATUS NFA_P2pSetLLCPConfig(uint16_t link_miu, uint8_t opt, uint8_t wt, |
| 965 | uint16_t link_timeout, |
| 966 | uint16_t inact_timeout_init, |
| 967 | uint16_t inact_timeout_target, |
| 968 | uint16_t symm_delay, |
| 969 | uint16_t data_link_timeout, |
| 970 | uint16_t delay_first_pdu_timeout) { |
| 971 | tNFA_P2P_API_SET_LLCP_CFG* p_msg; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 972 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 973 | DLOG_IF(INFO, nfc_debug_enabled) |
| 974 | << StringPrintf("link_miu:%d, opt:0x%02X, wt:%d, link_timeout:%d", |
| 975 | link_miu, opt, wt, link_timeout); |
| 976 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 977 | " inact_timeout(init:%d, target:%d), " |
| 978 | "symm_delay:%d, data_link_timeout:%d", |
| 979 | inact_timeout_init, inact_timeout_target, symm_delay, data_link_timeout); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 980 | DLOG_IF(INFO, nfc_debug_enabled) |
| 981 | << StringPrintf(" delay_first_pdu_timeout:%d", |
| 982 | delay_first_pdu_timeout); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 983 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 984 | if (nfa_p2p_cb.llcp_state == NFA_P2P_LLCP_STATE_ACTIVATED) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 985 | LOG(ERROR) << StringPrintf("LLCP link is activated"); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 986 | return (NFA_STATUS_FAILED); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | if ((p_msg = (tNFA_P2P_API_SET_LLCP_CFG*)GKI_getbuf( |
| 990 | sizeof(tNFA_P2P_API_SET_LLCP_CFG))) != NULL) { |
| 991 | p_msg->hdr.event = NFA_P2P_API_SET_LLCP_CFG_EVT; |
| 992 | |
| 993 | p_msg->link_miu = link_miu; |
| 994 | p_msg->opt = opt; |
| 995 | p_msg->wt = wt; |
| 996 | p_msg->link_timeout = link_timeout; |
| 997 | p_msg->inact_timeout_init = inact_timeout_init; |
| 998 | p_msg->inact_timeout_target = inact_timeout_target; |
| 999 | p_msg->symm_delay = symm_delay; |
| 1000 | p_msg->data_link_timeout = data_link_timeout; |
| 1001 | p_msg->delay_first_pdu_timeout = delay_first_pdu_timeout; |
| 1002 | |
| 1003 | nfa_sys_sendmsg(p_msg); |
| 1004 | |
| 1005 | return (NFA_STATUS_OK); |
| 1006 | } |
| 1007 | |
| 1008 | return (NFA_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | /******************************************************************************* |
| 1012 | ** |
| 1013 | ** Function NFA_P2pGetLLCPConfig |
| 1014 | ** |
| 1015 | ** Description This function is called to read LLCP config parameters. |
| 1016 | ** |
| 1017 | ** Parameters descriptions |
| 1018 | ** - Local Link MIU |
| 1019 | ** - Option parameter |
| 1020 | ** - Response Waiting Time Index |
| 1021 | ** - Local Link Timeout |
| 1022 | ** - Inactivity Timeout as initiator role |
| 1023 | ** - Inactivity Timeout as target role |
| 1024 | ** - Delay SYMM response |
| 1025 | ** - Data link connection timeout |
| 1026 | ** - Delay timeout to send first PDU as initiator |
| 1027 | ** |
| 1028 | ** Returns None |
| 1029 | ** |
| 1030 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1031 | void NFA_P2pGetLLCPConfig(uint16_t* p_link_miu, uint8_t* p_opt, uint8_t* p_wt, |
| 1032 | uint16_t* p_link_timeout, |
| 1033 | uint16_t* p_inact_timeout_init, |
| 1034 | uint16_t* p_inact_timeout_target, |
| 1035 | uint16_t* p_symm_delay, uint16_t* p_data_link_timeout, |
| 1036 | uint16_t* p_delay_first_pdu_timeout) { |
| 1037 | LLCP_GetConfig(p_link_miu, p_opt, p_wt, p_link_timeout, p_inact_timeout_init, |
| 1038 | p_inact_timeout_target, p_symm_delay, p_data_link_timeout, |
| 1039 | p_delay_first_pdu_timeout); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1040 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1041 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1042 | << StringPrintf("link_miu:%d, opt:0x%02X, wt:%d, link_timeout:%d", |
| 1043 | *p_link_miu, *p_opt, *p_wt, *p_link_timeout); |
| 1044 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1045 | " inact_timeout(init:%d, target:%d), " |
| 1046 | "symm_delay:%d, data_link_timeout:%d", |
| 1047 | *p_inact_timeout_init, *p_inact_timeout_target, *p_symm_delay, |
| 1048 | *p_data_link_timeout); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1049 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1050 | << StringPrintf(" delay_first_pdu_timeout:%d", |
| 1051 | *p_delay_first_pdu_timeout); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1052 | } |