Captain FTAFreeSatFIX.comBuckaneer Bob
Download FTA Satellite Receiver Software Free!
Go Back   FreeSatFix.com FTA Forums > FTA Receivers (Discussion) > NEUSAT
User Name
Password



Reply
 
Thread Tools Display Modes
  #1  
Old 02-09-2011, 11:11 PM
medamotcha's Avatar
medamotcha medamotcha is offline
thx team N3XT and RQ-sssp
 
Join Date: Dec 2007
Location: hanging out with the sharks
Posts: 2,207
medamotcha Gangwaymedamotcha Gangwaymedamotcha Gangway
Default cardsharing for neusat..enable on RQ client

check this out ...did you guys know thair was card sharing for nuesat
sp6000s...im working on how to config it...once i do that ill post..this is the file i think i have to config...im getting pritty good at this..finally figerd out how to open up the flash bins or the old doorstops......you know this really pisses me off when we could of had this info 2 years ago..assholes neosat.but we got a source code out of the deal...and this box has cs.thats y neosat wanted to unload all thair i-pro..instad of coding for this stb

HTML Code:
#include "dvb.h"
#include "cpu.h"
#if APP_NEC
#include "mmac/uart.h"
#include "mmac/support/dsi.h"
#endif
#include "itm.h"
#include "lgm.h"
#include "dbm.h"
#include "cam.h"
#if APP_CARD_SHARE
#include "sim.h"
#include "scm.h"
#include "csm.h"
#endif
#include "camsm.h"

#if APP_CARD_SHARE

#define CSM_UART_CHANNEL			MMAC_UART_1
#define CSM_UART_READ_TIMEOUT       50
#define CSM_UART_WRITE_TIMEOUT      50


static UINT8 camTxBuff[256];
static UINT8 camRxBuff[256];
static T_SIMSection    *shareEcm=NULL;
static UINT8    csmirActivated;

static UINT8 CSMServerProcess(UINT8 client, T_SCMConfig *scm);
static UINT8 CSMClientProcess(T_SCMConfig *clientScm, UINT8 *receiveEcm);
static UINT8 CSMUartInitial(UINT8 flag);
static UINT8 CSMPutData(UINT8 *ptr, UINT32 len);
static UINT8 CSMGetData(UINT8 *ptr, UINT32 *len, UINT32 timeout, UINT32 rLen);
static UINT8 CSMSendCardInfo(UINT8 client, T_SCMConfig *scmConfig);
static UINT8 CSMReceiveECM(UINT8 client, UINT8 *ptr, UINT32 len, T_SIMSection **dst);
static UINT8 CSMNotifyCardConfig(T_SCMConfig *scm);
static UINT8 CSMClientSendECM(UINT8 client, T_SIMSection *tbl, T_SCMConfig *scmConfig);
static UINT8 CSMNotifyCardShareStatus(UINT8 status);
static UINT8 CSMClientReceiveCardInfo(UINT8 *ptr, T_SCMConfig *scmConfig);
static UINT8 CSMAccessTable(UINT8 onOff);
static UINT8 CSMNotifyReportConfig(UINT8 reportType, T_SCMConfig *scm);

static UINT8 csCheckClient[2]    = { 0x11, 0x01};
//static UINT8 csResponseCheck[2]  = { 0x11, 0x02};
static UINT8 csRequestEcm[2]     = { 0x11, 0x03};
static UINT8 csSendCardInfo[2]   = { 0x11, 0x04};
static UINT8 csSendCW[2]         = { 0x11, 0x05};
//static UINT8 csSendECM[2]        = { 0x11, 0x06};

#define CS_CHECK_NO_INFO        0x20
#define CS_CHECK_CARD_INFO      0x21
#define CS_CHECK_NEW_ECM        0x22

//static UINT8   shareClientState=SHARE_CLIENT_READY;
//static UINT8 CAMConvertArrayToCardInfo(T_SCMConfig *scmConfig);
//static UINT8 CAMShareSendECM(UINT8 client, T_SIMSection *tbl, T_SCMConfig *scmConfig);
//static UINT8 CAMConvertArrayToECM(UINT8 client, UINT32 len, T_SIMSection **dst);

//UINT8 CAMInitialCardShare(void)
//{
//    return CSM_SUCCESS;
//}
static UINT8               uartInitial = 0;
UINT8 CSMInitilize(void)
{

    ITMCreateSemaphore(ITM_SEM_CSM_ACCESS, 0);

    if( DBMIsEnableCardShare() == DBM_SUCCESS )
    {
#if !APP_DEVELOP_MODE || APP_XCRYPT_DEBUG
        if( CSMUartInitial(DBM_ON)==CSM_SUCCESS )
            uartInitial = DBM_ON;
#endif
    }else
    {
#if !APP_DEVELOP_MODE || APP_XCRYPT_DEBUG
        if( CSMUartInitial(DBM_OFF)==CSM_SUCCESS )
            uartInitial = DBM_OFF;
#endif
    }

    if( ITMCreateMessage(ITM_CSM) != ITM_SUCCESS )
	{
		return CSM_FAILURE;
	}

	if( ITMCreateTask(ITM_CSM) != ITM_SUCCESS )
	{
		return CSM_FAILURE;
	}

    return CSM_SUCCESS;
}

