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_CONFIG_SEQ, 462 DEV_REL_SEQ, 463 464 /* HCI Reader Management Sequence */ 465 READER_MGMT_INIT_SEQ, 466 READER_ENABLE_SEQ, 467 READER_SELECT_SEQ, 468 READER_REACTIVATE_SEQ, 469 READER_SW_AUTO_SEQ, 470 READER_PRESENCE_CHK_SEQ, 471 READER_UICC_DISPATCH_SEQ, 472 READER_DESELECT_SEQ, 473 READER_RESELECT_SEQ, 474 READER_DISABLE_SEQ, 475 READER_MGMT_REL_SEQ, 476 477 /* HCI NFC-IP1 Sequence */ 478 NFCIP1_INIT_SEQ, 479 INITIATOR_SPEED_SEQ, 480 INITIATOR_GENERAL_SEQ, 481 TARGET_GENERAL_SEQ, 482 TARGET_SPEED_SEQ, 483 NFCIP1_REL_SEQ, 484 485 /* HCI Emulation Management Sequence */ 486 EMULATION_INIT_SEQ, 487 EMULATION_SWP_SEQ, 488 EMULATION_CONFIG_SEQ, 489 EMULATION_REL_SEQ, 490 491 HCI_END_SEQ, 492 HCI_INVALID_SEQ 493 } phHciNfc_eSeq_t; 494 495 496 497 typedef enum phHciNfc_eSeqType{ 498 RESET_SEQ = 0x00U, 499 INIT_SEQ, 500 UPDATE_SEQ, 501 INFO_SEQ, 502 CONFIG_SEQ, 503 REL_SEQ, 504 END_SEQ 505 } phHciNfc_eSeqType_t; 506 507 508 typedef enum phHciNfc_eConfigType{ 509 INVALID_CFG = 0x00U, 510 POLL_LOOP_CFG, 511 SMX_WI_CFG, 512 SMX_WI_MODE, 513 UICC_SWP_CFG, 514 SWP_EVT_CFG, 515 SWP_PROTECT_CFG, 516 NFC_GENERAL_CFG, 517 NFC_TARGET_CFG, 518 NFC_CE_A_CFG, 519 NFC_CE_B_CFG 520 } phHciNfc_eConfigType_t; 521 522 523 typedef struct phHciNfc_HCP_Message{ 524 /** \internal Identifies the Type and Kind of Instruction */ 525 uint8_t msg_header; 526 /** \internal Host Controller Protocol (HCP) Packet Message Payload */ 527 uint8_t payload[PHHCINFC_MAX_PACKET_DATA - 1]; 528 }phHciNfc_HCP_Message_t; 529 530 531 typedef struct phHciNfc_HCP_Packet{ 532 /** \internal Chaining Information and Pipe Identifier */ 533 uint8_t hcp_header; 534 /** \internal Host Controller Protocol (HCP) Packet Message or Payload */ 535 union 536 { 537 /** \internal Host Controller Protocol (HCP) Packet Message */ 538 phHciNfc_HCP_Message_t message; 539 /** \internal Host Controller Protocol (HCP) Packet Payload */ 540 uint8_t payload[PHHCINFC_MAX_PACKET_DATA]; 541 }msg; 542 }phHciNfc_HCP_Packet_t; 543 544 545 546 typedef struct phHciNfc_Gate_Info{ 547 /** \internal HCI Host Identifier */ 548 uint8_t host_id; 549 /** \internal HCI Gate Identifier */ 550 uint8_t gate_id; 551 }phHciNfc_Gate_Info_t; 552 553 554 typedef struct phHciNfc_Pipe_Params{ 555 /** \internal HCI Source Gate Information for the pipe */ 556 phHciNfc_Gate_Info_t source; 557 /** \internal HCI Destination Gate Information for the pipe */ 558 phHciNfc_Gate_Info_t dest; 559 /** \internal HCI Pipe Identifier */ 560 uint8_t pipe_id; 561 }phHciNfc_Pipe_Params_t; 562 563 564 typedef struct phHciNfc_Pipe_Info{ 565 /** \internal Structure containing the created dynamic pipe information */ 566 phHciNfc_Pipe_Params_t pipe; 567 /** \internal Status of the previous command sent to this pipe */ 568 NFCSTATUS prev_status; 569 /** \internal previous message type Sent to this pipe */ 570 uint8_t sent_msg_type; 571 /** \internal Message type Received in this pipe */ 572 uint8_t recv_msg_type; 573 /** \internal previous message sent to this pipe */ 574 uint8_t prev_msg; 575 /** \internal Index of the previous Set/Get Parameter command 576 * sent to this pipe */ 577 uint8_t reg_index; 578 /** \internal length of Parameter of the Set/Get Parameter 579 * command sent to this pipe */ 580 uint16_t param_length; 581 /** \internal Parameter of the Set/Get Parameter command 582 * sent to this pipe */ 583 void *param_info; 584 /** \internal Pointer to a Pipe specific Receive Response function */ 585 pphHciNfc_Pipe_Receive_t recv_resp; 586 /** \internal Pointer to a Pipe specific Receive Event function */ 587 pphHciNfc_Pipe_Receive_t recv_event; 588 /** \internal Pointer to a Pipe specific Receive Command function */ 589 pphHciNfc_Pipe_Receive_t recv_cmd; 590 }phHciNfc_Pipe_Info_t; 591 592 593 typedef struct phHciNfc_sContext{ 594 /** \internal HCI Layer Pointer from the upper layer for 595 lower layer function registration */ 596 phNfcLayer_sCfg_t *p_hci_layer; 597 /** \internal Pointer to the upper layer context */ 598 void *p_upper_context; 599 /** \internal Pointer to the Hardware Reference Sturcture */ 600 phHal_sHwReference_t *p_hw_ref; 601 /** \internal Pointer to the upper layer notification callback function */ 602 pphNfcIF_Notification_CB_t p_upper_notify; 603 /** \internal Structure to store the lower interface operations */ 604 phNfc_sLowerIF_t lower_interface; 605 /** \internal Execution Sequence using the HCI Context */ 606 volatile phHciNfc_eSeq_t hci_seq; 607 608 /** \internal State of the HCI Context */ 609 volatile phNfc_sState_t hci_state; 610 611 /** \internal Mode of HCI Initialisation */ 612 phHciNfc_Init_t init_mode; 613 614 /** \internal Mode of HCI Initialisation */ 615 void *p_io_params; 616 617 /** \internal HCI Configuration Type */ 618 phHciNfc_eConfigType_t config_type; 619 /** \internal HCI SmartMX Mode Configuration */ 620 phHal_eSmartMX_Mode_t smx_mode; 621 /** \internal HCI Configuration Information */ 622 void *p_config_params; 623 624 /** \internal Current RF Reader/Emulation Gate in Use */ 625 phHal_eRFDevType_t host_rf_type; 626 627 /** \internal Connected Target Information */ 628 phHal_sRemoteDevInformation_t *p_target_info; 629 630 /** \internal Information of all the pipes created and opened */ 631 phHciNfc_Pipe_Info_t *p_pipe_list[PHHCINFC_MAX_PIPE+1]; 632 633 /** \internal Tag */ 634 phHciNfc_XchgInfo_t *p_xchg_info; 635 636 /** \internal Information of the HCI Gates */ 637 /** \internal HCI Admin Management Gate Information */ 638 void *p_admin_info; 639 /** \internal HCI Link Management Gate Information */ 640 void *p_link_mgmt_info; 641 /** \internal HCI Identity Management Gate Information */ 642 void *p_identity_info; 643 /** \internal HCI Polling Loop Gate Information */ 644 void *p_poll_loop_info; 645 /** \internal HCI NFC Device Management Information */ 646 void *p_device_mgmt_info; 647 /** \internal HCI RF Reader Gates Management Information */ 648 void *p_reader_mgmt_info; 649 /** \internal HCI Card Application Gates and Emulation 650 Information */ 651 void *p_emulation_mgmt_info; 652 /** \internal HCI RF Reader A Gate Information */ 653 void *p_reader_a_info; 654 #ifdef TYPE_B 655 /** \internal HCI RF Reader B Gate Information */ 656 void *p_reader_b_info; 657 #endif 658 #ifdef TYPE_FELICA 659 /** \internal HCI Felica Reader Gate Information */ 660 void *p_felica_info; 661 #endif 662 #ifdef TYPE_JEWEL 663 /** \internal HCI Jewel Reader Gate Information */ 664 void *p_jewel_info; 665 #endif 666 #ifdef TYPE_ISO15693 667 /** \internal HCI ISO15693 Reader Gate Information */ 668 void *p_iso_15693_info; 669 #endif 670 671 #ifdef ENABLE_P2P 672 /** \internal HCI NFC-IP1 Peer to Peer Information */ 673 void *p_nfcip_info; 674 #endif 675 /** \internal HCI Secure Element Management Information */ 676 void *p_wi_info; 677 /** \internal HCI UICC Information */ 678 void *p_uicc_info; 679 /** \internal HCI SWP Information */ 680 void *p_swp_info; 681 #ifdef HOST_EMULATION 682 /** \internal HCI Card Emulation A Gate Information */ 683 void *p_ce_a_info; 684 /** \internal HCI Card Emulation B Gate Information */ 685 void *p_ce_b_info; 686 #endif 687 688 /** \internal HCI Packet Data to be sent to the lower layer */ 689 phHciNfc_HCP_Packet_t tx_packet; 690 /** \internal HCI Packet Data to be received from the lower layer */ 691 phHciNfc_HCP_Packet_t rx_packet; 692 693 /** \internal Previous Status (To Store the Error Status ) */ 694 NFCSTATUS error_status; 695 696 /** \internal Pointer to HCI Send Buffer */ 697 uint8_t send_buffer[PHHCINFC_MAX_BUFFERSIZE]; 698 /** \internal Pointer to HCI Receive Buffer */ 699 uint8_t recv_buffer[PHHCINFC_MAX_BUFFERSIZE]; 700 701 /** \internal Total Number of bytes to be Sent */ 702 volatile uint16_t tx_total; 703 /** \internal Number of bytes Remaining to be Sent */ 704 volatile uint16_t tx_remain; 705 /** \internal Number of bytes sent */ 706 volatile uint16_t tx_sent; 707 708 volatile uint16_t rx_index; 709 710 /** \internal Total Number of bytes received */ 711 volatile uint16_t rx_total; 712 /** \internal Number of bytes received */ 713 volatile uint16_t rx_recvd; 714 /** \internal Index of the received data in the 715 * response packet 716 */ 717 718 /** \internal Send HCP Chaining Information */ 719 volatile uint8_t tx_hcp_chaining; 720 /** \internal Send HCP Fragment Index */ 721 volatile uint16_t tx_hcp_frgmnt_index; 722 723 /** \internal Receive HCP Chaining Information */ 724 volatile uint8_t rx_hcp_chaining; 725 /** \internal Receive HCP Fragment Index */ 726 volatile uint16_t rx_hcp_frgmnt_index; 727 728 /** \internal The Device under Test */ 729 volatile uint8_t hci_mode; 730 /** \internal Wait for Response if Response is Pending */ 731 volatile uint8_t response_pending; 732 /** \internal Notify the Event if Notifcation is Pending */ 733 volatile uint8_t event_pending; 734 735 /** \internal Pending Release of the detected Target */ 736 uint8_t target_release; 737 738 }phHciNfc_sContext_t; 739 740 /* 741 ################################################################################ 742 *********************** Function Prototype Declaration ************************* 743 ################################################################################ 744 */ 745 746 747 /** 748 * 749 * \ingroup grp_hci_nfc 750 * 751 * The phHciNfc_Receive function receives the HCI Events or Response from the 752 * corresponding peripheral device, described by the HCI Context Structure. 753 * 754 * \param[in] psContext psContext is the context of 755 * the HCI Layer. 756 * \param[in] pHwRef pHwRef is the Information of 757 * the Device Interface Link . 758 * \param[out] pdata Pointer to the response buffer that 759 * receives the response read. 760 * \param[in] length Variable that receives 761 * the number of bytes read. 762 * 763 * \retval NFCSTATUS_PENDING Data successfully read. 764 * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 765 * could not be interpreted properly. 766 * \retval Other errors Other related errors 767 * 768 */ 769 770 extern 771 NFCSTATUS 772 phHciNfc_Receive( 773 void *psContext, 774 void *pHwRef, 775 uint8_t *pdata, 776 #ifdef ONE_BYTE_LEN 777 uint8_t length 778 #else 779 uint16_t length 780 #endif 781 ); 782 783 /** 784 * \ingroup grp_hci_nfc 785 * 786 * The phHciNfc_Send_Complete function acknowledges the completion of the HCI 787 * Commands sent to the device. 788 * 789 * \param[in] psContext psContext is the context of 790 * the HCI Layer. 791 * \param[in] pHwRef pHwRef is the Information of 792 * the Device Interface Link . 793 * \param[in] pInfo Transaction information like 794 * status and length after the 795 * completion of the send. 796 * 797 * \retval NONE. 798 * 799 */ 800 801 extern 802 void 803 phHciNfc_Send_Complete ( 804 void *psContext, 805 void *pHwRef, 806 phNfc_sTransactionInfo_t *pInfo 807 ); 808 809 /** 810 * \ingroup grp_hci_nfc 811 * 812 * The phHciNfc_Receive_Complete function acknowledges the completion of the HCI 813 * Event Information or Response received from the device. 814 * 815 * \param[in] psContext psContext is the context of 816 * the HCI Layer. 817 * \param[in] pHwRef pHwRef is the Information of 818 * the Device Interface Link . 819 * \param[in] pInfo Transaction information like status 820 * data and length after the completely 821 * receiving the response . 822 * \retval NONE. 823 * 824 * 825 */ 826 827 extern 828 void 829 phHciNfc_Receive_Complete ( 830 void *psContext, 831 void *pHwRef, 832 phNfc_sTransactionInfo_t *pInfo 833 ); 834 835 /** 836 * \ingroup grp_hci_nfc 837 * 838 * The phHciNfc_Notify_Event function notifies the occurence of the HCI 839 * Event from the device. 840 * 841 * \param[in] psContext psContext is the context of 842 * the HCI Layer. 843 * \param[in] pHwRef pHwRef is the Information of 844 * the Device Interface Link . 845 * \param[in] type reason returned for the notification to 846 * the HCI. 847 * \param[in] pInfo Notification information like status 848 * data,length etc from the lower layer 849 * to the HCI Layer. 850 * \retval NONE. 851 * 852 */ 853 854 extern 855 void 856 phHciNfc_Notify_Event( 857 void *psContext, 858 void *pHwRef, 859 uint8_t type, 860 void *pInfo 861 ); 862 863 /** 864 * \ingroup grp_hci_nfc 865 * 866 * The phHciNfc_Tag_Notify function notifies the the upper layer 867 * with the Tag Specific Notifications . 868 * 869 * \param[in] psContext psContext is the context of 870 * the HCI Layer. 871 * \param[in] pHwRef pHwRef is the Information of 872 * the Device Interface Link . 873 * \param[in] type reason returned for the notification to 874 * the HCI. 875 * \param[in] pInfo Notification information like status 876 * data,length etc from the lower layer 877 * to the HCI Layer. 878 * \retval NONE. 879 * 880 */ 881 extern 882 void 883 phHciNfc_Tag_Notify( 884 phHciNfc_sContext_t *psHciContext, 885 void *pHwRef, 886 uint8_t type, 887 void *pInfo 888 ); 889 890 /** 891 * \ingroup grp_hci_nfc 892 * 893 * The phHciNfc_Tag_Notify function notifies the the upper layer 894 * with the Tag Specific Notifications . 895 * 896 * \param[in] psContext psContext is the context of 897 * the HCI Layer. 898 * \param[in] pHwRef pHwRef is the Information of 899 * the Device Interface Link . 900 * \param[in] type reason returned for the notification to 901 * the HCI. 902 * \param[in] pInfo Notification information like status 903 * data,length etc from the lower layer 904 * to the HCI Layer. 905 * \retval NONE. 906 * 907 */ 908 909 extern 910 void 911 phHciNfc_Target_Select_Notify( 912 phHciNfc_sContext_t *psHciContext, 913 void *pHwRef, 914 uint8_t type, 915 void *pInfo 916 ); 917 918 919 /** 920 * \ingroup grp_hci_nfc 921 * 922 * The phHciNfc_Transceive_Notify function notifies the the upper layer 923 * with the after the transceive operation. 924 * 925 * \param[in] psContext psContext is the context of 926 * the HCI Layer. 927 * \param[in] pHwRef pHwRef is the Information of 928 * the Device Interface Link . 929 * \param[in] type reason returned for the notification to 930 * the HCI. 931 * \param[in] pInfo Notification information like status 932 * data,length etc from the lower layer 933 * to the HCI Layer. 934 * \retval NONE. 935 * 936 */ 937 extern 938 void 939 phHciNfc_Transceive_Notify( 940 phHciNfc_sContext_t *psHciContext, 941 void *pHwRef, 942 uint8_t type, 943 void *pInfo 944 ); 945 946 /** 947 * \ingroup grp_hci_nfc 948 * 949 * The phHciNfc_Notify function calls the upper layer notification callback. 950 * 951 * \param[in] pUpperNotify pUpperNotify is the notification 952 * callback of the upper HAL Layer. 953 * \param[in] pUpperContext pUpperContext is the context of 954 * the upper HAL Layer. 955 * \param[in] pHwRef pHwRef is the Information of 956 * the Device Interface Link . 957 * \param[in] type type of the notification to 958 * the upper HAL layer. 959 * \param[in] pInfo completion information returned 960 * to the Upper HAL Layer. 961 * NFCSTATUS_SUCCESS Notification successfully completed . 962 * NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 963 * could not be interpreted properly. 964 * Other errors Errors related to the HCI or lower layers 965 * 966 * \retval NONE. 967 * 968 */ 969 970 extern 971 void 972 phHciNfc_Notify( 973 pphNfcIF_Notification_CB_t p_upper_notify, 974 void *p_upper_context, 975 void *pHwRef, 976 uint8_t type, 977 void *pInfo 978 ); 979 980 /** 981 * \ingroup grp_hci_nfc 982 * 983 * The phHciNfc_Release_Notify function Releases HCI and notifies 984 * the upper layer. 985 * 986 * \param[in] psHciContext psHciContext is the context of 987 * the HCI Layer. 988 * \param[in] pHwRef pHwRef is the Information of 989 * the Device Interface Link . 990 * \param[in] type reason returned for the notification to 991 * the HCI. 992 * \param[in] pInfo Notification information like status 993 * data,length etc from the lower layer 994 * to the HCI Layer. 995 * \retval NONE. 996 * 997 */ 998 extern 999 void 1000 phHciNfc_Release_Notify( 1001 phHciNfc_sContext_t *psHciContext, 1002 void *pHwRef, 1003 uint8_t type, 1004 void *pInfo 1005 ); 1006 1007 1008 1009 /** 1010 * \ingroup grp_hci_nfc 1011 * 1012 * The phHciNfc_Send_Generic_Cmd function sends the HCI Generic Commands 1013 * to the device. 1014 * 1015 * \param[in] psHciContext psHciContext is the context of 1016 * the HCI Layer. 1017 * \param[in] pHwRef pHwRef is the Information of 1018 * the Device Interface Link . 1019 * \param[in] pipe_id The pipe to which the command 1020 * is being sent. 1021 * \param[in] cmd The HCI Generic command sent to a 1022 * particular pipe . 1023 * 1024 * \retval NFCSTATUS_PENDING HCI Generic Command send in progress . 1025 * \retval 1026 * NFCSTATUS_INSUFFICIENT_RESOURCES The memory could not be allocated 1027 * as required amount of memory 1028 * is not sufficient. 1029 * 1030 */ 1031 1032 extern 1033 NFCSTATUS 1034 phHciNfc_Send_Generic_Cmd ( 1035 phHciNfc_sContext_t *psHciContext, 1036 void *pHwRef, 1037 uint8_t pipe_id, 1038 uint8_t cmd 1039 ); 1040 1041 /** 1042 * \ingroup grp_hci_nfc 1043 * 1044 * The phHciNfc_Set_Param function configures the Gate specific register 1045 * with the provided value. 1046 * 1047 * \param[in] psHciContext psHciContext is the context of 1048 * the HCI Layer. 1049 * \param[in] pHwRef pHwRef is the Information of 1050 * the Device Interface Link . 1051 * \param[in] p_pipe_info Pointer to pipe specific information. 1052 * \param[in] reg_index Index of the register to be 1053 * configured . 1054 * \param[in] p_param Value to the configured in 1055 * particular register. 1056 * \param[in] param_length Length of the parameter provided 1057 * for the configuration. 1058 * 1059 * \retval NFCSTATUS_PENDING HCI Set parameter in progress . 1060 * \retval 1061 * NFCSTATUS_INVALID_HCI_INFORMATION The Information like p_pipe_info, 1062 * p_param or param_length is invalid 1063 * 1064 */ 1065 1066 extern 1067 NFCSTATUS 1068 phHciNfc_Set_Param ( 1069 phHciNfc_sContext_t *psHciContext, 1070 void *pHwRef, 1071 phHciNfc_Pipe_Info_t *p_pipe_info, 1072 uint8_t reg_index, 1073 void *p_param, 1074 uint16_t param_length 1075 ); 1076 1077 /** 1078 * \ingroup grp_hci_nfc 1079 * 1080 * The phHciNfc_Send_HCP function sends the HCI Host Control Packet 1081 * Frames to the device. 1082 * 1083 * \param[in] psHciContext psHciContext is the context of 1084 * the HCI Layer. 1085 * \param[in] pHwRef pHwRef is the Information of 1086 * the Device Interface Link . 1087 * 1088 * \retval NFCSTATUS_PENDING HCP Frame send pending. 1089 * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 1090 * could not be interpreted properly. 1091 * \retval Other errors Other related errors 1092 * 1093 * 1094 */ 1095 1096 extern 1097 NFCSTATUS 1098 phHciNfc_Send_HCP ( 1099 phHciNfc_sContext_t *psHciContext, 1100 void *pHwRef 1101 ); 1102 1103 1104 /** 1105 * \ingroup grp_hci_nfc 1106 * 1107 * The phHciNfc_Build_HCPFrame function initially builds the HCP Packet Frame 1108 * with the values passed in the arguments . 1109 * 1110 * \param[in] hcp_packet hcp_packet is the frame packet structure 1111 * in which the frame is populated with the 1112 * appropriate fields. 1113 * \param[in] chainbit chainbit specifies whether the following 1114 * HCP frames are chained or the frame is a 1115 * normal frame. 1116 * \param[in] pipe_id pipe_id of the pipe to which the frame has 1117 * to be sent. 1118 * \param[in] msg_type type of message sent to the pipe. 1119 * \param[in] instruction type of message instruction send to the pipe. 1120 * 1121 * \retval NONE. 1122 * 1123 */ 1124 1125 1126 extern 1127 void 1128 phHciNfc_Build_HCPFrame ( 1129 phHciNfc_HCP_Packet_t *hcp_packet, 1130 uint8_t chainbit, 1131 uint8_t pipe_id, 1132 uint8_t msg_type, 1133 uint8_t instruction 1134 ); 1135 1136 /** 1137 * \ingroup grp_hci_nfc 1138 * 1139 * The phHciNfc_Append_HCPFrame function Appends the HCP Packet Frame 1140 * with the values passed in the arguments . 1141 * 1142 * \param[in] hcp_data hcp_data is the pointer to the HCP 1143 * payload to which the data is to be 1144 * appended. 1145 * \param[in] hcp_index hcp_index is the index from which 1146 * the data source needs to be appended. 1147 * \param[in] src_data src_data that is to be appended to the 1148 * HCP packet. 1149 * \param[in] src_len The length of the data source that is 1150 * to be appended. 1151 * \retval NONE. 1152 * 1153 */ 1154 1155 extern 1156 void 1157 phHciNfc_Append_HCPFrame ( 1158 uint8_t *hcp_data, 1159 uint16_t hcp_index, 1160 uint8_t *src_data, 1161 uint16_t src_len 1162 ); 1163 1164 /** 1165 * \ingroup grp_hci_nfc 1166 * 1167 * The phHciNfc_Allocate_Resource function allocates and initialises the 1168 * resource memory for the HCI layer. 1169 * 1170 * \param[in] ppBuffer ppBuffer is the pointer to which the 1171 * resource memory is allocated. 1172 * \param[in] size Variable that specifies the size of 1173 * the memory that needs to be created. 1174 * 1175 * \retval NFCSTATUS_SUCCESS The Resource Memory was allocated 1176 * successfully . 1177 * \retval 1178 * NFCSTATUS_INSUFFICIENT_RESOURCES The memory could not be allocated 1179 * as required amount of memory 1180 * is not suffient. 1181 * 1182 */ 1183 1184 extern 1185 NFCSTATUS 1186 phHciNfc_Allocate_Resource ( 1187 void **ppBuffer, 1188 uint16_t size 1189 ); 1190 /** 1191 * \ingroup grp_hci_nfc 1192 * 1193 * The phHciNfc_Release_Resources function releases all the resources 1194 * allocated in the HCI Layer. 1195 * 1196 * \param[in] psHciContext psHciContext is the context of 1197 * the HCI Layer. 1198 * 1199 * \retval NONE. 1200 * 1201 */ 1202 1203 extern 1204 void 1205 phHciNfc_Release_Resources ( 1206 phHciNfc_sContext_t **ppsHciContext 1207 ); 1208 1209 /** 1210 * \ingroup grp_hci_nfc 1211 * 1212 * The phHciNfc_Release_Lower function initiates the release of the 1213 * lower layers. 1214 * 1215 * \param[in] psHciContext psHciContext is the context of 1216 * the HCI Layer. 1217 * \param[in] pHwRef pHwRef is the Information of 1218 * the Device Interface Link . 1219 * 1220 * \retval NONE. 1221 * 1222 */ 1223 1224 extern 1225 void 1226 phHciNfc_Release_Lower( 1227 phHciNfc_sContext_t *psHciContext, 1228 void *pHwRef 1229 ); 1230 1231 1232 1233 #endif 1234 1235