ccid.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include <stdlib.h> // malloc
  3. #include <stdint.h> // uint32_t
  4. #include <stdarg.h> // __VA_ARGS__
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include "sub.h"
  8. #include "seader_worker_i.h"
  9. #define SYNC (0x03)
  10. #define CTRL (0x06)
  11. #define NAK (0x15)
  12. #define BMICCSTATUS_MASK 0x03
  13. #define CARD_OUT 0x02
  14. #define CARD_IN_1 0x03
  15. #define CARD_IN_2 0x06
  16. #define CARD_IN_BOTH 0x07
  17. /*
  18. * * BULK_OUT messages from PC to Reader
  19. * * Defined in CCID Rev 1.1 6.1 (page 26)
  20. * */
  21. #define CCID_MESSAGE_TYPE_PC_to_RDR_IccPowerOn 0x62
  22. #define CCID_MESSAGE_TYPE_PC_to_RDR_IccPowerOff 0x63
  23. #define CCID_MESSAGE_TYPE_PC_to_RDR_GetSlotStatus 0x65
  24. #define CCID_MESSAGE_TYPE_PC_to_RDR_XfrBlock 0x6f
  25. #define CCID_MESSAGE_TYPE_PC_to_RDR_GetParameters 0x6c
  26. #define CCID_MESSAGE_TYPE_PC_to_RDR_ResetParameters 0x6d
  27. #define CCID_MESSAGE_TYPE_PC_to_RDR_SetParameters 0x61
  28. #define CCID_MESSAGE_TYPE_PC_to_RDR_Escape 0x6b
  29. #define CCID_MESSAGE_TYPE_PC_to_RDR_IccClock 0x6e
  30. #define CCID_MESSAGE_TYPE_PC_to_RDR_T0APDU 0x6a
  31. #define CCID_MESSAGE_TYPE_PC_to_RDR_Secure 0x69
  32. #define CCID_MESSAGE_TYPE_PC_to_RDR_Mechanical 0x71
  33. #define CCID_MESSAGE_TYPE_PC_to_RDR_Abort 0x72
  34. #define CCID_MESSAGE_TYPE_PC_to_RDR_SetDataRateAndClockFrequency 0x73
  35. /*
  36. * * BULK_IN messages from Reader to PC
  37. * * Defined in CCID Rev 1.1 6.2 (page 48)
  38. * */
  39. #define CCID_MESSAGE_TYPE_RDR_to_PC_DataBlock 0x80
  40. #define CCID_MESSAGE_TYPE_RDR_to_PC_SlotStatus 0x81
  41. #define CCID_MESSAGE_TYPE_RDR_to_PC_Parameters 0x82
  42. #define CCID_MESSAGE_TYPE_RDR_to_PC_Escape 0x83
  43. #define CCID_MESSAGE_TYPE_RDR_to_PC_DataRateAndClockFrequency 0x84
  44. /*
  45. * * INTERRUPT_IN messages from Reader to PC
  46. * * Defined in CCID Rev 1.1 6.3 (page 56)
  47. * */
  48. #define CCID_MESSAGE_TYPE_RDR_to_PC_NotifySlotChange 0x50
  49. #define CCID_MESSAGE_TYPE_RDR_to_PC_HardwareError 0x51
  50. /* Status codes that go in bStatus (see 6.2.6) */
  51. enum {
  52. ICC_STATUS_PRESENT_ACTIVE = 0,
  53. ICC_STATUS_PRESENT_INACTIVE,
  54. ICC_STATUS_NOT_PRESENT
  55. };
  56. enum {
  57. COMMAND_STATUS_NO_ERROR = 0,
  58. COMMAND_STATUS_FAILED,
  59. COMMAND_STATUS_TIME_EXTENSION_REQUIRED
  60. };
  61. /* Error codes that go in bError (see 6.2.6) */
  62. enum {
  63. ERROR_CMD_NOT_SUPPORTED = 0,
  64. ERROR_CMD_ABORTED = -1,
  65. ERROR_ICC_MUTE = -2,
  66. ERROR_XFR_PARITY_ERROR = -3,
  67. ERROR_XFR_OVERRUN = -4,
  68. ERROR_HW_ERROR = -5,
  69. };
  70. struct CCID_Message {
  71. uint8_t bMessageType;
  72. uint32_t dwLength;
  73. uint8_t bSlot;
  74. uint8_t bSeq;
  75. uint8_t bStatus;
  76. uint8_t bError;
  77. uint8_t *payload;
  78. size_t consumed;
  79. };
  80. void PC_to_RDR_IccPowerOn(SeaderUartBridge* seader_uart);
  81. void PC_to_RDR_GetSlotStatus(SeaderUartBridge* seader_uart);
  82. void PC_to_RDR_SetParameters(SeaderUartBridge* seader_uart);
  83. void PC_to_RDR_GetParameters(SeaderUartBridge* seader_uart);
  84. void PC_to_RDR_XfrBlock(SeaderUartBridge* seader_uart, uint8_t *data, size_t len);
  85. size_t processCCID(SeaderWorker* seader_worker, uint8_t* cmd, size_t cmd_len);