1 /* 2 * Copyright (C) 2010 NXP Semiconductors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /*! 18 * =========================================================================== * 19 * * 20 * * 21 * \file phHciNfc_Generic.h * 22 * \brief Common HCI Header for the Generic HCI Management. * 23 * * 24 * * 25 * Project: NFC-FRI-1.1 * 26 * * 27 * $Date: Mon Mar 29 17:34:47 2010 $ * 28 * $Author: ing04880 $ * 29 * $Revision: 1.73 $ * 30 * $Aliases: NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $ 31 * * 32 * =========================================================================== * 33 */ 34 35 /*@{*/ 36 #ifndef PHHCINFC_GENERIC_H 37 #define PHHCINFC_GENERIC_H 38 39 /*@}*/ 40 41 42 /** 43 * \name HCI 44 * 45 * File: \ref phHciNfc_Generic.h 46 * 47 */ 48 /*@{*/ 49 #define PHHCINFC_GENERIC_FILEREVISION "$Revision: 1.73 $" /**< \ingroup grp_file_attributes */ 50 #define PHHCINFC_GENERIC_FILEALIASES "$Aliases: NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $" /**< \ingroup grp_file_attributes */ 51 /*@}*/ 52 /* 53 54 ################################################################################ 55 ***************************** Header File Inclusion **************************** 56 ################################################################################ 57 */ 58 59 #include <phNfcIoctlCode.h> 60 #include<phNfcInterface.h> 61 #include <phHciNfc.h> 62 63 /* 64 ################################################################################ 65 ****************************** Macro Definitions ******************************* 66 ################################################################################ 67 */ 68 69 #if defined(DEBUG) /*|| defined(_DEBUG) */ 70 #define HCI_TRACE 71 #endif 72 73 #define Trace_buffer phOsalNfc_DbgTraceBuffer 74 75 /* HCI TRACE Macros */ 76 #if defined(HCI_TRACE)&& !defined(SILENT_HCI) 77 #include <phOsalNfc.h> 78 #include <stdio.h> 79 extern char phOsalNfc_DbgTraceBuffer[]; 80 #define MAX_TRACE_BUFFER 150 81 /* #define HCI_PRINT( str ) phOsalNfc_DbgTrace(str) */ 82 #define HCI_PRINT( str ) phOsalNfc_DbgString(str) 83 #define HCI_DEBUG(str, arg) \ 84 { \ 85 snprintf(Trace_buffer,MAX_TRACE_BUFFER,str,arg); \ 86 phOsalNfc_DbgString(Trace_buffer); \ 87 } 88 #define HCI_PRINT_BUFFER(msg,buf,len) \ 89 { \ 90 snprintf(Trace_buffer,MAX_TRACE_BUFFER,"\n\t %s:",msg); \ 91 phOsalNfc_DbgString(Trace_buffer); \ 92 phOsalNfc_DbgTrace(buf,len); \ 93 phOsalNfc_DbgString("\r"); \ 94 \ 95 } 96 #else 97 #include <phDbgTrace.h> 98 #if defined(PHDBG_TRACES) && !defined(HCI_TRACE) 99 #define HCI_PRINT( str ) PHDBG_INFO(str) 100 #define HCI_DEBUG(str, arg) 101 #define HCI_PRINT_BUFFER(msg,buf,len) 102 #else 103 #define HCI_PRINT( str ) 104 #define HCI_DEBUG(str, arg) 105 #define HCI_PRINT_BUFFER(msg,buf,len) 106 #endif /* #if defined(PHDBG_TRACES) */ 107 /* #if defined(PHDBG_INFO) && defined (PHDBG_CRITICAL_ERROR) */ 108 109 #endif /* #if defined(HCI_TRACE) */ 110 111 #define ZERO 0x00U 112 113 114 #ifdef MASK_BITS 115 #define BYTE_SIZE 0x08U 116 117 /* HCI GET and SET BITS Macros */ 118 #define MASK_BITS8(p,l) \ 119 ( ( (((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE )? \ 120 (~(0xFFU<<((p)+(l))) & (0xFFU<<(p))):(0U) ) 121 #ifdef MASK_BITS 122 #define GET_BITS8(num,p,l) \ 123 ( ((((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE)? \ 124 (((num)& (MASK_BITS8(p,l)))>>(p)):(0U) ) 125 #else 126 #define GET_BITS8(num,p,l) \ 127 ( ((((p)+(l))<=BYTE_SIZE))? \ 128 (((num)>>(p))& (~(0xFFU<<(l)))):(0U) ) 129 #endif 130 #define SET_BITS8(num,p,l,val) \ 131 ( ((((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE)? \ 132 (((num)& (~MASK_BITS8(p,l)))|((val)<<(p))):(0U)) 133 134 #endif 135 136 /** \ingroup grp_hci_retval 137 The Corresponding HCI Gate Not Supported. 138 */ 139 #define NFCSTATUS_HCI_GATE_NOT_SUPPORTED (0x71U) 140 141 /** \ingroup grp_hci_retval 142 Invalid Command from the HCI Layer 143 */ 144 #define NFCSTATUS_INVALID_HCI_COMMAND (0x72U) 145 146 /** \ingroup grp_hci_retval 147 HCI Command not supported . */ 148 #define NFCSTATUS_COMMAND_NOT_SUPPORTED (0x73U) 149 150 /** \ingroup grp_hci_retval 151 Invalide Response from the HCI Layer 152 */ 153 #define NFCSTATUS_INVALID_HCI_RESPONSE (0x74U) 154 155 /** \ingroup grp_hci_retval 156 The Invalid Instruction type (Neither Command/Response nor Event ). 157 */ 158 #define NFCSTATUS_INVALID_HCI_INSTRUCTION (0x75U) 159 160 /** \ingroup grp_hci_retval 161 The Invalid Instruction type (Neither Command/Response nor Event ). 162 */ 163 #define NFCSTATUS_INVALID_HCI_INFORMATION (0x76U) 164 165 /** \ingroup grp_hci_retval 166 The Invalid HCI Sequence. 167 */ 168 #define NFCSTATUS_INVALID_HCI_SEQUENCE (0x78U) 169 170 171 /** \ingroup grp_hci_retval 172 The HCI Error Response with Response code. 173 */ 174 #define NFCSTATUS_HCI_RESPONSE(code) (code) 175 176 177 /* Length of the HCP and the HCP Message Header in Bytes */ 178 #define HCP_HEADER_LEN 0x02U 179 180 /* Length of the HCP Message Header in Bytes */ 181 #define HCP_MESSAGE_LEN 0x01U 182 183 /* HCP Header Chaining Bit Offset */ 184 #define HCP_CHAINBIT_OFFSET 0x07U 185 /* HCP Header Chaining Bit Length */ 186 #define HCP_CHAINBIT_LEN 0x01U 187 188 /* Chaining Bit Values */ 189 #define HCP_CHAINBIT_DEFAULT 0x01U 190 #define HCP_CHAINBIT_BEGIN 0x00U 191 #define HCP_CHAINBIT_END HCP_CHAINBIT_DEFAULT 192 193 /* HCP Header Pipe ID Offset */ 194 #define HCP_PIPEID_OFFSET 0x00U 195 /* HCP Header Pipe ID Length */ 196 #define HCP_PIPEID_LEN 0x07U 197 198 /* HCP Message Header Type Offset */ 199 #define HCP_MSG_TYPE_OFFSET 0x06U 200 /* HCP Message Header Type Length */ 201 #define HCP_MSG_TYPE_LEN 0x02U 202 203 /* HCP Message Type Values */ 204 #define HCP_MSG_TYPE_COMMAND 0x00U 205 #define HCP_MSG_TYPE_EVENT 0x01U 206 #define HCP_MSG_TYPE_RESPONSE 0x02U 207 #define HCP_MSG_TYPE_RESERVED 0x03U 208 209 /* HCP Message Header Instruction Offset */ 210 #define HCP_MSG_INSTRUCTION_OFFSET 0x00U 211 /* HCP Message Header Instruction Length */ 212 #define HCP_MSG_INSTRUCTION_LEN 0x06U 213 /* HCP Invalid Message Instruction */ 214 #define HCP_MSG_INSTRUCTION_INVALID 0x3FU 215 216 217 /* HCP Packet Zero Length */ 218 #define HCP_ZERO_LEN 0x00U 219 220 221 222 /** \internal Generic HCI Commands for all the Gates */ 223 #define ANY_SET_PARAMETER 0x01U 224 #define ANY_GET_PARAMETER 0x02U 225 #define ANY_OPEN_PIPE 0x03U 226 #define ANY_CLOSE_PIPE 0x04U 227 #define ANY_GENERIC_CMD_RFU_B 0x05U 228 #define ANY_GENERIC_CMD_RFU_E 0x0FU 229 230 /* 231 * 0x05-0x0F is Reserved for Future Use 232 */ 233 234 /** \internal HCI Administration Com mands for the Management of the Host Network */ 235 236 #define ADM_CREATE_PIPE 0x10U 237 #define ADM_DELETE_PIPE 0x11U 238 #define ADM_NOTIFY_PIPE_CREATED 0x12U 239 #define ADM_NOTIFY_PIPE_DELETED 0x13U 240 #define ADM_CLEAR_ALL_PIPE 0x14U 241 #define ADM_NOTIFY_ALL_PIPE_CLEARED 0x15U 242 #define ADM_CMD_RFU_B 0x16U 243 #define ADM_CMD_RFU_E 0x3FU 244 245 #define MSG_INSTRUCTION_UNKNWON 0x3FU 246 247 /* 248 * 0x16-0x3F is Reserved for Future Use 249 */ 250 251 252 /** \internal HCI Generic Responses from the Gates */ 253 #define ANY_OK 0x00U 254 #define ANY_E_NOT_CONNECTED 0x01U 255 #define ANY_E_CMD_PAR_UNKNOWN 0x02U 256 #define ANY_E_NOK 0x03U 257 #define ANY_E_PIPES_FULL 0x04U 258 #define ANY_E_REG_PAR_UNKNOWN 0x05U 259 #define ANY_E_PIPE_NOT_OPENED 0x06U 260 #define ANY_E_CMD_NOT_SUPPORTED 0x07U 261 #define ANY_E_INHIBITED 0x08U 262 #define ANY_E_TIMEOUT 0x09U 263 #define ANY_E_REG_ACCESS_DENIED 0x0AU 264 #define ANY_E_PIPE_ACCESS_DENIED 0x0BU 265 266 /* Response Error Code for RF Reader Gate */ 267 #define WR_RF_ERROR 0x10U 268 269 /* 270 * 0x08, 0x0B-0x3F is Reserved for Future Use 271 */ 272 273 274 /** \internal HCI Generic Events from the Gates */ 275 #define EVT_HCI_END_OF_OPERATION 0x01 276 #define EVT_POST_DATA 0x02 277 #define EVT_HOT_PLUG 0x03 278 279 280 /* Maximum Buffer Size for the HCI Data */ 281 #define PHHCINFC_MAX_BUFFERSIZE (PHHAL_MAX_DATASIZE + 0x50U) 282 283 #define PHHCINFC_MAX_OPENPIPE 0x6FU 284 #define PHHCINFC_MAX_PIPE 0x6FU 285 #define PHHCINFC_MIN_PIPE 0x02U 286 287 288 /* Maximum Payload Length of HCI. */ 289 #define PHHCINFC_MAX_PACKET_DATA 0x1CU 290 #define PHHCINFC_MAX_HCP_LEN PHHCINFC_MAX_PACKET_DATA + 1 291 292 293 294 /* Maximum Payload Length of HCI. */ 295 296 297 /* 298 ################################################################################ 299 ******************** Enumeration and Structure Definition ********************** 300 ################################################################################ 301 */ 302 #if 1 303 typedef NFCSTATUS (*pphHciNfc_Pipe_Receive_t) ( 304 void *pContext, 305 void *pHwRef, 306 uint8_t *data, 307 #ifdef ONE_BYTE_LEN 308 uint8_t length 309 #else 310 uint16_t length 311 #endif 312 ); 313 #else 314 315 typedef pphNfcIF_Transact_t pphHciNfc_Pipe_Receive_t; 316 317 #endif 318 319 /** \defgroup grp_hci_nfc HCI Component 320 * 321 * 322 */ 323 324 typedef enum phHciNfc_HostID { 325 phHciNfc_HostControllerID = 0x00U, 326 phHciNfc_TerminalHostID = 0x01U, 327 phHciNfc_UICCHostID = 0x02U 328 /* 329 phHciNfc_HostID_RFU_B = 0x03U, 330 phHciNfc_HostID_RFU_E = 0xBFU, 331 phHciNfc_HostIDProprietary_B = 0xC0U, 332 phHciNfc_HostIDProprietary_E = 0xFFU 333 */ 334 }phHciNfc_HostID_t; 335 336 337 typedef enum phHciNfc_GateID{ 338 phHciNfc_AdminGate = 0x00U, 339 /* 340 phHciNfc_evGateIDProprietary_B = 0x01U, 341 phHciNfc_evGateIDProprietary_E = 0x03U, 342 */ 343 phHciNfc_LoopBackGate = 0x04U, 344 phHciNfc_IdentityMgmtGate = 0x05U, 345 phHciNfc_LinkMgmtGate = 0x06U, 346 /* 347 phHciNfc_GateID_RFU_B = 0x07U, 348 phHciNfc_GateID_RFU_E = 0x0FU, 349 */ 350 351 /* TODO: Fillin Other Gate Information */ 352 /* ETSI HCI Specific RF Reader Gates */ 353 phHciNfc_RFReaderAGate = 0x13, 354 phHciNfc_RFReaderBGate = 0x11, 355 356 /* Proprietary Reader Gate */ 357 phHciNfc_ISO15693Gate = 0x12, 358 phHciNfc_RFReaderFGate = 0x14, 359 phHciNfc_JewelReaderGate = 0x15, 360 361 /* ETSI HCI Card RF Gates */ 362 phHciNfc_CETypeBGate = 0x21, 363 phHciNfc_CETypeBPrimeGate = 0x22, 364 phHciNfc_CETypeAGate = 0x23, 365 phHciNfc_CETypeFGate = 0x24, 366 367 /* NFC-IP1 Gates */ 368 phHciNfc_NFCIP1InitRFGate = 0x30, 369 phHciNfc_NFCIP1TargetRFGate = 0x31, 370 371 /* ETSI HCI Connectivity Gate */ 372 phHciNfc_ConnectivityGate = 0x41, 373 374 375 /* Device Configuration Gates */ 376 phHciNfc_PN544MgmtGate = 0x90, 377 phHciNfc_HostCommGate = 0x91, 378 phHciNfc_GPIOGate = 0x92, 379 phHciNfc_RFMgmtGate = 0x93, 380 phHciNfc_PollingLoopGate = 0x94, 381 phHciNfc_DownloadMgmtGate = 0x95, 382 383 /* Card Emulation Managment Gates */ 384 phHciNfc_SwpMgmtGate = 0xA0, 385 phHciNfc_NfcWIMgmtGate = 0xA1, 386 phHciNfc_UnknownGate = 0xFF 387 388 }phHciNfc_GateID_t; 389 390 391 typedef enum phHciNfc_PipeID{ 392 HCI_LINKMGMT_PIPE_ID = 0x00U, 393 HCI_ADMIN_PIPE_ID = 0x01U, 394 HCI_DYNAMIC_PIPE_ID = 0x02U, 395 HCI_RESERVED_PIPE_ID = 0x70U, 396 HCI_UNKNOWN_PIPE_ID = PHHCINFC_MAX_PIPE 397 /* 398 phHciNfc_evOtherGatePipeID_B = 0x02U, 399 phHciNfc_evOtherGatePipeID_E = 0x6FU, 400 phHciNfc_evGatePipeID_RFU_B = 0x70U, 401 phHciNfc_evGatePipeID_RFU_E = 0x7FU, 402 */ 403 }phHciNfc_PipeID_t; 404 405 406 typedef enum phHciNfc_eState { 407 hciState_Reset = 0x00U, 408 hciState_Initialise, 409 hciState_Test, 410 hciState_Config, 411 hciState_IO, 412 hciState_Select, 413 hciState_Listen, 414 hciState_Activate, 415 hciState_Reactivate, 416 hciState_Connect, 417 hciState_Transact, 418 hciState_Disconnect, 419 hciState_Presence, 420 hciState_Release, 421 hciState_Unknown 422 }phHciNfc_eState_t; 423 424 typedef enum phHciNfc_eMode { 425 hciMode_Reset = 0x00U, 426 hciMode_Session, 427 hciMode_Override, 428 hciMode_Test, 429 hciMode_Unknown 430 }phHciNfc_eMode_t; 431 432 433 typedef enum phHciNfc_eSeq{ 434 /* HCI Admin Sequence */ 435 ADMIN_INIT_SEQ = 0x00U, 436 ADMIN_SESSION_SEQ, 437 ADMIN_CE_SEQ, 438 ADMIN_REL_SEQ, 439 ADMIN_EVT_HOTPLUG_SEQ, 440 441 /* HCI Link Management Sequence */ 442 LINK_MGMT_INIT_SEQ, 443 LINK_MGMT_REL_SEQ, 444 445 /* HCI Identity Management Sequence */ 446 IDENTITY_INIT_SEQ, 447 IDENTITY_INFO_SEQ, 448 IDENTITY_REL_SEQ, 449 450 /* HCI Polling Loop Sequence */ 451 PL_INIT_SEQ, 452 PL_DURATION_SEQ, 453 PL_CONFIG_PHASE_SEQ, 454 PL_TGT_DISABLE_SEQ, 455 PL_RESTART_SEQ, 456 PL_STOP_SEQ, 457 PL_REL_SEQ, 458 459 /* HCI Device Management Sequence */ 460 DEV_INIT_SEQ, 461 DEV_HAL_INFO_SEQ, 462 DEV_CONFIG_SEQ, 463 DEV_REL_SEQ, 464 465 /* HCI Reader Management Sequence */ 466 READER_MGMT_INIT_SEQ, 467 READER_ENABLE_SEQ, 468 READER_SELECT_SEQ, 469 READER_REACTIVATE_SEQ, 470 READER_SW_AUTO_SEQ, 471 READER_PRESENCE_CHK_SEQ, 472 READER_UICC_DISPATCH_SEQ, 473 READER_DESELECT_SEQ, 474 READER_RESELECT_SEQ, 475 READER_DISABLE_SEQ, 476 READER_MGMT_REL_SEQ, 477 478 /* HCI NFC-IP1 Sequence */ 479 NFCIP1_INIT_SEQ, 480 INITIATOR_SPEED_SEQ, 481 INITIATOR_GENERAL_SEQ, 482 TARGET_GENERAL_SEQ, 483 TARGET_SPEED_SEQ, 484 NFCIP1_REL_SEQ, 485 486 /* HCI Emulation Management Sequence */ 487 EMULATION_INIT_SEQ, 488 EMULATION_SWP_SEQ, 489 EMULATION_CONFIG_SEQ, 490 EMULATION_REL_SEQ, 491 492 HCI_END_SEQ, 493 HCI_INVALID_SEQ 494 } phHciNfc_eSeq_t; 495 496 497 498 typedef enum phHciNfc_eSeqType{ 499 RESET_SEQ = 0x00U, 500 INIT_SEQ, 501 UPDATE_SEQ, 502 INFO_SEQ, 503 CONFIG_SEQ, 504 REL_SEQ, 505 END_SEQ 506 } phHciNfc_eSeqType_t; 507 508 509 typedef enum phHciNfc_eConfigType{ 510 INVALID_CFG = 0x00U, 511 POLL_LOOP_CFG, 512 SMX_WI_CFG, 513 SMX_WI_MODE, 514 UICC_SWP_CFG, 515 SWP_EVT_CFG, 516 SWP_PROTECT_CFG, 517 NFC_GENERAL_CFG, 518 NFC_TARGET_CFG, 519 NFC_CE_A_CFG, 520 NFC_CE_B_CFG 521 } phHciNfc_eConfigType_t; 522 523 524 typedef struct phHciNfc_HCP_Message{ 525 /** \internal Identifies the Type and Kind of Instruction */ 526 uint8_t msg_header; 527 /** \internal Host Controller Protocol (HCP) Packet Message Payload */ 528 uint8_t payload[PHHCINFC_MAX_PACKET_DATA - 1]; 529 }phHciNfc_HCP_Message_t; 530 531 532 typedef struct phHciNfc_HCP_Packet{ 533 /** \internal Chaining Information and Pipe Identifier */ 534 uint8_t hcp_header; 535 /** \internal Host Controller Protocol (HCP) Packet Message or Payload */ 536 union 537 { 538 /** \internal Host Controller Protocol (HCP) Packet Message */ 539 phHciNfc_HCP_Message_t message; 540 /** \internal Host Controller Protocol (HCP) Packet Payload */ 541 uint8_t payload[PHHCINFC_MAX_PACKET_DATA]; 542 }msg; 543 }phHciNfc_HCP_Packet_t; 544 545 546 547 typedef struct phHciNfc_Gate_Info{ 548 /** \internal HCI Host Identifier */ 549 uint8_t host_id; 550 /** \internal HCI Gate Identifier */ 551 uint8_t gate_id; 552 }phHciNfc_Gate_Info_t; 553 554 555 typedef struct phHciNfc_Pipe_Params{ 556 /** \internal HCI Source Gate Information for the pipe */ 557 phHciNfc_Gate_Info_t source; 558 /** \internal HCI Destination Gate Information for the pipe */ 559 phHciNfc_Gate_Info_t dest; 560 /** \internal HCI Pipe Identifier */ 561 uint8_t pipe_id; 562 }phHciNfc_Pipe_Params_t; 563 564 565 typedef struct phHciNfc_Pipe_Info{ 566 /** \internal Structure containing the created dynamic pipe information */ 567 phHciNfc_Pipe_Params_t pipe; 568 /** \internal Status of the previous command sent to this pipe */ 569 NFCSTATUS prev_status; 570 /** \internal previous message type Sent to this pipe */ 571 uint8_t sent_msg_type; 572 /** \internal Message type Received in this pipe */ 573 uint8_t recv_msg_type; 574 /** \internal previous message sent to this pipe */ 575 uint8_t prev_msg; 576 /** \internal Index of the previous Set/Get Parameter command 577 * sent to this pipe */ 578 uint8_t reg_index; 579 /** \internal length of Parameter of the Set/Get Parameter 580 * command sent to this pipe */ 581 uint16_t param_length; 582 /** \internal Parameter of the Set/Get Parameter command 583 * sent to this pipe */ 584 void *param_info; 585 /** \internal Pointer to a Pipe specific Receive Response function */ 586 pphHciNfc_Pipe_Receive_t recv_resp; 587 /** \internal Pointer to a Pipe specific Receive Event function */ 588 pphHciNfc_Pipe_Receive_t recv_event; 589 /** \internal Pointer to a Pipe specific Receive Command function */ 590 pphHciNfc_Pipe_Receive_t recv_cmd; 591 }phHciNfc_Pipe_Info_t; 592 593 594 typedef struct phHciNfc_sContext{ 595 /** \internal HCI Layer Pointer from the upper layer for 596 lower layer function registration */ 597 phNfcLayer_sCfg_t *p_hci_layer; 598 /** \internal Pointer to the upper layer context */ 599 void *p_upper_context; 600 /** \internal Pointer to the Hardware Reference Sturcture */ 601 phHal_sHwReference_t *p_hw_ref; 602 /** \internal Pointer to the upper layer notification callback function */ 603 pphNfcIF_Notification_CB_t p_upper_notify; 604 /** \internal Structure to store the lower interface operations */ 605 phNfc_sLowerIF_t lower_interface; 606 /** \internal Execution Sequence using the HCI Context */ 607 volatile phHciNfc_eSeq_t hci_seq; 608 609 /** \internal State of the HCI Context */ 610 volatile phNfc_sState_t hci_state; 611 612 /** \internal Mode of HCI Initialisation */ 613 phHciNfc_Init_t init_mode; 614 615 /** \internal Memory Information for HCI Initialisation */ 616 uint8_t hal_mem_info[NXP_HAL_MEM_INFO_SIZE]; 617 618 /** \internal HCI Configuration Type */ 619 phHciNfc_eConfigType_t config_type; 620 /** \internal HCI SmartMX Mode Configuration */ 621 phHal_eSmartMX_Mode_t smx_mode; 622 /** \internal HCI Configuration Information */ 623 void *p_config_params; 624 625 /** \internal Current RF Reader/Emulation Gate in Use */ 626 phHal_eRFDevType_t host_rf_type; 627 628 /** \internal Connected Target Information */ 629 phHal_sRemoteDevInformation_t *p_target_info; 630 631 /** \internal Information of all the pipes created and opened */ 632 phHciNfc_Pipe_Info_t *p_pipe_list[PHHCINFC_MAX_PIPE+1]; 633 634 /** \internal Tag */ 635 phHciNfc_XchgInfo_t *p_xchg_info; 636 637 /** \internal Information of the HCI Gates */ 638 /** \internal HCI Admin Management Gate Information */ 639 void *p_admin_info; 640 /** \internal HCI Link Management Gate Information */ 641 void *p_link_mgmt_info; 642 /** \internal HCI Identity Management Gate Information */ 643 void *p_identity_info; 644 /** \internal HCI Polling Loop Gate Information */ 645 void *p_poll_loop_info; 646 /** \internal HCI NFC Device Management Information */ 647 void *p_device_mgmt_info; 648 /** \internal HCI RF Reader Gates Management Information */ 649 void *p_reader_mgmt_info; 650 /** \internal HCI Card Application Gates and Emulation 651 Information */ 652 void *p_emulation_mgmt_info; 653 /** \internal HCI RF Reader A Gate Information */ 654 void *p_reader_a_info; 655 #ifdef TYPE_B 656 /** \internal HCI RF Reader B Gate Information */ 657 void *p_reader_b_info; 658 #endif 659 #ifdef TYPE_FELICA 660 /** \internal HCI Felica Reader Gate Information */ 661 void *p_felica_info; 662 #endif 663 #ifdef TYPE_JEWEL 664 /** \internal HCI Jewel Reader Gate Information */ 665 void *p_jewel_info; 666 #endif 667 #ifdef TYPE_ISO15693 668 /** \internal HCI ISO15693 Reader Gate Information */ 669 void *p_iso_15693_info; 670 #endif 671 672 #ifdef ENABLE_P2P 673 /** \internal HCI NFC-IP1 Peer to Peer Information */ 674 void *p_nfcip_info; 675 #endif 676 /** \internal HCI Secure Element Management Information */ 677 void *p_wi_info; 678 /** \internal HCI UICC Information */ 679 void *p_uicc_info; 680 /** \internal HCI SWP Information */ 681 void *p_swp_info; 682 #ifdef HOST_EMULATION 683 /** \internal HCI Card Emulation A Gate Information */ 684 void *p_ce_a_info; 685 /** \internal HCI Card Emulation B Gate Information */ 686 void *p_ce_b_info; 687 #endif 688 689 /** \internal HCI Packet Data to be sent to the lower layer */ 690 phHciNfc_HCP_Packet_t tx_packet; 691 /** \internal HCI Packet Data to be received from the lower layer */ 692 phHciNfc_HCP_Packet_t rx_packet; 693 694 /** \internal Previous Status (To Store the Error Status ) */ 695 NFCSTATUS error_status; 696 697 /** \internal Pointer to HCI Send Buffer */ 698 uint8_t send_buffer[PHHCINFC_MAX_BUFFERSIZE]; 699 /** \internal Pointer to HCI Receive Buffer */ 700 uint8_t recv_buffer[PHHCINFC_MAX_BUFFERSIZE]; 701 702 /** \internal Total Number of bytes to be Sent */ 703 volatile uint16_t tx_total; 704 /** \internal Number of bytes Remaining to be Sent */ 705 volatile uint16_t tx_remain; 706 /** \internal Number of bytes sent */ 707 volatile uint16_t tx_sent; 708 709 volatile uint16_t rx_index; 710 711 /** \internal Total Number of bytes received */ 712 volatile uint16_t rx_total; 713 /** \internal Number of bytes received */ 714 volatile uint16_t rx_recvd; 715 /** \internal Index of the received data in the 716 * response packet 717 */ 718 719 /** \internal Send HCP Chaining Information */ 720 volatile uint8_t tx_hcp_chaining; 721 /** \internal Send HCP Fragment Index */ 722 volatile uint16_t tx_hcp_frgmnt_index; 723 724 /** \internal Receive HCP Chaining Information */ 725 volatile uint8_t rx_hcp_chaining; 726 /** \internal Receive HCP Fragment Index */ 727 volatile uint16_t rx_hcp_frgmnt_index; 728 729 /** \internal The Device under Test */ 730 volatile uint8_t hci_mode; 731 /** \internal Wait for Response if Response is Pending */ 732 volatile uint8_t response_pending; 733 /** \internal Notify the Event if Notifcation is Pending */ 734 volatile uint8_t event_pending; 735 736 /** \internal Pending Release of the detected Target */ 737 uint8_t target_release; 738 739 }phHciNfc_sContext_t; 740 741 /* 742 ################################################################################ 743 *********************** Function Prototype Declaration ************************* 744 ################################################################################ 745 */ 746 747 748 /** 749 * 750 * \ingroup grp_hci_nfc 751 * 752 * The phHciNfc_Receive function receives the HCI Events or Response from the 753 * corresponding peripheral device, described by the HCI Context Structure. 754 * 755 * \param[in] psContext psContext is the context of 756 * the HCI Layer. 757 * \param[in] pHwRef pHwRef is the Information of 758 * the Device Interface Link . 759 * \param[out] pdata Pointer to the response buffer that 760 * receives the response read. 761 * \param[in] length Variable that receives 762 * the number of bytes read. 763 * 764 * \retval NFCSTATUS_PENDING Data successfully read. 765 * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 766 * could not be interpreted properly. 767 * \retval Other errors Other related errors 768 * 769 */ 770 771 extern 772 NFCSTATUS 773 phHciNfc_Receive( 774 void *psContext, 775 void *pHwRef, 776 uint8_t *pdata, 777 #ifdef ONE_BYTE_LEN 778 uint8_t length 779 #else 780 uint16_t length 781 #endif 782 ); 783 784 /** 785 * \ingroup grp_hci_nfc 786 * 787 * The phHciNfc_Send_Complete function acknowledges the completion of the HCI 788 * Commands sent to the device. 789 * 790 * \param[in] psContext psContext is the context of 791 * the HCI Layer. 792 * \param[in] pHwRef pHwRef is the Information of 793 * the Device Interface Link . 794 * \param[in] pInfo Transaction information like 795 * status and length after the 796 * completion of the send. 797 * 798 * \retval NONE. 799 * 800 */ 801 802 extern 803 void 804 phHciNfc_Send_Complete ( 805 void *psContext, 806 void *pHwRef, 807 phNfc_sTransactionInfo_t *pInfo 808 ); 809 810 /** 811 * \ingroup grp_hci_nfc 812 * 813 * The phHciNfc_Receive_Complete function acknowledges the completion of the HCI 814 * Event Information or Response received from the device. 815 * 816 * \param[in] psContext psContext is the context of 817 * the HCI Layer. 818 * \param[in] pHwRef pHwRef is the Information of 819 * the Device Interface Link . 820 * \param[in] pInfo Transaction information like status 821 * data and length after the completely 822 * receiving the response . 823 * \retval NONE. 824 * 825 * 826 */ 827 828 extern 829 void 830 phHciNfc_Receive_Complete ( 831 void *psContext, 832 void *pHwRef, 833 phNfc_sTransactionInfo_t *pInfo 834 ); 835 836 /** 837 * \ingroup grp_hci_nfc 838 * 839 * The phHciNfc_Notify_Event function notifies the occurence of the HCI 840 * Event from the device. 841 * 842 * \param[in] psContext psContext is the context of 843 * the HCI Layer. 844 * \param[in] pHwRef pHwRef is the Information of 845 * the Device Interface Link . 846 * \param[in] type reason returned for the notification to 847 * the HCI. 848 * \param[in] pInfo Notification information like status 849 * data,length etc from the lower layer 850 * to the HCI Layer. 851 * \retval NONE. 852 * 853 */ 854 855 extern 856 void 857 phHciNfc_Notify_Event( 858 void *psContext, 859 void *pHwRef, 860 uint8_t type, 861 void *pInfo 862 ); 863 864 /** 865 * \ingroup grp_hci_nfc 866 * 867 * The phHciNfc_Tag_Notify function notifies the the upper layer 868 * with the Tag Specific Notifications . 869 * 870 * \param[in] psContext psContext is the context of 871 * the HCI Layer. 872 * \param[in] pHwRef pHwRef is the Information of 873 * the Device Interface Link . 874 * \param[in] type reason returned for the notification to 875 * the HCI. 876 * \param[in] pInfo Notification information like status 877 * data,length etc from the lower layer 878 * to the HCI Layer. 879 * \retval NONE. 880 * 881 */ 882 extern 883 void 884 phHciNfc_Tag_Notify( 885 phHciNfc_sContext_t *psHciContext, 886 void *pHwRef, 887 uint8_t type, 888 void *pInfo 889 ); 890 891 /** 892 * \ingroup grp_hci_nfc 893 * 894 * The phHciNfc_Tag_Notify function notifies the the upper layer 895 * with the Tag Specific Notifications . 896 * 897 * \param[in] psContext psContext is the context of 898 * the HCI Layer. 899 * \param[in] pHwRef pHwRef is the Information of 900 * the Device Interface Link . 901 * \param[in] type reason returned for the notification to 902 * the HCI. 903 * \param[in] pInfo Notification information like status 904 * data,length etc from the lower layer 905 * to the HCI Layer. 906 * \retval NONE. 907 * 908 */ 909 910 extern 911 void 912 phHciNfc_Target_Select_Notify( 913 phHciNfc_sContext_t *psHciContext, 914 void *pHwRef, 915 uint8_t type, 916 void *pInfo 917 ); 918 919 920 /** 921 * \ingroup grp_hci_nfc 922 * 923 * The phHciNfc_Transceive_Notify function notifies the the upper layer 924 * with the after the transceive operation. 925 * 926 * \param[in] psContext psContext is the context of 927 * the HCI Layer. 928 * \param[in] pHwRef pHwRef is the Information of 929 * the Device Interface Link . 930 * \param[in] type reason returned for the notification to 931 * the HCI. 932 * \param[in] pInfo Notification information like status 933 * data,length etc from the lower layer 934 * to the HCI Layer. 935 * \retval NONE. 936 * 937 */ 938 extern 939 void 940 phHciNfc_Transceive_Notify( 941 phHciNfc_sContext_t *psHciContext, 942 void *pHwRef, 943 uint8_t type, 944 void *pInfo 945 ); 946 947 /** 948 * \ingroup grp_hci_nfc 949 * 950 * The phHciNfc_Notify function calls the upper layer notification callback. 951 * 952 * \param[in] pUpperNotify pUpperNotify is the notification 953 * callback of the upper HAL Layer. 954 * \param[in] pUpperContext pUpperContext is the context of 955 * the upper HAL Layer. 956 * \param[in] pHwRef pHwRef is the Information of 957 * the Device Interface Link . 958 * \param[in] type type of the notification to 959 * the upper HAL layer. 960 * \param[in] pInfo completion information returned 961 * to the Upper HAL Layer. 962 * NFCSTATUS_SUCCESS Notification successfully completed . 963 * NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 964 * could not be interpreted properly. 965 * Other errors Errors related to the HCI or lower layers 966 * 967 * \retval NONE. 968 * 969 */ 970 971 extern 972 void 973 phHciNfc_Notify( 974 pphNfcIF_Notification_CB_t p_upper_notify, 975 void *p_upper_context, 976 void *pHwRef, 977 uint8_t type, 978 void *pInfo 979 ); 980 981 /** 982 * \ingroup grp_hci_nfc 983 * 984 * The phHciNfc_Release_Notify function Releases HCI and notifies 985 * the upper layer. 986 * 987 * \param[in] psHciContext psHciContext is the context of 988 * the HCI Layer. 989 * \param[in] pHwRef pHwRef is the Information of 990 * the Device Interface Link . 991 * \param[in] type reason returned for the notification to 992 * the HCI. 993 * \param[in] pInfo Notification information like status 994 * data,length etc from the lower layer 995 * to the HCI Layer. 996 * \retval NONE. 997 * 998 */ 999 extern 1000 void 1001 phHciNfc_Release_Notify( 1002 phHciNfc_sContext_t *psHciContext, 1003 void *pHwRef, 1004 uint8_t type, 1005 void *pInfo 1006 ); 1007 1008 1009 1010 /** 1011 * \ingroup grp_hci_nfc 1012 * 1013 * The phHciNfc_Send_Generic_Cmd function sends the HCI Generic Commands 1014 * to the device. 1015 * 1016 * \param[in] psHciContext psHciContext is the context of 1017 * the HCI Layer. 1018 * \param[in] pHwRef pHwRef is the Information of 1019 * the Device Interface Link . 1020 * \param[in] pipe_id The pipe to which the command 1021 * is being sent. 1022 * \param[in] cmd The HCI Generic command sent to a 1023 * particular pipe . 1024 * 1025 * \retval NFCSTATUS_PENDING HCI Generic Command send in progress . 1026 * \retval 1027 * NFCSTATUS_INSUFFICIENT_RESOURCES The memory could not be allocated 1028 * as required amount of memory 1029 * is not sufficient. 1030 * 1031 */ 1032 1033 extern 1034 NFCSTATUS 1035 phHciNfc_Send_Generic_Cmd ( 1036 phHciNfc_sContext_t *psHciContext, 1037 void *pHwRef, 1038 uint8_t pipe_id, 1039 uint8_t cmd 1040 ); 1041 1042 /** 1043 * \ingroup grp_hci_nfc 1044 * 1045 * The phHciNfc_Set_Param function configures the Gate specific register 1046 * with the provided value. 1047 * 1048 * \param[in] psHciContext psHciContext is the context of 1049 * the HCI Layer. 1050 * \param[in] pHwRef pHwRef is the Information of 1051 * the Device Interface Link . 1052 * \param[in] p_pipe_info Pointer to pipe specific information. 1053 * \param[in] reg_index Index of the register to be 1054 * configured . 1055 * \param[in] p_param Value to the configured in 1056 * particular register. 1057 * \param[in] param_length Length of the parameter provided 1058 * for the configuration. 1059 * 1060 * \retval NFCSTATUS_PENDING HCI Set parameter in progress . 1061 * \retval 1062 * NFCSTATUS_INVALID_HCI_INFORMATION The Information like p_pipe_info, 1063 * p_param or param_length is invalid 1064 * 1065 */ 1066 1067 extern 1068 NFCSTATUS 1069 phHciNfc_Set_Param ( 1070 phHciNfc_sContext_t *psHciContext, 1071 void *pHwRef, 1072 phHciNfc_Pipe_Info_t *p_pipe_info, 1073 uint8_t reg_index, 1074 void *p_param, 1075 uint16_t param_length 1076 ); 1077 1078 /** 1079 * \ingroup grp_hci_nfc 1080 * 1081 * The phHciNfc_Send_HCP function sends the HCI Host Control Packet 1082 * Frames to the device. 1083 * 1084 * \param[in] psHciContext psHciContext is the context of 1085 * the HCI Layer. 1086 * \param[in] pHwRef pHwRef is the Information of 1087 * the Device Interface Link . 1088 * 1089 * \retval NFCSTATUS_PENDING HCP Frame send pending. 1090 * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 1091 * could not be interpreted properly. 1092 * \retval Other errors Other related errors 1093 * 1094 * 1095 */ 1096 1097 extern 1098 NFCSTATUS 1099 phHciNfc_Send_HCP ( 1100 phHciNfc_sContext_t *psHciContext, 1101 void *pHwRef 1102 ); 1103 1104 1105 /** 1106 * \ingroup grp_hci_nfc 1107 * 1108 * The phHciNfc_Build_HCPFrame function initially builds the HCP Packet Frame 1109 * with the values passed in the arguments . 1110 * 1111 * \param[in] hcp_packet hcp_packet is the frame packet structure 1112 * in which the frame is populated with the 1113 * appropriate fields. 1114 * \param[in] chainbit chainbit specifies whether the following 1115 * HCP frames are chained or the frame is a 1116 * normal frame. 1117 * \param[in] pipe_id pipe_id of the pipe to which the frame has 1118 * to be sent. 1119 * \param[in] msg_type type of message sent to the pipe. 1120 * \param[in] instruction type of message instruction send to the pipe. 1121 * 1122 * \retval NONE. 1123 * 1124 */ 1125 1126 1127 extern 1128 void 1129 phHciNfc_Build_HCPFrame ( 1130 phHciNfc_HCP_Packet_t *hcp_packet, 1131 uint8_t chainbit, 1132 uint8_t pipe_id, 1133 uint8_t msg_type, 1134 uint8_t instruction 1135 ); 1136 1137 /** 1138 * \ingroup grp_hci_nfc 1139 * 1140 * The phHciNfc_Append_HCPFrame function Appends the HCP Packet Frame 1141 * with the values passed in the arguments . 1142 * 1143 * \param[in] hcp_data hcp_data is the pointer to the HCP 1144 * payload to which the data is to be 1145 * appended. 1146 * \param[in] hcp_index hcp_index is the index from which 1147 * the data source needs to be appended. 1148 * \param[in] src_data src_data that is to be appended to the 1149 * HCP packet. 1150 * \param[in] src_len The length of the data source that is 1151 * to be appended. 1152 * \retval NONE. 1153 * 1154 */ 1155 1156 extern 1157 void 1158 phHciNfc_Append_HCPFrame ( 1159 uint8_t *hcp_data, 1160 uint16_t hcp_index, 1161 uint8_t *src_data, 1162 uint16_t src_len 1163 ); 1164 1165 /** 1166 * \ingroup grp_hci_nfc 1167 * 1168 * The phHciNfc_Allocate_Resource function allocates and initialises the 1169 * resource memory for the HCI layer. 1170 * 1171 * \param[in] ppBuffer ppBuffer is the pointer to which the 1172 * resource memory is allocated. 1173 * \param[in] size Variable that specifies the size of 1174 * the memory that needs to be created. 1175 * 1176 * \retval NFCSTATUS_SUCCESS The Resource Memory was allocated 1177 * successfully . 1178 * \retval 1179 * NFCSTATUS_INSUFFICIENT_RESOURCES The memory could not be allocated 1180 * as required amount of memory 1181 * is not suffient. 1182 * 1183 */ 1184 1185 extern 1186 NFCSTATUS 1187 phHciNfc_Allocate_Resource ( 1188 void **ppBuffer, 1189 uint16_t size 1190 ); 1191 /** 1192 * \ingroup grp_hci_nfc 1193 * 1194 * The phHciNfc_Release_Resources function releases all the resources 1195 * allocated in the HCI Layer. 1196 * 1197 * \param[in] psHciContext psHciContext is the context of 1198 * the HCI Layer. 1199 * 1200 * \retval NONE. 1201 * 1202 */ 1203 1204 extern 1205 void 1206 phHciNfc_Release_Resources ( 1207 phHciNfc_sContext_t **ppsHciContext 1208 ); 1209 1210 /** 1211 * \ingroup grp_hci_nfc 1212 * 1213 * The phHciNfc_Release_Lower function initiates the release of the 1214 * lower layers. 1215 * 1216 * \param[in] psHciContext psHciContext is the context of 1217 * the HCI Layer. 1218 * \param[in] pHwRef pHwRef is the Information of 1219 * the Device Interface Link . 1220 * 1221 * \retval NONE. 1222 * 1223 */ 1224 1225 extern 1226 void 1227 phHciNfc_Release_Lower( 1228 phHciNfc_sContext_t *psHciContext, 1229 void *pHwRef 1230 ); 1231 1232 1233 1234 #endif 1235 1236