/*
 * 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
 */

#include "common.h"
#include "system.h"

#define SYSTEM_SHL           0x4A60

#define SYSTEM_NAME          "@SHL"
#define SYSTEM_PRI           -10
#define SYSTEM_CAN_HANDLE(x) ((x)==SYSTEM_SHL)

#define DEBUG_SHL

#ifdef DEBUG_SHL
#define ds(x) { (x); }
#define dsf(x) { (x); fflush(stdout); }
#else
#define ds(x) ;
#define dsf(x) ;
#endif

// -- cPidHopper ---------------------------------------------------------------

class cPidHopper {
};

// -- cSystemShl ---------------------------------------------------------------

#define ENC_OFF 12 // encrypted bytes offset
#define ENC_LEN 24 // encrypted bytes length

class cSystemShl : public cSystem {
private:
	cPidHopper *ph;
	bool hasPrvId;
public:
	cSystemShl(void);
	virtual ~cSystemShl();
	virtual bool ProcessECM(const cEcmInfo *ecm, unsigned char *source);
};

cSystemShl::cSystemShl(void)
:cSystem(SYSTEM_NAME,SYSTEM_PRI)
{
	ph=0; hasPrvId=false;
	hasLogger=needsLogger=true; maxEcmTry=20;
}

cSystemShl::~cSystemShl()
{
	delete ph;
}

bool cSystemShl::ProcessECM(const cEcmInfo *ecm, unsigned char *source)
{
	if(SCT_LEN(source)<(ENC_OFF+ENC_LEN+3)) {
		ds(printf("system-shl: short ecm\n"))
		return false;
	}
	return false;
}

// -- cSystemLinkShl -----------------------------------------------------------

class cSystemLinkShl : public cSystemLink {
public:
	cSystemLinkShl(void);
	virtual bool CanHandle(unsigned short SysId);
	virtual cSystem *Create(void) { return new cSystemShl; }
};

static cSystemLinkShl staticInit;

cSystemLinkShl::cSystemLinkShl(void)
:cSystemLink(SYSTEM_NAME,SYSTEM_PRI)
{
	Feature.NeedsKeyFile();
}

bool cSystemLinkShl::CanHandle(unsigned short SysId)
{
	SysId&=0xFFF0;
	return SYSTEM_CAN_HANDLE(SysId);
}