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