Skip to content

Commit

Permalink
Reduce the size of the CAPMT to include only video and audio channels…
Browse files Browse the repository at this point in the history
… and only CAIDs accepted by the CAM
  • Loading branch information
Catalin Toda authored and catalinii committed Apr 14, 2023
1 parent 73a5630 commit ad7a566
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 34 deletions.
33 changes: 31 additions & 2 deletions src/ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,34 @@ void disable_cws_for_all_pmts(ca_device_t *d) {
}
}

int CAPMT_add_PMT(uint8_t *capmt, int len, SPMT *pmt, int cmd_id,
int added_only, int ca_id) {
int i = 0, pos = 0;
for (i = 0; i < pmt->stream_pids; i++) {
if (added_only && !find_pid(pmt->adapter, pmt->stream_pid[i].pid)) {
LOGM("%s: skipping pmt %d (ad %d) pid %d from CAPMT", __FUNCTION__,
pmt->id, pmt->adapter, pmt->stream_pid[i].pid);
continue;
}
if (!pmt->stream_pid[i].is_audio && !pmt->stream_pid[i].is_video)

This comment has been minimized.

Copy link
@Jalle19

Jalle19 May 11, 2023

Collaborator

I think we have a bug somewhere that causes is_audio to sometimes be false even for audio streams, leading to missing audio.

This comment has been minimized.

Copy link
@catalinii

catalinii May 11, 2023

Owner

Did you notice missing audio?

This comment has been minimized.

Copy link
@Jalle19

Jalle19 May 11, 2023

Collaborator

Yes, but it happens even after reverting this. Seems to be related to dvbapi and oscam somehow (DEC-ERRORS keeps rising). It's like the audio PIDs aren't getting decrypted.

This comment has been minimized.

Copy link
@catalinii

catalinii May 11, 2023

Owner

Does it show any CW when 'found CW' is reported with -l pmt.

continue;
capmt[pos++] = pmt->stream_pid[i].type;
copy16(capmt, pos, pmt->stream_pid[i].pid);
pos += 2;
int pi_len_pos = pos, pi_len = 0;
pos += 2;

// append the stream descriptors
if (pmt->caids) {
capmt[pos++] = cmd_id;
pi_len = pmt_add_ca_descriptor(pmt, capmt + pos, ca_id);
pos += pi_len;
}
copy16(capmt, pi_len_pos, pi_len + 1);
}
return pos;
}

