Changeset 1560
- Timestamp:
- 02/14/10 19:44:18 (14 years ago)
- Location:
- branches/monitor-improvement
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/monitor-improvement/csctapi/apdu.c
r1517 r1560 41 41 */ 42 42 43 APDU_Cmd * APDU_Cmd_New (BYTE * data, unsigned long length) 44 { 45 APDU_Cmd *apdu; 46 47 if ((length > APDU_MAX_CMD_SIZE)) 48 return NULL; 49 50 apdu = (APDU_Cmd *) malloc (sizeof (APDU_Cmd)); 51 52 if (apdu != NULL) 53 { 54 apdu->length = MAX (APDU_MIN_CMD_SIZE, length); 55 apdu->command = (BYTE *) calloc (apdu->length, sizeof (BYTE)); 56 57 if (apdu->command != NULL) 58 { 59 memcpy (apdu->command, data, length); 60 if (length < apdu->length) 61 memset (apdu->command + length, 0, apdu->length - length); 62 } 63 else 64 { 65 free (apdu); 66 apdu = NULL; 67 } 68 } 69 70 return apdu; 71 } 72 73 void APDU_Cmd_Delete (APDU_Cmd * apdu) 74 { 75 free (apdu->command); 76 free (apdu); 77 } 78 79 int APDU_Cmd_Case (APDU_Cmd * apdu) 80 { 43 int APDU_Cmd_Case (unsigned char * command, unsigned long command_len) 44 { 45 APDU_Cmd c, * apdu; 46 c.command=command; 47 c.length=command_len; 48 apdu = &c; 49 81 50 BYTE B1; 82 51 ushort B2B3; … … 126 95 } 127 96 128 BYTE APDU_Cmd_Cla (APDU_Cmd * apdu)129 {130 return apdu->command[0];131 }132 133 97 BYTE APDU_Cmd_Ins (APDU_Cmd * apdu) 134 98 { 135 99 return apdu->command[1]; 136 }137 138 BYTE APDU_Cmd_P1 (APDU_Cmd * apdu)139 {140 return apdu->command[2];141 }142 143 BYTE APDU_Cmd_P2 (APDU_Cmd * apdu)144 {145 return apdu->command[3];146 100 } 147 101 … … 151 105 unsigned long res; 152 106 153 c = APDU_Cmd_Case (apdu );107 c = APDU_Cmd_Case (apdu->command, apdu->length); 154 108 155 109 if ((c == APDU_CASE_1) || (c == APDU_CASE_3S) || (c == APDU_CASE_3E)) … … 170 124 unsigned long res; 171 125 172 c = APDU_Cmd_Case (apdu );126 c = APDU_Cmd_Case (apdu->command, apdu->length); 173 127 174 128 if ((c == APDU_CASE_1) || (c == APDU_CASE_2S) || (c == APDU_CASE_2E)) … … 200 154 BYTE * res; 201 155 202 c = APDU_Cmd_Case (apdu );156 c = APDU_Cmd_Case (apdu->command, apdu->length); 203 157 204 158 if ((c == APDU_CASE_1) || (c == APDU_CASE_3S) || (c == APDU_CASE_3E)) … … 212 166 213 167 return res; 214 }215 216 BYTE * APDU_Cmd_Raw (APDU_Cmd * apdu)217 {218 return apdu->command;219 }220 221 unsigned long APDU_Cmd_RawLen (APDU_Cmd * apdu)222 {223 return apdu->length;224 168 } 225 169 -
branches/monitor-improvement/csctapi/apdu.h
r1517 r1560 78 78 */ 79 79 80 /* Create a APDU_Cmd */81 extern APDU_Cmd *APDU_Cmd_New (BYTE * data, unsigned long length);82 83 /* Delete a APDU_Cmd */84 extern void APDU_Cmd_Delete (APDU_Cmd * apdu);85 86 80 /* Return the case of command */ 87 extern int APDU_Cmd_Case (APDU_Cmd * apdu); 88 89 /* Return class of command */ 90 extern BYTE APDU_Cmd_Cla (APDU_Cmd * apdu); 81 int APDU_Cmd_Case (unsigned char * command, unsigned long command_len); 91 82 92 83 /* Return command instruction */ 93 extern BYTE APDU_Cmd_Ins (APDU_Cmd * apdu); 94 95 /* Return first paramenter of command */ 96 extern BYTE APDU_Cmd_P1 (APDU_Cmd * apdu); 97 98 /* Return second parameter of command */ 99 extern BYTE APDU_Cmd_P2 (APDU_Cmd * apdu); 84 BYTE APDU_Cmd_Ins (APDU_Cmd * apdu); 100 85 101 86 /* Return length of data sent */ 102 externunsigned long APDU_Cmd_Lc (APDU_Cmd * apdu);87 unsigned long APDU_Cmd_Lc (APDU_Cmd * apdu); 103 88 104 89 /* Return length of data expected */ 105 externunsigned long APDU_Cmd_Le (APDU_Cmd * apdu);90 unsigned long APDU_Cmd_Le (APDU_Cmd * apdu); 106 91 107 92 /* Return a pointer to the header of the command */ 108 externBYTE *APDU_Cmd_Header (APDU_Cmd * apdu);93 BYTE *APDU_Cmd_Header (APDU_Cmd * apdu); 109 94 110 95 /* Return a pointer to the data of the comamnd */ 111 extern BYTE *APDU_Cmd_Data (APDU_Cmd * apdu); 112 113 /* Return a pointer to the whole command */ 114 extern BYTE *APDU_Cmd_Raw (APDU_Cmd * apdu); 115 116 /* Return the length of the whole command */ 117 extern unsigned long APDU_Cmd_RawLen (APDU_Cmd * apdu); 96 BYTE *APDU_Cmd_Data (APDU_Cmd * apdu); 118 97 119 98 /* Create a APDU_Rsp */ 120 externAPDU_Rsp *APDU_Rsp_New (BYTE * data, unsigned long length);99 APDU_Rsp *APDU_Rsp_New (BYTE * data, unsigned long length); 121 100 122 101 /* Delete a APDU_Rsp */ 123 externvoid APDU_Rsp_Delete (APDU_Rsp * apdu);102 void APDU_Rsp_Delete (APDU_Rsp * apdu); 124 103 125 104 /* Return fitst status byte */ 126 externBYTE APDU_Rsp_SW1 (APDU_Rsp * apdu);105 BYTE APDU_Rsp_SW1 (APDU_Rsp * apdu); 127 106 128 107 /* Return second status byte */ 129 externBYTE APDU_Rsp_SW2 (APDU_Rsp * apdu);108 BYTE APDU_Rsp_SW2 (APDU_Rsp * apdu); 130 109 131 110 /* Return length of the data of the response */ 132 externunsigned long APDU_Rsp_DataLen (APDU_Rsp * apdu);111 unsigned long APDU_Rsp_DataLen (APDU_Rsp * apdu); 133 112 134 113 /* Return a pointer to the whole response */ 135 externBYTE *APDU_Rsp_Raw (APDU_Rsp * apdu);114 BYTE *APDU_Rsp_Raw (APDU_Rsp * apdu); 136 115 137 116 /* Return the length of the whole response */ 138 externunsigned long APDU_Rsp_RawLen (APDU_Rsp * apdu);117 unsigned long APDU_Rsp_RawLen (APDU_Rsp * apdu); 139 118 140 119 /* Truncate size of response APDU */ 141 externvoid APDU_Rsp_TruncateData (APDU_Rsp * apdu, unsigned long length);120 void APDU_Rsp_TruncateData (APDU_Rsp * apdu, unsigned long length); 142 121 143 122 /* Adds one APDU at the end of the data bytes of an APDU */ 144 externint APDU_Rsp_AppendData (APDU_Rsp * apdu1, APDU_Rsp * apdu2);123 int APDU_Rsp_AppendData (APDU_Rsp * apdu1, APDU_Rsp * apdu2); 145 124 146 125 #endif -
branches/monitor-improvement/csctapi/atr.h
r1373 r1560 109 109 110 110 /* Initialization */ 111 externint ATR_InitFromArray (ATR * atr, BYTE buffer[ATR_MAX_SIZE], unsigned length);112 externint ATR_InitFromStream (ATR * atr, unsigned timeout);111 int ATR_InitFromArray (ATR * atr, BYTE buffer[ATR_MAX_SIZE], unsigned length); 112 int ATR_InitFromStream (ATR * atr, unsigned timeout); 113 113 114 114 /* General smartcard characteristics */ 115 externint ATR_GetConvention (ATR * atr, int *convention);116 externint ATR_GetNumberOfProtocols (ATR * atr, unsigned *number_protocols);117 externint ATR_GetProtocolType (ATR * atr, unsigned number_protocol, BYTE *protocol_type);115 int ATR_GetConvention (ATR * atr, int *convention); 116 int ATR_GetNumberOfProtocols (ATR * atr, unsigned *number_protocols); 117 int ATR_GetProtocolType (ATR * atr, unsigned number_protocol, BYTE *protocol_type); 118 118 119 119 /* ATR parameters and integer values */ 120 externint ATR_GetInterfaceByte (ATR * atr, unsigned number, int character, BYTE * ib);121 externint ATR_GetIntegerValue (ATR * atr, int name, BYTE * value);122 externint ATR_GetParameter (ATR * atr, int name, double *parameter);123 externint ATR_GetHistoricalBytes (ATR * atr, BYTE * hist, unsigned *length);124 externint ATR_GetCheckByte (ATR * atr, BYTE * check_byte);125 externint ATR_GetFsMax (ATR * atr, unsigned long *fsmax);120 int ATR_GetInterfaceByte (ATR * atr, unsigned number, int character, BYTE * ib); 121 int ATR_GetIntegerValue (ATR * atr, int name, BYTE * value); 122 int ATR_GetParameter (ATR * atr, int name, double *parameter); 123 int ATR_GetHistoricalBytes (ATR * atr, BYTE * hist, unsigned *length); 124 int ATR_GetCheckByte (ATR * atr, BYTE * check_byte); 125 int ATR_GetFsMax (ATR * atr, unsigned long *fsmax); 126 126 127 127 /* Raw ATR retrieving */ 128 externint ATR_GetRaw (ATR * atr, BYTE * buffer, unsigned *lenght);129 externint ATR_GetSize (ATR * atr, unsigned *size);128 int ATR_GetRaw (ATR * atr, BYTE * buffer, unsigned *lenght); 129 int ATR_GetSize (ATR * atr, unsigned *size); 130 130 131 131 #endif /* _ATR_ */ -
branches/monitor-improvement/csctapi/icc_async.c
r1517 r1560 61 61 static unsigned int ETU_to_ms(unsigned long WWT); 62 62 static BYTE PPS_GetPCK (BYTE * block, unsigned length); 63 static int Protocol_Command ( APDU_Cmd * cmd, APDU_Rsp ** rsp);63 static int Protocol_Command (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 64 64 static int SetRightParity (void); 65 65 … … 256 256 int ICC_Async_CardWrite (unsigned char *cmd, unsigned short lc, unsigned char *rsp, unsigned short *lr) 257 257 { 258 APDU_Cmd *apdu_cmd;259 258 APDU_Rsp *apdu_rsp = NULL; 260 259 int remain; 261 260 bool err = FALSE; 262 261 263 /* Create a command APDU */ 264 apdu_cmd = APDU_Cmd_New (cmd, lc); 265 if (apdu_cmd == NULL) { 266 cs_log("ERROR creating APDU command"); 267 return ERROR; 268 } 269 270 call (Protocol_Command (apdu_cmd, &apdu_rsp)); 262 call (Protocol_Command (cmd, lc, &apdu_rsp)); 271 263 { 272 264 if (apdu_rsp != NULL) { … … 285 277 } 286 278 287 APDU_Cmd_Delete (apdu_cmd);288 279 if (err) { 289 280 cs_log("ERROR creating APDU response"); … … 294 285 } 295 286 296 int Protocol_Command ( APDU_Cmd * cmd, APDU_Rsp ** rsp)287 int Protocol_Command (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 297 288 { 298 289 switch (protocol_type) { 299 290 case ATR_PROTOCOL_TYPE_T0: 300 call (Protocol_T0_Command (c md, rsp));291 call (Protocol_T0_Command (command, command_len, rsp)); 301 292 break; 302 293 case ATR_PROTOCOL_TYPE_T1: 303 call (Protocol_T1_Command (c md, rsp));294 call (Protocol_T1_Command (command, command_len, rsp)); 304 295 break; 305 296 case ATR_PROTOCOL_TYPE_T14: 306 call (Protocol_T14_ExchangeTPDU (c md, rsp));297 call (Protocol_T14_ExchangeTPDU (command, command_len, rsp)); 307 298 break; 308 299 default: … … 854 845 //IFS setting in case of T1 855 846 if ((protocol_type == ATR_PROTOCOL_TYPE_T1) && (ifsc != DEFAULT_IFSC)) { 856 APDU_Cmd * cmd;857 847 APDU_Rsp ** rsp; 858 848 unsigned char tmp[] = { 0x21, 0xC1, 0x01, 0x00, 0x00 }; 859 849 tmp[3] = ifsc; // Information Field size 860 850 tmp[4] = ifsc ^ 0xE1; 861 cmd = APDU_Cmd_New (tmp, 5L); 862 Protocol_T1_Command (cmd, rsp); 863 APDU_Cmd_Delete (cmd); 851 Protocol_T1_Command (tmp, sizeof(tmp), rsp); 864 852 } 865 853 return OK; -
branches/monitor-improvement/csctapi/icc_async.h
r1479 r1560 63 63 64 64 /* Initialization and Deactivation */ 65 externint ICC_Async_Activate (ATR * newatr, unsigned short deprecated);66 externint ICC_Async_Close (void);65 int ICC_Async_Activate (ATR * newatr, unsigned short deprecated); 66 int ICC_Async_Close (void); 67 67 int ICC_Async_Device_Init (void); 68 68 69 69 /* Attributes */ 70 70 int ICC_Async_SetTimings (unsigned wait_etu); 71 externunsigned long ICC_Async_GetClockRate (void);71 unsigned long ICC_Async_GetClockRate (void); 72 72 int ICC_Async_GetStatus (int * has_card); 73 73 … … 75 75 /* Operations */ 76 76 int ICC_Async_CardWrite (unsigned char *cmd, unsigned short lc, unsigned char *rsp, unsigned short *lr); 77 externint ICC_Async_Transmit (unsigned size, BYTE * buffer);78 externint ICC_Async_Receive (unsigned size, BYTE * buffer);77 int ICC_Async_Transmit (unsigned size, BYTE * buffer); 78 int ICC_Async_Receive (unsigned size, BYTE * buffer); 79 79 80 80 #endif /* _ICC_ASYNC_ */ -
branches/monitor-improvement/csctapi/io_serial.h
r1438 r1560 55 55 56 56 /* IO_Serial creation and deletion */ 57 externvoid IO_Serial_Flush (void);57 void IO_Serial_Flush (void); 58 58 59 59 /* Initialization and closing */ 60 externbool IO_Serial_InitPnP (void);61 externbool IO_Serial_Close (void);60 bool IO_Serial_InitPnP (void); 61 bool IO_Serial_Close (void); 62 62 63 63 /* Transmission properties */ 64 externbool IO_Serial_DTR_RTS(int, int);64 bool IO_Serial_DTR_RTS(int, int); 65 65 #if defined(TUXBOX) && defined(PPC) 66 externvoid IO_Serial_Ioctl_Lock(int);66 void IO_Serial_Ioctl_Lock(int); 67 67 #else 68 68 #define IO_Serial_Ioctl_Lock(b) {} //FIXME ugly !! … … 75 75 76 76 /* Input and output */ 77 externbool IO_Serial_Read (unsigned timeout, unsigned size, BYTE * data);78 externbool IO_Serial_Write (unsigned delay, unsigned size, BYTE * data);77 bool IO_Serial_Read (unsigned timeout, unsigned size, BYTE * data); 78 bool IO_Serial_Write (unsigned delay, unsigned size, BYTE * data); 79 79 80 80 #endif /* IO_SERIAL */ -
branches/monitor-improvement/csctapi/protocol_t0.c
r1523 r1560 55 55 */ 56 56 57 static int Protocol_T0_Case2E ( APDU_Cmd * cmd, APDU_Rsp ** rsp);58 59 static int Protocol_T0_Case3E ( APDU_Cmd * cmd, APDU_Rsp ** rsp);60 61 static int Protocol_T0_Case4E ( APDU_Cmd * cmd, APDU_Rsp ** rsp);62 63 static int Protocol_T0_ExchangeTPDU ( APDU_Cmd * cmd, APDU_Rsp ** rsp);57 static int Protocol_T0_Case2E (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 58 59 static int Protocol_T0_Case3E (unsigned char * command, APDU_Rsp ** rsp); 60 61 static int Protocol_T0_Case4E (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 62 63 static int Protocol_T0_ExchangeTPDU (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 64 64 65 65 /* … … 67 67 */ 68 68 69 int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp) 70 { 69 int Protocol_T0_Command (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 70 { 71 if (command_len < 5) //APDU_CASE_1 or malformed 72 return ERROR; 73 74 APDU_Cmd c, * cmd; 75 c.command=command; 76 c.length=command_len; 77 cmd = &c; 78 71 79 int cmd_case; 72 80 73 cmd_case = APDU_Cmd_Case (cmd); 74 if (cmd_case != APDU_MALFORMED) 75 cs_debug_mask (D_IFD,"Protocol: T=0 Case %d %s\n", (cmd_case & 0x0F), APDU_CASE_IS_EXTENDED (cmd_case)? "extended": "short"); 76 81 cmd_case = APDU_Cmd_Case (command, command_len); 77 82 switch (cmd_case) { 78 83 case APDU_CASE_2E: 79 return Protocol_T0_Case2E (c md, rsp);84 return Protocol_T0_Case2E (command, command_len, rsp); 80 85 case APDU_CASE_3E: 81 return Protocol_T0_Case3E (c md, rsp);86 return Protocol_T0_Case3E (command, rsp); 82 87 case APDU_CASE_4E: 83 return Protocol_T0_Case4E (cmd, rsp); 84 case APDU_CASE_1: 85 cmd->command[4] = 0x00; 86 cmd->length = 5; 87 return Protocol_T0_ExchangeTPDU(cmd, rsp); 88 return Protocol_T0_Case4E (command, command_len, rsp); 88 89 case APDU_CASE_4S: 89 c md->length--;90 command_len--; //FIXME this should change 4S to 2S/3S command 90 91 case APDU_CASE_2S: 91 92 case APDU_CASE_3S: 92 return Protocol_T0_ExchangeTPDU(c md, rsp);93 return Protocol_T0_ExchangeTPDU(command, command_len, rsp); 93 94 default: 94 95 cs_debug_mask (D_IFD,"Protocol: T=0: Invalid APDU\n"); … … 102 103 103 104 104 static int Protocol_T0_Case2E ( APDU_Cmd * cmd, APDU_Rsp ** rsp)105 static int Protocol_T0_Case2E (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 105 106 { 106 107 int ret = OK; 107 108 BYTE buffer[PROTOCOL_T0_MAX_SHORT_COMMAND]; 108 APDU_Cmd *tpdu_cmd;109 109 APDU_Rsp *tpdu_rsp; 110 110 ulong i; 111 111 112 if (APDU_Cmd_Lc (cmd) < 256) 112 unsigned long Lc = (((unsigned long)(command[5]) << 8) | command[6]); 113 if (Lc < 256) 113 114 { 114 115 /* MAP APDU onto command TPDU */ 115 buffer[0] = APDU_Cmd_Cla (cmd); 116 buffer[1] = APDU_Cmd_Ins (cmd); 117 buffer[2] = APDU_Cmd_P1 (cmd); 118 buffer[3] = APDU_Cmd_P2 (cmd); 119 buffer[4] = (BYTE) APDU_Cmd_Lc (cmd); 120 121 memcpy (buffer + 5, APDU_Cmd_Data (cmd), buffer[4]); 122 123 tpdu_cmd = APDU_Cmd_New (buffer, buffer[4] + 5); 124 125 /* Send command TPDU */ 126 ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, rsp); 127 128 /* Delete command TPDU */ 129 APDU_Cmd_Delete (tpdu_cmd); 130 } 131 else 132 { 116 memcpy(buffer, command, 4); 117 buffer[4] = (BYTE) Lc; 118 memcpy (buffer + 5, command + 7, buffer[4]); 119 return Protocol_T0_ExchangeTPDU(buffer, buffer[4] + 5, rsp); 120 } 121 133 122 /* Prepare envelope TPDU */ 134 buffer[0] = APDU_Cmd_Cla (cmd);123 buffer[0] = command[0]; 135 124 buffer[1] = 0xC2; 136 125 buffer[2] = 0x00; 137 126 buffer[3] = 0x00; 138 127 139 for (i = 0; i < APDU_Cmd_RawLen (cmd); i += buffer[4])128 for (i = 0; i < command_len; i += buffer[4]) 140 129 { 141 130 /* Create envelope command TPDU */ 142 buffer[4] = MIN (255, APDU_Cmd_RawLen (cmd) - i); 143 memcpy (buffer + 5, APDU_Cmd_Raw (cmd) + i, buffer[4]); 144 145 tpdu_cmd = APDU_Cmd_New (buffer, buffer[4] + 5); 146 147 /* Send envelope command TPDU */ 148 ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp)); 149 150 /* Delete command TPDU */ 151 APDU_Cmd_Delete (tpdu_cmd); 152 131 buffer[4] = MIN (255, command_len - i); 132 memcpy (buffer + 5, command + i, buffer[4]); 133 ret = Protocol_T0_ExchangeTPDU(buffer, buffer[4] + 5, (&tpdu_rsp)); 153 134 if (ret == OK) 154 135 { … … 157 138 { 158 139 /* This is not the last segment */ 159 if (buffer[4] + i < APDU_Cmd_RawLen (cmd))140 if (buffer[4] + i < command_len) 160 141 { 161 142 /* Delete response TPDU */ … … 180 161 } 181 162 } 182 }183 163 184 164 return ret; … … 186 166 187 167 188 static int Protocol_T0_Case3E ( APDU_Cmd * cmd, APDU_Rsp ** rsp)168 static int Protocol_T0_Case3E (unsigned char * command, APDU_Rsp ** rsp) 189 169 { 190 170 int ret; 191 171 BYTE buffer[5]; 192 APDU_Cmd *tpdu_cmd;193 172 APDU_Rsp *tpdu_rsp; 194 173 long Lm, Lx; 195 196 if (APDU_Cmd_Le (cmd) <= 256) 174 175 unsigned long Le = ((((unsigned long)(command[5]) << 8) | command[6]) == 0 ? 65536 : (((unsigned long)(command[5]) << 8) | command[6])); 176 memcpy(buffer, command, 4);//Map APDU command onto TPDU 177 178 if (Le <= 256) 197 179 { 198 /* Map APDU onto command TPDU */ 199 buffer[0] = APDU_Cmd_Cla (cmd); 200 buffer[1] = APDU_Cmd_Ins (cmd); 201 buffer[2] = APDU_Cmd_P1 (cmd); 202 buffer[3] = APDU_Cmd_P2 (cmd); 203 buffer[4] = (BYTE) APDU_Cmd_Le (cmd); 204 205 tpdu_cmd = APDU_Cmd_New (buffer, 5); 206 207 /* Send command TPDU */ 208 ret = Protocol_T0_ExchangeTPDU (tpdu_cmd, rsp); //this was Case3S !!! 209 210 /* Delete command TPDU */ 211 APDU_Cmd_Delete (tpdu_cmd); 212 } 213 else 214 { 215 /* Map APDU onto command TPDU */ 216 buffer[0] = APDU_Cmd_Cla (cmd); 217 buffer[1] = APDU_Cmd_Ins (cmd); 218 buffer[2] = APDU_Cmd_P1 (cmd); 219 buffer[3] = APDU_Cmd_P2 (cmd); 220 buffer[4] = 0x00; 221 222 tpdu_cmd = APDU_Cmd_New (buffer, 5); 223 224 /* Send command TPDU */ 225 ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp)); 226 227 /* Delete command TPDU */ 228 APDU_Cmd_Delete (tpdu_cmd); 229 230 if (ret == OK) 180 buffer[4] = (BYTE)Le; 181 return Protocol_T0_ExchangeTPDU (buffer, 5, rsp); //this was Case3S !!! 182 } 183 184 /* Map APDU onto command TPDU */ 185 buffer[4] = 0x00; 186 call (Protocol_T0_ExchangeTPDU(buffer, 5 , (&tpdu_rsp))); 187 188 if (APDU_Rsp_SW1 (tpdu_rsp) == 0x6C) {/* Le not accepted, La indicated */ 189 /* Map command APDU onto TPDU */ 190 memcpy (buffer, command, 4); 191 buffer[4] = APDU_Rsp_SW2 (tpdu_rsp); 192 193 /* Delete response TPDU */ 194 APDU_Rsp_Delete (tpdu_rsp); 195 196 return Protocol_T0_ExchangeTPDU(buffer, 5, rsp); //Reissue command 197 } 198 199 (*rsp) = tpdu_rsp; //Map response TPDU onto APDU without change , also for SW1 = 0x67 200 ret = OK; 201 if (APDU_Rsp_SW1 (tpdu_rsp) == 0x61) {/* Command processed, Lx indicated */ 202 Lx = (APDU_Rsp_SW2 (tpdu_rsp) == 0x00) ? 256 : APDU_Rsp_SW2 (tpdu_rsp); 203 Lm = Le - APDU_Rsp_DataLen (*rsp); 204 205 /* Prepare Get Response TPDU */ 206 buffer[0] = command[0]; 207 buffer[1] = 0xC0; 208 buffer[2] = 0x00; 209 buffer[3] = 0x00; 210 211 while (Lm > 0) 231 212 { 232 /* Le definitely not accepted */ 233 if (APDU_Rsp_SW1 (tpdu_rsp) == 0x67) 213 buffer[4] = (BYTE) MIN (Lm, Lx); 214 call (Protocol_T0_ExchangeTPDU(buffer, 5, (&tpdu_rsp))); 215 216 /* Append response TPDU to APDU */ 217 if (APDU_Rsp_AppendData ((*rsp), tpdu_rsp) != APDU_OK) 234 218 { 235 /* Map response APDU onto TPDU without change */ 236 (*rsp) = tpdu_rsp; 237 } 238 else if (APDU_Rsp_SW1 (tpdu_rsp) == 0x6C) /* Le not accepted, La indicated */ 239 { 240 /* Map command APDU onto TPDU */ 241 memcpy (buffer, APDU_Cmd_Raw (cmd), 4); 242 buffer[4] = APDU_Rsp_SW2 (tpdu_rsp); 243 244 tpdu_cmd = APDU_Cmd_New (buffer, 5); 245 246 /* Delete response TPDU */ 219 ret = ERROR; 247 220 APDU_Rsp_Delete (tpdu_rsp); 248 249 /* Re-issue command TPDU */ 250 ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, rsp); 251 252 /* Delete command TPDU */ 253 APDU_Cmd_Delete (tpdu_cmd); 254 } 255 else if (APDU_Rsp_SW1 (tpdu_rsp) == 0x61) /* Command processed, Lx indicated */ 256 { 257 /* Map response TPDU onto APDU */ 258 (*rsp) = tpdu_rsp; 259 260 Lx = (APDU_Rsp_SW2 (tpdu_rsp) == 0x00) ? 256 : APDU_Rsp_SW2 (tpdu_rsp); 261 Lm = APDU_Cmd_Le (cmd) - APDU_Rsp_DataLen (*rsp); 262 263 /* Prepare Get Response TPDU */ 264 buffer[0] = APDU_Cmd_Cla (cmd); 265 buffer[1] = 0xC0; 266 buffer[2] = 0x00; 267 buffer[3] = 0x00; 268 269 while (Lm > 0) 270 { 271 buffer[4] = (BYTE) MIN (Lm, Lx); 272 273 tpdu_cmd = APDU_Cmd_New (buffer, 5); 274 275 /* Issue Get Response command TPDU */ 276 ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp)); 277 278 /* Delete command TPDU */ 279 APDU_Cmd_Delete (tpdu_cmd); 280 281 if (ret == OK) 282 { 283 /* Append response TPDU to APDU */ 284 if (APDU_Rsp_AppendData ((*rsp), tpdu_rsp) != APDU_OK) 285 { 286 ret = ERROR; 287 APDU_Rsp_Delete (tpdu_rsp); 288 break; 289 } 290 291 /* Delete response TPDU */ 292 APDU_Rsp_Delete (tpdu_rsp); 293 } 294 else 295 { 296 break; 297 } 298 299 Lm = APDU_Cmd_Le (cmd) - APDU_Rsp_DataLen (*rsp); 300 }/* Lm == 0 */ 301 } 302 else /* Le accepted: card has no more than 265 bytes or does not support Get Response */ 303 { 304 /* Map response TPDU onto APDU without change */ 305 (*rsp) = tpdu_rsp; 306 } 307 } 308 } 309 221 break; 222 } 223 224 /* Delete response TPDU */ 225 APDU_Rsp_Delete (tpdu_rsp); 226 227 Lm = Le - APDU_Rsp_DataLen (*rsp); 228 }/* Lm == 0 */ 229 } 310 230 return ret; 311 231 } 312 232 313 233 314 static int Protocol_T0_Case4E ( APDU_Cmd * cmd, APDU_Rsp ** rsp)234 static int Protocol_T0_Case4E (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 315 235 { 316 236 int ret; 317 237 BYTE buffer[PROTOCOL_T0_MAX_SHORT_COMMAND]; 318 APDU_Cmd *tpdu_cmd, *gr_cmd;319 238 APDU_Rsp *tpdu_rsp; 320 239 long Le; 321 240 241 unsigned long Lc = (((unsigned long)(command[5]) << 8) | command[6]); 322 242 /* 4E1 */ 323 if (APDU_Cmd_Lc (cmd) < 256) 324 { 243 if (Lc < 256) { 325 244 /* Map APDU onto command TPDU */ 326 buffer[0] = APDU_Cmd_Cla (cmd); 327 buffer[1] = APDU_Cmd_Ins (cmd); 328 buffer[2] = APDU_Cmd_P1 (cmd); 329 buffer[3] = APDU_Cmd_P2 (cmd); 330 buffer[4] = (BYTE) APDU_Cmd_Lc (cmd); 331 memcpy (buffer + 5, APDU_Cmd_Data (cmd), buffer[4]); 332 333 tpdu_cmd = APDU_Cmd_New (buffer, buffer[4] + 5); 334 335 /* Send command TPDU */ 336 ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp)); 337 338 /* Delete command TPDU */ 339 APDU_Cmd_Delete (tpdu_cmd); 245 memcpy(buffer,command,4); 246 buffer[4] = (BYTE) Lc; 247 memcpy (buffer + 5, command, buffer[4]); 248 ret = Protocol_T0_ExchangeTPDU(buffer, buffer[4] + 5, (&tpdu_rsp)); 340 249 } 341 250 else /* 4E2 */ 342 { 343 ret = Protocol_T0_Case2E (cmd, (&tpdu_rsp)); 344 } 251 ret = Protocol_T0_Case2E (command, command_len, (&tpdu_rsp)); 345 252 346 253 /* 4E1 a) b) and c) */ 347 254 if (ret == OK) 348 255 { 256 Le = ((((unsigned long)(command[command_len - 2]) << 8) | command[command_len - 1]) == 0 ? 65536 : (((unsigned long)(command[command_len - 2]) << 8) | command[command_len - 1])); 349 257 if (APDU_Rsp_SW1 (tpdu_rsp) == 0x61) 350 258 { 351 259 /* Lm == (Le - APDU_Rsp_RawLen (tpdu_rsp)) == 0 */ 352 353 260 if (APDU_Rsp_SW2 (tpdu_rsp) != 0x00) 354 Le = MIN(APDU_Rsp_SW2 (tpdu_rsp), APDU_Cmd_Le(cmd)); 355 else 356 Le = APDU_Cmd_Le (cmd); 261 Le = MIN(APDU_Rsp_SW2 (tpdu_rsp), Le); 357 262 358 263 /* Delete response TPDU */ … … 360 265 361 266 /* Prepare extended Get Response APDU command */ 362 buffer[0] = APDU_Cmd_Cla (cmd);267 buffer[0] = command[0]; 363 268 buffer[1] = 0xC0; 364 269 buffer[2] = 0x00; … … 367 272 buffer[5] = (BYTE) (Le >> 8); /* B2 = BL-1 */ 368 273 buffer[6] = (BYTE) (Le & 0x00FF); /* B3 = BL */ 369 370 gr_cmd = APDU_Cmd_New (buffer, 7); 371 372 /* Issue Case 3E get response command */ 373 ret = Protocol_T0_Case3E (gr_cmd, rsp); 374 375 /* Delete Get Response command APDU */ 376 APDU_Cmd_Delete (gr_cmd); 274 ret = Protocol_T0_Case3E (buffer, rsp); 377 275 } 378 276 else if ((APDU_Rsp_SW1 (tpdu_rsp) & 0xF0) == 0x60) … … 387 285 388 286 /* Prepare extended Get Response APDU command */ 389 buffer[0] = APDU_Cmd_Cla (cmd);287 buffer[0] = command[0]; 390 288 buffer[1] = 0xC0; 391 289 buffer[2] = 0x00; 392 290 buffer[3] = 0x00; 393 291 buffer[4] = 0x00; /* B1 = 0x00 */ 394 buffer[5] = (BYTE) (APDU_Cmd_Le (cmd) >> 8); /* B2 = BL-1 */ 395 buffer[6] = (BYTE) (APDU_Cmd_Le (cmd) & 0x00FF); /* B3 = BL */ 396 397 gr_cmd = APDU_Cmd_New (buffer, 7); 398 399 /* Issue Case 3E get response command */ 400 ret = Protocol_T0_Case3E (gr_cmd, rsp); 401 402 /* Delete Get Response command APDU */ 403 APDU_Cmd_Delete (gr_cmd); 292 buffer[5] = (BYTE) Le >> 8; /* B2 = BL-1 */ 293 buffer[6] = (BYTE) Le & 0x00FF; /* B3 = BL */ 294 ret = Protocol_T0_Case3E (buffer, rsp); 404 295 } 405 296 } … … 408 299 409 300 410 static int Protocol_T0_ExchangeTPDU (APDU_Cmd * cmd, APDU_Rsp ** rsp) 411 { 301 static int Protocol_T0_ExchangeTPDU (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 302 { 303 APDU_Cmd c, * cmd; 304 c.command=command; 305 c.length=command_len; 306 cmd = &c; 412 307 BYTE buffer[PROTOCOL_T0_MAX_SHORT_RESPONSE]; 413 308 BYTE *data; … … 420 315 Le = APDU_Cmd_Le (cmd); 421 316 data = APDU_Cmd_Data (cmd); 422 cmd_case = APDU_Cmd_Case (c md);317 cmd_case = APDU_Cmd_Case (command, command_len); 423 318 424 319 /* Check case of command */ … … 517 412 } 518 413 519 int Protocol_T14_ExchangeTPDU (APDU_Cmd * cmd, APDU_Rsp ** rsp) 520 { 414 int Protocol_T14_ExchangeTPDU (unsigned char * cmd_raw, unsigned long command_len, APDU_Rsp ** rsp) 415 { 416 APDU_Cmd c, * cmd; 417 c.command=cmd_raw; 418 c.length=command_len; 419 cmd = &c; 420 521 421 BYTE buffer[PROTOCOL_T14_MAX_SHORT_RESPONSE]; 522 BYTE *cmd_raw;523 422 long recv, cmd_len; 524 423 int cmd_case; … … 531 430 /* Parse APDU */ 532 431 cmd_len = APDU_Cmd_Lc (cmd) + 5; 533 cmd_raw = APDU_Cmd_Raw (cmd); 534 cmd_case = APDU_Cmd_Case (cmd); 432 cmd_case = APDU_Cmd_Case (cmd_raw, command_len); 535 433 for(i=0; i<cmd_len; i++) 536 434 ixor^=cmd_raw[i]; -
branches/monitor-improvement/csctapi/protocol_t0.h
r1523 r1560 31 31 32 32 /* Send a command and return a response */ 33 extern int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp);34 extern int Protocol_T14_ExchangeTPDU (APDU_Cmd * cmd, APDU_Rsp ** rsp);33 int Protocol_T0_Command (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 34 int Protocol_T14_ExchangeTPDU (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 35 35 36 36 #endif /* _PROTOCOL_T0_ */ -
branches/monitor-improvement/csctapi/protocol_t1.c
r1517 r1560 47 47 */ 48 48 49 int Protocol_T1_Command ( APDU_Cmd * cmd, APDU_Rsp ** rsp)49 int Protocol_T1_Command (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 50 50 { 51 51 T1_Block *block; … … 54 54 int ret; 55 55 bool more; 56 if ( APDU_Cmd_Ins(cmd)== T1_BLOCK_S_IFS_REQ)56 if (command[1] == T1_BLOCK_S_IFS_REQ) 57 57 { 58 BYTE inf = APDU_Cmd_P2(cmd);58 BYTE inf = command[3]; 59 59 60 60 /* Create an IFS request S-Block */ … … 86 86 /* Calculate the number of bytes to send */ 87 87 counter = 0; 88 bytes = MIN ( APDU_Cmd_RawLen (cmd), ifsc);88 bytes = MIN (command_len, ifsc); 89 89 90 90 /* See if chaining is needed */ 91 more = ( APDU_Cmd_RawLen (cmd)> ifsc);91 more = (command_len > ifsc); 92 92 93 93 /* Increment ns */ … … 95 95 96 96 /* Create an I-Block */ 97 block = T1_Block_NewIBlock (bytes, APDU_Cmd_Raw (cmd), ns, more);97 block = T1_Block_NewIBlock (bytes, command, ns, more); 98 98 cs_debug_mask (D_IFD,"Sending block I(%d,%d)\n", ns, more); 99 99 … … 122 122 /* Calculate the number of bytes to send */ 123 123 counter += bytes; 124 bytes = MIN ( APDU_Cmd_RawLen (cmd)- counter, ifsc);124 bytes = MIN (command_len - counter, ifsc); 125 125 126 126 /* See if chaining is needed */ 127 more = ( APDU_Cmd_RawLen (cmd)- counter > ifsc);127 more = (command_len - counter > ifsc); 128 128 129 129 /* Create an I-Block */ 130 130 block = 131 T1_Block_NewIBlock (bytes, APDU_Cmd_Raw (cmd)+ counter,131 T1_Block_NewIBlock (bytes, command + counter, 132 132 ns, more); 133 133 cs_debug_mask (D_IFD,"Protocol: Sending block I(%d,%d)\n", ns, more); -
branches/monitor-improvement/csctapi/protocol_t1.h
r1517 r1560 39 39 */ 40 40 41 /* Initialise a protocol handler */42 extern int43 Protocol_T1_Init ();44 45 41 /* Send a command and return a response */ 46 extern int 47 Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp); 42 int Protocol_T1_Command (unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 48 43 49 44 #endif /* _PROTOCOL_T1_ */ -
branches/monitor-improvement/csctapi/t1_block.h
r8 r1560 66 66 */ 67 67 68 extern T1_Block * 69 T1_Block_New (BYTE * buffer, unsigned length); 68 T1_Block * T1_Block_New (BYTE * buffer, unsigned length); 70 69 71 extern T1_Block * 72 T1_Block_NewIBlock (BYTE len, BYTE * inf, BYTE ns, bool more); 70 T1_Block * T1_Block_NewIBlock (BYTE len, BYTE * inf, BYTE ns, bool more); 73 71 74 extern T1_Block * 75 T1_Block_NewRBlock (BYTE type, BYTE nr); 72 T1_Block * T1_Block_NewRBlock (BYTE type, BYTE nr); 76 73 77 extern T1_Block * 78 T1_Block_NewSBlock (BYTE type, BYTE len, BYTE * inf); 74 T1_Block * T1_Block_NewSBlock (BYTE type, BYTE len, BYTE * inf); 79 75 80 extern BYTE 81 T1_Block_GetType (T1_Block * block); 76 BYTE T1_Block_GetType (T1_Block * block); 82 77 83 extern BYTE 84 T1_Block_GetNS (T1_Block * block); 78 BYTE T1_Block_GetNS (T1_Block * block); 85 79 86 extern bool 87 T1_Block_GetMore (T1_Block * block); 80 bool T1_Block_GetMore (T1_Block * block); 88 81 89 extern BYTE 90 T1_Block_GetNR (T1_Block * block); 82 BYTE T1_Block_GetNR (T1_Block * block); 91 83 92 extern BYTE 93 T1_Block_GetLen (T1_Block * block); 84 BYTE T1_Block_GetLen (T1_Block * block); 94 85 95 extern BYTE * 96 T1_Block_GetInf (T1_Block * block); 86 BYTE * T1_Block_GetInf (T1_Block * block); 97 87 98 extern BYTE * 99 T1_Block_Raw (T1_Block * block); 88 BYTE * T1_Block_Raw (T1_Block * block); 100 89 101 extern unsigned 102 T1_Block_RawLen (T1_Block * block); 90 unsigned T1_Block_RawLen (T1_Block * block); 103 91 104 extern void 105 T1_Block_Delete (T1_Block * block); 92 void T1_Block_Delete (T1_Block * block); 106 93 107 94 #endif /* _T1_BLOCK_ */ -
branches/monitor-improvement/globals.h
r1544 r1560 371 371 time_t expirationdate; 372 372 int c35_suppresscmd08; 373 int ncd_keepalive; 373 374 int disabled; 374 375 ulong grp; … … 574 575 time_t expirationdate; 575 576 int c35_suppresscmd08; 577 int ncd_keepalive; 576 578 int disabled; 577 579 struct s_auth *next; -
branches/monitor-improvement/module-newcamd.c
r1553 r1560 1073 1073 if(rc==-9) 1074 1074 { 1075 if (c fg->ncd_keepalive)1075 if (client[cs_idx].ncd_keepalive) 1076 1076 newcamd_reply_ka(); 1077 1077 else -
branches/monitor-improvement/oscam-config.c
r1540 r1560 841 841 if (!strcmp(token, "disabled")) { account->disabled=atoi(value); return; } 842 842 if (!strcmp(token, "suppresscmd08")) { account->c35_suppresscmd08=atoi(value); return; } 843 if (!strcmp(token, "keepalive")) { account->ncd_keepalive=atoi(value); return; } 843 844 /* 844 845 * case insensitive -
branches/monitor-improvement/oscam.c
r1555 r1560 346 346 client[i].autoau = account->autoau; 347 347 client[i].expirationdate = account->expirationdate; 348 349 //set first to global value and then to specific (higher prio) 350 client[i].ncd_keepalive = cfg->ncd_keepalive; 351 client[i].ncd_keepalive = account->ncd_keepalive; 348 352 349 353 //set first to global value and then to specific (higher prio) … … 1152 1156 client[cs_idx].disabled=account->disabled; 1153 1157 client[cs_idx].c35_suppresscmd08 = account->c35_suppresscmd08; 1158 client[cs_idx].ncd_keepalive = account->ncd_keepalive; 1154 1159 client[cs_idx].grp=account->grp; 1155 1160 client[cs_idx].au=account->au; … … 1252 1257 if ((grp & ecmcache[i].grp) && 1253 1258 ecmcache[i].caid==er->caid && 1254 ecmcache[i].prid==er->prid &&1255 1259 (!memcmp(ecmcache[i].ecmd5, er->ecmd5, CS_ECMSTORESIZE))) 1256 1260 {
Note:
See TracChangeset
for help on using the changeset viewer.