Changeset 387 for branches/merlin
- Timestamp:
- 09/04/09 10:47:34 (15 years ago)
- Location:
- branches/merlin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/merlin/include/sharing/newcamd.h
r276 r387 3 3 4 4 void sharing_newcamd_module(struct s_module *); 5 int network_tcp_connection_open(char *, ushort);5 int sharing_newcamd_tcp_connection_open(char *, ushort); 6 6 7 7 #endif // __SHARING_NEWCAMD_H__ -
branches/merlin/src/sharing/camd35.c
r386 r387 410 410 int handle = 0; 411 411 412 handle = network_tcp_connection_open(reader[ridx].device, reader[ridx].r_port);412 handle = sharing_newcamd_tcp_connection_open(reader[ridx].device, reader[ridx].r_port); 413 413 if (handle < 0) 414 414 return (0); -
branches/merlin/src/sharing/newcamd.c
r316 r387 49 49 static int ncd_proto = NCD_AUTO; 50 50 51 static int network_message_send(int handle, ushort * netMsgId, uchar * buffer, int len, uchar * deskey, comm_type_t commType, ushort sid)51 static int sharing_newcamd_message_send(int handle, ushort * netMsgId, uchar * buffer, int len, uchar * deskey, comm_type_t commType, ushort sid) 52 52 { 53 53 uchar netbuf[CWS_NETMSGSIZE]; … … 91 91 } 92 92 93 static int network_message_receive(int handle, ushort * netMsgId, uchar * buffer, uchar * deskey, comm_type_t commType)93 static int sharing_newcamd_message_receive(int handle, ushort * netMsgId, uchar * buffer, uchar * deskey, comm_type_t commType) 94 94 { 95 95 int len, ncd_off, msgid; … … 158 158 return -1; 159 159 } 160 // 160 // cs_ddump(netbuf, len, "nmr: decrypted data"); 161 161 if (netMsgId) { 162 162 switch (commType) { … … 193 193 } 194 194 195 static void network_cmd_no_data_send(int handle, ushort * netMsgId, net_msg_type_t cmd, uchar * deskey, comm_type_t commType)195 static void sharing_newcamd_cmd_no_data_send(int handle, ushort * netMsgId, net_msg_type_t cmd, uchar * deskey, comm_type_t commType) 196 196 { 197 197 uchar buffer[CWS_NETMSGSIZE]; … … 199 199 buffer[0] = cmd; 200 200 buffer[1] = 0; 201 network_message_send(handle, netMsgId, buffer, 3, deskey, commType, 0);202 } 203 204 static int network_cmd_no_data_receive(int handle, ushort * netMsgId, uchar * deskey, comm_type_t commType)201 sharing_newcamd_message_send(handle, netMsgId, buffer, 3, deskey, commType, 0); 202 } 203 204 static int sharing_newcamd_cmd_no_data_receive(int handle, ushort * netMsgId, uchar * deskey, comm_type_t commType) 205 205 { 206 206 uchar buffer[CWS_NETMSGSIZE]; 207 207 208 if ( network_message_receive(handle, netMsgId, buffer, deskey, commType) != 3 + 2)208 if (sharing_newcamd_message_receive(handle, netMsgId, buffer, deskey, commType) != 3 + 2) 209 209 return -1; 210 210 return buffer[2]; 211 211 } 212 212 213 static int connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, int nsec)213 static int sharing_newcamd_connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, int nsec) 214 214 { 215 215 int flags, n, error; … … 283 283 } 284 284 285 int network_tcp_connection_open(char *hostname, ushort port)285 int sharing_newcamd_tcp_connection_open(char *hostname, ushort port) 286 286 { 287 287 int flags; 288 288 289 if ( connect_nonb(client[cs_idx].udp_fd, (struct sockaddr *) &client[cs_idx].udp_sa, sizeof (client[cs_idx].udp_sa), 5) < 0) {289 if (sharing_newcamd_connect_nonb(client[cs_idx].udp_fd, (struct sockaddr *) &client[cs_idx].udp_sa, sizeof (client[cs_idx].udp_sa), 5) < 0) { 290 290 cs_log("connect(fd=%d) failed: (errno=%d)", client[cs_idx].udp_fd, errno); 291 291 return -1; … … 298 298 } 299 299 300 static void newcamd_reply_ka()300 static void sharing_newcamd_reply_ka() 301 301 { 302 302 if (!client[cs_idx].udp_fd) { … … 305 305 } 306 306 cs_debug("send keep_alive"); 307 network_cmd_no_data_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, MSG_KEEPALIVE, client[cs_idx].ncd_skey, COMMTYPE_SERVER);308 } 309 310 static int connect_newcamd_server()307 sharing_newcamd_cmd_no_data_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, MSG_KEEPALIVE, client[cs_idx].ncd_skey, COMMTYPE_SERVER); 308 } 309 310 static int sharing_newcamd_connect_server() 311 311 { 312 312 uint i; … … 326 326 // 1. Connect 327 327 // 328 handle = network_tcp_connection_open(reader[ridx].device, reader[ridx].r_port);328 handle = sharing_newcamd_tcp_connection_open(reader[ridx].device, reader[ridx].r_port); 329 329 if (handle < 0) 330 330 return -1; … … 354 354 // reader[ridx].r_port, reader[ridx].r_usr, reader[ridx].r_pwd, 355 355 // index+strlen(passwdcrypt)+1); 356 network_message_send(handle, 0, buf, index + strlen((char *) passwdcrypt) + 1, key, COMMTYPE_CLIENT, 0x8888);356 sharing_newcamd_message_send(handle, 0, buf, index + strlen((char *) passwdcrypt) + 1, key, COMMTYPE_CLIENT, 0x8888); 357 357 358 358 // 3.1 Get login answer 359 359 // 360 login_answer = network_cmd_no_data_receive(handle, &reader[ridx].ncd_msgid, key, COMMTYPE_CLIENT);360 login_answer = sharing_newcamd_cmd_no_data_receive(handle, &reader[ridx].ncd_msgid, key, COMMTYPE_CLIENT); 361 361 if (login_answer == MSG_CLIENT_2_SERVER_LOGIN_NAK) { 362 362 cs_log("login failed for user '%s'", reader[ridx].r_usr); … … 373 373 key = des_login_key_get(reader[ridx].ncd_key, passwdcrypt, strlen((char *) passwdcrypt)); 374 374 375 network_cmd_no_data_send(handle, &reader[ridx].ncd_msgid, MSG_CARD_DATA_REQ, key, COMMTYPE_CLIENT);376 bytes_received = network_message_receive(handle, &reader[ridx].ncd_msgid, buf, key, COMMTYPE_CLIENT);375 sharing_newcamd_cmd_no_data_send(handle, &reader[ridx].ncd_msgid, MSG_CARD_DATA_REQ, key, COMMTYPE_CLIENT); 376 bytes_received = sharing_newcamd_message_receive(handle, &reader[ridx].ncd_msgid, buf, key, COMMTYPE_CLIENT); 377 377 if (bytes_received < 16 || buf[2] != MSG_CARD_DATA) { 378 378 cs_log("expected MSG_CARD_DATA (%02X), received %02X", MSG_CARD_DATA, buf[2]); … … 404 404 reader[ridx].last_g = reader[ridx].last_s = time((time_t *) 0); 405 405 406 // 406 // cs_log("last_s=%d, last_g=%d", reader[ridx].last_s, reader[ridx].last_g); 407 407 408 408 // !!! Only after connect() on client[cs_idx].udp_fd (Linux) … … 412 412 } 413 413 414 static int newcamd_connect()415 { 416 if (!reader[ridx].tcp_connected && connect_newcamd_server() < 0)414 static int sharing_newcamd_connect() 415 { 416 if (!reader[ridx].tcp_connected && sharing_newcamd_connect_server() < 0) 417 417 return 0; 418 418 if (!client[cs_idx].udp_fd) … … 423 423 424 424 425 static int newcamd_send(uchar * buf, int ml, ushort sid)426 { 427 if (! newcamd_connect())425 static int sharing_newcamd_send(uchar * buf, int ml, ushort sid) 426 { 427 if (!sharing_newcamd_connect()) 428 428 return (-1); 429 429 430 430 //cs_ddump(buf, ml, "send %d bytes to %s", ml, remote_txt()); 431 return ( network_message_send(client[cs_idx].udp_fd, &reader[ridx].ncd_msgid, buf, ml, reader[ridx].ncd_skey, COMMTYPE_CLIENT, sid));432 } 433 434 static int newcamd_recv(uchar * buf, int l)431 return (sharing_newcamd_message_send(client[cs_idx].udp_fd, &reader[ridx].ncd_msgid, buf, ml, reader[ridx].ncd_skey, COMMTYPE_CLIENT, sid)); 432 } 433 434 static int sharing_newcamd_recv(uchar * buf, int l) 435 435 { 436 436 int rc, rs; 437 437 438 438 if (is_server) { 439 rs = network_message_receive(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, buf, client[cs_idx].ncd_skey, COMMTYPE_SERVER);439 rs = sharing_newcamd_message_receive(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, buf, client[cs_idx].ncd_skey, COMMTYPE_SERVER); 440 440 } else { 441 441 if (!client[cs_idx].udp_fd) 442 442 return (-1); 443 rs = network_message_receive(client[cs_idx].udp_fd, &reader[ridx].ncd_msgid, buf, reader[ridx].ncd_skey, COMMTYPE_CLIENT);443 rs = sharing_newcamd_message_receive(client[cs_idx].udp_fd, &reader[ridx].ncd_msgid, buf, reader[ridx].ncd_skey, COMMTYPE_CLIENT); 444 444 } 445 445 if (rs < 5) { … … 462 462 463 463 static unsigned int seed; 464 static uchar fast_rnd()464 static uchar sharing_newcamd_fast_rnd() 465 465 { 466 466 unsigned int offset = 12923; … … 471 471 } 472 472 473 static FILTER mk_user_au_ftab(int au)473 static FILTER sharing_newcamd_mk_user_au_ftab(int au) 474 474 { 475 475 int i, j, found; … … 498 498 } 499 499 500 static FILTER mk_user_ftab()500 static FILTER sharing_newcamd_mk_user_ftab() 501 501 { 502 502 FILTER *psfilt = 0; … … 615 615 } 616 616 617 static void newcamd_auth_client(in_addr_t ip)617 static void sharing_newcamd_auth_client(in_addr_t ip) 618 618 { 619 619 int i, ok = 0; … … 628 628 seed = (unsigned int) time((time_t *) 0); 629 629 for (i = 0; i < 14; i++) 630 buf[i] = fast_rnd();630 buf[i] = sharing_newcamd_fast_rnd(); 631 631 632 632 // send init sequence … … 699 699 } 700 700 701 network_cmd_no_data_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, (ok) ? MSG_CLIENT_2_SERVER_LOGIN_ACK : MSG_CLIENT_2_SERVER_LOGIN_NAK, client[cs_idx].ncd_skey, COMMTYPE_SERVER);701 sharing_newcamd_cmd_no_data_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, (ok) ? MSG_CLIENT_2_SERVER_LOGIN_ACK : MSG_CLIENT_2_SERVER_LOGIN_NAK, client[cs_idx].ncd_skey, COMMTYPE_SERVER); 702 702 703 703 // we need to add a test to make sure all card reader are ready before allowing more interaction with the user. … … 727 727 } 728 728 729 client[cs_idx].ftab.filts[0] = mk_user_ftab();729 client[cs_idx].ftab.filts[0] = sharing_newcamd_mk_user_ftab(); 730 730 pufilt = &client[cs_idx].ftab.filts[0]; 731 731 … … 736 736 memcpy(&pufilt_noau, pufilt, sizeof (FILTER)); 737 737 738 client[cs_idx].ftab.filts[0] = mk_user_au_ftab(au);738 client[cs_idx].ftab.filts[0] = sharing_newcamd_mk_user_au_ftab(au); 739 739 pufilt = &client[cs_idx].ftab.filts[0]; 740 740 … … 768 768 // For security reason don't send the real hexserial (see below) 769 769 // if a non-AU-client sends an EMM-request it will be thrown away 770 // (see function " newcamd_process_emm")770 // (see function "sharing_newcamd_process_emm") 771 771 //mbuf[3] = 1; 772 772 if (au != -1) … … 825 825 mbuf[8] = 0x00; 826 826 mbuf[9] = 0x00; 827 mbuf[10] = fast_rnd();828 mbuf[11] = fast_rnd();829 mbuf[12] = fast_rnd();830 mbuf[13] = fast_rnd();827 mbuf[10] = sharing_newcamd_fast_rnd(); 828 mbuf[11] = sharing_newcamd_fast_rnd(); 829 mbuf[12] = sharing_newcamd_fast_rnd(); 830 mbuf[13] = sharing_newcamd_fast_rnd(); 831 831 } 832 832 else 833 833 { 834 mbuf[6] = fast_rnd();835 mbuf[7] = fast_rnd();836 mbuf[8] = fast_rnd();837 mbuf[9] = fast_rnd();838 mbuf[10] = fast_rnd();839 mbuf[11] = fast_rnd();840 mbuf[12] = fast_rnd();841 mbuf[13] = fast_rnd();834 mbuf[6] = sharing_newcamd_fast_rnd(); 835 mbuf[7] = sharing_newcamd_fast_rnd(); 836 mbuf[8] = sharing_newcamd_fast_rnd(); 837 mbuf[9] = sharing_newcamd_fast_rnd(); 838 mbuf[10] = sharing_newcamd_fast_rnd(); 839 mbuf[11] = sharing_newcamd_fast_rnd(); 840 mbuf[12] = sharing_newcamd_fast_rnd(); 841 mbuf[13] = sharing_newcamd_fast_rnd(); 842 842 } 843 843 */ … … 909 909 } 910 910 911 if ( network_message_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, mbuf, len, key, COMMTYPE_SERVER, 0) < 0) {911 if (sharing_newcamd_message_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, mbuf, len, key, COMMTYPE_SERVER, 0) < 0) { 912 912 if (req) { 913 913 free(req); … … 930 930 } 931 931 932 static void newcamd_send_dcw(ECM_REQUEST * er)932 static void sharing_newcamd_send_dcw(ECM_REQUEST * er) 933 933 { 934 934 int len; … … 952 952 cs_debug("ncd_send_dcw: er->cpti=%d, cl_msgid=%d, %02X", er->cpti, cl_msgid, mbuf[0]); 953 953 954 network_message_send(client[cs_idx].udp_fd, &cl_msgid, mbuf, len, client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0);955 } 956 957 static void newcamd_process_ecm(uchar * buf, int l)954 sharing_newcamd_message_send(client[cs_idx].udp_fd, &cl_msgid, mbuf, len, client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0); 955 } 956 957 static void sharing_newcamd_process_ecm(uchar * buf, int l) 958 958 { 959 959 int pi; … … 976 976 } 977 977 978 static void newcamd_process_emm(uchar * buf, int l)978 static void sharing_newcamd_process_emm(uchar * buf, int l) 979 979 { 980 980 int au, ok = 1; … … 1022 1022 buf[1] = 0x10; 1023 1023 buf[2] = 0x00; 1024 network_message_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, buf, 3, client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0);1025 } 1026 1027 static void newcamd_server()1024 sharing_newcamd_message_send(client[cs_idx].udp_fd, &client[cs_idx].ncd_msgid, buf, 3, client[cs_idx].ncd_skey, COMMTYPE_SERVER, 0); 1025 } 1026 1027 static void sharing_newcamd_server() 1028 1028 { 1029 1029 int n; … … 1038 1038 client[cs_idx].ncd_server = 1; 1039 1039 cs_debug("client connected to %d port", cfg->ncd_ptab.ports[client[cs_idx].port_idx].s_port); 1040 newcamd_auth_client(client[cs_idx].ip);1040 sharing_newcamd_auth_client(client[cs_idx].ip); 1041 1041 1042 1042 n = -9; … … 1046 1046 case 0x80: 1047 1047 case 0x81: 1048 newcamd_process_ecm(mbuf, n);1048 sharing_newcamd_process_ecm(mbuf, n); 1049 1049 break; 1050 1050 case MSG_KEEPALIVE: 1051 newcamd_reply_ka();1051 sharing_newcamd_reply_ka(); 1052 1052 break; 1053 1053 default: 1054 1054 if (mbuf[2] > 0x81 && mbuf[2] < 0x90) 1055 newcamd_process_emm(mbuf + 2, n - 2);1055 sharing_newcamd_process_emm(mbuf + 2, n - 2); 1056 1056 else 1057 1057 cs_debug("unknown command !"); … … 1059 1059 } 1060 1060 if (n == -9) { 1061 newcamd_reply_ka();1061 sharing_newcamd_reply_ka(); 1062 1062 } 1063 1063 } … … 1075 1075 */ 1076 1076 1077 static int newcamd_client_init()1077 static int sharing_newcamd_client_init() 1078 1078 { 1079 1079 static struct sockaddr_in loc_sa; … … 1136 1136 } 1137 1137 1138 static int newcamd_send_ecm(ECM_REQUEST * er, uchar * buf)1138 static int sharing_newcamd_send_ecm(ECM_REQUEST * er, uchar * buf) 1139 1139 { 1140 1140 //int rc=(-1); … … 1143 1143 1144 1144 // check server filters 1145 if (! newcamd_connect())1145 if (!sharing_newcamd_connect()) 1146 1146 return (-1); 1147 1147 … … 1151 1151 memcpy(buf, er->ecm, er->l); 1152 1152 1153 return (( newcamd_send(buf, er->l, er->srvid) < 1) ? (-1) : 0);1154 } 1155 1156 static int newcamd_recv_chk(uchar * dcw, int *rc, uchar * buf, int n)1153 return ((sharing_newcamd_send(buf, er->l, er->srvid) < 1) ? (-1) : 0); 1154 } 1155 1156 static int sharing_newcamd_recv_chk(uchar * dcw, int *rc, uchar * buf, int n) 1157 1157 { 1158 1158 ushort idx; … … 1174 1174 ph->watchdog = 1; 1175 1175 ph->s_ip = cfg->ncd_srvip; 1176 ph->s_handler = newcamd_server;1177 ph->recv = newcamd_recv;1178 ph->send_dcw = newcamd_send_dcw;1176 ph->s_handler = sharing_newcamd_server; 1177 ph->recv = sharing_newcamd_recv; 1178 ph->send_dcw = sharing_newcamd_send_dcw; 1179 1179 ph->ptab = &cfg->ncd_ptab; 1180 1180 if (ph->ptab->nports == 0) 1181 1181 ph->ptab->nports = 1; // show disabled in log 1182 1182 ph->c_multi = 1; 1183 ph->c_init = newcamd_client_init;1184 ph->c_recv_chk = newcamd_recv_chk;1185 ph->c_send_ecm = newcamd_send_ecm;1186 1187 } 1183 ph->c_init = sharing_newcamd_client_init; 1184 ph->c_recv_chk = sharing_newcamd_recv_chk; 1185 ph->c_send_ecm = sharing_newcamd_send_ecm; 1186 1187 }
Note:
See TracChangeset
for help on using the changeset viewer.