int create_capmt(SCAPMT *ca, int listmgmt, uint8_t *capmt, int capmt_len,
int cmd_id, int added_only) {
int pos = 0;
Expand All @@ -297,10 +325,11 @@ int create_capmt(SCAPMT *ca, int listmgmt, uint8_t *capmt, int capmt_len,
capmt[pos++] = 0; // PI LEN 2 bytes, set 0
capmt[pos++] = 0;

pos += CAPMT_add_PMT(capmt + pos, capmt_len - pos, pmt, cmd_id, added_only);
pos += CAPMT_add_PMT(capmt + pos, capmt_len - pos, pmt, cmd_id, added_only,
dvbca_id);
if (other) {
pos += CAPMT_add_PMT(capmt + pos, capmt_len - pos, other, cmd_id,
added_only);
added_only, dvbca_id);
}

return pos;
Expand Down
3 changes: 2 additions & 1 deletion src/dvbapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ int dvbapi_send_pmt(SKey *k, int cmd_id) {
copy16(buf, 23, 0x8701); // ca_device_descriptor (caX)
buf[25] = demux;

len = 26 + pmt_add_ca_descriptor(pmt, buf + 26); // CA description
len =
26 + pmt_add_ca_descriptor(pmt, buf + 26, dvbapi_ca); // CA description

// Pids associated with the PMT
copy16(buf, 10, len - 12);
Expand Down
36 changes: 8 additions & 28 deletions src/pmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2313,10 +2313,16 @@ int pmt_tune(adapter *ad) {
return 0;
}

int pmt_add_ca_descriptor(SPMT *pmt, uint8_t *buf) {
int pmt_add_ca_descriptor(SPMT *pmt, uint8_t *buf, int ca_id) {
int i, len = 0;
for (i = 0; i < pmt->caids; i++) {
int private_data_len = pmt->ca[i].private_data_len;
#ifndef DISABLE_TABLES

This comment has been minimized.

Copy link
@Jalle19

Jalle19 Apr 15, 2023

Collaborator

Should we consider removing DISABLE_TABLES? Does it actually make sense anymore?

This comment has been minimized.

Copy link
@catalinii

catalinii Apr 15, 2023

Owner

Generally TABLES provides decrypting support, while PMT offers channel names. I think for AXE your build has one but not the other.
If it makes sense for AXE we can do it... there are just less and less devices with less cpu/memory resources

This comment has been minimized.

Copy link
@Jalle19

Jalle19 Apr 15, 2023

Collaborator

The satip-axe builds has PMT support nowadays.

This comment has been minimized.

Copy link
@catalinii

catalinii Apr 15, 2023

Owner

Has both as I can see (tables + pmt).

if (!match_ca_caid(ca_id, pmt->adapter, pmt->ca[i].id)){
LOGM("SCA %d cannot handle CAID %04X, skipping", ca_id, pmt->ca[i].id);

This comment has been minimized.

Copy link
@Jalle19

Jalle19 Apr 15, 2023

Collaborator

Why SCA and not just CA? Typo?

This comment has been minimized.

Copy link
@catalinii

catalinii Apr 15, 2023

Owner

CA is generally for a CAM....just to avoid confusion.

continue;
}
#endif
int private_data_len = pmt->ca[i].private_data_len;
buf[len] = 0x09;
buf[len + 1] = 0x04 + private_data_len;
copy16(buf, len + 2, pmt->ca[i].id);
Expand All @@ -2329,32 +2335,6 @@ int pmt_add_ca_descriptor(SPMT *pmt, uint8_t *buf) {
return len;
}

int CAPMT_add_PMT(uint8_t *capmt, int len, SPMT *pmt, int cmd_id,
int added_only) {
int i = 0, pos = 0;
for (i = 0; i < pmt->stream_pids; i++) {
if (added_only && !find_pid(pmt->adapter, pmt->stream_pid[i].pid)) {
LOGM("%s: skipping pmt %d (ad %d) pid %d from CAPMT", __FUNCTION__,
pmt->id, pmt->adapter, pmt->stream_pid[i].pid);
continue;
}
capmt[pos++] = pmt->stream_pid[i].type;
copy16(capmt, pos, pmt->stream_pid[i].pid);
pos += 2;
int pi_len_pos = pos, pi_len = 0;
pos += 2;

// append the stream descriptors
if (pmt->caids) {
capmt[pos++] = cmd_id;
pi_len = pmt_add_ca_descriptor(pmt, capmt + pos);
pos += pi_len;
}
copy16(capmt, pi_len_pos, pi_len + 1);
}
return pos;
}

char *get_channel_for_adapter(int aid, char *dest, int max_size) {
int i, pos = 0;
adapter *ad;
Expand Down
4 changes: 1 addition & 3 deletions src/pmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,13 @@ int assemble_packet(SFilter *f, uint8_t *b);
int clean_psi_buffer(uint8_t *pmt, uint8_t *clean, int clean_size);
void disable_cw(int master_pmt);
void expire_cw_for_pmt(int master_pmt, int parity, int64_t min_expiry);
int CAPMT_add_PMT(uint8_t *capmt, int len, SPMT *pmt, int cmd_id,
int added_only);
int pmt_add(int i, int adapter, int sid, int pmt_pid);
int test_decrypt_packet(SCW *cw, SPMT_batch *start, int len);
void init_algo();
void update_cw(SPMT *pmt);
int pmt_decrypt_stream(adapter *ad);
int wait_pusi(adapter *ad, int len);
int pmt_add_ca_descriptor(SPMT *pmt, uint8_t *buf);
int pmt_add_ca_descriptor(SPMT *pmt, uint8_t *buf, int sca_id);
void free_filters();
void stop_pmt(SPMT *pmt, adapter *ad);
#endif
10 changes: 10 additions & 0 deletions src/tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ int match_caid(SPMT *pmt, int caid, int mask) {
return 0;
}

// return 1 if CA can handle this specific CAID on the specified adapter
int match_ca_caid(int ica, int aid, int caid) {
int i;
for (i = 0; i < ca[ica].ad_info[aid].caids; i++)
if (ca[ica].ad_info[aid].caid[i] ==
(caid & ca[ica].ad_info[aid].mask[i]))
return 1;
return 0;
}

void close_pmt_for_ca(int i, adapter *ad, SPMT *pmt) {
uint64_t mask = 1ULL << i;
if (!ad)
Expand Down
1 change: 1 addition & 0 deletions src/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void close_pmt_for_ca(int i, adapter *ad, SPMT *pmt);
int close_pmt_for_cas(adapter *ad, SPMT *pmt);
void tables_ca_ts(adapter *ad);
int match_caid(SPMT *pmt, int caid, int mask);
int match_ca_caid(int ica, int aid, int caid);
void tables_update_encrypted_status(adapter *ad, SPMT *pmt);

#endif
Expand Down

0 comments on commit ad7a566

Please sign in to comment.