#define CSM_MSG_TIMEOUT 10

UINT8 CSMManager(void)
{
    T_ITMMsg			msg;
    UINT8               rtn;
    UINT16				action, object;
	void				*param1, **param2;
    static T_SCMConfig	serverScm, clientScm;
    UINT8               startClient=0;
    UINT8               clientCount = 0;
    UINT8               receiveEcm = 0;
    UINT8               standby;
    UINT8               serverCardExist=0;

    memset( &serverScm, 0x00, sizeof(T_SCMConfig));

    while(1)
    {
        rtn = ITMReceiveMessage( ITM_CSM, &msg, CSM_MSG_TIMEOUT );
		if( rtn != ITM_SUCCESS )
		{
            if( uartInitial==DBM_OFF )
            {
                continue;
            }

            DBMGetStandby(&standby);
            if( standby == DBM_SYSTEM_STANDBY )
				continue;

#if APP_SMARTCARD
            if( DBMIsServerModeCardShare() == DBM_SUCCESS ) //server mode
            {
                if( serverScm.slot[0].status == SCM_READY || 
                    serverScm.slot[0].status == SCM_ACTIVE )
                {
                    CSMServerProcess(++clientCount, &serverScm);
                    if( clientCount == DBM_MAX_CLIENT_NUMBER )
                        clientCount = 0;
                }
            }
            else
#endif
            if( DBMIsClientModeCardShare() == DBM_SUCCESS &&
                startClient )
            {
                rtn = CSMClientProcess(&clientScm, &receiveEcm);
                if( rtn != CSM_CONTINUE)//cw setting
                {
                    CSMNotifyCardShareStatus(rtn);
                }
            }
            continue;
        }
        action = msg.body.csm.action;
		object = msg.body.csm.object;
		param1 = msg.body.csm.param1;
		param2 = msg.body.csm.param2;

        switch( action )
		{
            case ITM_CSM_UART_INITIAL:
                LGMPrint("debug: csm uart initial.");
                /*if( uartInitial == object )
                    break;*/
                    uartInitial = object;
                if( CSMUartInitial(object)==CSM_SUCCESS )
                {
                    LGMPrint("debug: csm uart initial success.");
                }
               
                break;

		    case ITM_CSM_SERVER_REPORT_CARD_INFO://server
                serverScm = *(T_SCMConfig *)param1;
#if APP_SMARTCARD
                if( serverScm.slot[0].status==SCM_EMPTY )
                {
                    if( serverCardExist == 0 )
                        break;
                    serverCardExist = 0;
                }
                else
                {
                    if( serverCardExist )
                        break;
                    serverCardExist = 1;
                }
                SCMPrintConfig( &serverScm );
#endif
                clientCount = 0;
                if( !uartInitial )
                    break;
                {
                    //UINT8 i;
                    //for( i=1; i<=DBM_MAX_CLIENT_NUMBER;i++)
                    {
                        CSMSendCardInfo(0, &serverScm);//broadcast command
                        ITMSleep(5);
                    }
                }
                break;

            case ITM_CSM_CLIENT_START:
                if( object == 1 )//start
                    startClient = 1;
                else
                    startClient = 0;
                csmirActivated = 0;
                //LGMPrint("debug: CLIENT startStop=%d.", startClient);
                break;

            case ITM_CSM_CLIENT_SEND_ECM://client to server
                SIMFreeSection( shareEcm );
                shareEcm = NULL;
            	SIMCopySection( (T_SIMSection*)param1, &shareEcm );
                //SIMPrintHex(shareEcm->ptr, shareEcm->len);
                receiveEcm = 1;
                CSMAccessTable(0);
                //LGMPrint("debug: CLIENT receive ecm.");
                break;
        };
    }
}

UINT8 CSMEncryptionCW(UINT8 *buf)
{
	int i, j;
	UINT8 temp[16], value[16];
	UINT8 p, p1, p2;
	int tot = 0;

	memcpy(value, buf, 16);

	for(i = 0; i < 16; i++)
		temp[i] = value[15-i]; 
    
	for(i = 0; i < 4; i++)
    {
		tot = 0;
		for(j = 0; j < 4; j++)
        { 
			temp[i*4 +j] = 0x11 ^ temp[i*4 +j];//sum
			temp[i*4 +j] = 0x44 ^ temp[i*4 +j];//sum
			temp[i*4 +j] = 0x33 ^ temp[i*4 +j];//sum

		}
		for(j = 0; j < 4; j++)
			temp[i*4 +j] = temp[i*4 +j] ^ 0x55;
	}
	for(i = 0; i < 16; i++){
		p1 = temp[i] & 0x0f; //00001111
		p2 = temp[i] & 0xf0; //11110000
		p  = (p1 << 4) + (p2 >> 4);
		temp[i] = p;
	}
	memcpy(buf, temp, 16);

    return CSM_SUCCESS;
}

