nfa_dm_api.c revision b4b1c46fa5346651a3554c83eb5005f942f1af0f
1/****************************************************************************** 2 * 3 * Copyright (C) 2010-2013 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 * NFA interface for device management 23 * 24 ******************************************************************************/ 25#include <string.h> 26#include "nfa_api.h" 27#include "nfa_sys.h" 28#include "nfa_dm_int.h" 29#include "nfa_ce_int.h" 30#include "nfa_sys_int.h" 31#include "ndef_utils.h" 32 33/***************************************************************************** 34** Constants 35*****************************************************************************/ 36 37/***************************************************************************** 38** APIs 39*****************************************************************************/ 40/******************************************************************************* 41** 42** Function NFA_Init 43** 44** Description This function initializes control blocks for NFA 45** 46** p_hal_entry_tbl points to a table of HAL entry points 47** 48** NOTE: the buffer that p_hal_entry_tbl points must be 49** persistent until NFA is disabled. 50** 51** Returns none 52** 53*******************************************************************************/ 54void NFA_Init(tHAL_NFC_ENTRY *p_hal_entry_tbl) 55{ 56 NFA_TRACE_API0 ("NFA_Init ()"); 57 nfa_sys_init(); 58 nfa_dm_init(); 59 nfa_p2p_init(); 60 nfa_cho_init(); 61 nfa_snep_init(FALSE); 62 nfa_rw_init(); 63 nfa_ce_init(); 64 nfa_ee_init(); 65 if (nfa_ee_max_ee_cfg != 0) 66 { 67 nfa_dm_cb.get_max_ee = p_hal_entry_tbl->get_max_ee; 68 nfa_hci_init(); 69 } 70 71 72 /* Initialize NFC module */ 73 NFC_Init (p_hal_entry_tbl); 74} 75 76/******************************************************************************* 77** 78** Function NFA_Enable 79** 80** Description This function enables NFC. Prior to calling NFA_Enable, 81** the NFCC must be powered up, and ready to receive commands. 82** This function enables the tasks needed by NFC, opens the NCI 83** transport, resets the NFC controller, downloads patches to 84** the NFCC (if necessary), and initializes the NFC subsystems. 85** 86** This function should only be called once - typically when NFC 87** is enabled during boot-up, or when NFC is enabled from a 88** settings UI. Subsequent calls to NFA_Enable while NFA is 89** enabling or enabled will be ignored. When the NFC startup 90** procedure is completed, an NFA_DM_ENABLE_EVT is returned to the 91** application using the tNFA_DM_CBACK. 92** 93** Returns NFA_STATUS_OK if successfully initiated 94** NFA_STATUS_FAILED otherwise 95** 96*******************************************************************************/ 97tNFA_STATUS NFA_Enable (tNFA_DM_CBACK *p_dm_cback, 98 tNFA_CONN_CBACK *p_conn_cback) 99{ 100 tNFA_DM_API_ENABLE *p_msg; 101 102 NFA_TRACE_API0 ("NFA_Enable ()"); 103 104 /* Validate parameters */ 105 if ((!p_dm_cback) || (!p_conn_cback)) 106 { 107 NFA_TRACE_ERROR0 ("NFA_Enable (): error null callback"); 108 return (NFA_STATUS_FAILED); 109 } 110 111 if ((p_msg = (tNFA_DM_API_ENABLE *) GKI_getbuf (sizeof (tNFA_DM_API_ENABLE))) != NULL) 112 { 113 p_msg->hdr.event = NFA_DM_API_ENABLE_EVT; 114 p_msg->p_dm_cback = p_dm_cback; 115 p_msg->p_conn_cback = p_conn_cback; 116 117 nfa_sys_sendmsg (p_msg); 118 119 return (NFA_STATUS_OK); 120 } 121 122 return (NFA_STATUS_FAILED); 123} 124 125/******************************************************************************* 126** 127** Function NFA_Disable 128** 129** Description This function is called to shutdown NFC. The tasks for NFC 130** are terminated, and clean up routines are performed. This 131** function is typically called during platform shut-down, or 132** when NFC is disabled from a settings UI. When the NFC 133** shutdown procedure is completed, an NFA_DM_DISABLE_EVT is 134** returned to the application using the tNFA_DM_CBACK. 135** 136** The platform should wait until the NFC_DISABLE_REVT is 137** received before powering down the NFC chip and NCI transport. 138** This is required to so that NFA can gracefully shut down any 139** open connections. 140** 141** Returns NFA_STATUS_OK if successfully initiated 142** NFA_STATUS_FAILED otherwise 143** 144*******************************************************************************/ 145tNFA_STATUS NFA_Disable (BOOLEAN graceful) 146{ 147 tNFA_DM_API_DISABLE *p_msg; 148 149 NFA_TRACE_API1 ("NFA_Disable (graceful=%i)", graceful); 150 151 if ((p_msg = (tNFA_DM_API_DISABLE *) GKI_getbuf (sizeof (tNFA_DM_API_DISABLE))) != NULL) 152 { 153 p_msg->hdr.event = NFA_DM_API_DISABLE_EVT; 154 p_msg->graceful = graceful; 155 156 nfa_sys_sendmsg (p_msg); 157 158 return (NFA_STATUS_OK); 159 } 160 161 return (NFA_STATUS_FAILED); 162} 163 164/******************************************************************************* 165** 166** Function NFA_SetConfig 167** 168** Description Set the configuration parameters to NFCC. The result is 169** reported with an NFA_DM_SET_CONFIG_EVT in the tNFA_DM_CBACK 170** callback. 171** 172** Note: If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT 173** should happen before calling this function. Most Configuration 174** parameters are related to RF discovery. 175** 176** Returns NFA_STATUS_OK if successfully initiated 177** NFA_STATUS_BUSY if previous setting is on-going 178** NFA_STATUS_FAILED otherwise 179** 180*******************************************************************************/ 181tNFA_STATUS NFA_SetConfig (tNFA_PMID param_id, 182 UINT8 length, 183 UINT8 *p_data) 184{ 185 tNFA_DM_API_SET_CONFIG *p_msg; 186 187 NFA_TRACE_API1 ("NFA_SetConfig (): param_id:0x%X", param_id); 188 189 if ((p_msg = (tNFA_DM_API_SET_CONFIG *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_SET_CONFIG) + length))) != NULL) 190 { 191 p_msg->hdr.event = NFA_DM_API_SET_CONFIG_EVT; 192 193 p_msg->param_id = param_id; 194 p_msg->length = length; 195 p_msg->p_data = (UINT8 *) (p_msg + 1); 196 197 /* Copy parameter data */ 198 memcpy (p_msg->p_data, p_data, length); 199 200 nfa_sys_sendmsg (p_msg); 201 202 return (NFA_STATUS_OK); 203 } 204 205 return (NFA_STATUS_FAILED); 206} 207 208/******************************************************************************* 209** 210** Function NFA_GetConfig 211** 212** Description Get the configuration parameters from NFCC. The result is 213** reported with an NFA_DM_GET_CONFIG_EVT in the tNFA_DM_CBACK 214** callback. 215** 216** Returns NFA_STATUS_OK if successfully initiated 217** NFA_STATUS_FAILED otherwise 218** 219*******************************************************************************/ 220tNFA_STATUS NFA_GetConfig (UINT8 num_ids, 221 tNFA_PMID *p_param_ids) 222{ 223 tNFA_DM_API_GET_CONFIG *p_msg; 224 225 NFA_TRACE_API1 ("NFA_GetConfig (): num_ids: %i", num_ids); 226 227 228 if ((p_msg = (tNFA_DM_API_GET_CONFIG *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_GET_CONFIG) + num_ids))) != NULL) 229 { 230 p_msg->hdr.event = NFA_DM_API_GET_CONFIG_EVT; 231 232 p_msg->num_ids = num_ids; 233 p_msg->p_pmids = (tNFA_PMID *) (p_msg+1); 234 235 /* Copy the param IDs */ 236 memcpy (p_msg->p_pmids, p_param_ids, num_ids); 237 238 nfa_sys_sendmsg (p_msg); 239 240 return (NFA_STATUS_OK); 241 } 242 243 return (NFA_STATUS_FAILED); 244} 245 246/******************************************************************************* 247** 248** Function NFA_RequestExclusiveRfControl 249** 250** Description Request exclusive control of NFC. 251** - Previous behavior (polling/tag reading, DH card emulation) 252** will be suspended . 253** - Polling and listening will be done based on the specified 254** params 255** 256** The NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT event of 257** tNFA_CONN_CBACK indicates the status of the operation. 258** 259** NFA_ACTIVATED_EVT and NFA_DEACTIVATED_EVT indicates link 260** activation/deactivation. 261** 262** NFA_SendRawFrame is used to send data to the peer. NFA_DATA_EVT 263** indicates data from the peer. 264** 265** If a tag is activated, then the NFA_RW APIs may be used to 266** send commands to the tag. Incoming NDEF messages are sent to 267** the NDEF callback. 268** 269** Once exclusive RF control has started, NFA will not activate 270** LLCP internally. The application has exclusive control of 271** the link. 272** 273** Note: If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT 274** should happen before calling this function 275** 276** Returns NFA_STATUS_OK if successfully initiated 277** NFA_STATUS_FAILED otherwise 278** 279*******************************************************************************/ 280tNFA_STATUS NFA_RequestExclusiveRfControl (tNFA_TECHNOLOGY_MASK poll_mask, 281 tNFA_LISTEN_CFG *p_listen_cfg, 282 tNFA_CONN_CBACK *p_conn_cback, 283 tNFA_NDEF_CBACK *p_ndef_cback) 284{ 285 tNFA_DM_API_REQ_EXCL_RF_CTRL *p_msg; 286 287 NFA_TRACE_API1 ("NFA_RequestExclusiveRfControl () poll_mask=0x%x", poll_mask); 288 289 if (!p_conn_cback) 290 { 291 NFA_TRACE_ERROR0 ("NFA_RequestExclusiveRfControl (): error null callback"); 292 return (NFA_STATUS_FAILED); 293 } 294 295 if ((p_msg = (tNFA_DM_API_REQ_EXCL_RF_CTRL *) GKI_getbuf (sizeof (tNFA_DM_API_REQ_EXCL_RF_CTRL))) != NULL) 296 { 297 p_msg->hdr.event = NFA_DM_API_REQUEST_EXCL_RF_CTRL_EVT; 298 p_msg->poll_mask = poll_mask; 299 p_msg->p_conn_cback = p_conn_cback; 300 p_msg->p_ndef_cback = p_ndef_cback; 301 302 if (p_listen_cfg) 303 memcpy (&p_msg->listen_cfg, p_listen_cfg, sizeof (tNFA_LISTEN_CFG)); 304 else 305 memset (&p_msg->listen_cfg, 0x00, sizeof (tNFA_LISTEN_CFG)); 306 307 nfa_sys_sendmsg (p_msg); 308 309 return (NFA_STATUS_OK); 310 } 311 312 return (NFA_STATUS_FAILED); 313} 314 315/******************************************************************************* 316** 317** Function NFA_ReleaseExclusiveRfControl 318** 319** Description Release exclusive control of NFC. Once released, behavior 320** prior to obtaining exclusive RF control will resume. 321** 322** Returns NFA_STATUS_OK if successfully initiated 323** NFA_STATUS_FAILED otherwise 324** 325*******************************************************************************/ 326tNFA_STATUS NFA_ReleaseExclusiveRfControl (void) 327{ 328 BT_HDR *p_msg; 329 330 NFA_TRACE_API0 ("NFA_ReleaseExclusiveRfControl ()"); 331 332 if (!nfa_dm_cb.p_excl_conn_cback) 333 { 334 NFA_TRACE_ERROR0 ("NFA_ReleaseExclusiveRfControl (): Exclusive rf control is not in progress"); 335 return (NFA_STATUS_FAILED); 336 } 337 338 if ((p_msg = (BT_HDR *) GKI_getbuf (sizeof (BT_HDR))) != NULL) 339 { 340 p_msg->event = NFA_DM_API_RELEASE_EXCL_RF_CTRL_EVT; 341 nfa_sys_sendmsg (p_msg); 342 return (NFA_STATUS_OK); 343 } 344 345 return (NFA_STATUS_FAILED); 346} 347 348 349/******************************************************************************* 350** 351** Function NFA_EnablePolling 352** 353** Description Enable polling for technologies specified by poll_mask. 354** 355** The following events (notified using the connection 356** callback registered with NFA_Enable) are generated during 357** polling: 358** 359** - NFA_POLL_ENABLED_EVT indicates whether or not polling 360** successfully enabled. 361** - NFA_DISC_RESULT_EVT indicates there are more than one devices, 362** so application must select one of tags by calling NFA_Select(). 363** - NFA_SELECT_RESULT_EVT indicates whether previous selection was 364** successful or not. If it was failed then application must select 365** again or deactivate by calling NFA_Deactivate(). 366** - NFA_ACTIVATED_EVT is generated when an NFC link is activated. 367** - NFA_NDEF_DETECT_EVT is generated if tag is activated 368** - NFA_LLCP_ACTIVATED_EVT/NFA_LLCP_DEACTIVATED_EVT is generated 369** if NFC-DEP is activated 370** - NFA_DEACTIVATED_EVT will be returned after deactivating NFC link. 371** 372** Note: If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT 373** should happen before calling this function 374** 375** Returns NFA_STATUS_OK if successfully initiated 376** NFA_STATUS_FAILED otherwise 377** 378*******************************************************************************/ 379tNFA_STATUS NFA_EnablePolling (tNFA_TECHNOLOGY_MASK poll_mask) 380{ 381 tNFA_DM_API_ENABLE_POLL *p_msg; 382 383 NFA_TRACE_API1 ("NFA_EnablePolling () 0x%X", poll_mask); 384 385 if ((p_msg = (tNFA_DM_API_ENABLE_POLL *) GKI_getbuf (sizeof (tNFA_DM_API_ENABLE_POLL))) != NULL) 386 { 387 p_msg->hdr.event = NFA_DM_API_ENABLE_POLLING_EVT; 388 p_msg->poll_mask = poll_mask; 389 390 nfa_sys_sendmsg (p_msg); 391 392 return (NFA_STATUS_OK); 393 } 394 395 return (NFA_STATUS_FAILED); 396} 397 398/******************************************************************************* 399** 400** Function NFA_DisablePolling 401** 402** Description Disable polling 403** NFA_POLL_DISABLED_EVT will be returned after stopping polling. 404** 405** Note: If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT 406** should happen before calling this function 407** 408** Returns NFA_STATUS_OK if successfully initiated 409** NFA_STATUS_FAILED otherwise 410** 411*******************************************************************************/ 412tNFA_STATUS NFA_DisablePolling (void) 413{ 414 BT_HDR *p_msg; 415 416 NFA_TRACE_API0 ("NFA_DisablePolling ()"); 417 418 if ((p_msg = (BT_HDR *) GKI_getbuf (sizeof (BT_HDR))) != NULL) 419 { 420 p_msg->event = NFA_DM_API_DISABLE_POLLING_EVT; 421 422 nfa_sys_sendmsg (p_msg); 423 424 return (NFA_STATUS_OK); 425 } 426 427 return (NFA_STATUS_FAILED); 428} 429 430/******************************************************************************* 431** 432** Function NFA_SetP2pListenTech 433** 434** Description This function is called to set listen technology for NFC-DEP. 435** This funtion may be called before or after starting any server 436** on NFA P2P/CHO/SNEP. 437** If there is no technology for NFC-DEP, P2P listening will be 438** stopped. 439** 440** NFA_SET_P2P_LISTEN_TECH_EVT without data will be returned. 441** 442** Note: If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT 443** should happen before calling this function 444** 445** Returns NFA_STATUS_OK if successfully initiated 446** NFA_STATUS_FAILED otherwise 447** 448*******************************************************************************/ 449tNFA_STATUS NFA_SetP2pListenTech (tNFA_TECHNOLOGY_MASK tech_mask) 450{ 451 tNFA_DM_API_SET_P2P_LISTEN_TECH *p_msg; 452 453 NFA_TRACE_API1 ("NFA_P2pSetListenTech (): tech_mask:0x%X", tech_mask); 454 455 if ((p_msg = (tNFA_DM_API_SET_P2P_LISTEN_TECH *) GKI_getbuf (sizeof (tNFA_DM_API_SET_P2P_LISTEN_TECH))) != NULL) 456 { 457 p_msg->hdr.event = NFA_DM_API_SET_P2P_LISTEN_TECH_EVT; 458 p_msg->tech_mask = tech_mask; 459 460 nfa_sys_sendmsg (p_msg); 461 462 return (NFA_STATUS_OK); 463 } 464 465 return (NFA_STATUS_FAILED); 466} 467 468/******************************************************************************* 469** 470** Function NFA_StartRfDiscovery 471** 472** Description Start RF discovery 473** RF discovery parameters shall be set by other APIs. 474** 475** An NFA_RF_DISCOVERY_STARTED_EVT indicates whether starting was successful or not. 476** 477** Returns NFA_STATUS_OK if successfully initiated 478** NFA_STATUS_FAILED otherwise 479** 480*******************************************************************************/ 481tNFA_STATUS NFA_StartRfDiscovery (void) 482{ 483 BT_HDR *p_msg; 484 485 NFA_TRACE_API0 ("NFA_StartRfDiscovery ()"); 486 487 if ((p_msg = (BT_HDR *) GKI_getbuf (sizeof (BT_HDR))) != NULL) 488 { 489 p_msg->event = NFA_DM_API_START_RF_DISCOVERY_EVT; 490 491 nfa_sys_sendmsg (p_msg); 492 493 return (NFA_STATUS_OK); 494 } 495 496 return (NFA_STATUS_FAILED); 497} 498 499/******************************************************************************* 500** 501** Function NFA_StopRfDiscovery 502** 503** Description Stop RF discovery 504** 505** An NFA_RF_DISCOVERY_STOPPED_EVT indicates whether stopping was successful or not. 506** 507** Returns NFA_STATUS_OK if successfully initiated 508** NFA_STATUS_FAILED otherwise 509** 510*******************************************************************************/ 511tNFA_STATUS NFA_StopRfDiscovery (void) 512{ 513 BT_HDR *p_msg; 514 515 NFA_TRACE_API0 ("NFA_StopRfDiscovery ()"); 516 517 if ((p_msg = (BT_HDR *) GKI_getbuf (sizeof (BT_HDR))) != NULL) 518 { 519 p_msg->event = NFA_DM_API_STOP_RF_DISCOVERY_EVT; 520 521 nfa_sys_sendmsg (p_msg); 522 523 return (NFA_STATUS_OK); 524 } 525 526 return (NFA_STATUS_FAILED); 527} 528 529/******************************************************************************* 530** 531** Function NFA_SetRfDiscoveryDuration 532** 533** Description Set the duration of the single discovery period in [ms]. 534** Allowable range: 0 ms to 0xFFFF ms. 535** 536** If discovery is already started, the application should 537** call NFA_StopRfDiscovery prior to calling 538** NFA_SetRfDiscoveryDuration, and then call 539** NFA_StartRfDiscovery afterwards to restart discovery using 540** the new duration. 541** 542** Note: If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT 543** should happen before calling this function 544** 545** Returns: 546** NFA_STATUS_OK, if command accepted 547** NFA_STATUS_FAILED: otherwise 548** 549*******************************************************************************/ 550tNFA_STATUS NFA_SetRfDiscoveryDuration (UINT16 discovery_period_ms) 551{ 552 tNFA_DM_API_SET_RF_DISC_DUR *p_msg; 553 554 NFA_TRACE_API0 ("NFA_SetRfDiscoveryDuration ()"); 555 556 /* Post the API message */ 557 if ((p_msg = (tNFA_DM_API_SET_RF_DISC_DUR *) GKI_getbuf (sizeof (BT_HDR))) != NULL) 558 { 559 p_msg->hdr.event = NFA_DM_API_SET_RF_DISC_DURATION_EVT; 560 561 /* Set discovery duration */ 562 p_msg->rf_disc_dur_ms = discovery_period_ms; 563 564 nfa_sys_sendmsg (p_msg); 565 566 return (NFA_STATUS_OK); 567 } 568 569 return (NFA_STATUS_FAILED); 570} 571 572/******************************************************************************* 573** 574** Function NFA_Select 575** 576** Description Select one from detected devices during discovery 577** (from NFA_DISC_RESULT_EVTs). The application should wait for 578** the final NFA_DISC_RESULT_EVT before selecting. 579** 580** An NFA_SELECT_RESULT_EVT indicates whether selection was successful or not. 581** If failed then application must select again or deactivate by NFA_Deactivate(). 582** 583** Returns NFA_STATUS_OK if successfully initiated 584** NFA_STATUS_INVALID_PARAM if RF interface is not matched protocol 585** NFA_STATUS_FAILED otherwise 586** 587*******************************************************************************/ 588tNFA_STATUS NFA_Select (UINT8 rf_disc_id, 589 tNFA_NFC_PROTOCOL protocol, 590 tNFA_INTF_TYPE rf_interface) 591{ 592 tNFA_DM_API_SELECT *p_msg; 593 594 NFA_TRACE_API3 ("NFA_Select (): rf_disc_id:0x%X, protocol:0x%X, rf_interface:0x%X", 595 rf_disc_id, protocol, rf_interface); 596 597 if ( ((rf_interface == NFA_INTERFACE_ISO_DEP) && (protocol != NFA_PROTOCOL_ISO_DEP)) 598 ||((rf_interface == NFA_INTERFACE_NFC_DEP) && (protocol != NFA_PROTOCOL_NFC_DEP)) ) 599 { 600 NFA_TRACE_ERROR0 ("NFA_Select (): RF interface is not matched protocol"); 601 return (NFA_STATUS_INVALID_PARAM); 602 } 603 604 if ((p_msg = (tNFA_DM_API_SELECT *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_SELECT)))) != NULL) 605 { 606 p_msg->hdr.event = NFA_DM_API_SELECT_EVT; 607 p_msg->rf_disc_id = rf_disc_id; 608 p_msg->protocol = protocol; 609 p_msg->rf_interface = rf_interface; 610 611 nfa_sys_sendmsg (p_msg); 612 613 return (NFA_STATUS_OK); 614 } 615 616 return (NFA_STATUS_FAILED); 617} 618 619/******************************************************************************* 620** 621** Function NFA_UpdateRFCommParams 622** 623** Description This function is called to update RF Communication parameters 624** once the Frame RF Interface has been activated. 625** 626** An NFA_UPDATE_RF_PARAM_RESULT_EVT indicates whether updating 627** was successful or not. 628** 629** Returns NFA_STATUS_OK if successfully initiated 630** NFA_STATUS_FAILED otherwise 631** 632*******************************************************************************/ 633tNFA_STATUS NFA_UpdateRFCommParams (tNFA_RF_COMM_PARAMS *p_params) 634{ 635 tNFA_DM_API_UPDATE_RF_PARAMS *p_msg; 636 637 NFA_TRACE_API0 ("NFA_UpdateRFCommParams ()"); 638 639 if ((p_msg = (tNFA_DM_API_UPDATE_RF_PARAMS *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_UPDATE_RF_PARAMS)))) != NULL) 640 { 641 p_msg->hdr.event = NFA_DM_API_UPDATE_RF_PARAMS_EVT; 642 memcpy (&p_msg->params, p_params, sizeof (tNFA_RF_COMM_PARAMS)); 643 644 nfa_sys_sendmsg (p_msg); 645 646 return (NFA_STATUS_OK); 647 } 648 649 return (NFA_STATUS_FAILED); 650} 651 652/******************************************************************************* 653** 654** Function NFA_Deactivate 655** 656** Description 657** If sleep_mode=TRUE: 658** Deselect the activated device by deactivating into sleep mode. 659** 660** An NFA_DEACTIVATE_FAIL_EVT indicates that selection was not successful. 661** Application can select another discovered device or deactivate by NFA_Deactivate () 662** after receiving NFA_DEACTIVATED_EVT. 663** 664** Deactivating to sleep mode is not allowed when NFCC is in wait-for-host-select 665** mode, or in listen-sleep states; NFA will deactivate to idle or discovery state 666** for these cases respectively. 667** 668** 669** If sleep_mode=FALSE: 670** Deactivate the connection (e.g. as a result of presence check failure) 671** NFA_DEACTIVATED_EVT will indicate that link is deactivated. 672** Polling/listening will resume (unless the nfcc is in wait_for-all-discoveries state) 673** 674** 675** Returns NFA_STATUS_OK if successfully initiated 676** NFA_STATUS_FAILED otherwise 677** 678*******************************************************************************/ 679NFC_API extern tNFA_STATUS NFA_Deactivate (BOOLEAN sleep_mode) 680{ 681 tNFA_DM_API_DEACTIVATE *p_msg; 682 683 NFA_TRACE_API1 ("NFA_Deactivate (): sleep_mode:%i", sleep_mode); 684 685 if ((p_msg = (tNFA_DM_API_DEACTIVATE *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_DEACTIVATE)))) != NULL) 686 { 687 p_msg->hdr.event = NFA_DM_API_DEACTIVATE_EVT; 688 p_msg->sleep_mode = sleep_mode; 689 690 nfa_sys_sendmsg (p_msg); 691 692 return (NFA_STATUS_OK); 693 } 694 695 return (NFA_STATUS_FAILED); 696} 697 698/******************************************************************************* 699** 700** Function NFA_SendRawFrame 701** 702** Description Send a raw frame over the activated interface with the NFCC. 703** This function can only be called after NFC link is activated. 704** 705** If the activated interface is a tag and auto-presence check is 706** enabled then presence_check_start_delay can be used to indicate 707** the delay in msec after which the next auto presence check 708** command can be sent. NFA_DM_DEFAULT_PRESENCE_CHECK_START_DELAY 709** can be used as the default value for the delay. 710** 711** Returns NFA_STATUS_OK if successfully initiated 712** NFA_STATUS_FAILED otherwise 713** 714*******************************************************************************/ 715tNFA_STATUS NFA_SendRawFrame (UINT8 *p_raw_data, 716 UINT16 data_len, 717 UINT16 presence_check_start_delay) 718{ 719 BT_HDR *p_msg; 720 UINT16 size; 721 UINT8 *p; 722 723 NFA_TRACE_API1 ("NFA_SendRawFrame () data_len:%d", data_len); 724 725 /* Validate parameters */ 726 if ((data_len == 0) || (p_raw_data == NULL)) 727 return (NFA_STATUS_INVALID_PARAM); 728 729 size = BT_HDR_SIZE + NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE + data_len; 730 if ((p_msg = (BT_HDR *) GKI_getbuf (size)) != NULL) 731 { 732 p_msg->event = NFA_DM_API_RAW_FRAME_EVT; 733 p_msg->layer_specific = presence_check_start_delay; 734 p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; 735 p_msg->len = data_len; 736 737 p = (UINT8 *) (p_msg + 1) + p_msg->offset; 738 memcpy (p, p_raw_data, data_len); 739 740 nfa_sys_sendmsg (p_msg); 741 742 return (NFA_STATUS_OK); 743 } 744 745 return (NFA_STATUS_FAILED); 746} 747 748/******************************************************************************* 749** NDEF Handler APIs 750*******************************************************************************/ 751 752/******************************************************************************* 753** 754** Function NFA_RegisterNDefTypeHandler 755** 756** Description This function allows the applications to register for 757** specific types of NDEF records. When NDEF records are 758** received, NFA will parse the record-type field, and pass 759** the record to the registered tNFA_NDEF_CBACK. 760** 761** For records types which were not registered, the record will 762** be sent to the default handler. A default type-handler may 763** be registered by calling this NFA_RegisterNDefTypeHandler 764** with tnf=NFA_TNF_DEFAULT. In this case, all un-registered 765** record types will be sent to the callback. Only one default 766** handler may be registered at a time. 767** 768** An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK 769** to indicate that registration was successful, and provide a 770** handle for this record type. 771** 772** Returns NFA_STATUS_OK if successfully initiated 773** NFA_STATUS_FAILED otherwise 774** 775*******************************************************************************/ 776tNFA_STATUS NFA_RegisterNDefTypeHandler (BOOLEAN handle_whole_message, 777 tNFA_TNF tnf, 778 UINT8 *p_type_name, 779 UINT8 type_name_len, 780 tNFA_NDEF_CBACK *p_ndef_cback) 781{ 782 tNFA_DM_API_REG_NDEF_HDLR *p_msg; 783 784 NFA_TRACE_API2 ("NFA_RegisterNDefTypeHandler (): handle whole ndef message: %i, tnf=0x%02x", handle_whole_message, tnf); 785 786 /* Check for NULL callback */ 787 if (!p_ndef_cback) 788 { 789 NFA_TRACE_ERROR0 ("NFA_RegisterNDefTypeHandler (): error - null callback"); 790 return (NFA_STATUS_INVALID_PARAM); 791 } 792 793 794 if ((p_msg = (tNFA_DM_API_REG_NDEF_HDLR *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_REG_NDEF_HDLR) + type_name_len))) != NULL) 795 { 796 p_msg->hdr.event = NFA_DM_API_REG_NDEF_HDLR_EVT; 797 798 p_msg->flags = (handle_whole_message ? NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE : 0); 799 p_msg->tnf = tnf; 800 p_msg->name_len = type_name_len; 801 p_msg->p_ndef_cback = p_ndef_cback; 802 memcpy (p_msg->name, p_type_name, type_name_len); 803 804 nfa_sys_sendmsg (p_msg); 805 806 return (NFA_STATUS_OK); 807 } 808 809 return (NFA_STATUS_FAILED); 810} 811 812/******************************************************************************* 813** 814** Function NFA_RegisterNDefUriHandler 815** 816** Description This API is a special-case of NFA_RegisterNDefTypeHandler 817** with TNF=NFA_TNF_WKT, and type_name='U' (URI record); and allows 818** registering for specific URI types (e.g. 'tel:' or 'mailto:'). 819** 820** An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK 821** to indicate that registration was successful, and provide a 822** handle for this registration. 823** 824** If uri_id=NFA_NDEF_URI_ID_ABSOLUTE, then p_abs_uri contains the 825** unabridged URI. For all other uri_id values, the p_abs_uri 826** parameter is ignored (i.e the URI prefix is implied by uri_id). 827** See [NFC RTD URI] for more information. 828** 829** Returns NFA_STATUS_OK if successfully initiated 830** NFA_STATUS_FAILED otherwise 831** 832*******************************************************************************/ 833NFC_API extern tNFA_STATUS NFA_RegisterNDefUriHandler (BOOLEAN handle_whole_message, 834 tNFA_NDEF_URI_ID uri_id, 835 UINT8 *p_abs_uri, 836 UINT8 uri_id_len, 837 tNFA_NDEF_CBACK *p_ndef_cback) 838{ 839 tNFA_DM_API_REG_NDEF_HDLR *p_msg; 840 841 NFA_TRACE_API2 ("NFA_RegisterNDefUriHandler (): handle whole ndef message: %i, uri_id=0x%02x", handle_whole_message, uri_id); 842 843 /* Check for NULL callback */ 844 if (!p_ndef_cback) 845 { 846 NFA_TRACE_ERROR0 ("NFA_RegisterNDefUriHandler (): error - null callback"); 847 return (NFA_STATUS_INVALID_PARAM); 848 } 849 850 851 if ((p_msg = (tNFA_DM_API_REG_NDEF_HDLR *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_REG_NDEF_HDLR) + uri_id_len))) != NULL) 852 { 853 p_msg->hdr.event = NFA_DM_API_REG_NDEF_HDLR_EVT; 854 855 p_msg->flags = NFA_NDEF_FLAGS_WKT_URI; 856 857 if (handle_whole_message) 858 { 859 p_msg->flags |= NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE; 860 } 861 862 /* abs_uri is only valid fir uri_id=NFA_NDEF_URI_ID_ABSOLUTE */ 863 if (uri_id != NFA_NDEF_URI_ID_ABSOLUTE) 864 { 865 uri_id_len = 0; 866 } 867 868 p_msg->tnf = NFA_TNF_WKT; 869 p_msg->uri_id = uri_id; 870 p_msg->name_len = uri_id_len; 871 p_msg->p_ndef_cback = p_ndef_cback; 872 memcpy (p_msg->name, p_abs_uri, uri_id_len); 873 874 nfa_sys_sendmsg (p_msg); 875 876 return (NFA_STATUS_OK); 877 } 878 879 return (NFA_STATUS_FAILED); 880} 881 882/******************************************************************************* 883** 884** Function NFA_DeregisterNDefTypeHandler 885** 886** Description Deregister NDEF record type handler. 887** 888** Returns NFA_STATUS_OK if successfully initiated 889** NFA_STATUS_FAILED otherwise 890** 891*******************************************************************************/ 892NFC_API extern tNFA_STATUS NFA_DeregisterNDefTypeHandler (tNFA_HANDLE ndef_type_handle) 893{ 894 tNFA_DM_API_DEREG_NDEF_HDLR *p_msg; 895 896 NFA_TRACE_API1 ("NFA_DeregisterNDefHandler (): handle 0x%08x", ndef_type_handle); 897 898 899 if ((p_msg = (tNFA_DM_API_DEREG_NDEF_HDLR *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_DEREG_NDEF_HDLR)))) != NULL) 900 { 901 p_msg->hdr.event = NFA_DM_API_DEREG_NDEF_HDLR_EVT; 902 p_msg->ndef_type_handle = ndef_type_handle; 903 904 nfa_sys_sendmsg (p_msg); 905 906 return (NFA_STATUS_OK); 907 } 908 909 return (NFA_STATUS_FAILED); 910} 911 912/******************************************************************************* 913** 914** Function NFA_PowerOffSleepMode 915** 916** Description This function is called to enter or leave NFCC Power Off Sleep mode 917** NFA_DM_PWR_MODE_CHANGE_EVT will be sent to indicate status. 918** 919** start_stop : TRUE if entering Power Off Sleep mode 920** FALSE if leaving Power Off Sleep mode 921** 922** Returns NFA_STATUS_OK if successfully initiated 923** NFA_STATUS_FAILED otherwise 924** 925*******************************************************************************/ 926tNFA_STATUS NFA_PowerOffSleepMode (BOOLEAN start_stop) 927{ 928 BT_HDR *p_msg; 929 930 NFA_TRACE_API1 ("NFA_PowerOffSleepState () start_stop=%d", start_stop); 931 932 if (nfa_dm_cb.flags & NFA_DM_FLAGS_SETTING_PWR_MODE) 933 { 934 NFA_TRACE_ERROR0 ("NFA_PowerOffSleepState (): NFA DM is busy to update power mode"); 935 return (NFA_STATUS_FAILED); 936 } 937 else 938 { 939 nfa_dm_cb.flags |= NFA_DM_FLAGS_SETTING_PWR_MODE; 940 } 941 942 if ((p_msg = (BT_HDR *) GKI_getbuf (sizeof (BT_HDR))) != NULL) 943 { 944 p_msg->event = NFA_DM_API_POWER_OFF_SLEEP_EVT; 945 p_msg->layer_specific = start_stop; 946 947 nfa_sys_sendmsg (p_msg); 948 949 return (NFA_STATUS_OK); 950 } 951 952 return (NFA_STATUS_FAILED); 953} 954 955/******************************************************************************* 956** 957** Function NFA_RegVSCback 958** 959** Description This function is called to register or de-register a callback 960** function to receive Proprietary NCI response and notification 961** events. 962** The maximum number of callback functions allowed is NFC_NUM_VS_CBACKS 963** 964** Returns tNFC_STATUS 965** 966*******************************************************************************/ 967tNFC_STATUS NFA_RegVSCback (BOOLEAN is_register, 968 tNFA_VSC_CBACK *p_cback) 969{ 970 tNFA_DM_API_REG_VSC *p_msg; 971 972 NFA_TRACE_API1 ("NFA_RegVSCback() is_register=%d", is_register); 973 974 if (p_cback == NULL) 975 { 976 NFA_TRACE_ERROR0 ("NFA_RegVSCback() requires a valid callback function"); 977 return (NFA_STATUS_FAILED); 978 } 979 980 if ((p_msg = (tNFA_DM_API_REG_VSC *) GKI_getbuf (sizeof(tNFA_DM_API_REG_VSC))) != NULL) 981 { 982 p_msg->hdr.event = NFA_DM_API_REG_VSC_EVT; 983 p_msg->is_register = is_register; 984 p_msg->p_cback = p_cback; 985 986 nfa_sys_sendmsg (p_msg); 987 988 return (NFA_STATUS_OK); 989 } 990 991 return (NFA_STATUS_FAILED); 992} 993 994/******************************************************************************* 995** 996** Function NFA_SendVsCommand 997** 998** Description This function is called to send an NCI Vendor Specific 999** command to NFCC. 1000** 1001** oid - The opcode of the VS command. 1002** cmd_params_len - The command parameter len 1003** p_cmd_params - The command parameter 1004** p_cback - The callback function to receive the command 1005** status 1006** 1007** Returns NFA_STATUS_OK if successfully initiated 1008** NFA_STATUS_FAILED otherwise 1009** 1010*******************************************************************************/ 1011tNFA_STATUS NFA_SendVsCommand (UINT8 oid, 1012 UINT8 cmd_params_len, 1013 UINT8 *p_cmd_params, 1014 tNFA_VSC_CBACK *p_cback) 1015{ 1016 tNFA_DM_API_SEND_VSC *p_msg; 1017 UINT16 size = sizeof(tNFA_DM_API_SEND_VSC) + cmd_params_len; 1018 1019 NFA_TRACE_API1 ("NFA_SendVsCommand() oid=0x%x", oid); 1020 1021 if ((p_msg = (tNFA_DM_API_SEND_VSC *) GKI_getbuf (size)) != NULL) 1022 { 1023 p_msg->hdr.event = NFA_DM_API_SEND_VSC_EVT; 1024 p_msg->oid = oid; 1025 p_msg->p_cback = p_cback; 1026 if (cmd_params_len && p_cmd_params) 1027 { 1028 p_msg->cmd_params_len = cmd_params_len; 1029 p_msg->p_cmd_params = (UINT8 *)(p_msg + 1); 1030 memcpy (p_msg->p_cmd_params, p_cmd_params, cmd_params_len); 1031 } 1032 else 1033 { 1034 p_msg->cmd_params_len = 0; 1035 p_msg->p_cmd_params = NULL; 1036 } 1037 1038 nfa_sys_sendmsg (p_msg); 1039 1040 return (NFA_STATUS_OK); 1041 } 1042 1043 return (NFA_STATUS_FAILED); 1044} 1045 1046/******************************************************************************* 1047** 1048** Function NFA_SetTraceLevel 1049** 1050** Description This function sets the trace level for NFA. If called with 1051** a value of 0xFF, it simply returns the current trace level. 1052** 1053** Returns The new or current trace level 1054** 1055*******************************************************************************/ 1056UINT8 NFA_SetTraceLevel (UINT8 new_level) 1057{ 1058 if (new_level != 0xFF) 1059 nfa_sys_set_trace_level (new_level); 1060 1061 return (nfa_sys_cb.trace_level); 1062} 1063 1064