From 2ddb9ae15d7d3b1920306bfa7d01d951adab1b9c Mon Sep 17 00:00:00 2001 From: max_10 Date: Wed, 18 Nov 2015 17:16:39 +0100 Subject: [PATCH] test c** Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/46f67aaef07c5b90c2ad21e1b9a282f9a04adc14 Author: max_10 Date: 2015-11-18 (Wed, 18 Nov 2015) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- common/ca_ci.cpp | 10 +++---- libdvbci/dvbci_ccmgr.cpp | 55 +++++++++++++++++++++++++------------- libdvbci/dvbci_session.cpp | 2 +- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/common/ca_ci.cpp b/common/ca_ci.cpp index d4dcd53..429e3e3 100644 --- a/common/ca_ci.cpp +++ b/common/ca_ci.cpp @@ -193,7 +193,7 @@ static bool transmitData(tSlot* slot, unsigned char* d, int len) return eDataError; } #else -#if x_debug +#if y_debug printf("SendData with data (len %d) >\n", len); for (int i = 0; i < len; i++) printf("%02x ", d[i]); @@ -234,10 +234,12 @@ static bool sendRCV(tSlot* slot) send_data[2] = T_RCV; send_data[3] = 1; send_data[4] = slot->connection_id; +#if y_debug printf("*** > T_RCV: "); for (int i = 0; i < 5; i++) printf("%02x ", send_data[i]); printf("\n"); +#endif write(slot->fd, send_data, 5); return true; } @@ -343,13 +345,11 @@ void cCA::process_tpdu(tSlot* slot, unsigned char tpdu_tag, __u8* data, int asn_ if (slot->receivedData == NULL) { printf("%s -> single package\n", FILENAME); -#if x_debug - printf("%s -> calling receiveData with data (len %d)\n", FILENAME, asn_data_length); #if y_debug + printf("%s -> calling receiveData with data (len %d)\n", FILENAME, asn_data_length); for (int i = 0; i < asn_data_length; i++) printf("%02x ", data[i]); printf("\n"); -#endif #endif /* to avoid illegal session number: only if > 0 */ if (asn_data_length) @@ -368,7 +368,7 @@ void cCA::process_tpdu(tSlot* slot, unsigned char tpdu_tag, __u8* data, int asn_ slot->receivedData = new_data_buffer; memcpy(slot->receivedData + slot->receivedLen, data, asn_data_length); slot->receivedLen = new_data_length; -#if x_debug +#if y_debug printf("%s -> calling receiveData with data (len %d)\n", FILENAME, asn_data_length); for (int i = 0; i < slot->receivedLen; i++) printf("%02x ", slot->receivedData[i]); diff --git a/libdvbci/dvbci_ccmgr.cpp b/libdvbci/dvbci_ccmgr.cpp index e06d942..9024bb2 100644 --- a/libdvbci/dvbci_ccmgr.cpp +++ b/libdvbci/dvbci_ccmgr.cpp @@ -23,6 +23,10 @@ #include "dvbci_ccmgr.h" +/* for some debug > set to 1 */ +#define x_debug 0 +#define y_debug 0 + static const char * FILENAME = "[dvbci_ccmgr]"; /* storage & load of authenticated data (HostID & DHSK & AKH) */ @@ -620,9 +624,9 @@ static int sac_crypt(uint8_t *dst, const uint8_t *src, unsigned int len, const u AES_KEY key; /* AES_ENCRYPT is '1' */ - +#if x_debug printf("%s -> %s\n", FILENAME, __FUNCTION__); - +#endif if (encrypt) AES_set_encrypt_key(key_data, 128, &key); else @@ -850,9 +854,9 @@ static void check_new_key(struct cc_ctrl_data *cc_data) uint8_t *kp; uint8_t slot; unsigned int i; - +#if x_debug printf("%s -> %s\n", FILENAME, __FUNCTION__); - +#endif /* check for keyprecursor */ if (!element_valid(cc_data, 12)) return; @@ -885,7 +889,9 @@ static void check_new_key(struct cc_ctrl_data *cc_data) static int data_get_handle_new(struct cc_ctrl_data *cc_data, unsigned int id) { +#if x_debug printf("%s -> %s ID = (%d)\n", FILENAME, __FUNCTION__, id); +#endif /* handle trigger events */ /* depends on new received items */ @@ -934,8 +940,9 @@ static int data_get_handle_new(struct cc_ctrl_data *cc_data, unsigned int id) 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 */ { @@ -962,9 +969,9 @@ static int data_get_loop(struct cc_ctrl_data *cc_data, const unsigned char *data unsigned int i; int dt_id, dt_len; unsigned int pos = 0; - +#if x_debug printf("%s -> %s\n", FILENAME, __FUNCTION__); - +#endif for (i = 0; i < items; i++) { if (pos + 3 > datalen) return 0; @@ -975,9 +982,14 @@ static int data_get_loop(struct cc_ctrl_data *cc_data, const unsigned char *data if (pos + dt_len > datalen) return 0; - +#if x_debug printf("set element (%d) ", dt_id); +#if y_debug hexdump(&data[pos], dt_len); +#else + printf("\n"); +#endif +#endif element_set(cc_data, dt_id, &data[pos], dt_len); data_get_handle_new(cc_data, dt_id); @@ -994,27 +1006,32 @@ static int data_req_loop(struct cc_ctrl_data *cc_data, unsigned char *dest, cons unsigned int i; int pos = 0; int len; - +#if x_debug printf("%s -> %s\n", FILENAME, __FUNCTION__); - +#endif if (items > datalen) return -1; 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) { printf("cannot get element %d\n", dt_id); return -1; } -// +#if x_debug printf("element (%d) > ", dt_id); +#if y_debug for (int ic = 0; ic < len; ic++) printf("%02x ", dest[ic]); +#endif printf("\n"); -// +#endif + pos += len; dest += len; } @@ -1138,8 +1155,9 @@ void eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_sync_req(tSlot *tslot, int pos = 0; printf("%s -> %s\n", FILENAME, __FUNCTION__); +#if y_debug hexdump(data, len); - +#endif serial = UINT32(data, 4); pos += BYTE32(&dest[pos], serial); @@ -1173,12 +1191,12 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_send(tSlot *tslot, cons BYTE16(&data[6], pos - 8); /* len in header */ pos += sac_gen_auth(&data[pos], data, pos, cc_data->sak); -// +#if y_debug printf("Data for encrypt > "); for (unsigned int i = 0; i < pos; i++) printf("%02x ", data[i]); printf("\n"); -// +#endif sac_crypt(&data[8], &data[8], pos - 8, cc_data->sek, AES_ENCRYPT); sendAPDU(tag, data, pos); @@ -1204,12 +1222,12 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(tSlot *tslot, memcpy(tmp, data, 8); sac_crypt(&tmp[8], &data[8], len - 8, cc_data->sek, AES_DECRYPT); data = tmp; -// +#if y_debug printf("decryted > "); for (unsigned int i = 0; i < len; i++) printf("%02x ", data[i]); printf("\n"); -// +#endif if (!sac_check_auth(data, len, cc_data->sak)) { fprintf(stderr, "check_auth of message failed\n"); return false; @@ -1277,9 +1295,10 @@ void eDVBCIContentControlManagerSession::ci_ccmgr_doClose(tSlot *tslot) int eDVBCIContentControlManagerSession::receivedAPDU(const unsigned char *tag, const void *data, int len) { 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]); +#endif printf("\n"); if ((tag[0] == 0x9f) && (tag[1] == 0x90)) { diff --git a/libdvbci/dvbci_session.cpp b/libdvbci/dvbci_session.cpp index 9b95d0a..167f855 100644 --- a/libdvbci/dvbci_session.cpp +++ b/libdvbci/dvbci_session.cpp @@ -337,7 +337,7 @@ void eDVBCISession::receiveData(tSlot *slot, const unsigned char *ptr, size_t le alen = len; } - printf("1. Call receivedAPDU tag = 0x%2x, len = %d\n", (int) stag, alen); + //printf("1. Call receivedAPDU tag = 0x%2x, len = %d\n", (int) stag, alen); if (session->receivedAPDU(stag, pkt, alen)) session->action = 1;