formatting code using astyle

Origin commit data
------------------
Branch: master
Commit: bc17c13de4
Author: vanhofen <vanhofen@gmx.de>
Date: 2021-05-17 (Mon, 17 May 2021)

Origin message was:
------------------
- formatting code using astyle

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2021-05-17 23:47:39 +02:00
parent 7335985023
commit f54b0e7bec
161 changed files with 13025 additions and 11357 deletions

View File

@@ -1,6 +1,7 @@
/* DH */
unsigned char dh_p[256] = { /* prime */
unsigned char dh_p[256] = /* prime */
{
0xd6, 0x27, 0x14, 0x7a, 0x7c, 0x0c, 0x26, 0x63, 0x9d, 0x82, 0xeb, 0x1f, 0x4a, 0x18, 0xff, 0x6c,
0x34, 0xad, 0xea, 0xa6, 0xc0, 0x23, 0xe6, 0x65, 0xfc, 0x8e, 0x32, 0xc3, 0x33, 0xf4, 0x91, 0xa7,
0xcc, 0x88, 0x58, 0xd7, 0xf3, 0xb3, 0x17, 0x5e, 0xb0, 0xa8, 0xeb, 0x5c, 0xd4, 0xd8, 0x3a, 0xae,
@@ -19,7 +20,8 @@ unsigned char dh_p[256] = { /* prime */
0x15, 0xb8, 0x3c, 0x8d, 0x80, 0x92, 0x1c, 0xa1, 0x03, 0xd0, 0x83, 0x2f, 0x5f, 0xe3, 0x07, 0x69
};
unsigned char dh_g[256] = { /* generator */
unsigned char dh_g[256] = /* generator */
{
0x95, 0x7d, 0xd1, 0x49, 0x68, 0xc1, 0xa5, 0xf1, 0x48, 0xe6, 0x50, 0x4f, 0xa1, 0x10, 0x72, 0xc4,
0xef, 0x12, 0xec, 0x2d, 0x94, 0xbe, 0xc7, 0x20, 0x2c, 0x94, 0xf9, 0x68, 0x67, 0x0e, 0x22, 0x17,
0xb5, 0x5c, 0x0b, 0xca, 0xac, 0x9f, 0x25, 0x9c, 0xd2, 0xa6, 0x1a, 0x20, 0x10, 0x16, 0x6a, 0x42,

View File

@@ -11,7 +11,8 @@ int aes_xcbc_mac_init(struct aes_xcbc_mac_ctx *ctx, const uint8_t *key)
AES_set_encrypt_key(key, 128, &aes_key);
for (y = 0; y < 3; y++) {
for (y = 0; y < 3; y++)
{
for (x = 0; x < 16; x++)
ctx->K[y][x] = y + 1;
AES_ecb_encrypt(ctx->K[y], ctx->K[y], &aes_key, 1);
@@ -28,8 +29,10 @@ int aes_xcbc_mac_init(struct aes_xcbc_mac_ctx *ctx, const uint8_t *key)
int aes_xcbc_mac_process(struct aes_xcbc_mac_ctx *ctx, const uint8_t *in, unsigned int len)
{
while (len) {
if (ctx->buflen == 16) {
while (len)
{
if (ctx->buflen == 16)
{
AES_ecb_encrypt(ctx->IV, ctx->IV, &ctx->key, 1);
ctx->buflen = 0;
}
@@ -44,11 +47,14 @@ int aes_xcbc_mac_done(struct aes_xcbc_mac_ctx *ctx, uint8_t *out)
{
int i;
if (ctx->buflen == 16) {
if (ctx->buflen == 16)
{
/* K2 */
for (i = 0; i < 16; i++)
ctx->IV[i] ^= ctx->K[1][i];
} else {
}
else
{
ctx->IV[ctx->buflen] ^= 0x80;
/* K3 */
for (i = 0; i < 16; i++)

View File

@@ -1,7 +1,8 @@
#ifndef __AES_XCBC_H_
#define __AES_XCBC_H_
struct aes_xcbc_mac_ctx {
struct aes_xcbc_mac_ctx
{
uint8_t K[3][16];
uint8_t IV[16];
AES_KEY key;

View File

@@ -13,13 +13,14 @@
#include <config.h>
static const char * FILENAME = "[descrambler]";
static const char *FILENAME = "[descrambler]";
static int desc_fd = -1;
static int desc_user_count = 0;
#ifndef CA_SET_PID
typedef struct ca_pid {
typedef struct ca_pid
{
unsigned int pid;
int index; /* -1 == disable*/
} ca_pid_t;
@@ -28,17 +29,20 @@ typedef struct ca_pid {
#endif
#ifndef CA_SET_DESCR_DATA
enum ca_descr_data_type {
enum ca_descr_data_type
{
CA_DATA_IV,
CA_DATA_KEY,
};
enum ca_descr_parity {
enum ca_descr_parity
{
CA_PARITY_EVEN,
CA_PARITY_ODD,
};
struct ca_descr_data {
struct ca_descr_data
{
unsigned int index;
enum ca_descr_parity parity;
enum ca_descr_data_type data_type;
@@ -173,8 +177,9 @@ bool descrambler_open(void)
{
if (desc_fd > 0)
return true;
desc_fd = open(descrambler_filename, O_RDWR | O_NONBLOCK );
if (desc_fd <= 0) {
desc_fd = open(descrambler_filename, O_RDWR | O_NONBLOCK);
if (desc_fd <= 0)
{
printf("cannot open %s\n", descrambler_filename);
return false;
}

View File

@@ -20,8 +20,9 @@ static int pkcs_1_mgf1(const uint8_t *seed, unsigned long seedlen, uint8_t *mask
hLen = 20; /* SHA1 */
/* allocate memory */
buf = (uint8_t*)malloc(hLen);
if (buf == NULL) {
buf = (uint8_t *)malloc(hLen);
if (buf == NULL)
{
printf("error mem\n");
return -1;
}
@@ -29,7 +30,8 @@ static int pkcs_1_mgf1(const uint8_t *seed, unsigned long seedlen, uint8_t *mask
/* start counter */
counter = 0;
while (masklen > 0) {
while (masklen > 0)
{
/* handle counter */
BYTE32(buf, counter);
++counter;
@@ -50,8 +52,8 @@ static int pkcs_1_mgf1(const uint8_t *seed, unsigned long seedlen, uint8_t *mask
}
static int pkcs_1_pss_encode(const uint8_t *msghash, unsigned int msghashlen,
unsigned long saltlen, unsigned long modulus_bitlen,
uint8_t *out, unsigned int outlen)
unsigned long saltlen, unsigned long modulus_bitlen,
uint8_t *out, unsigned int outlen)
{
unsigned char *DB, *mask, *salt, *hash;
unsigned long x, y, hLen, modulus_len;
@@ -63,22 +65,25 @@ static int pkcs_1_pss_encode(const uint8_t *msghash, unsigned int msghashlen,
modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
/* allocate ram for DB/mask/salt/hash of size modulus_len */
DB = (unsigned char*)malloc(modulus_len);
mask = (unsigned char*)malloc(modulus_len);
salt = (unsigned char*)malloc(modulus_len);
hash = (unsigned char*)malloc(modulus_len);
DB = (unsigned char *)malloc(modulus_len);
mask = (unsigned char *)malloc(modulus_len);
salt = (unsigned char *)malloc(modulus_len);
hash = (unsigned char *)malloc(modulus_len);
hashbuflen = 8 + msghashlen + saltlen;
hashbuf = (unsigned char*)malloc(hashbuflen);
hashbuf = (unsigned char *)malloc(hashbuflen);
if (!(DB && mask && salt && hash && hashbuf)) {
if (!(DB && mask && salt && hash && hashbuf))
{
printf("out of memory\n");
goto LBL_ERR;
}
/* generate random salt */
if (saltlen > 0) {
if (get_random(salt, saltlen) != (long)saltlen) {
if (saltlen > 0)
{
if (get_random(salt, saltlen) != (long)saltlen)
{
printf("rnd failed\n");
goto LBL_ERR;
}
@@ -107,7 +112,8 @@ static int pkcs_1_pss_encode(const uint8_t *msghash, unsigned int msghashlen,
DB[y] ^= mask[y];
/* output is DB || hash || 0xBC */
if (outlen < modulus_len) {
if (outlen < modulus_len)
{
err = -1;
printf("error overflow\n");
goto LBL_ERR;
@@ -168,7 +174,8 @@ int dh_gen_exp(uint8_t *dest, int dest_len, uint8_t *dh_g, int dh_g_len, uint8_t
DH_get0_key(dh, &pub_key, &priv_key);
len = BN_num_bytes(priv_key);
#endif
if (len > dest_len) {
if (len > dest_len)
{
printf("len > dest_len\n");
return -1;
}
@@ -206,7 +213,8 @@ int dh_mod_exp(uint8_t *dest, int dest_len, uint8_t *base, int base_len, uint8_t
len = BN_num_bytes(bn_dest);
if (len > dest_len) {
if (len > dest_len)
{
printf("len > dest_len\n");
return -1;
}
@@ -251,7 +259,8 @@ int dh_dhph_signature(uint8_t *out, uint8_t *nonce, uint8_t *dhph, RSA *r)
SHA1(dest, 0x12e, hash);
if (pkcs_1_pss_encode(hash, 20, 20, 0x800, dbuf, sizeof(dbuf))) {
if (pkcs_1_pss_encode(hash, 20, 20, 0x800, dbuf, sizeof(dbuf)))
{
printf("pss encode failed\n");
return -1;
}

View File

@@ -6,7 +6,7 @@
#include "dvbci_appmgr.h"
/* prevent possibly segfaults: read at end of this file */
/* prevent possibly segfaults: read at end of this file */
#define yy_debug 0
eDVBCIApplicationManagerSession::eDVBCIApplicationManagerSession(eDVBCISlot *tslot)
@@ -26,7 +26,7 @@ int eDVBCIApplicationManagerSession::receivedAPDU(const unsigned char *tag, cons
{
printf("[CI AM] SESSION(%d)/APP %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]);
for (int i = 0; i < len; i++)
printf("%02x ", ((const unsigned char*)data)[i]);
printf("%02x ", ((const unsigned char *)data)[i]);
printf("\n");
if ((tag[0] == 0x9f) && (tag[1] == 0x80))
@@ -38,21 +38,21 @@ int eDVBCIApplicationManagerSession::receivedAPDU(const unsigned char *tag, cons
int dl;
printf("[CI AM] application info:\n");
printf("[CI AM] len: %d\n", len);
printf("[CI AM] application_type: %d\n", ((unsigned char*)data)[0]);
printf("[CI AM] application_manufacturer: %02x %02x\n", ((unsigned char*)data)[2], ((unsigned char*)data)[1]);
printf("[CI AM] manufacturer_code: %02x %02x\n", ((unsigned char*)data)[4], ((unsigned char*)data)[3]);
printf("[CI AM] application_type: %d\n", ((unsigned char *)data)[0]);
printf("[CI AM] application_manufacturer: %02x %02x\n", ((unsigned char *)data)[2], ((unsigned char *)data)[1]);
printf("[CI AM] manufacturer_code: %02x %02x\n", ((unsigned char *)data)[4], ((unsigned char *)data)[3]);
printf(" menu string: ");
dl = ((unsigned char*)data)[5];
dl = ((unsigned char *)data)[5];
if ((dl + 6) > len)
{
printf("[CI AM] warning, invalid length (%d vs %d)\n", dl + 6, len);
dl = len - 6;
}
char str[dl + 1];
memcpy(str, ((char*)data) + 6, dl);
memcpy(str, ((char *)data) + 6, dl);
str[dl] = '\0';
for (int i = 0; i < dl; ++i)
printf("%c", ((unsigned char*)data)[i + 6]);
printf("%c", ((unsigned char *)data)[i + 6]);
printf("\n");
strcpy(slot->name, str);
@@ -111,16 +111,16 @@ int eDVBCIApplicationManagerSession::startMMI()
bool eDVBCIApplicationManagerSession::readBlist()
{
int rc, i;
char cSid[4] = {0,0,0,0};
char cSid[4] = {0, 0, 0, 0};
u16 Sid;
FILE *fd;
char blacklist_file[32];
sprintf(blacklist_file,"/etc/blacklist_slot_%d",slot->slot);
sprintf(blacklist_file, "/etc/blacklist_slot_%d", slot->slot);
if (access(blacklist_file, F_OK) != 0)
return false;
fd = fopen(blacklist_file,"r");
fd = fopen(blacklist_file, "r");
if (!fd)
return false;
else
@@ -139,7 +139,8 @@ bool eDVBCIApplicationManagerSession::readBlist()
Sid = (u16)strtol(cSid, NULL, 16);
slot->bsids.push_back(Sid);
}
} while (rc != EOF);
}
while (rc != EOF);
fin:
fclose(fd);
}
@@ -153,7 +154,7 @@ int eDVBCIApplicationManagerSession::checkBlist()
{
if (readBlist())
{
/* out commented: causes sometimes segfault when reboot....don't know why :( */
/* out commented: causes sometimes segfault when reboot....don't know why :( */
#if yy_debug
printf("Blacked sids: %d > ", slot->bsids.size());
for (unsigned int i = 0; i < slot->bsids.size(); i++)

View File

@@ -5,22 +5,23 @@
class eDVBCIApplicationManagerSession: public eDVBCISession
{
enum {
stateFinal=statePrivate
};
enum
{
stateFinal = statePrivate
};
eDVBCISlot *slot;
eDVBCISlot *slot;
int wantmenu;
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
bool readBlist();
int checkBlist();
public:
eDVBCIApplicationManagerSession(eDVBCISlot *tslot);
~eDVBCIApplicationManagerSession();
int enterMenu();
int startMMI();
int wantmenu;
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
bool readBlist();
int checkBlist();
public:
eDVBCIApplicationManagerSession(eDVBCISlot *tslot);
~eDVBCIApplicationManagerSession();
int enterMenu();
int startMMI();
};
#endif

View File

@@ -20,7 +20,7 @@ int eDVBCICAManagerSession::receivedAPDU(const unsigned char *tag, const void *d
{
printf("[CI CA] SESSION(%d)/CA %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]);
for (int i = 0; i < len; i++)
printf("%02x ", ((const unsigned char*)data)[i]);
printf("%02x ", ((const unsigned char *)data)[i]);
printf("\n");
if ((tag[0] == 0x9f) && (tag[1] == 0x80))
@@ -32,8 +32,8 @@ int eDVBCICAManagerSession::receivedAPDU(const unsigned char *tag, const void *d
printf("[CI CA] ca info:\n");
for (int i = 0; i < len; i += 2)
{
printf("%04x ", (((const unsigned char*)data)[i] << 8) | (((const unsigned char*)data)[i + 1]));
caids.push_back((((const unsigned char*)data)[i] << 8) | (((const unsigned char*)data)[i + 1]));
printf("%04x ", (((const unsigned char *)data)[i] << 8) | (((const unsigned char *)data)[i + 1]));
caids.push_back((((const unsigned char *)data)[i] << 8) | (((const unsigned char *)data)[i + 1]));
}
if (!caids.empty())
{
@@ -85,7 +85,7 @@ int eDVBCICAManagerSession::doAction()
}
case stateFinal:
printf("[CI CA] stateFinal and action should not happen\n");
// fall through
// fall through
default:
return 0;
}

View File

@@ -7,18 +7,22 @@
class eDVBCICAManagerSession: public eDVBCISession
{
enum {
stateFinal=statePrivate
};
std::vector<uint16_t> caids;
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
eDVBCICAManagerSession(eDVBCISlot *tslot);
~eDVBCICAManagerSession();
enum
{
stateFinal = statePrivate
};
std::vector<uint16_t> caids;
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
eDVBCICAManagerSession(eDVBCISlot *tslot);
~eDVBCICAManagerSession();
const std::vector<uint16_t> &getCAIDs() const { return caids; }
int sendCAPMT(unsigned char *pmt, int len);
const std::vector<uint16_t> &getCAIDs() const
{
return caids;
}
int sendCAPMT(unsigned char *pmt, int len);
};
#endif

View File

@@ -28,15 +28,16 @@
#define x_debug 0
#define y_debug 0
static const char * FILENAME = "[dvbci_ccmgr]";
static const char *FILENAME = "[dvbci_ccmgr]";
/* storage & load of authenticated data (HostID & DHSK & AKH) */
static void CheckFile(char *file)
{
if (access(file, F_OK) != 0) {
if (access(file, F_OK) != 0)
{
printf("No File: %s\n", file);
FILE* fd;
FILE *fd;
fd = fopen(file, "w");
fclose(fd);
}
@@ -64,19 +65,23 @@ static bool get_authdata(uint8_t *host_id, uint8_t *dhsk, uint8_t *akh, unsigned
get_authdata_filename(filename, sizeof(filename), slot);
fd = open(filename, O_RDONLY);
if (fd <= 0) {
if (fd <= 0)
{
fprintf(stderr, "cannot open %s\n", filename);
return false;
}
for (i = 0; i < 5; i++) {
if (read(fd, chunk, sizeof(chunk)) != sizeof(chunk)) {
for (i = 0; i < 5; i++)
{
if (read(fd, chunk, sizeof(chunk)) != sizeof(chunk))
{
fprintf(stderr, "cannot read auth_data\n");
close(fd);
return false;
}
if (i == index) {
if (i == index)
{
memcpy(host_id, chunk, 8);
memcpy(dhsk, &chunk[8], 256);
memcpy(akh, &chunk[8 + 256], 32);
@@ -100,13 +105,15 @@ static bool write_authdata(unsigned int slot, const uint8_t *host_id, const uint
unsigned int i;
bool ret = false;
for (entries = 0; entries < 5; entries++) {
for (entries = 0; entries < 5; entries++)
{
int offset = (8 + 256 + 32) * entries;
if (!get_authdata(&buf[offset], &buf[offset + 8], &buf[offset + 8 + 256], slot, entries))
break;
/* check if we got this pair already */
if (!memcmp(&buf[offset + 8 + 256], akh, 32)) {
if (!memcmp(&buf[offset + 8 + 256], akh, 32))
{
printf("data already stored\n");
return true;
}
@@ -117,23 +124,27 @@ static bool write_authdata(unsigned int slot, const uint8_t *host_id, const uint
get_authdata_filename(filename, sizeof(filename), slot);
fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd <= 0) {
if (fd <= 0)
{
printf("cannot open %s for writing - authdata not stored\n", filename);
return false;
}
/* store new entry first */
if (write(fd, host_id, 8) != 8) {
if (write(fd, host_id, 8) != 8)
{
fprintf(stderr, "error in write\n");
goto end;
}
if (write(fd, dhsk, 256) != 256) {
if (write(fd, dhsk, 256) != 256)
{
fprintf(stderr, "error in write\n");
goto end;
}
if (write(fd, akh, 32) != 32) {
if (write(fd, akh, 32) != 32)
{
fprintf(stderr, "error in write\n");
goto end;
}
@@ -142,9 +153,11 @@ static bool write_authdata(unsigned int slot, const uint8_t *host_id, const uint
if (entries > 3)
entries = 3;
for (i = 0; i < entries; i++) {
for (i = 0; i < entries; i++)
{
int offset = (8 + 256 + 32) * i;
if (write(fd, &buf[offset], (8 + 256 + 32)) != (8 + 256 + 32)) {
if (write(fd, &buf[offset], (8 + 256 + 32)) != (8 + 256 + 32))
{
fprintf(stderr, "error in write\n");
goto end;
}
@@ -159,7 +172,8 @@ end:
/* CI+ certificates */
struct cert_ctx {
struct cert_ctx
{
X509_STORE *store;
/* Host */
@@ -173,7 +187,8 @@ struct cert_ctx {
static int verify_cb(int /*ok*/, X509_STORE_CTX *ctx)
{
if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_NOT_YET_VALID) {
if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_NOT_YET_VALID)
{
time_t now = time(NULL);
struct tm *t = localtime(&now);
if (t->tm_year < 2015)
@@ -193,7 +208,8 @@ static RSA *rsa_privatekey_open(const char *filename)
RSA *r = NULL;
fp = fopen(filename, "r");
if (!fp) {
if (!fp)
{
fprintf(stderr, "cannot open %s\n", filename);
return NULL;
}
@@ -213,7 +229,8 @@ static X509 *certificate_open(const char *filename)
X509 *cert;
fp = fopen(filename, "r");
if (!fp) {
if (!fp)
{
fprintf(stderr, "cannot open %s\n", filename);
return NULL;
}
@@ -256,15 +273,18 @@ static X509 *certificate_load_and_check(struct cert_ctx *ctx, const char *filena
{
X509 *cert;
if (!ctx->store) {
if (!ctx->store)
{
/* we assume this is the first certificate added - so its root-ca */
ctx->store = X509_STORE_new();
if (!ctx->store) {
if (!ctx->store)
{
fprintf(stderr, "cannot create cert_store\n");
exit(-1);
}
if (X509_STORE_load_locations(ctx->store, filename, NULL) != 1) {
if (X509_STORE_load_locations(ctx->store, filename, NULL) != 1)
{
fprintf(stderr, "load of first certificate (root_ca) failed\n");
exit(-1);
}
@@ -273,19 +293,22 @@ static X509 *certificate_load_and_check(struct cert_ctx *ctx, const char *filena
}
cert = certificate_open(filename);
if (!cert) {
if (!cert)
{
fprintf(stderr, "cannot open certificate %s\n", filename);
return NULL;
}
if (!certificate_validate(ctx, cert)) {
if (!certificate_validate(ctx, cert))
{
fprintf(stderr, "cannot vaildate certificate\n");
X509_free(cert);
return NULL;
}
/* push into store - create a chain */
if (X509_STORE_load_locations(ctx->store, filename, NULL) != 1) {
if (X509_STORE_load_locations(ctx->store, filename, NULL) != 1)
{
fprintf(stderr, "load of certificate failed\n");
X509_free(cert);
return NULL;
@@ -299,12 +322,14 @@ static X509 *certificate_import_and_check(struct cert_ctx *ctx, const uint8_t *d
X509 *cert;
cert = d2i_X509(NULL, &data, len);
if (!cert) {
if (!cert)
{
fprintf(stderr, "cannot read certificate\n");
return NULL;
}
if (!certificate_validate(ctx, cert)) {
if (!certificate_validate(ctx, cert))
{
fprintf(stderr, "cannot vaildate certificate\n");
X509_free(cert);
return NULL;
@@ -320,7 +345,8 @@ static X509 *certificate_import_and_check(struct cert_ctx *ctx, const uint8_t *d
#define MAX_ELEMENTS 33
uint32_t datatype_sizes[MAX_ELEMENTS] = {
uint32_t datatype_sizes[MAX_ELEMENTS] =
{
0, 50, 0, 0, 0, 8, 8, 0,
0, 0, 0, 0, 32, 256, 256, 0,
0, 256, 256, 32, 8, 8, 32, 32,
@@ -328,14 +354,16 @@ uint32_t datatype_sizes[MAX_ELEMENTS] = {
32
};
struct element {
struct element
{
uint8_t *data;
uint32_t size;
/* buffer valid */
bool valid;
};
struct cc_ctrl_data {
struct cc_ctrl_data
{
/* parent */
//struct ci_session *session;
eDVBCISlot *slot;
@@ -370,7 +398,8 @@ struct cc_ctrl_data {
static struct element *element_get(struct cc_ctrl_data *cc_data, unsigned int id)
{
/* array index */
if ((id < 1) || (id >= MAX_ELEMENTS)) {
if ((id < 1) || (id >= MAX_ELEMENTS))
{
fprintf(stderr, "element_get: invalid id\n");
return NULL;
}
@@ -383,7 +412,8 @@ static void element_invalidate(struct cc_ctrl_data *cc_data, unsigned int id)
struct element *e;
e = element_get(cc_data, id);
if (e) {
if (e)
{
free(e->data);
memset(e, 0, sizeof(struct element));
}
@@ -406,13 +436,14 @@ static bool element_set(struct cc_ctrl_data *cc_data, unsigned int id, const uin
return false;
/* check size */
if ((datatype_sizes[id] != 0) && (datatype_sizes[id] != size)) {
if ((datatype_sizes[id] != 0) && (datatype_sizes[id] != size))
{
fprintf(stderr, "size %d of datatype_id %d doesn't match\n", size, id);
return false;
}
free(e->data);
e->data = (uint8_t*)malloc(size);
e->data = (uint8_t *)malloc(size);
memcpy(e->data, data, size);
e->size = size;
e->valid = true;
@@ -428,12 +459,14 @@ static bool element_set_certificate(struct cc_ctrl_data *cc_data, unsigned int i
int cert_len;
cert_len = i2d_X509(cert, &cert_der);
if (cert_len <= 0) {
if (cert_len <= 0)
{
printf("cannot get data in DER format\n");
return false;
}
if (!element_set(cc_data, id, cert_der, cert_len)) {
if (!element_set(cc_data, id, cert_der, cert_len))
{
printf("cannot store element (%d)\n", id);
return false;
}
@@ -448,7 +481,8 @@ static bool element_set_hostid_from_certificate(struct cc_ctrl_data *cc_data, un
char hostid[20];
uint8_t bin_hostid[8];
if ((id != 5) && (id != 6)) {
if ((id != 5) && (id != 6))
{
printf("wrong datatype_id for hostid\n");
return false;
}
@@ -456,14 +490,16 @@ static bool element_set_hostid_from_certificate(struct cc_ctrl_data *cc_data, un
subject = X509_get_subject_name(cert);
X509_NAME_get_text_by_NID(subject, nid_cn, hostid, sizeof(hostid));
if (strlen(hostid) != 16) {
if (strlen(hostid) != 16)
{
printf("malformed hostid\n");
return false;
}
str2bin(bin_hostid, hostid, 16);
if (!element_set(cc_data, id, bin_hostid, sizeof(bin_hostid))) {
if (!element_set(cc_data, id, bin_hostid, sizeof(bin_hostid)))
{
printf("cannot set hostid\n");
return false;
}
@@ -488,12 +524,14 @@ static unsigned int element_get_buf(struct cc_ctrl_data *cc_data, uint8_t *dest,
if (e == NULL)
return 0;
if (!e->valid) {
if (!e->valid)
{
fprintf(stderr, "element_get_buf: datatype %d not valid\n", id);
return 0;
}
if (!e->data) {
if (!e->data)
{
fprintf(stderr, "element_get_buf: datatype %d doesn't exist\n", id);
return 0;
}
@@ -508,7 +546,8 @@ static unsigned int element_get_req(struct cc_ctrl_data *cc_data, uint8_t *dest,
{
unsigned int len = element_get_buf(cc_data, &dest[3], id);
if (len == 0) {
if (len == 0)
{
fprintf(stderr, "cannot get element %d\n", id);
return 0;
}
@@ -528,12 +567,14 @@ static uint8_t *element_get_ptr(struct cc_ctrl_data *cc_data, unsigned int id)
if (e == NULL)
return NULL;
if (!e->valid) {
if (!e->valid)
{
fprintf(stderr, "element_get_ptr: datatype %u not valid\n", id);
return NULL;
}
if (!e->data) {
if (!e->data)
{
fprintf(stderr, "element_get_ptr: datatype %u doesn't exist\n", id);
return NULL;
}
@@ -557,7 +598,8 @@ static bool sac_check_auth(const uint8_t *data, unsigned int len, uint8_t *sak)
aes_xcbc_mac_process(&ctx, data, len - 16);
aes_xcbc_mac_done(&ctx, calced_signature);
if (memcmp(&data[len - 16], calced_signature, 16)) {
if (memcmp(&data[len - 16], calced_signature, 16))
{
fprintf(stderr, "signature wrong\n");
return false;
}
@@ -654,7 +696,8 @@ static X509 *import_ci_certificates(struct cc_ctrl_data *cc_data, unsigned int i
len = element_get_buf(cc_data, buf, id);
cert = certificate_import_and_check(ctx, buf, len);
if (!cert) {
if (!cert)
{
printf("cannot read/verify DER cert\n");
return NULL;
}
@@ -688,19 +731,22 @@ static int check_ci_certificates(struct cc_ctrl_data *cc_data)
#endif
/* import CICAM_BrandCert */
if ((ctx->ci_cust_cert = import_ci_certificates(cc_data, 8)) == NULL) {
if ((ctx->ci_cust_cert = import_ci_certificates(cc_data, 8)) == NULL)
{
printf("cannot import cert\n");
return -1;
}
/* import CICAM_DevCert */
if ((ctx->ci_device_cert = import_ci_certificates(cc_data, 16)) == NULL) {
if ((ctx->ci_device_cert = import_ci_certificates(cc_data, 16)) == NULL)
{
printf("cannot import cert\n");
return -1;
}
/* everything seems to be fine here - so extract the CICAM_id from cert */
if (!element_set_hostid_from_certificate(cc_data, 6, ctx->ci_device_cert)) {
if (!element_set_hostid_from_certificate(cc_data, 6, ctx->ci_device_cert))
{
printf("cannot set cicam_id in elements\n");
return -1;
}
@@ -770,10 +816,13 @@ static int restart_dh_challenge(struct cc_ctrl_data *cc_data)
printf("%s -> %s\n", FILENAME, __FUNCTION__);
if (!cc_data->cert_ctx) {
ctx = (struct cert_ctx*)calloc(1, sizeof(struct cert_ctx));
if (!cc_data->cert_ctx)
{
ctx = (struct cert_ctx *)calloc(1, sizeof(struct cert_ctx));
cc_data->cert_ctx = ctx;
} else {
}
else
{
ctx = cc_data->cert_ctx;
}
@@ -782,7 +831,8 @@ static int restart_dh_challenge(struct cc_ctrl_data *cc_data)
ctx->cust_cert = certificate_load_and_check(ctx, CUSTOMER_CERT);
ctx->device_cert = certificate_load_and_check(ctx, DEVICE_CERT);
if (!ctx->cust_cert || !ctx->device_cert) {
if (!ctx->cust_cert || !ctx->device_cert)
{
fprintf(stderr, "cannot loader certificates\n");
return -1;
}
@@ -798,7 +848,8 @@ static int restart_dh_challenge(struct cc_ctrl_data *cc_data)
fprintf(stderr, "cannot set hostid in elements\n");
cc_data->rsa_device_key = rsa_privatekey_open(DEVICE_CERT);
if (!cc_data->rsa_device_key) {
if (!cc_data->rsa_device_key)
{
fprintf(stderr, "cannot read private key\n");
return -1;
}
@@ -901,46 +952,47 @@ static int data_get_handle_new(struct cc_ctrl_data *cc_data, unsigned int id)
/* depends on new received items */
switch (id) {
case 8: /* CICAM_BrandCert */
case 14: /* DHPM */
case 16: /* CICAM_DevCert */
case 18: /* Signature_B */
/* this results in CICAM_ID when cert-chain is verified and ok */
if (check_ci_certificates(cc_data))
switch (id)
{
case 8: /* CICAM_BrandCert */
case 14: /* DHPM */
case 16: /* CICAM_DevCert */
case 18: /* Signature_B */
/* this results in CICAM_ID when cert-chain is verified and ok */
if (check_ci_certificates(cc_data))
break;
/* generate DHSK & AKH */
check_dh_challenge(cc_data);
break;
/* generate DHSK & AKH */
check_dh_challenge(cc_data);
break;
case 19: /* auth_nonce - triggers new dh keychallenge - invalidates DHSK & AKH */
/* generate DHPH & Signature_A */
restart_dh_challenge(cc_data);
break;
case 19: /* auth_nonce - triggers new dh keychallenge - invalidates DHSK & AKH */
/* generate DHPH & Signature_A */
restart_dh_challenge(cc_data);
break;
case 21: /* Ns_module - triggers SAC key calculation */
generate_ns_host(cc_data);
generate_key_seed(cc_data);
generate_SAK_SEK(cc_data->sak, cc_data->sek, cc_data->ks_host);
break;
case 21: /* Ns_module - triggers SAC key calculation */
generate_ns_host(cc_data);
generate_key_seed(cc_data);
generate_SAK_SEK(cc_data->sak, cc_data->sek, cc_data->ks_host);
break;
/* SAC data messages */
/* SAC data messages */
case 6: //CICAM_id
case 12: //keyprecursor
check_new_key(cc_data);
break;
case 26: //programm number
case 25: //uri_message
generate_uri_confirm(cc_data, cc_data->sak);
break;
case 28: //key register
check_new_key(cc_data);
break;
case 6: //CICAM_id
case 12: //keyprecursor
check_new_key(cc_data);
break;
case 26: //programm number
case 25: //uri_message
generate_uri_confirm(cc_data, cc_data->sak);
break;
case 28: //key register
check_new_key(cc_data);
break;
default:
printf("%s -> %s unhandled ID (%d)\n", FILENAME, __FUNCTION__, id);
break;
default:
printf("%s -> %s unhandled ID (%d)\n", FILENAME, __FUNCTION__, id);
break;
}
return 0;
@@ -951,22 +1003,24 @@ static int data_req_handle_new(struct cc_ctrl_data *cc_data, unsigned int id)
#if x_debug
printf("%s -> %s ID = (%d)\n", FILENAME, __FUNCTION__, id);
#endif
switch (id) {
case 22: /* AKH */
switch (id)
{
uint8_t akh[32], host_id[8];
memset(akh, 0, sizeof(akh));
if (cc_data->akh_index != 5) {
if (!get_authdata(host_id, cc_data->dhsk, akh, cc_data->slot->slot, cc_data->akh_index++))
cc_data->akh_index = 5;
if (!element_set(cc_data, 22, akh, 32))
printf("cannot set AKH in elements\n");
if (!element_set(cc_data, 5, host_id, 8))
printf("cannot set host_id in elements\n");
case 22: /* AKH */
{
uint8_t akh[32], host_id[8];
memset(akh, 0, sizeof(akh));
if (cc_data->akh_index != 5)
{
if (!get_authdata(host_id, cc_data->dhsk, akh, cc_data->slot->slot, cc_data->akh_index++))
cc_data->akh_index = 5;
if (!element_set(cc_data, 22, akh, 32))
printf("cannot set AKH in elements\n");
if (!element_set(cc_data, 5, host_id, 8))
printf("cannot set host_id in elements\n");
}
}
}
default:
break;
default:
break;
}
return 0;
@@ -980,7 +1034,8 @@ static int data_get_loop(struct cc_ctrl_data *cc_data, const unsigned char *data
#if x_debug
printf("%s -> %s\n", FILENAME, __FUNCTION__);
#endif
for (i = 0; i < items; i++) {
for (i = 0; i < items; i++)
{
if (pos + 3 > datalen)
return 0;
@@ -1020,14 +1075,16 @@ static int data_req_loop(struct cc_ctrl_data *cc_data, unsigned char *dest, cons
if (items > datalen)
return -1;
for (i = 0; i < items; i++) {
for (i = 0; i < items; i++)
{
dt_id = *data++;
#if x_debug
printf("req element %d\n", dt_id);
#endif
data_req_handle_new(cc_data, dt_id); /* check if there is any action needed before we answer */
len = element_get_req(cc_data, dest, dt_id);
if (len == 0) {
if (len == 0)
{
printf("cannot get element %d\n", dt_id);
return -1;
}
@@ -1054,13 +1111,15 @@ bool eDVBCIContentControlManagerSession::data_initialize(eDVBCISlot *tslot)
printf("%s -> %s\n", FILENAME, __FUNCTION__);
if (tslot->private_data) {
if (tslot->private_data)
{
fprintf(stderr, "strange private_data not null!\n");
return false;
}
data = (struct cc_ctrl_data*)calloc(1, sizeof(struct cc_ctrl_data));
if (!data) {
data = (struct cc_ctrl_data *)calloc(1, sizeof(struct cc_ctrl_data));
if (!data)
{
fprintf(stderr, "out of memory\n");
return false;
}
@@ -1084,7 +1143,8 @@ bool eDVBCIContentControlManagerSession::data_initialize(eDVBCISlot *tslot)
/* load first AKH */
data->akh_index = 0;
if (!get_authdata(host_id, data->dhsk, buf, tslot->slot, data->akh_index)) {
if (!get_authdata(host_id, data->dhsk, buf, tslot->slot, data->akh_index))
{
/* no AKH available */
memset(buf, 0, sizeof(buf));
data->akh_index = 5; /* last one */
@@ -1114,7 +1174,7 @@ void eDVBCIContentControlManagerSession::ci_ccmgr_cc_open_cnf(eDVBCISlot *tslot)
bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len)
{
struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data);
struct cc_ctrl_data *cc_data = (struct cc_ctrl_data *)(tslot->private_data);
uint8_t cc_data_cnf_tag[3] = { 0x9f, 0x90, 0x04 };
uint8_t dest[2048 * 2];
int dt_nr;
@@ -1143,7 +1203,8 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(eDVBCISlot *tslot,
dest[1] = dt_nr;
answ_len = data_req_loop(cc_data, &dest[2], &data[rp], len - rp, dt_nr);
if (answ_len <= 0) {
if (answ_len <= 0)
{
fprintf(stderr, "cannot req data\n");
return false;
}
@@ -1157,9 +1218,9 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(eDVBCISlot *tslot,
void eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_sync_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int
#if y_debug
len
len
#endif
)
)
{
const uint8_t sync_cnf_tag[3] = { 0x9f, 0x90, 0x10 };
uint8_t dest[64];
@@ -1193,7 +1254,7 @@ void eDVBCIContentControlManagerSession::ci_ccmgr_cc_sync_req()
bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos)
{
struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data);
struct cc_ctrl_data *cc_data = (struct cc_ctrl_data *)(tslot->private_data);
printf("%s -> %s (%02X%02X%02X) \n", FILENAME, __FUNCTION__, tag[0], tag[1], tag[2]);
if (pos < 8)
@@ -1217,7 +1278,7 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_send(eDVBCISlot *tslot,
bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len)
{
struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data);
struct cc_ctrl_data *cc_data = (struct cc_ctrl_data *)(tslot->private_data);
const uint8_t data_cnf_tag[3] = { 0x9f, 0x90, 0x08 };
uint8_t dest[2048];
uint8_t tmp[len];
@@ -1240,7 +1301,8 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(eDVBCISlot *ts
printf("%02x ", data[i]);
printf("\n");
#endif
if (!sac_check_auth(data, len, cc_data->sak)) {
if (!sac_check_auth(data, len, cc_data->sak))
{
fprintf(stderr, "check_auth of message failed\n");
return false;
}
@@ -1269,7 +1331,8 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(eDVBCISlot *ts
dest[pos++] = dt_nr; /* dt_nbr */
answ_len = data_req_loop(cc_data, &dest[pos], &data[rp], len - rp, dt_nr);
if (answ_len <= 0) {
if (answ_len <= 0)
{
fprintf(stderr, "cannot req data\n");
return false;
}
@@ -1294,7 +1357,7 @@ eDVBCIContentControlManagerSession::~eDVBCIContentControlManagerSession()
void eDVBCIContentControlManagerSession::ci_ccmgr_doClose(eDVBCISlot *tslot)
{
struct cc_ctrl_data *data = (struct cc_ctrl_data*)(tslot->private_data);
struct cc_ctrl_data *data = (struct cc_ctrl_data *)(tslot->private_data);
printf("%s -> %s\n", FILENAME, __FUNCTION__);
descrambler_deinit();
@@ -1309,23 +1372,35 @@ int eDVBCIContentControlManagerSession::receivedAPDU(const unsigned char *tag, c
printf("SESSION(%d)/CC %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]);
#if y_debug
for (int i = 0; i < len; i++)
printf("%02x ", ((const unsigned char*)data)[i]);
printf("%02x ", ((const unsigned char *)data)[i]);
#endif
printf("\n");
if ((tag[0] == 0x9f) && (tag[1] == 0x90)) {
switch (tag[2]) {
case 0x01: ci_ccmgr_cc_open_cnf(slot); break;
case 0x03: ci_ccmgr_cc_data_req(slot, (const uint8_t*)data, len); break;
case 0x05: ci_ccmgr_cc_sync_req(); break;
case 0x07: ci_ccmgr_cc_sac_data_req(slot, (const uint8_t*)data, len); break;
case 0x09: ci_ccmgr_cc_sac_sync_req(slot, (const uint8_t*)data, len); break;
default:
fprintf(stderr, "unknown apdu tag %02x\n", tag[2]);
break;
if ((tag[0] == 0x9f) && (tag[1] == 0x90))
{
switch (tag[2])
{
case 0x01:
ci_ccmgr_cc_open_cnf(slot);
break;
case 0x03:
ci_ccmgr_cc_data_req(slot, (const uint8_t *)data, len);
break;
case 0x05:
ci_ccmgr_cc_sync_req();
break;
case 0x07:
ci_ccmgr_cc_sac_data_req(slot, (const uint8_t *)data, len);
break;
case 0x09:
ci_ccmgr_cc_sac_sync_req(slot, (const uint8_t *)data, len);
break;
default:
fprintf(stderr, "unknown apdu tag %02x\n", tag[2]);
break;
}
}
return 0;
}
@@ -1342,7 +1417,7 @@ int eDVBCIContentControlManagerSession::doAction()
}
case stateFinal:
printf("stateFinal und action! kann doch garnicht sein ;)\n");
// fall through
// fall through
default:
return 0;
}

View File

@@ -5,23 +5,24 @@
class eDVBCIContentControlManagerSession: public eDVBCISession
{
bool data_initialize(eDVBCISlot *tslot);
bool ci_ccmgr_cc_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len);
bool ci_ccmgr_cc_sac_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len);
bool ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos);
void ci_ccmgr_cc_sac_sync_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len);
void ci_ccmgr_cc_sync_req();
void ci_ccmgr_cc_open_cnf(eDVBCISlot *slot);
bool data_initialize(eDVBCISlot *tslot);
bool ci_ccmgr_cc_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len);
bool ci_ccmgr_cc_sac_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len);
bool ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos);
void ci_ccmgr_cc_sac_sync_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len);
void ci_ccmgr_cc_sync_req();
void ci_ccmgr_cc_open_cnf(eDVBCISlot *slot);
enum {
stateFinal=statePrivate
};
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
eDVBCIContentControlManagerSession(eDVBCISlot *tslot);
~eDVBCIContentControlManagerSession();
void ci_ccmgr_doClose(eDVBCISlot *tslot);
void resendKey(eDVBCISlot *tslot);
enum
{
stateFinal = statePrivate
};
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
eDVBCIContentControlManagerSession(eDVBCISlot *tslot);
~eDVBCIContentControlManagerSession();
void ci_ccmgr_doClose(eDVBCISlot *tslot);
void resendKey(eDVBCISlot *tslot);
};
#endif

View File

@@ -22,7 +22,7 @@ int eDVBCIDateTimeSession::receivedAPDU(const unsigned char *tag, const void *da
{
printf("[CI DT] SESSION(%d)/DATETIME %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]);
for (int i = 0; i < len; i++)
printf("%02x ", ((const unsigned char*)data)[i]);
printf("%02x ", ((const unsigned char *)data)[i]);
printf("\n");
if ((tag[0] == 0x9f) && (tag[1] == 0x84))
@@ -52,7 +52,7 @@ int eDVBCIDateTimeSession::doAction()
return 0;
case stateFinal:
printf("stateFinal und action! kann doch garnicht sein ;)\n");
// fall through
// fall through
default:
return 0;
}
@@ -66,7 +66,7 @@ void eDVBCIDateTimeSession::sendDateTime()
unsigned char msg[7] = {0, 0, 0, 0, 0, 0, 0};
printf("[CI DT] -> %s\n", __FUNCTION__);
time_t t = time(NULL);
if ( gmtime_r(&t, &tm_gmt) && localtime_r(&t, &tm_loc) )
if (gmtime_r(&t, &tm_gmt) && localtime_r(&t, &tm_loc))
{
int Y = tm_gmt.tm_year;
int M = tm_gmt.tm_mon + 1;

View File

@@ -5,15 +5,16 @@
class eDVBCIDateTimeSession: public eDVBCISession
{
enum {
stateFinal=statePrivate, stateSendDateTime
};
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
eDVBCIDateTimeSession(eDVBCISlot *tslot);
~eDVBCIDateTimeSession();
void sendDateTime();
enum
{
stateFinal = statePrivate, stateSendDateTime
};
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
eDVBCIDateTimeSession(eDVBCISlot *tslot);
~eDVBCIDateTimeSession();
void sendDateTime();
};
#endif

View File

@@ -17,7 +17,7 @@ eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot)
eDVBCIMMISession::~eDVBCIMMISession()
{
/* Send a message to Neutrino cam_menu handler */
CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE));
CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE));
memset(pMsg, 0, sizeof(CA_MESSAGE));
pMsg->MsgId = CA_MESSAGE_MSG_MMI_CLOSE;
@@ -34,7 +34,7 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
{
printf("[CI MMI] SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]);
for (int i = 0; i < len; i++)
printf("%02x ", ((const unsigned char*)data)[i]);
printf("%02x ", ((const unsigned char *)data)[i]);
printf("\n");
if ((tag[0] == 0x9f) && (tag[1] == 0x88))
@@ -45,7 +45,7 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
case 0x00: /* close */
{
/* Send a message to Neutrino cam_menu handler */
CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE));
CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE));
memset(pMsg, 0, sizeof(CA_MESSAGE));
pMsg->MsgId = CA_MESSAGE_MSG_MMI_CLOSE;
@@ -61,10 +61,10 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
break;
case 0x07: /* menu enq */
{
MMI_ENQUIRY_INFO* enquiry = (MMI_ENQUIRY_INFO*) malloc(sizeof(MMI_ENQUIRY_INFO));
MMI_ENQUIRY_INFO *enquiry = (MMI_ENQUIRY_INFO *) malloc(sizeof(MMI_ENQUIRY_INFO));
memset(enquiry, 0, sizeof(MMI_ENQUIRY_INFO));
unsigned char *d = (unsigned char*)data;
unsigned char *max = ((unsigned char*)d) + len;
unsigned char *d = (unsigned char *)data;
unsigned char *max = ((unsigned char *)d) + len;
int textlen = len - 2;
if ((d + 2) > max)
@@ -77,7 +77,7 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
break;
char str[textlen + 1];
memcpy(str, ((char*)d), textlen);
memcpy(str, ((char *)d), textlen);
str[textlen] = '\0';
printf("enq-text: %s", str);
enquiry->slot = slot->slot;
@@ -86,14 +86,14 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
strcpy(enquiry->enquiryText, str);
/* Send a message to Neutrino cam_menu handler */
CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE));
CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE));
memset(pMsg, 0, sizeof(CA_MESSAGE));
pMsg->MsgId = CA_MESSAGE_MSG_MMI_REQ_INPUT;
pMsg->SlotType = CA_SLOT_TYPE_CI;
pMsg->Slot = slot->slot;
pMsg->Flags = CA_MESSAGE_HAS_PARAM1_DATA;
pMsg->Msg.Data[0] = (uint8_t*)enquiry;
pMsg->Msg.Data[0] = (uint8_t *)enquiry;
cCA::GetInstance()->SendMessage(pMsg);
slot->mmiOpened = true;
@@ -102,14 +102,14 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
case 0x09: /* menu last */
case 0x0c: /* list last */
{
MMI_MENU_LIST_INFO* listInfo = (MMI_MENU_LIST_INFO*) malloc(sizeof(MMI_MENU_LIST_INFO));
MMI_MENU_LIST_INFO *listInfo = (MMI_MENU_LIST_INFO *) malloc(sizeof(MMI_MENU_LIST_INFO));
memset(listInfo, 0, sizeof(MMI_MENU_LIST_INFO));
listInfo->slot = slot->slot;
listInfo->choice_nb = 0;
unsigned char *d = (unsigned char*)data;
unsigned char *max = ((unsigned char*)d) + len;
unsigned char *d = (unsigned char *)data;
unsigned char *max = ((unsigned char *)d) + len;
int pos = 0;
if (tag[2] == 0x09)
@@ -142,7 +142,7 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
break;
char str[textlen + 1];
memcpy(str, ((char*)d), textlen);
memcpy(str, ((char *)d), textlen);
str[textlen] = '\0';
int type = pos++;
@@ -168,27 +168,27 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
if (tag[2] == 0x09)
{
/* Send a message to Neutrino cam_menu handler */
CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE));
CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE));
memset(pMsg, 0, sizeof(CA_MESSAGE));
pMsg->MsgId = CA_MESSAGE_MSG_MMI_MENU;
pMsg->SlotType = CA_SLOT_TYPE_CI;
pMsg->Slot = slot->slot;
pMsg->Flags = CA_MESSAGE_HAS_PARAM1_DATA;
pMsg->Msg.Data[0] = (uint8_t*)listInfo;
pMsg->Msg.Data[0] = (uint8_t *)listInfo;
cCA::GetInstance()->SendMessage(pMsg);
}
else
{
/* Send a message to Neutrino cam_menu handler */
CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE));
CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE));
memset(pMsg, 0, sizeof(CA_MESSAGE));
pMsg->MsgId = CA_MESSAGE_MSG_MMI_LIST;
pMsg->SlotType = CA_SLOT_TYPE_CI;
pMsg->Slot = slot->slot;
pMsg->Flags = CA_MESSAGE_HAS_PARAM1_DATA;
pMsg->Msg.Data[0] = (uint8_t*)listInfo;
pMsg->Msg.Data[0] = (uint8_t *)listInfo;
cCA::GetInstance()->SendMessage(pMsg);
}
}
@@ -245,7 +245,7 @@ int eDVBCIMMISession::stopMMI()
int eDVBCIMMISession::answerText(int answer)
{
printf("[CI MMI] eDVBCIMMISession::answerText(%d)\n",answer);
printf("[CI MMI] eDVBCIMMISession::answerText(%d)\n", answer);
unsigned char tag[] = {0x9f, 0x88, 0x0B};
unsigned char data[] = {0x00};

View File

@@ -5,20 +5,21 @@
class eDVBCIMMISession: public eDVBCISession
{
enum {
stateDisplayReply=statePrivate, stateFakeOK, stateIdle
};
enum
{
stateDisplayReply = statePrivate, stateFakeOK, stateIdle
};
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
eDVBCISlot *slot;
public:
eDVBCIMMISession(eDVBCISlot *tslot);
~eDVBCIMMISession();
int stopMMI();
int answerText(int answer);
int answerEnq(char *answer, int len);
int cancelEnq();
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
eDVBCISlot *slot;
public:
eDVBCIMMISession(eDVBCISlot *tslot);
~eDVBCIMMISession();
int stopMMI();
int answerText(int answer);
int answerEnq(char *answer, int len);
int cancelEnq();
};
#endif

View File

@@ -9,7 +9,7 @@ int eDVBCIResourceManagerSession::receivedAPDU(const unsigned char *tag, const v
if (len)
{
for (int i = 0; i < len; i++)
printf("%02x ", ((const unsigned char*)data)[i]);
printf("%02x ", ((const unsigned char *)data)[i]);
printf("\n");
}
if ((tag[0] == 0x9f) && (tag[1] == 0x80))
@@ -27,7 +27,7 @@ int eDVBCIResourceManagerSession::receivedAPDU(const unsigned char *tag, const v
printf("nothing");
else
for (int i = 0; i < len; i++)
printf("%02x ", ((const unsigned char*)data)[i]);
printf("%02x ", ((const unsigned char *)data)[i]);
printf("\n");
if (state == stateFirstProfileEnquiry)
@@ -76,16 +76,16 @@ int eDVBCIResourceManagerSession::doAction()
{
const unsigned char data[][4] =
{
{0x00, 0x01, 0x00, 0x41}, // resource
{0x00, 0x02, 0x00, 0x41}, // application V1
{0x00, 0x02, 0x00, 0x43}, // application V3
{0x00, 0x03, 0x00, 0x41}, // conditional access
{0x00, 0x20, 0x00, 0x41}, // host control (dummy)
{0x00, 0x40, 0x00, 0x41}, // mmi
{0x00, 0x24, 0x00, 0x41}, // date-time
{0x00, 0x8c, 0x10, 0x01}, // content control
{0x00, 0x8e, 0x10, 0x01} // cam upgrade (dummy)
// {0x00, 0x10, 0x00, 0x41} // auth.
{0x00, 0x01, 0x00, 0x41}, // resource
{0x00, 0x02, 0x00, 0x41}, // application V1
{0x00, 0x02, 0x00, 0x43}, // application V3
{0x00, 0x03, 0x00, 0x41}, // conditional access
{0x00, 0x20, 0x00, 0x41}, // host control (dummy)
{0x00, 0x40, 0x00, 0x41}, // mmi
{0x00, 0x24, 0x00, 0x41}, // date-time
{0x00, 0x8c, 0x10, 0x01}, // content control
{0x00, 0x8e, 0x10, 0x01} // cam upgrade (dummy)
// {0x00, 0x10, 0x00, 0x41} // auth.
};
sendAPDU(tag, data, sizeof(data));
}
@@ -93,14 +93,14 @@ int eDVBCIResourceManagerSession::doAction()
{
const unsigned char data[][4] =
{
{0x00, 0x01, 0x00, 0x41}, // resource
{0x00, 0x02, 0x00, 0x41}, // application V1
{0x00, 0x02, 0x00, 0x43}, // application V3
{0x00, 0x03, 0x00, 0x41}, // conditional access
// {0x00, 0x20, 0x00, 0x41}, // host control
{0x00, 0x40, 0x00, 0x41}, // mmi
{0x00, 0x24, 0x00, 0x41} // date-time
// {0x00, 0x10, 0x00, 0x41} // auth.
{0x00, 0x01, 0x00, 0x41}, // resource
{0x00, 0x02, 0x00, 0x41}, // application V1
{0x00, 0x02, 0x00, 0x43}, // application V3
{0x00, 0x03, 0x00, 0x41}, // conditional access
// {0x00, 0x20, 0x00, 0x41}, // host control
{0x00, 0x40, 0x00, 0x41}, // mmi
{0x00, 0x24, 0x00, 0x41} // date-time
// {0x00, 0x10, 0x00, 0x41} // auth.
};
sendAPDU(tag, data, sizeof(data));
}

View File

@@ -5,15 +5,16 @@
class eDVBCIResourceManagerSession: public eDVBCISession
{
enum {
stateFirstProfileEnquiry=statePrivate,
stateProfileChange,
stateProfileEnquiry,
stateFinal
};
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
enum
{
stateFirstProfileEnquiry = statePrivate,
stateProfileChange,
stateProfileEnquiry,
stateFinal
};
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
};

View File

@@ -12,7 +12,7 @@
#include "dvbci_mmi.h"
#include "dvbci_ccmgr.h"
eDVBCISession* eDVBCISession::sessions[SLMS];
eDVBCISession *eDVBCISession::sessions[SLMS];
eDVBCIHostControlSession::eDVBCIHostControlSession(eDVBCISlot *tslot)
{
@@ -23,11 +23,11 @@ eDVBCIHostControlSession::~eDVBCIHostControlSession()
{
}
int eDVBCIHostControlSession::receivedAPDU(const unsigned char *tag,const void *data, int len)
int eDVBCIHostControlSession::receivedAPDU(const unsigned char *tag, const void *data, int len)
{
printf("CI HC SESSION(%d)/TAG %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]);
for (int i=0; i<len; i++)
printf("%02x ", ((const unsigned char*)data)[i]);
for (int i = 0; i < len; i++)
printf("%02x ", ((const unsigned char *)data)[i]);
printf("\n");
return 0;
}
@@ -161,7 +161,7 @@ void eDVBCISession::deleteSessions(const eDVBCISlot *slot)
}
}
eDVBCISession* eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status)
eDVBCISession *eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status)
{
unsigned long tag;
unsigned short session_nb;
@@ -207,13 +207,13 @@ eDVBCISession* eDVBCISession::createSession(eDVBCISlot *slot, const unsigned cha
sessions[session_nb - 1] = new eDVBCIMMISession(slot);
printf("[CI SESS] MMI - create session\n");
break;
if (cCA::GetInstance()->CheckCerts())
{
if (cCA::GetInstance()->CheckCerts())
{
case 0x008c1001:
printf("[CI SESS] CC MANAGER\n");
sessions[session_nb - 1] = new eDVBCIContentControlManagerSession(slot);
break;
} // fall through
} // fall through
case 0x00200041:
sessions[session_nb - 1] = new eDVBCIHostControlSession(slot);
printf("[CI SESS] Host Control\n");
@@ -222,7 +222,7 @@ eDVBCISession* eDVBCISession::createSession(eDVBCISlot *slot, const unsigned cha
// session=new eDVBCIAuthSession;
printf("[CI SESS] AuthSession\n");
// break;
// fall through
// fall through
case 0x008e1001:
default:
printf("[CI SESS] unknown resource type %02x %02x %02x %02x\n", resource_identifier[0], resource_identifier[1], resource_identifier[2], resource_identifier[3]);
@@ -284,18 +284,18 @@ int eDVBCISession::pollAll()
void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len)
{
if ((ptr[0] == 0x90 || ptr[0] == 0x95) && (ptr[3] == 0 ))
if ((ptr[0] == 0x90 || ptr[0] == 0x95) && (ptr[3] == 0))
{
printf("[CI SESS] ****Mist: %02x %02x %02x %02x\n", ptr[0], ptr[1], ptr[2], ptr[3]);
}
const unsigned char *pkt = (const unsigned char*)ptr;
const unsigned char *pkt = (const unsigned char *)ptr;
unsigned char tag = *pkt++;
int llen, hlen;
printf("[CI SESS] receiveData slot: %p > ",slot);
printf("[CI SESS] receiveData slot: %p > ", slot);
#if 0
for(unsigned int i = 0; i < len; i++)
for (unsigned int i = 0; i < len; i++)
printf("%02x ", ptr[i]);
#endif
printf("\n");
@@ -303,9 +303,9 @@ void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size
llen = parseLengthField(pkt, hlen);
pkt += llen;
eDVBCISession* session = NULL;
eDVBCISession *session = NULL;
if(tag == 0x91)
if (tag == 0x91)
{
unsigned char status;
@@ -357,7 +357,7 @@ void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size
hlen += llen + 1; // lengthfield and tag
pkt = ((const unsigned char*)ptr) + hlen;
pkt = ((const unsigned char *)ptr) + hlen;
len -= hlen;
if (session)

View File

@@ -11,53 +11,68 @@
class eDVBCISession
{
static eDVBCISession* sessions[SLMS];
static eDVBCISession* createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status);
static void sendSPDU(eDVBCISlot *slot, unsigned char tag,const void *data, int len, unsigned short session_nb, const void *apdu = 0, int alen = 0);
static void sendOpenSessionResponse(eDVBCISlot *slot,unsigned char session_status, const unsigned char *resource_identifier, unsigned short session_nb);
void recvCreateSessionResponse(const unsigned char *data);
void recvCloseSessionRequest(const unsigned char *data);
protected:
int state;
int status;
int action;
eDVBCISlot *slot;
unsigned short session_nb;
virtual int receivedAPDU(const unsigned char *tag, const void *data, int len) = 0;
void sendAPDU(const unsigned char *tag, const void *data=0,int len=0);
virtual int doAction() = 0;
void handleClose();
public:
virtual ~eDVBCISession();
static eDVBCISession *sessions[SLMS];
static eDVBCISession *createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status);
static void sendSPDU(eDVBCISlot *slot, unsigned char tag, const void *data, int len, unsigned short session_nb, const void *apdu = 0, int alen = 0);
static void sendOpenSessionResponse(eDVBCISlot *slot, unsigned char session_status, const unsigned char *resource_identifier, unsigned short session_nb);
void recvCreateSessionResponse(const unsigned char *data);
void recvCloseSessionRequest(const unsigned char *data);
protected:
int state;
int status;
int action;
eDVBCISlot *slot;
unsigned short session_nb;
virtual int receivedAPDU(const unsigned char *tag, const void *data, int len) = 0;
void sendAPDU(const unsigned char *tag, const void *data = 0, int len = 0);
virtual int doAction() = 0;
void handleClose();
public:
virtual ~eDVBCISession();
static void deleteSessions(const eDVBCISlot *slot);
void sendSPDU(unsigned char tag, const void *data, int len, const void *apdu = 0, int alen = 0);
static void deleteSessions(const eDVBCISlot *slot);
void sendSPDU(unsigned char tag, const void *data, int len, const void *apdu = 0, int alen = 0);
int poll() { if (action) { action=doAction(); return 1; } return 0; }
enum { stateInCreation, stateBusy, stateInDeletion, stateStarted, statePrivate};
int poll()
{
if (action)
{
action = doAction();
return 1;
}
return 0;
}
enum { stateInCreation, stateBusy, stateInDeletion, stateStarted, statePrivate};
static int parseLengthField(const unsigned char *pkt, int &len);
static int buildLengthField(unsigned char *pkt, int len);
static int parseLengthField(const unsigned char *pkt, int &len);
static int buildLengthField(unsigned char *pkt, int len);
static void receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len);
static void receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len);
int getState() { return state; }
int getStatus() { return status; }
int getState()
{
return state;
}
int getStatus()
{
return status;
}
static int pollAll();
static int pollAll();
};
class eDVBCIHostControlSession: public eDVBCISession
{
enum {
stateFinal=statePrivate
};
eDVBCISlot *slot;
int receivedAPDU(const unsigned char *tag,const void *data, int len);
int doAction();
public:
eDVBCIHostControlSession(eDVBCISlot *tslot);
~eDVBCIHostControlSession();
enum
{
stateFinal = statePrivate
};
eDVBCISlot *slot;
int receivedAPDU(const unsigned char *tag, const void *data, int len);
int doAction();
public:
eDVBCIHostControlSession(eDVBCISlot *tslot);
~eDVBCIHostControlSession();
};

View File

@@ -16,12 +16,14 @@ int get_random(unsigned char *dest, int len)
const char *urnd = "/dev/urandom";
fd = open(urnd, O_RDONLY);
if (fd <= 0) {
if (fd <= 0)
{
printf("cannot open %s\n", urnd);
return -1;
}
if (read(fd, dest, len) != len) {
if (read(fd, dest, len) != len)
{
printf("cannot read from %s\n", urnd);
close(fd);
return -2;
@@ -37,11 +39,13 @@ int parseLengthField(const unsigned char *pkt, int *len)
int i;
*len = 0;
if (!(*pkt & 0x80)) {
if (!(*pkt & 0x80))
{
*len = *pkt;
return 1;
}
for (i = 0; i < (pkt[0] & 0x7F); ++i) {
for (i = 0; i < (pkt[0] & 0x7F); ++i)
{
*len <<= 8;
*len |= pkt[i + 1];
}
@@ -53,7 +57,8 @@ int add_padding(uint8_t *dest, unsigned int len, unsigned int blocklen)
uint8_t padding = 0x80;
int count = 0;
while (len & (blocklen - 1)) {
while (len & (blocklen - 1))
{
*dest++ = padding;
++len;
++count;
@@ -84,7 +89,7 @@ void str2bin(uint8_t *dst, char *data, int len)
int i;
for (i = 0; i < len; i += 2)
*dst++ = (get_bin_from_nibble(data[i]) << 4) | get_bin_from_nibble(data[i + 1]);
* dst++ = (get_bin_from_nibble(data[i]) << 4) | get_bin_from_nibble(data[i + 1]);
}
uint32_t UINT32(const unsigned char *in, unsigned int len)
@@ -92,7 +97,8 @@ uint32_t UINT32(const unsigned char *in, unsigned int len)
uint32_t val = 0;
unsigned int i;
for (i = 0; i < len; i++) {
for (i = 0; i < len; i++)
{
val <<= 8;
val |= *in++;
}