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 * 22 * This is the public interface file for NFA P2P, Broadcom's NFC 23 * application layer for mobile phones. 24 * 25 ******************************************************************************/ 26#ifndef NFA_P2P_API_H 27#define NFA_P2P_API_H 28 29#include "llcp_api.h" 30#include "nfa_api.h" 31 32/***************************************************************************** 33** Constants and data types 34*****************************************************************************/ 35 36/* NFA P2P Reason of disconnection */ 37#define NFA_P2P_DISC_REASON_REMOTE_INITIATE 0x00 /* remote initiated to disconnect */ 38#define NFA_P2P_DISC_REASON_LOCAL_INITITATE 0x01 /* local initiated to disconnect */ 39#define NFA_P2P_DISC_REASON_NO_SERVICE 0x02 /* no service bound in remote */ 40#define NFA_P2P_DISC_REASON_REMOTE_REJECT 0x03 /* remote rejected connection */ 41#define NFA_P2P_DISC_REASON_FRAME_ERROR 0x04 /* sending or receiving FRMR PDU */ 42#define NFA_P2P_DISC_REASON_LLCP_DEACTIVATED 0x05 /* LLCP link deactivated */ 43#define NFA_P2P_DISC_REASON_NO_RESOURCE 0x06 /* Out of resource in local device */ 44#define NFA_P2P_DISC_REASON_NO_INFORMATION 0x80 /* Without information */ 45 46/* NFA P2P callback events */ 47#define NFA_P2P_REG_SERVER_EVT 0x00 /* Server is registered */ 48#define NFA_P2P_REG_CLIENT_EVT 0x01 /* Client is registered */ 49#define NFA_P2P_ACTIVATED_EVT 0x02 /* LLCP Link has been activated */ 50#define NFA_P2P_DEACTIVATED_EVT 0x03 /* LLCP Link has been deactivated */ 51#define NFA_P2P_CONN_REQ_EVT 0x04 /* Data link connection request from peer */ 52#define NFA_P2P_CONNECTED_EVT 0x05 /* Data link connection has been established */ 53#define NFA_P2P_DISC_EVT 0x06 /* Data link connection has been disconnected */ 54#define NFA_P2P_DATA_EVT 0x07 /* Data received from peer */ 55#define NFA_P2P_CONGEST_EVT 0x08 /* Status indication of outgoing data */ 56#define NFA_P2P_LINK_INFO_EVT 0x09 /* link MIU and Well-Known Service list */ 57#define NFA_P2P_SDP_EVT 0x0A /* Remote SAP of SDP result */ 58 59typedef UINT8 tNFA_P2P_EVT; 60 61/* NFA allocates a SAP for server */ 62#define NFA_P2P_ANY_SAP LLCP_INVALID_SAP 63#define NFA_P2P_INVALID_SAP LLCP_INVALID_SAP 64 65/* Recommanded MIU's for connection-oriented */ 66#define NFA_P2P_MIU_1 (NCI_NFC_DEP_MAX_DATA - LLCP_PDU_HEADER_SIZE - LLCP_SEQUENCE_SIZE) 67#define NFA_P2P_MIU_2 (2*NCI_NFC_DEP_MAX_DATA - LLCP_PDU_HEADER_SIZE - LLCP_SEQUENCE_SIZE) 68#define NFA_P2P_MIU_3 (3*NCI_NFC_DEP_MAX_DATA - LLCP_PDU_HEADER_SIZE - LLCP_SEQUENCE_SIZE) 69#define NFA_P2P_MIU_8 (8*NCI_NFC_DEP_MAX_DATA - LLCP_PDU_HEADER_SIZE - LLCP_SEQUENCE_SIZE) 70 71#define NFA_P2P_LLINK_TYPE LLCP_LINK_TYPE_LOGICAL_DATA_LINK 72#define NFA_P2P_DLINK_TYPE LLCP_LINK_TYPE_DATA_LINK_CONNECTION 73typedef UINT8 tNFA_P2P_LINK_TYPE; 74 75/* Data for NFA_P2P_REG_SERVER_EVT */ 76typedef struct 77{ 78 tNFA_HANDLE server_handle; /* NFA_HANDLE_INVALID if failed */ 79 char service_name[LLCP_MAX_SN_LEN + 1]; 80 UINT8 server_sap; 81} tNFA_P2P_REG_SERVER; 82 83/* Data for NFA_P2P_REG_CLIENT_EVT */ 84typedef struct 85{ 86 tNFA_HANDLE client_handle; /* NFA_HANDLE_INVALID if failed */ 87} tNFA_P2P_REG_CLIENT; 88 89/* Data for NFA_P2P_ACTIVATED_EVT */ 90typedef struct 91{ 92 tNFA_HANDLE handle; 93 UINT16 local_link_miu; 94 UINT16 remote_link_miu; 95} tNFA_P2P_ACTIVATED; 96 97/* Data for NFA_P2P_DEACTIVATED_EVT */ 98typedef struct 99{ 100 tNFA_HANDLE handle; 101} tNFA_P2P_DEACTIVATED; 102 103/* Data for NFA_P2P_CONN_REQ_EVT */ 104typedef struct 105{ 106 tNFA_HANDLE server_handle; 107 tNFA_HANDLE conn_handle; 108 UINT8 remote_sap; 109 UINT16 remote_miu; 110 UINT8 remote_rw; 111} tNFA_P2P_CONN_REQ; 112 113/* Data for NFA_P2P_CONNECTED_EVT */ 114typedef struct 115{ 116 tNFA_HANDLE client_handle; 117 tNFA_HANDLE conn_handle; 118 UINT8 remote_sap; 119 UINT16 remote_miu; 120 UINT8 remote_rw; 121} tNFA_P2P_CONN; 122 123/* Data for NFA_P2P_DISC_EVT */ 124typedef struct 125{ 126 tNFA_HANDLE handle; 127 UINT8 reason; 128} tNFA_P2P_DISC; 129 130/* Data for NFA_P2P_DATA_EVT */ 131typedef struct 132{ 133 tNFA_HANDLE handle; 134 UINT8 remote_sap; 135 tNFA_P2P_LINK_TYPE link_type; 136} tNFA_P2P_DATA; 137 138/* Data for NFA_P2P_CONGEST_EVT */ 139typedef struct 140{ 141 tNFA_HANDLE handle; 142 BOOLEAN is_congested; 143 tNFA_P2P_LINK_TYPE link_type; 144} tNFA_P2P_CONGEST; 145 146/* Data for NFA_P2P_LINK_INFO_EVT */ 147typedef struct 148{ 149 tNFA_HANDLE handle; 150 UINT16 wks; /* well-known service */ 151 UINT16 local_link_miu; 152 UINT16 remote_link_miu; 153} tNFA_P2P_LINK_INFO; 154 155/* Data for NFA_P2P_SDP_EVT */ 156typedef struct 157{ 158 tNFA_HANDLE handle; 159 UINT8 remote_sap; /* 0x00 if failed */ 160} tNFA_P2P_SDP; 161 162/* Union of all P2P callback structures */ 163typedef union 164{ 165 tNFA_P2P_REG_SERVER reg_server; /* NFA_P2P_REG_SERVER_EVT */ 166 tNFA_P2P_REG_CLIENT reg_client; /* NFA_P2P_REG_CLIENT_EVT */ 167 tNFA_P2P_ACTIVATED activated; /* NFA_P2P_ACTIVATED_EVT */ 168 tNFA_P2P_DEACTIVATED deactivated; /* NFA_P2P_DEACTIVATED_EVT */ 169 tNFA_P2P_CONN_REQ conn_req; /* NFA_P2P_CONN_REQ_EVT */ 170 tNFA_P2P_CONN connected; /* NFA_P2P_CONNECTED_EVT */ 171 tNFA_P2P_DISC disc; /* NFA_P2P_DISC_EVT */ 172 tNFA_P2P_DATA data; /* NFA_P2P_DATA_EVT */ 173 tNFA_P2P_CONGEST congest; /* NFA_P2P_CONGEST_EVT */ 174 tNFA_P2P_LINK_INFO link_info; /* NFA_P2P_LINK_INFO_EVT */ 175 tNFA_P2P_SDP sdp; /* NFA_P2P_SDP_EVT */ 176} tNFA_P2P_EVT_DATA; 177 178/* NFA P2P callback */ 179typedef void (tNFA_P2P_CBACK)(tNFA_P2P_EVT event, tNFA_P2P_EVT_DATA *p_data); 180 181/***************************************************************************** 182** External Function Declarations 183*****************************************************************************/ 184#ifdef __cplusplus 185extern "C" 186{ 187#endif 188 189/******************************************************************************* 190** 191** Function NFA_P2pRegisterServer 192** 193** Description This function is called to listen to a SAP as server on LLCP. 194** 195** NFA_P2P_REG_SERVER_EVT will be returned with status and handle. 196** 197** If server_sap is set to NFA_P2P_ANY_SAP, then NFA will allocate 198** a SAP between LLCP_LOWER_BOUND_SDP_SAP and LLCP_UPPER_BOUND_SDP_SAP 199** Otherwise, server_sap must be between (LLCP_SDP_SAP + 1) and 200** LLCP_UPPER_BOUND_SDP_SAP 201** 202** link_type : NFA_P2P_LLINK_TYPE and/or NFA_P2P_DLINK_TYPE 203** 204** Note: If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT 205** should happen before calling this function 206** 207** Returns NFA_STATUS_OK if successfully initiated 208** NFA_STATUS_FAILED otherwise 209** 210*******************************************************************************/ 211NFC_API extern tNFA_STATUS NFA_P2pRegisterServer (UINT8 server_sap, 212 tNFA_P2P_LINK_TYPE link_type, 213 char *p_service_name, 214 tNFA_P2P_CBACK *p_cback); 215 216/******************************************************************************* 217** 218** Function NFA_P2pRegisterClient 219** 220** Description This function is called to register a client service on LLCP. 221** 222** NFA_P2P_REG_CLIENT_EVT will be returned with status and handle. 223** 224** link_type : NFA_P2P_LLINK_TYPE and/or NFA_P2P_DLINK_TYPE 225** 226** Returns NFA_STATUS_OK if successfully initiated 227** NFA_STATUS_FAILED otherwise 228** 229*******************************************************************************/ 230NFC_API extern tNFA_STATUS NFA_P2pRegisterClient (tNFA_P2P_LINK_TYPE link_type, 231 tNFA_P2P_CBACK *p_cback); 232 233/******************************************************************************* 234** 235** Function NFA_P2pDeregister 236** 237** Description This function is called to stop listening to a SAP as server 238** or stop client service on LLCP. 239** 240** Note: If this function is called to de-register a server and RF discovery 241** is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT 242** should happen before calling this function 243** 244** Returns NFA_STATUS_OK if successfully initiated 245** NFA_STATUS_BAD_HANDLE if handle is not valid 246** NFA_STATUS_FAILED otherwise 247** 248*******************************************************************************/ 249NFC_API extern tNFA_STATUS NFA_P2pDeregister (tNFA_HANDLE handle); 250 251/******************************************************************************* 252** 253** Function NFA_P2pAcceptConn 254** 255** Description This function is called to accept a request of data link 256** connection to a listening SAP on LLCP after receiving 257** NFA_P2P_CONN_REQ_EVT. 258** 259** Returns NFA_STATUS_OK if successfully initiated 260** NFA_STATUS_BAD_HANDLE if handle is not valid 261** NFA_STATUS_FAILED otherwise 262** 263*******************************************************************************/ 264NFC_API extern tNFA_STATUS NFA_P2pAcceptConn (tNFA_HANDLE conn_handle, 265 UINT16 miu, 266 UINT8 rw); 267 268/******************************************************************************* 269** 270** Function NFA_P2pRejectConn 271** 272** Description This function is called to reject a request of data link 273** connection to a listening SAP on LLCP after receiving 274** NFA_P2P_CONN_REQ_EVT. 275** 276** Returns NFA_STATUS_OK if successfully initiated 277** NFA_STATUS_BAD_HANDLE if handle is not valid 278** NFA_STATUS_FAILED otherwise 279** 280*******************************************************************************/ 281NFC_API extern tNFA_STATUS NFA_P2pRejectConn (tNFA_HANDLE conn_handle); 282 283/******************************************************************************* 284** 285** Function NFA_P2pDisconnect 286** 287** Description This function is called to disconnect an existing or 288** connecting data link connection. 289** 290** discard any pending data on data link connection if flush is set to TRUE 291** 292** NFA_P2P_DISC_EVT will be returned after data link connection is disconnected 293** 294** Returns NFA_STATUS_OK if successfully initiated 295** NFA_STATUS_BAD_HANDLE if handle is not valid 296** NFA_STATUS_FAILED otherwise 297** 298*******************************************************************************/ 299NFC_API extern tNFA_STATUS NFA_P2pDisconnect (tNFA_HANDLE conn_handle, 300 BOOLEAN flush); 301 302/******************************************************************************* 303** 304** Function NFA_P2pConnectByName 305** 306** Description This function is called to create a connection-oriented transport 307** by a service name. 308** NFA_P2P_CONNECTED_EVT if success 309** NFA_P2P_DISC_EVT if failed 310** 311** Returns NFA_STATUS_OK if successfully initiated 312** NFA_STATUS_BAD_HANDLE if client is not registered 313** NFA_STATUS_FAILED otherwise 314** 315*******************************************************************************/ 316NFC_API extern tNFA_STATUS NFA_P2pConnectByName (tNFA_HANDLE client_handle, 317 char *p_service_name, 318 UINT16 miu, 319 UINT8 rw); 320 321/******************************************************************************* 322** 323** Function NFA_P2pConnectBySap 324** 325** Description This function is called to create a connection-oriented transport 326** by a SAP. 327** NFA_P2P_CONNECTED_EVT if success 328** NFA_P2P_DISC_EVT if failed 329** 330** Returns NFA_STATUS_OK if successfully initiated 331** NFA_STATUS_BAD_HANDLE if client is not registered 332** NFA_STATUS_FAILED otherwise 333** 334*******************************************************************************/ 335NFC_API extern tNFA_STATUS NFA_P2pConnectBySap (tNFA_HANDLE client_handle, 336 UINT8 dsap, 337 UINT16 miu, 338 UINT8 rw); 339 340/******************************************************************************* 341** 342** Function NFA_P2pSendUI 343** 344** Description This function is called to send data on connectionless 345** transport. 346** 347** Returns NFA_STATUS_OK if successfully initiated 348** NFA_STATUS_BAD_HANDLE if handle is not valid 349** NFA_STATUS_BAD_LENGTH if data length is more than remote link MIU 350** NFA_STATUS_CONGESTED if congested 351** NFA_STATUS_FAILED otherwise 352** 353*******************************************************************************/ 354NFC_API extern tNFA_STATUS NFA_P2pSendUI (tNFA_HANDLE handle, 355 UINT8 dsap, 356 UINT16 length, 357 UINT8 *p_data); 358 359/******************************************************************************* 360** 361** Function NFA_P2pReadUI 362** 363** Description This function is called to read data on connectionless 364** transport when receiving NFA_P2P_DATA_EVT with NFA_P2P_LLINK_TYPE. 365** 366** - Remote SAP who sent UI PDU is returned. 367** - Information of UI PDU up to max_data_len is copied into p_data. 368** - If more information of UI PDU or more UI PDU in queue then more 369** is returned to TRUE. 370** - Information of next UI PDU is not concatenated. 371** 372** Returns NFA_STATUS_OK if successfully initiated 373** NFA_STATUS_BAD_HANDLE if handle is not valid 374** 375*******************************************************************************/ 376NFC_API extern tNFA_STATUS NFA_P2pReadUI (tNFA_HANDLE handle, 377 UINT32 max_data_len, 378 UINT8 *p_remote_sap, 379 UINT32 *p_data_len, 380 UINT8 *p_data, 381 BOOLEAN *p_more); 382 383/******************************************************************************* 384** 385** Function NFA_P2pFlushUI 386** 387** Description This function is called to flush data on connectionless 388** transport. 389** 390** Returns NFA_STATUS_OK if successfully initiated 391** NFA_STATUS_BAD_HANDLE if handle is not valid 392** 393*******************************************************************************/ 394NFC_API extern tNFA_STATUS NFA_P2pFlushUI (tNFA_HANDLE handle, 395 UINT32 *p_length); 396 397/******************************************************************************* 398** 399** Function NFA_P2pSendData 400** 401** Description This function is called to send data on connection-oriented 402** transport. 403** 404** Returns NFA_STATUS_OK if successfully initiated 405** NFA_STATUS_BAD_HANDLE if handle is not valid 406** NFA_STATUS_BAD_LENGTH if data length is more than remote MIU 407** NFA_STATUS_CONGESTED if congested 408** NFA_STATUS_FAILED otherwise 409** 410*******************************************************************************/ 411NFC_API extern tNFA_STATUS NFA_P2pSendData (tNFA_HANDLE conn_handle, 412 UINT16 length, 413 UINT8 *p_data); 414 415/******************************************************************************* 416** 417** Function NFA_P2pReadData 418** 419** Description This function is called to read data on connection-oriented 420** transport when receiving NFA_P2P_DATA_EVT with NFA_P2P_DLINK_TYPE. 421** 422** - Information of I PDU is copied into p_data up to max_data_len. 423** - If more information of I PDU or more I PDU in queue, then more 424** is returned to TRUE. 425** - Information of next I PDU is not concatenated. 426** 427** Returns NFA_STATUS_OK if successfully initiated 428** NFA_STATUS_BAD_HANDLE if handle is not valid 429** 430*******************************************************************************/ 431NFC_API extern tNFA_STATUS NFA_P2pReadData (tNFA_HANDLE handle, 432 UINT32 max_data_len, 433 UINT32 *p_data_len, 434 UINT8 *p_data, 435 BOOLEAN *p_more); 436 437/******************************************************************************* 438** 439** Function NFA_P2pFlushData 440** 441** Description This function is called to flush data on connection-oriented 442** transport. 443** 444** Returns NFA_STATUS_OK if successfully initiated 445** NFA_STATUS_BAD_HANDLE if handle is not valid 446** 447*******************************************************************************/ 448NFC_API extern tNFA_STATUS NFA_P2pFlushData (tNFA_HANDLE handle, 449 UINT32 *p_length); 450 451/******************************************************************************* 452** 453** Function NFA_P2pSetLocalBusy 454** 455** Description This function is called to stop or resume incoming data on 456** connection-oriented transport. 457** 458** Returns NFA_STATUS_OK if successfully initiated 459** NFA_STATUS_BAD_HANDLE if handle is not valid 460** NFA_STATUS_FAILED otherwise 461** 462*******************************************************************************/ 463NFC_API extern tNFA_STATUS NFA_P2pSetLocalBusy (tNFA_HANDLE conn_handle, 464 BOOLEAN is_busy); 465 466/******************************************************************************* 467** 468** Function NFA_P2pGetLinkInfo 469** 470** Description This function is called to get local/remote link MIU and 471** Well-Known Service list encoded as a 16-bit field of connected LLCP. 472** NFA_P2P_LINK_INFO_EVT will be returned. 473** 474** Returns NFA_STATUS_OK if successfully initiated 475** NFA_STATUS_BAD_HANDLE if server or client is not registered 476** NFA_STATUS_FAILED otherwise 477** 478*******************************************************************************/ 479NFC_API extern tNFA_STATUS NFA_P2pGetLinkInfo (tNFA_HANDLE handle); 480 481/******************************************************************************* 482** 483** Function NFA_P2pGetRemoteSap 484** 485** Description This function is called to get SAP associated by service name 486** on connected remote LLCP. 487** NFA_P2P_SDP_EVT will be returned. 488** 489** Returns NFA_STATUS_OK if successfully initiated 490** NFA_STATUS_BAD_HANDLE if server or client is not registered 491** NFA_STATUS_FAILED otherwise 492** 493*******************************************************************************/ 494NFC_API extern tNFA_STATUS NFA_P2pGetRemoteSap (tNFA_HANDLE handle, 495 char *p_service_name); 496 497/******************************************************************************* 498** 499** Function NFA_P2pSetLLCPConfig 500** 501** Description This function is called to change LLCP config parameters. 502** Application must call while LLCP is not activated. 503** 504** Parameters descriptions (default value) 505** - Local Link MIU (LLCP_MIU) 506** - Option parameter (LLCP_OPT_VALUE) 507** - Response Waiting Time Index (LLCP_WAITING_TIME) 508** - Local Link Timeout (LLCP_LTO_VALUE) 509** - Inactivity Timeout as initiator role (LLCP_INIT_INACTIVITY_TIMEOUT) 510** - Inactivity Timeout as target role (LLCP_TARGET_INACTIVITY_TIMEOUT) 511** - Delay SYMM response (LLCP_DELAY_RESP_TIME) 512** - Data link connection timeout (LLCP_DATA_LINK_CONNECTION_TOUT) 513** - Delay timeout to send first PDU as initiator (LLCP_DELAY_TIME_TO_SEND_FIRST_PDU) 514** 515** Returns NFA_STATUS_OK if successfully initiated 516** NFA_STATUS_FAILED otherwise 517** 518*******************************************************************************/ 519NFC_API extern tNFA_STATUS NFA_P2pSetLLCPConfig (UINT16 link_miu, 520 UINT8 opt, 521 UINT8 wt, 522 UINT16 link_timeout, 523 UINT16 inact_timeout_init, 524 UINT16 inact_timeout_target, 525 UINT16 symm_delay, 526 UINT16 data_link_timeout, 527 UINT16 delay_first_pdu_timeout); 528 529/******************************************************************************* 530** 531** Function NFA_P2pGetLLCPConfig 532** 533** Description This function is called to read LLCP config parameters. 534** 535** Parameters descriptions 536** - Local Link MIU 537** - Option parameter 538** - Response Waiting Time Index 539** - Local Link Timeout 540** - Inactivity Timeout as initiator role 541** - Inactivity Timeout as target role 542** - Delay SYMM response 543** - Data link connection timeout 544** - Delay timeout to send first PDU as initiator 545** 546** Returns None 547** 548*******************************************************************************/ 549NFC_API extern void NFA_P2pGetLLCPConfig (UINT16 *p_link_miu, 550 UINT8 *p_opt, 551 UINT8 *p_wt, 552 UINT16 *p_link_timeout, 553 UINT16 *p_inact_timeout_init, 554 UINT16 *p_inact_timeout_target, 555 UINT16 *p_symm_delay, 556 UINT16 *p_data_link_timeout, 557 UINT16 *p_delay_first_pdu_timeout); 558 559/******************************************************************************* 560** 561** Function NFA_P2pSetTraceLevel 562** 563** Description This function sets the trace level for P2P. If called with 564** a value of 0xFF, it simply returns the current trace level. 565** 566** Returns The new or current trace level 567** 568*******************************************************************************/ 569NFC_API extern UINT8 NFA_P2pSetTraceLevel (UINT8 new_level); 570 571#ifdef __cplusplus 572} 573#endif 574 575#endif /* NFA_P2P_API_H */ 576 577