• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 /******************************************************************************
20  *
21  *  This is the implementation file for the NFA P2P.
22  *
23  ******************************************************************************/
24 #include <android-base/stringprintf.h>
25 #include <base/logging.h>
26 
27 #include "llcp_api.h"
28 #include "nfa_dm_int.h"
29 #include "nfa_p2p_api.h"
30 #include "nfa_p2p_int.h"
31 
32 using android::base::StringPrintf;
33 
34 extern bool nfc_debug_enabled;
35 
36 /*****************************************************************************
37 **  Global Variables
38 *****************************************************************************/
39 
40 /*****************************************************************************
41 **  Static Functions
42 *****************************************************************************/
43 
44 /*****************************************************************************
45 **  Constants
46 *****************************************************************************/
47 
48 /*******************************************************************************
49 **
50 ** Function         nfa_p2p_allocate_conn_cb
51 **
52 ** Description      Allocate data link connection control block
53 **
54 **
55 ** Returns          uint8_t
56 **
57 *******************************************************************************/
nfa_p2p_allocate_conn_cb(uint8_t local_sap)58 static uint8_t nfa_p2p_allocate_conn_cb(uint8_t local_sap) {
59   uint8_t xx;
60 
61   for (xx = 0; xx < LLCP_MAX_DATA_LINK; xx++) {
62     if (nfa_p2p_cb.conn_cb[xx].flags == 0) {
63       nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_IN_USE;
64       nfa_p2p_cb.conn_cb[xx].local_sap = local_sap;
65 
66       return (xx);
67     }
68   }
69 
70   LOG(ERROR) << StringPrintf("No resource");
71 
72   return LLCP_MAX_DATA_LINK;
73 }
74 
75 /*******************************************************************************
76 **
77 ** Function         nfa_p2p_deallocate_conn_cb
78 **
79 ** Description      Deallocate data link connection control block
80 **
81 **
82 ** Returns          void
83 **
84 *******************************************************************************/
nfa_p2p_deallocate_conn_cb(uint8_t xx)85 static void nfa_p2p_deallocate_conn_cb(uint8_t xx) {
86   if (xx < LLCP_MAX_DATA_LINK) {
87     nfa_p2p_cb.conn_cb[xx].flags = 0;
88   } else {
89     LOG(ERROR) << StringPrintf("Invalid index (%d)", xx);
90   }
91 }
92 
93 /*******************************************************************************
94 **
95 ** Function         nfa_p2p_find_conn_cb
96 **
97 ** Description      Find data link connection control block by local/remote SAP
98 **
99 **
100 ** Returns          uint8_t
101 **
102 *******************************************************************************/
nfa_p2p_find_conn_cb(uint8_t local_sap,uint8_t remote_sap)103 static uint8_t nfa_p2p_find_conn_cb(uint8_t local_sap, uint8_t remote_sap) {
104   uint8_t xx;
105 
106   for (xx = 0; xx < LLCP_MAX_DATA_LINK; xx++) {
107     if ((nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_IN_USE) &&
108         (nfa_p2p_cb.conn_cb[xx].local_sap == local_sap) &&
109         (nfa_p2p_cb.conn_cb[xx].remote_sap == remote_sap)) {
110       return (xx);
111     }
112   }
113 
114   return (LLCP_MAX_DATA_LINK);
115 }
116 
117 /*******************************************************************************
118 **
119 ** Function         nfa_p2p_llcp_cback
120 **
121 ** Description      Processing SAP callback events from LLCP
122 **
123 **
124 ** Returns          None
125 **
126 *******************************************************************************/
nfa_p2p_llcp_cback(tLLCP_SAP_CBACK_DATA * p_data)127 static void nfa_p2p_llcp_cback(tLLCP_SAP_CBACK_DATA* p_data) {
128   DLOG_IF(INFO, nfc_debug_enabled)
129       << StringPrintf("event:0x%02X, local_sap:0x%02X", p_data->hdr.event,
130                       p_data->hdr.local_sap);
131 
132   switch (p_data->hdr.event) {
133     case LLCP_SAP_EVT_DATA_IND:
134       nfa_p2p_proc_llcp_data_ind(p_data);
135       break;
136 
137     case LLCP_SAP_EVT_CONNECT_IND:
138       nfa_p2p_proc_llcp_connect_ind(p_data);
139       break;
140 
141     case LLCP_SAP_EVT_CONNECT_RESP:
142       nfa_p2p_proc_llcp_connect_resp(p_data);
143       break;
144 
145     case LLCP_SAP_EVT_DISCONNECT_IND:
146       nfa_p2p_proc_llcp_disconnect_ind(p_data);
147       break;
148 
149     case LLCP_SAP_EVT_DISCONNECT_RESP:
150       nfa_p2p_proc_llcp_disconnect_resp(p_data);
151       break;
152 
153     case LLCP_SAP_EVT_CONGEST:
154       nfa_p2p_proc_llcp_congestion(p_data);
155       break;
156 
157     case LLCP_SAP_EVT_LINK_STATUS:
158       nfa_p2p_proc_llcp_link_status(p_data);
159       break;
160 
161     default:
162       LOG(ERROR) << StringPrintf("Unknown event:0x%02X", p_data->hdr.event);
163       return;
164   }
165 }
166 
167 /*******************************************************************************
168 **
169 ** Function         nfa_p2p_sdp_cback
170 **
171 ** Description      Process SDP callback event from LLCP
172 **
173 **
174 ** Returns          None
175 **
176 *******************************************************************************/
nfa_p2p_sdp_cback(uint8_t tid,uint8_t remote_sap)177 void nfa_p2p_sdp_cback(uint8_t tid, uint8_t remote_sap) {
178   uint8_t local_sap;
179   uint8_t xx;
180   tNFA_P2P_EVT_DATA evt_data;
181 
182   DLOG_IF(INFO, nfc_debug_enabled)
183       << StringPrintf("tid:0x%02X, remote_sap:0x%02X", tid, remote_sap);
184 
185   /* search for callback function to process */
186   for (xx = 0; xx < LLCP_MAX_SDP_TRANSAC; xx++) {
187     if ((nfa_p2p_cb.sdp_cb[xx].local_sap != LLCP_INVALID_SAP) &&
188         (nfa_p2p_cb.sdp_cb[xx].tid == tid)) {
189       local_sap = nfa_p2p_cb.sdp_cb[xx].local_sap;
190 
191       evt_data.sdp.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
192       evt_data.sdp.remote_sap = remote_sap;
193       nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_SDP_EVT, &evt_data);
194 
195       nfa_p2p_cb.sdp_cb[xx].local_sap = LLCP_INVALID_SAP;
196       break;
197     }
198   }
199 }
200 
201 /*******************************************************************************
202 **
203 ** Function         nfa_p2p_start_sdp
204 **
205 ** Description      Initiate SDP
206 **
207 **
208 ** Returns          TRUE if success
209 **
210 *******************************************************************************/
nfa_p2p_start_sdp(char * p_service_name,uint8_t local_sap)211 bool nfa_p2p_start_sdp(char* p_service_name, uint8_t local_sap) {
212   int xx;
213 
214   DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("SN:<%s>", p_service_name);
215 
216   /* search for empty slot */
217   for (xx = 0; xx < LLCP_MAX_SDP_TRANSAC; xx++) {
218     if (nfa_p2p_cb.sdp_cb[xx].local_sap == LLCP_INVALID_SAP) {
219       if (LLCP_DiscoverService(p_service_name, nfa_p2p_sdp_cback,
220                                &(nfa_p2p_cb.sdp_cb[xx].tid)) ==
221           LLCP_STATUS_SUCCESS) {
222         nfa_p2p_cb.sdp_cb[xx].local_sap = local_sap;
223         return true;
224       } else {
225         /* failure of SDP */
226         return false;
227       }
228     }
229   }
230   return false;
231 }
232 
233 /*******************************************************************************
234 **
235 ** Function         nfa_p2p_proc_llcp_data_ind
236 **
237 ** Description      Processing incoming data event from LLCP
238 **
239 **
240 ** Returns          None
241 **
242 *******************************************************************************/
nfa_p2p_proc_llcp_data_ind(tLLCP_SAP_CBACK_DATA * p_data)243 void nfa_p2p_proc_llcp_data_ind(tLLCP_SAP_CBACK_DATA* p_data) {
244   uint8_t local_sap, xx;
245   tNFA_P2P_EVT_DATA evt_data;
246 
247   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
248 
249   local_sap = p_data->data_ind.local_sap;
250 
251   if (nfa_p2p_cb.sap_cb[local_sap].p_cback) {
252     evt_data.data.handle = 0;
253     /* if connectionless */
254     if (p_data->data_ind.link_type == NFA_P2P_LLINK_TYPE) {
255       evt_data.data.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
256     } else {
257       xx = nfa_p2p_find_conn_cb(p_data->data_ind.local_sap,
258                                 p_data->data_ind.remote_sap);
259 
260       if (xx != LLCP_MAX_DATA_LINK) {
261         evt_data.data.handle =
262             (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
263       }
264     }
265 
266     evt_data.data.remote_sap = p_data->data_ind.remote_sap;
267     evt_data.data.link_type = p_data->data_ind.link_type;
268 
269     /* notify upper layer that there are data at LLCP */
270     nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DATA_EVT, &evt_data);
271   }
272 }
273 
274 /*******************************************************************************
275 **
276 ** Function         nfa_p2p_proc_llcp_connect_ind
277 **
278 ** Description      Processing connection request from peer
279 **
280 **
281 ** Returns          None
282 **
283 *******************************************************************************/
nfa_p2p_proc_llcp_connect_ind(tLLCP_SAP_CBACK_DATA * p_data)284 void nfa_p2p_proc_llcp_connect_ind(tLLCP_SAP_CBACK_DATA* p_data) {
285   uint8_t server_sap, local_sap;
286   tNFA_P2P_EVT_DATA evt_data;
287   uint8_t xx;
288 
289   DLOG_IF(INFO, nfc_debug_enabled)
290       << StringPrintf("server_sap:0x%x", p_data->connect_ind.server_sap);
291 
292   server_sap = p_data->connect_ind.server_sap;
293   local_sap = p_data->connect_ind.local_sap;
294 
295   if (nfa_p2p_cb.sap_cb[server_sap].p_cback) {
296     xx = nfa_p2p_allocate_conn_cb(server_sap);
297 
298     if (xx != LLCP_MAX_DATA_LINK) {
299       nfa_p2p_cb.conn_cb[xx].remote_sap = p_data->connect_ind.remote_sap;
300       nfa_p2p_cb.conn_cb[xx].remote_miu = p_data->connect_ind.miu;
301 
302       /* peer will not receive any data */
303       if (p_data->connect_ind.rw == 0)
304         nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_REMOTE_RW_ZERO;
305 
306       evt_data.conn_req.server_handle = (NFA_HANDLE_GROUP_P2P | server_sap);
307       evt_data.conn_req.conn_handle =
308           (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
309       evt_data.conn_req.remote_sap = p_data->connect_ind.remote_sap;
310       evt_data.conn_req.remote_miu = p_data->connect_ind.miu;
311       evt_data.conn_req.remote_rw = p_data->connect_ind.rw;
312 
313       nfa_p2p_cb.sap_cb[server_sap].p_cback(NFA_P2P_CONN_REQ_EVT, &evt_data);
314     }
315   } else {
316     LOG(ERROR) << StringPrintf("Not registered");
317   }
318 }
319 
320 /*******************************************************************************
321 **
322 ** Function         nfa_p2p_proc_llcp_connect_resp
323 **
324 ** Description      Processing connection response from peer
325 **
326 **
327 ** Returns          None
328 **
329 *******************************************************************************/
nfa_p2p_proc_llcp_connect_resp(tLLCP_SAP_CBACK_DATA * p_data)330 void nfa_p2p_proc_llcp_connect_resp(tLLCP_SAP_CBACK_DATA* p_data) {
331   uint8_t local_sap, xx;
332   tNFA_P2P_EVT_DATA evt_data;
333 
334   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
335 
336   local_sap = p_data->connect_resp.local_sap;
337 
338   if (nfa_p2p_cb.sap_cb[local_sap].p_cback) {
339     xx = nfa_p2p_allocate_conn_cb(local_sap);
340 
341     if (xx != LLCP_MAX_DATA_LINK) {
342       nfa_p2p_cb.conn_cb[xx].remote_sap = p_data->connect_resp.remote_sap;
343       nfa_p2p_cb.conn_cb[xx].remote_miu = p_data->connect_resp.miu;
344 
345       /* peer will not receive any data */
346       if (p_data->connect_resp.rw == 0)
347         nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_REMOTE_RW_ZERO;
348 
349       evt_data.connected.client_handle = (NFA_HANDLE_GROUP_P2P | local_sap);
350       evt_data.connected.conn_handle =
351           (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
352       evt_data.connected.remote_sap = p_data->connect_resp.remote_sap;
353       evt_data.connected.remote_miu = p_data->connect_resp.miu;
354       evt_data.connected.remote_rw = p_data->connect_resp.rw;
355 
356       nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_CONNECTED_EVT, &evt_data);
357     }
358   }
359 }
360 
361 /*******************************************************************************
362 **
363 ** Function         nfa_p2p_proc_llcp_disconnect_ind
364 **
365 ** Description      Processing disconnection request from peer
366 **
367 **
368 ** Returns          None
369 **
370 *******************************************************************************/
nfa_p2p_proc_llcp_disconnect_ind(tLLCP_SAP_CBACK_DATA * p_data)371 void nfa_p2p_proc_llcp_disconnect_ind(tLLCP_SAP_CBACK_DATA* p_data) {
372   uint8_t local_sap, xx;
373   tNFA_P2P_EVT_DATA evt_data;
374 
375   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
376 
377   local_sap = p_data->disconnect_ind.local_sap;
378 
379   if (nfa_p2p_cb.sap_cb[local_sap].p_cback) {
380     xx = nfa_p2p_find_conn_cb(p_data->disconnect_ind.local_sap,
381                               p_data->disconnect_ind.remote_sap);
382 
383     if (xx != LLCP_MAX_DATA_LINK) {
384       evt_data.disc.handle =
385           (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
386       evt_data.disc.reason = NFA_P2P_DISC_REASON_REMOTE_INITIATE;
387 
388       nfa_p2p_deallocate_conn_cb(xx);
389 
390       nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DISC_EVT, &evt_data);
391     } else {
392       /*
393       ** LLCP link has been deactivated before receiving CC or DM.
394       ** Return NFA_P2P_DISC_EVT to indicate failure of creating
395       ** connection
396       */
397 
398       evt_data.disc.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
399       evt_data.disc.reason = NFA_P2P_DISC_REASON_LLCP_DEACTIVATED;
400 
401       nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DISC_EVT, &evt_data);
402 
403       LOG(ERROR) << StringPrintf("Link deactivated");
404     }
405   }
406 }
407 
408 /*******************************************************************************
409 **
410 ** Function         nfa_p2p_proc_llcp_disconnect_resp
411 **
412 ** Description      Processing rejected connection from peer
413 **
414 **
415 ** Returns          None
416 **
417 *******************************************************************************/
nfa_p2p_proc_llcp_disconnect_resp(tLLCP_SAP_CBACK_DATA * p_data)418 void nfa_p2p_proc_llcp_disconnect_resp(tLLCP_SAP_CBACK_DATA* p_data) {
419   uint8_t local_sap, xx;
420   tNFA_P2P_EVT_DATA evt_data;
421 
422   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
423 
424   local_sap = p_data->disconnect_resp.local_sap;
425 
426   if (nfa_p2p_cb.sap_cb[local_sap].p_cback) {
427     if (p_data->disconnect_resp.reason == LLCP_SAP_DM_REASON_RESP_DISC) {
428       evt_data.disc.reason = NFA_P2P_DISC_REASON_LOCAL_INITITATE;
429     } else if ((p_data->disconnect_resp.reason ==
430                 LLCP_SAP_DM_REASON_APP_REJECTED) ||
431                (p_data->disconnect_resp.reason ==
432                 LLCP_SAP_DM_REASON_PERM_REJECT_THIS) ||
433                (p_data->disconnect_resp.reason ==
434                 LLCP_SAP_DM_REASON_PERM_REJECT_ANY) ||
435                (p_data->disconnect_resp.reason ==
436                 LLCP_SAP_DM_REASON_TEMP_REJECT_THIS) ||
437                (p_data->disconnect_resp.reason ==
438                 LLCP_SAP_DM_REASON_TEMP_REJECT_ANY)) {
439       evt_data.disc.reason = NFA_P2P_DISC_REASON_REMOTE_REJECT;
440     } else if (p_data->disconnect_resp.reason ==
441                LLCP_SAP_DM_REASON_NO_SERVICE) {
442       evt_data.disc.reason = NFA_P2P_DISC_REASON_NO_SERVICE;
443     } else if (p_data->disconnect_resp.reason ==
444                LLCP_SAP_DM_REASON_NO_ACTIVE_CONNECTION) {
445       evt_data.disc.reason = NFA_P2P_DISC_REASON_LLCP_DEACTIVATED;
446     } else {
447       evt_data.disc.reason = NFA_P2P_DISC_REASON_NO_INFORMATION;
448     }
449 
450     if (evt_data.disc.reason == NFA_P2P_DISC_REASON_LOCAL_INITITATE) {
451       xx = nfa_p2p_find_conn_cb(p_data->disconnect_resp.local_sap,
452                                 p_data->disconnect_resp.remote_sap);
453 
454       if (xx != LLCP_MAX_DATA_LINK) {
455         evt_data.disc.handle =
456             (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
457 
458         nfa_p2p_deallocate_conn_cb(xx);
459 
460         nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DISC_EVT, &evt_data);
461       } else {
462         LOG(ERROR) << StringPrintf("No connection found");
463       }
464     } else {
465       evt_data.disc.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
466       nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DISC_EVT, &evt_data);
467     }
468   }
469 }
470 
471 /*******************************************************************************
472 **
473 ** Function         nfa_p2p_proc_llcp_congest
474 **
475 ** Description      Processing LLCP congestion event
476 **
477 **
478 ** Returns          None
479 **
480 *******************************************************************************/
nfa_p2p_proc_llcp_congestion(tLLCP_SAP_CBACK_DATA * p_data)481 void nfa_p2p_proc_llcp_congestion(tLLCP_SAP_CBACK_DATA* p_data) {
482   uint8_t local_sap, remote_sap, xx;
483   tNFA_P2P_EVT_DATA evt_data;
484 
485   local_sap = p_data->congest.local_sap;
486   remote_sap = p_data->congest.remote_sap;
487 
488   evt_data.congest.link_type = p_data->congest.link_type;
489   evt_data.congest.is_congested = p_data->congest.is_congested;
490 
491   if (p_data->congest.is_congested) {
492     DLOG_IF(INFO, nfc_debug_enabled)
493         << StringPrintf("START SAP=(0x%x,0x%x)", local_sap, remote_sap);
494 
495   } else {
496     DLOG_IF(INFO, nfc_debug_enabled)
497         << StringPrintf("END SAP=(0x%x,0x%x)", local_sap, remote_sap);
498   }
499 
500   if (nfa_p2p_cb.sap_cb[local_sap].p_cback) {
501     if (evt_data.congest.link_type == NFA_P2P_LLINK_TYPE) {
502       evt_data.congest.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
503 
504       if ((evt_data.congest.is_congested == false) &&
505           (nfa_p2p_cb.sap_cb[local_sap].flags &
506            NFA_P2P_SAP_FLAG_LLINK_CONGESTED)) {
507         nfa_p2p_cb.sap_cb[local_sap].flags &= ~NFA_P2P_SAP_FLAG_LLINK_CONGESTED;
508         nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_CONGEST_EVT, &evt_data);
509       } else if ((evt_data.congest.is_congested == true) &&
510                  (!(nfa_p2p_cb.sap_cb[local_sap].flags &
511                     NFA_P2P_SAP_FLAG_LLINK_CONGESTED))) {
512         /* this is overall congestion due to high usage of buffer pool */
513         nfa_p2p_cb.sap_cb[local_sap].flags |= NFA_P2P_SAP_FLAG_LLINK_CONGESTED;
514         nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_CONGEST_EVT, &evt_data);
515       }
516     } else {
517       xx = nfa_p2p_find_conn_cb(local_sap, remote_sap);
518 
519       if (xx != LLCP_MAX_DATA_LINK) {
520         evt_data.congest.handle =
521             (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
522 
523         if ((evt_data.congest.is_congested == false) &&
524             (nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_CONGESTED)) {
525           nfa_p2p_cb.conn_cb[xx].flags &= ~NFA_P2P_CONN_FLAG_CONGESTED;
526           nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_CONGEST_EVT, &evt_data);
527         } else if ((evt_data.congest.is_congested == true) &&
528                    (!(nfa_p2p_cb.conn_cb[xx].flags &
529                       NFA_P2P_CONN_FLAG_CONGESTED))) {
530           /* this is overall congestion due to high usage of buffer pool */
531           nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_CONGESTED;
532           nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_CONGEST_EVT, &evt_data);
533         }
534       } else {
535         LOG(ERROR) << StringPrintf("No connection found");
536       }
537     }
538   }
539 }
540 
541 /*******************************************************************************
542 **
543 ** Function         nfa_p2p_proc_llcp_link_status
544 **
545 ** Description      Processing LLCP link status
546 **
547 **
548 ** Returns          next state after processing this event
549 **
550 *******************************************************************************/
nfa_p2p_proc_llcp_link_status(tLLCP_SAP_CBACK_DATA * p_data)551 void nfa_p2p_proc_llcp_link_status(tLLCP_SAP_CBACK_DATA* p_data) {
552   uint8_t local_sap, xx;
553   tNFA_P2P_EVT_DATA evt_data;
554 
555   DLOG_IF(INFO, nfc_debug_enabled)
556       << StringPrintf("is_activated:%d", p_data->link_status.is_activated);
557 
558   local_sap = p_data->link_status.local_sap;
559 
560   if (nfa_p2p_cb.sap_cb[local_sap].p_cback) {
561     if (p_data->link_status.is_activated) {
562       /* only for server */
563       evt_data.activated.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
564       evt_data.activated.local_link_miu = nfa_p2p_cb.local_link_miu;
565       evt_data.activated.remote_link_miu = nfa_p2p_cb.remote_link_miu;
566 
567       nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_ACTIVATED_EVT, &evt_data);
568     } else /* if LLCP link is deactivated */
569     {
570       for (xx = 0; xx < LLCP_MAX_DATA_LINK; xx++) {
571         if ((nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_IN_USE) &&
572             (nfa_p2p_cb.conn_cb[xx].local_sap == local_sap)) {
573           evt_data.disc.handle =
574               (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
575           evt_data.disc.reason = NFA_P2P_DISC_REASON_LLCP_DEACTIVATED;
576 
577           nfa_p2p_deallocate_conn_cb(xx);
578           nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DISC_EVT, &evt_data);
579         }
580       }
581 
582       /* notify deactivation and clear flags */
583       if (nfa_p2p_cb.sap_cb[local_sap].flags & NFA_P2P_SAP_FLAG_SERVER) {
584         evt_data.deactivated.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
585         nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DEACTIVATED_EVT,
586                                              &evt_data);
587 
588         nfa_p2p_cb.sap_cb[local_sap].flags = NFA_P2P_SAP_FLAG_SERVER;
589       } else if (nfa_p2p_cb.sap_cb[local_sap].flags & NFA_P2P_SAP_FLAG_CLIENT) {
590         evt_data.deactivated.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
591         nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DEACTIVATED_EVT,
592                                              &evt_data);
593 
594         nfa_p2p_cb.sap_cb[local_sap].flags = NFA_P2P_SAP_FLAG_CLIENT;
595       } else /* if this is not registered service */
596       {
597         nfa_p2p_cb.sap_cb[local_sap].p_cback = nullptr;
598       }
599     }
600   }
601 }
602 
603 /*******************************************************************************
604 **
605 ** Function         nfa_p2p_reg_server
606 **
607 ** Description      Allocate a service as server and register to LLCP
608 **
609 **
610 ** Returns          FALSE if need to keep buffer
611 **
612 *******************************************************************************/
nfa_p2p_reg_server(tNFA_P2P_MSG * p_msg)613 bool nfa_p2p_reg_server(tNFA_P2P_MSG* p_msg) {
614   tNFA_P2P_EVT_DATA evt_data;
615   uint8_t server_sap;
616 
617   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
618 
619   server_sap = LLCP_RegisterServer(
620       p_msg->api_reg_server.server_sap, p_msg->api_reg_server.link_type,
621       p_msg->api_reg_server.service_name, nfa_p2p_llcp_cback);
622 
623   if (server_sap == LLCP_INVALID_SAP) {
624     evt_data.reg_server.server_handle = NFA_HANDLE_INVALID;
625     evt_data.reg_server.server_sap = NFA_P2P_INVALID_SAP;
626     strncpy(evt_data.reg_server.service_name,
627             p_msg->api_reg_server.service_name, LLCP_MAX_SN_LEN);
628     evt_data.reg_server.service_name[LLCP_MAX_SN_LEN] = 0;
629 
630     p_msg->api_reg_server.p_cback(NFA_P2P_REG_SERVER_EVT, &evt_data);
631 
632     return true;
633   }
634 
635   /* if need to update WKS in LLCP Gen bytes */
636   if (server_sap <= LLCP_UPPER_BOUND_WK_SAP) {
637     nfa_p2p_enable_listening(NFA_ID_P2P, true);
638   } else if (!nfa_p2p_cb.is_p2p_listening) {
639     nfa_p2p_enable_listening(NFA_ID_P2P, false);
640   }
641 
642   nfa_p2p_cb.sap_cb[server_sap].p_cback = p_msg->api_reg_server.p_cback;
643   nfa_p2p_cb.sap_cb[server_sap].flags = NFA_P2P_SAP_FLAG_SERVER;
644 
645   evt_data.reg_server.server_handle = (NFA_HANDLE_GROUP_P2P | server_sap);
646   evt_data.reg_server.server_sap = server_sap;
647   strncpy(evt_data.reg_server.service_name, p_msg->api_reg_server.service_name,
648           LLCP_MAX_SN_LEN);
649   evt_data.reg_server.service_name[LLCP_MAX_SN_LEN] = 0;
650 
651   /* notify NFA_P2P_REG_SERVER_EVT to server */
652   nfa_p2p_cb.sap_cb[server_sap].p_cback(NFA_P2P_REG_SERVER_EVT, &evt_data);
653 
654   /* if LLCP is already activated */
655   if (nfa_p2p_cb.llcp_state == NFA_P2P_LLCP_STATE_ACTIVATED) {
656     evt_data.activated.handle = (NFA_HANDLE_GROUP_P2P | server_sap);
657     evt_data.activated.local_link_miu = nfa_p2p_cb.local_link_miu;
658     evt_data.activated.remote_link_miu = nfa_p2p_cb.remote_link_miu;
659 
660     /* notify NFA_P2P_ACTIVATED_EVT to server */
661     nfa_p2p_cb.sap_cb[server_sap].p_cback(NFA_P2P_ACTIVATED_EVT, &evt_data);
662   }
663 
664   return true;
665 }
666 
667 /*******************************************************************************
668 **
669 ** Function         nfa_p2p_reg_client
670 **
671 ** Description      Allocate a service as client and register to LLCP
672 **
673 **
674 ** Returns          TRUE to deallocate buffer
675 **
676 *******************************************************************************/
nfa_p2p_reg_client(tNFA_P2P_MSG * p_msg)677 bool nfa_p2p_reg_client(tNFA_P2P_MSG* p_msg) {
678   tNFA_P2P_EVT_DATA evt_data;
679   uint8_t local_sap;
680 
681   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
682 
683   local_sap =
684       LLCP_RegisterClient(p_msg->api_reg_client.link_type, nfa_p2p_llcp_cback);
685 
686   if (local_sap == LLCP_INVALID_SAP) {
687     evt_data.reg_client.client_handle = NFA_HANDLE_INVALID;
688     p_msg->api_reg_client.p_cback(NFA_P2P_REG_CLIENT_EVT, &evt_data);
689     return true;
690   }
691 
692   nfa_p2p_cb.sap_cb[local_sap].p_cback = p_msg->api_reg_client.p_cback;
693   nfa_p2p_cb.sap_cb[local_sap].flags = NFA_P2P_SAP_FLAG_CLIENT;
694 
695   evt_data.reg_client.client_handle = (NFA_HANDLE_GROUP_P2P | local_sap);
696   nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_REG_CLIENT_EVT, &evt_data);
697 
698   /* if LLCP is already activated */
699   if (nfa_p2p_cb.llcp_state == NFA_P2P_LLCP_STATE_ACTIVATED) {
700     evt_data.activated.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
701     evt_data.activated.local_link_miu = nfa_p2p_cb.local_link_miu;
702     evt_data.activated.remote_link_miu = nfa_p2p_cb.remote_link_miu;
703 
704     /* notify NFA_P2P_ACTIVATED_EVT to client */
705     nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_ACTIVATED_EVT, &evt_data);
706   }
707 
708   return true;
709 }
710 
711 /*******************************************************************************
712 **
713 ** Function         nfa_p2p_dereg
714 **
715 ** Description      Deallocate a service as server or client and deregister to
716 **                  LLCP. LLCP will deallocate data link connection created by
717 **                  this server
718 **
719 ** Returns          TRUE to deallocate buffer
720 **
721 *******************************************************************************/
nfa_p2p_dereg(tNFA_P2P_MSG * p_msg)722 bool nfa_p2p_dereg(tNFA_P2P_MSG* p_msg) {
723   uint8_t local_sap, xx;
724 
725   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
726 
727   local_sap = (uint8_t)(p_msg->api_dereg.handle & NFA_HANDLE_MASK);
728 
729   if (nfa_p2p_cb.sap_cb[local_sap].p_cback) {
730     for (xx = 0; xx < LLCP_MAX_DATA_LINK; xx++) {
731       if ((nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_IN_USE) &&
732           (nfa_p2p_cb.conn_cb[xx].local_sap == local_sap)) {
733         nfa_p2p_deallocate_conn_cb(xx);
734       }
735     }
736   }
737 
738   LLCP_Deregister(local_sap);
739   nfa_p2p_cb.sap_cb[local_sap].p_cback = nullptr;
740 
741   if (nfa_p2p_cb.is_p2p_listening) {
742     /* check if this is the last server on NFA P2P */
743     for (xx = 0; xx < NFA_P2P_NUM_SAP; xx++) {
744       if ((nfa_p2p_cb.sap_cb[xx].p_cback) &&
745           (nfa_p2p_cb.sap_cb[xx].flags & NFA_P2P_SAP_FLAG_SERVER)) {
746         break;
747       }
748     }
749 
750     if (xx >= NFA_P2P_NUM_SAP) {
751       /* if need to update WKS in LLCP Gen bytes */
752       if (local_sap <= LLCP_UPPER_BOUND_WK_SAP)
753         nfa_p2p_disable_listening(NFA_ID_P2P, true);
754       else
755         nfa_p2p_disable_listening(NFA_ID_P2P, false);
756     }
757     /* if need to update WKS in LLCP Gen bytes */
758     else if (local_sap <= LLCP_UPPER_BOUND_WK_SAP) {
759       nfa_p2p_enable_listening(NFA_ID_P2P, true);
760     }
761   }
762 
763   return true;
764 }
765 
766 /*******************************************************************************
767 **
768 ** Function         nfa_p2p_accept_connection
769 **
770 ** Description      Connection Confirm from local application
771 **
772 **
773 ** Returns          TRUE to deallocate buffer
774 **
775 *******************************************************************************/
nfa_p2p_accept_connection(tNFA_P2P_MSG * p_msg)776 bool nfa_p2p_accept_connection(tNFA_P2P_MSG* p_msg) {
777   uint8_t xx;
778   tLLCP_CONNECTION_PARAMS params;
779 
780   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
781 
782   xx = (uint8_t)(p_msg->api_accept.conn_handle & NFA_HANDLE_MASK);
783   xx &= ~NFA_P2P_HANDLE_FLAG_CONN;
784 
785   params.miu = p_msg->api_accept.miu;
786   params.rw = p_msg->api_accept.rw;
787   params.sn[0] = 0;
788 
789   LLCP_ConnectCfm(nfa_p2p_cb.conn_cb[xx].local_sap,
790                   nfa_p2p_cb.conn_cb[xx].remote_sap, &params);
791 
792   return true;
793 }
794 
795 /*******************************************************************************
796 **
797 ** Function         nfa_p2p_reject_connection
798 **
799 ** Description      Reject connection by local application
800 **
801 **
802 ** Returns          TRUE to deallocate buffer
803 **
804 *******************************************************************************/
nfa_p2p_reject_connection(tNFA_P2P_MSG * p_msg)805 bool nfa_p2p_reject_connection(tNFA_P2P_MSG* p_msg) {
806   uint8_t xx;
807 
808   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
809 
810   xx = (uint8_t)(p_msg->api_reject.conn_handle & NFA_HANDLE_MASK);
811   xx &= ~NFA_P2P_HANDLE_FLAG_CONN;
812 
813   LLCP_ConnectReject(nfa_p2p_cb.conn_cb[xx].local_sap,
814                      nfa_p2p_cb.conn_cb[xx].remote_sap,
815                      LLCP_SAP_DM_REASON_APP_REJECTED);
816 
817   /* no need to deregister service on LLCP */
818   nfa_p2p_deallocate_conn_cb(xx);
819 
820   return true;
821 }
822 
823 /*******************************************************************************
824 **
825 ** Function         nfa_p2p_disconnect
826 **
827 ** Description      Disconnect data link connection by local application
828 **
829 **
830 ** Returns          TRUE to deallocate buffer
831 **
832 *******************************************************************************/
nfa_p2p_disconnect(tNFA_P2P_MSG * p_msg)833 bool nfa_p2p_disconnect(tNFA_P2P_MSG* p_msg) {
834   uint8_t local_sap, xx;
835   tLLCP_STATUS status;
836   tNFA_P2P_EVT_DATA evt_data;
837 
838   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
839 
840   xx = (uint8_t)(p_msg->api_disconnect.conn_handle & NFA_HANDLE_MASK);
841 
842   /* if this is for data link connection */
843   if (xx & NFA_P2P_HANDLE_FLAG_CONN) {
844     xx &= ~NFA_P2P_HANDLE_FLAG_CONN;
845 
846     status = LLCP_DisconnectReq(nfa_p2p_cb.conn_cb[xx].local_sap,
847                                 nfa_p2p_cb.conn_cb[xx].remote_sap,
848                                 p_msg->api_disconnect.flush);
849 
850     if (status == LLCP_STATUS_SUCCESS) {
851       /* wait for disconnect response if successful */
852       return true;
853     } else {
854       /*
855       ** while we are waiting for connect confirm,
856       ** we cannot sent DISC because we don't know DSAP yet
857       */
858       local_sap = nfa_p2p_cb.conn_cb[xx].local_sap;
859 
860       if (nfa_p2p_cb.sap_cb[local_sap].p_cback) {
861         evt_data.disc.handle =
862             (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
863         evt_data.disc.reason = NFA_P2P_DISC_REASON_LOCAL_INITITATE;
864 
865         nfa_p2p_deallocate_conn_cb(xx);
866         nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DISC_EVT, &evt_data);
867       }
868     }
869   } else {
870     LOG(ERROR) << StringPrintf("Handle is not for Data link connection");
871   }
872 
873   return true;
874 }
875 
876 /*******************************************************************************
877 **
878 ** Function         nfa_p2p_create_data_link_connection
879 **
880 ** Description      Create data link connection
881 **
882 **
883 ** Returns          TRUE to deallocate buffer
884 **
885 *******************************************************************************/
nfa_p2p_create_data_link_connection(tNFA_P2P_MSG * p_msg)886 bool nfa_p2p_create_data_link_connection(tNFA_P2P_MSG* p_msg) {
887   uint8_t local_sap;
888   tNFA_P2P_EVT_DATA evt_data;
889   tLLCP_CONNECTION_PARAMS conn_params;
890   tLLCP_STATUS status;
891 
892   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
893 
894   local_sap = (uint8_t)(p_msg->api_connect.client_handle & NFA_HANDLE_MASK);
895 
896   conn_params.miu = p_msg->api_connect.miu;
897   conn_params.rw = p_msg->api_connect.rw;
898 
899   /* NFA_P2pConnectBySap () */
900   if (p_msg->api_connect.dsap != LLCP_INVALID_SAP) {
901     conn_params.sn[0] = 0;
902     status = LLCP_ConnectReq(local_sap, p_msg->api_connect.dsap, &conn_params);
903   }
904   /* NFA_P2pConnectByName () */
905   else {
906     strncpy(conn_params.sn, p_msg->api_connect.service_name, LLCP_MAX_SN_LEN);
907     conn_params.sn[LLCP_MAX_SN_LEN] = 0;
908 
909     status = LLCP_ConnectReq(local_sap, LLCP_SAP_SDP, &conn_params);
910   }
911 
912   if (status != LLCP_STATUS_SUCCESS) {
913     evt_data.disc.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
914     evt_data.disc.reason = NFA_P2P_DISC_REASON_NO_INFORMATION;
915 
916     nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_DISC_EVT, &evt_data);
917   }
918 
919   return true;
920 }
921 
922 /*******************************************************************************
923 **
924 ** Function         nfa_p2p_send_ui
925 **
926 ** Description      Send UI PDU
927 **
928 **
929 ** Returns          TRUE to deallocate buffer
930 **
931 *******************************************************************************/
nfa_p2p_send_ui(tNFA_P2P_MSG * p_msg)932 bool nfa_p2p_send_ui(tNFA_P2P_MSG* p_msg) {
933   uint8_t local_sap;
934   tLLCP_STATUS status;
935   tNFA_P2P_EVT_DATA evt_data;
936 
937   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
938 
939   local_sap = (uint8_t)(p_msg->api_send_ui.handle & NFA_HANDLE_MASK);
940 
941   /* decrease number of tx UI PDU which is not processed by NFA for congestion
942    * control */
943   if (nfa_p2p_cb.sap_cb[local_sap].num_pending_ui_pdu)
944     nfa_p2p_cb.sap_cb[local_sap].num_pending_ui_pdu--;
945 
946   if (nfa_p2p_cb.total_pending_ui_pdu) nfa_p2p_cb.total_pending_ui_pdu--;
947 
948   status =
949       LLCP_SendUI(local_sap, p_msg->api_send_ui.dsap, p_msg->api_send_ui.p_msg);
950 
951   if (status == LLCP_STATUS_CONGESTED) {
952     if (!(nfa_p2p_cb.sap_cb[local_sap].flags &
953           NFA_P2P_SAP_FLAG_LLINK_CONGESTED)) {
954       nfa_p2p_cb.sap_cb[local_sap].flags |= NFA_P2P_SAP_FLAG_LLINK_CONGESTED;
955 
956       /* notify that this logical link is congested */
957       evt_data.congest.link_type = NFA_P2P_LLINK_TYPE;
958       evt_data.congest.handle = (NFA_HANDLE_GROUP_P2P | local_sap);
959       evt_data.congest.is_congested = true;
960 
961       nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_CONGEST_EVT, &evt_data);
962     }
963   }
964 
965   return true;
966 }
967 
968 /*******************************************************************************
969 **
970 ** Function         nfa_p2p_send_data
971 **
972 ** Description      Send I PDU
973 **
974 **
975 ** Returns          TRUE to deallocate buffer
976 **
977 *******************************************************************************/
nfa_p2p_send_data(tNFA_P2P_MSG * p_msg)978 bool nfa_p2p_send_data(tNFA_P2P_MSG* p_msg) {
979   tNFA_P2P_EVT_DATA evt_data;
980   tLLCP_STATUS status;
981   uint8_t xx;
982 
983   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
984 
985   xx = (uint8_t)(p_msg->api_send_data.conn_handle & NFA_HANDLE_MASK);
986   xx &= ~NFA_P2P_HANDLE_FLAG_CONN;
987 
988   /* decrease number of tx I PDU which is not processed by NFA for congestion
989    * control */
990   if (nfa_p2p_cb.conn_cb[xx].num_pending_i_pdu)
991     nfa_p2p_cb.conn_cb[xx].num_pending_i_pdu--;
992 
993   if (nfa_p2p_cb.total_pending_i_pdu) nfa_p2p_cb.total_pending_i_pdu--;
994 
995   status = LLCP_SendData(nfa_p2p_cb.conn_cb[xx].local_sap,
996                          nfa_p2p_cb.conn_cb[xx].remote_sap,
997                          p_msg->api_send_data.p_msg);
998 
999   if (status == LLCP_STATUS_CONGESTED) {
1000     if (!(nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_CONGESTED)) {
1001       nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_CONGESTED;
1002 
1003       /* notify that this data link is congested */
1004       evt_data.congest.link_type = NFA_P2P_DLINK_TYPE;
1005       evt_data.congest.handle =
1006           (NFA_HANDLE_GROUP_P2P | NFA_P2P_HANDLE_FLAG_CONN | xx);
1007       evt_data.congest.is_congested = true;
1008 
1009       nfa_p2p_cb.sap_cb[nfa_p2p_cb.conn_cb[xx].local_sap].p_cback(
1010           NFA_P2P_CONGEST_EVT, &evt_data);
1011     }
1012   }
1013 
1014   return true;
1015 }
1016 
1017 /*******************************************************************************
1018 **
1019 ** Function         nfa_p2p_set_local_busy
1020 **
1021 ** Description      Set or reset local busy
1022 **
1023 **
1024 ** Returns          TRUE to deallocate buffer
1025 **
1026 *******************************************************************************/
nfa_p2p_set_local_busy(tNFA_P2P_MSG * p_msg)1027 bool nfa_p2p_set_local_busy(tNFA_P2P_MSG* p_msg) {
1028   uint8_t xx;
1029 
1030   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
1031 
1032   xx = (uint8_t)(p_msg->api_local_busy.conn_handle & NFA_HANDLE_MASK);
1033   xx &= ~NFA_P2P_HANDLE_FLAG_CONN;
1034 
1035   LLCP_SetLocalBusyStatus(nfa_p2p_cb.conn_cb[xx].local_sap,
1036                           nfa_p2p_cb.conn_cb[xx].remote_sap,
1037                           p_msg->api_local_busy.is_busy);
1038 
1039   return true;
1040 }
1041 
1042 /*******************************************************************************
1043 **
1044 ** Function         nfa_p2p_get_link_info
1045 **
1046 ** Description      Get WKS of remote and link MIU
1047 **
1048 **
1049 ** Returns          TRUE to deallocate buffer
1050 **
1051 *******************************************************************************/
nfa_p2p_get_link_info(tNFA_P2P_MSG * p_msg)1052 bool nfa_p2p_get_link_info(tNFA_P2P_MSG* p_msg) {
1053   tNFA_P2P_EVT_DATA evt_data;
1054   uint8_t local_sap;
1055 
1056   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
1057 
1058   evt_data.link_info.handle = p_msg->api_link_info.handle;
1059   evt_data.link_info.wks = LLCP_GetRemoteWKS();
1060   evt_data.link_info.local_link_miu = nfa_p2p_cb.local_link_miu;
1061   evt_data.link_info.remote_link_miu = nfa_p2p_cb.remote_link_miu;
1062 
1063   local_sap = (uint8_t)(p_msg->api_link_info.handle & NFA_HANDLE_MASK);
1064   nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_LINK_INFO_EVT, &evt_data);
1065 
1066   return true;
1067 }
1068 
1069 /*******************************************************************************
1070 **
1071 ** Function         nfa_p2p_get_remote_sap
1072 **
1073 ** Description      Get remote SAP
1074 **
1075 **
1076 ** Returns          TRUE to deallocate buffer
1077 **
1078 *******************************************************************************/
nfa_p2p_get_remote_sap(tNFA_P2P_MSG * p_msg)1079 bool nfa_p2p_get_remote_sap(tNFA_P2P_MSG* p_msg) {
1080   tNFA_P2P_EVT_DATA evt_data;
1081   uint8_t local_sap;
1082 
1083   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
1084 
1085   local_sap = (uint8_t)(p_msg->api_remote_sap.handle & NFA_HANDLE_MASK);
1086 
1087   if (!nfa_p2p_start_sdp(p_msg->api_remote_sap.service_name, local_sap)) {
1088     evt_data.sdp.handle = p_msg->api_remote_sap.handle;
1089     evt_data.sdp.remote_sap = 0x00;
1090     nfa_p2p_cb.sap_cb[local_sap].p_cback(NFA_P2P_SDP_EVT, &evt_data);
1091   }
1092 
1093   return true;
1094 }
1095 
1096 /*******************************************************************************
1097 **
1098 ** Function         nfa_p2p_set_llcp_cfg
1099 **
1100 ** Description      Set LLCP configuration
1101 **
1102 **
1103 ** Returns          TRUE to deallocate buffer
1104 **
1105 *******************************************************************************/
nfa_p2p_set_llcp_cfg(tNFA_P2P_MSG * p_msg)1106 bool nfa_p2p_set_llcp_cfg(tNFA_P2P_MSG* p_msg) {
1107   LLCP_SetConfig(p_msg->api_set_llcp_cfg.link_miu, p_msg->api_set_llcp_cfg.opt,
1108                  p_msg->api_set_llcp_cfg.wt,
1109                  p_msg->api_set_llcp_cfg.link_timeout,
1110                  p_msg->api_set_llcp_cfg.inact_timeout_init,
1111                  p_msg->api_set_llcp_cfg.inact_timeout_target,
1112                  p_msg->api_set_llcp_cfg.symm_delay,
1113                  p_msg->api_set_llcp_cfg.data_link_timeout,
1114                  p_msg->api_set_llcp_cfg.delay_first_pdu_timeout);
1115 
1116   return true;
1117 }
1118 
1119 /*******************************************************************************
1120 **
1121 ** Function         nfa_p2p_restart_rf_discovery
1122 **
1123 ** Description      Restart RF discovery by deactivating to IDLE
1124 **
1125 **
1126 ** Returns          TRUE to deallocate buffer
1127 **
1128 *******************************************************************************/
nfa_p2p_restart_rf_discovery(tNFA_P2P_MSG * p_msg)1129 bool nfa_p2p_restart_rf_discovery(__attribute__((unused)) tNFA_P2P_MSG* p_msg) {
1130   DLOG_IF(INFO, nfc_debug_enabled) << __func__;
1131 
1132   nfa_dm_rf_deactivate(NFA_DEACTIVATE_TYPE_IDLE);
1133 
1134   return true;
1135 }
1136