new Nagra build system
authorleslie <unknown>
Thu, 27 Dec 2007 21:13:55 +0000 (22:13 +0100)
committerleslie <unknown>
Thu, 27 Dec 2007 21:13:55 +0000 (22:13 +0100)
12 files changed:
misc.h
system-common.h
systems/nagra/nagra-def.h [new file with mode: 0644]
systems/nagra/nagra.c
systems/nagra/nagra.h
systems/nagra/nagra.mk
systems/nagra/nagra1.c
systems/nagra/nagra2-0101.c
systems/nagra/nagra2-0501.c
systems/nagra/nagra2-4101.c
systems/nagra/nagra2.c
systems/nagra/nagra2.h [new file with mode: 0644]

diff --git a/misc.h b/misc.h
index f24f1ff346b5ff36b8924373148d9a2afd7f87d0..b02fd3992fce43d6b8867502ab9b68c0a2d04c1b 100644 (file)
--- a/misc.h
+++ b/misc.h
 #define WORD(buffer,index,mask) (((buffer[(index)]<<8) + buffer[(index)+1]) & mask)
 #define SCT_LEN(sct) (3+(((sct)[1]&0x0f)<<8)+(sct)[2])
 
+#define MBC(a,b)    (((a)<<8)+(b))
+#define ADDC3(ab,c) ((ab)+((c)<<16))
+#define MBC3(a,b,c) ADDC3(MBC((a),(b)),(c))
+#define C2(x)       (((x)>>8)&0xFF)
+#define C3(x)       (((x)>>16)&0xFF)
+#define C2MASK      0xFFFF
+
 // replacement for variable-sized arrays
 #define AUTOARRAY(type,size) (type *)alloca(sizeof(type)*(size))
 #define AUTOMEM(size)        (unsigned char *)alloca(size)
index 6728b49032883353fb6e9faf170e9feda53d9734..396a0b779db5bb952ed312a259c24e7ac449165a 100644 (file)
 #include "data.h"
 #include "system.h"
 
