Changeset 11429 for trunk/csctapi/protocol_t1.c
- Timestamp:
- 07/28/18 21:31:01 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/protocol_t1.c
r10283 r11429 1 /*2 protocol_t1.c3 Handling of ISO 7816 T=1 protocol4 5 This file is part of the Unix driver for Towitoko smartcard readers6 Copyright (C) 2000 Carlos Prados <cprados@yahoo.com>7 8 This version is modified by doz21 to work in a special manner ;)9 10 This library is free software; you can redistribute it and/or11 modify it under the terms of the GNU Lesser General Public12 License as published by the Free Software Foundation; either13 version 2 of the License, or (at your option) any later version.14 15 This library is distributed in the hope that it will be useful,16 but WITHOUT ANY WARRANTY; without even the implied warranty of17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU18 Lesser General Public License for more details.19 20 You should have received a copy of the GNU Lesser General Public21 License along with this library; if not, write to the Free Software22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA23 */24 25 1 #include "../globals.h" 26 2 #include "../oscam-time.h" … … 28 4 #include "icc_async.h" 29 5 30 #define OK 31 #define ERROR 6 #define OK 0 7 #define ERROR 1 32 8 33 9 /* Buffer sizes */ 34 #define T1_BLOCK_MAX_SIZE 10 #define T1_BLOCK_MAX_SIZE 259 35 11 36 12 /* Types of block */ 37 #define T1_BLOCK_I 38 #define T1_BLOCK_R_OK 39 #define T1_BLOCK_R_EDC_ERR 40 #define T1_BLOCK_R_OTHER_ERR 41 #define T1_BLOCK_S_RESYNCH_REQ 42 #define T1_BLOCK_S_RESYNCH_RES 43 #define T1_BLOCK_S_IFS_REQ 44 #define T1_BLOCK_S_IFS_RES 45 #define T1_BLOCK_S_ABORT_REQ 46 #define T1_BLOCK_S_ABORT_RES 47 #define T1_BLOCK_S_WTX_REQ 48 #define T1_BLOCK_S_WTX_RES 49 #define T1_BLOCK_S_VPP_ERR 50 51 #define T1_BLOCK_NAD 0x0013 #define T1_BLOCK_I 0x00 14 #define T1_BLOCK_R_OK 0x80 15 #define T1_BLOCK_R_EDC_ERR 0x81 16 #define T1_BLOCK_R_OTHER_ERR 0x82 17 #define T1_BLOCK_S_RESYNCH_REQ 0xC0 18 #define T1_BLOCK_S_RESYNCH_RES 0xE0 19 #define T1_BLOCK_S_IFS_REQ 0xC1 20 #define T1_BLOCK_S_IFS_RES 0xE1 21 #define T1_BLOCK_S_ABORT_REQ 0xC2 22 #define T1_BLOCK_S_ABORT_RES 0xE2 23 #define T1_BLOCK_S_WTX_REQ 0xC3 24 #define T1_BLOCK_S_WTX_RES 0xE3 25 #define T1_BLOCK_S_VPP_ERR 0xE4 26 27 #define T1_BLOCK_NAD 0x21 52 28 53 29 #define T1_Block_GetNS(a) ((a[1] >> 6) & 0x01) … … 62 38 uint32_t i; 63 39 for(i = 0; i < length; i++) 64 { lrc ^= data[i]; } 40 { 41 lrc ^= data[i]; 42 } 65 43 return lrc; 66 44 } 67 45 68 static int32_t T1_Block_SendIBlock(struct s_reader *reader, uint8_t *block_data, unsigned char len, unsigned char *inf, unsigned char ns, int32_t more, uint32_t timeout)46 static int32_t T1_Block_SendIBlock(struct s_reader *reader, uint8_t *block_data, unsigned char len, unsigned char *inf, unsigned char ns, int32_t more, uint32_t timeout, uint8_t block_nad) 69 47 { 70 48 int length = len + 4; 71 49 72 block_data[0] = T1_BLOCK_NAD;50 block_data[0] = block_nad; 73 51 block_data[1] = T1_BLOCK_I | ((ns << 6) & 0x40); 74 52 if(more) 75 { block_data[1] |= 0x20; } 53 { 54 block_data[1] |= 0x20; 55 } 76 56 block_data[2] = len; 77 57 if(len != 0x00) 78 { memcpy(block_data + 3, inf, len); } 58 { 59 memcpy(block_data + 3, inf, len); 60 } 79 61 block_data[len + 3] = T1_Block_LRC(block_data, len + 3); 80 62 … … 102 84 block_data[2] = len; 103 85 if(len != 0x00) 104 { memcpy(block_data + 3, inf, len); } 86 { 87 memcpy(block_data + 3, inf, len); 88 } 105 89 106 90 block_data[len + 3] = T1_Block_LRC(block_data, len + 3); … … 115 99 /* Receive four mandatory bytes */ 116 100 if(ICC_Async_Receive(reader, 4, block_data, 0, timeout)) 117 { ret = ERROR; } 101 { 102 ret = ERROR; 103 } 118 104 else 119 105 { … … 125 111 /* Receive remaining bytes */ 126 112 if(ICC_Async_Receive(reader, *block_length - 4, block_data + 4, 0, timeout)) 127 { ret = ERROR; } 113 { 114 ret = ERROR; 115 } 128 116 else 129 { ret = OK; } 117 { 118 ret = OK; 119 } 130 120 } 131 121 else … … 140 130 } 141 131 142 int32_t Protocol_T1_Command(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr )132 int32_t Protocol_T1_Command(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr, uint8_t block_nad) 143 133 { 144 134 uint8_t block_data[T1_BLOCK_MAX_SIZE]; … … 148 138 bool more; 149 139 uint32_t block_length = 0; 140 141 if(block_nad == 0) 142 { 143 block_nad = T1_BLOCK_NAD; 144 } 145 150 146 if(command[1] == T1_BLOCK_S_IFS_REQ) 151 147 { 148 rdr_log_dbg(reader, D_READER, "command[1] == T1_BLOCK_S_IFS_REQ"); 149 152 150 uint8_t inf = command[3]; 153 151 … … 177 175 else if(command[1] == T1_BLOCK_S_RESYNCH_REQ) 178 176 { 177 rdr_log_dbg(reader, D_READER, "command[1] == T1_BLOCK_S_RESYNCH_REQ"); 179 178 /* Create an Resynch request S-Block */ 180 179 timeout = ICC_Async_GetTimings(reader, reader->CWT); // we are going to send: CWT timeout … … 213 212 timeout = ICC_Async_GetTimings(reader, reader->CWT); // we are going to send: CWT timeout 214 213 //cs_sleepus(reader->block_delay); // we were receiving, now sending so wait BGT time 215 ret = T1_Block_SendIBlock(reader, block_data, bytes, command, reader->ns, more, timeout );214 ret = T1_Block_SendIBlock(reader, block_data, bytes, command, reader->ns, more, timeout, block_nad); 216 215 rdr_log_dbg(reader, D_IFD, "Sending block I(%d,%d)", reader->ns, more); 217 216 … … 244 243 timeout = ICC_Async_GetTimings(reader, reader->CWT); // we are going to send: CWT timeout 245 244 //cs_sleepus(reader->block_delay); // we were receiving, now sending so wait BGT time 246 ret = T1_Block_SendIBlock(reader, block_data, bytes, command + counter, reader->ns, more, timeout );245 ret = T1_Block_SendIBlock(reader, block_data, bytes, command + counter, reader->ns, more, timeout, block_nad); 247 246 rdr_log_dbg(reader, D_IFD, "Protocol: Sending block I(%d,%d)", reader->ns, more); 248 247 … … 286 285 nr = (T1_Block_GetNS(block_data) + 1) % 2; 287 286 288 if(counter + bytes > T1_BLOCK_MAX_SIZE) { return ERROR; } 287 if(counter + bytes > T1_BLOCK_MAX_SIZE) 288 { 289 return ERROR; 290 } 289 291 290 292 memcpy(rsp + counter, block_data + 3, bytes); … … 324 326 325 327 if(ret == OK) 326 { *lr = counter; } 328 { 329 *lr = counter; 330 } 327 331 328 332 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.