UINT8 CSMDecryptionCW(UINT8 *buf)
{
	UINT8 temp[16], value[16];
	UINT8 p, p1, p2, i, j;

	for(i = 0; i < 16; i++)
	{
		p1 = buf[i] & 0x0f; //00001111
		p2 = buf[i] & 0xf0; //11110000
		p  = (p1 << 4) + (p2 >> 4);
		temp[i] = p;
	}
	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 4; j++)
			temp[i*4 +j] = 0x55 ^ temp[i*4 +j];//sum

		for(j = 0; j < 4; j++)
		{
			temp[i*4 +j] = temp[i*4 +j] ^ 0x33;
			temp[i*4 +j] = temp[i*4 +j] ^ 0x44;
			temp[i*4 +j] = temp[i*4 +j] ^ 0x11;
		}
	}
	for(i = 0; i < 16; i++)
		value[i] = temp[15-i]; 
	memcpy(buf, value, 16);

	return CSM_SUCCESS;
}

#if APP_SMARTCARD
static UINT8 csmRequestEcm=CSM_FAILURE;
UINT8 CSMShareNowReceiveEcm(void)
{
    return csmRequestEcm;
}

static UINT16 cardExistBit=0;
UINT8 CSMIsExistClient(void)
{
    if( cardExistBit != 0 )
        return TRUE;
    return FALSE;
}

static UINT8 CSMServerProcess(UINT8 client, T_SCMConfig *scmConfig)
{
    UINT8  rtn=CSM_SUCCESS;
    UINT32 len;
    static T_SIMSection *ecm=NULL;
    UINT8  cwData[16];
    UINT16 irChnId, timeOut;
    //static UINT16 cardExistBit=0;

    memset( camRxBuff, 0x00, sizeof(camRxBuff));
    //check client
    memcpy(camTxBuff, csCheckClient, 2);
    camTxBuff[2] = client;
    //LGMPrint("debug: check client %d.", client);
    CSMPutData(camTxBuff, 3);
    ITMSleep(20);
    if( (cardExistBit>>client) & 0x01 )
        timeOut = 200;
    else
        timeOut = 80;
    //if( CSMGetData(camRxBuff, &len, 100, 0 ) == CSM_SUCCESS )
    if( CSMGetData(camRxBuff, &len, timeOut, 0 ) == CSM_SUCCESS )
    {
        //if( client!=camRxBuff[2] )
          //  LGMPrint("debug: invalid server=%d, client=%d.", client, camRxBuff[2]);
        //LGMPrint("debug: len=%d, txBuff=0x%x,0x%x,0x%x, rxBuff=0x%x, 0x%x, 0x%x.", 
          //  len, camTxBuff[0], camTxBuff[1], camTxBuff[2], camRxBuff[0], camRxBuff[1], camRxBuff[2]);
        if( memcmp(camTxBuff, camRxBuff, 3 )== 0 && len > 3 )
        {
            cardExistBit |= (1 << client);
            if( camRxBuff[3] == CS_CHECK_NO_INFO )
            {
                //LGMPrint("debug: client is not ready.");
                ;//break;
            }
            else if( camRxBuff[3] == CS_CHECK_CARD_INFO )
            {
                //LGMPrint("debug: request card info.");
                rtn = CSMSendCardInfo(client, scmConfig);
                //break;
            }
            else if( camRxBuff[3] == CS_CHECK_NEW_ECM )
            {
                csmRequestEcm = CSM_SUCCESS;
                //LGMPrint("debug: receive ecm len=%d", len);
                rtn = CSMReceiveECM(client, &camRxBuff[4], len-4, &ecm);
                if( rtn == CSM_FAILURE )
                {
                    memcpy(camTxBuff, csSendCW, 2);
                    camTxBuff[2] = client;
                    camTxBuff[3] = 0x00;
                    rtn = CSMPutData(camTxBuff, 4);
                    csmRequestEcm = CSM_FAILURE;
                    return CSM_FAILURE;
                }
                //LGMPrint("debug: ecm convert end.");
#if 1
                rtn = SCMNotifyEcmChanged(0, 2, ecm); //send ecm to card
                csmRequestEcm = CSM_FAILURE;
                if( rtn == CSM_SUCCESS )
                {
                    LGMPrint("debug: get cw ok.");
                    SCMGetCardShareCwData(cwData);
                    CSMEncryptionCW(cwData);
                    //LGMPrint("debug: CW DATA.");
                    //SIMPrintHex(cwData, 16);
                    memcpy(camTxBuff, csSendCW, 2);
                    camTxBuff[2] = client;
                    camTxBuff[3] = 16;
                    if( scmConfig->slot[0].type == SCM_TYPE_IRDETO||
                        scmConfig->slot[0].type == SCM_TYPE_IRDETO_FUN )
                    {
                        SCMGetIrChannelId(&irChnId);
                        camTxBuff[4] = (irChnId&0xFF00)>>8;
                        camTxBuff[5] = (irChnId&0x00FF);
                    }
                    memcpy(&camTxBuff[6], cwData, 16 );
                    rtn = CSMPutData(camTxBuff, 16+6);
                    //break;
                }
                else //fail cw
                {
                    memcpy(camTxBuff, csSendCW, 2);
                    camTxBuff[2] = client;
                    camTxBuff[3] = 0x00;
                    rtn = CSMPutData(camTxBuff, 4);
                    //break;
                    LGMPrint("debug: get cw fail.");
                }
#else
                rtn = CSMNotifyEcmChanged(ecm);
#endif
            }
        }
        else
        {
            cardExistBit &= (~(1 << client));
            //break;
        }
    }
    else
    {
        cardExistBit &= (~(1 << client));
        //break;
    }
    //else
      //  LGMPrint("debug: no response.");
    //}

    return rtn;
}
#endif

