Changeset 1857
- Timestamp:
- 03/20/10 23:32:06 (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/globals.h
r1846 r1857 659 659 uchar ncd_key[16]; 660 660 int ncd_keepalive; 661 int ncd_mgclient; 661 662 struct s_ip *ncd_allowed; 662 663 PTAB cc_ptab; -
trunk/module-newcamd.c
r1847 r1857 25 25 MSG_ADMIN_COMMAND_ACK, 26 26 MSG_ADMIN_COMMAND_NAK, 27 MSG_KEEPALIVE = CWS_FIRSTCMDNO + 0x1d 27 MSG_KEEPALIVE = CWS_FIRSTCMDNO + 0x1d, 28 MSG_SERVER_2_CLIENT_OSD = 0xd1, 29 MSG_SERVER_2_CLIENT_ALLCARDS = 0xd2, 30 MSG_SERVER_2_CLIENT_ADDCARD = 0xd3, 31 MSG_SERVER_2_CLIENT_REMOVECARD = 0xd4, 32 MSG_SERVER_2_CLIENT_CHANGE_KEY = 0xd5, 33 MSG_SERVER_2_CLIENT_GET_VERSION = 0xd6, 34 MSG_SERVER_2_CLIENT_ADDSID = 0xd7, 35 MSG_CLIENT_2_SERVER_CARDDISCOVER = 0xd8 28 36 } net_msg_type_t; 29 37 … … 34 42 } comm_type_t; 35 43 44 45 typedef struct custom_data 46 { 47 unsigned short sid; 48 unsigned short caid; 49 int provid; 50 uchar x; 51 } custom_data_t; 52 36 53 #define REQ_SIZE 2 37 54 static uchar *req=0; … … 40 57 static int network_message_send(int handle, uint16 *netMsgId, uint8 *buffer, 41 58 int len, uint8 *deskey, comm_type_t commType, 42 ushort sid )59 ushort sid, custom_data_t *cd) 43 60 { 44 61 uint8 netbuf[CWS_NETMSGSIZE]; … … 72 89 netbuf[(ncd_proto==NCD_524)?7:5] = (uchar)(sid); 73 90 } 91 if ((!ncd_proto==NCD_524) && (buffer[0] >= 0xd1) && (buffer[0]<= 0xd8)) { // extended proto for mg 92 cs_debug("newcamd: extended: msg"); 93 if (cd) { 94 cs_debug("newcamd: extended: has cd"); 95 netbuf[4] = cd->sid >> 8; 96 netbuf[5] = cd->sid & 0xff; 97 netbuf[6] = cd->caid >> 8; 98 netbuf[7] = cd->caid & 0xff; 99 netbuf[8] = (cd->provid >> 16) & 0xFF; 100 netbuf[9] = (cd->provid >> 8) & 0xff; 101 netbuf[10] = cd->provid & 0xff; 102 } 103 } 74 104 netbuf[0] = (len - 2) >> 8; 75 105 netbuf[1] = (len - 2) & 0xff; … … 196 226 197 227 buffer[0] = cmd; buffer[1] = 0; 198 network_message_send(handle, netMsgId, buffer, 3, deskey, commType, 0 );228 network_message_send(handle, netMsgId, buffer, 3, deskey, commType, 0, NULL); 199 229 } 200 230 … … 270 300 // index+strlen(passwdcrypt)+1); 271 301 network_message_send(handle, 0, buf, index+strlen((char *)passwdcrypt)+1, key, 272 COMMTYPE_CLIENT, 0x8888 );302 COMMTYPE_CLIENT, 0x8888, NULL); 273 303 274 304 // 3.1 Get login answer … … 351 381 //cs_ddump(buf, ml, "send %d bytes to %s", ml, remote_txt()); 352 382 return(network_message_send(client[cs_idx].udp_fd, &reader[ridx].ncd_msgid, 353 buf, ml, reader[ridx].ncd_skey, COMMTYPE_CLIENT, sid ));383 buf, ml, reader[ridx].ncd_skey, COMMTYPE_CLIENT, sid, NULL)); 354 384 } 355 385 356 386 static int newcamd_recv(uchar *buf) 357 387 { 358 359 360 361 362 rs = network_message_receive(client[cs_idx].udp_fd, 363 &client[cs_idx].ncd_msgid, buf, 364 365 366 367 368 369 rs = network_message_receive(client[cs_idx].udp_fd, 370 &reader[ridx].ncd_msgid, buf, 371 372 373 374 if (rs < 5) rc =(-1);375 else rc =rs;376 377 378 379 380 if(rc == -1) { 381 if (rs > 0) 382 cs_log("packet to small or too large (%d bytes)", rs); 383 else 384 cs_log("Connection closed to %s", remote_txt()); 385 } 386 387 388 int rc, rs; 389 390 if (is_server) 391 { 392 rs=network_message_receive(client[cs_idx].udp_fd, 393 &client[cs_idx].ncd_msgid, buf, 394 client[cs_idx].ncd_skey, COMMTYPE_SERVER); 395 } 396 else 397 { 398 if (!client[cs_idx].udp_fd) return(-1); 399 rs=network_message_receive(client[cs_idx].udp_fd, 400 &reader[ridx].ncd_msgid,buf, 401 reader[ridx].ncd_skey, COMMTYPE_CLIENT); 402 } 403 404 if (rs<5) rc=(-1); 405 else rc=rs; 406 407 cs_ddump(buf, rs, "received %d bytes from %s", rs, remote_txt()); 408 client[cs_idx].last = time((time_t *) 0); 409 410 if( rc==-1 ) 411 { 412 if (rs > 0) 413 cs_log("packet to small (%d bytes)", rs); 414 else 415 cs_log("Connection closed to %s", remote_txt()); 416 } 417 return(rc); 388 418 } 389 419 … … 652 682 else 653 683 { 654 cs_debug("AU flag %d for user %s", au ,usr);684 cs_debug("AU flag %d for user %s", au, usr); 655 685 } 656 686 } 657 687 else 658 688 { 659 cs_log("AU disabled for user %s", usr);689 cs_log("AU disabled for user %s", usr); 660 690 } 661 691 } … … 901 931 } 902 932 903 if( network_message_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, mbuf, len, key, COMMTYPE_SERVER, 0 933 if( network_message_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, mbuf, len, key, COMMTYPE_SERVER, 0, NULL) <0 ) 904 934 { 905 935 if(req) … … 953 983 954 984 network_message_send(client[cs_idx].udp_fd, &cl_msgid, mbuf, len, 955 client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0 );985 client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0, NULL); 956 986 } 957 987 … … 1025 1055 buf[2] = 0x00; 1026 1056 network_message_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, buf, 3, 1027 client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0 );1057 client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0, NULL); 1028 1058 } 1029 1059 … … 1043 1073 cs_debug("client connected to %d port", cfg->ncd_ptab.ports[client[cs_idx].port_idx].s_port); 1044 1074 newcamd_auth_client(client[cs_idx].ip); 1075 1076 // report all cards if using extended mg proto 1077 if (cfg->ncd_mgclient) { 1078 cs_debug("newcamd: extended: report all available cards"); 1079 int r, j, k; 1080 uint8 buf[512]; 1081 custom_data_t *cd = malloc(sizeof(struct custom_data)); 1082 memset(cd, 0, sizeof(struct custom_data)); 1083 memset(buf, 0, sizeof(buf)); 1084 1085 buf[0] = MSG_SERVER_2_CLIENT_ADDCARD; 1086 1087 for (r=0; r<CS_MAXREADER; r++) { 1088 int flt = 0; 1089 if (reader[r].ftab.filts) { 1090 for (j=0; j<CS_MAXFILTERS; j++) { 1091 if (reader[r].ftab.filts[j].caid) { 1092 cd->caid = reader[r].ftab.filts[j].caid; 1093 for (k=0; k<reader[r].ftab.filts[j].nprids; k++) { 1094 cd->provid = reader[r].ftab.filts[j].prids[k]; 1095 cs_debug("newcamd: extended: report card"); 1096 1097 network_message_send(client[cs_idx].udp_fd, 1098 &client[cs_idx].ncd_msgid, buf, 3, 1099 client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0, cd); 1100 1101 flt = 1; 1102 } 1103 } 1104 } 1105 } 1106 1107 if (reader[r].caid[0] && !flt) { 1108 if ((reader[r].tcp_connected || reader[r].card_status == CARD_INSERTED)) { 1109 cd->caid = reader[r].caid[0]; 1110 for (j=0; j<reader[r].nprov; j++) { 1111 if (reader[r].card_status == CARD_INSERTED) 1112 cd->provid = (reader[r].prid[j][1]) << 16 1113 | (reader[r].prid[j][2] << 8) || reader[r].prid[j][3]; 1114 else 1115 cd->provid = (reader[r].prid[j][0]) << 16 1116 | (reader[r].prid[j][1] << 8) || reader[r].prid[j][2]; 1117 1118 cs_debug("newcamd: extended: report card"); 1119 network_message_send(client[cs_idx].udp_fd, 1120 &client[cs_idx].ncd_msgid, buf, 3, 1121 client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0, cd); 1122 } 1123 } 1124 } 1125 } 1126 free(cd); 1127 } 1045 1128 1046 1129 // check for clienttimeout, if timeout occurs try to send keepalive / wait for answer -
trunk/oscam-config.c
r1855 r1857 919 919 } else { 920 920 cfg->ncd_keepalive = atoi(value); 921 return; 922 } 923 } 924 925 if (!strcmp(token, "mgclient")) { 926 if(strlen(value) == 0) { 927 cfg->ncd_mgclient = 1; 928 return; 929 } else { 930 cfg->ncd_mgclient = atoi(value); 921 931 return; 922 932 } -
trunk/reader-conax.c
r1803 r1857 4 4 extern uchar cta_res[]; 5 5 extern ushort cta_lr; 6 7 /*8 static unsigned int Conax_ToDate(char data0, char data1)9 { // decimal: yyyymmdd10 int y,m,d;11 unsigned int l;12 13 y= 1990+ ((data1>>4) + ((data0>>5)&0x7)*10);14 m= data1&0xf;15 d= data0&0x1f;16 l= (y*100+m)*100+d;17 return l;18 }*/19 20 static char *chid_date(uchar *ptr, char *buf, int l)21 {22 if (buf)23 {24 snprintf(buf, l, "%04d/%02d/%02d",25 1990+(ptr[1]>>4)+(((ptr[0]>>5)&7)*10), ptr[1]&0xf, ptr[0]&0x1f);26 }27 return(buf);28 }29 6 30 7 #define write_cmd(cmd, data) \ … … 36 13 { \ 37 14 if (card_write(cmd, NULL)) return ERROR; \ 15 } 16 17 static char *chid_date(const uchar *ptr, char *buf, int l) 18 { 19 if (buf) 20 { 21 snprintf(buf, l, "%04d/%02d/%02d", 22 1990+(ptr[1]>>4)+(((ptr[0]>>5)&7)*10), ptr[1]&0xf, ptr[0]&0x1f); 23 } 24 return(buf); 38 25 } 39 26 … … 75 62 } 76 63 64 // Ins82 command needs to use the correct CAID reported in nano 0x28 65 ins82[17]=(reader[ridx].caid[0]>>8)&0xFF; 66 ins82[18]=(reader[ridx].caid[1])&0xFF; 67 77 68 if ((n=read_record(ins82, ins82+5))<0) return ERROR; // read serial 78 69 … … 80 71 switch(cta_res[i]) 81 72 { 82 83 73 case 0x23: 84 if ( cta_res[i+5] != 0x00) 85 { 86 memcpy(reader[ridx].hexserial, &cta_res[i+3], 6); 87 }else{ 88 89 memcpy(reader[ridx].sa[j], &cta_res[i+5], 4); 90 j++; 91 } 92 break; 93 } 74 if ( cta_res[i+5] != 0x00) 75 { 76 memcpy(reader[ridx].hexserial, &cta_res[i+3], 6); 77 }else{ 78 memcpy(reader[ridx].sa[j], &cta_res[i+5], 4); 79 j++; 80 } 81 break; 82 } 94 83 95 84 /* we have one provider, 0x0000 */ … … 103 92 for (j=0; j<reader[ridx].nprov; j++) 104 93 { 105 cs_ri_log("Provider:%d Provider-Id:%06X", j+1, b2ll(4, reader[ridx].prid[j])); 106 cs_ri_log("Provider:%d SharedAddress:%08X", j+1, b2ll(4, reader[ridx].sa[j])); 94 cs_ri_log("Provider:%d Provider-Id:%06X", j+1, b2ll(4, reader[ridx].prid[j])); 95 cs_ri_log("Provider:%d SharedAddress:%08X", j+1, b2ll(4, reader[ridx].sa[j])); 107 96 } 108 97 … … 113 102 static int conax_send_pin(void) 114 103 { 115 unsigned char insPIN[] = { 0xDD,0xC8,0x00,0x00,0x07,0x1D,0x05,0x01,0x00,0x00,0x00,0x00 }; // letzte vier ist derPin-Code104 unsigned char insPIN[] = { 0xDD,0xC8,0x00,0x00,0x07,0x1D,0x05,0x01,0x00,0x00,0x00,0x00 }; //Last four are the Pin-Code 116 105 memcpy(insPIN+8,reader[ridx].pincode,4); 117 106 118 107 write_cmd(insPIN, insPIN+5); 119 cs_ri_log("sending pincode to card"); 120 108 cs_ri_log("sending pincode to card"); 109 121 110 return OK; 122 111 } … … 143 132 write_cmd(insA2, buf); // write Header + ECM 144 133 145 while ((cta_res[cta_lr-2]==0x98) && // Antwort 146 134 while ((cta_res[cta_lr-2]==0x98) && // Antwort 135 ((insCA[4]=cta_res[cta_lr-1])>0) && (insCA[4]!=0xFF)) 147 136 { 148 137 read_cmd(insCA, NULL); //Codeword auslesen 149 138 150 139 if ((cta_res[cta_lr-2]==0x98) || 151 140 ((cta_res[cta_lr-2]==0x90) )) 152 141 { 153 142 for(i=0; i<cta_lr-2; i+=cta_res[i+1]+2) 154 155 switch (cta_res[i]) 156 { 157 case 0x25: 158 if ( (cta_res[i+1]>=0xD) && !((n=cta_res[i+4])&0xFE) ) 159 { 160 rc|=(1<<n); 161 memcpy(er->cw+(n<<3), cta_res+i+7, 8); 162 } 163 break; 164 case 0x31: 165 if ( (cta_res[i+1]==0x02 && cta_res[i+2]==0x00 && cta_res[i+3]==0x00) || \ 166 (cta_res[i+1]==0x02 && cta_res[i+2]==0x40 && cta_res[i+3]==0x00) ) 167 break; 168 else if (strcmp(reader[ridx].pincode, "none")) 169 { 170 conax_send_pin(); 171 write_cmd(insA2, buf); // write Header + ECM 172 while ((cta_res[cta_lr-2]==0x98) && // Antwort 173 ((insCA[4]=cta_res[cta_lr-1])>0) && (insCA[4]!=0xFF)) 174 { 175 read_cmd(insCA, NULL); //Codeword auslesen 176 if ((cta_res[cta_lr-2]==0x98) || 177 ((cta_res[cta_lr-2]==0x90) && (!cta_res[cta_lr-1]))) 178 { 179 180 for(j=0;j<cta_lr-2; j+=cta_res[j+1]+2) 181 if ((cta_res[j]==0x25) && // access: is cw 182 (cta_res[j+1]>=0xD) && // 0xD: 5 header + 8 cw 183 !((n=cta_res[j+4])&0xFE)) // cw idx must be 0 or 1 184 { 185 rc|=(1<<n); 186 memcpy(er->cw+(n<<3), cta_res+j+7, 8); 187 } 188 } 189 } 190 191 } 192 break; 193 194 } 195 196 197 198 } 199 } 200 if (rc==3) 201 return OK; 202 else 203 return ERROR; 143 { 144 switch (cta_res[i]) 145 { 146 case 0x25: 147 if ( (cta_res[i+1]>=0xD) && !((n=cta_res[i+4])&0xFE) ) 148 { 149 rc|=(1<<n); 150 memcpy(er->cw+(n<<3), cta_res+i+7, 8); 151 } 152 break; 153 case 0x31: 154 if ( (cta_res[i+1]==0x02 && cta_res[i+2]==0x00 && cta_res[i+3]==0x00) || \ 155 (cta_res[i+1]==0x02 && cta_res[i+2]==0x40 && cta_res[i+3]==0x00) ) 156 break; 157 else if (strcmp(reader[ridx].pincode, "none")) 158 { 159 conax_send_pin(); 160 write_cmd(insA2, buf); // write Header + ECM 161 162 while ((cta_res[cta_lr-2]==0x98) && // Antwort 163 ((insCA[4]=cta_res[cta_lr-1])>0) && (insCA[4]!=0xFF)) 164 { 165 read_cmd(insCA, NULL); //Codeword auslesen 166 167 if ((cta_res[cta_lr-2]==0x98) || 168 ((cta_res[cta_lr-2]==0x90) && (!cta_res[cta_lr-1]))) 169 { 170 for(j=0;j<cta_lr-2; j+=cta_res[j+1]+2) 171 if ((cta_res[j]==0x25) && // access: is cw 172 (cta_res[j+1]>=0xD) && // 0xD: 5 header + 8 cw 173 !((n=cta_res[j+4])&0xFE)) // cw idx must be 0 or 1 174 { 175 rc|=(1<<n); 176 memcpy(er->cw+(n<<3), cta_res+j+7, 8); 177 } 178 } 179 } 180 } 181 break; 182 } 183 } 184 } 185 } 186 if (rc==3) 187 return OK; 188 else 189 return ERROR; 204 190 } 205 191 … … 238 224 } 239 225 } 240 241 226 242 227 int conax_do_emm(EMM_PACKET *ep) 243 228 { 244 /* by KrazyIvan245 * EMM with lenght 83 and 85, is the same as ECM and PPV.246 * EMM with lenght AA and A8 (keyupdate).247 * 82 70 82 00 00 00 00 2c 86 52 70 79 64 10 16 bc248 * */249 250 251 229 unsigned char insEMM[] = { 0xDD,0x84,0x00,0x00,0x00 }; 252 230 unsigned char buf[255]; 253 231 int rc=0; 254 232 255 int l=ep->emm[2];233 const int l = ep->emm[2]; 256 234 257 235 insEMM[4]=l+5; … … 264 242 265 243 if (rc) 266 267 268 244 return OK; 245 else 246 return ERROR; 269 247 } 270 248
Note:
See TracChangeset
for help on using the changeset viewer.