-#define MBC(a,b)    (((a)<<8)+(b))
-#define ADDC3(ab,c) ((ab)+((c)<<16))
-#define MBC3(a,b,c) ADDC3(MBC((a),(b)),(c))
-#define C2(x)       (((x)>>8)&0xFF)
-#define C3(x)       (((x)>>16)&0xFF)
-#define C2MASK      0xFFFF
-
 // ----------------------------------------------------------------
 
 class cHexKey : public cPlainKey {
diff --git a/systems/nagra/nagra-def.h b/systems/nagra/nagra-def.h
new file mode 100644 (file)
index 0000000..71b43bd
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Softcam plugin to VDR (C++)
+ *
+ * This code is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This code is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
+ */
+
+#ifndef __NAGRA_NAGRA_DEF_H
+#define __NAGRA_NAGRA_DEF_H
+
+// ----------------------------------------------------------------
+
+#define SYSTEM_NAGRA         0x1800
+#define SYSTEM_NAGRA2        0x1801
+#define SYSTEM_NAGRA_BEV     0x1234
+
+// ----------------------------------------------------------------
+
+// Nagra1 defines
+#define DEF_TYPE 0
+#define DEF_PK   2
+#define DEF_ROM  0
+
+#define TYPE(keynr)         (((keynr)>>16)&1)
+#define PK(keynr)           (((keynr)>>17)&3)
+#define ROM(keynr)          (((keynr)>>19)&15)
+#define KEYSET(rom,pk,type) ((((rom)&15)<<3)|(((pk)&3)<<1)|((type)&1))
+
+// Nagra2 defines
+#define N2_MAGIC   0x80
+#define N2_EMM_G_I 0x02
+#define N2_EMM_G_R 0x12
+#define N2_EMM_S_I 0x01
+#define N2_EMM_S_R 0x11
+#define N2_EMM_SEL 0x40
+#define N2_EMM_V   0x03
+
+#endif
index 392a837ca3176ad509ed6c73a5a848c24bc23016..37e4f101fb2e38549db0c24551a0bf4c3c9de830 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 
 #include "nagra.h"
+#include "nagra-def.h"
 #include "log-nagra.h"
 #include "log-core.h"
 
index 2b2874e8e03f8bd3ee63e6d01c4d2320f93c8958..aedad545a09da95e0c0a895e3a76f3bc98d65d29 100644 (file)
 
 // ----------------------------------------------------------------
 
-#define SYSTEM_NAGRA         0x1800
-#define SYSTEM_NAGRA2        0x1801
-#define SYSTEM_NAGRA_BEV     0x1234
-
 extern int minEcmTime;
 
 // ----------------------------------------------------------------
 
-// Nagra1 defines
-#define DEF_TYPE 0
-#define DEF_PK   2
-#define DEF_ROM  0
-
-#define TYPE(keynr)         (((keynr)>>16)&1)
-#define PK(keynr)           (((keynr)>>17)&3)
-#define ROM(keynr)          (((keynr)>>19)&15)
-#define KEYSET(rom,pk,type) ((((rom)&15)<<3)|(((pk)&3)<<1)|((type)&1))
-
-// Nagra2 defines
-#define N2_MAGIC   0x80
-#define N2_EMM_G_I 0x02
-#define N2_EMM_G_R 0x12
-#define N2_EMM_S_I 0x01
-#define N2_EMM_S_R 0x11
-#define N2_EMM_SEL 0x40
-#define N2_EMM_V   0x03
-
-#define MATCH_ID(x,y) ((((x)^(y))&~0x107)==0)
-
 class cPlainKeyNagra : public cDualKey {
 private:
   int ParseTag(const char *tag, const char * &line);
index a8e843097a168697df1ab35b872234f8a6b5c755..d511b1375431b72c40f25da5d8dce32015340ff1 100644 (file)
@@ -2,11 +2,6 @@
 # Nagra
 #
 TARGET = nagra
-OBJS   = nagra.o nagra1.o nagra2.o cpu.o
+OBJS   = nagra.o nagra1.o nagra2.o cpu.o \
+         $(patsubst %.c,%.o,$(wildcard nagra2-[0-9][0-9][0-9][0-9].c))
 LIBS   = -lcrypto
-CLEAN_RM = nagra2-prov.c
-
-nagra2-prov.c:
-       echo >$@ "/* generated file, do not edit */"
-       find -name "nagra2-[0-9][0-9][0-9][0-9].c" -printf '#include "%f"\n' >>$@
-       @rm .dependencies
index a2c4e0a77489db68058ce33c2c0fec38e7704fe3..d65cae48ec4ab46fbe389b1bb298d3f7bd61e009 100644 (file)
@@ -27,6 +27,7 @@
 #include "helper.h"
 
 #include "nagra.h"
+#include "nagra-def.h"
 #include "cpu.h"
 #include "log-nagra.h"
 
index 2e5f2c31a6b7923ca73ae4163c51965fcab06b9d..e061d1a177951352e55742c650f52132210453df 100644 (file)
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nagra2.h"
+
 // -- cAuxSrv ------------------------------------------------------------------
 
 //#define HAS_AUXSRV
 
 #ifdef HAS_AUXSRV
+#include "network.h"
 #define AUX_PROTOCOL_VERSION 2
 static int auxEnabled=0;
 static int auxPort=7777;
index 6821da14b2a11795ca9e169b12cf3d2843657330..03dfce8b3aeb3b909c5ed14dd0dc65470b07708f 100644 (file)
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nagra2.h"
+
 // -- cMap0501 -----------------------------------------------------------------
 
 class cMap0501 : public cMapCore {
index 7366ccba16c76736ae4ec9bd86a092bb41850b88..9e5af258a26ebf03512aaa17c5003962b871dfd5 100644 (file)
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nagra2.h"
+
 // -- cMap4101 -----------------------------------------------------------------
 
 class cMap4101 : public cMapCore {
index d2bda22e4a5d3f904eb4928addb21f47b02f101b..b4700cd36f8370aac4223e014fdec03009c318b7 100644 (file)
 #include <string.h>
 
 #include "system.h"
-#include "misc.h"
 #include "opts.h"
-#include "network.h"
-#include "crypto.h"
-#include "helper.h"
-
-#include <openssl/des.h>
-#include <openssl/sha.h>
-#include "openssl-compat.h"
 
 #include "nagra.h"
-#include "cpu.h"
-#include "log-nagra.h"
+#include "nagra2.h"
 
 #define SYSTEM_NAME          "Nagra2"
 #define SYSTEM_PRI           -10
 
 // -- cN2Emu -------------------------------------------------------------------
 
-class cN2Emu : protected c6805 {
-private:
-  bool initDone;
-protected:
-  bool Init(int id, int romv);
-  virtual bool RomInit(void) { return true; }
-  virtual void Stepper(void) {}
-public:
-  cN2Emu(void);
-  virtual ~cN2Emu() {}
-  };
-
 cN2Emu::cN2Emu(void)
 {
   initDone=false;
@@ -87,67 +66,6 @@ bool cN2Emu::Init(int id, int romv)
 
 // -- cMapCore -----------------------------------------------------------------
 
-#define SETSIZE     0x02
-#define IMPORT_J    0x03
-#define IMPORT_A    0x04
-#define IMPORT_B    0x05
-#define IMPORT_C    0x06
-#define IMPORT_D    0x07
-#define IMPORT_LAST 0x08
-#define EXPORT_J    0x09
-#define EXPORT_A    0x0A
-#define EXPORT_B    0x0B
-#define EXPORT_C    0x0C
-#define EXPORT_D    0x0D
-#define EXPORT_LAST 0x0E
-#define SWAP_A      0x0F
-#define SWAP_B      0x10
-#define SWAP_C      0x11
-#define SWAP_D      0x12
-#define CLEAR_A     0x13
-#define CLEAR_B     0x14
-#define CLEAR_C     0x15
-#define CLEAR_D     0x16
-#define COPY_A_B    0x17
-#define COPY_B_A    0x18
-#define COPY_A_C    0x19
-#define COPY_C_A    0x1A
-#define COPY_C_D    0x1B
-#define COPY_D_C    0x1C
-
-class cMapCore {
-private:
-  int last;
-  cBN *regs[5];
-  cBN x, y, s;
-protected:
-  int wordsize;
-  cBN A, B, C, D, J, I;
-  cBN Px, Py, Pz,Qx, Qy, Qz; // 0x00,0x20,0x40,0x60,0x80,0x180
-  cBN sA0, sC0, sE0, s100, s120, s140, s160;
-  cBNctx ctx;
-  SHA_CTX sctx;
-  // stateless
-  void MakeJ0(BIGNUM *j, BIGNUM *d);
-  void ModAdd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *d);
-  void ModSub(BIGNUM *r, BIGNUM *d, BIGNUM *b);
-  void MonMul(BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j);
-  // statefull
-  void MonInit(int bits=0);
-  void MonMul(BIGNUM *o, BIGNUM *a, BIGNUM *b) { MonMul(o,a,b,C,D,J); }
-  void MonExpNeg(void);
-  // ECC
-  void DoubleP(int temp);
-  void AddP(int temp);
-  void ToProjective(int set, BIGNUM *x, BIGNUM *y);
-  void ToAffine(void);
-  void CurveInit(BIGNUM *a);
-  //
-  bool DoMap(int f, unsigned char *data=0, int l=0);
-public:
-  cMapCore(void);
-  };
-
 cMapCore::cMapCore(void)
 {
   wordsize=4; last=1;
@@ -450,37 +368,6 @@ bool cMapCore::DoMap(int f, unsigned char *data, int l)
 
 // -- cN2Prov ------------------------------------------------------------------
 
-#define N2FLAG_NONE     0
-#define N2FLAG_MECM     1
-#define N2FLAG_Bx       2
-#define N2FLAG_POSTAU   4
-#define N2FLAG_Ex       8
-#define N2FLAG_INV      128
-
-class cN2Prov {
-private:
-  unsigned char seed[32], cwkey[8];
-  bool keyValid;
-protected:
-  int id, flags, seedSize;
-  cIDEA idea;
-  //
-  virtual bool Algo(int algo, unsigned char *hd, const unsigned char *ed, unsigned char *hw) { return false; }
-  virtual bool NeedsCwSwap(void) { return false; }
-  void ExpandInput(unsigned char *hw);
-public:
-  cN2Prov(int Id, int Flags);
-  virtual ~cN2Prov() {}
-  bool MECM(unsigned char in15, int algo, const unsigned char *ed, unsigned char *cw);
-  void SwapCW(unsigned char *cw);
-  virtual int ProcessBx(unsigned char *data, int len, int pos) { return -1; }
-  virtual int ProcessEx(unsigned char *data, int len, int pos) { return -1; }
-  virtual bool PostProcAU(int id, unsigned char *data) { return true; }
-  bool CanHandle(int Id) { return MATCH_ID(Id,id); }
-  bool HasFlags(int Flags) { return (flags&Flags)==Flags; }
-  void PrintCaps(int c);
-  };
-
 cN2Prov::cN2Prov(int Id, int Flags)
 {
   keyValid=false; id=Id|0x100; flags=Flags; seedSize=5;
@@ -564,40 +451,7 @@ void cN2Prov::SwapCW(unsigned char *cw)
     }
 }
 
-// -- cN2ProvLink & cN2Providers -----------------------------------------------
-
-class cN2Providers;
-
-class cN2ProvLink {
-friend class cN2Providers;
-private:
-  cN2ProvLink *next;
-protected:
-  int id, flags;
-  //
-  virtual cN2Prov *Create(void)=0;
-  bool CanHandle(int Id) { return MATCH_ID(Id,id); }
-  bool HasFlags(int Flags) { return (flags&Flags)==Flags; }
-public:
-  cN2ProvLink(int Id, int Flags);
-  virtual ~cN2ProvLink() {}
-  };
-
-class cN2Providers {
-friend class cN2ProvLink;
-private:
-  static cN2ProvLink *first;
-  //
-  static void Register(cN2ProvLink *plink);
-public:
-  static cN2Prov *GetProv(int Id, int Flags);
-  };
-
-template<class PROV, int ID, int FLAGS> class cN2ProvLinkReg : public cN2ProvLink {
-public:
-  cN2ProvLinkReg(void):cN2ProvLink(ID,FLAGS) {}
-  virtual cN2Prov *Create(void) { return new PROV(id,flags); }
-  };
+// -- cN2Providers -------------------------------------------------------------
 
 cN2ProvLink *cN2Providers::first=0;
 
@@ -618,16 +472,14 @@ cN2Prov *cN2Providers::GetProv(int Id, int Flags)
   return 0;
 }
 
+// -- cN2ProvLink --------------------------------------------------------------
+
 cN2ProvLink::cN2ProvLink(int Id, int Flags)
 {
   id=Id; flags=Flags;
   cN2Providers::Register(this);
 }
 
-#include "nagra2-prov.c"
-
-#ifndef TESTER
-
 // -- cNagra2 ------------------------------------------------------------------
 
 class cNagra2 : public cNagra {
@@ -1093,5 +945,3 @@ bool cSystemLinkNagra2::CanHandle(unsigned short SysId)
   return ((SysId&SYSTEM_MASK)==SYSTEM_NAGRA && (SysId&0xFF)>0) ||
           SysId==SYSTEM_NAGRA_BEV;
 }
-
-#endif //TESTER
diff --git a/systems/nagra/nagra2.h b/systems/nagra/nagra2.h
new file mode 100644 (file)
index 0000000..96e00a1
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * Softcam plugin to VDR (C++)
+ *
+ * This code is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This code is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
+ */
+
+#ifndef __NAGRA_NAGRA2_H
+#define __NAGRA_NAGRA2_H
+
+#include "data.h"
+#include "crypto.h"
+#include "misc.h"
+#include "helper.h"
+
+#include <openssl/des.h>
+#include <openssl/sha.h>
+#include "openssl-compat.h"
+
+#include "nagra-def.h"
+#include "cpu.h"
+#include "log-nagra.h"
+
+// ----------------------------------------------------------------
+
+#define MATCH_ID(x,y) ((((x)^(y))&~0x107)==0)
+
+// ----------------------------------------------------------------
+
+class cN2Emu : protected c6805 {
+private:
+  bool initDone;
+protected:
+  bool Init(int id, int romv);
+  virtual bool RomInit(void) { return true; }
+  virtual void Stepper(void) {}
+public:
+  cN2Emu(void);
+  virtual ~cN2Emu() {}
+  };
+
+// ----------------------------------------------------------------
+
+#define SETSIZE     0x02
+#define IMPORT_J    0x03
+#define IMPORT_A    0x04
+#define IMPORT_B    0x05
+#define IMPORT_C    0x06
+#define IMPORT_D    0x07
+#define IMPORT_LAST 0x08
+#define EXPORT_J    0x09
+#define EXPORT_A    0x0A
+#define EXPORT_B    0x0B
+#define EXPORT_C    0x0C
+#define EXPORT_D    0x0D
+#define EXPORT_LAST 0x0E
+#define SWAP_A      0x0F
+#define SWAP_B      0x10
+#define SWAP_C      0x11
+#define SWAP_D      0x12
+#define CLEAR_A     0x13
+#define CLEAR_B     0x14
+#define CLEAR_C     0x15
+#define CLEAR_D     0x16
+#define COPY_A_B    0x17
+#define COPY_B_A    0x18
+#define COPY_A_C    0x19
+#define COPY_C_A    0x1A
+#define COPY_C_D    0x1B
+#define COPY_D_C    0x1C
+
+class cMapCore {
+private:
+  int last;
+  cBN *regs[5];
+  cBN x, y, s;
+protected:
+  int wordsize;
+  cBN A, B, C, D, J, I;
+  cBN Px, Py, Pz,Qx, Qy, Qz; // 0x00,0x20,0x40,0x60,0x80,0x180
+  cBN sA0, sC0, sE0, s100, s120, s140, s160;
+  cBNctx ctx;
+  SHA_CTX sctx;
+  // stateless
+  void MakeJ0(BIGNUM *j, BIGNUM *d);
+  void ModAdd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *d);
+  void ModSub(BIGNUM *r, BIGNUM *d, BIGNUM *b);
+  void MonMul(BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j);
+  // statefull
+  void MonInit(int bits=0);
+  void MonMul(BIGNUM *o, BIGNUM *a, BIGNUM *b) { MonMul(o,a,b,C,D,J); }
+  void MonExpNeg(void);
+  // ECC
+  void DoubleP(int temp);
+  void AddP(int temp);
+  void ToProjective(int set, BIGNUM *x, BIGNUM *y);
+  void ToAffine(void);
+  void CurveInit(BIGNUM *a);
+  //
+  bool DoMap(int f, unsigned char *data=0, int l=0);
+public:
+  cMapCore(void);
+  };
+
+// ----------------------------------------------------------------
+
+#define N2FLAG_NONE     0
+#define N2FLAG_MECM     1
+#define N2FLAG_Bx       2
+#define N2FLAG_POSTAU   4
+#define N2FLAG_Ex       8
+#define N2FLAG_INV      128
+
+class cN2Prov {
+private:
+  unsigned char seed[32], cwkey[8];
+  bool keyValid;
+protected:
+  int id, flags, seedSize;
+  cIDEA idea;
+  //
+  virtual bool Algo(int algo, unsigned char *hd, const unsigned char *ed, unsigned char *hw) { return false; }
+  virtual bool NeedsCwSwap(void) { return false; }
+  void ExpandInput(unsigned char *hw);
+public:
+  cN2Prov(int Id, int Flags);
+  virtual ~cN2Prov() {}
+  bool MECM(unsigned char in15, int algo, const unsigned char *ed, unsigned char *cw);
+  void SwapCW(unsigned char *cw);
+  virtual int ProcessBx(unsigned char *data, int len, int pos) { return -1; }
+  virtual int ProcessEx(unsigned char *data, int len, int pos) { return -1; }
+  virtual bool PostProcAU(int id, unsigned char *data) { return true; }
+  virtual int RunEmu(unsigned char *data, int len, unsigned short load, unsigned short run, unsigned short stop, unsigned short fetch, int fetch_len) { return -1; }
+  bool CanHandle(int Id) { return MATCH_ID(Id,id); }
+  bool HasFlags(int Flags) { return (flags&Flags)==Flags; }
+  void PrintCaps(int c);
+  };
+
+// ----------------------------------------------------------------
+
+class cN2Providers;
+
+class cN2ProvLink {
+friend class cN2Providers;
+private:
+  cN2ProvLink *next;
+protected:
+  int id, flags;
+  //
+  virtual cN2Prov *Create(void)=0;
+  bool CanHandle(int Id) { return MATCH_ID(Id,id); }
+  bool HasFlags(int Flags) { return (flags&Flags)==Flags; }
+public:
+  cN2ProvLink(int Id, int Flags);
+  virtual ~cN2ProvLink() {}
+  };
+
+template<class PROV, int ID, int FLAGS> class cN2ProvLinkReg : public cN2ProvLink {
+public:
+  cN2ProvLinkReg(void):cN2ProvLink(ID,FLAGS) {}
+  virtual cN2Prov *Create(void) { return new PROV(id,flags); }
+  };
+
+// ----------------------------------------------------------------
+
+class cN2Providers {
+friend class cN2ProvLink;
+private:
+  static cN2ProvLink *first;
+  //
+  static void Register(cN2ProvLink *plink);
+public:
+  static cN2Prov *GetProv(int Id, int Flags);
+  };
+
+#endif