void TestUartReset(void)
{
#if 0
    MMAC_UART_CNTRL_IOPB    iopb;

    iopb.deviceNumber = MMAC_UART_1;
    iopb.operation = MMAC_UART_RESET;
    MMAC_UART_Cntrl(&iopb);
#endif
    return;
}

static UINT8 CSMIrMakeEcmFilter(UINT16 chnId, T_SIMFilterConfig *filter)
{
	memset( filter, 0x00, sizeof(T_SIMFilterConfig) );

	filter->list[0].data[0] = SIM_ECM_TID1;
    filter->list[0].mask[0] = 0xFE;

    filter->list[0].data[6] = (chnId>>8)&0xFF;
    filter->list[0].mask[6] = 0xFF;

    filter->list[0].data[7] = (chnId&0xFF);
    filter->list[0].mask[7] = 0xFF;

    filter->nFilter++;

	return SCM_SUCCESS;
}

static UINT8 CSMClientProcess(T_SCMConfig *clientScm, UINT8 *receiveEcm)
{
    UINT32 len;
    UINT8  client, rtn;
    static UINT8 cardExist = 0;
    static UINT8 cw[16];
    UINT16 irChnId;
    UINT16  timeOut=200;
    

    DBMGetClientNumberCardShare(&client);
    while(1)
    {
    memset( camRxBuff, 0x00, sizeof(camRxBuff));
    if( CSMGetData(camRxBuff, &len, timeOut, 0 ) == CSM_SUCCESS )
    {
        if( camRxBuff[2]==0 && (memcmp(camRxBuff, csSendCardInfo, 2)==0) )//broadcast command
            ;
        else if( len < 3 || camRxBuff[2] != client )
            return CSM_CONTINUE;
        ITMSleep(5);
        if( memcmp(csCheckClient, camRxBuff, 2) == 0 )
        {
            if( cardExist == 0 )
            {
                memcpy(camTxBuff, csCheckClient, 2 );
                camTxBuff[2] = client;
                camTxBuff[3] = CS_CHECK_CARD_INFO;
                CSMPutData(camTxBuff, 4);
                //TestUartReset();
                //ITMSleep(30);
                continue;
            }
            else if( *receiveEcm && cardExist )
            {
                //LGMPrint("debug: send ecm.");
                CSMClientSendECM(client, shareEcm, clientScm);
                //TestUartReset();
                ITMSleep(200);
                *receiveEcm = 0;
                if( csmirActivated )
                    timeOut = 2000;//1 sec wait..
                continue;
            }
            else
            {
                memcpy(camTxBuff, csCheckClient, 2 );
                camTxBuff[2] = client;
                camTxBuff[3] = CS_CHECK_NO_INFO;
                CSMPutData(camTxBuff, 4);
                break;
                //TestUartReset();
                //LGMPrint("debug: no info.");
            }
        }
        else if( memcmp(csSendCardInfo, camRxBuff, 2) == 0 )
        {
            //LGMPrint("debug: receive card info len=%d.", len);
            rtn = CSMClientReceiveCardInfo(&camRxBuff[3], clientScm);
            if( rtn == CSM_SUCCESS )
                cardExist = 1;
            else
                cardExist = 0;
            CSMNotifyCardConfig(clientScm);
            break;
        }
        else if( memcmp(csSendCW, camRxBuff, 2 ) == 0 )
        {
            if( camRxBuff[3] == 0x00 )
            {
                if( clientScm->slot[0].type==SCM_TYPE_IRDETO ||
                    clientScm->slot[0].type==SCM_TYPE_IRDETO_FUN )
                    return CSM_SUCCESS;
                else
                    return CSM_FAILURE;
            }
            //LGMPrint("debug: cw setting.");
#if 1
            if( csmirActivated == 0 &&
                (clientScm->slot[0].type==SCM_TYPE_IRDETO ||
                    clientScm->slot[0].type==SCM_TYPE_IRDETO_FUN) )
            {
                irChnId = (camRxBuff[4]<<8) | camRxBuff[5];
                CSMIrMakeEcmFilter( irChnId, &clientScm->slot[0].ecmFilter);
                CSMNotifyReportConfig(SCM_REPORT_ECM_FILTER, clientScm);
            }
            csmirActivated = 1;
#endif
            memcpy(cw, &camRxBuff[6], 16);
            CSMDecryptionCW(cw);
            AVMNotifySetControlWord( 0, cw );
            return CSM_SUCCESS;
        }
    }
    else
        break;
    }
    return CSM_CONTINUE;
}

