Changeset 11478 for trunk/reader-tongfang.c
- Timestamp:
- 01/18/19 23:36:20 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/reader-tongfang.c
r11069 r11478 3 3 #include "reader-common.h" 4 4 5 static int32_t cw_is_valid(unsigned char *cw) //returns 1 if cw_is_valid, returns 0 if cw is all zeros 5 // returns 1 if cw_is_valid, returns 0 if cw is all zeros 6 static int32_t cw_is_valid(uint8_t *cw) 6 7 { 7 8 int32_t i; … … 9 10 for(i = 0; i < 8; i++) 10 11 { 11 if(cw[i] != 0) //test if cw = 0012 if(cw[i] != 0) // test if cw = 00 12 13 { 13 14 return OK; … … 17 18 } 18 19 19 static int32_t tongfang_read_data(struct s_reader *reader, u char size, uchar*cta_res, uint16_t *status)20 { 21 u char read_data_cmd[] = {0x00, 0xc0, 0x00, 0x00, 0xff};20 static int32_t tongfang_read_data(struct s_reader *reader, uint8_t size, uint8_t *cta_res, uint16_t *status) 21 { 22 uint8_t read_data_cmd[] = { 0x00, 0xc0, 0x00, 0x00, 0xff }; 22 23 uint16_t cta_lr; 23 24 … … 32 33 static int32_t tongfang_card_init(struct s_reader *reader, ATR *newatr) 33 34 { 34 static const u char begin_cmd[] = {0x00, 0xa4, 0x04, 0x00, 0x05, 0xf9, 0x5a, 0x54, 0x00, 0x06};35 static const u char get_serial_cmd[] = {0x80, 0x46, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x04};36 u char pairing_cmd[] = {0x80, 0x4c, 0x00, 0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF};37 38 u chardata[257];35 static const uint8_t begin_cmd[] = { 0x00, 0xa4, 0x04, 0x00, 0x05, 0xf9, 0x5a, 0x54, 0x00, 0x06 }; 36 static const uint8_t get_serial_cmd[] = { 0x80, 0x46, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x04 }; 37 uint8_t pairing_cmd[] = { 0x80, 0x4c, 0x00, 0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF }; 38 39 uint8_t data[257]; 39 40 int32_t data_len = 0; 40 41 uint16_t status = 0; 41 u char boxID[] = {0xFF, 0xFF, 0xFF, 0xFF};42 uint8_t boxID[] = { 0xFF, 0xFF, 0xFF, 0xFF }; 42 43 int32_t i; 43 44 … … 45 46 get_hist; 46 47 47 if((hist_size < 4) || (memcmp(hist, "NTIC", 4))) { return ERROR; } 48 if((hist_size < 4) || (memcmp(hist, "NTIC", 4))) 49 { 50 return ERROR; 51 } 48 52 49 53 reader->caid = 0x4A02; … … 55 59 56 60 write_cmd(begin_cmd, begin_cmd + 5); 57 if((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00)) { return ERROR; } 61 if((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00)) 62 { 63 return ERROR; 64 } 58 65 59 66 write_cmd(get_serial_cmd, get_serial_cmd + 5); 60 if((cta_res[cta_lr - 2] & 0xf0) != 0x60) { return ERROR; } 67 if((cta_res[cta_lr - 2] & 0xf0) != 0x60) 68 { 69 return ERROR; 70 } 71 61 72 data_len = tongfang_read_data(reader, cta_res[cta_lr - 1], data, &status); 62 63 if(data_len < 0) { return ERROR; } 64 if(status != 0x9000) { return ERROR; } 73 if(data_len < 0) 74 { 75 return ERROR; 76 } 77 78 if(status != 0x9000) 79 { 80 return ERROR; 81 } 65 82 66 83 memset(reader->hexserial, 0, 8); … … 98 115 static int32_t tongfang_do_ecm(struct s_reader *reader, const ECM_REQUEST *er, struct s_ecm_answer *ea) 99 116 { 100 u charecm_cmd[200];117 uint8_t ecm_cmd[200]; 101 118 int32_t ecm_len; 102 const u char*pbuf = er->ecm;119 const uint8_t *pbuf = er->ecm; 103 120 char *tmp; 104 121 int32_t i = 0; … … 106 123 def_resp; 107 124 int32_t read_size = 0; 108 u chardata[100];125 uint8_t data[100]; 109 126 int32_t data_len = 0; 110 127 uint16_t status = 0; 111 128 112 if((ecm_len = check_sct_len(er->ecm, 3)) < 0) { return ERROR; } 129 if((ecm_len = check_sct_len(er->ecm, 3)) < 0) 130 { 131 return ERROR; 132 } 133 113 134 if(cs_malloc(&tmp, ecm_len * 3 + 1)) 114 135 { … … 128 149 129 150 memcpy(ecm_cmd, pbuf, write_len); 130 131 151 write_cmd(ecm_cmd, ecm_cmd + 5); 132 152 … … 149 169 data_len = tongfang_read_data(reader, read_size, data, &status); 150 170 151 if(data_len < 23) { return ERROR; } 171 if(data_len < 23) 172 { 173 return ERROR; 174 } 152 175 153 176 if(!(er->ecm[0] & 0x01)) … … 162 185 163 186 // All zeroes is no valid CW, can be a result of wrong boxid 164 if(!cw_is_valid(ea->cw) || !cw_is_valid(ea->cw + 8)) { return ERROR; } 187 if(!cw_is_valid(ea->cw) || !cw_is_valid(ea->cw + 8)) 188 { 189 return ERROR; 190 } 165 191 166 192 return OK; … … 175 201 static int32_t tongfang_do_emm(struct s_reader *reader, EMM_PACKET *ep) 176 202 { 177 u charemm_cmd[200];203 uint8_t emm_cmd[200]; 178 204 def_resp; 179 205 int32_t write_len; 180 206 181 if(SCT_LEN(ep->emm) < 8) { return ERROR; } 207 if(SCT_LEN(ep->emm) < 8) 208 { 209 return ERROR; 210 } 182 211 183 212 write_len = ep->emm[15] + 5; … … 191 220 static int32_t tongfang_card_info(struct s_reader *reader) 192 221 { 193 static const u charget_provider_cmd[] = {0x80, 0x44, 0x00, 0x00, 0x08};222 static const uint8_t get_provider_cmd[] = {0x80, 0x44, 0x00, 0x00, 0x08}; 194 223 def_resp; 195 224 int32_t i; 196 225 197 226 write_cmd(get_provider_cmd, NULL); 198 if((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00)) { return ERROR; } 227 if((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00)) 228 { 229 return ERROR; 230 } 199 231 200 232 for(i = 0; i < 4; i++)
Note:
See TracChangeset
for help on using the changeset viewer.