1little_endian_packets 2 3enum PacketBoundaryFlag : 1 { 4 COMPLETE_OR_FINAL = 0, 5 INCOMPLETE = 1, 6} 7 8enum NciMsgType : 3 { 9 DATA = 0, 10 COMMAND = 1, 11 RESPONSE = 2, 12 NOTIFICATION = 3, 13} 14 15enum Opcode : 8 { 16 CORE_RESET = 0x0, 17 CORE_INIT = 0x1, 18 CORE_SET_CONFIG = 0x2, 19 CORE_GET_CONFIG = 0x3, 20 CORE_CONN_CREATE = 0x4, 21 CORE_CONN_CLOSE = 0x5, 22 CORE_CONN_CREDITS = 0x6, 23 CORE_GENERIC_ERROR = 0x7, 24 CORE_INTERFACE_ERROR = 0x8, 25 CORE_SET_POWER_SUBSTATE = 0x9, 26 RF_DISCOVER_MAP = 0x40, 27 RF_SET_LISTEN_MODE_ROUTING = 0x41, 28 RF_GET_LISTEN_MODE_ROUTING = 0x42, 29 RF_DISCOVER = 0x43, 30 RF_DISCOVER_SELECT = 0x44, 31 RF_INTF_ACTIVATED = 0x45, 32 RF_DIACTIVATE = 0x46, 33 RF_FIELD_INFO = 0x47, 34 RF_T3T_POLLING = 0x48, 35 RF_NFCEE_ACTION = 0x49, 36 RF_NFCEE_DISCOVERY_REQ = 0x4A, 37 RF_PARAMETER_UPDATE = 0x4B, 38 RF_INTF_EXT_START = 0x4C, 39 RF_INTF_EXT_STOP = 0x4D, 40 RF_EXT_AGG_ABORT = 0x4E, 41 RF_NDEF_ABORT = 0x4F, 42 RF_ISO_DEP_NAK_PRESENCE = 0x50, 43 RF_SET_FORCED_NFCEE_ROUTING_CMD = 0x51, 44} 45 46enum Status : 8 { 47 OK = 0x00, 48 REJECTED = 0x01, 49 FAILED = 0x03, 50 NOT_INITIALIZED = 0x04, 51 SYNTAX_ERROR = 0x05, 52 SEMANTIC_ERROR = 0x06, 53 INVALID_PARAM = 0x09, 54 MESSAGE_SIZE_EXCEEDED = 0x0A, 55 OK_1_BIT = 0x11, 56 OK_2_BIT = 0x12, 57 OK_3_BIT = 0x13, 58 OK_4_BIT = 0x14, 59 OK_5_BIT = 0x15, 60 OK_6_BIT = 0x16, 61 OK_7_BIT = 0x17, 62 DISCOVERY_ALREADY_STARTED = 0xA0, 63 DISCOVERY_TARGET_ACTIVATION_FAILED = 0xA1, 64 DISCOVERY_TEAR_DOWN = 0xA2, 65 RF_FRAME_CORRUPTED = 0x02, 66 RF_TRANSMISSION_EXCEPTION = 0xB0, 67 RF_PROTOCOL_EXCEPTION = 0xB1, 68 RF_TIMEOUT_EXCEPTION = 0xB2, 69 RF_UNEXPECTED_DATA = 0xB3, 70 NFCEE_INTERFACE_ACTIVATION_FAILED = 0xC0, 71 NFCEE_TRANSMISSION_ERROR = 0xC1, 72 NFCEE_PROTOCOL_ERROR = 0xC2, 73 NFCEE_TIMEOUT_ERROR = 0xC3, 74} 75 76packet NciPacket { 77 gid : 4, 78 pbf : PacketBoundaryFlag, 79 mt : NciMsgType, 80 _payload_, 81} 82 83packet Command : NciPacket (mt = COMMAND) { 84 op : Opcode, 85 _size_(_payload_) : 8, 86 _payload_, 87} 88 89packet Response : NciPacket (mt = RESPONSE) { 90 cmd_op : Opcode, 91 _size_(_payload_) : 8, 92 _payload_, 93} 94 95packet Notification : NciPacket (mt = NOTIFICATION) { 96 cmd_op : Opcode, 97 _size_(_payload_) : 8, 98 _payload_, 99} 100 101packet DataPacket { 102 conn_id : 4, 103 pbf : PacketBoundaryFlag, 104 _fixed_ = 0x0 : 3, 105 cr : 8, 106 _size_(_payload_) : 8, 107 _payload_, 108} 109 110enum ResetType : 8 { 111 KEEP_CONFIG = 0, 112 RESET_CONFIG = 1, 113} 114 115packet ResetCommand : Command (op = CORE_RESET) { 116 reset_type: ResetType, 117} 118 119test ResetCommand { 120 "\x20\x00\x01\x01", 121} 122 123packet ResetResponse : Response (cmd_op = CORE_RESET) { 124 status: Status, 125} 126 127test ResetResponse { 128 "\x40\x00\x01\x00", 129} 130 131enum ResetTrigger : 8 { 132 UNRECOVERABLE_ERROR = 0, 133 POWER_ON = 1, 134 RESET_COMMAND = 2, 135} 136 137enum NciVersion : 8 { 138 VERSION_1_0 = 0x10, 139 VERSION_1_1 = 0x11, 140 VERSION_2_0 = 0x20, 141} 142 143enum ConfigStatus : 8 { 144 CONFIG_KEPT = 0x00, 145 CONFIG_RESET = 0x01, 146} 147 148packet ResetNotification : Notification (cmd_op = CORE_RESET) { 149 trigger : ResetTrigger, 150 config_status : ConfigStatus, 151 nci_version : NciVersion, 152 manufacturer_id: 8, 153 _size_(mfsi) : 8, 154 mfsi : 8[], 155} 156 157test ResetNotification { 158 "\x60\x00\x1f\x02\x01\x20\x02\x1a\x05\x03\x03\x06\x88\x97\x01\x06\x00\x00\x44\x64\xd6\x00\x00\xec\x10\x00\x00\x00\x01\x00\x00\xee\xe7\x02", 159} 160 161enum FeatureEnable : 16 { 162 RFU = 0, 163} 164 165 166enum DiscConfMode : 2 { 167 DH_ONLY = 0x0, 168 DH_AND_EE = 0x1, 169} 170 171enum FeatureState : 1 { 172 DISABLED = 0, 173 AVAILABLE = 1, 174} 175 176struct PropCaps { 177 b7 : 1, 178 b6 : 1, 179 b5 : 1, 180 b4 : 1, 181 b3 : 1, 182 b2 : 1, 183 b1 : 1, 184 b0 : 1, 185} 186 187struct NfccFeatures { 188 disc_freq_conf : FeatureState, 189 disc_conf_mode : DiscConfMode, 190 hci_net_support : FeatureState, 191 active_comm_mode : FeatureState, 192 _reserved_ : 3, 193 _reserved_: 1, 194 tech_routing : FeatureState, 195 proto_routing : FeatureState, 196 aid_routing : FeatureState, 197 syc_code_routing : FeatureState, 198 apdu_pttn_routing : FeatureState, 199 forced_nfcee_routing : FeatureState, 200 _reserved_ : 1, 201 batt_off_st : FeatureState, 202 soff_st : FeatureState, 203 swon_subst : FeatureState, 204 rf_conf_soff: FeatureState, 205 _reserved_ : 4, 206 prop_caps: PropCaps, 207} 208 209enum Intf : 8 { 210 NFCEE_DIRECT_RF = 0x00, 211 FRAME_RF = 0x01, 212 ISO_DEP_RF = 0x02, 213 NFC_DEP_RF = 0x03, 214 NDEF_RF = 0x06, 215} 216 217enum Extns : 8 { 218 FR_AGREG_RF_EXT = 0x00, 219 LLCP_SYM_RF_EXT = 0x01, 220} 221 222struct ExtList { 223 ext : Extns, 224} 225 226struct RfInterface { 227 intf : 8, 228 _size_(extns) : 8, 229 extns : 8[], 230} 231 232packet InitCommand : Command (op = CORE_INIT) { 233 feature_enable : FeatureEnable, 234} 235 236test InitCommand { 237 "\x20\x01\x02\x00\x00", 238} 239 240packet InitResponse : Response (cmd_op = CORE_INIT) { 241 status : Status, 242 nfcc_features : NfccFeatures, 243 max_log_conns : 4, //TODO set max to 0x0E 244 _reserved_ : 4, 245 max_rout_tbls_size : 16, 246 max_ctrl_payload : 8, //TODO 32 <= val <= 255 247 max_data_payload : 8, 248 num_of_credits : 8, 249 max_nfcv_rf_frame_sz : 16, 250 _count_(rf_interface) : 8, 251 rf_interface: RfInterface[], 252} 253 254test InitResponse { 255 "\x40\x01\x18\x00\x1a\x7e\x06\x00\x01\x00\x04\xff\xff\x00\x0c\x01\x05\x01\x00\x02\x00\x03\x00\x00\x00\x90\x00", 256} 257 258enum ParamIds : 8 { 259 TOTAL_DURATION = 0x00, 260 CON_DISCOVERY_PARAM = 0x02, 261 POWER_STATE = 0x03, 262 PA_BAIL_OUT = 0x08, 263 PA_DEVICES_LIMIT = 0x09, 264 PB_AFI = 0x10, 265 PB_BAIL_OUT = 0x11, 266 PB_ATTRIB_PARAM1 = 0x12, 267 PB_SENSB_REQ_PARAM = 0x13, 268 PB_DEVICES_LIMIT = 0x14, 269 PF_BIT_RATE = 0x18, 270 PF_BAIL_OUT = 0x19, 271 PF_DEVICES_LIMIT = 0x1A, 272 PI_B_H_INFO = 0x20, 273 PI_BIT_RATE = 0x21, 274 PN_NFC_DEP_PSL = 0x28, 275 PN_ATR_REQ_GEN_BYTES = 0x29, 276 PN_ATR_REQ_CONFIG = 0x2A, 277 PV_DEVICES_LIMIT = 0x2F, 278 LA_BIT_FRAME_SDD = 0x30, 279 LA_PLATFORM_CONFIG = 0x31, 280 LA_SEL_INFO = 0x32, 281 LA_NFCID1 = 0x33, 282 LB_SENSB_INFO = 0x38, 283 LB_NFCID0 = 0x39, 284 LB_APPLICATION_DATA = 0x3A, 285 LB_SFGI = 0x3B, 286 LB_FWI_ADC_FO = 0x3C, 287 LB_BIT_RATE = 0x3E, 288 LF_T3T_IDENTIFIERS_1 = 0x40, 289 LF_T3T_IDENTIFIERS_2 = 0x41, 290 LF_T3T_IDENTIFIERS_3 = 0x42, 291 LF_T3T_IDENTIFIERS_4 = 0x43, 292 LF_T3T_IDENTIFIERS_5 = 0x44, 293 LF_T3T_IDENTIFIERS_6 = 0x45, 294 LF_T3T_IDENTIFIERS_7 = 0x46, 295 LF_T3T_IDENTIFIERS_8 = 0x47, 296 LF_T3T_IDENTIFIERS_9 = 0x48, 297 LF_T3T_IDENTIFIERS_10 = 0x49, 298 LF_T3T_IDENTIFIERS_11 = 0x4A, 299 LF_T3T_IDENTIFIERS_12 = 0x4B, 300 LF_T3T_IDENTIFIERS_13 = 0x4C, 301 LF_T3T_IDENTIFIERS_14 = 0x4D, 302 LF_T3T_IDENTIFIERS_15 = 0x4E, 303 LF_T3T_IDENTIFIERS_16 = 0x4F, 304 LF_T3T_MAX = 0x52, 305 LF_T3T_FLAGS = 0x53, 306 LF_T3T_RD_ALLOWED = 0x55, 307 LF_PROTOCOL_TYPE = 0x50, 308 LI_A_RATS_TB1 = 0x58, 309 LI_A_HIST_BY = 0x59, 310 LI_B_H_INFO_RESP = 0x5A, 311 LI_A_BIT_RATE = 0x5B, 312 LI_A_RATS_TC1 = 0x5C, 313 LN_WT = 0x60, 314 LN_ATR_RES_GEN_BYTES = 0x61, 315 LN_ATR_RES_CONFIG = 0x62, 316 PACM_BIT_RATE = 0x68, 317 RF_FIELD_INFO = 0x80, 318 RF_NFCEE_ACTION = 0x81, 319 NFCDEP_OP = 0x82, 320 LLCP_VERSION = 0x83, 321 NFCC_CONFIG_CONTROL = 0x85, 322 PROP0 = 0xa0, 323 PROP1 = 0xa1, 324 PROP2 = 0xa2, 325 PROP3 = 0xa3, 326 PROP4 = 0xa4, 327 PROP5 = 0xa5, 328} 329 330struct ConfigParams { 331 paramid : ParamIds, 332 _size_(valm) : 8, 333 valm : 8[], 334} 335 336struct ParamList { 337 pids : ParamIds, 338} 339 340packet SetConfigCommand : Command (op = CORE_SET_CONFIG) { 341 _count_(params) : 8, 342 params : ConfigParams[], 343} 344 345test SetConfigCommand { 346 "\x20\x02\x10\x05\x30\x01\x04\x31\x01\x00\x32\x01\x20\x38\x01\x01\x50\x01\x00", 347} 348 349packet SetConfigResponse : Response (cmd_op = CORE_SET_CONFIG) { 350 status : Status, 351 _count_(paramids) : 8, 352 paramids : ParamList[], 353} 354 355test SetConfigResponse { 356 "\x40\x02\x02\x00\x00", 357} 358 359packet GetConfigCommand : Command (op = CORE_GET_CONFIG) { 360 _count_(paramids) : 8, 361 paramids : ParamList[], 362} 363 364test GetConfigCommand { 365 "\x20\x03\x02\x01\x52", 366} 367 368packet GetConfigResponse : Response (cmd_op = CORE_GET_CONFIG) { 369 status : Status, 370 _count_(params) : 8, 371 params : ConfigParams[], 372} 373 374test GetConfigResponse { 375 "\x40\x03\x05\x00\x01\x52\x01\x10", 376} 377 378enum RfProtocols : 8 { 379 PROTOCOL_UNDETERMINED = 0x00, 380 PROTOCOL_T1T = 0x01, 381 PROTOCOL_T2T = 0x02, 382 PROTOCOL_T3T = 0x03, 383 PROTOCOL_ISO_DEP = 0x04, 384 PROTOCOL_NFC_DEP = 0x05, 385 PROTOCOL_T5T = 0x06, 386 PROTOCOL_NDEF = 0x07, 387} 388 389enum NfceeProtocols : 8 { 390 APDU = 0x00, 391 RFU = 0x01, 392 T3CS = 0x02, 393 TRANSPARENT = 0x04, 394} 395 396enum DestTypes : 8 { 397 RFU = 0x00, 398 NFCC_LPBK = 0x01, 399 REMOTE = 0x02, 400 NFCEE = 0x03, 401} 402 403enum DestParamTypes : 8 { 404 RF_DISC = 0x00, 405 NFCEE = 0x01, 406} 407 408struct RfDiscType { 409 id : 8, 410 proto: RfProtocols, 411} 412 413struct NfceeType { 414 id : 8, 415 proto : NfceeProtocols, 416} 417 418struct DestParam { 419 ptype : DestParamTypes, 420 _size_(parameter) : 8, 421 parameter : 8[], 422} 423 424packet ConnCreateCommand : Command (op = CORE_CONN_CREATE) { 425 dt : DestTypes, 426 _count_(destparams) : 8, 427 destparams : DestParam[], 428} 429 430packet ConnCreateResponse : Response (cmd_op = CORE_CONN_CREATE) { 431 status : Status, 432 mpps : 8, 433 ncreds : 8, 434 conn_id : 8, 435} 436 437packet ConnCloseCommand : Command (op = CORE_CONN_CLOSE) { 438 conn_id : 8, 439} 440 441packet ConnCloseResponse : Response (cmd_op = CORE_CONN_CLOSE) { 442 status : Status, 443} 444 445struct CreditsPerConn { 446 conn_id : 4, 447 rfu : 4, 448 ncredits : 8, 449} 450 451packet ConnCreditsNotification : Notification (cmd_op = CORE_CONN_CREDITS) { 452 _count_(conns) : 8, 453 conns : CreditsPerConn[], 454} 455 456packet GenericError : Notification (cmd_op = CORE_GENERIC_ERROR) { 457 status : Status, 458} 459 460packet InterfaceError : Notification (cmd_op = CORE_INTERFACE_ERROR) { 461 status : Status, 462 conn_id : 8, 463} 464 465enum RfMode : 8 { 466 POLL = 0x1, 467 LISTEN = 0x2, 468} 469 470enum RfInterfaceType : 8 { 471 NFCEE_DIRECT = 0x0, 472 FRAME = 0x1, 473 ISO_DEP = 0x2, 474 NFC_DEP = 0x3, 475 NDEF = 0x6, 476} 477 478struct RfMappingConfiguration { 479 rf_proto : RfProtocols, 480 mode : RfMode, 481 intf : RfInterfaceType, 482} 483 484packet RfDiscoverMapCommand : Command (op = RF_DISCOVER_MAP) { 485 _count_(map_configs) : 8, 486 map_configs : RfMappingConfiguration[], 487} 488 489packet RfDiscoverMapResponse : Response (cmd_op = RF_DISCOVER_MAP) { 490 status : Status, 491} 492 493enum More : 8 { 494 LAST = 0x0, 495 MORE = 0x1, 496} 497 498enum ListenModeREntryType : 4 { 499 TECH = 0, 500 PROTO = 1, 501 AID = 2, 502 SYSCODE = 3, 503 PATTERN = 4, 504} 505 506struct QualifierType { 507 lmr_type : ListenModeREntryType, 508 long_ok : 1, 509 short_ok : 1, 510 block : 1, 511 _fixed_ = 0 : 1, 512} 513 514struct RoutingEntry { 515 qt : QualifierType, 516 _size_(valr) : 8, 517 valr : 8[], 518} 519 520enum NfcEeID : 8 { 521 DH = 0x0, 522 HCI = 0x1, 523} 524 525struct PowerState { 526 _fixed_ = 0x0 : 2, 527 subst3 : 1, 528 subst2 : 1, 529 subst1 : 1, 530 batt_off : 1, 531 switch_off : 1, 532 switch_on : 1, 533} 534 535enum Technology : 8 { 536 TECH_A = 0x0, 537 TECH_B = 0x1, 538 TECH_F = 0x2, 539 TECH_V = 0x3, 540} 541 542struct TechRE { 543 id : 8, // NfcEeID 0x80-0xfe dynamic HCI-EEs, 0x10-0x7f other synamic EEs 544 pstate : PowerState, 545 tech : Technology, 546} 547 548struct ProtoRE { 549 id : 8, 550 pstate : PowerState, 551 proto : RfProtocols, 552} 553 554struct CommonRE { 555 id : 8, 556 pstate: PowerState, 557 _payload_, 558} 559 560packet RfSetListenModeRoutingCommand : Command (op = RF_SET_LISTEN_MODE_ROUTING) { 561 more : More, 562 _count_(entries) : 8, 563 entries : RoutingEntry[], 564} 565 566packet RfSetListenModeRoutingResponse : Response (cmd_op = RF_SET_LISTEN_MODE_ROUTING) { 567 status : Status, 568} 569 570packet RfGetListenModeRoutingCommand : Command (op = RF_GET_LISTEN_MODE_ROUTING) { 571} 572 573packet RfGetListenModeRoutingResponse : Response (cmd_op = RF_GET_LISTEN_MODE_ROUTING) { 574 status : Status, 575} 576 577packet RfGetListenModeRoutingNotification : Notification (cmd_op = RF_GET_LISTEN_MODE_ROUTING) { 578 more : More, 579 _count_(entries) : 8, 580 entries : RoutingEntry[], 581} 582 583enum PowerSubState : 8 { 584 SWITCHED_ON = 0x0, 585 SO_SUBSTATE1 = 0x1, 586 SO_SUBSTATE2 = 0x2, 587 SO_SUBSTATE3 = 0x3, 588} 589 590packet SetPowerSubStateCommand : Command (op = CORE_SET_POWER_SUBSTATE) { 591 pstate : PowerSubState, 592} 593 594packet SetPowerSubStateResponse : Response (cmd_op = CORE_SET_POWER_SUBSTATE) { 595 status : Status, 596} 597