static UINT8 CSMClientSendECM(UINT8 client, T_SIMSection *tbl, T_SCMConfig *scmConfig)
{
    UINT8   ecmCount=0;
    UINT16 i;
    T_SIMSection	*tmp;
    
    if( tbl == NULL )
        return CAM_FAILURE;

    memcpy(camTxBuff, csCheckClient, 2 );
    camTxBuff[2] = client;
    camTxBuff[3] = CS_CHECK_NEW_ECM;

    i = 4;
    if( scmConfig->slot[0].type == SCM_TYPE_IRDETO||
        scmConfig->slot[0].type == SCM_TYPE_IRDETO_FUN )
    {
        for( tmp = tbl ; tmp != NULL ; tmp=tmp->next)
	    {
            ecmCount++;
            //LGMPrint("debug: irdeto send ecm = %d, %d.", tmp->len, ecmCount);
            camTxBuff[i]=tmp->len;
            i++;
            memcpy(&camTxBuff[i], tmp->ptr, tmp->len);
            i+=tmp->len;
            //LGMPrint("debug: ecm ptr.");
            //SIMPrintHex(tmp->ptr, tmp->len);
        }
    }
    else
    {
        camTxBuff[i] = tbl->len;
        i++;
        memcpy(&camTxBuff[i], tbl->ptr, tbl->len);
        i+=tbl->len;
    }
    //SIMPrintHex(camTxBuff, i);
    CSMPutData(camTxBuff, i);
    //LGMPrint("fatal: send ecm len=%d.", i);
    return CSM_SUCCESS;
}

static UINT8 CSMClientReceiveCardInfo(UINT8 *ptr, T_SCMConfig *scmConfig)
{
    UINT8 i, j, rtn = CSM_FAILURE;
    struct _slot	*slot;

    slot = &scmConfig->slot[0];
    //slot->status = SCM_READY;
    slot->nCa = ptr[0];
    j= 1;
    for( i = 0 ; i<slot->nCa; i++, j+=2 )
    {
        slot->caSystem[i] = (ptr[j]<<8)|ptr[j+1];
    }
    slot->nProvider = ptr[j++];
    for( i = 0 ; i<slot->nProvider; i++, j+=3 )
    {
        slot->provider[i][0] = ptr[j];
        slot->provider[i][1] = ptr[j+1];
        slot->provider[i][2] = ptr[j+2];
        //LGMPrint("debug: provider=0x%x %x %x.", 
          //  slot->provider[i][0],slot->provider[i][1],slot->provider[i][2]);
    }
    slot->type = ptr[j++];
    scmConfig->nSlot = ptr[j++];
    slot->status = ptr[j++];
    if( slot->status == SCM_READY ||
        slot->status == SCM_ACTIVE )
        rtn = CSM_SUCCESS;
    //LGMPrint("debug: slot->nCa=%d, caSystem=0x%x, nProvider=%d.", slot->nCa, slot->caSystem[0], slot->nProvider);
    //LGMPrint("debug: nSlot=%d, CARD_TYPE=%d.", scmConfig->nSlot, slot->type);
    return rtn;
}

static UINT8 CSMSendCardInfo(UINT8 client, T_SCMConfig *scmConfig)
{
    UINT16 i, j;
    struct _slot	*slot;
    UINT8 rtn;

    slot = &scmConfig->slot[0];
    
    memcpy(camTxBuff, csSendCardInfo, 2);
    camTxBuff[2] = client;
    camTxBuff[3] = slot->nCa;
    j= 4;
    //LGMPrint("debug: send card 0x%x.", slot->caSystem[0]);
    for( i = 0 ; i<slot->nCa; i++, j+=2 )
    {
        camTxBuff[j]   = ((slot->caSystem[i]&0xFF00)>>8);
        camTxBuff[j+1] = (slot->caSystem[i]&0xFF);
    }
    camTxBuff[j] = slot->nProvider;
    j++;
    for( i = 0 ; i<slot->nProvider; i++, j+=3 )
    {
        camTxBuff[j] = slot->provider[i][0];
        camTxBuff[j+1] = slot->provider[i][1];
        camTxBuff[j+2] = slot->provider[i][2];
    }
    camTxBuff[j++] = slot->type;
    camTxBuff[j++] = scmConfig->nSlot;
    camTxBuff[j++] = slot->status;
    //LGMPrint("debug: send card info len=%d.", j);
    //SIMPrintHex(camTxBuff, j);

    rtn = CSMPutData(camTxBuff, j);

    return rtn;
}

