Changeset 1217


Ignore:
Timestamp:
01/14/10 09:27:58 (11 years ago)
Author:
cogsi
Message:

speedfrog's cccam-reader updates (thanks!)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/module-cccam.c

    r1137 r1217  
    742742{
    743743  int n;
     744  uchar *cbuf;
    744745  struct cc_data *cc = reader[ridx].cc;
    745   uchar *cbuf = malloc(l);
     746
     747  if (buf==NULL) return -1;
     748  cbuf = malloc(l);
     749  if (cbuf==NULL) return -1;
    746750
    747751  memcpy(cbuf, buf, l);   // make a copy of buf
     
    756760  }
    757761
    758   cs_ddump(buf, n, "cccam: received %d bytes from %s", n, remote_txt());
     762  cs_ddump(cbuf, n, "cccam: received %d bytes from %s", n, remote_txt());
    759763  client[cs_idx].last = time((time_t *) 0);
    760764
    761   if (n < 4) {
     765  if (n == 0) {
     766    cs_log("cccam: Connection closed to %s", remote_txt());
     767    n = -1;
     768  } else if (n < 4) {
    762769    cs_log("cccam: packet to small (%d bytes)", n);
    763770    n = -1;
    764   } else if (n == 0) {
    765     cs_log("cccam: Connection closed to %s", remote_txt());
    766     n = -1;
    767   }
    768 
    769   cc_parse_msg(cbuf, n);
    770 
    771   memcpy(buf, cbuf, l);
     771  } else {
     772    // parse it and write it back, if we have received something of value
     773    cc_parse_msg(cbuf, n);
     774    memcpy(buf, cbuf, l);
     775  }
    772776
    773777  X_FREE(cbuf);
     
    784788  uint8 hash[SHA_DIGEST_LENGTH];
    785789  uint8 buf[CC_MAXMSGSIZE];
     790  char pwd[64];
    786791  struct cc_data *cc;
     792
     793  if (reader[ridx].cc) X_FREE(reader[ridx].cc);
    787794
    788795  // init internals data struct
    789796  cc = malloc(sizeof(struct cc_data));
     797  if (cc==NULL) {
     798    cs_log("cccam: cannot allocate memory");
     799    return -1;
     800  }
    790801  reader[ridx].cc = cc;
    791802  bzero(reader[ridx].cc, sizeof(struct cc_data));
     
    827838
    828839  bzero(buf, sizeof(buf));
    829 
    830840  memcpy(buf, reader[ridx].r_usr, strlen(reader[ridx].r_usr));
    831841  cs_ddump(buf, 20, "cccam: username '%s':", buf);
     
    833843
    834844  bzero(buf, sizeof(buf));
     845  bzero(pwd, sizeof(pwd));
    835846
    836847  cs_debug("cccam: 'CCcam' xor");
    837848  memcpy(buf, "CCcam", 5);
    838   cc_crypt(&cc->block[ENCRYPT], (uint8 *)reader[ridx].r_pwd, strlen(reader[ridx].r_pwd), ENCRYPT);     // modify encryption state w/ pwd
     849  strncpy(pwd, reader[ridx].r_pwd, 63);
     850  cc_crypt(&cc->block[ENCRYPT], (uint8 *)pwd, strlen(pwd), ENCRYPT);
    839851  cc_cmd_send(buf, 6, MSG_NO_HEADER); // send 'CCcam' xor w/ pwd
    840852
     
    925937    bcopy((char *)server->h_addr, (char *)&client[cs_idx].udp_sa.sin_addr.s_addr, server->h_length);
    926938
    927     reader[ridx].tcp_rto = 60 * 60 * 10;  // timeout to 10 hours
     939    if (reader[ridx].tcp_rto <= 0) reader[ridx].tcp_rto = 60 * 60 * 10;  // timeout to 10 hours
     940    cs_debug("cccam: reconnect timeout set to: %d", reader[ridx].tcp_rto);
    928941    if (!reader[ridx].cc_maxhop) reader[ridx].cc_maxhop = 10; // default maxhop to 10 if not configured
    929942
  • trunk/oscam-reader.c

    r1137 r1217  
    189189    }
    190190
     191    reader[ridx].ncd_msgid=0;
     192    reader[ridx].last_s=reader[ridx].last_g=0;
     193
    191194    if (reader[ridx].ph.c_init())
    192195    {
     
    196199
    197200    cs_resolve();
    198     reader[ridx].ncd_msgid=0;
    199     reader[ridx].last_s=reader[ridx].last_g=0;
    200201//  cs_log("last_s=%d, last_g=%d", reader[ridx].last_s, reader[ridx].last_g);
    201202  }
Note: See TracChangeset for help on using the changeset viewer.