vdr  2.4.0
ci.c
Go to the documentation of this file.
1 /*
2  * ci.c: Common Interface
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: ci.c 4.21 2018/03/19 16:37:03 kls Exp $
8  */
9 
10 #include "ci.h"
11 #include <ctype.h>
12 #include <linux/dvb/ca.h>
13 #include <malloc.h>
14 #include <netinet/in.h>
15 #include <poll.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <sys/ioctl.h>
19 #include <time.h>
20 #include <unistd.h>
21 #include "device.h"
22 #include "mtd.h"
23 #include "pat.h"
24 #include "receiver.h"
25 #include "remux.h"
26 #include "libsi/si.h"
27 #include "skins.h"
28 #include "tools.h"
29 
30 // Set these to 'true' for debug output:
31 static bool DumpTPDUDataTransfer = false;
32 static bool DebugProtocol = false;
33 static bool DumpPolls = false;
34 static bool DumpDateTime = false;
35 
36 #define dbgprotocol(a...) if (DebugProtocol) fprintf(stderr, a)
37 
38 // --- Helper functions ------------------------------------------------------
39 
40 #define SIZE_INDICATOR 0x80
41 
42 static const uint8_t *GetLength(const uint8_t *Data, int &Length)
46 {
47  Length = *Data++;
48  if ((Length & SIZE_INDICATOR) != 0) {
49  int l = Length & ~SIZE_INDICATOR;
50  Length = 0;
51  for (int i = 0; i < l; i++)
52  Length = (Length << 8) | *Data++;
53  }
54  return Data;
55 }
56 
57 static uint8_t *SetLength(uint8_t *Data, int Length)
60 {
61  uint8_t *p = Data;
62  if (Length < 128)
63  *p++ = Length;
64  else {
65  int n = sizeof(Length);
66  for (int i = n - 1; i >= 0; i--) {
67  int b = (Length >> (8 * i)) & 0xFF;
68  if (p != Data || b)
69  *++p = b;
70  }
71  *Data = (p - Data) | SIZE_INDICATOR;
72  p++;
73  }
74  return p;
75 }
76 
77 static char *CopyString(int Length, const uint8_t *Data)
80 {
81  char *s = MALLOC(char, Length + 1);
82  char *p = s;
83  while (Length > 0) {
84  char c = *Data;
85  if (isprint(c)) // some CAMs send funny characters in their strings, let's just skip them
86  *p++ = c;
87  else if (c == 0x8A) // the character 0x8A is used as newline, so let's put a real '\n' in there
88  *p++ = '\n';
89  Length--;
90  Data++;
91  }
92  *p = 0;
93  return s;
94 }
95 
96 static char *GetString(int &Length, const uint8_t **Data)
100 {
101  if (Length > 0 && Data && *Data) {
102  int l = 0;
103  const uint8_t *d = GetLength(*Data, l);
104  char *s = CopyString(l, d);
105  Length -= d - *Data + l;
106  *Data = d + l;
107  return s;
108  }
109  return NULL;
110 }
111 
112 // --- cCaPidReceiver --------------------------------------------------------
113 
114 // A receiver that is used to make the device receive the ECM pids, as well as the
115 // CAT and the EMM pids.
116 
117 class cCaPidReceiver : public cReceiver {
118 private:
121  uchar buffer[2048]; // 11 bit length, max. 2048 byte
123  uchar mtdCatBuffer[TS_SIZE]; // TODO: handle multi packet CATs!
124  int length;
127  void AddEmmPid(int Pid);
128  void DelEmmPids(void);
129 public:
130  cCaPidReceiver(void);
131  virtual ~cCaPidReceiver() { Detach(); }
132  virtual void Receive(const uchar *Data, int Length);
133  bool HasCaPids(void) const { return NumPids() - emmPids.Size() - 1 > 0; }
134  void Reset(void) { DelEmmPids(); catVersion = -1; }
135  bool HandlingPid(void);
144  };
145 
147 {
148  catVersion = -1;
149  bufp = NULL;
150  length = 0;
151  handlingPid = false;
152  cMutexLock MutexLock(&mutex);
153  handlingPid = true;
154  AddPid(CATPID);
155  handlingPid = false;
156 }
157 
159 {
160  for (int i = 0; i < emmPids.Size(); i++) {
161  if (emmPids[i] == Pid)
162  return;
163  }
164  emmPids.Append(Pid);
165  cMutexLock MutexLock(&mutex);
166  handlingPid = true;
167  AddPid(Pid);
168  handlingPid = false;
169 }
170 
172 {
173  cMutexLock MutexLock(&mutex);
174  handlingPid = true;
175  for (int i = 0; i < emmPids.Size(); i++)
176  DelPid(emmPids[i]);
177  emmPids.Clear();
178  handlingPid = false;
179 }
180 
181 void cCaPidReceiver::Receive(const uchar *Data, int Length)
182 {
183  if (TsPid(Data) == CATPID) {
184  cMtdCamSlot *MtdCamSlot = dynamic_cast<cMtdCamSlot *>(Device()->CamSlot());
185  const uchar *p = NULL;
186  if (TsPayloadStart(Data)) {
187  if (Data[5] == SI::TableIdCAT) {
188  length = (int(Data[6] & 0x03) << 8) | Data[7]; // section length
189  if (length > 5) {
190  int v = (Data[10] & 0x3E) >> 1; // version number
191  if (v != catVersion) {
192  if (Data[11] == 0 && Data[12] == 0) { // section number, last section number
193  if (length > TS_SIZE - 8) {
194  if (MtdCamSlot)
195  esyslog("ERROR: need to implement multi packet CAT handling for MTD!");
196  int n = TS_SIZE - 13;
197  memcpy(buffer, Data + 13, n);
198  bufp = buffer + n;
199  length -= n + 5; // 5 = header
200  }
201  else {
202  p = Data + 13; // no need to copy the data
203  length -= 5; // header
204  }
205  }
206  else
207  dsyslog("multi table CAT section - unhandled!");
208  catVersion = v;
209  }
210  else if (MtdCamSlot)
211  MtdCamSlot->PutCat(mtdCatBuffer, TS_SIZE);
212  }
213  }
214  }
215  else if (bufp && length > 0) {
216  int n = min(length, TS_SIZE - 4);
217  if (bufp + n - buffer <= int(sizeof(buffer))) {
218  memcpy(bufp, Data + 4, n);
219  bufp += n;
220  length -= n;
221  if (length <= 0) {
222  p = buffer;
223  length = bufp - buffer;
224  }
225  }
226  else {
227  esyslog("ERROR: buffer overflow in cCaPidReceiver::Receive()");
228  bufp = 0;
229  length = 0;
230  }
231  }
232  if (p) {
233  DelEmmPids();
234  for (int i = 0; i < length - 4; i++) { // -4 = checksum
235  if (p[i] == 0x09) {
236  int CaId = int(p[i + 2] << 8) | p[i + 3];
237  int EmmPid = Peek13(p + i + 4);
238  AddEmmPid(EmmPid);
239  if (MtdCamSlot)
240  MtdMapPid(const_cast<uchar *>(p + i + 4), MtdCamSlot->MtdMapper());
241  switch (CaId >> 8) {
242  case 0x01: for (int j = i + 7; j < p[i + 1] + 2; j += 4) {
243  EmmPid = Peek13(p + j);
244  AddEmmPid(EmmPid);
245  if (MtdCamSlot)
246  MtdMapPid(const_cast<uchar *>(p + j), MtdCamSlot->MtdMapper());
247  }
248  break;
249  }
250  i += p[i + 1] + 2 - 1; // -1 to compensate for the loop increment
251  }
252  }
253  p = NULL;
254  bufp = 0;
255  length = 0;
256  memcpy(mtdCatBuffer, Data, TS_SIZE);
257  if (MtdCamSlot)
258  MtdCamSlot->PutCat(mtdCatBuffer, TS_SIZE);
259  }
260  }
261 }
262 
264 {
265  cMutexLock MutexLock(&mutex);
266  return handlingPid;
267 }
268 
269 // --- cCaActivationReceiver -------------------------------------------------
270 
271 // A receiver that is used to make the device stay on a given channel and
272 // keep the CAM slot assigned.
273 
274 #define UNSCRAMBLE_TIME 5 // seconds of receiving purely unscrambled data before considering the smart card "activated"
275 #define TS_PACKET_FACTOR 1024 // only process every TS_PACKET_FACTORth packet to keep the load down
276 
278 private:
282 protected:
283  virtual void Receive(const uchar *Data, int Length);
284 public:
285  cCaActivationReceiver(const cChannel *Channel, cCamSlot *CamSlot);
286  virtual ~cCaActivationReceiver();
287  };
288 
290 :cReceiver(Channel, MINPRIORITY + 1)
291 {
292  camSlot = CamSlot;
293  lastScrambledTime = time(NULL);
294  numTsPackets = 0;
295 }
296 
298 {
299  Detach();
300 }
301 
302 void cCaActivationReceiver::Receive(const uchar *Data, int Length)
303 {
304  if (numTsPackets++ % TS_PACKET_FACTOR == 0) {
305  time_t Now = time(NULL);
306  if (TsIsScrambled(Data))
307  lastScrambledTime = Now;
308  else if (Now - lastScrambledTime > UNSCRAMBLE_TIME) {
309  dsyslog("CAM %d: activated!", camSlot->MasterSlotNumber());
310  Skins.QueueMessage(mtInfo, tr("CAM activated!"));
311  cDevice *d = Device();
312  Detach();
313  if (d) {
314  if (cCamSlot *s = d->CamSlot())
315  s->CancelActivation(); // this will delete *this* object, so no more code referencing *this* after this call!
316  }
317  }
318  }
319 }
320 
321 // --- cCamResponse ----------------------------------------------------------
322 
323 // CAM Response Actions:
324 
325 #define CRA_NONE 0
326 #define CRA_DISCARD -1
327 #define CRA_CONFIRM -2
328 #define CRA_SELECT -3
329 
330 class cCamResponse : public cListObject {
331 private:
333  char *text;
334  int action;
335 public:
336  cCamResponse(void);
337  ~cCamResponse();
338  bool Parse(const char *s);
339  int Matches(int CamNumber, const char *Text) const;
340  };
341 
343 {
344  camNumber = -1;
345  text = NULL;
346  action = CRA_NONE;
347 }
348 
350 {
351  free(text);
352 }
353 
354 bool cCamResponse::Parse(const char *s)
355 {
356  // Number:
357  s = skipspace(s);
358  if (*s == '*') {
359  camNumber = 0; // all CAMs
360  s++;
361  }
362  else {
363  char *e;
364  camNumber = strtol(s, &e, 10);
365  if (e == s || camNumber <= 0)
366  return false;
367  s = e;
368  }
369  // Text:
370  s = skipspace(s);
371  char *t = const_cast<char *>(s); // might have to modify it
372  char *q = NULL; // holds a copy in case of backslashes
373  bool InQuotes = false;
374  while (*t) {
375  if (*t == '"') {
376  if (t == s) { // opening quotes
377  InQuotes = true;
378  s++;
379  }
380  else if (InQuotes) // closing quotes
381  break;
382  }
383  else if (*t == '\\') {
384  if (!q) { // need to make a copy in order to strip backslashes
385  q = strdup(s);
386  t = q + (t - s);
387  s = q;
388  }
389  memmove(t, t + 1, strlen(t));
390  }
391  else if (*t == ' ') {
392  if (!InQuotes)
393  break;
394  }
395  t++;
396  }
397  free(text); // just for safety
398  text = NULL;
399  if (t != s) {
400  text = strndup(s, t - s);
401  s = t + 1;
402  }
403  free(q);
404  if (!text)
405  return false;
406  // Action:
407  s = skipspace(s);
408  if (strcasecmp(s, "DISCARD") == 0) action = CRA_DISCARD;
409  else if (strcasecmp(s, "CONFIRM") == 0) action = CRA_CONFIRM;
410  else if (strcasecmp(s, "SELECT") == 0) action = CRA_SELECT;
411  else if (isnumber(s)) action = atoi(s);
412  else
413  return false;
414  return true;
415 }
416 
417 int cCamResponse::Matches(int CamNumber, const char *Text) const
418 {
419  if (!camNumber || camNumber == CamNumber) {
420  if (strcmp(text, Text) == 0)
421  return action;
422  }
423  return CRA_NONE;
424 }
425 
426 // --- cCamResponses --------------------------------------------------------
427 
428 class cCamResponses : public cConfig<cCamResponse> {
429 public:
430  int GetMatch(int CamNumber, const char *Text) const;
431  };
432 
433 int cCamResponses::GetMatch(int CamNumber, const char *Text) const
434 {
435  for (const cCamResponse *cr = First(); cr; cr = Next(cr)) {
436  int Action = cr->Matches(CamNumber, Text);
437  if (Action != CRA_NONE) {
438  dsyslog("CAM %d: auto response %4d to '%s'\n", CamNumber, Action, Text);
439  return Action;
440  }
441  }
442  return CRA_NONE;
443 }
444 
446 
447 bool CamResponsesLoad(const char *FileName, bool AllowComments, bool MustExist)
448 {
449  return CamResponses.Load(FileName, AllowComments, MustExist);
450 }
451 
452 // --- cTPDU -----------------------------------------------------------------
453 
454 #define MAX_TPDU_SIZE 4096
455 #define MAX_TPDU_DATA (MAX_TPDU_SIZE - 4)
456 
457 #define DATA_INDICATOR 0x80
458 
459 #define T_SB 0x80
460 #define T_RCV 0x81
461 #define T_CREATE_TC 0x82
462 #define T_CTC_REPLY 0x83
463 #define T_DELETE_TC 0x84
464 #define T_DTC_REPLY 0x85
465 #define T_REQUEST_TC 0x86
466 #define T_NEW_TC 0x87
467 #define T_TC_ERROR 0x88
468 #define T_DATA_LAST 0xA0
469 #define T_DATA_MORE 0xA1
470 
471 class cTPDU {
472 private:
473  int size;
475  const uint8_t *GetData(const uint8_t *Data, int &Length);
476 public:
477  cTPDU(void) { size = 0; }
478  cTPDU(uint8_t Slot, uint8_t Tcid, uint8_t Tag, int Length = 0, const uint8_t *Data = NULL);
479  uint8_t Slot(void) { return buffer[0]; }
480  uint8_t Tcid(void) { return buffer[1]; }
481  uint8_t Tag(void) { return buffer[2]; }
482  const uint8_t *Data(int &Length) { return GetData(buffer + 3, Length); }
483  uint8_t Status(void);
484  uint8_t *Buffer(void) { return buffer; }
485  int Size(void) { return size; }
486  void SetSize(int Size) { size = Size; }
487  int MaxSize(void) { return sizeof(buffer); }
488  void Dump(int SlotNumber, bool Outgoing);
489  };
490 
491 cTPDU::cTPDU(uint8_t Slot, uint8_t Tcid, uint8_t Tag, int Length, const uint8_t *Data)
492 {
493  size = 0;
494  buffer[0] = Slot;
495  buffer[1] = Tcid;
496  buffer[2] = Tag;
497  switch (Tag) {
498  case T_RCV:
499  case T_CREATE_TC:
500  case T_CTC_REPLY:
501  case T_DELETE_TC:
502  case T_DTC_REPLY:
503  case T_REQUEST_TC:
504  buffer[3] = 1; // length
505  buffer[4] = Tcid;
506  size = 5;
507  break;
508  case T_NEW_TC:
509  case T_TC_ERROR:
510  if (Length == 1) {
511  buffer[3] = 2; // length
512  buffer[4] = Tcid;
513  buffer[5] = Data[0];
514  size = 6;
515  }
516  else
517  esyslog("ERROR: invalid data length for TPDU tag 0x%02X: %d (%d/%d)", Tag, Length, Slot, Tcid);
518  break;
519  case T_DATA_LAST:
520  case T_DATA_MORE:
521  if (Length <= MAX_TPDU_DATA) {
522  uint8_t *p = buffer + 3;
523  p = SetLength(p, Length + 1);
524  *p++ = Tcid;
525  if (Length)
526  memcpy(p, Data, Length);
527  size = Length + (p - buffer);
528  }
529  else
530  esyslog("ERROR: invalid data length for TPDU tag 0x%02X: %d (%d/%d)", Tag, Length, Slot, Tcid);
531  break;
532  default:
533  esyslog("ERROR: unknown TPDU tag: 0x%02X (%d/%d)", Tag, Slot, Tcid);
534  }
535  }
536 
537 void cTPDU::Dump(int SlotNumber, bool Outgoing)
538 {
539  if (DumpTPDUDataTransfer && (DumpPolls || Tag() != T_SB)) {
540 #define MAX_DUMP 256
541  fprintf(stderr, " %d: %s ", SlotNumber, Outgoing ? "-->" : "<--");
542  for (int i = 0; i < size && i < MAX_DUMP; i++)
543  fprintf(stderr, "%02X ", buffer[i]);
544  fprintf(stderr, "%s\n", size >= MAX_DUMP ? "..." : "");
545  if (!Outgoing) {
546  fprintf(stderr, " ");
547  for (int i = 0; i < size && i < MAX_DUMP; i++)
548  fprintf(stderr, "%2c ", isprint(buffer[i]) ? buffer[i] : '.');
549  fprintf(stderr, "%s\n", size >= MAX_DUMP ? "..." : "");
550  }
551  }
552 }
553 
554 const uint8_t *cTPDU::GetData(const uint8_t *Data, int &Length)
555 {
556  if (size) {
557  Data = GetLength(Data, Length);
558  if (Length) {
559  Length--; // the first byte is always the tcid
560  return Data + 1;
561  }
562  }
563  return NULL;
564 }
565 
566 uint8_t cTPDU::Status(void)
567 {
568  if (size >= 4 && buffer[size - 4] == T_SB && buffer[size - 3] == 2)
569  return buffer[size - 1];
570  return 0;
571 }
572 
573 // --- cCiTransportConnection ------------------------------------------------
574 
575 #define MAX_SESSIONS_PER_TC 16
576 
578 private:
581  uint8_t tcid;
585  bool hasUserIO;
588  cCiSession *sessions[MAX_SESSIONS_PER_TC + 1]; // session numbering starts with 1
590  void SendTPDU(uint8_t Tag, int Length = 0, const uint8_t *Data = NULL);
591  void SendTag(uint8_t Tag, uint16_t SessionId, uint32_t ResourceId = 0, int Status = -1);
592  void Poll(void);
593  uint32_t ResourceIdToInt(const uint8_t *Data);
594  cCiSession *GetSessionBySessionId(uint16_t SessionId);
595  void OpenSession(int Length, const uint8_t *Data);
596  void CloseSession(uint16_t SessionId);
597  void HandleSessions(cTPDU *TPDU);
598 public:
600  virtual ~cCiTransportConnection();
601  void SetTsPostProcessor(cCiSession *CiSession);
602  bool TsPostProcess(uint8_t *TsPacket);
603  cCamSlot *CamSlot(void) { return camSlot; }
604  uint8_t Tcid(void) const { return tcid; }
607  const char *GetCamName(void);
608  bool Ready(void);
609  bool HasUserIO(void) { return hasUserIO; }
610  void SendData(int Length, const uint8_t *Data);
611  bool Process(cTPDU *TPDU = NULL);
612  cCiSession *GetSessionByResourceId(uint32_t ResourceId);
613  };
614 
615 // --- cCiSession ------------------------------------------------------------
616 
617 // Session Tags:
618 
619 #define ST_SESSION_NUMBER 0x90
620 #define ST_OPEN_SESSION_REQUEST 0x91
621 #define ST_OPEN_SESSION_RESPONSE 0x92
622 #define ST_CREATE_SESSION 0x93
623 #define ST_CREATE_SESSION_RESPONSE 0x94
624 #define ST_CLOSE_SESSION_REQUEST 0x95
625 #define ST_CLOSE_SESSION_RESPONSE 0x96
626 
627 // Session Status:
628 
629 #define SS_OK 0x00
630 #define SS_NOT_ALLOCATED 0xF0
631 
632 // Resource Identifiers:
633 
634 #define RI_RESOURCE_MANAGER 0x00010041
635 #define RI_APPLICATION_INFORMATION 0x00020041
636 #define RI_CONDITIONAL_ACCESS_SUPPORT 0x00030041
637 #define RI_HOST_CONTROL 0x00200041
638 #define RI_DATE_TIME 0x00240041
639 #define RI_MMI 0x00400041
640 
641 // Application Object Tags:
642 
643 #define AOT_NONE 0x000000
644 #define AOT_PROFILE_ENQ 0x9F8010
645 #define AOT_PROFILE 0x9F8011
646 #define AOT_PROFILE_CHANGE 0x9F8012
647 #define AOT_APPLICATION_INFO_ENQ 0x9F8020
648 #define AOT_APPLICATION_INFO 0x9F8021
649 #define AOT_ENTER_MENU 0x9F8022
650 #define AOT_CA_INFO_ENQ 0x9F8030
651 #define AOT_CA_INFO 0x9F8031
652 #define AOT_CA_PMT 0x9F8032
653 #define AOT_CA_PMT_REPLY 0x9F8033
654 #define AOT_TUNE 0x9F8400
655 #define AOT_REPLACE 0x9F8401
656 #define AOT_CLEAR_REPLACE 0x9F8402
657 #define AOT_ASK_RELEASE 0x9F8403
658 #define AOT_DATE_TIME_ENQ 0x9F8440
659 #define AOT_DATE_TIME 0x9F8441
660 #define AOT_CLOSE_MMI 0x9F8800
661 #define AOT_DISPLAY_CONTROL 0x9F8801
662 #define AOT_DISPLAY_REPLY 0x9F8802
663 #define AOT_TEXT_LAST 0x9F8803
664 #define AOT_TEXT_MORE 0x9F8804
665 #define AOT_KEYPAD_CONTROL 0x9F8805
666 #define AOT_KEYPRESS 0x9F8806
667 #define AOT_ENQ 0x9F8807
668 #define AOT_ANSW 0x9F8808
669 #define AOT_MENU_LAST 0x9F8809
670 #define AOT_MENU_MORE 0x9F880A
671 #define AOT_MENU_ANSW 0x9F880B
672 #define AOT_LIST_LAST 0x9F880C
673 #define AOT_LIST_MORE 0x9F880D
674 #define AOT_SUBTITLE_SEGMENT_LAST 0x9F880E
675 #define AOT_SUBTITLE_SEGMENT_MORE 0x9F880F
676 #define AOT_DISPLAY_MESSAGE 0x9F8810
677 #define AOT_SCENE_END_MARK 0x9F8811
678 #define AOT_SCENE_DONE 0x9F8812
679 #define AOT_SCENE_CONTROL 0x9F8813
680 #define AOT_SUBTITLE_DOWNLOAD_LAST 0x9F8814
681 #define AOT_SUBTITLE_DOWNLOAD_MORE 0x9F8815
682 #define AOT_FLUSH_DOWNLOAD 0x9F8816
683 #define AOT_DOWNLOAD_REPLY 0x9F8817
684 #define AOT_COMMS_CMD 0x9F8C00
685 #define AOT_CONNECTION_DESCRIPTOR 0x9F8C01
686 #define AOT_COMMS_REPLY 0x9F8C02
687 #define AOT_COMMS_SEND_LAST 0x9F8C03
688 #define AOT_COMMS_SEND_MORE 0x9F8C04
689 #define AOT_COMMS_RCV_LAST 0x9F8C05
690 #define AOT_COMMS_RCV_MORE 0x9F8C06
691 
692 #define RESOURCE_CLASS_MASK 0xFFFF0000
693 
694 cCiSession::cCiSession(uint16_t SessionId, uint32_t ResourceId, cCiTransportConnection *Tc)
695 {
698  tc = Tc;
699 }
700 
702 {
703 }
704 
705 void cCiSession::SetResourceId(uint32_t Id)
706 {
707  resourceId = Id;
708 }
709 
711 {
712  tc->SetTsPostProcessor(this);
713 }
714 
715 int cCiSession::GetTag(int &Length, const uint8_t **Data)
719 {
720  if (Length >= 3 && Data && *Data) {
721  int t = 0;
722  for (int i = 0; i < 3; i++)
723  t = (t << 8) | *(*Data)++;
724  Length -= 3;
725  return t;
726  }
727  return AOT_NONE;
728 }
729 
730 const uint8_t *cCiSession::GetData(const uint8_t *Data, int &Length)
731 {
732  Data = GetLength(Data, Length);
733  return Length ? Data : NULL;
734 }
735 
736 void cCiSession::SendData(int Tag, int Length, const uint8_t *Data)
737 {
738  uint8_t buffer[MAX_TPDU_SIZE];
739  uint8_t *p = buffer;
740  *p++ = ST_SESSION_NUMBER;
741  *p++ = 0x02;
742  *p++ = (sessionId >> 8) & 0xFF;
743  *p++ = sessionId & 0xFF;
744  *p++ = (Tag >> 16) & 0xFF;
745  *p++ = (Tag >> 8) & 0xFF;
746  *p++ = Tag & 0xFF;
747  p = SetLength(p, Length);
748  if (p - buffer + Length < int(sizeof(buffer))) {
749  if (Data)
750  memcpy(p, Data, Length);
751  p += Length;
752  tc->SendData(p - buffer, buffer);
753  }
754  else
755  esyslog("ERROR: CAM %d: data length (%d) exceeds buffer size", CamSlot()->SlotNumber(), Length);
756 }
757 
759 {
760  return Tc()->CamSlot();
761 }
762 
763 void cCiSession::Process(int Length, const uint8_t *Data)
764 {
765 }
766 
767 // --- cCiResourceManager ----------------------------------------------------
768 
770 private:
771  int state;
772 public:
774  virtual void Process(int Length = 0, const uint8_t *Data = NULL);
775  };
776 
778 :cCiSession(SessionId, RI_RESOURCE_MANAGER, Tc)
779 {
780  dbgprotocol("Slot %d: new Resource Manager (session id %d)\n", CamSlot()->SlotNumber(), SessionId);
781  state = 0;
782 }
783 
784 void cCiResourceManager::Process(int Length, const uint8_t *Data)
785 {
786  if (Data) {
787  int Tag = GetTag(Length, &Data);
788  switch (Tag) {
789  case AOT_PROFILE_ENQ: {
790  dbgprotocol("Slot %d: <== Profile Enquiry (%d)\n", CamSlot()->SlotNumber(), SessionId());
791  dbgprotocol("Slot %d: ==> Profile (%d)\n", CamSlot()->SlotNumber(), SessionId());
792  SendData(AOT_PROFILE, CiResourceHandlers.NumIds() * sizeof(uint32_t), (uint8_t*)CiResourceHandlers.Ids());
793  state = 3;
794  }
795  break;
796  case AOT_PROFILE: {
797  dbgprotocol("Slot %d: <== Profile (%d)\n", CamSlot()->SlotNumber(), SessionId());
798  if (state == 1) {
799  int l = 0;
800  const uint8_t *d = GetData(Data, l);
801  if (l > 0 && d)
802  esyslog("ERROR: CAM %d: resource manager: unexpected data", CamSlot()->SlotNumber());
803  dbgprotocol("Slot %d: ==> Profile Change (%d)\n", CamSlot()->SlotNumber(), SessionId());
805  state = 2;
806  }
807  else {
808  esyslog("ERROR: CAM %d: resource manager: unexpected tag %06X in state %d", CamSlot()->SlotNumber(), Tag, state);
809  }
810  }
811  break;
812  default: esyslog("ERROR: CAM %d: resource manager: unknown tag %06X", CamSlot()->SlotNumber(), Tag);
813  }
814  }
815  else if (state == 0) {
816  dbgprotocol("Slot %d: ==> Profile Enq (%d)\n", CamSlot()->SlotNumber(), SessionId());
818  state = 1;
819  }
820 }
821 
822 // --- cCiApplicationInformation ---------------------------------------------
823 
825 :cCiSession(SessionId, RI_APPLICATION_INFORMATION, Tc)
826 {
827  dbgprotocol("Slot %d: new Application Information (session id %d)\n", CamSlot()->SlotNumber(), SessionId);
828  state = 0;
829  menuString = NULL;
830 }
831 
833 {
834  free(menuString);
835 }
836 
837 void cCiApplicationInformation::Process(int Length, const uint8_t *Data)
838 {
839  if (Data) {
840  int Tag = GetTag(Length, &Data);
841  switch (Tag) {
842  case AOT_APPLICATION_INFO: {
843  dbgprotocol("Slot %d: <== Application Info (%d)\n", CamSlot()->SlotNumber(), SessionId());
844  int l = 0;
845  const uint8_t *d = GetData(Data, l);
846  if ((l -= 1) < 0) break;
847  applicationType = *d++;
848  if ((l -= 2) < 0) break;
849  applicationManufacturer = ntohs(get_unaligned((uint16_t *)d));
850  d += 2;
851  if ((l -= 2) < 0) break;
852  manufacturerCode = ntohs(get_unaligned((uint16_t *)d));
853  d += 2;
854  free(menuString);
855  menuString = GetString(l, &d);
856  isyslog("CAM %d: %s, %02X, %04X, %04X", CamSlot()->SlotNumber(), menuString, applicationType, applicationManufacturer, manufacturerCode);
857  state = 2;
858  }
859  break;
860  default: esyslog("ERROR: CAM %d: application information: unknown tag %06X", CamSlot()->SlotNumber(), Tag);
861  }
862  }
863  else if (state == 0) {
864  dbgprotocol("Slot %d: ==> Application Info Enq (%d)\n", CamSlot()->SlotNumber(), SessionId());
866  state = 1;
867  }
868 }
869 
871 {
872  if (state == 2) {
873  dbgprotocol("Slot %d: ==> Enter Menu (%d)\n", CamSlot()->SlotNumber(), SessionId());
875  return true;
876  }
877  return false;
878 }
879 
880 // --- cCiCaPmt --------------------------------------------------------------
881 
882 #define MAXCASYSTEMIDS 64
883 
884 // Ca Pmt List Management:
885 
886 #define CPLM_MORE 0x00
887 #define CPLM_FIRST 0x01
888 #define CPLM_LAST 0x02
889 #define CPLM_ONLY 0x03
890 #define CPLM_ADD 0x04
891 #define CPLM_UPDATE 0x05
892 
893 // Ca Pmt Cmd Ids:
894 
895 #define CPCI_OK_DESCRAMBLING 0x01
896 #define CPCI_OK_MMI 0x02
897 #define CPCI_QUERY 0x03
898 #define CPCI_NOT_SELECTED 0x04
899 
900 class cCiCaPmt {
902 private:
903  uint8_t cmdId;
907  int source;
910  int caSystemIds[MAXCASYSTEMIDS + 1]; // list is zero terminated!
911  void AddCaDescriptors(int Length, const uint8_t *Data);
912 public:
913  cCiCaPmt(uint8_t CmdId, int Source, int Transponder, int ProgramNumber, const int *CaSystemIds);
914  uint8_t CmdId(void) { return cmdId; }
915  void SetListManagement(uint8_t ListManagement);
916  uint8_t ListManagement(void) { return capmt.Get(0); }
917  void AddPid(int Pid, uint8_t StreamType);
918  void MtdMapPids(cMtdMapper *MtdMapper);
919  };
920 
921 cCiCaPmt::cCiCaPmt(uint8_t CmdId, int Source, int Transponder, int ProgramNumber, const int *CaSystemIds)
922 {
923  cmdId = CmdId;
924  source = Source;
925  transponder = Transponder;
926  programNumber = ProgramNumber;
927  int i = 0;
928  if (CaSystemIds) {
929  for (; CaSystemIds[i]; i++)
930  caSystemIds[i] = CaSystemIds[i];
931  }
932  caSystemIds[i] = 0;
935  capmt.Append((ProgramNumber >> 8) & 0xFF);
936  capmt.Append( ProgramNumber & 0xFF);
937  capmt.Append(0x01); // version_number, current_next_indicator - apparently vn doesn't matter, but cni must be 1
939  capmt.Append(0x00); // program_info_length H (at program level)
940  capmt.Append(0x00); // program_info_length L
942 }
943 
944 void cCiCaPmt::SetListManagement(uint8_t ListManagement)
945 {
947 }
948 
949 void cCiCaPmt::AddPid(int Pid, uint8_t StreamType)
950 {
951  if (Pid) {
953  capmt.Append(StreamType);
954  capmt.Append((Pid >> 8) & 0xFF);
955  capmt.Append( Pid & 0xFF);
957  capmt.Append(0x00); // ES_info_length H (at ES level)
958  capmt.Append(0x00); // ES_info_length L
960  }
961 }
962 
963 void cCiCaPmt::AddCaDescriptors(int Length, const uint8_t *Data)
964 {
965  if (esInfoLengthPos) {
966  if (Length || cmdId == CPCI_QUERY) {
967  capmt.Append(cmdId);
968  capmt.Append(Data, Length);
969  int l = capmt.Length() - esInfoLengthPos - 2;
970  capmt.Set(esInfoLengthPos, (l >> 8) & 0xFF);
971  capmt.Set(esInfoLengthPos + 1, l & 0xFF);
972  }
973  esInfoLengthPos = 0;
974  }
975  else
976  esyslog("ERROR: adding CA descriptor without Pid!");
977 }
978 
979 static int MtdMapCaDescriptor(uchar *p, cMtdMapper *MtdMapper)
980 {
981  // See pat.c: cCaDescriptor::cCaDescriptor() for the layout of the data!
982  if (*p == SI::CaDescriptorTag) {
983  int l = *++p;
984  if (l >= 4) {
985  MtdMapPid(p + 3, MtdMapper);
986  return l + 2;
987  }
988  else
989  esyslog("ERROR: wrong length (%d) in MtdMapCaDescriptor()", l);
990  }
991  else
992  esyslog("ERROR: wrong tag (%d) in MtdMapCaDescriptor()", *p);
993  return -1;
994 }
995 
996 static int MtdMapCaDescriptors(uchar *p, cMtdMapper *MtdMapper)
997 {
998  int Length = p[0] * 256 + p[1];
999  if (Length >= 3) {
1000  p += 3;
1001  int m = Length - 1;
1002  while (m > 0) {
1003  int l = MtdMapCaDescriptor(p, MtdMapper);
1004  if (l > 0) {
1005  p += l;
1006  m -= l;
1007  }
1008  }
1009  }
1010  return Length + 2;
1011 }
1012 
1013 static int MtdMapStream(uchar *p, cMtdMapper *MtdMapper)
1014 {
1015  // See ci.c: cCiCaPmt::AddPid() for the layout of the data!
1016  MtdMapPid(p + 1, MtdMapper);
1017  int l = MtdMapCaDescriptors(p + 3, MtdMapper);
1018  if (l > 0)
1019  return l + 3;
1020  return -1;
1021 }
1022 
1023 static int MtdMapStreams(uchar *p, cMtdMapper *MtdMapper, int Length)
1024 {
1025  int m = Length;
1026  while (m >= 5) {
1027  int l = MtdMapStream(p, MtdMapper);
1028  if (l > 0) {
1029  p += l;
1030  m -= l;
1031  }
1032  else
1033  break;
1034  }
1035  return Length;
1036 }
1037 
1039 {
1040  uchar *p = capmt.Data();
1041  int m = capmt.Length();
1042  if (m >= 3) {
1043  MtdMapSid(p + 1, MtdMapper);
1044  p += 4;
1045  m -= 4;
1046  if (m >= 2) {
1047  int l = MtdMapCaDescriptors(p, MtdMapper);
1048  if (l >= 0) {
1049  p += l;
1050  m -= l;
1051  MtdMapStreams(p, MtdMapper, m);
1052  }
1053  }
1054  }
1055 }
1056 
1057 // --- cCiConditionalAccessSupport -------------------------------------------
1058 
1059 // CA Enable Ids:
1060 
1061 #define CAEI_POSSIBLE 0x01
1062 #define CAEI_POSSIBLE_COND_PURCHASE 0x02
1063 #define CAEI_POSSIBLE_COND_TECHNICAL 0x03
1064 #define CAEI_NOT_POSSIBLE_ENTITLEMENT 0x71
1065 #define CAEI_NOT_POSSIBLE_TECHNICAL 0x73
1066 
1067 #define CA_ENABLE_FLAG 0x80
1068 
1069 #define CA_ENABLE(x) (((x) & CA_ENABLE_FLAG) ? (x) & ~CA_ENABLE_FLAG : 0)
1070 
1071 #define QUERY_WAIT_TIME 500 // ms to wait before sending a query
1072 #define QUERY_REPLY_TIMEOUT 2000 // ms to wait for a reply to a query
1073 #define QUERY_RETRIES 6 // max. number of retries to check if there is a reply to a query
1074 
1076 private:
1077  int state;
1079  int caSystemIds[MAXCASYSTEMIDS + 1]; // list is zero terminated!
1083 public:
1085  virtual void Process(int Length = 0, const uint8_t *Data = NULL);
1086  const int *GetCaSystemIds(void) { return caSystemIds; }
1087  void SendPMT(cCiCaPmt *CaPmt);
1088  bool RepliesToQuery(void) { return repliesToQuery; }
1089  bool Ready(void) { return state >= 4; }
1090  bool ReceivedReply(void) { return state >= 5; }
1091  bool CanDecrypt(void) { return state == 6; }
1092  };
1093 
1096 {
1097  dbgprotocol("Slot %d: new Conditional Access Support (session id %d)\n", CamSlot()->SlotNumber(), SessionId);
1098  state = 0; // inactive
1099  caSystemIds[numCaSystemIds = 0] = 0;
1100  repliesToQuery = false;
1101  numRetries = 0;
1102 }
1103 
1104 void cCiConditionalAccessSupport::Process(int Length, const uint8_t *Data)
1105 {
1106  if (Data) {
1107  int Tag = GetTag(Length, &Data);
1108  switch (Tag) {
1109  case AOT_CA_INFO: {
1110  dbgprotocol("Slot %d: <== Ca Info (%d)", CamSlot()->SlotNumber(), SessionId());
1111  cString Ids;
1112  numCaSystemIds = 0;
1113  int l = 0;
1114  const uint8_t *d = GetData(Data, l);
1115  while (l > 1) {
1116  uint16_t id = ((uint16_t)(*d) << 8) | *(d + 1);
1117  Ids = cString::sprintf("%s %04X", *Ids ? *Ids : "", id);
1118  dbgprotocol(" %04X", id);
1119  d += 2;
1120  l -= 2;
1122  caSystemIds[numCaSystemIds++] = id;
1123  else {
1124  esyslog("ERROR: CAM %d: too many CA system IDs!", CamSlot()->SlotNumber());
1125  break;
1126  }
1127  }
1129  dbgprotocol("\n");
1130  if (state == 1) {
1131  timer.Set(0);
1133  state = 2; // got ca info
1134  }
1135  dsyslog("CAM %d: system ids:%s", CamSlot()->SlotNumber(), *Ids ? *Ids : " none");
1136  }
1137  break;
1138  case AOT_CA_PMT_REPLY: {
1139  dbgprotocol("Slot %d: <== Ca Pmt Reply (%d)", CamSlot()->SlotNumber(), SessionId());
1140  if (!repliesToQuery) {
1141  if (CamSlot()->IsMasterSlot())
1142  dsyslog("CAM %d: replies to QUERY - multi channel decryption (MCD) possible", CamSlot()->SlotNumber());
1143  repliesToQuery = true;
1144  if (CamSlot()->MtdAvailable()) {
1145  if (CamSlot()->IsMasterSlot())
1146  dsyslog("CAM %d: supports multi transponder decryption (MTD)", CamSlot()->SlotNumber());
1147  CamSlot()->MtdActivate(true);
1148  }
1149  }
1150  state = 5; // got ca pmt reply
1151  int l = 0;
1152  const uint8_t *d = GetData(Data, l);
1153  if (l > 1) {
1154  uint16_t pnr = ((uint16_t)(*d) << 8) | *(d + 1);
1155  dbgprotocol(" %d", pnr);
1156  d += 2;
1157  l -= 2;
1158  if (l > 0) {
1159  dbgprotocol(" %02X", *d);
1160  d += 1;
1161  l -= 1;
1162  if (l > 0) {
1163  if (l % 3 == 0 && l > 1) {
1164  // The EN50221 standard defines that the next byte is supposed
1165  // to be the CA_enable value at programme level. However, there are
1166  // CAMs (for instance the AlphaCrypt with firmware <= 3.05) that
1167  // insert a two byte length field here.
1168  // This is a workaround to skip this length field:
1169  uint16_t len = ((uint16_t)(*d) << 8) | *(d + 1);
1170  if (len == l - 2) {
1171  d += 2;
1172  l -= 2;
1173  }
1174  }
1175  unsigned char caepl = *d;
1176  dbgprotocol(" %02X", caepl);
1177  d += 1;
1178  l -= 1;
1179  bool ok = true;
1180  if (l <= 2)
1181  ok = CA_ENABLE(caepl) == CAEI_POSSIBLE;
1182  while (l > 2) {
1183  uint16_t pid = ((uint16_t)(*d) << 8) | *(d + 1);
1184  unsigned char caees = *(d + 2);
1185  dbgprotocol(" %d=%02X", pid, caees);
1186  d += 3;
1187  l -= 3;
1188  if (CA_ENABLE(caees) != CAEI_POSSIBLE)
1189  ok = false;
1190  }
1191  if (ok)
1192  state = 6; // descrambling possible
1193  }
1194  }
1195  }
1196  dbgprotocol("\n");
1197  }
1198  break;
1199  default: esyslog("ERROR: CAM %d: conditional access support: unknown tag %06X", CamSlot()->SlotNumber(), Tag);
1200  }
1201  }
1202  else if (state == 0) {
1203  dbgprotocol("Slot %d: ==> Ca Info Enq (%d)\n", CamSlot()->SlotNumber(), SessionId());
1205  state = 1; // enquired ca info
1206  }
1207  else if ((state == 2 || state == 3) && timer.TimedOut()) {
1208  if (numRetries-- > 0) {
1209  cCiCaPmt CaPmt(CPCI_QUERY, 0, 0, 0, NULL);
1210  SendPMT(&CaPmt);
1212  state = 3; // waiting for reply
1213  }
1214  else {
1215  dsyslog("CAM %d: doesn't reply to QUERY - only a single channel can be decrypted", CamSlot()->SlotNumber());
1216  CamSlot()->MtdActivate(false);
1217  state = 4; // normal operation
1218  }
1219  }
1220 }
1221 
1223 {
1224  if (CaPmt && state >= 2) {
1225  dbgprotocol("Slot %d: ==> Ca Pmt (%d) %d %d\n", CamSlot()->SlotNumber(), SessionId(), CaPmt->ListManagement(), CaPmt->CmdId());
1226  SendData(AOT_CA_PMT, CaPmt->capmt.Length(), CaPmt->capmt.Data());
1227  state = 4; // sent ca pmt
1228  }
1229 }
1230 
1231 // --- cCiHostControl --------------------------------------------------------
1232 
1233 class cCiHostControl : public cCiSession {
1234 public:
1236  virtual void Process(int Length = 0, const uint8_t *Data = NULL);
1237  };
1238 
1240 :cCiSession(SessionId, RI_HOST_CONTROL, Tc)
1241 {
1242  dbgprotocol("Slot %d: new Host Control (session id %d)\n", CamSlot()->SlotNumber(), SessionId);
1243 }
1244 
1245 void cCiHostControl::Process(int Length, const uint8_t* Data)
1246 {
1247  if (Data) {
1248  int Tag = GetTag(Length, &Data);
1249  switch (Tag) {
1250  case AOT_TUNE:
1251  dbgprotocol("Slot %d: <== Host Control Tune (%d)\n", CamSlot()->SlotNumber(), SessionId());
1252  break;
1253  case AOT_REPLACE:
1254  dbgprotocol("Slot %d: <== Host Control Replace (%d)\n", CamSlot()->SlotNumber(), SessionId());
1255  break;
1256  case AOT_CLEAR_REPLACE:
1257  dbgprotocol("Slot %d: <== Host Control Clear Replace (%d)\n", CamSlot()->SlotNumber(), SessionId());
1258  break;
1259  default: esyslog("ERROR: CAM %d: Host Control: unknown tag %06X", CamSlot()->SlotNumber(), Tag);
1260  }
1261  }
1262 }
1263 
1264 // --- cCiDateTime -----------------------------------------------------------
1265 
1266 class cCiDateTime : public cCiSession {
1267 private:
1269  time_t lastTime;
1270  void SendDateTime(void);
1271 public:
1273  virtual void Process(int Length = 0, const uint8_t *Data = NULL);
1274  };
1275 
1277 :cCiSession(SessionId, RI_DATE_TIME, Tc)
1278 {
1279  interval = 0;
1280  lastTime = 0;
1281  dbgprotocol("Slot %d: new Date Time (session id %d)\n", CamSlot()->SlotNumber(), SessionId);
1282 }
1283 
1285 {
1286  time_t t = time(NULL);
1287  struct tm tm_gmt;
1288  struct tm tm_loc;
1289  if (gmtime_r(&t, &tm_gmt) && localtime_r(&t, &tm_loc)) {
1290  int Y = tm_gmt.tm_year;
1291  int M = tm_gmt.tm_mon + 1;
1292  int D = tm_gmt.tm_mday;
1293  int L = (M == 1 || M == 2) ? 1 : 0;
1294  int MJD = 14956 + D + int((Y - L) * 365.25) + int((M + 1 + L * 12) * 30.6001);
1295 #define DEC2BCD(d) uint8_t(((d / 10) << 4) + (d % 10))
1296 #pragma pack(1)
1297  struct tTime { uint16_t mjd; uint8_t h, m, s; short offset; };
1298 #pragma pack()
1299  tTime T = { mjd : htons(MJD), h : DEC2BCD(tm_gmt.tm_hour), m : DEC2BCD(tm_gmt.tm_min), s : DEC2BCD(tm_gmt.tm_sec), offset : short(htons(tm_loc.tm_gmtoff / 60)) };
1300  bool OldDumpTPDUDataTransfer = DumpTPDUDataTransfer;
1302  if (DumpDateTime)
1303  dbgprotocol("Slot %d: ==> Date Time (%d)\n", CamSlot()->SlotNumber(), SessionId());
1304  SendData(AOT_DATE_TIME, 7, (uint8_t*)&T);
1305  DumpTPDUDataTransfer = OldDumpTPDUDataTransfer;
1306  }
1307 }
1308 
1309 void cCiDateTime::Process(int Length, const uint8_t *Data)
1310 {
1311  if (Data) {
1312  int Tag = GetTag(Length, &Data);
1313  switch (Tag) {
1314  case AOT_DATE_TIME_ENQ: {
1315  interval = 0;
1316  int l = 0;
1317  const uint8_t *d = GetData(Data, l);
1318  if (l > 0)
1319  interval = *d;
1320  dbgprotocol("Slot %d: <== Date Time Enq (%d), interval = %d\n", CamSlot()->SlotNumber(), SessionId(), interval);
1321  lastTime = time(NULL);
1322  SendDateTime();
1323  }
1324  break;
1325  default: esyslog("ERROR: CAM %d: date time: unknown tag %06X", CamSlot()->SlotNumber(), Tag);
1326  }
1327  }
1328  else if (interval && time(NULL) - lastTime > interval) {
1329  lastTime = time(NULL);
1330  SendDateTime();
1331  }
1332 }
1333 
1334 // --- cCiMMI ----------------------------------------------------------------
1335 
1336 // Display Control Commands:
1337 
1338 #define DCC_SET_MMI_MODE 0x01
1339 #define DCC_DISPLAY_CHARACTER_TABLE_LIST 0x02
1340 #define DCC_INPUT_CHARACTER_TABLE_LIST 0x03
1341 #define DCC_OVERLAY_GRAPHICS_CHARACTERISTICS 0x04
1342 #define DCC_FULL_SCREEN_GRAPHICS_CHARACTERISTICS 0x05
1343 
1344 // MMI Modes:
1345 
1346 #define MM_HIGH_LEVEL 0x01
1347 #define MM_LOW_LEVEL_OVERLAY_GRAPHICS 0x02
1348 #define MM_LOW_LEVEL_FULL_SCREEN_GRAPHICS 0x03
1349 
1350 // Display Reply IDs:
1351 
1352 #define DRI_MMI_MODE_ACK 0x01
1353 #define DRI_LIST_DISPLAY_CHARACTER_TABLES 0x02
1354 #define DRI_LIST_INPUT_CHARACTER_TABLES 0x03
1355 #define DRI_LIST_GRAPHIC_OVERLAY_CHARACTERISTICS 0x04
1356 #define DRI_LIST_FULL_SCREEN_GRAPHIC_CHARACTERISTICS 0x05
1357 #define DRI_UNKNOWN_DISPLAY_CONTROL_CMD 0xF0
1358 #define DRI_UNKNOWN_MMI_MODE 0xF1
1359 #define DRI_UNKNOWN_CHARACTER_TABLE 0xF2
1360 
1361 // Enquiry Flags:
1362 
1363 #define EF_BLIND 0x01
1364 
1365 // Answer IDs:
1366 
1367 #define AI_CANCEL 0x00
1368 #define AI_ANSWER 0x01
1369 
1370 class cCiMMI : public cCiSession {
1371 private:
1372  char *GetText(int &Length, const uint8_t **Data);
1375 public:
1377  virtual ~cCiMMI();
1378  virtual void Process(int Length = 0, const uint8_t *Data = NULL);
1379  virtual bool HasUserIO(void) { return menu || enquiry; }
1380  cCiMenu *Menu(bool Clear = false);
1381  cCiEnquiry *Enquiry(bool Clear = false);
1382  void SendMenuAnswer(uint8_t Selection);
1383  bool SendAnswer(const char *Text);
1384  bool SendCloseMMI(void);
1385  };
1386 
1387 cCiMMI::cCiMMI(uint16_t SessionId, cCiTransportConnection *Tc)
1388 :cCiSession(SessionId, RI_MMI, Tc)
1389 {
1390  dbgprotocol("Slot %d: new MMI (session id %d)\n", CamSlot()->SlotNumber(), SessionId);
1391  menu = fetchedMenu = NULL;
1392  enquiry = fetchedEnquiry = NULL;
1393 }
1394 
1396 {
1397  if (fetchedMenu) {
1398  cMutexLock MutexLock(fetchedMenu->mutex);
1399  fetchedMenu->mmi = NULL;
1400  }
1401  delete menu;
1402  if (fetchedEnquiry) {
1403  cMutexLock MutexLock(fetchedEnquiry->mutex);
1404  fetchedEnquiry->mmi = NULL;
1405  }
1406  delete enquiry;
1407 }
1408 
1409 char *cCiMMI::GetText(int &Length, const uint8_t **Data)
1413 {
1414  int Tag = GetTag(Length, Data);
1415  if (Tag == AOT_TEXT_LAST) {
1416  char *s = GetString(Length, Data);
1417  dbgprotocol("Slot %d: <== Text Last (%d) '%s'\n", CamSlot()->SlotNumber(), SessionId(), s);
1418  return s;
1419  }
1420  else
1421  esyslog("ERROR: CAM %d: MMI: unexpected text tag: %06X", CamSlot()->SlotNumber(), Tag);
1422  return NULL;
1423 }
1424 
1425 void cCiMMI::Process(int Length, const uint8_t *Data)
1426 {
1427  if (Data) {
1428  int Tag = GetTag(Length, &Data);
1429  switch (Tag) {
1430  case AOT_DISPLAY_CONTROL: {
1431  dbgprotocol("Slot %d: <== Display Control (%d)\n", CamSlot()->SlotNumber(), SessionId());
1432  int l = 0;
1433  const uint8_t *d = GetData(Data, l);
1434  if (l > 0) {
1435  switch (*d) {
1436  case DCC_SET_MMI_MODE:
1437  if (l == 2 && *++d == MM_HIGH_LEVEL) {
1438  struct tDisplayReply { uint8_t id; uint8_t mode; };
1439  tDisplayReply dr = { id : DRI_MMI_MODE_ACK, mode : MM_HIGH_LEVEL };
1440  dbgprotocol("Slot %d: ==> Display Reply (%d)\n", CamSlot()->SlotNumber(), SessionId());
1441  SendData(AOT_DISPLAY_REPLY, 2, (uint8_t *)&dr);
1442  }
1443  break;
1444  default: esyslog("ERROR: CAM %d: MMI: unsupported display control command %02X", CamSlot()->SlotNumber(), *d);
1445  }
1446  }
1447  }
1448  break;
1449  case AOT_LIST_LAST:
1450  case AOT_MENU_LAST: {
1451  dbgprotocol("Slot %d: <== Menu Last (%d)\n", CamSlot()->SlotNumber(), SessionId());
1452  delete menu;
1453  menu = new cCiMenu(this, Tag == AOT_MENU_LAST);
1454  int l = 0;
1455  const uint8_t *d = GetData(Data, l);
1456  if (l > 0) {
1457  // since the specification allows choiceNb to be undefined it is useless, so let's just skip it:
1458  d++;
1459  l--;
1460  if (l > 0) menu->titleText = GetText(l, &d);
1461  if (l > 0) menu->subTitleText = GetText(l, &d);
1462  if (l > 0) menu->bottomText = GetText(l, &d);
1463  int Action = CRA_NONE;
1464  int Select = -1;
1465  int Item = 0;
1466  while (l > 0) {
1467  char *s = GetText(l, &d);
1468  if (s) {
1469  if (!menu->AddEntry(s))
1470  free(s);
1471  else if (Action == CRA_NONE) {
1472  Action = CamResponses.GetMatch(CamSlot()->SlotNumber(), s);
1473  if (Action == CRA_SELECT)
1474  Select = Item;
1475  }
1476  }
1477  else
1478  break;
1479  Item++;
1480  }
1481  if (Action != CRA_NONE) {
1482  delete menu;
1483  menu = NULL;
1484  cCondWait::SleepMs(100);
1485  if (Action == CRA_DISCARD) {
1486  SendCloseMMI();
1487  dsyslog("CAM %d: DISCARD", CamSlot()->SlotNumber());
1488  }
1489  else if (Action == CRA_CONFIRM) {
1490  SendMenuAnswer(1);
1491  dsyslog("CAM %d: CONFIRM", CamSlot()->SlotNumber());
1492  }
1493  else if (Action == CRA_SELECT) {
1494  SendMenuAnswer(Select + 1);
1495  dsyslog("CAM %d: SELECT %d", CamSlot()->SlotNumber(), Select + 1);
1496  }
1497  }
1498  }
1499  }
1500  break;
1501  case AOT_ENQ: {
1502  dbgprotocol("Slot %d: <== Enq (%d)\n", CamSlot()->SlotNumber(), SessionId());
1503  delete enquiry;
1504  enquiry = new cCiEnquiry(this);
1505  int l = 0;
1506  const uint8_t *d = GetData(Data, l);
1507  if (l > 0) {
1508  uint8_t blind = *d++;
1509  //XXX GetByte()???
1510  l--;
1511  enquiry->blind = blind & EF_BLIND;
1512  enquiry->expectedLength = *d++;
1513  l--;
1514  // I really wonder why there is no text length field here...
1515  enquiry->text = CopyString(l, d);
1516  int Action = CamResponses.GetMatch(CamSlot()->SlotNumber(), enquiry->text);
1517  if (Action > CRA_NONE) {
1518  char s[enquiry->expectedLength * 2];
1519  snprintf(s, sizeof(s), "%d", Action);
1520  if (int(strlen(s)) == enquiry->expectedLength) {
1521  delete enquiry;
1522  enquiry = NULL;
1523  SendAnswer(s);
1524  dsyslog("CAM %d: PIN", CamSlot()->SlotNumber());
1525  }
1526  else
1527  esyslog("CAM %d: ERROR: unexpected PIN length %d, expected %d", CamSlot()->SlotNumber(), int(strlen(s)), enquiry->expectedLength);
1528  }
1529  }
1530  }
1531  break;
1532  case AOT_CLOSE_MMI: {
1533  int id = -1;
1534  int delay = -1;
1535  int l = 0;
1536  const uint8_t *d = GetData(Data, l);
1537  if (l > 0) {
1538  id = *d++;
1539  if (l > 1)
1540  delay = *d;
1541  }
1542  dbgprotocol("Slot %d: <== Close MMI (%d) id = %02X delay = %d\n", CamSlot()->SlotNumber(), SessionId(), id, delay);
1543  }
1544  break;
1545  default: esyslog("ERROR: CAM %d: MMI: unknown tag %06X", CamSlot()->SlotNumber(), Tag);
1546  }
1547  }
1548 }
1549 
1550 cCiMenu *cCiMMI::Menu(bool Clear)
1551 {
1552  if (Clear)
1553  fetchedMenu = NULL;
1554  else if (menu) {
1555  fetchedMenu = menu;
1556  menu = NULL;
1557  }
1558  return fetchedMenu;
1559 }
1560 
1562 {
1563  if (Clear)
1564  fetchedEnquiry = NULL;
1565  else if (enquiry) {
1567  enquiry = NULL;
1568  }
1569  return fetchedEnquiry;
1570 }
1571 
1572 void cCiMMI::SendMenuAnswer(uint8_t Selection)
1573 {
1574  dbgprotocol("Slot %d: ==> Menu Answ (%d)\n", CamSlot()->SlotNumber(), SessionId());
1575  SendData(AOT_MENU_ANSW, 1, &Selection);
1576 }
1577 
1578 bool cCiMMI::SendAnswer(const char *Text)
1579 {
1580  dbgprotocol("Slot %d: ==> Answ (%d)\n", CamSlot()->SlotNumber(), SessionId());
1581  struct tAnswer { uint8_t id; char text[256]; };//XXX
1582  tAnswer answer;
1583  answer.id = Text ? AI_ANSWER : AI_CANCEL;
1584  if (Text)
1585  strncpy(answer.text, Text, sizeof(answer.text));
1586  SendData(AOT_ANSW, Text ? strlen(Text) + 1 : 1, (uint8_t *)&answer);
1587  return true;
1588 }
1589 
1591 {
1592  dbgprotocol("Slot %d: ==> Close MMI (%d)\n", CamSlot()->SlotNumber(), SessionId());
1593  SendData(AOT_CLOSE_MMI, 0);
1594  return true;
1595 }
1596 
1597 // --- cCiMenu ---------------------------------------------------------------
1598 
1599 cCiMenu::cCiMenu(cCiMMI *MMI, bool Selectable)
1600 {
1601  mmi = MMI;
1602  mutex = NULL;
1604  titleText = subTitleText = bottomText = NULL;
1605  numEntries = 0;
1606 }
1607 
1609 {
1610  cMutexLock MutexLock(mutex);
1611  if (mmi)
1612  mmi->Menu(true);
1613  free(titleText);
1614  free(subTitleText);
1615  free(bottomText);
1616  for (int i = 0; i < numEntries; i++)
1617  free(entries[i]);
1618 }
1619 
1620 bool cCiMenu::AddEntry(char *s)
1621 {
1623  entries[numEntries++] = s;
1624  return true;
1625  }
1626  return false;
1627 }
1628 
1630 {
1631  // If the mmi is gone, the menu shall be closed, which also qualifies as 'update'.
1632  return !mmi || mmi->HasUserIO();
1633 }
1634 
1635 void cCiMenu::Select(int Index)
1636 {
1637  cMutexLock MutexLock(mutex);
1638  if (mmi && -1 <= Index && Index < numEntries)
1639  mmi->SendMenuAnswer(Index + 1);
1640 }
1641 
1643 {
1644  Select(-1);
1645 }
1646 
1647 void cCiMenu::Abort(void)
1648 {
1649  cMutexLock MutexLock(mutex);
1650  if (mmi)
1651  mmi->SendCloseMMI();
1652 }
1653 
1654 // --- cCiEnquiry ------------------------------------------------------------
1655 
1657 {
1658  mmi = MMI;
1659  mutex = NULL;
1660  text = NULL;
1661  blind = false;
1662  expectedLength = 0;
1663 }
1664 
1666 {
1667  cMutexLock MutexLock(mutex);
1668  if (mmi)
1669  mmi->Enquiry(true);
1670  free(text);
1671 }
1672 
1673 void cCiEnquiry::Reply(const char *s)
1674 {
1675  cMutexLock MutexLock(mutex);
1676  if (mmi)
1677  mmi->SendAnswer(s);
1678 }
1679 
1681 {
1682  Reply(NULL);
1683 }
1684 
1686 {
1687  cMutexLock MutexLock(mutex);
1688  if (mmi)
1689  mmi->SendCloseMMI();
1690 }
1691 
1692 // --- cCiResourceHandler ----------------------------------------------------
1693 
1695 {
1696 }
1697 
1699 {
1700 }
1701 
1702 // --- cCiDefaultResourceHandler ---------------------------------------------
1703 
1705 public:
1706  virtual const uint32_t *ResourceIds(void) const;
1707  virtual cCiSession *GetNewCiSession(uint32_t ResourceId, uint16_t SessionId, cCiTransportConnection *Tc);
1708  };
1709 
1710 const uint32_t *cCiDefaultResourceHandler::ResourceIds(void) const
1711 {
1712  static uint32_t Ids[] = {
1717  RI_DATE_TIME,
1718  RI_MMI,
1719  0
1720  };
1721  return Ids;
1722 }
1723 
1725 {
1726  switch (ResourceId) {
1727  case RI_RESOURCE_MANAGER: return new cCiResourceManager(SessionId, Tc); break;
1728  case RI_APPLICATION_INFORMATION: return new cCiApplicationInformation(SessionId, Tc); break;
1729  case RI_CONDITIONAL_ACCESS_SUPPORT: return new cCiConditionalAccessSupport(SessionId, Tc); break;
1730  case RI_HOST_CONTROL: return new cCiHostControl(SessionId, Tc); break;
1731  case RI_DATE_TIME: return new cCiDateTime(SessionId, Tc); break;
1732  case RI_MMI: return new cCiMMI(SessionId, Tc); break;
1733  default: return NULL;
1734  }
1735 }
1736 
1737 // --- cCiResourceHandlers ---------------------------------------------------
1738 
1740 
1742 {
1744 }
1745 
1747 {
1748  if (ResourceHandler) {
1749  Add(ResourceHandler);
1750  if (const uint32_t *r = ResourceHandler->ResourceIds()) {
1751  while (*r) {
1752  resourceIds.Append(htonl(*r));
1753  r++;
1754  }
1755  }
1756  }
1757 }
1758 
1759 cCiSession *cCiResourceHandlers::GetNewCiSession(uint32_t ResourceId, uint16_t SessionId, cCiTransportConnection *Tc)
1760 {
1761  for (cCiResourceHandler *r = Last(); r; r = Prev(r)) {
1762  if (cCiSession *CiSession = r->GetNewCiSession(ResourceId, SessionId, Tc))
1763  return CiSession;
1764  }
1765  return NULL;
1766 }
1767 
1768 // --- cCiTransportConnection (cont'd) ---------------------------------------
1769 
1770 #define TC_POLL_TIMEOUT 300 // ms WORKAROUND: TC_POLL_TIMEOUT < 300ms doesn't work with DragonCAM
1771 #define TC_ALIVE_TIMEOUT 2000 // ms after which a transport connection is assumed dead
1772 
1774 {
1775  dbgprotocol("Slot %d: creating connection %d/%d\n", CamSlot->SlotNumber(), CamSlot->SlotIndex(), Tcid);
1776  camSlot = CamSlot;
1777  tcid = Tcid;
1778  state = stIDLE;
1779  createConnectionRequested = false;
1780  deleteConnectionRequested = false;
1781  hasUserIO = false;
1783  for (int i = 0; i <= MAX_SESSIONS_PER_TC; i++) // sessions[0] is not used, but initialized anyway
1784  sessions[i] = NULL;
1785  tsPostProcessor = NULL;
1786 }
1787 
1789 {
1790  for (int i = 1; i <= MAX_SESSIONS_PER_TC; i++)
1791  delete sessions[i];
1792 }
1793 
1795 {
1796  tsPostProcessor = CiSession;
1797 }
1798 
1800 {
1801  if (tsPostProcessor)
1802  return tsPostProcessor->TsPostProcess(TsPacket);
1803  return false;
1804 }
1805 
1807 {
1809  return cas && cas->Ready();
1810 }
1811 
1813 {
1815  return ai ? ai->GetMenuString() : NULL;
1816 }
1817 
1818 void cCiTransportConnection::SendTPDU(uint8_t Tag, int Length, const uint8_t *Data)
1819 {
1820  cTPDU TPDU(camSlot->SlotIndex(), tcid, Tag, Length, Data);
1821  camSlot->Write(&TPDU);
1823 }
1824 
1825 void cCiTransportConnection::SendData(int Length, const uint8_t *Data)
1826 {
1827  // if Length ever exceeds MAX_TPDU_DATA this needs to be handled differently
1828  if (state == stACTIVE && Length > 0)
1829  SendTPDU(T_DATA_LAST, Length, Data);
1830 }
1831 
1832 void cCiTransportConnection::SendTag(uint8_t Tag, uint16_t SessionId, uint32_t ResourceId, int Status)
1833 {
1834  uint8_t buffer[16];
1835  uint8_t *p = buffer;
1836  *p++ = Tag;
1837  *p++ = 0x00; // will contain length
1838  if (Status >= 0)
1839  *p++ = Status;
1840  if (ResourceId) {
1841  put_unaligned(htonl(ResourceId), (uint32_t *)p);
1842  p += 4;
1843  }
1844  put_unaligned(htons(SessionId), (uint16_t *)p);
1845  p += 2;
1846  buffer[1] = p - buffer - 2; // length
1847  SendData(p - buffer, buffer);
1848 }
1849 
1851 {
1852  bool OldDumpTPDUDataTransfer = DumpTPDUDataTransfer;
1854  if (DumpPolls)
1855  dbgprotocol("Slot %d: ==> Poll\n", camSlot->SlotNumber());
1857  DumpTPDUDataTransfer = OldDumpTPDUDataTransfer;
1858 }
1859 
1860 uint32_t cCiTransportConnection::ResourceIdToInt(const uint8_t *Data)
1861 {
1862  return (ntohl(get_unaligned((uint32_t *)Data)));
1863 }
1864 
1866 {
1867  return (SessionId <= MAX_SESSIONS_PER_TC) ? sessions[SessionId] : NULL;
1868 }
1869 
1871 {
1872  cCiSession *CiSession = NULL;
1873  for (int i = 1; i <= MAX_SESSIONS_PER_TC; i++) {
1874  if (cCiSession *s = sessions[i]) {
1875  if (s->ResourceId() == ResourceId)
1876  return s; // prefer exact match
1877  if ((s->ResourceId() & RESOURCE_CLASS_MASK) == (ResourceId & RESOURCE_CLASS_MASK))
1878  CiSession = s;
1879  }
1880  }
1881  return CiSession;
1882 }
1883 
1884 void cCiTransportConnection::OpenSession(int Length, const uint8_t *Data)
1885 {
1886  if (Length == 6 && *(Data + 1) == 0x04) {
1887  uint32_t ResourceId = ResourceIdToInt(Data + 2);
1888  dbgprotocol("Slot %d: open session %08X\n", camSlot->SlotNumber(), ResourceId);
1889  if (!GetSessionByResourceId(ResourceId)) {
1890  for (int i = 1; i <= MAX_SESSIONS_PER_TC; i++) {
1891  if (!sessions[i]) {
1892  sessions[i] = CiResourceHandlers.GetNewCiSession(ResourceId, i, this);
1893  if (sessions[i])
1894  SendTag(ST_OPEN_SESSION_RESPONSE, sessions[i]->SessionId(), sessions[i]->ResourceId(), SS_OK);
1895  else
1896  esyslog("ERROR: CAM %d: unknown resource identifier: %08X (%d/%d)", camSlot->SlotNumber(), ResourceId, camSlot->SlotIndex(), tcid);
1897  return;
1898  }
1899  }
1900  esyslog("ERROR: CAM %d: no free session slot for resource identifier %08X (%d/%d)", camSlot->SlotNumber(), ResourceId, camSlot->SlotIndex(), tcid);
1901  }
1902  else
1903  esyslog("ERROR: CAM %d: session for resource identifier %08X already exists (%d/%d)", camSlot->SlotNumber(), ResourceId, camSlot->SlotIndex(), tcid);
1904  }
1905 }
1906 
1908 {
1909  dbgprotocol("Slot %d: close session %d\n", camSlot->SlotNumber(), SessionId);
1910  cCiSession *Session = GetSessionBySessionId(SessionId);
1911  if (Session && sessions[SessionId] == Session) {
1912  delete Session;
1913  sessions[SessionId] = NULL;
1914  SendTag(ST_CLOSE_SESSION_RESPONSE, SessionId, 0, SS_OK);
1915  }
1916  else {
1917  esyslog("ERROR: CAM %d: unknown session id: %d (%d/%d)", camSlot->SlotNumber(), SessionId, camSlot->SlotIndex(), tcid);
1919  }
1920 }
1921 
1923 {
1924  int Length;
1925  const uint8_t *Data = TPDU->Data(Length);
1926  if (Data && Length > 1) {
1927  switch (*Data) {
1928  case ST_SESSION_NUMBER: if (Length > 4) {
1929  uint16_t SessionId = ntohs(get_unaligned((uint16_t *)&Data[2]));
1930  cCiSession *Session = GetSessionBySessionId(SessionId);
1931  if (Session)
1932  Session->Process(Length - 4, Data + 4);
1933  else
1934  esyslog("ERROR: CAM %d: unknown session id: %d (%d/%d)", camSlot->SlotNumber(), SessionId, camSlot->SlotIndex(), tcid);
1935  }
1936  break;
1937  case ST_OPEN_SESSION_REQUEST: OpenSession(Length, Data);
1938  break;
1939  case ST_CLOSE_SESSION_REQUEST: if (Length == 4)
1940  CloseSession(ntohs(get_unaligned((uint16_t *)&Data[2])));
1941  break;
1942  case ST_CREATE_SESSION_RESPONSE: // not implemented
1943  case ST_CLOSE_SESSION_RESPONSE: // not implemented
1944  default: esyslog("ERROR: CAM %d: unknown session tag: %02X (%d/%d)", camSlot->SlotNumber(), *Data, camSlot->SlotIndex(), tcid);
1945  }
1946  }
1947 }
1948 
1950 {
1951  if (TPDU)
1953  else if (alive.TimedOut())
1954  return false;
1955  switch (state) {
1956  case stIDLE:
1958  dbgprotocol("Slot %d: create connection %d/%d\n", camSlot->SlotNumber(), camSlot->SlotIndex(), tcid);
1959  createConnectionRequested = false;
1961  state = stCREATION;
1962  }
1963  return true;
1964  case stCREATION:
1965  if (TPDU && TPDU->Tag() == T_CTC_REPLY) {
1966  dbgprotocol("Slot %d: connection created %d/%d\n", camSlot->SlotNumber(), camSlot->SlotIndex(), tcid);
1967  Poll();
1968  state = stACTIVE;
1969  }
1970  else if (timer.TimedOut()) {
1971  dbgprotocol("Slot %d: timeout while creating connection %d/%d\n", camSlot->SlotNumber(), camSlot->SlotIndex(), tcid);
1972  state = stIDLE;
1973  }
1974  return true;
1975  case stACTIVE:
1977  dbgprotocol("Slot %d: delete connection requested %d/%d\n", camSlot->SlotNumber(), camSlot->SlotIndex(), tcid);
1978  deleteConnectionRequested = false;
1980  state = stDELETION;
1981  return true;
1982  }
1983  if (TPDU) {
1984  switch (TPDU->Tag()) {
1985  case T_REQUEST_TC:
1986  esyslog("ERROR: CAM %d: T_REQUEST_TC not implemented (%d/%d)", camSlot->SlotNumber(), camSlot->SlotIndex(), tcid);
1987  break;
1988  case T_DATA_MORE:
1989  case T_DATA_LAST:
1990  HandleSessions(TPDU);
1991  // continue with T_SB
1992  case T_SB:
1993  if ((TPDU->Status() & DATA_INDICATOR) != 0) {
1994  dbgprotocol("Slot %d: receive data %d/%d\n", camSlot->SlotNumber(), camSlot->SlotIndex(), tcid);
1995  SendTPDU(T_RCV);
1996  }
1997  break;
1998  case T_DELETE_TC:
1999  dbgprotocol("Slot %d: delete connection %d/%d\n", camSlot->SlotNumber(), camSlot->SlotIndex(), tcid);
2001  state = stIDLE;
2002  return true;
2003  case T_RCV:
2004  case T_CREATE_TC:
2005  case T_CTC_REPLY:
2006  case T_DTC_REPLY:
2007  case T_NEW_TC:
2008  case T_TC_ERROR:
2009  break;
2010  default:
2011  esyslog("ERROR: unknown TPDU tag: 0x%02X (%s)", TPDU->Tag(), __FUNCTION__);
2012  }
2013  }
2014  else if (timer.TimedOut())
2015  Poll();
2016  hasUserIO = false;
2017  for (int i = 1; i <= MAX_SESSIONS_PER_TC; i++) {
2018  if (sessions[i]) {
2019  sessions[i]->Process();
2020  if (sessions[i]->HasUserIO())
2021  hasUserIO = true;
2022  }
2023  }
2024  break;
2025  case stDELETION:
2026  if (TPDU && TPDU->Tag() == T_DTC_REPLY || timer.TimedOut()) {
2027  dbgprotocol("Slot %d: connection deleted %d/%d\n", camSlot->SlotNumber(), camSlot->SlotIndex(), tcid);
2028  state = stIDLE;
2029  }
2030  return true;
2031  default:
2032  esyslog("ERROR: unknown state: %d (%s)", state, __FUNCTION__);
2033  }
2034  return true;
2035 }
2036 
2037 // --- cCiCaPidData ----------------------------------------------------------
2038 
2039 class cCiCaPidData : public cListObject {
2040 public:
2041  bool active;
2042  int pid;
2044  cCiCaPidData(int Pid, int StreamType)
2045  {
2046  active = false;
2047  pid = Pid;
2048  streamType = StreamType;
2049  }
2050  };
2051 
2052 // --- cCiCaProgramData ------------------------------------------------------
2053 
2055 public:
2057  bool modified;
2059  cCiCaProgramData(int ProgramNumber)
2060  {
2061  programNumber = ProgramNumber;
2062  modified = false;
2063  }
2064  bool Active(void)
2065  {
2066  for (cCiCaPidData *p = pidList.First(); p; p = pidList.Next(p)) {
2067  if (p->active)
2068  return true;
2069  }
2070  return false;
2071  }
2072  };
2073 
2074 // --- cCiAdapter ------------------------------------------------------------
2075 
2077 :cThread("CI adapter")
2078 {
2079  for (int i = 0; i < MAX_CAM_SLOTS_PER_ADAPTER; i++)
2080  camSlots[i] = NULL;
2081 }
2082 
2084 {
2085  Cancel(3);
2086  for (int i = 0; i < MAX_CAM_SLOTS_PER_ADAPTER; i++)
2087  delete camSlots[i];
2088 }
2089 
2091 {
2092  if (CamSlot) {
2093  for (int i = 0; i < MAX_CAM_SLOTS_PER_ADAPTER; i++) {
2094  if (!camSlots[i]) {
2095  CamSlot->slotIndex = i;
2096  camSlots[i] = CamSlot;
2097  return;
2098  }
2099  }
2100  esyslog("ERROR: no free CAM slot in CI adapter");
2101  }
2102 }
2103 
2105 {
2106  if (Iter >= 0) {
2107  for (; Iter < MAX_CAM_SLOTS_PER_ADAPTER; ) {
2108  if (cCamSlot *Found = camSlots[Iter++])
2109  return Found;
2110  }
2111  }
2112  return NULL;
2113 }
2114 
2116 {
2117  cTPDU TPDU;
2118  while (Running()) {
2119  int n = Read(TPDU.Buffer(), TPDU.MaxSize());
2120  if (n > 0 && TPDU.Slot() < MAX_CAM_SLOTS_PER_ADAPTER) {
2121  TPDU.SetSize(n);
2122  cCamSlot *cs = camSlots[TPDU.Slot()];
2123  TPDU.Dump(cs ? cs->SlotNumber() : 0, false);
2124  if (cs)
2125  cs->Process(&TPDU);
2126  }
2127  for (int i = 0; i < MAX_CAM_SLOTS_PER_ADAPTER; i++) {
2128  if (camSlots[i])
2129  camSlots[i]->Process();
2130  }
2131  }
2132 }
2133 
2134 // --- cCamSlot --------------------------------------------------------------
2135 
2136 #define MODULE_CHECK_INTERVAL 500 // ms
2137 #define MODULE_RESET_TIMEOUT 2 // s
2138 
2139 cCamSlot::cCamSlot(cCiAdapter *CiAdapter, bool WantsTsData, cCamSlot *MasterSlot)
2140 {
2141  ciAdapter = CiAdapter;
2143  assignedDevice = NULL;
2144  caPidReceiver = WantsTsData ? new cCaPidReceiver : NULL;
2145  caActivationReceiver = NULL;
2146  slotIndex = -1;
2147  mtdAvailable = false;
2148  mtdHandler = NULL;
2149  lastModuleStatus = msReset; // avoids initial reset log message
2150  resetTime = 0;
2151  resendPmt = false;
2152  for (int i = 0; i <= MAX_CONNECTIONS_PER_CAM_SLOT; i++) // tc[0] is not used, but initialized anyway
2153  tc[i] = NULL;
2154  if (MasterSlot)
2156  if (ciAdapter) {
2157  CamSlots.Add(this);
2158  slotNumber = Index() + 1;
2159  ciAdapter->AddCamSlot(this);
2160  Reset();
2161  }
2162 }
2163 
2165 {
2166  Assign(NULL);
2167  delete caPidReceiver;
2168  delete caActivationReceiver;
2169  CamSlots.Del(this, false);
2171  delete mtdHandler;
2172 }
2173 
2175 {
2176  cMutexLock MutexLock(&mutex);
2177  if (mtdHandler)
2178  return mtdHandler->GetMtdCamSlot(this);
2179  return this;
2180 }
2181 
2182 bool cCamSlot::Assign(cDevice *Device, bool Query)
2183 {
2184  cMutexLock MutexLock(&mutex);
2185  if (Device == assignedDevice)
2186  return true;
2187  if (ciAdapter) {
2188  int OldDeviceNumber = 0;
2189  if (assignedDevice && !Query) {
2190  OldDeviceNumber = assignedDevice->DeviceNumber() + 1;
2191  if (caPidReceiver)
2193  assignedDevice->SetCamSlot(NULL);
2194  assignedDevice = NULL;
2195  }
2196  if (ciAdapter->Assign(Device, true)) {
2197  if (!Query) {
2198  StopDecrypting();
2199  if (ciAdapter->Assign(Device)) {
2200  if (Device) {
2201  Device->SetCamSlot(this);
2203  if (caPidReceiver) {
2204  caPidReceiver->Reset();
2206  }
2207  dsyslog("CAM %d: assigned to device %d", MasterSlotNumber(), Device->DeviceNumber() + 1);
2208  }
2209  else {
2210  CancelActivation();
2211  dsyslog("CAM %d: unassigned from device %d", MasterSlotNumber(), OldDeviceNumber);
2212  }
2213  }
2214  else
2215  return false;
2216  }
2217  return true;
2218  }
2219  }
2220  return false;
2221 }
2222 
2224 {
2225  cMutexLock MutexLock(&mutex);
2226  if (mtdHandler)
2227  return mtdHandler->Devices(CardIndexes);
2228  if (assignedDevice)
2229  CardIndexes.Append(assignedDevice->CardIndex());
2230  return CardIndexes.Size() > 0;
2231 }
2232 
2234 {
2235  cMutexLock MutexLock(&mutex);
2236  for (int i = 1; i <= MAX_CONNECTIONS_PER_CAM_SLOT; i++) {
2237  if (!tc[i]) {
2238  tc[i] = new cCiTransportConnection(this, i);
2239  tc[i]->CreateConnection();
2240  return;
2241  }
2242  }
2243  esyslog("ERROR: CAM %d: can't create new transport connection!", slotNumber);
2244 }
2245 
2247 {
2248  cMutexLock MutexLock(&mutex);
2249  for (int i = 1; i <= MAX_CONNECTIONS_PER_CAM_SLOT; i++) {
2250  delete tc[i];
2251  tc[i] = NULL;
2252  }
2253 }
2254 
2256 {
2257  cMutexLock MutexLock(&mutex);
2258  if (TPDU) {
2259  int n = TPDU->Tcid();
2260  if (1 <= n && n <= MAX_CONNECTIONS_PER_CAM_SLOT) {
2261  if (tc[n])
2262  tc[n]->Process(TPDU);
2263  }
2264  }
2265  for (int i = 1; i <= MAX_CONNECTIONS_PER_CAM_SLOT; i++) {
2266  if (tc[i]) {
2267  if (!tc[i]->Process()) {
2268  Reset();
2269  return;
2270  }
2271  }
2272  }
2273  if (moduleCheckTimer.TimedOut()) {
2274  eModuleStatus ms = ModuleStatus();
2275  if (ms != lastModuleStatus) {
2276  switch (ms) {
2277  case msNone:
2278  dbgprotocol("Slot %d: no module present\n", slotNumber);
2279  isyslog("CAM %d: no module present", slotNumber);
2280  StopDecrypting();
2282  CancelActivation();
2283  if (mtdHandler)
2285  else
2286  Assign(NULL);
2287  break;
2288  case msReset:
2289  dbgprotocol("Slot %d: module reset\n", slotNumber);
2290  isyslog("CAM %d: module reset", slotNumber);
2292  break;
2293  case msPresent:
2294  dbgprotocol("Slot %d: module present\n", slotNumber);
2295  isyslog("CAM %d: module present", slotNumber);
2296  break;
2297  case msReady:
2298  dbgprotocol("Slot %d: module ready\n", slotNumber);
2299  isyslog("CAM %d: module ready", slotNumber);
2300  NewConnection();
2301  resendPmt = true;
2302  break;
2303  default:
2304  esyslog("ERROR: unknown module status %d (%s)", ms, __FUNCTION__);
2305  }
2306  lastModuleStatus = ms;
2307  }
2309  }
2310  if (resendPmt && Ready()) {
2311  if (mtdHandler) {
2313  resendPmt = false;
2314  }
2315  else if (caProgramList.Count())
2316  StartDecrypting();
2317  }
2318  processed.Broadcast();
2319 }
2320 
2322 {
2323  cMutexLock MutexLock(&mutex);
2324  return tc[1] ? tc[1]->GetSessionByResourceId(ResourceId) : NULL;
2325 }
2326 
2328 {
2329  cMutexLock MutexLock(&mutex);
2330  if (ciAdapter && TPDU->Size()) {
2331  TPDU->Dump(SlotNumber(), true);
2332  ciAdapter->Write(TPDU->Buffer(), TPDU->Size());
2333  }
2334 }
2335 
2337 {
2338  cMutexLock MutexLock(&mutex);
2341  if (ciAdapter) {
2342  dbgprotocol("Slot %d: reset...", slotNumber);
2343  if (ciAdapter->Reset(slotIndex)) {
2344  resetTime = time(NULL);
2345  dbgprotocol("ok.\n");
2347  return true;
2348  }
2349  dbgprotocol("failed!\n");
2350  }
2351  return false;
2352 }
2353 
2355 {
2356  return ModuleStatus() == msReady;
2357 }
2358 
2360 {
2361  cMutexLock MutexLock(&mutex);
2362  if (!caActivationReceiver) {
2363  if (cDevice *d = Device()) {
2365  if (const cChannel *Channel = Channels->GetByNumber(cDevice::CurrentChannel())) {
2366  caActivationReceiver = new cCaActivationReceiver(Channel, this);
2367  d->AttachReceiver(caActivationReceiver);
2368  dsyslog("CAM %d: activating on device %d with channel %d (%s)", SlotNumber(), d->DeviceNumber() + 1, Channel->Number(), Channel->Name());
2369  }
2370  }
2371  }
2372 }
2373 
2375 {
2376  cMutexLock MutexLock(&mutex);
2377  if (mtdHandler)
2379  else {
2380  delete caActivationReceiver;
2381  caActivationReceiver = NULL;
2382  }
2383 }
2384 
2386 {
2387  if (mtdHandler)
2388  return mtdHandler->IsActivating();
2389  return caActivationReceiver;
2390 }
2391 
2393 {
2394  cMutexLock MutexLock(&mutex);
2396  if (resetTime) {
2397  if (ms <= msReset) {
2398  if (time(NULL) - resetTime < MODULE_RESET_TIMEOUT)
2399  return msReset;
2400  }
2401  resetTime = 0;
2402  }
2403  return ms;
2404 }
2405 
2406 const char *cCamSlot::GetCamName(void)
2407 {
2408  cMutexLock MutexLock(&mutex);
2409  return tc[1] ? tc[1]->GetCamName() : NULL;
2410 }
2411 
2413 {
2414  cMutexLock MutexLock(&mutex);
2415  return ModuleStatus() == msNone || tc[1] && tc[1]->Ready();
2416 }
2417 
2419 {
2421 }
2422 
2424 {
2425  cMutexLock MutexLock(&mutex);
2426  return tc[1] && tc[1]->HasUserIO();
2427 }
2428 
2430 {
2431  cMutexLock MutexLock(&mutex);
2433  return api ? api->EnterMenu() : false;
2434 }
2435 
2437 {
2438  cMutexLock MutexLock(&mutex);
2440  if (mmi) {
2441  cCiMenu *Menu = mmi->Menu();
2442  if (Menu)
2443  Menu->mutex = &mutex;
2444  return Menu;
2445  }
2446  return NULL;
2447 }
2448 
2450 {
2451  cMutexLock MutexLock(&mutex);
2453  if (mmi) {
2454  cCiEnquiry *Enquiry = mmi->Enquiry();
2455  if (Enquiry)
2456  Enquiry->mutex = &mutex;
2457  return Enquiry;
2458  }
2459  return NULL;
2460 }
2461 
2463 {
2464  for (int i = 0; i < caPmts.Size(); i++)
2465  delete caPmts[i];
2466 }
2467 
2468 cCiCaPmt *cCiCaPmtList::Add(uint8_t CmdId, int Source, int Transponder, int ProgramNumber, const int *CaSystemIds)
2469 {
2470  cCiCaPmt *p = new cCiCaPmt(CmdId, Source, Transponder, ProgramNumber, CaSystemIds);
2471  caPmts.Append(p);
2472  return p;
2473 }
2474 
2476 {
2477  if (caPmts.RemoveElement(CaPmt))
2478  delete CaPmt;
2479 }
2480 
2482 {
2483  cMutexLock MutexLock(&mutex);
2485  return cas && cas->RepliesToQuery();
2486 }
2487 
2488 void cCamSlot::BuildCaPmts(uint8_t CmdId, cCiCaPmtList &CaPmtList, cMtdMapper *MtdMapper)
2489 {
2490  cMutexLock MutexLock(&mutex);
2491  CaPmtList.caPmts.Clear();
2492  const int *CaSystemIds = GetCaSystemIds();
2493  if (CaSystemIds && *CaSystemIds) {
2494  if (caProgramList.Count()) {
2495  for (cCiCaProgramData *p = caProgramList.First(); p; p = caProgramList.Next(p)) {
2496  if (p->modified || resendPmt) {
2497  bool Active = p->Active();
2498  cCiCaPmt *CaPmt = CaPmtList.Add(Active ? CmdId : CPCI_NOT_SELECTED, source, transponder, p->programNumber, CaSystemIds);
2499  for (cCiCaPidData *q = p->pidList.First(); q; q = p->pidList.Next(q)) {
2500  if (q->active)
2501  CaPmt->AddPid(q->pid, q->streamType);
2502  }
2503  if (caPidReceiver) {
2504  int CaPids[MAXRECEIVEPIDS + 1];
2505  if (GetCaPids(source, transponder, p->programNumber, CaSystemIds, MAXRECEIVEPIDS + 1, CaPids) > 0) {
2506  if (Active)
2507  caPidReceiver->AddPids(CaPids);
2508  else
2509  caPidReceiver->DelPids(CaPids);
2510  }
2511  }
2512  if (RepliesToQuery())
2513  CaPmt->SetListManagement(Active ? CPLM_ADD : CPLM_UPDATE);
2514  if (MtdMapper)
2515  CaPmt->MtdMapPids(MtdMapper);
2516  p->modified = false;
2517  }
2518  }
2519  }
2520  else if (CmdId == CPCI_NOT_SELECTED)
2521  CaPmtList.Add(CmdId, 0, 0, 0, NULL);
2522  }
2523 }
2524 
2526 {
2527  cMutexLock MutexLock(&mutex);
2529  if (cas) {
2530  for (int i = 0; i < CaPmtList.caPmts.Size(); i++)
2531  cas->SendPMT(CaPmtList.caPmts[i]);
2532  }
2533  resendPmt = false;
2534 }
2535 
2536 void cCamSlot::SendCaPmt(uint8_t CmdId)
2537 {
2538  cMutexLock MutexLock(&mutex);
2539  cCiCaPmtList CaPmtList;
2540  BuildCaPmts(CmdId, CaPmtList);
2541  SendCaPmts(CaPmtList);
2542 }
2543 
2545 {
2546  mtdAvailable = true;
2547 }
2548 
2550 {
2551  if (McdAvailable() && MtdAvailable()) {
2552  if (On) {
2553  if (!mtdHandler) {
2554  dsyslog("CAM %d: activating MTD support", SlotNumber());
2555  mtdHandler = new cMtdHandler;
2556  }
2557  }
2558  else if (mtdHandler) {
2559  dsyslog("CAM %d: deactivating MTD support", SlotNumber());
2560  delete mtdHandler;
2561  mtdHandler = NULL;
2562  }
2563  }
2564 }
2565 
2566 int cCamSlot::MtdPutData(uchar *Data, int Count)
2567 {
2568  return mtdHandler->Put(Data, Count);
2569 }
2570 
2572 {
2573  cMutexLock MutexLock(&mutex);
2575  return cas ? cas->GetCaSystemIds() : NULL;
2576 }
2577 
2579 {
2580  if (mtdHandler)
2581  return mtdHandler->Priority();
2582  cDevice *d = Device();
2583  return d ? d->Priority() : IDLEPRIORITY;
2584 }
2585 
2586 bool cCamSlot::ProvidesCa(const int *CaSystemIds)
2587 {
2588  cMutexLock MutexLock(&mutex);
2590  if (cas) {
2591  for (const int *ids = cas->GetCaSystemIds(); ids && *ids; ids++) {
2592  for (const int *id = CaSystemIds; *id; id++) {
2593  if (*id == *ids)
2594  return true;
2595  }
2596  }
2597  }
2598  return false;
2599 }
2600 
2601 void cCamSlot::AddPid(int ProgramNumber, int Pid, int StreamType)
2602 {
2603  cMutexLock MutexLock(&mutex);
2604  cCiCaProgramData *ProgramData = NULL;
2605  for (cCiCaProgramData *p = caProgramList.First(); p; p = caProgramList.Next(p)) {
2606  if (p->programNumber == ProgramNumber) {
2607  ProgramData = p;
2608  for (cCiCaPidData *q = p->pidList.First(); q; q = p->pidList.Next(q)) {
2609  if (q->pid == Pid)
2610  return;
2611  }
2612  }
2613  }
2614  if (!ProgramData)
2615  caProgramList.Add(ProgramData = new cCiCaProgramData(ProgramNumber));
2616  ProgramData->pidList.Add(new cCiCaPidData(Pid, StreamType));
2617 }
2618 
2619 void cCamSlot::SetPid(int Pid, bool Active)
2620 {
2622  return;
2623  cMutexLock MutexLock(&mutex);
2624  for (cCiCaProgramData *p = caProgramList.First(); p; p = caProgramList.Next(p)) {
2625  for (cCiCaPidData *q = p->pidList.First(); q; q = p->pidList.Next(q)) {
2626  if (q->pid == Pid) {
2627  if (q->active != Active) {
2628  q->active = Active;
2629  p->modified = true;
2630  }
2631  return;
2632  }
2633  }
2634  }
2635 }
2636 
2637 // see ISO/IEC 13818-1
2638 #define STREAM_TYPE_VIDEO 0x02
2639 #define STREAM_TYPE_AUDIO 0x04
2640 #define STREAM_TYPE_PRIVATE 0x06
2641 
2642 void cCamSlot::AddChannel(const cChannel *Channel)
2643 {
2644  cMutexLock MutexLock(&mutex);
2645  if (source != Channel->Source() || transponder != Channel->Transponder())
2646  StopDecrypting();
2647  source = Channel->Source();
2648  transponder = Channel->Transponder();
2649  if (Channel->Ca() >= CA_ENCRYPTED_MIN) {
2650  AddPid(Channel->Sid(), Channel->Vpid(), STREAM_TYPE_VIDEO);
2651  for (const int *Apid = Channel->Apids(); *Apid; Apid++)
2652  AddPid(Channel->Sid(), *Apid, STREAM_TYPE_AUDIO);
2653  for (const int *Dpid = Channel->Dpids(); *Dpid; Dpid++)
2654  AddPid(Channel->Sid(), *Dpid, STREAM_TYPE_PRIVATE);
2655  for (const int *Spid = Channel->Spids(); *Spid; Spid++)
2656  AddPid(Channel->Sid(), *Spid, STREAM_TYPE_PRIVATE);
2657  }
2658 }
2659 
2660 #define QUERY_REPLY_WAIT 100 // ms to wait between checks for a reply
2661 
2662 bool cCamSlot::CanDecrypt(const cChannel *Channel, cMtdMapper *MtdMapper)
2663 {
2664  if (Channel->Ca() < CA_ENCRYPTED_MIN)
2665  return true; // channel not encrypted
2666  if (!IsDecrypting())
2667  return true; // any CAM can decrypt at least one channel
2668  cMutexLock MutexLock(&mutex);
2670  if (cas && cas->RepliesToQuery()) {
2671  cCiCaPmt CaPmt(CPCI_QUERY, Channel->Source(), Channel->Transponder(), Channel->Sid(), GetCaSystemIds());
2672  CaPmt.SetListManagement(CPLM_ADD); // WORKAROUND: CPLM_ONLY doesn't work with Alphacrypt 3.09 (deletes existing CA_PMTs)
2673  CaPmt.AddPid(Channel->Vpid(), STREAM_TYPE_VIDEO);
2674  for (const int *Apid = Channel->Apids(); *Apid; Apid++)
2675  CaPmt.AddPid(*Apid, STREAM_TYPE_AUDIO);
2676  for (const int *Dpid = Channel->Dpids(); *Dpid; Dpid++)
2677  CaPmt.AddPid(*Dpid, STREAM_TYPE_PRIVATE);
2678  for (const int *Spid = Channel->Spids(); *Spid; Spid++)
2679  CaPmt.AddPid(*Spid, STREAM_TYPE_PRIVATE);
2680  if (MtdMapper)
2681  CaPmt.MtdMapPids(MtdMapper);
2682  cas->SendPMT(&CaPmt);
2683  cTimeMs Timeout(QUERY_REPLY_TIMEOUT);
2684  do {
2686  if ((cas = (cCiConditionalAccessSupport *)GetSessionByResourceId(RI_CONDITIONAL_ACCESS_SUPPORT)) != NULL) { // must re-fetch it, there might have been a reset
2687  if (cas->ReceivedReply())
2688  return cas->CanDecrypt();
2689  }
2690  else
2691  return false;
2692  } while (!Timeout.TimedOut());
2693  dsyslog("CAM %d: didn't reply to QUERY", SlotNumber());
2694  }
2695  return false;
2696 }
2697 
2699 {
2701 }
2702 
2704 {
2705  cMutexLock MutexLock(&mutex);
2706  if (caProgramList.Count()) {
2707  caProgramList.Clear();
2708  if (!dynamic_cast<cMtdCamSlot *>(this))
2710  }
2711 }
2712 
2714 {
2715  cMutexLock MutexLock(&mutex);
2716  if (mtdHandler)
2717  return mtdHandler->IsDecrypting();
2718  if (caProgramList.Count()) {
2719  for (cCiCaProgramData *p = caProgramList.First(); p; p = caProgramList.Next(p)) {
2720  if (p->modified)
2721  return true; // any modifications need to be processed before we can assume it's no longer decrypting
2722  for (cCiCaPidData *q = p->pidList.First(); q; q = p->pidList.Next(q)) {
2723  if (q->active)
2724  return true;
2725  }
2726  }
2727  }
2728  return false;
2729 }
2730 
2731 uchar *cCamSlot::Decrypt(uchar *Data, int &Count)
2732 {
2733  if (Data)
2734  Count = TS_SIZE;
2735  return Data;
2736 }
2737 
2739 {
2740  return tc[1] ? tc[1]->TsPostProcess(Data) : false;
2741 }
2742 
2743 bool cCamSlot::Inject(uchar *Data, int Count)
2744 {
2745  return true;
2746 }
2747 
2748 void cCamSlot::InjectEit(int Sid)
2749 {
2750  cEitGenerator Eit(Sid);
2751  Inject(Eit.Data(), Eit.Length());
2752 }
2753 
2754 // --- cCamSlots -------------------------------------------------------------
2755 
2757 
2759 {
2760  int n = 0;
2761  for (cCamSlot *CamSlot = CamSlots.First(); CamSlot; CamSlot = CamSlots.Next(CamSlot)) {
2762  if (CamSlot->IsMasterSlot() && CamSlot->ModuleStatus() == msReady)
2763  n++;
2764  }
2765  return n;
2766 }
2767 
2769 {
2770  bool ready = true;
2771  for (time_t t0 = time(NULL); time(NULL) - t0 < Timeout; ) {
2772  ready = true;
2773  for (cCamSlot *CamSlot = CamSlots.First(); CamSlot; CamSlot = CamSlots.Next(CamSlot)) {
2774  if (!CamSlot->Ready()) {
2775  ready = false;
2776  cCondWait::SleepMs(100);
2777  }
2778  }
2779  if (ready)
2780  break;
2781  }
2782  for (cCamSlot *CamSlot = CamSlots.First(); CamSlot; CamSlot = CamSlots.Next(CamSlot))
2783  dsyslog("CAM %d: %sready, %s", CamSlot->SlotNumber(), CamSlot->Ready() ? "" : "not ", CamSlot->IsMasterSlot() ? *cString::sprintf("master (%s)", CamSlot->GetCamName() ? CamSlot->GetCamName() : "empty") : *cString::sprintf("slave of CAM %d", CamSlot->MasterSlotNumber()));
2784  return ready;
2785 }
2786 
2787 // --- cChannelCamRelation ---------------------------------------------------
2788 
2789 #define CAM_CHECKED_TIMEOUT 15 // seconds before a CAM that has been checked for a particular channel will be checked again
2790 
2792 private:
2796  time_t lastChecked;
2797 public:
2799  bool TimedOut(void);
2800  tChannelID ChannelID(void) { return channelID; }
2801  bool CamChecked(int CamSlotNumber);
2802  bool CamDecrypt(int CamSlotNumber);
2803  void SetChecked(int CamSlotNumber);
2804  void SetDecrypt(int CamSlotNumber);
2805  void ClrChecked(int CamSlotNumber);
2806  void ClrDecrypt(int CamSlotNumber);
2807  };
2808 
2810 {
2811  channelID = ChannelID;
2812  camSlotsChecked = 0;
2813  camSlotsDecrypt = 0;
2814  lastChecked = 0;
2815 }
2816 
2818 {
2819  return !camSlotsDecrypt && time(NULL) - lastChecked > CAM_CHECKED_TIMEOUT;
2820 }
2821 
2822 bool cChannelCamRelation::CamChecked(int CamSlotNumber)
2823 {
2824  if (lastChecked && time(NULL) - lastChecked > CAM_CHECKED_TIMEOUT) {
2825  lastChecked = 0;
2826  camSlotsChecked = 0;
2827  }
2828  return camSlotsChecked & (1 << (CamSlotNumber - 1));
2829 }
2830 
2831 bool cChannelCamRelation::CamDecrypt(int CamSlotNumber)
2832 {
2833  return camSlotsDecrypt & (1 << (CamSlotNumber - 1));
2834 }
2835 
2836 void cChannelCamRelation::SetChecked(int CamSlotNumber)
2837 {
2838  camSlotsChecked |= (1 << (CamSlotNumber - 1));
2839  lastChecked = time(NULL);
2840  ClrDecrypt(CamSlotNumber);
2841 }
2842 
2843 void cChannelCamRelation::SetDecrypt(int CamSlotNumber)
2844 {
2845  camSlotsDecrypt |= (1 << (CamSlotNumber - 1));
2846  ClrChecked(CamSlotNumber);
2847 }
2848 
2849 void cChannelCamRelation::ClrChecked(int CamSlotNumber)
2850 {
2851  camSlotsChecked &= ~(1 << (CamSlotNumber - 1));
2852  lastChecked = 0;
2853 }
2854 
2855 void cChannelCamRelation::ClrDecrypt(int CamSlotNumber)
2856 {
2857  camSlotsDecrypt &= ~(1 << (CamSlotNumber - 1));
2858 }
2859 
2860 // --- cChannelCamRelations --------------------------------------------------
2861 
2862 #define MAX_CAM_NUMBER 32
2863 #define CHANNEL_CAM_RELATIONS_CLEANUP_INTERVAL 3600 // seconds between cleanups
2864 
2866 
2868 {
2869  lastCleanup = time(NULL);
2870 }
2871 
2873 {
2874  cMutexLock MutexLock(&mutex);
2876  for (cChannelCamRelation *ccr = First(); ccr; ) {
2877  cChannelCamRelation *c = ccr;
2878  ccr = Next(ccr);
2879  if (c->TimedOut())
2880  Del(c);
2881  }
2882  lastCleanup = time(NULL);
2883  }
2884 }
2885 
2887 {
2888  cMutexLock MutexLock(&mutex);
2889  Cleanup();
2890  for (cChannelCamRelation *ccr = First(); ccr; ccr = Next(ccr)) {
2891  if (ccr->ChannelID() == ChannelID)
2892  return ccr;
2893  }
2894  return NULL;
2895 }
2896 
2898 {
2899  cMutexLock MutexLock(&mutex);
2900  cChannelCamRelation *ccr = GetEntry(ChannelID);
2901  if (!ccr)
2902  Add(ccr = new cChannelCamRelation(ChannelID));
2903  return ccr;
2904 }
2905 
2906 void cChannelCamRelations::Reset(int CamSlotNumber)
2907 {
2908  cMutexLock MutexLock(&mutex);
2909  for (cChannelCamRelation *ccr = First(); ccr; ccr = Next(ccr)) {
2910  ccr->ClrChecked(CamSlotNumber);
2911  ccr->ClrDecrypt(CamSlotNumber);
2912  }
2913 }
2914 
2915 bool cChannelCamRelations::CamChecked(tChannelID ChannelID, int CamSlotNumber)
2916 {
2917  cMutexLock MutexLock(&mutex);
2918  cChannelCamRelation *ccr = GetEntry(ChannelID);
2919  return ccr ? ccr->CamChecked(CamSlotNumber) : false;
2920 }
2921 
2922 bool cChannelCamRelations::CamDecrypt(tChannelID ChannelID, int CamSlotNumber)
2923 {
2924  cMutexLock MutexLock(&mutex);
2925  cChannelCamRelation *ccr = GetEntry(ChannelID);
2926  return ccr ? ccr->CamDecrypt(CamSlotNumber) : false;
2927 }
2928 
2929 void cChannelCamRelations::SetChecked(tChannelID ChannelID, int CamSlotNumber)
2930 {
2931  cMutexLock MutexLock(&mutex);
2932  cChannelCamRelation *ccr = AddEntry(ChannelID);
2933  if (ccr)
2934  ccr->SetChecked(CamSlotNumber);
2935 }
2936 
2937 void cChannelCamRelations::SetDecrypt(tChannelID ChannelID, int CamSlotNumber)
2938 {
2939  cMutexLock MutexLock(&mutex);
2940  cChannelCamRelation *ccr = AddEntry(ChannelID);
2941  if (ccr)
2942  ccr->SetDecrypt(CamSlotNumber);
2943 }
2944 
2945 void cChannelCamRelations::ClrChecked(tChannelID ChannelID, int CamSlotNumber)
2946 {
2947  cMutexLock MutexLock(&mutex);
2948  cChannelCamRelation *ccr = GetEntry(ChannelID);
2949  if (ccr)
2950  ccr->ClrChecked(CamSlotNumber);
2951 }
2952 
2953 void cChannelCamRelations::ClrDecrypt(tChannelID ChannelID, int CamSlotNumber)
2954 {
2955  cMutexLock MutexLock(&mutex);
2956  cChannelCamRelation *ccr = GetEntry(ChannelID);
2957  if (ccr)
2958  ccr->ClrDecrypt(CamSlotNumber);
2959 }
2960 
2961 void cChannelCamRelations::Load(const char *FileName)
2962 {
2963  cMutexLock MutexLock(&mutex);
2964  fileName = FileName;
2965  if (access(fileName, R_OK) == 0) {
2966  dsyslog("loading %s", *fileName);
2967  if (FILE *f = fopen(fileName, "r")) {
2968  cReadLine ReadLine;
2969  char *s;
2970  while ((s = ReadLine.Read(f)) != NULL) {
2971  if (char *p = strchr(s, ' ')) {
2972  *p = 0;
2973  if (*++p) {
2974  tChannelID ChannelID = tChannelID::FromString(s);
2975  if (ChannelID.Valid()) {
2976  char *q;
2977  char *strtok_next;
2978  while ((q = strtok_r(p, " ", &strtok_next)) != NULL) {
2979  int CamSlotNumber = atoi(q);
2980  if (CamSlotNumber >= 1 && CamSlotNumber <= MAX_CAM_NUMBER)
2981  SetDecrypt(ChannelID, CamSlotNumber);
2982  p = NULL;
2983  }
2984  }
2985  }
2986  }
2987  }
2988  fclose(f);
2989  }
2990  else
2992  }
2993 }
2994 
2996 {
2997  if (!*fileName)
2998  return;
2999  cMutexLock MutexLock(&mutex);
3000  struct stat st;
3001  if (stat(fileName, &st) == 0) {
3002  if ((st.st_mode & S_IWUSR) == 0) {
3003  dsyslog("not saving %s (file is read-only)", *fileName);
3004  return;
3005  }
3006  }
3007  dsyslog("saving %s", *fileName);
3008  cSafeFile f(fileName);
3009  if (f.Open()) {
3010  for (cChannelCamRelation *ccr = First(); ccr; ccr = Next(ccr)) {
3011  if (ccr->ChannelID().Valid()) {
3012  cString s;
3013  for (int i = 1; i <= MAX_CAM_NUMBER; i++) {
3014  if (ccr->CamDecrypt(i))
3015  s = cString::sprintf("%s%s%d", *s ? *s : "", *s ? " " : "", i);
3016  }
3017  if (*s)
3018  fprintf(f, "%s %s\n", *ccr->ChannelID().ToString(), *s);
3019  }
3020  }
3021  f.Close();
3022  }
3023  else
3025 }
cCiHostControl(uint16_t SessionId, cCiTransportConnection *Tc)
Definition: ci.c:1239
uchar * Data(void)
Definition: remux.h:442
uint16_t applicationManufacturer
Definition: ci.h:72
Definition: ci.h:170
virtual void Process(int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:1309
cTimeMs alive
Definition: ci.c:586
cCiCaProgramData(int ProgramNumber)
Definition: ci.c:2059
#define RI_HOST_CONTROL
Definition: ci.c:637
#define AOT_DISPLAY_CONTROL
Definition: ci.c:661
#define MAXRECEIVEPIDS
Definition: receiver.h:15
int programNumber
Definition: ci.c:2056
unsigned char uchar
Definition: tools.h:31
#define EF_BLIND
Definition: ci.c:1363
static int MtdMapStream(uchar *p, cMtdMapper *MtdMapper)
Definition: ci.c:1013
cMutex mutex
Definition: ci.h:238
bool CanDecrypt(void)
Definition: ci.c:1091
int action
Definition: ci.c:334
virtual void Action(void)
Handles the attached CAM slots in a separate thread.
Definition: ci.c:2115
#define T_SB
Definition: ci.c:459
cCamSlot * MtdSpawn(void)
If this CAM slot can do MTD ("Multi Transponder Decryption"), a call to this function returns a cMtdC...
Definition: ci.c:2174
bool Devices(cVector< int > &CardIndexes)
Adds the card indexes of any devices that currently use this CAM to the given CardIndexes.
Definition: ci.c:2223
bool Process(cTPDU *TPDU=NULL)
Definition: ci.c:1949
#define CRA_SELECT
Definition: ci.c:328
#define AOT_PROFILE_ENQ
Definition: ci.c:644
static tChannelID FromString(const char *s)
Definition: channels.c:23
#define dsyslog(a...)
Definition: tools.h:37
int pid
Definition: ci.c:2042
cCamSlot * CamSlot(void) const
Returns the CAM slot that is currently used with this device, or NULL if no CAM slot is in use.
Definition: device.h:469
Definition: ci.h:492
uint16_t sessionId
Definition: ci.h:34
#define CA_ENCRYPTED_MIN
Definition: channels.h:44
cCiCaPidData(int Pid, int StreamType)
Definition: ci.c:2044
bool isnumber(const char *s)
Definition: tools.c:346
cVector< cCiCaPmt * > caPmts
Definition: ci.h:226
int MasterSlotNumber(void)
Returns the number of this CAM's master slot within the whole system.
Definition: ci.h:346
virtual bool ProvidesCa(const int *CaSystemIds)
Returns true if the CAM in this slot provides one of the given CaSystemIds.
Definition: ci.c:2586
cCondVar processed
Definition: ci.h:239
static char * CopyString(int Length, const uint8_t *Data)
Definition: ci.c:77
void Set(int Ms=0)
Definition: tools.c:774
bool Devices(cVector< int > &CardIndexes)
Adds the card indexes of the devices of any active MTD CAM slots to the given CardIndexes.
Definition: mtd.c:130
bool Close(void)
Definition: tools.c:1750
#define MAXCASYSTEMIDS
Definition: ci.c:882
virtual ~cCiAdapter()
The derived class must call Cancel(3) in its destructor.
Definition: ci.c:2083
uint8_t Tcid(void) const
Definition: ci.c:604
virtual bool HasUserIO(void)
Definition: ci.c:1379
const uint32_t * Ids(void)
Definition: ci.h:110
virtual void StartActivation(void)
Puts the CAM in this slot into a mode where an inserted smart card can be activated.
Definition: ci.c:2359
cCamSlot * ItCamSlot(int &Iter)
Iterates over all added CAM slots of this adapter.
Definition: ci.c:2104
#define MAX_TPDU_SIZE
Definition: ci.c:454
#define T_CREATE_TC
Definition: ci.c:461
bool RemoveElement(const T &Data)
Definition: tools.h:759
cCiSession(uint16_t SessionId, uint32_t ResourceId, cCiTransportConnection *Tc)
Definition: ci.c:694
cList< cCiCaPidData > pidList
Definition: ci.c:2058
virtual void AddPid(int ProgramNumber, int Pid, int StreamType)
Adds the given PID information to the list of PIDs.
Definition: ci.c:2601
bool HasUpdate(void)
Definition: ci.c:1629
virtual void Write(const uint8_t *Buffer, int Length)
Writes Length bytes of the given Buffer.
Definition: ci.h:192
void Add(cListObject *Object, cListObject *After=NULL)
Definition: tools.c:2152
uint16_t Peek13(const uchar *p)
Definition: tools.h:258
int source
Definition: ci.h:252
#define CRA_CONFIRM
Definition: ci.c:327
int esInfoLengthPos
Definition: ci.c:904
#define AOT_PROFILE_CHANGE
Definition: ci.c:646
bool CamChecked(int CamSlotNumber)
Definition: ci.c:2822
cCiMenu * menu
Definition: ci.c:1373
#define T_REQUEST_TC
Definition: ci.c:465
cTPDU(void)
Definition: ci.c:477
#define AOT_NONE
Definition: ci.c:643
#define CATPID
Definition: remux.h:53
cCiApplicationInformation(uint16_t SessionId, cCiTransportConnection *Tc)
Definition: ci.c:824
virtual void InjectEit(int Sid)
Injects a generated EIT with a "present event" for the given Sid into the TS data stream sent to the ...
Definition: ci.c:2748
bool Open(void)
Definition: tools.c:1740
const char * GetMenuString(void)
Definition: ci.h:80
virtual void StartDecrypting(void)
Sends all CA_PMT entries to the CAM that have been modified since the last call to this function.
Definition: ci.c:2698
int caSystemIds[MAXCASYSTEMIDS+1]
Definition: ci.c:1079
bool TsPayloadStart(const uchar *p)
Definition: remux.h:72
#define AOT_ENTER_MENU
Definition: ci.c:649
#define MAX_CONNECTIONS_PER_CAM_SLOT
Definition: ci.h:21
static char * GetString(int &Length, const uint8_t **Data)
Definition: ci.c:96
static int MtdMapCaDescriptors(uchar *p, cMtdMapper *MtdMapper)
Definition: ci.c:996
void MtdActivate(bool On)
Activates (On == true) or deactivates (On == false) MTD.
Definition: ci.c:2549
#define MAX_CAM_SLOTS_PER_ADAPTER
Definition: ci.h:20
#define AOT_APPLICATION_INFO_ENQ
Definition: ci.c:647
cCiResourceHandlers CiResourceHandlers
Definition: ci.c:1739
virtual bool TsPostProcess(uchar *Data)
If there is a cCiSession that needs to do additional processing on TS packets (after the CAM has done...
Definition: ci.c:2738
virtual void Receive(const uchar *Data, int Length)
This function is called from the cDevice we are attached to, and delivers one TS packet from the set ...
Definition: ci.c:302
static cString sprintf(const char *fmt,...) __attribute__((format(printf
Definition: tools.c:1127
bool MtdAvailable(void)
Returns true if this CAM supports MTD ("Multi Transponder Decryption").
Definition: ci.h:285
cCamResponses CamResponses
Definition: ci.c:445
#define CHANNEL_CAM_RELATIONS_CLEANUP_INTERVAL
Definition: ci.c:2863
virtual void Append(T Data)
Definition: tools.h:737
Definition: ci.h:148
int QueueMessage(eMessageType Type, const char *s, int Seconds=0, int Timeout=0)
Like Message(), but this function may be called from a background thread.
Definition: skins.c:293
int slotNumber
Definition: ci.h:246
int Source(void) const
Definition: channels.h:150
virtual void Process(int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:1104
int NumReadyMasterSlots(void)
Returns the number of master CAM slots in the system that are ready to decrypt.
Definition: ci.c:2758
void SetCamSlot(cCamSlot *CamSlot)
Sets the given CamSlot to be used with this device.
Definition: device.c:440
#define T_CTC_REPLY
Definition: ci.c:462
char * bottomText
Definition: ci.h:129
#define SIZE_INDICATOR
Definition: ci.c:40
#define RESOURCE_CLASS_MASK
Definition: ci.c:692
static bool DumpDateTime
Definition: ci.c:34
bool SendCloseMMI(void)
Definition: ci.c:1590
#define esyslog(a...)
Definition: tools.h:35
#define QUERY_WAIT_TIME
Definition: ci.c:1071
#define dbgprotocol(a...)
Definition: ci.c:36
void Select(int Index)
Definition: ci.c:1635
#define AOT_ANSW
Definition: ci.c:668
#define ST_CLOSE_SESSION_RESPONSE
Definition: ci.c:625
virtual void Process(int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:784
void Detach(cFilter *Filter)
Detaches the given filter from this device.
Definition: device.c:699
cCamSlot * CamSlot(void)
Definition: ci.c:758
#define CRA_DISCARD
Definition: ci.c:326
int camNumber
Definition: ci.c:332
int Index(void) const
Definition: tools.c:2072
Definition: ci.h:170
bool AttachReceiver(cReceiver *Receiver)
Attaches the given receiver to this device.
Definition: device.c:1750
void MtdEnable(void)
Enables MTD support for this CAM.
Definition: ci.c:2544
virtual bool CanActivate(void)
Returns true if there is a CAM in this slot that can be put into activation mode.
Definition: ci.c:2354
static bool DumpTPDUDataTransfer
Definition: ci.c:31
#define DCC_SET_MMI_MODE
Definition: ci.c:1338
#define LOG_ERROR_STR(s)
Definition: tools.h:40
cMutex mutex
Definition: ci.c:125
bool AddPids(const int *Pids)
Adds the given zero terminated list of Pids to the list of PIDs of this receiver.
Definition: receiver.c:60
uint8_t ListManagement(void)
Definition: ci.c:916
bool Load(const char *FileName=NULL, bool AllowComments=false, bool MustExist=false)
Definition: config.h:120
#define AOT_CLOSE_MMI
Definition: ci.c:660
virtual bool Inject(uchar *Data, int Count)
Sends all Count bytes of the given Data to the CAM, and returns true if this was possible.
Definition: ci.c:2743
int source
Definition: ci.c:907
cTimeMs timer
Definition: ci.c:587
bool Parse(const char *s)
Definition: ci.c:354
int GetTag(int &Length, const uint8_t **Data)
Definition: ci.c:715
#define CPCI_NOT_SELECTED
Definition: ci.c:898
virtual void Process(int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:1425
bool resendPmt
Definition: ci.h:251
uint8_t tcid
Definition: ci.c:581
#define CPLM_ADD
Definition: ci.c:890
#define AOT_APPLICATION_INFO
Definition: ci.c:648
cCiMMI * mmi
Definition: ci.h:152
const int * GetCaSystemIds(void)
Definition: ci.c:1086
cDevice * Device(void)
Definition: receiver.h:32
const int * Spids(void) const
Definition: channels.h:157
#define STREAM_TYPE_VIDEO
Definition: ci.c:2638
friend class cCiTransportConnection
Definition: ci.h:234
virtual ~cCaPidReceiver()
Definition: ci.c:131
uint32_t resourceId
Definition: ci.h:35
#define MINPRIORITY
Definition: config.h:44
time_t resetTime
Definition: ci.h:249
void Set(int Index, uchar Data)
Definition: tools.h:839
bool Selectable(void)
Definition: ci.h:141
#define AI_CANCEL
Definition: ci.c:1367
cCiSession * GetSessionByResourceId(uint32_t ResourceId)
Definition: ci.c:1870
char * GetText(int &Length, const uint8_t **Data)
Definition: ci.c:1409
cCiAdapter(void)
Definition: ci.c:2076
Definition: ci.c:1370
int SlotIndex(void)
Returns the index of this CAM slot within its CI adapter.
Definition: ci.h:340
cCiSession * GetNewCiSession(uint32_t ResourceId, uint16_t SessionId, cCiTransportConnection *Tc)
Definition: ci.c:1759
cCamSlot * camSlot
Definition: ci.c:580
T min(T a, T b)
Definition: tools.h:59
int Ca(int Index=0) const
Definition: channels.h:171
int slotIndex
Definition: ci.h:245
cCaPidReceiver(void)
Definition: ci.c:146
#define ST_SESSION_NUMBER
Definition: ci.c:619
const uint8_t * GetData(const uint8_t *Data, int &Length)
Definition: ci.c:554
void SetTsPostProcessor(void)
If this cCiSession implements the TsPostProcess() function, it shall call SetTsPostProcessor() to reg...
Definition: ci.c:710
bool CamDecrypt(int CamSlotNumber)
Definition: ci.c:2831
void NewConnection(void)
Definition: ci.c:2233
virtual eModuleStatus ModuleStatus(void)
Returns the status of the CAM in this slot.
Definition: ci.c:2392
int numEntries
Definition: ci.h:131
void AddPid(int Pid, uint8_t StreamType)
Definition: ci.c:949
cCiSession * sessions[MAX_SESSIONS_PER_TC+1]
Definition: ci.c:588
virtual void AddChannel(const cChannel *Channel)
Adds all PIDs of the given Channel to the current list of PIDs.
Definition: ci.c:2642
uint32_t ResourceId(void)
Definition: ci.h:53
const int * Apids(void) const
Definition: channels.h:155
void Write(cTPDU *TPDU)
Definition: ci.c:2327
#define AOT_TUNE
Definition: ci.c:654
char * Read(FILE *f)
Definition: tools.c:1459
void SetListManagement(uint8_t ListManagement)
Definition: ci.c:944
#define MALLOC(type, size)
Definition: tools.h:47
#define RI_CONDITIONAL_ACCESS_SUPPORT
Definition: ci.c:636
void Cleanup(void)
Definition: ci.c:2872
virtual void Clear(void)
Definition: tools.c:2229
int TsPid(const uchar *p)
Definition: remux.h:82
virtual void SendCaPmt(uint8_t CmdId)
Definition: ci.c:2536
bool McdAvailable(void)
Returns true if this CAM supports MCD ("Multi Channel Decyption").
Definition: ci.h:283
#define AOT_CA_INFO_ENQ
Definition: ci.c:650
uint32_t camSlotsChecked
Definition: ci.c:2794
void Reset(void)
Definition: ci.c:134
virtual bool Reset(int Slot)
Resets the CAM in the given Slot.
Definition: ci.h:194
#define AOT_TEXT_LAST
Definition: ci.c:663
cCiTransportConnection * tc[MAX_CONNECTIONS_PER_CAM_SLOT+1]
Definition: ci.h:247
#define MAX_CAM_NUMBER
Definition: ci.c:2862
#define CRA_NONE
Definition: ci.c:325
uint8_t applicationType
Definition: ci.h:71
void CreateConnection(void)
Definition: ci.c:605
int GetMatch(int CamNumber, const char *Text) const
Definition: ci.c:433
cCaActivationReceiver * caActivationReceiver
Definition: ci.h:244
void SendTag(uint8_t Tag, uint16_t SessionId, uint32_t ResourceId=0, int Status=-1)
Definition: ci.c:1832
static int MtdMapCaDescriptor(uchar *p, cMtdMapper *MtdMapper)
Definition: ci.c:979
T get_unaligned(T *p)
Definition: tools.h:80
#define MM_HIGH_LEVEL
Definition: ci.c:1346
void CancelActivation(void)
Tells all active MTD CAM slots to cancel activation.
Definition: mtd.c:115
bool blind
Definition: ci.h:155
#define AOT_MENU_LAST
Definition: ci.c:669
void MtdMapPid(uchar *p, cMtdMapper *MtdMapper)
Definition: mtd.c:230
void AddEmmPid(int Pid)
Definition: ci.c:158
int Transponder(void) const
Returns the transponder frequency in MHz, plus the polarization in case of sat.
Definition: channels.c:146
char * titleText
Definition: ci.h:127
#define MODULE_RESET_TIMEOUT
Definition: ci.c:2137
#define MAX_DUMP
#define IDLEPRIORITY
Definition: config.h:47
bool HasUserIO(void)
Definition: ci.c:609
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
Definition: device.h:350
void DelPids(const int *Pids)
Deletes the given zero terminated list of Pids from the list of PIDs of this receiver.
Definition: receiver.c:106
cCamSlot * masterSlot
Definition: ci.h:241
#define ST_CLOSE_SESSION_REQUEST
Definition: ci.c:624
cCiTransportConnection * tc
Definition: ci.h:36
int streamType
Definition: ci.c:2043
cCiSession * GetSessionByResourceId(uint32_t ResourceId)
Definition: ci.c:2321
int caSystemIds[MAXCASYSTEMIDS+1]
Definition: ci.c:910
virtual void Receive(const uchar *Data, int Length)
This function is called from the cDevice we are attached to, and delivers one TS packet from the set ...
Definition: ci.c:181
virtual void Process(int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:1245
const int * Dpids(void) const
Definition: channels.h:156
~cCiMenu()
Definition: ci.c:1608
virtual ~cCamSlot()
Definition: ci.c:2164
cChannelCamRelation(tChannelID ChannelID)
Definition: ci.c:2809
uint8_t Tag(void)
Definition: ci.c:481
int length
Definition: ci.c:124
char * subTitleText
Definition: ci.h:128
time_t lastScrambledTime
Definition: ci.c:280
virtual cCiSession * GetNewCiSession(uint32_t ResourceId, uint16_t SessionId, cCiTransportConnection *Tc)
Returns a new cCiSession, according to the given ResourceId.
Definition: ci.c:1724
uint32_t ResourceIdToInt(const uint8_t *Data)
Definition: ci.c:1860
bool Ready(void)
Definition: ci.c:1806
int programNumber
Definition: ci.c:909
#define CPLM_UPDATE
Definition: ci.c:891
#define QUERY_REPLY_WAIT
Definition: ci.c:2660
void HandleSessions(cTPDU *TPDU)
Definition: ci.c:1922
cCiEnquiry(cCiMMI *MMI)
Definition: ci.c:1656
void Process(cTPDU *TPDU=NULL)
Definition: ci.c:2255
#define MAX_TPDU_DATA
Definition: ci.c:455
int MtdPutData(uchar *Data, int Count)
Sends at most Count bytes of the given Data to the individual MTD CAM slots that are using this CAM.
Definition: ci.c:2566
virtual ~cCiResourceHandler()
Definition: ci.c:1698
void GetCaDescriptors(int Source, int Transponder, int ServiceId, const int *CaSystemIds, cDynamicBuffer &Buffer, int EsPid)
Gets all CA descriptors for a given channel.
Definition: pat.c:268
virtual bool HasUserIO(void)
Returns true if there is a pending user interaction, which shall be retrieved via GetMenu() or GetEnq...
Definition: ci.c:2423
void DelEmmPids(void)
Definition: ci.c:171
uint16_t SessionId(void)
Definition: ci.h:52
void SetDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2937
void SendData(int Tag, int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:736
cCiEnquiry * enquiry
Definition: ci.c:1374
void Broadcast(void)
Definition: thread.c:150
cCiSession * GetSessionBySessionId(uint16_t SessionId)
Definition: ci.c:1865
cDynamicBuffer capmt
Definition: ci.c:906
void SendDateTime(void)
Definition: ci.c:1284
int Sid(void) const
Definition: channels.h:174
virtual cCiMenu * GetMenu(void)
Gets a pending menu, or NULL if there is no menu.
Definition: ci.c:2436
int Size(void) const
Definition: tools.h:717
bool handlingPid
Definition: ci.c:126
bool SendAnswer(const char *Text)
Definition: ci.c:1578
void StartDecrypting(void)
Tells all active MTD CAM slots to start decrypting.
Definition: mtd.c:105
#define LOCK_CHANNELS_READ
Definition: channels.h:265
cCiConditionalAccessSupport(uint16_t SessionId, cCiTransportConnection *Tc)
Definition: ci.c:1094
#define AI_ANSWER
Definition: ci.c:1368
Definition: ci.h:32
int Length(void)
Definition: tools.h:843
int expectedLength
Definition: ci.h:156
#define ST_OPEN_SESSION_RESPONSE
Definition: ci.c:621
uint8_t Tcid(void)
Definition: ci.c:480
#define RI_MMI
Definition: ci.c:639
int size
Definition: ci.c:473
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
Definition: thread.c:72
#define AOT_REPLACE
Definition: ci.c:655
void Cancel(void)
Definition: ci.c:1642
cList< cCiCaProgramData > caProgramList
Definition: ci.h:254
bool EnterMenu(void)
Definition: ci.c:870
#define STREAM_TYPE_AUDIO
Definition: ci.c:2639
cCiCaPmt(uint8_t CmdId, int Source, int Transponder, int ProgramNumber, const int *CaSystemIds)
Definition: ci.c:921
#define AOT_CA_INFO
Definition: ci.c:651
#define AOT_PROFILE
Definition: ci.c:645
Definition: ci.h:172
#define ST_OPEN_SESSION_REQUEST
Definition: ci.c:620
uint8_t Slot(void)
Definition: ci.c:479
cDynamicBuffer caDescriptors
Definition: ci.c:905
void MtdMapPids(cMtdMapper *MtdMapper)
Definition: ci.c:1038
virtual ~cCiTransportConnection()
Definition: ci.c:1788
#define CA_ENABLE(x)
Definition: ci.c:1069
cCiEnquiry * Enquiry(bool Clear=false)
Definition: ci.c:1561
int Matches(int CamNumber, const char *Text) const
Definition: ci.c:417
#define AOT_LIST_LAST
Definition: ci.c:672
bool WantsTsData(void) const
Returns true if this CAM slot wants to receive the TS data through its Decrypt() function.
Definition: ci.h:337
Definition: skins.h:37
cMtdCamSlot * GetMtdCamSlot(cCamSlot *MasterSlot)
Creates a new MTD CAM slot, or reuses an existing one that is currently unused.
Definition: mtd.c:46
#define AOT_DISPLAY_REPLY
Definition: ci.c:662
void ClrChecked(int CamSlotNumber)
Definition: ci.c:2849
cVector< uint32_t > resourceIds
Definition: ci.h:101
int Size(void)
Definition: ci.c:485
bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2922
virtual int Read(uint8_t *Buffer, int MaxLength)
Reads one chunk of data into the given Buffer, up to MaxLength bytes.
Definition: ci.h:187
bool Active(void)
Definition: ci.c:2064
void Load(const char *FileName)
Definition: ci.c:2961
uint16_t manufacturerCode
Definition: ci.h:73
#define MAX_SESSIONS_PER_TC
Definition: ci.c:575
eModuleStatus lastModuleStatus
Definition: ci.h:248
#define STREAM_TYPE_PRIVATE
Definition: ci.c:2640
Definition: ci.h:232
#define CPLM_ONLY
Definition: ci.c:889
uint32_t camSlotsDecrypt
Definition: ci.c:2795
void AddCamSlot(cCamSlot *CamSlot)
Adds the given CamSlot to this CI adapter.
Definition: ci.c:2090
cVector< int > emmPids
Definition: ci.c:120
void BuildCaPmts(uint8_t CmdId, cCiCaPmtList &CaPmtList, cMtdMapper *MtdMapper=NULL)
Generates all CA_PMTs with the given CmdId and stores them in the given CaPmtList.
Definition: ci.c:2488
bool Running(void)
Returns false if a derived cThread object shall leave its Action() function.
Definition: thread.h:101
cCiAdapter * ciAdapter
Definition: ci.h:240
const cCiResourceHandler * Last(void) const
Returns the last element in this list, or NULL if the list is empty.
Definition: tools.h:608
cCiTransportConnection * Tc(void)
Definition: ci.h:48
bool active
Definition: ci.c:2041
uint8_t CmdId(void)
Definition: ci.c:914
Definition: thread.h:67
bool HandlingPid(void)
The cCaPidReceiver adds/deletes PIDs to/from the base class cReceiver, which in turn does the same on...
Definition: ci.c:263
#define AOT_ENQ
Definition: ci.c:667
bool TimedWait(cMutex &Mutex, int TimeoutMs)
Definition: thread.c:132
Definition: ci.c:471
cCiSession * tsPostProcessor
Definition: ci.c:589
void OpenSession(int Length, const uint8_t *Data)
Definition: ci.c:1884
#define AOT_CLEAR_REPLACE
Definition: ci.c:656
#define DATA_INDICATOR
Definition: ci.c:457
virtual const int * GetCaSystemIds(void)
Definition: ci.c:2571
uint8_t Status(void)
Definition: ci.c:566
void SetChecked(int CamSlotNumber)
Definition: ci.c:2836
#define CPCI_OK_DESCRAMBLING
Definition: ci.c:895
void Dump(int SlotNumber, bool Outgoing)
Definition: ci.c:537
#define T_TC_ERROR
Definition: ci.c:467
int CardIndex(void) const
Returns the card index of this device (0 ... MAXDEVICES - 1).
Definition: device.h:214
cCiResourceHandlers(void)
Creates the default list of resourceIds.
Definition: ci.c:1741
bool AddPid(int Pid)
Adds the given Pid to the list of PIDs of this receiver.
Definition: receiver.c:42
#define AOT_MENU_ANSW
Definition: ci.c:671
const cCiResourceHandler * Prev(const cCiResourceHandler *Object) const
Definition: tools.h:610
cCamSlot * MasterSlot(void)
Returns this CAM slot's master slot, or a pointer to itself if it is a master slot.
Definition: ci.h:308
int PutCat(const uchar *Data, int Count)
Definition: mtd.c:353
const cCamResponse * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition: tools.h:606
#define RI_DATE_TIME
Definition: ci.c:638
static uint8_t * SetLength(uint8_t *Data, int Length)
Definition: ci.c:57
virtual bool Reset(void)
Resets the CAM in this slot.
Definition: ci.c:2336
time_t lastTime
Definition: ci.c:1269
void SendCaPmts(cCiCaPmtList &CaPmtList)
Sends the given list of CA_PMTs to the CAM.
Definition: ci.c:2525
bool CamResponsesLoad(const char *FileName, bool AllowComments, bool MustExist)
Definition: ci.c:447
virtual bool IsDecrypting(void)
Returns true if the CAM in this slot is currently used for decrypting.
Definition: ci.c:2713
bool createConnectionRequested
Definition: ci.c:583
#define SS_OK
Definition: ci.c:629
int transponder
Definition: ci.h:253
cCiMMI(uint16_t SessionId, cCiTransportConnection *Tc)
Definition: ci.c:1387
void SendMenuAnswer(uint8_t Selection)
Definition: ci.c:1572
void SendData(int Length, const uint8_t *Data)
Definition: ci.c:1825
const char * GetCamName(void)
Definition: ci.c:1812
int Vpid(void) const
Definition: channels.h:152
#define T_RCV
Definition: ci.c:460
void DelPid(int Pid)
Deletes the given Pid from the list of PIDs of this receiver.
Definition: receiver.c:90
void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2953
void Del(cCiCaPmt *CaPmt)
Definition: ci.c:2475
virtual void SetPid(int Pid, bool Active)
Sets the given Pid (which has previously been added through a call to AddPid()) to Active.
Definition: ci.c:2619
bool HasCaPids(void) const
Definition: ci.c:133
cCamSlot * camSlots[MAX_CAM_SLOTS_PER_ADAPTER]
Definition: ci.h:175
virtual cCiEnquiry * GetEnquiry(void)
Gets a pending enquiry, or NULL if there is no enquiry.
Definition: ci.c:2449
cChannelCamRelation * AddEntry(tChannelID ChannelID)
Definition: ci.c:2897
cString fileName
Definition: ci.h:512
cCiDateTime(uint16_t SessionId, cCiTransportConnection *Tc)
Definition: ci.c:1276
void SetTsPostProcessor(cCiSession *CiSession)
Definition: ci.c:1794
cMutex mutex
Definition: ci.h:511
#define AOT_DATE_TIME_ENQ
Definition: ci.c:658
uchar Get(int Index)
Definition: tools.h:840
#define TC_ALIVE_TIMEOUT
Definition: ci.c:1771
uint8_t * Buffer(void)
Definition: ci.c:484
#define T_NEW_TC
Definition: ci.c:466
time_t lastChecked
Definition: ci.c:2796
bool WaitForAllCamSlotsReady(int Timeout=0)
Waits until all CAM slots have become ready, or the given Timeout (seconds) has expired.
Definition: ci.c:2768
cCiMenu * fetchedMenu
Definition: ci.c:1373
#define CAM_CHECKED_TIMEOUT
Definition: ci.c:2789
bool modified
Definition: ci.c:2057
virtual ~cCiMMI()
Definition: ci.c:1395
void Del(cListObject *Object, bool DeleteObject=true)
Definition: tools.c:2184
cMtdHandler * mtdHandler
Definition: ci.h:256
~cCiEnquiry()
Definition: ci.c:1665
bool TsPostProcess(uint8_t *TsPacket)
Definition: ci.c:1799
#define RI_RESOURCE_MANAGER
Definition: ci.c:634
int DeviceNumber(void) const
Returns the number of this device (0 ... numDevices - 1).
Definition: device.c:160
bool IsDecrypting(void)
Returns true if any of the active MTD CAM slots is currently decrypting.
Definition: mtd.c:96
virtual void Process(int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:763
bool Valid(void) const
Definition: channels.h:58
#define DRI_MMI_MODE_ACK
Definition: ci.c:1352
int Put(const uchar *Data, int Count)
Puts at most Count bytes of Data into the CAM slot which's index is derived from the PID of the TS pa...
Definition: mtd.c:60
void SendPMT(cCiCaPmt *CaPmt)
Definition: ci.c:1222
void Reply(const char *s)
Definition: ci.c:1673
void MtdMapSid(uchar *p, cMtdMapper *MtdMapper)
Definition: mtd.c:225
#define T_DTC_REPLY
Definition: ci.c:464
cCiMenu * Menu(bool Clear=false)
Definition: ci.c:1550
int NumIds(void)
Definition: ci.h:111
~cCamResponse()
Definition: ci.c:349
Definition: ci.h:119
uchar * bufp
Definition: ci.c:122
#define SS_NOT_ALLOCATED
Definition: ci.c:630
virtual eModuleStatus ModuleStatus(int Slot)
Returns the status of the CAM in the given Slot.
Definition: ci.h:197
virtual bool HasMMI(void)
Returns 'true' if the CAM in this slot has an active MMI.
Definition: ci.c:2418
cDevice * assignedDevice
Definition: ci.h:242
virtual ~cCaActivationReceiver()
Definition: ci.c:297
cCaActivationReceiver(const cChannel *Channel, cCamSlot *CamSlot)
Definition: ci.c:289
#define MODULE_CHECK_INTERVAL
Definition: ci.c:2136
void Cancel(void)
Definition: ci.c:1680
tChannelID ChannelID(void)
Definition: ci.c:2800
int Length(void)
Definition: remux.h:443
void SetChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2929
#define T_DATA_LAST
Definition: ci.c:468
uint8_t cmdId
Definition: ci.c:903
virtual const char * GetCamName(void)
Returns the name of the CAM in this slot, or NULL if there is no ready CAM in this slot.
Definition: ci.c:2406
#define tr(s)
Definition: i18n.h:85
char * entries[MAX_CIMENU_ENTRIES]
Definition: ci.h:130
bool TimedOut(void)
Definition: ci.c:2817
cCiEnquiry * fetchedEnquiry
Definition: ci.c:1374
void ClrDecrypt(int CamSlotNumber)
Definition: ci.c:2855
cCiResourceHandler(void)
Creates a new resource handler, through which the available resources can be provides.
Definition: ci.c:1694
bool TsIsScrambled(const uchar *p)
Definition: remux.h:93
cChannelCamRelations ChannelCamRelations
Definition: ci.c:2865
cListObject * Next(void) const
Definition: tools.h:510
virtual bool Ready(void)
Returns 'true' if the CAM in this slot is ready to decrypt.
Definition: ci.c:2412
cCamResponse(void)
Definition: ci.c:342
void DeleteConnection(void)
Definition: ci.c:606
char * skipspace(const char *s)
Definition: tools.h:209
cTimeMs moduleCheckTimer
Definition: ci.h:250
cCaPidReceiver * caPidReceiver
Definition: ci.h:243
cCamSlot * camSlot
Definition: ci.c:279
#define T_DELETE_TC
Definition: ci.c:463
time_t lastCleanup
Definition: ci.h:515
cMutex * mutex
Definition: ci.h:125
virtual void CancelActivation(void)
Cancels a previously started activation (if any).
Definition: ci.c:2374
#define isyslog(a...)
Definition: tools.h:36
virtual uchar * Decrypt(uchar *Data, int &Count)
If this is a CAM slot that can be freely assigned to any device, but will not be directly inserted in...
Definition: ci.c:2731
virtual bool CanDecrypt(const cChannel *Channel, cMtdMapper *MtdMapper=NULL)
Returns true if there is a CAM in this slot that is able to decrypt the given Channel (or at least cl...
Definition: ci.c:2662
Definition: thread.h:79
Definition: ci.c:900
bool mtdAvailable
Definition: ci.h:255
int Priority(void)
Returns the priority of the device this slot is currently assigned to, or IDLEPRIORITY if it is not a...
Definition: ci.c:2578
bool CamChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2915
virtual void StopDecrypting(void)
Clears the list of CA_PMT entries and tells the CAM to stop decrypting.
Definition: ci.c:2703
void Append(const uchar *Data, int Length)
Definition: tools.c:2328
virtual bool TsPostProcess(uint8_t *TsPacket)
If this cCiSession needs to do additional processing on TS packets (after the CAM has done the decryp...
Definition: ci.h:57
virtual ~cCiSession()
Definition: ci.c:701
void ClrChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2945
#define TS_PACKET_FACTOR
Definition: ci.c:275
void AddCaDescriptors(int Length, const uint8_t *Data)
Definition: ci.c:963
const uint8_t * GetData(const uint8_t *Data, int &Length)
Definition: ci.c:730
void put_unaligned(unsigned int v, T *p)
Definition: tools.h:86
Definition: tools.h:369
void Abort(void)
Definition: ci.c:1685
#define TS_SIZE
Definition: remux.h:34
void Reset(int CamSlotNumber)
Definition: ci.c:2906
#define T_DATA_MORE
Definition: ci.c:469
cCiTransportConnection(cCamSlot *CamSlot, uint8_t Tcid)
Definition: ci.c:1773
virtual bool EnterMenu(void)
Requests the CAM in this slot to start its menu.
Definition: ci.c:2429
eModuleStatus
Definition: ci.h:170
int GetCaPids(int Source, int Transponder, int ServiceId, const int *CaSystemIds, int BufSize, int *Pids)
Gets all CA pids for a given channel.
Definition: pat.c:273
void Save(void)
Definition: ci.c:2995
cCiMenu(cCiMMI *MMI, bool Selectable)
Definition: ci.c:1599
void Register(cCiResourceHandler *ResourceHandler)
Adds the given ResourceHandler to the list of resource handlers and appends its ResourceIds to the gl...
Definition: ci.c:1746
tChannelID channelID
Definition: ci.c:2793
#define TC_POLL_TIMEOUT
Definition: ci.c:1770
#define ST_CREATE_SESSION_RESPONSE
Definition: ci.c:623
#define QUERY_REPLY_TIMEOUT
Definition: ci.c:1072
cCamSlot(cCiAdapter *CiAdapter, bool WantsTsData=false, cCamSlot *MasterSlot=NULL)
Creates a new CAM slot for the given CiAdapter.
Definition: ci.c:2139
static const uint8_t * GetLength(const uint8_t *Data, int &Length)
Definition: ci.c:42
void UnAssignAll(void)
Unassigns all MTD CAM slots from their devices.
Definition: mtd.c:137
cCiMMI * mmi
Definition: ci.h:124
uchar * Data(void)
Definition: tools.h:842
char * text
Definition: ci.c:333
#define DEC2BCD(d)
#define AOT_DATE_TIME
Definition: ci.c:659
bool deleteConnectionRequested
Definition: ci.c:584
void CloseSession(uint16_t SessionId)
Definition: ci.c:1907
virtual bool Assign(cDevice *Device, bool Query=false)
Assigns this adapter to the given Device, if this is possible.
Definition: ci.h:199
uint8_t buffer[MAX_TPDU_SIZE]
Definition: ci.c:474
void Abort(void)
Definition: ci.c:1647
cChannelCamRelation * GetEntry(tChannelID ChannelID)
Definition: ci.c:2886
#define RI_APPLICATION_INFORMATION
Definition: ci.c:635
virtual void Clear(void)
Definition: tools.h:768
virtual bool Assign(cDevice *Device, bool Query=false)
Assigns this CAM slot to the given Device, if this is possible.
Definition: ci.c:2182
virtual const uint32_t * ResourceIds(void) const
Returns a pointer to an array of resource identifiers, where the last value is zero.
Definition: ci.c:1710
#define AOT_CA_PMT
Definition: ci.c:652
bool IsActivating(void)
Returns true if any of the active MTD CAM slots is currently activating.
Definition: mtd.c:121
uchar buffer[2048]
Definition: ci.c:121
Definition: ci.h:170
virtual bool IsActivating(void)
Returns true if this CAM slot is currently activating a smart card.
Definition: ci.c:2385
void SendTPDU(uint8_t Tag, int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:1818
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
Definition: thread.c:354
cMtdMapper * MtdMapper(void)
Definition: mtd.h:168
int NumPids(void) const
Definition: receiver.h:81
void Poll(void)
Definition: ci.c:1850
char * text
Definition: ci.h:154
~cCiCaPmtList()
Definition: ci.c:2462
cCamSlot * CamSlot(void)
Definition: ci.c:603
int Count(void) const
Definition: tools.h:590
cCiCaPmt * Add(uint8_t CmdId, int Source, int Transponder, int ProgramNumber, const int *CaSystemIds)
Definition: ci.c:2468
#define QUERY_RETRIES
Definition: ci.c:1073
#define UNSCRAMBLE_TIME
Definition: ci.c:274
bool ReceivedReply(void)
Definition: ci.c:1090
cMutex * mutex
Definition: ci.h:153
cChannelCamRelations(void)
Definition: ci.c:2867
void DeleteAllConnections(void)
Definition: ci.c:2246
void Detach(void)
Definition: receiver.c:125
void SetResourceId(uint32_t Id)
If this is a class that has been derived from an existing cCiSession class, but implements a differen...
Definition: ci.c:705
bool RepliesToQuery(void)
Definition: ci.c:1088
virtual void Process(int Length=0, const uint8_t *Data=NULL)
Definition: ci.c:837
int transponder
Definition: ci.c:908
const uint8_t * Data(int &Length)
Definition: ci.c:482
int Priority(void)
Returns the maximum priority of any of the active MTD CAM slots.
Definition: mtd.c:88
static int MtdMapStreams(uchar *p, cMtdMapper *MtdMapper, int Length)
Definition: ci.c:1023
int MaxSize(void)
Definition: ci.c:487
#define AOT_CA_PMT_REPLY
Definition: ci.c:653
cCamSlots CamSlots
Definition: ci.c:2756
int Priority(void) const
Returns the priority of the current receiving session (-MAXPRIORITY..MAXPRIORITY),...
Definition: device.c:1632
int SlotNumber(void)
Returns the number of this CAM slot within the whole system.
Definition: ci.h:343
#define CAEI_POSSIBLE
Definition: ci.c:1061
int interval
Definition: ci.c:1268
uchar mtdCatBuffer[TS_SIZE]
Definition: ci.c:123
Definition: tools.h:176
virtual ~cCiApplicationInformation()
Definition: ci.c:832
static bool DumpPolls
Definition: ci.c:33
static bool DebugProtocol
Definition: ci.c:32
bool selectable
Definition: ci.h:126
cCiResourceManager(uint16_t SessionId, cCiTransportConnection *Tc)
Definition: ci.c:777
bool AddEntry(char *s)
Definition: ci.c:1620
virtual const uint32_t * ResourceIds(void) const =0
Returns a pointer to an array of resource identifiers, where the last value is zero.
int catVersion
Definition: ci.c:119
Definition: ci.h:170
cSkins Skins
Definition: skins.c:219
cDevice * Device(void)
Returns the device this CAM slot is currently assigned to.
Definition: ci.h:331
bool TimedOut(void) const
Definition: tools.c:779
virtual bool RepliesToQuery(void)
Returns true if the CAM in this slot replies to queries and thus supports MCD ("Multi Channel Decrypt...
Definition: ci.c:2481
#define CPCI_QUERY
Definition: ci.c:897
void SetSize(int Size)
Definition: ci.c:486
const cCamResponse * Next(const cCamResponse *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
Definition: tools.h:613
void SetDecrypt(int CamSlotNumber)
Definition: ci.c:2843