static UINT8 CSMReceiveECM(UINT8 client, UINT8 *ptr, UINT32 len, T_SIMSection **dst)
{
    T_SIMSection    *tmp, *newSec;
    UINT16  i;
    UINT8   ecmCount = 0;

    SIMFreeSection(*dst);
    *dst = NULL;

    for( i = 0; i<len; )
    {
        ecmCount++;
        newSec = ITMMalloc( sizeof(T_SIMSection) );
        if( newSec == NULL )
            return CSM_FAILURE;
        memset( newSec, 0x00, sizeof(T_SIMSection) );

        newSec->len = ptr[i];
        //LGMPrint("debug: receive newSec->len=%d.", newSec->len);
        i++;
        newSec->ptr = ITMMalloc( newSec->len );	
        if( newSec->ptr == NULL )
            return CSM_FAILURE;

        memcpy(newSec->ptr, &ptr[i], newSec->len);
        i+=newSec->len;
        //LGMPrint("debug: ecm ptr.");
        //SIMPrintHex(newSec->ptr, newSec->len);
        if( *dst == NULL )
		{
		    *dst = tmp = newSec;
		}
		else
		{
			tmp->next = newSec;
			tmp = tmp->next;
		}
    }
    //LGMPrint("debug: receive ecmCount=%d.", ecmCount);
    return CSM_SUCCESS;
}

static UINT8 CSMUartInitial(UINT8  flag)
{
	MMAC_UART_OPEN_IOPB		openIOPB;
	MMAC_UART_RESULT_CODE	status;
	MMAC_UART_CNTRL_IOPB	cntrlIOPB;
    MMAC_UART_CLOSE_IOPB	closeIOPB;
    UINT32					alternate;
    UINT8   firstPowerOn = TRUE;

#if APP_EMMA2LL||APP_EMMA2SL
	alternate = emmaBHIF.BHIF_ALTERNATE;
	emmaBHIF.BHIF_ALTERNATE = alternate 
#if APP_EMMA2LL
        | 0x00000800;//enable fuart1
#elif APP_EMMA2SL
        | 0x00004000;//enable fuart1
#endif
#endif
#if APP_NEC
    if(1)// firstPowerOn == TRUE )
    {
        firstPowerOn = FALSE;
	    status = MMAC_UART_Initialise();
        if( status != MMAC_UART_OK )
        {
            LGMPrint("fatal: UART INITIAL FAIL.");
        }
        firstPowerOn = FALSE;
	    openIOPB.deviceNumber = CSM_UART_CHANNEL;
	    status = MMAC_UART_Open( &openIOPB );
	    if (status != MMAC_UART_OK)
	    {
		    if (status != MMAC_UART_ALREADY_OPEN)
            {
#if APP_EMMA2LL||APP_EMMA2SL
			    emmaBHIF.BHIF_ALTERNATE = alternate;//restore disable fuart 1
#endif
			    LGMPrint("fatal: UART OPEN FAIL.");
			    return CSM_FAILURE;
		    }
	    }
    }
	cntrlIOPB.deviceNumber = CSM_UART_CHANNEL;
	cntrlIOPB.operation = MMAC_UART_GET_PARAMS;
	if (MMAC_UART_Cntrl( &cntrlIOPB ) != MMAC_UART_OK)
	{
#if APP_EMMA2LL||APP_EMMA2SL
		emmaBHIF.BHIF_ALTERNATE = alternate;//restore disable fuart 1
#endif
		LGMPrint("fatal: uart get fail.");
		return CSM_FAILURE;
	}

	cntrlIOPB.operation = MMAC_UART_SET_PARAMS;
	cntrlIOPB.params.databits = MMAC_UART_DATA_8;
	cntrlIOPB.params.baudrate = MMAC_UART_BR_9600;
    if(flag == DBM_OFF)
    {
        cntrlIOPB.params.readTimeout = 5;//for sat to sat
        cntrlIOPB.params.writeTimeout = 3000;
    }
    else
    {
	cntrlIOPB.params.readTimeout = CSM_UART_READ_TIMEOUT;
	cntrlIOPB.params.writeTimeout = CSM_UART_WRITE_TIMEOUT;
    }
	
	cntrlIOPB.params.stopbits = MMAC_UART_STOP_1;
	cntrlIOPB.params.parity = MMAC_UART_PARITY_NONE;

	if (MMAC_UART_Cntrl( &cntrlIOPB ) != MMAC_UART_OK)
	{
#if APP_EMMA2LL||APP_EMMA2SL
		emmaBHIF.BHIF_ALTERNATE = alternate;//restore disable fuart 1
#endif
        LGMPrint("infor: uart set fail.");
		return CSM_FAILURE;
	}

#if APP_EMMA2LL||APP_EMMA2SL
	emmaBHIF.BHIF_ALTERNATE = alternate;//restore disable fuart 1
#endif

#else//app_st
    STUART_Close(GUartHandle);
    UartOpenParams.LoopBackEnabled = FALSE; /* NO internal loopback */
	UartOpenParams.FlushIOBuffers = TRUE;   /* Flush before open */
    UartOpenParams.DefaultParams = &UartDefaultParams;
    UartOpenParams.DefaultParams->RxMode.DataBits = CAM_XCRYPT_CARD_PARITY;
    UartOpenParams.DefaultParams->TxMode.DataBits = CAM_XCRYPT_CARD_PARITY;
    UartOpenParams.DefaultParams->RxMode.StopBits = CAM_XCRYPT_CARD_STOPBITS;
    UartOpenParams.DefaultParams->TxMode.StopBits = CAM_XCRYPT_CARD_STOPBITS;
    UartOpenParams.DefaultParams->RxMode.BaudRate = CAM_XCRYPT_CARD_BAUDRATE;
    UartOpenParams.DefaultParams->TxMode.BaudRate = CAM_XCRYPT_CARD_BAUDRATE;
    Err = STUART_Open(UARTDeviceName, &UartOpenParams, &GUartHandle);
    if( Err != ST_NO_ERROR )
    {
        LGMPrint("fatal: XCRYPT UART OPEN FAIL.");
        return CSM_FAILURE;
    }
#endif

    return CSM_SUCCESS;
}

static UINT8 CSMPutData(UINT8 *ptr, UINT32 len)
{
	UINT32 i;
#if APP_NEC
	MMAC_UART_RESULT_CODE	status;
	static MMAC_UART_WRITE_IOPB	writeIOPB;

	writeIOPB.deviceNumber  = CSM_UART_CHANNEL;
	writeIOPB.length        = 1;
	for(i=0; i<len; i++)
	{
        if( i < 4 )
            ITMSleep(1);
		writeIOPB.data          = &ptr[i];
		status = MMAC_UART_Write(&writeIOPB);
		if( status != MMAC_UART_OK )
        {
            LGMPrint("fatal: CSM RS232 WRITE FAIL.");
			return CSM_FAILURE;
        }
	}
    ITMSleep(1);
#else
    ST_ErrorCode_t Err;
    UINT32	NumberOfUARTBytesWritten=0;
    
    for(i = 0; i<len; i++ )
    {
        //if( flag )
			ITMSleep(1);
        Err = STUART_Write(GUartHandle, &ptr[i], 1, &NumberOfUARTBytesWritten, CAM_UART_WRITE_TIMEOUT);
        if( Err != ST_NO_ERROR )
        {
            LGMPrint("fatal: XCRYPT RS232 WRITE FAIL.");
			return CSM_FAILURE;
        }
    }
	return;
#endif
	return CSM_SUCCESS;
}

static UINT8 CSMGetData(UINT8 *ptr, UINT32 *len, UINT32 timeout, UINT32 rLen)
{
#if APP_NEC
	MMAC_UART_CNTRL_IOPB	cntrlIOPB;
	MMAC_UART_RESULT_CODE	status;
	static MMAC_UART_READ_IOPB	readIOPB;
	UINT32 count=0;

	*len = 0;
	while(1)
	{
		readIOPB.deviceNumber  = CSM_UART_CHANNEL;
		readIOPB.data          = &ptr[*len];
		readIOPB.length        = 1;
		status = MMAC_UART_Read(&readIOPB);
		if(status == MMAC_UART_OK && readIOPB.length)
		{
			*len += readIOPB.length;
			if( rLen !=0 && rLen == *len )
				break;
		}
		else if( *len != 0 && status != MMAC_UART_OK && rLen==0) //complete
			break;
		else if( count++ >= timeout/CSM_UART_READ_TIMEOUT )
		{
			//LGMPrint("fatal: CSM RS232 READ TIMEOUT.");
			break;
		}
	}
#else
    UINT32 count=0;
    ST_ErrorCode_t Err;
    UINT32  NumberRead=0;

    *len = 0;
	while(1)
	{
        Err = STUART_Read(GUartHandle, &ptr[*len], 1, &NumberRead, CAM_UART_READ_TIMEOUT);
        if( Err == ST_NO_ERROR )
        {
            *len += NumberRead;
            if( rLen !=0 && rLen == *len )
				break;
        }
        else if ( *len != 0 && Err != ST_NO_ERROR && rLen==0 )//complete
        	break;
		else if( count++ >= timeout/CAM_UART_READ_TIMEOUT )
		{
			LGMPrint("fatal: XCRYPT RS232 READ TIMEOUT.");
			break;
		}
    }
#endif
	if( *len > 0 ) return CSM_SUCCESS;
    return CSM_FAILURE;
}


static UINT8 CSMNotifyCardConfig(T_SCMConfig *scm)
{
    T_ITMMsg		msg;

    memset(&msg, 0x00, sizeof(T_ITMMsg));
	msg.header.receiver = ITM_CAM;
	msg.header.sender = ITM_CSM;

	msg.body.cam.action = ITM_SCM_REPORT_CONFIG;
	msg.body.cam.object = SCM_REPORT_CARD_CONFIG;
    msg.body.cam.param1 = (void*)scm;
    ITMSendMessage(&msg);

    return CSM_SUCCESS;
}

static UINT8 CSMNotifyReportConfig(UINT8 reportType, T_SCMConfig *scm)
{
    T_ITMMsg		msg;

    memset(&msg, 0x00, sizeof(T_ITMMsg));
	msg.header.receiver = ITM_CAM;
	msg.header.sender = ITM_CSM;

	msg.body.cam.action = ITM_SCM_REPORT_CONFIG;
	msg.body.cam.object = reportType;
    msg.body.cam.param1 = (void*)scm;
    ITMSendMessage(&msg);

    return CSM_SUCCESS;
}

UINT8 CSMNotifyServerCardInfo(void *scm)
{
    T_ITMMsg		msg;

	memset(&msg, 0x00, sizeof(T_ITMMsg));

	msg.header.receiver = ITM_CSM;
	msg.header.sender = ITMGetTaskIndex();
	msg.body.csm.action = ITM_CSM_SERVER_REPORT_CARD_INFO;
    msg.body.csm.param1 = scm;

    ITMSendMessage(&msg);

    return CSM_SUCCESS;
}

UINT8 CSMNotifyUartInitial(UINT8 startStop)
{
    T_ITMMsg		msg;

	memset(&msg, 0x00, sizeof(T_ITMMsg));

	msg.header.receiver = ITM_CSM;
	msg.header.sender = ITMGetTaskIndex();
	msg.body.csm.action = ITM_CSM_UART_INITIAL;
    msg.body.csm.object = startStop;

    ITMSendMessage(&msg);

    return CSM_SUCCESS;
}

UINT8 CSMNotifyClientStartStop(UINT8 startStop)
{
    T_ITMMsg		msg;

	memset(&msg, 0x00, sizeof(T_ITMMsg));

	msg.header.receiver = ITM_CSM;
	msg.header.sender = ITMGetTaskIndex();
	msg.body.csm.action = ITM_CSM_CLIENT_START;
    msg.body.csm.object = startStop;

    ITMSendMessage(&msg);

    return CSM_SUCCESS;
}

UINT8 CSMNotifyClientEcm(void *ecm)
{
    T_ITMMsg		msg;

	memset(&msg, 0x00, sizeof(T_ITMMsg));

	msg.header.receiver = ITM_CSM;
	msg.header.sender = ITMGetTaskIndex();
	msg.body.csm.action = ITM_CSM_CLIENT_SEND_ECM;
    msg.body.csm.param1 = ecm;

    ITMSendMessage(&msg);
    CSMAccessTable(1);

    return CSM_SUCCESS;
}

static UINT8 CSMNotifyCardShareStatus(UINT8 status)
{
    T_ITMMsg		msg;

	memset(&msg, 0x00, sizeof(T_ITMMsg));

	msg.header.receiver = ITM_CAM;
	msg.header.sender = ITMGetTaskIndex();
	msg.body.cam.action = ITM_CSM_CLIENT_STATUS;
    msg.body.cam.object = status;

    ITMSendMessage(&msg);

    return CSM_SUCCESS;
}

static UINT8 CSMNotifyEcmChanged(UINT8 status)
{
    T_ITMMsg		msg;

	memset(&msg, 0x00, sizeof(T_ITMMsg));

	msg.header.receiver = ITM_CAM;
	msg.header.sender = ITMGetTaskIndex();
	msg.body.cam.action = ITM_CSM_SERVER_ECM_CHANGED;
    msg.body.cam.object = status;

    ITMSendMessage(&msg);

    return CSM_SUCCESS;
}

static UINT8 CSMAccessTable(UINT8 onOff)
{
	if( onOff == 1 )
		ITMTakeSemaphore(ITM_SEM_CSM_ACCESS, ITM_WAIT);
	else if( onOff == 0 )
		ITMGiveSemaphore(ITM_SEM_CSM_ACCESS);
	else
		ITMResetSemaphore(ITM_SEM_CSM_ACCESS);

	return SCM_SUCCESS;
}
#endif
//End of file
Reply With Quote
  #2  
Old 03-03-2011, 06:17 PM
medamotcha's Avatar
medamotcha medamotcha is offline
thx team N3XT and RQ-sssp
 
Join Date: Dec 2007
Location: hanging out with the sharks
Posts: 2,207
medamotcha Gangwaymedamotcha Gangwaymedamotcha Gangway
Default

ok guys at fsf...well ive got 3/4 of the code straitned out...i can make all bins accepped the compiale the data...witch is the first step..but i can do step 2,3,4..and compress z the bin..i dont know what boot c yet is but working on it..ive got about 100 hrs on figering out this source code..but ill get it...i made my first master-slave bin last night ....do not use ..yet..im just showing what ive done...sweet...neusat made a mess of this ..thay switched the names so i have to figer out and use the config file and put the paths were thair suppost to go...my last thing i have to do is config paths for all app.h....that means all in the app file and all headers that r in thair ...and that will compial all data..and make me a dvb-nec2ll.bld...than i can make a bin and crush it down..and im done and cardshare should be in the bin..load it up and turn it on.......y couldent nueshit make a bin from the biginning.nueshit would have been working in the old N2 days..but remember who is reading this you need a working sub card so you can run your server off that..
Attached Files
File Type: rar nuesat bins not finished.rar (2.47 MB, 27 views)

Last edited by medamotcha; 03-03-2011 at 07:38 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump




All times are GMT. The time now is 05:33 AM.
Powered by FreeSatFix-vBulletin® | Copyright ©2000 - 2009, FreeSatFix.com

© Copyright 2006 FreeSatFIX.com
Home Disclaimer Privacy Contact Archive Top